scopedocs-cli 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. scopedocs_cli-0.1.3/.gitignore +91 -0
  2. scopedocs_cli-0.1.3/PKG-INFO +345 -0
  3. scopedocs_cli-0.1.3/README.md +308 -0
  4. scopedocs_cli-0.1.3/pyproject.toml +84 -0
  5. scopedocs_cli-0.1.3/scopedocs_cli/__init__.py +12 -0
  6. scopedocs_cli-0.1.3/scopedocs_cli/client.py +376 -0
  7. scopedocs_cli-0.1.3/scopedocs_cli/commands/__init__.py +0 -0
  8. scopedocs_cli-0.1.3/scopedocs_cli/commands/ask.py +281 -0
  9. scopedocs_cli-0.1.3/scopedocs_cli/commands/auth.py +232 -0
  10. scopedocs_cli-0.1.3/scopedocs_cli/commands/feedback.py +62 -0
  11. scopedocs_cli-0.1.3/scopedocs_cli/commands/impact.py +73 -0
  12. scopedocs_cli-0.1.3/scopedocs_cli/commands/update.py +288 -0
  13. scopedocs_cli-0.1.3/scopedocs_cli/commands/why.py +107 -0
  14. scopedocs_cli-0.1.3/scopedocs_cli/config.py +222 -0
  15. scopedocs_cli-0.1.3/scopedocs_cli/main.py +341 -0
  16. scopedocs_cli-0.1.3/scopedocs_cli/orchestrator/__init__.py +124 -0
  17. scopedocs_cli-0.1.3/scopedocs_cli/orchestrator/base.py +51 -0
  18. scopedocs_cli-0.1.3/scopedocs_cli/orchestrator/budget.py +60 -0
  19. scopedocs_cli-0.1.3/scopedocs_cli/orchestrator/providers/__init__.py +11 -0
  20. scopedocs_cli-0.1.3/scopedocs_cli/orchestrator/providers/environment.py +36 -0
  21. scopedocs_cli-0.1.3/scopedocs_cli/orchestrator/providers/git.py +101 -0
  22. scopedocs_cli-0.1.3/scopedocs_cli/orchestrator/providers/ide.py +49 -0
  23. scopedocs_cli-0.1.3/scopedocs_cli/orchestrator/providers/workspace.py +99 -0
  24. scopedocs_cli-0.1.3/scopedocs_cli/orchestrator/trace.py +208 -0
  25. scopedocs_cli-0.1.3/scopedocs_cli/renderers/__init__.py +32 -0
  26. scopedocs_cli-0.1.3/scopedocs_cli/renderers/json.py +14 -0
  27. scopedocs_cli-0.1.3/scopedocs_cli/renderers/tui.py +250 -0
  28. scopedocs_cli-0.1.3/scopedocs_cli/theme.py +111 -0
  29. scopedocs_cli-0.1.3/scopedocs_cli/tui.py +898 -0
  30. scopedocs_cli-0.1.3/scopedocs_cli/ui.py +272 -0
