@c4a/context 0.7.1 → 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 -428
  6. package/docs/guides/agent-guide.md +94 -518
  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 -121
  10. package/docs/reference/indexer-provider-protocol.md +43 -110
  11. package/docs/reference/package-templates.md +2 -3
  12. package/docs/reference/project-api.md +52 -986
  13. package/index.d.ts +10 -8
  14. package/index.js +4739 -7103
  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 +219 -252
  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 +66 -60
  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/indexerContractOverlay.d.ts +10 -10
  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 +491 -287
  55. package/indexerOverlayQuestionApplyProposal.d.ts +1022 -614
  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 -218
  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
package/README.md CHANGED
@@ -2,206 +2,105 @@
2
2
 
3
3
  [简体中文](./README.zh-CN.md)
4
4
 
5
- `@c4a/context` is the declarative model behind a Context knowledge workspace.
6
- It lets the workspace describe which sources contribute knowledge, how evidence
7
- is processed, where human review applies, and which reusable outputs should be
8
- built.
5
+ `@c4a/context` is the declarative SDK used by a Context knowledge workspace.
6
+ Most users work through the Context Agent and CLI; project authors use this
7
+ package to declare source capture and package output.
9
8
 
10
- Most users do not install or operate this SDK directly. They start through the
11
- Context Agent entry, describe a knowledge goal, and let the selected workflow
12
- Route guide the Agent when `src/index.ts` needs configuration. This README is
13
- for knowledge-project authors, Agent maintainers, and developers who need to
14
- understand that project declaration.
9
+ Knowledge authoring has one path: `src/indexers.yaml` selects Indexer Providers
10
+ and owns requirements, profiles, scopes, and customization. Code and Markdown
11
+ knowledge are not produced by project phases in `src/index.ts`.
15
12
 
16
- The SDK is intentionally declarative. It does not read sources, write workspace
17
- state, execute an Agent, or build packages by itself. Those operations belong
18
- to the [Context workflow runtime](../context-cli/README.md).
19
-
20
- ## Place in the knowledge workflow
13
+ ## Project boundary
21
14
 
22
15
  ```text
23
- User intent + source boundaries
24
- ↓
25
- src/index.ts declaration ← this package
26
- ↓
27
- Context Route + Agent judgment
28
- ↓
29
- approved knowledge → package output
16
+ sources/*/index.yaml registered source boundaries
17
+ src/index.ts capture and package declarations
18
+ src/indexers.yaml knowledge-authoring authority
19
+ knowledge/ approved, human-readable knowledge
20
+ dist/ reader-facing package output
21
+ .tmp/context-runtime/ recoverable runtime state (not committed)
30
22
  ```
31
23
 
32
- The declaration answers four stable questions:
33
-
34
- - Which registered source boundaries may contribute evidence?
35
- - Which capture, extraction, alignment, compilation, and review phases exist?
36
- - Which approved collections belong in each output?
37
- - Which templates and asset-delivery policies shape the built package?
38
-
39
- It does not encode current progress. Workspace facts and the bundled workflow
40
- Provider select the next Route at runtime, so `src/index.ts` remains a project
41
- contract rather than a second state machine.
24
+ `src/index.ts` may declare:
42
25
 
43
- ## Project Model
26
+ - `source()` / `allSources()` references;
27
+ - `captureFile()` and `captureLark()` snapshot phases;
28
+ - `customPhase()` for project orchestration that does not publish knowledge;
29
+ - `kbPackage()` and `llmsPackage()` output definitions.
44
30
 
45
- A Context project follows a sources-to-phases-to-packages model:
31
+ Example:
46
32
 
47
33
  ```ts
48
34
  import {
35
+ captureFile,
49
36
  defineProject,
50
- extractTs,
51
37
  kbPackage,
52
- reviewValidity,
53
38
  source,
54
39
  } from "@c4a/context";
55
40
 
56
- const sampleLib = source("20260712", "sample-lib");
41
+ const docs = source("product-docs", { type: "file" });
57
42
 
58
43
  export default defineProject({
59
- sources: [sampleLib],
60
- phases: [
61
- extractTs({ source: sampleLib, collection: "codeindex" }),
62
- reviewValidity({ collection: "codeindex" }),
63
- ],
44
+ sources: [docs],
45
+ phases: [captureFile({ source: docs })],
64
46
  packages: [
65
47
  kbPackage({
66
- name: "sample-lib-kb",
67
- template: {
68
- path: "src/package-templates/kb",
69
- vars: { displayName: "Sample Library KB" },
70
- },
71
- select: { collections: ["codeindex"], okfRoots: ["wikis"] },
48
+ name: "product-kb",
49
+ template: "src/package-templates/kb",
50
+ select: { collections: ["product", "architecture"] },
72
51
  }),
73
52
  ],
74
53
  });
75
54
  ```
76
55
 
