@c4a/context-cli 0.6.1-beta.3 → 0.6.1-beta.5

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 (43) hide show
  1. package/README.md +22 -9
  2. package/README.zh-CN.md +12 -8
  3. package/cli.js +76339 -69108
  4. package/docs/quickstart.md +7 -0
  5. package/package.json +4 -3
  6. package/plugins/README.md +7 -2
  7. package/plugins/README_CN.md +7 -2
  8. package/plugins/VERSION +1 -1
  9. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  10. package/plugins/claude/commands/continue.md +17 -3
  11. package/plugins/claude/commands/init.md +7 -4
  12. package/plugins/codex/.codex-plugin/plugin.json +2 -2
  13. package/plugins/codex/skills/continue/SKILL.md +17 -3
  14. package/plugins/codex/skills/init/SKILL.md +6 -3
  15. package/plugins/cursor/.cursor-plugin/plugin.json +1 -1
  16. package/plugins/cursor/commands/context-continue.md +17 -3
  17. package/plugins/cursor/commands/context-init.md +7 -4
  18. package/plugins/skills/context-continue/SKILL.md +17 -3
  19. package/plugins/skills/context-init/SKILL.md +6 -3
  20. package/providers/context/actions/accept-package-templates.yaml +5 -0
  21. package/providers/context/actions/align-next.yaml +1 -0
  22. package/providers/context/codes.yaml +2 -0
  23. package/providers/context/graphs/workspace.yaml +26 -1
  24. package/providers/context/manifest.json +67 -40
  25. package/providers/context/provider.yaml +1 -1
  26. package/providers/context/resources/diagnostics/projection-stale.md +13 -0
  27. package/providers/context/resources/dialogue/document-classification.md +2 -1
  28. package/providers/context/resources/dialogue/package-output.md +5 -7
  29. package/providers/context/resources/manuals/guides/package-outputs.md +40 -37
  30. package/providers/context/resources/manuals/reference/package-templates.md +36 -48
  31. package/providers/context/resources/manuals/reference/project-api.md +139 -17
  32. package/providers/context/resources/manuals/reference/template-variables.md +12 -11
  33. package/providers/context/resources/procedures/close-and-build.md +3 -1
  34. package/providers/context/resources/procedures/code-extraction.md +22 -2
  35. package/providers/context/resources/procedures/document-capture.md +14 -0
  36. package/providers/context/resources/procedures/document-classification.md +3 -0
  37. package/providers/context/resources/procedures/package-output.md +17 -11
  38. package/providers/context/resources/procedures/prose-align.md +45 -0
  39. package/providers/context/resources/procedures/source-boundary.md +6 -0
  40. package/providers/context/resources/procedures/source-capture-detailed.md +10 -0
  41. package/providers/context/resources/semantic/align/candidate-resolution.md +4 -2
  42. package/providers/context/resources/semantic/align/structure-planning.md +8 -5
  43. package/providers/context/schemas/prose-structure-batch.schema.json +35 -0
