@c4a/context-cli 0.5.29-alpha.1

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 (38) hide show
  1. package/README.md +122 -0
  2. package/cli.js +37711 -0
  3. package/package.json +18 -0
  4. package/plugin/.claude-plugin/plugin.json +16 -0
  5. package/plugin/.claude-plugin/plugin.json.template +16 -0
  6. package/plugin/.codex-plugin/plugin.json +35 -0
  7. package/plugin/.codex-plugin/plugin.json.template +35 -0
  8. package/plugin/commands/align.md +54 -0
  9. package/plugin/commands/capture-aspect.md +17 -0
  10. package/plugin/commands/capture-code.md +25 -0
  11. package/plugin/commands/capture.md +67 -0
  12. package/plugin/commands/compile.md +89 -0
  13. package/plugin/commands/context.md +30 -0
  14. package/plugin/commands/drop.md +17 -0
  15. package/plugin/commands/extract.md +18 -0
  16. package/plugin/commands/init.md +95 -0
  17. package/plugin/commands/purge.md +18 -0
  18. package/plugin/commands/query.md +13 -0
  19. package/plugin/commands/status.md +21 -0
  20. package/plugin/skills/align-finalize/SKILL.md +137 -0
  21. package/plugin/skills/align-propose/SKILL.md +142 -0
  22. package/plugin/skills/align-scan/SKILL.md +161 -0
  23. package/plugin/skills/align-scan/references/data-model.md +343 -0
  24. package/plugin/skills/align-scan/references/user-question-contract.md +155 -0
  25. package/plugin/skills/compile-close/SKILL.md +122 -0
  26. package/plugin/skills/compile-draft/SKILL.md +246 -0
  27. package/plugin/skills/context-query/SKILL.md +166 -0
  28. package/plugin/skills/drop/SKILL.md +163 -0
  29. package/plugin/skills/semantic-reconcile/SKILL.md +106 -0
  30. package/scripts/build-plugin.ts +70 -0
  31. package/scripts/postinstall.mjs +183 -0
  32. package/templates/aspects/code/prompt.md +29 -0
  33. package/templates/aspects/design-system/prompt.md +27 -0
  34. package/templates/aspects/graphql/prompt.md +24 -0
  35. package/templates/aspects/openapi/prompt.md +24 -0
  36. package/wasm/tree-sitter-tsx.wasm +0 -0
  37. package/wasm/tree-sitter-typescript.wasm +0 -0
  38. package/wasm/tree-sitter.wasm +0 -0
