@uniqbit/mate-core 0.18.3-canary.0 → 0.18.3

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 (96) hide show
  1. package/claude-plugin/hooks/hooks.json +10 -1
  2. package/claude-plugin/hooks/session-banner.mjs +4 -3
  3. package/claude-plugin/hooks/session-prepare.mjs +9 -0
  4. package/opencode-plugin/src/companion.ts +47 -12
  5. package/opencode-plugin/src/server.ts +39 -4
  6. package/package.json +3 -3
  7. package/src/cli/commands/artifact/finish/openspec.ts +1 -1
  8. package/src/cli/commands/artifact/pending/discovery.ts +60 -21
  9. package/src/cli/commands/companion/link.ts +16 -11
  10. package/src/cli/commands/companion/list.ts +4 -5
  11. package/src/cli/commands/companion/open.ts +4 -5
  12. package/src/cli/commands/companion/tui.ts +1 -1
  13. package/src/cli/commands/doctor.ts +1 -1
  14. package/src/cli/commands/report/renderer.ts +9 -19
  15. package/src/cli/commands/session/prepare.ts +119 -0
  16. package/src/cli/commands/shared/companion-selection.ts +2 -2
  17. package/src/cli/commands/studio/reports.ts +0 -1
  18. package/src/cli/commands/studio/server.ts +6 -2
  19. package/src/cli/commands/unwrap.ts +28 -3
  20. package/src/cli/commands/wrap.ts +53 -59
  21. package/src/cli/companion-selector.tsx +1 -1
  22. package/src/cli/main.ts +17 -0
  23. package/src/cli/usage.ts +3 -1
  24. package/src/hooks/session-banner.ts +19 -10
  25. package/src/hooks/session-prepare.ts +101 -0
  26. package/src/lib/fs-utils.ts +13 -0
  27. package/src/lib/orchestrator/adapters/base.ts +43 -8
  28. package/src/lib/orchestrator/adapters/claude.ts +130 -29
  29. package/src/lib/orchestrator/adapters/opencode.ts +17 -19
  30. package/src/lib/orchestrator/companion-git-sync.ts +28 -1
  31. package/src/lib/orchestrator/companion-hub.ts +2 -1
  32. package/src/lib/orchestrator/config-store.ts +56 -2
  33. package/src/lib/orchestrator/framework-context.ts +5 -29
  34. package/src/lib/orchestrator/launcher.ts +36 -171
  35. package/src/lib/orchestrator/projection-claude-entry.ts +17 -6
  36. package/src/lib/orchestrator/projection-claude-skills.ts +54 -22
  37. package/src/lib/orchestrator/projection-entries.ts +78 -11
  38. package/src/lib/orchestrator/projection-opencode-copies.ts +230 -0
  39. package/src/lib/orchestrator/projection-record.ts +7 -1
  40. package/src/lib/orchestrator/projection-runtime-documents.ts +83 -130
  41. package/src/lib/orchestrator/projection-types.ts +38 -33
  42. package/src/lib/orchestrator/repository-link.ts +473 -0
  43. package/src/lib/orchestrator/root-context.ts +6 -2
  44. package/src/lib/orchestrator/session-prepare.ts +425 -0
  45. package/src/lib/orchestrator/setup-compatibilities.ts +1 -1
  46. package/src/lib/orchestrator/setup-preflight.ts +3 -1
  47. package/src/lib/orchestrator/types.ts +4 -1
  48. package/src/lib/orchestrator/working-repo-projection.ts +71 -159
  49. package/src/lib/orchestrator/workspace-inventory.ts +2 -2
  50. package/src/lib/orchestrator/wrap-pass.ts +131 -0
  51. package/src/lib/runtime-directory-refresh.ts +186 -0
  52. package/src/lib/update-checker.ts +6 -0
  53. package/src/opencode/companion-hooks.ts +24 -132
  54. package/src/opencode/companion-policy.ts +26 -10
  55. package/src/opencode/index.ts +1 -7
  56. package/src/opencode/session-notes.ts +76 -0
  57. package/src/opencode/session-prepare.ts +139 -0
  58. package/src/opencode/tui.tsx +56 -9
  59. package/src/runtime/claude-delivery-plan.ts +73 -0
  60. package/src/runtime/claude-hook-group.ts +21 -0
  61. package/src/runtime/companion-lock.ts +121 -0
  62. package/src/runtime/companion-sync.ts +66 -9
  63. package/src/runtime/runtime-directory.ts +43 -0
  64. package/src/runtime/runtime-document-manifest.ts +335 -0
  65. package/src/runtime/session-prepare-runner.ts +148 -0
  66. package/src/runtime/wrap-state.ts +90 -0
  67. package/src/runtime/write-atomic.ts +27 -0
  68. package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +2 -1
  69. package/src/templates/capabilities/openspec-cap/mate-v1/schema.yaml +2 -1
  70. package/src/templates/capabilities/openspec-cap/openspec-conventions.yaml +5 -0
  71. package/src/templates/capabilities/react-doctor/mate-react-doctor/SKILL.md +84 -0
  72. package/src/templates/capabilities/react-doctor/{skill → mate-react-doctor}/references/explain.md +18 -15
  73. package/src/templates/mate-skills/agents/mate-openspec-backfill/SKILL.md +45 -29
  74. package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +1 -1
  75. package/src/templates/mate-skills/claude/mate-openspec-backfill/SKILL.md +45 -29
  76. package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +1 -1
  77. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +850 -499
  78. package/src/tools/setup/capabilities/react-doctor.ts +34 -50
  79. package/src/tools/setup/dynamic-plugins/hydrate.ts +1 -1
  80. package/src/tools/setup/engine.ts +15 -4
  81. package/src/tools/setup/mate.ts +1 -1
  82. package/src/tools/setup/providers/claude-format.ts +11 -18
  83. package/src/tools/setup/providers/claude-plugin-hooks.ts +61 -24
  84. package/src/tools/setup/providers/claude.ts +23 -6
  85. package/src/tools/setup/runtime-documents.ts +152 -32
  86. package/src/tools/setup/working-repo-local-state.ts +82 -13
  87. package/src/tools/setup.ts +2 -2
  88. package/src/lib/orchestrator/companion-registry-reader.ts +0 -37
  89. package/src/lib/orchestrator/companion-resolver.ts +0 -179
  90. package/src/lib/orchestrator/companion-store.ts +0 -94
  91. package/src/lib/orchestrator/repo-local-registry.ts +0 -143
  92. package/src/templates/capabilities/react-doctor/claude/hooks/react-doctor.sh +0 -144
  93. package/src/templates/capabilities/react-doctor/skill/SKILL.md +0 -51
  94. package/src/templates/report-assets/README.md +0 -32
  95. package/src/templates/report-assets/mermaid.LICENSE +0 -21
  96. package/src/templates/report-assets/mermaid.min.js +0 -4376
