@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
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { checkoutAt } from "./git-layout";
|
|
6
|
+
|
|
7
|
+
type IsolationEnv = Readonly<Record<string, string | undefined>>;
|
|
8
|
+
type Isolation = "worktree" | "none";
|
|
9
|
+
|
|
10
|
+
export interface ClaudeSessionIsolation {
|
|
11
|
+
isolated: boolean;
|
|
12
|
+
/** Isolation values Claude Code does not define, each ignored. */
|
|
13
|
+
diagnostics: string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function isIsolation(value: unknown): value is Isolation {
|
|
17
|
+
return value === "worktree" || value === "none";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function ignored(source: string, value: unknown): string {
|
|
21
|
+
return `${source} is ${JSON.stringify(value)}, not "worktree" or "none"; ignored`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function bgIsolationOf(
|
|
25
|
+
settings: unknown,
|
|
26
|
+
source: string,
|
|
27
|
+
diagnostics: string[],
|
|
28
|
+
): Isolation | undefined {
|
|
29
|
+
if (typeof settings !== "object" || settings === null) return undefined;
|
|
30
|
+
const worktree = (settings as { worktree?: unknown }).worktree;
|
|
31
|
+
if (typeof worktree !== "object" || worktree === null) return undefined;
|
|
32
|
+
const value = (worktree as { bgIsolation?: unknown }).bgIsolation;
|
|
33
|
+
if (isIsolation(value)) return value;
|
|
34
|
+
if (value !== undefined) diagnostics.push(ignored(`worktree.bgIsolation in ${source}`, value));
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Lenient like Claude Code: unparseable JSON, or an unreadable file, sets nothing.
|
|
39
|
+
function parseJson(text: string): unknown {
|
|
40
|
+
try {
|
|
41
|
+
return JSON.parse(text);
|
|
42
|
+
} catch {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function readJson(file: string): unknown {
|
|
48
|
+
try {
|
|
49
|
+
return parseJson(fs.readFileSync(file, "utf8"));
|
|
50
|
+
} catch {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A `--settings` value, a file path or inline JSON as Claude reads it. */
|
|
56
|
+
function flagSettings(value: string): unknown {
|
|
57
|
+
return value.trimStart().startsWith("{") ? parseJson(value) : readJson(value);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function settingsFlagValue(flags: readonly unknown[], index: number): unknown {
|
|
61
|
+
const flag = flags[index];
|
|
62
|
+
if (flag === "--settings") return flags[index + 1];
|
|
63
|
+
if (typeof flag === "string" && flag.startsWith("--settings=")) {
|
|
64
|
+
return flag.slice("--settings=".length);
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The isolation a background job was started with: its own (e.g. `none` for a
|
|
71
|
+
* backgrounded REPL), else the last `--settings` it was launched with that sets one.
|
|
72
|
+
*/
|
|
73
|
+
function jobIsolation(jobDir: string, diagnostics: string[]): Isolation | undefined {
|
|
74
|
+
const state = readJson(path.join(jobDir, "state.json")) as {
|
|
75
|
+
bgIsolation?: unknown;
|
|
76
|
+
respawnFlags?: unknown;
|
|
77
|
+
} | null;
|
|
78
|
+
const own = state?.bgIsolation;
|
|
79
|
+
if (isIsolation(own)) return own;
|
|
80
|
+
const flags = Array.isArray(state?.respawnFlags) ? state.respawnFlags : [];
|
|
81
|
+
let isolation: Isolation | undefined;
|
|
82
|
+
for (let index = 0; index < flags.length; index += 1) {
|
|
83
|
+
const value = settingsFlagValue(flags, index);
|
|
84
|
+
if (typeof value !== "string") continue;
|
|
85
|
+
isolation = bgIsolationOf(flagSettings(value), "--settings", diagnostics) ?? isolation;
|
|
86
|
+
}
|
|
87
|
+
return isolation;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Whether Claude Code refuses this session's writes in `repoPath`: true for a background
|
|
92
|
+
* session whose isolation is not `none`, when `repoPath` lies in a Git checkout that is
|
|
93
|
+
* not a linked worktree. A folder outside Git, such as an Umbrella Repository, is never
|
|
94
|
+
* isolated.
|
|
95
|
+
*
|
|
96
|
+
* @remarks
|
|
97
|
+
* A background session is told by `CLAUDE_JOB_DIR`; Claude usually hides
|
|
98
|
+
* `CLAUDE_CODE_SESSION_KIND` and `CLAUDE_BG_ISOLATION` from its tools, and either is
|
|
99
|
+
* honored when visible. Isolation resolves from `CLAUDE_BG_ISOLATION`, then the job's
|
|
100
|
+
* `state.json` (its own isolation, else the `--settings` it was launched with, as the
|
|
101
|
+
* VS Code extension sets), then `worktree.bgIsolation` in
|
|
102
|
+
* `<repoPath>/.claude/settings.local.json`, `<repoPath>/.claude/settings.json`, the user
|
|
103
|
+
* `settings.json` (`CLAUDE_CONFIG_DIR`, else `~/.claude`), else `worktree`. An undefined
|
|
104
|
+
* value is ignored and reported. Managed policy and the folder the session started in are
|
|
105
|
+
* not visible here.
|
|
106
|
+
*/
|
|
107
|
+
export function claudeSessionIsolation(
|
|
108
|
+
env: IsolationEnv,
|
|
109
|
+
repoPath: string,
|
|
110
|
+
): ClaudeSessionIsolation {
|
|
111
|
+
const diagnostics: string[] = [];
|
|
112
|
+
const background = env.CLAUDE_CODE_SESSION_KIND === "bg" || Boolean(env.CLAUDE_JOB_DIR);
|
|
113
|
+
if (!background) return { isolated: false, diagnostics };
|
|
114
|
+
// Claude guards only a Git checkout, found upward as Git finds it, that is not a linked worktree.
|
|
115
|
+
const checkout = checkoutAt(repoPath);
|
|
116
|
+
if (!checkout || checkout.layout.kind === "linked") return { isolated: false, diagnostics };
|
|
117
|
+
const isolated = resolveIsolation(env, repoPath, diagnostics) !== "none";
|
|
118
|
+
return { isolated, diagnostics };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function resolveIsolation(env: IsolationEnv, repoPath: string, diagnostics: string[]): Isolation {
|
|
122
|
+
const variable = env.CLAUDE_BG_ISOLATION;
|
|
123
|
+
if (isIsolation(variable)) return variable;
|
|
124
|
+
if (variable) diagnostics.push(ignored("CLAUDE_BG_ISOLATION", variable));
|
|
125
|
+
const job = env.CLAUDE_JOB_DIR ? jobIsolation(env.CLAUDE_JOB_DIR, diagnostics) : undefined;
|
|
126
|
+
if (job) return job;
|
|
127
|
+
const userDir = env.CLAUDE_CONFIG_DIR || path.join(env.HOME || os.homedir(), ".claude");
|
|
128
|
+
const files = [
|
|
129
|
+
path.join(repoPath, ".claude", "settings.local.json"),
|
|
130
|
+
path.join(repoPath, ".claude", "settings.json"),
|
|
131
|
+
path.join(userDir, "settings.json"),
|
|
132
|
+
];
|
|
133
|
+
for (const file of files) {
|
|
134
|
+
const value = bgIsolationOf(readJson(file), file, diagnostics);
|
|
135
|
+
if (value) return value;
|
|
136
|
+
}
|
|
137
|
+
return "worktree";
|
|
138
|
+
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
1
3
|
import type { ClaudeHookGroup } from "./claude-hook-group";
|
|
4
|
+
import { otherServingClaudeWrapRoot } from "./serving-claude-wrap";
|
|
5
|
+
import type { SessionKind } from "./session-kind";
|
|
2
6
|
import { NOT_WRAPPED, readWrapStateSync, type WrapState } from "./wrap-state";
|
|
3
7
|
|
|
4
8
|
/**
|
|
@@ -7,13 +11,6 @@ import { NOT_WRAPPED, readWrapStateSync, type WrapState } from "./wrap-state";
|
|
|
7
11
|
* may import it.
|
|
8
12
|
*/
|
|
9
13
|
|
|
10
|
-
/**
|
|
11
|
-
* `managed-repo`: `mate claude` with a Working Repository; its prepare just
|
|
12
|
-
* reconciled the Claude wrap, which the launcher asserts. `managed-companion`:
|
|
13
|
-
* a companion-scoped launch. `unmanaged`: a session with no launch environment.
|
|
14
|
-
*/
|
|
15
|
-
export type SessionKind = "managed-repo" | "managed-companion" | "unmanaged";
|
|
16
|
-
|
|
17
14
|
export interface ClaudeDeliveryPlan {
|
|
18
15
|
/** Capability hook groups; `launchSettingsExclude` is what `--settings` must not repeat. */
|
|
19
16
|
readonly hooks: {
|
|
@@ -28,9 +25,112 @@ export interface ClaudeDeliveryPlan {
|
|
|
28
25
|
readonly reconcile: "attended-prepare" | "prepare-hook" | "none";
|
|
29
26
|
/** Companion Git synchronization. */
|
|
30
27
|
readonly gitSync: "launch-preflight" | "prepare-hook" | "banner";
|
|
28
|
+
/**
|
|
29
|
+
* Plugin folders loaded as Claude plugins. A managed launch passes Mate's
|
|
30
|
+
* bundled plugin and every gathered Capability folder but `launchExclude`,
|
|
31
|
+
* the folders the wrap carries; a Claude-wrapped plain session gets those
|
|
32
|
+
* from the wrap alone.
|
|
33
|
+
*/
|
|
34
|
+
readonly plugins: {
|
|
35
|
+
readonly owner: "launch-flag" | "wrap" | "none";
|
|
36
|
+
readonly launchExclude: readonly string[];
|
|
37
|
+
};
|
|
38
|
+
/** Companion Instructions, per thread kind; `dirAccess` through settings loads no memory file. */
|
|
39
|
+
readonly instructions: ClaudeInstructionOwners;
|
|
31
40
|
}
|
|
32
41
|
|
|
33
|
-
export
|
|
42
|
+
export interface ClaudeInstructionOwners {
|
|
43
|
+
/** `wrap-session-hook`: the wrap's session-prepare hook, once it has prepared, for a launch and a plain session alike. */
|
|
44
|
+
readonly main: "native-memory" | "wrap-session-hook" | "none";
|
|
45
|
+
/** `plugin-subagent-hook`: the bundled plugin's SubagentStart copy; `wrap-subagent-hook`: the wrap's. */
|
|
46
|
+
readonly subagents: "plugin-subagent-hook" | "native-memory" | "wrap-subagent-hook" | "none";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Whether the session's launch passes `--plugin-dir`: every managed launch does, a plain
|
|
51
|
+
* session cannot. Not whether the session loads plugin folders: a Claude-wrapped plain
|
|
52
|
+
* session gets them from the wrap.
|
|
53
|
+
*/
|
|
54
|
+
export function launchPassesClaudePluginFolders(kind: SessionKind): boolean {
|
|
55
|
+
return kind !== "unmanaged";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function planClaudeDelivery(
|
|
59
|
+
kind: SessionKind,
|
|
60
|
+
wrap: WrapState,
|
|
61
|
+
worktreePluginOverrides: readonly string[] = [],
|
|
62
|
+
): ClaudeDeliveryPlan {
|
|
63
|
+
return {
|
|
64
|
+
...planChannels(kind, wrap),
|
|
65
|
+
plugins: planPlugins(kind, wrap, worktreePluginOverrides),
|
|
66
|
+
instructions: planClaudeInstructions(kind, wrap.runtimes.has("claude")),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The instruction owners alone, for a hook that knows its wrap without reading
|
|
72
|
+
* one: a wrap-carried hook runs only because a Claude wrap installed it, maybe
|
|
73
|
+
* the main checkout's, so it must not gate on this Checkout's manifest.
|
|
74
|
+
*/
|
|
75
|
+
export function planClaudeInstructions(
|
|
76
|
+
kind: SessionKind,
|
|
77
|
+
wrappedForClaude: boolean,
|
|
78
|
+
): ClaudeInstructionOwners {
|
|
79
|
+
switch (kind) {
|
|
80
|
+
case "managed-repo":
|
|
81
|
+
return { main: "wrap-session-hook", subagents: "plugin-subagent-hook" };
|
|
82
|
+
case "managed-companion":
|
|
83
|
+
return { main: "native-memory", subagents: "native-memory" };
|
|
84
|
+
case "unmanaged":
|
|
85
|
+
return wrappedForClaude
|
|
86
|
+
? { main: "wrap-session-hook", subagents: "wrap-subagent-hook" }
|
|
87
|
+
: { main: "none", subagents: "none" };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The folders a managed launch passes with `--plugin-dir`, in order: the
|
|
93
|
+
* bundled plugin, then each gathered folder the wrap does not carry, matched
|
|
94
|
+
* by resolved path. None when the launch flag does not own plugin folders.
|
|
95
|
+
*/
|
|
96
|
+
export function launchPluginFolders(
|
|
97
|
+
plan: ClaudeDeliveryPlan,
|
|
98
|
+
gathered: readonly string[],
|
|
99
|
+
bundledPluginRoot: string,
|
|
100
|
+
): string[] {
|
|
101
|
+
if (plan.plugins.owner !== "launch-flag") return [];
|
|
102
|
+
const carried = new Set(plan.plugins.launchExclude.map((dir) => path.resolve(dir)));
|
|
103
|
+
return [bundledPluginRoot, ...gathered.filter((dir) => !carried.has(path.resolve(dir)))];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function planPlugins(
|
|
107
|
+
kind: SessionKind,
|
|
108
|
+
wrap: WrapState,
|
|
109
|
+
worktreePluginOverrides: readonly string[],
|
|
110
|
+
): ClaudeDeliveryPlan["plugins"] {
|
|
111
|
+
switch (kind) {
|
|
112
|
+
case "managed-repo": {
|
|
113
|
+
const overrides = new Set(
|
|
114
|
+
worktreePluginOverrides.map((directory) => path.resolve(directory)),
|
|
115
|
+
);
|
|
116
|
+
return {
|
|
117
|
+
owner: "launch-flag",
|
|
118
|
+
launchExclude: wrap.carriedClaudePluginDirectories.filter(
|
|
119
|
+
(directory) => !overrides.has(path.resolve(directory)),
|
|
120
|
+
),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
case "managed-companion":
|
|
124
|
+
return { owner: "launch-flag", launchExclude: [] };
|
|
125
|
+
case "unmanaged":
|
|
126
|
+
return { owner: wrap.runtimes.has("claude") ? "wrap" : "none", launchExclude: [] };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function planChannels(
|
|
131
|
+
kind: SessionKind,
|
|
132
|
+
wrap: WrapState,
|
|
133
|
+
): Omit<ClaudeDeliveryPlan, "plugins" | "instructions"> {
|
|
34
134
|
switch (kind) {
|
|
35
135
|
case "managed-repo":
|
|
36
136
|
return {
|
|
@@ -67,7 +167,17 @@ export function planClaudeDelivery(kind: SessionKind, wrap: WrapState): ClaudeDe
|
|
|
67
167
|
}
|
|
68
168
|
}
|
|
69
169
|
|
|
70
|
-
/**
|
|
71
|
-
|
|
72
|
-
|
|
170
|
+
/**
|
|
171
|
+
* For session-start hooks: the plan of a plain session in the Checkout at
|
|
172
|
+
* `checkoutRoot`, from a lenient read; no root, not wrapped. Planned from the
|
|
173
|
+
* wrap serving it while that one is wrapped for Claude, else from its own:
|
|
174
|
+
* Claude Code loads both settings files there, and each hook group runs from
|
|
175
|
+
* the one that carries it (design Decisions 1 and 12).
|
|
176
|
+
*/
|
|
177
|
+
export function unmanagedClaudeDelivery(checkoutRoot: string | undefined): ClaudeDeliveryPlan {
|
|
178
|
+
if (!checkoutRoot) return planClaudeDelivery("unmanaged", NOT_WRAPPED);
|
|
179
|
+
const other = otherServingClaudeWrapRoot(checkoutRoot);
|
|
180
|
+
const serving = other ? readWrapStateSync(other) : null;
|
|
181
|
+
const wrap = serving?.runtimes.has("claude") ? serving : readWrapStateSync(checkoutRoot);
|
|
182
|
+
return planClaudeDelivery("unmanaged", wrap);
|
|
73
183
|
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
import { heredocBodies, stripHeredocBodies } from "./shell-heredoc";
|
|
4
|
+
|
|
5
|
+
const CO_AUTHOR_TRAILER = /^\s*co-authored-by\s*[:=]\s*(.+)$/gim;
|
|
6
|
+
/** Substrings, not words: `ChatGPT` and `claude_bot` mention a model too. */
|
|
7
|
+
const MODEL_NAME = /claude|anthropic|gpt|openai|codex|gemini|copilot|opencode/i;
|
|
8
|
+
|
|
9
|
+
/** `git` options before the subcommand that take the next word as their value. */
|
|
10
|
+
const GIT_VALUE_OPTIONS = new Set(["-C", "-c"]);
|
|
11
|
+
/** `git commit` short options whose value is the next word, or the rest of the cluster. */
|
|
12
|
+
const COMMIT_VALUE_SHORTS = new Set(["m", "F", "t", "c", "C"]);
|
|
13
|
+
/** Words that run the command after them, with their own dash options. */
|
|
14
|
+
const COMMAND_WRAPPERS = new Set(["env", "sudo", "command", "exec", "nice", "nohup", "time"]);
|
|
15
|
+
/** Characters a backslash escapes inside double quotes; before any other it stays. */
|
|
16
|
+
const DOUBLE_QUOTE_ESCAPES = new Set(["$", "`", '"', "\\", "\n"]);
|
|
17
|
+
|
|
18
|
+
const SEPARATOR = Symbol("separator");
|
|
19
|
+
/** A word and the first and last lines it spans. */
|
|
20
|
+
interface Word {
|
|
21
|
+
text: string;
|
|
22
|
+
start: number;
|
|
23
|
+
end: number;
|
|
24
|
+
}
|
|
25
|
+
type Token = Word | typeof SEPARATOR;
|
|
26
|
+
|
|
27
|
+
/** One simple command's words and the lines it spans. */
|
|
28
|
+
interface Segment {
|
|
29
|
+
words: string[];
|
|
30
|
+
start: number;
|
|
31
|
+
end: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Shell words and command separators (`&&`, `||`, `;`, `|`, `&`, parentheses,
|
|
36
|
+
* newline), quotes removed. A quoted string stays one word across lines, so a
|
|
37
|
+
* multi-line `-m` message is one value. A heuristic, not a parser.
|
|
38
|
+
*/
|
|
39
|
+
function shellTokens(command: string): Token[] {
|
|
40
|
+
const tokens: Token[] = [];
|
|
41
|
+
let word = "";
|
|
42
|
+
let quote: string | undefined;
|
|
43
|
+
let quoted = false;
|
|
44
|
+
let line = 0;
|
|
45
|
+
let start = 0;
|
|
46
|
+
const markStart = () => {
|
|
47
|
+
if (!word && !quoted) start = line;
|
|
48
|
+
};
|
|
49
|
+
const append = (text: string) => {
|
|
50
|
+
markStart();
|
|
51
|
+
word += text;
|
|
52
|
+
};
|
|
53
|
+
const flush = () => {
|
|
54
|
+
if (word || quoted) tokens.push({ text: word, start, end: line });
|
|
55
|
+
word = "";
|
|
56
|
+
quoted = false;
|
|
57
|
+
};
|
|
58
|
+
for (let i = 0; i < command.length; i++) {
|
|
59
|
+
const char = command[i];
|
|
60
|
+
if (quote) {
|
|
61
|
+
if (char === quote) quote = undefined;
|
|
62
|
+
else if (char === "\\" && quote === '"' && DOUBLE_QUOTE_ESCAPES.has(command[i + 1] ?? "")) {
|
|
63
|
+
append(command[++i]);
|
|
64
|
+
} else append(char);
|
|
65
|
+
} else if (char === "'" || char === '"') {
|
|
66
|
+
markStart();
|
|
67
|
+
quote = char;
|
|
68
|
+
quoted = true;
|
|
69
|
+
} else if (char === "\\" && i + 1 < command.length) {
|
|
70
|
+
if (command[i + 1] !== "\n") append(command[i + 1]);
|
|
71
|
+
i++;
|
|
72
|
+
} else if (";|&\n()".includes(char)) {
|
|
73
|
+
flush();
|
|
74
|
+
if (tokens.at(-1) !== SEPARATOR) tokens.push(SEPARATOR);
|
|
75
|
+
} else if (/\s/.test(char)) {
|
|
76
|
+
flush();
|
|
77
|
+
} else {
|
|
78
|
+
append(char);
|
|
79
|
+
}
|
|
80
|
+
if (command[i] === "\n") line++;
|
|
81
|
+
}
|
|
82
|
+
flush();
|
|
83
|
+
return tokens;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function segments(tokens: Token[]): Segment[] {
|
|
87
|
+
const result: Segment[] = [];
|
|
88
|
+
let current: Segment | undefined;
|
|
89
|
+
for (const token of tokens) {
|
|
90
|
+
if (token === SEPARATOR) {
|
|
91
|
+
current = undefined;
|
|
92
|
+
} else if (current) {
|
|
93
|
+
current.words.push(token.text);
|
|
94
|
+
current.end = token.end;
|
|
95
|
+
} else {
|
|
96
|
+
current = { words: [token.text], start: token.start, end: token.end };
|
|
97
|
+
result.push(current);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The words after `git commit`, or null when the segment runs something else. */
|
|
104
|
+
function commitArguments(segment: Segment): string[] | null {
|
|
105
|
+
const words = segment.words;
|
|
106
|
+
let i = 0;
|
|
107
|
+
while (i < words.length) {
|
|
108
|
+
const word = words[i];
|
|
109
|
+
if (COMMAND_WRAPPERS.has(word) || word === "{" || word === "!" || /^\w+=/.test(word)) i++;
|
|
110
|
+
else if (i > 0 && COMMAND_WRAPPERS.has(words[i - 1]) && word.startsWith("-")) i++;
|
|
111
|
+
else break;
|
|
112
|
+
}
|
|
113
|
+
if (i >= words.length || path.basename(words[i]) !== "git") return null;
|
|
114
|
+
i++;
|
|
115
|
+
while (i < words.length && words[i].startsWith("-")) {
|
|
116
|
+
i += GIT_VALUE_OPTIONS.has(words[i]) ? 2 : 1;
|
|
117
|
+
}
|
|
118
|
+
return words[i] === "commit" ? words.slice(i + 1) : null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Message text the arguments carry: `-m x`, `-mx`, `-am x`, `--message=x` and
|
|
123
|
+
* `--message x` values, plus each `--trailer` value as a trailer line.
|
|
124
|
+
*/
|
|
125
|
+
function messageValues(args: string[]): string[] {
|
|
126
|
+
const values: string[] = [];
|
|
127
|
+
for (let i = 0; i < args.length; i++) {
|
|
128
|
+
const arg = args[i];
|
|
129
|
+
if (arg === "--") break;
|
|
130
|
+
if (arg === "--message" || arg === "--trailer") {
|
|
131
|
+
if (i + 1 < args.length) values.push(args[++i]);
|
|
132
|
+
} else if (arg.startsWith("--message=") || arg.startsWith("--trailer=")) {
|
|
133
|
+
values.push(arg.slice(arg.indexOf("=") + 1));
|
|
134
|
+
} else if (/^-[^-]/.test(arg)) {
|
|
135
|
+
for (let j = 1; j < arg.length; j++) {
|
|
136
|
+
if (!COMMIT_VALUE_SHORTS.has(arg[j])) continue;
|
|
137
|
+
const rest = arg.slice(j + 1);
|
|
138
|
+
const value = rest || args[++i];
|
|
139
|
+
if (arg[j] === "m" && value !== undefined) values.push(value);
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return values;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Whether a trailer credits a model; a literal `\n`, as `printf` or `$'…'` expand it, counts as a line break. */
|
|
148
|
+
function creditsModel(text: string): boolean {
|
|
149
|
+
for (const trailer of text.replace(/\\n/g, "\n").matchAll(CO_AUTHOR_TRAILER)) {
|
|
150
|
+
if (MODEL_NAME.test(trailer[1])) return true;
|
|
151
|
+
}
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const REFUSAL = [
|
|
156
|
+
"Mate guardrail: Co-Authored-By trailers that credit an AI model are not allowed in this repository.",
|
|
157
|
+
"No commit was created. Rerun the same commit without the Co-Authored-By trailer; do not amend or rewrite history to remove it.",
|
|
158
|
+
].join("\n");
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Returns the refusal for a shell command running `git commit` whose message
|
|
162
|
+
* credits an AI model as co-author, or null. Reads only message text in the
|
|
163
|
+
* command: `-m`/`--message`/`--trailer` values and the heredoc bodies a commit
|
|
164
|
+
* reads, those whose marker sits on a line the commit spans. `-F`, `-t` and
|
|
165
|
+
* editor messages pass unchecked.
|
|
166
|
+
*/
|
|
167
|
+
export function checkCommitAttribution(command: string): string | null {
|
|
168
|
+
const commits = segments(shellTokens(stripHeredocBodies(command))).flatMap((segment) => {
|
|
169
|
+
const args = commitArguments(segment);
|
|
170
|
+
return args ? [{ segment, args }] : [];
|
|
171
|
+
});
|
|
172
|
+
if (commits.length === 0) return null;
|
|
173
|
+
|
|
174
|
+
const bodies = heredocBodies(command)
|
|
175
|
+
.filter((body) =>
|
|
176
|
+
commits.some(({ segment }) => body.line >= segment.start && body.line <= segment.end),
|
|
177
|
+
)
|
|
178
|
+
.map((body) => body.text);
|
|
179
|
+
const messages = [...commits.flatMap(({ args }) => messageValues(args)), ...bodies];
|
|
180
|
+
return messages.some(creditsModel) ? REFUSAL : null;
|
|
181
|
+
}
|
|
@@ -62,6 +62,34 @@ export function isAuthenticationFailure(result: GitResult): boolean {
|
|
|
62
62
|
].some((marker) => output.includes(marker));
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
const NETWORK_FAILURE_MARKERS = [
|
|
66
|
+
"could not resolve host",
|
|
67
|
+
"connection timed out",
|
|
68
|
+
"connection refused",
|
|
69
|
+
"connection reset",
|
|
70
|
+
"operation timed out",
|
|
71
|
+
"the remote end hung up unexpectedly",
|
|
72
|
+
"kex_exchange_identification",
|
|
73
|
+
"early eof",
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
const REMOTE_REJECTION = /\[(?:remote )?rejected\]|non-fast-forward|protected branch/;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A remote failure a retry may cure: an authentication rejection or a network
|
|
80
|
+
* failure. A rejection by the remote's rules never is, whatever else it prints.
|
|
81
|
+
*/
|
|
82
|
+
export function isTransientRemoteFailure(result: GitResult): boolean {
|
|
83
|
+
if (result.status === 0) return false;
|
|
84
|
+
const output = `${result.stderr}\n${result.stdout}`.toLowerCase();
|
|
85
|
+
if (REMOTE_REJECTION.test(output)) return false;
|
|
86
|
+
return (
|
|
87
|
+
Boolean(result.timedOut) ||
|
|
88
|
+
isAuthenticationFailure(result) ||
|
|
89
|
+
NETWORK_FAILURE_MARKERS.some((marker) => output.includes(marker))
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
65
93
|
/** `git@host:path` (`ssh://` when a port is given) for an HTTP(S) Git URL; `null` otherwise. */
|
|
66
94
|
export function toSshUrl(url: string): string | null {
|
|
67
95
|
try {
|
|
@@ -149,6 +177,8 @@ export interface CompanionGitOptions {
|
|
|
149
177
|
/** Bound on each local command, applied within `budgetMs`. */
|
|
150
178
|
commandCapMs?: number;
|
|
151
179
|
env?: Record<string, string | undefined>;
|
|
180
|
+
/** Index file local commands use instead of the repository's own. */
|
|
181
|
+
indexFile?: string;
|
|
152
182
|
}
|
|
153
183
|
|
|
154
184
|
export interface CompanionGit {
|
|
@@ -252,18 +282,27 @@ function spawnGit(
|
|
|
252
282
|
* free to prompt, so `never` clears every askpass source: both variables, and
|
|
253
283
|
* `core.askPass` through an appended `GIT_CONFIG_*` entry.
|
|
254
284
|
*/
|
|
255
|
-
function withoutAskPass(
|
|
285
|
+
export function withoutAskPass(
|
|
256
286
|
env: Record<string, string | undefined>,
|
|
257
287
|
): Record<string, string | undefined> {
|
|
258
288
|
const { GIT_ASKPASS: _gitAskPass, SSH_ASKPASS: _sshAskPass, ...rest } = env;
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
289
|
+
return withGitConfig({ ...rest, SSH_ASKPASS_REQUIRE: "never" }, { "core.askPass": "" });
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** `env` with `config` appended as `GIT_CONFIG_*` entries, after any already there. */
|
|
293
|
+
export function withGitConfig(
|
|
294
|
+
env: Record<string, string | undefined>,
|
|
295
|
+
config: Record<string, string>,
|
|
296
|
+
): Record<string, string | undefined> {
|
|
297
|
+
const next: Record<string, string | undefined> = { ...env };
|
|
298
|
+
let count = Number.parseInt(next.GIT_CONFIG_COUNT ?? "0", 10) || 0;
|
|
299
|
+
for (const [key, value] of Object.entries(config)) {
|
|
300
|
+
next[`GIT_CONFIG_KEY_${count}`] = key;
|
|
301
|
+
next[`GIT_CONFIG_VALUE_${count}`] = value;
|
|
302
|
+
count += 1;
|
|
303
|
+
}
|
|
304
|
+
next.GIT_CONFIG_COUNT = String(count);
|
|
305
|
+
return next;
|
|
267
306
|
}
|
|
268
307
|
|
|
269
308
|
/** The operation's policy is fixed when it is opened; every step below inherits it. */
|
|
@@ -272,7 +311,10 @@ export function companionGit(
|
|
|
272
311
|
options: CompanionGitOptions,
|
|
273
312
|
deps: typeof companionGitDeps = companionGitDeps,
|
|
274
313
|
): CompanionGit {
|
|
275
|
-
const baseEnv
|
|
314
|
+
const baseEnv: Record<string, string | undefined> = {
|
|
315
|
+
...gitEnvironment(options.env ?? process.env),
|
|
316
|
+
...(options.indexFile ? { GIT_INDEX_FILE: options.indexFile } : {}),
|
|
317
|
+
};
|
|
276
318
|
const mayPrompt = options.prompt === "if-terminal" && deps.isTerminal();
|
|
277
319
|
const deadline =
|
|
278
320
|
options.budgetMs === undefined ? Number.POSITIVE_INFINITY : Date.now() + options.budgetMs;
|
|
@@ -407,11 +449,19 @@ async function resolveUpstreamTarget(
|
|
|
407
449
|
): Promise<UpstreamTarget | null> {
|
|
408
450
|
const upstream = await run(["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"]);
|
|
409
451
|
const configured = parseRemoteRef(upstream.stdout);
|
|
410
|
-
if (upstream.status === 0 && configured)
|
|
452
|
+
if (upstream.status === 0 && configured) {
|
|
453
|
+
return configured.remote.startsWith("-") || configured.branch.startsWith("-")
|
|
454
|
+
? null
|
|
455
|
+
: configured;
|
|
456
|
+
}
|
|
411
457
|
|
|
412
458
|
const remoteHead = await run(["symbolic-ref", "--short", "refs/remotes/origin/HEAD"]);
|
|
413
459
|
const fromRemoteHead = parseRemoteRef(remoteHead.stdout);
|
|
414
|
-
if (remoteHead.status === 0 && fromRemoteHead)
|
|
460
|
+
if (remoteHead.status === 0 && fromRemoteHead) {
|
|
461
|
+
return fromRemoteHead.remote.startsWith("-") || fromRemoteHead.branch.startsWith("-")
|
|
462
|
+
? null
|
|
463
|
+
: fromRemoteHead;
|
|
464
|
+
}
|
|
415
465
|
|
|
416
466
|
for (const branch of ["main", "master"]) {
|
|
417
467
|
// oxlint-disable-next-line no-await-in-loop -- the steps are a decision chain
|