@c4a/context 0.6.1-beta.1 → 0.6.1-beta.3

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.
@@ -27,6 +27,10 @@ kbPackage({
27
27
  include: ["architecture/component-lib/**", "sop/component-lib/**"],
28
28
  exclude: ["**/internal/**"],
29
29
  },
30
+ navigation: {
31
+ foldDirectoryIndexes: true,
32
+ maxInlineEntries: 50,
33
+ },
30
34
  });
31
35
  ```
32
36
 
@@ -47,10 +51,66 @@ llmsPackage({
47
51
  | `name` | yes | Lowercase path-safe package name. Output goes to `dist/<name>/`. |
48
52
  | `template` | yes | Project-relative template directory or `{ path, vars }`. |
49
53
  | `select` | no | Approved knowledge selector. Omit to include all approved knowledge. Supports internal `collections`, OKF `okfRoots`, and `include` / `exclude` path patterns relative to `knowledge/`. |
54
+ | `navigation` | no | KB directory-index policy. Defaults to `{ foldDirectoryIndexes: true, maxInlineEntries: 50 }`. |
55
+ | `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. |
50
56
 
51
57
  `template` is required. Do not call `kbPackage({ name })` or
52
58
  `llmsPackage({ name })`.
53
59
 
60
+ ## Knowledge Distribution Namespace
61
+
62
+ `name` identifies the build folder under `dist/` and is also the default
63
+ single-level `distribution.knowledgeNamespace`. An explicit namespace may be
64
+ one segment or a slash-separated sequence of safe lowercase path segments. A
65
+ segment may contain letters and numbers joined by hyphens or dots, allowing
66
+ identifiers such as `personal-user.123/package`. Keep every segment short,
67
+ stable, and recognizable. Context treats the complete value as an opaque
68
+ knowledge path and does not assign downstream meanings to individual segments.
69
+
70
+ Templates keep a logical, consumer-neutral layout:
71
+
72
+ ```text
73
+ skills/knowledge-query/SKILL.md
74
+ wikis/index.md
75
+ guides/...
76
+ rules/...
77
+ feats/...
78
+ ```
79
+
80
+ For `name: "component-lib-kb"` with no explicit distribution, `context build`
81
+ writes:
82
+
83
+ ```text
84
+ skills/knowledge-query/SKILL.md
85
+ wikis/component-lib-kb/index.md
86
+ guides/component-lib-kb/...
87
+ rules/component-lib-kb/...
88
+ feats/component-lib-kb/...
89
+ ```
90
+
91
+ The builder applies the knowledge mapping to template paths, copied knowledge,
92
+ generated indexes, links, and inventory records. It does not apply the
93
+ knowledge namespace to `skills/`, rewrite Markdown prose, or infer path
94
+ segments from downstream platform identifiers. An explicit
95
+ `distribution: { knowledgeNamespace: "platform/component-lib" }` produces the
96
+ same shape under that multi-segment namespace instead.
97
+
98
+ Because every KB package has a knowledge namespace, Skill templates must not
99
+ hard-code flat package paths such as `wikis/index.md` or
100
+ `rules/standards/index.md`.
101
+ Use `{{wikisRoot}}`, `{{rulesRoot}}`, `{{guidesRoot}}`, or `{{featsRoot}}`
102
+ instead. `context build` and `context status` reject flat Markdown links and
103
+ inline-code paths in `skills/**/*.md` with
104
+ `package/template-namespace-reference-flat`. This check is generic package
105
+ validation; it does not depend on a downstream registry or distribution tool.
106
+
107
+ Each rendered Skill must live at `skills/<skill-name>/SKILL.md`, and its YAML
108
+ frontmatter `name` must equal `<skill-name>`. Use `{{skillName}}` in custom
109
+ Skill templates. Skill names are author-maintained: when a short prefix is
110
+ useful, rename the template directory to the complete final name, such as
111
+ `skills/android-query/`; Context does not derive it from
112
+ `knowledgeNamespace`.
113
+
54
114
  ## Template Variables
55
115
 
56
116
  Templates are rendered with Handlebars. Variables are available in both file
@@ -62,6 +122,11 @@ Built-in variables:
62
122
  |---|---|
63
123
  | `{{packageName}}` | Package name from the declaration. |
64
124
  | `{{packageKind}}` | `kb` or `llms`. |
125
+ | `{{knowledgeNamespace}}` | Final KB knowledge namespace. Defaults to the package name; empty only for non-KB packages. |
126
+ | `{{namespacedKnowledge}}` | Whether the package is a KB package with a knowledge namespace. |
127
+ | `{{skillName}}` | Current author-maintained Skill directory name. |
128
+ | `{{skillPath}}` | Current Skill's final package-relative `SKILL.md` path. |
129
+ | `{{wikisRoot}}`, `{{guidesRoot}}`, `{{rulesRoot}}`, `{{featsRoot}}` | Final package-relative OKF root paths. |
65
130
  | `{{displayName}}` | Display name. Defaults to a title-cased `packageName`; override with `template.vars.displayName`. |
