@c4a/context-cli 0.6.0-beta.7 → 0.6.1-beta.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 (104) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +130 -132
  3. package/README.zh-CN.md +158 -0
  4. package/cli.js +14978 -15477
  5. package/package.json +18 -3
  6. package/plugins/README.md +8 -0
  7. package/plugins/README_CN.md +6 -0
  8. package/plugins/VERSION +1 -1
  9. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  10. package/plugins/claude/skills/skill-continue-workflow/SKILL.md +39 -3
  11. package/plugins/claude/skills/skill-package-output/SKILL.md +16 -3
  12. package/plugins/claude/skills/skill-prose-align/SKILL.md +26 -31
  13. package/plugins/claude/skills/skill-prose-align/references/internal-procedures/structure-planning/references/gates.md +6 -12
  14. package/plugins/claude/skills/skill-prose-align/references/internal-procedures/structure-planning.md +16 -10
  15. package/plugins/claude/skills/skill-prose-compile/SKILL.md +26 -27
  16. package/plugins/claude/skills/skill-review-gate/SKILL.md +17 -6
  17. package/plugins/claude/skills/skill-source-scope/SKILL.md +10 -9
  18. package/plugins/codex/.codex-plugin/plugin.json +2 -2
  19. package/plugins/codex/skills/continue/references/internal-procedures/skill-continue-workflow.md +39 -3
  20. package/plugins/codex/skills/continue/references/internal-procedures/skill-package-output.md +16 -3
  21. package/plugins/codex/skills/continue/references/internal-procedures/skill-prose-align/references/internal-procedures/structure-planning/references/gates.md +6 -12
  22. package/plugins/codex/skills/continue/references/internal-procedures/skill-prose-align/references/internal-procedures/structure-planning.md +16 -10
  23. package/plugins/codex/skills/continue/references/internal-procedures/skill-prose-align.md +26 -31
  24. package/plugins/codex/skills/continue/references/internal-procedures/skill-prose-compile.md +26 -27
  25. package/plugins/codex/skills/continue/references/internal-procedures/skill-review-gate.md +17 -6
  26. package/plugins/codex/skills/continue/references/internal-procedures/skill-source-scope.md +10 -9
  27. package/plugins/codex/skills/init/references/internal-procedures/skill-continue-workflow.md +39 -3
  28. package/plugins/codex/skills/init/references/internal-procedures/skill-package-output.md +16 -3
  29. package/plugins/codex/skills/init/references/internal-procedures/skill-prose-align/references/internal-procedures/structure-planning/references/gates.md +6 -12
  30. package/plugins/codex/skills/init/references/internal-procedures/skill-prose-align/references/internal-procedures/structure-planning.md +16 -10
  31. package/plugins/codex/skills/init/references/internal-procedures/skill-prose-align.md +26 -31
  32. package/plugins/codex/skills/init/references/internal-procedures/skill-prose-compile.md +26 -27
  33. package/plugins/codex/skills/init/references/internal-procedures/skill-review-gate.md +17 -6
  34. package/plugins/codex/skills/init/references/internal-procedures/skill-source-scope.md +10 -9
  35. package/plugins/cursor/.cursor-plugin/plugin.json +1 -1
  36. package/plugins/cursor/skills/skill-continue-workflow/SKILL.md +39 -3
  37. package/plugins/cursor/skills/skill-package-output/SKILL.md +16 -3
  38. package/plugins/cursor/skills/skill-prose-align/SKILL.md +26 -31
  39. package/plugins/cursor/skills/skill-prose-align/references/internal-procedures/structure-planning/references/gates.md +6 -12
  40. package/plugins/cursor/skills/skill-prose-align/references/internal-procedures/structure-planning.md +16 -10
  41. package/plugins/cursor/skills/skill-prose-compile/SKILL.md +26 -27
  42. package/plugins/cursor/skills/skill-review-gate/SKILL.md +17 -6
  43. package/plugins/cursor/skills/skill-source-scope/SKILL.md +10 -9
  44. package/plugins/skills/context-continue/references/internal-procedures/skill-continue-workflow.md +39 -3
  45. package/plugins/skills/context-continue/references/internal-procedures/skill-package-output.md +16 -3
  46. package/plugins/skills/context-continue/references/internal-procedures/skill-prose-align/references/internal-procedures/structure-planning/references/gates.md +6 -12
  47. package/plugins/skills/context-continue/references/internal-procedures/skill-prose-align/references/internal-procedures/structure-planning.md +16 -10
  48. package/plugins/skills/context-continue/references/internal-procedures/skill-prose-align.md +26 -31
  49. package/plugins/skills/context-continue/references/internal-procedures/skill-prose-compile.md +26 -27
  50. package/plugins/skills/context-continue/references/internal-procedures/skill-review-gate.md +17 -6
  51. package/plugins/skills/context-continue/references/internal-procedures/skill-source-scope.md +10 -9
  52. package/plugins/skills/context-init/references/internal-procedures/skill-continue-workflow.md +39 -3
  53. package/plugins/skills/context-init/references/internal-procedures/skill-package-output.md +16 -3
  54. package/plugins/skills/context-init/references/internal-procedures/skill-prose-align/references/internal-procedures/structure-planning/references/gates.md +6 -12
  55. package/plugins/skills/context-init/references/internal-procedures/skill-prose-align/references/internal-procedures/structure-planning.md +16 -10
  56. package/plugins/skills/context-init/references/internal-procedures/skill-prose-align.md +26 -31
  57. package/plugins/skills/context-init/references/internal-procedures/skill-prose-compile.md +26 -27
  58. package/plugins/skills/context-init/references/internal-procedures/skill-review-gate.md +17 -6
  59. package/plugins/skills/context-init/references/internal-procedures/skill-source-scope.md +10 -9
  60. package/plugin/.claude-plugin/plugin.json.template +0 -16
  61. package/plugin/.codex-plugin/plugin.json.template +0 -38
  62. package/plugin/.cursor-plugin/plugin.json.template +0 -29
  63. package/plugin/README.md +0 -150
  64. package/plugin/README_CN.md +0 -136
  65. package/plugin/assets/icon.svg +0 -3
  66. package/plugin/assets/logo.svg +0 -3
  67. package/plugin/assets/workflow-en.png +0 -0
  68. package/plugin/assets/workflow.png +0 -0
  69. package/plugin/commands/continue.md +0 -34
  70. package/plugin/commands/init.md +0 -21
  71. package/plugin/skills/skill-continue-workflow/SKILL.md +0 -199
  72. package/plugin/skills/skill-init-workspace/SKILL.md +0 -74
  73. package/plugin/skills/skill-package-output/SKILL.md +0 -167
  74. package/plugin/skills/skill-prose-align/SKILL.md +0 -327
  75. package/plugin/skills/skill-prose-align/references/internal-procedures/structure-planning/references/candidate-resolution.md +0 -91
  76. package/plugin/skills/skill-prose-align/references/internal-procedures/structure-planning/references/density-profile.md +0 -30
  77. package/plugin/skills/skill-prose-align/references/internal-procedures/structure-planning/references/gates.md +0 -269
  78. package/plugin/skills/skill-prose-align/references/internal-procedures/structure-planning.md +0 -276
  79. package/plugin/skills/skill-prose-compile/SKILL.md +0 -288
  80. package/plugin/skills/skill-prose-compile/references/internal-procedures/close-gate.md +0 -132
  81. package/plugin/skills/skill-prose-compile/references/internal-procedures/compile-actions/references/action-domain-gates.md +0 -52
  82. package/plugin/skills/skill-prose-compile/references/internal-procedures/compile-actions/references/notes.md +0 -48
  83. package/plugin/skills/skill-prose-compile/references/internal-procedures/compile-actions/references/refresh-and-update.md +0 -85
  84. package/plugin/skills/skill-prose-compile/references/internal-procedures/compile-actions/references/structural-challenges.md +0 -73
  85. package/plugin/skills/skill-prose-compile/references/internal-procedures/compile-actions.md +0 -413
  86. package/plugin/skills/skill-prose-compile/references/internal-procedures/compile-judgment.md +0 -123
  87. package/plugin/skills/skill-prose-compile/references/internal-procedures/semantic-judgment/references/disposition-semantics.md +0 -81
  88. package/plugin/skills/skill-prose-compile/references/internal-procedures/semantic-judgment/references/leakage-and-ownership.md +0 -55
  89. package/plugin/skills/skill-prose-compile/references/internal-procedures/semantic-judgment/references/scope-review-and-omit.md +0 -93
  90. package/plugin/skills/skill-prose-compile/references/internal-procedures/semantic-judgment/references/temporal-and-evidence.md +0 -79
  91. package/plugin/skills/skill-prose-compile/references/internal-procedures/semantic-judgment/references/user-confirmation.md +0 -111
  92. package/plugin/skills/skill-prose-compile/references/internal-procedures/semantic-judgment.md +0 -194
  93. package/plugin/skills/skill-review-gate/SKILL.md +0 -127
  94. package/plugin/skills/skill-source-scope/SKILL.md +0 -524
  95. package/plugin/skills/skill-source-scope/references/capture-source.md +0 -201
  96. package/plugins/assets/icon.svg +0 -3
  97. package/plugins/assets/workflow-en.png +0 -0
  98. package/plugins/assets/workflow.png +0 -0
  99. package/plugins/codex/assets/workflow-en.png +0 -0
  100. package/plugins/codex/assets/workflow.png +0 -0
  101. package/plugins/cursor/assets/icon.svg +0 -3
  102. package/plugins/cursor/assets/workflow-en.png +0 -0
  103. package/plugins/cursor/assets/workflow.png +0 -0
  104. package/scripts/build-plugin.ts +0 -658
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 context4ai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,48 +1,64 @@
1
- # @c4a/context-cli
1
+ # Context CLI
2
2
 