package/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # @c4a/context-cli
2
+
3
+ Local knowledge workspace CLI for [c4a — Context For AI](https://github.com/context4ai/c4a).
4
+
5
+ `@c4a/context-cli` ships three surfaces in a single npm package:
6
+
7
+ 1. **`context` CLI** — a Node/Bun-compatible executable that captures documents, extracts code structure, and manages a local context workspace.
8
+ 2. **Claude Code plugin `context`** — slash commands (`/context:init`, `/context:capture`, `/context:align`, `/context:compile`, `/context:query`, `/context:drop`, `/context:purge`, `/context:status`, …) and a pipeline of eight skills (`align-scan`, `align-propose`, `align-finalize`, `compile-draft`, `compile-close`, `context-query`, `drop`, `semantic-reconcile`) whose SKILL.md + canonical `data-model.md` reference define the agent-driven align / compile / query / drop protocols.
9
+ 3. **Codex plugin `context`** — a `.codex-plugin/plugin.json` manifest that points Codex at the same `plugin/skills/` directory, exposed through the repo marketplace at `.agents/plugins/marketplace.json`.
10
+
11
+ The split follows a simple rule: mechanical work is the CLI's job; synthesis work (knowledge alignment, compilation, knowledge-side drop cleanup) is the Claude agent's job. The CLI never calls an LLM.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ # Install the CLI globally (recommended — puts `context` on PATH).
17
+ bun install -g @c4a/context-cli
18
+ context --version
19
+
20
+ # Install as a Claude Code plugin (adds the /context:* slash commands).
21
+ # The plugin assumes the CLI is on PATH; install -g first.
22
+ claude plugin install @c4a/context-cli
23
+
24
+ # Add the Codex repo marketplace when working from the c4a monorepo.
25
+ # The marketplace points at packages/context-cli/plugin.
26
+ codex plugin marketplace add context4ai/c4a --sparse .agents/plugins packages/context-cli/plugin
27
+ ```
28
+
29
+ When installed as a Claude Code plugin, the `postinstall` hook checks whether the `context` bin is already on PATH. If not, it prints the two commands you can run yourself (`bun install -g @c4a/context-cli` for registry installs, or `bun link` for a local build). It never spawns an install on your behalf — that would silently substitute a registry build for a local tarball / file: / github: plugin install.
30
+
31
+ ## Quick tour
32
+
33
+ ```bash
34
+ # Initialize a workspace in the current project
35
+ context init my-product --with-all-aspects
36
+
37
+ # Dedicated knowledge repo: use the current directory as the data root
38
+ context init my-kb --layout root --language English --minimal
39
+
40
+ # Capture material into raw/ (CLI does the ingestion)
41
+ context capture https://example.feishu.cn/docx/<token>
42
+ context capture ./docs/design.md
43
+ context capture --inbox
44
+ context capture-code # extract TypeScript structure
45
+
46
+ # In Claude Code, align → compile → drop are agent-driven
47
+ /context:align # agent classifies raw into a Node tree; user confirms
48
+ /context:compile # agent writes Section-level actions for each Node; CLI renders
49
+ /context:drop feishu:doc:xxx --reason "obsolete"
50
+ /context:status
51
+ ```
52
+
53
+ ## Workspace layout
54
+
55
+ Embedded layout (default):
56
+
57
+ ```
58
+ .context/
59
+ ├── config.yaml # workspace name, schema version, aspects
60
+ ├── raw/ # immutable captured sources (CLI-owned)
61
+ │ ├── _sources.yaml # authoritative source registry
62
+ │ ├── feishu/<date>-<slug>…md
63
+ │ ├── local/<date>-<slug>…md
64
+ │ └── aspect/code/<date>-<sha7>/
65
+ ├── output/ # align pipeline scratch (not committed)
66
+ │ ├── align.scan.yaml
67
+ │ ├── align.propose.{md,yaml}
68
+ │ ├── align.user-decisions.yaml
69
+ │ ├── align.{md,final.input.yaml}
70
+ │ └── bind.yaml
71
+ ├── knowledge/ # synthesized articles (CLI-rendered, agent-directed)
72
+ │ ├── _index.md # workspace index (derivable, rebuilt by compile --close)
73
+ │ ├── changelog.md # append-only compile / drop log (derivable from git)
74
+ │ ├── domain/ entity/ action/ concept/ # one directory per Node type
75
+ ├── archive/ # dropped but restorable raw / knowledge artifacts
76
+ └── aspects/<name>/prompt.md # per-aspect capture prompt templates
77
+ ```
78
+
79
+ Root layout (`context init --layout root`) uses the same tree directly in the current directory: `config.yaml`, `raw/`, `output/`, `knowledge/`, `archive/`, `aspects/`, and `inbox/` live at repo root. Root layout is intended for dedicated knowledge repositories; initialization refuses to run if those C4A-owned entries already exist.
80
+
81
+ `context init` also creates `AGENTS.md` inside the C4A data root (`.context/` in embedded layout, current directory in root layout) and, when absent, a same-directory `CLAUDE.md` symlink pointing to `AGENTS.md`. Existing files are kept.
82
+
83
+ Data model: Node (`domain` / `entity` / `action` / `concept`) + Section (ten kinds — see `plugin/skills/align-scan/references/data-model.md` shipped in the tarball for the canonical tables) + five logical Edge types.
84
+
85
+ ## Commands
86
+
87
+ | Command | Role | Notes |
88
+ |---|---|---|
89
+ | `context init [name]` | CLI | Create or append an embedded `.context/` workspace or a root-layout workspace; copy aspect templates and write `AGENTS.md`. |
90
+ | `context capture <url \| ./path.md [./more.md...] \| --stdin \| --inbox \| --refresh>` | CLI | Ingest documents. Feishu URLs use `lark-cli`; local `.md` files can be captured one at a time, as variadic paths, or as newline-separated paths from stdin. Local source identity follows the captured file's stable origin path, so title edits append snapshots to the same source. Re-capturing an identical dropped source restores its source/raw archive entry without overwriting active knowledge edits. |
91
+ | `context capture-code` | CLI | Snapshot TypeScript packages/symbols/edges. |
92
+ | `context capture-aspect <name>` | CLI | Stub in the current release — every invocation exits non-zero with "planned for a future release". |
93
+ | `context extract <path>` | CLI | Read-only debug print of an extraction; never writes workspace files. |
94
+ | `context align --scan \| --save-scan-decisions <file\|-> \| --propose <file\|-> [--save-input] \| --save-user-decisions <file\|-> \| --finalize <file\|-> [--save-input]` | CLI | Workflow helpers driven by the `/context:align` skill pipeline. Domain commands own align protocol files; agents do not write them directly. |
95
+ | `context compile --context <slug> [--save-output] \| --draft <slug> --input <file\|-> [--plan] [--save-input] \| --close` | CLI | Workflow helpers driven by the `/context:compile` skill pipeline. `--save-*` stores CLI-owned scratch copies under `output/` for close-time archival. |
96
+ | `context mdrive <group> <verb>` | CLI | Knowledge primitive shell: node / section / edge / query / verify / glossary / workspace. Run `context mdrive --help` for subcommands. |
97
+ | `context drop <source-id\|raw-path\|url> --plan` / `context drop --apply-plan <file\|-> --reason <text> [--yes]` | CLI | Plans and applies source retraction: archives affected active raw/knowledge under `archive/`, removes unsupported active Sections/empty Nodes, stamps `_sources.yaml.status=dropped`, appends `[drop]`, and verifies. |
98
+ | `context purge [--yes]` | CLI | Permanently deletes every archive under `archive/` after a summary + confirmation; active `raw/` and `knowledge/` are not modified. |
99
+ | `context verify` | CLI | Whole-workspace verify (schema, Section mount matrix, contains acyclicity, dropped-source references, dangling `src-N`, body ad-hoc headings, domain-inline-child, duplicate slug). |
100
+ | `context doctor` | CLI | Four-layer diagnostics (output scan / propose / align / knowledge). |
101
+ | `context status [--format json\|table]` | CLI | Workspace overview + next-action suggestions. |
102
+ | `/context:align`, `/context:compile`, `/context:drop`, `/context:purge` | Agent | Skill-driven wrappers around the CLI; align/compile/drop produce structured JSON/YAML per skill contract, purge delegates to CLI confirmation. |
103
+ | `/context:context <free text>` | Agent | Fuzzy router over the above. |
104
+
105
+ CLI commands that require a workspace exit with a workspace-not-found error if run outside a directory tree containing either embedded `.context/` layout or root layout; `context init` is the only command that creates one.
106
+
107
+ ## Development
108
+
109
+ Source lives at [`packages/context-cli/`](./src) in the c4a monorepo.
110
+
111
+ ```bash
112
+ bun run --filter @c4a/context-cli build # bundle CLI + render plugin.json
113
+ bun run --filter @c4a/context-cli test # unit + integration tests
114
+ bun run --filter @c4a/context-cli typecheck
115
+ bun run --filter @c4a/context-cli lint
116
+ ```
117
+
118
+ The build chains `scripts/build-plugin.ts`, which reads the Claude and Codex plugin manifest templates and substitutes `__VERSION__` from `package.json`.
119
+
120
+ ## License
121
+
122
+ MIT.