@@ -1,26 +1,26 @@
1
1
  ---
2
2
  name: mate-openspec-backfill
3
- description: Reverse-engineer an OpenSpec spec for one existing feature and emit a ready-to-finish backfill change. Use when the user wants to backfill, document, or spec existing or legacy behavior that has no spec yet.
4
- allowed-tools: Bash(openspec:*), Bash(mate:*)
3
+ description: Reverse-engineer an OpenSpec spec for one existing feature and write it directly to the canonical spec, ready to publish. Use when the user wants to backfill, document, or spec existing or legacy behavior that has no spec yet.
4
+ allowed-tools: Bash(openspec:*), Bash(mate:*), Bash(git remote:*), Bash(git diff:*)
5
5
  license: MIT
6
6
  compatibility: Requires the mate CLI and the openspec capability enabled.
7
7
  metadata:
8
8
  author: mate
9
- version: "1.0"
9
+ version: "2.0"
10
10
  ---
11
11
 
12
12
  # Mate OpenSpec Backfill
13
13
 
14
- Create a spec for one feature that already exists in the working repository. The run ends with a standard ready-to-finish change — it never edits main specs and never finishes.
14
+ Specify one feature that already exists in the working repository. A backfill records behavior that already shipped, so the run writes the canonical spec `openspec/specs/<capability>/spec.md` directly and leaves it uncommitted. It never creates a change and never publishes; publication happens afterwards through `mate-artifact-publish`.
15
15
 
16
16
  ## Scope rules
17
17
 
18
18
  - **One named feature per run.** Refuse Area-wide or repository-wide sweeps; ask the user to name a single feature and run the skill once per feature.
19
- - **Interactive by design.** Every ambiguity and every suspected bug becomes a user question. Do not run this skill unattended.
19
+ - **Interactive by design.** Every ambiguity and every suspected bug becomes a user question, and nothing is written before the user approves the review table. Do not run this skill unattended.
20
20
 
21
21
  ## Steps
22
22
 