66
131
  | `{{knowledgeCount}}` | Number of selected approved Markdown files. |
67
132
  | `{{knowledgeTimestamp}}` | Latest `timestamp` from selected approved Markdown, or `1970-01-01T00:00:00.000Z` when empty. |
@@ -72,7 +137,7 @@ Built-in variables:
72
137
  | `{{knowledgeTreeNodes}}` | Nested path tree for custom navigation. |
73
138
  | `{{knowledgeTree}}` | Markdown tree preview. |
74
139
  | `{{knowledgeItemsMarkdown}}` | Markdown page list. |
75
- | `{{knowledgeGroupsMarkdown}}` | Markdown first-level group list with links to OKF root index paths. |
140
+ | `{{knowledgeGroupsMarkdown}}` | Markdown navigation for the current index: direct page links for folded directories and links to generated indexes for expanded directories. |
76
141
 
77
142
  Custom variables come from `template.vars`.
78
143
 
@@ -120,18 +185,22 @@ The default kb template includes:
120
185
  collections expose
121
186
  `guides/`, `rules/`, or `feats/` indexes when those roots are selected.
122
187
  - `wikis/index.md`, the editable OKF bundle entry page for the generated
123
- `dist/<package-name>/wikis/` directory.
188
+ `dist/<package-name>/wikis/<knowledge-namespace>/` directory.
189
+
190
+ These are logical template paths. The package distribution namespace changes
191
+ their final output paths as described above.
124
192
 
125
193
  During `context build`, the root `wikis/index.md` is rendered from the template.
126
- The builder also creates `index.md` files for directories under selected OKF
127
- roots when a directory does not already contain one. Keep OKF root indexes
128
- shallow by default: link to the next-level directories there, then let
129
- child indexes expose their own subdirectories and pages.
194
+ The builder always provides an index for every selected OKF root. With the
195
+ default navigation policy, smaller child directories are folded into their
196
+ nearest generated ancestor index, so a short collection can link directly to
197
+ its pages instead of producing one index per path segment.
130
198
 
131
199
  ## OKF Directory Indexes
132
200
 
133
- The generated `dist/<package-name>/wikis/` tree is the required default KB
134
- entry surface. Internal collections are mapped into OKF roots during build:
201
+ The generated
202
+ `dist/<package-name>/wikis/<knowledge-namespace>/` tree is the required default
203
+ KB entry surface. Internal collections are mapped into OKF roots during build:
135
204
  `codegraph`, `business`, and `product` go to `wikis/`; `architecture`, `sop`,
136
205
  `faq`, `decision`, and `incident` go to `guides/`; `standards` and `test` go to
137
206
  `rules/`; and `feats` goes to `feats/`. Treat `wikis/` as the structured
@@ -141,24 +210,30 @@ a relationship.
141
210
 
142
211
  Default navigation rules:
143
212
 
144
- - `wikis/index.md` is the required default bundle index. It should describe the
145
- package and list only the next-level directories. Other selected OKF roots
146
- use their own `<okf-root>/index.md` when present or generated.
147
- - `<okf-root>/<group>/index.md` and deeper directory indexes are generated by
148
- `context build` when missing.
213
+ - `wikis/index.md` is the required default bundle index. Other selected OKF
214
+ roots always use their own `<okf-root>/index.md`.
215
+ - With `foldDirectoryIndexes: true`, a non-root directory gets its own
216
+ `index.md` only when its descendant knowledge-page count is greater than
217
+ `maxInlineEntries`. The default threshold is `50`.
218
+ - A folded directory is not discarded. Its pages are listed in the nearest
219
+ generated ancestor index, grouped by their relative directory path.
220
+ - The threshold counts selected knowledge pages in the path tree. It does not
221
+ inspect Markdown line counts, headings, or content semantics.
222
+ - Set `foldDirectoryIndexes: false` to generate an `index.md` for every
223
+ directory, matching the fully expanded navigation shape.
149
224
  - A generated directory index uses OKF frontmatter with `type: Knowledge
150
225
  Directory`, `title`, `description`, `tags`, `timestamp`, `resource`,
151
226
  `package`, `package_kind`, and `knowledge_count`.
152
- - Directory indexes list child directories first, then pages directly under the
153
- directory.
227
+ - Directory indexes list generated child indexes first, then pages from folded
228
+ paths.
154
229
  - `context build` validates links in OKF root indexes and generated
155
230
  child `index.md` files. Relative links must resolve to files inside
156
231
  `dist/<package-name>/`; broken links are reported as
157
232
  `package/index-link-invalid`.
