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

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 (49) hide show
  1. package/README.md +71 -34
  2. package/cli.js +42978 -20206
  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 +99 -0
  8. package/plugin/README_CN.md +97 -0
  9. package/plugin/assets/icon.svg +3 -0
  10. package/plugin/assets/logo.svg +3 -0
  11. package/plugin/commands/align.md +44 -44
  12. package/plugin/commands/capture.md +27 -11
  13. package/plugin/commands/compile.md +90 -36
  14. package/plugin/commands/context.md +7 -4
  15. package/plugin/commands/drop.md +14 -6
  16. package/plugin/commands/extract.md +3 -3
  17. package/plugin/commands/init.md +48 -9
  18. package/plugin/commands/purge.md +6 -6
  19. package/plugin/commands/query.md +11 -3
  20. package/plugin/commands/status.md +4 -2
  21. package/plugin/skills/skill-align-workflow/SKILL.md +55 -0
  22. package/plugin/skills/skill-align-workflow/references/candidate-resolution.md +60 -0
  23. package/plugin/skills/skill-align-workflow/references/density-profile.md +23 -0
  24. package/plugin/skills/skill-align-workflow/references/gates.md +95 -0
  25. package/plugin/skills/skill-compile-close/SKILL.md +127 -0
  26. package/plugin/skills/skill-compile-draft/SKILL.md +409 -0
  27. package/plugin/skills/skill-context-query/SKILL.md +184 -0
  28. package/plugin/skills/skill-drop/SKILL.md +190 -0
  29. package/plugin/skills/skill-semantic-reconcile/SKILL.md +249 -0
  30. package/scripts/build-plugin.ts +674 -45
  31. package/templates/aspects/code/aspect.yaml +21 -0
  32. package/templates/aspects/code/prompt.md +33 -18
  33. package/templates/aspects/design-system/prompt.md +2 -3
  34. package/templates/aspects/graphql/prompt.md +2 -2
  35. package/templates/aspects/openapi/prompt.md +2 -2
  36. package/plugin/.claude-plugin/plugin.json +0 -16
  37. package/plugin/.codex-plugin/plugin.json +0 -35
  38. package/plugin/commands/capture-aspect.md +0 -17
  39. package/plugin/commands/capture-code.md +0 -25
  40. package/plugin/skills/align-finalize/SKILL.md +0 -137
  41. package/plugin/skills/align-propose/SKILL.md +0 -163
  42. package/plugin/skills/align-scan/SKILL.md +0 -161
  43. package/plugin/skills/align-scan/references/data-model.md +0 -343
  44. package/plugin/skills/align-scan/references/user-question-contract.md +0 -159
  45. package/plugin/skills/compile-close/SKILL.md +0 -122
  46. package/plugin/skills/compile-draft/SKILL.md +0 -252
  47. package/plugin/skills/context-query/SKILL.md +0 -166
  48. package/plugin/skills/drop/SKILL.md +0 -170
  49. package/plugin/skills/semantic-reconcile/SKILL.md +0 -129
