@c4a/context-cli 0.5.29-alpha.2 → 0.5.29-beta.17

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 (51) hide show
  1. package/README.md +71 -34
  2. package/cli.js +43511 -20153
  3. package/package.json +1 -1
  4. package/plugin/.claude-plugin/plugin.json.template +1 -1
  5. package/plugin/.codex-plugin/plugin.json.template +8 -5
  6. package/plugin/.cursor-plugin/plugin.json.template +29 -0
  7. package/plugin/README.md +127 -0
  8. package/plugin/README_CN.md +125 -0
  9. package/plugin/assets/icon.svg +3 -0
  10. package/plugin/assets/logo.svg +3 -0
  11. package/plugin/assets/workflow-en.png +0 -0
  12. package/plugin/assets/workflow.png +0 -0
  13. package/plugin/commands/align.md +50 -42
  14. package/plugin/commands/capture.md +27 -11
  15. package/plugin/commands/compile.md +91 -36
  16. package/plugin/commands/context.md +7 -4
  17. package/plugin/commands/drop.md +14 -6
  18. package/plugin/commands/extract.md +3 -3
  19. package/plugin/commands/init.md +48 -9
  20. package/plugin/commands/purge.md +6 -6
  21. package/plugin/commands/query.md +11 -3
  22. package/plugin/commands/status.md +4 -2
  23. package/plugin/skills/skill-align-workflow/SKILL.md +61 -0
  24. package/plugin/skills/skill-align-workflow/references/candidate-resolution.md +60 -0
  25. package/plugin/skills/skill-align-workflow/references/density-profile.md +23 -0
  26. package/plugin/skills/skill-align-workflow/references/gates.md +95 -0
  27. package/plugin/skills/skill-compile-close/SKILL.md +127 -0
  28. package/plugin/skills/skill-compile-draft/SKILL.md +409 -0
  29. package/plugin/skills/skill-context-query/SKILL.md +184 -0
  30. package/plugin/skills/skill-drop/SKILL.md +190 -0
  31. package/plugin/skills/skill-semantic-reconcile/SKILL.md +251 -0
  32. package/scripts/build-plugin.ts +674 -45
  33. package/templates/aspects/code/aspect.yaml +21 -0
  34. package/templates/aspects/code/prompt.md +33 -18
  35. package/templates/aspects/design-system/prompt.md +2 -3
  36. package/templates/aspects/graphql/prompt.md +2 -2
  37. package/templates/aspects/openapi/prompt.md +2 -2
  38. package/plugin/.claude-plugin/plugin.json +0 -16
  39. package/plugin/.codex-plugin/plugin.json +0 -35
  40. package/plugin/commands/capture-aspect.md +0 -17
  41. package/plugin/commands/capture-code.md +0 -25
  42. package/plugin/skills/align-finalize/SKILL.md +0 -137
  43. package/plugin/skills/align-propose/SKILL.md +0 -163
  44. package/plugin/skills/align-scan/SKILL.md +0 -161
  45. package/plugin/skills/align-scan/references/data-model.md +0 -343
  46. package/plugin/skills/align-scan/references/user-question-contract.md +0 -159
  47. package/plugin/skills/compile-close/SKILL.md +0 -122
  48. package/plugin/skills/compile-draft/SKILL.md +0 -252
  49. package/plugin/skills/context-query/SKILL.md +0 -166
  50. package/plugin/skills/drop/SKILL.md +0 -170
  51. package/plugin/skills/semantic-reconcile/SKILL.md +0 -129
