Skip to content

Commit 7f40c04

Browse files
committed
fix: implement init and test CLI commands
1 parent 391bf1d commit 7f40c04

2 files changed

Lines changed: 100 additions & 23 deletions

File tree

.devscontext.yaml.example

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
# DevsContext Configuration
2-
# Copy this file to .devscontext.yaml and configure for your environment
2+
# Copy this file to .devscontext.yaml and configure your adapters.
3+
# API tokens should be set via environment variables for security.
34

45
adapters:
5-
# Jira integration for fetching ticket details
66
jira:
7-
enabled: false
7+
enabled: true
88
base_url: "https://your-company.atlassian.net"
9-
email: "your-email@company.com"
10-
# Use environment variable for API token:
11-
# export JIRA_API_TOKEN="your-api-token"
9+
email: "${JIRA_EMAIL}"
1210
api_token: "${JIRA_API_TOKEN}"
1311

14-
# Fireflies.ai for meeting transcripts
1512
fireflies:
1613
enabled: false
17-
# Use environment variable for API key:
18-
# export FIREFLIES_API_KEY="your-api-key"
1914
api_key: "${FIREFLIES_API_KEY}"
2015

21-
# Local documentation directories
2216
local_docs:
2317
enabled: true
2418
paths:
2519
- "./docs"
26-
- "./architecture"
27-
# Add more paths as needed
20+
- "./CLAUDE.md"
21+
22+
synthesis:
23+
provider: "anthropic" # anthropic, openai, or ollama
24+
model: "claude-3-haiku-20240307"
25+
# api_key: "${ANTHROPIC_API_KEY}" # Uses ANTHROPIC_API_KEY env var by default
2826

29-
# Cache settings
3027
cache:
31-
ttl_seconds: 300 # 5 minutes
32-
max_size: 100 # Maximum cached items
28+
ttl_seconds: 300
29+
max_size: 100

src/devscontext/cli.py

Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,57 @@ def cli(ctx: click.Context) -> None:
4343
def init() -> None:
4444
"""Create .devscontext.yaml configuration interactively.
4545
46-
Guides the user through setting up adapters and configuration.
47-
Currently shows placeholder text with manual setup instructions.
46+
Creates a starter configuration file with common defaults.
4847
"""
49-
click.echo("TODO: interactive setup")
48+
from pathlib import Path
49+
50+
config_path = Path(".devscontext.yaml")
51+
52+
if config_path.exists():
53+
click.echo(f"Config file already exists: {config_path}")
54+
if not click.confirm("Overwrite?", default=False):
55+
click.echo("Aborted.")
56+
return
57+
58+
config_content = """\
59+
# DevsContext Configuration
60+
# See https://github.com/anthropics/devscontext for documentation
61+
62+
adapters:
63+
jira:
64+
enabled: true
65+
base_url: "https://your-company.atlassian.net"
66+
email: "${JIRA_EMAIL}"
67+
api_token: "${JIRA_API_TOKEN}"
68+
69+
fireflies:
70+
enabled: false
71+
api_key: "${FIREFLIES_API_KEY}"
72+
73+
local_docs:
74+
enabled: true
75+
paths:
76+
- "./docs"
77+
- "./CLAUDE.md"
78+
79+
synthesis:
80+
provider: "anthropic"
81+
model: "claude-3-haiku-20240307"
82+
83+
cache:
84+
ttl_seconds: 300
85+
max_size: 100
86+
"""
87+
88+
config_path.write_text(config_content)
89+
click.echo(f"Created {config_path}")
5090
click.echo()
51-
click.echo("For now, copy .devscontext.yaml.example to .devscontext.yaml")
52-
click.echo("and configure your adapters manually.")
91+
click.echo("Next steps:")
92+
click.echo(" 1. Edit .devscontext.yaml with your Jira URL")
93+
click.echo(" 2. Set environment variables:")
94+
click.echo(" export JIRA_EMAIL='your-email@company.com'")
95+
click.echo(" export JIRA_API_TOKEN='your-api-token'")
96+
click.echo(" 3. Test: devscontext test --ticket YOUR-123")
5397

5498

5599
@cli.command()
@@ -65,12 +109,48 @@ def test(ticket: str | None) -> None:
65109
Verifies that all enabled adapters can connect to their respective
66110
services. Optionally tests fetching context for a specific ticket.
67111
"""
68-
click.echo("TODO: test connection")
112+
import asyncio
113+
114+
from devscontext.config import load_devscontext_config
115+
from devscontext.core import DevsContextCore
116+
117+
try:
118+
config = load_devscontext_config()
119+
except FileNotFoundError:
120+
click.echo("No .devscontext.yaml found. Run 'devscontext init' first.")
121+
return
122+
123+
click.echo("Testing adapter connections...")
124+
click.echo()
125+
126+
core = DevsContextCore(config)
127+
128+
async def run_health_checks() -> dict[str, bool]:
129+
return await core.health_check()
130+
131+
results = asyncio.run(run_health_checks())
132+
133+
for adapter, healthy in results.items():
134+
status = click.style("✓", fg="green") if healthy else click.style("✗", fg="red")
135+
click.echo(f" {status} {adapter}")
136+
69137
click.echo()
138+
70139
if ticket:
71-
click.echo(f"Would test fetching context for: {ticket}")
140+
click.echo(f"Fetching context for {ticket}...")
141+
142+
async def fetch_context() -> str:
143+
result = await core.get_task_context(ticket)
144+
return result.synthesized
145+
146+
try:
147+
output = asyncio.run(fetch_context())
148+
click.echo()
149+
click.echo(output)
150+
except Exception as e:
151+
click.echo(f"Error: {e}", err=True)
72152
else:
73-
click.echo("Use --ticket PROJ-123 to test fetching a specific ticket.")
153+
click.echo("Use --ticket PROJ-123 to test fetching a ticket.")
74154

75155

76156
@cli.command()

0 commit comments

Comments
 (0)