@uniqbit/mate-core 1.0.0-canary.5 → 1.0.0-canary.7
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/plugin.json +1 -1
- package/claude-capability-plugins/companion-mentions/hooks/register.ts +1 -1
- package/claude-plugin/hooks/hooks.json +41 -1
- package/claude-plugin/hooks/rtk-worktree-git.mjs +58 -0
- package/claude-plugin/hooks/workflow-turn.mjs +68 -0
- package/opencode-plugin/src/companion.ts +6 -0
- package/opencode-plugin/src/server.ts +33 -2
- package/package.json +5 -2
- package/src/cli/commands/artifact/apply-context.ts +1 -0
- package/src/cli/commands/artifact/artifact.ts +16 -0
- package/src/cli/commands/artifact/delivery/archive.ts +37 -112
- package/src/cli/commands/artifact/delivery/branch-flags.ts +19 -1
- package/src/cli/commands/artifact/delivery/environment.ts +32 -72
- package/src/cli/commands/artifact/delivery/link.ts +53 -34
- package/src/cli/commands/artifact/delivery/output.ts +25 -4
- package/src/cli/commands/artifact/delivery/resolve.ts +101 -0
- package/src/cli/commands/artifact/delivery/submit.ts +164 -0
- package/src/cli/commands/artifact/delivery/take.ts +45 -0
- package/src/cli/commands/artifact/extract-repo-name.ts +1 -1
- package/src/cli/commands/artifact/finish/command.ts +455 -43
- package/src/cli/commands/artifact/finish/engine.ts +79 -61
- package/src/cli/commands/artifact/finish/finisher.ts +5 -12
- package/src/cli/commands/artifact/finish/git.ts +9 -10
- package/src/cli/commands/artifact/finish/openspec.ts +21 -174
- package/src/cli/commands/artifact/finish/secret-scan.ts +5 -43
- package/src/cli/commands/artifact/finish/worktree-cleanup.ts +57 -7
- package/src/cli/commands/artifact/pending/command.ts +119 -6
- package/src/cli/commands/artifact/pending/discovery.ts +7 -11
- package/src/cli/commands/artifact/project/command.ts +60 -0
- package/src/cli/commands/companion/list.ts +70 -14
- package/src/cli/commands/companion/sync.ts +18 -0
- package/src/cli/commands/companion/update.ts +4 -19
- package/src/cli/commands/doctor.ts +51 -0
- package/src/cli/commands/friction.ts +558 -0
- package/src/cli/commands/install.ts +48 -36
- package/src/cli/commands/launch/claude.ts +2 -0
- package/src/cli/commands/launch/shared.ts +33 -6
- package/src/cli/commands/plugin/install.ts +27 -11
- package/src/cli/commands/report/index.ts +180 -184
- package/src/cli/commands/report/markdown.ts +67 -72
- 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 +72 -0
- package/src/cli/commands/studio/companion-removal.ts +15 -8
- package/src/cli/commands/studio/connection.ts +53 -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 +4 -4
- package/src/{lib/factory/outcomes/sessions.ts → cli/commands/studio/live-sessions.ts} +26 -2
- package/src/cli/commands/studio/payload.ts +214 -32
- package/src/cli/commands/studio/reports.ts +19 -18
- package/src/cli/commands/studio/routes.ts +8 -18
- package/src/cli/commands/studio/selection.ts +21 -5
- package/src/cli/commands/studio/server.ts +322 -191
- package/src/cli/commands/studio/service-host.ts +266 -0
- package/src/cli/commands/studio/services.ts +59 -16
- package/src/cli/commands/studio/studio-app.ts +1 -0
- package/src/cli/commands/studio/terminal.ts +45 -3
- package/src/cli/commands/studio/vault.ts +41 -40
- package/src/cli/commands/studio/views/model.ts +1 -9
- package/src/cli/commands/studio/views/vault/markdown-tree.ts +90 -8
- package/src/cli/commands/triage.ts +151 -0
- package/src/cli/commands/unwrap.ts +3 -0
- package/src/cli/commands/update.ts +2 -0
- package/src/cli/commands/vscode/release-vsix.json +4 -0
- package/src/cli/commands/vscode/setup.ts +71 -13
- package/src/cli/commands/vscode/vsix.ts +48 -7
- package/src/cli/commands/workflow/workflow.ts +516 -0
- package/src/cli/commands/working/cleanup.ts +40 -8
- package/src/cli/commands/working/worktree.ts +176 -35
- package/src/cli/main.ts +61 -10
- package/src/cli/plugin-commands.ts +6 -1
- package/src/cli/repo-list-table.tsx +73 -37
- package/src/cli/usage.ts +29 -8
- package/src/create-mate.ts +11 -5
- package/src/distribution.ts +2 -0
- package/src/factory-host.ts +69 -0
- package/src/hooks/companion-instructions.ts +19 -8
- package/src/hooks/hook-io.ts +3 -1
- package/src/hooks/rtk-worktree-git.ts +48 -0
- package/src/hooks/session-banner.ts +25 -0
- package/src/hooks/validate-artifact-path.ts +108 -26
- package/src/hooks/workflow-turn.ts +219 -0
- package/src/lib/apply-context/fingerprint.ts +2 -1
- package/src/lib/apply-context/protocol.ts +2 -2
- package/src/lib/artifact-trailer.ts +27 -0
- package/src/lib/change-layout.ts +83 -38
- package/src/lib/delivery/branch-template.ts +114 -0
- package/src/lib/delivery/branches.ts +21 -16
- package/src/lib/delivery/checkout.ts +103 -0
- package/src/lib/delivery/environment.ts +131 -7
- package/src/lib/delivery/merge-git.ts +282 -26
- package/src/lib/delivery/overlap.ts +68 -16
- package/src/lib/delivery/record-delivery.ts +178 -37
- package/src/lib/delivery/record.ts +201 -27
- package/src/lib/delivery/refresh.ts +212 -151
- package/src/lib/delivery/remote.ts +66 -0
- package/src/lib/delivery/repository-access.ts +19 -60
- package/src/lib/delivery/resolve-branch.ts +157 -110
- package/src/lib/delivery/stages.ts +83 -50
- package/src/lib/delivery/staging/apply-chain.ts +164 -0
- package/src/lib/delivery/staging/artifact-type.ts +101 -0
- package/src/lib/delivery/staging/declared-type.ts +277 -0
- package/src/lib/delivery/staging/naming.ts +64 -0
- package/src/lib/delivery/staging/openspec-type.ts +135 -0
- package/src/lib/delivery/staging/pending-edit.ts +291 -0
- package/src/lib/delivery/staging/pending.ts +780 -0
- package/src/lib/delivery/staging/project.ts +373 -0
- package/src/lib/delivery/staging/publish.ts +1024 -0
- package/src/lib/delivery/staging/refs.ts +258 -0
- package/src/lib/delivery/staging/registry.ts +73 -0
- package/src/lib/delivery/staging/replay.ts +308 -0
- package/src/lib/delivery/staging/requirement-blocks.ts +10 -0
- package/src/lib/delivery/staging/resolve.ts +264 -0
- package/src/lib/delivery/staging/settle-linked.ts +290 -0
- package/src/lib/delivery/staging/submit.ts +929 -0
- package/src/lib/delivery/staging/worktree.ts +130 -0
- package/src/lib/delivery/submit-change.ts +443 -0
- package/src/lib/friction/describe.ts +42 -0
- package/src/lib/friction/fields.ts +60 -0
- package/src/lib/friction/mark.ts +156 -0
- package/src/lib/friction/view/model.ts +67 -0
- package/src/lib/friction/view/read.ts +136 -0
- package/src/lib/friction/view/select.ts +54 -0
- package/src/lib/git-key.ts +15 -0
- package/src/lib/install.ts +2 -0
- package/src/lib/openspec-canonical-frontmatter.ts +159 -0
- package/src/lib/orchestrator/adapters/base.ts +31 -20
- package/src/lib/orchestrator/adapters/claude.ts +21 -7
- package/src/lib/orchestrator/adapters/opencode.ts +4 -0
- package/src/lib/orchestrator/companion-git-sync.ts +152 -16
- package/src/lib/orchestrator/companion-hub.ts +6 -1
- package/src/lib/orchestrator/engine-floor.ts +48 -0
- package/src/lib/orchestrator/framework-context.ts +15 -1
- package/src/lib/orchestrator/launcher.ts +34 -1
- package/src/lib/orchestrator/projection-claude-commands.ts +2 -2
- package/src/lib/orchestrator/projection-claude-entry.ts +42 -21
- package/src/lib/orchestrator/projection-claude-links.ts +33 -8
- package/src/lib/orchestrator/projection-claude-skills.ts +2 -2
- package/src/lib/orchestrator/projection-entries.ts +22 -18
- package/src/lib/orchestrator/projection-opencode-copies.ts +65 -21
- package/src/lib/orchestrator/projection-runtime-documents.ts +66 -43
- package/src/lib/orchestrator/projection-types.ts +28 -1
- package/src/lib/orchestrator/refresh-working-claude-links.ts +4 -1
- package/src/lib/orchestrator/root-context.ts +23 -6
- package/src/lib/orchestrator/session-prepare.ts +17 -2
- package/src/lib/orchestrator/setup-compatibilities.ts +1 -1
- package/src/lib/orchestrator/types.ts +4 -0
- package/src/lib/orchestrator/umbrella-checkouts.ts +102 -0
- package/src/lib/orchestrator/working-repo-projection.ts +24 -4
- package/src/lib/orchestrator/wrap-pass.ts +1 -0
- package/src/lib/package-paths.ts +23 -15
- package/src/lib/prebuilt-workspace-prepare.ts +2 -1
- package/src/lib/prebuilt-workspace.ts +1 -0
- package/src/lib/public-npm.ts +95 -50
- package/src/lib/session-attribution.ts +3 -7
- package/src/lib/session-state.ts +74 -3
- package/src/lib/triage/context.ts +186 -0
- package/src/lib/triage/launch.ts +52 -0
- package/src/lib/triage/prepare.ts +97 -0
- package/src/lib/triage/session.ts +126 -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/workflow/declaration.ts +6 -0
- package/src/lib/workflow/handoff.ts +90 -0
- package/src/lib/workflow/hook-trust.ts +108 -0
- package/src/lib/workflow/position.ts +524 -0
- package/src/lib/workflow/report.ts +79 -0
- package/src/lib/workflow/work.ts +106 -0
- package/src/lib/workset/factory-local.ts +157 -0
- package/src/lib/workset/record.ts +25 -11
- package/src/lib/workset/repositories.ts +118 -25
- package/src/lib/workset/stage.ts +4 -2
- package/src/lib/workset/stages.ts +64 -4
- package/src/lib/workset/worktree-include.ts +161 -0
- package/src/lib/workset/worktree-index.ts +6 -2
- package/src/lib/workset/worktree.ts +622 -114
- package/src/opencode/companion-hooks.ts +105 -18
- package/src/opencode/companion-policy.ts +18 -5
- package/src/opencode/enter-worktree.ts +254 -6
- package/src/opencode/projected-guidance.ts +7 -2
- package/src/opencode/session-register.ts +2 -2
- package/src/opencode/turn-hook.ts +241 -0
- package/src/playbooks/companion-guidance.ts +7 -4
- package/src/plugin-api.ts +47 -0
- package/src/runtime/artifact-trailers.ts +63 -0
- package/src/runtime/claude-bg-isolation.ts +138 -0
- package/src/runtime/claude-hook-group.ts +2 -0
- package/src/runtime/command-friction.ts +97 -0
- package/src/runtime/companion-git-state.ts +155 -10
- package/src/runtime/companion-git.ts +96 -13
- package/src/runtime/companion-guidance.ts +136 -20
- package/src/runtime/companion-instructions.ts +1 -1
- package/src/runtime/companion-sync.ts +109 -21
- package/src/runtime/current-branch.ts +16 -2
- package/src/runtime/entered-worktree.ts +24 -0
- package/src/runtime/env-names.ts +2 -2
- package/src/runtime/env.ts +7 -6
- package/src/runtime/forge-remote.ts +48 -0
- package/src/runtime/friction-fingerprint.ts +35 -0
- package/src/runtime/friction-log.ts +352 -0
- package/src/runtime/friction-recorder.ts +199 -0
- package/src/runtime/friction-retention.ts +1 -0
- package/src/runtime/friction-state.ts +110 -0
- package/src/runtime/friction-switch.ts +26 -0
- package/src/runtime/friction-vocabulary.ts +42 -0
- package/src/runtime/git-layout.ts +21 -7
- package/src/runtime/git-tracked.ts +60 -0
- package/src/runtime/json-fields.ts +8 -0
- package/src/runtime/pending-records.ts +533 -0
- package/src/runtime/projected-guidance.ts +8 -3
- package/src/runtime/publication-secret-scan.ts +45 -0
- package/src/runtime/repo-destination.ts +72 -0
- package/src/runtime/repo-local.ts +25 -3
- package/src/runtime/rtk-git-guard.ts +66 -0
- package/src/runtime/runtime-document-manifest.ts +229 -19
- package/src/runtime/runtime-document-manifest.typecheck.ts +10 -0
- package/src/runtime/secret-guard.ts +9 -2
- package/src/runtime/secret-patterns.ts +3 -2
- package/src/runtime/secret-policy-weakening.ts +122 -0
- package/src/runtime/secret-values.ts +16 -0
- package/src/runtime/serving-claude-wrap.ts +15 -2
- package/src/runtime/session-id.ts +24 -0
- package/src/runtime/session-prepare-runner.ts +3 -0
- package/src/runtime/skill-prefix.ts +75 -0
- package/src/runtime/submitted-arrivals.ts +547 -0
- package/src/runtime/turn-state.d.mts +14 -0
- package/src/runtime/turn-state.mjs +93 -0
- package/src/runtime/umbrella-children.ts +52 -0
- package/src/runtime/umbrella-folder.ts +84 -0
- package/src/runtime/workflow/change-folders.ts +66 -0
- package/src/runtime/workflow/declaration.ts +720 -0
- package/src/runtime/workflow/globs.ts +85 -0
- package/src/runtime/workflow/next-handoff-process.ts +99 -0
- package/src/runtime/workflow/turn.ts +309 -0
- package/src/runtime/workflow/workflow.ts +262 -0
- package/src/runtime/wrap-state.ts +5 -13
- package/src/studio.ts +112 -19
- package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/schema.yaml +3 -3
- package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/design.md +1 -1
- package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/proposal.md +1 -1
- package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/tasks.md +1 -1
- package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +3 -3
- package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +103 -30
- package/src/templates/mate-skills/agents/mate-apply-change/references/openspec-apply-change.md +1 -1
- package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +7 -70
- package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +13 -7
- package/src/templates/mate-skills/agents/mate-domain-modeling/SKILL.md +10 -0
- package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +46 -14
- package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +50 -31
- package/src/templates/mate-skills/agents/mate-propose-change/references/mate-revise.md +13 -7
- package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-update-change.md +1 -1
- package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +114 -86
- package/src/templates/mate-skills/agents/mate-publish-artifact/references/openspec.md +111 -100
- package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +11 -5
- package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +16 -6
- package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +114 -0
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +103 -30
- package/src/templates/mate-skills/claude/mate-apply-change/references/openspec-apply-change.md +1 -1
- package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +7 -70
- package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +13 -7
- package/src/templates/mate-skills/claude/mate-domain-modeling/SKILL.md +10 -0
- package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +46 -14
- package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +50 -31
- package/src/templates/mate-skills/claude/mate-propose-change/references/mate-revise.md +13 -7
- package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-update-change.md +1 -1
- package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +114 -86
- package/src/templates/mate-skills/claude/mate-publish-artifact/references/openspec.md +111 -100
- package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +11 -5
- package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +16 -6
- package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +114 -0
- package/src/templates/mate-skills/openspec-references.ts +3 -2
- package/src/templates/triage/PLAYBOOK.md +112 -0
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +912 -139
- package/src/tools/setup/capabilities/openspec.ts +54 -15
- package/src/tools/setup/capabilities/rtk.ts +113 -9
- package/src/tools/setup/capabilities/tokensave.ts +3 -2
- package/src/tools/setup/dynamic-plugins/api.ts +38 -0
- 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/host.ts +2 -32
- package/src/tools/setup/dynamic-plugins/hydrate.ts +4 -4
- package/src/tools/setup/dynamic-plugins/install.ts +24 -22
- 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 +20 -1
- package/src/tools/setup/mate.ts +5 -3
- package/src/tools/setup/package-managers/bun.ts +8 -8
- package/src/tools/setup/plugin.ts +14 -1
- package/src/tools/setup/plugins/gitignore.ts +15 -9
- package/src/tools/setup/plugins/guidance.ts +4 -2
- package/src/tools/setup/providers/claude-plugin-hooks.ts +30 -0
- package/src/tools/setup/providers/claude.ts +43 -6
- package/src/tools/setup/service-registry.ts +69 -0
- package/src/tools/setup/service.ts +237 -0
- package/src/tools/setup/utils.ts +28 -5
- package/src/tools/setup/working-repo-cleanup.ts +2 -2
- package/src/tools/setup/working-repo-local-state.ts +2 -0
- package/src/tools/setup.ts +41 -16
- package/studio-dist/client/assets/app-aIwDxf48.css +2 -0
- package/studio-dist/client/assets/button-CX0sWAJl.js +1 -0
- package/studio-dist/client/assets/combobox-BmA8RjOc.js +1 -0
- package/studio-dist/client/assets/companion-view-DINdPF-b.js +1 -0
- package/studio-dist/client/assets/fields-BobQ7zRF.js +1 -0
- package/studio-dist/client/assets/friction-YdYd3zaz.js +1 -0
- package/studio-dist/client/assets/getting-started-CY7NEtTw.js +1 -0
- package/studio-dist/client/assets/getting-started-djaQeWlu.js +1 -0
- package/studio-dist/client/assets/getting-started._topic-DVB8e5R9.js +1 -0
- package/studio-dist/client/assets/getting-started.index-DQvLHEr1.js +1 -0
- package/studio-dist/client/assets/graph-DbNnR884.js +2 -0
- package/studio-dist/client/assets/graph-canvas-DIcAqwtK.js +3242 -0
- package/studio-dist/client/assets/guides-D6T6W_jV.js +1 -0
- package/studio-dist/client/assets/index-CysBCSxM.js +40 -0
- package/studio-dist/client/assets/jsx-runtime-MZURdZre.js +1 -0
- package/studio-dist/client/assets/markdown-view-jMiaBTSO.js +1 -0
- package/studio-dist/client/assets/panel-Csr49lBo.js +1 -0
- package/studio-dist/client/assets/plugins._service._view-CEA_CcPe.js +1 -0
- package/studio-dist/client/assets/{prepaint-CwSrpdFA.js → prepaint-CKsXyJOR.js} +3 -3
- package/studio-dist/client/assets/queries-Dfp5deWj.js +1 -0
- package/studio-dist/client/assets/react-BYUSgtBs.js +1 -0
- package/studio-dist/client/assets/reports-CLdgxxkg.js +1 -0
- package/studio-dist/client/assets/routes-DGilWbDE.js +1 -0
- package/studio-dist/client/assets/search-CXosfvYh.js +1 -0
- package/studio-dist/client/assets/select-DdebbX7K.js +1 -0
- package/studio-dist/client/assets/skills-C3zNkU8g.js +1 -0
- package/studio-dist/client/assets/specs-Dl8HfGlU.js +1 -0
- package/studio-dist/client/assets/specs-view-B_n0Pekv.js +1 -0
- package/studio-dist/client/assets/steps-CKUno4lh.js +1 -0
- package/studio-dist/client/assets/store-DyXbi6o9.js +1 -0
- package/studio-dist/client/assets/studio-0ueISxwP.js +100 -0
- package/studio-dist/client/assets/studio-queries-BflKt9va.js +2 -0
- package/studio-dist/client/assets/usage-Blcl8kA_.js +55 -0
- package/studio-dist/client/assets/useAnchoredPopupScrollLock-BBXJpX5L.js +1 -0
- package/studio-dist/client/assets/useBaseQuery-C2cjmeH2.js +1 -0
- package/studio-dist/client/assets/useMutation-DI6LbvVa.js +1 -0
- package/studio-dist/client/assets/useSelector-AYcH7lB0.js +2 -0
- package/studio-dist/client/assets/vault-Cb9DmM1i.js +1 -0
- package/studio-dist/client/assets/warnings-B-rvoW8q.js +1 -0
- package/studio-dist/client/assets/workflow-DN5T19jd.js +1 -0
- package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-JoHQ5ihx.js +122 -0
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +100 -39
- package/studio-dist/server/assets/{button-CIJqAhni.js → button-B7e1fRyW.js} +63 -3574
- package/studio-dist/server/assets/combobox--S_OmUfh.js +483 -0
- package/studio-dist/server/assets/{companion-view-DISASvdJ.js → companion-view-D-vGM55e.js} +3 -3
- package/studio-dist/server/assets/companions-Dr6IpNAb.js +31 -0
- package/studio-dist/server/assets/{createServerRpc-tK2lE9R2.js → createServerRpc-bFKFpGFG.js} +1 -1
- package/studio-dist/server/assets/fields-B4qM2ZwC.js +1190 -0
- package/studio-dist/server/assets/friction-CWOTjpCV.js +62 -0
- package/studio-dist/server/assets/friction-sLxaWY-H.js +903 -0
- package/studio-dist/server/assets/getting-started-B136TP57.js +4 -0
- package/studio-dist/server/assets/getting-started-Cq5Pcnsr.js +67 -0
- package/studio-dist/server/assets/getting-started._topic-CmWdl3u3.js +13 -0
- package/studio-dist/server/assets/getting-started.index-AB8xpTFY.js +13 -0
- package/studio-dist/server/assets/graph-B11ITte0.js +16 -0
- package/studio-dist/server/assets/graph-C_Hn-Wf_.js +800 -0
- package/studio-dist/server/assets/graph-canvas-BthrSmPS.js +21066 -0
- package/studio-dist/server/assets/graph-wire-BdSUx0G5.js +58 -0
- package/studio-dist/server/assets/guides-B8HdeK_C.js +13 -0
- package/studio-dist/server/assets/guides-BVQ4pt5B.js +5 -0
- package/studio-dist/server/assets/guides.server-DqFQAStf.js +66 -0
- package/studio-dist/server/assets/jsx-runtime-Bt0s0YKS.js +451 -0
- package/studio-dist/server/assets/{markdown-view-Bn7xPdks.js → markdown-view-rwiiVcPC.js} +28 -9
- package/studio-dist/server/assets/{panel-3Jmn4awF.js → panel-CUxRIpYL.js} +5 -5
- package/studio-dist/server/assets/plugins._service._view-BSvGnlhU.js +94 -0
- package/studio-dist/server/assets/{prepaint-DJfTQ_VH.js → prepaint-B28ClcPN.js} +1 -1
- package/studio-dist/server/assets/queries-S_Pl90IG.js +32 -0
- package/studio-dist/server/assets/{react-Ce6dj15C.js → react-CiBZPDs8.js} +3 -4
- package/studio-dist/server/assets/redirect-BaZ_QyqF.js +39 -0
- package/studio-dist/server/assets/{reports-C06RXVE2.js → reports-B9k98oE6.js} +3 -3
- package/studio-dist/server/assets/{reports-D6YMqhnO.js → reports-CJpAItPk.js} +14 -10
- package/studio-dist/server/assets/{router-C8MGqlAY.js → router-DF0etoNa.js} +1322 -3127
- package/studio-dist/server/assets/{routes-BcFgvqf7.js → routes-6ylCLkyg.js} +221 -76
- package/studio-dist/server/assets/search-b-yQesv3.js +78 -0
- package/studio-dist/server/assets/select-CjuKScan.js +1609 -0
- package/studio-dist/server/assets/{shell-DS3wUexh.js → shell-DLkP7wG9.js} +15 -6
- package/studio-dist/server/assets/{skills-CtrBAtX3.js → skills-DGg0mWDM.js} +3 -3
- package/studio-dist/server/assets/{skills-BEnOxiDl.js → skills-zeU80A9S.js} +8 -8
- package/studio-dist/server/assets/specs-DDBNT_v1.js +51 -0
- package/studio-dist/server/assets/specs-view-exvmWdg0.js +425 -0
- package/studio-dist/server/assets/{steps-Dq_CwY_s.js → steps-D1tYAyWZ.js} +88 -45
- package/studio-dist/server/assets/store-kS7zk0Hr.js +93 -0
- package/studio-dist/server/assets/studio-qRvQjRpz.js +10482 -0
- package/studio-dist/server/assets/studio-queries-qOXOYoPt.js +1393 -0
- package/studio-dist/server/assets/usage-C2um7YiV.js +25553 -0
- package/studio-dist/server/assets/usage-Cwle9-xY.js +24 -0
- package/studio-dist/server/assets/useAnchoredPopupScrollLock-kQBB3y_b.js +756 -0
- package/studio-dist/server/assets/useBaseQuery--iH3rd-T.js +2051 -0
- package/studio-dist/server/assets/useMutation-C-WO6hCM.js +690 -0
- package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-M2GBs8s3.js → useSelector-DUmCUXAs.js} +4 -668
- package/studio-dist/server/assets/{vault-Fvxt2Tzl.js → vault-B8vgVIH9.js} +10 -7
- package/studio-dist/server/assets/{vault-BmWnryh3.js → vault-CEBBRLMb.js} +3 -3
- package/studio-dist/server/assets/{views-BgYa-za2.js → views-UgO0Qz_g.js} +9 -6
- package/studio-dist/server/assets/{warnings-DzR6fyZh.js → warnings-BxK4VfV5.js} +2 -2
- package/studio-dist/server/assets/{delivery-path-C29fBynY.js → workflow-BrTK632u.js} +152 -120
- package/studio-dist/server/server.js +582 -8
- package/src/cli/commands/factory/factory.ts +0 -301
- package/src/cli/commands/report/collector.ts +0 -288
- package/src/cli/commands/studio/factory-credential.ts +0 -49
- package/src/cli/commands/studio/workset-session.ts +0 -131
- package/src/lib/delivery/archive-change.ts +0 -165
- package/src/lib/delivery/forge.ts +0 -279
- package/src/lib/delivery/token.ts +0 -24
- package/src/lib/factory/attach-client.ts +0 -113
- package/src/lib/factory/attach.ts +0 -178
- package/src/lib/factory/broker.ts +0 -190
- package/src/lib/factory/bun-commands.ts +0 -39
- package/src/lib/factory/client.ts +0 -92
- package/src/lib/factory/command.ts +0 -61
- package/src/lib/factory/credential-store.ts +0 -153
- package/src/lib/factory/frames.ts +0 -77
- package/src/lib/factory/ids.ts +0 -58
- package/src/lib/factory/outcomes/actions.ts +0 -114
- package/src/lib/factory/outcomes/index.ts +0 -391
- package/src/lib/factory/outcomes/lifecycle.ts +0 -205
- package/src/lib/factory/outcomes/runs.ts +0 -81
- package/src/lib/factory/prepare.ts +0 -49
- package/src/lib/factory/pty.ts +0 -103
- package/src/lib/factory/runner/companion-context.ts +0 -178
- package/src/lib/factory/runner/control.ts +0 -92
- package/src/lib/factory/runner/harness-agent.ts +0 -250
- package/src/lib/factory/runner/live.ts +0 -159
- package/src/lib/factory/runner/questions.ts +0 -22
- package/src/lib/factory/runner/rank.ts +0 -26
- package/src/lib/factory/runner/run-policy.ts +0 -12
- package/src/lib/factory/runner/run.ts +0 -199
- package/src/lib/factory/runner/scheduler.ts +0 -416
- package/src/lib/factory/runner/state.ts +0 -233
- package/src/lib/factory/runner/workflow.ts +0 -542
- package/src/lib/factory/runtime.ts +0 -981
- package/src/lib/factory/sandbox.ts +0 -292
- package/src/lib/factory/worktree-branch.ts +0 -17
- package/src/templates/capabilities/openspec-cap/mate-v1/templates/explore-brief.md +0 -25
- package/studio-dist/client/assets/app-CdPiFv59.css +0 -2
- package/studio-dist/client/assets/button-BIIHE0EQ.js +0 -3
- package/studio-dist/client/assets/companion-view-DM6YyXaR.js +0 -1
- package/studio-dist/client/assets/delivery-path-DELxj0Av.js +0 -1
- package/studio-dist/client/assets/factory-BZy0E8ty.js +0 -4
- package/studio-dist/client/assets/index-B3wkMzjA.js +0 -40
- package/studio-dist/client/assets/markdown-view-pQ2Qp_i5.js +0 -1
- package/studio-dist/client/assets/panel-CbajlC3p.js +0 -1
- package/studio-dist/client/assets/react-CN2GSx7x.js +0 -1
- package/studio-dist/client/assets/reports-DllhYQ5_.js +0 -1
- package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +0 -1
- package/studio-dist/client/assets/routes-COm-G3mK.js +0 -1
- package/studio-dist/client/assets/skills-DmWAy-jZ.js +0 -1
- package/studio-dist/client/assets/specs-BG3Wi3ln.js +0 -1
- package/studio-dist/client/assets/steps-DFsH3Neu.js +0 -1
- package/studio-dist/client/assets/vault-B2q1nBY5.js +0 -1
- package/studio-dist/client/assets/warnings-BSXIyuSQ.js +0 -1
- package/studio-dist/client/assets/workflow-DlsQD6Hc.js +0 -1
- package/studio-dist/server/assets/actions-Bvgj9eb8.js +0 -54
- package/studio-dist/server/assets/companions-BYbHWKOZ.js +0 -15
- package/studio-dist/server/assets/createServerFn-F5sAOF8V.js +0 -459
- package/studio-dist/server/assets/factory-DGPmNGbo.js +0 -69
- package/studio-dist/server/assets/factory-DUTa0eDs.js +0 -2172
- package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +0 -34
- package/studio-dist/server/assets/search-JAKurDNh.js +0 -36
- package/studio-dist/server/assets/specs-C8rv34-5.js +0 -211
- package/studio-dist/server/assets/studio-BeltxxKt.js +0 -216
- package/studio-dist/server/assets/workflow-liRYecHk.js +0 -73
- /package/src/lib/{factory/keyed-serial.ts → keyed-serial.ts} +0 -0
- /package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/spec.md +0 -0
|
@@ -6,39 +6,48 @@ import { FRAMEWORK_NAME } from "../../framework";
|
|
|
6
6
|
import { gitEnvironment, withoutAskPass } from "../../runtime/companion-git";
|
|
7
7
|
import { withCompanionLock } from "../../runtime/companion-lock";
|
|
8
8
|
import { errorMessage } from "../../runtime/error-message";
|
|
9
|
+
import { readGitLayout } from "../../runtime/git-layout";
|
|
10
|
+
import { repoLocalRegistryPath } from "../../runtime/repo-local";
|
|
9
11
|
import type { WrapRuntime } from "../../runtime/runtime-document-manifest";
|
|
10
12
|
import { readWrapState, WRAP_RUNTIMES } from "../../runtime/wrap-state";
|
|
11
13
|
import { cleanupWorkingRepository } from "../../tools/setup/working-repo-cleanup";
|
|
12
|
-
import { locateChange } from "../change-layout";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
14
|
+
import { changeNameOf, type ChangeLocation, locateChange } from "../change-layout";
|
|
15
|
+
import { classifyBranch, configuredProtectedPatterns } from "../delivery/branches";
|
|
16
|
+
import { deliveryCheckout } from "../delivery/checkout";
|
|
15
17
|
import { type DeliveryRecord, readDeliveryRecord } from "../delivery/record";
|
|
16
18
|
import {
|
|
17
|
-
listRefsWith,
|
|
18
|
-
mergeProbeWith,
|
|
19
19
|
newBranchBase,
|
|
20
20
|
resolveDeliveryBranch,
|
|
21
21
|
worktreeAddArgs,
|
|
22
22
|
type BranchSource,
|
|
23
23
|
} from "../delivery/resolve-branch";
|
|
24
|
+
import { repositoryPath } from "../delivery/remote";
|
|
24
25
|
import { scopedRepositories } from "../openspec-scopes";
|
|
25
26
|
import { attendedLockOptions } from "../orchestrator/companion-git-sync";
|
|
27
|
+
import { readCompanionConfig } from "../orchestrator/config-store";
|
|
26
28
|
import {
|
|
27
29
|
findRepoLocalLinkTo,
|
|
28
30
|
readCompanionRegistry,
|
|
29
31
|
writeRepoLocalRegistryEntry,
|
|
30
32
|
} from "../orchestrator/repository-link";
|
|
33
|
+
import { projectionEntries } from "../orchestrator/projection-entries";
|
|
31
34
|
import type { LinkedRepository } from "../orchestrator/types";
|
|
35
|
+
import { linkedCheckoutsOf, type EntryCheckout } from "../orchestrator/umbrella-checkouts";
|
|
32
36
|
import { runWrapPass } from "../orchestrator/wrap-pass";
|
|
33
|
-
import {
|
|
34
|
-
|
|
37
|
+
import {
|
|
38
|
+
indexWorktree,
|
|
39
|
+
UMBRELLA_NOT_INDEXED,
|
|
40
|
+
type IndexOutcome,
|
|
41
|
+
type TokensaveRunner,
|
|
42
|
+
} from "./worktree-index";
|
|
43
|
+
import { copyIncludedFiles, selectIncludedFiles, type IncludeOutcome } from "./worktree-include";
|
|
35
44
|
import { findWorkset, readWorksets, resolveWorksetBranch, resolveWorksetOf } from "./record";
|
|
36
45
|
|
|
37
46
|
/**
|
|
38
47
|
* Workset worktrees outside the factory: one Git worktree per Working Repository at
|
|
39
48
|
* `<main checkout>.worktrees/<workset-id>`, on the Workset's Delivery Branch, linked to
|
|
40
|
-
* the companion, wrapped like its main checkout and installed.
|
|
41
|
-
* path
|
|
49
|
+
* the companion, wrapped like its main checkout and installed. Ignored files named by the
|
|
50
|
+
* main checkout's include files are copied in; other env files are reported by path only.
|
|
42
51
|
*/
|
|
43
52
|
|
|
44
53
|
export interface GitResult {
|
|
@@ -51,6 +60,8 @@ export interface GitRunOptions {
|
|
|
51
60
|
/** Added to the promptless environment every command gets. */
|
|
52
61
|
env?: Record<string, string>;
|
|
53
62
|
timeoutMs?: number;
|
|
63
|
+
/** Written to standard input, which is then closed. */
|
|
64
|
+
input?: string;
|
|
54
65
|
}
|
|
55
66
|
|
|
56
67
|
export type GitRunner = (
|
|
@@ -101,16 +112,36 @@ export interface WorktreeRepositoryResult {
|
|
|
101
112
|
wrap: WrapOutcome;
|
|
102
113
|
/** The worktree's tokensave index; a failure only warns. */
|
|
103
114
|
index: IndexOutcome;
|
|
115
|
+
/** Ignored files copied from the main checkout by its include files. */
|
|
116
|
+
include: IncludeOutcome;
|
|
104
117
|
/** Env files of the main checkout the worktree lacks, relative to the repository root. */
|
|
105
118
|
missingEnv: string[];
|
|
106
119
|
/** Set when a step for this repository failed. */
|
|
107
120
|
error?: string;
|
|
108
121
|
}
|
|
109
122
|
|
|
123
|
+
/** An Umbrella Repository's mirrored worktree, linked and wrapped like the umbrella. */
|
|
124
|
+
export interface UmbrellaWorktreeResult {
|
|
125
|
+
/** The Umbrella Repository. */
|
|
126
|
+
path: string;
|
|
127
|
+
/** The mirrored worktree folder holding the children's worktrees. */
|
|
128
|
+
worktree: string;
|
|
129
|
+
action: "created" | "reused";
|
|
130
|
+
/** The children whose worktree the folder holds, as `org/repository`. */
|
|
131
|
+
repositories: string[];
|
|
132
|
+
wrap: WrapOutcome;
|
|
133
|
+
/** The folder's tokensave index, kept when the umbrella has one; a failure only warns. */
|
|
134
|
+
index: IndexOutcome;
|
|
135
|
+
/** Set when linking or wrapping the folder failed; its worktrees stay. */
|
|
136
|
+
error?: string;
|
|
137
|
+
}
|
|
138
|
+
|
|
110
139
|
export interface WorktreeResult {
|
|
111
140
|
workset: string;
|
|
112
141
|
ok: boolean;
|
|
113
142
|
repositories: WorktreeRepositoryResult[];
|
|
143
|
+
/** Present only when a repository is an Umbrella Repository's child. */
|
|
144
|
+
umbrella?: UmbrellaWorktreeResult;
|
|
114
145
|
diagnostics: string[];
|
|
115
146
|
warnings: string[];
|
|
116
147
|
}
|
|
@@ -125,11 +156,25 @@ export interface PruneEntry {
|
|
|
125
156
|
export interface PruneTarget {
|
|
126
157
|
id: string;
|
|
127
158
|
changes: readonly string[];
|
|
159
|
+
/** Delivery Records already read, by entry of `changes`; others are read from this checkout. */
|
|
160
|
+
records?: ReadonlyMap<string, DeliveryRecord>;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** An Umbrella Repository's mirrored worktree of a Workset. */
|
|
164
|
+
export interface PruneMirrorEntry {
|
|
165
|
+
workset: string;
|
|
166
|
+
umbrella: string;
|
|
167
|
+
path: string;
|
|
128
168
|
}
|
|
129
169
|
|
|
130
170
|
export interface PruneResult {
|
|
131
171
|
removed: PruneEntry[];
|
|
132
172
|
kept: (PruneEntry & { reason: string })[];
|
|
173
|
+
/** Present only when a pruned Workset has a mirrored umbrella worktree. */
|
|
174
|
+
umbrellas?: {
|
|
175
|
+
removed: PruneMirrorEntry[];
|
|
176
|
+
kept: (PruneMirrorEntry & { reason: string })[];
|
|
177
|
+
};
|
|
133
178
|
warnings: string[];
|
|
134
179
|
}
|
|
135
180
|
|
|
@@ -142,19 +187,24 @@ function promptlessEnv(): NodeJS.ProcessEnv {
|
|
|
142
187
|
} as NodeJS.ProcessEnv;
|
|
143
188
|
}
|
|
144
189
|
|
|
145
|
-
const runGit: GitRunner = (cwd, args, options = {}) =>
|
|
190
|
+
export const runGit: GitRunner = (cwd, args, options = {}) =>
|
|
146
191
|
new Promise<GitResult>((resolve) => {
|
|
147
192
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
193
|
+
// Unbounded: a merge check pipes a whole `git log -p` range into `git patch-id`.
|
|
148
194
|
const child = execFile(
|
|
149
195
|
"git",
|
|
150
196
|
args,
|
|
151
|
-
{ cwd, env: { ...promptlessEnv(), ...options.env }, maxBuffer:
|
|
197
|
+
{ cwd, env: { ...promptlessEnv(), ...options.env }, maxBuffer: Infinity },
|
|
152
198
|
(error, stdout, stderr) => {
|
|
153
199
|
clearTimeout(timer);
|
|
154
200
|
const code = error ? (typeof error.code === "number" ? error.code : 1) : 0;
|
|
155
201
|
resolve({ code, stdout: String(stdout), stderr: String(stderr) });
|
|
156
202
|
},
|
|
157
203
|
);
|
|
204
|
+
if (options.input !== undefined) {
|
|
205
|
+
child.stdin?.on("error", () => {});
|
|
206
|
+
child.stdin?.end(options.input);
|
|
207
|
+
}
|
|
158
208
|
const { timeoutMs } = options;
|
|
159
209
|
if (timeoutMs !== undefined) {
|
|
160
210
|
// Resolved without awaiting `close`: an SSH grandchild may hold the pipes open.
|
|
@@ -271,23 +321,42 @@ async function listWorktrees(git: GitRunner, repo: string): Promise<WorktreeEntr
|
|
|
271
321
|
);
|
|
272
322
|
}
|
|
273
323
|
|
|
324
|
+
/** A linked checkout; `umbrella` is set for an Umbrella Repository's child, whose id is the umbrella's. */
|
|
325
|
+
type LinkedCheckout = LinkedRepository & { umbrella?: string };
|
|
326
|
+
|
|
274
327
|
interface LinkedLookup {
|
|
275
|
-
linked:
|
|
328
|
+
linked: LinkedCheckout | null;
|
|
329
|
+
/** Registered paths that no longer exist. */
|
|
330
|
+
missing: string[];
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/** Every checkout linked to the companion, in lookup order, with its `org/repository`. */
|
|
334
|
+
interface LinkedIndex {
|
|
335
|
+
checkouts: { linked: LinkedCheckout; identity: string | null }[];
|
|
276
336
|
/** Registered paths that no longer exist. */
|
|
277
337
|
missing: string[];
|
|
278
338
|
}
|
|
279
339
|
|
|
340
|
+
/** The first checkout in the index whose `origin` is the repository. */
|
|
341
|
+
function linkedCheckout(index: LinkedIndex, repository: string): LinkedLookup {
|
|
342
|
+
// The first match in registry order decides, umbrella children in name order.
|
|
343
|
+
const match = index.checkouts.find(
|
|
344
|
+
({ identity }) => identity?.toLowerCase() === repository.toLowerCase(),
|
|
345
|
+
);
|
|
346
|
+
return { linked: match?.linked ?? null, missing: index.missing };
|
|
347
|
+
}
|
|
348
|
+
|
|
280
349
|
/**
|
|
281
|
-
* The
|
|
282
|
-
*
|
|
283
|
-
*
|
|
350
|
+
* The existing registered checkouts, an Umbrella Repository's children included, then
|
|
351
|
+
* the one the repo-local link holding `cwd` names, so an entry left naming a removed
|
|
352
|
+
* folder does not hide it. Read once per run: expanding an umbrella reads every child's
|
|
353
|
+
* `origin`.
|
|
284
354
|
*/
|
|
285
|
-
async function
|
|
355
|
+
async function linkedIndex(
|
|
286
356
|
companionPath: string,
|
|
287
|
-
repository: string,
|
|
288
357
|
git: GitRunner,
|
|
289
358
|
cwd: string,
|
|
290
|
-
): Promise<
|
|
359
|
+
): Promise<LinkedIndex> {
|
|
291
360
|
let repos: LinkedRepository[] = [];
|
|
292
361
|
try {
|
|
293
362
|
repos = (await readCompanionRegistry(companionPath)).repos;
|
|
@@ -296,24 +365,50 @@ async function linkedCheckout(
|
|
|
296
365
|
}
|
|
297
366
|
const present = await Promise.all(repos.map((repo) => exists(repo.path)));
|
|
298
367
|
const current = await findRepoLocalLinkTo(cwd, companionPath);
|
|
299
|
-
const
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
368
|
+
const entries = [...repos.filter((_, index) => present[index]), ...(current ? [current] : [])];
|
|
369
|
+
const readOrigin = async (checkout: string) => {
|
|
370
|
+
// Raw config, not `remote get-url`, so `insteadOf` rewrites do not change the identity.
|
|
371
|
+
const remote = await git(checkout, ["config", "--get", "remote.origin.url"]);
|
|
372
|
+
return remote.code === 0 ? remote.stdout.trim() || null : null;
|
|
373
|
+
};
|
|
374
|
+
const expanded = await Promise.all(
|
|
375
|
+
entries.map(async (entry) =>
|
|
376
|
+
Promise.all(
|
|
377
|
+
(await linkedCheckoutsOf(entry, readOrigin, readOrigin)).map(async (checkout) => ({
|
|
378
|
+
linked: { ...entry, ...(await mainChild(checkout)) },
|
|
379
|
+
identity: checkout.remote ? repositoryPath(checkout.remote) : null,
|
|
380
|
+
})),
|
|
381
|
+
),
|
|
382
|
+
),
|
|
310
383
|
);
|
|
311
384
|
return {
|
|
312
|
-
|
|
385
|
+
checkouts: expanded.flat(),
|
|
313
386
|
missing: repos.filter((_, at) => !present[at]).map((repo) => repo.path),
|
|
314
387
|
};
|
|
315
388
|
}
|
|
316
389
|
|
|
390
|
+
/**
|
|
391
|
+
* The checkout and umbrella an entry's checkout stands for. A child of a mirrored worktree
|
|
392
|
+
* `<umbrella>.worktrees/<id>/<name>`, a worktree of `<umbrella>/<name>`, stands for that
|
|
393
|
+
* main checkout, so the real umbrella stays the one mirrored.
|
|
394
|
+
*/
|
|
395
|
+
async function mainChild(checkout: EntryCheckout): Promise<{ path: string; umbrella?: string }> {
|
|
396
|
+
const { path: child } = checkout;
|
|
397
|
+
if (!checkout.umbrella) return { path: child };
|
|
398
|
+
// Canonical, so an umbrella reached by a registry path and by Git's paths is one.
|
|
399
|
+
const umbrella = await canonical(checkout.umbrella);
|
|
400
|
+
const layout = readGitLayout(child);
|
|
401
|
+
if (layout?.kind === "linked" && path.basename(layout.commonDir) === ".git") {
|
|
402
|
+
const main = path.dirname(layout.commonDir);
|
|
403
|
+
const real = await canonical(path.dirname(main));
|
|
404
|
+
const mirrored =
|
|
405
|
+
path.basename(main) === path.basename(child) &&
|
|
406
|
+
(await canonical(worktreePathFor(real, path.basename(umbrella)))) === umbrella;
|
|
407
|
+
if (mirrored) return { path: main, umbrella: real };
|
|
408
|
+
}
|
|
409
|
+
return { path: child, umbrella };
|
|
410
|
+
}
|
|
411
|
+
|
|
317
412
|
interface Plan {
|
|
318
413
|
repository: string;
|
|
319
414
|
/** The main checkout's Repository Link id, which the worktree's link repeats. */
|
|
@@ -325,6 +420,10 @@ interface Plan {
|
|
|
325
420
|
/** Start point when `source` is `new`. */
|
|
326
421
|
base?: string;
|
|
327
422
|
reuse: boolean;
|
|
423
|
+
/** `--take-branch`: `branch` is checked out in `checkout`, which is detached first. */
|
|
424
|
+
take?: boolean;
|
|
425
|
+
/** Set for an Umbrella Repository's child: the umbrella, whose mirrored worktree holds `target`. */
|
|
426
|
+
umbrella?: string;
|
|
328
427
|
}
|
|
329
428
|
|
|
330
429
|
/** A resolved Workset: its id and the repositories that get a worktree. */
|
|
@@ -362,25 +461,100 @@ async function changeTarget(companionPath: string, change: string): Promise<Targ
|
|
|
362
461
|
return { id: resolution.id, repositories };
|
|
363
462
|
}
|
|
364
463
|
|
|
464
|
+
type ProtectedPatterns = readonly string[];
|
|
465
|
+
|
|
466
|
+
type PlanOptions = Pick<CreateWorktreesOptions, "ticket" | "takeBranch"> & {
|
|
467
|
+
/** The companion's protected patterns, read once for every repository's take. */
|
|
468
|
+
protectedPatterns?: ProtectedPatterns;
|
|
469
|
+
};
|
|
470
|
+
|
|
365
471
|
/** Phase 1: every check for every repository; any failure means nothing is created. */
|
|
366
472
|
async function planWorktrees(
|
|
367
473
|
companionPath: string,
|
|
368
474
|
target: Target,
|
|
369
475
|
git: GitRunner,
|
|
370
476
|
cwd: string,
|
|
371
|
-
ticket
|
|
372
|
-
): Promise<{ plans: Plan[]; diagnostics: string[]; warnings: string[] }> {
|
|
477
|
+
options: Pick<CreateWorktreesOptions, "ticket" | "takeBranch">,
|
|
478
|
+
): Promise<{ plans: Plan[]; mirror?: Mirror; diagnostics: string[]; warnings: string[] }> {
|
|
373
479
|
const warnings: string[] = [];
|
|
480
|
+
const index = await linkedIndex(companionPath, git, cwd);
|
|
481
|
+
const planOptions: PlanOptions = options.takeBranch
|
|
482
|
+
? {
|
|
483
|
+
...options,
|
|
484
|
+
protectedPatterns: configuredProtectedPatterns(
|
|
485
|
+
(await readCompanionConfig(companionPath)).capabilities ?? [],
|
|
486
|
+
),
|
|
487
|
+
}
|
|
488
|
+
: options;
|
|
374
489
|
const checked = await Promise.all(
|
|
375
490
|
target.repositories.map((repository) =>
|
|
376
|
-
planRepository(companionPath, target.id, repository, git,
|
|
491
|
+
planRepository(companionPath, target.id, repository, git, index, warnings, planOptions),
|
|
377
492
|
),
|
|
378
493
|
);
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
};
|
|
494
|
+
const plans = checked.filter((entry): entry is Plan => !Array.isArray(entry));
|
|
495
|
+
const diagnostics = checked.flatMap((entry) => (Array.isArray(entry) ? entry : []));
|
|
496
|
+
const mirror = await planMirror(companionPath, target.id, plans);
|
|
497
|
+
if (Array.isArray(mirror)) return { plans, diagnostics: [...diagnostics, ...mirror], warnings };
|
|
498
|
+
return { plans, ...(mirror ? { mirror } : {}), diagnostics, warnings };
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/** The mirrored worktree a Workset's umbrella children get. */
|
|
502
|
+
interface Mirror {
|
|
503
|
+
umbrella: string;
|
|
504
|
+
/** The umbrella's Repository Link id, which the folder's link repeats. */
|
|
505
|
+
repositoryId: string;
|
|
506
|
+
folder: string;
|
|
507
|
+
/** The folder already is this umbrella's mirrored worktree. */
|
|
508
|
+
reuse: boolean;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* The mirrored worktree of the plans' Umbrella Repository, or the diagnostics that stop
|
|
513
|
+
* the run: the folder must be this umbrella's mirrored worktree, or hold nothing but OS
|
|
514
|
+
* metadata, Mate's material, and its children's reused worktrees, as a run interrupted
|
|
515
|
+
* before linking leaves it.
|
|
516
|
+
*/
|
|
517
|
+
async function planMirror(
|
|
518
|
+
companionPath: string,
|
|
519
|
+
worksetId: string,
|
|
520
|
+
plans: readonly Plan[],
|
|
521
|
+
): Promise<Mirror | string[] | undefined> {
|
|
522
|
+
const children = plans.filter((plan) => plan.umbrella);
|
|
523
|
+
const umbrellas = [...new Set(children.map((plan) => plan.umbrella!))];
|
|
524
|
+
if (umbrellas.length === 0) return undefined;
|
|
525
|
+
if (umbrellas.length > 1) {
|
|
526
|
+
return [
|
|
527
|
+
`the Workset spans the Umbrella Repositories ${umbrellas.join(", ")}; a mirrored worktree serves one`,
|
|
528
|
+
];
|
|
529
|
+
}
|
|
530
|
+
const umbrella = umbrellas[0]!;
|
|
531
|
+
const repositoryId = children[0]!.repositoryId;
|
|
532
|
+
const folder = await canonical(worktreePathFor(umbrella, worksetId));
|
|
533
|
+
if (await isMirrorOf(folder, companionPath, repositoryId)) {
|
|
534
|
+
return { umbrella, repositoryId, folder, reuse: true };
|
|
535
|
+
}
|
|
536
|
+
// A link of its own names another companion or id: someone else's folder.
|
|
537
|
+
if (await exists(repoLocalRegistryPath(folder))) {
|
|
538
|
+
return [`${folder} exists and is not the mirrored worktree of ${umbrella}`];
|
|
539
|
+
}
|
|
540
|
+
const listed = await fs.readdir(folder).catch(() => []);
|
|
541
|
+
const material = mirrorMaterial();
|
|
542
|
+
const reused = new Set(
|
|
543
|
+
children.filter((plan) => plan.reuse).map((plan) => path.basename(plan.target)),
|
|
544
|
+
);
|
|
545
|
+
const foreign = listed.filter((name) => !material.has(name) && !reused.has(name));
|
|
546
|
+
if (foreign.length === 0) return { umbrella, repositoryId, folder, reuse: false };
|
|
547
|
+
return [`${folder} exists and is not the mirrored worktree of ${umbrella}`];
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/** `folder` carries its own repo-local link to the companion under the umbrella's id. */
|
|
551
|
+
async function isMirrorOf(
|
|
552
|
+
folder: string,
|
|
553
|
+
companionPath: string,
|
|
554
|
+
repositoryId: string,
|
|
555
|
+
): Promise<boolean> {
|
|
556
|
+
const link = await findRepoLocalLinkTo(folder, companionPath);
|
|
557
|
+
return link !== null && link.id === repositoryId && (await canonical(link.path)) === folder;
|
|
384
558
|
}
|
|
385
559
|
|
|
386
560
|
/** One repository's plan, or the diagnostics that stop the run. */
|
|
@@ -389,11 +563,11 @@ async function planRepository(
|
|
|
389
563
|
worksetId: string,
|
|
390
564
|
repository: string,
|
|
391
565
|
git: GitRunner,
|
|
392
|
-
|
|
566
|
+
index: LinkedIndex,
|
|
393
567
|
warnings: string[],
|
|
394
|
-
ticket
|
|
568
|
+
{ ticket, takeBranch, protectedPatterns }: PlanOptions,
|
|
395
569
|
): Promise<Plan | string[]> {
|
|
396
|
-
const { linked, missing } =
|
|
570
|
+
const { linked, missing } = linkedCheckout(index, repository);
|
|
397
571
|
if (!linked) {
|
|
398
572
|
// An identity problem outranks the missing link.
|
|
399
573
|
const identity = await resolveWorksetBranch(companionPath, worksetId, repository);
|
|
@@ -410,23 +584,24 @@ async function planRepository(
|
|
|
410
584
|
`${repository}: fetching origin failed, using local refs: ${fetched.stderr.trim()}`,
|
|
411
585
|
);
|
|
412
586
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
listRefs: listRefsWith(async (args) => {
|
|
420
|
-
const listed = await git(linked.path, args);
|
|
421
|
-
return listed.code === 0 ? listed.stdout : null;
|
|
587
|
+
// Every probe runs through the same runner; it already adds the promptless environment.
|
|
588
|
+
const checkout = deliveryCheckout(linked.path, (args, { input, timeoutMs }) =>
|
|
589
|
+
git(linked.path, [...args], {
|
|
590
|
+
env: { GIT_NO_LAZY_FETCH: "1" },
|
|
591
|
+
...(input !== undefined ? { input } : {}),
|
|
592
|
+
...(timeoutMs !== undefined ? { timeoutMs } : {}),
|
|
422
593
|
}),
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
594
|
+
);
|
|
595
|
+
const resolution = await resolveDeliveryBranch(
|
|
596
|
+
checkout,
|
|
597
|
+
{ companionPath, repository, worksetId },
|
|
598
|
+
ticket ? { ticket } : {},
|
|
599
|
+
);
|
|
600
|
+
// Concerns the companion, not a repository: reported once, first.
|
|
601
|
+
const { templateDiagnostic } = resolution;
|
|
602
|
+
if (templateDiagnostic && !warnings.includes(templateDiagnostic)) {
|
|
603
|
+
warnings.unshift(templateDiagnostic);
|
|
604
|
+
}
|
|
430
605
|
const { branch, source } = resolution;
|
|
431
606
|
if (branch === null || source === null) {
|
|
432
607
|
return resolution.diagnostics.map((line) => `${repository}: ${line}`);
|
|
@@ -436,7 +611,11 @@ async function planRepository(
|
|
|
436
611
|
const entries = await listWorktrees(git, linked.path);
|
|
437
612
|
const main = entries?.[0];
|
|
438
613
|
if (!main) return [`${repository}: cannot list the worktrees of ${linked.path}`];
|
|
439
|
-
const target = await canonical(
|
|
614
|
+
const target = await canonical(
|
|
615
|
+
linked.umbrella
|
|
616
|
+
? path.join(worktreePathFor(linked.umbrella, worksetId), path.basename(linked.path))
|
|
617
|
+
: worktreePathFor(main.path, worksetId),
|
|
618
|
+
);
|
|
440
619
|
const atTarget = entries.find((entry) => entry.path === target);
|
|
441
620
|
// A stale entry is never reused: wrapping it would only refill a folder without a checkout.
|
|
442
621
|
const stale = entries.find(
|
|
@@ -447,11 +626,20 @@ async function planRepository(
|
|
|
447
626
|
`${repository}: ${stale.path} is a stale worktree entry (${stale.stale}); remove any folder left there, run \`git worktree prune\` in ${main.path}, then retry`,
|
|
448
627
|
];
|
|
449
628
|
}
|
|
450
|
-
const plan = {
|
|
629
|
+
const plan = {
|
|
630
|
+
repository,
|
|
631
|
+
repositoryId: linked.id,
|
|
632
|
+
checkout: main.path,
|
|
633
|
+
branch,
|
|
634
|
+
source,
|
|
635
|
+
...(linked.umbrella ? { umbrella: linked.umbrella } : {}),
|
|
636
|
+
};
|
|
451
637
|
const elsewhere = entries.find((entry) => entry.branch === branch && entry.path !== target);
|
|
452
638
|
const inherited = resolution.inheritedFrom.join(", ");
|
|
639
|
+
const take = Boolean(takeBranch && elsewhere?.path === main.path);
|
|
453
640
|
// An inherited branch is the dependency's worktree; one branch has one worktree.
|
|
454
|
-
|
|
641
|
+
// In the main checkout, only `--take-branch` moves it out.
|
|
642
|
+
if (elsewhere && inherited && !atTarget && !take) {
|
|
455
643
|
if (elsewhere.path === main.path) {
|
|
456
644
|
return [
|
|
457
645
|
`${repository}: ${branch}, inherited from ${inherited}, is checked out in ${main.path}; work there or switch it to another branch`,
|
|
@@ -466,20 +654,97 @@ async function planRepository(
|
|
|
466
654
|
if (!reuse && (atTarget || (await exists(target)))) {
|
|
467
655
|
return [`${repository}: ${target} exists and is not a worktree of ${repository} on ${branch}`];
|
|
468
656
|
}
|
|
657
|
+
if (take) {
|
|
658
|
+
const refusal = await takeRefusal(git, main.path, branch, checkout, protectedPatterns ?? []);
|
|
659
|
+
if (refusal) return [`${repository}: ${refusal}`];
|
|
660
|
+
return { ...plan, target, reuse: false, take: true };
|
|
661
|
+
}
|
|
469
662
|
if (elsewhere) return [`${repository}: ${branch} is already checked out at ${elsewhere.path}`];
|
|
470
663
|
return {
|
|
471
664
|
...plan,
|
|
472
665
|
target,
|
|
473
|
-
base: source === "new" ? await newBranchBase(hasRef) : undefined,
|
|
666
|
+
base: source === "new" ? await newBranchBase(checkout.hasRef) : undefined,
|
|
474
667
|
reuse,
|
|
475
668
|
};
|
|
476
669
|
}
|
|
477
670
|
|
|
671
|
+
/** Why `--take-branch` leaves `branch` in the main checkout `main`, or null to take it. */
|
|
672
|
+
async function takeRefusal(
|
|
673
|
+
git: GitRunner,
|
|
674
|
+
main: string,
|
|
675
|
+
branch: string,
|
|
676
|
+
checkout: { defaultBranch(): Promise<string> },
|
|
677
|
+
patterns: ProtectedPatterns,
|
|
678
|
+
): Promise<string | null> {
|
|
679
|
+
const protection = classifyBranch(branch, {
|
|
680
|
+
defaultBranch: await checkout.defaultBranch(),
|
|
681
|
+
patterns,
|
|
682
|
+
});
|
|
683
|
+
if (protection.protected) {
|
|
684
|
+
return `--take-branch does not take the protected branch ${branch} out of ${main}`;
|
|
685
|
+
}
|
|
686
|
+
return trackedChangesRefusal(git, main);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/** Why `main`'s tracked changes block a take, or null when it has none. */
|
|
690
|
+
async function trackedChangesRefusal(git: GitRunner, main: string): Promise<string | null> {
|
|
691
|
+
const status = await git(main, ["status", "--porcelain", "-z", "--untracked-files=no"]);
|
|
692
|
+
if (status.code !== 0) return `cannot read the status of ${main}: ${status.stderr.trim()}`;
|
|
693
|
+
// `XY path\0`; a rename or copy, in either column, adds its source as the next field,
|
|
694
|
+
// which is skipped.
|
|
695
|
+
const fields = status.stdout.split("\0");
|
|
696
|
+
const changed: string[] = [];
|
|
697
|
+
for (let at = 0; at < fields.length; at++) {
|
|
698
|
+
const field = fields[at]!;
|
|
699
|
+
if (field.length <= 3) continue;
|
|
700
|
+
changed.push(field.slice(3));
|
|
701
|
+
if (/[RC]/.test(field.slice(0, 2))) at++;
|
|
702
|
+
}
|
|
703
|
+
if (changed.length > 0) {
|
|
704
|
+
return `${main} has uncommitted changes to tracked files (${changed.join(", ")}); commit or stash them, then retry --take-branch`;
|
|
705
|
+
}
|
|
706
|
+
return null;
|
|
707
|
+
}
|
|
708
|
+
|
|
478
709
|
async function addWorktree(git: GitRunner, plan: Plan): Promise<string | null> {
|
|
479
710
|
const result = await git(plan.checkout, worktreeAddArgs(plan, plan.target, plan.base));
|
|
480
711
|
return result.code === 0 ? null : `creating the worktree failed: ${result.stderr.trim()}`;
|
|
481
712
|
}
|
|
482
713
|
|
|
714
|
+
/**
|
|
715
|
+
* `--take-branch`: detach the main checkout, add the worktree, and undo both on failure.
|
|
716
|
+
* Earlier repositories' takes stay: their worktrees are made, as for any later failure.
|
|
717
|
+
*/
|
|
718
|
+
async function takeIntoWorktree(
|
|
719
|
+
git: GitRunner,
|
|
720
|
+
plan: Plan,
|
|
721
|
+
warnings: string[],
|
|
722
|
+
): Promise<string | null> {
|
|
723
|
+
// Checked again: earlier repositories' setup may have given the developer time to edit.
|
|
724
|
+
const changed = await trackedChangesRefusal(git, plan.checkout);
|
|
725
|
+
if (changed) return changed;
|
|
726
|
+
const detached = await git(plan.checkout, ["switch", "--detach"]);
|
|
727
|
+
if (detached.code !== 0) return `detaching ${plan.checkout} failed: ${detached.stderr.trim()}`;
|
|
728
|
+
const failure = await addWorktree(git, plan);
|
|
729
|
+
if (!failure) {
|
|
730
|
+
warnings.push(
|
|
731
|
+
`${plan.repository}: ${plan.checkout} is now on a detached HEAD; ${plan.branch} moved to ${plan.target}`,
|
|
732
|
+
);
|
|
733
|
+
return null;
|
|
734
|
+
}
|
|
735
|
+
// Back to the state before the command, so a failed take changes nothing visible. A
|
|
736
|
+
// worktree registered before the add failed still holds the branch; the planned target
|
|
737
|
+
// did not exist, so removing it drops only what the add left. A failed remove matters
|
|
738
|
+
// only when the switch back fails too: an add that registered nothing leaves nothing.
|
|
739
|
+
const removed = await git(plan.checkout, ["worktree", "remove", "--force", plan.target]);
|
|
740
|
+
await git(plan.checkout, ["worktree", "prune"]);
|
|
741
|
+
const restored = await git(plan.checkout, ["switch", plan.branch]);
|
|
742
|
+
if (restored.code === 0) return failure;
|
|
743
|
+
const kept =
|
|
744
|
+
removed.code === 0 ? "" : `; removing ${plan.target} failed: ${removed.stderr.trim()}`;
|
|
745
|
+
return `${failure}${kept}; switching ${plan.checkout} back to ${plan.branch} failed: ${restored.stderr.trim()}`;
|
|
746
|
+
}
|
|
747
|
+
|
|
483
748
|
/** The runtimes `checkout` is wrapped for, in wrap order. */
|
|
484
749
|
async function wrappedRuntimes(checkout: string, deps: WorktreeDeps): Promise<WrapRuntime[]> {
|
|
485
750
|
const state = await (deps.readWrapState ?? readWrapState)(checkout);
|
|
@@ -556,10 +821,18 @@ async function missingEnvFiles(
|
|
|
556
821
|
|
|
557
822
|
export interface CreateWorktreesOptions {
|
|
558
823
|
install: boolean;
|
|
559
|
-
/**
|
|
824
|
+
/**
|
|
825
|
+
* Names a new Delivery Branch by the template (default `workset/<TICKET>-<id>`); an existing
|
|
826
|
+
* or recorded one wins.
|
|
827
|
+
*/
|
|
560
828
|
ticket?: string;
|
|
561
829
|
/** Pass the installer's output through; false discards it, as `--json` needs. */
|
|
562
830
|
streamInstall: boolean;
|
|
831
|
+
/**
|
|
832
|
+
* Take a resolved, unprotected branch, inherited ones included, out of a main checkout
|
|
833
|
+
* without tracked changes: detach that checkout, then add the worktree on the branch.
|
|
834
|
+
*/
|
|
835
|
+
takeBranch?: boolean;
|
|
563
836
|
}
|
|
564
837
|
|
|
565
838
|
/**
|
|
@@ -605,12 +878,12 @@ async function createTargetWorktrees(
|
|
|
605
878
|
const worksetId = target.id;
|
|
606
879
|
const git = deps.git ?? runGit;
|
|
607
880
|
const cwd = (deps.cwd ?? process.cwd)();
|
|
608
|
-
const { plans, diagnostics, warnings } = await planWorktrees(
|
|
881
|
+
const { plans, mirror, diagnostics, warnings } = await planWorktrees(
|
|
609
882
|
companionPath,
|
|
610
883
|
target,
|
|
611
884
|
git,
|
|
612
885
|
cwd,
|
|
613
|
-
options
|
|
886
|
+
options,
|
|
614
887
|
);
|
|
615
888
|
if (diagnostics.length > 0) {
|
|
616
889
|
return { workset: worksetId, ok: false, repositories: [], diagnostics, warnings };
|
|
@@ -634,21 +907,118 @@ async function createTargetWorktrees(
|
|
|
634
907
|
}),
|
|
635
908
|
);
|
|
636
909
|
}
|
|
910
|
+
// After its children exist, so the folder is linked only once it holds a worktree.
|
|
911
|
+
const held = plans.flatMap((plan, at) =>
|
|
912
|
+
plan.umbrella && repositories[at]!.install.reason !== NOT_CREATED ? [plan.repository] : [],
|
|
913
|
+
);
|
|
914
|
+
const umbrella =
|
|
915
|
+
mirror && held.length > 0
|
|
916
|
+
? await realizeMirror(companionPath, mirror, held, deps, warnings)
|
|
917
|
+
: undefined;
|
|
918
|
+
// An unlinked mirror is reported broken; it gets no index. It holds the children's
|
|
919
|
+
// worktrees, so it is indexed after theirs rather than over them.
|
|
920
|
+
if (umbrella && mirror && !umbrella.error) {
|
|
921
|
+
const children = Promise.all(indexing);
|
|
922
|
+
indexing.push(
|
|
923
|
+
children
|
|
924
|
+
.then(() =>
|
|
925
|
+
indexWorktree(
|
|
926
|
+
mirror.umbrella,
|
|
927
|
+
mirror.folder,
|
|
928
|
+
companionPath,
|
|
929
|
+
deps.tokensave,
|
|
930
|
+
(action) => progress?.(`${mirror.umbrella}: tokensave ${action} of ${mirror.folder}…`),
|
|
931
|
+
UMBRELLA_NOT_INDEXED,
|
|
932
|
+
),
|
|
933
|
+
)
|
|
934
|
+
.then((index) => {
|
|
935
|
+
umbrella.index = index;
|
|
936
|
+
}),
|
|
937
|
+
);
|
|
938
|
+
}
|
|
637
939
|
await Promise.all(indexing);
|
|
638
940
|
for (const result of repositories) {
|
|
639
941
|
if (result.index.outcome === "failed") {
|
|
640
942
|
warnings.push(`${result.repository}: tokensave index step failed: ${result.index.reason}`);
|
|
641
943
|
}
|
|
642
944
|
}
|
|
945
|
+
if (umbrella?.index.outcome === "failed") {
|
|
946
|
+
warnings.push(`${umbrella.path}: tokensave index step failed: ${umbrella.index.reason}`);
|
|
947
|
+
}
|
|
643
948
|
return {
|
|
644
949
|
workset: worksetId,
|
|
645
|
-
ok: repositories.every((entry) => !entry.error),
|
|
950
|
+
ok: repositories.every((entry) => !entry.error) && !umbrella?.error,
|
|
646
951
|
repositories,
|
|
952
|
+
...(umbrella ? { umbrella } : {}),
|
|
647
953
|
diagnostics,
|
|
648
954
|
warnings,
|
|
649
955
|
};
|
|
650
956
|
}
|
|
651
957
|
|
|
958
|
+
/**
|
|
959
|
+
* Links the mirrored worktree folder under the umbrella's id, without the companion
|
|
960
|
+
* registry, and wraps it for the umbrella's runtimes. Its children get neither: the
|
|
961
|
+
* folder's projection serves them, as the umbrella's serves its own.
|
|
962
|
+
*/
|
|
963
|
+
async function realizeMirror(
|
|
964
|
+
companionPath: string,
|
|
965
|
+
mirror: Mirror,
|
|
966
|
+
repositories: string[],
|
|
967
|
+
deps: WorktreeDeps,
|
|
968
|
+
warnings: string[],
|
|
969
|
+
): Promise<UmbrellaWorktreeResult> {
|
|
970
|
+
const { wrap, error, warning } = await linkAndWrap(
|
|
971
|
+
companionPath,
|
|
972
|
+
{ id: mirror.repositoryId, path: mirror.folder },
|
|
973
|
+
mirror.umbrella,
|
|
974
|
+
mirror.reuse,
|
|
975
|
+
deps,
|
|
976
|
+
);
|
|
977
|
+
if (warning) warnings.push(`${mirror.folder}: ${warning}`);
|
|
978
|
+
return {
|
|
979
|
+
path: mirror.umbrella,
|
|
980
|
+
worktree: mirror.folder,
|
|
981
|
+
action: mirror.reuse ? "reused" : "created",
|
|
982
|
+
repositories,
|
|
983
|
+
wrap,
|
|
984
|
+
index: { outcome: "skipped", ...(error ? { reason: "mirrored worktree broken" } : {}) },
|
|
985
|
+
...(error ? { error } : {}),
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
/**
|
|
990
|
+
* Links `repository.path` to the companion and wraps it like `wrappedFrom`. A reused
|
|
991
|
+
* folder still wrapped from before stays usable, so a failed refresh only warns.
|
|
992
|
+
*/
|
|
993
|
+
async function linkAndWrap(
|
|
994
|
+
companionPath: string,
|
|
995
|
+
repository: LinkedRepository,
|
|
996
|
+
wrappedFrom: string,
|
|
997
|
+
reuse: boolean,
|
|
998
|
+
deps: WorktreeDeps,
|
|
999
|
+
): Promise<{ wrap: WrapOutcome; error?: string; warning?: string }> {
|
|
1000
|
+
try {
|
|
1001
|
+
await (deps.writeLink ?? writeRepoLocalRegistryEntry)(
|
|
1002
|
+
repository.path,
|
|
1003
|
+
companionPath,
|
|
1004
|
+
repository,
|
|
1005
|
+
"existing",
|
|
1006
|
+
);
|
|
1007
|
+
} catch (error) {
|
|
1008
|
+
return {
|
|
1009
|
+
wrap: { runtimes: [], outcome: "skipped", reason: "worktree not linked" },
|
|
1010
|
+
error: `linking the worktree failed: ${errorMessage(error)}`,
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
const wrap = await wrapWorktree(companionPath, wrappedFrom, repository, deps);
|
|
1014
|
+
if (wrap.outcome !== "failed") return { wrap };
|
|
1015
|
+
const message = `wrapping the worktree failed: ${wrap.reason}`;
|
|
1016
|
+
if (reuse && (await stillWrapped(repository.path, wrap.runtimes, deps))) {
|
|
1017
|
+
return { wrap, warning: `${message}; its earlier wrap stays` };
|
|
1018
|
+
}
|
|
1019
|
+
return { wrap, error: message };
|
|
1020
|
+
}
|
|
1021
|
+
|
|
652
1022
|
async function realize(
|
|
653
1023
|
companionPath: string,
|
|
654
1024
|
plan: Plan,
|
|
@@ -666,10 +1036,13 @@ async function realize(
|
|
|
666
1036
|
install: { command: null, outcome: "skipped" },
|
|
667
1037
|
wrap: { runtimes: [], outcome: "skipped" },
|
|
668
1038
|
index: { outcome: "skipped" },
|
|
1039
|
+
include: { sources: [], copied: [], failed: [] },
|
|
669
1040
|
missingEnv: [],
|
|
670
1041
|
};
|
|
671
1042
|
if (!plan.reuse) {
|
|
672
|
-
const failure =
|
|
1043
|
+
const failure = plan.take
|
|
1044
|
+
? await takeIntoWorktree(git, plan, warnings)
|
|
1045
|
+
: await addWorktree(git, plan);
|
|
673
1046
|
if (failure) {
|
|
674
1047
|
return {
|
|
675
1048
|
...result,
|
|
@@ -680,28 +1053,27 @@ async function realize(
|
|
|
680
1053
|
};
|
|
681
1054
|
}
|
|
682
1055
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
1056
|
+
if (plan.umbrella) {
|
|
1057
|
+
result.wrap.reason = "served by the mirrored worktree";
|
|
1058
|
+
} else {
|
|
1059
|
+
// The main checkout's id: a session moved here keeps its `MATE_REPOSITORY_ID`.
|
|
1060
|
+
const linked = await linkAndWrap(
|
|
688
1061
|
companionPath,
|
|
689
|
-
|
|
690
|
-
|
|
1062
|
+
{ id: plan.repositoryId, path: plan.target },
|
|
1063
|
+
plan.checkout,
|
|
1064
|
+
plan.reuse,
|
|
1065
|
+
deps,
|
|
691
1066
|
);
|
|
692
|
-
result.wrap =
|
|
693
|
-
if (result.
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
}
|
|
702
|
-
} catch (error) {
|
|
703
|
-
result.error = `linking the worktree failed: ${errorMessage(error)}`;
|
|
704
|
-
result.wrap.reason = "worktree not linked";
|
|
1067
|
+
result.wrap = linked.wrap;
|
|
1068
|
+
if (linked.error) result.error = linked.error;
|
|
1069
|
+
if (linked.warning) warnings.push(`${plan.repository}: ${linked.warning}`);
|
|
1070
|
+
}
|
|
1071
|
+
// Before install: a copied `.npmrc` may be what lets it reach a private registry.
|
|
1072
|
+
const selection = await selectIncludedFiles(git, plan.checkout);
|
|
1073
|
+
for (const warning of selection.warnings) warnings.push(`${plan.repository}: ${warning}`);
|
|
1074
|
+
result.include = await copyIncludedFiles(plan.checkout, plan.target, selection);
|
|
1075
|
+
if (result.include.failed.length > 0) {
|
|
1076
|
+
result.error ??= `copying ${result.include.failed.map((entry) => entry.path).join(", ")} failed`;
|
|
705
1077
|
}
|
|
706
1078
|
const command = await installCommand(plan.target);
|
|
707
1079
|
result.install.command = command ? command.join(" ") : null;
|
|
@@ -756,26 +1128,42 @@ async function keepReason(
|
|
|
756
1128
|
return null;
|
|
757
1129
|
}
|
|
758
1130
|
|
|
1131
|
+
/**
|
|
1132
|
+
* The folder of `change` in this checkout; an archive anchor not archived here falls back
|
|
1133
|
+
* to its undated change name, which a checkout behind the published commit still holds.
|
|
1134
|
+
*/
|
|
1135
|
+
async function localChange(companionPath: string, change: string): Promise<ChangeLocation | null> {
|
|
1136
|
+
const found = await locateChange(companionPath, change);
|
|
1137
|
+
if (found) return found;
|
|
1138
|
+
const name = changeNameOf(change);
|
|
1139
|
+
return name === change ? null : await locateChange(companionPath, name);
|
|
1140
|
+
}
|
|
1141
|
+
|
|
759
1142
|
/** Recorded Delivery Branches per Working Repository; not-applicable deliveries name none. */
|
|
760
1143
|
async function recordedBranches(
|
|
761
1144
|
companionPath: string,
|
|
762
|
-
changes:
|
|
1145
|
+
{ changes, records }: PruneTarget,
|
|
763
1146
|
warnings: string[],
|
|
764
1147
|
): Promise<Map<string, Set<string>>> {
|
|
765
1148
|
const byRepository = new Map<string, Set<string>>();
|
|
766
1149
|
for (const change of changes) {
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
if (!location) continue;
|
|
770
|
-
let record: DeliveryRecord | null;
|
|
771
|
-
try {
|
|
1150
|
+
let record = records?.get(change) ?? null;
|
|
1151
|
+
if (!record) {
|
|
772
1152
|
// oxlint-disable-next-line no-await-in-loop -- a few small files, in order
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
1153
|
+
const location = await localChange(companionPath, change);
|
|
1154
|
+
try {
|
|
1155
|
+
// oxlint-disable-next-line no-await-in-loop -- a few small files, in order
|
|
1156
|
+
record = location ? await readDeliveryRecord(location.dir) : null;
|
|
1157
|
+
} catch (error) {
|
|
1158
|
+
warnings.push(`${change}: cannot read its Delivery Record: ${errorMessage(error)}`);
|
|
1159
|
+
continue;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
if (!record) {
|
|
1163
|
+
warnings.push(`${change}: no Delivery Record found, its worktrees were not cleaned up`);
|
|
776
1164
|
continue;
|
|
777
1165
|
}
|
|
778
|
-
for (const delivery of record
|
|
1166
|
+
for (const delivery of record.deliveries) {
|
|
779
1167
|
if (!delivery.branch || delivery.notApplicable) continue;
|
|
780
1168
|
const branches = byRepository.get(delivery.repository) ?? new Set<string>();
|
|
781
1169
|
branches.add(delivery.branch);
|
|
@@ -785,27 +1173,24 @@ async function recordedBranches(
|
|
|
785
1173
|
return byRepository;
|
|
786
1174
|
}
|
|
787
1175
|
|
|
1176
|
+
/** Returns the Umbrella Repository whose child the repository is, so its mirror is pruned after. */
|
|
788
1177
|
async function pruneRepository(
|
|
789
1178
|
companionPath: string,
|
|
790
1179
|
worksetId: string,
|
|
791
1180
|
repository: string,
|
|
792
1181
|
branches: ReadonlySet<string>,
|
|
1182
|
+
index: LinkedIndex,
|
|
793
1183
|
git: GitRunner,
|
|
794
1184
|
deps: WorktreeDeps,
|
|
795
1185
|
result: PruneResult,
|
|
796
|
-
): Promise<
|
|
797
|
-
const { linked } =
|
|
798
|
-
|
|
799
|
-
repository,
|
|
800
|
-
git,
|
|
801
|
-
(deps.cwd ?? process.cwd)(),
|
|
802
|
-
);
|
|
803
|
-
if (!linked) return;
|
|
1186
|
+
): Promise<LinkedCheckout | undefined> {
|
|
1187
|
+
const { linked } = linkedCheckout(index, repository);
|
|
1188
|
+
if (!linked) return undefined;
|
|
804
1189
|
const entries = await listWorktrees(git, linked.path);
|
|
805
1190
|
const main = entries?.[0];
|
|
806
1191
|
if (!main) {
|
|
807
1192
|
result.warnings.push(`${repository}: cannot list the worktrees of ${linked.path}`);
|
|
808
|
-
return;
|
|
1193
|
+
return linked.umbrella ? linked : undefined;
|
|
809
1194
|
}
|
|
810
1195
|
// The first entry is the main checkout; a detached HEAD has no branch and never matches.
|
|
811
1196
|
const candidates = entries
|
|
@@ -821,6 +1206,7 @@ async function pruneRepository(
|
|
|
821
1206
|
result,
|
|
822
1207
|
);
|
|
823
1208
|
}
|
|
1209
|
+
return linked.umbrella ? linked : undefined;
|
|
824
1210
|
}
|
|
825
1211
|
|
|
826
1212
|
interface PruneCandidate {
|
|
@@ -828,7 +1214,7 @@ interface PruneCandidate {
|
|
|
828
1214
|
repository: string;
|
|
829
1215
|
/** The main checkout's path. */
|
|
830
1216
|
main: string;
|
|
831
|
-
linked:
|
|
1217
|
+
linked: LinkedCheckout;
|
|
832
1218
|
listed: WorktreeEntry;
|
|
833
1219
|
}
|
|
834
1220
|
|
|
@@ -848,12 +1234,18 @@ async function pruneWorktree(
|
|
|
848
1234
|
result.kept.push({ ...entry, reason });
|
|
849
1235
|
return;
|
|
850
1236
|
}
|
|
851
|
-
//
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
1237
|
+
// A worktree in the mirrored folder carries no wrap; the folder is unwrapped after.
|
|
1238
|
+
const inMirror =
|
|
1239
|
+
linked.umbrella !== undefined &&
|
|
1240
|
+
path.dirname(target) === (await canonical(worktreePathFor(linked.umbrella, worksetId)));
|
|
1241
|
+
if (!inMirror) {
|
|
1242
|
+
// Unwrap first: machine-local state keyed by its path (Claude local-scope MCP) must not outlive it.
|
|
1243
|
+
try {
|
|
1244
|
+
await (deps.unwrap ?? cleanupWorkingRepository)(target, [companionPath]);
|
|
1245
|
+
} catch (error) {
|
|
1246
|
+
result.kept.push({ ...entry, reason: `removing its wrap failed: ${errorMessage(error)}` });
|
|
1247
|
+
return;
|
|
1248
|
+
}
|
|
857
1249
|
}
|
|
858
1250
|
const removed = await git(main, ["worktree", "remove", target]);
|
|
859
1251
|
if (removed.code === 0) {
|
|
@@ -861,6 +1253,18 @@ async function pruneWorktree(
|
|
|
861
1253
|
return;
|
|
862
1254
|
}
|
|
863
1255
|
const refused = removed.stderr.trim() || "git refused";
|
|
1256
|
+
if (inMirror) {
|
|
1257
|
+
result.kept.push({ ...entry, reason: refused });
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
// The umbrella's id is no link for a child's own worktree, so Mate cannot re-wrap it.
|
|
1261
|
+
if (linked.umbrella) {
|
|
1262
|
+
result.kept.push({
|
|
1263
|
+
...entry,
|
|
1264
|
+
reason: `${refused}; its wrap was removed, run \`${FRAMEWORK_NAME} wrap\` there`,
|
|
1265
|
+
});
|
|
1266
|
+
return;
|
|
1267
|
+
}
|
|
864
1268
|
// Kept, so it gets its guardrails back.
|
|
865
1269
|
const rewrap = await wrapWorktree(companionPath, main, { id: linked.id, path: target }, deps);
|
|
866
1270
|
result.kept.push({
|
|
@@ -886,13 +1290,117 @@ export async function pruneWorksetWorktrees(
|
|
|
886
1290
|
): Promise<PruneResult> {
|
|
887
1291
|
const git = deps.git ?? runGit;
|
|
888
1292
|
const result: PruneResult = { removed: [], kept: [], warnings: [] };
|
|
1293
|
+
let index: LinkedIndex | undefined;
|
|
889
1294
|
for (const workset of done) {
|
|
890
1295
|
// oxlint-disable-next-line no-await-in-loop -- Worksets one at a time
|
|
891
|
-
const branches = await recordedBranches(companionPath, workset
|
|
1296
|
+
const branches = await recordedBranches(companionPath, workset, result.warnings);
|
|
1297
|
+
if (branches.size === 0) continue;
|
|
1298
|
+
// oxlint-disable-next-line no-await-in-loop -- read once, on first need
|
|
1299
|
+
index ??= await linkedIndex(companionPath, git, (deps.cwd ?? process.cwd)());
|
|
1300
|
+
// Umbrella path to its Repository Link id.
|
|
1301
|
+
const umbrellas = new Map<string, string>();
|
|
892
1302
|
for (const [repository, names] of branches) {
|
|
893
1303
|
// oxlint-disable-next-line no-await-in-loop -- Git operations on shared checkouts, one at a time
|
|
894
|
-
await pruneRepository(
|
|
1304
|
+
const child = await pruneRepository(
|
|
1305
|
+
companionPath,
|
|
1306
|
+
workset.id,
|
|
1307
|
+
repository,
|
|
1308
|
+
names,
|
|
1309
|
+
index,
|
|
1310
|
+
git,
|
|
1311
|
+
deps,
|
|
1312
|
+
result,
|
|
1313
|
+
);
|
|
1314
|
+
if (child?.umbrella) umbrellas.set(child.umbrella, child.id);
|
|
1315
|
+
}
|
|
1316
|
+
for (const [umbrella, repositoryId] of umbrellas) {
|
|
1317
|
+
// oxlint-disable-next-line no-await-in-loop -- after its children, one at a time
|
|
1318
|
+
await pruneMirror(
|
|
1319
|
+
companionPath,
|
|
1320
|
+
{ worksetId: workset.id, umbrella, repositoryId },
|
|
1321
|
+
deps,
|
|
1322
|
+
result,
|
|
1323
|
+
);
|
|
895
1324
|
}
|
|
896
1325
|
}
|
|
897
1326
|
return result;
|
|
898
1327
|
}
|
|
1328
|
+
|
|
1329
|
+
/** Files the OS writes into any folder it shows, e.g. Finder's; never anyone's work. */
|
|
1330
|
+
const OS_METADATA = new Set([".DS_Store", "Thumbs.db", "desktop.ini"]);
|
|
1331
|
+
|
|
1332
|
+
/**
|
|
1333
|
+
* Top-level names a wrap, a link, or the OS may write; everything else in a mirrored
|
|
1334
|
+
* worktree is someone's work.
|
|
1335
|
+
*/
|
|
1336
|
+
function mirrorMaterial(): Set<string> {
|
|
1337
|
+
return new Set([
|
|
1338
|
+
...projectionEntries()
|
|
1339
|
+
.map((entry) => entry.path.split(/[\\/]/)[0]!)
|
|
1340
|
+
.filter((name) => name !== ".git" && name !== "~"),
|
|
1341
|
+
...OS_METADATA,
|
|
1342
|
+
]);
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
/**
|
|
1346
|
+
* Best effort: unwraps and removes the Workset's mirrored worktree, then an empty
|
|
1347
|
+
* `<umbrella>.worktrees`, only when nothing but Mate's material is left. Never recursive,
|
|
1348
|
+
* never forced; a folder that stays is named with the reason.
|
|
1349
|
+
*/
|
|
1350
|
+
async function pruneMirror(
|
|
1351
|
+
companionPath: string,
|
|
1352
|
+
mirror: { worksetId: string; umbrella: string; repositoryId: string },
|
|
1353
|
+
deps: WorktreeDeps,
|
|
1354
|
+
result: PruneResult,
|
|
1355
|
+
): Promise<void> {
|
|
1356
|
+
const { worksetId, umbrella, repositoryId } = mirror;
|
|
1357
|
+
const folder = await canonical(worktreePathFor(umbrella, worksetId));
|
|
1358
|
+
// Only this companion's mirrored worktree, never a folder it does not own.
|
|
1359
|
+
if (!(await isMirrorOf(folder, companionPath, repositoryId))) return;
|
|
1360
|
+
const umbrellas = (result.umbrellas ??= { removed: [], kept: [] });
|
|
1361
|
+
const entry = { workset: worksetId, umbrella, path: folder };
|
|
1362
|
+
const keep = (reason: string): void => void umbrellas.kept.push({ ...entry, reason });
|
|
1363
|
+
if (await holds(folder, (deps.cwd ?? process.cwd)())) return keep("in use (current directory)");
|
|
1364
|
+
const material = mirrorMaterial();
|
|
1365
|
+
const listed = await fs.readdir(folder).catch(() => null);
|
|
1366
|
+
if (listed === null) return keep("cannot list its entries");
|
|
1367
|
+
const others = listed.filter((name) => !material.has(name)).toSorted();
|
|
1368
|
+
if (others.length > 0) return keep(`still holds ${others.join(", ")}`);
|
|
1369
|
+
try {
|
|
1370
|
+
await (deps.unwrap ?? cleanupWorkingRepository)(folder, [companionPath]);
|
|
1371
|
+
} catch (error) {
|
|
1372
|
+
return keep(`removing its wrap failed: ${errorMessage(error)}`);
|
|
1373
|
+
}
|
|
1374
|
+
// A failure shows below as what unwrapping left.
|
|
1375
|
+
await Promise.all(
|
|
1376
|
+
listed
|
|
1377
|
+
.filter((name) => OS_METADATA.has(name))
|
|
1378
|
+
.map((name) => fs.rm(path.join(folder, name), { force: true }).catch(() => undefined)),
|
|
1379
|
+
);
|
|
1380
|
+
try {
|
|
1381
|
+
await fs.rmdir(folder);
|
|
1382
|
+
} catch (error) {
|
|
1383
|
+
const left = await fs.readdir(folder).catch(() => []);
|
|
1384
|
+
const refused =
|
|
1385
|
+
left.length > 0
|
|
1386
|
+
? `unwrapping left ${left.toSorted().join(", ")}`
|
|
1387
|
+
: `removing it failed: ${errorMessage(error)}`;
|
|
1388
|
+
// Kept, so it gets its link and guardrails back, and a later prune finds it again.
|
|
1389
|
+
const restored = await linkAndWrap(
|
|
1390
|
+
companionPath,
|
|
1391
|
+
{ id: repositoryId, path: folder },
|
|
1392
|
+
umbrella,
|
|
1393
|
+
false,
|
|
1394
|
+
deps,
|
|
1395
|
+
);
|
|
1396
|
+
const failure = restored.error ?? restored.warning;
|
|
1397
|
+
return keep(
|
|
1398
|
+
failure
|
|
1399
|
+
? `${refused}; restoring it failed, run \`${FRAMEWORK_NAME} wrap\` there: ${failure}`
|
|
1400
|
+
: refused,
|
|
1401
|
+
);
|
|
1402
|
+
}
|
|
1403
|
+
umbrellas.removed.push(entry);
|
|
1404
|
+
// The parent stays while another Workset's mirror is in it.
|
|
1405
|
+
await fs.rmdir(path.dirname(folder)).catch(() => undefined);
|
|
1406
|
+
}
|