158
233
  - If a project needs curated default navigation, edit the template-owned
159
- `wikis/index.md`. Child `<okf-root>/**/index.md` paths are generated
160
- directory indexes; template files or copied knowledge pages that collide with
161
- those paths are rejected during build/status preflight.
234
+ `wikis/index.md`. Template files or copied knowledge pages that collide with
235
+ an index path selected by the current navigation policy are rejected during
236
+ build/status preflight.
162
237
 
163
238
  Users are expected to customize these template files. Edit
164
239
  `src/package-templates/kb/**` before `context build` to define project
@@ -225,9 +300,17 @@ endpoints are present in the selected package. Use those edge records for
225
300
  relationship citations inside the package instead of assuming the workspace
226
301
  `knowledge/structure.yaml` file is bundled.
227
302
 
303
+ For KB packages, the inventory records `package.distribution` as
304
+ `layout: "namespaced"` with the final `knowledge_namespace` and OKF root paths.
305
+ Non-KB package types can remain `layout: "flat"`. Selected file and group
306
+ records expose both the logical `okf_root` and final `okf_root_path`, so
307
+ installers can inspect the layout without parsing paths or rewriting package
308
+ content.
309
+
228
310
  Build expects approved knowledge to be closed when the project has source-bound
229
- document knowledge. If status says `compile-close-needed`, run
230
- `context close --format json` before build. Current close derives
311
+ document knowledge. When `workflow.current.reason_code` is
312
+ `route.close.projection-stale`, run the exact returned close command. Current
313
+ close derives
231
314
  `knowledge/structure.yaml`, persists approved edge projection, and runs the
232
315
  final verify gate. References, changelog, package index, and section
233
316
  fingerprint rebuilds are not current close output; build only packages the
@@ -27,7 +27,8 @@ Codegraph NodeRef/ViewRef and knowledge paths use the stable module name without
27
27
  the date:
28
28
 
29
29
  ```text
30
- knowledge/<collection>/<containment>/<slug>.md
30
+ knowledge/<collection>/<slug>.md
31
+ knowledge/<collection>/<containment>/<slug>.md # only for an intentional hierarchy
31
32
  knowledge/codegraph/<module>/symbol/<slug>.md
32
33
  repo:<date>/<module>#symbol:...
33
34
  file:<date>/<module>/<document>#span:...
@@ -48,6 +49,11 @@ knowledge/codegraph/module-a/...
48
49
  knowledge/codegraph/module-b/...
49
50
  ```
50
51
 
52
+ For prose Views, omit `containment` when the page is an independent collection
53
+ entry. The CLI then derives `knowledge/<collection>/<slug>.md`. Set
54
+ `containment` only when the approved structure intentionally places the page
55
+ under a parent path; it is not a required source/module wrapper.
56
+
51
57
  The registry stores this as one date entry containing several `modules` entries,
52
58
  and materializes each module at `sources/repo/<date>/<module>`.
53
59
  Repo module names are project-wide codegraph identities and therefore cannot be
@@ -133,7 +139,7 @@ is a repo, file, or lark source:
133
139
  ```ts
134
140
  import { source } from "@c4a/context";
135
141
 
136
- const legacyDocs = source("product-docs");
142
+ const productDocs = source("product-docs");
137
143
  ```
138
144
 
139
145
  ### `source(namespace, module)`
@@ -165,16 +171,15 @@ siblings under `sources/file|lark/<date>/` and share the date-level
165
171
  directory level.
166
172
 
167
173
  For a confirmed multi-document request, declare one capture phase per module.
168
- While any module is uncaptured, `context status --format json` reports either:
169
-
170
- - `needs-capture-phase` with `routing.configuration` when a module is not yet
171
- declared in `src/index.ts`; or
172
- - `needs-capture` with every declared command in `routing.command_plan`.
174
+ While any module is uncaptured, `context status --format json` selects either
175
+ the `route.capture.configuration-required` Route with
176
+ `workflow.current.configuration`, or the `route.capture.pending-target` Route
177
+ with the next declared command in `workflow.current.commands`.
173
178
 
174
- Each command-plan item says whether it is `immediate` or
175
- `after-human-confirmation`. The `routing.human_gate` object identifies the
176
- decision type and whether its result lives only in the current conversation or
177
- is persisted by a later workspace command.
179
+ Each command item declares its effect and availability. The current route's
180
+ `gate` identifies the decision and authority boundary. Write commands are bound
181
+ to the workflow revision; after one succeeds, rerun status instead of reusing
182
+ the old command.
178
183
 
179
184
  ### `allSources("repo")`
180
185
 
