@c4a/context-cli 0.6.18 → 0.6.19

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 (46) hide show
  1. package/README.md +6 -2
  2. package/README.zh-CN.md +5 -2
  3. package/cli.js +8551 -5388
  4. package/docs/document-optimization.md +35 -11
  5. package/docs/document-optimization.zh-CN.md +29 -9
  6. package/package.json +2 -2
  7. package/plugins/VERSION +1 -1
  8. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  9. package/plugins/claude/commands/context.md +36 -6
  10. package/plugins/codex/.codex-plugin/plugin.json +2 -2
  11. package/plugins/codex/skills/context/SKILL.md +36 -6
  12. package/plugins/cursor/.cursor-plugin/plugin.json +1 -1
  13. package/plugins/cursor/commands/c4a-context.md +36 -6
  14. package/plugins/skills/c4a-context/SKILL.md +36 -6
  15. package/providers/context/actions/apply-code-index-guidance.yaml +5 -0
  16. package/providers/context/actions/maintain-evidence.yaml +1 -1
  17. package/providers/context/actions/migrate-codeindex.yaml +5 -0
  18. package/providers/context/actions/register-source-batch.yaml +1 -1
  19. package/providers/context/actions/restore-repository-sources.yaml +1 -1
  20. package/providers/context/codes.yaml +2 -0
  21. package/providers/context/graphs/workspace.yaml +32 -2
  22. package/providers/context/manifest.json +76 -58
  23. package/providers/context/provider.yaml +1 -1
  24. package/providers/context/resources/dialogue/code-extraction.md +12 -0
  25. package/providers/context/resources/dialogue/document-classification.md +1 -1
  26. package/providers/context/resources/dialogue/knowledge-review.md +7 -1
  27. package/providers/context/resources/dialogue/source-boundary.md +9 -1
  28. package/providers/context/resources/dialogue/workflow-mode-after-capture.md +11 -8
  29. package/providers/context/resources/dialogue/workflow-mode-after-creation.md +6 -4
  30. package/providers/context/resources/manuals/guides/lark-resources.md +7 -0
  31. package/providers/context/resources/manuals/guides/package-outputs.md +3 -3
  32. package/providers/context/resources/manuals/reference/code-extractors.md +5 -4
  33. package/providers/context/resources/manuals/reference/package-templates.md +18 -10
  34. package/providers/context/resources/manuals/reference/project-api.md +47 -22
  35. package/providers/context/resources/procedures/close-and-build.md +24 -9
  36. package/providers/context/resources/procedures/code-extraction.md +35 -11
  37. package/providers/context/resources/procedures/code-index-audit.md +53 -13
  38. package/providers/context/resources/procedures/document-capture.md +9 -0
  39. package/providers/context/resources/procedures/document-optimization.md +69 -21
  40. package/providers/context/resources/procedures/document-revision.md +11 -6
  41. package/providers/context/resources/procedures/knowledge-review.md +4 -1
  42. package/providers/context/resources/procedures/source-boundary.md +20 -8
  43. package/providers/context/resources/semantic/align/structure-planning.md +4 -4
  44. package/providers/context/resources/semantic/code-index/classification.md +8 -5
  45. package/providers/context/schemas/document-optimization-decisions.schema.json +29 -6
  46. package/providers/context/schemas/source-batch-input.schema.json +18 -3
@@ -4,40 +4,88 @@ kind: procedure
4
4
  mediaType: text/markdown
5
5
  ---
6
6
 
7
- # Document revisions
7
+ # Source-constrained editorial revisions
8
8
 
9
- This optional phase improves the presentation of approved file and document
10
- prose without mutating the approved page. It runs only when
9
+ This optional phase improves the publication value and readability of approved
10
+ file and document prose without mutating the approved page. It runs only when
11
11
  `package.json.context.documentOptimization` is true.
12
12
 
