@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,325 @@
|
|
|
1
|
+
# Agent Dialogue
|
|
2
|
+
|
|
3
|
+
This guide defines how agents should talk to users while operating a Context
|
|
4
|
+
workspace.
|
|
5
|
+
|
|
6
|
+
## Principle
|
|
7
|
+
|
|
8
|
+
Talk about the user decision first, then the implementation detail.
|
|
9
|
+
|
|
10
|
+
Do not start a human gate by exposing internal API names, default option names,
|
|
11
|
+
or placeholder commands. The user needs to understand:
|
|
12
|
+
|
|
13
|
+
- what decision is being made;
|
|
14
|
+
- what will happen after they approve;
|
|
15
|
+
- what files or knowledge shape will be affected;
|
|
16
|
+
- what alternatives they can choose.
|
|
17
|
+
|
|
18
|
+
CLI commands, source names, phase ids, status values, payload keys, and
|
|
19
|
+
`source_ref` values are protocol text. Keep those exact when needed, but do not
|
|
20
|
+
make them the main explanation.
|
|
21
|
+
|
|
22
|
+
## Human Gate Question Form
|
|
23
|
+
|
|
24
|
+
When the decision has a small fixed option set, use the host's native
|
|
25
|
+
multi-choice tool when available:
|
|
26
|
+
|
|
27
|
+
- Claude Code: `AskUserQuestion`
|
|
28
|
+
- Codex: use the available native user-input tool, for example
|
|
29
|
+
`request_user_input` when it is exposed
|
|
30
|
+
- Cursor Plan Mode: `AskQuestion`
|
|
31
|
+
|
|
32
|
+
If no native question tool is available, fall back to Markdown `A/B/C` choices.
|
|
33
|
+
Each option must include a short impact statement. Do not ask an open-ended
|
|
34
|
+
free-text question when the actual workflow has two or three known branches.
|
|
35
|
+
The option labels must be semantic user choices, not API or factory names. Use
|
|
36
|
+
implementation names such as `alignProse`, `compileProse`, `kbPackage`, or
|
|
37
|
+
`llmsPackage` only in a technical follow-up, command, or `src/index.ts` change
|
|
38
|
+
summary.
|
|
39
|
+
|
|
40
|
+
Examples:
|
|
41
|
+
|
|
42
|
+
- document structure gate: continue material investigation vs add user
|
|
43
|
+
structure guidance vs narrow the captured source;
|
|
44
|
+
- package output: agent knowledge-base package vs LLM text bundle vs skip for
|
|
45
|
+
now;
|
|
46
|
+
- stale approved page: create a replacement review candidate vs confirm the
|
|
47
|
+
existing content is still valid;
|
|
48
|
+
- orphaned approved page: mark the page deprecated vs keep it as unverifiable
|
|
49
|
+
knowledge.
|
|
50
|
+
|
|
51
|
+
## Source Boundary Gate
|
|
52
|
+
|
|
53
|
+
Bad:
|
|
54
|
+
|
|
55
|
+
```text
|
|
56
|
+
Please provide source name:
|
|
57
|
+
context source add repo <name> --local <repo-or-subdir>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Good:
|
|
61
|
+
|
|
62
|
+
```text
|
|
63
|
+
Next we need to choose the knowledge source.
|
|
64
|
+
|
|
65
|
+
If you want one manual for only this package, choose the package directory as
|
|
66
|
+
the source boundary. If you want one manual for the whole subspace, choose the
|
|
67
|
+
subspace root.
|
|
68
|
+
|
|
69
|
+
The source name becomes part of source refs, phase ids, and package names.
|
|
70
|
+
Approved knowledge paths are derived from collection, containment, and slug;
|
|
71
|
+
NodeRef/ViewRef are identity fields, not path strings:
|
|
72
|
+
knowledge/<collection>/<containment>/<slug>.md
|
|
73
|
+
repo:<source-name>#...
|
|
74
|
+
dist/<source-name>-kb/...
|
|
75
|
+
|
|
76
|
+
If the user already gave a path and only the source name is missing, still
|
|
77
|
+
explain what the name means:
|
|
78
|
+
|
|
79
|
+
- if the path is one package/module, the name appears once in source refs and
|
|
80
|
+
phase ids;
|
|
81
|
+
- if the path is a parent monorepo/subspace, the name is a parent namespace and
|
|
82
|
+
child modules can appear below it later;
|
|
83
|
+
- current extraction should inspect a parent source first, then extract from
|
|
84
|
+
a confirmed package/subdirectory boundary.
|
|
85
|
+
|
|
86
|
+
For a multi-module subspace package shape, a parent name such as product-ui
|
|
87
|
+
can group children like:
|
|
88
|
+
knowledge/codegraph/product-ui/component-web/...
|
|
89
|
+
knowledge/codegraph/product-ui/component-lynx/...
|
|
90
|
+
|
|
91
|
+
For the current first extraction, I will still ask you to confirm the concrete
|
|
92
|
+
package/subdirectory boundary before reading code.
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Only after that explanation should the agent show the concrete command it will
|
|
96
|
+
run.
|
|
97
|
+
|
|
98
|
+
## Document Read Permission Gate
|
|
99
|
+
|
|
100
|
+
Bad:
|
|
101
|
+
|
|
102
|
+
```text
|
|
103
|
+
Running capture:file:docs now.
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Good:
|
|
107
|
+
|
|
108
|
+
```text
|
|
109
|
+
The source is registered, but registration did not read the document body.
|
|
110
|
+
|
|
111
|
+
The next operation will read this local Markdown file or folder and write a
|
|
112
|
+
committed snapshot under `sources/file/<source-name>/`. That snapshot is used
|
|
113
|
+
later for review, verify, and fresh-clone reproduction.
|
|
114
|
+
|
|
115
|
+
Please confirm that I may read this document source now. After you confirm, I
|
|
116
|
+
will declare the capture phase in `src/index.ts`, summarize that change, and
|
|
117
|
+
run the capture command.
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
For Lark / Feishu:
|
|
121
|
+
|
|
122
|
+
```text
|
|
123
|
+
The source is registered, but registration did not fetch the remote document.
|
|
124
|
+
|
|
125
|
+
The next operation will read the Lark/Feishu document you provided and write a
|
|
126
|
+
normalized snapshot under `sources/lark/<source-name>/`. The snapshot is
|
|
127
|
+
committed by default so verify can work offline and after a fresh clone. Access
|
|
128
|
+
credentials stay in the Lark CLI; they are not written to this workspace. If
|
|
129
|
+
your business repository wants to ignore this snapshot, that is a repository
|
|
130
|
+
policy decision and verify will report degraded offline evidence later.
|
|
131
|
+
|
|
132
|
+
Please confirm that I may read this remote document now.
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Do not run capture preview, capture, or refresh before this permission is clear.
|
|
136
|
+
|
|
137
|
+
## Document Investigation Gate
|
|
138
|
+
|
|
139
|
+
Bad:
|
|
140
|
+
|
|
141
|
+
```text
|
|
142
|
+
Run align:file:docs:architecture or compile:file:docs:architecture?
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Good:
|
|
146
|
+
|
|
147
|
+
```text
|
|
148
|
+
The document source has been captured into a committed snapshot.
|
|
149
|
+
|
|
150
|
+
Capture summary:
|
|
151
|
+
- documents: <count>
|
|
152
|
+
- title tree: <top-level titles or heading groups>
|
|
153
|
+
- evidence views: read-plan, source-index --compact, span-detail, span-text
|
|
154
|
+
|
|
155
|
+
Next I will investigate the material and propose a structure draft. That draft
|
|
156
|
+
decides:
|
|
157
|
+
|
|
158
|
+
- which knowledge pages should exist;
|
|
159
|
+
- which sections belong to each page;
|
|
160
|
+
- which relationships have source-backed evidence;
|
|
161
|
+
- which questions remain unresolved.
|
|
162
|
+
|
|
163
|
+
Confirming the structure will freeze paths, section ownership, relationships,
|
|
164
|
+
and compile order for this round. No approved Markdown is written before review.
|
|
165
|
+
|
|
166
|
+
You can choose:
|
|
167
|
+
A. Continue material investigation and let me propose the structure draft.
|
|
168
|
+
B. First give structure preferences, such as expected domains or naming.
|
|
169
|
+
C. Go back and narrow or correct the captured source.
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
After the user chooses, update `src/index.ts` if the matching align/compile
|
|
173
|
+
phases are not declared yet, then summarize the change. For example:
|
|
174
|
+
|
|
175
|
+
```text
|
|
176
|
+
I updated the project flow to add document structure planning and source-bound
|
|
177
|
+
compile for `product-docs`. No approved Markdown is written yet. The next gate
|
|
178
|
+
is a structure draft for your confirmation.
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
If the user asks for one page per source document, explain that it is modeled as
|
|
182
|
+
a simple structure draft. It still goes through structure confirmation and
|
|
183
|
+
source-bound compile; there is no separate shortcut that writes final page body
|
|
184
|
+
directly from capture.
|
|
185
|
+
|
|
186
|
+
## Extraction Scope Gate
|
|
187
|
+
|
|
188
|
+
Bad:
|
|
189
|
+
|
|
190
|
+
```text
|
|
191
|
+
是否按 Context 默认范围继续?
|
|
192
|
+
extractTs({
|
|
193
|
+
source: source("component-lib"),
|
|
194
|
+
collection: "codegraph",
|
|
195
|
+
// include defaults to ["src/**/*.{ts,tsx}"]
|
|
196
|
+
// exportedOnly defaults to true
|
|
197
|
+
})
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Good:
|
|
201
|
+
|
|
202
|
+
```text
|
|
203
|
+
The source is ready and resolves to one package.
|
|
204
|
+
|
|
205
|
+
Proposed extraction:
|
|
206
|
+
- read TypeScript/TSX files under `src/`;
|
|
207
|
+
- only include exported symbols such as components, functions, types, and props;
|
|
208
|
+
- create draft candidates for human review;
|
|
209
|
+
- no approved Markdown is written until you review the candidates.
|
|
210
|
+
|
|
211
|
+
This means files outside `src/` and non-exported/internal helpers are skipped.
|
|
212
|
+
If you want docs, tests, examples, or internal APIs included, say that before
|
|
213
|
+
extraction.
|
|
214
|
+
|
|
215
|
+
I will first generate a preview without writing candidates. The preview will
|
|
216
|
+
show the file count, symbol count, candidate count, and planned `knowledge/`
|
|
217
|
+
tree. I will only run extraction after that preview matches your expectation.
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Mention `extractTs`, `include`, `exportedOnly`, or `reviewValidity` only if the
|
|
221
|
+
user asks for implementation details, or when editing `src/index.ts` in a code
|
|
222
|
+
summary.
|
|
223
|
+
|
|
224
|
+
## Review Gate
|
|
225
|
+
|
|
226
|
+
Bad:
|
|
227
|
+
|
|
228
|
+
```text
|
|
229
|
+
Run reviewValidity and apply payload.
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Good:
|
|
233
|
+
|
|
234
|
+
```text
|
|
235
|
+
Draft candidates are ready. The next step is human review.
|
|
236
|
+
|
|
237
|
+
Open the review HTML, approve or reject candidates, then copy the Payload back
|
|
238
|
+
into chat. I will only apply the payload you provide; I will not approve or
|
|
239
|
+
reject candidates on your behalf. Review decides which draft entries become
|
|
240
|
+
approved Markdown under `knowledge/`, and which entries stay rejected in the
|
|
241
|
+
ledger.
|
|
242
|
+
|
|
243
|
+
You do not need to save a payload file; I will write a temporary file and run
|
|
244
|
+
the apply command.
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Package Gate
|
|
248
|
+
|
|
249
|
+
Bad:
|
|
250
|
+
|
|
251
|
+
```text
|
|
252
|
+
Choose one: skills, llms, both, none.
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Good:
|
|
256
|
+
|
|
257
|
+
```text
|
|
258
|
+
Approved knowledge is ready. Now choose how it should be packaged.
|
|
259
|
+
|
|
260
|
+
Recommended first output is an agent knowledge-base package:
|
|
261
|
+
dist/<name>-kb/
|
|
262
|
+
├── AGENTS.md
|
|
263
|
+
├── skills/knowledge-query/SKILL.md
|
|
264
|
+
└── wikis/
|
|
265
|
+
├── index.md
|
|
266
|
+
├── <group>/index.md
|
|
267
|
+
└── <group>/...
|
|
268
|
+
|
|
269
|
+
This gives agents a reusable knowledge-query skill plus copied approved
|
|
270
|
+
knowledge pages. The
|
|
271
|
+
default query skill starts from OKF indexes, cites page/section evidence, uses
|
|
272
|
+
structure/build metadata when present, and reports gaps rather than inventing
|
|
273
|
+
unsupported answers. The template under `src/package-templates/kb/` is editable
|
|
274
|
+
before build, including `wikis/index.md` for bundle scope and query guidance.
|
|
275
|
+
The root index should stay shallow by default: it lists next-level directories,
|
|
276
|
+
and `context build` generates child directory indexes so users can browse from
|
|
277
|
+
bundle to group to page.
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Offer the alternatives as user-facing choices:
|
|
281
|
+
|
|
282
|
+
- Agent knowledge-base package: creates `dist/<name>-kb/` for agents to query
|
|
283
|
+
and cite approved knowledge pages.
|
|
284
|
+
- LLM text bundle: creates `dist/<name>-llms/` for one text/RAG import bundle.
|
|
285
|
+
- Skip for now: leaves approved Markdown in `knowledge/` without a `dist/`
|
|
286
|
+
package.
|
|
287
|
+
|
|
288
|
+
Do not offer `both` as a shortcut. If the user wants multiple outputs, declare
|
|
289
|
+
one package first, build and inspect it, then ask before adding another. Use
|
|
290
|
+
`kbPackage` / `llmsPackage` only after the user has chosen the semantic output
|
|
291
|
+
shape.
|
|
292
|
+
|
|
293
|
+
## Evidence Maintenance Gates
|
|
294
|
+
|
|
295
|
+
When approved knowledge still exists but the source evidence changed, explain
|
|
296
|
+
that the approved page remains usable but is no longer fully current against
|
|
297
|
+
the latest snapshot.
|
|
298
|
+
|
|
299
|
+
Use semantic choices:
|
|
300
|
+
|
|
301
|
+
- Create an updated draft for review: best when the source change may require
|
|
302
|
+
wording, scope, or facts to change. This creates a replacement candidate and
|
|
303
|
+
still requires review.
|
|
304
|
+
- Confirm the current page is still valid: best when the source change is only
|
|
305
|
+
formatting, typo cleanup, or otherwise does not affect the approved content.
|
|
306
|
+
This re-binds the page to the current evidence without changing its body.
|
|
307
|
+
|
|
308
|
+
When an approved page points to a source document that no longer exists in the
|
|
309
|
+
current snapshot, do not offer replacement or re-binding. Use semantic choices:
|
|
310
|
+
|
|
311
|
+
- Mark the page as deprecated: removes it from later package output while
|
|
312
|
+
preserving audit history.
|
|
313
|
+
- Keep it as source-orphaned knowledge: leaves it approved, but verify/status
|
|
314
|
+
will keep reporting an evidence warning.
|
|
315
|
+
|
|
316
|
+
## Reporting
|
|
317
|
+
|
|
318
|
+
Keep reports short and state transitions oriented:
|
|
319
|
+
|
|
320
|
+
- commands run;
|
|
321
|
+
- current state;
|
|
322
|
+
- what changed;
|
|
323
|
+
- the next human decision, if any.
|
|
324
|
+
|
|
325
|
+
Do not paste long raw CLI transcripts unless the user asks for exact output.
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
# Agent Guide
|
|
2
|
+
|
|
3
|
+
This guide is for Coding Agents operating a Context workspace.
|
|
4
|
+
|
|
5
|
+
## Start Here
|
|
6
|
+
|
|
7
|
+
1. If a public Agent entry is available, use the installed Context continuation command/skill from the project root; the exact slash command or skill name is host-specific.
|
|
8
|
+
2. If you are implementing that entry or operating without plugins, run `context status`.
|
|
9
|
+
3. Execute safe mechanical CLI `next:` steps instead of merely reporting them.
|
|
10
|
+
Stop and ask at `Human gate:` next steps, placeholder next steps, human
|
|
11
|
+
decision gates, or external source-repo operations.
|
|
12
|
+
4. Before editing `src/index.ts`, read [Project API](../reference/project-api.md).
|
|
13
|
+
5. Before declaring or repairing packages, read [Package Outputs](./package-outputs.md)
|
|
14
|
+
and [Package Templates](../reference/package-templates.md).
|
|
15
|
+
6. Before asking a human gate question, read [Agent Dialogue](./agent-dialogue.md).
|
|
16
|
+
|
|
17
|
+
If the installed docs are unavailable, run `bun install` in the Context workspace.
|
|
18
|
+
|
|
19
|
+
## Dialogue Language
|
|
20
|
+
|
|
21
|
+
Use the user's current conversation language for explanations, questions,
|
|
22
|
+
confirmations, and final summaries. Treat CLI output, commands, flags, file
|
|
23
|
+
paths, ids, status values, JSONL payload keys, and `source_ref` tokens as
|
|
24
|
+
protocol text: copy those exactly and do not translate them.
|
|
25
|
+
|
|
26
|
+
At human gates, explain the product decision and impact before internal API
|
|
27
|
+
details. Do not start with `extractTs`, `include`, `exportedOnly`,
|
|
28
|
+
`reviewValidity`, placeholder commands, or raw TypeScript snippets unless the
|
|
29
|
+
user asks for implementation detail. The required dialogue patterns are in
|
|
30
|
+
[Agent Dialogue](./agent-dialogue.md).
|
|
31
|
+
|
|
32
|
+
## Do Not Self-Discover The SDK
|
|
33
|
+
|
|
34
|
+
Do not write temporary scripts to inspect `node_modules/@c4a/context/dist/index.js`
|
|
35
|
+
or infer API shapes from bundled output. The public contract is documented in:
|
|
36
|
+
|
|
37
|
+
```text
|
|
38
|
+
node_modules/@c4a/context/docs/reference/project-api.md
|
|
39
|
+
node_modules/@c4a/context/docs/reference/package-templates.md
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Workspace State Rules
|
|
43
|
+
|
|
44
|
+
- `src/index.ts` declares sources, phases, and packages.
|
|
45
|
+
- `sources/repo/index.yaml`, `sources/file/index.yaml`, and `sources/lark/index.yaml` declare sources.
|
|
46
|
+
- `unapproved/entities.jsonl` is the committed draft/rejected/deprecated ledger.
|
|
47
|
+
- `knowledge/` contains approved Markdown.
|
|
48
|
+
- `dist/` contains generated package outputs.
|
|
49
|
+
- file and Lark snapshots live under `sources/file/<name>/` and `sources/lark/<name>/`.
|
|
50
|
+
- `.tmp/context-runtime/` contains ignored runtime cache, logs, review HTML, previews, and locks.
|
|
51
|
+
|
|
52
|
+
Do not create hidden workspace state directories.
|
|
53
|
+
|
|
54
|
+
## Workflow Entrypoints
|
|
55
|
+
|
|
56
|
+
Present only the current workflow surface:
|
|
57
|
+
|
|
58
|
+
| Task | Current route |
|
|
59
|
+
|---|---|
|
|
60
|
+
| Register a knowledge boundary | `context source add file/lark/repo ...`, followed by the matching project phase declaration. Source registration is a user-confirmed boundary decision. |
|
|
61
|
+
| Capture document sources | Run the declared `capture:file:<source>` or `capture:lark:<source>` phase only after read permission. Capture writes committed snapshots under `sources/file/<name>/` or `sources/lark/<name>/`. |
|
|
62
|
+
| Investigate captured material | Use `context status` and the returned `context run align:<type>:<source>:<collection> --view ...` commands. Evidence views drive reading; raw directory grep is not the workflow. |
|
|
63
|
+
| Confirm prose structure | `alignProse` validates and stages `unapproved/structure.yaml`. Validation does not equal user confirmation; only confirmed lifecycle state may enter prose compile. |
|
|
64
|
+
| Compile source-bound drafts | `compileProse` turns confirmed structure into source-bound draft pages. It does not approve knowledge. |
|
|
65
|
+
| Review and apply | Use `context review html` and `context review apply`. Approved prose pages are source-mirrored; rewrite/compression problems should return to structure/compile repair before apply. |
|
|
66
|
+
| Close, verify, build | Run `context close`, `context verify`, then `context build`. Close derives `knowledge/structure.yaml`, approved edge projection, and the final verify gate. |
|
|
67
|
+
| Code extraction | Use `context source inspect <source-name>` and the declared extract phase preview before code draft writes. |
|
|
68
|
+
| Source retraction | Follow the current status or lifecycle command if one exists. Do not delete `sources/`, `knowledge/`, `unapproved/`, `dist/`, or `.tmp` to simulate lifecycle actions. |
|
|
69
|
+
|
|
70
|
+
Judgment behavior is part of evidence views, source span resolvers, repair
|
|
71
|
+
hints, review/status diagnostics, OKF indexes, and package query discipline. Do
|
|
72
|
+
not describe unsupported commands or unsupported lifecycle state as alternate
|
|
73
|
+
routes.
|
|
74
|
+
|
|
75
|
+
## Source Safety
|
|
76
|
+
|
|
77
|
+
The CLI never silently clones, checks out, resets, fetches, installs, builds, or
|
|
78
|
+
runs scripts inside source repositories. If a repo operation is needed, ask the
|
|
79
|
+
user first.
|
|
80
|
+
|
|
81
|
+
`missing-source` is a human gate. In user-facing language, describe the next
|
|
82
|
+
action as adding a knowledge source, not as filling CLI placeholders. Treat this
|
|
83
|
+
as a source boundary decision. Explain that the source name is a stable prefix
|
|
84
|
+
that appears in source refs and phase ids. Approved paths are derived from
|
|
85
|
+
collection, containment, and slug. NodeRef/ViewRef are identity fields, not path strings:
|
|
86
|
+
|
|
87
|
+
```text
|
|
88
|
+
knowledge/<collection>/<containment>/<slug>.md
|
|
89
|
+
repo:<source-name>#symbol:...
|
|
90
|
+
file:<source-name>/<document>#span:...
|
|
91
|
+
lark:<source-name>/<document>#span:...
|
|
92
|
+
capture:file:<source-name>
|
|
93
|
+
align:lark:<source-name>:architecture
|
|
94
|
+
dist/<source-name>-kb/
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Approved paths are not derived directly from the source name. Align/compile
|
|
98
|
+
derive them from collection, containment, and slug; extraction and structure
|
|
99
|
+
planning may choose containment that reflects package/module shape when the
|
|
100
|
+
source boundary intentionally covers multiple modules.
|
|
101
|
+
|
|
102
|
+
Ask what the user wants the source to cover: a single local Markdown/MDX document,
|
|
103
|
+
a local Markdown/MDX directory, an article/documentation repository as a file
|
|
104
|
+
source, a Lark/Feishu document URL or token, a local code repo/package, a remote
|
|
105
|
+
Git repo/package, or a multi-module namespace. Do not infer the source from cwd,
|
|
106
|
+
parent directories, monorepo layout, package names, or git remotes. Do not ask
|
|
107
|
+
for a raw source name as an isolated parameter; propose one only after the
|
|
108
|
+
boundary is clear.
|
|
109
|
+
|
|
110
|
+
If the user already provided a path and the remaining question is only the
|
|
111
|
+
source name, still explain the boundary implication before asking for
|
|
112
|
+
confirmation. A package/module path means the source name becomes the stable
|
|
113
|
+
source-ref, phase-id, and package-output identity. A parent monorepo/subspace
|
|
114
|
+
path means the source name is a source namespace for possible child modules,
|
|
115
|
+
and current extraction must inspect that parent before choosing concrete
|
|
116
|
+
package/subdirectory boundaries. Approved paths still come from collection,
|
|
117
|
+
containment, and slug.
|
|
118
|
+
|
|
119
|
+
Current execution supports repo sources, local Markdown/MDX file sources, and Lark /
|
|
120
|
+
Feishu document sources. Local
|
|
121
|
+
repo/package sources are registered with `context source add repo <name>
|
|
122
|
+
--local <path>`; the materialized `sources/repo/<name>` entry is an ignored
|
|
123
|
+
symlink to the selected checkout or subdirectory view. Local Markdown/MDX sources
|
|
124
|
+
are registered with `context source add file <name> --local <path>` plus any
|
|
125
|
+
needed `--include` patterns, captured with `captureFile`, then planned through
|
|
126
|
+
`alignProse` and compiled with
|
|
127
|
+
`compileProse`. A one-file-to-one-page outcome is a degenerate structure plan,
|
|
128
|
+
not a separate content path. Remote Git operations require explicit user approval before any
|
|
129
|
+
clone/checkout; clone into an ignored local path, checkout the requested commit,
|
|
130
|
+
then register that local checkout. Do not commit cloned source content. Lark /
|
|
131
|
+
Feishu sources are registered as document sources, captured through the Lark
|
|
132
|
+
capture phase, and written as committed snapshots under `sources/lark/<name>/`;
|
|
133
|
+
do not fetch or import Lark content with ad hoc scripts.
|
|
134
|
+
|
|
135
|
+
Extraction scope is also a human gate. If no extract phase is declared, explain
|
|
136
|
+
what code area and symbol policy will become draft knowledge, then ask which
|
|
137
|
+
registered source and file/symbol range to ingest. Do not inspect the source
|
|
138
|
+
repository to choose packages or globs on the user's behalf.
|
|
139
|
+
|
|
140
|
+
For monorepos, one source may conceptually cover the whole repo/subspace or one
|
|
141
|
+
package/subdirectory. Explain that the source name becomes a source-ref and
|
|
142
|
+
phase-id namespace. A parent source name can support grouped codegraph NodeRefs
|
|
143
|
+
such as `knowledge/codegraph/product-ui/component-web/...` and
|
|
144
|
+
`knowledge/codegraph/product-ui/component-lynx/...`. In the current executable
|
|
145
|
+
flow, use the whole repo/subspace only for inspection/planning. If the user wants
|
|
146
|
+
a focused package manual and chooses `packages/button`, register that
|
|
147
|
+
subdirectory as its own source and write
|
|
148
|
+
`extractTs({ source: source("button"), ... })`. Do not use
|
|
149
|
+
`include: ["packages/button/src/**"]` to choose a package from a larger source;
|
|
150
|
+
`include` only filters files inside the selected source.
|
|
151
|
+
|
|
152
|
+
Follow the source inspection pattern when scope is unclear: run
|
|
153
|
+
`context source inspect <source-name> --format json`, show the candidate package
|
|
154
|
+
paths from that CLI output, wait for the user to choose the package path(s), then
|
|
155
|
+
declare sources/phases. If the extraction preview reports modules outside the
|
|
156
|
+
confirmed source boundary, stop before review and repair the source declaration.
|
|
157
|
+
|
|
158
|
+
Before running extraction, prefer:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
context source inspect <source-name> --format json
|
|
162
|
+
context run <extract-phase-id> --dry-run --format json
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Use the `preview.sources[].modules[]`, `candidateEstimate`, and `agent_hints`
|
|
166
|
+
fields as the authoritative scope check. To the user, call it a preview without
|
|
167
|
+
writing candidates; avoid the internal CLI term. Also show `knowledgeTree` and
|
|
168
|
+
`knowledgePathExamples` before first extraction. Explain that approved pages
|
|
169
|
+
will be written under paths derived from collection, containment, and slug:
|
|
170
|
+
|
|
171
|
+
```text
|
|
172
|
+
knowledge/<collection>/<containment>/<slug>.md
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
If the source name, optional module segment, or resulting path shape looks
|
|
176
|
+
wrong, stop and ask whether to rename the source or change the source boundary
|
|
177
|
+
before running extraction. A source that already points at one package/module
|
|
178
|
+
root should not repeat the package name in the path. A source rename after
|
|
179
|
+
extraction is a migration, not a cosmetic change. Do not write ad hoc scripts to
|
|
180
|
+
count packages, parse `package.json`, or sample `unapproved/entities.jsonl`.
|
|
181
|
+
|
|
182
|
+
## Review Rules
|
|
183
|
+
|
|
184
|
+
- Use `context review html <collection> --open` for visual review. If the
|
|
185
|
+
browser cannot be opened, provide the emitted `file://` URL to the user.
|
|
186
|
+
- Use `context review list <collection>` only for a textual overview.
|
|
187
|
+
- Ask the user to paste the copied JSONL payload into chat. The agent writes
|
|
188
|
+
that pasted payload to a temporary scratch file and runs `context review apply
|
|
189
|
+
<payload-file>` only after the user has reviewed and provided the payload.
|
|
190
|
+
- Do not synthesize review payloads from HTML, JSON, runtime snapshots, or
|
|
191
|
+
candidate ids.
|
|
192
|
+
- Do not default candidates to approved/rejected on behalf of the user.
|
|
193
|
+
- If the user explicitly authorizes a quick or automated decision, use
|
|
194
|
+
`context review approve <candidate-id> --collection <collection>` /
|
|
195
|
+
`context review reject <candidate-id> --collection <collection>` or `--all`.
|
|
196
|
+
These commands still enforce the scoped candidate-id gate.
|
|
197
|
+
- Do not expand compact review JSONL into pretty JSON unless the user asks.
|
|
198
|
+
- Do not edit approved Markdown by hand as part of review apply.
|
|
199
|
+
|
|
200
|
+
## Prose Align And Compile Rules
|
|
201
|
+
|
|
202
|
+
After document capture, do not ask the user to choose an SDK path. Explain the
|
|
203
|
+
product sequence:
|
|
204
|
+
|
|
205
|
+
1. investigate material through Context evidence views;
|
|
206
|
+
2. propose a structure draft with nodes, section plans, supported edges, and
|
|
207
|
+
unresolved items;
|
|
208
|
+
3. ask the user to confirm the structure, because confirmation freezes paths,
|
|
209
|
+
section ownership, relationships, and compile order for this round;
|
|
210
|
+
4. compile source-bound draft pages from confirmed structure;
|
|
211
|
+
5. send compiled drafts through human review, then close and build.
|
|
212
|
+
|
|
213
|
+
One file per page is still possible, but it is represented as a simple
|
|
214
|
+
structure draft. It does not bypass structure confirmation or compile.
|
|
215
|
+
|
|
216
|
+
Material investigation:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
context run align:<type>:<source>:<collection> --view read-plan --format json
|
|
220
|
+
context run align:<type>:<source>:<collection> --view source-index --compact --format json
|
|
221
|
+
context run align:<type>:<source>:<collection> --view span-detail --span <source-ref> --format json
|
|
222
|
+
context run align:<type>:<source>:<collection> --view span-text --span <source-ref> --format json
|
|
223
|
+
context run align:<type>:<source>:<collection> --view schema --format json
|
|
224
|
+
context run align:<type>:<source>:<collection> --validate --input <structure.yaml> --format json
|
|
225
|
+
context run align:<type>:<source>:<collection> --view structure-summary --input <structure.yaml> --format json
|
|
226
|
+
context run align:<type>:<source>:<collection> --stage --input <structure.yaml> --format json
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Read source material only through these evidence views. `source-index` gives a
|
|
230
|
+
compact refs-first map when run with `--compact`; use `span-detail` /
|
|
231
|
+
`span-text` only for exact evidence. `structure-summary` is the review surface
|
|
232
|
+
for the structure confirmation gate. Do not inspect `sources/` or `.tmp`
|
|
233
|
+
directly.
|
|
234
|
+
|
|
235
|
+
Compile:
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
context run compile:<type>:<source>:<collection> --view read-plan --format json
|
|
239
|
+
context run compile:<type>:<source>:<collection> --view node-context --source <view-ref> --format json
|
|
240
|
+
context run compile:<type>:<source>:<collection> --view schema --format json
|
|
241
|
+
context run compile:<type>:<source>:<collection> --validate --input <compile-actions.yaml> --format json
|
|
242
|
+
context run compile:<type>:<source>:<collection> --stage --input <compile-actions.yaml> --format json
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Default compile actions should mirror source spans into `verbatim` body and
|
|
246
|
+
attach summary/kind/source refs. Explicit reader-visible content is not part of
|
|
247
|
+
the current compile action contract; split evidence or return to structure
|
|
248
|
+
confirmation instead. Relationships and cross references are structure typed
|
|
249
|
+
edges in current output; this workflow does not render relationship reference
|
|
250
|
+
blocks. Never inject relation markers into verbatim body.
|
|
251
|
+
|
|
252
|
+
## Package Rules
|
|
253
|
+
|
|
254
|
+
If `context status` says `needs-package-output`, treat it as a human gate.
|
|
255
|
+
First read [Package Outputs](./package-outputs.md). Then explain the package
|
|
256
|
+
decision using concrete output trees, not unexplained labels.
|
|
257
|
+
|
|
258
|
+
Recommended first option:
|
|
259
|
+
|
|
260
|
+
```text
|
|
261
|
+
dist/<name>-kb/
|
|
262
|
+
├── AGENTS.md
|
|
263
|
+
├── skills/knowledge-query/SKILL.md
|
|
264
|
+
└── wikis/
|
|
265
|
+
├── index.md
|
|
266
|
+
├── <group>/index.md
|
|
267
|
+
└── <group>/...
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
This is an agent knowledge-base package. It is the recommended first output for
|
|
271
|
+
agent consumption; the internal `skills/` folder follows agent installation
|
|
272
|
+
conventions.
|
|
273
|
+
The default `knowledge-query` skill teaches agents to query copied OKF root
|
|
274
|
+
directories structure-first, starting with `wikis/`, cite
|
|
275
|
+
page/section evidence, use structure/build metadata when present, and report
|
|
276
|
+
gaps instead of inventing unsupported answers. Tell the user that
|
|
277
|
+
`src/package-templates/kb/` is editable before build, so they can customize the
|
|
278
|
+
query skill or add project-specific skills when needed.
|
|
279
|
+
|
|
280
|
+
Selected OKF root subtrees such as `wikis/`, `guides/`, `rules/`, and
|
|
281
|
+
`feats/` follow the C4A OKF Profile. The package root contains agent
|
|
282
|
+
installation files; the OKF-compatible interchange surface is the selected OKF
|
|
283
|
+
root directories. Tell the user they can customize
|
|
284
|
+
`src/package-templates/kb/wikis/index.md` before build to describe package
|
|
285
|
+
scope and query guidance. The default root index should list only next-level
|
|
286
|
+
directories. `context build` generates child directory indexes such as
|
|
287
|
+
`<okf-root>/<group>/index.md` for deeper navigation.
|
|
288
|
+
|
|
289
|
+
Alternative:
|
|
290
|
+
|
|
291
|
+
```text
|
|
292
|
+
dist/<name>-llms/
|
|
293
|
+
└── llms.txt
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
This is an LLM text bundle output for one model/RAG import file.
|
|
297
|
+
|
|
298
|
+
The user may also skip package output for now and keep only `knowledge/`.
|
|
299
|
+
|
|
300
|
+
Do not offer `both` as a shortcut. If the user wants multiple outputs, declare
|
|
301
|
+
one package first, build and inspect it, then ask before adding another.
|
|
302
|
+
|
|
303
|
+
Every package needs a template path. Treat `src/package-templates/kb` and
|
|
304
|
+
`src/package-templates/llms` as editable starting points, not final deliverables.
|
|
305
|
+
The agent knowledge-base package template must contain at least one `SKILL.md` and
|
|
306
|
+
`wikis/index.md`; otherwise it is a hollow package and should not be reported
|
|
307
|
+
as usable. Template paths also must not collide with copied knowledge paths.
|
|
308
|
+
When a collision is reported, rename the template file or exclude the knowledge
|
|
309
|
+
path before build.
|
|
310
|
+
|
|
311
|
+
Do not present a clean `context build`, clean `context verify`, or file count as
|
|
312
|
+
proof that the output is useful. Inspect the generated package shape against the
|
|
313
|
+
user's chosen output contract.
|