@@ -202,7 +207,7 @@ review html/apply`, `context close`, `context verify`, and `context build`.
202
207
 
203
208
  ### Status declaration coverage
204
209
 
205
- `context status --format json` includes a `declarationGraph` and
210
+ `context status --format json --view full` includes a `declarationGraph` and
206
211
  `configurationGaps` for document workflows. Each row reports capture, align,
207
212
  compile, and Review coverage for a canonical source plus collection. Gaps are
208
213
  non-blocking before structure confirmation. Once a structure is confirmed,
@@ -218,18 +223,20 @@ declarations are complete, status returns the exact align investigation command
218
223
  for the next target. A built package does not freeze the workspace or require a
219
224
  new workspace for later sources.
220
225
 
221
- Use `context status --format json --view summary` when only the current state,
222
- target, counts, diagnostics, and recommended command are needed. The full view
223
- retains source, phase, package, and lifecycle inventories.
226
+ `context status --format json` defaults to the compact workflow route, target,
227
+ progress, counts, and aggregated diagnostics. Use `--view full` only when
228
+ source, phase, package, and lifecycle inventories are needed for debugging.
224
229
 
225
230
  ### Current-conversation managed execution
226
231
 
227
232
  `context status --managed --format json` exposes
228
233
  `executionMode: { mode: "managed", scope: "current-conversation" }` and resolves
229
234
  eligible human gates into immediate commands. The flag is deliberately absent
230
- from `defineProject`: callers must pass it on each status/run/review command in
231
- the authorized conversation. A later process or conversation gets ordinary
232
- human-gated behavior by default.
235
+ from `defineProject`: callers start each workflow evaluation loop with managed
236
+ status, then execute the returned revision-bound command unchanged. Returned
237
+ commands carry a compact current-conversation marker instead of repeating every
238
+ authority. A later process or conversation gets ordinary human-gated behavior
239
+ by default.
233
240
 
234
241
  Managed Review is atomic and scope-validated:
235
242
 
@@ -238,10 +245,21 @@ context review approve-all <collection> --managed --format json
238
245
  context review approve-all --all --managed --format json
239
246
  ```
240
247
 
241
- Managed structure staging uses `context run <align-phase> --stage --managed
242
- --input <structure.yaml> --format json`. Source boundaries and unread source
243
- bodies, external operations, payload validation, deterministic close, and
244
- verification errors are never bypassed.
248
+ Managed structure confirmation and Review use only the revision-bound commands
249
+ returned by `workflow.current`. Source boundaries and unread source bodies,
250
+ external operations, payload validation, deterministic close, and verification
251
+ errors are never bypassed.
252
+
253
+ For consecutive mechanical routes, the Agent may run:
254
+
255
+ ```bash
256
+ context run --managed --until blocked-or-complete --format json
257
+ ```
258
+
259
+ This is a bounded host loop over the same revisioned routes. It stops before
260
+ read-only interpretation, project configuration, unresolved authority,
261
+ diagnostics, or a non-unique command plan; it does not add another workflow
262
+ entry or make semantic decisions.
245
263
 
246
264
  ### `captureFile`
247
265
 
@@ -347,6 +365,7 @@ context run align:file:<source-name>:architecture --view read-plan --format json
347
365
  context run align:file:<source-name>:architecture --view source-index --compact --format json
348
366
  context run align:file:<source-name>:architecture --view span-detail --span <source-ref> --format json
349
367
  context run align:file:<source-name>:architecture --view span-text --span <source-ref> --format json
368
+ context run align:file:<source-name>:architecture --view existing-knowledge --query <title-or-stable-ref> --format json
350
369
  context run align:file:<source-name>:architecture --view schema --format json
351
370
  context run align:file:<source-name>:architecture --view semantic-rules --format json
352
371
  context run align:file:<source-name>:architecture --validate --input <structure.yaml> --format json
@@ -355,14 +374,23 @@ context run align:file:<source-name>:architecture --view structure-summary --inp
355
374
  context run align:file:<source-name>:architecture --stage --input <structure.yaml> --format json