13
- Run the Route-selected plan command. Read every returned fragment in the
14
- current batch and write one decision for each fragment to the returned
15
- `payload_target`, using the Route input schema. Use `keep` when no safe local
16
- repair is needed. Use `replace` only for Markdown structure, spacing, obvious
17
- typographical errors, or link syntax. Preserve meaning, paragraph order,
18
- technical identifiers, URLs, code, and numbers. Do not summarize, expand,
19
- reorder, or invent facts.
13
+ Run the Route-selected plan command. Each fragment is one source-backed Context
14
+ Section and includes mechanical readability signals, allowed actions, exact
15
+ line ranges, and source identity. Read every returned Section and write one
16
+ decision for each fragment to the returned `payload_target`:
17
+
18
+ - `keep` when it is already useful and readable. If the fragment has any
19
+ mechanical signal, include a concrete `assessment` that explains why every
20
+ signal is a false positive or why changing the Section would reduce source
21
+ fidelity. Name every reported signal code in that assessment so the CLI can
22
+ verify complete coverage; do not use one generic assessment for a batch;
23
+ - `repair` for local typography, Markdown, spacing, or a descriptive link label
24
+ whose purpose is already stated in the same Section;
25
+ - `reshape` for source-preserving structural changes such as a wide table into
26
+ a short index plus detail entries, or a long paragraph into stable headings;
27
+ - `omit` only when the plan permits it and the selected reason matches a
28
+ mechanically identified non-knowledge Section.
29
+
30
+ An unanswered question set, empty placeholder, decision-free draft, duplicate,
31
+ or obsolete-only Section may be omitted. Questions with answers, limitations
32
+ with impact and action, and deprecations with a replacement remain knowledge.
33
+ Mechanical signals are review leads, not a complete readability verdict. Read
34
+ every fragment even when it has no signal. A mixture of false positives and
35
+ valid repair candidates does not justify keeping the whole batch unchanged.
36
+ Every actionable signal must end in a safe edit, an eligible omission, a
37
+ batched input request, or a Section-specific explanation that the signal is a
38
+ false positive or that the edit would damage source fidelity. Time, token or
39
+ compute cost, workload, batch size, deadline, and desire to finish sooner are
40
+ never valid reasons to keep, skip, defer, or reduce an optimization. Do not
41
+ default a batch to `keep` because it contains many fragments; finish the
42
+ complete current batch with the same quality standard as a single fragment.
43
+ Signals that recommend `request-input` identify ambiguous currency, ownership,
44
+ link purpose, or sensitive values. The plan returns all of them in
45
+ `input_requests`: ask one concise, batched question and wait before applying
46
+ the complete optimization payload. Do not convert a required input into
47
+ `keep` merely to avoid a pause. Preserve the exact destination of a volatile
48
+ URL and safely improve its descriptive label or surrounding layout when the
49
+ same Section already states its purpose; ask only for information that cannot
50
+ be recovered from the approved Section or its source evidence.
51
+
52
+ In fully managed operation, apply every safe `repair`, `reshape`, and eligible
53
+ `omit` autonomously and continue until the optimization status is current.
54
+ Managed authority removes routine review pauses, not quality work or genuine
55
+ missing-input boundaries. A large repair set is expected work, not a blocker.
56
+ If an `input_requests` batch remains after completing all independently safe
57
+ analysis, ask once for that batch and resume from the returned Route.
58
+
59
+ Keep all work inside the same source Section. Preserve link destinations,
60
+ images, code, commands, numbers, identifiers, conditions, and source markers
61
+ exactly. Do not introduce facts, infer an answer, or replace a complete
62
+ contract with a summary.
20
63
 
21
64
  After the complete payload is ready, execute the exact `next_action.command`
22
- returned by the plan. Context rejects stale, incomplete, duplicate, or
23
- semantically broad decisions. Unchanged fragments reuse their previous
24
- decision; changed fragments alone return to this phase.
65
+ returned by the plan. Context rejects stale, incomplete, duplicate,
66
+ cross-Section, protected-value, semantically broad, or unexplained signaled
67
+ `keep` decisions. The assessment is used only to audit the current decision and
68
+ is not stored in approved knowledge, revisions, or package output. Unchanged
69
+ Sections reuse their previous decision; changed Sections alone return to this
70
+ phase.
25
71
 