@@ -0,0 +1,91 @@
1
+ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
+
3
+ # IDE and editors
4
+ .idea/
5
+ .vscode/
6
+
7
+ # Dependencies
8
+ node_modules/
9
+ /node_modules
10
+ /.pnp
11
+ .pnp.js
12
+ .yarn/install-state.gz
13
+ .yarn/*
14
+ !.yarn/patches
15
+ !.yarn/plugins
16
+ !.yarn/releases
17
+ !.yarn/versions
18
+
19
+ # Testing
20
+ /coverage
21
+
22
+ # Next.js
23
+ /.next/
24
+ /out/
25
+ next-env.d.ts
26
+ *.tsbuildinfo
27
+
28
+ # Production builds
29
+ /build
30
+ dist/
31
+ dist
32
+
33
+ # Environment files (comprehensive coverage)
34
+
35
+ *token.json*
36
+ *credentials.json*
37
+
38
+ # Logs and debug files
39
+ npm-debug.log*
40
+ yarn-debug.log*
41
+ yarn-error.log*
42
+ .pnpm-debug.log*
43
+ dump.rdb
44
+
45
+ # System files
46
+ .DS_Store
47
+ *.pem
48
+
49
+ # Python
50
+ __pycache__/
51
+ *pyc*
52
+ venv/
53
+ .venv/
54
+ .venv-backend/
55
+ frontend-next/.venv-img/
56
+
57
+ # Development tools
58
+ chainlit.md
59
+ .chainlit
60
+ .ipynb_checkpoints/
61
+ .ac
62
+
63
+ # Deployment
64
+ .vercel
65
+
66
+ # Data and databases
67
+ agenthub/agents/youtube/db
68
+
69
+ # Archive files and large assets
70
+ **/*.zip
71
+ **/*.tar.gz
72
+ **/*.tar
73
+ **/*.tgz
74
+ *.pack
75
+ *.deb
76
+ *.dylib
77
+
78
+ # Build caches
79
+ .cache/
80
+
81
+ # Mobile development
82
+ android-sdk/
83
+
84
+ # Environment files
85
+ *.env
86
+ *.env.*
87
+
88
+ # Claude Code local files (developer-specific, not shared)
89
+ CLAUDE.local.md
90
+ .claude/settings.local.json
91
+ .env
@@ -0,0 +1,345 @@
1
+ Metadata-Version: 2.4
2
+ Name: scopedocs-cli
3
+ Version: 0.1.3
4
+ Summary: ScopeDocs CLI — explain services, map impact, ask questions across your engineering knowledge graph.
5
+ Project-URL: Homepage, https://scopedocs.ai
6
+ Project-URL: Documentation, https://guide.scopedocs.app
7
+ Project-URL: Source, https://github.com/scopedocs/scopedocs-ai
8
+ Project-URL: Issues, https://github.com/scopedocs/scopedocs-ai/issues
9
+ Project-URL: Changelog, https://github.com/scopedocs/scopedocs-ai/blob/main/cli/CHANGELOG.md
10
+ Author-email: ScopeDocs <support@scopedocs.ai>
11
+ Maintainer-email: Long Nguyen <long@scopedocs.ai>
12
+ Keywords: agent,cli,developer-tools,documentation,knowledge-graph,mcp,rag,scopedocs
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: Other/Proprietary License
17
+ Classifier: Operating System :: MacOS
18
+ Classifier: Operating System :: Microsoft :: Windows
19
+ Classifier: Operating System :: POSIX :: Linux
20
+ Classifier: Programming Language :: Python :: 3
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: Software Development
25
+ Classifier: Topic :: Software Development :: Documentation
26
+ Classifier: Topic :: Utilities
27
+ Requires-Python: >=3.11
28
+ Requires-Dist: httpx>=0.27
29
+ Requires-Dist: packaging>=23.0
30
+ Requires-Dist: rich>=13.7
31
+ Requires-Dist: textual>=0.79
32
+ Requires-Dist: typer>=0.12
33
+ Provides-Extra: test
34
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'test'
35
+ Requires-Dist: pytest>=8.0; extra == 'test'
36
+ Description-Content-Type: text/markdown
37
+
38
+ # ScopeDocs CLI
39
+
40
+ Stateless HTTP client for the ScopeDocs knowledge graph. Three core verbs — `ask`, `impact`, `why` — plus auth and feedback. Designed for humans (TUI) and agents (`--json`) with the same code path.
41
+
42
+ ```
43
+ $ scopedocs why payment-service
44
+
45
+ ᴡʜʏ — payment-service
46
+ ════════════════════════════════════════════════════
47
+ Stripe was chosen over Adyen in 2024-Q3 to keep the
48
+ refund SLA under 5 minutes [1]. Idempotency keys are
49
+ enforced at the edge by checkout-web [2].
50
+
51
+ ɢ ᴏ ᴠ ᴇ ʀ ɴ ɪ ɴ ɢ ᴅ ᴇ ᴄ ɪ ꜱ ɪ ᴏ ɴ ꜱ
52
+ ADR-042 Refund SLA + provider choice long@
53
+ ADR-051 Idempotency at edge radha@
54
+
55
+ [1] notion://adr-042
56
+ [2] github://checkout-web/pull/1834
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Install
62
+
63
+ Requires Python 3.11+.
64
+
65
+ **macOS / Linux / WSL2:**
66
+
67
+ ```bash
68
+ curl -fsSL https://api.scopedocs.ai/install.sh | sh
69
+ ```
70
+
71
+ **Windows (PowerShell):**
72
+
73
+ ```powershell
74
+ irm https://api.scopedocs.ai/install.ps1 | iex
75
+ ```
76
+
77
+ **Manual (any platform):**
78
+
79
+ ```bash
80
+ pipx install scopedocs-cli # recommended
81
+ python3 -m pip install --user scopedocs-cli # plain pip
82
+ ```
83
+
84
+ **Local dev install:**
85
+
86
+ ```bash
87
+ cd cli
88
+ python3 -m venv .venv
89
+ .venv/bin/pip install -e .
90
+ ```
91
+
92
+ ## Authenticate
93
+
94
+ Get an API key from the ScopeDocs web UI (Settings → API keys), then:
95
+
96
+ ```bash
97
+ scopedocs auth login # prompts for the key
98
+ scopedocs auth status # who am I — key, org, scopes, rate-limit
99
+ scopedocs auth status --json # same, machine-readable
100
+ scopedocs auth logout # clears saved credentials
101
+ ```
102
+
103
+ `auth status` hits `/api/v1/me` and shows your CLI version, key name, org, scopes, rate-limit budget, and last-used timestamp. Use it as a "whoami" probe in CI to verify a key is still valid.
104
+
105
+ Credentials are saved to `~/.config/scopedocs/config.toml` with `0600` perms. You can also bypass the file with the `SCOPEDOCS_API_KEY` env var or `--api-key` flag.
106
+
107
+ ## Core commands
108
+
109
+ ### `scopedocs ask "<question>"`
110
+
111
+ Free-form Q&A across all sources (GitHub, Linear, Slack, Notion, code). Streams tokens by default.
112
+
113
+ ```bash
114
+ scopedocs ask "why is the refund flow flaky right now?"
115
+ scopedocs ask "who owns auth-service on-call?" --json
116
+ ```
117
+
118
+ Backend: `POST /api/v1/chat`.
119
+
120
+ ### `scopedocs impact <target>`
121
+
122
+ Blast-radius map for a service, file, or symbol — direct consumers, pipelines, dashboards, recent incidents (≤90 days), live workarounds.
123
+
124
+ ```bash
125
+ scopedocs impact payment-service
126
+ scopedocs impact backend/payment/stripe.py
127
+ scopedocs impact RefundProcessor.refund
128
+ ```
129
+
130
+ Backend: `GET /api/v1/impact/{target}`.
131
+
132
+ > **Status:** the backend endpoint is not deployed yet. The CLI calls it and exits cleanly with code `4` (not-found) until backend ships it. No canned data fallback.
133
+
134
+ ### `scopedocs why <target>`
135
+
136
+ Why is this designed this way? Returns governing ADRs, chosen path, rejected alternatives, owners — **decisions only**, not "what does this code do" (that's your coding agent's job).
137
+
138
+ ```bash
139
+ scopedocs why payment-service
140
+ scopedocs why backend/auth/jwt_auth.py
141
+ ```
142
+
143
+ Backend: `GET /api/v1/docs/search?query=...&category=adr` + `GET /api/v1/graph/node/{id}`.
144
+
145
+ ### `scopedocs update`
146
+
147
+ Check PyPI for a newer release. Detects how the CLI was installed (pipx / pip --user / venv) and prints the matching upgrade command. Pass `--apply` to run it automatically (only safe for pipx — other install methods print the command for you to run manually).
148
+
149
+ ```bash
150
+ scopedocs update # check + print upgrade command
151
+ scopedocs update --apply # auto-upgrade (pipx only)
152
+ scopedocs update --json # machine-readable
153
+ scopedocs update --channel pre # opt into pre-releases
154
+ ```
155
+
156
+ The default `--channel auto` mirrors the channel of the installed version: stable on `0.x.y`, pre-release on `0.x.ybN` / `0.x.yaN`. Pass `--channel pre` to track betas, `--channel stable` to ignore them.
157
+
158
+ ### `scopedocs feedback --good | --bad "<note>"`
159
+
160
+ Rate the most recent answer. Reads the latest entry from the local trace log, posts it to `/api/v1/feedback` with the original `client_trace_id` so the backend can join it back to the original query for DSPy training.
161
+
162
+ ```bash
163
+ scopedocs feedback --good "matched the right ADR"
164
+ scopedocs feedback --bad "missed the live workaround for INC-204"
165
+ ```
166
+
167
+ ## Interactive TUI
168
+
169
+ Run with no arguments to open a chat-style Textual app:
170
+
171
+ ```bash
172
+ scopedocs
173
+ ```
174
+
175
+ Slash commands: `/ask`, `/impact`, `/why`, `/copy` (Ctrl+Y), `/clear` (Ctrl+L), `/help`, `/exit`. Bare input (no leading slash) is treated as `/ask`. `↑`/`↓` walks prompt history.
176
+
177
+ Copy uses OSC 52 — works over SSH and tmux on iTerm2, Kitty, Alacritty, WezTerm, Ghostty, Windows Terminal. Silently no-ops on macOS Terminal.app and GNOME Terminal.
178
+
179
+ ## Global flags
180
+
181
+ Apply to every command:
182
+
183
+ | Flag | Default | Purpose |
184
+ |---|---|---|
185
+ | `--format text\|json\|markdown` | `text` | Output format. Markdown deferred. |
186
+ | `--json` | off | Shortcut for `--format json` |
187
+ | `--budget <n>` | `3000` | Token budget hint sent to backend |
188
+ | `--workspace <id>` | from config | Override workspace |
189
+ | `--api-key <key>` | from env / config | Override auth |
190
+ | `--backend <url>` | from config | Override backend URL |
191
+ | `--no-color` | auto | Disable ANSI (auto-detected on non-tty) |
192
+ | `--quiet` / `-q` | off | Suppress logs |
193
+ | `--verbose` / `-v` | off | Print HTTP request/response trace to stderr |
194
+ | `--no-context` | off | Skip the local query-enrichment layer (privacy) |
195
+ | `--no-trace` | off | Don't append to the local trace log |
196
+ | `--session` | off | Attach the last few Q/A turns from the same cwd as conversation history |
197
+ | `--no-stream` | off | Force single-shot response (disable SSE streaming) |
198
+ | `--version`, `--help` | — | Standard |
199
+
200
+ ## Config
201
+
202
+ Precedence (high → low): **CLI flag > env var > user config > repo config > built-in default**.
203
+
204
+ User config (path varies by platform):
205
+ - POSIX: `$XDG_CONFIG_HOME/scopedocs/config.toml`, default `~/.config/scopedocs/config.toml`
206
+ - Windows: `%APPDATA%/scopedocs/config.toml`
207
+
208
+ ```toml
209
+ [default]
210
+ workspace = "ws_xxx"
211
+ api_key = "sk-sd_xxx"
212
+ budget = 3000
213
+
214
+ [backend]
215
+ url = "https://api.scopedocs.ai" # default — override only for self-hosted / staging
216
+ ```
217
+
218
+ Repo override: `.scopedocs/config.toml` at the repo root (commit this for team-wide defaults). Currently honors `workspace`, `repo_alias`, and `privacy.deny`.
219
+
220
+ Environment variables: `SCOPEDOCS_API_KEY`, `SCOPEDOCS_WORKSPACE`, `SCOPEDOCS_BACKEND_URL`, `SCOPEDOCS_BUDGET`, `SCOPEDOCS_NO_TRACE`.
221
+
222
+ ## Exit codes
223
+
224
+ | Code | Meaning |
225
+ |---|---|
226
+ | `0` | Success |
227
+ | `1` | Auth required / invalid key, or generic backend error |
228
+ | `2` | Usage error (handled by Typer) |
229
+ | `3` | Backend unreachable (network / timeout) |
230
+ | `4` | Not found (404 — endpoint or target missing) |
231
+
232
+ All error paths print a clean one-line message; no Python tracebacks reach the user.
233
+
234
+ ## Query enrichment layer
235
+
236
+ Before every `/api/v1/chat` call, the CLI attaches a small `query_context` payload that the backend cannot otherwise see. This is **query refinement only** — it is *not* the DSPy context distillation, which lives in the backend.
237
+
238
+ | Provider | Collects |
239
+ |---|---|
240
+ | `env` | cwd, CLI version, terminal, IDE hint |
241
+ | `git` | branch, head sha (12 chars), uncommitted dirty files (cap 20) |
242
+ | `ide_selection` | file, line range, highlighted text (cap 1200 chars) |
243
+ | `workspace_config` | `.scopedocs/config.toml` workspace, repo alias, privacy denylist |
244
+
245
+ Total payload is capped at ~2000 chars (≈500 tokens). Eviction order when over: `workspace_config` → `ide_selection.text` → `git.dirty_files[5:]` → drop entire provider. `env` always survives.
246
+
247
+ **Deliberately not collected:** recent commits, PR descriptions, file content beyond uncommitted changes — those already exist in Layer 2 via the GitHub integration.
248
+
249
+ Disable with `--no-context` (one-shot) or remove the relevant provider via `.scopedocs/config.toml`.
250
+
251
+ ## Trace log
252
+
253
+ Every invocation appends one JSONL line to a per-user state file:
254
+ - POSIX: `$XDG_STATE_HOME/scopedocs/traces.jsonl`, default `~/.local/state/scopedocs/traces.jsonl`
255
+ - Windows: `%LOCALAPPDATA%/scopedocs/traces.jsonl`
256
+
257
+ ```json
258
+ {"trace_id": "...", "ts": "...", "command": "ask", "question": "...", "query_context": {...}, "answer_summary": "...", "source_refs": [...], "tokens_used": 0, "backend_request_id": "..."}
259
+ ```
260
+
261
+ Perms `0600`. Auto-rotates at 5000 lines. The `feedback` command reads the most recent entry to wire the rating back to the original query.
262
+
263
+ Disable with `--no-trace` or `SCOPEDOCS_NO_TRACE=1`.
264
+
265
+ ## JSON output
266
+
267
+ Every command supports `--json` for agent consumption. Stable schemas — see [scopedocs_cli/renderers/json.py](scopedocs_cli/renderers/json.py). Example:
268
+
269
+ ```bash
270
+ scopedocs ask "who owns billing?" --json | jq '.sources[].url'
271
+ ```
272
+
273
+ `ask` shape:
274
+
275
+ ```json
276
+ {
277
+ "command": "ask",
278
+ "question": "string",
279
+ "summary": "string with [1] [2] citations",
280
+ "evidence": [{"source": "...", "system": "github|slack|linear|notion|...", "signal": "...", "ref": "1"}],
281
+ "recommendation": "string",
282
+ "sources": [{"ref": "1", "url": "...", "type": "pr|slack_thread|notion_page|adr|incident", "title": "..."}],
283
+ "tokens_used": 0,
284
+ "tokens_budget": 3000
285
+ }
286
+ ```
287
+
288
+ Schemas for `impact` and `why` are documented inline in [scopedocs_cli/renderers/json.py](scopedocs_cli/renderers/json.py).
289
+
290
+ ## Verbose mode
291
+
292
+ `--verbose` enables Warp-style per-request tracing on stderr:
293
+
294
+ ```
295
+ → POST https://api.scopedocs.ai/api/v1/chat
296
+ ← 200 https://api.scopedocs.ai/api/v1/chat in 412ms
297
+ ```
298
+
299
+ Useful when debugging auth/backend issues without enabling Python logging.
300
+
301
+ ## Structure
302
+
303
+ ```
304
+ cli/
305
+ ├── pyproject.toml
306
+ ├── README.md
307
+ └── scopedocs_cli/
308
+ ├── main.py # Typer entry, global flags, lazy-imported subcommands
309
+ ├── client.py # httpx wrapper (4 exception types, streaming SSE)
310
+ ├── config.py # XDG config loader, save/clear creds
311
+ ├── theme.py # Terminal Cartography palette
312
+ ├── tui.py # Textual chat TUI
313
+ ├── ui.py # Rich helpers (shared TUI + one-shot)
314
+ ├── commands/ # ask · impact · why · feedback · auth
315
+ ├── orchestrator/ # query enrichment layer + budget + trace
316
+ │ ├── budget.py
317
+ │ ├── trace.py
318
+ │ └── providers/ # env · git · ide_selection · workspace_config
319
+ └── renderers/ # tui.py + json.py
320
+ ```
321
+
322
+ ## Tests
323
+
324
+ ```bash
325
+ cd cli && python -m pytest tests/ -v
326
+ ```
327
+
328
+ 73 tests covering providers, budget, trace, client, config, ask command, `auth status` / `me` plumbing, and `update` (version compare, channel filtering, install-method detection). Mocked with `httpx.MockTransport`; no live network. CI runs the matrix on Python 3.11/3.12/3.13 across Ubuntu, macOS, and Windows — see [.github/workflows/cli-tests.yml](../.github/workflows/cli-tests.yml).
329
+
330
+ ## Releasing
331
+
332
+ Releases are automatic. Merge a PR that bumps the version in `cli/pyproject.toml` (and the matching `cli/scopedocs_cli/__init__.py`) to `main`, and `.github/workflows/cli-release.yml` will:
333
+
334
+ 1. Read the version from `cli/pyproject.toml`.
335
+ 2. Verify `__init__.py` matches (catch desync mistakes).
336
+ 3. Skip cleanly if that version already exists on PyPI (idempotent).
337
+ 4. Run the test suite, build sdist + wheel, validate with `twine check --strict`.
338
+ 5. Publish to PyPI via Trusted Publishing (OIDC — no API token in secrets).
339
+ 6. Tag the commit `cli-v<version>` and create a GitHub Release with the artifacts attached.
340
+
341
+ To force a re-publish (rare — only if you yanked and want to re-upload), use the workflow's `workflow_dispatch` trigger with `force=true`.
342
+
343
+ **One-time setup** (already done if you can see releases): on PyPI go to project → Settings → Publishing → "Add a new pending publisher" with `owner=scopedocs`, `repo=scopedocs-ai`, `workflow=cli-release.yml`, `environment=pypi-cli-release-d9421f10`. Then create the `pypi-cli-release-d9421f10` environment in GitHub repo settings (no secrets needed; restrict deployment branches to `main`).
344
+
345
+ See [CHANGELOG.md](CHANGELOG.md) for release history.