@uniqbit/mate-core 0.18.4 → 0.20.0
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.
- package/claude-capability-plugins/companion-mentions/.claude-plugin/marketplace.json +14 -0
- package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +8 -0
- package/claude-capability-plugins/companion-mentions/hooks/companion.ts +457 -0
- package/claude-capability-plugins/companion-mentions/hooks/hooks.json +1 -0
- package/claude-capability-plugins/companion-mentions/hooks/register.ts +403 -0
- package/claude-plugin/hooks/companion-instructions.mjs +9 -0
- package/claude-plugin/hooks/hooks.json +41 -2
- package/claude-plugin/hooks/session-attention.mjs +10 -0
- package/claude-plugin/hooks/session-end.mjs +9 -0
- package/claude-plugin/hooks/session-guidance.mjs +1 -1
- package/claude-plugin/hooks/tokensave-route.mjs +52 -0
- package/opencode-plugin/src/add-dir.ts +76 -10
- package/opencode-plugin/src/companion.ts +1 -8
- package/opencode-plugin/src/server.ts +19 -17
- package/opencode-plugin/src/tui.tsx +3 -1
- package/opencode-plugin/tui.tsx +4 -1
- package/package.json +52 -15
- package/src/brand/art.generated.ts +69 -0
- package/src/brand/index.ts +12 -0
- package/src/brand/palette.ts +19 -0
- package/src/brand/svg.generated.ts +8 -0
- package/src/brand/terminal.ts +88 -0
- package/src/brand/types.ts +33 -0
- package/src/cli/commands/artifact/apply-context.ts +275 -0
- package/src/cli/commands/artifact/artifact.ts +12 -0
- package/src/cli/commands/artifact/delivery/archive.ts +125 -0
- package/src/cli/commands/artifact/delivery/branch-flags.ts +55 -0
- package/src/cli/commands/artifact/delivery/environment.ts +127 -0
- package/src/cli/commands/artifact/delivery/link.ts +191 -0
- package/src/cli/commands/artifact/delivery/output.ts +97 -0
- package/src/cli/commands/artifact/finish/command.ts +83 -8
- package/src/cli/commands/artifact/finish/engine.ts +91 -14
- package/src/cli/commands/artifact/finish/finisher.ts +10 -0
- package/src/cli/commands/artifact/finish/git.ts +132 -19
- package/src/cli/commands/artifact/finish/openspec.ts +203 -129
- package/src/cli/commands/artifact/finish/secret-scan.ts +43 -0
- package/src/cli/commands/artifact/finish/worktree-cleanup.ts +92 -0
- package/src/cli/commands/artifact/pending/command.ts +31 -3
- package/src/cli/commands/artifact/pending/discovery.ts +21 -57
- package/src/cli/commands/cap/graphify.ts +52 -3
- package/src/cli/commands/cap/index-cmd.ts +71 -15
- package/src/cli/commands/cap/openspec.ts +13 -25
- package/src/cli/commands/cap/tokensave.ts +7 -5
- package/src/cli/commands/companion/companion.ts +1 -1
- package/src/cli/commands/companion/link.ts +50 -5
- package/src/cli/commands/companion/open.ts +101 -51
- package/src/cli/commands/companion/sync.ts +10 -0
- package/src/cli/commands/companion/tui.ts +17 -7
- package/src/cli/commands/companion/update.ts +143 -48
- package/src/cli/commands/doctor.ts +396 -80
- package/src/cli/commands/factory/factory.ts +301 -0
- package/src/cli/commands/install.ts +133 -17
- package/src/cli/commands/launch/shared.ts +16 -11
- package/src/cli/commands/plugin/install.ts +9 -4
- package/src/cli/commands/plugin/plugin.ts +3 -2
- package/src/cli/commands/report/adapter.ts +11 -2
- package/src/cli/commands/report/contract.ts +21 -0
- package/src/cli/commands/report/highlight.ts +34 -4
- package/src/cli/commands/report/index.ts +20 -1
- package/src/cli/commands/report/markdown.ts +110 -0
- package/src/cli/commands/report/palette.ts +118 -0
- package/src/cli/commands/report/renderer.ts +456 -153
- package/src/cli/commands/report/types.ts +16 -0
- package/src/cli/commands/session/context.ts +102 -0
- package/src/cli/commands/session/prepare.ts +32 -4
- package/src/cli/commands/session/registry.ts +90 -0
- package/src/cli/commands/setup.ts +50 -24
- package/src/cli/commands/studio/companion-removal.ts +79 -0
- package/src/cli/commands/studio/factory-credential.ts +49 -0
- package/src/cli/commands/studio/index.ts +29 -2
- package/src/cli/commands/studio/mate-inventory.ts +1 -1
- package/src/cli/commands/studio/openspec-cli.ts +10 -58
- package/src/cli/commands/studio/payload.ts +260 -15
- package/src/cli/commands/studio/routes.ts +41 -6
- package/src/cli/commands/studio/selection.ts +161 -17
- package/src/cli/commands/studio/server.ts +429 -326
- package/src/cli/commands/studio/services.ts +80 -0
- package/src/cli/commands/studio/skill-files.ts +133 -0
- package/src/cli/commands/studio/studio-app.ts +67 -0
- package/src/cli/commands/studio/terminal-assets.ts +21 -33
- package/src/cli/commands/studio/terminal-launch.ts +7 -16
- package/src/cli/commands/studio/terminal.ts +85 -15
- package/src/cli/commands/studio/vault.ts +218 -44
- package/src/cli/commands/studio/views/model.ts +13 -0
- package/src/cli/commands/studio/views/vault/markdown-tree.ts +518 -0
- package/src/cli/commands/studio/views/vault/view.ts +185 -0
- package/src/cli/commands/studio/workset-session.ts +131 -0
- package/src/cli/commands/unwrap.ts +16 -0
- package/src/cli/commands/update.ts +53 -9
- package/src/cli/commands/vscode/setup.ts +155 -0
- package/src/cli/commands/vscode/vsix.ts +73 -0
- package/src/cli/commands/working/cleanup.ts +44 -11
- package/src/cli/commands/working/link.ts +76 -0
- package/src/cli/commands/working/working.ts +10 -0
- package/src/cli/commands/working/worktree.ts +406 -0
- package/src/cli/commands/wrap.ts +39 -46
- package/src/cli/companion-link-wizard.tsx +2 -0
- package/src/cli/companion-selector.tsx +2 -0
- package/src/cli/confirm.ts +2 -0
- package/src/cli/install-plan.tsx +127 -160
- package/src/cli/launch-selector.tsx +2 -0
- package/src/cli/main.ts +31 -3
- package/src/cli/parse-flags.ts +32 -6
- package/src/cli/repo-list-table.tsx +2 -0
- package/src/cli/setup-selector.tsx +86 -151
- package/src/cli/usage.ts +21 -3
- package/src/create-mate.ts +5 -4
- package/src/hooks/companion-instructions.ts +198 -0
- package/src/hooks/hook-io.ts +78 -0
- package/src/hooks/session-banner.ts +24 -30
- package/src/hooks/session-end.ts +10 -0
- package/src/hooks/session-guidance.ts +19 -41
- package/src/hooks/session-prepare.ts +137 -34
- package/src/hooks/session-register.ts +199 -0
- package/src/hooks/tokensave-route.ts +30 -0
- package/src/hooks/validate-artifact-path.ts +90 -25
- package/src/index.ts +4 -0
- package/src/lib/apply-context/fingerprint.ts +174 -0
- package/src/lib/apply-context/protocol.ts +193 -0
- package/src/lib/change-layout.ts +154 -0
- package/src/lib/components/confirm-prompt.tsx +21 -9
- package/src/lib/components/select-menu.tsx +10 -3
- package/src/lib/components/spinner.tsx +4 -2
- package/src/lib/components/startup-progress.tsx +227 -41
- package/src/lib/components/text-input-display.tsx +2 -0
- package/src/lib/components/wizard-footer.tsx +2 -0
- package/src/lib/components/wizard-header.tsx +16 -12
- package/src/lib/context-mode-package.ts +24 -11
- package/src/lib/delivery/archive-change.ts +165 -0
- package/src/lib/delivery/branches.ts +147 -0
- package/src/lib/delivery/environment.ts +35 -0
- package/src/lib/delivery/forge.ts +279 -0
- package/src/lib/delivery/merge-git.ts +261 -0
- package/src/lib/delivery/overlap.ts +209 -0
- package/src/lib/delivery/record-delivery.ts +338 -0
- package/src/lib/delivery/record.ts +405 -0
- package/src/lib/delivery/refresh.ts +288 -0
- package/src/lib/delivery/repository-access.ts +141 -0
- package/src/lib/delivery/resolve-branch.ts +383 -0
- package/src/lib/delivery/stages.ts +111 -0
- package/src/lib/delivery/token.ts +24 -0
- package/src/lib/factory/attach-client.ts +113 -0
- package/src/lib/factory/attach.ts +178 -0
- package/src/lib/factory/broker.ts +190 -0
- package/src/lib/factory/bun-commands.ts +39 -0
- package/src/lib/factory/client.ts +92 -0
- package/src/lib/factory/command.ts +61 -0
- package/src/lib/factory/credential-store.ts +153 -0
- package/src/lib/factory/frames.ts +77 -0
- package/src/lib/factory/ids.ts +58 -0
- package/src/lib/factory/keyed-serial.ts +27 -0
- package/src/lib/factory/outcomes/actions.ts +114 -0
- package/src/lib/factory/outcomes/index.ts +391 -0
- package/src/lib/factory/outcomes/lifecycle.ts +205 -0
- package/src/lib/factory/outcomes/runs.ts +81 -0
- package/src/lib/factory/outcomes/sessions.ts +38 -0
- package/src/lib/factory/prepare.ts +49 -0
- package/src/lib/factory/pty.ts +103 -0
- package/src/lib/factory/runner/companion-context.ts +178 -0
- package/src/lib/factory/runner/control.ts +92 -0
- package/src/lib/factory/runner/harness-agent.ts +250 -0
- package/src/lib/factory/runner/live.ts +159 -0
- package/src/lib/factory/runner/questions.ts +22 -0
- package/src/lib/factory/runner/rank.ts +26 -0
- package/src/lib/factory/runner/run-policy.ts +12 -0
- package/src/lib/factory/runner/run.ts +199 -0
- package/src/lib/factory/runner/scheduler.ts +416 -0
- package/src/lib/factory/runner/state.ts +233 -0
- package/src/lib/factory/runner/workflow.ts +542 -0
- package/src/lib/factory/runtime.ts +981 -0
- package/src/lib/factory/sandbox.ts +292 -0
- package/src/lib/factory/worktree-branch.ts +17 -0
- package/src/lib/frontmatter.ts +18 -0
- package/src/lib/install.ts +66 -14
- package/src/lib/live-progress.ts +36 -0
- package/src/lib/member-choices.ts +67 -0
- package/src/lib/opencode-plugin-package.ts +5 -5
- package/src/lib/opencode-server.ts +238 -0
- package/src/lib/openspec-cli.ts +116 -0
- package/src/lib/openspec-scopes.ts +86 -0
- package/src/lib/orchestrator/adapters/base.ts +55 -22
- package/src/lib/orchestrator/adapters/claude-args.ts +50 -0
- package/src/lib/orchestrator/adapters/claude.ts +210 -162
- package/src/lib/orchestrator/adapters/opencode.ts +60 -24
- package/src/lib/orchestrator/checkout-adoption.ts +125 -0
- package/src/lib/orchestrator/companion-registry-store.ts +6 -2
- package/src/lib/orchestrator/config-store.ts +5 -72
- package/src/lib/orchestrator/editor.ts +32 -26
- package/src/lib/orchestrator/framework-context.ts +26 -14
- package/src/lib/orchestrator/global-config-store.ts +11 -0
- package/src/lib/orchestrator/launcher.ts +15 -2
- package/src/lib/orchestrator/openspec-store.ts +14 -54
- package/src/lib/orchestrator/projection-claude-commands.ts +36 -0
- package/src/lib/orchestrator/projection-claude-links.ts +206 -0
- package/src/lib/orchestrator/projection-claude-skills.ts +37 -182
- package/src/lib/orchestrator/projection-companion-link.ts +12 -1
- package/src/lib/orchestrator/projection-entries.ts +100 -35
- package/src/lib/orchestrator/projection-opencode-copies.ts +32 -15
- package/src/lib/orchestrator/projection-openspec-store.ts +54 -9
- package/src/lib/orchestrator/projection-runtime-documents.ts +15 -6
- package/src/lib/orchestrator/projection-types.ts +36 -3
- package/src/lib/orchestrator/refresh-working-claude-links.ts +87 -0
- package/src/lib/orchestrator/registry-checkouts.ts +177 -0
- package/src/lib/orchestrator/repository-link.ts +216 -57
- package/src/lib/orchestrator/serving-claude-wrap.ts +43 -0
- package/src/lib/orchestrator/session-context-link.ts +73 -0
- package/src/lib/orchestrator/session-prepare.ts +84 -92
- package/src/lib/orchestrator/setup-compatibilities.ts +56 -70
- package/src/lib/orchestrator/types.ts +12 -2
- package/src/lib/orchestrator/working-repo-projection.ts +50 -7
- package/src/lib/orchestrator/workspace-document.ts +105 -0
- package/src/lib/orchestrator/workspace-inventory.ts +5 -1
- package/src/lib/orchestrator/wrap-pass.ts +22 -88
- package/src/lib/package-paths.ts +37 -0
- package/src/lib/public-npm.ts +17 -0
- package/src/lib/runtime-directory-refresh.ts +17 -1
- package/src/lib/session-attribution.ts +52 -0
- package/src/lib/session-state.ts +285 -0
- package/src/lib/session-stop.ts +64 -0
- package/src/lib/workset/record.ts +533 -0
- package/src/lib/workset/repositories.ts +55 -0
- package/src/lib/workset/stage.ts +148 -0
- package/src/lib/workset/stages.ts +113 -0
- package/src/lib/workset/worktree-index.ts +116 -0
- package/src/lib/workset/worktree.ts +898 -0
- package/src/opencode/background-server.ts +145 -0
- package/src/opencode/companion-hooks.ts +111 -7
- package/src/opencode/companion-policy.ts +39 -20
- package/src/opencode/enter-worktree.ts +72 -0
- package/src/opencode/projected-guidance.ts +6 -2
- package/src/opencode/session-prepare.ts +2 -1
- package/src/opencode/session-register.ts +176 -0
- package/src/opencode/tui.tsx +24 -27
- package/src/plugins.ts +1 -0
- package/src/runtime/artifact-refusal.ts +63 -0
- package/src/runtime/claude-delivery-plan.ts +121 -11
- package/src/runtime/commit-attribution-guard.ts +181 -0
- package/src/runtime/companion-git.ts +52 -10
- package/src/runtime/companion-guidance.ts +20 -8
- package/src/runtime/companion-instructions.ts +340 -0
- package/src/runtime/companion-lock.ts +30 -7
- package/src/runtime/current-branch.ts +10 -0
- package/src/runtime/env.ts +59 -8
- package/src/runtime/error-message.ts +4 -0
- package/src/runtime/git-layout.ts +366 -0
- package/src/runtime/guidance.ts +0 -17
- package/src/runtime/index.ts +29 -0
- package/src/runtime/launch-env-guard.ts +65 -0
- package/src/runtime/managed-block.ts +117 -0
- package/src/runtime/markdown-scan.ts +266 -0
- package/src/runtime/opencode-server-record.ts +136 -0
- package/src/runtime/physical-path.ts +111 -0
- package/src/runtime/policy.ts +47 -12
- package/src/runtime/projected-flag.ts +7 -0
- package/src/runtime/projected-guidance.ts +1 -0
- package/src/runtime/projection.ts +40 -6
- package/src/runtime/repo-local.ts +6 -1
- package/src/runtime/runtime-directory.ts +5 -0
- package/src/runtime/runtime-document-manifest.ts +62 -28
- package/src/runtime/secret-guard.ts +162 -0
- package/src/runtime/secret-patterns.ts +397 -0
- package/src/runtime/secret-scan.ts +90 -0
- package/src/runtime/serving-claude-wrap.ts +28 -0
- package/src/runtime/session-context.ts +99 -0
- package/src/runtime/session-kind.ts +13 -0
- package/src/runtime/session-registry.ts +434 -0
- package/src/runtime/shell-heredoc.ts +81 -0
- package/src/runtime/tokensave-route.ts +157 -0
- package/src/runtime/wrap-state.ts +75 -6
- package/src/runtime/write-atomic.ts +64 -0
- package/src/studio.ts +126 -0
- package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +14 -10
- package/src/templates/capabilities/openspec-cap/mate-minimal/templates/spec.md +3 -5
- package/src/templates/capabilities/openspec-cap/mate-v1/schema.yaml +18 -102
- package/src/templates/capabilities/openspec-cap/mate-v1/templates/spec.md +3 -5
- package/src/templates/capabilities/openspec-cap/openspec-conventions.yaml +20 -14
- package/src/templates/mate-skills/THIRD-PARTY-NOTICES.md +40 -0
- package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +162 -0
- package/src/templates/mate-skills/agents/mate-apply-change/references/mate-compact-apply.md +47 -0
- package/src/templates/mate-skills/agents/mate-apply-change/references/openspec-apply-change.md +200 -0
- package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +81 -0
- package/src/templates/mate-skills/agents/{mate-openspec-backfill → mate-backfill-spec}/SKILL.md +11 -4
- package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +110 -0
- package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +66 -0
- package/src/templates/mate-skills/agents/mate-explore-change/references/openspec-explore.md +350 -0
- package/src/templates/mate-skills/agents/mate-grill-me/SKILL.md +11 -4
- package/src/templates/mate-skills/agents/mate-grill-with-docs/SKILL.md +2 -2
- package/src/templates/mate-skills/agents/mate-interview-me/SKILL.md +12 -5
- package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +102 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/mate-revise.md +45 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-propose.md +169 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-update-change.md +103 -0
- package/src/templates/mate-skills/agents/{mate-artifact-publish → mate-publish-artifact}/SKILL.md +109 -24
- package/src/templates/mate-skills/{claude/mate-artifact-publish → agents/mate-publish-artifact}/references/openspec.md +8 -5
- package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +95 -16
- package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +87 -68
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +162 -0
- package/src/templates/mate-skills/claude/mate-apply-change/references/mate-compact-apply.md +47 -0
- package/src/templates/mate-skills/claude/mate-apply-change/references/openspec-apply-change.md +200 -0
- package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +81 -0
- package/src/templates/mate-skills/claude/{mate-openspec-backfill → mate-backfill-spec}/SKILL.md +11 -4
- package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +110 -0
- package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +66 -0
- package/src/templates/mate-skills/claude/mate-explore-change/references/openspec-explore.md +350 -0
- package/src/templates/mate-skills/claude/mate-grill-me/SKILL.md +11 -4
- package/src/templates/mate-skills/claude/mate-grill-with-docs/SKILL.md +2 -2
- package/src/templates/mate-skills/claude/mate-interview-me/SKILL.md +12 -5
- package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +102 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/mate-revise.md +45 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-propose.md +169 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-update-change.md +103 -0
- package/src/templates/mate-skills/claude/{mate-artifact-publish → mate-publish-artifact}/SKILL.md +109 -24
- package/src/templates/mate-skills/{agents/mate-artifact-publish → claude/mate-publish-artifact}/references/openspec.md +8 -5
- package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +95 -16
- package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +87 -68
- package/src/templates/mate-skills/openspec-references.ts +142 -0
- package/src/templates/root/TEMPLATE_AGENTS.md +2 -2
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +4340 -419
- package/src/tools/setup/capabilities/companion-mentions.ts +27 -0
- package/src/tools/setup/capabilities/context-mode.ts +56 -7
- package/src/tools/setup/capabilities/graphify-gate.ts +31 -0
- package/src/tools/setup/capabilities/graphify-secrets.ts +243 -0
- package/src/tools/setup/capabilities/graphify.ts +46 -7
- package/src/tools/setup/capabilities/openspec.ts +284 -271
- package/src/tools/setup/capabilities/react-doctor.ts +8 -1
- package/src/tools/setup/capabilities/rtk.ts +4 -0
- package/src/tools/setup/capabilities/tokensave.ts +113 -71
- package/src/tools/setup/context-services.ts +9 -17
- package/src/tools/setup/dynamic-plugins/audiences.ts +7 -39
- package/src/tools/setup/dynamic-plugins/declarations.ts +1 -1
- package/src/tools/setup/dynamic-plugins/hydrate.ts +8 -10
- package/src/tools/setup/dynamic-plugins/install.ts +24 -28
- package/src/tools/setup/engine.ts +96 -150
- package/src/tools/setup/install-contract.ts +8 -0
- package/src/tools/setup/managed-output.ts +51 -0
- package/src/tools/setup/mate-skill-copies.ts +51 -0
- package/src/tools/setup/mate.ts +86 -11
- package/src/tools/setup/package-managers/uv.ts +73 -11
- package/src/tools/setup/plugin.ts +42 -17
- package/src/tools/setup/plugins/gitignore.ts +1 -7
- package/src/tools/setup/plugins/guidance.ts +7 -4
- package/src/tools/setup/providers/agent-file-sections.ts +4 -2
- package/src/tools/setup/providers/claude-attribution.ts +65 -0
- package/src/tools/setup/providers/claude-plugin-folders.ts +625 -0
- package/src/tools/setup/providers/claude-plugin-hooks.ts +77 -19
- package/src/tools/setup/providers/claude-worktree-plugins.ts +122 -0
- package/src/tools/setup/providers/claude.ts +311 -34
- package/src/tools/setup/providers/opencode.ts +180 -11
- package/src/tools/setup/registry.ts +2 -24
- package/src/tools/setup/surface-target.ts +4 -13
- package/src/tools/setup/utils.ts +18 -4
- package/src/tools/setup/working-repo-cleanup.ts +29 -1
- package/src/tools/setup/working-repo-local-state.ts +252 -75
- package/src/tools/setup.ts +187 -33
- package/studio-dist/client/assets/app-CdPiFv59.css +2 -0
- package/studio-dist/client/assets/button-BIIHE0EQ.js +3 -0
- package/studio-dist/client/assets/companion-view-DM6YyXaR.js +1 -0
- package/studio-dist/client/assets/delivery-path-DELxj0Av.js +1 -0
- package/studio-dist/client/assets/dist-Dm7MtyHc.js +5 -0
- package/studio-dist/client/assets/factory-BZy0E8ty.js +4 -0
- package/studio-dist/client/assets/index-B3wkMzjA.js +40 -0
- package/studio-dist/client/assets/markdown-view-pQ2Qp_i5.js +1 -0
- package/studio-dist/client/assets/panel-CbajlC3p.js +1 -0
- package/studio-dist/client/assets/preload-helper-BLdHbfdN.js +1 -0
- package/studio-dist/client/assets/prepaint-CwSrpdFA.js +27 -0
- package/studio-dist/client/assets/react-CN2GSx7x.js +1 -0
- package/studio-dist/client/assets/reports-DllhYQ5_.js +1 -0
- package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +1 -0
- package/studio-dist/client/assets/routes-COm-G3mK.js +1 -0
- package/studio-dist/client/assets/skills-DmWAy-jZ.js +1 -0
- package/studio-dist/client/assets/specs-BG3Wi3ln.js +1 -0
- package/studio-dist/client/assets/steps-DFsH3Neu.js +1 -0
- package/studio-dist/client/assets/terminal-eU5fzQzv.css +1 -0
- package/studio-dist/client/assets/vault-B2q1nBY5.js +1 -0
- package/studio-dist/client/assets/warnings-BSXIyuSQ.js +1 -0
- package/studio-dist/client/assets/wasm-inline-C2en61B5.js +1 -0
- package/studio-dist/client/assets/workflow-DlsQD6Hc.js +1 -0
- package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-M2GBs8s3.js +4051 -0
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +95 -0
- package/studio-dist/server/assets/actions-Bvgj9eb8.js +54 -0
- package/studio-dist/server/assets/actions-D8erOphH.js +44 -0
- package/studio-dist/server/assets/button-CIJqAhni.js +11929 -0
- package/studio-dist/server/assets/companion-view-DISASvdJ.js +39 -0
- package/studio-dist/server/assets/companions-BYbHWKOZ.js +15 -0
- package/studio-dist/server/assets/createServerFn-F5sAOF8V.js +459 -0
- package/studio-dist/server/assets/createServerRpc-tK2lE9R2.js +11 -0
- package/studio-dist/server/assets/delivery-path-C29fBynY.js +654 -0
- package/studio-dist/server/assets/dist-DpJWKyCm.js +5582 -0
- package/studio-dist/server/assets/empty-plugin-adapters-Cipd4ZH4.js +4 -0
- package/studio-dist/server/assets/factory-DGPmNGbo.js +69 -0
- package/studio-dist/server/assets/factory-DUTa0eDs.js +2172 -0
- package/studio-dist/server/assets/markdown-view-Bn7xPdks.js +86 -0
- package/studio-dist/server/assets/model-PyPALjii.js +18 -0
- package/studio-dist/server/assets/panel-3Jmn4awF.js +169 -0
- package/studio-dist/server/assets/prepaint-DJfTQ_VH.js +45 -0
- package/studio-dist/server/assets/react-Ce6dj15C.js +46 -0
- package/studio-dist/server/assets/reports-C06RXVE2.js +18 -0
- package/studio-dist/server/assets/reports-D6YMqhnO.js +142 -0
- package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +34 -0
- package/studio-dist/server/assets/router-C8MGqlAY.js +13713 -0
- package/studio-dist/server/assets/routes-BcFgvqf7.js +622 -0
- package/studio-dist/server/assets/search-JAKurDNh.js +36 -0
- package/studio-dist/server/assets/shell-DS3wUexh.js +52 -0
- package/studio-dist/server/assets/skills-BEnOxiDl.js +266 -0
- package/studio-dist/server/assets/skills-CtrBAtX3.js +28 -0
- package/studio-dist/server/assets/specs-C8rv34-5.js +211 -0
- package/studio-dist/server/assets/start-h3ICWwd2.js +36 -0
- package/studio-dist/server/assets/steps-Dq_CwY_s.js +181 -0
- package/studio-dist/server/assets/studio-BeltxxKt.js +216 -0
- package/studio-dist/server/assets/utils-C9CX1kcy.js +221 -0
- package/studio-dist/server/assets/vault-BmWnryh3.js +85 -0
- package/studio-dist/server/assets/vault-Fvxt2Tzl.js +1032 -0
- package/studio-dist/server/assets/views-BgYa-za2.js +80 -0
- package/studio-dist/server/assets/warnings-DzR6fyZh.js +23 -0
- package/studio-dist/server/assets/wasm-inline-CNeBKGwC.js +3 -0
- package/studio-dist/server/assets/workflow-liRYecHk.js +73 -0
- package/studio-dist/server/server.js +16066 -0
- package/wrappers/bin/graphify +52 -4
- package/wrappers/bin/openspec +33 -9
- package/wrappers/lib/graphify-gate.mjs +8 -0
- package/opencode-plugin/src/audience-layer.ts +0 -91
- package/src/cli/commands/studio/views/client.ts +0 -654
- package/src/cli/commands/studio/views/companion-picker.tsx +0 -95
- package/src/cli/commands/studio/views/companion-selector.tsx +0 -94
- package/src/cli/commands/studio/views/dashboard/changes.tsx +0 -107
- package/src/cli/commands/studio/views/dashboard/index.tsx +0 -19
- package/src/cli/commands/studio/views/document.tsx +0 -842
- package/src/cli/commands/studio/views/error.tsx +0 -20
- package/src/cli/commands/studio/views/reports/index.tsx +0 -49
- package/src/cli/commands/studio/views/selection-fields.tsx +0 -14
- package/src/cli/commands/studio/views/skills/index.tsx +0 -87
- package/src/cli/commands/studio/views/specs/index.tsx +0 -157
- package/src/cli/commands/studio/views/styles.ts +0 -519
- package/src/cli/commands/studio/views/terminal.tsx +0 -484
- package/src/cli/commands/studio/views/vault/state.ts +0 -43
- package/src/cli/commands/studio/views/warnings.tsx +0 -21
- package/src/cli/commands/studio/views/workflow/index.tsx +0 -21
- package/src/cli/commands/studio/views/workflow/steps.ts +0 -337
- package/src/cli/commands/studio/views/workflow/transcript.tsx +0 -190
- package/src/lib/components/theme.ts +0 -2
- package/src/runtime/audience-layer.ts +0 -84
- package/src/runtime/opencode-audience-layer.ts +0 -176
- package/src/tools/setup/audience-isolation.fixture.ts +0 -325
- package/src/tools/setup/audience-layer.ts +0 -207
- package/src/tools/setup/audience-registrations.ts +0 -52
- package/src/tools/setup/contribution-ledger.ts +0 -207
- package/src/tools/setup/git-utils.ts +0 -30
- package/src/tools/setup/isolation-diagnostics.ts +0 -139
- package/src/tools/setup/runtime-documents.ts +0 -291
- package/src/tools/setup/upgrade-sweep.ts +0 -153
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
fingerprintArtifacts,
|
|
6
|
+
type FingerprintOptions,
|
|
7
|
+
type FingerprintResult,
|
|
8
|
+
} from "../../../lib/apply-context/fingerprint";
|
|
9
|
+
import {
|
|
10
|
+
compactableTasks,
|
|
11
|
+
computeDigest,
|
|
12
|
+
encodeApplyContext,
|
|
13
|
+
fullReason,
|
|
14
|
+
isWellFormedDigest,
|
|
15
|
+
type ApplyPayload,
|
|
16
|
+
type DigestIdentity,
|
|
17
|
+
} from "../../../lib/apply-context/protocol";
|
|
18
|
+
import { hasOpenspecCapability } from "../../../lib/orchestrator/capabilities";
|
|
19
|
+
import {
|
|
20
|
+
resolveForCapability,
|
|
21
|
+
type LaunchContext,
|
|
22
|
+
} from "../../../lib/orchestrator/framework-context";
|
|
23
|
+
import type { CapabilityConfig } from "../../../lib/orchestrator/types";
|
|
24
|
+
import { WorkingRepoRequiredError } from "../../../lib/orchestrator/types";
|
|
25
|
+
import { locateOpenSpec, runOpenSpec, type RunOpenSpec } from "../../../lib/openspec-cli";
|
|
26
|
+
import { generatedHeader } from "../../../runtime/projection";
|
|
27
|
+
import { parseSecretsConfig, type SecretPolicy } from "../../../runtime/secret-patterns";
|
|
28
|
+
import { type BooleanFlagSet, parseFlags, positionalArgs, stringFlag } from "../../parse-flags";
|
|
29
|
+
import { ensureUnambiguousCompanion } from "../shared/companion-selection";
|
|
30
|
+
import { commandOutput } from "./delivery/output";
|
|
31
|
+
|
|
32
|
+
export interface ApplyContextCommandDeps {
|
|
33
|
+
cwd?: () => string;
|
|
34
|
+
ensureUnambiguousCompanion?: (cwd: string) => Promise<boolean>;
|
|
35
|
+
resolveContext?: (cwd: string) => Promise<LaunchContext>;
|
|
36
|
+
loadCapabilities?: (context: LaunchContext) => Promise<CapabilityConfig[]>;
|
|
37
|
+
loadSecretPolicy?: (context: LaunchContext) => Promise<SecretPolicy>;
|
|
38
|
+
run?: RunOpenSpec;
|
|
39
|
+
/** The upstream producer's identity; a new OpenSpec version invalidates every baseline. */
|
|
40
|
+
producer?: () => Record<string, unknown>;
|
|
41
|
+
stdout?: (line: string) => void;
|
|
42
|
+
stderr?: (line: string) => void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const BOOLEAN_FLAGS: BooleanFlagSet = new Set(["json"]);
|
|
46
|
+
|
|
47
|
+
/** Upper bound on one upstream call, as Studio uses; a hung CLI fails the command. */
|
|
48
|
+
const OPENSPEC_TIMEOUT_MS = 60_000;
|
|
49
|
+
|
|
50
|
+
/** Attempts before a context that keeps changing during collection is sent without a digest. */
|
|
51
|
+
const COLLECTION_ATTEMPTS = 3;
|
|
52
|
+
|
|
53
|
+
async function defaultLoadCapabilities(context: LaunchContext): Promise<CapabilityConfig[]> {
|
|
54
|
+
return (await context.configStore.load()).capabilities ?? [];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function defaultLoadSecretPolicy(context: LaunchContext): Promise<SecretPolicy> {
|
|
58
|
+
const config = (await context.configStore.load()) as { secrets?: unknown };
|
|
59
|
+
return parseSecretsConfig(config.secrets);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function isUnder(child: string, root: string): boolean {
|
|
63
|
+
const relative = path.relative(root, child);
|
|
64
|
+
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function physical(dir: string): Promise<string> {
|
|
68
|
+
return fs.realpath(dir).catch(() => path.resolve(dir));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The directory the wrapped `openspec instructions` runs in: the Working Repository
|
|
73
|
+
* root when the caller is inside it, outside the companion, and the root carries
|
|
74
|
+
* Mate's store pointer; otherwise the companion. Mirrors `wrappers/bin/openspec`.
|
|
75
|
+
*/
|
|
76
|
+
export async function wrappedOpenSpecCwd(
|
|
77
|
+
companionPath: string,
|
|
78
|
+
repoPath: string | undefined,
|
|
79
|
+
cwd: string,
|
|
80
|
+
): Promise<{ cwd: string; notice?: string }> {
|
|
81
|
+
if (!repoPath) return { cwd: companionPath };
|
|
82
|
+
const repoRoot = await physical(repoPath);
|
|
83
|
+
const here = await physical(cwd);
|
|
84
|
+
const companionRoot = await physical(companionPath);
|
|
85
|
+
if (!isUnder(here, repoRoot) || isUnder(here, companionRoot)) return { cwd: companionPath };
|
|
86
|
+
const pointer = path.join(repoRoot, "openspec", "config.yaml");
|
|
87
|
+
const first = await fs
|
|
88
|
+
.readFile(pointer, "utf8")
|
|
89
|
+
.then((text) => text.split("\n")[0])
|
|
90
|
+
.catch(() => undefined);
|
|
91
|
+
if (first !== undefined) {
|
|
92
|
+
return first === generatedHeader() ? { cwd: repoRoot } : { cwd: companionPath };
|
|
93
|
+
}
|
|
94
|
+
const hasYml = await fs
|
|
95
|
+
.access(path.join(repoRoot, "openspec", "config.yml"))
|
|
96
|
+
.then(() => true)
|
|
97
|
+
.catch(() => false);
|
|
98
|
+
if (hasYml) return { cwd: companionPath };
|
|
99
|
+
return {
|
|
100
|
+
cwd: companionPath,
|
|
101
|
+
notice: `openspec: no OpenSpec store pointer in ${repoRoot}, so edits are scoped to the companion — run \`mate wrap\` to enable Working Repository edit roots`,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function failureDetail(stdout: string, stderr: string): string {
|
|
106
|
+
return (stderr.trim() || stdout.trim()).split("\n").slice(-3).join("; ");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function parsePayload(stdout: string): ApplyPayload | undefined {
|
|
110
|
+
const text = stdout.trim();
|
|
111
|
+
const candidates = [text, text.slice(Math.max(0, text.indexOf("{")))];
|
|
112
|
+
for (const candidate of candidates) {
|
|
113
|
+
try {
|
|
114
|
+
const value: unknown = JSON.parse(candidate);
|
|
115
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
116
|
+
return value as ApplyPayload;
|
|
117
|
+
}
|
|
118
|
+
return undefined;
|
|
119
|
+
} catch {
|
|
120
|
+
// Try the next candidate: text before the JSON object, such as a notice.
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function sameHashes(a: FingerprintResult, b: FingerprintResult): boolean {
|
|
127
|
+
if (!a.ok || !b.ok) return false;
|
|
128
|
+
return JSON.stringify(a.raw) === JSON.stringify(b.raw);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
interface Collected {
|
|
132
|
+
payload: ApplyPayload;
|
|
133
|
+
/** Null when compaction is unavailable; `limitation` then says why. */
|
|
134
|
+
digest: string | null;
|
|
135
|
+
limitation?: string;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Fetches the payload and fingerprints its artifacts twice; a digest only when both passes
|
|
140
|
+
* agree. Retries a context that changes during collection. A string is an upstream failure.
|
|
141
|
+
*/
|
|
142
|
+
async function collect(
|
|
143
|
+
fetchPayload: () => Promise<ApplyPayload | string>,
|
|
144
|
+
identity: DigestIdentity,
|
|
145
|
+
options: FingerprintOptions,
|
|
146
|
+
): Promise<Collected | string> {
|
|
147
|
+
for (let attempt = 1; ; attempt++) {
|
|
148
|
+
const payload = await fetchPayload();
|
|
149
|
+
if (typeof payload === "string") return payload;
|
|
150
|
+
const shape = compactableTasks(payload);
|
|
151
|
+
if (!shape.ok) {
|
|
152
|
+
// A blocked payload goes out in full anyway; its missing tasks are no limitation.
|
|
153
|
+
const limitation = fullReason(payload) === null ? shape.reason : undefined;
|
|
154
|
+
return { payload, digest: null, limitation };
|
|
155
|
+
}
|
|
156
|
+
let limitation: string;
|
|
157
|
+
const first = await fingerprintArtifacts(payload, options);
|
|
158
|
+
if (first.ok) {
|
|
159
|
+
const second = await fingerprintArtifacts(payload, options);
|
|
160
|
+
if (sameHashes(first, second)) {
|
|
161
|
+
return { payload, digest: computeDigest(identity, payload, first.fingerprints) };
|
|
162
|
+
}
|
|
163
|
+
limitation = "context changed while it was collected";
|
|
164
|
+
} else {
|
|
165
|
+
limitation = first.reason;
|
|
166
|
+
// A state mismatch can be a checkbox written between the upstream read and ours.
|
|
167
|
+
if (!first.reason.includes("state differs")) return { payload, digest: null, limitation };
|
|
168
|
+
}
|
|
169
|
+
if (attempt === COLLECTION_ATTEMPTS) return { payload, digest: null, limitation };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @command mate artifact apply-context <change>
|
|
175
|
+
* @description Fetches fresh `openspec instructions apply --json` for a change, resolved as
|
|
176
|
+
* the wrapped `openspec` resolves it, and wraps it in a versioned envelope for Mate's opt-in
|
|
177
|
+
* compact apply transport. Without a matching `--since` it emits the full upstream payload
|
|
178
|
+
* with a baseline `digest`; with one it emits only `state`, `progress`, and every ordered
|
|
179
|
+
* task `{id, done}`. Warnings, a blocked state, missing artifacts, and any change to the
|
|
180
|
+
* static payload, referenced artifacts, edit context, or OpenSpec version force a full
|
|
181
|
+
* envelope. Read-only: no writes, no forge or network access, no initialization.
|
|
182
|
+
* @flags
|
|
183
|
+
* - `--json` — required; emit the envelope as JSON.
|
|
184
|
+
* - `--since <digest>` — the digest of a full envelope still held in full by the caller.
|
|
185
|
+
* @remarks Upstream failures, timeouts, and malformed output exit non-zero; nothing is cached
|
|
186
|
+
* or inferred. A full envelope with `digest: null` names its `limitation`, such as an
|
|
187
|
+
* unreadable context file or an ambiguous task location.
|
|
188
|
+
*/
|
|
189
|
+
export async function runArtifactApplyContextCommand(
|
|
190
|
+
argv: string[],
|
|
191
|
+
deps: ApplyContextCommandDeps = {},
|
|
192
|
+
): Promise<void> {
|
|
193
|
+
const { emitOut, emitErr, refuse } = commandOutput(deps);
|
|
194
|
+
const flags = parseFlags(argv, BOOLEAN_FLAGS);
|
|
195
|
+
const changes = positionalArgs(argv, BOOLEAN_FLAGS);
|
|
196
|
+
if (changes.length !== 1) return refuse("mate: artifact apply-context requires one change name.");
|
|
197
|
+
if (flags.json !== true) return refuse("mate: artifact apply-context requires --json.");
|
|
198
|
+
const since = flags.since === undefined ? undefined : stringFlag(flags.since);
|
|
199
|
+
if (flags.since !== undefined && since === undefined) {
|
|
200
|
+
return refuse("mate: --since expects a digest.");
|
|
201
|
+
}
|
|
202
|
+
const change = changes[0];
|
|
203
|
+
|
|
204
|
+
const cwd = (deps.cwd ?? (() => process.cwd()))();
|
|
205
|
+
if (!(await (deps.ensureUnambiguousCompanion ?? ensureUnambiguousCompanion)(cwd))) {
|
|
206
|
+
return refuse();
|
|
207
|
+
}
|
|
208
|
+
let context: LaunchContext;
|
|
209
|
+
try {
|
|
210
|
+
context = await (deps.resolveContext ?? ((dir: string) => resolveForCapability(dir)))(cwd);
|
|
211
|
+
} catch (err) {
|
|
212
|
+
if (err instanceof WorkingRepoRequiredError) return refuse(err.message);
|
|
213
|
+
throw err;
|
|
214
|
+
}
|
|
215
|
+
const capabilities = await (deps.loadCapabilities ?? defaultLoadCapabilities)(context);
|
|
216
|
+
if (!hasOpenspecCapability(capabilities)) {
|
|
217
|
+
return refuse("mate: the openspec capability must be enabled to read apply context.");
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const repoPath = context.repository?.path ?? process.env.MATE_REPO_PATH;
|
|
221
|
+
const target = await wrappedOpenSpecCwd(context.companionPath, repoPath, cwd);
|
|
222
|
+
if (target.notice) emitErr(target.notice);
|
|
223
|
+
const run = deps.run ?? runOpenSpec;
|
|
224
|
+
const args = ["instructions", "apply", "--change", change, "--json"];
|
|
225
|
+
|
|
226
|
+
const fetchPayload = async (): Promise<ApplyPayload | string> => {
|
|
227
|
+
const output = await run(args, { cwd: target.cwd, timeout: OPENSPEC_TIMEOUT_MS });
|
|
228
|
+
if (output.missing) return `mate: ${output.stderr}`;
|
|
229
|
+
if (output.code === null) return "mate: openspec instructions apply timed out.";
|
|
230
|
+
if (output.code !== 0) {
|
|
231
|
+
const detail = failureDetail(output.stdout, output.stderr);
|
|
232
|
+
return `mate: openspec instructions apply failed (exit code ${output.code})${detail ? `: ${detail}` : ""}`;
|
|
233
|
+
}
|
|
234
|
+
return (
|
|
235
|
+
parsePayload(output.stdout) ?? "mate: openspec instructions apply returned malformed JSON."
|
|
236
|
+
);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const producer = (
|
|
240
|
+
deps.producer ??
|
|
241
|
+
(() => {
|
|
242
|
+
const location = locateOpenSpec();
|
|
243
|
+
return { openspec: "missing" in location ? null : (location.version ?? null) };
|
|
244
|
+
})
|
|
245
|
+
)();
|
|
246
|
+
const identity: DigestIdentity = {
|
|
247
|
+
producer,
|
|
248
|
+
editContext: {
|
|
249
|
+
change,
|
|
250
|
+
cwd: await physical(target.cwd),
|
|
251
|
+
companion: await physical(context.companionPath),
|
|
252
|
+
repository: repoPath ? await physical(repoPath) : null,
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
const secretPolicy = await (deps.loadSecretPolicy ?? defaultLoadSecretPolicy)(context);
|
|
256
|
+
const allowedRoots = [context.companionPath, ...(repoPath ? [repoPath] : [])];
|
|
257
|
+
|
|
258
|
+
const collected = await collect(fetchPayload, identity, { allowedRoots, secretPolicy });
|
|
259
|
+
if (typeof collected === "string") return refuse(collected);
|
|
260
|
+
const { payload, digest, limitation } = collected;
|
|
261
|
+
|
|
262
|
+
if (since !== undefined && !isWellFormedDigest(since)) {
|
|
263
|
+
emitErr("warning: --since is not a well-formed digest; sending the full context.");
|
|
264
|
+
}
|
|
265
|
+
const envelope = encodeApplyContext({
|
|
266
|
+
payload,
|
|
267
|
+
digest,
|
|
268
|
+
limitation,
|
|
269
|
+
...(since !== undefined && isWellFormedDigest(since) ? { since } : {}),
|
|
270
|
+
});
|
|
271
|
+
if (envelope.mode === "full" && envelope.limitation) {
|
|
272
|
+
emitErr(`warning: compact updates are unavailable: ${envelope.limitation}`);
|
|
273
|
+
}
|
|
274
|
+
emitOut(JSON.stringify(envelope));
|
|
275
|
+
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { usage } from "../../usage";
|
|
2
|
+
import { runArtifactApplyContextCommand } from "./apply-context";
|
|
3
|
+
import { runArtifactArchiveCommand } from "./delivery/archive";
|
|
4
|
+
import { runArtifactLinkCommand } from "./delivery/link";
|
|
2
5
|
import { runArtifactPublishCommand } from "./finish";
|
|
3
6
|
import { runArtifactPendingCommand } from "./pending";
|
|
4
7
|
|
|
@@ -30,6 +33,15 @@ export async function runArtifactCommand(
|
|
|
30
33
|
case "pending":
|
|
31
34
|
await runArtifactPendingCommand(argv);
|
|
32
35
|
return;
|
|
36
|
+
case "link":
|
|
37
|
+
await runArtifactLinkCommand(argv);
|
|
38
|
+
return;
|
|
39
|
+
case "archive":
|
|
40
|
+
await runArtifactArchiveCommand(argv);
|
|
41
|
+
return;
|
|
42
|
+
case "apply-context":
|
|
43
|
+
await runArtifactApplyContextCommand(argv);
|
|
44
|
+
return;
|
|
33
45
|
default:
|
|
34
46
|
console.error(`Unknown artifact command: ${subcommand ?? ""}`);
|
|
35
47
|
console.error(usage());
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {
|
|
2
|
+
archiveChange,
|
|
3
|
+
type ArchiveChangeDeps,
|
|
4
|
+
type ArchiveResult,
|
|
5
|
+
} from "../../../../lib/delivery/archive-change";
|
|
6
|
+
import type { DeliveryRefusal } from "../../../../lib/delivery/record-delivery";
|
|
7
|
+
import { type BooleanFlagSet, parseFlags, positionalArgs } from "../../../parse-flags";
|
|
8
|
+
import {
|
|
9
|
+
branchFlagsFrom,
|
|
10
|
+
canonicalRepository,
|
|
11
|
+
deliveryEditFrom,
|
|
12
|
+
DIRECT_NEEDS_BRANCH,
|
|
13
|
+
repositoryFlag,
|
|
14
|
+
valueFlagError,
|
|
15
|
+
} from "./branch-flags";
|
|
16
|
+
import { resolveDeliveryEnvironment, type DeliveryEnvironmentDeps } from "./environment";
|
|
17
|
+
import {
|
|
18
|
+
commandOutput,
|
|
19
|
+
renderDelivery,
|
|
20
|
+
renderOutcome,
|
|
21
|
+
sharedRefusalMessage,
|
|
22
|
+
unscopedDeliveryWarning,
|
|
23
|
+
} from "./output";
|
|
24
|
+
|
|
25
|
+
export interface ArchiveCommandDeps
|
|
26
|
+
extends DeliveryEnvironmentDeps, Omit<ArchiveChangeDeps, "onWarnings"> {
|
|
27
|
+
stdout?: (line: string) => void;
|
|
28
|
+
stderr?: (line: string) => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const BOOLEAN_FLAGS: BooleanFlagSet = new Set(["json", "direct", "skip-branch", "fetch"]);
|
|
32
|
+
|
|
33
|
+
function refusalMessage(refusal: DeliveryRefusal): string {
|
|
34
|
+
if (refusal.reason === "unknown-change") {
|
|
35
|
+
return `mate: no active change named "${refusal.change}" to archive.`;
|
|
36
|
+
}
|
|
37
|
+
return sharedRefusalMessage(refusal);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Warnings are not repeated here: they go to stderr before anything is archived. */
|
|
41
|
+
function renderHuman(result: ArchiveResult): string[] {
|
|
42
|
+
return [
|
|
43
|
+
result.message,
|
|
44
|
+
...result.record.deliveries.map(renderDelivery),
|
|
45
|
+
...result.outcomes.flatMap(renderOutcome),
|
|
46
|
+
` delivery: ${result.settlement.status}`,
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @command mate artifact archive <change>
|
|
52
|
+
* @description Archives an active change whether or not its delivery is merged, so a
|
|
53
|
+
* feature's later changes build on its canonical specs. Writes overlap, dependency, and
|
|
54
|
+
* incomplete-planning warnings to stderr before archiving, refreshes merge state from the
|
|
55
|
+
* forge when a token is available and from a local checkout otherwise, always leaves a `delivery.yaml` (unlinked when none was recorded), then
|
|
56
|
+
* runs `openspec archive` with the bundled CLI. Merge state is reported, never a refusal.
|
|
57
|
+
* @flags
|
|
58
|
+
* - `--repository <org/repo>` — the delivery `--branch` or `--not-applicable` records; defaults
|
|
59
|
+
* to the Working Repository.
|
|
60
|
+
* - `--branch <branch>` / `--direct` — record the delivery branch first, as `artifact link`.
|
|
61
|
+
* - `--not-applicable <reason>` — record that no branch delivers this change.
|
|
62
|
+
* - `--skip-branch` — archive with an unlinked record when the user skips the question, so
|
|
63
|
+
* publication asks again.
|
|
64
|
+
* - `--fetch` — fetch the default and delivery branches before the merge check even when the
|
|
65
|
+
* companion's Git mode is not `auto`.
|
|
66
|
+
* - `--json` — emit an {@link ArchiveResult}.
|
|
67
|
+
* @remarks Without a recorded delivery and none of the branch flags, nothing is archived:
|
|
68
|
+
* the result is `needs-branch`, a question rather than a refusal (exit 0), with
|
|
69
|
+
* the change's resolved Delivery Branch suggested before legacy `change/<change-name>`
|
|
70
|
+
* when either exists, so the caller can ask the user.
|
|
71
|
+
*/
|
|
72
|
+
export async function runArtifactArchiveCommand(
|
|
73
|
+
argv: string[],
|
|
74
|
+
deps: ArchiveCommandDeps = {},
|
|
75
|
+
): Promise<void> {
|
|
76
|
+
const { emitOut, emitErr, refuse } = commandOutput(deps);
|
|
77
|
+
const flags = parseFlags(argv, BOOLEAN_FLAGS);
|
|
78
|
+
const flagError = valueFlagError(flags, ["repository", "branch", "not-applicable"]);
|
|
79
|
+
if (flagError) return refuse(flagError);
|
|
80
|
+
const json = flags.json === true;
|
|
81
|
+
const [change] = positionalArgs(argv, BOOLEAN_FLAGS);
|
|
82
|
+
const branchFlags = branchFlagsFrom(flags);
|
|
83
|
+
const { branch, notApplicable } = branchFlags;
|
|
84
|
+
const skip = flags["skip-branch"] === true;
|
|
85
|
+
|
|
86
|
+
if (!change) return refuse("mate: artifact archive requires a change name.");
|
|
87
|
+
if ([branch !== undefined, notApplicable !== undefined, skip].filter(Boolean).length > 1) {
|
|
88
|
+
return refuse("mate: pass only one of --branch, --not-applicable, or --skip-branch.");
|
|
89
|
+
}
|
|
90
|
+
if (branchFlags.direct && branch === undefined) return refuse(DIRECT_NEEDS_BRANCH);
|
|
91
|
+
const requested = repositoryFlag(flags);
|
|
92
|
+
if ("error" in requested) return refuse(requested.error);
|
|
93
|
+
if (requested.repository !== undefined && branch === undefined && notApplicable === undefined) {
|
|
94
|
+
return refuse("mate: --repository names the delivery --branch or --not-applicable records.");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const environment = await resolveDeliveryEnvironment(deps);
|
|
98
|
+
if ("error" in environment) return refuse(environment.error);
|
|
99
|
+
const repository = canonicalRepository(environment, requested.repository);
|
|
100
|
+
const delivery = deliveryEditFrom(branchFlags);
|
|
101
|
+
const outcome = await archiveChange(
|
|
102
|
+
environment,
|
|
103
|
+
{
|
|
104
|
+
change,
|
|
105
|
+
...(repository ? { repository } : {}),
|
|
106
|
+
...(delivery ? { delivery } : {}),
|
|
107
|
+
skipBranch: skip,
|
|
108
|
+
fetch: flags.fetch === true,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
...deps,
|
|
112
|
+
onWarnings: (warnings, unscoped) => {
|
|
113
|
+
for (const warning of warnings) emitErr(`warning: ${warning.message}`);
|
|
114
|
+
for (const entry of unscoped) emitErr(unscopedDeliveryWarning(change, entry));
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
);
|
|
118
|
+
if ("refusal" in outcome) return refuse(refusalMessage(outcome.refusal));
|
|
119
|
+
|
|
120
|
+
const { result } = outcome;
|
|
121
|
+
for (const diagnostic of result.diagnostics) emitErr(`warning: ${diagnostic}`);
|
|
122
|
+
if (result.status === "failed") process.exitCode = 1;
|
|
123
|
+
if (json) emitOut(JSON.stringify(result));
|
|
124
|
+
else for (const line of renderHuman(result)) emitOut(line);
|
|
125
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { DeliveryEnvironment } from "../../../../lib/delivery/environment";
|
|
2
|
+
import { sameRepository } from "../../../../lib/delivery/record";
|
|
3
|
+
import type { DeliveryEdit } from "../../../../lib/delivery/record-delivery";
|
|
4
|
+
import { type CliFlags, malformedValueFlag, stringFlag } from "../../../parse-flags";
|
|
5
|
+
|
|
6
|
+
/** `--branch` with `--direct`, or `--not-applicable`, as `artifact link` and `archive` take them. */
|
|
7
|
+
export interface BranchFlags {
|
|
8
|
+
branch?: string;
|
|
9
|
+
direct: boolean;
|
|
10
|
+
notApplicable?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function branchFlagsFrom(flags: CliFlags): BranchFlags {
|
|
14
|
+
return {
|
|
15
|
+
branch: stringFlag(flags.branch),
|
|
16
|
+
direct: flags.direct === true,
|
|
17
|
+
notApplicable: stringFlag(flags["not-applicable"]),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const DIRECT_NEEDS_BRANCH = "mate: --direct records a direct delivery and needs --branch.";
|
|
22
|
+
|
|
23
|
+
/** The delivery edit the branch flags ask for; `--branch` wins over `--not-applicable`. */
|
|
24
|
+
export function deliveryEditFrom(flags: BranchFlags): DeliveryEdit["delivery"] {
|
|
25
|
+
if (flags.branch !== undefined) return { branch: flags.branch, direct: flags.direct };
|
|
26
|
+
if (flags.notApplicable !== undefined) return { notApplicable: flags.notApplicable };
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Refuses a value flag given bare or repeated, which would otherwise read as absent. */
|
|
31
|
+
export function valueFlagError(flags: CliFlags, names: readonly string[]): string | undefined {
|
|
32
|
+
const name = malformedValueFlag(flags, names);
|
|
33
|
+
return name === undefined ? undefined : `mate: --${name} takes exactly one value.`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** `--repository <org/repo>`, or the refusal for a malformed one. */
|
|
37
|
+
export function repositoryFlag(flags: CliFlags): { repository?: string } | { error: string } {
|
|
38
|
+
const repository = stringFlag(flags.repository);
|
|
39
|
+
if (repository !== undefined && !/^[\w.-]+(?:\/[\w.-]+)+$/.test(repository)) {
|
|
40
|
+
return {
|
|
41
|
+
error:
|
|
42
|
+
"mate: --repository expects a repository path such as <org/repo> or <group/subgroup/repo>.",
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return repository === undefined ? {} : { repository };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** GitHub slugs are case-insensitive; the Working Repository's own spelling keeps one delivery. */
|
|
49
|
+
export function canonicalRepository(
|
|
50
|
+
environment: DeliveryEnvironment,
|
|
51
|
+
requested: string | undefined,
|
|
52
|
+
): string | undefined {
|
|
53
|
+
const own = environment.workingRepo?.slug;
|
|
54
|
+
return own && requested !== undefined && sameRepository(requested, own) ? own : requested;
|
|
55
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import {
|
|
2
|
+
workingRepoGit,
|
|
3
|
+
configuredProtectedPatterns,
|
|
4
|
+
configuredTicketFormat,
|
|
5
|
+
type WorkingRepoGit,
|
|
6
|
+
} from "../../../../lib/delivery/branches";
|
|
7
|
+
import type { DeliveryEnvironment, WorkingRepoInfo } from "../../../../lib/delivery/environment";
|
|
8
|
+
import { parseRemote, repositoryPath, type ForgeRepo } from "../../../../lib/delivery/forge";
|
|
9
|
+
import { sameRepository } from "../../../../lib/delivery/record";
|
|
10
|
+
import { hasOpenspecCapability } from "../../../../lib/orchestrator/capabilities";
|
|
11
|
+
import {
|
|
12
|
+
resolveForCapability,
|
|
13
|
+
type LaunchContext,
|
|
14
|
+
} from "../../../../lib/orchestrator/framework-context";
|
|
15
|
+
import type { CapabilityConfig, LinkedRepository } from "../../../../lib/orchestrator/types";
|
|
16
|
+
import { WorkingRepoRequiredError } from "../../../../lib/orchestrator/types";
|
|
17
|
+
import { ensureUnambiguousCompanion } from "../../shared/companion-selection";
|
|
18
|
+
|
|
19
|
+
export interface DeliveryEnvironmentDeps {
|
|
20
|
+
ensureUnambiguousCompanion?: (cwd: string) => Promise<boolean>;
|
|
21
|
+
resolveContext?: (cwd: string) => Promise<LaunchContext>;
|
|
22
|
+
loadCapabilities?: (context: LaunchContext) => Promise<CapabilityConfig[]>;
|
|
23
|
+
workingRepoGit?: (repoPath: string) => WorkingRepoGit;
|
|
24
|
+
loadLinkedRepositories?: (context: LaunchContext) => Promise<LinkedRepository[]>;
|
|
25
|
+
/** True when the companion's Git mode is `auto`. */
|
|
26
|
+
loadGitAutoMode?: (context: LaunchContext) => Promise<boolean>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function defaultLoadLinkedRepositories(context: LaunchContext): Promise<LinkedRepository[]> {
|
|
30
|
+
return (await context.workingRepoStore.load()).repos;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A linked repository's checkout with its parsed `origin` remote. */
|
|
34
|
+
interface LinkedCheckout {
|
|
35
|
+
remote: ForgeRepo;
|
|
36
|
+
path: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function defaultLoadGitAutoMode(context: LaunchContext): Promise<boolean> {
|
|
40
|
+
return (await context.configStore.load()).git === "auto";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function defaultLoadCapabilities(context: LaunchContext): Promise<CapabilityConfig[]> {
|
|
44
|
+
const config = await context.configStore.load();
|
|
45
|
+
return config.capabilities ?? [];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The companion, the Working Repository with its remote identity, and the configured
|
|
50
|
+
* protected-branch patterns. `error` explains why the command cannot run; it is null
|
|
51
|
+
* when the companion check has already reported the problem.
|
|
52
|
+
*/
|
|
53
|
+
export async function resolveDeliveryEnvironment(
|
|
54
|
+
deps: DeliveryEnvironmentDeps,
|
|
55
|
+
): Promise<DeliveryEnvironment | { error: string | null }> {
|
|
56
|
+
const ensureCompanion = deps.ensureUnambiguousCompanion ?? ensureUnambiguousCompanion;
|
|
57
|
+
if (!(await ensureCompanion(process.cwd()))) return { error: null };
|
|
58
|
+
|
|
59
|
+
let context: LaunchContext;
|
|
60
|
+
try {
|
|
61
|
+
context = await (deps.resolveContext ?? ((cwd: string) => resolveForCapability(cwd)))(
|
|
62
|
+
process.cwd(),
|
|
63
|
+
);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
if (err instanceof WorkingRepoRequiredError) return { error: err.message };
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const capabilities = await (deps.loadCapabilities ?? defaultLoadCapabilities)(context);
|
|
70
|
+
if (!hasOpenspecCapability(capabilities)) {
|
|
71
|
+
return { error: "mate: the openspec capability must be enabled to record delivery." };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const openGit = deps.workingRepoGit ?? workingRepoGit;
|
|
75
|
+
const repoPath = context.repository?.path ?? process.env.MATE_REPO_PATH;
|
|
76
|
+
let workingRepo: WorkingRepoInfo | null = null;
|
|
77
|
+
if (repoPath) {
|
|
78
|
+
const git = openGit(repoPath);
|
|
79
|
+
const remote = await git.remoteUrl();
|
|
80
|
+
const forgeRepo = remote ? parseRemote(remote) : null;
|
|
81
|
+
workingRepo = {
|
|
82
|
+
path: repoPath,
|
|
83
|
+
slug: forgeRepo ? repositoryPath(forgeRepo) : null,
|
|
84
|
+
forgeRepo,
|
|
85
|
+
git,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let linkedRemotes: Promise<LinkedCheckout[]> | undefined;
|
|
90
|
+
// Read once, and only when a repository other than the Working Repository is looked up.
|
|
91
|
+
const linked = (): Promise<LinkedCheckout[]> =>
|
|
92
|
+
(linkedRemotes ??= (async () => {
|
|
93
|
+
// An unreadable registry only loses hints; the Working Repository remains.
|
|
94
|
+
const repositories = await (deps.loadLinkedRepositories ?? defaultLoadLinkedRepositories)(
|
|
95
|
+
context,
|
|
96
|
+
).catch(() => []);
|
|
97
|
+
const others = repositories.filter((repository) => repository.path !== repoPath);
|
|
98
|
+
const remotes = await Promise.all(
|
|
99
|
+
others.map((repository) => openGit(repository.path).remoteUrl()),
|
|
100
|
+
);
|
|
101
|
+
return others.flatMap((repository, index) => {
|
|
102
|
+
const remote = remotes[index] ? parseRemote(remotes[index]) : null;
|
|
103
|
+
return remote ? [{ remote, path: repository.path }] : [];
|
|
104
|
+
});
|
|
105
|
+
})());
|
|
106
|
+
const linkedMatch = async (repository: string) =>
|
|
107
|
+
(await linked()).find(({ remote }) => sameRepository(repositoryPath(remote), repository));
|
|
108
|
+
const hostOf = async (repository: string): Promise<string | null> =>
|
|
109
|
+
(await linkedMatch(repository))?.remote.host ?? workingRepo?.forgeRepo?.host ?? null;
|
|
110
|
+
const checkoutOf = async (repository: string): Promise<string | null> => {
|
|
111
|
+
if (workingRepo?.slug && sameRepository(workingRepo.slug, repository)) return workingRepo.path;
|
|
112
|
+
return (await linkedMatch(repository))?.path ?? null;
|
|
113
|
+
};
|
|
114
|
+
const gitAutoMode = await (deps.loadGitAutoMode ?? defaultLoadGitAutoMode)(context).catch(
|
|
115
|
+
() => false,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
companionPath: context.companionPath,
|
|
120
|
+
workingRepo,
|
|
121
|
+
protectedPatterns: configuredProtectedPatterns(capabilities),
|
|
122
|
+
ticket: configuredTicketFormat(capabilities),
|
|
123
|
+
hostOf,
|
|
124
|
+
checkoutOf,
|
|
125
|
+
gitAutoMode,
|
|
126
|
+
};
|
|
127
|
+
}
|