77
- `src/index.ts` is similar to a build configuration for knowledge. It defines
78
- what enters the project, which transformations and gates are available, and
79
- what can be built at the end. The installed Agent entry stays thin; the current
80
- workflow Route selects the exact procedures, schemas, and manuals needed to
81
- maintain this declaration from the user's requirements.
56
+ The Context lifecycle discovers or updates `src/indexers.yaml`, runs the
57
+ selected Provider, presents readable Candidate pages for Review, writes only
58
+ approved knowledge, and then builds declared packages.
82
59
 
83
- ## Public Surface
60
+ ## Public surface
84
61
 
85
62
  | API | Purpose |
86
63
  |---|---|
87
- | `defineProject()` | Declares the complete project graph. |
88
- | `source()` and `allSources()` | References registered repo, file, or Lark source boundaries. |
89
- | `extractTs()` | Extracts TypeScript/JavaScript and TSX/JSX symbols and relationships into `codeindex` candidates. |
90
- | `extractCustom()` | Runs a project-owned code extractor while Context owns candidate, evidence, freshness, and Review state. |
91
- | `alignProse()` and `compileProse()` | Legacy explicit phase factories retained for existing workspace migration and repair. New workspaces use `src/indexers.yaml` and the Context Indexer lifecycle. |
92
- | `reviewValidity()` | Declares the review gate for one collection or the project. |
93
- | `customPhase()` | Adds project-specific orchestration when built-in phase factories are not enough. |
94
- | `kbPackage()` | Builds an Agent knowledge-base package from approved knowledge and templates. |
95
- | `llmsPackage()` | Builds a single text bundle for model context or RAG import. |
96
-
97
- Use `extractCustom()` when a repository needs a non-TypeScript or aggregated
98
- code extractor. Use `customPhase()` only for orchestration that does not publish
99
- knowledge candidates; it is not a replacement for source, extraction, Review,
100
- and package lifecycle rules.
101
-
102
- Context CLI intentionally does not bundle every language or repository parser.
103
- Optional structural libraries can be installed by the knowledge project and
104
- used inside `extractCustom()`:
105
-
106
- | Package | Structural facts |
107
- |---|---|
108
- | `@c4a/extract-go` | Go declarations, imports, calls, and common HTTP route registrations |
109
- | `@c4a/extract-rush` | Rush projects, tags, entry signals, workspace dependencies, and owner boundaries |
110
- | `@c4a/extract-ts` | TypeScript extraction plus reusable React Router route facts |
111
-
112
- These libraries do not create Context phases or candidates by themselves. The
113
- project maps their deterministic facts to its own candidate identities and
114
- review summaries; Context continues to own evidence validation, freshness,
115
- Review, close, and package output.
116
-
117
- ## Knowledge Collections
118
-
119
- Approved Markdown is organized under `knowledge/<collection>/`:
120
-
121
- | Collection | What it contains | Typical sources |
122
- |---|---|---|
123
- | `codeindex` | Code symbols, modules, and relationships | Code repositories |
124
- | `business` | Business concepts, roles, and relationships | Business and Lark documents |
125
- | `product` | Product capabilities and behavior | Product and requirement documents |
126
- | `architecture` | System structure and design explanations | Architecture and design documents |
127
- | `sop` | Procedures, runbooks, and operational steps | Handbooks and operation documents |
128
- | `faq` | Common questions and troubleshooting | FAQs, support documents, experience notes |
129
- | `decision` | Decisions, alternatives, and trade-offs | Design reviews and decision records |
130
- | `incident` | Incident timelines, response, and follow-up | Incident reports and retrospectives |
131
- | `standards` | Normative rules and constraints | Engineering standards and business rules |
132
- | `test` | Validation rules, scenarios, and acceptance criteria | Test plans and acceptance documents |
133
- | `feats` | Capability records for a specific use case | Custom project workflows and approved knowledge |
134
-
135
- Collections are semantic classifications, not final package directories.
136
- Package build maps selected collections into OKF roots such as `wikis/`,
137
- `guides/`, `rules/`, and `feats/`. One source may contribute to several
138
- collections; classification should be based on evidence and user confirmation,
139
- not filenames.
140
-
141
- ## Package Templates
142
-
143
- Package declarations point at editable templates under
144
- `src/package-templates/`. Installed examples are available at:
64
+ | `defineProject()` | Declares the project boundary. |
65
+ | `source()` / `allSources()` | References registered repo, file, or Lark sources. |
66
+ | `captureFile()` / `captureLark()` | Creates deterministic document snapshots. |
67
+ | `mdxJsonDocs()` | Configures the MDX/JSON documentation capture processor. |
68
+ | `customPhase()` | Runs non-knowledge project orchestration. |
69
+ | `kbPackage()` | Builds an Agent-readable knowledge package. |
70
+ | `llmsPackage()` | Builds a text bundle for model or retrieval input. |
145
71
 
