@c4a/context-cli 0.5.29-alpha.1 → 0.5.29-beta.16

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 (49) hide show
  1. package/README.md +71 -34
  2. package/cli.js +39951 -15792
  3. package/package.json +1 -1
  4. package/plugin/.claude-plugin/plugin.json.template +1 -1
  5. package/plugin/.codex-plugin/plugin.json.template +8 -5
  6. package/plugin/.cursor-plugin/plugin.json.template +29 -0
  7. package/plugin/README.md +99 -0
  8. package/plugin/README_CN.md +97 -0
  9. package/plugin/assets/icon.svg +3 -0
  10. package/plugin/assets/logo.svg +3 -0
  11. package/plugin/commands/align.md +44 -44
  12. package/plugin/commands/capture.md +28 -12
  13. package/plugin/commands/compile.md +97 -34
  14. package/plugin/commands/context.md +7 -4
  15. package/plugin/commands/drop.md +14 -6
  16. package/plugin/commands/extract.md +4 -4
  17. package/plugin/commands/init.md +49 -10
  18. package/plugin/commands/purge.md +8 -4
  19. package/plugin/commands/query.md +11 -3
  20. package/plugin/commands/status.md +4 -2
  21. package/plugin/skills/skill-align-workflow/SKILL.md +55 -0
  22. package/plugin/skills/skill-align-workflow/references/candidate-resolution.md +60 -0
  23. package/plugin/skills/skill-align-workflow/references/density-profile.md +23 -0
  24. package/plugin/skills/skill-align-workflow/references/gates.md +95 -0
  25. package/plugin/skills/skill-compile-close/SKILL.md +127 -0
  26. package/plugin/skills/skill-compile-draft/SKILL.md +409 -0
  27. package/plugin/skills/skill-context-query/SKILL.md +184 -0
  28. package/plugin/skills/skill-drop/SKILL.md +190 -0
  29. package/plugin/skills/skill-semantic-reconcile/SKILL.md +249 -0
  30. package/scripts/build-plugin.ts +674 -45
  31. package/templates/aspects/code/aspect.yaml +21 -0
  32. package/templates/aspects/code/prompt.md +33 -18
  33. package/templates/aspects/design-system/prompt.md +2 -3
  34. package/templates/aspects/graphql/prompt.md +2 -2
  35. package/templates/aspects/openapi/prompt.md +2 -2
  36. package/plugin/.claude-plugin/plugin.json +0 -16
  37. package/plugin/.codex-plugin/plugin.json +0 -35
  38. package/plugin/commands/capture-aspect.md +0 -17
  39. package/plugin/commands/capture-code.md +0 -25
  40. package/plugin/skills/align-finalize/SKILL.md +0 -137
  41. package/plugin/skills/align-propose/SKILL.md +0 -142
  42. package/plugin/skills/align-scan/SKILL.md +0 -161
  43. package/plugin/skills/align-scan/references/data-model.md +0 -343
  44. package/plugin/skills/align-scan/references/user-question-contract.md +0 -155
  45. package/plugin/skills/compile-close/SKILL.md +0 -122
  46. package/plugin/skills/compile-draft/SKILL.md +0 -246
  47. package/plugin/skills/context-query/SKILL.md +0 -166
  48. package/plugin/skills/drop/SKILL.md +0 -163
  49. package/plugin/skills/semantic-reconcile/SKILL.md +0 -106
package/README.md CHANGED
@@ -2,32 +2,43 @@
2
2
 