3
- Local knowledge workspace CLI for Context projects.
3
+ [简体中文](./README.zh-CN.md)
4
4
 
5
- `@c4a/context-cli` is the **CLI** package the `context` executable plus global agent plugin installer. The V1 workflow uses a globally installed CLI/plugin for agent commands, while each knowledge workspace keeps only project state and SDK dependency metadata.
5
+ `@c4a/context-cli` provides the **Context CLI** and the global Agent plugin
6
+ installer. The CLI manages project-local workspace state; the Agent plugin
7
+ explains that state, asks for user decisions, and edits project configuration.
6
8
 
7
- This package ships:
9
+ The CLI is Node/Bun compatible and does not call an LLM. Mechanical work belongs
10
+ to the CLI, semantic judgment belongs to the Agent, and important decisions
11
+ belong to the user.
8
12
 
9
- 1. **`context` CLI** — a Node/Bun-compatible executable that manages project-local context workspaces, repo sources, extraction, review, package build, verify, and status guidance.
10
- 2. **Global plugin installer** — `context plugin install` installs and refreshes the package-bundled plugin marketplace globally for Claude and Codex. It materializes the Codex plugin copy under `~/.codex/plugins/cache/c4a/context/local/`. The public plugin entrypoints are `init` and `continue`; `continue` is agent guidance, not a CLI primitive.
11
- 3. **`plugin/` source** — human-maintained command/skill/manifest sources that `scripts/build-plugin.ts` compiles into installable marketplace trees.
13
+ ## Install
12
14
 
