@c4a/context-cli 0.6.0-beta.8 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +129 -137
  3. package/cli.js +1573 -3320
  4. package/package.json +18 -3
  5. package/plugins/VERSION +1 -1
  6. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  7. package/plugins/claude/skills/skill-review-gate/SKILL.md +0 -3
  8. package/plugins/claude/skills/skill-source-scope/SKILL.md +0 -6
  9. package/plugins/codex/.codex-plugin/plugin.json +2 -2
  10. package/plugins/codex/skills/continue/references/internal-procedures/skill-review-gate.md +0 -3
  11. package/plugins/codex/skills/continue/references/internal-procedures/skill-source-scope.md +0 -6
  12. package/plugins/codex/skills/init/references/internal-procedures/skill-review-gate.md +0 -3
  13. package/plugins/codex/skills/init/references/internal-procedures/skill-source-scope.md +0 -6
  14. package/plugins/cursor/.cursor-plugin/plugin.json +1 -1
  15. package/plugins/cursor/skills/skill-review-gate/SKILL.md +0 -3
  16. package/plugins/cursor/skills/skill-source-scope/SKILL.md +0 -6
  17. package/plugins/skills/context-continue/references/internal-procedures/skill-review-gate.md +0 -3
  18. package/plugins/skills/context-continue/references/internal-procedures/skill-source-scope.md +0 -6
  19. package/plugins/skills/context-init/references/internal-procedures/skill-review-gate.md +0 -3
  20. package/plugins/skills/context-init/references/internal-procedures/skill-source-scope.md +0 -6
  21. package/plugin/.claude-plugin/plugin.json.template +0 -16
  22. package/plugin/.codex-plugin/plugin.json.template +0 -38
  23. package/plugin/.cursor-plugin/plugin.json.template +0 -29
  24. package/plugin/README.md +0 -158
  25. package/plugin/README_CN.md +0 -142
  26. package/plugin/assets/icon.svg +0 -3
  27. package/plugin/assets/logo.svg +0 -3
  28. package/plugin/assets/workflow-en.png +0 -0
  29. package/plugin/assets/workflow.png +0 -0
  30. package/plugin/commands/continue.md +0 -34
  31. package/plugin/commands/init.md +0 -21
  32. package/plugin/skills/skill-continue-workflow/SKILL.md +0 -235
  33. package/plugin/skills/skill-init-workspace/SKILL.md +0 -74
  34. package/plugin/skills/skill-package-output/SKILL.md +0 -180
  35. package/plugin/skills/skill-prose-align/SKILL.md +0 -322
  36. package/plugin/skills/skill-prose-align/references/internal-procedures/structure-planning/references/candidate-resolution.md +0 -91
  37. package/plugin/skills/skill-prose-align/references/internal-procedures/structure-planning/references/density-profile.md +0 -30
  38. package/plugin/skills/skill-prose-align/references/internal-procedures/structure-planning/references/gates.md +0 -263
  39. package/plugin/skills/skill-prose-align/references/internal-procedures/structure-planning.md +0 -282
  40. package/plugin/skills/skill-prose-compile/SKILL.md +0 -287
  41. package/plugin/skills/skill-prose-compile/references/internal-procedures/close-gate.md +0 -132
  42. package/plugin/skills/skill-prose-compile/references/internal-procedures/compile-actions/references/action-domain-gates.md +0 -52
  43. package/plugin/skills/skill-prose-compile/references/internal-procedures/compile-actions/references/notes.md +0 -48
  44. package/plugin/skills/skill-prose-compile/references/internal-procedures/compile-actions/references/refresh-and-update.md +0 -85
  45. package/plugin/skills/skill-prose-compile/references/internal-procedures/compile-actions/references/structural-challenges.md +0 -73
  46. package/plugin/skills/skill-prose-compile/references/internal-procedures/compile-actions.md +0 -413
  47. package/plugin/skills/skill-prose-compile/references/internal-procedures/compile-judgment.md +0 -123
  48. package/plugin/skills/skill-prose-compile/references/internal-procedures/semantic-judgment/references/disposition-semantics.md +0 -81
  49. package/plugin/skills/skill-prose-compile/references/internal-procedures/semantic-judgment/references/leakage-and-ownership.md +0 -55
  50. package/plugin/skills/skill-prose-compile/references/internal-procedures/semantic-judgment/references/scope-review-and-omit.md +0 -93
  51. package/plugin/skills/skill-prose-compile/references/internal-procedures/semantic-judgment/references/temporal-and-evidence.md +0 -79
  52. package/plugin/skills/skill-prose-compile/references/internal-procedures/semantic-judgment/references/user-confirmation.md +0 -111
  53. package/plugin/skills/skill-prose-compile/references/internal-procedures/semantic-judgment.md +0 -194
  54. package/plugin/skills/skill-review-gate/SKILL.md +0 -141
  55. package/plugin/skills/skill-source-scope/SKILL.md +0 -531
  56. package/plugin/skills/skill-source-scope/references/capture-source.md +0 -201
  57. package/plugins/assets/icon.svg +0 -3
  58. package/plugins/assets/workflow-en.png +0 -0
  59. package/plugins/assets/workflow.png +0 -0
  60. package/plugins/codex/assets/workflow-en.png +0 -0
  61. package/plugins/codex/assets/workflow.png +0 -0
  62. package/plugins/cursor/assets/icon.svg +0 -3
  63. package/plugins/cursor/assets/workflow-en.png +0 -0
  64. package/plugins/cursor/assets/workflow.png +0 -0
  65. package/scripts/build-plugin.ts +0 -658
