@c4a/context 0.6.1 → 0.6.2
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.
- package/README.md +17 -6
- package/README.zh-CN.md +121 -0
- package/contracts.d.ts +5 -0
- package/docs/README.md +11 -8
- package/docs/getting-started.md +63 -28
- package/docs/guides/agent-dialogue.md +38 -350
- package/docs/guides/agent-guide.md +143 -93
- package/docs/guides/package-outputs.md +87 -25
- package/docs/reference/package-templates.md +121 -32
- package/docs/reference/project-api.md +225 -84
- package/docs/reference/template-variables.md +32 -15
- package/index.d.ts +13 -5
- package/index.js +99 -28
- package/package.json +1 -1
- package/phases.d.ts +65 -6
- package/templates/package-templates/kb/AGENTS.md +13 -16
- package/templates/package-templates/kb/skills/knowledge-query/SKILL.md +101 -177
- package/templates/package-templates/kb/skills/knowledge-query/scripts/search.mjs +264 -0
- package/templates/package-templates/kb/wikis/index.md +8 -8
- package/templates/package-templates.zh-CN/kb/AGENTS.md +30 -0
- package/templates/package-templates.zh-CN/kb/skills/knowledge-query/SKILL.md +99 -0
- package/templates/package-templates.zh-CN/kb/skills/knowledge-query/scripts/search.mjs +264 -0
- package/templates/package-templates.zh-CN/kb/wikis/index.md +39 -0
- package/templates/package-templates.zh-CN/llms/llms.txt +8 -0
|
@@ -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,54 @@ 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 | Legacy input accepted from older workspaces. It no longer changes package paths and should not be added to new declarations. |
|
|
50
56
|
|
|
51
57
|
`template` is required. Do not call `kbPackage({ name })` or
|
|
52
58
|
`llmsPackage({ name })`.
|
|
53
59
|
|
|
60
|
+
## Flat Package Roots
|
|
61
|
+
|
|
62
|
+
`name` identifies the package boundary under `dist/`. Context does not repeat
|
|
63
|
+
that name inside the package's knowledge roots.
|
|
64
|
+
|
|
65
|
+
Templates keep a logical, consumer-neutral layout:
|
|
66
|
+
|
|
67
|
+
```text
|
|
68
|
+
skills/knowledge-query/SKILL.md
|
|
69
|
+
wikis/index.md
|
|
70
|
+
guides/...
|
|
71
|
+
rules/...
|
|
72
|
+
feats/...
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
For `name: "component-lib-kb"`, `context build` writes:
|
|
76
|
+
|
|
77
|
+
```text
|
|
78
|
+
skills/knowledge-query/SKILL.md
|
|
79
|
+
wikis/index.md
|
|
80
|
+
guides/...
|
|
81
|
+
rules/...
|
|
82
|
+
feats/...
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The builder maps copied knowledge, generated indexes, links, and inventory
|
|
86
|
+
records into these roots without rewriting Markdown prose or inferring a
|
|
87
|
+
downstream registry identity. New declarations should omit `distribution`.
|
|
88
|
+
Older declarations that still contain `distribution.knowledgeNamespace` remain
|
|
89
|
+
loadable, but the value does not change output paths or the build fingerprint.
|
|
90
|
+
|
|
91
|
+
Use `{{wikisRoot}}`, `{{rulesRoot}}`, `{{guidesRoot}}`, or `{{featsRoot}}` in
|
|
92
|
+
Skill templates so references share the package-root contract. These variables
|
|
93
|
+
render to the flat root names above.
|
|
94
|
+
|
|
95
|
+
Each rendered Skill must live at `skills/<skill-name>/SKILL.md`, and its YAML
|
|
96
|
+
frontmatter `name` must equal `<skill-name>`. Use `{{skillName}}` in custom
|
|
97
|
+
Skill templates. Skill names are author-maintained: when a short prefix is
|
|
98
|
+
useful, rename the template directory to the complete final name, such as
|
|
99
|
+
`skills/android-query/`; Context does not derive it from
|
|
100
|
+
the package name.
|
|
101
|
+
|
|
54
102
|
## Template Variables
|
|
55
103
|
|
|
56
104
|
Templates are rendered with Handlebars. Variables are available in both file
|
|
@@ -62,6 +110,11 @@ Built-in variables:
|
|
|
62
110
|
|---|---|
|
|
63
111
|
| `{{packageName}}` | Package name from the declaration. |
|
|
64
112
|
| `{{packageKind}}` | `kb` or `llms`. |
|
|
113
|
+
| `{{knowledgeNamespace}}` | Legacy configured namespace when an older workspace still declares one; otherwise empty. Do not use it for new output paths. |
|
|
114
|
+
| `{{namespacedKnowledge}}` | Always `false`; retained only so older templates remain renderable. |
|
|
115
|
+
| `{{skillName}}` | Current author-maintained Skill directory name. |
|
|
116
|
+
| `{{skillPath}}` | Current Skill's final package-relative `SKILL.md` path. |
|
|
117
|
+
| `{{wikisRoot}}`, `{{guidesRoot}}`, `{{rulesRoot}}`, `{{featsRoot}}` | Final package-relative OKF root paths. |
|
|
65
118
|
| `{{displayName}}` | Display name. Defaults to a title-cased `packageName`; override with `template.vars.displayName`. |
|
|
66
119
|
| `{{knowledgeCount}}` | Number of selected approved Markdown files. |
|
|
67
120
|
| `{{knowledgeTimestamp}}` | Latest `timestamp` from selected approved Markdown, or `1970-01-01T00:00:00.000Z` when empty. |
|
|
@@ -72,7 +125,7 @@ Built-in variables:
|
|
|
72
125
|
| `{{knowledgeTreeNodes}}` | Nested path tree for custom navigation. |
|
|
73
126
|
| `{{knowledgeTree}}` | Markdown tree preview. |
|
|
74
127
|
| `{{knowledgeItemsMarkdown}}` | Markdown page list. |
|
|
75
|
-
| `{{knowledgeGroupsMarkdown}}` | Markdown
|
|
128
|
+
| `{{knowledgeGroupsMarkdown}}` | Markdown navigation for the current index: direct page links for folded directories and links to generated indexes for expanded directories. |
|
|
76
129
|
|
|
77
130
|
Custom variables come from `template.vars`.
|
|
78
131
|
|
|
@@ -98,7 +151,9 @@ src/package-templates/
|
|
|
98
151
|
│ │ └── index.md
|
|
99
152
|
│ └── skills/
|
|
100
153
|
│ └── knowledge-query/
|
|
101
|
-
│
|
|
154
|
+
│ ├── SKILL.md
|
|
155
|
+
│ └── scripts/
|
|
156
|
+
│ └── search.mjs
|
|
102
157
|
└── llms/
|
|
103
158
|
└── llms.txt
|
|
104
159
|
```
|
|
@@ -116,22 +171,30 @@ The default kb template includes:
|
|
|
116
171
|
query copied knowledge pages structure-first, cite page/section evidence, use
|
|
117
172
|
`context-build-inventory.json` edge records for package-visible
|
|
118
173
|
relationships, and report gaps instead of inventing unsupported answers. The
|
|
174
|
+
build inventory also exposes `structure.relationship_coverage` so a consumer
|
|
175
|
+
can distinguish an observed zero-edge result from unknown relationship
|
|
176
|
+
coverage. The
|
|
119
177
|
default entry OKF root is `wikis/`; packages that select additional internal
|
|
120
178
|
collections expose
|
|
121
179
|
`guides/`, `rules/`, or `feats/` indexes when those roots are selected.
|
|
180
|
+
- `skills/knowledge-query/scripts/search.mjs`, a dependency-free BM25 fallback
|
|
181
|
+
for exact terms, mixed keyword queries, and large Markdown indexes. It chunks
|
|
182
|
+
mechanically, returns inspectable paths and line ranges, and never replaces
|
|
183
|
+
source-backed relationship evidence.
|
|
122
184
|
- `wikis/index.md`, the editable OKF bundle entry page for the generated
|
|
123
185
|
`dist/<package-name>/wikis/` directory.
|
|
124
186
|
|
|
125
187
|
During `context build`, the root `wikis/index.md` is rendered from the template.
|
|
126
|
-
The builder
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
188
|
+
The builder always provides an index for every selected OKF root. With the
|
|
189
|
+
default navigation policy, smaller child directories are folded into their
|
|
190
|
+
nearest generated ancestor index, so a short collection can link directly to
|
|
191
|
+
its pages instead of producing one index per path segment.
|
|
130
192
|
|
|
131
193
|
## OKF Directory Indexes
|
|
132
194
|
|
|
133
|
-
The generated
|
|
134
|
-
|
|
195
|
+
The generated
|
|
196
|
+
`dist/<package-name>/wikis/` tree is the required default
|
|
197
|
+
KB entry surface. Internal collections are mapped into OKF roots during build:
|
|
135
198
|
`codegraph`, `business`, and `product` go to `wikis/`; `architecture`, `sop`,
|
|
136
199
|
`faq`, `decision`, and `incident` go to `guides/`; `standards` and `test` go to
|
|
137
200
|
`rules/`; and `feats` goes to `feats/`. Treat `wikis/` as the structured
|
|
@@ -141,39 +204,48 @@ a relationship.
|
|
|
141
204
|
|
|
142
205
|
Default navigation rules:
|
|
143
206
|
|
|
144
|
-
- `wikis/index.md` is the required default bundle index.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
`
|
|
207
|
+
- `wikis/index.md` is the required default bundle index. Other selected OKF
|
|
208
|
+
roots always use their own `<okf-root>/index.md`.
|
|
209
|
+
- With `foldDirectoryIndexes: true`, a non-root directory gets its own
|
|
210
|
+
`index.md` only when its descendant knowledge-page count is greater than
|
|
211
|
+
`maxInlineEntries`. The default threshold is `50`.
|
|
212
|
+
- A folded directory is not discarded. Its pages are listed in the nearest
|
|
213
|
+
generated ancestor index, grouped by their relative directory path.
|
|
214
|
+
- The threshold counts selected knowledge pages in the path tree. It does not
|
|
215
|
+
inspect Markdown line counts, headings, or content semantics.
|
|
216
|
+
- Set `foldDirectoryIndexes: false` to generate an `index.md` for every
|
|
217
|
+
directory, matching the fully expanded navigation shape.
|
|
149
218
|
- A generated directory index uses OKF frontmatter with `type: Knowledge
|
|
150
219
|
Directory`, `title`, `description`, `tags`, `timestamp`, `resource`,
|
|
151
220
|
`package`, `package_kind`, and `knowledge_count`.
|
|
152
|
-
- Directory indexes list child
|
|
153
|
-
|
|
221
|
+
- Directory indexes list generated child indexes first, then pages from folded
|
|
222
|
+
paths.
|
|
154
223
|
- `context build` validates links in OKF root indexes and generated
|
|
155
224
|
child `index.md` files. Relative links must resolve to files inside
|
|
156
225
|
`dist/<package-name>/`; broken links are reported as
|
|
157
226
|
`package/index-link-invalid`.
|
|
158
227
|
- If a project needs curated default navigation, edit the template-owned
|
|
159
|
-
`wikis/index.md`.
|
|
160
|
-
|
|
161
|
-
|
|
228
|
+
`wikis/index.md`. Template files or copied knowledge pages that collide with
|
|
229
|
+
an index path selected by the current navigation policy are rejected during
|
|
230
|
+
build/status preflight.
|
|
162
231
|
|
|
163
|
-
|
|
164
|
-
`src/package-templates/kb/**`
|
|
165
|
-
specific skills, prompts, routing rules,
|
|
166
|
-
package
|
|
167
|
-
|
|
232
|
+
The generated templates are complete generic defaults. Before publishing,
|
|
233
|
+
package authors should replace or edit `src/package-templates/kb/**` when the
|
|
234
|
+
package needs project-specific skills, prompts, routing rules, terminology, or
|
|
235
|
+
package instructions. If the generic behavior is intentionally sufficient,
|
|
236
|
+
explicitly accept the unchanged default through the package-template Review
|
|
237
|
+
Route. Do not add a package-name Skill by default; add one only when the user
|
|
238
|
+
wants project-specific behavior beyond knowledge lookup.
|
|
168
239
|
|
|
169
|
-
##
|
|
240
|
+
## Context OKF Profiles
|
|
170
241
|
|
|
171
|
-
Approved Markdown
|
|
242
|
+
Approved Markdown under `knowledge/` is the production source of truth:
|
|
172
243
|
|
|
173
244
|
- top-level YAML frontmatter uses OKF fields such as `type`, `title`,
|
|
174
245
|
`description`, `tags`, `timestamp`, and `resource`;
|
|
175
|
-
-
|
|
176
|
-
|
|
246
|
+
- Context production metadata such as `sources`, `node_type`, `visibility`,
|
|
247
|
+
`code_symbols`, relationship records, and `candidate_fingerprint` also lives
|
|
248
|
+
at the top level;
|
|
177
249
|
- do not nest C4A extension metadata under `context`; fields such as
|
|
178
250
|
`context.sources` and `context.code_symbols` are not part of the 0.6 profile;
|
|
179
251
|
- section provenance lives in `<!-- context:section ... source_ref="..." -->`
|
|
@@ -182,6 +254,15 @@ Approved Markdown and kb package OKF output are an OKF superset:
|
|
|
182
254
|
section source refs when needed;
|
|
183
255
|
- do not add `context` or `schema` fields.
|
|
184
256
|
|
|
257
|
+
Package knowledge pages under `dist/<package-name>/` use a consumer projection.
|
|
258
|
+
They retain reader-facing fields such as `title`, `type`, `description`, `tags`,
|
|
259
|
+
`timestamp`, and custom non-lifecycle fields. Node identity, `resource`,
|
|
260
|
+
`sources`, Section evidence comments, and build-only fields are omitted from the
|
|
261
|
+
page. `context-build-inventory.json` records the distributed path, approved
|
|
262
|
+
knowledge path, node identity, source summary, and package-visible structure.
|
|
263
|
+
Maintainers return to the mapped `knowledge/` page for exact `sources` and
|
|
264
|
+
`source_ref` attribution. `knowledge/` is never rewritten by this projection.
|
|
265
|
+
|
|
185
266
|
Accepted section `source_ref` forms:
|
|
186
267
|
|
|
187
268
|
```text
|
|
@@ -191,7 +272,7 @@ src-N#span:<heading-hint> L<start>-<end>@<span-hash>
|
|
|
191
272
|
|
|
192
273
|
The code symbol form includes the source-relative file so same-name symbols in
|
|
193
274
|
different files resolve to one exact symbol-index row. Consumers should still
|
|
194
|
-
treat the complete `source_ref` as opaque.
|
|
275
|
+
treat the complete `source_ref` as opaque. Production codegraph pages keep
|
|
195
276
|
`candidate_fingerprint` at the top level and do not duplicate this evidence in
|
|
196
277
|
`code_origin`.
|
|
197
278
|
|
|
@@ -209,7 +290,7 @@ The OKF-compatible surface is the selected `wikis/`, `guides/`, `rules/`, and
|
|
|
209
290
|
|
|
210
291
|
1. Selects approved Markdown from `knowledge/`.
|
|
211
292
|
2. Renders all files from `template.path`.
|
|
212
|
-
3.
|
|
293
|
+
3. Projects selected approved Markdown into consumer-oriented package pages.
|
|
213
294
|
4. For `llmsPackage`, appends selected knowledge to `llms.txt` when the template
|
|
214
295
|
does not already use `{{knowledge}}` or `{{approvedKnowledge}}`.
|
|
215
296
|
5. Writes deterministic package inventory such as
|
|
@@ -217,7 +298,9 @@ The OKF-compatible surface is the selected `wikis/`, `guides/`, `rules/`, and
|
|
|
217
298
|
6. Writes output under `dist/<package-name>/`.
|
|
218
299
|
|
|
219
300
|
`context-build-inventory.json` records what was selected and why. Each selected
|
|
220
|
-
file includes `selected_by` entries such as `{ "kind": "collection" }
|
|
301
|
+
file includes `selected_by` entries such as `{ "kind": "collection" }` and a
|
|
302
|
+
`production_metadata` object for selected page-level production fields. Child
|
|
303
|
+
and relationship records use the inventory's canonical structure projection,
|
|
221
304
|
`{ "kind": "okf_root" }`, `{ "kind": "include" }`, or
|
|
222
305
|
`{ "kind": "default" }`. The inventory also exposes package-visible typed
|
|
223
306
|
edges under `structure.edge_records`; these records are filtered to edges whose
|
|
@@ -225,9 +308,15 @@ endpoints are present in the selected package. Use those edge records for
|
|
|
225
308
|
relationship citations inside the package instead of assuming the workspace
|
|
226
309
|
`knowledge/structure.yaml` file is bundled.
|
|
227
310
|
|
|
311
|
+
For KB packages, the inventory records `package.distribution` as
|
|
312
|
+
`layout: "flat"`, `knowledge_namespace: null`, and the four package-relative
|
|
313
|
+
OKF roots. Selected file and group records expose both the logical `okf_root`
|
|
314
|
+
and final `okf_root_path`, so consumers do not need to infer paths.
|
|
315
|
+
|
|
228
316
|
Build expects approved knowledge to be closed when the project has source-bound
|
|
229
|
-
document knowledge.
|
|
230
|
-
`
|
|
317
|
+
document knowledge. When `workflow.current.reason_code` is
|
|
318
|
+
`route.close.projection-stale`, run the exact returned close command. Current
|
|
319
|
+
close derives
|
|
231
320
|
`knowledge/structure.yaml`, persists approved edge projection, and runs the
|
|
232
321
|
final verify gate. References, changelog, package index, and section
|
|
233
322
|
fingerprint rebuilds are not current close output; build only packages the
|