26
72
  Only pages with reader-visible changes are stored. A revision is a full
27
73
  Markdown sidecar beside its approved page: `knowledge/guides/setup.md` becomes
28
74
  `knowledge/guides/setup__revision.md`. Default knowledge discovery excludes the
29
75
  reserved suffix. The filename derives the base page; the revision stores only
30
- the base digest that cannot be derived. Unchanged fragments inside a revision
31
- are inferred. A page with no changes stores one derived negative cache key
32
- below `.tmp/context-runtime/document-optimization/`; replacement prose and
33
- fragment metadata are never duplicated there.
76
+ the base digest that cannot be derived. Unchanged Sections inside a full
77
+ revision are inferred. A page with no changes stores one derived negative cache
78
+ key below `.tmp/context-runtime/document-optimization/`; replacement prose and
79
+ Section metadata are never duplicated there. An omitted Section keeps its
80
+ lifecycle marker in the revision so its source identity remains auditable, but
81
+ its reader-visible body and all revision audit state are absent from `dist/`.
34
82
 
35
83
  For a later user-requested correction, use `context revise "<title or approved
36
84
  path>" --format json`. The resulting `route.document-revision.requested` owns
37
85
  target selection, revision editing, and validation; it also works when broad
38
86
  document optimization was not previously enabled. The compatibility entry
39
87
  `context optimize-docs revise` accepts the same selectors. Validation rejects
40
- lifecycle metadata changes, stale page baselines, unsafe token changes, broad
41
- rewrites, and invalid Markdown structure. A source change makes the revision a
42
- blocking conflict instead of silently applying it. Do not create fragment JSON
43
- files or another revision namespace.
88
+ lifecycle metadata changes, stale page baselines, protected-value changes,
89
+ cross-Section rewrites, unsupported omissions, and invalid Markdown structure.
90
+ A source change makes the revision a blocking conflict instead of silently
91
+ applying it. Do not create fragment JSON files or another revision namespace.
@@ -8,7 +8,10 @@ mediaType: text/markdown
8
8
 
9
9
  Use this procedure only for a correction explicitly requested by the user after
10
10
  an approved knowledge page already exists. The request selects one page; it
11
- does not authorize a broad rewrite or a change to source facts.
11
+ does not authorize a free rewrite or a change to source facts. It may repair or
12
+ reshape reader-visible content within one existing Context Section, and may
13
+ omit a complete Section only when the current source supports a documented
14
+ non-knowledge reason.
12
15
 
13
16
  1. Run the Route command `context optimize-docs revise-current --format json`.
14
17
  2. Read the complete approved page and its sibling `__revision.md` page named
@@ -16,12 +19,14 @@ does not authorize a broad rewrite or a change to source facts.
16
19
  could change a fact rather than formatting or wording.
17
20
  3. Edit only the returned revision page. Preserve its frontmatter identity,
18
21
  `context_revision` baseline, Context section boundaries, evidence markers,
19
- links, code, numbers, and unsupported details. Make the smallest change that
20
- satisfies the user's request. Never edit the approved base page for this
21
- operation.
22
+ link destinations, images, code, numbers, identifiers, and supported facts.
23
+ A wide table may become an index plus detail entries, and a source-backed
24
+ list may be reorganized, but facts cannot move across Section boundaries.
25
+ Never edit the approved base page for this operation.
22
26
  4. Run `context optimize-docs validate --format json`. If validation reports a
23
- stale baseline, unsafe replacement, or missing evidence, stop and report the
24
- exact finding instead of weakening the correction.
27
+ stale baseline, protected-value change, unsupported omission, broad rewrite,
28
+ or missing evidence, stop and report the exact finding instead of weakening
29
+ the correction.
25
30
  5. Continue from the returned `context status --format json` Route. A valid
26
31
  correction makes the package stale, so the normal build Route will offer
27
32
  compilation without requiring a second correction decision.
@@ -24,7 +24,9 @@ Without explicit session-managed authority:
24
24
 
25
25
  - open the report returned by the route;
26
26
  - let the user approve or reject candidates;