146
- ```text
147
- node_modules/@c4a/context/templates/package-templates/
148
- ```
72
+ The package also exports the Indexer schemas and validators used by Provider
73
+ authors and the Context runtime. Those APIs describe the same
74
+ `src/indexers.yaml` lifecycle; they are not a second user workflow.
75
+
76
+ Parser packages such as `@c4a/extract-ts`, `@c4a/extract-go`, and
77
+ `@c4a/extract-rush` are implementation dependencies of Indexer Providers. A
78
+ workspace does not wrap them in project phases.
79
+
80
+ ## Knowledge and package output
149
81
 
150
- The default KB template includes:
82
+ Approved pages live under `knowledge/<collection>/`. Paths and filenames are
83
+ reader-oriented, for example:
151
84
 
152
85
  ```text
153
- kb/
154
- |-- AGENTS.md
155
- |-- skills/
156
- | `-- knowledge-query/SKILL.md
157
- `-- wikis/index.md
86
+ knowledge/codeindex/tux-web/avatar.md
87
+ knowledge/architecture/tux-official-docs/react-lynx-input-fields.md
158
88
  ```
159
89
 
160
- The `knowledge-query` Skill teaches consuming Agents how to navigate indexes,
161
- inspect approved knowledge, and cite evidence. A project can add more Skills or
162
- template files under `wikis/`, `guides/`, `rules/`, and other package paths.
163
-
164
- Templates use Handlebars variables in file contents and paths. Common variables
165
- include `{{packageName}}`, `{{displayName}}`, `{{knowledgeCount}}`,
166
- `{{knowledgeGroups}}`, `{{knowledgeItems}}`, `{{knowledgeTree}}`, and
167
- `{{buildInventory}}`.
168
-
169
- Every KB package emits flat roots such as `wikis/`, `guides/`, `rules/`, and
170
- `feats/`. The package `name` defines only the `dist/<package-name>/` boundary;
171
- it is not repeated inside knowledge paths. Context still accepts
172
- `distribution.knowledgeNamespace` from older workspaces, but the legacy value
173
- no longer changes build output and new declarations do not need it. Skill names
174
- remain author-maintained and independent.
175
-
176
- New KB setup should offer `assets: { delivery: "git-raw" }` first. Build
177
- rewrites resource links to Git raw URLs; committing and publishing the resource
178
- files remains the package author's responsibility. Non-Git workspaces may use
179
- an explicit `urlPrefix`; without one they can bundle resources or explicitly
180
- omit them and retain unresolved references. Bundled delivery may
181
- install `sharp` in the workspace and configure `assets.optimize`; Context
182
- itself has no image dependency and never changes source snapshots or approved
183
- resources.
184
-
185
- For advanced routing and retrieval, a template may carry a local script such as
186
- `query.ts`, with a Skill describing when and how an Agent should call it. The
187
- Skill can also route the Agent to MCP servers, CLI commands, or other tools to
188
- form a package-specific Agentic Search workflow.
189
-
190
- Long-lived, multi-source production workspaces can copy
191
- `templates/project-skills/maintain-project-knowledge/SKILL.md` into their
192
- `.agents/skills/` directory and customize it with project ownership, source
193
- impact mappings, and readiness criteria. This project adapter is not included
194
- in knowledge packages; lifecycle authority remains with the installed Context
195
- Skill and current Route.
196
-
197
- ## State Boundary
198
-
199
- The SDK stays declarative. It may describe reads, writes, phases, review, and
200
- package selection, but the CLI owns source materialization, capture, extraction,
201
- review application, approved Markdown materialization, verification, and build.
202
- Do not replace CLI lifecycle operations with direct edits to `sources/`,
203
- `knowledge/`, `dist/`, or the ignored `.tmp/context-runtime/lifecycle/` runtime
204
- state. The CLI owns that runtime state and removes it after a successful close.
90
+ Workspace pages keep only metadata required to rebuild or update knowledge.
91
+ Package pages in `dist/` contain the smaller reader projection: useful title,
92
+ kind, summary/tags when present, and content. Internal evidence identities and
93
+ digests stay in runtime artifacts unless recovery requires them.
94
+
95
+ Package templates live under `src/package-templates/`; installed examples are
96
+ available from `node_modules/@c4a/context/templates/package-templates/`.
97
+
98
+ ## State boundary
99
+
100
+ Do not directly edit lifecycle files under `.tmp/context-runtime/`. The CLI
101
+ owns Candidate state, Review application, recovery, close, verification, and
102
+ build. Source registries, `src/index.ts`, `src/indexers.yaml`, approved
103
+ `knowledge/`, and package templates are the durable project inputs.
205
104
 
206
105
  ## Documentation
207
106
 
@@ -209,11 +108,7 @@ state. The CLI owns that runtime state and removes it after a successful close.
209
108
  - [Getting Started](./docs/getting-started.md)