23
- 1. **Scope.** Map the named feature to code: entry points, callees, tests. Use whatever exploration tooling this project has enabled (code-graph or index tools when present, otherwise search and targeted reading) — assume no specific capability is installed. Then check `openspec/specs/` for an existing capability covering this domain — prefer extending it (`MODIFIED`/`ADDED` deltas) over minting a new capability id.
23
+ 1. **Scope.** Map the named feature to code: entry points, callees, tests. Use whatever exploration tooling this project has enabled (code-graph or index tools when present, otherwise search and targeted reading) — assume no specific capability is installed. Then check `openspec/specs/` for an existing capability covering this domain — prefer extending it in place over minting a new capability id.
24
24
 
25
25
  2. **Sweep.** Extract candidate behaviors and tag each finding:
26
26
  - `[test-backed]` — an existing test verifies it (strongest; scenarios translate almost directly from tests)
@@ -30,38 +30,54 @@ Create a spec for one feature that already exists in the working repository. The
30
30
  Every candidate requirement needs at least one citation: a test name or `file:line`. Docs and comments corroborate but never stand alone. `[inferred]` findings are not requirements — they become questions for step 3.
31
31
 
32
32
  3. **Ask.** Batch the open questions to the user:
33
- - Behavior that looks unintended → the user rules **spec the actual behavior** or **spec the intent** (with a follow-up fix change). Suspected bugs never silently become requirements.
34
- - `[inferred]` findings → confirm, demote to out-of-scope, or convert to a question the emitted proposal records as open.
33
+ - Behavior that looks unintended → the user rules **spec the actual behavior** or **spec the intent** (and the user may open a separate fix change). Suspected bugs never silently become requirements.
34
+ - `[inferred]` findings → confirm, demote to out-of-scope, or drop.
35
35
 
36
- 4. **Emit.** Create the change and build its artifacts in dependency order:
36
+ 4. **Review.** Before writing any file, present every drafted requirement in one table and wait for the user's approval:
37
+
38
+ | Requirement | Evidence | Citation |
39
+ | ------------------------------- | --------------- | -------------------------------- |
40
+ | Propagates the child exit code | `[test-backed]` | `launch.test.ts` › "exits with…" |
41
+ | Refuses an unknown framework id | `[code-only]` | `src/launch.ts:142` |
42
+
43
+ Write only the requirements the user approves, worded as approved. A rejected requirement is not written. This table is the only place citations and evidence tags appear — they never go into the spec.
44
+
45
+ 5. **Learn the spec format.** Never assume a spec format. Read it from the schema active in this OpenSpec root, so the run follows whichever workflow the project uses:
37
46
 
38
47
  ```bash
39
- openspec new change "backfill-spec-<capability>"
40
- openspec status --change "backfill-spec-<capability>" --json
41
- openspec instructions <artifact-id> --change "backfill-spec-<capability>" --json
48
+ openspec schema which <schema-name> --json
42
49
  ```
43
50
 
44
- The artifact set comes from the active schema (`schemaName` in the status JSON) — never assume a fixed artifact list. Follow each artifact's returned instructions and template, and state the active schema in the proposal so reviewers know which workflow produced the change. Map the backfill roles onto whatever artifacts the schema defines:
51
+ - The active schema name is the `schema:` key in `openspec/config.yaml`. When the file or key is absent, it is OpenSpec's default, `spec-driven`.
52
+ - In the returned `path`, read `schema.yaml` and find the artifact that generates the specs (`generates: specs/**/*.md`). Read its `instruction`, its `template` under `templates/`, and every reference file the instruction tells you to read (for example `openspec/mate-conventions.yaml`).
53
+ - Those sources usually describe the **delta** a change writes. You write the **canonical** spec that archive would produce from it, so apply the schema's own delta-to-canonical rules: requirement blocks go under `## Requirements` instead of `## ADDED Requirements`, and frontmatter, per-requirement markers, and `## Purpose` take the canonical shape the schema or its references define. Leave out delta-only elements such as change backlinks and change or delta tags.
54
+ - When a spec already exists under `openspec/specs/`, use it as a concrete example of the canonical shape, but follow the schema where the two disagree.
55
+ - Derive any repository identity the format needs from the Git remote (`git remote get-url origin`), and any Area or scope value from the schema's rules. Never invent a format element the schema does not define.
56
+
57
+ 6. **Write.** Write the approved requirements to `openspec/specs/<capability>/spec.md` in the format from step 5.
58
+
59
+ **New capability.** Create the file with the schema's canonical frontmatter (when it defines one), a `## Purpose` section of one or two sentences, and a `## Requirements` section holding the approved requirements with their scenarios.
45
60
 
