@c4a/context 0.6.0-beta.5 → 0.6.0-beta.7
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 +1 -1
- package/docs/getting-started.md +113 -49
- package/docs/guides/agent-dialogue.md +32 -23
- package/docs/guides/agent-guide.md +133 -58
- package/docs/reference/package-templates.md +7 -1
- package/docs/reference/project-api.md +240 -49
- package/index.js +190 -102
- package/package.json +1 -1
- package/sources.d.ts +22 -0
|
@@ -19,41 +19,110 @@ declaration list. Put heavy logic in imported transform files.
|
|
|
19
19
|
|
|
20
20
|
## Sources
|
|
21
21
|
|
|
22
|
-
A source is a stable knowledge boundary, not only a display label.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
slug. NodeRef/ViewRef are identity fields, not path strings:
|
|
22
|
+
A source is a stable knowledge boundary, not only a display label. Repo, file,
|
|
23
|
+
and Lark sources use a date batch plus a concrete module name; multiple code or
|
|
24
|
+
document modules may share the date. The flattened selector `YYYYMMDD/module`
|
|
25
|
+
is the source identity used by phases, snapshot paths, and source refs.
|
|
26
|
+
Codegraph NodeRef/ViewRef and knowledge paths use the stable module name without
|
|
27
|
+
the date:
|
|
29
28
|
|
|
30
29
|
```text
|
|
31
30
|
knowledge/<collection>/<containment>/<slug>.md
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
knowledge/codegraph/<module>/symbol/<slug>.md
|
|
32
|
+
repo:<date>/<module>#symbol:...
|
|
33
|
+
file:<date>/<module>/<document>#span:...
|
|
34
|
+
lark:<date>/<module>/<document>#span:...
|
|
35
|
+
capture:file:<date>/<module>
|
|
36
|
+
align:lark:<date>/<module>:architecture
|
|
37
37
|
dist/<source-name>-kb/...
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
Choose the boundary before extraction. In a monorepo,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
from collection, containment, and slug. Long term, extraction and structure
|
|
46
|
-
planning can still choose containment such as `product-ui/component-web` for
|
|
47
|
-
child codegraph views:
|
|
40
|
+
Choose the module boundary before extraction. In a monorepo, register each
|
|
41
|
+
confirmed package/subdirectory under the same date batch. A repo root that
|
|
42
|
+
resolves to multiple modules is for inspection; it is not an extraction unit.
|
|
43
|
+
Approved codegraph paths use the stable module name; the date remains only in
|
|
44
|
+
source selectors, phase ids, and evidence refs:
|
|
48
45
|
|
|
49
46
|
```text
|
|
50
|
-
knowledge/codegraph/
|
|
51
|
-
knowledge/codegraph/
|
|
47
|
+
knowledge/codegraph/module-a/...
|
|
48
|
+
knowledge/codegraph/module-b/...
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The registry stores this as one date entry containing several `modules` entries,
|
|
52
|
+
and materializes each module at `sources/repo/<date>/<module>`.
|
|
53
|
+
Repo module names are project-wide codegraph identities and therefore cannot be
|
|
54
|
+
reused under another date batch. Refresh an existing module through its original
|
|
55
|
+
date/module selector.
|
|
56
|
+
When a repo module and the Context workspace share the same Git root, the CLI
|
|
57
|
+
normalizes even an absolute `--local` input into a path relative to the
|
|
58
|
+
workspace and stores the package directory as `subpath`. Materialized repo
|
|
59
|
+
links always use relative symlink targets. This keeps the registry and links
|
|
60
|
+
valid when the whole checkout moves. Cross-repository absolute checkout roots
|
|
61
|
+
remain absolute because no shared movable root can be assumed.
|
|
62
|
+
The date entry must be a valid calendar date in `YYYYMMDD` form. Use
|
|
63
|
+
`context source ensure <date>` or `context source inspect <date>` for the whole
|
|
64
|
+
batch, and `<date>/<module>` when targeting one module.
|
|
65
|
+
|
|
66
|
+
```yaml
|
|
67
|
+
sources:
|
|
68
|
+
- name: "20260712"
|
|
69
|
+
modules:
|
|
70
|
+
- name: module-a
|
|
71
|
+
local: ../monorepo
|
|
72
|
+
subpath: packages/module-a
|
|
73
|
+
git:
|
|
74
|
+
remote: https://git.example.com/product/monorepo.git
|
|
75
|
+
ref: <full-commit-sha>
|
|
76
|
+
- name: module-b
|
|
77
|
+
local: ../monorepo
|
|
78
|
+
subpath: packages/module-b
|
|
79
|
+
git:
|
|
80
|
+
remote: https://git.example.com/product/monorepo.git
|
|
81
|
+
ref: <full-commit-sha>
|
|
52
82
|
```
|
|
53
83
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
84
|
+
File and Lark registries use the same outer shape. Their modules hold local
|
|
85
|
+
document boundaries or remote document identities:
|
|
86
|
+
|
|
87
|
+
```yaml
|
|
88
|
+
sources:
|
|
89
|
+
- name: "20260712"
|
|
90
|
+
modules:
|
|
91
|
+
- name: local-manual
|
|
92
|
+
local: ../manual
|
|
93
|
+
- name: api-guide
|
|
94
|
+
local: ../api-guide
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Batch source registration
|
|
98
|
+
|
|
99
|
+
Use one command when a user confirms several source modules together:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
context source add batch [YYYYMMDD] --input <sources.yaml|json|-> --format json
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The payload is a non-empty `sources` array. Every item requires `type`. Repo
|
|
106
|
+
also requires `module` and accepts `local`/`remote`/`ref`. File requires `local`
|
|
107
|
+
and accepts `include`; Lark accepts exactly one of `url`, `docToken`, or
|
|
108
|
+
`wikiToken` plus optional `title`. File/Lark `module` is optional and is derived
|
|
109
|
+
with the same lowercase path-safe rule as the single-source commands. Resolved
|
|
110
|
+
module identities must be unique across the batch.
|
|
111
|
+
|
|
112
|
+
Source mutations share a project write lock, and every registry file is
|
|
113
|
+
replaced atomically. Never run separate `source add` processes in parallel. A
|
|
114
|
+
batch executes items in order; if a runtime item fails, its error lists the
|
|
115
|
+
completed items and the same payload may be rerun idempotently.
|
|
116
|
+
|
|
117
|
+
```yaml
|
|
118
|
+
sources:
|
|
119
|
+
- name: "20260712"
|
|
120
|
+
modules:
|
|
121
|
+
- name: user-manual
|
|
122
|
+
url: https://example.larksuite.com/wiki/example-a
|
|
123
|
+
- name: migration-guide
|
|
124
|
+
url: https://example.larksuite.com/wiki/example-b
|
|
125
|
+
```
|
|
57
126
|
|
|
58
127
|
### `source(name)`
|
|
59
128
|
|
|
@@ -64,9 +133,49 @@ is a repo, file, or lark source:
|
|
|
64
133
|
```ts
|
|
65
134
|
import { source } from "@c4a/context";
|
|
66
135
|
|
|
67
|
-
const
|
|
136
|
+
const legacyDocs = source("product-docs");
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### `source(namespace, module)`
|
|
140
|
+
|
|
141
|
+
Reference one registered repo module. Use the date batch and module name
|
|
142
|
+
returned by `context source add repo`:
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
const moduleA = source("20260712", "module-a");
|
|
146
|
+
const moduleB = source("20260712", "module-b");
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
These references resolve to `20260712/module-a` and `20260712/module-b`;
|
|
150
|
+
extraction and verification remain independent.
|
|
151
|
+
|
|
152
|
+
### `source(namespace, module, { type })`
|
|
153
|
+
|
|
154
|
+
Reference one file or Lark module under a date batch:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
const localManual = source("20260712", "local-manual", { type: "file" });
|
|
158
|
+
const userManual = source("20260712", "user-manual", { type: "lark" });
|
|
68
159
|
```
|
|
69
160
|
|
|
161
|
+
These references produce module-scoped phase ids and manifest entries without
|
|
162
|
+
treating the date as one document identity. Captured document files remain
|
|
163
|
+
siblings under `sources/file|lark/<date>/` and share the date-level
|
|
164
|
+
`manifest.json`; the logical `date/module` identity does not create another
|
|
165
|
+
directory level.
|
|
166
|
+
|
|
167
|
+
For a confirmed multi-document request, declare one capture phase per module.
|
|
168
|
+
While any module is uncaptured, `context status --format json` reports either:
|
|
169
|
+
|
|
170
|
+
- `needs-capture-phase` with `routing.configuration` when a module is not yet
|
|
171
|
+
declared in `src/index.ts`; or
|
|
172
|
+
- `needs-capture` with every declared command in `routing.command_plan`.
|
|
173
|
+
|
|
174
|
+
Each command-plan item says whether it is `immediate` or
|
|
175
|
+
`after-human-confirmation`. The `routing.human_gate` object identifies the
|
|
176
|
+
decision type and whether its result lives only in the current conversation or
|
|
177
|
+
is persisted by a later workspace command.
|
|
178
|
+
|
|
70
179
|
### `allSources("repo")`
|
|
71
180
|
|
|
72
181
|
Reference all repo sources as one collection:
|
|
@@ -78,7 +187,7 @@ const repoSources = allSources("repo");
|
|
|
78
187
|
```
|
|
79
188
|
|
|
80
189
|
Use `allSources("repo")` only when the project should list every registered
|
|
81
|
-
repo
|
|
190
|
+
repo module. Prefer a specific `source("date", "module")` for extraction phases.
|
|
82
191
|
|
|
83
192
|
## Phases
|
|
84
193
|
|
|
@@ -91,6 +200,20 @@ extraction phases, review gates, close/build, and packages explicitly. The CLI
|
|
|
91
200
|
then routes work through `context status`, `context run <phase-id>`, `context
|
|
92
201
|
review html/apply`, `context close`, `context verify`, and `context build`.
|
|
93
202
|
|
|
203
|
+
### Status declaration coverage
|
|
204
|
+
|
|
205
|
+
`context status --format json` includes a `declarationGraph` and
|
|
206
|
+
`configurationGaps` for document workflows. Each row reports capture, align,
|
|
207
|
+
compile, and Review coverage for a canonical source plus collection. Gaps are
|
|
208
|
+
non-blocking before structure confirmation. Once a structure is confirmed,
|
|
209
|
+
compile routing is exact: phase selection uses canonical source plus collection,
|
|
210
|
+
and candidate progress remains bound to the current `structure_digest`. A
|
|
211
|
+
compile phase from another collection is never used as fallback.
|
|
212
|
+
|
|
213
|
+
Use `context status --format json --view summary` when only the current state,
|
|
214
|
+
target, counts, diagnostics, and recommended command are needed. The full view
|
|
215
|
+
retains source, phase, package, and lifecycle inventories.
|
|
216
|
+
|
|
94
217
|
### `captureFile`
|
|
95
218
|
|
|
96
219
|
Capture a registered file source into a committed normalized document snapshot.
|
|
@@ -127,11 +250,12 @@ Phase id:
|
|
|
127
250
|
capture:file:<source-name>
|
|
128
251
|
```
|
|
129
252
|
|
|
130
|
-
Register the source first with
|
|
253
|
+
Register the source first with
|
|
254
|
+
`context source add file [YYYYMMDD] --module <module> --local <path>`.
|
|
131
255
|
The first registration requires `--local`; the registry may later keep `local`
|
|
132
|
-
only as a refresh hint while committed snapshots remain verifiable.
|
|
133
|
-
|
|
134
|
-
|
|
256
|
+
only as a refresh hint while committed snapshots remain verifiable. Multiple
|
|
257
|
+
file modules may share one date. When `--module` is omitted, the CLI derives it
|
|
258
|
+
from the local file or directory name.
|
|
135
259
|
|
|
136
260
|
### `captureLark`
|
|
137
261
|
|
|
@@ -148,12 +272,21 @@ Phase id:
|
|
|
148
272
|
capture:lark:<source-name>
|
|
149
273
|
```
|
|
150
274
|
|
|
151
|
-
Register
|
|
152
|
-
|
|
275
|
+
Register each source with
|
|
276
|
+
`context source add lark [YYYYMMDD] --module <module>` and exactly one identity
|
|
277
|
+
flag: `--url`, `--doc-token`, or `--wiki-token`. Multiple documents may share
|
|
278
|
+
one date batch; when `--module` is omitted, the CLI derives an opaque,
|
|
279
|
+
credential-safe module id. Capture reads the
|
|
153
280
|
remote document through the CLI runner, writes normalized snapshot files under
|
|
154
|
-
`sources/lark/<
|
|
155
|
-
workspace.
|
|
156
|
-
|
|
281
|
+
`sources/lark/<date>/` as sibling document files tracked by one date-level `manifest.json`, and does not write access credentials into the
|
|
282
|
+
workspace.
|
|
283
|
+
|
|
284
|
+
Use a typed document reference in project declarations:
|
|
285
|
+
|
|
286
|
+
```ts
|
|
287
|
+
const handbook = source("20260712", "user-manual", { type: "lark" });
|
|
288
|
+
const localDocs = source("20260712", "local-manual", { type: "file" });
|
|
289
|
+
```
|
|
157
290
|
|
|
158
291
|
### `alignProse`
|
|
159
292
|
|
|
@@ -185,6 +318,30 @@ context run align:file:<source-name>:architecture --view structure-summary --inp
|
|
|
185
318
|
context run align:file:<source-name>:architecture --stage --input <structure.yaml> --format json
|
|
186
319
|
```
|
|
187
320
|
|
|
321
|
+
`--validate`, `--stage`, `--confirm`, and `--repair` are mutually exclusive
|
|
322
|
+
operations. An `--input` without an operation is rejected unless the selected
|
|
323
|
+
view explicitly consumes that input. Successful validation returns a stage
|
|
324
|
+
command with the same file path. JSON run output keeps `next_action` first and
|
|
325
|
+
omits repeated contracts outside `read-plan`/`schema`; add `--verbose` for the
|
|
326
|
+
full phase reads/writes, source metadata, and contracts.
|
|
327
|
+
|
|
328
|
+
Align and compile evidence results include `semantic_rules`. Its `required`
|
|
329
|
+
array is the rule subset selected for the current judgment, with a selection
|
|
330
|
+
reason and content digest for each rule. `handle`, `digest`, and
|
|
331
|
+
`rules_version` are stable cache checks: reuse a loaded ruleset only while its
|
|
332
|
+
content remains in the active context and both handle and digest still match.
|
|
333
|
+
After context compaction, reload the returned required subset; a handle alone
|
|
334
|
+
does not imply that the rule text is still available.
|
|
335
|
+
|
|
336
|
+
Document evidence boundaries are deterministic rather than semantic.
|
|
337
|
+
`source-index` and `chunks` mark Markdown AST blocks with
|
|
338
|
+
`boundary_role: "markdown-ast-block"` and `section_candidate: true`.
|
|
339
|
+
`span-text`/`span-detail` mark each returned page as
|
|
340
|
+
`range_role: "transport-page"` and `section_candidate: false`; pagination line
|
|
341
|
+
ranges are never structure boundaries. Structure validation blocks repeated
|
|
342
|
+
fixed-width line grids that cut through AST blocks and reports sections that
|
|
343
|
+
cross multiple heading paths, without classifying document topics.
|
|
344
|
+
|
|
188
345
|
Evidence views include `read-plan`, `source-index`, `span-detail`,
|
|
189
346
|
`span-text`, `schema`, and `structure-summary`. Additional diagnostic views may
|
|
190
347
|
be present, but the default path is compact index first, then exact source spans.
|
|
@@ -232,6 +389,12 @@ context run compile:file:<source-name>:architecture --validate --input <compile-
|
|
|
232
389
|
context run compile:file:<source-name>:architecture --stage --input <compile-actions.yaml> --format json
|
|
233
390
|
```
|
|
234
391
|
|
|
392
|
+
Compile remains one View per write for evidence isolation. After staging, follow
|
|
393
|
+
`continue_compile_batch` to prepare the next View. Only the final View returns
|
|
394
|
+
the human Review action, so one confirmed structure produces one review
|
|
395
|
+
payload. `context close` is blocked while a planned View is unprepared, still
|
|
396
|
+
draft, or rejected without a structure revision.
|
|
397
|
+
|
|
235
398
|
Compile action payloads use `schema_version: "context.compile-actions.v1"`.
|
|
236
399
|
By default, actions should omit body content and let the CLI mirror cited source
|
|
237
400
|
spans into `verbatim` sections. Explicit reader-visible content is not accepted
|
|
@@ -256,7 +419,7 @@ Options:
|
|
|
256
419
|
|
|
257
420
|
| Field | Meaning |
|
|
258
421
|
|---|---|
|
|
259
|
-
| `source` | `source("
|
|
422
|
+
| `source` | `source("date", "module")` for one repo module |
|
|
260
423
|
| `collection` | Code extraction uses `"codegraph"` |
|
|
261
424
|
| `include` | Optional glob list inside the selected source; default is `["src/**/*.{ts,tsx}"]` |
|
|
262
425
|
| `mode` | `"exports"` (default) traces public exports from automatic or configured entries; `"scan"` uses every file matched by `include` as an entry root |
|
|
@@ -293,13 +456,13 @@ TypeScript extraction reads the selected module's `tsconfig.json` or
|
|
|
293
456
|
tracing and internal dependency relations, so aliases such as `@/*` resolve to
|
|
294
457
|
their source files.
|
|
295
458
|
|
|
296
|
-
In monorepos, make
|
|
297
|
-
chosen package path with `context source add repo --local <package-dir>` and
|
|
298
|
-
reference
|
|
459
|
+
In monorepos, make each package/subdirectory a module boundary. Register the
|
|
460
|
+
chosen package path with `context source add repo [YYYYMMDD] --module <module> --local <package-dir>` and
|
|
461
|
+
reference it with `source("<date>", "<module>")`.
|
|
299
462
|
Do not use `include` to choose a
|
|
300
463
|
package from a larger monorepo source.
|
|
301
464
|
|
|
302
|
-
Use `context source inspect <
|
|
465
|
+
Use `context source inspect <date>/<module>` to list detected module/package
|
|
303
466
|
boundaries before choosing the source. Use `context run <phase-id> --dry-run
|
|
304
467
|
--format json` to check the resolved modules, file counts, symbol counts, and
|
|
305
468
|
candidate estimate before writing `unapproved/entities.jsonl`. The dry-run
|
|
@@ -323,13 +486,35 @@ Codegraph extraction has two execution policies:
|
|
|
323
486
|
result returns `next_action.human_gate=false` and the Agent continues.
|
|
324
487
|
- `context run <phase-id> --auto-promote` is the explicit CI/CD path. It is valid
|
|
325
488
|
only for `phase.extract.ts` codegraph phases, applies deterministic code deltas
|
|
326
|
-
without Review,
|
|
327
|
-
|
|
489
|
+
without Review, refreshes deterministic close when approved knowledge changed,
|
|
490
|
+
then runs project verification. Close or verification errors make the command
|
|
491
|
+
fail; JSON output reports applied/materialized/removed counts plus a `close`
|
|
492
|
+
state of `refreshed`, `current`, or `not-required`. Package build remains a
|
|
493
|
+
separate pipeline step; existing package outputs are reported stale.
|
|
328
494
|
|
|
329
495
|
This policy never auto-promotes architecture, business, decision, test, or
|
|
330
496
|
other semantic knowledge. Agents must follow the returned
|
|
331
497
|
`next_action.human_gate` instead of assuming every extraction requires Review.
|
|
332
498
|
|
|
499
|
+
Approved codegraph sections use the local evidence form
|
|
500
|
+
`src-N#symbol:<file>:<symbol>:<kind>@<digest>`. The file segment makes reverse
|
|
501
|
+
lookup exact when multiple files contain the same symbol name, kind, and digest;
|
|
502
|
+
the complete ref remains opaque to agents. New pages keep only top-level
|
|
503
|
+
`candidate_fingerprint` and do not emit `code_origin`.
|
|
504
|
+
|
|
505
|
+
Projects created by the beta.5 protocol can upgrade approved pages without a
|
|
506
|
+
second human decision. Rerun every declared codegraph extraction phase to write
|
|
507
|
+
the current file-aware symbol index, then run:
|
|
508
|
+
|
|
509
|
+
```bash
|
|
510
|
+
context review migrate-codegraph-refs
|
|
511
|
+
context verify
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
Migration resolves each legacy ref against the trusted index and its existing
|
|
515
|
+
origin metadata, removes `code_origin`, preserves the approved body and review
|
|
516
|
+
state, and rolls back all page writes if final verification fails.
|
|
517
|
+
|
|
333
518
|
### `reviewValidity`
|
|
334
519
|
|
|
335
520
|
Declare the review step for a collection:
|
|
@@ -353,10 +538,16 @@ review:all:validity
|
|
|
353
538
|
|
|
354
539
|
The review HTML and apply flow are CLI-owned.
|
|
355
540
|
|
|
356
|
-
This phase marks a human review gate when current candidates exist. Agents
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
541
|
+
This phase marks a human review gate when current candidates exist. Agents
|
|
542
|
+
should run `context review html <collection> --open --format json` or `context
|
|
543
|
+
review html --all --open --format json`, confirm the returned `opened` field,
|
|
544
|
+
and wait for the user-copied payload. They should not run the phase as an
|
|
545
|
+
automatic approval step or synthesize a payload themselves.
|
|
546
|
+
|
|
547
|
+
The gate is batch-scoped: prose waits for every planned View in the confirmed
|
|
548
|
+
structure, and codegraph waits for every pending extract phase in the confirmed
|
|
549
|
+
module round. Candidate count/hash therefore describes the complete current
|
|
550
|
+
batch rather than one page or module.
|
|
360
551
|
|
|
361
552
|
If the user explicitly asks for an automated or quick approval/rejection path,
|
|
362
553
|
use the scoped quick commands instead of hand-writing a payload:
|
|
@@ -375,9 +566,9 @@ default human review gate.
|
|
|
375
566
|
Use only when the typed factories cannot express a project-specific workflow:
|
|
376
567
|
|
|
377
568
|
```ts
|
|
378
|
-
const sample = source("sample");
|
|
569
|
+
const sample = source("20260712", "sample");
|
|
379
570
|
|
|
380
|
-
customPhase("custom:sample:review", async (ctx) => {
|
|
571
|
+
customPhase("custom:20260712/sample:review", async (ctx) => {
|
|
381
572
|
await ctx.ensureSources({ source: sample });
|
|
382
573
|
await ctx.extract.ts(extractTs({ source: sample, collection: "codegraph" }));
|
|
383
574
|
await ctx.review.html(reviewValidity({ collection: "codegraph" }));
|