210
109
  - [Agent Guide](./docs/guides/agent-guide.md)
211
110
  - [Project API](./docs/reference/project-api.md)
111
+ - [Indexer Provider Protocol](./docs/reference/indexer-provider-protocol.md)
212
112
  - [Package Outputs](./docs/guides/package-outputs.md)
213
- - [Lark Resource Materialization](./docs/guides/lark-resources.md)
214
113
  - [Package Templates](./docs/reference/package-templates.md)
215
- - [Template Variables](./docs/reference/template-variables.md)
216
114
 
217
- The [documentation index](./docs/README.md) explains which references should be
218
- read for each workflow decision. Agents should prefer Route-selected resources
219
- over preloading every manual.
package/README.zh-CN.md CHANGED
@@ -2,183 +2,106 @@
2
2
 
3
3
  [English](./README.md)
4
4
 
5
- `@c4a/context` 是 Context 知识工作区背后的声明模型。它让工作区说明哪些来源会
6
- 贡献知识、证据经过哪些处理、哪些地方需要人工审核,以及最终应该构建哪些可复用
7
- 产物。
5
+ `@c4a/context` 是 Context 知识工作区使用的声明式 SDK。多数用户通过 Context
6
+ Agent 和 CLI 工作;项目作者使用本包声明来源采集与知识包输出。
8
7
 
9
- 多数用户不需要单独安装或直接操作这个 SDK。他们从 Context Agent 入口开始,说明
10
- 知识目标;当 `src/index.ts` 需要配置时,当前工作流 Route 会引导 Agent 完成修改。
11
- 这份 README 面向知识项目作者、Agent 维护者和需要理解项目声明的开发者。
8
+ 知识生产只有一条路径:`src/indexers.yaml` 选择 Indexer Provider,并管理需求、
9
+ Profile、范围和定制。`src/index.ts` 中的项目阶段不再负责生产代码或 Markdown
10
+ 知识。
12
11
 
13
- SDK 有意保持声明式:它本身不读取来源、不写入工作区状态、不运行 Agent,也不
14
- 构建知识包。这些操作由 [Context 工作流运行时](../context-cli/README.zh-CN.md)
15
- 负责。
16
-
17
- ## 在知识生产工作流中的位置
12
+ ## 项目边界
18
13
 
19
14
  ```text
20
- 用户意图 + 来源边界
21
- ↓
22
- src/index.ts 项目声明 ← 本包
23
- ↓
24
- Context Route + Agent 判断
25
- ↓
26
- 正式知识 → 知识包产物
15
+ sources/*/index.yaml 已登记的来源边界
16
+ src/index.ts 采集与知识包声明
17
+ src/indexers.yaml 知识生产的唯一权威配置
18
+ knowledge/ 已批准、可读的知识
19
+ dist/ 面向读者的知识包产物
20
+ .tmp/context-runtime/ 可恢复运行态(不提交)
27
21
  ```
28
22
 
29
- 项目声明回答四个长期稳定的问题:
30
-
31
- - 哪些已经登记的来源边界可以贡献证据?
32
- - 存在哪些采集、提取、对齐、编译和审核阶段?
33
- - 每种产物应该选择哪些正式知识分类?
34
- - 哪些模板和资源分发策略决定最终包的结构?
23
+ `src/index.ts` 可以声明:
35
24
 
36
- 它不记录当前进度。工作区事实和随包发布的 Workflow Provider 会在运行时选择下一
37
- 条 Route,因此 `src/index.ts` 是项目契约,不是第二套状态机。
25
+ - `source()` / `allSources()` 来源引用;
26
+ - `captureFile()`、`captureLark()` 文档快照阶段;
27
+ - 不发布知识的 `customPhase()` 项目编排;
28
+ - `kbPackage()`、`llmsPackage()` 输出。
38
29
 
39
- ## 项目模型
40
-
41
- Context 项目使用“来源 → 阶段 → 知识包”的声明模型:
30
+ 示例:
42
31
 
43
32
  ```ts
44
33
  import {
34
+ captureFile,
45
35
  defineProject,
46
- extractTs,
47
36
  kbPackage,
48
- reviewValidity,
49
37
  source,
50
38
  } from "@c4a/context";
51
39
 
52
- const sampleLib = source("20260712", "sample-lib");
40
+ const docs = source("product-docs", { type: "file" });
53
41
 
54
42
  export default defineProject({
55
- sources: [sampleLib],
56
- phases: [
57
- extractTs({ source: sampleLib, collection: "codeindex" }),
58
- reviewValidity({ collection: "codeindex" }),
59
- ],
43
+ sources: [docs],
44
+ phases: [captureFile({ source: docs })],
60
45
  packages: [
61
46
  kbPackage({
62
- name: "sample-lib-kb",
63
- template: {
64
- path: "src/package-templates/kb",
65
- vars: { displayName: "Sample Library KB" },
66
- },
67
- select: { collections: ["codeindex"], okfRoots: ["wikis"] },
47
+ name: "product-kb",
48
+ template: "src/package-templates/kb",
49
+ select: { collections: ["product", "architecture"] },
68
50
  }),
69
51
  ],
70
52
  });
71
53
  ```