@@ -58,20 +58,15 @@ llmsPackage({
58
58
  | `template` | yes | Project-relative template directory or `{ path, vars }`. |
59
59
  | `select` | no | Approved knowledge selector. Omit to include all approved knowledge. Supports internal `collections`, OKF `okfRoots`, and `include` / `exclude` path patterns relative to `knowledge/`. |
60
60
  | `navigation` | no | KB directory-index policy. Defaults to `{ foldDirectoryIndexes: true, maxInlineEntries: 50 }`. |
61
- | `distribution` | no | Final knowledge-root namespace for a KB package. Defaults to `{ knowledgeNamespace: name }`; set it explicitly for a custom single- or multi-segment path. |
61
+ | `distribution` | no | Legacy input accepted from older workspaces. It no longer changes package paths and should not be added to new declarations. |
62
62
 
63
63
  `template` is required. Do not call `kbPackage({ name })` or
64
64
  `llmsPackage({ name })`.
65
65
 
66
- ## Knowledge Distribution Namespace
66
+ ## Flat Package Roots
67
67
 
68
- `name` identifies the build folder under `dist/` and is also the default
69
- single-level `distribution.knowledgeNamespace`. An explicit namespace may be
70
- one segment or a slash-separated sequence of safe lowercase path segments. A
71
- segment may contain letters and numbers joined by hyphens or dots, allowing
72
- identifiers such as `personal-user.123/package`. Keep every segment short,
73
- stable, and recognizable. Context treats the complete value as an opaque
74
- knowledge path and does not assign downstream meanings to individual segments.
68
+ `name` identifies the package boundary under `dist/`. Context does not repeat
69
+ that name inside the package's knowledge roots.
75
70
 
76
71
  Templates keep a logical, consumer-neutral layout:
77
72
 
@@ -83,39 +78,32 @@ rules/...
83
78
  feats/...
84
79
  ```
85
80
 
86
- For `name: "component-lib-kb"` with no explicit distribution, `context build`
87
- writes:
81
+ For `name: "component-lib-kb"`, `context build` writes:
88
82
 
89
83
  ```text
90
84
  skills/knowledge-query/SKILL.md
91
- wikis/component-lib-kb/index.md
92
- guides/component-lib-kb/...
93
- rules/component-lib-kb/...
94
- feats/component-lib-kb/...
85
+ wikis/index.md
86
+ guides/...
87
+ rules/...
88
+ feats/...
95
89
  ```
96
90
 
97
- The builder applies the knowledge mapping to template paths, copied knowledge,
98
- generated indexes, links, and inventory records. It does not apply the
99
- knowledge namespace to `skills/`, rewrite Markdown prose, or infer path
100
- segments from downstream platform identifiers. An explicit
101
- `distribution: { knowledgeNamespace: "platform/component-lib" }` produces the
102
- same shape under that multi-segment namespace instead.
103
-
104
- Because every KB package has a knowledge namespace, Skill templates must not
105
- hard-code flat package paths such as `wikis/index.md` or
106
- `rules/standards/index.md`.
107
- Use `{{wikisRoot}}`, `{{rulesRoot}}`, `{{guidesRoot}}`, or `{{featsRoot}}`
108
- instead. `context build` and `context status` reject flat Markdown links and
109
- inline-code paths in `skills/**/*.md` with
110
- `package/template-namespace-reference-flat`. This check is generic package
111
- validation; it does not depend on a downstream registry or distribution tool.
91
+ The builder maps copied knowledge, generated indexes, links, and inventory
92
+ records into these roots without rewriting Markdown prose or inferring a
93
+ downstream registry identity. New declarations should omit `distribution`.
94
+ Older declarations that still contain `distribution.knowledgeNamespace` remain
95
+ loadable, but the value does not change output paths or the build fingerprint.
96
+
97
+ Use `{{wikisRoot}}`, `{{rulesRoot}}`, `{{guidesRoot}}`, or `{{featsRoot}}` in
98
+ Skill templates so references share the package-root contract. These variables
99
+ render to the flat root names above.
112
100
 
113
101
  Each rendered Skill must live at `skills/<skill-name>/SKILL.md`, and its YAML
114
102
  frontmatter `name` must equal `<skill-name>`. Use `{{skillName}}` in custom
115
103
  Skill templates. Skill names are author-maintained: when a short prefix is
116
104
  useful, rename the template directory to the complete final name, such as
117
105
  `skills/android-query/`; Context does not derive it from
118
- `knowledgeNamespace`.
106
+ the package name.
119
107
 
120
108
  ## Template Variables
121
109
 
@@ -128,8 +116,8 @@ Built-in variables:
128
116
  |---|---|
129
117
  | `{{packageName}}` | Package name from the declaration. |
130
118
  | `{{packageKind}}` | `kb` or `llms`. |
131
- | `{{knowledgeNamespace}}` | Final KB knowledge namespace. Defaults to the package name; empty only for non-KB packages. |
132
- | `{{namespacedKnowledge}}` | Whether the package is a KB package with a knowledge namespace. |
119
+ | `{{knowledgeNamespace}}` | Legacy configured namespace when an older workspace still declares one; otherwise empty. Do not use it for new output paths. |
120
+ | `{{namespacedKnowledge}}` | Always `false`; retained only so older templates remain renderable. |
133
121
  | `{{skillName}}` | Current author-maintained Skill directory name. |
134
122
  | `{{skillPath}}` | Current Skill's final package-relative `SKILL.md` path. |
135
123
  | `{{wikisRoot}}`, `{{guidesRoot}}`, `{{rulesRoot}}`, `{{featsRoot}}` | Final package-relative OKF root paths. |
@@ -187,14 +175,14 @@ The default kb template includes:
187
175
  query copied knowledge pages structure-first, cite page/section evidence, use
188
176
  `context-build-inventory.json` edge records for package-visible
189
177
  relationships, and report gaps instead of inventing unsupported answers. The
178
+ build inventory also exposes `structure.relationship_coverage` so a consumer
179
+ can distinguish an observed zero-edge result from unknown relationship
180
+ coverage. The
190
181
  default entry OKF root is `wikis/`; packages that select additional internal
191
182
  collections expose
192
183
  `guides/`, `rules/`, or `feats/` indexes when those roots are selected.
193
184
  - `wikis/index.md`, the editable OKF bundle entry page for the generated
194
- `dist/<package-name>/wikis/<knowledge-namespace>/` directory.
195
-
196
- These are logical template paths. The package distribution namespace changes
197
- their final output paths as described above.
185
+ `dist/<package-name>/wikis/` directory.
198
186
 
199
187
  During `context build`, the root `wikis/index.md` is rendered from the template.
200
188
  The builder always provides an index for every selected OKF root. With the
@@ -205,7 +193,7 @@ its pages instead of producing one index per path segment.
205
193
  ## OKF Directory Indexes
206
194
 
207
195
  The generated
208
- `dist/<package-name>/wikis/<knowledge-namespace>/` tree is the required default
196
+ `dist/<package-name>/wikis/` tree is the required default
209
197
  KB entry surface. Internal collections are mapped into OKF roots during build:
210
198
  `codegraph`, `business`, and `product` go to `wikis/`; `architecture`, `sop`,
211
199
  `faq`, `decision`, and `incident` go to `guides/`; `standards` and `test` go to
@@ -241,11 +229,13 @@ Default navigation rules:
241
229
  an index path selected by the current navigation policy are rejected during
242
230
  build/status preflight.
243
231
 
244
- Users are expected to customize these template files. Edit
245
- `src/package-templates/kb/**` before `context build` to define project
246
- specific skills, prompts, routing rules, and package instructions. Do not add a
247
- package-name skill by default; add one only when the user wants project-specific
248
- behavior beyond knowledge lookup.
232
+ The generated templates are complete generic defaults. Before publishing,
233
+ package authors should replace or edit `src/package-templates/kb/**` when the
234
+ package needs project-specific skills, prompts, routing rules, terminology, or
235
+ package instructions. If the generic behavior is intentionally sufficient,
236
+ explicitly accept the unchanged default through the package-template Review
237
+ Route. Do not add a package-name Skill by default; add one only when the user
238
+ wants project-specific behavior beyond knowledge lookup.
249
239
 
250
240
  ## C4A OKF Profile
251
241
 
@@ -307,11 +297,9 @@ relationship citations inside the package instead of assuming the workspace
307
297
  `knowledge/structure.yaml` file is bundled.
308
298
 
309
299
  For KB packages, the inventory records `package.distribution` as
310
- `layout: "namespaced"` with the final `knowledge_namespace` and OKF root paths.
311
- Non-KB package types can remain `layout: "flat"`. Selected file and group
312
- records expose both the logical `okf_root` and final `okf_root_path`, so
313
- installers can inspect the layout without parsing paths or rewriting package
314
- content.
300
+ `layout: "flat"`, `knowledge_namespace: null`, and the four package-relative
301
+ OKF roots. Selected file and group records expose both the logical `okf_root`
302
+ and final `okf_root_path`, so consumers do not need to infer paths.
315
303
 
316
304
  Build expects approved knowledge to be closed when the project has source-bound
317
305
  document knowledge. When `workflow.current.reason_code` is
@@ -55,10 +55,11 @@ knowledge/codegraph/module-a/...
55
55
  knowledge/codegraph/module-b/...
56
56
  ```
57
57
 
58
- For prose Views, omit `containment` when the page is an independent collection
59
- entry. The CLI then derives `knowledge/<collection>/<slug>.md`. Set
60
- `containment` only when the approved structure intentionally places the page
61
- under a parent path; it is not a required source/module wrapper.
58
+ For prose Views, provide a stable filename `slug` and omit `path`; the CLI
59
+ derives the path. Omit `containment` when the page is an independent collection
60
+ entry, producing `knowledge/<collection>/<slug>.md`. Set `containment` only
61
+ when the approved structure intentionally places the page under a parent path;
62
+ it is not a required source/module wrapper.
62
63
 
63
64
  The registry stores this as one date entry containing several `modules` entries,
64
65
  and materializes each module at `sources/repo/<date>/<module>`.
@@ -185,7 +186,10 @@ with the next declared command in `workflow.current.commands`.
185
186
  Each command item declares its effect and availability. The current route's
186
187
  `gate` identifies the decision and authority boundary. Write commands are bound
187
188
  to the workflow revision; after one succeeds, rerun status instead of reusing
188
- the old command.
189
+ the old command. An external command also declares
190
+ `execution.target: agent-host`; execute it as a top-level Agent-host action so
191
+ network and credential-store access are not lost inside a restricted child
192
+ sandbox.
189
193
 
190
194
  ### `allSources("repo")`
191
195
 
@@ -251,6 +255,10 @@ context review approve-all <collection> --managed --format json
251
255
  context review approve-all --all --managed --format json
252
256
  ```
253
257
 
258
+ The default JSON result reports counts and change totals without listing every
259
+ candidate id or materialized path. Add `--verbose` only when debugging requires
260
+ the complete candidate and page details.
261
+
254
262
  Managed structure confirmation and Review use only the revision-bound commands
255
263
  returned by `workflow.current`. Source boundaries and unread source bodies,
256
264
  external operations, payload validation, deterministic close, and verification
@@ -330,9 +338,17 @@ Register each source with
330
338
  flag: `--url`, `--doc-token`, or `--wiki-token`. Multiple documents may share
331
339
  one date batch; when `--module` is omitted, the CLI derives an opaque,
332
340
  credential-safe module id. Capture reads the
333
- remote document through the CLI runner, writes normalized snapshot files under
334
- `sources/lark/<date>/` as sibling document files tracked by one date-level `manifest.json`, and does not write access credentials into the
335
- workspace.
341
+ remote document through the CLI runner as structured Docx XML. Context keeps a
342
+ redacted XML audit asset, projects supported blocks deterministically into
343
+ readable Markdown, and registers external resources such as document citations,
344
+ images, video, whiteboards, and Base references in the snapshot manifest even
345
+ when their binary content is not downloaded. The projection does not infer or
346
+ summarize document meaning. Its fidelity report closes discovered blocks against
347
+ converted and intentionally skipped blocks; a non-empty unsupported block is a
348
+ fidelity error and prevents downstream Review until capture support is fixed.
349
+ Snapshot files live under `sources/lark/<date>/` as sibling document files
350
+ tracked by one date-level `manifest.json`. Access credentials and transient
351
+ signed media URLs are not written into the workspace.
336
352
 
337
353
  Use a typed document reference in project declarations:
338
354
 
@@ -380,15 +396,56 @@ context run align:file:<source-name>:architecture --view structure-summary --inp
380
396
  context run align:file:<source-name>:architecture --stage --input <structure.yaml> --format json
381
397
  ```
382
398
 
399
+ When `workflow.current.batch` is present, several independent document slots
400
+ can be prepared in one Agent pass and validated or staged through one command:
401
+
402
+ ```yaml
403
+ schema: context.prose.structure-batch.v1
404
+ items:
405
+ - phase_id: align:file:<source-a>:architecture
406
+ input: .tmp/agent-payloads/<source-a>-structure.yaml
407
+ - phase_id: align:file:<source-b>:architecture
408
+ input: .tmp/agent-payloads/<source-b>-structure.yaml
409
+ ```
410
+
411
+ ```bash
412
+ context run --batch-input .tmp/agent-payloads/prose-structure-batch.yaml --validate --format json
413
+ context run --batch-input .tmp/agent-payloads/prose-structure-batch.yaml --stage --managed --format json
414
+ ```
415
+
416
+ Batch preflight validates every payload before writing. Stage writes ready
417
+ slots serially; it does not merge documents or decide their semantic shape.
418
+
419
+ Align results expose a recommended `payload_target.path` under
420
+ `.tmp/agent-payloads/`. Agents should use it for transient structure inputs and
421
+ may remove the file after a successful stage. The CLI continues to accept an
422
+ explicit alternative path; this is an authoring convention, not validation.
423
+
424
+ For the ordinary path, `read-plan` is a complete authoring packet: it includes
425
+ the payload contract, a budgeted canonical source-ref map, exact source-body
426
+ resources, and a direct `--stage` command. Read the bodies, author the payload,
427
+ and run that stage command. Request `source-index` only when the packet reports
428
+ omitted refs, and request `existing-knowledge` only when reusing or checking an
429
+ approved identity. The separate schema and validate views are optional
430
+ diagnostic tools, not required lifecycle steps.
431
+
383
432
  `--validate`, `--stage`, and `--confirm` are mutually exclusive operations. An
384
433
  `--input` without an operation is rejected unless the selected view explicitly
385
434
  consumes that input. Deterministic boundary repairs run internally before the
386
- result is returned. Successful validation returns a stage command with the
435
+ result is returned. `self_healed` includes input/output Section counts, the
436
+ number of original Sections split, and structural reason codes. Stage performs validation before writing and returns the
437
+ same diagnostics on failure; in managed mode, a valid stage also confirms the
438
+ structure. Successful standalone validation returns a stage command with the
387
439
  same file path. JSON run output keeps `next_action` first;
388
440
  schema and full reports stay behind explicit Views, while `--verbose` restores
389
441
  the full phase result and repeated contracts. Long diagnostics return a compact
390
442
  first page plus an exact diagnostics continuation command.
391
443
 
444
+ Validation returns `state: ready | repair-required | invalid`. Only `ready`
445
+ sets `valid: true` and may proceed to stage. `error_free: true` with
446
+ `state: repair-required` means no error diagnostic remains, but a declared
447
+ confirmation blocker still requires repair; it is not a successful result.
448
+
392
449
  `existing-knowledge` is the authoring-time lookup for approved identities. It
393
450
  returns stable NodeRefs, ViewRefs, titles, tags, collections, and section counts
394
451
  without exposing workspace storage paths. `--query` performs deterministic
@@ -420,7 +477,20 @@ After capture, the capture phase itself exposes collection-neutral `read-plan`,
420
477
  Status selects `route.document.classification-required` until every captured
421
478
  target has an evidence-backed, user-confirmed align declaration. Align then
422
479
  adds `schema` and `structure-summary` for structure work. Agents should not
423
- inspect `sources/` or `.tmp` directly.
480
+ scan `sources/` or `.tmp` to invent evidence. They may read only the exact
481
+ source-body files selected as required resources by the current Route; those
482
+ files carry stable content digests and must be read in full before a receipt is
483
+ reported. Read all required direct paths, then execute the Route's single
484
+ `resources.after_read.command`; the CLI writes and carries the merged receipt
485
+ set without requiring Agent-authored JSON. That acknowledgement response
486
+ already contains the re-evaluated `workflow.current`, so no additional status
487
+ command is needed.
488
+
489
+ Generated Context Views use the same content-addressed rule. Materialization
490
+ returns a receipt-set path and an exact post-read command. Read the complete
491
+ file, then execute that command; unchanged content remains current across
492
+ workflow revisions, while write and external commands still require the exact
493
+ current revision.
424
494
 
425
495
  Compile `read-plan`, `blockers`, and `diagnostics` Views are workspace-read-only
426
496
  and may run concurrently. Compile `--validate`, compile `--stage`, structure
@@ -457,9 +527,9 @@ compile:file:<source-name>:architecture
457
527
  compile:lark:<source-name>:architecture
458
528
  ```
459
529
 
460
- Compile requires confirmed `unapproved/structure.yaml`. It freezes the current
461
- structure for the compile round; if the user wants to change nodes, section
462
- ownership, or relationships, return to the align/structure gate.
530
+ Compile requires confirmed CLI-managed lifecycle structure. It freezes the
531
+ current structure for the compile round; if the user wants to change nodes,
532
+ section ownership, or relationships, return to the align/structure gate.
463
533
 
464
534
  Common commands:
465
535
 
@@ -543,7 +613,7 @@ package from a larger monorepo source.
543
613
  Use `context source inspect <date>/<module>` to list detected module/package
544
614
  boundaries before choosing the source. Use `context run <phase-id> --dry-run
545
615
  --format json` to check the resolved modules, file counts, symbol counts, and
546
- candidate estimate before writing `unapproved/entities.jsonl`. The dry-run
616
+ candidate estimate before writing the ignored lifecycle candidate ledger. The dry-run
547
617
  preview also includes `knowledgeTree` and `knowledgePathExamples`, which show
548
618
  where approved Markdown will land after review apply.
549
619
  Its module and total summaries distinguish `discoveredFiles`, `analyzedFiles`,
@@ -586,6 +656,56 @@ lookup exact when multiple files contain the same symbol name, kind, and digest;
586
656
  the complete ref remains opaque to agents. New pages keep only top-level
587
657
  `candidate_fingerprint` and do not emit `code_origin`.
588
658
 
659
+ ### `extractCustom`
660
+
661
+ Use a project-owned extractor when code facts cannot be represented by the
662
+ TypeScript symbol extractor, for example a language-specific parser or an
663
+ aggregated repository protocol:
664
+
665
+ ```ts
666
+ extractCustom({
667
+ id: "extract:service:protocol",
668
+ sources: [service],
669
+ collection: "codegraph",
670
+ extract: async ({ projectRoot }) => ({
671
+ candidates: [{
672
+ nodeRef: "service/protocol",
673
+ kind: "protocol",
674
+ visibility: "exported",
675
+ module: "service",
676
+ markdown: renderProtocol(projectRoot),
677
+ evidence: [{
678
+ source: "20260811/service",
679
+ file: "src/protocol.ts",
680
+ symbol: "protocol",
681
+ kind: "variable",
682
+ digest: "0123456789ab",
683
+ }],
684
+ review: {
685
+ title: "Service protocol",
686
+ summary: "Aggregated protocol boundary.",
687
+ signals: ["source-backed"],
688
+ reason: "Review the project-owned extraction.",
689
+ },
690
+ }],
691
+ }),
692
+ });
693
+ ```
694
+
695
+ `sources` is the complete registered repo scope for the phase. Every candidate
696
+ and edge carries structured `evidence`; the CLI validates that evidence against
697
+ the declared sources, creates canonical `source_ref` values, writes the symbol
698
+ index, candidate ledger and Review snapshots atomically, and records a phase
699
+ fingerprint. `context status` therefore treats this phase exactly like another
700
+ pending code extraction target, and Review can verify snapshot freshness
701
+ without a placeholder `extractTs` phase.
702
+
703
+ The extractor returns knowledge semantics (`nodeRef`, rendered Markdown,
704
+ Review summary and source-backed evidence). It must not write `knowledge/`,
705
+ `.tmp/context-runtime/lifecycle/candidates.jsonl`, extraction fingerprints or
706
+ Review snapshots directly. Context owns those files and preserves rejected and
707
+ unchanged-approved decisions across reruns.
708
+
589
709
  ### `reviewValidity`
590
710
 
591
711
  Declare the review step for a collection:
@@ -625,7 +745,8 @@ structure slots and every declared `pendingStructureTargets` item in the round;
625
745
  codegraph waits for every pending extract phase in the confirmed module round.
626
746
  Candidate count/hash therefore describes the complete current batch rather than
627
747
  one page, source slot, or module. Deterministic close later merges all active
628
- slots into `knowledge/structure.yaml`.
748
+ slots into `knowledge/structure.yaml`, retains only their source, collection,
749
+ and consumed snapshot hash as `source_inputs`, then removes the lifecycle slots.
629
750
 
630
751
  `status.structureBatch` lists unclassified, configuration-required, pending,
631
752
  and active structure slots together with the execution policy for the round.
@@ -656,8 +777,9 @@ customPhase("custom:20260712/sample:review", async (ctx) => {
656
777
  });
657
778
  ```
658
779
 
659
- Custom phases are an escape hatch. Prefer built-in factories for source,
660
- extract, review, and package workflows. The supported runtime helpers are:
780
+ Custom phases are an orchestration escape hatch. Use `extractCustom()` instead
781
+ when project code needs to publish codegraph candidates. The supported runtime
782
+ helpers are:
661
783
 
662
784
  - `ctx.ensureSources(...)` for repo source readiness.
663
785
  - `ctx.extract.ts(...)` for declared TypeScript extraction.
@@ -97,13 +97,13 @@ Read node_modules/@c4a/context/docs/reference/template-variables.md.
97
97
  |---|---|---|
98
98
  | `packageName` | string | Package name from `kbPackage()` / `llmsPackage()`. |
99
99
  | `packageKind` | string | `kb` or `llms`. |
100
- | `knowledgeNamespace` | string | KB knowledge namespace; defaults to the package name and may be explicitly overridden. Empty for non-KB packages. |
101
- | `namespacedKnowledge` | boolean | Whether the KB package has a knowledge namespace. |
100
+ | `knowledgeNamespace` | string | Legacy configured namespace when an older workspace still declares one; otherwise empty. It does not change output paths. |
101
+ | `namespacedKnowledge` | boolean | Always `false`; retained so older templates remain renderable. |
102
102
  | `skillsRoot` | string | Skills root, currently `skills`. |
103
- | `wikisRoot` | string | Final wikis root, such as `wikis/component-lib-kb` or `wikis/platform/component-lib`. |
104
- | `guidesRoot` | string | Final guides root, such as `guides/component-lib-kb` or `guides/platform/component-lib`. |
105
- | `rulesRoot` | string | Final rules root, such as `rules/component-lib-kb` or `rules/platform/component-lib`. |
106
- | `featsRoot` | string | Final feats root, such as `feats/component-lib-kb` or `feats/platform/component-lib`. |
103
+ | `wikisRoot` | string | Final wikis root: `wikis`. |
104
+ | `guidesRoot` | string | Final guides root: `guides`. |
105
+ | `rulesRoot` | string | Final rules root: `rules`. |
106
+ | `featsRoot` | string | Final feats root: `feats`. |
107
107
  | `skillName` | string | Author-maintained name of the Skill currently being rendered. Empty outside a `skills/<name>/...` template. |
108
108
  | `skillPath` | string | Final package-relative `SKILL.md` path for the Skill currently being rendered. Empty outside a Skill template. |
109
109
  | `knowledgeCount` | number | Selected approved Markdown file count. |
@@ -145,7 +145,7 @@ Each item contains:
145
145
  | `internal_collection` | Alias for `internalCollection`. |
146
146
  | `collection` | Internal approved collection; alias for `internalCollection`. |
147
147
  | `okf_root` | OKF output root, for example `wikis`, `guides`, `rules`, or `feats`. |
148
- | `okf_root_path` | Final package-relative OKF root; for KB packages it includes the distribution namespace. |
148
+ | `okf_root_path` | Final flat package-relative OKF root. |
149
149
  | `node_ref` | Stable NodeRef from approved frontmatter, for example `entity/button`. |
150
150
  | `view_ref` | Stable ViewRef from approved frontmatter, for example `architecture:entity/button`. |
151
151
  | `pathWithinCollection` | Path below the OKF root, for example `component-lib/symbol/button.md`. |
@@ -183,7 +183,7 @@ Each group contains:
183
183
  | `internalCollection` | Internal approved collection; alias for `collection`. |
184
184
  | `internal_collection` | Alias for `internalCollection`. |
185
185
  | `okf_root` | OKF output root for this group, for example `wikis`, `guides`, `rules`, or `feats`. |
186
- | `okf_root_path` | Final package-relative OKF root; for KB packages it includes the distribution namespace. |
186
+ | `okf_root_path` | Final flat package-relative OKF root. |
187
187
  | `title` | Display title; defaults to `name`, or the OKF root title for a root group. |
188
188
  | `count` | Number of selected pages in this group. |
189
189
  | `hasIndex` | Whether the active package navigation policy generates `indexPath`. |
@@ -242,6 +242,7 @@ non-root directory gets its own index only when it contains more than 50
242
242
  descendant knowledge pages. Configure this with
243
243
  `kbPackage({ navigation: { foldDirectoryIndexes, maxInlineEntries } })`.
244
244
 
245
- The output is only a starter. Edit
246
- `src/package-templates/kb/wikis/index.md` to add project-specific reading
247
- paths, API entry points, or task-focused navigation before `context build`.
245
+ The output is only a starter. Edit the files under
246
+ `src/package-templates/kb/` when the package needs different reading paths or
247
+ navigation before `context build`. An unchanged generated starter must instead
248
+ be explicitly accepted through the current package-template Review Route.
@@ -8,7 +8,9 @@ mediaType: text/markdown
8
8
 
9
9
  Close deterministically derives `knowledge/structure.yaml` from approved
10
10
  Markdown and the confirmed structure snapshots. It validates the rebuilt
11
- projection; it does not rewrite approved page bodies.
11
+ projection; it does not rewrite approved page bodies. Before removing the
12
+ transient snapshots, it retains only each closed prose target's source,
13
+ collection, and consumed snapshot hash under `source_inputs`.
12
14
 
13
15
  Build runs only after close and verification are current. It writes declared
14
16
  packages under `dist/` and records an inventory receipt with added, updated,
@@ -26,5 +26,25 @@ semantic knowledge. After confirmation, process exactly one pending extraction
26
26
  target and evaluate again.
27
27
 
28
28
  Do not open Review while another extraction target in the same batch remains.
29
- Unchanged approved symbols do not need another decision; new, changed, or
30
- unapproved candidates remain subject to the current Review policy.
29
+ Unchanged approved or rejected symbols do not need another decision; new or
30
+ changed candidates remain subject to the current Review policy.
31
+
32
+ For TypeScript sources, Context also carries extractor-reported AST relations
33
+ between selected symbols. A relation is projected only when both endpoints
34
+ resolve uniquely inside the selected module; external, unselected, and
35
+ ambiguous endpoints are counted as omissions instead of guessed. The extract
36
+ receipt reports `relationships.detected`, `emitted`, and omission counts.
37
+ Review materializes those source-backed relations with the approved symbol,
38
+ and deterministic close refreshes the typed edge projection.
39
+
40
+ Zero edges remain a valid result. Read `close.relationshipCoverage` or the
41
+ package inventory's `structure.relationship_coverage` to distinguish a current
42
+ source-backed extraction that found no approved edges from an older or
43
+ otherwise unknown relationship mode. Never infer missing edges from symbol
44
+ co-occurrence, filenames, or package size.
45
+
46
+ When the built-in TypeScript extractor cannot represent the code source, use a
47
+ declared `extractCustom` phase. The project-owned callback returns candidate
48
+ semantics plus structured source evidence; Context owns canonical refs,
49
+ fingerprints, candidate storage, Review snapshots, freshness, and rerun cleanup.
50
+ Do not use a generic `customPhase` callback to write lifecycle files directly.
@@ -20,6 +20,20 @@ documents grants source-read permission for those named modules. A mention,
20
20
  possible-source discussion, or register-only request does not. An explicit
21
21
  refusal always wins.
22
22
 
23
+ When that permission is already present in the conversation, execute the
24
+ Gate's returned authority-carrying command. In managed mode it runs the
25
+ deterministic capture batch until the next real blocker; in ordinary mode it
26
+ reevaluates status with `context.source-read`. The authority remains in the
27
+ current command chain and is never persisted in the project. Never bypass the
28
+ Route by running a bare capture phase.
29
+
30
+ Document capture is an external action. Execute a returned command with
31
+ `execution.target: agent-host` through the Agent host so its network and
32
+ credential-store access remain available; do not nest it inside a restricted
33
+ child sandbox. If the CLI reports an external-environment requirement, retry
34
+ the same returned command through the host. Never downgrade credential
35
+ protection as a recovery step.
36
+
23
37
  Capture targets are a batch. Process one current target, evaluate status again,
24
38
  and continue until the graph reports the batch complete. Never treat one
25
39
  successful module as completion of the whole batch.
@@ -13,6 +13,9 @@ example, or a fixed content-specific prompt.
13
13
  Read the current collection-neutral evidence view, explain a short
14
14
  evidence-backed recommendation and its output implications, then obtain the
15
15
  user decision unless the current session explicitly delegates this gate.
16
+ Read every Route-selected `context.source-body/*` resource in full. Index and
17
+ heading metadata support navigation but are not evidence that the document
18
+ body was read.
16
19
 
17
20
  After the decision, declare the complete align, compile, and review lifecycle
18
21
  for the same canonical source and collection. Re-evaluate instead of assuming
@@ -11,21 +11,27 @@ agents or text consumers. Explain the available Context package kinds and their
11
11
  directory shape before asking the user to choose.
12
12
 
13
13
  After confirmation, declare the package in `src/index.ts` using the SDK schema
14
- resource. Templates may customize presentation, but they must not overwrite
14
+ resource. The current Route's `configuration.contract` lists the supported
15
+ output choices, required fields, mechanical defaults, and follow-up status
16
+ command; do not infer another factory or hidden default. Templates may customize presentation, but they must not overwrite
15
17
  approved knowledge paths or remove required indexes.
16
18
 
17
- An Agent knowledge-base package uses its package name as a stable single-level
18
- knowledge namespace by default. Explain that default after the package name is
19
- confirmed. Ask for a custom namespace only when the user needs another value;
20
- it may contain several concise lowercase path segments, such as
21
- `group/package` or `personal-user.123/package`, with letters and numbers joined
22
- by hyphens or dots. Declare an override as
23
- `kbPackage({ distribution: { knowledgeNamespace } })`; do not derive it from
24
- an unstated downstream identity or rewrite template prose.
19
+ Generated generic templates carry a mechanical digest marker. Before the first
20
+ build, replace or edit the declared template source, or explicitly accept the
21
+ unchanged generic default through the current Route. Editing the template
22
+ changes its digest and resolves the review without a separate command.
23
+ Acceptance records only that decision; Context does not judge template prose
24
+ or infer audience, scope, or navigation semantics.
25
25
 
26
- Ask separately whether the author wants a short optional Skill prefix. If so,
26
+ An Agent knowledge-base package writes flat package-relative roots such as
27
+ `wikis/`, `guides/`, `rules/`, and `feats/`. The package name already provides
28
+ the surrounding `dist/<package-name>/` boundary. Do not ask the user for a
29
+ distribution namespace or add `distribution.knowledgeNamespace` to a new
30
+ declaration.
31
+
32
+ Ask whether the author wants a short optional Skill prefix. If so,
27
33
  maintain the complete final Skill directory name in the template, such as
28
- `skills/android-query/`. Knowledge namespaces never rename Skills.
34
+ `skills/android-query/`. Package-root layout never renames Skills.
29
35
 
30
36
  Package output is incremental: a built package is current only for the approved
31
37
  knowledge and template digests recorded by its receipt.
@@ -14,10 +14,55 @@ and block boundaries when they preserve coherent reading units; fixed line
14
14
  windows are only a fallback for unstructured text. A page may contain multiple
15
15
  sections, each with its own continuous evidence span.
16
16
 
17
+ The default `read-plan` is the authoring packet for ordinary documents. It
18
+ includes the payload contract, a compact canonical source-ref map, exact source
19
+ body resources, the recommended scratch path, and the direct stage command.
20
+ Do not separately request `schema`, `source-index`, or `existing-knowledge`
21
+ unless the packet reports truncation or the task specifically needs an existing
22
+ approved identity. Those views are diagnostics and large-source fallbacks, not
23
+ mandatory workflow steps.
24
+
25
+ Every `context.source-body/*` item selected in `workflow.current.resources`
26
+ is source evidence, not supporting metadata. Read the complete Markdown file
27
+ when its `read_state` is `read-required`. A source index, heading tree, token
28
+ count, or successful capture never substitutes for body reading. A matching
29
+ content digest receipt may be reused only while that text remains available in
30
+ the current conversation. After reading every selected direct path, execute the
31
+ single `resources.after_read.command`. For a generated Context View, execute
32
+ its materialization command, read its complete file, then execute its exact
33
+ `next_action.command`. Context carries the merged receipt file forward. A Route
34
+ revision change does not invalidate unchanged bytes, but every lifecycle
35
+ command remains revision-bound.
36
+
37
+ When the route returns `payload_target`, write the Agent-authored structure input
38
+ to its recommended `.tmp/agent-payloads/` path. This scratch area is separate
39
+ from CLI-owned `.tmp/context-runtime/` and can be discarded after a successful
40
+ stage. The recommendation does not restrict an explicit user-selected path.
41
+
17
42
  Stage all required source/collection slots before batch Review. Structure
18
43
  confirmation is an explicit gate. A confirmation applies only to the staged
19
44
  slot digest shown by the route; if the digest changes, confirm again.
20
45
 
46
+ When the current Route exposes `batch`, author every listed target payload in
47
+ one Agent planning pass, then write the small batch manifest to `batch.input`.
48
+ Use `batch.validate.command` for a read-only all-target check or
49
+ `batch.stage.command` to validate every target before any stage begins and then
50
+ write the ready slots serially. The manifest contains only each `phase_id` and
51
+ its structure payload `input` path; it does not merge document semantics or let
52
+ the CLI choose page structure. A failed preflight writes no slot. If a later
53
+ filesystem write fails, the result identifies completed slots and the Route
54
+ remains recoverable.
55
+
56
+ `--stage` performs the same validation and deterministic self-repair as
57
+ `--validate`; use the separate validation command only for a diagnostics-only
58
+ pass. In a managed conversation, a valid stage also records structure
59
+ confirmation in the same write. Validation states are literal: `ready` may
60
+ stage, `repair-required` may not, and `invalid` contains errors. `valid` is true
61
+ only for `ready`; `error_free` distinguishes a blocker-only result from one
62
+ containing errors. `self_healed` reports the input and output Section counts,
63
+ how many original Sections were split, and the structural reason codes used by
64
+ the repair.
65
+
21
66
  Independent read-only evidence views may run in parallel. Structure stage,
22
67
  confirmation, compile writes, and Review application are serial lifecycle
23
68
  mutations; execute them in the order selected by `workflow.current`.
@@ -30,6 +30,12 @@ them. A date-only inspection addresses the batch; `<date>/<module>` addresses
30
30
  one source. Register a confirmed multi-source request as one serial batch
31
31
  mutation instead of running registry writes in parallel.
32
32
 
33
+ To retire a registered source, first run `context source remove <source-id>
34
+ --format json`. This is a read-only preview that lists every project, candidate,
35
+ or approved-knowledge reference. Only after those references are intentionally
36
+ resolved may the route use `--yes`; the CLI never silently deletes referenced
37
+ knowledge or another source's materialized files.
38
+
33
39
  Repository readiness checks are mechanical and may run after the boundary is
34
40
  registered. Clone, fetch, checkout, install, build, test, and other external
35
41
  repository operations need separate authority. File and remote-document