13
- The split follows a simple rule: mechanical work is the CLI's job; synthesis work is the agent's job. The CLI never calls an LLM. Naming surfaces are deliberately separate: `/context:init` and `/context:continue` are Claude slash commands, Cursor exposes prefixed entries such as `/context-init` / `/context-continue`, `Context: ...` / `context-*` is a public skill entry for skill-only agents, and `context ...` is the CLI primitive. There is no `context continue` CLI command.
15
+ ```bash
16
+ npm install -g @c4a/context-cli
17
+ context plugin install
18
+ ```
14
19
 
15
- Agent-facing dialogue follows the user's current conversation language. CLI
16
- commands, flags, ids, status values, JSONL keys, and `source_ref` tokens remain
17
- stable protocol text and are not translated.
20
+ Global package installation also attempts a best-effort plugin refresh. Run
21
+ `context plugin install` again after installing or upgrading Claude or Codex,
22
+ then restart the Agent.
18
23
 
19
- ## Global Plugin + Project Workspace
24
+ The public Agent entries are:
20
25
 
21
- ```bash
22
- # Install the CLI and refresh available global agent commands/skills.
23
- npm install -g @c4a/context-cli
26
+ - `/context:init` creates a project-local Context workspace.
27
+ - `/context:continue` reads the current workspace state and continues from the
28
+ next action.
24
29
 
25
- # Create a standalone context project.
26
- context init context
30
+ `/context:continue` is Agent guidance, not a CLI subcommand. There is no
31
+ `context continue` command.
32
+
33
+ For the shortest installed-package walkthrough, read
34
+ [CLI Quickstart](./docs/quickstart.md).
35
+
36
+ ## CLI And Agent Responsibilities
27
37
 
38
+ | Responsibility | Owner |
39
+ |---|---|
40
+ | Source registries, capture, extraction, review application, verify, and build | CLI |
41
+ | Explaining choices, editing `src/index.ts`, proposing structure, and generating candidates from evidence | Agent |
42
+ | Source permission, classification, review decisions, and package-output choice | User |
43
+
44
+ The Agent follows `context status` and CLI diagnostics rather than guessing the
45
+ next command. It may execute safe mechanical steps, but it stops at human gates
46
+ and external source-repository operations.
47
+
48
+ ## Create Or Continue A Workspace
49
+
50
+ ```bash
51
+ # Create a standalone workspace.
52
+ context init context
28
53
  cd context
29
54
  bun install
55
+
56
+ # Ask the Agent to continue from the current state.
30
57
  /context:continue