72
54
 
73
- `src/index.ts` 类似知识项目的构建配置:它定义哪些内容进入项目、可以经过哪些转换
74
- 和门禁,以及最终能够构建什么产物。安装好的 Agent 入口保持精简,当前工作流
75
- Route 会按需选择维护这份声明所需的操作说明、Schema 和手册。
55
+ Context 生命周期负责发现或更新 `src/indexers.yaml`、运行选中的 Provider、展示可读
56
+ Candidate 供审核、只写入批准后的知识,最后构建声明的知识包。
76
57
 
77
58
  ## 主要 API
78
59
 
79
60
  | API | 用途 |
80
61
  |---|---|
81
- | `defineProject()` | 声明完整的项目处理图。 |
82
- | `source()` 和 `allSources()` | 引用已经登记的代码仓库、本地文件或飞书来源边界。 |
83
- | `extractTs()` | 从 TypeScript/JavaScript 与 TSX/JSX 中提取符号和关系,生成 `codeindex` 候选。 |
84
- | `extractCustom()` | 运行项目自有代码提取器,同时由 Context 维护候选、证据、新鲜度和审核状态。 |
85
- | `alignProse()` 和 `compileProse()` | 仅为既有工作区迁移和修复保留的显式阶段工厂;新工作区使用 `src/indexers.yaml` 与统一 Indexer 生命周期。 |
86
- | `reviewValidity()` | 声明单个知识类型或整个项目的审核门禁。 |
87
- | `customPhase()` | 在内置阶段无法覆盖时增加项目专用编排。 |
88
- | `kbPackage()` | 使用审核通过的知识和模板构建 Agent 知识库。 |
89
- | `llmsPackage()` | 构建供模型上下文或 RAG 导入使用的单文件文本包。 |
90
-
91
- 非 TypeScript 或需要聚合代码事实时使用 `extractCustom()`。`customPhase()`
92
- 只用于不发布知识候选的项目专用编排,不能绕开来源、提取、审核和打包生命周期。
93
-
94
- Context CLI 不会把所有语言和仓库解析器都打入自身。知识项目可以按需安装结构
95
- 提取库,并在 `extractCustom()` 中使用:
96
-
97
- | 包 | 提供的结构事实 |
98
- |---|---|
99
- | `@c4a/extract-go` | Go 声明、导入、调用和常见 HTTP 路由注册 |
100
- | `@c4a/extract-rush` | Rush 项目、标签、入口信号、工作区依赖和所有者边界 |
101
- | `@c4a/extract-ts` | TypeScript 提取,以及可复用的 React Router 路由事实 |
102
-
103
- 这些库本身不会创建 Context 阶段或候选。项目负责把确定性事实映射为自己的候选
104
- 身份和审核摘要;证据校验、新鲜度、审核、close 和打包仍由 Context 管理。
105
-
106
- ## 知识分类
107
-
108
- 审核通过的 Markdown 会存放在 `knowledge/<collection>/`:
62
+ | `defineProject()` | 声明项目边界。 |
63
+ | `source()` / `allSources()` | 引用已登记的代码仓库、本地文件或飞书来源。 |
64
+ | `captureFile()` / `captureLark()` | 生成确定性的文档快照。 |
65
+ | `mdxJsonDocs()` | 配置 MDX/JSON 文档采集处理器。 |
66
+ | `customPhase()` | 执行不生产知识的项目编排。 |
67
+ | `kbPackage()` | 构建 Agent 可读的知识包。 |
68
+ | `llmsPackage()` | 构建供模型或检索使用的文本包。 |
109
69
 
110
- | 知识类型 | 主要内容 | 常见来源 |
111
- |---|---|---|
112
- | `codeindex` | 代码符号、模块和调用关系 | 代码仓库 |
113
- | `business` | 业务概念、角色和业务关系 | 业务文档、飞书文档 |
114
- | `product` | 产品能力、功能行为和产品关系 | 产品文档、需求文档 |
115
- | `architecture` | 系统结构、模块职责和设计说明 | 架构文档、设计文档 |
116
- | `sop` | 操作流程、运行手册和处理步骤 | 操作手册、值班文档 |
117
- | `faq` | 常见问题、解释和排障方法 | FAQ、支持文档、经验记录 |
118
- | `decision` | 方案选择、取舍和决策背景 | 设计评审、决策记录 |
119
- | `incident` | 故障过程、处置方式和后续行动 | 故障复盘、事故报告 |
120
- | `standards` | 必须遵守的规范和约束 | 研发规范、业务规则 |
121
- | `test` | 验证规则、测试场景和验收标准 | 测试文档、验收说明 |
122
- | `feats` | 面向具体场景整理的能力记录 | 项目自定义处理和已确认知识 |
70
+ 本包也导出 Provider 作者和 Context 运行时使用的 Indexer Schema 与校验器。它们
71
+ 描述的仍是同一套 `src/indexers.yaml` 生命周期,不是第二条用户流程。
123
72
 
