@uniqbit/mate-core 0.18.5 → 0.21.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 +50 -2
- package/claude-plugin/hooks/rtk-worktree-git.mjs +58 -0
- 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 +25 -3
- package/opencode-plugin/src/tui.tsx +3 -1
- package/opencode-plugin/tui.tsx +4 -1
- package/package.json +53 -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 +147 -0
- package/src/cli/commands/artifact/delivery/link.ts +210 -0
- package/src/cli/commands/artifact/delivery/output.ts +104 -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 +144 -66
- package/src/cli/commands/doctor.ts +317 -7
- package/src/cli/commands/factory/factory.ts +311 -0
- package/src/cli/commands/install.ts +180 -45
- package/src/cli/commands/launch/claude.ts +2 -0
- package/src/cli/commands/launch/shared.ts +48 -16
- package/src/cli/commands/plugin/install.ts +36 -15
- 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 +186 -171
- package/src/cli/commands/report/markdown.ts +105 -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/shared/companion-selection.ts +3 -1
- package/src/cli/commands/studio/access.ts +6 -14
- package/src/cli/commands/studio/areas.ts +112 -33
- package/src/cli/commands/studio/companion-add.ts +87 -0
- package/src/cli/commands/studio/companion-removal.ts +86 -0
- package/src/cli/commands/studio/factory-credential.ts +35 -0
- package/src/cli/commands/studio/factory-git-tokens.ts +40 -0
- package/src/cli/commands/studio/factory-relay.ts +18 -0
- package/src/cli/commands/studio/graph-model.ts +61 -0
- package/src/cli/commands/studio/graph.ts +336 -0
- package/src/cli/commands/studio/index.ts +33 -6
- 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 +292 -20
- package/src/cli/commands/studio/repository-add.ts +116 -0
- package/src/cli/commands/studio/routes.ts +47 -6
- package/src/cli/commands/studio/selection.ts +170 -17
- package/src/cli/commands/studio/server.ts +552 -327
- package/src/cli/commands/studio/services.ts +120 -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 +128 -16
- 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 +599 -0
- package/src/cli/commands/studio/views/vault/view.ts +185 -0
- package/src/cli/commands/studio/workset-session.ts +164 -0
- package/src/cli/commands/unwrap.ts +19 -0
- package/src/cli/commands/update.ts +55 -9
- package/src/cli/commands/vscode/release-vsix.json +4 -0
- package/src/cli/commands/vscode/setup.ts +213 -0
- package/src/cli/commands/vscode/vsix.ts +114 -0
- package/src/cli/commands/working/cleanup.ts +83 -18
- 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 +547 -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 +48 -5
- 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/rtk-worktree-git.ts +48 -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 +121 -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/branch-template.ts +122 -0
- package/src/lib/delivery/branches.ts +152 -0
- package/src/lib/delivery/checkout.ts +102 -0
- package/src/lib/delivery/environment.ts +37 -0
- package/src/lib/delivery/forge.ts +279 -0
- package/src/lib/delivery/merge-git.ts +273 -0
- package/src/lib/delivery/overlap.ts +209 -0
- package/src/lib/delivery/record-delivery.ts +392 -0
- package/src/lib/delivery/record.ts +417 -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 +430 -0
- package/src/lib/delivery/stages.ts +111 -0
- package/src/lib/delivery/token.ts +24 -0
- package/src/lib/factory/attach-client.ts +123 -0
- package/src/lib/factory/attach.ts +178 -0
- package/src/lib/factory/broker.ts +187 -0
- package/src/lib/factory/bun-commands.ts +39 -0
- package/src/lib/factory/client.ts +113 -0
- package/src/lib/factory/clone-url.ts +39 -0
- package/src/lib/factory/command.ts +77 -0
- package/src/lib/factory/credential-store.ts +153 -0
- package/src/lib/factory/frames.ts +77 -0
- package/src/lib/factory/git-auth.ts +61 -0
- package/src/lib/factory/git-credential-store.ts +181 -0
- package/src/lib/factory/ids.ts +68 -0
- package/src/lib/factory/keyed-serial.ts +27 -0
- package/src/lib/factory/outcomes/actions.ts +130 -0
- package/src/lib/factory/outcomes/index.ts +457 -0
- package/src/lib/factory/outcomes/lifecycle.ts +212 -0
- package/src/lib/factory/outcomes/runs.ts +81 -0
- package/src/lib/factory/outcomes/sessions.ts +60 -0
- package/src/lib/factory/prepare.ts +55 -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 +498 -0
- package/src/lib/factory/runner/state.ts +233 -0
- package/src/lib/factory/runner/workflow.ts +546 -0
- package/src/lib/factory/runtime.ts +1081 -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-hub.ts +6 -1
- 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/engine-floor.ts +48 -0
- 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 +49 -3
- 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-entry.ts +42 -21
- package/src/lib/orchestrator/projection-claude-links.ts +230 -0
- package/src/lib/orchestrator/projection-claude-skills.ts +39 -131
- package/src/lib/orchestrator/projection-companion-link.ts +12 -1
- package/src/lib/orchestrator/projection-entries.ts +121 -51
- package/src/lib/orchestrator/projection-opencode-copies.ts +93 -32
- package/src/lib/orchestrator/projection-openspec-store.ts +54 -9
- package/src/lib/orchestrator/projection-runtime-documents.ts +81 -49
- package/src/lib/orchestrator/projection-types.ts +63 -1
- package/src/lib/orchestrator/refresh-working-claude-links.ts +89 -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 +87 -12
- package/src/lib/orchestrator/setup-compatibilities.ts +56 -70
- package/src/lib/orchestrator/types.ts +16 -2
- package/src/lib/orchestrator/umbrella-checkouts.ts +102 -0
- package/src/lib/orchestrator/working-repo-projection.ts +73 -10
- 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 +23 -1
- package/src/lib/package-paths.ts +37 -0
- package/src/lib/public-npm.ts +105 -43
- package/src/lib/runtime-directory-refresh.ts +17 -1
- package/src/lib/session-attribution.ts +52 -0
- package/src/lib/session-state.ts +355 -0
- package/src/lib/session-stop.ts +64 -0
- package/src/lib/update-checker.ts +7 -1
- package/src/lib/usage/aggregate.ts +202 -0
- package/src/lib/usage/cache.ts +87 -0
- package/src/lib/usage/claude-pricing.ts +71 -0
- package/src/lib/usage/claude.ts +189 -0
- package/src/lib/usage/collect.ts +56 -0
- package/src/lib/usage/opencode.ts +188 -0
- package/src/lib/usage/records.ts +80 -0
- package/src/lib/usage/rtk-database.ts +72 -0
- package/src/lib/usage/savings.ts +209 -0
- package/src/lib/usage/scope.ts +182 -0
- package/src/lib/usage/source.ts +102 -0
- package/src/lib/usage/types.ts +143 -0
- package/src/lib/usage/window.ts +37 -0
- package/src/lib/workset/factory-local.ts +157 -0
- package/src/lib/workset/record.ts +547 -0
- package/src/lib/workset/repositories.ts +148 -0
- package/src/lib/workset/stage.ts +148 -0
- package/src/lib/workset/stages.ts +113 -0
- package/src/lib/workset/worktree-include.ts +161 -0
- package/src/lib/workset/worktree-index.ts +120 -0
- package/src/lib/workset/worktree.ts +1388 -0
- package/src/opencode/background-server.ts +145 -0
- package/src/opencode/companion-hooks.ts +151 -9
- package/src/opencode/companion-policy.ts +54 -22
- package/src/opencode/enter-worktree.ts +320 -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-bg-isolation.ts +138 -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 +62 -12
- package/src/runtime/companion-guidance.ts +37 -12
- package/src/runtime/companion-instructions.ts +340 -0
- package/src/runtime/companion-lock.ts +30 -7
- package/src/runtime/current-branch.ts +24 -0
- package/src/runtime/entered-worktree.ts +24 -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/git-tracked.ts +60 -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-destination.ts +72 -0
- package/src/runtime/repo-local.ts +29 -2
- package/src/runtime/rtk-git-guard.ts +66 -0
- package/src/runtime/runtime-directory.ts +5 -0
- package/src/runtime/runtime-document-manifest.ts +290 -29
- package/src/runtime/runtime-document-manifest.typecheck.ts +10 -0
- package/src/runtime/secret-guard.ts +169 -0
- package/src/runtime/secret-patterns.ts +397 -0
- package/src/runtime/secret-policy-weakening.ts +122 -0
- package/src/runtime/secret-scan.ts +90 -0
- package/src/runtime/serving-claude-wrap.ts +41 -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/umbrella-folder.ts +56 -0
- package/src/runtime/wrap-state.ts +80 -15
- package/src/runtime/write-atomic.ts +64 -0
- package/src/studio.ts +163 -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 +217 -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 +70 -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 +106 -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-publish-artifact/SKILL.md +271 -0
- 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 +105 -20
- package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +91 -68
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +217 -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 +70 -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 +106 -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-publish-artifact/SKILL.md +271 -0
- 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 +105 -20
- package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +91 -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 +4581 -397
- 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 +97 -1
- 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 +65 -21
- package/src/tools/setup/dynamic-plugins/frozen.ts +32 -13
- package/src/tools/setup/dynamic-plugins/hydrate.ts +8 -7
- package/src/tools/setup/dynamic-plugins/install.ts +46 -48
- package/src/tools/setup/dynamic-plugins/loader.ts +11 -7
- package/src/tools/setup/dynamic-plugins/paths.ts +30 -10
- package/src/tools/setup/dynamic-plugins/verify.ts +10 -7
- package/src/tools/setup/dynamic-plugins/workspaces.ts +153 -0
- 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 +88 -13
- package/src/tools/setup/package-managers/uv.ts +73 -11
- package/src/tools/setup/plugin.ts +40 -0
- package/src/tools/setup/plugins/gitignore.ts +15 -9
- 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 +89 -19
- package/src/tools/setup/providers/claude-worktree-plugins.ts +122 -0
- package/src/tools/setup/providers/claude.ts +332 -8
- package/src/tools/setup/providers/opencode.ts +180 -1
- package/src/tools/setup/utils.ts +22 -6
- package/src/tools/setup/working-repo-cleanup.ts +30 -2
- package/src/tools/setup/working-repo-local-state.ts +252 -75
- package/src/tools/setup.ts +196 -28
- package/studio-dist/client/assets/app-D9cw6szy.css +2 -0
- package/studio-dist/client/assets/artifacts-WD2ZXYrx.js +1 -0
- package/studio-dist/client/assets/button-Br0O1sXw.js +1 -0
- package/studio-dist/client/assets/combobox-DA7RAUUZ.js +1 -0
- package/studio-dist/client/assets/companion-view-CrabvxS8.js +1 -0
- package/studio-dist/client/assets/dist-Dm7MtyHc.js +5 -0
- package/studio-dist/client/assets/factory-DGS0E16C.js +6 -0
- package/studio-dist/client/assets/fields-6aXBpFhJ.js +1 -0
- package/studio-dist/client/assets/getting-started-Clde4w6P.js +1 -0
- package/studio-dist/client/assets/getting-started-D6kgWwWZ.js +1 -0
- package/studio-dist/client/assets/getting-started._topic-BiunccbT.js +1 -0
- package/studio-dist/client/assets/getting-started.index-DpiNoGw8.js +1 -0
- package/studio-dist/client/assets/graph-B_TCBVbu.js +2 -0
- package/studio-dist/client/assets/graph-canvas-Ba37Y5AE.js +3242 -0
- package/studio-dist/client/assets/guides-Du_RtJxP.js +1 -0
- package/studio-dist/client/assets/index-Df8L1LQa.js +40 -0
- package/studio-dist/client/assets/jsx-runtime-MZURdZre.js +1 -0
- package/studio-dist/client/assets/markdown-view-BOX6x0rL.js +1 -0
- package/studio-dist/client/assets/panel-dbmCx7Mx.js +1 -0
- package/studio-dist/client/assets/preload-helper-BLdHbfdN.js +1 -0
- package/studio-dist/client/assets/queries-RvHeXY12.js +1 -0
- package/studio-dist/client/assets/react-3QStrcDO.js +27 -0
- package/studio-dist/client/assets/report-url-XRL0x1SY.js +1 -0
- package/studio-dist/client/assets/reports-r3IK7Doz.js +1 -0
- package/studio-dist/client/assets/routes-C0A5LTFc.js +1 -0
- package/studio-dist/client/assets/select-CnaMd617.js +1 -0
- package/studio-dist/client/assets/skills-CzjzHpBT.js +1 -0
- package/studio-dist/client/assets/specs-B0ldF_6J.js +1 -0
- package/studio-dist/client/assets/specs-view-BnCLA0gW.js +1 -0
- package/studio-dist/client/assets/spinner-Dcm3fqK1.js +1 -0
- package/studio-dist/client/assets/steps-C0p2N1Pb.js +1 -0
- package/studio-dist/client/assets/store-Dw34catY.js +1 -0
- package/studio-dist/client/assets/studio-Cpz_HRHp.js +100 -0
- package/studio-dist/client/assets/studio-queries-ibmpFo6R.js +2 -0
- package/studio-dist/client/assets/terminal-eU5fzQzv.css +1 -0
- package/studio-dist/client/assets/usage-C2QJ_0IZ.js +55 -0
- package/studio-dist/client/assets/useAnchoredPopupScrollLock-Bj-FWb8z.js +1 -0
- package/studio-dist/client/assets/useMutation-aAr2uiay.js +1 -0
- package/studio-dist/client/assets/useSelector-AYcH7lB0.js +2 -0
- package/studio-dist/client/assets/vault-BGcxkSIY.js +1 -0
- package/studio-dist/client/assets/warnings-R1cE1rLf.js +1 -0
- package/studio-dist/client/assets/wasm-inline-C2en61B5.js +1 -0
- package/studio-dist/client/assets/workflow-C2qTrMDH.js +1 -0
- package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-Bn896ZYj.js +122 -0
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +162 -0
- package/studio-dist/server/assets/actions-D8erOphH.js +44 -0
- package/studio-dist/server/assets/actions-DYSv-9VV.js +60 -0
- package/studio-dist/server/assets/artifacts-DnF9L3dZ.js +216 -0
- package/studio-dist/server/assets/button-CgOIVdmD.js +10240 -0
- package/studio-dist/server/assets/combobox-DV_s9W0s.js +483 -0
- package/studio-dist/server/assets/companion-view-BKVXD3TO.js +39 -0
- package/studio-dist/server/assets/companions-C7fctnU9.js +31 -0
- package/studio-dist/server/assets/createServerRpc-bFKFpGFG.js +11 -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-C7Ybg0xG.js +3075 -0
- package/studio-dist/server/assets/factory-Df5uAHjb.js +116 -0
- package/studio-dist/server/assets/fields-BbieQTD0.js +1190 -0
- package/studio-dist/server/assets/getting-started-B136TP57.js +4 -0
- package/studio-dist/server/assets/getting-started-CRxMWorQ.js +67 -0
- package/studio-dist/server/assets/getting-started._topic-DJKQAzYl.js +13 -0
- package/studio-dist/server/assets/getting-started.index-D84gec1t.js +13 -0
- package/studio-dist/server/assets/graph-CSje3029.js +801 -0
- package/studio-dist/server/assets/graph-DDZzXM1L.js +16 -0
- package/studio-dist/server/assets/graph-canvas-22bWB5-2.js +21066 -0
- package/studio-dist/server/assets/graph-wire-BdSUx0G5.js +58 -0
- package/studio-dist/server/assets/guides-D9dk1Frq.js +13 -0
- package/studio-dist/server/assets/guides-IE-19POz.js +5 -0
- package/studio-dist/server/assets/guides.server-vcYRY5wx.js +66 -0
- package/studio-dist/server/assets/jsx-runtime-Bt0s0YKS.js +451 -0
- package/studio-dist/server/assets/markdown-view-BR8dJ7aR.js +105 -0
- package/studio-dist/server/assets/model-PyPALjii.js +18 -0
- package/studio-dist/server/assets/panel-BR_t9iMM.js +169 -0
- package/studio-dist/server/assets/queries-DWoTin-q.js +32 -0
- package/studio-dist/server/assets/react-CdqSUhaL.js +89 -0
- package/studio-dist/server/assets/redirect-BaZ_QyqF.js +39 -0
- package/studio-dist/server/assets/report-url-BUXPcE_8.js +9 -0
- package/studio-dist/server/assets/reports-CQ9qQ1-n.js +141 -0
- package/studio-dist/server/assets/reports-dYDEoBeq.js +18 -0
- package/studio-dist/server/assets/router-DkRHNTpE.js +11638 -0
- package/studio-dist/server/assets/routes-B6GfOew4.js +473 -0
- package/studio-dist/server/assets/search-BJnWLfkG.js +55 -0
- package/studio-dist/server/assets/select-Af7Wibii.js +1609 -0
- package/studio-dist/server/assets/shell-Hq-hXgnT.js +53 -0
- package/studio-dist/server/assets/skills-B7nEuVbx.js +267 -0
- package/studio-dist/server/assets/skills-B_YYL7q8.js +28 -0
- package/studio-dist/server/assets/specs-BpLUFntA.js +51 -0
- package/studio-dist/server/assets/specs-view-0peMVd22.js +426 -0
- package/studio-dist/server/assets/spinner-CdwJW4VB.js +20 -0
- package/studio-dist/server/assets/start-h3ICWwd2.js +36 -0
- package/studio-dist/server/assets/steps-D56DApvK.js +181 -0
- package/studio-dist/server/assets/store-Cs17okNG.js +280 -0
- package/studio-dist/server/assets/studio-CAcKp3bM.js +10340 -0
- package/studio-dist/server/assets/studio-queries-BtRGzDdh.js +1451 -0
- package/studio-dist/server/assets/usage-COdjd1gD.js +25570 -0
- package/studio-dist/server/assets/usage-f6pqE1tm.js +24 -0
- package/studio-dist/server/assets/useAnchoredPopupScrollLock-DlBKHRw7.js +756 -0
- package/studio-dist/server/assets/useMutation-DzTZGenE.js +690 -0
- package/studio-dist/server/assets/useSelector-DUmCUXAs.js +3387 -0
- package/studio-dist/server/assets/utils-C9CX1kcy.js +221 -0
- package/studio-dist/server/assets/vault-BDuIUq0F.js +1035 -0
- package/studio-dist/server/assets/vault-BVLp6zu3.js +85 -0
- package/studio-dist/server/assets/views-flRUr21z.js +80 -0
- package/studio-dist/server/assets/warnings-CDy9pdgL.js +24 -0
- package/studio-dist/server/assets/wasm-inline-CNeBKGwC.js +3 -0
- package/studio-dist/server/assets/workflow-D9GKI2EV.js +680 -0
- package/studio-dist/server/server.js +16640 -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/report/collector.ts +0 -288
- 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/templates/mate-skills/agents/mate-artifact-publish/SKILL.md +0 -185
- package/src/templates/mate-skills/claude/mate-artifact-publish/SKILL.md +0 -185
- package/src/tools/setup/git-utils.ts +0 -30
- package/src/tools/setup/runtime-documents.ts +0 -291
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/** Prepares a plain Claude session in a Claude-wrapped repository as `mate claude` would. */
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
|
|
4
|
+
import { errorMessage } from "../runtime/error-message";
|
|
4
5
|
import { unmanagedClaudeDelivery } from "../runtime/claude-delivery-plan";
|
|
5
6
|
import { hasLaunchEnvironment } from "../runtime/env";
|
|
6
|
-
import {
|
|
7
|
+
import { FRAMEWORK_NAME } from "../runtime/framework";
|
|
8
|
+
import { projectionCheckout, resolveProjection } from "../runtime/projection";
|
|
7
9
|
import { runtimeDirectoryPath, runtimeMateBin } from "../runtime/runtime-directory";
|
|
8
10
|
import {
|
|
9
11
|
PREPARE_TIMEOUT_MS,
|
|
@@ -12,12 +14,22 @@ import {
|
|
|
12
14
|
type PrepareRun,
|
|
13
15
|
type PrepareRunner,
|
|
14
16
|
} from "../runtime/session-prepare-runner";
|
|
15
|
-
import type
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
import { instructionHookPayload, type InstructionHookDeps } from "./companion-instructions";
|
|
18
|
+
import {
|
|
19
|
+
hookFolder,
|
|
20
|
+
hookOutcome,
|
|
21
|
+
runHook,
|
|
22
|
+
type HookCall,
|
|
23
|
+
type HookEnv,
|
|
24
|
+
type HookOutcome,
|
|
25
|
+
} from "./hook-io";
|
|
26
|
+
import {
|
|
27
|
+
isWrapCopy,
|
|
28
|
+
registerClaudeSession,
|
|
29
|
+
registersHere,
|
|
30
|
+
sessionRegisterDeps,
|
|
31
|
+
type SessionRegisterDeps,
|
|
32
|
+
} from "./session-register";
|
|
21
33
|
|
|
22
34
|
export interface SessionPrepareHookDeps {
|
|
23
35
|
/** The runtime-directory launcher; `null` until a `mate` run wrote it. */
|
|
@@ -25,6 +37,10 @@ export interface SessionPrepareHookDeps {
|
|
|
25
37
|
runner: (mateBin: string, repoPath: string) => PrepareRunner;
|
|
26
38
|
startSync: (mateBin: string, repoPath: string) => void;
|
|
27
39
|
timeoutMs: number;
|
|
40
|
+
/** The main thread's instruction read, after the prepare. */
|
|
41
|
+
instructions?: InstructionHookDeps;
|
|
42
|
+
/** Session registry writes; defaults to the real registry. */
|
|
43
|
+
registry?: SessionRegisterDeps;
|
|
28
44
|
}
|
|
29
45
|
|
|
30
46
|
export const sessionPrepareHookDeps: SessionPrepareHookDeps = {
|
|
@@ -37,27 +53,32 @@ export const sessionPrepareHookDeps: SessionPrepareHookDeps = {
|
|
|
37
53
|
timeoutMs: PREPARE_TIMEOUT_MS,
|
|
38
54
|
};
|
|
39
55
|
|
|
40
|
-
const INERT: SessionPrepareHookOutcome = { exitCode: 0, stdout: "" };
|
|
41
|
-
|
|
42
56
|
/** `systemMessage` only: the model must never be told to repair the companion. */
|
|
43
|
-
function operatorMessage(lines: string[]):
|
|
44
|
-
|
|
45
|
-
return { exitCode: 0, stdout: `${JSON.stringify({ systemMessage: lines.join("\n") })}\n` };
|
|
57
|
+
function operatorMessage(lines: string[]): HookOutcome {
|
|
58
|
+
return hookOutcome(lines.length > 0 ? { systemMessage: lines.join("\n") } : null);
|
|
46
59
|
}
|
|
47
60
|
|
|
48
61
|
async function runLocalPhase(
|
|
49
62
|
deps: SessionPrepareHookDeps,
|
|
50
63
|
mateBin: string,
|
|
51
|
-
|
|
64
|
+
checkoutRoot: string,
|
|
52
65
|
): Promise<PrepareRun> {
|
|
53
|
-
const pending = deps.runner(mateBin,
|
|
66
|
+
const pending = deps.runner(mateBin, checkoutRoot)({ sync: false, timeoutMs: deps.timeoutMs });
|
|
54
67
|
try {
|
|
55
68
|
return await pending;
|
|
56
69
|
} catch (error) {
|
|
57
|
-
return { ok: false, notes: [
|
|
70
|
+
return { ok: false, notes: [errorMessage(error)] };
|
|
58
71
|
}
|
|
59
72
|
}
|
|
60
73
|
|
|
74
|
+
/** The local phase's notes, and the Git sync it leaves for the caller to start. */
|
|
75
|
+
interface Prepared {
|
|
76
|
+
notes: string[];
|
|
77
|
+
startSync: () => void;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const NO_SYNC = (): void => {};
|
|
81
|
+
|
|
61
82
|
/**
|
|
62
83
|
* Inert under a launch environment or where the plan gives it nothing to own.
|
|
63
84
|
* Awaits the local phase within a bound, then starts Git sync detached. Always
|
|
@@ -67,35 +88,117 @@ export async function runSessionPrepareHook(
|
|
|
67
88
|
env: HookEnv,
|
|
68
89
|
cwd: string = process.cwd(),
|
|
69
90
|
deps: SessionPrepareHookDeps = sessionPrepareHookDeps,
|
|
70
|
-
): Promise<
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
91
|
+
): Promise<HookOutcome> {
|
|
92
|
+
const prepared = await guardedPrepare(env, hookFolder(null, env, cwd), deps);
|
|
93
|
+
return operatorMessage([...prepared.notes, ...startSync(prepared)]);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function prepareFailure(error: unknown): string {
|
|
97
|
+
return `${FRAMEWORK_NAME}: session prepare failed: ${errorMessage(error)}`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** A prepare that throws becomes a note, so the instructions after it still go out. */
|
|
101
|
+
async function guardedPrepare(
|
|
102
|
+
env: HookEnv,
|
|
103
|
+
folder: string,
|
|
104
|
+
deps: SessionPrepareHookDeps,
|
|
105
|
+
): Promise<Prepared> {
|
|
106
|
+
try {
|
|
107
|
+
return await prepare(env, folder, deps);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
return { notes: [prepareFailure(error)], startSync: NO_SYNC };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** A sync that fails to start becomes a note. */
|
|
114
|
+
function startSync(prepared: Prepared): string[] {
|
|
115
|
+
try {
|
|
116
|
+
prepared.startSync();
|
|
117
|
+
return [];
|
|
118
|
+
} catch (error) {
|
|
119
|
+
return [prepareFailure(error)];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Prepares the Checkout the session serves, a borrowing worktree's own root included. */
|
|
124
|
+
async function prepare(
|
|
125
|
+
env: HookEnv,
|
|
126
|
+
folder: string,
|
|
127
|
+
deps: SessionPrepareHookDeps,
|
|
128
|
+
): Promise<Prepared> {
|
|
129
|
+
const nothing = { notes: [], startSync: NO_SYNC };
|
|
130
|
+
if (hasLaunchEnvironment(env)) return nothing;
|
|
131
|
+
const projection = resolveProjection(folder);
|
|
132
|
+
if (!projection) return nothing;
|
|
133
|
+
const checkoutRoot = projectionCheckout(projection);
|
|
134
|
+
const plan = unmanagedClaudeDelivery(checkoutRoot);
|
|
76
135
|
const reconciles = plan.reconcile === "prepare-hook";
|
|
77
136
|
const syncs = plan.gitSync === "prepare-hook";
|
|
78
|
-
if (!reconciles && !syncs) return
|
|
137
|
+
if (!reconciles && !syncs) return nothing;
|
|
79
138
|
|
|
80
139
|
const mateBin = deps.mateBin();
|
|
81
140
|
if (!mateBin) {
|
|
82
|
-
return
|
|
83
|
-
|
|
84
|
-
|
|
141
|
+
return {
|
|
142
|
+
notes: [
|
|
143
|
+
`${FRAMEWORK_NAME}: session prepare skipped: ${runtimeDirectoryPath()} is missing; run \`${FRAMEWORK_NAME}\` once to repair it.`,
|
|
144
|
+
],
|
|
145
|
+
startSync: NO_SYNC,
|
|
146
|
+
};
|
|
85
147
|
}
|
|
86
148
|
|
|
87
149
|
const local = reconciles
|
|
88
|
-
? await runLocalPhase(deps, mateBin,
|
|
150
|
+
? await runLocalPhase(deps, mateBin, checkoutRoot)
|
|
89
151
|
: { ok: true, notes: [] };
|
|
90
|
-
if (syncs) deps.startSync(mateBin, projectDir);
|
|
91
|
-
|
|
92
152
|
const verdict = local.ok ? "warning" : "failed";
|
|
93
|
-
return
|
|
153
|
+
return {
|
|
154
|
+
notes: local.notes.map((note) => `${FRAMEWORK_NAME}: session prepare ${verdict}: ${note}`),
|
|
155
|
+
startSync: syncs ? () => deps.startSync(mateBin, checkoutRoot) : NO_SYNC,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The prepare, the main thread's Companion Instructions, then the Git sync, in
|
|
161
|
+
* one hook: Claude Code runs an event's hooks in parallel, and the prepare and
|
|
162
|
+
* a fast-forward both rewrite the files the instructions are read from. Only
|
|
163
|
+
* the wrap's copy runs any. Input that is not a JSON object is no event.
|
|
164
|
+
*/
|
|
165
|
+
export async function runSessionStartHook(
|
|
166
|
+
call: HookCall,
|
|
167
|
+
deps: SessionPrepareHookDeps = sessionPrepareHookDeps,
|
|
168
|
+
): Promise<HookOutcome> {
|
|
169
|
+
const { env, cwd, input } = call;
|
|
170
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) return hookOutcome(null);
|
|
171
|
+
const registry = deps.registry ?? sessionRegisterDeps;
|
|
172
|
+
const wrapCopy = isWrapCopy(call);
|
|
173
|
+
const folder = hookFolder(input, env, cwd);
|
|
174
|
+
// Registration never throws; it runs beside the prepare, off its critical path.
|
|
175
|
+
const registering = registersHere(wrapCopy, folder, registry)
|
|
176
|
+
? registerClaudeSession(env, cwd, input, registry)
|
|
177
|
+
: Promise.resolve();
|
|
178
|
+
if (!wrapCopy) {
|
|
179
|
+
await registering;
|
|
180
|
+
return hookOutcome(null);
|
|
181
|
+
}
|
|
182
|
+
const [prepared] = await Promise.all([guardedPrepare(env, folder, deps), registering]);
|
|
183
|
+
const { hookSpecificOutput, systemMessage } =
|
|
184
|
+
instructionHookPayload(
|
|
185
|
+
{ env, cwd, input, projected: true, directory: folder },
|
|
186
|
+
deps.instructions,
|
|
187
|
+
) ?? {};
|
|
188
|
+
const notes = [...prepared.notes, ...startSync(prepared)];
|
|
189
|
+
const messages = systemMessage ? [...notes, systemMessage] : notes;
|
|
190
|
+
if (!hookSpecificOutput) return operatorMessage(messages);
|
|
191
|
+
return hookOutcome({
|
|
192
|
+
hookSpecificOutput,
|
|
193
|
+
...(messages.length > 0 ? { systemMessage: messages.join("\n") } : {}),
|
|
194
|
+
});
|
|
94
195
|
}
|
|
95
196
|
|
|
96
|
-
/** Plugin-shim entry. */
|
|
97
|
-
export
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
197
|
+
/** Plugin-shim entry; exits zero even when reading its input fails. */
|
|
198
|
+
export function run(argv: readonly string[] = process.argv.slice(2)): Promise<number> {
|
|
199
|
+
return runHook(
|
|
200
|
+
(input) => runSessionStartHook({ env: process.env, cwd: process.cwd(), argv, input }),
|
|
201
|
+
(error) =>
|
|
202
|
+
operatorMessage([`${FRAMEWORK_NAME}: session start hook failed: ${errorMessage(error)}`]),
|
|
203
|
+
);
|
|
101
204
|
}
|
|
@@ -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,84 @@ export function commandMatches(command: string): string[] {
|
|
|
252
251
|
return targets;
|
|
253
252
|
}
|
|
254
253
|
|
|
254
|
+
const stringOrEmpty = (value: unknown) => (typeof value === "string" ? value : "");
|
|
255
|
+
|
|
256
|
+
function replacement(edit: Record<string, unknown>) {
|
|
257
|
+
return {
|
|
258
|
+
oldText: stringOrEmpty(edit.old_string),
|
|
259
|
+
newText: stringOrEmpty(edit.new_string),
|
|
260
|
+
all: edit.replace_all === true,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Claude tool payloads in the shape the shared secret guard reads. */
|
|
265
|
+
function secretToolCall(
|
|
266
|
+
toolName: string,
|
|
267
|
+
toolInput: Record<string, unknown>,
|
|
268
|
+
ctx: GuardContext,
|
|
269
|
+
): SecretToolCall | null {
|
|
270
|
+
const text = (value: unknown) => (typeof value === "string" ? value : "");
|
|
271
|
+
const target = (value: unknown) =>
|
|
272
|
+
text(value) ? resolveArtifactTarget(text(value), ctx.repoRoot) : "";
|
|
273
|
+
switch (toolName) {
|
|
274
|
+
case "Read":
|
|
275
|
+
return { kind: "read", paths: [target(toolInput.file_path)] };
|
|
276
|
+
case "Write":
|
|
277
|
+
return {
|
|
278
|
+
kind: "write",
|
|
279
|
+
writes: [{ path: target(toolInput.file_path), content: text(toolInput.content) }],
|
|
280
|
+
};
|
|
281
|
+
case "Edit":
|
|
282
|
+
return {
|
|
283
|
+
kind: "write",
|
|
284
|
+
writes: [
|
|
285
|
+
{
|
|
286
|
+
path: target(toolInput.file_path),
|
|
287
|
+
content: text(toolInput.new_string),
|
|
288
|
+
result: { kind: "replace", edits: [replacement(toolInput)] },
|
|
289
|
+
},
|
|
290
|
+
],
|
|
291
|
+
};
|
|
292
|
+
case "MultiEdit": {
|
|
293
|
+
const edits = (Array.isArray(toolInput.edits) ? toolInput.edits : []).map((edit) =>
|
|
294
|
+
edit && typeof edit === "object" ? (edit as Record<string, unknown>) : {},
|
|
295
|
+
);
|
|
296
|
+
const content = edits.map((edit) => text(edit.new_string)).join("\n");
|
|
297
|
+
return {
|
|
298
|
+
kind: "write",
|
|
299
|
+
writes: [
|
|
300
|
+
{
|
|
301
|
+
path: target(toolInput.file_path),
|
|
302
|
+
content,
|
|
303
|
+
result: { kind: "replace", edits: edits.map(replacement) },
|
|
304
|
+
},
|
|
305
|
+
],
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
case "NotebookEdit":
|
|
309
|
+
return {
|
|
310
|
+
kind: "write",
|
|
311
|
+
writes: [
|
|
312
|
+
{
|
|
313
|
+
path: target(toolInput.notebook_path),
|
|
314
|
+
content: text(toolInput.new_source),
|
|
315
|
+
result: { kind: "unknown" },
|
|
316
|
+
},
|
|
317
|
+
],
|
|
318
|
+
};
|
|
319
|
+
case "Bash":
|
|
320
|
+
return { kind: "shell", command: text(toolInput.command) };
|
|
321
|
+
case "Grep":
|
|
322
|
+
return {
|
|
323
|
+
kind: "search",
|
|
324
|
+
paths: [target(toolInput.path)],
|
|
325
|
+
globs: [text(toolInput.glob)],
|
|
326
|
+
};
|
|
327
|
+
default:
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
255
332
|
/**
|
|
256
333
|
* Fails open only when no Mate context resolves from either source; in a
|
|
257
334
|
* wrapped Working Repository the guard runs without a launch.
|
|
@@ -273,6 +350,16 @@ export async function evaluate(
|
|
|
273
350
|
? (input.tool_input as Record<string, unknown>)
|
|
274
351
|
: {};
|
|
275
352
|
|
|
353
|
+
/** Secrets first: a secret refusal wins over every artifact-placement verdict. */
|
|
354
|
+
const secretCall = secretToolCall(toolName, toolInput, ctx);
|
|
355
|
+
if (secretCall) {
|
|
356
|
+
const refusal = await checkSecretAccess(secretCall, {
|
|
357
|
+
companionPath: ctx.companion,
|
|
358
|
+
isCompanionPath: (target) => isCompanionPath(target, ctx),
|
|
359
|
+
});
|
|
360
|
+
if (refusal) return { exitCode: 2, stderr: `${refusal}\n` };
|
|
361
|
+
}
|
|
362
|
+
|
|
276
363
|
if (toolName === "Write" || toolName === "Edit" || toolName === "MultiEdit") {
|
|
277
364
|
const filePath = String(toolInput.file_path ?? "");
|
|
278
365
|
/** The path refusal wins when both apply: its message is not replaced. */
|
|
@@ -282,6 +369,9 @@ export async function evaluate(
|
|
|
282
369
|
|
|
283
370
|
if (toolName === "Bash") {
|
|
284
371
|
const command = String(toolInput.command ?? "");
|
|
372
|
+
const attribution = checkCommitAttribution(command);
|
|
373
|
+
if (attribution) return { exitCode: 2, stderr: `${attribution}\n` };
|
|
374
|
+
|
|
285
375
|
const targets = commandMatches(command);
|
|
286
376
|
for (const target of targets) {
|
|
287
377
|
const outcome = checkFilePath(target, ctx);
|
|
@@ -314,7 +404,13 @@ export async function run(): Promise<number> {
|
|
|
314
404
|
} catch {
|
|
315
405
|
payload = {};
|
|
316
406
|
}
|
|
317
|
-
|
|
407
|
+
// A background session can inherit another launch's environment from Claude's daemon.
|
|
408
|
+
guardLaunchEnvironment(process.env, process.cwd());
|
|
409
|
+
const outcome = await evaluate(
|
|
410
|
+
payload,
|
|
411
|
+
process.env,
|
|
412
|
+
hookFolder(payload, process.env, process.cwd()),
|
|
413
|
+
);
|
|
318
414
|
if (outcome.stderr) process.stderr.write(outcome.stderr);
|
|
319
415
|
return outcome.exitCode;
|
|
320
416
|
}
|