@c4a/context-cli 0.5.29-beta.17 → 0.5.29-beta.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/README.md +3 -3
  2. package/cli.js +5039 -2615
  3. package/package.json +1 -1
  4. package/plugin/README.md +4 -3
  5. package/plugin/README_CN.md +4 -3
  6. package/plugin/commands/align.md +40 -4
  7. package/plugin/commands/capture.md +17 -1
  8. package/plugin/commands/compile.md +17 -12
  9. package/plugin/commands/query.md +1 -0
  10. package/plugin/skills/skill-align-workflow/SKILL.md +42 -9
  11. package/plugin/skills/skill-align-workflow/references/gates.md +85 -45
  12. package/plugin/skills/skill-compile-close/SKILL.md +3 -4
  13. package/plugin/skills/skill-compile-draft/SKILL.md +106 -305
  14. package/plugin/skills/skill-compile-draft/references/action-domain-gates.md +34 -0
  15. package/plugin/skills/skill-compile-draft/references/notes.md +34 -0
  16. package/plugin/skills/skill-compile-draft/references/refresh-and-update.md +71 -0
  17. package/plugin/skills/skill-compile-draft/references/structural-challenges.md +76 -0
  18. package/plugin/skills/skill-compile-judge/SKILL.md +106 -0
  19. package/plugin/skills/skill-context-query/SKILL.md +137 -92
  20. package/plugin/skills/skill-drop/SKILL.md +2 -3
  21. package/plugin/skills/skill-semantic-reconcile/SKILL.md +67 -183
  22. package/plugin/skills/skill-semantic-reconcile/references/leakage-and-ownership.md +31 -0
  23. package/plugin/skills/skill-semantic-reconcile/references/mode-semantics.md +41 -0
  24. package/plugin/skills/skill-semantic-reconcile/references/scope-review-and-omit.md +60 -0
  25. package/plugin/skills/skill-semantic-reconcile/references/temporal-and-evidence.md +66 -0
  26. package/plugin/skills/skill-semantic-reconcile/references/user-confirmation.md +69 -0
@@ -30,9 +30,9 @@ command. It does not hand-edit rendered knowledge.
30
30
  - Content / Section issues (`invalid-section-mount`, `body-ad-hoc-heading`, `dangling-source-alias`) → user re-runs `/context:compile` (draft loop fixes its own Section actions; the close stage does not patch)
31
31
  - Structural issues (`contains-cycle`, `edge-dangling-node`, `duplicate-slug`, `invalid-node-type`, `domain-same-file-child`) → user runs `/context:align` to revise the plan
32
32
  - Source issues (`dropped-source-reference`) → user runs `/context:drop <id>` to complete the drop
33
- - Exit 0 → summarise node/section totals, verify, `recompiled`, `locator_updates`, `rebuilt`, fingerprint rebuild count, and archive status / archived file count when printed; then stop.
33
+ - Exit 0 → summarise node/section totals, verify, `recompiled`, `locator_updates`, `rebuilt`, fingerprint rebuild count, archive status / archived file count, and any `ready_with_debt` coverage warnings when printed; then stop.
34
34
  - Exit 2 → report the full issue list verbatim + point at the right re-entry command above. Do not hand-open the affected rendered article.
35
- - If exit 2 includes `coverage-high-signal-unresolved`, follow the CLI hint. Read the node-scoped payload with `context workflow show --payload coverage-candidates --scope <node-run-scope> --view coverage`. If all unresolved candidates are intentionally excluded for the same reason, use `context compile --coverage-skip-unresolved --coverage-disposition-node <slug> --payload-digest <digest> --reason "<reason>"`; otherwise inspect `context schema coverage-disposition`. Do not guess workspace-scope payload paths.
35
+ - Coverage warning choice: `ready_with_debt` means close succeeded and unresolved coverage remains visible. You may either continue with the warning recorded, or run an uncovered-only repair/skip round. If all unresolved candidates are intentionally excluded for the same reason, use `context compile --coverage-skip-unresolved --coverage-disposition-node <slug> --reason "<reason>"`; otherwise inspect `context schema coverage-disposition`.
36
36
  - Never re-run `context compile --draft` from close to paper over verify failures. Draft failures belong in the draft loop.
37
37
  - Do not use Python, Node.js, shell scripts, `ls`, `find`, `rg`, `cat`, or similar ad-hoc commands to inspect `WORKSPACE_DIR`, `.context`, knowledge files, or `/tmp` workflow artifacts.
38
38
  - Derivable files self-heal: missing `_index.md` or `changelog.md` is rebuilt inside `compile --close` before the append, locator-only source moves are refreshed, non-canonical but hash-valid `source_ref` locators are canonicalized, and high-signal coverage candidates already backed by active Sections are marked covered. No pre-check needed.
@@ -62,11 +62,10 @@ Close is one in-process command with one exit code:
62
62
  | Outcome | Agent action |
63
63
  |---|---|
64
64
  | Exit 0, 0 issues | Summarise those counts in the user's language: Nodes touched; Sections added / updated / superseded / deprecated / skipped; `recompiled`; `locator_updates`; `rebuilt`; verify green. Stop. |
65
- | Exit 0, warnings only | Summarise + list warnings verbatim. Point at `/context:status` or `context cache status` when the warning is incremental-cache-related. Stop. |
65
+ | Exit 0, warnings only | Summarise + list warnings verbatim. For coverage warnings, name both choices: continue with `ready_with_debt`, or run an uncovered-only repair/skip round through `context compile --coverage-skip-unresolved` or `context schema coverage-disposition`. Stop. |
66
66
  | Exit 2, Section / content issue | Surface the full issue list; point the user at re-running `/context:compile` (the draft loop owns Section writes). Do NOT Edit the affected rendered article. |
67
67
  | Exit 2, structural issue (cycle, duplicate slug, `invalid-node-type`, `domain-same-file-child`) | Surface the full issue list; point the user at `/context:align` to revise structure. Do not re-run compile. |
68
68
  | Exit 2, `dropped-source-reference` | Surface the source-id; point the user at `/context:drop <id>` to complete the drop cleanup. |
69
- | Exit 2, `coverage-high-signal-unresolved` | Read the node-scoped coverage payload named in the CLI hint. If all unresolved candidates are intentionally covered by sibling Nodes or should not be written for this Node for the same reason, run `context compile --coverage-skip-unresolved --coverage-disposition-node <slug> --payload-digest <digest> --reason "<reason>"`; otherwise submit targeted dispositions from `context schema coverage-disposition`. |
70
69
 
71
70
  The close stage never edits rendered knowledge on the agent side. Every verify error routes back to the correct upstream command (compile / align / drop), never sideways into a hand Edit. Use the CLI issue code and hint printed by `context compile --close` for the error→command mapping.
72
71
 
@@ -4,7 +4,7 @@ description: >
4
4
  Packaged skill invoked by `/context:compile`; not a user slash command. For one Node at a time, reads
5
5
  the CLI-provided `NodeContext` (planned metadata, raw snippets, and
6
6
  existing Sections if any), classifies every raw fragment into a Section