124
- 知识类型是语义分类,不是最终知识包目录。构建时会把选中的类型映射到 `wikis/`、`guides/`、`rules/`、`feats/` 等 OKF 目录。同一份来源可能贡献多种知识,分类应该依据证据和用户确认,而不是文件名。
73
+ `@c4a/extract-ts`、`@c4a/extract-go`、`@c4a/extract-rush` 等解析包属于
74
+ Indexer Provider 的实现依赖,工作区不再把它们包装成项目阶段。
125
75
 
126
- ## 知识包模板
76
+ ## 知识与知识包
127
77
 
128
- 知识包声明会引用 `src/package-templates/` 下的可编辑模板。安装后的示例位于:
78
+ 批准后的知识位于 `knowledge/<collection>/`,目录和文件名面向人阅读,例如:
129
79
 
130
80
  ```text
131
- node_modules/@c4a/context/templates/package-templates/
81
+ knowledge/codeindex/tux-web/avatar.md
82
+ knowledge/architecture/tux-official-docs/react-lynx-input-fields.md
132
83
  ```
133
84
 
134
- 默认 KB 模板包含:
135
-
136
- ```text
137
- kb/
138
- |-- AGENTS.md
139
- |-- skills/
140
- | `-- knowledge-query/SKILL.md
141
- `-- wikis/index.md
142
- ```
143
-
144
- `knowledge-query` Skill 会告诉消费知识包的 Agent 如何浏览索引、读取审核通过的知识并引用证据。项目还可以增加更多 Skills,或者在 `wikis/`、`guides/`、`rules/` 等目录中加入模板文件。
145
-
146
- 模板使用 Handlebars 变量,可以作用于文件内容和路径。常用变量包括 `{{packageName}}`、`{{displayName}}`、`{{knowledgeCount}}`、`{{knowledgeGroups}}`、`{{knowledgeItems}}`、`{{knowledgeTree}}` 和 `{{buildInventory}}`。
147
-
148
- 每个 KB 包直接输出扁平的 `wikis/`、`guides/`、`rules/`、`feats/` 等根目录;包 `name`
149
- 只用于确定 `dist/<package-name>/` 边界,不会再次写入知识路径。旧工作区中的
150
- `distribution.knowledgeNamespace` 仍可被读取,但不再改变构建结果;新声明无需配置它。
151
- Skill 名称继续由作者独立维护。
152
-
153
- 新建 KB 时优先选择 `assets: { delivery: "git-raw" }`:构建器把资源链接改写到
154
- Git raw 地址;资源的提交和发布由知识包作者负责,Context 不做远端探测。
155
- 非 Git 工作区也可以配置显式 `urlPrefix`,引用另一个仓库已经发布的资源;没有
156
- 可用 Git 或显式前缀时,可选择 `delivery: "bundle"` 随包分发,或显式选择
157
- `delivery: "omit"` 不输出资源并保留失效引用。随包分发还可以在工作区安装 `sharp` 并通过
158
- `assets.optimize` 仅优化生成的知识包;Context 本身不依赖图片处理库。
159
-
160
- 如果需要更强的路由和检索能力,模板可以携带 `query.ts` 一类本地脚本,再由 Skill 约定 Agent 何时、如何调用。Skill 也可以把 Agent 路由到 MCP、CLI 或其他工具,组成适合当前知识包的 Agentic Search 流程。
85
+ 工作区页面只保留后续重建或更新所需的元数据。`dist/` 中的知识包页面使用更小的
86
+ 读者投影:有用的标题、类型、摘要/标签(存在时)和正文。内部证据 ID 与摘要除非
87
+ 恢复需要,否则只留在运行时 Artifact 中。
161
88
 
162
- 长期维护、多来源的知识生产工作区可以从
163
- `templates/project-skills.zh-CN/maintain-project-knowledge/SKILL.md` 复制一份
164
- 项目维护 Skill 到 `.agents/skills/`。它不进入知识包,而是补充项目专属的来源
165
- 归属、仓库变化影响范围和准出标准;Context 生命周期仍由已安装的 Context Skill
166
- 和当前 Route 负责。
89
+ 知识包模板位于 `src/package-templates/`;安装后的示例位于
90
+ `node_modules/@c4a/context/templates/package-templates/`。
167
91
 
168
92
  ## 状态边界
169
93
 