31
58
  ```
32
59
 
33
- Global installation runs `context plugin install` automatically for the
34
- available Claude and Codex CLIs. Plugin refresh is best-effort and does not
35
- make the CLI installation fail; rerun `context plugin install` manually after
36
- installing an agent CLI. Set `CONTEXT_CLI_SKIP_PLUGIN_INSTALL=1` to opt out.
37
-
38
- The global plugin calls `context ...` from the current project root.
39
- Agent commands follow CLI `next:` hints: they execute safe mechanical steps and
40
- stop at `Human gate:` / placeholder next steps, source registration, source scope
41
- selection, review, package output choice, or source-repo operations outside the
42
- CLI. Agents must not infer repo sources or extraction scope from the surrounding
43
- monorepo.
44
-
45
- After `bun install`, the workspace has an installed SDK manual:
60
+ The generated `AGENTS.md` is the Agent's project-local operating guide. After
61
+ dependency installation, SDK manuals are available at:
46
62
 
47
63
  ```text
48
64
  node_modules/@c4a/context/docs/README.md
@@ -51,134 +67,116 @@ node_modules/@c4a/context/docs/reference/project-api.md
51
67
  node_modules/@c4a/context/docs/reference/package-templates.md
52
68
  ```
53
69
 
54
- Template examples ship at:
55
-
56
- ```text
57
- node_modules/@c4a/context/templates/package-templates/
58
- ```
70
+ The workspace state is split across:
59
71
 
60
- Agents should read these files instead of probing `node_modules/@c4a/context/dist`
61
- with temporary scripts.
72
+ - `src/` for project declarations and package templates.
73
+ - `sources/` for source registries and captured evidence.
74
+ - `unapproved/` for draft, rejected, or deprecated candidates.
75
+ - `knowledge/` for approved knowledge.
76
+ - `dist/` for generated package output.
77
+ - `.tmp/context-runtime/` for ignored logs, previews, reports, locks, and caches.
62
78
 
63
- For the complete source, link, plugin, and npm-mode development workflow, see
64
- the workspace [DEVELOPMENT.md](../../DEVELOPMENT.md). CLI plugin-specific notes
65
- remain in this package's [DEVELOPMENT.md](./DEVELOPMENT.md).
79
+ Do not repair lifecycle state by manually deleting or rewriting these
80
+ directories. Use the command or next action returned by the CLI.
66
81
 
67
- ## Project-local quick tour
82
+ ## Status-Driven Workflow
68
83
 
69
- ```bash
70
- # Create a standalone context project.
71
- bunx @c4a/context-cli init context
72
- cd context
73
- bun install
84
+ The project workflow is declared in `src/index.ts` and routed by
85
+ `context status`:
74
86
 
75
- # Or initialize the current directory as the project root.
76
- bunx @c4a/context-cli init . --name my-product-context
77
- bun install
87
+ | Stage | CLI surface |
88
+ |---|---|
89
+ | Source setup | `context source add repo/file/lark`, `context source add batch`, and `context source ensure` |
90
+ | Document capture | Declared capture phases through `context run <phase-id>` |
91
+ | Code extraction | Declared `extractTs` phases through `context run <phase-id>` |
92
+ | Prose structure | `context run align:<type>:<source>:<collection> ...` evidence and validation views |
93
+ | Prose compile | `context run compile:<type>:<source>:<collection> ...` evidence and validation views |
94
+ | Review | `context review html`, scoped decisions, and `context review apply` |
95
+ | Close and quality | `context close` and `context verify` |
96
+ | Package output | `context build` |
78
97
 
79
- # Register a local repo source when the agent-guided next step asks for it.
80
- # The ref should be a pinned commit SHA.
81
- context source add repo sample-lib --local ../sample-lib
98
+ Building a package completes the currently active approved state; it does not
99
+ freeze the workspace. New sources can be added and processed later.
82
100
 
83
- # In a monorepo, register the chosen package/subdirectory as the source.
84
- # Do not register the parent monorepo and use extractTs.include as a package selector.
85
- context source add repo sample-lib --local ../packages/sample-lib
101
+ ## Command Groups
86
102
 
