@c4a/context 0.7.0 → 0.7.4

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 (117) hide show
  1. package/README.md +65 -170
  2. package/README.zh-CN.md +52 -129
  3. package/docs/README.md +9 -10
  4. package/docs/README.zh-CN.md +6 -7
  5. package/docs/getting-started.md +73 -422
  6. package/docs/guides/agent-guide.md +94 -523
  7. package/docs/guides/code-indexer-skill-authoring.md +24 -13
  8. package/docs/guides/markdown-indexer-skill-authoring.md +14 -14
  9. package/docs/reference/code-extractors.md +29 -136
  10. package/docs/reference/indexer-provider-protocol.md +60 -138
  11. package/docs/reference/package-templates.md +2 -3
  12. package/docs/reference/project-api.md +52 -985
  13. package/index.d.ts +12 -10
  14. package/index.js +12749 -15335
  15. package/indexerAgentStepProtocol.d.ts +1366 -7649
  16. package/indexerArtifact.d.ts +225 -0
  17. package/indexerArtifactDependencies.d.ts +41 -39
  18. package/indexerArtifactResult.d.ts +221 -255
  19. package/indexerAuthorizedWorksetView.d.ts +368 -0
  20. package/indexerBaseQuestionAmendment.d.ts +484 -280
  21. package/indexerBenchmark.d.ts +16 -16
  22. package/indexerCandidateCompile.d.ts +206 -16
  23. package/indexerCapabilityGroupEvidence.d.ts +6 -6
  24. package/indexerCatalogFallback.d.ts +122 -128
  25. package/indexerCollectionMapping.d.ts +13 -13
  26. package/indexerContentLayers.d.ts +8 -8
  27. package/{indexerOverlayTrust.d.ts → indexerContractOverlay.d.ts} +23 -569
  28. package/indexerControlledInvocation.d.ts +12 -12
  29. package/indexerControlledProgram.d.ts +2467 -2797
  30. package/indexerCoreExports.d.ts +6 -6
  31. package/indexerCustomizationDraft.d.ts +3315 -2091
  32. package/indexerCustomizationLadder.d.ts +2 -2
  33. package/indexerDependencyView.d.ts +108 -108
  34. package/indexerEffectiveArtifact.d.ts +1134 -0
  35. package/indexerEvidenceAdapterAuthorityMerge.d.ts +48 -0
  36. package/indexerEvidenceAdapterResult.d.ts +52 -52
  37. package/indexerExampleDecision.d.ts +128 -128
  38. package/indexerExampleIdentity.d.ts +6 -6
  39. package/indexerGeneratedAuthoringAudit.d.ts +18 -18
  40. package/indexerIncrementalImpact.d.ts +16 -16
  41. package/indexerInspectorWorksetProjection.d.ts +6 -0
  42. package/indexerInventoryDisposition.d.ts +70 -70
  43. package/indexerLayerComposition.d.ts +2139 -373
  44. package/indexerLayoutChange.d.ts +10 -10
  45. package/indexerLayoutProposalSet.d.ts +71 -66
  46. package/indexerLayoutResolver.d.ts +53 -48
  47. package/indexerLayoutTransition.d.ts +0 -50
  48. package/indexerLifecycle.d.ts +0 -13
  49. package/indexerMainLifecycle.d.ts +10 -0
  50. package/indexerMainRunLedger.d.ts +138 -11
  51. package/indexerMainRunProtocol.d.ts +1406 -785
  52. package/indexerMainWorkset.d.ts +460 -206
  53. package/indexerMaterialGapLedger.d.ts +13 -2904
  54. package/indexerOverlayQuestionAmendment.d.ts +497 -293
  55. package/indexerOverlayQuestionApplyProposal.d.ts +1030 -622
  56. package/indexerParserCapabilityCatalog.d.ts +136 -0
  57. package/indexerParserCoordinate.d.ts +16 -16
  58. package/indexerParserDependencyIntent.d.ts +22 -0
  59. package/indexerParserExecutionPlan.d.ts +388 -0
  60. package/indexerParserFactView.d.ts +42 -22
  61. package/indexerPartitionConvergence.d.ts +0 -3
  62. package/indexerPartitionInventory.d.ts +2 -0
  63. package/indexerPartitionPlan.d.ts +101 -99
  64. package/indexerPhysicalArtifactManifest.d.ts +8 -8
  65. package/indexerPostAuthorComposition.d.ts +116 -1156
  66. package/indexerPostAuthorRunLedger.d.ts +1434 -280
  67. package/indexerPrimaryProjection.d.ts +10 -10
  68. package/indexerPrimaryResultView.d.ts +435 -0
  69. package/indexerProfileContract.d.ts +181 -181
  70. package/indexerProgramExecutionAuthorization.d.ts +12 -12
  71. package/indexerProgramRunProtocol.d.ts +2141 -2749
  72. package/indexerProjectProposal.d.ts +496 -292
  73. package/indexerProjectedArtifactFanOutAudit.d.ts +0 -3
  74. package/indexerProtocolCommon.d.ts +4 -1
  75. package/indexerProvider.d.ts +134 -281
  76. package/indexerProviderComposition.d.ts +53 -53
  77. package/indexerProviderResolution.d.ts +12 -12
  78. package/indexerProviderResolutionAction.d.ts +14 -14
  79. package/indexerProviderRouting.d.ts +923 -515
  80. package/indexerProviderSelectionProposal.d.ts +893 -485
  81. package/indexerQuestionAuthority.d.ts +46 -47
  82. package/indexerReaderTargetInventory.d.ts +8 -8
  83. package/indexerRegistry.d.ts +765 -357
  84. package/indexerRequirementConfirmation.d.ts +98 -98
  85. package/indexerRequirementLifecycle.d.ts +224 -224
  86. package/indexerResultReconciliation.d.ts +204 -5919
  87. package/indexerResultReconciliationRun.d.ts +0 -1
  88. package/indexerRunEnvelope.d.ts +20 -20
  89. package/indexerSemanticInput.d.ts +3678 -0
  90. package/indexerStructuredDeclaration.d.ts +57 -53
  91. package/indexerSubjectCatalog.d.ts +14 -14
  92. package/indexerSubjectIdentity.d.ts +2 -2
  93. package/indexerSubjectKeyAuthority.d.ts +31 -30
  94. package/indexerTemplateRendering.d.ts +64 -64
  95. package/indexerToolSnapshot.d.ts +8 -8
  96. package/package.json +1 -1
  97. package/phases.d.ts +3 -183
  98. package/codeIndexPlan.d.ts +0 -158
  99. package/indexerAuditFacts.d.ts +0 -66
  100. package/indexerAuditOverrideReadiness.d.ts +0 -27
  101. package/indexerAuditProtocol.d.ts +0 -238
  102. package/indexerAuditRevision.d.ts +0 -726
  103. package/indexerAuditRevisionActions.d.ts +0 -236
  104. package/indexerMaterialAnswer.d.ts +0 -738
  105. package/indexerMaterialAnswerActualization.d.ts +0 -91
  106. package/indexerMaterialAnswerExecutionPlan.d.ts +0 -2887
  107. package/indexerMaterialAnswerFlow.d.ts +0 -63
  108. package/indexerMaterialAnswerLayout.d.ts +0 -76
  109. package/indexerMaterialAnswerReview.d.ts +0 -217
  110. package/indexerMaterialAnswerReviewRoute.d.ts +0 -6145
  111. package/indexerMaterialAnswerRunLedger.d.ts +0 -918
  112. package/indexerMaterialAnswerRunProtocol.d.ts +0 -1253
  113. package/indexerMaterialQuestionExclusion.d.ts +0 -129
  114. package/indexerMaterialQuestionWorkset.d.ts +0 -508
  115. package/indexerPlannedMaterialAnswer.d.ts +0 -116
  116. package/indexerProfileMetricAudit.d.ts +0 -218
  117. package/indexerWorksetRead.d.ts +0 -287