356
375
  ```
357
376
 
358
- `--validate`, `--stage`, `--confirm`, and `--repair` are mutually exclusive
359
- operations. An `--input` without an operation is rejected unless the selected
360
- view explicitly consumes that input. Successful validation returns a stage
361
- command with the same file path. JSON run output keeps `next_action` first;
377
+ `--validate`, `--stage`, and `--confirm` are mutually exclusive operations. An
378
+ `--input` without an operation is rejected unless the selected view explicitly
379
+ consumes that input. Deterministic boundary repairs run internally before the
380
+ result is returned. Successful validation returns a stage command with the
381
+ same file path. JSON run output keeps `next_action` first;
362
382
  schema and full reports stay behind explicit Views, while `--verbose` restores
363
383
  the full phase result and repeated contracts. Long diagnostics return a compact
364
384
  first page plus an exact diagnostics continuation command.
365
385
 
386
+ `existing-knowledge` is the authoring-time lookup for approved identities. It
387
+ returns stable NodeRefs, ViewRefs, titles, tags, collections, and section counts
388
+ without exposing workspace storage paths. `--query` performs deterministic
389
+ case-insensitive exact/prefix/substring matching; `--collection`,
390
+ `--node-type`, `--page-size`, and the returned continuation command narrow or
391
+ page the same View. Use it after reading source evidence and before introducing
392
+ a new Node identity. Structure validation remains the final duplicate gate.
393
+
366
394
  Align and compile evidence results include `semantic_rules`. Its `required`
367
395
  array is the rule subset selected for the current judgment, with a selection
368
396
  reason and content digest for each rule. `handle`, `digest`, and
@@ -383,22 +411,22 @@ cross multiple heading paths, without classifying document topics.
383
411
 
384
412
  After capture, the capture phase itself exposes collection-neutral `read-plan`,
385
413
  `source-index`, `span-detail`, `span-text`, and other read-only evidence views.
386
- Status reports `captured-ready-to-classify` until every captured target has an
387
- evidence-backed, user-confirmed align declaration. Align then adds `schema` and
388
- `structure-summary` for structure work. Agents should not inspect `sources/` or
389
- `.tmp` directly.
414
+ Status selects `route.document.classification-required` until every captured
415
+ target has an evidence-backed, user-confirmed align declaration. Align then
416
+ adds `schema` and `structure-summary` for structure work. Agents should not
417
+ inspect `sources/` or `.tmp` directly.
390
418
 
391
- Compile `read-plan`, `blockers`, `node-context`, and `schema` Views are also
392
- workspace-read-only and may run concurrently. `--validate`, `--stage`,
393
- structure confirmation, Review apply, and close are serial mutations.
419
+ Compile `read-plan`, `blockers`, and `diagnostics` Views are workspace-read-only
420
+ and may run concurrently. Compile `--validate`, compile `--stage`, structure
421
+ confirmation, Review apply, and close are serial operations.
394
422
 
395
423
  Structure payloads use `schema_version: "context.structure.v1"` and canonical
396
424
  `file:` / `lark:` `#span` source refs. A one-file-to-one-page plan is represented
397
425
  as ordinary `nodes[]` and `views[]` in the structure. It does not bypass
398
426
  structure confirmation or compile. Continuity applies to each Section, while one View/Page may
399
- contain multiple independently retrievable continuous Sections. The optional
400
- `suggested-splits` repair can expand a broad cross-heading Section into Markdown
401
- structural groups without creating child Views.
427
+ contain multiple independently retrievable continuous Sections. Deterministic
428
+ boundary splitting is applied internally during validate/stage; it is not a
429
+ separate Agent-authored payload or approval step.
402
430
 
403
431
  ### `compileProse`
404
432
 
@@ -431,27 +459,22 @@ Common commands:
431
459
 