@@ -0,0 +1,409 @@
1
+ ---
2
+ name: skill-compile-draft
3
+ description: >
4
+ Packaged skill invoked by `/context:compile`; not a user slash command. For one Node at a time, reads
5
+ the CLI-provided `NodeContext` (planned metadata, raw snippets, and
6
+ existing Sections if any), classifies every raw fragment into a Section
7
+ kind via the priority chain, writes content + detail + `source_refs[]`,
8
+ and emits a compile draft JSON document. The CLI
9
+ validates the actions via `context compile --draft <slug> --input - --plan`.
10
+ Activates when `/context:compile` iterates across the confirmed align plan.
11
+ tools:
12
+ - Bash
13
+ ---
14
+
15
+ # skill-compile-draft — write Section actions for one Node
16
+
17
+ Classify raw evidence for one Node into `add / update / supersede /
18
+ deprecate / skip` actions; emit JSON; the CLI performs every write.
19
+
20
+ ## TL;DR — Non-negotiables
21
+
22
+ - 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
+ - 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.
34
+ - 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.
36
+ - `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
+ - 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`.
43
+ - `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.
46
+ - 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
+ - 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.
50
+
51
+ <reference>
52
+
53
+ ## Input — `NodeContext`
54
+
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
+ ```
122
+
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
+ ```
208
+
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
+ }
241
+ ```
242
+
243
+ Hints are recall/explanation aids only. The final relation/action must come
244
+ from `context reconcile prepare` candidates and semantic reconcile decisions.
245
+
246
+ ## Confidence rubric
247
+
248
+ Four legal values; pick per raw evidence strength.
249
+
250
+ | `confidence` | When |
251
+ |---|---|
252
+ | `verified` | Raw shows the fact already happened or held — recorded run output, observed metric value, incident timestamp, benchmark result, or explicit "ran X, got Y" log. Executable form alone is not enough; without execution evidence, downgrade to `confirmed`. |
253
+ | `confirmed` | Raw states the fact in normative voice or as a documented spec / config / example, without showing the run that confirmed it. This is the default for code blocks, configuration samples, feature lists, and design rules. |
254
+ | `inferred` | You combined ≥2 raw fragments into a load-bearing conclusion that no single fragment states. |
255
+ | `speculative` | Raw only hints; the Section is a best-effort reading that may not survive review. |
256
+
257
+ Don't game the rubric. Compile-close flags Nodes dominated by `speculative` Sections, and a Node whose Sections are uniformly `verified` despite raw containing only specs / samples is the symptom of a misread rubric, not strong evidence.
258
+
259
+ ## Description anti-abuse gates
260
+
261
+ `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
+
263
+ 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`.
265
+ 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
+
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.
270
+
271
+ ## Glossary and `refers_to_nodes`
272
+
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`.
283
+
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.
294
+
295
+ ## FAQ attachment priority
296
+
297
+ | FAQ topic | Attach to |
298
+ |---|---|
299
+ | About a concrete thing | That thing's Entity (Section `faq`) |
300
+ | About a mechanism or term | The matching Entity |
301
+ | About an action / flow | That Action |
302
+ | Cross-topic / generic workspace FAQ | Domain (fallback only) |
303
+
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.
307
+
308
+ </reference>
309
+
310
+ <procedures>
311
+
312
+ ### Step 1 — Sanity-check the context
313
+
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:
319
+
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.
324
+
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.
326
+
327
+ Coverage self-check:
328
+
329
+ 1. Count citation-eligible, non-navigation snippets and group them by `block_locator_id` heading prefix.
330
+ 2. For 3-11 such snippets, read each snippet once. If later snippets are distinct facts, emit separate actions before moving to the next Node. Do not stop after one supported description just because the file is short.
331
+ 3. For roughly 12+ citation-eligible snippets or 5+ distinct locator areas, plan multiple Sections in this single draft. Large manuals/design docs usually need several orthogonal actions.
332
+ 4. This is not a quota: skip duplicates, navigation-only blocks, placeholders, and unsupported fragments. The goal is coverage of distinct source-backed knowledge, not maximum Section count.
333
+ 5. If `context reconcile prepare` returns `compact-source-low-coverage` or `dense-source-low-coverage`, revise the same draft to cover the suggested uncovered evidence candidates before review/apply. Do not treat those warnings as ignorable polish.
334
+
335
+ ### Step 2 — Classify each raw snippet
336
+
337
+ For each `raw_snippets[]` entry:
338
+
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`.
344
+
345
+ 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
+
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
357
+
358
+ For each change from Steps 2-3:
359
+
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.
363
+ 4. Omit `confidence` for ordinary confirmed claims. Assign `confidence` per the [Confidence rubric](#confidence-rubric) only when the evidence is not confirmed.
364
+ 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
383
+
384
+ 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
+
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.
408
+
409
+ </procedures>
@@ -0,0 +1,184 @@
1
+ ---
2
+ name: skill-context-query
3
+ description: >
4
+ Packaged skill invoked by `/context:query`; not a user slash command. The agent uses
5
+ `context query` hit/miss/select results first, supplements only with scoped
6
+ query views when needed, and answers with Node slug, Section id,
7
+ and compact node/section citations plus explicit gaps for unsupported claims.
8
+ Activates when `/context:query` is invoked or when an agent needs to
9
+ answer a question using local Context workspace knowledge with citations.
10
+ tools:
11
+ - Bash
12
+ ---
13
+
14
+ # skill-context-query — answer from local knowledge with CLI citations
15
+
16
+ Answer a user question from the local Context workspace without reading
17
+ workspace files directly. The CLI is the only source of local knowledge.
18
+
19
+ ## TL;DR — Non-negotiables
20
+
21
+ - First evidence-bearing tool call should be the ordinary default query: `context query "$ARGUMENTS"`. One optional `context query --intent orientation` or empty `context query` call may run before it when this conversation has no usable workspace map; orientation is only for choosing a better query/scope and is never evidence for the answer.
22
+ - Do not Read, Glob, Grep, or Write `raw/`, `knowledge/`, `archive/`, `decisions/`, or any workspace file to answer the question.
23
+ - Use only `context query` output as evidence. If the CLI returns `miss` or fails, report that result instead of searching files yourself.
24
+ - Every key conclusion must cite the returned `node` and `section` handles. Default query output intentionally omits source provenance; do not invent or parse source locators.
25
+ - If returned entries do not support a conclusion, mark it as a gap. Do not turn missing local knowledge into a definite answer.
26
+ - If the output asks for a narrower scope or shows multiple candidate slugs, choose one only when the user's wording makes it unambiguous; otherwise ask the user which `slug` to use.
27
+ - If the output reports a broad, blocked, or truncated recall, follow that diagnostic: ask for a narrower Node, term, version, or scope; when entries are returned but truncated, answer from those entries and state the result is not exhaustive.
28
+ - Do not use Python, Node.js, shell scripts, `ls`, `find`, `rg`, `cat`, or similar ad-hoc commands to inspect `WORKSPACE_DIR`, `.context`, or `/tmp` workflow artifacts.
29
+ - If the question names a Node title, alias, or slug, state the actual Node slug used in the answer.
30
+ - When the first query is insufficient, supplement only with scoped query views named in the Supplemental context section or anchors from entry `refers_to_nodes`.
31
+ - Output language follows the user's conversation language. CLI flags, output column names, slugs, and Section ids stay as printed.
32
+
33
+ <reference>
34
+
35
+ ## Evidence Shape
36
+
37
+ Primary evidence comes from the default `context query` output. Treat each
38
+ returned row as a small evidence card.
39
+
40
+ | Column / text | Use |
41
+ |---|---|
42
+ | `node` | Required citation handle for Section rows |
43
+ | `section` | Required citation handle for Section rows |
44
+ | `kind` | Section kind; use it to avoid overstating description/spec/warning content |
45
+ | `content` | Evidence text for answer claims |
46
+ | `refers_to_nodes` | Optional supplemental anchors when present |
47
+ | `slug` | Candidate handle when the output is asking you to choose a Node |
48
+ | `message` | Miss, broad-query, blocked, or narrowing guidance |
49
+
50
+ Supplemental context can come from:
51
+
52
+ ```text
53
+ context query --intent node_search --scope <slug>
54
+ context query --intent impact_analysis --scope <slug>
55
+ context query --intent node_search --refers-to <slug>
56
+ ```
57
+
58
+ ## Answer citation shape
59
+
60
+ Use compact citations next to each key claim:
61
+
62
+ ```text
63
+ <claim> [node / section]
64
+ ```
65
+
66
+ If multiple Sections support the same claim, cite the strongest one or two.
67
+ Avoid citation-only dumps: summarize what the cited Section supports.
68
+
69
+ ## Gap shape
70
+
71
+ Use a visible gap when the CLI evidence cannot support the requested fact:
72
+
73
+ ```text
74
+ Gap: local knowledge did not return evidence for <missing point>.
75
+ ```
76
+
77
+ If the likely cause is stale workflow state, suggest the relevant context
78
+ workflow (`/context:align` or `/context:compile`) only when the CLI output or
79
+ the user's wording indicates newly captured material is not yet knowledge.
80
+
81
+ </reference>
82
+
83
+ <procedures>
84
+
85
+ ## Step 1: Query
86
+
87
+ If `$ARGUMENTS` is empty or whitespace-only, ask the user for a question first;
88
+ do not run the query.
89
+
90
+ If the current conversation has no useful workspace map and the user's question
91
+ is broad, ambiguous, or asks what can be queried, run one orientation pass before
92
+ the first evidence query:
93
+
94
+ ```bash
95
+ context query --intent orientation
96
+ ```
97
+
98
+ Empty `context query` returns the same orientation map.
99
+
100
+ Orientation returns directly queryable slug/title structure and one query
101
+ template. Use it only to choose a scope or show the user what can be queried.
102
+ Do not answer from orientation output. Do not cite orientation output.
103
+
104
+ If the user already asked a concrete question but this conversation has no
105
+ workspace map, you may run `context query --intent orientation` (or empty `context query`) and the first
106
+ ordinary `context query "$ARGUMENTS"` concurrently. Use the evidence
107
+ query for the answer; use orientation only for scoped follow-up if the first
108
+ query is insufficient.
109
+
110
+ Run the ordinary query first:
111
+
112
+ ```bash
113
+ context query "$ARGUMENTS"
114
+ ```
115
+
116
+ If the user explicitly asks for archive comparison, source cleanup audit, or
117
+ semantic reconciliation candidates, use recall with the matching profile:
118
+
119
+ - duplicate / near duplicate / dedupe → `--profile reconcile-dedupe`
120
+ - support check / source support → `--profile reconcile-support`
121
+ - refresh / stale source comparison → `--profile reconcile-refresh`
122
+
123
+ ```bash
124
+ context query --intent recall --profile reconcile-dedupe --query "$ARGUMENTS"
125
+ ```
126
+
127
+ Do not use recall archive profiles for ordinary questions.
128
+
129
+ ## Step 2: Read and gate
130
+
131
+ Read the command output before answering.
132
+
133
+ - If the command fails, report the CLI failure and stop.
134
+ - If the output says `miss` or no local knowledge matched, report no local knowledge hit and stop.
135
+ - If the output shows candidate slugs instead of evidence rows, ask for a specific `slug`, unless the user's wording already identifies one candidate.
136
+ - If the output reports broad or blocked recall, stop and ask for a narrower Node, term, version, or scope before treating missing candidates as evidence of absence.
137
+ - If the output reports truncated recall, answer from the returned evidence when entries exist, mark coverage as non-exhaustive, and ask for narrowing only if the user needs a complete inventory.
138
+ - Keep a working set of returned rows with `node`, `section`, `kind`, `content`, and non-empty `refers_to_nodes`.
139
+
140
+ ## Step 3: Anchor explicit Node mentions
141
+
142
+ If the user's question contains a likely Node title, alias, slug, code symbol,
143
+ or version:
144
+
145
+ 1. Prefer exact slug, title, or alias matches from the query result.
146
+ 2. State the actual Node slug used.
147
+ 3. If the candidate set points to multiple plausible slugs, say which slugs were used and keep claims scoped to those slugs.
148
+
149
+ ## Step 4: Supplement only when needed
150
+
151
+ Use supplemental commands only when the first query has entries but lacks
152
+ enough surrounding structure to answer the question.
153
+
154
+ Use supplements per the Supplemental context section, only after the first query
155
+ and only for slugs present in returned entries, entry `refers_to_nodes`, or
156
+ the user's explicit question. Use `refers_to_nodes` as extra anchors only when
157
+ they appear in returned Sections. Do not discover extra anchors by reading
158
+ workspace files.
159
+
160
+ ## Step 5: Compose
161
+
162
+ Answer only from the query and supplemental outputs.
163
+
164
+ Required response behavior:
165
+
166
+ 1. Start with the direct answer if evidence supports one.
167
+ 2. Cite every key conclusion with Node slug and Section id.
168
+ 3. Include a short "Used nodes" line when the question was anchored by title, alias, slug, code symbol, or version.
169
+ 4. Include "Gap:" lines for requested points that are not supported.
170
+ 5. Include a blocked / broad-query note when recall hints require narrowing, or a truncated/non-exhaustive note when returned evidence is only a subset.
171
+
172
+ ## Self-check before final answer
173
+
174
+ - [ ] First evidence-bearing tool call was ordinary `context query "$ARGUMENTS"` or an explicit reconcile `--intent recall` query. If an orientation command ran first or concurrently, it was only `context query --intent orientation` or empty `context query`, and an evidence-bearing `context query` command ran before answering — if not, go back to **Step 1**.
175
+ - [ ] No direct file Read / Glob / Grep / Write was used against workspace local knowledge — if not, discard that evidence and go back to **Step 1**.
176
+ - [ ] No ad-hoc script or shell file traversal was used against `WORKSPACE_DIR`, `.context`, or `/tmp` workflow artifacts — if not, discard that evidence and go back to **Step 1**.
177
+ - [ ] Direct answer is given when evidence supports one — if not, go back to **Step 5**.
178
+ - [ ] Every key conclusion has `node / section` — if not, go back to **Step 5**.
179
+ - [ ] If the question carried a Node title / alias / slug / code symbol / version, the answer includes a "Used nodes" line — if not, go back to **Step 3** and **Step 5**.
180
+ - [ ] Any unsupported conclusion is marked as a gap — if not, go back to **Step 5**.
181
+ - [ ] Recall diagnostics are handled: broad/blocked asks for narrowing; truncated with entries answers with a non-exhaustive note — if not, go back to **Step 2** and **Step 5**.
182
+ - [ ] Archive entries appear only for explicit reconcile profiles — if not, go back to **Step 1** with the correct profile.
183
+
184
+ </procedures>