@@ -1,525 +1,96 @@
1
1
  # Agent Guide
2
2
 
3
- This guide is for Coding Agents operating a Context workspace.
4
-
5
- ## Start Here
6
-
7
- 1. If a public Agent entry is available, use the installed Context continuation command/skill from the project root; the exact slash command or skill name is host-specific.
8
- 2. If you are implementing that entry or operating without plugins, run
9
- `context status --format json`.
10
- 3. Treat `workflow.current` as the current-step authority. Read every
11
- `resources.required` item, execute only returned commands with their
12
- revision/authority flags unchanged, and rerun status after each action.
13
- A phase-local `next_action` may continue pagination or validation inside the
14
- current operation; it never replaces the workspace route.
15
- 4. Before editing `src/index.ts`, read [Project API](../reference/project-api.md).
16
- 5. Before declaring or repairing packages, read [Package Outputs](./package-outputs.md)
17
- and [Package Templates](../reference/package-templates.md).
18
- 6. Before asking a human gate question, read the dialogue resource selected in
19
- `workflow.current.resources.required`; use [Agent Dialogue](./agent-dialogue.md)
20
- only for stable cross-gate principles.
21
-
22
- ## Current-conversation fully managed mode
23
-
24
- When the user explicitly requests fully managed operation in the current
25
- conversation, use `context status --managed --format json` and keep `--managed`
26
- only on commands that actually include it. Preserve every returned
27
- revision/authority flag. Eligible classification, extraction
28
- scope, structure confirmation, Review, and package-output gates may proceed
29
- without another question. Review uses the CLI's atomic `context review
30
- approve-all ... --managed` route; valid structure staging records
31
- `confirmed_by: managed-session`.
32
-
33
- The Provider may omit an ordinary Gate's HTML inspection Action and
34
- user-dialogue resources only on its session-authority Route, then expose the
35
- authority-selected revision-bound resolution Action directly. The ordinary
36
- inspection and resolution capabilities remain available in ordinary mode.
37
- Evidence reads needed to choose an extraction scope or classify a captured
38
- document are not removed.
39
-
40
- After the first managed status evaluation, use
41
- `context run --managed --until blocked-or-complete --format json` when the
42
- current work can advance through consecutive mechanical routes. The CLI
43
- executes only a unique immediate non-read command, re-evaluates after each
44
- receipt, and stops before Agent interpretation, configuration, missing
45
- authority, diagnostics, or multiple commands. Continue from the returned
46
- `workflow.current`.
47
-
48
- This is execution authority, not project configuration. Do not add it to
49
- `defineProject`, environment files, or committed workspace state, and do not
50
- carry it into a new conversation. It never grants a new source boundary or
51
- source-body read permission, authorizes clone/checkout/fetch/install/build/test
52
- operations outside the Context workspace, or suppresses validation, close, or
53
- verify failures. Without an explicit request, use ordinary status and all
54
- existing human gates.
55
-
56
- If the installed docs are unavailable, run `bun install` in the Context workspace.
57
-
58
- ## Dialogue Language
59
-
60
- Use the user's current conversation language for explanations, questions,
61
- confirmations, and final summaries. Treat CLI output, commands, flags, file
62
- paths, ids, status values, JSONL payload keys, and `source_ref` tokens as
63
- protocol text: copy those exactly and do not translate them.
64
-
65
- At human gates, explain the product decision and impact before internal API
66
- details. Do not start with `extractTs`, `include`, `exportedOnly`,
67
- `reviewValidity`, placeholder commands, or raw TypeScript snippets unless the
68
- user asks for implementation detail. The current gate's dialogue pattern is
69
- selected by `workflow.current.resources`; [Agent Dialogue](./agent-dialogue.md)
70
- explains stable cross-gate principles.
71
-
72
- ## Do Not Self-Discover The SDK
73
-
74
- Do not write temporary scripts to inspect `node_modules/@c4a/context/dist/index.js`
75
- or infer API shapes from bundled output. The public contract is documented in:
76
-
77
- ```text
78
- node_modules/@c4a/context/docs/reference/project-api.md
79
- node_modules/@c4a/context/docs/reference/package-templates.md
80
- ```
81
-
82
- When configuring code extraction, use the Route-selected
83
- `reference/code-extractors.md` manual. Run the Gate's read-only source
84
- inspection first, use its manifest signals to select a matching extractor, and
85
- read that package's public README before implementing an `extractCustom()`
86
- adapter. Do not probe compiled package output or treat TypeScript as the default
87
- for a non-TypeScript module.
88
-
89
- ## Workspace State Rules
90
-
91
- - `src/index.ts` declares sources, phases, and packages.
92
- - `sources/repo/index.yaml`, `sources/file/index.yaml`, and `sources/lark/index.yaml` declare sources.
93
- - `.tmp/context-runtime/lifecycle/` is the ignored, CLI-managed draft candidate
94
- ledger and confirmed structure state for an open lifecycle round.
95
- - `knowledge/` contains approved Markdown, the durable
96
- `knowledge/structure.yaml` projection, and (only when needed) the compact
97
- `knowledge/decisions.json` rejected candidate ID-to-fingerprint map.
98
- - `knowledge/structure.yaml.source_inputs` contains only source, collection,
99
- and consumed snapshot hash for closed prose targets. It lets status detect a
100
- changed or unfinished target without retaining lifecycle snapshots.
101
- - `dist/` contains generated package outputs.
102
- - `.tmp/agent-payloads/` is the recommended location for transient inputs written
103
- by the Agent for CLI commands. It is not enforced, but avoids introducing
104
- top-level scratch directories; remove these files after the corresponding
105
- stage or apply succeeds unless the user explicitly wants to retain them.
106
- - file and Lark documents from one date live as sibling files under `sources/file/<date>/` and `sources/lark/<date>/`; each date directory has one shared `manifest.json`.
107
- - `.tmp/context-runtime/` contains ignored runtime cache, logs, review HTML, previews, and locks. Successful close removes completed lifecycle and review runtime state.
108
-
109
- Do not create hidden workspace state directories.
110
-
111
- ## Workflow resources and entrypoints
112
-
113
- Long procedures, semantic judgment rules, schemas, and current workspace views
114
- are published as Context workflow resources. Status returns only the resources
115
- selected for the current route. Read required resources before acting; use
116
- recommended resources only when the current evidence or diagnostic needs them.
117
- Do not preload every workflow resource or SDK manual.
118
-
119
- Present only the current workflow surface:
120
-
121
- | Task | Current route |
122
- |---|---|
123
- | Register a knowledge boundary | `context source add file/lark/repo ...`, followed by the matching project phase declaration. Source registration is a user-confirmed boundary decision. |
124
- | Capture document sources | Run the declared `capture:file:<date>/<module>` or `capture:lark:<date>/<module>` phase only after read permission. Capture writes a sibling document file under the matching date directory, updates that directory's single `manifest.json`, and mechanically materializes supported Lark resources. Do not download or rewrite embedded resources outside the CLI. |
125
- | Investigate captured material | Use `context status` and the returned `context run align:<type>:<source>:<collection> --view ...` commands. Evidence views drive reading; raw directory grep is not the workflow. |
126
- | Confirm prose structure | `alignProse` validates and stages CLI-managed lifecycle structure. Validation does not equal user confirmation; only confirmed lifecycle state may enter prose compile. |
127
- | Compile source-bound drafts | `compileProse` turns confirmed structure into source-bound draft pages. It does not approve knowledge. |
128
- | Review and apply | Use `context review html` and `context review apply`. Approved prose pages are source-mirrored; rewrite/compression problems should return to structure/compile repair before apply. |
129
- | Close, verify, build | Run `context close`, `context verify`, then `context build`. Close derives `knowledge/structure.yaml`, approved edge projection, and the final verify gate. |
130
- | Code extraction | Use `context source inspect <source-name>` and the declared extract phase preview before code draft writes. |
131
- | Source retraction | Follow the current status or lifecycle command if one exists. Do not delete `sources/`, `knowledge/`, `dist/`, or `.tmp` to simulate lifecycle actions. |
132
-
133
- Judgment behavior is part of evidence views, source span resolvers, repair
134
- hints, review/status diagnostics, OKF indexes, and package query discipline. Do
135
- not describe unsupported commands or unsupported lifecycle state as alternate
136
- routes.
137
-
138
- ## Source Safety
139
-
140
- The CLI never silently clones, checks out, resets, fetches, installs, builds, or
141
- runs scripts inside source repositories. If a repo operation is needed, ask the
142
- user first.
143
-
144
- `missing-source` is a human gate. In user-facing language, describe the next
145
- action as adding a knowledge source, not as filling CLI placeholders. Treat this
146
- as a source boundary decision. Document sources use today's local date as their
147
- name. Repo sources use the date as a batch and require the confirmed module
148
- identity. Do not invent semantic date suffixes. The concrete repo selector
149
- appears in source refs, phase ids, and codeindex paths:
150
-
151
- ```text
152
- knowledge/<collection>/<slug>.md
153
- knowledge/<collection>/<containment>/<slug>.md # intentional hierarchy only
154
- repo:<date>/<module>#symbol:...
155
- file:<source-name>/<document>#span:...
156
- lark:<source-name>/<document>#span:...
157
- capture:file:<source-name>
158
- align:lark:<source-name>:architecture
159
- dist/<source-name>-kb/
160
- ```
161
-
162
- Every prose View requires a stable filename `slug`. The CLI derives its path
163
- from collection, slug, and optional `containment`; omit `path` from the input.
164
- Supply `containment` only for an intentional parent/child hierarchy;
165
- independent collection entries stay directly under the collection.
166
- Codegraph paths use the registered date/module grouping before the symbol slug.
167
-
168
- Ask what the user wants the source to cover: a single local Markdown/MDX document,
169
- a local Markdown/MDX directory, an article/documentation repository as a file
170
- source, a Lark/Feishu document URL or token, a local code repo/package, or a
171
- remote Git repo/package. Repo sources use today's date as one batch and a
172
- confirmed `--module` identity; do not create date suffixes for separate
173
- packages. The CLI rejects non-date or impossible repo batch names. Use
174
- `context source ensure <date>` / `context source inspect <date>` to operate on
175
- all registered modules in one batch, or `<date>/<module>` for one module.
176
- If the user supplies several repo/file/Lark sources in one request, create one
177
- `context source add batch <date> --input <payload> --format json` payload and
178
- register them under a single project write lock. Never parallelize mutating
179
- `source add` commands; on a lock-held error, wait and retry.
180
-
181
- Do not select sources from repository layout or Git metadata. After the user
182
- has named an exact local module or path, however, resolving one unique matching
183
- directory and reading its Git root, `origin`, and current commit are mechanical
184
- identity checks. Pass the resolved local path relative to the Context project
185
- root; when the workspace was initialized in a child `context/` directory,
186
- recompute sibling paths from that new root. In ordinary and fully managed modes,
187
- do not request a remote URL again when that confirmed local checkout provides
188
- it.
189
-
190
- Current execution supports repo sources, local Markdown/MDX file sources, and Lark /
191
- Feishu document sources. Local
192
- repo/package sources are registered with `context source add repo [YYYYMMDD] --module <module> --local <path>`;
193
- the materialized `sources/repo/<date>/<module>` entry is an ignored
194
- relative symlink to the selected checkout or subdirectory view. If the source
195
- and Context workspace share a Git root, absolute input is normalized to a
196
- workspace-relative repo root plus `subpath`; do not rewrite it back to an
197
- absolute machine path. Local Markdown/MDX sources
198
- are registered with `context source add file [YYYYMMDD] --module <module> --local <path>` plus any
199
- needed `--include` patterns, captured with `captureFile`, then planned through
200
- `alignProse` and compiled with
201
- `compileProse`. A one-file-to-one-page outcome is a degenerate structure plan,
202
- not a separate content path. Remote Git operations require explicit user approval before any
203
- clone/checkout; clone into an ignored local path, checkout the requested commit,
204
- then register that local checkout. Do not commit cloned source content. Lark /
205
- Feishu sources are registered as document modules under a shared date batch,
206
- captured through the Lark capture phase, and written as committed snapshots
207
- as a sibling file under `sources/lark/<date>/`, tracked by the date-level `manifest.json`;
208
- do not fetch or import Lark content with ad hoc scripts.
209
- If the user requests multiple documents together, register and declare all of
210
- them before capture. The user's explicit batch request supplies one read scope,
211
- but it does not imply a mainline collection unless the user explicitly chose
212
- one. Follow `workflow.current.commands`: run `immediate` items directly and run
213
- `after-human-confirmation` items only after the current conversation contains
214
- that confirmation. Preserve the returned workflow revision and authority flags
215
- exactly. Do not ask for another date name or repeat the collection gate per
216
- document.
217
-
218
- ## Current-step protocol
219
-
220
- Treat `context status --format json` `workflow.current` as the complete
221
- protocol for the current step:
222
-
223
- - `availability` distinguishes an immediately executable route from a human
224
- decision or a blocked route;
225
- - `gate` identifies the decision, its authority, and whether a managed session
226
- may resolve it;
227
- - `configuration` identifies the exact project file and declaration action when
228
- no CLI command is valid yet;
229
- - `commands[].availability` says whether each command runs immediately or only
230
- after user confirmation;
231
- - `resources.required` is the complete mandatory context for this route;
232
- - `resources.recommended` is optional follow-up context; and
233
- - `after_action.evaluate` requires status to be evaluated again after the
234
- action.
235
-
236
- Read a resource `path` directly. If a resource provides `command`, execute that
237
- revision-bound Context command and read the returned file. Long procedures and
238
- semantic rules live in these resources; they are loaded progressively, not
239
- discarded or shortened into the status response.
240
-
241
- Status also returns `declarationGraph` and `configurationGaps`. These expose
242
- capture, align, compile, and Review coverage for each canonical document source
243
- and declared align collection. Missing declarations are early warnings while
244
- structure is still being planned; after confirmation, every collection planned
245
- by the structure must have an exact compile route for the same source. Do not
246
- run a compile command from another collection as a fallback. A
247
- `reviewValidity({ scope: "all" })` declaration covers every collection.
248
-
249
- When `workflow.current.reason_code` is
250
- `route.document.classification-required`, execute its read-only
251
- `inspection_action` commands before adding align/compile declarations. Inspect
252
- every unclassified target, explain the evidence behind the proposed mainline
253
- collection, and wait for user confirmation. Filenames, URLs, source titles,
254
- and collection names are hints, not sufficient classification evidence.
255
-
256
- Also inspect `pendingStructureTargets`. A non-empty list means captured document
257
- work remains outside the active structure snapshots, even if the current package
258
- is already built. Follow `needs-prose-configuration` first when declarations are
259
- missing, then run the exact returned align command. Continue in the same
260
- workspace; do not replace a valid earlier structure round or create a second
261
- workspace merely to add the next document. Missing declarations are selected
262
- by `route.prose.configuration-required`; do not branch on an old top-level
263
- `needs-prose-configuration` state.
264
-
265
- Use `structureBatch` for the complete multi-source slot overview. Evidence View
266
- commands are workspace-read-only and parallel-safe; structure stage/confirm,
267
- compile stage, Review apply, and close mutate workspace state and must run
268
- serially.
269
-
270
- The confirmation and Review scopes are different: confirm each canonical source
271
- plus collection structure slot independently, but do not open Review while
272
- another declared slot remains pending in the same round. Compile every View from
273
- all slots first, open one collection-level Review, and let deterministic close
274
- merge the active slots into `knowledge/structure.yaml`.
275
-
276
- Do not infer permission from the presence of a command. When
277
- `workflow.current.commands` is empty, do not derive a lifecycle command from
278
- prose; complete the returned `configuration` action or resolve the returned
279
- gate, then rerun status.
280
-
281
- Extraction scope is also a human gate. If no extract phase is declared, explain
282
- what code area and symbol policy will become draft knowledge, then ask which
283
- registered source and file/symbol range to ingest. Do not inspect the source
284
- repository to choose packages or globs on the user's behalf. The
285
- `route.extract.configuration-required` Route carries
286
- `workflow.current.configuration` until that confirmed scope is declared; only
287
- a declared phase can select `route.extract.pending-target` and return an
288
- executable preview or extraction command.
289
-
290
- For a fresh mixed-source workspace, capture every confirmed file/Lark source
291
- first. If repo code is still unprocessed and document structure has not started,
292
- `context status` prioritizes `route.extract.pending-target` over document
293
- investigation. Complete code extraction and its batch Review before starting
294
- prose align. Once a document structure draft exists, keep that current human
295
- gate and do not switch workflows mid-review.
296
-
297
- For monorepos, the date is one registration batch and every selected package is
298
- a module under it. Stable codeindex paths omit that batch date and therefore
299
- look like `knowledge/codeindex/module-a/...` and
300
- `knowledge/codeindex/module-b/...`. Date/module remains in phase ids and
301
- repo source refs. Use the whole repo/subspace
302
- only for inspection when it contains multiple modules. If the user chooses
303
- `packages/button`, register it with `--module button` under the same date and
304
- write `extractTs({ source: source("20260712", "button"), ... })`. Do not use
305
- `include: ["packages/button/src/**"]` to choose a package from a larger source;
306
- `include` only filters files inside the selected source. Repo module names are
307
- project-wide codeindex identities; refresh an existing module through its
308
- original date/module selector instead of reusing its name under a later date.
309
-
310
- For a non-standard package, configure source-relative `entries` on `extractTs`;
311
- every entry must match `include`. If the user wants all declarations in the
312
- selected files instead of public API reachability, use `mode: "scan"`, which
313
- needs no entries and defaults to including internal symbols. Never add an entry
314
- file or package manifest field to the source repository solely to make Context
315
- run.
316
-
317
- Follow the source inspection pattern when scope is unclear: run
318
- `context source inspect <date>/<module> --format json`, show the candidate package
319
- paths from that CLI output, wait for the user to choose the package path(s), then
320
- declare sources/phases. If the extraction preview reports modules outside the
321
- confirmed source boundary, stop before review and repair the source declaration.
322
-
323
- Before running extraction, prefer:
324
-
325
- ```bash
326
- context source inspect <date>/<module> --format json
327
- context run <extract-phase-id> --dry-run --format json
328
- ```
329
-
330
- After the preview, run codeindex extraction normally unless the user explicitly
331
- asked for CI/CD automation. The first normal run requires Review for all code
332
- candidates. Subsequent normal runs require Review only for added, changed, or
333
- removed symbols; unchanged approved symbols stay approved. After each result,
334
- run `context status --format json`. `continue-codeindex-batch` only requests
335
- workspace re-evaluation. Open Review only when
336
- `workflow.current.gate.id=knowledge-review`; otherwise execute the current
337
- route.
338
-
339
- For a non-interactive pipeline, use `context run <extract-phase-id>
340
- --auto-promote --format json`. This flag applies only to codeindex, applies its
341
- deterministic deltas, refreshes deterministic close when needed, runs verify,
342
- and fails the command if close or verify fails. Read `autoPromotion.close` and
343
- `autoPromotion.verify` before continuing. Package build remains explicit: when
344
- the pipeline publishes packages, run `context build` after successful auto
345
- promotion. Never use auto promotion for semantic knowledge collections.
346
-
347
- Use the preview `mode`, optional `entries`, `preview.sources[].modules[]`,
348
- `entryFiles`, exported/internal symbol counts, `candidateKinds`,
349
- `candidateEstimate`, and `agent_hints`
350
- fields as the authoritative scope check. To the user, call it a preview without
351
- writing candidates; avoid the internal CLI term. Also show `knowledgeTree` and
352
- `knowledgePathExamples` before first extraction.
353
-
354
- These are structural extractor facts. Do not turn kind counts or file paths
355
- into a product-specific recommendation unless the user or Agent supplies that
356
- judgment.
357
-
358
- Treat `NO_ENTRY_DETECTED` as a configuration failure: choose explicit
359
- `entries`, or use `mode: "scan"` when the intended scope is all matched files;
360
- never report an empty extraction as success. Report discovered, AST-analyzed,
361
- skipped, symbol, and relation counts separately. The extractor follows
362
- tsconfig/jsconfig `baseUrl` and `paths`, so do not ask users to rewrite `@/`
363
- imports solely for Context. Explain the concrete output shape:
364
-
365
- ```text
366
- knowledge/codeindex/<module>/symbol/<slug>.md
367
- ```
368
-
369
- If the module or resulting path shape looks wrong, stop and repair the
370
- module registration before running extraction. An extra repeated package
371
- segment below the module may indicate an over-broad source boundary. Do not write ad hoc scripts to
372
- count packages, parse `package.json`, or sample the lifecycle candidate ledger.
373
-
374
- ## Review Rules
375
-
376
- - Use `context review html <collection> --open --format json` for visual review.
377
- Check `opened`: say the browser opened only when it is `true`; otherwise
378
- report `open_error` and provide the emitted `file_url` plus `absolute_path`.
379
- - Use `context review list <collection>` only for a textual overview.
380
- - Ask the user to paste the copied review decision Payload into chat. Uniform
381
- decisions use one JSON line; exceptions add JSONL lines. The agent writes
382
- that pasted payload to a temporary scratch file and runs `context review apply
383
- <payload-file>` only after the user has reviewed and provided the payload.
384
- - Do not synthesize review payloads from HTML, JSON, runtime snapshots, or
385
- candidate ids.
386
- - Do not default candidates to approved/rejected on behalf of the user.
387
- - If the user explicitly authorizes a quick or automated decision, use
388
- `context review approve <candidate-id> --collection <collection>` /
389
- `context review reject <candidate-id> --collection <collection>` or `--all`.
390
- These commands still enforce the scoped candidate-id gate.
391
- - Do not edit approved Markdown by hand as part of review apply.
392
-
393
- ## Prose Align And Compile Rules
394
-
395
- After document capture, do not ask the user to choose an SDK path. Explain the
396
- product sequence:
397
-
398
- 1. investigate material through Context evidence views;
399
- 2. propose a structure draft with nodes, section plans, supported edges, and
400
- unresolved items;
401
- 3. resolve only the non-mechanical blockers until validation state is `ready`,
402
- stage the structure, open its HTML report, then follow the current Route's
403
- structure-confirmation gate;
404
- 4. compile source-bound draft pages from confirmed structure;
405
- 5. send compiled drafts through human review, then close and build.
406
-
407
- One file per page is still possible, but it is represented as a simple
408
- structure draft. It does not bypass structure confirmation or compile.
409
-
410
- Material investigation:
411
-
412
- ```bash
413
- context run align:<type>:<source>:<collection> --view read-plan --format json
414
- context run align:<type>:<source>:<collection> --view source-index --compact --format json
415
- context run align:<type>:<source>:<collection> --view span-detail --span <source-ref> --format json
416
- context run align:<type>:<source>:<collection> --view span-text --span <source-ref> --format json
417
- context run align:<type>:<source>:<collection> --view existing-knowledge --query <title-or-stable-ref> --format json
418
- context run align:<type>:<source>:<collection> --view schema --format json
419
- context run align:<type>:<source>:<collection> --validate --input <structure.yaml> --format json
420
- context run align:<type>:<source>:<collection> --view structure-summary --input <structure.yaml> --format json
421
- context run align:<type>:<source>:<collection> --stage --input <structure.yaml> --format json
422
- ```
423
-
424
- Read source material only through these evidence views. `source-index` gives a
425
- compact refs-first map when run with `--compact`; use `span-detail` /
426
- `span-text` only for exact evidence. Before introducing a new Node identity,
427
- use the targeted `existing-knowledge` View returned by the read plan to inspect
428
- approved stable refs; do not inspect `knowledge/**` directly. The CLI applies
429
- deterministic boundary repairs internally and returns only blockers that need
430
- Agent judgment. For oversized Views, use the returned structural diagnostics
431
- while classifying
432
- child Nodes from evidence. Stage only after validation state is `ready`; stage
433
- opens the final `structure-summary` report for the current Route's confirmation
434
- gate. Ask a separate structure-design question only when evidence supports
435
- multiple incompatible semantic choices. Do not inspect `sources/` or `.tmp`
436
- directly.
437
-
438
- Compile:
439
-
440
- ```bash
441
- context run compile:<type>:<source>:<collection> --view read-plan --format json
442
- context run compile:<type>:<source>:<collection> --validate --format json
443
- context run compile:<type>:<source>:<collection> --stage --format json
444
- context run compile:<type>:<source>:<collection> --view diagnostics --format json
445
- ```
446
-
447
- Compile derives every candidate mechanically from the confirmed section ids,
448
- kinds, ownership, and source spans. One stage command validates the complete
449
- source/collection slot before atomically writing its candidates. The Agent does
450
- not author compile actions or rewrite reader-visible body. Re-evaluate status
451
- after the batch, finish any other structure slots, then open one
452
- collection-level Review, apply one Payload, and run close once.
453
-
454
- Relationships and cross references remain structure typed edges; compile does
455
- not infer them or inject relation markers into verbatim body.
456
-
457
- ## Package Rules
458
-
459
- If `workflow.current.reason_code` is `route.package.output-required`, treat it
460
- as a human gate.
461
- First read [Package Outputs](./package-outputs.md). Then explain the package
462
- decision using concrete output trees, not unexplained labels.
463
-
464
- Recommended first option:
465
-
466
- ```text
467
- dist/<name>-kb/
468
- ├── AGENTS.md
469
- ├── skills/knowledge-query/SKILL.md
470
- └── wikis/
471
- ├── index.md
472
- ├── <group-page>.md
473
- └── <large-group>/index.md
474
- ```
475
-
476
- This is an agent knowledge-base package. It is the recommended first output for
477
- agent consumption; the internal `skills/` folder follows agent installation
478
- conventions.
479
- The package name already identifies the surrounding `dist/` directory. Its OKF
480
- roots stay flat (`wikis/`, `guides/`, `rules/`, and `feats/`), so do not ask for
481
- a second distribution namespace. Ask separately whether the author wants a
482
- short Skill prefix; if so, maintain the complete final Skill directory name in
483
- the template.
484
- The default `knowledge-query` skill teaches agents to query copied OKF root
485
- directories structure-first, starting with `wikis/`, cite
486
- page/section evidence, use structure/build metadata when present, and report
487
- gaps instead of inventing unsupported answers. Tell the user that
488
- `src/package-templates/kb/` is editable before build, so they can customize the
489
- query skill or add project-specific skills when needed.
490
-
491
- Selected OKF root subtrees such as `wikis/`, `guides/`, `rules/`, and
492
- `feats/` follow the C4A OKF Profile. The package root contains agent
493
- installation files; the OKF-compatible interchange surface is the selected OKF
494
- root directories. Tell the user they can customize
495
- `src/package-templates/kb/wikis/index.md` before build to describe package
496
- scope and query guidance. The default root index should list only next-level
497
- entries. By default, `context build` links small directory contents directly
498
- and generates a child index only when that directory contains more than 50
499
- selected knowledge pages.
500
-
501
- Alternative:
502
-
503
- ```text
504
- dist/<name>-llms/
505
- └── llms.txt
506
- ```
507
-
508
- This is an LLM text bundle output for one model/RAG import file.
509
-
510
- The user may also skip package output for now and keep only `knowledge/`.
511
-
512
- Do not offer `both` as a shortcut. If the user wants multiple outputs, declare
513
- one package first, build and inspect it, then ask before adding another.
514
-
515
- Every package needs a template path. Treat `src/package-templates/kb` and
516
- `src/package-templates/llms` as editable starting points, not final deliverables.
517
- The agent knowledge-base package template must contain at least one `SKILL.md` and
518
- `wikis/index.md`; otherwise it is a hollow package and should not be reported
519
- as usable. Template paths also must not collide with copied knowledge paths.
520
- When a collision is reported, rename the template file or exclude the knowledge
521
- path before build.
522
-
523
- Do not present a clean `context build`, clean `context verify`, or file count as
524
- proof that the output is useful. Inspect the generated package shape against the
525
- user's chosen output contract.
3
+ The Context Agent coordinates one knowledge-production lifecycle. It does not
4
+ invent a separate pipeline for code, documents, or a particular host.
5
+
6
+ ## Start from the Route
7
+
8
+ Read `context status --format json`, then consume only the procedures, schemas,
9
+ and manuals selected by `workflow.current.resources`. Preserve revision and
10
+ authority flags in the next command. Do not infer progress from filenames or
11
+ probe ignored runtime files when the Route already states the next action.
12
+
13
+ ## Stable decisions
14
+
15
+ Ask the user only when the answer changes a durable boundary:
16
+
17
+ - which source or module is in scope;
18
+ - which readers and questions matter;
19
+ - whether two subjects are the same knowledge owner;
20
+ - whether a Provider customization or executable extension is acceptable;
21
+ - whether the proposed semantic outline organizes the requested knowledge;
22
+ - whether the displayed Candidate content is approved.
23
+
24
+ The Agent may decide mechanical details from evidence: parser selection within
25
+ an approved Provider, deterministic partition execution, page slug generation,
26
+ and recovery of an already completed step.
27
+
28
+ ## Authoring boundary
29
+
30
+ `src/index.ts` owns source capture and package output. `src/indexers.yaml` owns
31
+ knowledge requirements and Provider selection. Keep these responsibilities
32
+ separate.
33
+
34
+ Code and Markdown Providers receive controlled worksets and return typed
35
+ results. They do not write Candidate, Review, `knowledge/`, or `dist/` files.
36
+ Context validates and persists their result before the next action consumes it.
37
+ Initial Provider selection follows the same rule: use the requirements and
38
+ CLI-bundled catalog in the current Action input, return only non-CLI visible
39
+ Skill identities and semantic Indexer entries, and let the CLI perform routing,
40
+ resolution, staging, validation, and atomic registry apply. External resolver
41
+ results and non-allowlisted program decisions resume through subsequent
42
+ `complete-current` Routes; do not invoke the low-level Provider commands.
43
+ For Partition, Author, and Composer steps, read the Route-selected instructions
44
+ and Authorized Workset View, return only the compact semantic value requested
45
+ by the current schema, and submit it with the Route's single
46
+ `context action complete-current` command. Do not create a helper script or
47
+ construct internal Result, digest, receipt, Fact, or evidence-binding objects.
48
+
49
+ Parser packages are Provider internals. Do not expose parser choice as an
50
+ extra user workflow unless it changes coverage or requires executable code the
51
+ user has not authorized.
52
+
53
+ ## Review boundary
54
+
55
+ Review is about the proposed knowledge, not the storage mechanism. Show:
56
+
57
+ - readable target paths and titles;
58
+ - concise summaries and relevant source paths;
59
+ - the final page content or a clear structural preview;
60
+ - conflicts, omissions, and forced-approval warnings that affect correctness.
61
+
62
+ Do not show evidence hashes, content-addressed IDs, execution receipts, or
63
+ other machine fields by default. Keep those in runtime state only when they are
64
+ needed for validation, stale detection, or recovery.
65
+
66
+ A compatible production round has two semantic judgments. The first checks the
67
+ outline after all Partition shards converge; the second checks the final
68
+ reader-facing Candidate set. Ordinary mode presents both to the user. Fully
69
+ managed mode lets the Agent resolve both with current-conversation authority.
70
+ A destructive or ambiguous layout change is separate and always human-only.
71
+
72
+ ## Quality bar
73
+
74
+ Judge output from the reader's point of view:
75
+
76
+ - pages have semantic subjects rather than ordinal batches or symbol dumps;
77
+ - filenames and directories are readable and stable;
78
+ - content explains behavior, boundaries, examples, and constraints supported
79
+ by the source;
80
+ - templates are actually filled with source-specific information;
81
+ - duplicate pages and unsupported claims are absent;
82
+ - `dist/` is smaller and cleaner than the production workspace.
83
+
84
+ When dogfooding, compare the generated knowledge with an existing useful
85
+ knowledge base. Feed gaps back into the Provider profile, instructions,
86
+ templates, or parser coverage rather than editing generated pages by hand.
87
+
88
+ ## Recovery and Git
89
+
90
+ Runtime artifacts under `.tmp/context-runtime/` may be rich because they are
91
+ local and disposable. Committed knowledge should contain only readable content
92
+ and metadata required for future updates or rebuilds. A successful close may
93
+ discard transient Review details.
94
+
95
+ Context completion does not authorize Git operations. Stage, commit, push,
96
+ publish, and deploy only when the user explicitly requests them.