432
460
  ```bash
433
461
  context run compile:file:<source-name>:architecture --view read-plan --format json
434
- context run compile:file:<source-name>:architecture --view node-context --source <view-ref> --format json
435
- context run compile:file:<source-name>:architecture --view schema --format json
436
- context run compile:file:<source-name>:architecture --validate --input <compile-actions.yaml> --format json
437
- context run compile:file:<source-name>:architecture --stage --input <compile-actions.yaml> --format json
438
- ```
439
-
440
- Compile remains one View per write for evidence isolation. After staging, follow
441
- `continue_compile_batch` to prepare the next View. Each canonical source plus
442
- collection is confirmed as an independent structure slot. When other captured
443
- align targets remain pending, status routes to those slots before opening one
444
- collection-level Review payload. `context close` is blocked while a planned
445
- View is unprepared, still draft, or rejected without a structure revision.
446
-
447
- Compile action payloads use `schema_version: "context.compile-actions.v1"`.
448
- By default, actions should omit body content and let the CLI mirror cited source
449
- spans into `verbatim` sections. Explicit reader-visible content is not accepted
450
- by the current compile action contract; split source evidence or return to the
451
- structure gate instead. The current approved section wire contract accepts `verbatim` and `empty`;
452
- it does not accept rewritten or mechanical projection modes.
453
- Relationships stay in `structure.yaml` typed edges in current output; do not
454
- inject relation markers into verbatim body.
462
+ context run compile:file:<source-name>:architecture --validate --format json
463
+ context run compile:file:<source-name>:architecture --stage --format json
464
+ context run compile:file:<source-name>:architecture --view diagnostics --format json
465
+ ```
466
+
467
+ Compile validates the complete confirmed source/collection slot before writing
468
+ any candidate, then materializes the slot atomically. Section bodies are
469
+ source-mirrored from the confirmed spans; the Agent does not create a separate
470
+ compile-actions payload. Each canonical source plus collection remains an
471
+ independent structure slot. When other captured align targets remain pending,
472
+ status routes to those slots before opening one collection-level Review
473
+ payload. `context close` is blocked while a planned View is unprepared, still
474
+ draft, or rejected without a structure revision.
475
+
476
+ Relationships stay in `structure.yaml` typed edges in current output; compile
477
+ does not infer relationships or inject relation markers into verbatim body.
455
478
 
456
479
  ### `extractTs`
457
480
 
@@ -518,8 +541,12 @@ candidate estimate before writing `unapproved/entities.jsonl`. The dry-run
518
541
  preview also includes `knowledgeTree` and `knowledgePathExamples`, which show
519
542
  where approved Markdown will land after review apply.
520
543
  Its module and total summaries distinguish `discoveredFiles`, `analyzedFiles`,
521
- `skippedFiles`, `symbols`, and `relations`; modules with skipped files include
522
- the reason, such as files not reachable from exports-mode entries.
544
+ `skippedFiles`, `symbols`, and `relations`. Module summaries also expose the
545
+ resolved `entryFiles`, exported/internal symbol counts, and a structural
546
+ `candidateKinds` count. These fields describe extractor output only; the CLI
547
+ does not infer which symbols are meaningful to a particular product or
548
+ audience. Modules with skipped files include the deterministic traversal
549
+ reason, such as files not reachable from exports-mode entries.
523
550
 
524
551
  Phase id shape:
525
552
 
@@ -531,8 +558,9 @@ Codegraph extraction has two execution policies:
531
558
 
532
559
  - `context run <phase-id>` is the Agent/user default. The first run sends every
533
560
  code symbol to Review. Later runs preserve unchanged approved symbols and send
534
- only `add`, `update`, and `remove` deltas to Review. If there is no delta, the
535
- result returns `next_action.human_gate=false` and the Agent continues.
561
+ only `add`, `update`, and `remove` deltas to Review. After every phase result,
562
+ the Agent re-evaluates `context status --format json`; only
563
+ `workflow.current` decides whether Review is now required.
536
564
  - `context run <phase-id> --auto-promote` is the explicit CI/CD path. It is valid
537
565
  only for `phase.extract.ts` codegraph phases, applies deterministic code deltas
538
566
  without Review, refreshes deterministic close when approved knowledge changed,
@@ -542,8 +570,9 @@ Codegraph extraction has two execution policies:
542
570
  separate pipeline step; existing package outputs are reported stale.
543
571
 
544
572
  This policy never auto-promotes architecture, business, decision, test, or
545
- other semantic knowledge. Agents must follow the returned
546
- `next_action.human_gate` instead of assuming every extraction requires Review.
573
+ other semantic knowledge. Agents must not infer a human gate from a phase-local
574
+ result. Human gates and their inspection/resolution Actions are exposed only by
575
+ `workflow.current`.
547
576
 
548
577
  Approved codegraph sections use the local evidence form
549
578
  `src-N#symbol:<file>:<symbol>:<kind>@<digest>`. The file segment makes reverse
@@ -551,19 +580,6 @@ lookup exact when multiple files contain the same symbol name, kind, and digest;
551
580
  the complete ref remains opaque to agents. New pages keep only top-level
552
581
  `candidate_fingerprint` and do not emit `code_origin`.
553
582
 
554
- Projects created by the beta.5 protocol can upgrade approved pages without a
555
- second human decision. Rerun every declared codegraph extraction phase to write
556
- the current file-aware symbol index, then run:
557
-
558
- ```bash
559
- context review migrate-codegraph-refs
560
- context verify
561
- ```
562
-
563
- Migration resolves each legacy ref against the trusted index and its existing
564
- origin metadata, removes `code_origin`, preserves the approved body and review
565
- state, and rolls back all page writes if final verification fails.
566
-
567
583
  ### `reviewValidity`
568
584
 
569
585
  Declare the review step for a collection:
@@ -91,6 +91,15 @@ Read node_modules/@c4a/context/docs/reference/template-variables.md.
91
91
  |---|---|---|
92
92
  | `packageName` | string | Package name from `kbPackage()` / `llmsPackage()`. |
93
93
  | `packageKind` | string | `kb` or `llms`. |
94
+ | `knowledgeNamespace` | string | KB knowledge namespace; defaults to the package name and may be explicitly overridden. Empty for non-KB packages. |
95
+ | `namespacedKnowledge` | boolean | Whether the KB package has a knowledge namespace. |
96
+ | `skillsRoot` | string | Skills root, currently `skills`. |
97
+ | `wikisRoot` | string | Final wikis root, such as `wikis/component-lib-kb` or `wikis/platform/component-lib`. |
98
+ | `guidesRoot` | string | Final guides root, such as `guides/component-lib-kb` or `guides/platform/component-lib`. |
99
+ | `rulesRoot` | string | Final rules root, such as `rules/component-lib-kb` or `rules/platform/component-lib`. |
100
+ | `featsRoot` | string | Final feats root, such as `feats/component-lib-kb` or `feats/platform/component-lib`. |
101
+ | `skillName` | string | Author-maintained name of the Skill currently being rendered. Empty outside a `skills/<name>/...` template. |
102
+ | `skillPath` | string | Final package-relative `SKILL.md` path for the Skill currently being rendered. Empty outside a Skill template. |
94
103
  | `knowledgeCount` | number | Selected approved Markdown file count. |