87
- # Keep non-standard TypeScript entry roots in the Context project src/index.ts.
88
- # Do not add package.json entry fields or source files solely for Context.
89
- # extractTs({ source, collection: "codegraph", include: ["src/**/*.ts"], entries: ["src/api.ts"] })
90
- # Use mode: "scan" instead when every include-matched file is a scan root.
103
+ ```bash
104
+ # Plugin installation and diagnostics
105
+ context plugin install
106
+ context plugin status
91
107
 
92
- # Optional overrides when origin / HEAD cannot be inferred:
93
- context source add repo sample-lib \
94
- --local ../sample-lib \
95
- --remote https://git.example.com/sample-lib.git \
96
- --ref <commit-sha>
108
+ # Workspace state
109
+ context init [project-dir]
110
+ context status
97
111
 
98
- # Check source readiness. The CLI reports diagnostics and hints only;
99
- # it does not clone, checkout, reset, or otherwise mutate the source repo.
100
- context source ensure
112
+ # Sources
113
+ context source add repo [YYYYMMDD] --module <module> --local <repo-or-subdir>
114
+ context source add file [YYYYMMDD] --module <module> --local <file-or-folder>
115
+ context source add lark [YYYYMMDD] --module <module> --url <lark-url>
116
+ context source add batch [YYYYMMDD] --input <yaml-or-json>
117
+ context source ensure [source]
118
+ context source inspect [source]
101
119
 
102
- # Inspect declared phases and let status suggest the next step.
103
- context status
120
+ # Declared phases and review
104
121
  context run --list
105
- context run extract:sample-lib:codegraph --dry-run
122
+ context run <phase-id> --dry-run
123
+ context run <phase-id>
124
+ context review html [collection] --open
125
+ context review apply <payload-file>
126
+
127
+ # Final quality and output
128
+ context close
129
+ context verify
130
+ context build
106
131
  ```
107
132
 
108
- The current project-local protocol uses `src/index.ts`, `sources/`, `unapproved/`, `knowledge/`,
109
- `README.md`, `AGENTS.md`, and `package.json`. `dist/` contains generated package
110
- outputs and is rebuilt from approved knowledge and templates.
111
- Runtime scratch lives under `.tmp/context-runtime/` and is ignored. It may contain run logs, review HTML, previews, locks, and cache files; it is not the committed state source. Committed state is the combination of source registries and document snapshots under `sources/`, `unapproved/entities.jsonl`, approved Markdown under `knowledge/`, project code under `src/`, and project guidance in `README.md` / `AGENTS.md`.
133
+ Run `context <command> --help` for current flags. Commands that require a
134
+ workspace search upward for a `package.json` with `context.project=true` and a
135
+ configured `context.entry`.
112
136
 
113
- ## Current Workflow Model
137
+ ## Human Gates And Evidence
114
138
 
115
- The project-local workflow is status-driven. Register sources, declare phases in
116
- `src/index.ts`, then let `context status` and phase views route each gate:
139
+ - The CLI never silently clones, checks out, resets, fetches, installs, builds,
140
+ or runs scripts in a source repository.
141
+ - Source registration and source-body reading are separate permissions.
142
+ - Extraction scope and document classification are confirmed before candidate
143
+ writes.
144
+ - Review decisions come from the user. The Agent must not invent approval or
145
+ rejection payloads.
146
+ - Package output is chosen after approved knowledge exists; package templates
147
+ are project configuration, not a second factual source.
117
148
 