@@ -1,263 +0,0 @@
1
- # Node Classification Gates
2
-
3
- Use these gates before every structure draft and before authoring the align
4
- payload described by the current schema view.
5
- Align owns Node type, tag, graph, planned Section, and ownership classification. It does **not** write Section prose.
6
-
7
- Current schema mapping:
8
-
9
- - Treat the action checklist, domain checklist, and inference tables as private
10
- working notes unless the current schema view explicitly exposes matching
11
- fields.
12
- - In `context.structure.v1`, persist the outcome through `node_type`, `tags`,
13
- `summary`, `ownership`, `sections[].source_refs`, `edges[]`, and
14
- `unresolved[]`.
15
- - Do not add unknown gate fields to the payload just because this procedure uses
16
- them for reasoning.
17
-
18
- ## Node Type Order
19
-
20
- Answer in this order and stop at the first match:
21
-
22
- 1. **Action?** A large executable event / process with both:
23
- - scale: can support `planned_sections` with at least two distinct Section kinds, or contains at least one child Action;
24
- - process evidence: explicit steps, phases, trigger -> handling -> result, role collaboration, or repeatable plan. Parallel lists such as "three API modes" are not process evidence.
25
- Single-section user-story / scenario / incident records may be meaningful to
26
- a human reader, but the CLI does not infer that exception from source prose.
27
- If the structure cannot express at least two distinct Section kinds or a
28
- child Action, keep the material as a Section under the owning Node.
29
- 2. **Entity?** A concrete independent subject with retrieval value: deployable code, product/application/system, library/module/CLI/symbol, or an atomic term/pattern.
30
- 3. **Domain?** A container/scope that groups at least one child Node.
31
- 4. Otherwise do not create a Node; leave the material for compile as a Section under the owning Node.
32
-
33
- Good examples:
34
-
35
- | Type | Examples |
36
- |---|---|
37
- | `domain` | "X business domain", "Y technical area", "Z research topic" |
38
- | `entity` concrete | `@acme/api-server`, `@acme/ui-kit` `Button`, "X sub-application" |
39
- | `entity` term | "X identifier", "Y business metric", idempotency |
40
- | `action` | "user submits X request end-to-end flow", "operator executes Y change flow", "team Z release flow" |
41
-
42
- ## Title and Source Heading Rules
43
-
44
- Classify the Node by the evidence referent, not by the source file title, heading, or local section title. A source title is ordinary evidence just like body prose. It has no automatic right to become `node.title`, `aliases[]`, or `slug`.
45
-
46
- After choosing `node_type`, choose the title to fit that type:
47
-
48
- | Final type | Title shape |
49
- |---|---|
50
- | `entity` concrete | The concrete product, service, library, module, CLI, symbol, application, or system name. |
51
- | `entity` term | The atomic concept or pattern name, without extra scope/process suffixes. |
52
- | `domain` | The grouping scope that owns child Nodes. |
53
- | `action` | The executable process / runbook / flow name that passed the Action Gate. |
54
-
55
- Scope/process words in a source title are warning signals when proposed as an Entity title, not hard classification rules. Re-check the type/title when a proposed Entity title contains words such as "方案", "架构", "体系", "演练", "流程", "策略", "能力", "机制", "framework", "architecture", "system", "strategy", "process", or "drill". Keep the wording only when evidence shows it is the formal name of a concrete object or an atomic term.
56
-
57
- Do not promote broad architecture/system/方案 content to `domain` just because it sounds like a scope. When the source has writable Sections but no resolvable current/existing child Nodes, use an Entity such as `[system]` or `[application]` and put the architecture facts in Sections. Use `domain` only when it groups child Nodes through supported `edges[]`.
58
-
59
- Relation-only sources should not force title copying or dangling graph edges. Decide placeholder handling in this order:
60
-
61
- 1. If resolved current/existing child Nodes make the page a real grouping scope, keep the relation evidence as supported `edges[]` only when the Domain also has at least one source-backed planned Section.
62
- 2. If an explicit user-facing retrieval need or graph need makes the source/page identity valuable, and the title names an atomic concept or concrete object, keep that identity in `unresolved[]` until it has source-backed section evidence, a valid generated `parent_index` view with source-backed `contains` edges to child views, or a compile-time `skip` decision. Do not submit root-level `planned_sections: []` or ordinary source-bound `sections: []`.
63
- 3. Otherwise, skip navigation-only / placeholder-only material; keep a short
64
- `unresolved[]` note only when the deferred relation remains useful.
65
-
66
- Do not create a hidden domain-gate object. A kept placeholder needs support:
67
- source refs, approved graph support, or explicit user-confirmed retrieval value.
68
- For Domain placeholders, write only resolved current/existing children as typed
69
- `edges[]`; if all children are unresolved/deferred relation clues, keep those
70
- target hints in `unresolved[]`. If the source names only an atomic concept and
71
- that term is useful on its own, prefer a concise term Entity title without
72
- scope/process suffixes.
73
-
74
- For no-write placeholder summaries, describe only the preserved page identity and unresolved navigation clues. Do not say the Node "provides navigation/links/relations to X" unless those targets are resolved graph children or rendered links; say the source contains deferred navigation clues instead.
75
-
76
- ## Section Promotion Gate
77
-
78
- Classify local evidence as a Section before creating a child Node/View. A
79
- heading, table row, FAQ label, or short sub-topic does not by itself establish a
80
- standalone page.
81
-
82
- Promote a Section to a child View only when at least one condition is supported
83
- by source evidence:
84
-
85
- 1. The title is a concrete product/code object/system/module/library, not just a
86
- local heading.
87
- 2. The item is an atomic term or pattern that answers standalone lookup
88
- questions outside the parent page.
89
- 3. The item clears the Action Gate or Domain Gate.
90
- 4. The source gives it independent article identity: owner/date, lifecycle,
91
- timeline, tracking record, or cross-cutting support scope.
92
-
93
- Use one content-neutral test for every proposed child View: does cited evidence
94
- support an independent subject identity, enough context to stand alone, and a
95
- separate retrieval need? A heading, section kind, collection name, or contains
96
- edge is not sufficient by itself. The CLI warns when many same-source,
97
- single-section child Entities look mechanically fragmented, but it does not
98
- reject a page merely because of its content type.
99
-
100
- ## Entity Tag Rules
101
-
102
- Use `tags` to state what the Entity is. Legal combinations:
103
-
104
- | Case | Tags |
105
- |---|---|
106
- | Runtime/code object | one A tag: `app`, `service`, `lib`, `cli`, `module`, or `symbol` |
107
- | Product-analysis object | one B tag: `application` or `system` |
108
- | Code + product object | one A tag plus one B tag |
109
- | Pure term / pattern | only `term` |
110
-
111
- `term` is mutually exclusive with A/B tags. React is `[lib]`, not `[lib, term]`; if a separate term entry is useful, create another Entity tagged `[term]` and let the structure plan express the relation as a typed edge or unresolved relation with `source_refs[]`.
112
-
113
- Do not inherit scope tags mechanically. If a parent Entity is tagged `system` or
114
- `application`, a child Entity should repeat that tag only when it is itself an
115
- independent system/application. Local aspects under that parent should either
116
- use their own shape tag or remain Sections.
117
-
118
- ## Action Gate
119
-
120
- Use `node_type: action` only after the Node Type Order says action. Fill the
121
- action reasoning checklist in your working notes; persist only fields accepted by
122
- the current structure schema.
123
-
124
- The action probe uses five booleans as a reasoning checklist, but the semantic
125
- bar is:
126
-
127
- | Field | Meaning | Evidence rule |
128
- |---|---|---|
129
- | `has_steps_or_phases` | Process evidence exists: steps, phases, trigger -> handling -> result, role collaboration, or repeatable plan. | Hard requirement; support it from span evidence. |
130
- | `has_actor_or_role` | A user, system, operator, service, or role performs the work. | May be inferred; record the source. |
131
- | `has_outcome_or_goal` | The process has a target result, acceptance condition, or operational goal. | May be inferred; record the source. |
132
- | `is_repeatable_or_planned` | The work is repeatable, scheduled, policy-like, or intentionally planned. | May be inferred; record the source. |
133
- | `queries_answerable_with_refs` | The Node can answer how/when/who/what-to-do questions from cited spans. | May be inferred; record the source. |
134
-
135
- Do not emit an Action for a single sentence, a one-off conclusion, a short operation, or a parallel enumeration. Those become Sections under the owning Entity or Domain. The CLI does not infer single-Section Action exceptions from source prose; represent the material with enough structure or keep it as a Section.
136
-
137
- Action anti-examples:
138
-
139
- | Candidate | Correct routing |
140
- |---|---|
141
- | "migrate to X tool" as one conclusion | `decision` Section under the owning Entity |
142
- | "component X usage" as one sentence | `description` + maybe `example` under X |
143
- | "submit -> validate -> generate" as one unexpanded sentence | `spec` Section under X/Y |
144
- | "three API call modes" | `comparison`, `spec`, or `description` Section; not Action |
145
-
146
- ## Fake Entity Gate
147
-
148
- A relationship-style title is only suspicious by itself. Downgrade or change type when at least **two** signals are true:
149
-
150
- 1. Title contains relationship language such as "X impact on Y", "Y under X", "Y side of X", "X migration", or "X collection".
151
- 2. No legal Entity tag fits.
152
- 3. The Node does not stand alone away from its upstream Node.
153
-
154
- Repairs:
155
-
156
- | Pattern | Repair |
157
- |---|---|
158
- | "X impact on Y" | Section under X plus a typed edge or unresolved relation to Y when the evidence supports it |
159
- | "Y under X condition" | Section under Y; X is a condition in the Section body |
160
- | "X subsystem migration" | Action only if it clears the Action Gate; otherwise `decision` Section under X |
161
- | "X error collection" / "X FAQ collection" | `faq` / `incident` Sections under X |
162
-
163
- ## Domain Gate
164
-
165
- Use `node_type: domain` only for a scope that groups child Nodes. Keep this
166
- domain reasoning checklist in working notes and persist supported relations through current
167
- `edges[]` or `unresolved[]`:
168
-
169
- | Field | Meaning |
170
- |---|---|
171
- | `scope_refs[]` | Source refs that describe the scope boundary or grouping. |
172
- | `child_refs[]` | Working-note candidate ids, local refs, or final slugs for children in the scope; persist valid ones as `edges[]`. |
173
- | `grouping_reason` | Why these children belong together under this domain. |
174
-
175
- If a domain has no resolvable child refs, no clear grouping reason, or only one same-file child without a broader scope, do not emit a Domain. For navigation-only / placeholder-only sources with only deferred children, skip the Node after ruling out standalone retrieval or graph value for an atomic-term or concrete Entity; keep only useful unresolved relation notes. Emit an Entity only when evidence names an atomic term or concrete object and choose its Entity tag yourself. The CLI rejects invalid Domain gates; it does not auto-downgrade a Domain or choose fallback tags.
176
-
177
- Scope-name titles such as "X 业务域", "Y 领域", "business domain", or "technical area" are a warning sign when proposed as Entity. Keep them as Entity only when the subject is an atomic term or concrete object; otherwise use Domain with supported child edges or unresolved relation hints.
178
-
179
- ## Edge Gate
180
-
181
- Use a typed edge only when all four checks pass:
182
-
183
- 1. Both `from` and `to` nodes exist in the current structure or approved
184
- knowledge.
185
- 2. The relation type is in the current closed set (`is_a`, `contains`,
186
- `depends_on`, `corresponds_to`, `causes`, `triggers`, `prerequisite`,
187
- `applies_to`, `verified_by`, `supersedes`).
188
- 3. `source_refs[]` cite evidence for the relation itself, not just for one
189
- endpoint.
190
- 4. The relation is stronger than a vague "related" hint.
191
-
192
- If any check fails, write an `unresolved[]` item instead of an edge.
193
-
194
- If the source sentence states the relation with uncertainty, keep the edge only
195
- when the uncertainty is source-authored and preserved through
196
- `confidence: possible` or `confidence: hypothesis`. Do not use `confidence` for
197
- Agent uncertainty. If you are uncertain whether the evidence supports the
198
- relation, write `unresolved[]` instead.
199
-
200
- ## Inference Sources
201
-
202
- Inference sources are working notes for the action reasoning checklist; do not
203
- persist this object unless the current schema explicitly exposes it:
204
-
205
- ```yaml
206
- inference_sources:
207
- actor:
208
- source_type: explicit-span
209
- source_refs: ["file:docs/runbook.md#span:steps L10-18@<span-hash>"]
210
- rationale: "The span names the operator role."
211
- outcome_or_goal:
212
- source_type: inferred-from-span
213
- source_refs: ["file:docs/runbook.md#span:steps L10-18@<span-hash>"]
214
- rationale: "The span describes recovery as the expected result."
215
- repeatability_or_plan:
216
- source_type: heading-and-span
217
- source_refs: ["file:docs/runbook.md#span:steps L10-18@<span-hash>"]
218
- rationale: "The runbook heading and ordered list indicate planned reuse."
219
- answerability:
220
- source_type: explicit-span
221
- source_refs: ["file:docs/runbook.md#span:steps L10-18@<span-hash>"]
222
- rationale: "The steps answer how the operation is performed."
223
- ```
224
-
225
- Allowed `source_type` values:
226
-
227
- | Value | Use when |
228
- |---|---|
229
- | `explicit-span` | The evidence span directly states the signal. |
230
- | `heading-and-span` | The heading plus span text together support the signal. |
231
- | `ref-node` | An existing or same-decision Node reference supplies the signal. Include `ref_nodes`. |
232
- | `inferred-from-span` | The signal is inferred from span content. Keep the rationale short and concrete. |
233
-
234
- Each source must include `rationale` when inferred and at least one of `source_refs[]` or `ref_nodes[]`.
235
-
236
- ## Final Reflection
237
-
238
- - Entity cannot pick a legal tag, or depends on its upstream title to make sense -> write it as a Section under the upstream Node or change type before submit.
239
- - Action only supports one Section -> write it as a Section instead of an Action, or add source-backed structure that reaches at least two distinct Section kinds / one child Action. The CLI does not use source prose keywords to grant an exception.
240
- - Action "steps" are parallel options/configs -> route to Entity `comparison` / `spec` / `description`.
241
- - Domain has no children -> delete it or merge it into a larger Domain.
242
-
243
- ## Current CLI Quality Diagnostics
244
-
245
- Current `context.structure.v1` validation preserves the old Node quality
246
- checks as deterministic diagnostics:
247
-
248
- | Diagnostic | Meaning | Required response |
249
- |---|---|---|
250
- | `schema.section_kind_invalid` | A planned Section uses a kind outside the current prose kind set. | Replace it with a kind from the schema view; do not invent local kind names. |
251
- | `schema.section_kind_mount_invalid` | A planned Section kind cannot be mounted on the chosen `node_type`. | Choose a kind allowed by the mount matrix, or reclassify the Node before confirming structure. |
252
- | `tags.term_conflict` | An Entity uses `term` together with concrete runtime/product tags such as `lib`, `service`, `application`, or `system`. | Split the term from the concrete object, or remove the conflicting tag before staging. |
253
- | `node.description_dominates` | A non-Action Node has at least half of its planned Sections as `description`. | Re-run kind precision. Keep it only when source evidence is genuinely narrative; otherwise split into `example`, `spec`, `comparison`, `faq`, `incident`, `decision`, `warning`, or `principle`. |
254
- | `node.thin_concrete_entity` | A concrete Entity has one Section and no child Nodes. | Keep it only when it has stable standalone retrieval value; otherwise merge it into the owning Node. |
255
- | `node.children_should_be_sections` | One parent contains many same-source, single-section child Entities with no stable shape tag. | Merge those children into parent Sections unless the user confirms each child has standalone lookup value. |
256
- | `node.term_expanded_beyond_definition` | A `term` Entity has grown past a compact definition or owns children. | Move rules, procedures, designs, and examples to the owning Node; keep the term entry narrow. |
257
- | `node.action_too_thin` | An Action has fewer than two distinct planned Section kinds and no child Action. | Downgrade it to a Section under the owning Node, add a distinct Section kind, or add a child Action; the CLI does not infer a single-section exception from source text. |
258
- | `node.domain_without_children` | A Domain has no source-backed `contains` child edge. | Add supported children, keep an explicitly confirmed no-write placeholder, or reclassify the Node. |
259
- | `tags.child_inherits_system` | A child Entity repeats its parent `system` / `application` scope tag. | Retag by the child’s own shape/scope, or keep the child as a Section if it is only a local aspect. |
260
- | `edge.confidence_invalid` | An edge declares a confidence value outside the current schema. | Use only `possible` or `hypothesis`, or omit the field for source-certain relations. |
261
-
262
- Warnings are not automatic blockers, but they are not suggestions to ignore.
263
- Resolve them or include the user-confirmed rationale when confirming structure.
@@ -1,282 +0,0 @@
1
- ---
2
- name: structure-planning
3
- description: "Internal procedure for the current align gate. Reads CLI-guided align evidence, applies semantic Node classification gates, and emits context.structure.v1 payloads for CLI validation/stage."
4
- ---
5
-
6
- # Structure Planning Procedure
7
-
8
- ## TL;DR
9
-
10
- Run `context run align:<type>:<source>:<collection> --view read-plan --format json`, follow the top-level `next_action.command` to read the CLI-selected evidence path, produce a `context.structure.v1` structure payload, and continue following top-level `next_action`. The CLI owns route, validation, repair commands, and stage guards; this skill owns only semantic classification and source-bound structure judgment.
11
-
12
- <reference>
13
-
14
- ## Canonical Data
15
-
16
- - The current phase view result is authoritative. Branch on `next_action.kind`,
17
- execute `next_action.command`, and treat listed views as detail reads rather
18
- than a checklist.
19
- - `allowed_actions[]` describes capabilities on the current view result; it is
20
- not a menu of alternate write paths and does not override `next_action`.
21
- - `agent_hints[]`, when present, are diagnostics. Do not prefer them over
22
- top-level `next_action`.
23
- - Schema names and enum values come from
24
- `context run align:<type>:<source>:<collection> --view schema --format json`. Use
25
- that schema as the authoring contract for `context.structure.v1`.
26
- - Existing approved knowledge and `knowledge/structure.yaml` are the lookup
27
- registry exposed through current CLI/status/query views. Do not read
28
- `knowledge/**` or create a separate registry file.
29
- - Code projection Nodes are reusable knowledge handles. When document evidence belongs on a code symbol, reuse the code slug instead of creating a parallel document Node.
30
- - Validation diagnostics are the mechanical structure ownership source of
31
- truth. Non-content spans such as navigation references, placeholders, front
32
- matter, marker quotes, embed tags, and embedded assets should not become
33
- reader-facing Sections unless the evidence itself is the cited knowledge.
34
- - When relation hints are present, inspect them before finalizing graph
35
- structure. Use existing/current matches for typed `edges[]`; keep unresolved
36
- target ref/title hints deferred in `unresolved[]` and do not write dangling
37
- parent, child, or edge refs. Ordinary source-bound views require at least one
38
- source-backed planned section. The only empty-section exception is a generated
39
- parent index view: it must use `generated: parent_index`, `sections: []`, and
40
- source-backed `contains` edges to child views. For navigation-only /
41
- placeholder-only sources, keep useful source/page identities as `unresolved[]`
42
- notes until there is source-backed section evidence, a supported edge target,
43
- a valid parent-index container, or a later compile `skip` decision. If a
44
- placeholder/relation source is skipped entirely, leave its relation clues in
45
- `unresolved[]` only when they still matter; otherwise omit them.
46
- - `views[]` and diagnostics distinguish citable evidence from supporting context. Do not promote supporting/context-only material into cited Sections unless a later ownership correction makes it citation-eligible.
47
- - Keep cache-friendly prompt order: fixed protocol/schema first, existing knowledge lookup second, source evidence views third, current semantic payload last. Preserve CLI JSON order and do not add timestamps, random ids, scratch paths, or host paths to generated payloads.
48
- - Structure digests and snapshot hashes are stale guards. Follow returned
49
- `next_action.command` and do not invent digest values.
50
- - Node type, tag, fake-Entity, `domain`, and `action` gates are in `structure-planning/references/gates.md`.
51
- - Coarse reading density and neutral signal rules are in `structure-planning/references/density-profile.md`.
52
- - Candidate anomaly handling, stable references, duplicate handling, and
53
- conflict handling are in
54
- `structure-planning/references/candidate-resolution.md`.
55
-
56
- </reference>
57
-
58
- <procedures>
59
-
60
- Use this only inside the current align gate.
61
-
62
- ### Step 1 — Start From The Envelope
63
-
64
- Run `context run align:<type>:<source>:<collection> --view read-plan --format json`.
65
- Confirm the response is the current prose align view result, then identify
66
- `next_action`, available views, source metadata, and diagnostics.
67
-
68
- If the host truncates a view result but the preview includes top-level
69
- `next_action.command`, run that command. If `next_action` is not visible, rerun
70
- the current view command; do not recover host tool-result files.
71
-
72
- If no current phase view result is present, stop and surface the CLI output; do
73
- not reconstruct an align route from prior prompt memory.
74
-
75
- ### Step 2 — Follow The Evidence Read Path
76
-
77
- Run the returned `next_action.command`. For structural align work this is
78
- normally `read-plan`; after that, follow the evidence view's `next_action.command`
79
- or `next_command`.
80
-
81
- `read-plan` is the navigation surface. It chooses whether the next evidence read
82
- is `source-index`, `span-detail`, `span-text`, or another current evidence view.
83
- Read those views and then author the requested
84
- `context.structure.v1` payload yourself. Never pipe evidence text into validate.
85
-
86
- If an evidence view is truncated, `page.has_more: true`, or the CLI returns a
87
- `next_command`, run that command before authoring.
88
-
89
- Read evidence through semantic CLI views, not shell parsing. Follow `page.next_command` for pagination. If the command contains `--read-cursor`, treat it as opaque continuation state and run it exactly; do not replace it with hand-written `--source`, `--heading`, `--window`, or `--range` selectors. Use `--source`, `--heading`, `--window`, `--range`, and `--token-budget` as view filters only. `--unwrap` removes workflow metadata; it does not expand a compact view into full detail.
90
-
91
- If an evidence view returns `page.has_more`, `truncated: true`, or a
92
- view-specific incomplete-read diagnostic, treat that response as a partial
93
- read. Do not decide source-wide ownership or dense planned Sections from
94
- headings alone; continue the current detail view only when `page.next_command`
95
- is explicitly needed, otherwise return to the CLI-designated navigation view.
96
-
97
- ### Step 3 — Reuse Existing Knowledge
98
-
99
- Query existing knowledge for reusable names before proposing new term/service/system/action Nodes. Exact title/slug/alias hits should usually become references to the existing Node, not duplicate candidates.
100
-
101
- When a code projection Node already represents the object, reuse its slug for prose evidence and plan only prose-owned Sections for the current source evidence.
102
-
103
- ### Step 4 — Route Collection, Then Classify Semantic Structure
104
-
105
- Before choosing Node type or Section kind, route each evidence unit to its
106
- internal collection. The phase `<collection>` is only the entry profile for the
107
- current run; it is not a cap on what this structure may contain. A mixed source
108
- can produce multiple `views[]` in one confirmed structure when source evidence
109
- supports them.
110
-
111
- Use collection routing first:
112
-
113
- - product intent, user story, requirement, roadmap, or product scenario ->
114
- `product`;
115
- - architecture, service/module/system design, runtime dependency, code-adjacent
116
- prose -> `architecture`; if an existing code projection already owns the
117
- object, reuse its NodeRef/ViewRef instead of creating a `codegraph` prose
118
- view;
119
- - SOP, runbook, operation drill, workflow, or how-to procedure -> `sop`;
120
- - FAQ, question/answer, support notes -> `faq` only when the evidence is an
121
- independent FAQ page or cross-cutting support knowledge; a single Q&A or
122
- scattered support note stays as a `faq` Section under the owning view;
123
- - standards, policy, rules, conventions, reusable constraints -> `standards`;
124
- - decision record, trade-off, migration conclusion -> `decision` only when it
125
- is an independent decision record with owner/date/lifecycle or cross-cutting
126
- decision scope; one-off conclusions stay as `decision` Sections under the
127
- owning view;
128
- - incident, postmortem, outage, fault timeline, action item -> `incident` only
129
- when it has incident identity, timeline, follow-up, or tracking lifecycle;
130
- isolated warnings/failures/action items stay as `incident` or `warning`
131
- Sections under the owning view;
132
- - test plan, validation scenario, acceptance case -> `test`;
133
-
134
- Do not route prose align views to `codegraph` or `feats`: `codegraph` is
135
- produced by code extraction / AST projection, and `feats` is reserved for the
136
- dedicated feature workflow. For section-vs-collection overlap, keep a local
137
- `faq`, `decision`, or `incident` as a Section kind under the owning view unless
138
- the source is independently queryable across the package and has its own
139
- lifecycle, ownership, timeline, or cross-cutting scope.
140
-
141
- After collection routing, apply `structure-planning/references/gates.md` before
142
- authoring Nodes: classify Node type in order (`action` scale + process evidence,
143
- then concrete/term `entity`, then child-bearing `domain`), reject fake Entities
144
- only when at least two suspicious signals match, keep `term` separate from
145
- concrete tags, and provide required gate evidence.
146
-
147
- Preserve shared-source intent when the same source span legitimately supports
148
- multiple views. Do not copy the span text into multiple rewritten bodies; cite
149
- the same CLI `source_ref` in each supported view and let structure-summary mark
150
- the shared evidence.
151
-
152
- Source titles and headings are ordinary evidence, not structural authority. Choose titles and summaries that fit the final Node type and the CLI-provided generation policy.
153
-
154
- Plan source material as Sections first. A source heading only becomes a child
155
- Node/View when the cited evidence names a concrete independent subject, an
156
- atomic term, a gated Action, or a child-bearing Domain. A `contains` edge only
157
- states hierarchy; it does not prove that a thin child page has standalone
158
- retrieval value.
159
-
160
- Avoid same-source fragmentation. If one parent would contain many single-section
161
- child Entities from the same source document, keep them as Sections unless each
162
- child has an independent product/code object, atomic term, Action, or Domain
163
- identity. Also avoid copying the parent `system` / `application` scope tag onto
164
- local child aspects; tag a child by what it independently is.
165
-
166
- Do not promote a source fragment into a child page solely because it has a
167
- heading or a recognized section kind. Judge every proposed child with the same
168
- source-backed criteria: independent subject identity, sufficient context, and
169
- standalone retrieval value. The CLI may warn about repeated same-source thin
170
- children, but page granularity remains an evidence-backed structure decision
171
- for the review report rather than a content-type-specific hard gate.
172
-
173
- For `node.title` and `node.summary`, follow the workspace/source language
174
- surfaced by the current view or the user's instruction. In Chinese workspaces,
175
- translate descriptive scaffold words such as architecture, strategy, lifecycle,
176
- overview, scheduling, high availability, and warning into Chinese while
177
- preserving product names, code identifiers, CLI flags, slugs, source_ref tokens,
178
- and citation tokens exactly when needed. Do not copy an English source title
179
- into `node.title` merely because the source is English.
180
-
181
- Do not classify a broad architecture/system/方案 source as `domain` just because the title sounds like a scope. If it has writable Sections but no resolvable current/existing child Nodes, use an `entity` tag such as `system` or `application`; reserve `domain` for grouping child Nodes through typed `edges[]` with supported child targets.
182
-
183
- For large or batched payloads, use
184
- `structure-planning/references/density-profile.md` and
185
- `structure-planning/references/candidate-resolution.md` as judgment aids.
186
- They do not create additional workflow stages or alternate payloads.
187
-
188
- ### Step 5 — Build The Payload Requested By `next_action`
189
-
190
- Use `context run align:<type>:<source>:<collection> --view schema --format json` to
191
- shape the payload. Treat that schema as the authoring contract.
192
-
193
- Produce one `context.structure.v1` document with semantic Nodes, planned
194
- Sections, typed edges, unresolved items, lifecycle state, sources, and evidence
195
- snapshot hash. Section identities are part of the structure gate: choose stable
196
- section ids such as `overview`, `behavior`, `constraints`, or a source-backed
197
- domain-specific name when the evidence supports it.
198
-
199
- Use only CLI-provided `source_refs[]` for section and edge evidence. Continuity
200
- is a per-Section constraint, not a per-View constraint: one View may contain
201
- many independently retrievable Sections, each with its own continuous mirror.
202
- Do not invent heading/range/window selectors inside the structure. Treat source
203
- heading changes as section-planning signals: sibling sub-headings under a shared parent
204
- may stay in one Section when they form one coherent semantic topic; headings
205
- with no shared parent should usually split unless you intentionally want one
206
- Section to span them. If a semantic section would require non-contiguous or
207
- cross-source evidence, split it during align or return the issue to the
208
- structure gate. Current compile writes approved knowledge by mirroring source
209
- spans; it does not use rewritten multi-ref sections to compress unrelated
210
- evidence.
211
-
212
- Validate will surface source mirror blockers before confirmation. Treat
213
- `section.source_mirror_split_required`,
214
- `section.source_mirror_repair_required`, and
215
- `section.source_mirror_source_refs_missing` as structure problems, not compile
216
- drafting problems. Use the returned `repair.suggested_splits[]` when present;
217
- otherwise repair source refs from CLI evidence views or move unsupported
218
- material to `unresolved[]`.
219
-
220
- For pure suggested-split repairs, prefer the CLI repair view before hand-editing:
221
- `context run align:<type>:<source>:<collection> --repair suggested-splits --input <structure.yaml> --format json`.
222
- It splits non-contiguous Section mirrors and can expand a broad cross-heading
223
- Section into Markdown structural groups within the same View. Apply the
224
- non-blocking repair hint when the groups should be independently retrievable;
225
- otherwise keep the Section and explain the grouping in structure review.
226
- Oversized Views still require the Agent to apply the returned child-View and contains-edge suggestions while
227
- classifying every child Node from evidence. The repair command does not resolve
228
- orphan ownership, unsupported evidence, or competing semantic groupings.
229
-
230
- When the cited source sentence itself is uncertain, preserve that uncertainty on
231
- the edge with `confidence: possible` or `confidence: hypothesis`. This is only
232
- for source-authored uncertainty such as "可能", "疑似", "may", or "might". If
233
- you are unsure whether the source supports the relation, do not add an uncertain
234
- edge; move the relation to `unresolved[]`.
235
-
236
- No-write/navigation-only/placeholder-only material should become `unresolved`
237
- at align time when it has retrieval or graph value but lacks source-backed
238
- section evidence. Do not turn relation-only navigation into a factual Section.
239
- Do not submit `sections: []` for an ordinary source-bound view. Use
240
- `sections: []` only for a generated parent index view, and only when it has
241
- `generated: parent_index` plus source-backed `contains` edges to child views.
242
- If the relationship matters but evidence or a target node is missing, keep it
243
- unresolved instead of writing a dangling edge.
244
-
245
- Emit `depends_on` edges only when cited source refs explicitly say one Node
246
- consumes, requires, calls, is configured by, or is downstream of another Node as
247
- a prerequisite, capability provider, upstream input, runtime dependency, or
248
- data-flow source. Direction is consumer/downstream -> provider/upstream. Do not
249
- create `depends_on` for parent/child containment, `Related`/`See also` lists,
250
- sibling co-occurrence, shared table membership, name similarity, or a plain
251
- mention without a dependency predicate. `edges[].source_refs[]` must include the
252
- source ref that states the dependency; if the relationship matters but evidence
253
- is missing, leave the edge unresolved instead of guessing.
254
-
255
- Prefer the strongest source-backed `section_kind` using the current schema's `section_kind_priority` and `section_kind_triggers`; avoid planning an entire dense source as `description` when the evidence clearly contains fenced examples, comparison tables, Q&A, decisions, specs, warnings, or principles. Use `example` for fenced command/config/code or literal sample blocks, not ordinary scenario prose. Use `incident` only for dated or timestamped failure evidence with impact scope plus root cause, mitigation, or handling record. Use `decision` only when the source surfaces two or more alternatives or options plus the chosen path and rationale. Treat kind precision as a drafting quality preference, not a reason to block an otherwise source-backed write. Keep only raw-backed semantic decisions in the payload; leave mechanical repair and patch routing to CLI diagnostics.
256
-
257
- There is no parallel candidate-body authoring path. Emit only the
258
- `context.structure.v1` payload accepted by the current schema view.
259
-
260
- ### Step 6 — Validate And Submit
261
-
262
- Before staging, run `context run align:<type>:<source>:<collection> --validate --input - --format json` with the `context.structure.v1` payload. If validate returns `repair_confirmation_blockers`, follow its repair route and rerun validate without asking for preliminary approval. `--repair suggested-splits` handles non-contiguous source mirror Sections. For oversized Views, apply the returned child-View and contains-edge suggestions while classifying child Nodes from evidence. Resolve other blockers from evidence; ask the user only when evidence supports multiple incompatible semantic choices, and state that this is not final review. Stage only after `confirmation_ready=true`. The stage result opens the final HTML report and is the human review gate: show the structure to the user through `structure_report.file_url`, `structure_report.absolute_path`, and the compact summary before asking for confirmation. Only write `lifecycle.state: confirmed` only after explicit confirmation; then run `context run align:<type>:<source>:<collection> --confirm --format json` or pass an explicit file with `--confirm --input <structure.yaml> --format json`.
263
-
264
- After stage succeeds, do not rerun the same write command to confirm success.
265
- Use `context status --format json` or the returned result for read-only
266
- confirmation; then continue with the returned `next_action.command`, normally
267
- `context run compile:<type>:<source>:<collection> --view read-plan --format json`.
268
-
269
- If any write is rejected, follow the returned `next_action` and `reason_code`.
270
- Do not retry by guessing direct/batched stages, forcing route bypasses, or
271
- editing CLI-managed files.
272
-
273
- ### Step 7 — Self-verify
274
-
275
- - [ ] All writes followed top-level `next_action.command`. If not, return to **Step 1**.
276
- - [ ] Evidence was read through returned `next_action.command`, `next_command`, or current CLI schema/view commands only. If not, return to **Step 2**.
277
- - [ ] Node classification used the semantic gates in `structure-planning/references/gates.md`. If not, return to **Step 4**.
278
- - [ ] URL/reference ownership followed CLI diagnostics, not static prompt rules. If not, return to **Step 5**.
279
- - [ ] The requested align payload passed `context run align:<type>:<source>:<collection> --validate --input - --format json` before stage. If not, return to **Step 6**.
280
- - [ ] No `sources/`, `unapproved/`, `knowledge/`, `dist/`, `.tmp`, host tool-results, or CLI-managed files were read or written with generic tools. If violated, restart from **Step 1**.
281
-
282
- </procedures>