3
3
  Local knowledge workspace CLI for [c4a — Context For AI](https://github.com/context4ai/c4a).
4
4
 
5
- `@c4a/context-cli` ships three surfaces in a single npm package:
5
+ `@c4a/context-cli` is the **CLI** package the `context` executable plus its source-of-truth plugin templates. Plugin install trees are distributed separately through the [context4ai/context](https://github.com/context4ai/context) repo (Claude / Codex / Cursor / Vercel-style skills), generated by `bun run build:plugin` from `plugin/` source.
6
+
7
+ This package ships:
6
8
 
7
9
  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
+ 2. **`plugin/` source**human-maintained command/skill/manifest sources that `scripts/build-plugin.ts` compiles into the four plugin install trees in the `context4ai/context` repo.
10
11
 
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
+ The split follows a simple rule: mechanical work is the CLI's job; synthesis work (knowledge alignment, compilation, knowledge-side drop cleanup) is the agent's job. The CLI never calls an LLM. Naming surfaces are deliberately separate: `/context:*` is a Claude slash command, Cursor exposes prefixed command entries such as `/context-align` / `/context-compile`, `Context: ...` / `context-*` is a public skill entry for skill-only agents, `context ...` is the CLI primitive, and `context:skill-*` is an internal procedure invoked by the workflow.
12
13
 
13
14
  ## Install
14
15
 
15
16
  ```bash
16
- # Install the CLI globally (recommended puts `context` on PATH).
17
+ # 1. Install the CLI globally (required by every plugin path; `context` must be on PATH).
17
18
  bun install -g @c4a/context-cli
18
19
  context --version
19
20
 
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
21
+ # 2. Install the plugin for your editor.
22
+ # Claude Code:
23
+ claude /plugin marketplace add context4ai/context
24
+ claude /plugin install context@context
25
+
26
+ # Codex CLI:
27
+ codex marketplace add context4ai/context
28
+
29
+ # Cursor:
30
+ # Dashboard → Settings → Plugins → Import → https://github.com/context4ai/context
23
31
 
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
32
+ # Vercel-style skills (Windsurf / OpenCode / Cline / Copilot etc.):
33
+ npx skills add github:context4ai/context skill-context-align
27
34
  ```
28
35
 
36
+ All four plugin paths point at the [context4ai/context](https://github.com/context4ai/context) repo (generated from this package's `plugin/` source). They are independent of the npm CLI — the CLI is a hard prerequisite the plugin commands call out to via `$PATH`.
37
+
29
38
  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
39
 
40
+ For local checkout development, link installs, or branch-specific plugin testing, see [DEVELOPMENT.md](./DEVELOPMENT.md).
41
+
31
42
  ## Quick tour
32
43
 
33
44
  ```bash
@@ -37,11 +48,17 @@ context init my-product --with-all-aspects
37
48
  # Dedicated knowledge repo: use the current directory as the data root
38
49
  context init my-kb --layout root --language English --minimal
39
50
 
40
- # Capture material into raw/ (CLI does the ingestion)
51
+ # Start without aspects; append them later when needed
52
+ context init my-kb --no-aspects
53
+ context init --with-aspects code,openapi
54
+
55
+ # Capture material as sources (CLI does the ingestion)
41
56
  context capture https://example.feishu.cn/docx/<token>
42
57
  context capture ./docs/design.md
43
58
  context capture --inbox
44
- context capture-code # extract TypeScript structure
59
+ context capture --code packages/extract --plan --format json
60
+ context capture --code --module packages/extract --version-from package
61
+ context capture --code # refresh existing code capture config
45
62
 
46
63
  # In Claude Code, align → compile → drop are agent-driven
47
64
  /context:align # agent classifies raw into a Node tree; user confirms
@@ -50,28 +67,42 @@ context capture-code # extract TypeScript structure
50
67
  /context:status
51
68
  ```
52
69
 
53
- ## Workspace layout
70
+ ## Production Agent Contract
71
+
72
+ For production Agent workflows, `context` is a semantic service. A local path is valid when it is the external capture input (`context capture ./docs/design.md`) or another user-supplied source target. Agent-authored workflow payloads use stdin plus CLI-owned payload handles, not scratch files. After capture succeeds, continue with the returned `source_id`, `block_id`, `source_ref`, `node_slug`, Section id, workflow payload name, scope id, digest, or query text.
73
+
74
+ Workspace language is also part of the Agent contract. `config.yaml` can set `workspace.language` or `defaults.compile_language`; align and compile expose this as `generation_policy` in `align-segments` and NodeContext. Agents should generate Node titles, summaries, Section prose, and user-facing reports in that language while preserving product names, code identifiers, flags, slugs, `source_ref` values, and exact quoted evidence.
75
+
76
+ Do not treat the workspace storage tree as the protocol. Agent-facing workflows should not read, list, grep, cat, or derive state from `.context/**`, `raw/**`, `knowledge/**`, `output/**`, archives, cache roots, or rendered Markdown files. Use `context workflow status/show` for workflow payloads, `context source ...` for source metadata, `context mdrive ...` and `context query` for knowledge, and `context status` / `context doctor` / `context verify` for semantic diagnostics.
77
+
78
+ Agent-facing output should be stable by construction: shared protocol/schema/lookup context comes before task-specific objects, JSON key order is deterministic, and default output does not add current timestamps, random ids, storage paths, or host absolute paths. Existing knowledge is the registry. Use `context mdrive glossary list|match`, `context mdrive node list`, and `context query` to reuse term/service/system/action/domain handles; do not create or read a separate dynamic registry file.
79
+
80
+ `source_ref` is an opaque citation token. Copy it into citations and decisions exactly as printed; do not parse it or dereference it as a file path. Human/report views may show clickable files for user inspection. Developer/debug-only `context debug ...` commands may expose storage paths for diagnostics, but those values are not production Agent workflow inputs.
81
+
82
+ ## Developer Storage Layout
83
+
84
+ The following tree describes the CLI-owned storage implementation for developers and operators. It is not the production Agent workflow contract.
54
85
 
55
86
  Embedded layout (default):
56
87
 
57
88
  ```
58
89
  .context/
59
90
  ├── config.yaml # workspace name, schema version, aspects
60
- ├── raw/ # immutable captured sources (CLI-owned)
91
+ ├── raw/ # immutable captured source bodies (CLI-owned; metadata lives in _sources.yaml)
61
92
  │ ├── _sources.yaml # authoritative source registry
62
93
  │ ├── feishu/<date>-<slug>…md
63
94
  │ ├── 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
95
+ │ └── aspect/code/<source-slug>/<snapshot-id>/
96
+ ├── output/ # workflow scratch only; root contains directories, not files
97
+ │ ├── align/ # align proposal/review/debug scratch
98
+ │ ├── compile/ # compile context/draft/prepare/review scratch
99
+ │ ├── drop/ # drop plan/prepare/review scratch
100
+ └── archive/ # archived workflow scratch
101
+ ├── .cache/ # ignored internal cache, including current align binding
71
102
  ├── knowledge/ # synthesized articles (CLI-rendered, agent-directed)
72
103
  │ ├── _index.md # workspace index (derivable, rebuilt by compile --close)
73
104
  │ ├── changelog.md # append-only compile / drop log (derivable from git)
74
- │ ├── domain/ entity/ action/ concept/ # one directory per Node type
105
+ │ ├── domain/ entity/ action/ # one directory per Node type
75
106
  ├── archive/ # dropped but restorable raw / knowledge artifacts
76
107
  └── aspects/<name>/prompt.md # per-aspect capture prompt templates
77
108
  ```
@@ -80,24 +111,23 @@ Root layout (`context init --layout root`) uses the same tree directly in the cu
80
111
 
81
112
  `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
113
 
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.
114
+ Data model: Node (`domain` / `entity` / `action`) + Section (ten kinds, mounted by node type) + derived traversal edges. Named concept-layer subjects are modeled as `entity` nodes with the `term` tag when their core content is a stable 1-3 sentence definition. Routing schemes, durable rules, data-shape descriptions, procedures, and design choices live inside the matching domain/entity/action Sections such as `spec`, `principle`, `decision`, `comparison`, or `warning`. `mdrive node list` and `mdrive query` expose a `node_class` (`domain`, `action`, `concrete_entity`, `term`) so glossary-style terms stay visible without flattening them into concrete services/systems.
84
115
 
85
116
  ## Commands
86
117
 
87
118
  | Command | Role | Notes |
88
119
  |---|---|---|
89
120
  | `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. |
121
+ | `context capture <url \| ./path.md [./more.md...] \| --stdin \| --inbox \| --refresh \| --code [path]>` | CLI | Ingest external documents or code into the source registry. 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. `--code` snapshots TypeScript packages/symbols/edges through the code aspect. For Agent interaction, run `context capture --code <path> --plan --format json` first, show only package name / module path / version, then capture with repeated `--module <path>`. After capture, continue with source ids and semantic handles, not storage paths. |
122
+ | `context extract <path>` | CLI | Read-only developer/debug print of an extraction; never writes workspace files and is not part of the production Agent workflow. |
123
+ | `context debug <workflow\|source\|workspace\|storage\|command\|snapshot> ...` | CLI | Developer/debug-only path diagnostics. Output is storage-coupled and not a production Agent workflow input. |
124
+ | `context align --scan \| --finalize - --digest <segments-digest>` | CLI | Workflow helpers driven by the `/context:align` skill pipeline. `--scan` returns workflow payload names, scopes, digests, and `generation_policy` when workspace language is configured; agents inspect compact payload views with `context workflow show --view ... --unwrap` and semantic filters. `--unwrap` only removes the workflow metadata envelope; it does not change summary/detail behavior. Finalize by submitting an `align-structure-decision` document through stdin with the matching segments digest. `--schema <name>` prints the exact align workflow input schemas. |
125
+ | `context compile --context <slug> --format json \| --node-cycle <slug> --input - --accept-safe-defaults \| --draft <slug> --input - --plan --prepare \| --close` | CLI | Workflow helpers driven by the `/context:compile` skill pipeline. The context entrypoint prepares durable NodeContext, generation policy, and coverage workflow payloads, then prints semantic payload handles; agents read citation handles through compact `workflow show` views. `--node-cycle` is the low-friction per-node path: it validates the submitted draft, prepares reconcile, accepts mechanically safe defaults, and applies only when no semantic judgment remains. Manual `--draft --prepare → reconcile review/apply` remains the fallback for questions and unsupported evidence. Normal handoff uses stdin plus workflow payload digests; `--save-input` is only an explicit debug scratch copy, not workspace truth. |
126
+ | `context mdrive <group> <verb>` | CLI | Knowledge primitive shell: node / section / edge / query / verify / glossary / workspace. Node/query results include `node_class` to distinguish concrete entities from term definitions. `context mdrive verify workspace --experimental` adds heuristic quality warnings for very thin concrete entities and terms that have grown beyond definition shape; these are warnings, not entity-count limits. `context mdrive query --stats-only` prints only workspace counts; run `context mdrive --help` for subcommands. |
127
+ | `context drop <source-id\|url> --plan [--save-output [file]]` / `context drop --apply-plan --reason <text> --yes` | CLI | Plans and applies source retraction through the current drop workflow. `drop --plan` stores the canonical `drop-plan` workflow payload and returns a digest; `--save-output` is only an optional human-readable scratch copy, not a later input. `reconcile prepare --mode drop` reads the current workflow plan, `reconcile review --prepare-digest <digest>` stores the ready review when semantic decisions are needed, and `drop --apply-plan` consumes the current workflow plan/review without plan or decisions files. |
98
128
  | `context purge [--yes]` | CLI | Permanently deletes every archive under `archive/` after a summary + confirmation; active `raw/` and `knowledge/` are not modified. |
99
129
  | `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). |
130
+ | `context doctor` | CLI | Workspace diagnostics for current workflow, align output, knowledge, caches, evidence, coverage, semantic ledger, and archive state. |
101
131
  | `context status [--format json\|table]` | CLI | Workspace overview + next-action suggestions. |
102
132
  | `/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
133
  | `/context:context <free text>` | Agent | Fuzzy router over the above. |
@@ -115,7 +145,14 @@ bun run --filter @c4a/context-cli typecheck
115
145
  bun run --filter @c4a/context-cli lint
116
146
  ```
117
147
 
118
- The build chains `scripts/build-plugin.ts`, which reads the Claude and Codex plugin manifest templates and substitutes `__VERSION__` from `package.json`.
148
+ The build chains `scripts/build-plugin.ts`, which reads the human-maintained `plugin/` source and generates self-contained install trees into the nested `c4a-plugins/` directory at the c4a repo root. That directory is an independent git repo (remote: [`context4ai/context`](https://github.com/context4ai/context)) and is `.gitignore`d by c4a. Before running `build:plugin` locally for the first time, clone it:
149
+
150
+ ```bash
151
+ cd /path/to/c4a
152
+ git clone https://github.com/context4ai/context.git c4a-plugins
153
+ ```
154
+
155
+ Plugin marketplace releases are pushed from `c4a-plugins/`, separate from the npm tarball that `@c4a/context-cli` publishes. Do not edit generated build trees directly.
119
156
 
120
157
  ## License
121
158