118
- | Gate | Current surface |
119
- |---|---|
120
- | Source setup | `context source add repo/file/lark`, `context source ensure`, and project source declarations. |
121
- | Document capture | Declared `capture:file:<source>` / `capture:lark:<source>` phases through `context run` after the source read gate. |
122
- | Prose structure | `alignProse` phases through `context run align:<type>:<source>:<collection> --view/--validate/--stage`, producing confirmed `unapproved/structure.yaml`. |
123
- | Source-bound prose compile | `compileProse` phases through `context run compile:<type>:<source>:<collection> --view/--validate/--stage`, producing review candidates from confirmed structure. |
124
- | Review/apply | `context review html` and `context review apply` own approval, rejection, scoped quick decisions, and source-mirrored approved Markdown materialization. |
125
- | Close/verify/build | `context close`, `context verify`, `context build`, package templates, OKF indexes, and generated `knowledge-query` skills own final package readiness. |
126
-
127
- Do not simulate lifecycle or retraction work by deleting files under `sources/`,
128
- `knowledge/`, `unapproved/`, `dist/`, or `.tmp`. Status and plugin guidance must
129
- route users back to the gate that owns the fix.
130
-
131
- ## Agent Contract
132
-
133
- For project workflows, `context` is a semantic service. Agents should call the CLI and use returned source names, phase ids, candidate ids, package names, diagnostics, and `source_ref` values. They should not derive state by walking runtime cache directories.
134
-
135
- `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 source locations for inspection, but those values are not production workflow inputs.
136
-
137
- ## Commands
138
-
139
- | Command | Role | Notes |
140
- |---|---|---|
141
- | `context plugin path` | CLI | Print the bundled plugin marketplace root. Installed packages normally use `dist/plugins`; source checkouts use the same path after build. |
142
- | `context plugin install [--agent claude\|codex\|all] [--dry-run]` | CLI | Install or refresh the bundled plugin marketplace globally for Claude and/or Codex. It replaces existing `context` marketplace entries and Codex cache owned by this package before reinstalling. |
143
- | `context plugin status [--agent claude\|codex\|all]` | CLI | Inspect bundled plugin path and agent CLI availability. |
144
- | `context init [project-dir] [--name <name>] [--dev]` | CLI | Create a project-local context workspace. Defaults to `context/`; use `.` to initialize the current directory. Use `--dev` for local checkout testing before `@c4a/context` is published. |
145
- | `context source add repo <name> --local <repo-or-subdir> [--remote <url>] [--ref <sha>]` | CLI | Register a repo source and pin it to a commit. Local paths may point at a monorepo subdirectory; the CLI stores the git root plus subpath, and materializes the source view to the subdirectory. Remote and ref are inferred from local origin / HEAD when omitted. Short SHAs are resolved to full commits when the local repo is available. |
146
- | `context source ensure [name]` | CLI | Validate and materialize local source symlinks. Missing remotes only produce hints; the CLI does not clone or checkout automatically. |
147
- | `context source add batch [date] --input <file|->` | CLI | Register multiple repo, file, or Lark modules under one project write lock from YAML/JSON input. Repo modules are explicit; file/Lark modules may be derived when omitted. |
148
- | `context source list|get <name>` | CLI | Inspect the repo source registry and readiness metadata. |
149
- | `context source inspect [name]` | CLI | Detect module/package boundaries in registered repo sources without extraction. Use this before extracting monorepo roots; it prints package names, paths, versions when available, and suggested source registration commands. |
150
- | `context run --list` | CLI | List phases declared by `src/index.ts`. |
151
- | `context run <phase-id> [--dry-run] [--auto-promote]` | CLI | Inspect or run one declared phase. Extract dry-run separates discovered, AST-analyzed, skipped, symbol, and relation counts. Missing/empty entries fail with `NO_ENTRY_DETECTED`; TypeScript aliases come from tsconfig/jsconfig `baseUrl` and `paths`. Codegraph defaults to first-run full Review and later delta-only Review; `--auto-promote` applies deterministic codegraph deltas, refreshes deterministic close when needed, then verifies. Existing package outputs become stale and remain an explicit downstream build step. |
152
- | `context review html [collection] [--open]` | CLI | Render the local self-contained HTML review surface under `.tmp/context-runtime/review/`, emit a clickable `file://` URL, and optionally open it with the system browser. |
153
- | `context review list [collection]` | CLI | List draft candidates for CLI-oriented review. |
154
- | `context review apply <payload-file>` | CLI | Apply copied review decisions; approved entities materialize to `knowledge/`, rejected entities remain in `unapproved/entities.jsonl`. |
155
- | `context review approve|reject <candidate-id> --collection <collection>` / `--all` | CLI | Scoped quick marking for a single draft candidate when the user explicitly authorizes an automated or quick path. |
156
- | `context review migrate-codegraph-refs` | CLI | Upgrade legacy approved codegraph refs to `src-N#symbol:<file>:<symbol>:<kind>@<digest>`, remove redundant `code_origin`, and verify. Rerun declared codegraph extraction first; this metadata migration does not repeat Review. |
157
- | `context build` | CLI | Build declared project packages from approved knowledge into `dist/<package-name>/`. |
158
- | `context verify [--format table\|json]` | CLI | Validate the project skeleton, registry, unapproved ledger, approved Markdown, source refs, and package outputs. |
159
- | `context status [--format json\|table]` | CLI | Workspace overview + a canonical `next:` hint. Agent plugins expose this workflow as `/context:continue`; do not add or call `context continue`. |
160
-
161
- Commands that require a project exit with a workspace-not-found error if run outside a directory tree containing a `package.json` `context.project=true` / `context.entry` marker. `context init` is the command that creates one.
162
-
163
- For a beta.5 project that reports `approved-source-ref-ambiguous`, upgrade in
164
- this order: rerun each declared codegraph extraction phase to create the current
165
- file-aware symbol index, run `context review migrate-codegraph-refs`, then run
166
- `context verify`. The migration preserves approved content and review decisions;
167
- it changes only code evidence identity and removes the old `code_origin` copy.
149
+ CLI-returned source names, phase IDs, candidate IDs, diagnostics, and
150
+ `source_ref` values are workflow tokens. A `source_ref` is an opaque evidence
151
+ citation: copy it exactly and do not parse it as a filesystem path.
152
+
153
+ ## Further Reading
154
+
155
+ - [CLI Quickstart](./docs/quickstart.md)
156
+ - [SDK documentation index](../context/docs/README.md)
157
+ - [Getting Started](../context/docs/getting-started.md)
158
+ - [Agent Guide](../context/docs/guides/agent-guide.md)
159
+ - [Agent Dialogue](../context/docs/guides/agent-dialogue.md)
160
+ - [Project API](../context/docs/reference/project-api.md)
161
+ - [Package Templates](../context/docs/reference/package-templates.md)
168
162
 
169
163
  ## Development