170
- SDK 只负责声明。它可以描述读取、写入、阶段、审核和知识包选择,但来源物化、内容读取、代码提取、审核应用、正式知识写入、质量验证和构建都由 CLI 负责。不要通过直接编辑 `sources/`、`knowledge/`、`dist/` 或被忽略的 `.tmp/context-runtime/lifecycle/` 运行态来替代 CLI 生命周期操作;成功 close 后 CLI 会清理该运行态。
94
+ 不要直接修改 `.tmp/context-runtime/` 下的生命周期文件。Candidate 状态、审核应用、
95
+ 恢复、close、验证与构建由 CLI 管理。来源注册表、`src/index.ts`、
96
+ `src/indexers.yaml`、批准后的 `knowledge/` 和知识包模板才是长期项目输入。
171
97
 
172
98
  ## 参考文档
173
99
 
174
- - [文档索引](./docs/README.md)
100
+ - [文档索引](./docs/README.zh-CN.md)
175
101
  - [快速开始](./docs/getting-started.md)
176
102
  - [Agent 指南](./docs/guides/agent-guide.md)
177
103
  - [项目 API](./docs/reference/project-api.md)
104
+ - [Indexer Provider 协议](./docs/reference/indexer-provider-protocol.md)
178
105
  - [知识包输出](./docs/guides/package-outputs.md)
179
- - [飞书资源物化](./docs/guides/lark-resources.md)
180
106
  - [知识包模板](./docs/reference/package-templates.md)
181
- - [模板变量](./docs/reference/template-variables.md)
182
107
 
183
- [文档索引](./docs/README.zh-CN.md)说明每类工作流决策应该查看哪些参考资料。Agent
184
- 应优先读取 Route 选择的资源,不要预加载整套手册。
package/docs/README.md CHANGED
@@ -8,8 +8,8 @@ These docs ship inside the installed SDK package at:
8
8
  node_modules/@c4a/context/docs/