27
- - apply the exact returned decision payload.
27
+ - apply the exact returned decision payload; and
28
+ - retain the exact report reference and reviewed scope in this conversation for
29
+ the final completion summary.
28
30
 
29
31
  The ordinary Route also carries a revision-bound force-approval resolution
30
32
  Action as an escape path. Do not advertise it when first presenting Review.
@@ -38,3 +40,4 @@ conversation. It does not bypass source permission, validation, close, or
38
40
  verify.
39
41
 
40
42
  After apply, re-evaluate. Do not infer that close or package output is current.
43
+ Do not persist a duplicate review-report ledger in the workspace.
@@ -10,14 +10,26 @@ A source boundary is a user decision about which repositories, modules, or
10
10
  documents may become approved knowledge. It affects extraction scope,
11
11
  provenance, output paths, and freshness checks.
12
12
 
13
- Do not infer this boundary from the current directory, monorepo layout, package
14
- names, or Git remotes. Explain the decision in the user's language, obtain the
15
- specific paths or documents, then use the Context source schema and conditional
16
- registration command selected by the route. The command uses `--input -`; after
17
- the current conversation contains the required confirmation, send one YAML or
18
- JSON payload matching the selected schema to its standard input. Do not run the
19
- command before confirmation and do not replace it with a command remembered
20
- from another route.
13
+ Do not infer this boundary by using the current directory, monorepo layout,
14
+ package names, or Git remotes to select additional sources. Once the user has named a concrete local module
15
+ or path, resolving its unique local directory and reading that checkout's Git
16
+ root, `origin`, and current commit are mechanical identity resolution, not a
17
+ new source-boundary decision. Paths in the registration payload are resolved
18
+ from the Context project root; after initializing a child `context/` directory,
19
+ recompute sibling paths from that root instead of reusing the caller's relative
20
+ path. As a final CLI safeguard, an omitted `local` may resolve only to one Git
21
+ directory named by the confirmed module at the project root or its parent; zero
22
+ or multiple matches do not authorize a guess.
23
+
24
+ Explain the decision in the user's language, obtain the specific paths or
25
+ documents, then use the Context source schema and conditional registration
26
+ command selected by the route. If the current user request already names the
27
+ exact modules or documents, that decision is already present; do not ask for
28
+ their remote URLs when a confirmed local Git checkout can supply them. The
29
+ command names a file below `.tmp/agent-payloads/`; after the current
30
+ conversation contains the required confirmation, write one JSON payload
31
+ matching the selected schema to that exact path. Do not run the command before confirmation and do not replace
32
+ it with a command remembered from another route.
21
33
 
22
34
  Context source identity has two parts:
23
35
 
@@ -141,7 +141,7 @@ Use collection routing first:
141
141
  `product`;
142
142
  - architecture, service/module/system design, runtime dependency, code-adjacent
143
143
  prose -> `architecture`; if an existing code projection already owns the
144
- object, reuse its NodeRef/ViewRef instead of creating a `codegraph` prose
144
+ object, reuse its NodeRef/ViewRef instead of creating a `codeindex` prose
145
145
  view;
146
146
  - SOP, runbook, operation drill, workflow, or how-to procedure -> `sop`;
147
147
  - FAQ, question/answer, support notes -> `faq` only when the evidence is an
@@ -158,7 +158,7 @@ Use collection routing first:
158
158
  Sections under the owning view;
159
159
  - test plan, validation scenario, acceptance case -> `test`;
160
160
 
161
- Do not route prose align views to `codegraph` or `feats`: `codegraph` is
161
+ Do not route prose align views to `codeindex` or `feats`: `codeindex` is
162
162
  produced by code extraction / AST projection, and `feats` is reserved for the
163
163
  dedicated feature workflow. For section-vs-collection overlap, keep a local
164
164
  `faq`, `decision`, or `incident` as a Section kind under the owning view unless
@@ -314,7 +314,7 @@ There is no parallel candidate-body authoring path. Emit only the
314
314
 
315
315
  ### Step 6 — Validate And Submit
316
316
 