170
164
 
171
- Source lives at [`packages/context-cli/`](./src) in this workspace.
165
+ For the complete source, link, plugin, and npm-mode workflow, see
166
+ [`DEVELOPMENT.md`](../../DEVELOPMENT.md) and this package's
167
+ [`DEVELOPMENT.md`](./DEVELOPMENT.md).
172
168
 
173
169
  ```bash
174
- ./start.sh link # local checkout: build CLI, link global context, register SDK for init --dev
175
- bun run --filter @c4a/context-cli build # bundle CLI + render dist/plugins
176
- bun run --filter @c4a/context-cli test # unit + integration tests
170
+ ./start.sh link
171
+ bun run --filter @c4a/context-cli build
177
172
  bun run --filter @c4a/context-cli typecheck
178
173
  bun run --filter @c4a/context-cli lint
174
+ bun run --filter @c4a/context-cli test
179
175
  ```
180
176
 
181
- The package build writes installable plugin trees to `dist/plugins`, which is shipped in the npm tarball. `context plugin install` resolves that package-bundled path at runtime and installs it globally for Claude / Codex. For Codex, the installer also copies `dist/plugins/codex` into `~/.codex/plugins/cache/c4a/context/local/`, matching Codex's local-plugin cache convention. Do not edit generated build trees directly.
177
+ Build writes the installable Claude, Codex, Cursor, and skill-only trees to
178
+ `dist/plugins`. `context plugin install` installs from that package-bundled
179
+ output. Do not edit generated plugin trees directly.
182
180
 
183
181
  ## License
184
182
 