9
9
  ```
10
10
 
11
- These manuals explain how a knowledge project declares sources, processing,
12
- review, and package output. They are references inside the larger Agent-driven
11
+ These manuals explain how a knowledge project declares sources, capture,
12
+ Indexer selection, Review, and package output. They are references inside the larger Agent-driven
13
13
  workflow, not a second set of lifecycle instructions.
14
14
 
15
15
  For active knowledge production, start through the installed Context Agent
@@ -24,7 +24,7 @@ preload the whole manual set.
24
24
  |---|---|
25
25
  | Understand the whole knowledge-project shape | [Getting Started](./getting-started.md) |
26
26
  | Know what the Agent may decide or change | [Agent Guide](./guides/agent-guide.md) and [Agent Dialogue](./guides/agent-dialogue.md) |
27
- | Configure sources, phases, review, or packages | [Project API](./reference/project-api.md) |
27
+ | Configure sources, capture, Indexers, or packages | [Project API](./reference/project-api.md) |
28
28
  | Author or inspect an Indexer Provider protocol | [Indexer Provider Protocol](./reference/indexer-provider-protocol.md) |
29
29
  | Select or customize an Indexer Provider | [Provider Selection and Customization](./guides/indexer-provider-and-customization.md) |
30
30
  | Author a Code or Markdown Indexer Skill | [Code Indexer Authoring](./guides/code-indexer-skill-authoring.md) and [Markdown Indexer Authoring](./guides/markdown-indexer-skill-authoring.md) |
@@ -40,7 +40,7 @@ preload the whole manual set.
40
40
  - [Agent Dialogue](./guides/agent-dialogue.md) — stable dialogue principles and how route-selected gate resources are discovered.
41
41
  - [Package Outputs](./guides/package-outputs.md) — how to choose between an agent knowledge-base package, LLM text, or no package output.
42
42
  - [Lark Resource Materialization](./guides/lark-resources.md) — how embedded resources move from source evidence to approved knowledge and package assets.
43
- - [Project API](./reference/project-api.md) — `defineProject`, sources, phases, review, and packages.
43
+ - [Project API](./reference/project-api.md) — `defineProject`, sources, capture, Indexers, and packages.
44
44
  - [Indexer Provider Protocol](./reference/indexer-provider-protocol.md) — manifest, controlled execution, detector/inspector I/O, customization, and staged project apply.
45
45
  - [Provider Selection and Customization](./guides/indexer-provider-and-customization.md) — registry-only selection, the six-level customization ladder, upgrade conflicts, debugging, and completion conditions.
46
46
  - [Code Indexer Authoring](./guides/code-indexer-skill-authoring.md) — the 23-point Provider Skill release contract and anonymous fixture expectations.
@@ -49,12 +49,11 @@ preload the whole manual set.
49
49
  - [Package Templates](./reference/package-templates.md) — `kbPackage`, `llmsPackage`, template variables, and examples.
50
50
  - [Template Variables](./reference/template-variables.md) — Handlebars variables, loops, comments, and default knowledge inventories.
51
51
 
52
- Approved Markdown follows the complete Context production profile. Package
53
- knowledge pages use a smaller consumer projection containing only reader-facing
54
- metadata and content. Node identity, provenance, section evidence, review
55
- fingerprints, symbol lists, generated-child records, and relationships remain in
56
- the production workspace or `context-build-inventory.json`. The inventory maps
57
- each distributed path back to its approved knowledge path. The kb package root may contain agent files; the
52
+ Approved Markdown keeps reader-facing content plus the minimum metadata needed
53
+ to update or rebuild it. Package knowledge pages use an even smaller consumer
54
+ projection. Internal evidence IDs, execution receipts, and transient Review
55
+ state stay in local runtime artifacts. The build inventory maps each distributed
56
+ path back to its approved knowledge path. The kb package root may contain agent files; the
58
57
  OKF-compatible surface is its selected `wikis/`, `guides/`, `rules/`, and
59
58
  `feats/` subtrees.
60
59
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  [English](./README.md)
4
4
 
5
- 这些手册说明知识项目如何声明来源、处理过程、审核和知识包产物。它们是 Agent
5
+ 这些手册说明知识项目如何声明来源、采集、Indexer 选择、审核和知识包产物。它们是 Agent
6
6
  驱动工作流中的参考资料,不是另一套生命周期指令。
7
7
 
8
8
  进行知识生产时,应先从已安装的 Context Agent 入口开始。Agent 优先消费
@@ -15,7 +15,7 @@
15
15
  |---|---|
16
16
  | 理解完整知识项目的形态 | [Getting Started](./getting-started.md) |
17
17
  | 判断 Agent 可以决定或修改什么 | [Agent Guide](./guides/agent-guide.md) 和 [Agent Dialogue](./guides/agent-dialogue.md) |
18
- | 配置来源、阶段、审核或产物 | [Project API](./reference/project-api.md) |
18
+ | 配置来源、采集、Indexer 或产物 | [Project API](./reference/project-api.md) |
19
19
  | 选择或定制 Indexer Provider | [Provider Selection and Customization](./guides/indexer-provider-and-customization.md) |
20
20
  | 编写 Code/Markdown Indexer Skill | [Code Indexer Authoring](./guides/code-indexer-skill-authoring.md) 和 [Markdown Indexer Authoring](./guides/markdown-indexer-skill-authoring.md) |
21
21
  | 选择代码提取方式 | [Code Extractor Selection](./reference/code-extractors.md) |
@@ -30,7 +30,7 @@
30
30
  - [Agent Dialogue](./guides/agent-dialogue.md):稳定的对话原则和 Route-selected Gate 资源发现方式。
31
31
  - [Package Outputs](./guides/package-outputs.md):如何选择 Agent 知识包、LLM 文本或不构建产物。
32
32
  - [Lark Resource Materialization](./guides/lark-resources.md):内嵌资源如何从来源证据进入正式知识和知识包。
33
- - [Project API](./reference/project-api.md):`defineProject`、来源、阶段、审核和知识包声明。
33
+ - [Project API](./reference/project-api.md):`defineProject`、来源、采集、Indexer 和知识包声明。
34
34
  - [Provider Selection and Customization](./guides/indexer-provider-and-customization.md):registry-only 选择、六级最小定制阶梯、升级冲突、调试与退出条件。
35
35
  - [Code Indexer Authoring](./guides/code-indexer-skill-authoring.md):Code Provider Skill 的 23 项作者/发布契约。
36
36
  - [Markdown Indexer Authoring](./guides/markdown-indexer-skill-authoring.md):capture/semantic 边界、Section 投影、material answer、编辑策略与局部增量。
@@ -38,10 +38,9 @@
38
38
  - [Package Templates](./reference/package-templates.md):`kbPackage`、`llmsPackage`、模板变量和示例。
39
39
  - [Template Variables](./reference/template-variables.md):Handlebars 变量、循环、注释和默认知识清单。
40
40
 
41
- 正式 Markdown 使用完整的 Context production profile。知识包内的知识页只保留
42
- 面向读者的元数据和正文;Node 身份、来源、Section 证据、审核指纹、符号清单、
43
- 生成子项和关系继续留在生产工作区或 `context-build-inventory.json` 中。构建清单
44
- 将每个分发路径映射回正式知识路径。知识包根目录可以包含 Agent 文件;可交换知识
41
+ 正式 Markdown 保留面向读者的内容和后续更新、重建所需的最少元数据。知识包内的
42
+ 知识页使用更小的读者投影;内部证据 ID、执行回执和临时审核状态只留在本地运行态。
43
+ 构建清单将每个分发路径映射回正式知识路径。知识包根目录可以包含 Agent 文件;可交换知识
45
44
  位于所选的 `wikis/`、`guides/`、`rules/` 和 `feats/` 子树。
46
45
 
47
46
  ## 已安装模板