@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
@@ -1,170 +0,0 @@
1
- ---
2
- name: drop
3
- description: >
4
- Source retraction through CLI-owned planning and application. The agent
5
- calls `context drop --plan` for a structured impact plan, presents the
6
- user-facing summary for confirmation, runs semantic reconciliation, then
7
- calls `context drop --apply-plan --decisions` so the CLI archives raw and
8
- removed knowledge, cleans active knowledge, applies source alias reindexing,
9
- source stamp, changelog append, semantic ledger write, and verify.
10
- Activates when `/context:drop` is invoked with a source-id, raw snapshot
11
- path, or URL.
12
- tools:
13
- - Bash
14
- ---
15
-
16
- # drop — retract a source without losing the audit trail
17
-
18
- Ask the CLI for a structured cleanup plan, confirm the user-visible impact,
19
- run semantic reconciliation on affected knowledge items, then ask the CLI to
20
- apply the plan with the confirmed decision document. Do not inspect or mutate
21
- workspace files directly.
22
-
23
- `WORKSPACE_DIR` is provided by the caller from `context workspace locate --format json` (`ctxDir`). It is `.context/` in embedded layout and the repository root in root layout.
24
-
25
- ## TL;DR — Non-negotiables
26
-
27
- - Plan + semantic prepare/review + apply are CLI-owned. The agent only presents the plan, asks semantic questions when required, and waits for confirmation.
28
- - Drop removes affected raw / unsupported knowledge from the active workspace and stores them under `archive/` for restore/audit.
29
- - Do not Read / Glob / Grep / Write anything under `WORKSPACE_DIR`; all impact analysis and mutation must go through `context drop --plan`, `context reconcile prepare --mode drop`, `context reconcile review`, and `context drop --apply-plan --decisions`.
30
- - `context drop --plan <source-id|raw-path|url> --format json` resolves source-id, computes affected topics / knowledge items, and reports alias reindex impact.
31
- - `context drop --apply-plan <plan-file> --decisions <decisions-file> --reason "<text>" --yes` archives affected active content, consumes semantic decisions, removes unsupported Sections / empty Nodes from active knowledge, applies source alias reindexing, writes the semantic ledger, source stamp, changelog append, and verify.
32
- - User confirmation required unless `--yes` was passed; abort on any non-`y` answer without writing. `--yes` does not skip semantic `ask_user` questions.
33
- - Confirmation prose follows `${CLAUDE_PLUGIN_ROOT}/skills/align-scan/references/user-question-contract.md`: describe affected topics and claims, not source-ref mechanics.
34
- - Source evidence, section, and verify rule meanings stay anchored to `${CLAUDE_PLUGIN_ROOT}/skills/align-scan/references/data-model.md`.
35
- - Output language: impact plan + report match the user's language; CLI commands, flag names, source-ids, comment attributes stay English.
36
-
37
- <reference>
38
-
39
- ## Plan fields
40
-
41
- The JSON plan has:
42
-
43
- | Field | Meaning |
44
- |---|---|
45
- | `source_id` | Canonical source id resolved from user input |
46
- | `resolved_from.kind` | `source-id`, `snapshot-path`, or `url` |
47
- | `affected_nodes[]` | Topics whose source list contains the dropped source |
48
- | `affected_nodes[].sections[]` | Knowledge items that require semantic reconciliation before the source is dropped |
49
- | `affected_nodes[].reindex_sections[]` | Knowledge items whose internal source alias will be renumbered after the source is removed |
50
- | `affected_nodes[].will_be_sourceless` | Topic has no remaining source ids after cleanup |
51
- | `affected_nodes[].will_be_empty` | Topic has no remaining Section/body/children/contains after cleanup and may be archived even if another source id remains |
52
- | `affected_graph_edges[]` | Explicit graph edges that will be removed if one endpoint is archived by apply |
53
- | `unaffected_references[]` | Topic relationships that mention affected topics but are not source evidence |
54
- | `summary` | Counts for confirmation and changelog |
55
-
56
- If a non-domain Node would keep an active source id but lose all of its own Sections while still carrying child Nodes, contains links, or body text, do not rely on verify to catch it after mutation. Produce a semantic reanchor/split decision that preserves a supported Section, or expect `drop --apply-plan` to reject before writing.
57
-
58
- ## User-facing impact summary shape
59
-
60
- ```
61
- Affected: N topics · M knowledge items
62
-
63
- <topic title>
64
- "short claim preview" → remove from active knowledge and archive
65
- "short claim preview" → keep, supported by another source document
66
- <topic title>
67
- "short claim preview" → remove from active knowledge and archive
68
-
69
- Proceed? [y/N]
70
- ```
71
-
72
- Keep the internal node slug, Section id, and source-ref patch data in your
73
- working notes for Step 4; show them only if the user asks for implementation
74
- details.
75
-
76
- ## CLI shapes
77
-
78
- ```
79
- context drop --plan <source-id|raw-path|url> --format json
80
- context reconcile prepare --mode drop --drop-plan <plan-file> --format json
81
- context reconcile review --context <context-file> --decisions <decisions-file> --format json
82
- context drop --apply-plan <plan-file> --decisions <decisions-file> --reason "<text>" --yes
83
- ```
84
-
85
- The apply command writes a source-specific archive under `archive/sources/`,
86
- moves affected raw out of active `raw/`, consumes semantic decisions for
87
- reanchor / remove_unsupported / split_then_reanchor, removes unsupported
88
- Sections / empty Nodes from active `knowledge/`, flips the source registry entry to
89
- `status: dropped`, stamps `drop_reason` + `dropped_at` + `archive_path`,
90
- appends a `[drop]` line to `knowledge/changelog.md`, records
91
- `decisions/semantic.yaml`, and runs verify. It exits
92
- non-zero if the source-id is unknown, already dropped, plan shape is invalid,
93
- the plan is stale, semantic decisions are unresolved/invalid, or verify reports errors.
94
- In drop mode, `remove_unsupported` means physical removal from active knowledge
95
- after the archive captures the before snapshot; compile/refresh apply uses the
96
- same action name for Section deprecation.
97
-
98
- </reference>
99
-
100
- <procedures>
101
-
102
- ### Step 1 — Parse arguments
103
-
104
- From `$ARGUMENTS`: `<source-id|raw-path|url>` (required), `--reason <text>` (optional), `--yes` (optional). If the target is missing, stop and ask for the source id or raw snapshot path. If the reason is missing but the user's wording gives a clear reason, infer a concise reason such as `用户主动撤回`; otherwise collect it before Step 4.
105
-
106
- ### Step 2 — Ask CLI for a plan
107
-
108
- Run `context drop --plan <source-id|raw-path|url> --format json`. Do not inspect
109
- workspace files yourself. If the CLI reports source-not-found or
110
- source-already-dropped, relay the error and stop.
111
-
112
- ### Step 3 — Present the impact plan
113
-
114
- Render the [User-facing impact summary shape](#user-facing-impact-summary-shape)
115
- from the plan JSON in the user's language. Make clear that dropping a source
116
- removes listed content from active knowledge but keeps it restorable under
117
- `archive/` until `context purge`. Mention conditional graph edge cleanup when
118
- `affected_graph_edges[]` is non-empty; these edges are removed only if the
119
- endpoint leaves active knowledge after reconciliation. Include the reason that will be stamped; if
120
- it is still unknown, ask for the reason before continuing. If `--yes`, log
121
- "auto-confirmed per --yes" and continue. Otherwise wait for `y`; abort on
122
- anything else without writing.
123
-
124
- ### Step 4 — Reconcile affected knowledge
125
-
126
- Write the exact plan JSON to a temporary file outside `WORKSPACE_DIR`, then run:
127
-
128
- ```
129
- context reconcile prepare --mode drop --drop-plan <plan-file> --format json
130
- ```
131
-
132
- Invoke `${CLAUDE_PLUGIN_ROOT}/skills/semantic-reconcile/SKILL.md` with that
133
- prepare payload. Save its decision document outside `WORKSPACE_DIR`, then run
134
- `context reconcile review --context <context-file> --decisions <decisions-file> --format json`.
135
- If review returns any `questions[]`, ask the user and convert those decisions
136
- from `ask_user` into one of `reanchor`, `remove_unsupported`, or
137
- `split_then_reanchor` before continuing. Do not let `--yes` bypass this step.
138
-
139
- ### Step 5 — Apply the plan
140
-
141
- Write the exact plan JSON and confirmed semantic decision document to temporary
142
- files outside `WORKSPACE_DIR`, then call:
143
-
144
- ```
145
- context drop --apply-plan <plan-file> --decisions <decisions-file> --reason "<text>" --yes
146
- ```
147
-
148
- Do not call `context mdrive section ...` or `context mdrive node ...` for the
149
- standard drop flow; `drop --apply-plan --decisions` owns cleanup, ledger write,
150
- and verify.
151
-
152
- ### Step 6 — Report
153
-
154
- The apply command already verifies. Run `context source get <source-id>` and
155
- report in the user's language: topics affected, knowledge items marked
156
- archived/removed from active knowledge, source alias reindex count, archive
157
- path, changelog timestamp.
158
-
159
- ### Step 7 — Self-verify
160
-
161
- - [ ] No Read / Glob / Grep / Write was used against `WORKSPACE_DIR` — if any was used, restart from **Step 2** with CLI-only flow.
162
- - [ ] `context drop --plan` succeeded before asking the user — if not, **Step 2**.
163
- - [ ] `context reconcile prepare --mode drop` was run from the exact drop plan — if not, **Step 2**.
164
- - [ ] `context reconcile review` returned zero `questions[]` before apply; if any question remains, ask the user and regenerate the decisions document.
165
- - [ ] User confirmed unless `--yes` was passed — if not, abort without writing.
166
- - [ ] `context drop --apply-plan` exited 0 — if not, surface the CLI error and stop.
167
- - [ ] `context source get <source-id>` shows the source as dropped — if not, surface the mismatch.
168
- - [ ] The reported source entry includes `archive_path` — if missing, surface the mismatch.
169
-
170
- </procedures>
@@ -1,129 +0,0 @@
1
- ---
2
- name: semantic-reconcile
3
- description: >
4
- Internal skill for `/context:compile` and `/context:drop`. Consumes only
5
- `context reconcile prepare` output, judges semantic relation/action for each
6
- item, and emits a schema_version 1.0 semantic decision document for
7
- `context reconcile review` / `context reconcile apply`.
8
- tools:
9
- - Bash
10
- ---
11
-
12
- # semantic-reconcile — decide Section reconciliation
13
-
14
- Judge duplicate, merge, conflict, reanchor, and unsupported cases from the
15
- CLI-prepared context. Emit decisions only; the CLI performs every write.
16
-
17
- ## TL;DR — Non-negotiables
18
-
19
- - Input is only the `context reconcile prepare` payload. Do not Read, Glob, Grep, or Write workspace `raw/`, `knowledge/`, `archive/`, or `decisions/`.
20
- - Output exactly one YAML or JSON document with `schema_version: "1.0"` and `decisions[]`.
21
- - Use canonical relations: `exact_duplicate`, `strong_equivalent`, `near_duplicate`, `complement`, `supersedes`, `conflicts`, `reanchor`, `unsupported`, `keep_separate`, `ask_user`.
22
- - Use canonical actions: `duplicate_skip`, `merge_update`, `supersede`, `reanchor`, `remove_unsupported`, `keep_separate`, `split_then_reanchor`, `ask_user`.
23
- - `no-op` is not a decision action. For unchanged refresh items, emit no decision or `duplicate_skip`.
24
- - Never expose `src-N`, Section ids, or source refs as the user-facing choice. They may appear only in the structured payload.
25
- - `merge_update` is legal only when the final Section content is supported by one valid `source_ref`; otherwise use `keep_separate`, `split_then_reanchor`, or `ask_user`.
26
- - Unresolved conflicts and low-confidence support questions must be `action: ask_user`.
27
-
28
- <reference>
29
-
30
- ## Decision Shape
31
-
32
- ```yaml
33
- schema_version: "1.0"
34
- decisions:
35
- - item_id: claim-001
36
- relation: near_duplicate
37
- action: merge_update
38
- target:
39
- node: payment-runtime
40
- section_id: section-3
41
- proposed:
42
- content: "Runtime isolation uses sandboxing to avoid state pollution."
43
- confidence: confirmed
44
- source_ref: "src-2#runtime L12-14"
45
- source_ref_text: "sandboxing to avoid state pollution"
46
- rationale: "The new evidence refines the same claim."
47
- ```
48
-
49
- ## Action Rules
50
-
51
- | action | Required fields | Validation |
52
- |---|---|---|
53
- | `duplicate_skip` | `target` | Exact duplicate or already-applied no-op only. |
54
- | `merge_update` | `target`, `proposed.content`, `proposed.source_ref`, `proposed.source_ref_text` when present in prepare | Final content must be supported by one raw line range; `proposed.kind`, when present, must match target kind. |
55
- | `supersede` | `target`, `proposed.kind`, `proposed.content`, `proposed.source_ref`, `proposed.source_ref_text` when present in prepare | New Section claim must be supported by one raw line range. |
56
- | `reanchor` | `target`, `proposed.source_ref`, `proposed.confidence` | Use only when target content is still supported by the new source. |
57
- | `remove_unsupported` | `target` | Use when no active source supports the target claim in this mode. |
58
- | `keep_separate` | `target`, `proposed.kind`, `proposed.content`, `proposed.source_ref`, `proposed.source_ref_text` when present in prepare | New orthogonal claim must be supported by one raw line range. |
59
- | `split_then_reanchor` | `target`, `proposed.sections[]` with each Section carrying `kind`, `content`, `source_ref`, and `source_ref_text` when present in prepare | Each split Section must be independently supported by its cited raw line range. |
60
- | `ask_user` | `user_confirmation.required: true` | Use only when business meaning or support cannot be decided from prepared evidence. |
61
-
62
- For `merge_update`, `supersede`, `keep_separate`, and
63
- `split_then_reanchor`, the final Section content must be lexically supported by
64
- the cited raw line range in `proposed.source_ref`. Preserve
65
- `proposed.source_ref_text` from the prepared context when it is present; it is
66
- the human-readable evidence text the CLI used to derive the canonical
67
- `source_ref`. Content should retain the raw evidence's key domain terms,
68
- numbers, code literals, and named entities. Do not turn sparse raw evidence
69
- into a broad summary, and do not cite a title, `Relations`, `Parent`,
70
- `Children`, or `Related` navigation line as the only support for a substantive
71
- claim.
72
-
73
- The support gate exists to prevent orphan claims and false evidence links, not
74
- to optimize retrieval. Prefer preserving a precise raw-backed claim over
75
- rewriting content into a smoother summary. If a useful reader summary would
76
- combine multiple evidence ranges, choose `split_then_reanchor` or `ask_user`
77
- instead of forcing it into one `source_ref`.
78
-
79
- Final executable decisions must not carry `user_confirmation.required: true`.
80
- Use that flag only on `action: ask_user` items that still require user input.
81
-
82
- `remove_unsupported` has mode-specific write behavior. In compile/refresh
83
- apply it deprecates the target Section so the unsupported claim remains visible
84
- as inactive history. In drop apply it physically removes the Section from active
85
- knowledge after `archive/sources/.../knowledge/before/` captures the pre-drop
86
- file. Use the same action only when this mode-specific outcome is intended.
87
-
88
- </reference>
89
-
90
- <procedures>
91
-
92
- ### Step 1 — Read Prepared Context
93
-
94
- Use the caller-provided `context reconcile prepare` output. For each item,
95
- compare `proposed`, `candidates`, `previous_decisions`, and `evidence`.
96
-
97
- ### Step 2 — Reuse Stable Priors
98
-
99
- If `previous_decisions[]` shows the same boundary and the prepared item still
100
- matches, emit the same final action. If the target changed, treat the previous
101
- decision as a prior only and continue judging.
102
-
103
- ### Step 3 — Decide Relation And Action
104
-
105
- Classify each item:
106
-
107
- - Exact same claim already active -> `exact_duplicate` + `duplicate_skip`.
108
- - Same claim with a raw-supported correction or refinement from one supporting source -> `strong_equivalent` or `near_duplicate` + `merge_update`.
109
- - Additional but separate boundary -> `complement` + `keep_separate`.
110
- - New material replaces old rule -> `supersedes` + `supersede`.
111
- - Direct contradiction -> `conflicts` + `ask_user`.
112
- - Drop item still fully supported elsewhere -> `reanchor` + `reanchor`.
113
- - Drop item partly supported -> `reanchor` + `split_then_reanchor`.
114
- - No surviving support -> `unsupported` + `remove_unsupported`.
115
- - Evidence is close but not enough -> `ask_user`.
116
-
117
- ### Step 4 — Emit Decisions
118
-
119
- Emit only executable final decisions plus unresolved `ask_user` questions.
120
- Do not include prose outside the document.
121
-
122
- ### Step 5 — Self-verify
123
-
124
- - [ ] Every decision uses canonical relation/action values. If not, **Step 3**.
125
- - [ ] No `no-op` action appears. If not, **Step 3**.
126
- - [ ] Every write action has the required fields from [Action Rules](#action-rules). If not, **Step 4**.
127
- - [ ] No workspace files were read or written directly. If violated, restart from **Step 1**.
128
-
129
- </procedures>