@@ -0,0 +1,158 @@
1
+ # Context CLI
2
+
3
+ [English](./README.md)
4
+
5
+ `@c4a/context-cli` 提供 **Context CLI** 和全局 Agent 插件安装能力。CLI 负责管理本地知识工作区的状态,Agent 插件负责解释状态、询问用户决策并修改项目配置。
6
+
7
+ CLI 同时兼容 Node 和 Bun,本身不会调用 LLM。机械操作交给 CLI,语义判断交给 Agent,重要决策交给用户。
8
+
9
+ ## 安装
10
+
11
+ ```bash
12
+ npm install -g @c4a/context-cli
13
+ context plugin install
14
+ ```
15
+
16
+ 全局安装 npm 包时也会尝试刷新插件,但不会因为插件安装失败而阻塞 CLI 安装。安装或升级 Claude、Codex 后,可以再次执行 `context plugin install`,然后重启 Agent。
17
+
18
+ 面向用户的 Agent 入口是:
19
+
20
+ - `/context:init`:创建一个本地 Context workspace。
21
+ - `/context:continue`:读取已有工作区的状态,并从下一步继续。
22
+
23
+ `/context:continue` 是 Agent 工作指引,不是 CLI 子命令;不存在 `context continue` 命令。
24
+
25
+ 最简安装后流程参见 [CLI 快速开始](./docs/quickstart.md)。
26
+
27
+ ## CLI、Agent 和用户的分工
28
+
29
+ | 职责 | 负责方 |
30
+ |---|---|
31
+ | 来源登记、内容读取、代码提取、应用审核、验证和构建 | CLI |
32
+ | 解释选择、修改 `src/index.ts`、提出知识结构、基于证据生成候选 | Agent |
33
+ | 来源授权、知识分类、审核决定和打包方式 | 用户 |
34
+
35
+ Agent 会跟随 `context status` 和 CLI 返回的诊断,不会凭记忆猜下一条命令。安全的机械步骤可以自动执行,但遇到人工门禁和来源仓库外部操作时会停下来确认。
36
+
37
+ ## 创建或继续工作区
38
+
39
+ ```bash
40
+ # 创建独立工作区
41
+ context init context
42
+ cd context
43
+ bun install
44
+
45
+ # 让 Agent 从当前状态继续
46
+ /context:continue
47
+ ```
48
+
49
+ 初始化生成的 `AGENTS.md` 是 Agent 在当前项目中的操作指南。安装依赖后,SDK 手册位于:
50
+
51
+ ```text
52
+ node_modules/@c4a/context/docs/README.md
53
+ node_modules/@c4a/context/docs/guides/agent-guide.md
54
+ node_modules/@c4a/context/docs/reference/project-api.md
55
+ node_modules/@c4a/context/docs/reference/package-templates.md
56
+ ```
57
+
58
+ 工作区状态分布在:
59
+
60
+ - `src/`:项目声明和知识包模板。
61
+ - `sources/`:来源登记和已经读取的证据。
62
+ - `unapproved/`:草稿、拒绝或废弃的知识候选。
63
+ - `knowledge/`:审核通过的知识。
64
+ - `dist/`:构建生成的知识包。
65
+ - `.tmp/context-runtime/`:忽略的日志、预览、报告、锁和缓存。
66
+
67
+ 不要通过手动删除或改写这些目录来修复流程状态,应使用 CLI 返回的命令或下一步操作。
68
+
69
+ ## 状态驱动流程
70
+
71
+ 项目流程声明在 `src/index.ts` 中,由 `context status` 负责路由:
72
+
73
+ | 阶段 | CLI 入口 |
74
+ |---|---|
75
+ | 来源设置 | `context source add repo/file/lark`、`context source add batch`、`context source ensure` |
76
+ | 文档读取 | 通过 `context run <phase-id>` 执行声明好的 capture 阶段 |
77
+ | 代码提取 | 通过 `context run <phase-id>` 执行声明好的 `extractTs` 阶段 |
78
+ | 文档结构 | `context run align:<type>:<source>:<collection> ...` 的证据和校验视图 |
79
+ | 文档编译 | `context run compile:<type>:<source>:<collection> ...` 的证据和校验视图 |
80
+ | 人工审核 | `context review html`、范围化决定和 `context review apply` |
81
+ | 收口与质量 | `context close`、`context verify` |
82
+ | 知识包输出 | `context build` |
83
+
84
+ 一次构建只完成当前已经确认的知识状态,并不会冻结工作区。后续还可以继续添加和处理新的来源。
85
+
86
+ ## 命令分组
87
+
88
+ ```bash
89
+ # 插件安装与诊断
90
+ context plugin install
91
+ context plugin status
92
+
93
+ # 工作区状态
94
+ context init [project-dir]
95
+ context status
96
+
97
+ # 知识来源
98
+ context source add repo [YYYYMMDD] --module <module> --local <repo-or-subdir>
99
+ context source add file [YYYYMMDD] --module <module> --local <file-or-folder>
100
+ context source add lark [YYYYMMDD] --module <module> --url <lark-url>
101
+ context source add batch [YYYYMMDD] --input <yaml-or-json>
102
+ context source ensure [source]
103
+ context source inspect [source]
104
+
105
+ # 声明阶段与审核
106
+ context run --list
107
+ context run <phase-id> --dry-run
108
+ context run <phase-id>
109
+ context review html [collection] --open
110
+ context review apply <payload-file>
111
+
112
+ # 最终质量与输出
113
+ context close
114
+ context verify
115
+ context build
116
+ ```
117
+
118
+ 当前参数以 `context <command> --help` 为准。需要工作区的命令会向上查找带有 `context.project=true` 和 `context.entry` 配置的 `package.json`。
119
+
120
+ ## 人工门禁与证据
121
+
122
+ - CLI 不会悄悄在来源仓库中执行 clone、checkout、reset、fetch、install、build 或脚本。
123
+ - 登记来源和读取来源正文是两次独立授权。
124
+ - 写入知识候选前,需要确认代码提取范围和文档分类。
125
+ - 审核决定来自用户,Agent 不能自行编造批准或拒绝结果。
126
+ - 正式知识准备好后再选择打包方式;知识包模板是项目配置,不是第二份事实来源。
127
+
128
+ CLI 返回的来源名称、阶段 ID、候选 ID、诊断和 `source_ref` 都是流程标识。`source_ref` 是不可拆解的证据引用,应原样复制,不能把它当作文件路径解析。
129
+
130
+ ## 继续阅读
131
+
132
+ - [CLI 快速开始](./docs/quickstart.md)
133
+ - [SDK 文档索引](../context/docs/README.md)
134
+ - [快速开始](../context/docs/getting-started.md)
135
+ - [Agent 指南](../context/docs/guides/agent-guide.md)
136
+ - [Agent 对话指南](../context/docs/guides/agent-dialogue.md)
137
+ - [项目 API](../context/docs/reference/project-api.md)
138
+ - [知识包模板](../context/docs/reference/package-templates.md)
139
+
140
+ ## 开发
141
+
142
+ 完整的源码、链接、插件和 npm 产物流程参见
143
+ [`DEVELOPMENT.md`](../../DEVELOPMENT.md) 和当前包的
144
+ [`DEVELOPMENT.md`](./DEVELOPMENT.md)。
145
+
146
+ ```bash
147
+ ./start.sh link
148
+ bun run --filter @c4a/context-cli build
149
+ bun run --filter @c4a/context-cli typecheck
150
+ bun run --filter @c4a/context-cli lint
151
+ bun run --filter @c4a/context-cli test
152
+ ```
153
+
154
+ 构建会把 Claude、Codex、Cursor 和纯 Skill 形态的插件写入 `dist/plugins`。`context plugin install` 从包内构建产物安装插件,不要直接修改生成目录。
155
+
156
+ ## License
157
+
158
+ MIT.