@c4a/context 0.6.0-alpha.1
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 +100 -0
- package/contracts.d.ts +31 -0
- package/docs/README.md +39 -0
- package/docs/getting-started.md +320 -0
- package/docs/guides/agent-dialogue.md +325 -0
- package/docs/guides/agent-guide.md +313 -0
- package/docs/guides/package-outputs.md +171 -0
- package/docs/reference/package-templates.md +274 -0
- package/docs/reference/project-api.md +326 -0
- package/docs/reference/template-variables.md +225 -0
- package/documentEvidence.d.ts +17 -0
- package/index.d.ts +55 -0
- package/index.js +11810 -0
- package/package.json +11 -0
- package/phases.d.ts +169 -0
- package/sources.d.ts +138 -0
- package/templates/package-templates/kb/AGENTS.md +31 -0
- package/templates/package-templates/kb/skills/knowledge-query/SKILL.md +204 -0
- package/templates/package-templates/kb/wikis/index.md +43 -0
- package/templates/package-templates/llms/llms.txt +9 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
# Project API
|
|
2
|
+
|
|
3
|
+
Import from `@c4a/context` in `src/index.ts`.
|
|
4
|
+
|
|
5
|
+
## `defineProject`
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { defineProject } from "@c4a/context";
|
|
9
|
+
|
|
10
|
+
export default defineProject({
|
|
11
|
+
sources: [],
|
|
12
|
+
phases: [],
|
|
13
|
+
packages: [],
|
|
14
|
+
});
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The project file is executable TypeScript, but the preferred style is a small
|
|
18
|
+
declaration list. Put heavy logic in imported transform files.
|
|
19
|
+
|
|
20
|
+
## Sources
|
|
21
|
+
|
|
22
|
+
A source is a stable knowledge boundary, not only a display label. The source
|
|
23
|
+
name becomes a stable identity in source references, phase ids, and package
|
|
24
|
+
naming. Approved knowledge paths are derived from collection, containment, and slug. NodeRef/ViewRef are identity fields, not path strings:
|
|
25
|
+
|
|
26
|
+
```text
|
|
27
|
+
knowledge/<collection>/<containment>/<slug>.md
|
|
28
|
+
repo:<source-name>#symbol:...
|
|
29
|
+
file:<source-name>/<document>#span:...
|
|
30
|
+
lark:<source-name>/<document>#span:...
|
|
31
|
+
capture:file:<source-name>
|
|
32
|
+
align:lark:<source-name>:architecture
|
|
33
|
+
dist/<source-name>-kb/...
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Choose the boundary before extraction. In a monorepo, a source can be the whole
|
|
37
|
+
repo/subspace when the user wants one unified knowledge product, or a specific
|
|
38
|
+
package/subdirectory when the user wants a focused package manual. Renaming a
|
|
39
|
+
source later is a source-ref, phase-id, and package-output migration. Approved
|
|
40
|
+
paths are not derived directly from the source name; align/compile derives them
|
|
41
|
+
from collection, containment, and slug. Long term, extraction and structure
|
|
42
|
+
planning can still choose containment such as `product-ui/component-web` for
|
|
43
|
+
child codegraph views:
|
|
44
|
+
|
|
45
|
+
```text
|
|
46
|
+
knowledge/codegraph/product-ui/component-web/...
|
|
47
|
+
knowledge/codegraph/product-ui/component-lynx/...
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
In the current repo extraction flow, treat multi-module parent sources as
|
|
51
|
+
inspection/planning boundaries. Register the concrete package/subdirectory as
|
|
52
|
+
the source before running extraction.
|
|
53
|
+
|
|
54
|
+
### `source(name)`
|
|
55
|
+
|
|
56
|
+
Reference one registered source by name. The reference is type-neutral in
|
|
57
|
+
project code; each phase resolves it through the registry and checks whether it
|
|
58
|
+
is a repo, file, or lark source:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { source } from "@c4a/context";
|
|
62
|
+
|
|
63
|
+
const componentLib = source("component-lib");
|
|
64
|
+
const docs = source("product-docs");
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### `allSources("repo")`
|
|
68
|
+
|
|
69
|
+
Reference all repo sources as one collection:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { allSources } from "@c4a/context";
|
|
73
|
+
|
|
74
|
+
const repoSources = allSources("repo");
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Use `allSources("repo")` only when the project should list every registered
|
|
78
|
+
repo source. Prefer a specific `source("name")` for extraction phases.
|
|
79
|
+
|
|
80
|
+
## Phases
|
|
81
|
+
|
|
82
|
+
Phases declare reads and writes. The runtime can inspect them, dry-run them, and
|
|
83
|
+
record per-phase logs.
|
|
84
|
+
|
|
85
|
+
The API exposes the current declared workflow only. Declare file/lark sources,
|
|
86
|
+
capture phases, prose structure gates, source-bound compile phases, code
|
|
87
|
+
extraction phases, review gates, close/build, and packages explicitly. The CLI
|
|
88
|
+
then routes work through `context status`, `context run <phase-id>`, `context
|
|
89
|
+
review html/apply`, `context close`, `context verify`, and `context build`.
|
|
90
|
+
|
|
91
|
+
### `captureFile`
|
|
92
|
+
|
|
93
|
+
Capture a registered file source into a committed normalized document snapshot.
|
|
94
|
+
Default file capture treats `.md` files as document bodies. For MDX
|
|
95
|
+
documentation sites that use `_meta.json` route metadata, declare the processor
|
|
96
|
+
in `src/index.ts`:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
captureFile({ source: docs, processor: mdxJsonDocs() });
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
With that processor, `.md` and `.mdx` are document bodies. Included
|
|
103
|
+
`_meta.json` files are captured as route metadata assets and surfaced in
|
|
104
|
+
`read-plan` / `source-index`; they are not treated as body evidence.
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
captureFile({ source: docs });
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Phase id:
|
|
111
|
+
|
|
112
|
+
```text
|
|
113
|
+
capture:file:<source-name>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Register the source first with `context source add file <name> --local <path>`.
|
|
117
|
+
The first registration requires `--local`; the registry may later keep `local`
|
|
118
|
+
only as a refresh hint while committed snapshots remain verifiable.
|
|
119
|
+
|
|
120
|
+
### `captureLark`
|
|
121
|
+
|
|
122
|
+
Capture a registered Lark / Feishu document source into a committed normalized
|
|
123
|
+
Markdown snapshot:
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
captureLark({ source: handbook });
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Phase id:
|
|
130
|
+
|
|
131
|
+
```text
|
|
132
|
+
capture:lark:<source-name>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Register the source first with `context source add lark <name>` and exactly one
|
|
136
|
+
identity flag: `--url`, `--doc-token`, or `--wiki-token`. Capture reads the
|
|
137
|
+
remote document through the CLI runner, writes normalized snapshot files under
|
|
138
|
+
`sources/lark/<name>/`, and does not write access credentials into the
|
|
139
|
+
workspace. Multi-document Lark organization goes through `alignProse`; the
|
|
140
|
+
current workflow does not provide a one-step Lark stage shortcut.
|
|
141
|
+
|
|
142
|
+
### `alignProse`
|
|
143
|
+
|
|
144
|
+
Open the prose structure gate for document evidence:
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
alignProse({
|
|
148
|
+
source: docs,
|
|
149
|
+
collection: "architecture",
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
When `source("name")` is type-neutral, the SDK may declare
|
|
154
|
+
`align:source:<source-name>:architecture`; the CLI resolves it to
|
|
155
|
+
`align:file:<source-name>:architecture` or `align:lark:<source-name>:architecture` after
|
|
156
|
+
reading the registry.
|
|
157
|
+
|
|
158
|
+
Align is a gated workflow. It produces and validates a structure draft, not
|
|
159
|
+
final approved body:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
context run align:file:<source-name>:architecture --view read-plan --format json
|
|
163
|
+
context run align:file:<source-name>:architecture --view source-index --compact --format json
|
|
164
|
+
context run align:file:<source-name>:architecture --view span-detail --span <source-ref> --format json
|
|
165
|
+
context run align:file:<source-name>:architecture --view span-text --span <source-ref> --format json
|
|
166
|
+
context run align:file:<source-name>:architecture --view schema --format json
|
|
167
|
+
context run align:file:<source-name>:architecture --validate --input <structure.yaml> --format json
|
|
168
|
+
context run align:file:<source-name>:architecture --view structure-summary --input <structure.yaml> --format json
|
|
169
|
+
context run align:file:<source-name>:architecture --stage --input <structure.yaml> --format json
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Evidence views include `read-plan`, `source-index`, `span-detail`,
|
|
173
|
+
`span-text`, `schema`, and `structure-summary`. Additional diagnostic views may
|
|
174
|
+
be present, but the default path is compact index first, then exact source spans.
|
|
175
|
+
Agents should not inspect `sources/` or `.tmp` directly.
|
|
176
|
+
|
|
177
|
+
Structure payloads use `schema_version: "context.structure.v1"` and canonical
|
|
178
|
+
`file:` / `lark:` `#span` source refs. A one-file-to-one-page plan is represented
|
|
179
|
+
as ordinary `nodes[]` and `views[]` in the structure. It does not bypass
|
|
180
|
+
structure confirmation or compile.
|
|
181
|
+
|
|
182
|
+
### `compileProse`
|
|
183
|
+
|
|
184
|
+
Compile confirmed prose structure into reviewable source-bound draft pages:
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
compileProse({
|
|
188
|
+
source: docs,
|
|
189
|
+
collection: "architecture",
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
When `source("name")` is type-neutral, the SDK may declare
|
|
194
|
+
`compile:source:<source-name>:architecture`; the CLI resolves it to
|
|
195
|
+
`compile:file:<source-name>:architecture` or `compile:lark:<source-name>:architecture` after
|
|
196
|
+
reading the registry.
|
|
197
|
+
|
|
198
|
+
Phase id:
|
|
199
|
+
|
|
200
|
+
```text
|
|
201
|
+
compile:file:<source-name>:architecture
|
|
202
|
+
compile:lark:<source-name>:architecture
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Compile requires confirmed `unapproved/structure.yaml`. It freezes the current
|
|
206
|
+
structure for the compile round; if the user wants to change nodes, section
|
|
207
|
+
ownership, or relationships, return to the align/structure gate.
|
|
208
|
+
|
|
209
|
+
Common commands:
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
context run compile:file:<source-name>:architecture --view read-plan --format json
|
|
213
|
+
context run compile:file:<source-name>:architecture --view node-context --source <view-ref> --format json
|
|
214
|
+
context run compile:file:<source-name>:architecture --view schema --format json
|
|
215
|
+
context run compile:file:<source-name>:architecture --validate --input <compile-actions.yaml> --format json
|
|
216
|
+
context run compile:file:<source-name>:architecture --stage --input <compile-actions.yaml> --format json
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Compile action payloads use `schema_version: "context.compile-actions.v1"`.
|
|
220
|
+
By default, actions should omit body content and let the CLI mirror cited source
|
|
221
|
+
spans into `verbatim` sections. Explicit reader-visible content is not accepted
|
|
222
|
+
by the current compile action contract; split source evidence or return to the
|
|
223
|
+
structure gate instead. The current approved section wire contract accepts `verbatim` and `empty`;
|
|
224
|
+
it does not accept rewritten or mechanical projection modes.
|
|
225
|
+
Relationships stay in `structure.yaml` typed edges in current output; do not
|
|
226
|
+
inject relation markers into verbatim body.
|
|
227
|
+
|
|
228
|
+
### `extractTs`
|
|
229
|
+
|
|
230
|
+
Extract exported TypeScript / TSX symbols into draft candidates:
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
extractTs({
|
|
234
|
+
source: componentLib,
|
|
235
|
+
collection: "codegraph",
|
|
236
|
+
});
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Options:
|
|
240
|
+
|
|
241
|
+
| Field | Meaning |
|
|
242
|
+
|---|---|
|
|
243
|
+
| `source` | `source("name")` |
|
|
244
|
+
| `collection` | Code extraction uses `"codegraph"` |
|
|
245
|
+
| `include` | Optional glob list inside the selected source; default is `["src/**/*.{ts,tsx}"]` |
|
|
246
|
+
| `exportedOnly` | Default `true` |
|
|
247
|
+
| `transform` | Optional markdown transform function or functions |
|
|
248
|
+
|
|
249
|
+
In monorepos, make the package/subdirectory the source boundary. Register the
|
|
250
|
+
chosen package path with `context source add repo <name> --local <package-dir>`
|
|
251
|
+
and reference it with `source("<name>")`. Do not use `include` to choose a
|
|
252
|
+
package from a larger monorepo source.
|
|
253
|
+
|
|
254
|
+
Use `context source inspect <source-name>` to list detected module/package
|
|
255
|
+
boundaries before choosing the source. Use `context run <phase-id> --dry-run
|
|
256
|
+
--format json` to check the resolved modules, file counts, symbol counts, and
|
|
257
|
+
candidate estimate before writing `unapproved/entities.jsonl`. The dry-run
|
|
258
|
+
preview also includes `knowledgeTree` and `knowledgePathExamples`, which show
|
|
259
|
+
where approved Markdown will land after review apply.
|
|
260
|
+
|
|
261
|
+
Phase id shape:
|
|
262
|
+
|
|
263
|
+
```text
|
|
264
|
+
extract:<source-name-or-repo>:codegraph
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### `reviewValidity`
|
|
268
|
+
|
|
269
|
+
Declare the review step for a collection:
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
reviewValidity({ collection: "codegraph" });
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Declare one review gate for all current draft collections:
|
|
276
|
+
|
|
277
|
+
```ts
|
|
278
|
+
reviewValidity({ scope: "all" });
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Phase id:
|
|
282
|
+
|
|
283
|
+
```text
|
|
284
|
+
review:codegraph:validity
|
|
285
|
+
review:all:validity
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
The review HTML and apply flow are CLI-owned.
|
|
289
|
+
|
|
290
|
+
This phase marks a human review gate. Agents should open `context review html
|
|
291
|
+
<collection> --open` or `context review html --all --open` and wait for the
|
|
292
|
+
user-copied payload; they should not run the phase as an automatic approval step
|
|
293
|
+
or synthesize a payload themselves.
|
|
294
|
+
|
|
295
|
+
If the user explicitly asks for an automated or quick approval/rejection path,
|
|
296
|
+
use the scoped quick commands instead of hand-writing a payload:
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
context review approve <candidate-id> --collection <collection>
|
|
300
|
+
context review reject <candidate-id> --all
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
These commands still compute the current review scope and apply the same
|
|
304
|
+
candidate-id gate as the copied payload flow. They are not a replacement for the
|
|
305
|
+
default human review gate.
|
|
306
|
+
|
|
307
|
+
### `customPhase`
|
|
308
|
+
|
|
309
|
+
Use only when the typed factories cannot express a project-specific workflow:
|
|
310
|
+
|
|
311
|
+
```ts
|
|
312
|
+
const sample = source("sample");
|
|
313
|
+
|
|
314
|
+
customPhase("custom:sample:review", async (ctx) => {
|
|
315
|
+
await ctx.ensureSources({ source: sample });
|
|
316
|
+
await ctx.extract.ts(extractTs({ source: sample, collection: "codegraph" }));
|
|
317
|
+
await ctx.review.html(reviewValidity({ collection: "codegraph" }));
|
|
318
|
+
});
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
Custom phases are an escape hatch. Prefer built-in factories for source,
|
|
322
|
+
extract, review, and package workflows. The supported runtime helpers are:
|
|
323
|
+
|
|
324
|
+
- `ctx.ensureSources(...)` for repo source readiness.
|
|
325
|
+
- `ctx.extract.ts(...)` for declared TypeScript extraction.
|
|
326
|
+
- `ctx.review.html(...)` for the human review HTML gate.
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# Template Variables
|
|
2
|
+
|
|
3
|
+
Context package templates are rendered with Handlebars during `context build`.
|
|
4
|
+
|
|
5
|
+
This reference covers the template variables available to files under
|
|
6
|
+
`src/package-templates/**`. Templates can render values, loop over arrays,
|
|
7
|
+
branch with conditionals, and use template-only comments. They cannot run
|
|
8
|
+
JavaScript.
|
|
9
|
+
|
|
10
|
+
## Syntax
|
|
11
|
+
|
|
12
|
+
### Value
|
|
13
|
+
|
|
14
|
+
```md
|
|
15
|
+
Package: {{packageName}}
|
|
16
|
+
Approved pages: {{knowledgeCount}}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Values support dotted paths:
|
|
20
|
+
|
|
21
|
+
```md
|
|
22
|
+
{{context.package}}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Loop
|
|
26
|
+
|
|
27
|
+
```md
|
|
28
|
+
{{#each knowledgeItems}}
|
|
29
|
+
- [{{title}}]({{href}}) - {{type}}
|
|
30
|
+
{{/each}}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Nested loops are supported:
|
|
34
|
+
|
|
35
|
+
```md
|
|
36
|
+
{{#each knowledgeGroups}}
|
|
37
|
+
## {{title}}
|
|
38
|
+
|
|
39
|
+
{{#each items}}
|
|
40
|
+
- [{{title}}]({{href}})
|
|
41
|
+
{{/each}}
|
|
42
|
+
{{/each}}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Inside a loop, `{{@index}}` is zero-based. Use the built-in `inc` helper when
|
|
46
|
+
you need a one-based number:
|
|
47
|
+
|
|
48
|
+
```md
|
|
49
|
+
{{#each knowledgeItems}}
|
|
50
|
+
{{inc @index}}. [{{title}}]({{href}})
|
|
51
|
+
{{/each}}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Conditional
|
|
55
|
+
|
|
56
|
+
```md
|
|
57
|
+
{{#if description}}
|
|
58
|
+
Description: {{description}}
|
|
59
|
+
{{/if}}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The block renders when the value exists, is not `false`, and is not an empty
|
|
63
|
+
string or empty array.
|
|
64
|
+
|
|
65
|
+
### Template-only Comments
|
|
66
|
+
|
|
67
|
+
Use Handlebars comments, or HTML comments that start with `context:template`,
|
|
68
|
+
for guidance that should not appear in the generated package:
|
|
69
|
+
|
|
70
|
+
```md
|
|
71
|
+
{{! This comment is removed by Handlebars. }}
|
|
72
|
+
|
|
73
|
+
<!-- context:template
|
|
74
|
+
Explain why this section exists and where to edit it.
|
|
75
|
+
Read node_modules/@c4a/context/docs/reference/template-variables.md.
|
|
76
|
+
-->
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`context build` strips these comments from rendered output.
|
|
80
|
+
|
|
81
|
+
## Helpers
|
|
82
|
+
|
|
83
|
+
| Helper | Example | Meaning |
|
|
84
|
+
|---|---|---|
|
|
85
|
+
| `inc` | `{{inc @index}}` | Adds 1 to a numeric value. Useful for numbered lists. |
|
|
86
|
+
| `json` | `{{json knowledgeGroups}}` | Renders a value as formatted JSON for debugging or machine-readable docs. |
|
|
87
|
+
|
|
88
|
+
## Built-in Variables
|
|
89
|
+
|
|
90
|
+
| Variable | Type | Meaning |
|
|
91
|
+
|---|---|---|
|
|
92
|
+
| `packageName` | string | Package name from `kbPackage()` / `llmsPackage()`. |
|
|
93
|
+
| `packageKind` | string | `kb` or `llms`. |
|
|
94
|
+
| `knowledgeCount` | number | Selected approved Markdown file count. |
|
|
95
|
+
| `knowledgeTimestamp` | string | Latest selected approved Markdown `timestamp`, or epoch when empty. |
|
|
96
|
+
| `knowledge` | string | Concatenated selected approved Markdown bundle. Use carefully; it can be large. |
|
|
97
|
+
| `approvedKnowledge` | string | Alias for `knowledge`. |
|
|
98
|
+
| `knowledgeItems` | array | One record per selected approved Markdown page. |
|
|
99
|
+
| `knowledgeGroups` | array | Selected pages grouped by OKF root and the first directory segment under that root; each item also exposes `internal_collection`. |
|
|
100
|
+
| `knowledgeTreeNodes` | array | Nested path tree for selected pages. Useful for custom navigation. |
|
|
101
|
+
| `knowledgeTree` | string | Markdown tree preview of selected pages. |
|
|
102
|
+
| `knowledgeItemsMarkdown` | string | Markdown list of up to 50 selected pages. |
|
|
103
|
+
| `knowledgeGroupsMarkdown` | string | Markdown list of first-level directories with links to their generated `index.md` files. |
|
|
104
|
+
| `buildInventory` | object | Deterministic package build inventory, including selected files, selected-by reasons, collection summaries, and package-visible edge records. |
|
|
105
|
+
| `buildInventoryJson` | string | Pretty JSON form of `buildInventory`. |
|
|
106
|
+
| `buildInventoryPath` | string | Package-relative inventory path, currently `context-build-inventory.json`. |
|
|
107
|
+
| `knowledgeStructure` | object or null | Selected-package projection derived from workspace `knowledge/structure.yaml` at build time. It contains only selected views, their nodes, and package-visible edges. Templates may inspect it, but the default package consumer should rely on `context-build-inventory.json`. |
|
|
108
|
+
| `knowledgeStructureJson` | string | Pretty JSON form of `knowledgeStructure`, or `null`. |
|
|
109
|
+
| `knowledgeStructurePath` | string | Workspace source structure path, currently `knowledge/structure.yaml`; the variable itself is not copied into the package unless a template renders selected structure data. |
|
|
110
|
+
|
|
111
|
+
Custom variables from `template.vars` are also available.
|
|
112
|
+
|
|
113
|
+
`buildInventory.structure.edge_records` contains typed edge records whose
|
|
114
|
+
endpoints are visible in the selected package. Use those records when a
|
|
115
|
+
template or generated skill needs package-local relationship evidence. The
|
|
116
|
+
workspace `knowledge/structure.yaml` is not automatically copied into the
|
|
117
|
+
package unless a project-specific template explicitly renders it.
|
|
118
|
+
|
|
119
|
+
## `knowledgeItems`
|
|
120
|
+
|
|
121
|
+
Each item contains:
|
|
122
|
+
|
|
123
|
+
| Field | Meaning |
|
|
124
|
+
|---|---|
|
|
125
|
+
| `path` | Package-relative OKF path, for example `wikis/component-lib/symbol/button.md`. |
|
|
126
|
+
| `sourcePath` | Approved knowledge path before OKF output mapping, for example `architecture/entity/button.md`. |
|
|
127
|
+
| `approved_path` | Alias for `sourcePath`. |
|
|
128
|
+
| `dist_path` | Alias for `path`. |
|
|
129
|
+
| `internalCollection` | Internal approved collection, for example `architecture`. |
|
|
130
|
+
| `internal_collection` | Alias for `internalCollection`. |
|
|
131
|
+
| `collection` | Internal approved collection; alias for `internalCollection`. |
|
|
132
|
+
| `okf_root` | OKF output root, for example `wikis`, `guides`, `rules`, or `feats`. |
|
|
133
|
+
| `node_ref` | Stable NodeRef from approved frontmatter, for example `entity/button`. |
|
|
134
|
+
| `view_ref` | Stable ViewRef from approved frontmatter, for example `architecture:entity/button`. |
|
|
135
|
+
| `pathWithinCollection` | Path below the OKF root, for example `component-lib/symbol/button.md`. |
|
|
136
|
+
| `href` | Link relative to the template file currently being rendered. Use this in custom templates. |
|
|
137
|
+
| `hrefFromTemplate` | Alias for `href`. |
|
|
138
|
+
| `hrefFromPackageRoot` | Link from a package-root file such as `AGENTS.md`, for example `./wikis/component-lib/symbol/button.md`. |
|
|
139
|
+
| `hrefFromCollectionIndex` | Link from the current OKF root index, for example `./component-lib/symbol/button.md` for a `wikis` item. |
|
|
140
|
+
| `title` | Page title from frontmatter, or a title derived from the file name. |
|
|
141
|
+
| `type` | OKF `type` from frontmatter. |
|
|
142
|
+
| `description` | OKF `description` from frontmatter, when present. |
|
|
143
|
+
| `timestamp` | OKF `timestamp` from frontmatter, when present. |
|
|
144
|
+
| `source` | First top-level `sources` entry without the `repo:` prefix, or the group name. |
|
|
145
|
+
| `group` | First path segment under the OKF root. |
|
|
146
|
+
| `parentPath` | Parent path below the OKF root. |
|
|
147
|
+
| `depth` | Segment count below the OKF root. |
|
|
148
|
+
| `segments` | Path segments below the OKF root. |
|
|
149
|
+
| `tags` | Comma-separated tags from frontmatter. |
|
|
150
|
+
|
|
151
|
+
Example:
|
|
152
|
+
|
|
153
|
+
```md
|
|
154
|
+
{{#each knowledgeItems}}
|
|
155
|
+
- [{{title}}]({{href}}) — {{type}}{{#if description}}: {{description}}{{/if}}
|
|
156
|
+
{{/each}}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## `knowledgeGroups`
|
|
160
|
+
|
|
161
|
+
Each group contains:
|
|
162
|
+
|
|
163
|
+
| Field | Meaning |
|
|
164
|
+
|---|---|
|
|
165
|
+
| `name` | First directory segment under the OKF root, or `root` for pages directly under the OKF root. |
|
|
166
|
+
| `collection` | Internal approved collection for this group. |
|
|
167
|
+
| `internalCollection` | Internal approved collection; alias for `collection`. |
|
|
168
|
+
| `internal_collection` | Alias for `internalCollection`. |
|
|
169
|
+
| `okf_root` | OKF output root for this group, for example `wikis`, `guides`, `rules`, or `feats`. |
|
|
170
|
+
| `title` | Display title; defaults to `name`, or the OKF root title for a root group. |
|
|
171
|
+
| `count` | Number of selected pages in this group. |
|
|
172
|
+
| `indexPath` | OKF-root-aware index path, for example `wikis/component-lib/index.md`, `guides/component-lib/index.md`, or `rules/index.md` for a root group. |
|
|
173
|
+
| `indexHrefFromTemplate` | Link from the template file currently being rendered to `indexPath`. Use this in custom templates. |
|
|
174
|
+
| `indexHrefFromCollectionIndex` | Link from the OKF root index to `indexPath`. |
|
|
175
|
+
| `items` | `knowledgeItems` in the group. |
|
|
176
|
+
|
|
177
|
+
Example:
|
|
178
|
+
|
|
179
|
+
```md
|
|
180
|
+
{{#each knowledgeGroups}}
|
|
181
|
+
## [{{title}}]({{indexHrefFromTemplate}}) ({{count}})
|
|
182
|
+
|
|
183
|
+
{{#each items}}
|
|
184
|
+
- [{{title}}]({{href}}) - {{type}}
|
|
185
|
+
{{/each}}
|
|
186
|
+
{{/each}}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## `knowledgeTreeNodes`
|
|
190
|
+
|
|
191
|
+
`knowledgeTreeNodes` is a nested representation of selected pages. Each node
|
|
192
|
+
contains:
|
|
193
|
+
|
|
194
|
+
| Field | Meaning |
|
|
195
|
+
|---|---|
|
|
196
|
+
| `name` | Path segment name. |
|
|
197
|
+
| `title` | Display title derived from `name`. |
|
|
198
|
+
| `path` | Path below the OKF root. |
|
|
199
|
+
| `depth` | Depth below the OKF root. |
|
|
200
|
+
| `count` | Number of pages under this node. |
|
|
201
|
+
| `items` | Pages directly under this node. |
|
|
202
|
+
| `children` | Child nodes. |
|
|
203
|
+
|
|
204
|
+
Use it when a package needs navigation by source, module, category, or symbol
|
|
205
|
+
folder. Handlebars does not include recursive partials by default, so keep
|
|
206
|
+
starter templates shallow or add project-specific sections for the levels you
|
|
207
|
+
care about.
|
|
208
|
+
|
|
209
|
+
## Starter `wikis/index.md`
|
|
210
|
+
|
|
211
|
+
The default KB template uses the variables above to generate a starter index:
|
|
212
|
+
|
|
213
|
+
- bundle count and timestamp in OKF frontmatter;
|
|
214
|
+
- next-level directory links;
|
|
215
|
+
- links to generated directory indexes such as `wikis/<group>/index.md` or
|
|
216
|
+
another selected OKF root's `<okf-root>/<group>/index.md`.
|
|
217
|
+
|
|
218
|
+
`context build` also generates `index.md` files for directories under selected
|
|
219
|
+
OKF roots when a directory does not already contain one. The root
|
|
220
|
+
`wikis/index.md` should stay shallow by default; put detailed navigation in the
|
|
221
|
+
generated child indexes or in custom template sections.
|
|
222
|
+
|
|
223
|
+
The output is only a starter. Edit
|
|
224
|
+
`src/package-templates/kb/wikis/index.md` to add project-specific reading
|
|
225
|
+
paths, API entry points, or task-focused navigation before `context build`.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const DOCUMENT_SECTION_CONTENT_MODES: readonly ["verbatim", "empty"];
|
|
2
|
+
export type DocumentSectionContentMode = typeof DOCUMENT_SECTION_CONTENT_MODES[number];
|
|
3
|
+
export type DocumentEvidenceSectionMetadata = {
|
|
4
|
+
id: string;
|
|
5
|
+
kind: string;
|
|
6
|
+
content_mode: DocumentSectionContentMode;
|
|
7
|
+
source_ref?: string;
|
|
8
|
+
source_refs?: readonly string[];
|
|
9
|
+
};
|
|
10
|
+
export declare const DOCUMENT_EVIDENCE_SECTION_VALIDATION_STAGES: readonly ["candidate", "approved"];
|
|
11
|
+
export type DocumentEvidenceSectionValidationStage = typeof DOCUMENT_EVIDENCE_SECTION_VALIDATION_STAGES[number];
|
|
12
|
+
export type DocumentEvidenceSectionValidationOptions = {
|
|
13
|
+
stage: DocumentEvidenceSectionValidationStage;
|
|
14
|
+
};
|
|
15
|
+
export declare const DOCUMENT_COMPILE_ACTION_SCHEMA_VERSION = "context.compile-actions.v1";
|
|
16
|
+
export declare const DOCUMENT_STRUCTURE_SCHEMA_VERSION = "context.structure.v1";
|
|
17
|
+
export declare const assertDocumentEvidenceSectionMetadata: (section: DocumentEvidenceSectionMetadata, options: DocumentEvidenceSectionValidationOptions, field?: string) => void;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { PackageSelectDefinition } from "./contracts.js";
|
|
2
|
+
import type { PhaseDefinition, PhaseResourceReference } from "./phases.js";
|
|
3
|
+
import type { ProjectSourceDefinition } from "./sources.js";
|
|
4
|
+
export type { CodegraphCollection, DocumentMainlineCollection, EntityStatus, KnowledgeCollection, MainlineCollection, MarkdownTransform, FileCaptureProcessorDefinition, OkfRoot, PackageKind, PackageSelectDefinition, TopLevelNamespace, } from "./contracts.js";
|
|
5
|
+
export { assertDocumentMainlineCollection, assertKnowledgeCollection, assertMainlineCollection, assertOkfRoot, assertTopLevelNamespace, DOC_MAINLINE_COLLECTIONS, KNOWLEDGE_COLLECTIONS, MAINLINE_COLLECTIONS, OKF_ROOTS, TOP_LEVEL_NAMESPACES, } from "./contracts.js";
|
|
6
|
+
export { assertDocumentEvidenceSectionMetadata, DOCUMENT_COMPILE_ACTION_SCHEMA_VERSION, DOCUMENT_EVIDENCE_SECTION_VALIDATION_STAGES, DOCUMENT_SECTION_CONTENT_MODES, DOCUMENT_STRUCTURE_SCHEMA_VERSION, } from "./documentEvidence.js";
|
|
7
|
+
export type { DocumentEvidenceSectionMetadata, DocumentEvidenceSectionValidationOptions, DocumentEvidenceSectionValidationStage, DocumentSectionContentMode, } from "./documentEvidence.js";
|
|
8
|
+
export { alignProse, captureFile, captureLark, compileProse, customPhase, extractTs, mdxJsonDocs, reviewValidity, } from "./phases.js";
|
|
9
|
+
export type { AlignProsePhaseDefinition, CaptureFilePhaseDefinition, CaptureLarkPhaseDefinition, CompileProsePhaseDefinition, ContextPhase, ContextPhaseContext, CustomPhaseDefinition, ExtractTsPhaseDefinition, PhaseDefinition, PhaseResourceReference, ReviewValidityPhaseDefinition, ReviewValidityScope, } from "./phases.js";
|
|
10
|
+
export { allSources, DEFAULT_FILE_SOURCES_REGISTRY_PATH, DEFAULT_LARK_SOURCES_REGISTRY_PATH, DEFAULT_REPO_SOURCES_REGISTRY_PATH, loadSourcesRegistry, resolveSourceReference, source, } from "./sources.js";
|
|
11
|
+
export type { DocumentSourceDefinition, DocumentSourceReference, DocumentSourceType, FileSourceDefinition, FileSourceReference, FileSourceRegistryEntry, LarkSourceDefinition, LarkSourceReference, LarkSourceRegistryEntry, LoadSourcesRegistryOptions, ProjectSourceDefinition, RepoProjectSourceDefinition, RepoSourceDefinition, RepoSourceReference, RepoSourceRegistryEntry, RepoSourcesRegistry, SourceCollectionReference, SourceDefinition, SourceReference, SourcesRegistry, SourceType, } from "./sources.js";
|
|
12
|
+
export type TemplateVarValue = string | number | boolean | null | Record<string, unknown> | readonly Record<string, unknown>[];
|
|
13
|
+
export type PackageTemplateDefinition = {
|
|
14
|
+
path: string;
|
|
15
|
+
vars?: Record<string, TemplateVarValue>;
|
|
16
|
+
};
|
|
17
|
+
export type PackageTemplateInput = string | {
|
|
18
|
+
path: string;
|
|
19
|
+
vars?: Record<string, TemplateVarValue>;
|
|
20
|
+
};
|
|
21
|
+
export type BasePackageDefinition = {
|
|
22
|
+
name: string;
|
|
23
|
+
reads: readonly PhaseResourceReference[];
|
|
24
|
+
writes: readonly PhaseResourceReference[];
|
|
25
|
+
select?: PackageSelectDefinition;
|
|
26
|
+
template: PackageTemplateDefinition;
|
|
27
|
+
outDir: string;
|
|
28
|
+
};
|
|
29
|
+
export type KbPackageDefinition = BasePackageDefinition & {
|
|
30
|
+
kind: "package.kb";
|
|
31
|
+
};
|
|
32
|
+
export type LlmsPackageDefinition = BasePackageDefinition & {
|
|
33
|
+
kind: "package.llms";
|
|
34
|
+
};
|
|
35
|
+
export type PackageDefinition = KbPackageDefinition | LlmsPackageDefinition;
|
|
36
|
+
export type ContextProjectDefinition = {
|
|
37
|
+
sources: readonly ProjectSourceDefinition[];
|
|
38
|
+
phases: readonly PhaseDefinition[];
|
|
39
|
+
packages: readonly PackageDefinition[];
|
|
40
|
+
};
|
|
41
|
+
export type ContextProjectModule<TProject extends ContextProjectDefinition = ContextProjectDefinition> = {
|
|
42
|
+
kind: "context.project";
|
|
43
|
+
project: TProject;
|
|
44
|
+
};
|
|
45
|
+
export declare const defineProject: <TProject extends ContextProjectDefinition>(project: TProject) => ContextProjectModule<TProject>;
|
|
46
|
+
export declare const kbPackage: (definition: {
|
|
47
|
+
name: string;
|
|
48
|
+
template: PackageTemplateInput;
|
|
49
|
+
select?: PackageSelectDefinition;
|
|
50
|
+
}) => KbPackageDefinition;
|
|
51
|
+
export declare const llmsPackage: (definition: {
|
|
52
|
+
name: string;
|
|
53
|
+
template: PackageTemplateInput;
|
|
54
|
+
select?: PackageSelectDefinition;
|
|
55
|
+
}) => LlmsPackageDefinition;
|