95
104
  | `knowledgeTimestamp` | string | Latest selected approved Markdown `timestamp`, or epoch when empty. |
96
105
  | `knowledge` | string | Concatenated selected approved Markdown bundle. Use carefully; it can be large. |
@@ -100,7 +109,7 @@ Read node_modules/@c4a/context/docs/reference/template-variables.md.
100
109
  | `knowledgeTreeNodes` | array | Nested path tree for selected pages. Useful for custom navigation. |
101
110
  | `knowledgeTree` | string | Markdown tree preview of selected pages. |
102
111
  | `knowledgeItemsMarkdown` | string | Markdown list of up to 50 selected pages. |
103
- | `knowledgeGroupsMarkdown` | string | Markdown list of first-level directories with links to their generated `index.md` files. |
112
+ | `knowledgeGroupsMarkdown` | string | Markdown navigation for the current index. Folded directories render direct page links; expanded directories render links to generated indexes. |
104
113
  | `buildInventory` | object | Deterministic package build inventory, including selected files, selected-by reasons, collection summaries, and package-visible edge records. |
105
114
  | `buildInventoryJson` | string | Pretty JSON form of `buildInventory`. |
106
115
  | `buildInventoryPath` | string | Package-relative inventory path, currently `context-build-inventory.json`. |
@@ -130,6 +139,7 @@ Each item contains:
130
139
  | `internal_collection` | Alias for `internalCollection`. |
131
140
  | `collection` | Internal approved collection; alias for `internalCollection`. |
132
141
  | `okf_root` | OKF output root, for example `wikis`, `guides`, `rules`, or `feats`. |
142
+ | `okf_root_path` | Final package-relative OKF root; for KB packages it includes the distribution namespace. |
133
143
  | `node_ref` | Stable NodeRef from approved frontmatter, for example `entity/button`. |
134
144
  | `view_ref` | Stable ViewRef from approved frontmatter, for example `architecture:entity/button`. |
135
145
  | `pathWithinCollection` | Path below the OKF root, for example `component-lib/symbol/button.md`. |
@@ -167,10 +177,13 @@ Each group contains:
167
177
  | `internalCollection` | Internal approved collection; alias for `collection`. |
168
178
  | `internal_collection` | Alias for `internalCollection`. |
169
179
  | `okf_root` | OKF output root for this group, for example `wikis`, `guides`, `rules`, or `feats`. |
180
+ | `okf_root_path` | Final package-relative OKF root; for KB packages it includes the distribution namespace. |
170
181
  | `title` | Display title; defaults to `name`, or the OKF root title for a root group. |
171
182
  | `count` | Number of selected pages in this group. |
183
+ | `hasIndex` | Whether the active package navigation policy generates `indexPath`. |
184
+ | `has_index` | Alias for `hasIndex`. |
172
185
  | `indexPath` | OKF-root-aware index path, for example `wikis/component-lib/index.md`, `guides/component-lib/index.md`, or `rules/index.md` for a root group. |
173
- | `indexHrefFromTemplate` | Link from the template file currently being rendered to `indexPath`. Use this in custom templates. |
186
+ | `indexHrefFromTemplate` | Link from the template file currently being rendered to `indexPath`. Check `hasIndex` before rendering it. |
174
187
  | `indexHrefFromCollectionIndex` | Link from the OKF root index to `indexPath`. |
175
188
  | `items` | `knowledgeItems` in the group. |
176
189
 
@@ -178,8 +191,11 @@ Example:
178
191
 
