@uniqbit/mate-core 0.18.5 → 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/server.ts +17 -2
- 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 +180 -138
- 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 +317 -7
- package/src/cli/commands/factory/factory.ts +301 -0
- package/src/cli/commands/install.ts +133 -9
- 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.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 +38 -20
- 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 +20 -1
- 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 +18 -22
- 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 +201 -43
- package/src/lib/orchestrator/adapters/opencode.ts +55 -2
- 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 +3 -2
- 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 -129
- package/src/lib/orchestrator/projection-companion-link.ts +12 -1
- package/src/lib/orchestrator/projection-entries.ts +100 -34
- 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 -1
- 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 +81 -11
- 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 -1
- 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/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 +50 -2
- 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 -11
- 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 -2
- 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/{claude/mate-openspec-backfill → agents/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/{agents/mate-openspec-backfill → claude/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 +163 -272
- 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/hydrate.ts +4 -3
- package/src/tools/setup/dynamic-plugins/install.ts +24 -28
- package/src/tools/setup/engine.ts +100 -23
- 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 +40 -0
- 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 +310 -8
- package/src/tools/setup/providers/opencode.ts +180 -1
- 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 +183 -26
- 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/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/tools/setup/git-utils.ts +0 -30
- package/src/tools/setup/runtime-documents.ts +0 -291
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeps Claude sessions an editor plugin started current in the Mate session
|
|
3
|
+
* registry, from Claude's own hook events. Any other session writes nothing.
|
|
4
|
+
*/
|
|
5
|
+
import {
|
|
6
|
+
addSession,
|
|
7
|
+
endSession,
|
|
8
|
+
isRegistered,
|
|
9
|
+
patchSession,
|
|
10
|
+
refreshSession,
|
|
11
|
+
startedByEditor,
|
|
12
|
+
type RegisteredSession,
|
|
13
|
+
type SessionInput,
|
|
14
|
+
type WriteOptions,
|
|
15
|
+
} from "../runtime/session-registry";
|
|
16
|
+
import { currentBranch } from "../runtime/current-branch";
|
|
17
|
+
import { PROJECTED_FLAG } from "../runtime/projected-flag";
|
|
18
|
+
import { resolveProjection } from "../runtime/projection";
|
|
19
|
+
import { readWrapStateSync } from "../runtime/wrap-state";
|
|
20
|
+
import { hookOutcome, runHook, type HookCall, type HookEnv, type HookOutcome } from "./hook-io";
|
|
21
|
+
|
|
22
|
+
export interface SessionRegisterDeps {
|
|
23
|
+
register: (input: SessionInput) => Promise<unknown>;
|
|
24
|
+
/** Updates a registered session; writes nothing for any other. */
|
|
25
|
+
refresh: (input: SessionInput) => Promise<unknown>;
|
|
26
|
+
registered: (id: string) => Promise<boolean>;
|
|
27
|
+
end: (id: string) => Promise<unknown>;
|
|
28
|
+
patch: (id: string, patch: Partial<RegisteredSession>) => Promise<unknown>;
|
|
29
|
+
branch: (cwd: string) => Promise<string | null>;
|
|
30
|
+
/** True when the Working Repository at `dir` is wrapped for Claude, so the wrap's hook copy runs. */
|
|
31
|
+
wrappedForClaude: (dir: string) => boolean;
|
|
32
|
+
now: () => Date;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Hooks skip a write they cannot lock within 2 s; the next event registers again. */
|
|
36
|
+
const HOOK_WRITE: WriteOptions = { lock: { waitMs: 2000 } };
|
|
37
|
+
|
|
38
|
+
export const sessionRegisterDeps: SessionRegisterDeps = {
|
|
39
|
+
register: (input) => addSession(input, HOOK_WRITE),
|
|
40
|
+
refresh: (input) => refreshSession(input, HOOK_WRITE),
|
|
41
|
+
registered: (id) => isRegistered(id, HOOK_WRITE),
|
|
42
|
+
end: (id) => endSession(id, HOOK_WRITE),
|
|
43
|
+
patch: (id, patch) => patchSession(id, patch, HOOK_WRITE),
|
|
44
|
+
branch: currentBranch,
|
|
45
|
+
wrappedForClaude: (dir) => {
|
|
46
|
+
const projection = resolveProjection(dir);
|
|
47
|
+
return !!projection && readWrapStateSync(projection.repoRoot).runtimes.has("claude");
|
|
48
|
+
},
|
|
49
|
+
now: () => new Date(),
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
interface ClaudeHookInput {
|
|
53
|
+
session_id?: unknown;
|
|
54
|
+
cwd?: unknown;
|
|
55
|
+
transcript_path?: unknown;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function stringField(value: unknown): string | undefined {
|
|
59
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function pidOf(env: HookEnv): number | undefined {
|
|
63
|
+
const pid = Number(env.CLAUDE_PID);
|
|
64
|
+
return Number.isInteger(pid) && pid > 0 ? pid : undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Registers the session of a `SessionStart` event when an editor plugin started
|
|
69
|
+
* it, else refreshes it if registered (a resume). Never throws: a registry
|
|
70
|
+
* failure must not touch the session.
|
|
71
|
+
*/
|
|
72
|
+
export async function registerClaudeSession(
|
|
73
|
+
env: HookEnv,
|
|
74
|
+
cwd: string,
|
|
75
|
+
input: unknown,
|
|
76
|
+
deps: SessionRegisterDeps = sessionRegisterDeps,
|
|
77
|
+
): Promise<void> {
|
|
78
|
+
const event = (input ?? {}) as ClaudeHookInput;
|
|
79
|
+
const id = stringField(event.session_id);
|
|
80
|
+
if (!id) return;
|
|
81
|
+
const dir = stringField(event.cwd) ?? cwd;
|
|
82
|
+
try {
|
|
83
|
+
const editor = startedByEditor(env);
|
|
84
|
+
// Any other session costs one registry read, no Git call.
|
|
85
|
+
if (!editor && !(await deps.registered(id))) return;
|
|
86
|
+
const branch = await deps.branch(dir).catch(() => null);
|
|
87
|
+
const transcript = stringField(event.transcript_path);
|
|
88
|
+
const pid = pidOf(env);
|
|
89
|
+
const entry: SessionInput = {
|
|
90
|
+
id,
|
|
91
|
+
runtime: "claude",
|
|
92
|
+
cwd: dir,
|
|
93
|
+
origin: "editor",
|
|
94
|
+
...(pid !== undefined ? { pid } : {}),
|
|
95
|
+
...(branch ? { branch } : {}),
|
|
96
|
+
...(transcript ? { transcript } : {}),
|
|
97
|
+
};
|
|
98
|
+
await (editor ? deps.register(entry) : deps.refresh(entry));
|
|
99
|
+
} catch {
|
|
100
|
+
/* best-effort */
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Legacy rule: wraps before `--projected` registered this copy bare, and only
|
|
106
|
+
* this hook re-wraps them. So a bare copy counts as the wrap's unless
|
|
107
|
+
* `CLAUDE_PLUGIN_ROOT`, set for plugin hooks only, marks it as the plugin's.
|
|
108
|
+
* Lives here, not in `session-prepare`, so the recording hooks load light.
|
|
109
|
+
*/
|
|
110
|
+
export function isWrapCopy({ argv, env }: Pick<HookCall, "argv" | "env">): boolean {
|
|
111
|
+
return argv.includes(PROJECTED_FLAG) || !env.CLAUDE_PLUGIN_ROOT;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Which hook copy registers: the wrap's always; the plugin's only where no wrap
|
|
116
|
+
* copy runs, i.e. a Mate launch in a repository not wrapped for Claude.
|
|
117
|
+
*/
|
|
118
|
+
export function registersHere(
|
|
119
|
+
wrapCopy: boolean,
|
|
120
|
+
dir: string,
|
|
121
|
+
deps: Pick<SessionRegisterDeps, "wrappedForClaude"> = sessionRegisterDeps,
|
|
122
|
+
): boolean {
|
|
123
|
+
if (wrapCopy) return true;
|
|
124
|
+
try {
|
|
125
|
+
return !deps.wrappedForClaude(dir);
|
|
126
|
+
} catch {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Applies `write` to the event's session when this hook copy records; always
|
|
133
|
+
* an empty outcome, and a failed write is dropped. The registry read comes
|
|
134
|
+
* first: most sessions are not registered, and the wrap check reads files.
|
|
135
|
+
*/
|
|
136
|
+
async function recordForSession(
|
|
137
|
+
call: HookCall,
|
|
138
|
+
wrapCopy: boolean,
|
|
139
|
+
deps: SessionRegisterDeps,
|
|
140
|
+
write: (id: string) => Promise<unknown>,
|
|
141
|
+
): Promise<HookOutcome> {
|
|
142
|
+
const event = (call.input ?? {}) as ClaudeHookInput;
|
|
143
|
+
const id = stringField(event.session_id);
|
|
144
|
+
const dir = stringField(event.cwd) ?? call.cwd;
|
|
145
|
+
if (!id || !(await deps.registered(id).catch(() => false))) return hookOutcome(null);
|
|
146
|
+
if (registersHere(wrapCopy, dir, deps)) await write(id).catch(() => {});
|
|
147
|
+
return hookOutcome(null);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** `SessionEnd`: records `endedAt` for a registered session. */
|
|
151
|
+
export function runSessionEndHook(
|
|
152
|
+
call: HookCall,
|
|
153
|
+
wrapCopy: boolean,
|
|
154
|
+
deps: SessionRegisterDeps = sessionRegisterDeps,
|
|
155
|
+
): Promise<HookOutcome> {
|
|
156
|
+
return recordForSession(call, wrapCopy, deps, (id) => deps.end(id));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** `Notification`: records when the session asked the user for input. */
|
|
160
|
+
export function runNotificationHook(
|
|
161
|
+
call: HookCall,
|
|
162
|
+
wrapCopy: boolean,
|
|
163
|
+
deps: SessionRegisterDeps = sessionRegisterDeps,
|
|
164
|
+
): Promise<HookOutcome> {
|
|
165
|
+
return recordForSession(call, wrapCopy, deps, (id) =>
|
|
166
|
+
deps.patch(id, { attentionAt: deps.now().toISOString() }),
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
type RecordingHook = (call: HookCall, wrapCopy: boolean) => Promise<HookOutcome>;
|
|
171
|
+
|
|
172
|
+
/** Shim entry for a recording hook; exits zero even when reading its input fails. */
|
|
173
|
+
function runRecordingHook(
|
|
174
|
+
hook: RecordingHook,
|
|
175
|
+
copyOf: (call: HookCall) => boolean,
|
|
176
|
+
argv: readonly string[],
|
|
177
|
+
): Promise<number> {
|
|
178
|
+
return runHook(
|
|
179
|
+
(input) => {
|
|
180
|
+
const call = { env: process.env, cwd: process.cwd(), argv, input };
|
|
181
|
+
return hook(call, copyOf(call));
|
|
182
|
+
},
|
|
183
|
+
() => hookOutcome(null),
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function runEnd(
|
|
188
|
+
copyOf: (call: HookCall) => boolean,
|
|
189
|
+
argv: readonly string[] = process.argv.slice(2),
|
|
190
|
+
): Promise<number> {
|
|
191
|
+
return runRecordingHook(runSessionEndHook, copyOf, argv);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function runNotification(
|
|
195
|
+
copyOf: (call: HookCall) => boolean,
|
|
196
|
+
argv: readonly string[] = process.argv.slice(2),
|
|
197
|
+
): Promise<number> {
|
|
198
|
+
return runRecordingHook(runNotificationHook, copyOf, argv);
|
|
199
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Route a Claude session's tokensave calls to the linked worktree it works in.
|
|
2
|
+
import { routeTokensaveInput, type RouteDeps } from "../runtime/tokensave-route";
|
|
3
|
+
import { hookOutcome, type HookOutcome } from "./hook-io";
|
|
4
|
+
|
|
5
|
+
interface TokensaveHookInput {
|
|
6
|
+
cwd?: unknown;
|
|
7
|
+
tool_name?: unknown;
|
|
8
|
+
tool_input?: unknown;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* `updatedInput` when the call should run against the session directory's
|
|
13
|
+
* worktree, else no output. Never a permission decision: the call keeps its
|
|
14
|
+
* own permission flow. Input-pure apart from `CLAUDE_PROJECT_DIR`, the start
|
|
15
|
+
* directory whose checkout the MCP server serves, so the plugin copy and a
|
|
16
|
+
* carried copy emit the same rewrite and the call is routed once either way.
|
|
17
|
+
*/
|
|
18
|
+
export function buildTokensaveRoute(input: unknown, deps?: RouteDeps): HookOutcome {
|
|
19
|
+
const { cwd, tool_name: tool, tool_input: toolInput } = (input ?? {}) as TokensaveHookInput;
|
|
20
|
+
const updatedInput =
|
|
21
|
+
typeof cwd === "string" && typeof tool === "string"
|
|
22
|
+
? routeTokensaveInput(tool, cwd, toolInput, {
|
|
23
|
+
servedDirectory: process.env.CLAUDE_PROJECT_DIR,
|
|
24
|
+
...deps,
|
|
25
|
+
})
|
|
26
|
+
: undefined;
|
|
27
|
+
return hookOutcome(
|
|
28
|
+
updatedInput ? { hookSpecificOutput: { hookEventName: "PreToolUse", updatedInput } } : null,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -12,12 +12,16 @@ import fs from "node:fs";
|
|
|
12
12
|
import os from "node:os";
|
|
13
13
|
import path from "node:path";
|
|
14
14
|
|
|
15
|
+
import { artifactRefusal, resolveArtifactTarget } from "../runtime/artifact-refusal";
|
|
16
|
+
import { checkCommitAttribution } from "../runtime/commit-attribution-guard";
|
|
15
17
|
import { gitEnvironment } from "../runtime/companion-git";
|
|
16
18
|
import { companionForkRefusal } from "../runtime/companion-sync";
|
|
17
19
|
import { readCompanionRuntimeContext } from "../runtime/env";
|
|
20
|
+
import { guardLaunchEnvironment } from "../runtime/launch-env-guard";
|
|
18
21
|
import { companionLinkPath } from "../runtime/repo-local";
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
import { checkSecretAccess, type SecretToolCall } from "../runtime/secret-guard";
|
|
23
|
+
import { stripHeredocBodies } from "../runtime/shell-heredoc";
|
|
24
|
+
import { hookFolder, type HookEnv } from "./hook-io";
|
|
21
25
|
|
|
22
26
|
export interface HookOutcome {
|
|
23
27
|
exitCode: number;
|
|
@@ -44,8 +48,9 @@ const ARTIFACT_PATH_MARKERS = [
|
|
|
44
48
|
"/docs/prd/",
|
|
45
49
|
];
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
const
|
|
51
|
+
/** `[ \t]`, not `\s`: a redirect or `tee` names its target on its own line. */
|
|
52
|
+
const MD_REDIRECT_PATTERN = />{1,2}[ \t]*([^\s;|&<>]+\.md)\b/g;
|
|
53
|
+
const MD_TEE_PATTERN = /\btee[ \t]+(?:-a[ \t]+)?([^\s;|&<>]+\.md)\b/g;
|
|
49
54
|
|
|
50
55
|
export function artifactLikePath(filePath: string): boolean {
|
|
51
56
|
if (!filePath) return false;
|
|
@@ -118,11 +123,6 @@ function claudeConfigRoot(env: HookEnv): string {
|
|
|
118
123
|
return path.normalize(path.join(env.HOME || os.homedir(), ".claude"));
|
|
119
124
|
}
|
|
120
125
|
|
|
121
|
-
function normalizePath(filePath: string, ctx: GuardContext): string {
|
|
122
|
-
if (path.isAbsolute(filePath)) return path.normalize(filePath);
|
|
123
|
-
return path.normalize(path.join(ctx.repoRoot, filePath));
|
|
124
|
-
}
|
|
125
|
-
|
|
126
126
|
function isUnder(target: string, root: string): boolean {
|
|
127
127
|
const relative = path.relative(path.normalize(root), path.normalize(target));
|
|
128
128
|
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
|
@@ -181,17 +181,14 @@ function isProductDocumentationPath(target: string, ctx: GuardContext): boolean
|
|
|
181
181
|
return false;
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
function blockWrite(target: string,
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
lines.push(`Note: CLAUDE.md already lives in the companion repo at ${companion}/CLAUDE.md.`);
|
|
193
|
-
}
|
|
194
|
-
return { exitCode: 2, stderr: lines.join("\n") + "\n" };
|
|
184
|
+
function blockWrite(target: string, resolved: string, ctx: GuardContext): HookOutcome {
|
|
185
|
+
const refusal = artifactRefusal({
|
|
186
|
+
target,
|
|
187
|
+
resolved,
|
|
188
|
+
companion: ctx.companion,
|
|
189
|
+
repoRoot: ctx.repoRoot,
|
|
190
|
+
});
|
|
191
|
+
return { exitCode: 2, stderr: `${refusal}\n` };
|
|
195
192
|
}
|
|
196
193
|
|
|
197
194
|
function checkFilePath(
|
|
@@ -201,7 +198,7 @@ function checkFilePath(
|
|
|
201
198
|
): HookOutcome | null {
|
|
202
199
|
if (!filePath) return null;
|
|
203
200
|
|
|
204
|
-
const normalized =
|
|
201
|
+
const normalized = resolveArtifactTarget(filePath, ctx.repoRoot);
|
|
205
202
|
if (isCompanionPath(normalized, ctx)) return null;
|
|
206
203
|
|
|
207
204
|
if (isUnder(normalized, claudeConfigRoot(ctx.env))) return null;
|
|
@@ -219,7 +216,7 @@ function checkFilePath(
|
|
|
219
216
|
return null;
|
|
220
217
|
}
|
|
221
218
|
|
|
222
|
-
return blockWrite(filePath, ctx
|
|
219
|
+
return blockWrite(filePath, normalized, ctx);
|
|
223
220
|
}
|
|
224
221
|
|
|
225
222
|
/**
|
|
@@ -234,17 +231,19 @@ async function checkForkedCompanion(
|
|
|
234
231
|
ctx: GuardContext,
|
|
235
232
|
): Promise<HookOutcome | null> {
|
|
236
233
|
if (!filePath || !artifactLikePath(filePath)) return null;
|
|
237
|
-
if (!isCompanionPath(
|
|
234
|
+
if (!isCompanionPath(resolveArtifactTarget(filePath, ctx.repoRoot), ctx)) return null;
|
|
238
235
|
|
|
239
236
|
const refusal = await companionForkRefusal(ctx.env, ctx.companion);
|
|
240
237
|
return refusal ? { exitCode: 2, stderr: `${refusal}\n` } : null;
|
|
241
238
|
}
|
|
242
239
|
|
|
240
|
+
/** Heredoc bodies are what a command writes, not what it runs: they are not scanned. */
|
|
243
241
|
export function commandMatches(command: string): string[] {
|
|
244
242
|
const targets: string[] = [];
|
|
243
|
+
const commandText = stripHeredocBodies(command);
|
|
245
244
|
for (const pattern of [MD_REDIRECT_PATTERN, MD_TEE_PATTERN]) {
|
|
246
245
|
const matcher = new RegExp(pattern.source, pattern.flags);
|
|
247
|
-
for (const match of
|
|
246
|
+
for (const match of commandText.matchAll(matcher)) {
|
|
248
247
|
const target = match[1].trim().replace(/^["']+|["']+$/g, "");
|
|
249
248
|
if (target) targets.push(target);
|
|
250
249
|
}
|
|
@@ -252,6 +251,53 @@ export function commandMatches(command: string): string[] {
|
|
|
252
251
|
return targets;
|
|
253
252
|
}
|
|
254
253
|
|
|
254
|
+
/** Claude tool payloads in the shape the shared secret guard reads. */
|
|
255
|
+
function secretToolCall(
|
|
256
|
+
toolName: string,
|
|
257
|
+
toolInput: Record<string, unknown>,
|
|
258
|
+
ctx: GuardContext,
|
|
259
|
+
): SecretToolCall | null {
|
|
260
|
+
const text = (value: unknown) => (typeof value === "string" ? value : "");
|
|
261
|
+
const target = (value: unknown) =>
|
|
262
|
+
text(value) ? resolveArtifactTarget(text(value), ctx.repoRoot) : "";
|
|
263
|
+
switch (toolName) {
|
|
264
|
+
case "Read":
|
|
265
|
+
return { kind: "read", paths: [target(toolInput.file_path)] };
|
|
266
|
+
case "Write":
|
|
267
|
+
return {
|
|
268
|
+
kind: "write",
|
|
269
|
+
writes: [{ path: target(toolInput.file_path), content: text(toolInput.content) }],
|
|
270
|
+
};
|
|
271
|
+
case "Edit":
|
|
272
|
+
return {
|
|
273
|
+
kind: "write",
|
|
274
|
+
writes: [{ path: target(toolInput.file_path), content: text(toolInput.new_string) }],
|
|
275
|
+
};
|
|
276
|
+
case "MultiEdit": {
|
|
277
|
+
const edits = Array.isArray(toolInput.edits) ? toolInput.edits : [];
|
|
278
|
+
const content = edits
|
|
279
|
+
.map((edit) => (edit && typeof edit === "object" ? text(edit.new_string) : ""))
|
|
280
|
+
.join("\n");
|
|
281
|
+
return { kind: "write", writes: [{ path: target(toolInput.file_path), content }] };
|
|
282
|
+
}
|
|
283
|
+
case "NotebookEdit":
|
|
284
|
+
return {
|
|
285
|
+
kind: "write",
|
|
286
|
+
writes: [{ path: target(toolInput.notebook_path), content: text(toolInput.new_source) }],
|
|
287
|
+
};
|
|
288
|
+
case "Bash":
|
|
289
|
+
return { kind: "shell", command: text(toolInput.command) };
|
|
290
|
+
case "Grep":
|
|
291
|
+
return {
|
|
292
|
+
kind: "search",
|
|
293
|
+
paths: [target(toolInput.path)],
|
|
294
|
+
globs: [text(toolInput.glob)],
|
|
295
|
+
};
|
|
296
|
+
default:
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
255
301
|
/**
|
|
256
302
|
* Fails open only when no Mate context resolves from either source; in a
|
|
257
303
|
* wrapped Working Repository the guard runs without a launch.
|
|
@@ -273,6 +319,16 @@ export async function evaluate(
|
|
|
273
319
|
? (input.tool_input as Record<string, unknown>)
|
|
274
320
|
: {};
|
|
275
321
|
|
|
322
|
+
/** Secrets first: a secret refusal wins over every artifact-placement verdict. */
|
|
323
|
+
const secretCall = secretToolCall(toolName, toolInput, ctx);
|
|
324
|
+
if (secretCall) {
|
|
325
|
+
const refusal = await checkSecretAccess(secretCall, {
|
|
326
|
+
companionPath: ctx.companion,
|
|
327
|
+
isCompanionPath: (target) => isCompanionPath(target, ctx),
|
|
328
|
+
});
|
|
329
|
+
if (refusal) return { exitCode: 2, stderr: `${refusal}\n` };
|
|
330
|
+
}
|
|
331
|
+
|
|
276
332
|
if (toolName === "Write" || toolName === "Edit" || toolName === "MultiEdit") {
|
|
277
333
|
const filePath = String(toolInput.file_path ?? "");
|
|
278
334
|
/** The path refusal wins when both apply: its message is not replaced. */
|
|
@@ -282,6 +338,9 @@ export async function evaluate(
|
|
|
282
338
|
|
|
283
339
|
if (toolName === "Bash") {
|
|
284
340
|
const command = String(toolInput.command ?? "");
|
|
341
|
+
const attribution = checkCommitAttribution(command);
|
|
342
|
+
if (attribution) return { exitCode: 2, stderr: `${attribution}\n` };
|
|
343
|
+
|
|
285
344
|
const targets = commandMatches(command);
|
|
286
345
|
for (const target of targets) {
|
|
287
346
|
const outcome = checkFilePath(target, ctx);
|
|
@@ -314,7 +373,13 @@ export async function run(): Promise<number> {
|
|
|
314
373
|
} catch {
|
|
315
374
|
payload = {};
|
|
316
375
|
}
|
|
317
|
-
|
|
376
|
+
// A background session can inherit another launch's environment from Claude's daemon.
|
|
377
|
+
guardLaunchEnvironment(process.env, process.cwd());
|
|
378
|
+
const outcome = await evaluate(
|
|
379
|
+
payload,
|
|
380
|
+
process.env,
|
|
381
|
+
hookFolder(payload, process.env, process.cwd()),
|
|
382
|
+
);
|
|
318
383
|
if (outcome.stderr) process.stderr.write(outcome.stderr);
|
|
319
384
|
return outcome.exitCode;
|
|
320
385
|
}
|
package/src/index.ts
CHANGED
|
@@ -39,13 +39,17 @@ export type {
|
|
|
39
39
|
McpService,
|
|
40
40
|
Plugin,
|
|
41
41
|
PluginCliCommand,
|
|
42
|
+
PluginDirectoryContribution,
|
|
42
43
|
PluginPolicy,
|
|
43
44
|
PluginRegistration,
|
|
44
45
|
ProviderHosting,
|
|
45
46
|
ProviderPlugin,
|
|
47
|
+
RuntimeContributions,
|
|
48
|
+
RuntimeContributionsByRuntime,
|
|
46
49
|
SetupContext,
|
|
47
50
|
TemplatesService,
|
|
48
51
|
} from "./tools/setup/plugin";
|
|
52
|
+
export type { SessionKind } from "./runtime/session-kind";
|
|
49
53
|
export type {
|
|
50
54
|
FrameworkType,
|
|
51
55
|
FrameworkConfig,
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { isSecretFile, type SecretPolicy } from "../../runtime/secret-patterns";
|
|
6
|
+
import type { ApplyPayload, ArtifactFingerprint } from "./protocol";
|
|
7
|
+
|
|
8
|
+
export interface FingerprintOptions {
|
|
9
|
+
/** Directories a referenced file must resolve into; nothing outside them is read. */
|
|
10
|
+
allowedRoots: string[];
|
|
11
|
+
secretPolicy: SecretPolicy;
|
|
12
|
+
readFile?: (filePath: string) => Promise<string>;
|
|
13
|
+
realpath?: (filePath: string) => Promise<string>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type FingerprintResult =
|
|
17
|
+
| {
|
|
18
|
+
ok: true;
|
|
19
|
+
/** Hashes with validated tracked checkbox states normalized; feeds the digest. */
|
|
20
|
+
fingerprints: ArtifactFingerprint[];
|
|
21
|
+
/** Hashes of the bytes as read; detects a file changing during collection. */
|
|
22
|
+
raw: ArtifactFingerprint[];
|
|
23
|
+
}
|
|
24
|
+
| { ok: false; reason: string };
|
|
25
|
+
|
|
26
|
+
/** A task checkbox line: indent, list marker, the state character, then the task text. */
|
|
27
|
+
const CHECKBOX = /^(\s*[-*+]\s+\[)([ xX])(\]\s+)(.*?)\s*$/;
|
|
28
|
+
|
|
29
|
+
interface TrackedTask {
|
|
30
|
+
id: string;
|
|
31
|
+
description: string;
|
|
32
|
+
done: boolean;
|
|
33
|
+
line: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function sha256(text: string): string {
|
|
37
|
+
return createHash("sha256").update(text).digest("hex");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function isUnder(child: string, root: string): boolean {
|
|
41
|
+
const relative = path.relative(root, child);
|
|
42
|
+
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Every file path the payload references: `contextFiles` values and task source paths. */
|
|
46
|
+
function referencedPaths(payload: ApplyPayload): string[] | string {
|
|
47
|
+
const paths = new Set<string>();
|
|
48
|
+
const contextFiles = payload.contextFiles;
|
|
49
|
+
if (contextFiles !== undefined) {
|
|
50
|
+
if (contextFiles === null || typeof contextFiles !== "object" || Array.isArray(contextFiles)) {
|
|
51
|
+
return "contextFiles has an unsupported shape";
|
|
52
|
+
}
|
|
53
|
+
for (const value of Object.values(contextFiles)) {
|
|
54
|
+
const list = Array.isArray(value) ? value : [value];
|
|
55
|
+
for (const entry of list) {
|
|
56
|
+
if (typeof entry !== "string") return "contextFiles has an unsupported shape";
|
|
57
|
+
paths.add(entry);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (Array.isArray(payload.tasks)) {
|
|
62
|
+
for (const task of payload.tasks as Record<string, unknown>[]) {
|
|
63
|
+
if (task && typeof task.sourcePath === "string") paths.add(task.sourcePath);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return [...paths].sort();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Tasks per source file; a string names the ambiguity that disables compaction. */
|
|
70
|
+
function trackedTasks(payload: ApplyPayload): Map<string, TrackedTask[]> | string {
|
|
71
|
+
const byFile = new Map<string, TrackedTask[]>();
|
|
72
|
+
if (!Array.isArray(payload.tasks)) return byFile;
|
|
73
|
+
const locations = new Set<string>();
|
|
74
|
+
for (const task of payload.tasks as Record<string, unknown>[]) {
|
|
75
|
+
if (!task || task.sourcePath === undefined) continue;
|
|
76
|
+
const { id, description, done, sourcePath, line } = task;
|
|
77
|
+
if (
|
|
78
|
+
typeof sourcePath !== "string" ||
|
|
79
|
+
typeof id !== "string" ||
|
|
80
|
+
typeof description !== "string" ||
|
|
81
|
+
typeof done !== "boolean" ||
|
|
82
|
+
typeof line !== "number" ||
|
|
83
|
+
!Number.isInteger(line) ||
|
|
84
|
+
line < 1
|
|
85
|
+
) {
|
|
86
|
+
return `task ${String(id)} has an unsupported source location`;
|
|
87
|
+
}
|
|
88
|
+
const location = `${sourcePath}:${line}`;
|
|
89
|
+
if (locations.has(location)) return `two tasks share the source location ${location}`;
|
|
90
|
+
locations.add(location);
|
|
91
|
+
const list = byFile.get(sourcePath) ?? [];
|
|
92
|
+
list.push({ id, description, done, line });
|
|
93
|
+
byFile.set(sourcePath, list);
|
|
94
|
+
}
|
|
95
|
+
return byFile;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Normalizes the checkbox state character of each task line that freshly parsed
|
|
100
|
+
* upstream tasks vouch for. Any line that does not match its task, by text or by
|
|
101
|
+
* state, makes the file ambiguous: every other byte stays significant.
|
|
102
|
+
*/
|
|
103
|
+
function normalizeTracked(content: string, tasks: TrackedTask[]): string | { reason: string } {
|
|
104
|
+
const lines = content.split("\n");
|
|
105
|
+
for (const task of tasks) {
|
|
106
|
+
const match = CHECKBOX.exec(lines[task.line - 1] ?? "");
|
|
107
|
+
if (!match || match[4] !== task.description.trim()) {
|
|
108
|
+
return { reason: `task ${task.id} does not match its source line ${task.line}` };
|
|
109
|
+
}
|
|
110
|
+
if ((match[2] !== " ") !== task.done) {
|
|
111
|
+
return { reason: `task ${task.id} state differs from its source line ${task.line}` };
|
|
112
|
+
}
|
|
113
|
+
lines[task.line - 1] = lines[task.line - 1].replace(
|
|
114
|
+
CHECKBOX,
|
|
115
|
+
(_all, open, _state, close, text) => `${open} ${close}${text}`,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
return lines.join("\n");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Read-only fingerprints of every referenced artifact. Files outside the allowed
|
|
123
|
+
* roots, secret files, unreadable files, and ambiguous task locations are never
|
|
124
|
+
* guessed around: they disable compaction with a reason.
|
|
125
|
+
*/
|
|
126
|
+
export async function fingerprintArtifacts(
|
|
127
|
+
payload: ApplyPayload,
|
|
128
|
+
options: FingerprintOptions,
|
|
129
|
+
): Promise<FingerprintResult> {
|
|
130
|
+
const readFile = options.readFile ?? ((filePath: string) => fs.readFile(filePath, "utf8"));
|
|
131
|
+
const realpath = options.realpath ?? fs.realpath;
|
|
132
|
+
const paths = referencedPaths(payload);
|
|
133
|
+
if (typeof paths === "string") return { ok: false, reason: paths };
|
|
134
|
+
const tracked = trackedTasks(payload);
|
|
135
|
+
if (typeof tracked === "string") return { ok: false, reason: tracked };
|
|
136
|
+
|
|
137
|
+
const roots: string[] = [];
|
|
138
|
+
for (const root of options.allowedRoots) {
|
|
139
|
+
roots.push(await realpath(root).catch(() => path.resolve(root)));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const fingerprints: ArtifactFingerprint[] = [];
|
|
143
|
+
const raw: ArtifactFingerprint[] = [];
|
|
144
|
+
for (const filePath of paths) {
|
|
145
|
+
if (!path.isAbsolute(filePath)) return { ok: false, reason: `${filePath} is not absolute` };
|
|
146
|
+
if (isSecretFile(filePath, options.secretPolicy)) {
|
|
147
|
+
return { ok: false, reason: `${path.basename(filePath)} is a secret file and is not read` };
|
|
148
|
+
}
|
|
149
|
+
let resolved: string;
|
|
150
|
+
try {
|
|
151
|
+
resolved = await realpath(filePath);
|
|
152
|
+
} catch {
|
|
153
|
+
return { ok: false, reason: `${filePath} is unreadable` };
|
|
154
|
+
}
|
|
155
|
+
if (!roots.some((root) => isUnder(resolved, root))) {
|
|
156
|
+
return { ok: false, reason: `${filePath} is outside the companion and Working Repository` };
|
|
157
|
+
}
|
|
158
|
+
if (isSecretFile(resolved, options.secretPolicy)) {
|
|
159
|
+
return { ok: false, reason: `${path.basename(resolved)} is a secret file and is not read` };
|
|
160
|
+
}
|
|
161
|
+
let content: string;
|
|
162
|
+
try {
|
|
163
|
+
content = await readFile(resolved);
|
|
164
|
+
} catch {
|
|
165
|
+
return { ok: false, reason: `${filePath} is unreadable` };
|
|
166
|
+
}
|
|
167
|
+
const tasks = tracked.get(filePath);
|
|
168
|
+
const normalized = tasks ? normalizeTracked(content, tasks) : content;
|
|
169
|
+
if (typeof normalized !== "string") return { ok: false, reason: normalized.reason };
|
|
170
|
+
fingerprints.push({ path: filePath, sha256: sha256(normalized) });
|
|
171
|
+
raw.push({ path: filePath, sha256: sha256(content) });
|
|
172
|
+
}
|
|
173
|
+
return { ok: true, fingerprints, raw };
|
|
174
|
+
}
|