317
- Before staging, run `context run align:<type>:<source>:<collection> --validate --input - --format json` with the `context.structure.v1` payload. The CLI applies deterministic boundary repairs internally and returns only remaining blockers. For oversized Views, apply the returned child-View and contains-edge suggestions while classifying child Nodes from evidence. Resolve other blockers from evidence; ask the user only when evidence supports multiple incompatible semantic choices. Stage only after validation state is `ready`. The stage result opens the final HTML report for the Route-selected structure-confirmation gate. Execute the revision-bound confirmation command returned by `workflow.current`; managed session authority may resolve that gate without another question.
317
+ Before staging, write the `context.structure.v1` payload to the Route-selected `.tmp/agent-payloads/` path and run the returned `context run align:<type>:<source>:<collection> --validate --input <payload-file> --format json` command. The CLI applies deterministic boundary repairs internally and returns only remaining blockers. For oversized Views, apply the returned child-View and contains-edge suggestions while classifying child Nodes from evidence. Resolve other blockers from evidence; ask the user only when evidence supports multiple incompatible semantic choices. Stage only after validation state is `ready`. The stage result opens the final HTML report for the Route-selected structure-confirmation gate. Execute the revision-bound confirmation command returned by `workflow.current`; managed session authority may resolve that gate without another question.
318
318
 
319
319
  After stage succeeds, do not rerun the same write command to confirm success.
320
320
  Use `context status --format json` or the returned result for read-only
@@ -331,7 +331,7 @@ editing CLI-managed files.
331
331
  - [ ] Evidence was read through returned `next_action.command`, `next_command`, or current CLI schema/view commands only. If not, return to **Step 2**.
332
332
  - [ ] Node classification used the semantic gates in `structure-planning/references/gates.md`. If not, return to **Step 4**.
333
333
  - [ ] URL/reference ownership followed CLI diagnostics, not static prompt rules. If not, return to **Step 5**.
334
- - [ ] The requested align payload passed `context run align:<type>:<source>:<collection> --validate --input - --format json` before stage. If not, return to **Step 6**.
334
+ - [ ] The requested align payload passed the exact Route-selected `--validate --input <payload-file>` command before stage. If not, return to **Step 6**.
335
335
  - [ ] No `sources/`, `knowledge/`, `dist/`, `.tmp`, host tool-results, or CLI-managed files were read or written with generic tools. If violated, restart from **Step 1**.
336
336
 
337
337
  </procedures>
@@ -52,6 +52,7 @@ Each module must have:
52
52
  - every additional applicable type in `moduleTypes`;
53
53
  - relevant behavior and boundary `facets`;
54
54
  - concrete inspected paths in `moduleTypeEvidence`;
55
+ - exact source-relative Markdown paths already read in `documents`;
55
56
  - an explicit gap when available source cannot support a reliable claim.
56
57
 
57
58
  Choose the primary type from the boundary through which a reader most often
@@ -152,11 +153,12 @@ Extractor shape is part of the plan, not an implementation detail:
152
153
  overlapping cross-source unit causes `ownership-ambiguous`.
153
154
  - Use `extractCustom()` for aggregate pages or multiple units over one source.
154
155
  Every candidate must declare its owning `module`, and its evidence must cover
155
- the Route-reported structural probes. Use evidence-scoped `sections` rather
156
- than one undifferentiated `markdown` body: each section declares a coverage
157
- kind and the exact source evidence supporting that part of the page. Resolve
158
- source roots from the extractor context's `sources[].absolutePath`; never
159
- embed a machine-specific checkout path.
156
+ the Route-reported structural probes. The custom-candidate contract has no
157
+ page-level Markdown fallback: every candidate must provide at least one
158
+ evidence-scoped `section`, and each section declares a coverage kind and the
159
+ exact source evidence supporting that part of the page. Resolve source roots
160
+ from the extractor context's `sources[].absolutePath`; never embed a
161
+ machine-specific checkout path.
160
162
  - Register independently visible monorepo children as separate sources before
161
163
  giving them separate `extractTs()` units. An `include` pattern filters files;
162
164
  it does not create a source boundary.