7
- kind via the priority chain, writes content + detail + `source_refs[]`,
7
+ kind via the priority chain, writes `body` + `source_refs[]`,
8
8
  and emits a compile draft JSON document. The CLI
9
9
  validates the actions via `context compile --draft <slug> --input - --plan`.
10
10
  Activates when `/context:compile` iterates across the confirmed align plan.
@@ -14,234 +14,98 @@ tools:
14
14
 
15
15
  # skill-compile-draft — write Section actions for one Node
16
16
 
17
- Classify raw evidence for one Node into `add / update / supersede /
18
- deprecate / skip` actions; emit JSON; the CLI performs every write.
17
+ Classify raw evidence for one Node into `add` / `skip` (and on refresh: `update` / `supersede` / `deprecate`) actions; emit JSON; the CLI performs every write.
19
18
 
20
19
  ## TL;DR — Non-negotiables
21
20
 
22
21
  - One Node per invocation — `target_node` MUST equal `node.slug`; no cross-Node writes. Finish the current Node's draft quality checks before the caller moves to another Node's review/apply loop.
23
22
  - Agent emits JSON only; no markdown, no direct workspace file writes. The caller passes the JSON to `context compile --draft <slug> --input - --plan --prepare`; the CLI stores workflow payloads. `--save-input` is only for an explicit debug scratch copy.
24
- - Default compile sends changed-only NodeContext. Treat `raw_snippets[]` as the complete evidence boundary; never use direct workspace file tools to expand it.
25
- - Use `raw_snippet_indexes.citation_eligible` as the citeable evidence set; `raw_snippet_indexes.context_only` and every secondary shared snippet are background only. `request_full_text` may expose full secondary text for inspection, but it does not make that snippet citation-eligible. If a secondary shared block is needed as evidence, emit `pending_ownership_challenge` or `structure_challenge`; do not cite it. If the NodeContext is too large and only citation handles are needed, ask the caller to use `context compile --source-refs <slug> --format json` and cite from `citation_refs[]`; do not slice the saved NodeContext with ad-hoc scripts.
26
- - Do not use Python, Node.js, shell scripts, `ls`, `find`, `rg`, `cat`, or similar ad-hoc commands to inspect or preprocess `WORKSPACE_DIR`, `.context`, NodeContext scratch files, or `/tmp` workflow artifacts.
27
- - If `incremental.status` is `full-context`, draft from the full fallback and preserve the `unknown_inputs[]` reasons in any abort/retry explanation.
28
- - The CLI may deterministically skip unchanged output or update locator-only evidence before writing. Do not force rewrites to bypass fingerprint skip.
29
- - `incremental.locator_only_changes[]` entries have `agent_action: "none"` and `handled_by: "compile-close"`; do not emit draft actions for those Sections unless the same Section also has a real `changed_blocks[]` content change.
30
- - Actions are candidate write actions, not final semantic decisions. If raw appears similar to existing knowledge, add only a `reconcile_hint`; the semantic reconcile procedure may ignore it.
31
- - For `node.type: "action"`, use `node.action_gate` as the compile boundary. Actor, goal/outcome, repeatability, answerability, trigger, step, and phase claims must come from cited `raw_snippets[]` or structured `action_gate.inference_sources`; if `trigger_blocks` is empty, do not invent a trigger.
32
- - For `node.type: "domain"`, treat `node.domain_gate` as grouping metadata only. It can explain why child Nodes belong under the Domain, but it is not evidence for a Section unless the same fact appears in citation-eligible raw snippets.
33
- - Note snippets are captured conversation material. `raw_snippets[].note_intent`, `anchored_to[]`, and `revision_kind` are prioritization hints only: they may suggest update / supersede / complement / skip, but they never authorize a write without semantic review.
23
+ - Evidence boundary: treat `raw_snippets[]` as complete. Only `raw_snippet_indexes.citation_eligible` may be cited; `context_only` and secondary-shared snippets are background. `request_full_text` may expose full visible evidence text for inspection, including primary evidence, but it does not change citation eligibility. If a secondary-shared or `context_only` block holds facts that need citation, emit `pending_ownership_challenge` or `structure_challenge` — see [references/structural-challenges.md](references/structural-challenges.md). Never `grep` / `sed` / `jq` / `cat` / `head` raw `--format json` stdout or workflow scratch files in `/tmp` or `.context/.cache/` to recover a token. Instead: for the digest of any workflow payload use `context workflow show --payload <name> --digest-only --format text` (prints just the digest); for substructure use explicit compact views such as `context compile --source-refs <slug> --format json`, `context workflow show --payload node-context --view source-refs --unwrap --format json`, or `context workflow show --payload prepare --view issues --unwrap --format json`; for write commands that take `--payload-digest`, omit the flag entirely and let the CLI auto-resolve the latest payload for the current workflow scope.
24
+ - Actions are candidate write actions, not final semantic decisions; `context reconcile prepare` re-derives near-duplicate / conflict / merge relations from `candidates[]` on its own. Op naming is scoped by schema: compile-draft `actions[]` already targets Sections, so Section lifecycle ops are verb-only (`add`, `update`, `supersede`, `deprecate`, `skip`). Do not use align-style names such as `add_section`, `write_section`, or `propose_section`.
34
25
  - Source support passing is not completion. Before emitting, estimate coverage from the provided `raw_snippets[]`: if there are 3+ citation-eligible snippets, a one-action draft is valid only when the later snippets are duplicates, navigation, placeholders, or continuations of the same fact. Small dense docs still need multiple actions when later snippets state distinct capabilities, constraints, examples, risks, FAQ, or usage notes. Large manuals/design docs should compile to several orthogonal actions in the same draft. Do not switch into "speed mode" because the first action validates; coverage is part of the draft task.