@@ -0,0 +1,60 @@
1
+ # Candidate Resolution Rules
2
+
3
+ Use these rules after reading candidate ledger and aggregate payloads, before `align-structure-decision`.
4
+
5
+ ## Anomaly Signals
6
+
7
+ `anomaly_signals[]` are mechanical warnings. Do not ignore them and do not treat them as recommendations.
8
+
9
+ For each anomaly, choose one outcome and record the reasoning in either the next ledger op rationale, the final node summary/audit warning, or `unresolved[]`:
10
+
11
+ | Outcome | Use When |
12
+ |---|---|
13
+ | `accept` | The anomaly points to a real correction. Apply a concrete op or final structure choice. |
14
+ | `dismiss` | The warning is mechanically true but semantically harmless. Keep the candidate and state why. |
15
+ | `unresolved` | The warning changes structure but the source evidence is insufficient. Add an unresolved question instead of guessing. |
16
+
17
+ Known anomaly kinds:
18
+
19
+ | Kind | Meaning | Required Handling |
20
+ |---|---|---|
21
+ | `missing_evidence` | An active candidate has no evidence block. | Add evidence, reject the candidate, or mark the structure unresolved. |
22
+ | `ledger_churn` | A candidate was renamed, merged, superseded, or rejected during discovery. | Confirm the final title/slug/target or mark unresolved if the shape is still ambiguous. |
23
+ | `duplicate_block` | The same evidence block appears more than once on a candidate. | Dedupe the evidence or explain why repeated evidence is harmless. |
24
+ | `general_review_recommended` | The CLI collapsed more than eight anomalies. | Review the affected candidate broadly; do not finalize solely from aggregate ordering. |
25
+
26
+ ## Label Hints
27
+
28
+ For `merge_into`, `supersede`, and `reject`, include the visible label hint fields:
29
+
30
+ - `source_label_hint` and `target_label_hint` for `merge_into`
31
+ - `source_label_hint` and `target_label_hint` for `supersede`
32
+ - `candidate_label_hint` for `reject`
33
+
34
+ These hints are for audit and Agent DX. Copy them from ledger labels/titles when available. Do not invent a label that contradicts the visible candidate.
35
+
36
+ ## `llm_slug_hint` And Refs
37
+
38
+ Use `llm_slug_hint` as the stable reference inside one `align-structure-decision` payload when final slugs may be normalized by the CLI.
39
+
40
+ Recommended pattern:
41
+
42
+ ```yaml
43
+ nodes:
44
+ - llm_slug_hint: local:data-region
45
+ slug: data-region
46
+ node_type: entity
47
+ tags: [term]
48
+ - llm_slug_hint: local:failover
49
+ contains_parent_ref: local:data-region
50
+ edges:
51
+ - edge_type: depends_on
52
+ from_ref: local:failover
53
+ to_ref: local:data-region
54
+ sections:
55
+ - owner: local:data-region
56
+ block_ownership:
57
+ - owners: [local:data-region]
58
+ ```
59
+
60
+ Refs may point to `llm_slug_hint` or final `slug`; prefer `*_ref` fields when a schema provides them. If the CLI rejects an unknown ref, use the returned `agent_hints[].available_node_refs` and resubmit a corrected `align-structure-decision`.
@@ -0,0 +1,23 @@
1
+ # Coarse Read Density Selection
2
+
3
+ Use `density_profile` in `align-coarse-read` to describe how much structure the document needs before candidate discovery. This is a reading strategy, not a quality score.
4
+
5
+ | Profile | Use When | Agent Behavior |
6
+ |---|---|---|
7
+ | `macro` | A long source has many headings, sections, or broad topic shifts. | Create section proposals around major headings and preserve document-level anchors so later passes do not flatten scope. |
8
+ | `meso` | Default for normal product, design, or operational documents with several related sections. | Produce section proposals for meaningful local units and neutral content signals for each anchor. |
9
+ | `micro` | The source is fragmented, note-like, or dense with short independent claims. | Keep section proposals narrow and avoid bundling unrelated blocks into one candidate. |
10
+ | `single_pass` | The source is short enough that one read can safely discover all relevant structure. | Still emit the `align-coarse-read` artifact, but keep anchors minimal and avoid over-segmentation. |
11
+
12
+ ## Content Signals
13
+
14
+ `content_signals` are neutral shape signals used later by action/domain gates. They must not directly claim `node_type`, tags, or recommendations.
15
+
16
+ | Signal | Meaning |
17
+ |---|---|
18
+ | `temporal_density` | The text has timelines, phases, schedules, version changes, or ordered time references. |
19
+ | `actor_density` | The text names roles, users, teams, systems, services, or operators that perform work. |
20
+ | `step_density` | The text contains ordered steps, procedures, phases, checklists, or how-to flow. |
21
+ | `directive_density` | The text contains imperatives, policies, constraints, must/should language, or runbook-like instructions. |
22
+
23
+ Use only `high`, `med`, or `low` based on the local section text. The canonical middle value is `med`; do not write `medium`. High `step_density` plus explicit actors and outcomes is useful evidence for an Action Gate, but it is not enough by itself to emit an `action` Node.
@@ -0,0 +1,95 @@
1
+ # Candidate Validation Gates
2
+
3
+ Use these gates before producing `align-structure-decision`. The CLI may reject malformed gates or downgrade weak `domain` / `action` proposals to `entity`.
4
+
5
+ ## Action Gate
6
+
7
+ Use `node_type: action` only when the candidate is a user story, runbook, how-to, roadmap, or other planned procedure. Fill both `action_probe` and `action_gate`.
8
+
9
+ `action_probe` and `action_gate` use the same five booleans:
10
+
11
+ | Field | Meaning | Evidence rule |
12
+ |---|---|---|
13
+ | `has_steps_or_phases` | The source contains explicit steps, phases, ordered work, or a procedural sequence. | Hard requirement. Must be directly supported by block evidence. |
14
+ | `has_actor_or_role` | A user, system, operator, service, or role performs the work. | May be inferred, but inference must be recorded. |
15
+ | `has_outcome_or_goal` | The action has a target result, acceptance condition, or operational goal. | May be inferred, but inference must be recorded. |
16
+ | `is_repeatable_or_planned` | The work is repeatable, scheduled, policy-like, or intentionally planned. | May be inferred, but inference must be recorded. |
17
+ | `queries_answerable_with_refs` | The resulting Node can answer how/when/who/what-to-do questions from cited blocks. | May be inferred, but inference must be recorded. |
18
+
19
+ `has_steps_or_phases: false` means do not emit an action Node. If the subject has a stable named definition that people can reference, use `entity` with tag `term`. Routing schemes, durable rules, and data-shape descriptions belong inside the matching domain/entity/action Sections (`spec`, `principle`, `decision`, `comparison`, `warning`, and related mounted kinds).
20
+
21
+ ## Term Entity Boundary
22
+
23
+ Use `entity` + `tags: [term]` only for a stable named definition. The core content should fit a 1-3 sentence glossary entry answering "what is X?" without if/else branches, steps, trade-offs, or "we choose" reasoning.
24
+
25
+ Decision tree:
26
+
27
+ 1. If the subject is a procedure, ordered work, runbook, how-to, or repeated planned operation, use an `action` Node.
28
+ 2. If the subject is a concrete product, service, system, app, library, module, CLI, or code symbol, use the matching concrete `entity` tag.
29
+ 3. If the content is a rule, risk, design choice, comparison, data shape, durable behavior, or operational detail, do not create a Node for it; place it as a Section under the owning Node.
30
+ 4. If the subject is a stable named definition that can be written as a short glossary entry and referenced across documents, use `entity` + `tags: [term]`.
31
+ 5. If explaining the subject requires alternatives, steps, condition branches, trade-offs, or "we choose" reasoning, it is not `term`; route it to an owning Section or an `action` Node.
32
+
33
+ Term boundary TTL: re-run this decision tree before every candidate-ops batch and again immediately before `align-structure-decision`. If you have processed more than one batch or about ten candidates since the last check, treat the previous check as expired.
34
+
35
+ Good `term` examples:
36
+
37
+ - `Data Region`: a named deployment or compliance scope used across documents.
38
+ - `IDC` / `Region`: named scope terms with stable definitions.
39
+ - `request-id`: a named identifier with a stable meaning.
40
+ - `target-region`: a named cookie, header, or routing key.
41
+ - `Dynamic Site Acceleration`: a named traffic acceleration category.
42
+
43
+ Not `term`:
44
+
45
+ - cookie-plus-IP routing: a conditional routing scheme; put it in the owning service/system as `spec`.
46
+ - shared load-balancer rollout: a design choice with constraints; use `spec`, `principle`, or `decision` under the owning entity.
47
+ - six-dimensional resilience matrix: a structured comparison/framework; use a domain/entity `comparison` or `spec` Section.
48
+ - CDN scheduling strategy: service behavior and design choices; model the CDN or traffic service as `service` and place the strategy in Sections.
49
+
50
+ ## Inference Sources
51
+
52
+ `action_gate.inference_sources` is required and must be a structured object with four keys:
53
+
54
+ ```yaml
55
+ inference_sources:
56
+ actor:
57
+ source_type: explicit-block
58
+ evidence_blocks: [b0001]
59
+ rationale: "The block names the operator role."
60
+ outcome_or_goal:
61
+ source_type: inferred-from-block
62
+ evidence_blocks: [b0001]
63
+ rationale: "The block describes recovery as the expected result."
64
+ repeatability_or_plan:
65
+ source_type: heading-and-block
66
+ evidence_blocks: [b0001]
67
+ rationale: "The runbook heading and ordered list indicate planned reuse."
68
+ answerability:
69
+ source_type: explicit-block
70
+ evidence_blocks: [b0001]
71
+ rationale: "The steps answer how the operation is performed."
72
+ ```
73
+
74
+ Allowed `source_type` values:
75
+
76
+ | Value | Use when |
77
+ |---|---|
78
+ | `explicit-block` | The evidence block directly states the signal. |
79
+ | `heading-and-block` | The heading plus block text together support the signal. |
80
+ | `ref-node` | An existing or same-decision Node reference supplies the signal. Include `ref_nodes`. |
81
+ | `inferred-from-block` | The signal is inferred from block content. Keep the rationale short and concrete. |
82
+
83
+ Each source must include `rationale` and at least one of `evidence_blocks[]` or `ref_nodes[]`. Do not write free-text-only inference explanations.
84
+
85
+ ## Domain Gate
86
+
87
+ Use `node_type: domain` only for a scope that groups multiple child Nodes. Fill:
88
+
89
+ | Field | Meaning |
90
+ |---|---|
91
+ | `scope_blocks[]` | Blocks that describe the scope boundary or grouping. |
92
+ | `child_refs[]` | Candidate ids, local refs, or final slugs for children in the scope. |
93
+ | `grouping_reason` | Why these children belong together under this domain. |
94
+
95
+ If a domain has no resolvable child refs, no clear grouping reason, or only one same-file child without a broader scope, emit an `entity` instead. Weak domain gates are downgraded by finalize and recorded in `audit_warnings`.
@@ -0,0 +1,127 @@
1
+ ---
2
+ name: skill-compile-close
3
+ description: >
4
+ Packaged skill invoked by `/context:compile`; not a user slash command. Runs after every draft
5
+ iteration. Triggers `context compile --close`, which in one invocation
6
+ refreshes locator-only evidence, canonicalizes source refs, compacts and verifies the final workspace,
7
+ rebuilds the knowledge index, appends a changelog
8
+ entry, rebuilds section fingerprints + incremental cache, and
9
+ archives compile scratch files. Agent intervention is
10
+ limited to interpreting the CLI's output and routing any verify
11
+ error back to its upstream command (`/context:compile` for Section
12
+ issues, `/context:align` for structural issues, `/context:drop`
13
+ for dropped-source references). The skill never hand-edits rendered knowledge.
14
+ Activates once all draft actions are applied and before user-visible
15
+ success is declared.
16
+ tools:
17
+ - Bash
18
+ ---
19
+
20
+ # skill-compile-close — global verify + index + changelog
21
+
22
+ Close a compile run. The CLI does the work; the skill reads the
23
+ CLI's output and routes any failure back to the correct upstream
24
+ command. It does not hand-edit rendered knowledge.
25
+
26
+ ## TL;DR — Non-negotiables
27
+
28
+ - CLI-driven. `context compile --close` performs deterministic close writes first (locator refresh, source_ref canonicalization, compact, index/changelog), verifies the final workspace, then rebuilds section fingerprints + incremental cache and archives compile scratch files. Use the command's stdout + exit code; that's the close's full output.
29
+ - **Agent NEVER edits rendered knowledge from the close stage.** The CLI is the sole writer for articles, the index, and the changelog. If verify reports an error here, route it back, not around:
30
+ - Content / Section issues (`invalid-section-mount`, `body-ad-hoc-heading`, `dangling-source-alias`) → user re-runs `/context:compile` (draft loop fixes its own Section actions; the close stage does not patch)
31
+ - Structural issues (`contains-cycle`, `edge-dangling-node`, `duplicate-slug`, `invalid-node-type`, `domain-same-file-child`) → user runs `/context:align` to revise the plan
32
+ - Source issues (`dropped-source-reference`) → user runs `/context:drop <id>` to complete the drop
33
+ - Exit 0 → summarise node/section totals, verify, `recompiled`, `locator_updates`, `rebuilt`, fingerprint rebuild count, and archive status / archived file count when printed; then stop.
34
+ - Exit 2 → report the full issue list verbatim + point at the right re-entry command above. Do not hand-open the affected rendered article.
35
+ - If exit 2 includes `coverage-high-signal-unresolved`, follow the CLI hint. Read the node-scoped payload with `context workflow show --payload coverage-candidates --scope <node-run-scope> --view coverage` or inspect `context schema coverage-disposition`; do not guess workspace-scope payload paths.
36
+ - Never re-run `context compile --draft` from close to paper over verify failures. Draft failures belong in the draft loop.
37
+ - Do not use Python, Node.js, shell scripts, `ls`, `find`, `rg`, `cat`, or similar ad-hoc commands to inspect `WORKSPACE_DIR`, `.context`, knowledge files, or `/tmp` workflow artifacts.
38
+ - Derivable files self-heal: missing `_index.md` or `changelog.md` is rebuilt inside `compile --close` before the append, locator-only source moves are refreshed, non-canonical but hash-valid `source_ref` locators are canonicalized, and high-signal coverage candidates already backed by active Sections are marked covered. No pre-check needed.
39
+ - LLM-assisted repair (`--fix-with-llm`) is not available in the current release.
40
+ - Output language: summary prose matches the user's language; CLI output, issue codes, file paths stay as printed.
41
+ - Successful close archives CLI scratch artifacts through the output lifecycle and rebuilds the user-level incremental cache. Current align state is internal CLI state, not a file protocol. The CLI owns this lifecycle — the agent must not move, delete, or archive workspace output files by hand.
42
+ - Semantic decisions are applied and recorded before close. Compile-close does not judge or rewrite semantic decisions; it only verifies the already-applied workspace and rebuilds derived indexes.
43
+
44
+ <reference>
45
+
46
+ ## Stages inside `context compile --close`
47
+
48
+ Close is one in-process command with one exit code:
49
+
50
+ 1. **Coverage guard with self-heal** — drops stale candidates and treats high-signal candidates already backed by active Sections as covered.
51
+ 2. **Locator refresh** — if evidence moved but block hashes are unchanged, updates only section locators.
52
+ 3. **Source ref canonicalization** — if a Section `source_ref` resolves to the same raw evidence block but has a stale anchor/range rendering, rewrites it to the canonical locator.
53
+ 4. **Workspace compact** — re-renders every knowledge article canonically (Section order, frontmatter field order, `## Contains` list ordering, heading depth).
54
+ 5. **Rebuild knowledge index** — regenerates the index from the current workspace state; previous content overwritten.
55
+ 6. **Append changelog** — appends one compile list item to the changelog; existing entries preserved.
56
+ 7. **Workspace verify** — runs the full rule set against the final close output. Any error flips exit to 2 and close rolls back its writes.
57
+ 8. **Rebuild incremental cache** — rebuilds section fingerprints and cache indexes from workspace truth sources.
58
+ 9. **Archive scratch files** — moves CLI-owned context/draft/prepare/review scratch payloads into the output archive lifecycle.
59
+
60
+ ## Outcome routing
61
+
62
+ | Outcome | Agent action |
63
+ |---|---|
64
+ | Exit 0, 0 issues | Summarise those counts in the user's language: Nodes touched; Sections added / updated / superseded / deprecated / skipped; `recompiled`; `locator_updates`; `rebuilt`; verify green. Stop. |
65
+ | Exit 0, warnings only | Summarise + list warnings verbatim. Point at `/context:status` or `context cache status` when the warning is incremental-cache-related. Stop. |
66
+ | Exit 2, Section / content issue | Surface the full issue list; point the user at re-running `/context:compile` (the draft loop owns Section writes). Do NOT Edit the affected rendered article. |
67
+ | Exit 2, structural issue (cycle, duplicate slug, `invalid-node-type`, `domain-same-file-child`) | Surface the full issue list; point the user at `/context:align` to revise structure. Do not re-run compile. |
68
+ | Exit 2, `dropped-source-reference` | Surface the source-id; point the user at `/context:drop <id>` to complete the drop cleanup. |
69
+ | Exit 2, `coverage-high-signal-unresolved` | Read the node-scoped coverage payload named in the CLI hint. If the candidate is intentionally covered by sibling Nodes or should not be written for this Node, submit `action: skip` with a reason; for skip only, `source_refs` may be omitted to dispose the whole candidate. |
70
+
71
+ The close stage never edits rendered knowledge on the agent side. Every verify error routes back to the correct upstream command (compile / align / drop), never sideways into a hand Edit. Use the CLI issue code and hint printed by `context compile --close` for the error→command mapping.
72
+
73
+ ## Changelog entry shape
74
+
75
+ `context compile --close` appends one markdown list item per run to
76
+ the changelog with aggregate counts — not a multi-line
77
+ block:
78
+
79
+ ```
80
+ - [compile] nodes=N sections=M recompiled=R locator_updates=L @ <ISO timestamp>
81
+ ```
82
+
83
+ `[drop]` lines from `/context:drop` follow the same single-line list-
84
+ item convention (see the drop skill for the exact shape).
85
+
86
+ </reference>
87
+
88
+ <procedures>
89
+
90
+ ### Step 1 — Invoke close
91
+
92
+ Run `context compile --close`. The caller (typically `/context:compile`) may have already invoked it; check for existing output before re-running.
93
+
94
+ ### Step 2 — Interpret
95
+
96
+ Use stdout + stderr. The exit code selects the path via [Outcome routing](#outcome-routing).
97
+
98
+ ### Step 3 — Route errors to the correct upstream command
99
+
100
+ For each error in the CLI's report, classify via [Outcome routing](#outcome-routing) and name the re-entry command in your report. Do NOT hand-edit rendered knowledge — that violates the CLI-sole-writer principle and masks the real upstream fix. Specifically:
101
+
102
+ - Section / content issue → user re-runs `/context:compile` (draft loop produces new Section actions; the CLI re-writes).
103
+ - Structural issue → user runs `/context:align` (revise the plan; re-compile afterwards).
104
+ - `dropped-source-reference` → user runs `/context:drop <id>` to finish drop cleanup.
105
+
106
+ One pass. If the CLI reports multiple errors, list them all and let the user choose the order; do not loop the close stage itself.
107
+
108
+ ### Step 4 — Report
109
+
110
+ Summarise in the user's language:
111
+
112
+ - Nodes touched and counts per op (add / update / supersede / deprecate / skip / locator-only).
113
+ - Knowledge index rebuilt / updated; changelog appended at `<timestamp>`.
114
+ - Incremental close counts printed by the CLI: `recompiled`, `locator_updates`, `canonical_source_ref_updates`, `rebuilt`, and section fingerprint rebuild count.
115
+ - Verify result: green / `<n>` warnings / `<n>` errors (issue codes verbatim).
116
+
117
+ Stop. Do not auto-invoke follow-on commands.
118
+
119
+ ### Step 5 — Self-verify
120
+
121
+ - [ ] `context compile --close` ran exactly once per close call — if not, **Step 1**.
122
+ - [ ] If exit 2, every error is surfaced to the user with a re-entry command (compile / align / drop); no silent ignores — **Step 3**.
123
+ - [ ] No agent-hand edits to rendered knowledge — if any, revert; the close stage is read-only for knowledge content.
124
+ - [ ] No Read / Glob / Grep / Write was used against `WORKSPACE_DIR`; CLI-owned output archival is allowed.
125
+ - [ ] No ad-hoc script or shell file traversal was used against `WORKSPACE_DIR`, `.context`, or `/tmp` workflow artifacts.
126
+
127
+ </procedures>