46
- | Backfill role | Typical artifact (mate-v1 example) |
47
- | ---------------------------------------------------------------------------------------------- | ---------------------------------- |
48
- | Scope decisions and rulings from step 3 | explore-brief.md |
49
- | "Documents existing behavior, no code changes" + open questions | proposal.md |
50
- | `ADDED`/`MODIFIED` requirements, behavior only, one citation each | specs/ |
51
- | As-built evidence dossier: entry points, test inventory, `file:line` citations per requirement | design.md |
52
- | Verification checklist: one task per requirement, "confirm behavior at <citation>" | tasks.md |
61
+ **Existing capability.** Edit its `spec.md` in place: append new requirements under `## Requirements` and rewrite only the requirements the user's rulings change. Preserve every other requirement, the frontmatter, and the Purpose exactly.
53
62
 
54
- The verification task artifact MUST open with this rule, verbatim, so the applying agent sees it without knowing this skill: "These are verification tasks for a docs-only backfill change. If a requirement fails verification, update the delta spec (reword, drop, or re-cite the requirement) — never modify code in this change. A real bug found here becomes a separate fix change."
63
+ In both cases every requirement you write carries each per-requirement marker the schema requires (for example an `**Area:**` marker whose value appears in the spec's frontmatter). Requirements state observable contracts, never implementation detail ("propagates the child exit code", not "uses spawnSync"). The spec contains no citations, no `file:line` references, and no evidence tags.
64
+
65
+ 7. **Validate.** Run:
66
+
67
+ ```bash
68
+ openspec validate <capability> --type spec
69
+ ```
55
70
 
56
- Requirements state observable contracts, never implementation detail ("propagates the child exit code", not "uses spawnSync").
71
+ Fix every reported error and re-validate until it passes. Do not hand off a spec that fails validation.
57
72
 
58
- 5. **Stop.** Report the change as ready-to-finish and hand off:
59
- - Verify: `openspec-apply-change` works through tasks.md, checking each requirement against the code.
60
- - Publish: `mate-artifact-publish` applies the deltas to main specs and anchors the change.
73
+ 8. **Hand off.** Report the written path and show the uncommitted diff (`git diff -- openspec/specs/<capability>/`, or the file itself when it is new). Point the user to `mate-artifact-publish`: the spec appears there under **Drifted specs** and can be published on its own or with the rest.
61
74
 
62
75
  ## Guardrails
63
76
 
64
- - Never write files under `openspec/specs/` — main specs change only through finished changes.
65
- - Never invoke any finish flow (`mate artifact publish`, `openspec archive`); stop at ready-to-finish.
66
- - Never emit a requirement without a citation, and never spec a suspected bug without the user's ruling.
67
- - Keep capability ids opaque kebab-case; extend existing capabilities before creating new ones.
77
+ - Never create an OpenSpec change, change artifacts, or verification tasks, and never archive.
78
+ - Never commit, tag, push, or publish — never run `mate artifact publish`. Publication belongs to `mate-artifact-publish`.
79
+ - Never write any file before the user approves the review table.
80
+ - Never write a requirement without a citation in the review table, and never spec a suspected bug without the user's ruling.
81
+ - Never write citations or evidence tags into the canonical spec.
82
+ - Never hard-code a spec format: take it from the active schema on every run.
83
+ - Keep capability ids opaque kebab-case; extend existing capabilities in place before creating new ones, and never drop or reword requirements outside the named feature.
@@ -137,7 +137,7 @@ If the document fails contract validation, report the diagnostic and correct the
137
137
  - Use Mermaid whenever the user asks for a diagram or the subject has meaningful control flow, sequencing, lifecycle, or relationships. A `text` payload is a deliberate fallback, not the default for runtime flows.
138
138
  - Pick the diagram type that matches the question: `classDiagram` for structure, `sequenceDiagram` for interaction between components, `stateDiagram-v2` for lifecycles, `flowchart TD` for control flow and call trees.
139
139
  - Keep labels short enough to read at report width. A label that needs a sentence belongs in the neighbouring `text` section.
140
- - Do not use ELK-only layouts or math labels. The report inlines the self-contained mermaid bundle, which may not carry those chunks.
140
+ - Do not use ELK-only layouts or math labels. The report loads the single-file mermaid build from a CDN, which does not carry those chunks.
141
141
  - Pair each Mermaid visual with a short neighbouring `text` section that calls out the ownership boundary or invariant the reader should notice.
142
142
  - Prefer the `text` payload for pseudocode, shallow file trees, or cases where a picture would genuinely obscure the point.
143
143