179
192
  ```md
180
193
  {{#each knowledgeGroups}}
181
- ## [{{title}}]({{indexHrefFromTemplate}}) ({{count}})
194
+ ## {{title}} ({{count}})
182
195
 
196
+ {{#if hasIndex}}
197
+ [Open directory index]({{indexHrefFromTemplate}})
198
+ {{/if}}
183
199
  {{#each items}}
184
200
  - [{{title}}]({{href}}) - {{type}}
185
201
  {{/each}}
@@ -211,14 +227,14 @@ care about.
211
227
  The default KB template uses the variables above to generate a starter index:
212
228
 
213
229
  - bundle count and timestamp in OKF frontmatter;
214
- - next-level directory links;
215
- - links to generated directory indexes such as `wikis/<group>/index.md` or
216
- another selected OKF root's `<okf-root>/<group>/index.md`.
217
-
218
- `context build` also generates `index.md` files for directories under selected
219
- OKF roots when a directory does not already contain one. The root
220
- `wikis/index.md` should stay shallow by default; put detailed navigation in the
221
- generated child indexes or in custom template sections.
230
+ - direct page links for directories folded by the active navigation policy;
231
+ - links to generated directory indexes when a directory exceeds the configured
232
+ inline-entry threshold.
233
+
234
+ `context build` always provides selected OKF root indexes. By default, a
235
+ non-root directory gets its own index only when it contains more than 50
236
+ descendant knowledge pages. Configure this with
237
+ `kbPackage({ navigation: { foldDirectoryIndexes, maxInlineEntries } })`.
222
238
 
223
239
  The output is only a starter. Edit
224
240
  `src/package-templates/kb/wikis/index.md` to add project-specific reading
package/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import type { PackageSelectDefinition } from "./contracts.js";
1
+ import type { PackageNavigationDefinition, PackageSelectDefinition } from "./contracts.js";
2
2
  import type { PhaseDefinition, PhaseResourceReference } from "./phases.js";
3
3
  import type { ProjectSourceDefinition } from "./sources.js";
4
- export type { CodegraphCollection, DocumentMainlineCollection, EntityStatus, KnowledgeCollection, MainlineCollection, MarkdownTransform, FileCaptureProcessorDefinition, OkfRoot, PackageKind, PackageSelectDefinition, TopLevelNamespace, } from "./contracts.js";
5
- export { assertDocumentMainlineCollection, assertKnowledgeCollection, assertMainlineCollection, assertOkfRoot, assertTopLevelNamespace, DOC_MAINLINE_COLLECTIONS, KNOWLEDGE_COLLECTIONS, MAINLINE_COLLECTIONS, OKF_ROOTS, TOP_LEVEL_NAMESPACES, } from "./contracts.js";
4
+ export type { CodegraphCollection, DocumentMainlineCollection, EntityStatus, KnowledgeCollection, MainlineCollection, MarkdownTransform, FileCaptureProcessorDefinition, OkfRoot, PackageKind, PackageNavigationDefinition, PackageSelectDefinition, TopLevelNamespace, } from "./contracts.js";
5
+ export { assertDocumentMainlineCollection, assertKnowledgeCollection, assertMainlineCollection, assertOkfRoot, assertTopLevelNamespace, DOC_MAINLINE_COLLECTIONS, DEFAULT_PACKAGE_NAVIGATION, KNOWLEDGE_COLLECTIONS, MAINLINE_COLLECTIONS, OKF_ROOTS, TOP_LEVEL_NAMESPACES, } from "./contracts.js";
6
6
  export { assertDocumentEvidenceSectionMetadata, DOCUMENT_COMPILE_ACTION_SCHEMA_VERSION, DOCUMENT_EVIDENCE_SECTION_VALIDATION_STAGES, DOCUMENT_SECTION_CONTENT_MODES, DOCUMENT_STRUCTURE_SCHEMA_VERSION, } from "./documentEvidence.js";
7
7
  export type { DocumentEvidenceSectionMetadata, DocumentEvidenceSectionValidationOptions, DocumentEvidenceSectionValidationStage, DocumentSectionContentMode, } from "./documentEvidence.js";
8
8
  export { alignProse, captureFile, captureLark, compileProse, customPhase, extractTs, ExtractTsConfigurationError, NO_ENTRY_DETECTED, mdxJsonDocs, reviewValidity, } from "./phases.js";
@@ -18,6 +18,9 @@ export type PackageTemplateInput = string | {
18
18
  path: string;
19
19
  vars?: Record<string, TemplateVarValue>;
20
20
  };
21
+ export type PackageDistributionDefinition = {
22
+ knowledgeNamespace: string;
23
+ };
21
24
  export type BasePackageDefinition = {
22
25
  name: string;
23
26
  reads: readonly PhaseResourceReference[];
@@ -28,6 +31,8 @@ export type BasePackageDefinition = {
28
31
  };
29
32
  export type KbPackageDefinition = BasePackageDefinition & {
30
33
  kind: "package.kb";
34
+ navigation: PackageNavigationDefinition;
35
+ distribution?: PackageDistributionDefinition;
31
36
  };
32
37
  export type LlmsPackageDefinition = BasePackageDefinition & {
33
38
  kind: "package.llms";
@@ -47,6 +52,8 @@ export declare const kbPackage: (definition: {
47
52
  name: string;
48
53
  template: PackageTemplateInput;
49
54
  select?: PackageSelectDefinition;
55
+ navigation?: Partial<PackageNavigationDefinition>;
56
+ distribution?: PackageDistributionDefinition;
50
57
  }) => KbPackageDefinition;
51
58
  export declare const llmsPackage: (definition: {
52
59
  name: string;