35
- - Pick `kind` from the form of the cited raw block: code / config / command sample → `example`; verifiable rule with a check method → `spec`; stable invariant, design rule, or core mechanism `principle`; ≥2 subjects × ≥2 dimensions → `comparison`; explicit risk or caveat `warning`; Q+A pair `faq`; real incident with timeline `incident`; versioned change record → `changelog`. Reach `description` only when none of those forms fit — narrative that defines an entity, explains a mechanism, or summarises a stance. First matching form wins.
26
+ - Pick `kind` by the [Section Kind Canon](#section-kind-canon), also exposed as `section_kind_priority` in `context schema compile-draft`. First matching form wins. A `decision` needs at least two surfaced alternatives plus a reason; bare "we use X because Y" is `spec`. Reach `description` only after every more specific kind fails.
36
27
  - `kind × node.type` must satisfy the CLI Section mount matrix; mismatches get rejected at write time. When the strongest kind is blocked by mount matrix, fall to the next legal kind whose form actually fits — do not collapse to `description` just because it mounts everywhere, and do not invent thin precision (e.g. one-line `spec`) just to avoid `description` either. See [Description anti-abuse gates](#description-anti-abuse-gates) for the classification checks at the description boundary.
37
28
  - Every write action cites raw via `source_refs[]`, choosing values from `raw_snippets[].source_ref`. Use a single-element array for one citation. Treat each source ref as an opaque citation token; never fabricate, parse, dereference, or cite navigation-only blocks as evidence for a content Section.
38
- - `content` ≤256 chars; long prose goes in `detail`. If a cited raw sentence is already short, single-line, and readable, use it with `content_mode: "extract"` instead of asking AI to summarize it. Do not compress 200 readable characters into a 180-character paraphrase just to make it look rewritten.
39
- - `detail` is not an evidence echo field. Do not copy raw evidence into `detail`, do not prefix detail with labels such as `原文:`, and do not use detail only to show the raw quote. Raw evidence is traceable through `source_refs[]`.
40
- - For `example` Sections, if the cited raw snippet contains command / config / code fences, keep `content` as a short summary and preserve the relevant fenced block in `detail`; do not collapse copyable examples into prose-only summaries unless semantic review asks the user and the user accepts that compression.
41
- - Preserve documentation/reference URL blocks. If a cited raw block is primarily links (官网 / docs / reference / related links), create a small `description` Section such as "相关链接" and put every URL in `detail`; do not drop link-only evidence just because it is not prose.
42
- - For `add` and `supersede.new`, omit optional fields when empty; do not emit `detail: null`. `detail: null` only has "clear existing detail" meaning on `update`.
29
+ - Use one `body` field for Section prose; it may be long and may contain fenced code. The CLI derives the internal short claim/detail split and rejects retired fields (`content`, `detail`, singular `source_ref`, quoted-evidence) with canonical repair hints read those hints rather than memorising the blacklist. Omit optional fields when empty.
30
+ - Preserve documentation/reference URL blocks. If a citation-eligible raw block is primarily links (官网 / docs / reference / related links), create a small `description` Section such as "相关链接" and keep every URL in `body`; do not drop link-only evidence just because it is not prose. If the URL block is only `context_only`, keep it as background and emit an ownership/structure challenge instead of citing it.
43
31
  - `refers_to_nodes[]` only carries slugs present in the context's glossary, existing Sections, or the current align plan; never invent one.
44
- - `supersede` is for semantic replacement; `update` is for typo / wording fixes; `deprecate` needs a `reason`; `skip` is the honest default when raw adds nothing.
45
- - If a note or raw snippet was reviewed and should intentionally not write active knowledge, emit `skip` with `source_refs[]` from that exact snippet. This lets semantic review record `reviewed_no_write`; a bare skip is only for deterministic no-op cases such as unchanged input or navigation-only context.
32
+ - `skip` is the honest default when raw adds nothing. Bare `skip` (no `source_refs[]`) is only for deterministic no-ops such as unchanged input or pure navigation. When a snippet was reviewed and intentionally not written, emit `skip` with `source_refs[]` from that snippet so semantic review can record `reviewed_no_write`.
46
33
  - Any Node may legitimately compile to no Sections when the provided snippets contain only navigation (`Parent` / `Children` / `Related` / `Relations`) or placeholder text that explicitly says no detailed content is available. Emit `skip`; do not turn align summaries, parent/child lists, sibling links, or placeholders into `description` Sections. The align graph and Node metadata preserve structure; active Sections need citation-eligible content.
47
34
  - FAQ collections attach to the most specific finalized Node (Entity → Action → Domain fallback); never create a standalone FAQ container.
48
- - Output language: `content`, `detail`, Node-facing summaries, and user-facing draft explanations follow `NodeContext.generation_policy.language` when present; otherwise match the raw material. Preserve product names, code identifiers, CLI flags, slugs, `source_ref` tokens, and exact quoted evidence as printed. Kind / confidence / identifier fields stay English.
49
- - Stable output: keep action order aligned with evidence order, keep object fields in the documented schema order, omit empty optional fields, and do not add current timestamps, random ids, scratch paths, or host paths. Fixed rules and schema come from this skill; only the current NodeContext should vary between repeated Node draft calls.
35
+ - Output language: Node-facing summaries and user-facing draft explanations follow `NodeContext.generation_policy.language` when present; otherwise match the raw material. Draft `body` is source-bound: prefer the cited source language when it differs from the workspace language, and do not translate quoted English facts into Chinese just to satisfy workspace language. Preserve product names, code identifiers, CLI flags, slugs, `block_id` / `source_ref` tokens, and exact quoted evidence as printed. Kind / confidence / identifier fields stay English.
36
+ - Stable output: keep action order aligned with evidence order that ordering is the only stability concern the CLI cannot enforce. The CLI rejects unknown fields (timestamps, random ids, host/scratch paths) and canonicalises stored payloads; fixed rules and schema come from this skill, so only the current NodeContext should vary between repeated Node draft calls.
37
+
38
+ ## Edge cases — consult references when:
39
+
40
+ | Condition | Reference |
41
+ |---|---|
42
+ | `node.type` is `action` or `domain` | [references/action-domain-gates.md](references/action-domain-gates.md); use `node.action_gate` (including `trigger_blocks`) and treat `node.domain_gate` as grouping metadata |
43
+ | any `raw_snippets[].source_type` is `"note"` | [references/notes.md](references/notes.md) |
44
+ | `existing.sections[]` non-empty, **or** `incremental.status` is `unchanged` / `full-context`, **or** `incremental.locator_only_changes[]` non-empty | [references/refresh-and-update.md](references/refresh-and-update.md) |
45
+ | evidence implies missing Action / wrong parent / `depends_on` gap / ownership upgrade from `context_only` or secondary-shared | [references/structural-challenges.md](references/structural-challenges.md) |
46
+
47
+ If none of the above hold, you are on the main path (first compile of an entity Node with default `changed-only` incremental status). The procedure below covers that path end-to-end.
50
48
 
51
49
  <reference>
52
50
 
53
51
  ## Input — `NodeContext`
54
52
 
55
- ```jsonc
56
- {
57
- "node": {
58
- "slug": "...", "type": "entity|action|domain",
59
- "tags": [...], "title": "...",
60
- "sources": ["..."], "aliases": ["..."], "summary": "...",
61
- "planned_sections": ["spec", "..."],
62
- "action_gate": {
63
- "actor_blocks": ["b0002"],
64
- "trigger_blocks": [],
65
- "goal_blocks": ["b0003"],
66
- "step_blocks": ["b0004"],
67
- "outcome_blocks": ["b0005"],
68
- "repeatability_or_plan_blocks": ["b0006"],
69
- "inference_sources": {
70
- "actor": { "source_type": "explicit-block", "evidence_blocks": ["b0002"], "rationale": "..." },
71
- "outcome_or_goal": { "source_type": "explicit-block", "evidence_blocks": ["b0003"], "rationale": "..." },
72
- "repeatability_or_plan": { "source_type": "explicit-block", "evidence_blocks": ["b0006"], "rationale": "..." },
73
- "answerability": { "source_type": "ref-node", "ref_nodes": ["..."], "rationale": "..." }
74
- }
75
- },
76
- "domain_gate": {
77
- "scope_blocks": ["b0001"],
78
- "child_refs": ["..."],
79
- "grouping_reason": "..."
80
- }
81
- },
82
- "generation_policy": {
83
- "language": "Chinese",
84
- "source": "workspace.language",
85
- "applies_to": ["node.title", "node.summary", "section.content", "section.detail", "user_facing_report"],
86
- "instruction": "Generate knowledge titles, summaries, Section content/detail, and user-facing reports in Chinese; preserve product names, code identifiers, CLI flags, source_ref tokens, slugs, and quoted evidence exactly when needed."
87
- },
88
- "existing": { // present if the Node already exists
89
- "sections": [
90
- { "id": "section-1", "kind": "description", "content": "...",
91
- "detail": "...", "status": "active|deprecated",
92
- "confidence": "...", "source_ref": "src-1#anchor L10-14@ab12cd34ef56",
93
- "refers_to_nodes": [...] }
94
- ]
95
- },
96
- // Default NodeContext does not expose raw file paths. Copy raw_snippets[].source_ref
97
- // into draft source_refs[]; identify blocks via source_id + block_locator_id (or block_hash).
98
- "mentions": [ { "line": 12, "quote": "...", "source_id": "local:billing", "block_locator_id": "h2-api" } ],
99
- "raw_snippets": [ { "line": 10,
100
- "line_range": [10, 18],
101
- "source_ref": "src-1#api L10-18@ab12cd34ef56",
102
- "quote": "...context block...",
103
- "mention_quote": "...",
104
- "source_type": "local|feishu|note",
105
- "source_id": "local:billing",
106
- "note_intent": "revision|decision|brainstorm",
107
- "anchored_to": [{ "node_slug": "...", "section_id": "section-1" }],
108
- "revision_kind": "replace|clarify|...",
109
- "block_locator_id": "h2-api",
110
- "block_hash": "sha256:...",
111
- "change_status": "changed" } ],
112
- "incremental": {
113
- "mode": "changed-only",
114
- "status": "changed-only|full-context|unchanged",
115
- "reason": "source_block_changed|unknown-input|first-compile",
116
- "changed_blocks": [ { "status": "changed", "source_id": "local:billing", "block_locator_id": "h2-api" } ],
117
- "locator_only_changes": [ { "source_id": "local:billing", "agent_action": "none", "handled_by": "compile-close", "affected_sections": ["section-3"] } ],
118
- "unknown_inputs": [ { "scope": "compile-changes", "reason": "section-fingerprints-missing" } ]
119
- }
120
- }
121
- ```
53
+ Canonical shape: `context schema node-context --format yaml` (or `--format json`). The CLI is the source of truth for fields, enums, and produced-by paths.
122
54
 
123
- `mentions` = raw positions that named this Node. `raw_snippets` =
124
- wider context blocks around those positions, or the changed raw blocks
125
- selected by `context compile --scan-changes`. Never reach outside these —
126
- they are the evidence floor.
127
- `source_id` is the source registry id, such as `local:billing`; `src-N`
128
- aliases only appear inside `source_ref` strings.
129
- When `source_type` is `note`, the snippet came from `context capture --note`.
130
- Use `note_intent`, `anchored_to[]`, and `revision_kind` to decide which
131
- existing Section to compare first. They are routing hints, not proof that the
132
- note should be written as active knowledge.
133
- `node.sources[]` are the only sources that can be cited as `src-N`.
134
- `node.context_sources[]` may contribute `raw_snippets[]` for comparison or
135
- background, but they are context-only and must not be cited unless the CLI has
136
- also placed that source in `node.sources[]`.
137
- `node.action_gate` is present only for finalized Action Nodes. Use it to avoid
138
- inventing process semantics: write triggers only when `trigger_blocks` or cited
139
- raw explicitly provide them; write actor / outcome / repeatability claims only
140
- from cited raw or the matching structured `inference_sources` entry. If
141
- `answerability` depends on `ref_nodes`, use `refers_to_nodes[]` or a local link
142
- hint instead of describing another Node's internals.
143
- `node.domain_gate` is present only for finalized Domain Nodes. It is grouping
144
- metadata for scope and children; do not turn `grouping_reason` into a Section
145
- unless citation-eligible raw snippets state the same claim.
146
-
147
- ## Output — Compile Draft JSON
148
-
149
- ```jsonc
150
- {
151
- "schema_version": "compile.draft.v2",
152
- "target_node": "<matches node.slug>",
153
- "actions": [
154
- { "op": "add", "kind": "spec",
155
- "content": "...", "detail": "...",
156
- "refers_to_nodes": ["..."],
157
- "source_refs": ["src-1#api L10-14@ab12cd34ef56"],
158
- "content_mode": "extract",
159
- "basis_spans": [
160
- { "source_ref": "src-1#api L10-14@ab12cd34ef56" }
161
- ]
162
- },
163
- { "op": "update", "target_section_id": "section-3",
164
- "content": "...", "detail": null, // null clears detail
165
- "refers_to_nodes": null,
166
- "source_refs": ["src-1#api L18-21@cd34ef56ab78"],
167
- "content_mode": "minimal_paraphrase",
168
- "paraphrase_reason": "fragment_fix",
169
- "basis_spans": [
170
- { "source_ref": "src-1#api L18-21@cd34ef56ab78" }
171
- ] },
172
- { "op": "supersede", "target_section_id": "section-5",
173
- "reason": "raw published a new retention value",
174
- "new": { "kind": "spec", "content": "...", "detail": "...",
175
- "refers_to_nodes": ["..."],
176
- "source_refs": ["src-1#limits L30-34@ef56ab78cd90"],
177
- "content_mode": "extract",
178
- "basis_spans": [
179
- { "source_ref": "src-1#limits L30-34@ef56ab78cd90" }
180
- ] } },
181
- { "op": "deprecate", "target_section_id": "section-2", "reason": "..." },
182
- { "op": "skip", "reason": "no new evidence in raw snippets" },
183
- { "op": "skip", "reason": "reviewed; intentionally not written",
184
- "source_refs": ["src-1#note L4-8@ab12cd34ef56"] },
185
- { "op": "structure_challenge",
186
- "challenge_id": "ch_0001",
187
- "kind": "missing_action_node",
188
- "node_slug": "<matches node.slug>",
189
- "action_tag": "rollout-runbook",
190
- "summary": "The cited evidence is a repeatable procedure.",
191
- "source_ref": "src-1#ops L40-55@cd34ef56ab78",
192
- "reason": "Align must review structure before compile writes process prose." },
193
- { "op": "structure_challenge",
194
- "challenge_id": "ch_0002",
195
- "kind": "wrong_shared_block_split",
196
- "node_slug": "<matches node.slug>",
197
- "unresolved_target": "rollout-runbook",
198
- "reason": "The finalized shared block split leaves this Node with only secondary, non-citable evidence." },
199
- { "op": "pending_ownership_challenge",
200
- "challenge_id": "och_0001",
201
- "node_slug": "<matches node.slug>",
202
- "block_id": "b0032",
203
- "requested_role": "shared",
204
- "reason": "A visible context_only or secondary shared block contains facts that need citation." }
205
- ]
206
- }
207
- ```
55
+ Boundary recap (rules not captured by the schema enums):
56
+
57
+ - `mentions[]` are raw positions that named this Node; `raw_snippets[]` are the wider context blocks around those positions, or the changed raw blocks selected by `context compile --scan-changes`. These two arrays are the evidence floor — never reach outside them.
58
+ - `node.sources[]` are the only sources that may be cited as `src-N`. `node.context_sources[]` contribute `raw_snippets[]` for comparison or background only and must not be cited unless the CLI has also placed that source in `node.sources[]`.
59
+ - `source_id` is the source registry id (e.g. `local:billing`); `src-N` aliases only appear inside `source_ref` strings — copy `raw_snippets[].source_ref` verbatim into draft `source_refs[]`.
60
+
61
+ ## Output Compile Draft JSON (main path)
62
+
63
+ Canonical shape: `context schema compile-draft --format yaml` (or `--format json`). The CLI is the source of truth for fields, enums, and validation — do not memorise the shape from this file.
64
+
65
+ Main-path ops are **`add`** and **`skip`**. A typical new Section action is `{ op: "add", kind: "<chain-picked>", body: "...", source_refs: ["src-1#... L10-14@..."] }`; never spell that as `add_section` because the `actions[]` array already names the target object. A bare skip is `{ op: "skip", reason: "..." }`; a reviewed-no-write skip carries `source_refs[]` from the cited snippet.
66
+
67
+ `update` / `supersede` / `deprecate` ops live in [references/refresh-and-update.md](references/refresh-and-update.md). `structure_challenge` / `pending_ownership_challenge` ops live in [references/structural-challenges.md](references/structural-challenges.md). Do not emit them from the main path.
68
+
69
+ `source_refs[]` values are copied verbatim from `raw_snippets[].source_ref`; a single citation is still a single-element array. When one Section summarises contiguous multi-block evidence, list only the source refs the `body` actually consumes. If the CLI reports `compile-source-refs-auto-narrowed`, it safely reduced an over-wide citation; removed refs are still uncovered, so add separate actions for distinct knowledge or leave them to an evidence-carrying `skip`. Set `rewrite: false` only when the raw wording is already clear and should be preserved. Preserving a cited prose/bullet list as the Section's user-facing content is allowed when that list is the actual knowledge; the anti-pattern is copying raw text into long detail only as traceability or lexical-score padding. For `example` Sections that cite command / config / code fences, include the relevant fenced block alongside the short summary in `body`.
70
+
71
+ ## Section Kind Canon
72
+
73
+ Walk this priority chain and stop at the first form that fits:
208
74
 
209
- `source_refs[]` values are copied from `raw_snippets[].source_ref`; a single
210
- citation is still written as a single-element array. Submitting singular
211
- `source_ref` or quoted-evidence fields is rejected with canonical repair hints.
212
- Every Section write (`add`, `update` with content/detail/source refs, and
213
- `supersede.new`) must include `content_mode` plus `basis_spans[]`. Use
214
- `content_mode: "extract"` when the cited raw sentence already fits the
215
- single-line content contract and you keep the original sentence order. If you reorder
216
- sentences, merge sentences with new punctuation, or consolidate bullets, use
217
- `content_mode: "minimal_paraphrase"` with the matching `paraphrase_reason`. Use `content_mode: "minimal_paraphrase"` only
218
- when direct extract would be malformed, too broad, duplicated, or needs
219
- multi-span consolidation; include `paraphrase_reason`.
220
- Do not mark sentence 1 + sentence 3 from the same evidence block as
221
- `extract`; non-contiguous copies are `minimal_paraphrase` even when every word
222
- came from raw evidence.
223
- `structure_challenge` and `pending_ownership_challenge` do not write Sections;
224
- the CLI stores them as workflow payloads and close exposes them as debt until
225
- align resolution handles them. Supported structure challenge kinds include
226
- `missing_action_node`, `extra_action_node`, `wrong_shared_block_split`,
227
- `missing_depends_on_edge`, and `wrong_parent`.
228
-
229
- Optional `reconcile_hint` shape for any action:
230
-
231
- ```jsonc
232
- {
233
- "reconcile_hint": {
234
- "suggested_relation": "exact_duplicate|near_duplicate|complement|conflicts|keep_separate",
235
- "suggested_action": "duplicate_skip|merge_update|keep_separate|ask_user",
236
- "similar_section_id": "section-3",
237
- "confidence": 0.72,
238
- "reason": "The new snippet is close to the existing sandbox isolation Section."
239
- }
240
- }
75
+ ```
76
+ example -> comparison -> faq -> incident -> changelog ->
77
+ decision -> spec -> warning -> principle -> description
241
78
  ```
242
79
 
243
- Hints are recall/explanation aids only. The final relation/action must come
244
- from `context reconcile prepare` candidates and semantic reconcile decisions.
80
+ | kind | Use when | `body` should contain | Positive / negative boundary |
81
+ |---|---|---|---|
82
+ | `example` | fenced code, config, or command sample | what the sample does plus the full snippet when useful | `<AppProvider />` sample or `bun run build`; plain "wrap with AppProvider" is `description` |
83
+ | `comparison` | at least two subjects across at least two dimensions | compared subjects, dimensions, and table/matrix | `X vs Y vs Z` table; "two options have tradeoffs" is `description`; "choose X over Y" is `decision` |
84
+ | `faq` | one explicit question-answer pair | question plus answer | Q/A block; an "X FAQ collection" is several `faq` Sections on X, not a container Node |
85
+ | `incident` | happened event with time, impact, and root cause / handling | time, severity/impact, root cause, timeline/actions | dated outage postmortem; "risk may happen" is `warning` |
86
+ | `changelog` | version/date plus change description | version, change type, migration notes if present | `v1.2.0 added X`; "X supports Y" without version is `spec` or `description` |
87
+ | `decision` | text surfaces at least two alternatives plus a reason | selected option, alternatives, reason, impact | "choose async rather than sync because..."; bare "use X because..." is `spec` |
88
+ | `spec` | verifiable behavior, threshold, default, limit, or check method | object, condition, value/constraint | retry max 3; vague "consider concurrency" is `principle` or `description` |
89
+ | `warning` | factual risk, caveat, or negative consequence | trigger condition and consequence | "without warmup first 30s timeout"; "don't change config" without consequence is too vague |
90
+ | `principle` | stable design invariant / philosophy with no check method and no choice action | invariant and reason | "single way to write UI"; retry max 3 is `spec`; "choose X over Y" is `decision` |
91
+ | `description` | fallback definition, overview, or plain narrative | definition, purpose, scope, distinction | only after the nine kinds above fail; do not use it to hide lists, rules, tables, samples, risks, or decisions |
92
+
93
+ Mount matrix:
94
+
95
+ | kind | domain | entity | action |
96
+ |---|:---:|:---:|:---:|
97
+ | `description` | yes | yes | yes |
98
+ | `spec` | no | yes | yes |
99
+ | `warning` | yes | yes | yes |
100
+ | `principle` | yes | yes | no |
101
+ | `decision` | yes | yes | yes |
102
+ | `incident` | no | yes | yes |
103
+ | `example` | no | yes | no |
104
+ | `changelog` | no | yes | no |
105
+ | `comparison` | no | yes | no |
106
+ | `faq` | yes | yes | yes |
107
+
108
+ When the strongest kind is not mountable on this Node type, choose the next legal kind that the evidence truly supports, or `skip` with a structural challenge reason. Do not force `description` just because it mounts everywhere.
245
109
 
246
110
  ## Confidence rubric
247
111
 
@@ -261,36 +125,16 @@ Don't game the rubric. Compile-close flags Nodes dominated by `speculative` Sect
261
125
  `description` is the kind for narrative claims that do not match any other form. Before locking in `kind: description` for a snippet, run three classification checks against the cited block:
262
126
 
263
127
  1. **Atomicity**: single narrative, or multi-step / multi-row / multi-config? Multi → split into the right kinds — each step into its own `spec` / `warning`, each row into a `comparison` Section, each config block into `example` (sample) or `spec` (constraint with a check method).
264
- 2. **Kind-precision**: does a higher-priority kind fit better? A comparison table belongs in `comparison`; a verifiable rule belongs in `spec`; a stable design rule, core mechanism, or "X is the key to Y" claim belongs in `principle`; a code / config / command block belongs in `example`; explicit risks belong in `warning`; a Q+A pair belongs in `faq`; a real incident with timeline belongs in `incident`.
128
+ 2. **Kind-precision**: does a higher-priority kind fit better? A code / config / command block belongs in `example`; a comparison table belongs in `comparison`; a Q+A pair belongs in `faq`; a real incident with timeline belongs in `incident`; a versioned change record belongs in `changelog`; a multi-option choice (≥ 2 surfaced candidates + rationale) belongs in `decision`; a verifiable rule with a check method belongs in `spec`; explicit risks belong in `warning`; a stable design rule or core mechanism without surfaced alternatives or check method belongs in `principle`.
265
129
  3. **Action threshold**: multi-step fragments that clear the Action bar → emit `op: skip` with a note "evidence warrants sub-Action; re-align needed"; do not create Nodes from this skill.
266
130
 
267
- A Node whose raw is genuinely narrative — definitions, summaries, plain prose without enumerations or normative wording — legitimately ends with description-dominant output. The smell fires the other way: when raw contained enumerations, normative rules, or code blocks, and the draft collapsed them to `description`. Redraft from Step 2 in that case, not from a percentage threshold.
268
-
269
- Navigation-only exception: if a Node's evidence is only a child list, relation navigation, sibling link, parent pointer, or placeholder wording, emit `skip`. The Node remains useful through align graph edges, `## Contains` / `## Related`, and metadata; a navigation-only snippet is not evidence for a `description` claim. The Node `summary` is metadata for context and listings, not a Section or a required lead paragraph.
131
+ A Node whose raw is genuinely narrative — definitions, summaries, plain prose without enumerations or normative wording — legitimately ends with description-dominant output. The smell fires the other way: when raw contained enumerations, normative rules, or code blocks, and the draft collapsed them to `description`. Redraft from Step 2 in that case, not from a percentage threshold. Navigation-only evidence is handled separately by the TL;DR navigation rule and Step 2 — the gates above are not the right place to second-guess that path.
270
132
 
271
133
  ## Glossary and `refers_to_nodes`
272
134
 
273
- When raw mentions a name that overlaps the workspace glossary, put
274
- that name's slug in `refers_to_nodes[]` for the Section that discusses
275
- it — do NOT substitute it into the prose. This preserves explicit
276
- cross-Node references for query answers and citations without rewriting
277
- the claim. Slugs come from existing Sections, the context glossary, or Nodes already declared by the current align plan; never invent one. A
278
- Section can reference multiple Nodes (common on `comparison` /
279
- `decision`).
280
- If the CLI returns `compile-missing-refers-to-node`, treat it as advisory:
281
- add the suggested slug only when the Section actually depends on that Node;
282
- otherwise leave the draft unchanged and rely on the cited `source_ref`.
135
+ When raw mentions a name that overlaps the workspace glossary, put that name's slug in `refers_to_nodes[]` for the Section that discusses it — do NOT substitute it into the prose. This preserves explicit cross-Node references for query answers and citations without rewriting the claim. Slugs come from existing Sections, the context glossary, or Nodes already declared by the current align plan; never invent one. A Section can reference multiple Nodes (common on `comparison` / `decision`).
283
136
 
284
- ## Supersede vs update
285
-
286
- | Situation | op |
287
- |---|---|
288
- | Same meaning, fixing typo / tightening prose / adding detail | `update` — same `section-N` stays active |
289
- | New rule replaces old rule (values / policy / spec changed) | `supersede` — old flips to `deprecated`; new gets fresh `section-N+k` |
290
- | Old rule removed without replacement | `deprecate` (with `reason`) |
291
-
292
- `supersede` preserves the audit trail so readers see the prior
293
- policy — critical for specs / decisions / principles.
137
+ If the CLI returns `compile-missing-refers-to-node`, treat it as advisory: add the suggested slug only when the Section actually depends on that Node; otherwise leave the draft unchanged and rely on the cited `source_ref`.
294
138
 
295
139
  ## FAQ attachment priority
296
140
 
@@ -301,9 +145,7 @@ policy — critical for specs / decisions / principles.
301
145
  | About an action / flow | That Action |
302
146
  | Cross-topic / generic workspace FAQ | Domain (fallback only) |
303
147
 
304
- Never manufacture a FAQ container Node. If a FAQ cluster grows too large, a
305
- sub-Entity is the correct escape hatch; flag it in `decisions.notes`
306
- for a re-align pass.
148
+ Never manufacture a FAQ container Node. If a FAQ cluster grows too large, a sub-Entity is the correct escape hatch; flag it in `decisions.notes` for a re-align pass.
307
149
 
308
150
  </reference>
309
151
 
@@ -311,18 +153,11 @@ for a re-align pass.
311
153
 
312
154
  ### Step 1 — Sanity-check the context
313
155
 
314
- Confirm `node.slug` is set; abort if not. Note `node.type` — it caps legal kinds per the CLI Section mount matrix. If `existing.sections[]` is non-empty, read it; you need `section-N` ids for update / supersede / deprecate.
315
- If `incremental.status` is `unchanged`, emit one `skip` action. If it is `full-context`, continue with the full context but keep the fallback reason visible in any user-facing explanation.
316
- Estimate coverage from the provided `raw_snippets[]` before writing actions. Treat "the first quote is supported" as only a validation result, not a completion signal.
317
-
318
- If `node.type` is `action`, inspect `node.action_gate` before classification:
156
+ Confirm `node.slug` is set; abort if not. Note `node.type` — it caps legal kinds per the CLI Section mount matrix.
319
157
 
320
- - `step_blocks` / `phase_blocks` / cited step snippets can produce `spec` or `example` Sections for procedure content.
321
- - `actor_blocks`, `goal_blocks`, `outcome_blocks`, and `repeatability_or_plan_blocks` can support concise `description` / `spec` Sections when the same source refs are citation-eligible.
322
- - Empty `trigger_blocks` means no trigger was finalized; write goal or applicability if supported, but do not add a trigger sentence.
323
- - `inference_sources.answerability.ref_nodes` should become `refers_to_nodes[]` when the current Section depends on those Nodes; do not summarize those Nodes' facts here.
158
+ Check edge case conditions from the routing table at the top of this skill. If any apply, read the relevant reference **before** continuing. The references explain how their conditions modify Step 1 / Step 2 / Step 3.
324
159
 
325
- If `node.type` is `domain`, inspect `node.domain_gate` only to understand scope and child grouping. It does not authorize new Section facts by itself.
160
+ Estimate coverage from the provided `raw_snippets[]` before writing actions. Treat "the first quote is supported" as only a validation result, not a completion signal.
326
161
 
327
162
  Coverage self-check:
328
163
 
@@ -336,74 +171,40 @@ Coverage self-check:
336
171
 
337
172
  For each `raw_snippets[]` entry:
338
173
 
339
- 1. If `source_type` is `note` and `anchored_to[]` names this Node or Section, compare it against the target first. A revision/decision note usually becomes `update`, `supersede`, `add` as complement, or `skip`; do not create a new Node from the note title here. If the note says not to modify active knowledge yet, or the correct outcome is no-write after review, use `skip` with `source_refs[]` containing the note's `raw_snippets[].source_ref` so the semantic ledger can record it as reviewed.
340
- 2. If the snippet only contains navigation or placeholder evidence (`Parent` / `Children` / `Related` / `Relations`, sibling links, "no detailed content", etc.), emit `skip`. Do not create a Section whose content is just "Children: ..." or "Related: ..." and do not summarize facts that are not present in the snippet.
341
- 3. Walk the Section kind priority chain from the TL;DR classification rule; stop at the first kind whose trigger fires.
342
- 4. Verify the kind against the mount matrix for `node.type`. Mismatch pick the next legal kind down the chain, or emit `skip` with a reason pointing at a better Node. Never "fall through to description" just to place evidence.
343
- 5. If you land on `description`, walk the [Description anti-abuse gates](#description-anti-abuse-gates). Any gate fires → split or `skip`.
174
+ 1. If the snippet only contains navigation or placeholder evidence (`Parent` / `Children` / `Related` / `Relations`, sibling links, "no detailed content", etc.), emit `skip`. Do not create a Section whose content is just "Children: ..." or "Related: ..." and do not summarize facts that are not present in the snippet.
175
+ 2. Walk the Section kind priority chain from [Section Kind Canon](#section-kind-canon); stop at the first kind whose trigger fires.
176
+ 3. Verify the kind against the mount matrix for `node.type`. Mismatch → pick the next legal kind down the chain, or emit `skip` with a reason pointing at a better Node. Never "fall through to description" just to place evidence.
177
+ 4. If you land on `description`, walk the [Description anti-abuse gates](#description-anti-abuse-gates). Any gate fires split or `skip`.
344
178
 
345
179
  For dense documents, group nearby snippets by their `block_locator_id` heading prefix and write one action per coherent fact group. Repeated `#` headings inside one source are often internal chapters of the current Node; keep them as Sections unless the raw evidence establishes a separate durable Node identity.
346
180
 
347
- ### Step 3 — Reconcile with existing Sections
348
-
349
- For each existing Section:
350
-
351
- - Raw still supports it unchanged → emit nothing (or one summarising `skip`).
352
- - Raw clarifies or rephrases without changing meaning → `update`.
353
- - Raw changes meaning (new spec value, reversed decision) → `supersede`.
354
- - Raw removes supporting evidence → `deprecate` with `reason`.
355
-
356
- ### Step 4 — Build actions
181
+ ### Step 3 — Build actions
357
182
 
358
- For each change from Steps 2-3:
183
+ For each classified snippet:
359
184
 
360
- 1. Split the cited block into `content` and `detail` so the Section is independently addressable in retrieval. `content` (≤256 chars) carries the Section's identity — for `example` / `spec` / `incident` that is the load-bearing identifiers the cited block hinges on (command name, key flags, field names, distinguishing values, mode names, error codes); for `principle` / `description` / `decision` / `comparison` / `warning` / `faq` / `changelog` it is the claim itself in raw's own terms. If the raw sentence already fits this shape, keep it as an extract instead of summarizing it. `detail` carries active knowledge that cannot fit in `content`, especially copyable code/config/URL/table material. Prefer splitting prose into separate supported Sections over storing a raw prose quote in `detail`. Do not put the raw evidence itself into `detail` as a "source copy"; the rendered Section already carries source_ref, and the CLI can resolve the raw evidence from that token.
361
- 2. Keep `content` and `detail` faithful to the cited raw terms: do not introduce acronyms, abbreviations, translations, or aliases that do not appear in the cited raw snippet unless raw itself defines the equivalence or the user confirms it later during semantic review.
362
- 3. If the cited block contains documentation/reference URLs, preserve them in `content` or `detail`. Link-only blocks are still useful knowledge; use `kind: description` with a concise "相关链接" identity when no more specific kind applies.
185
+ 1. Write `body` as the Section text the reader should see. It can include long prose, URLs, tables, command/config/code fences, or short raw wording. Keep one coherent, cited fact group per action; the CLI derives the internal `content`/`detail` split.
186
+ 2. Keep `body` faithful to the cited raw terms: do not introduce acronyms, abbreviations, translations, or aliases that do not appear in the cited raw snippet unless raw itself defines the equivalence or the user confirms it later during semantic review. Use `rewrite: false` when preserving raw expression is the least surprising representation.
187
+ - `source_support` is a lexical diagnostic, not the final semantic judge. Do not stuff raw text into `body` just to raise matched-term counts.
188
+ - There is no separate default `evidence-echo` warning. Treat "echo" as an anti-pattern: raw copied into detail merely to show basis/evidence, while `source_ref` already provides traceability.
189
+ - For `description` / `spec`, a concise summary plus the cited bullet list is acceptable when the bullets are the useful user-facing knowledge. It becomes echo only when the copied text is not meant to be read as active knowledge.
190
+ 3. If the cited block contains documentation/reference URLs, preserve them in `body`. Link-only blocks are still useful knowledge; use `kind: description` with a concise "相关链接" identity when no more specific kind applies.
363
191
  4. Omit `confidence` for ordinary confirmed claims. Assign `confidence` per the [Confidence rubric](#confidence-rubric) only when the evidence is not confirmed.
364
192
  5. Fill `refers_to_nodes[]` per [Glossary and refers_to_nodes](#glossary-and-refers_to_nodes).
365
- 6. Cite evidence with `source_refs[]`, picking values from `raw_snippets[].source_ref`. When one Section summarizes contiguous multi-block evidence, list every relevant source ref in order under `source_refs[]`; the CLI verifies that the refs can collapse to one canonical citation token. If the evidence is non-contiguous or contains separable claims, split the draft into separately cited actions instead of stretching one action across unrelated blocks. For `skip`, include `source_refs[]` only when the skip represents reviewed no-write material; omit evidence for purely deterministic no-ops such as unchanged input. Never submit singular `source_ref` or quoted-evidence fields; the CLI rejects them.
366
- 7. Add the extractive contract to every Section write: `content_mode`,
367
- `basis_spans[]`, and `paraphrase_reason` when `content_mode` is
368
- `minimal_paraphrase`. Each `basis_spans[]` entry contains only
369
- `source_ref`; the CLI resolves cited text and computes the audit basis
370
- internally. When one short basis span is already a valid `content`, choose
371
- `content_mode: "extract"`.
372
- 8. If evidence implies a missing Action, missing `depends_on`, wrong parent, or
373
- needed ownership upgrade from `context_only`, emit the corresponding
374
- challenge action instead of forcing the content into a Section.
375
- `pending_ownership_challenge.requested_role` is `owned` or `shared`.
376
-
377
- Rendered knowledge uses the short claim as the visible blockquote and renders
378
- `detail` as a collapsed Details block under that claim. A reader should be able
379
- to understand the Section from `content` first; `detail` is supporting active
380
- knowledge, not a hidden evidence copy.
381
-
382
- ### Step 5 — Emit the JSON
193
+ 6. Cite evidence with `source_refs[]`, picking values from `raw_snippets[].source_ref`. When one Section summarizes contiguous multi-block evidence, list only the source refs consumed by that Section body; the CLI verifies that the refs can collapse to one canonical citation token and may auto-narrow over-wide citations. If the evidence is non-contiguous or contains separable claims, split the draft into separately cited actions instead of stretching one action across unrelated blocks. For `skip`, include `source_refs[]` only when the skip represents reviewed no-write material; omit evidence for purely deterministic no-ops such as unchanged input. Never submit singular `source_ref` or quoted-evidence fields; the CLI rejects them.
194
+
195
+ Rendered knowledge uses a CLI-derived short claim as the visible blockquote and renders longer supporting material from `body` as collapsed Details when needed. A reader should be able to understand the Section from the short claim first; long supporting material is active knowledge, not a hidden evidence copy.
196
+
197
+ ### Step 4 Emit the JSON
383
198
 
384
199
  Emit one compile draft JSON document for the caller to pass to `context compile --draft <slug> --input - --plan --prepare`. No markdown wrapper, no leading prose, no trailing commentary.
385
200
 
386
- ### Step 6 — Self-verify
387
-
388
- - [ ] `target_node` equals `node.slug` if not, **Step 5**.
389
- - [ ] Every `add` / `supersede.new` has a legal kind × type combination — if not, **Step 2**.
390
- - [ ] Every action's `source_refs[]` entries appear in `raw_snippets[].source_ref` for this NodeContext, and no action carries singular `source_ref` or quoted-evidence fields if not, **Step 4**; pick the right source ref, split non-contiguous claims, or use `skip` only when raw has no write-worthy fact.
391
- - [ ] Every Section write has `content_mode` and `basis_spans[]`; every
392
- `minimal_paraphrase` has `paraphrase_reason` if not, **Step 4**.
393
- - [ ] Short, readable, single-line evidence was not rewritten just for style. If it already fits `content`, switch to `content_mode: "extract"` if not, **Step 4**.
394
- - [ ] `content` does not add new hard terms, acronyms, abbreviations, translations, URLs, code literals, versions, or aliases absent from the cited raw snippet — if it does, either use the raw wording, move the extra explanation into a user-confirmed decision later, or **Step 4**.
395
- - [ ] No `add` / `supersede.new` action contains `detail: null` — omit `detail` instead.
396
- - [ ] No `description` action that would fail the anti-abuse gates — if any, **Step 2**.
397
- - [ ] Every citation-eligible raw URL block is either preserved in a Section or intentionally skipped with evidence and reason; if not, **Step 4**.
398
- - [ ] Dense raw material was not collapsed into one broad Section. If `raw_snippets[]` spans many locator areas and only one write action exists, return to **Step 2** unless the remaining snippets are duplicates, navigation-only, or already covered by existing Sections.
399
- - [ ] Every `update` / `supersede` / `deprecate` targets a known `section-N` — if not, **Step 3**.
400
- - [ ] `refers_to_nodes[]` only contains slugs from `existing` / glossary / current align plan — if not, **Step 4**.
401
- - [ ] When the Node ended description-dominant, verify raw was genuinely narrative (no enumerations, no normative wording, no code/config blocks). If raw contained any of those forms and they were collapsed to `description`, redo classification from **Step 2**. Do not invent unsupported precision Sections for ratio reasons.
402
- - [ ] When raw adds nothing, exactly one `op: skip` with a reason; not `actions: []`.
403
- - [ ] When raw only has navigation/placeholder evidence, use `skip`; do not add a low-value Section from `Parent` / `Children` / `Related` / `Relations` lines.
404
- - [ ] When `skip` means "reviewed but intentionally not written", it includes `source_refs[]` from the relevant note/raw snippet so review can persist no-write status.
405
- - [ ] Changed-only context was not expanded by direct workspace reads — if any were used, restart from the CLI-provided NodeContext.
406
- - [ ] No Read / Glob / Grep / Write was used against `WORKSPACE_DIR` — if any, restart from the CLI-provided NodeContext.
407
- - [ ] No ad-hoc script or shell file traversal was used against `WORKSPACE_DIR`, `.context`, or `/tmp` workflow artifacts — if any, restart from the CLI-provided NodeContext.
201
+ ### Step 5 — Self-verify
202
+
203
+ - [ ] Every action's `target_node` equals `node.slug`, with a legal `kind × node.type` combination and `body` + `source_refs[]` only (no singular `source_ref`, no `content` / `detail`, no quoted-evidence or extractive-contract fields, no new terms absent from the cited raw). If not, return to **Step 2** for kind/mount-matrix issues, otherwise **Step 3**.
204
+ - [ ] Every `description` action survives the [Description anti-abuse gates](#description-anti-abuse-gates). If not, **Step 2** to split or `skip`.
205
+ - [ ] Coverage matches evidence density: dense raw with one broad action returns to **Step 2** unless remaining snippets are duplicates / navigation / placeholders / already covered. Citation-eligible URL blocks are either preserved or `skip`-with-evidence.
206
+ - [ ] `skip` semantics: bare `skip` only for deterministic no-op (unchanged input or pure navigation); reviewed-no-write `skip` carries `source_refs[]` from the cited snippet. When raw adds nothing, exactly one `op: skip` with a reason — not `actions: []`. If not, **Step 3**.
207
+ - [ ] If any edge case condition applies (action/domain Node, note snippets, existing Sections, non-changed-only incremental, or structural defect), the relevant reference's Self-verify items were also satisfied.
208
+ - [ ] NodeContext was the only evidence source no Read / Glob / Grep / Write / ad-hoc script or shell file traversal against `WORKSPACE_DIR`, `.context`, `/tmp` workflow artifacts, or CLI `--format json` stdout. If any was used, restart from the CLI-provided NodeContext.
408
209
 
409
210
  </procedures>