@@ -176,6 +178,7 @@ custom cross-module flow. A minimal plan has this shape:
176
178
  moduleTypes: ["web-application"],
177
179
  facets: ["page-routing", "protocol-consumer"],
178
180
  moduleTypeEvidence: ["package.json", "src/routes.ts"],
181
+ documents: ["README.md", "docs/architecture.md"],
179
182
  outputOwner: "customer-portal",
180
183
  outputProfile: "application-map",
181
184
  inputSources: ["repo:customer-portal"],
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "context.document-optimization-decisions.v1",
4
- "title": "Context document optimization decisions",
3
+ "$id": "context.document-optimization-decisions.v2",
4
+ "title": "Context source-constrained editorial revision decisions",
5
5
  "type": "object",
6
6
  "additionalProperties": false,
7
7
  "required": ["schema", "decisions"],
8
8
  "properties": {
9
- "schema": { "const": "context.document-optimization-decisions.v1" },
9
+ "schema": { "const": "context.document-optimization-decisions.v2" },
10
10
  "decisions": {
11
11
  "type": "array",
12
12
  "items": {
@@ -18,14 +18,37 @@
18
18
  "input_digest": { "type": "string", "minLength": 1 },
19
19
  "context_digest": { "type": "string", "minLength": 1 },
20
20
  "policy_digest": { "type": "string", "minLength": 1 },
21
- "action": { "enum": ["keep", "replace"] },
21
+ "action": {
22
+ "enum": ["keep", "repair", "reshape", "omit"],
23
+ "description": "Keep the Section, repair local presentation, reshape it within the same source boundary, or omit a mechanically eligible non-knowledge Section."
24
+ },
22
25
  "replacement": { "type": "string" },
23
- "reason": { "type": "string" }
26
+ "assessment": {
27
+ "type": "string",
28
+ "minLength": 12,
29
+ "description": "Required when keeping a Section that has mechanical signals. Explain why the signals are false positives or why changing the Section would reduce source fidelity. This value is decision-only and is not published."
30
+ },
31
+ "reason": {
32
+ "enum": [
33
+ "unanswered-question",
34
+ "empty-or-placeholder",
35
+ "draft-without-decision",
36
+ "duplicate-content",
37
+ "obsolete-without-replacement",
38
+ "volatile-reference",
39
+ "sensitive-value-candidate",
40
+ "conversion-artifact"
41
+ ]
42
+ }
24
43
  },
25
44
  "allOf": [
26
45
  {
27
- "if": { "properties": { "action": { "const": "replace" } } },
46
+ "if": { "properties": { "action": { "enum": ["repair", "reshape"] } } },
28
47
  "then": { "required": ["replacement"] }
48
+ },
49
+ {
50
+ "if": { "properties": { "action": { "const": "omit" } } },
51
+ "then": { "required": ["reason"] }
29
52
  }
30
53
  ]
31
54
  }
@@ -44,13 +44,28 @@
44
44
  "$ref": "#/$defs/module"
45
45
  },
46
46
  "local": {
47
- "$ref": "#/$defs/nonEmptyString"
47
+ "allOf": [
48
+ {
49
+ "$ref": "#/$defs/nonEmptyString"
50
+ }
51
+ ],
52
+ "description": "Local repository or module path resolved from the Context project root. A valid Git checkout supplies origin and current commit when remote/ref are omitted."
48
53
  },
49
54
  "remote": {
50
- "$ref": "#/$defs/nonEmptyString"
55
+ "allOf": [
56
+ {
57
+ "$ref": "#/$defs/nonEmptyString"
58
+ }
59
+ ],
60
+ "description": "Repository remote URL. Optional when local resolves to a Git checkout with origin configured."
51
61
  },
52
62
  "ref": {
53
- "$ref": "#/$defs/nonEmptyString"
63
+ "allOf": [
64
+ {
65
+ "$ref": "#/$defs/nonEmptyString"
66
+ }
67
+ ],
68
+ "description": "Pinned commit. Optional when local resolves to a Git checkout with a current commit."
54
69
  }
55
70
  }
56
71
  },