@uniqbit/mate-core 0.21.1 → 1.0.0-canary.10
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-plugin/hooks/hooks.json +32 -1
- package/claude-plugin/hooks/workflow-turn.mjs +68 -0
- package/opencode-plugin/src/companion.ts +6 -0
- package/opencode-plugin/src/server.ts +24 -0
- package/package.json +9 -4
- 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 +30 -90
- package/src/cli/commands/artifact/delivery/link.ts +26 -26
- package/src/cli/commands/artifact/delivery/output.ts +27 -4
- package/src/cli/commands/artifact/delivery/resolve.ts +102 -0
- package/src/cli/commands/artifact/delivery/submit.ts +171 -0
- package/src/cli/commands/artifact/delivery/take.ts +46 -0
- package/src/cli/commands/artifact/extract-repo-name.ts +1 -1
- package/src/cli/commands/artifact/finish/command.ts +486 -55
- package/src/cli/commands/artifact/finish/engine.ts +87 -69
- 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 +187 -10
- package/src/cli/commands/artifact/pending/discovery.ts +7 -11
- package/src/cli/commands/artifact/project/command.ts +59 -0
- package/src/cli/commands/cap/tokensave.ts +2 -2
- package/src/cli/commands/companion/hub.ts +11 -6
- package/src/cli/commands/companion/link.ts +173 -46
- 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 -3
- package/src/cli/commands/doctor.ts +84 -4
- package/src/cli/commands/friction.ts +558 -0
- package/src/cli/commands/install.ts +9 -4
- package/src/cli/commands/plugin/install.ts +82 -35
- package/src/cli/commands/studio/companion-add.ts +12 -27
- package/src/cli/commands/studio/connection.ts +53 -0
- package/src/{lib/factory/outcomes/sessions.ts → cli/commands/studio/live-sessions.ts} +7 -5
- package/src/cli/commands/studio/mcp-manager.ts +162 -0
- package/src/cli/commands/studio/payload.ts +172 -17
- package/src/cli/commands/studio/reports.ts +19 -18
- package/src/cli/commands/studio/routes.ts +8 -24
- package/src/cli/commands/studio/selection.ts +13 -4
- package/src/cli/commands/studio/server.ts +267 -243
- package/src/cli/commands/studio/service-host.ts +269 -0
- package/src/cli/commands/studio/services.ts +53 -34
- package/src/cli/commands/studio/studio-app.ts +1 -0
- package/src/cli/commands/studio/terminal.ts +1 -1
- 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 +6 -5
- package/src/cli/commands/triage.ts +172 -0
- package/src/cli/commands/vscode/release-vsix.json +2 -2
- package/src/cli/commands/workflow/workflow.ts +516 -0
- package/src/cli/commands/working/cleanup.ts +1 -18
- package/src/cli/companion-link-wizard.tsx +158 -91
- package/src/cli/install-plan.tsx +3 -0
- package/src/cli/main.ts +106 -26
- package/src/cli/plugin-commands.ts +6 -1
- package/src/cli/repo-list-table.tsx +73 -37
- package/src/cli/usage.ts +30 -9
- package/src/create-mate.ts +15 -6
- package/src/distribution.ts +2 -0
- package/src/factory-host.ts +75 -0
- package/src/hooks/companion-instructions.ts +19 -8
- package/src/hooks/hook-io.ts +3 -1
- package/src/hooks/session-banner.ts +25 -0
- package/src/hooks/validate-artifact-path.ts +73 -22
- package/src/hooks/workflow-turn.ts +219 -0
- package/src/index.ts +1 -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 +4 -12
- package/src/lib/delivery/checkout.ts +3 -2
- package/src/lib/delivery/environment.ts +129 -7
- package/src/lib/delivery/merge-git.ts +312 -28
- package/src/lib/delivery/overlap.ts +81 -16
- package/src/lib/delivery/record-delivery.ts +102 -9
- package/src/lib/delivery/record.ts +186 -24
- package/src/lib/delivery/refresh.ts +241 -152
- package/src/lib/delivery/remote.ts +66 -0
- package/src/lib/delivery/repository-access.ts +30 -66
- package/src/lib/delivery/stages.ts +83 -50
- package/src/lib/delivery/staging/apply-chain.ts +182 -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/linked-merges.ts +175 -0
- package/src/lib/delivery/staging/naming.ts +67 -0
- package/src/lib/delivery/staging/openspec-type.ts +166 -0
- package/src/lib/delivery/staging/pending-edit.ts +291 -0
- package/src/lib/delivery/staging/pending.ts +922 -0
- package/src/lib/delivery/staging/preflight.ts +239 -0
- package/src/lib/delivery/staging/project.ts +512 -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 +310 -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 +176 -0
- package/src/lib/delivery/staging/submit.ts +1050 -0
- package/src/lib/delivery/staging/worktree.ts +130 -0
- package/src/lib/delivery/submit-change.ts +569 -0
- package/src/lib/friction/describe.ts +42 -0
- package/src/lib/friction/fields.ts +60 -0
- package/src/lib/friction/mark.ts +194 -0
- package/src/lib/friction/view/model.ts +67 -0
- package/src/lib/friction/view/read.ts +145 -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/mcp-manager/resolve.ts +88 -0
- package/src/lib/mcp-manager/store.ts +133 -0
- package/src/lib/mcp-manager/types.ts +72 -0
- package/src/lib/mcp-manager/validate.ts +242 -0
- package/src/lib/openspec-canonical-frontmatter.ts +159 -0
- package/src/lib/openspec-cli.ts +10 -5
- 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/config-store.ts +30 -7
- package/src/lib/orchestrator/engine-floor.ts +16 -4
- package/src/lib/orchestrator/engine-guard.ts +7 -1
- package/src/lib/orchestrator/framework-context.ts +15 -1
- package/src/lib/orchestrator/projection-claude-links.ts +1 -0
- package/src/lib/orchestrator/refresh-working-claude-links.ts +1 -0
- package/src/lib/orchestrator/repo-local-store.ts +14 -0
- package/src/lib/orchestrator/repository-link.ts +80 -52
- package/src/lib/orchestrator/root-context.ts +40 -7
- package/src/lib/orchestrator/session-prepare.ts +11 -1
- package/src/lib/orchestrator/types.ts +4 -0
- package/src/lib/orchestrator/umbrella-checkouts.ts +4 -4
- 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/session-attribution.ts +3 -7
- package/src/lib/session-state.ts +3 -2
- package/src/lib/skills-cli.ts +38 -0
- package/src/lib/tool-manifest.ts +73 -0
- package/src/lib/triage/context.ts +312 -0
- package/src/lib/triage/launch.ts +52 -0
- package/src/lib/triage/prepare.ts +112 -0
- package/src/lib/triage/session.ts +126 -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 +2 -2
- package/src/lib/workset/repositories.ts +2 -2
- package/src/lib/workset/stage.ts +4 -2
- package/src/lib/workset/stages.ts +64 -4
- package/src/lib/workset/worktree.ts +32 -14
- package/src/opencode/companion-hooks.ts +63 -14
- package/src/opencode/projected-guidance.ts +7 -2
- package/src/opencode/turn-hook.ts +241 -0
- package/src/playbooks/companion-guidance.ts +7 -4
- package/src/plugin-api.ts +48 -0
- package/src/runtime/artifact-trailers.ts +63 -0
- package/src/runtime/claude-hook-group.ts +2 -0
- package/src/runtime/command-arg.ts +15 -0
- package/src/runtime/command-friction.ts +97 -0
- package/src/runtime/companion-git-state.ts +155 -10
- package/src/runtime/companion-git.ts +86 -11
- package/src/runtime/companion-guidance.ts +120 -17
- package/src/runtime/companion-instructions.ts +1 -1
- package/src/runtime/companion-sync.ts +109 -21
- package/src/runtime/env-names.ts +2 -2
- package/src/runtime/env.ts +7 -6
- package/src/runtime/forge-remote.ts +54 -0
- package/src/runtime/friction-fingerprint.ts +35 -0
- package/src/runtime/friction-log.ts +376 -0
- package/src/runtime/friction-recorder.ts +212 -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 +13 -2
- 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/secret-patterns.ts +7 -5
- package/src/runtime/secret-values.ts +16 -0
- 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 +31 -3
- 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 +311 -0
- package/src/runtime/workflow/workflow.ts +262 -0
- package/src/studio.ts +113 -23
- 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 +7 -3
- package/src/templates/capabilities/react-doctor/mate-react-doctor/SKILL.md +28 -0
- package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +84 -28
- 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 +30 -68
- package/src/templates/mate-skills/agents/mate-backfill-spec/SKILL.md +23 -1
- package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +39 -8
- package/src/templates/mate-skills/agents/mate-domain-modeling/SKILL.md +38 -0
- package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +65 -12
- package/src/templates/mate-skills/agents/mate-grill-me/SKILL.md +28 -0
- package/src/templates/mate-skills/agents/mate-grill-with-docs/SKILL.md +28 -0
- package/src/templates/mate-skills/agents/mate-grilling/SKILL.md +25 -0
- package/src/templates/mate-skills/agents/mate-interview-me/SKILL.md +28 -0
- package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +68 -28
- 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 +136 -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 +28 -3
- package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +39 -5
- package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +138 -0
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +84 -28
- 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 +30 -68
- package/src/templates/mate-skills/claude/mate-backfill-spec/SKILL.md +23 -1
- package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +39 -8
- package/src/templates/mate-skills/claude/mate-domain-modeling/SKILL.md +38 -0
- package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +65 -12
- package/src/templates/mate-skills/claude/mate-grill-me/SKILL.md +28 -0
- package/src/templates/mate-skills/claude/mate-grill-with-docs/SKILL.md +28 -0
- package/src/templates/mate-skills/claude/mate-grilling/SKILL.md +25 -0
- package/src/templates/mate-skills/claude/mate-interview-me/SKILL.md +28 -0
- package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +68 -28
- 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 +136 -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 +28 -3
- package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +39 -5
- package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +138 -0
- package/src/templates/mate-skills/openspec-references.ts +3 -2
- package/src/templates/triage/PLAYBOOK.md +120 -0
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +678 -170
- package/src/tools/setup/capabilities/graphify.ts +23 -1
- package/src/tools/setup/capabilities/mcp-manager.ts +73 -0
- package/src/tools/setup/capabilities/openspec.ts +54 -15
- package/src/tools/setup/capabilities/rtk.ts +47 -94
- package/src/tools/setup/capabilities/tokensave.ts +79 -56
- package/src/tools/setup/context-services.ts +35 -6
- package/src/tools/setup/dynamic-plugins/api.ts +38 -0
- package/src/tools/setup/dynamic-plugins/audiences.ts +31 -16
- package/src/tools/setup/dynamic-plugins/host.ts +2 -32
- package/src/tools/setup/dynamic-plugins/hydrate.ts +32 -14
- package/src/tools/setup/dynamic-plugins/install.ts +2 -0
- package/src/tools/setup/dynamic-plugins/installed.ts +73 -0
- package/src/tools/setup/dynamic-plugins/loader.ts +12 -10
- package/src/tools/setup/dynamic-plugins/local.ts +492 -0
- package/src/tools/setup/dynamic-plugins/paths.ts +34 -6
- package/src/tools/setup/dynamic-plugins/verify.ts +34 -14
- package/src/tools/setup/dynamic-plugins/workspaces.ts +21 -12
- package/src/tools/setup/engine.ts +75 -4
- package/src/tools/setup/mate.ts +28 -1
- package/src/tools/setup/package-managers/bun.ts +8 -8
- package/src/tools/setup/plugin.ts +28 -1
- package/src/tools/setup/plugins/gitignore.ts +45 -12
- package/src/tools/setup/plugins/guidance.ts +4 -2
- package/src/tools/setup/providers/claude-format.ts +39 -2
- package/src/tools/setup/providers/claude-plugin-hooks.ts +18 -0
- package/src/tools/setup/providers/claude.ts +56 -6
- package/src/tools/setup/providers/opencode-format.ts +13 -3
- package/src/tools/setup/providers/opencode.ts +7 -18
- package/src/tools/setup/providers/relative-path-warnings.ts +26 -0
- package/src/tools/setup/service-registry.ts +69 -0
- package/src/tools/setup/service.ts +245 -0
- package/src/tools/setup/utils.ts +34 -4
- package/src/tools/setup.ts +16 -2
- package/studio-dist/client/assets/DialogTitle-B_G47-lk.js +1 -0
- package/studio-dist/client/assets/app-0NoFqMou.css +2 -0
- package/studio-dist/client/assets/button-D_0295cs.js +1 -0
- package/studio-dist/client/assets/cn-Cx_D6I3u.js +1 -0
- package/studio-dist/client/assets/combobox-D0iPQP50.js +1 -0
- package/studio-dist/client/assets/{companion-view-CrabvxS8.js → companion-view-D3A76MLj.js} +1 -1
- package/studio-dist/client/assets/fields-Ctheim1h.js +1 -0
- package/studio-dist/client/assets/friction-Cn9n_zBA.js +1 -0
- package/studio-dist/client/assets/getting-started-DgoVWbWo.js +1 -0
- package/studio-dist/client/assets/{getting-started-D6kgWwWZ.js → getting-started-MmLqvy01.js} +1 -1
- package/studio-dist/client/assets/getting-started._topic-DBF0khhz.js +1 -0
- package/studio-dist/client/assets/getting-started.index-BRdAVqIh.js +1 -0
- package/studio-dist/client/assets/graph-BVRdq46V.js +2 -0
- package/studio-dist/client/assets/{graph-canvas-Ba37Y5AE.js → graph-canvas-BNzd-eVb.js} +1 -1
- package/studio-dist/client/assets/guides-DY1W9LRs.js +1 -0
- package/studio-dist/client/assets/index-CuTIc9yd.js +40 -0
- package/studio-dist/client/assets/{markdown-view-BOX6x0rL.js → markdown-view-BqZQkk_k.js} +1 -1
- package/studio-dist/client/assets/mcp-CIFxmDs0.js +4 -0
- package/studio-dist/client/assets/panel-DafanLQ4.js +1 -0
- package/studio-dist/client/assets/plugins._service._view-xSRLxHNM.js +1 -0
- package/studio-dist/client/assets/prepaint-C--F50QZ.js +27 -0
- package/studio-dist/client/assets/{queries-RvHeXY12.js → queries-ByCoiacy.js} +1 -1
- package/studio-dist/client/assets/react-BYUSgtBs.js +1 -0
- package/studio-dist/client/assets/reports-Diryyked.js +1 -0
- package/studio-dist/client/assets/routes-DbRwPd55.js +1 -0
- package/studio-dist/client/assets/search-BDKQRwa5.js +1 -0
- package/studio-dist/client/assets/select-_9JT3hpU.js +1 -0
- package/studio-dist/client/assets/skills-D5a6ybQM.js +1 -0
- package/studio-dist/client/assets/{specs-B0ldF_6J.js → specs-COAWUTog.js} +1 -1
- package/studio-dist/client/assets/specs-view-9eTn9TcN.js +1 -0
- package/studio-dist/client/assets/steps-BS588WAV.js +1 -0
- package/studio-dist/client/assets/store-3cffhIO6.js +1 -0
- package/studio-dist/client/assets/studio-CG9eioSx.js +100 -0
- package/studio-dist/client/assets/studio-queries-BS1yR7Wc.js +2 -0
- package/studio-dist/client/assets/{usage-C2QJ_0IZ.js → usage-Ccl4d7w0.js} +15 -15
- package/studio-dist/client/assets/useAnchoredPopupScrollLock-D_y83VP7.js +1 -0
- package/studio-dist/client/assets/useBlocker-BQOfcu_f.js +1 -0
- package/studio-dist/client/assets/useMutation-BDmS2V6y.js +1 -0
- package/studio-dist/client/assets/usePopupHandleStore-BcqpNR-F.js +1 -0
- package/studio-dist/client/assets/vault-C1tOhQMe.js +1 -0
- package/studio-dist/client/assets/warnings-BZ_X1nkO.js +1 -0
- package/studio-dist/client/assets/workflow-Cm2fsnly.js +1 -0
- package/studio-dist/server/assets/DialogTitle-KSVhF_7V.js +421 -0
- package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-Bn896ZYj.js → __23tanstack-start-server-fn-resolver-QQnIXyKi.js} +40 -28
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +84 -74
- package/studio-dist/server/assets/{button-CgOIVdmD.js → button-C7EMLaX6.js} +229 -5527
- package/studio-dist/server/assets/cn-D7uJiH_O.js +5528 -0
- package/studio-dist/server/assets/{combobox-DV_s9W0s.js → combobox-Dc4_y20Y.js} +6 -5
- package/studio-dist/server/assets/{companion-view-BKVXD3TO.js → companion-view-CrSi37Mb.js} +2 -2
- package/studio-dist/server/assets/{companions-C7fctnU9.js → companions-CDSuLqA4.js} +1 -1
- package/studio-dist/server/assets/{fields-BbieQTD0.js → fields-BxBN6-Dz.js} +10 -2
- package/studio-dist/server/assets/friction-B1K8Kp8r.js +62 -0
- package/studio-dist/server/assets/friction-Vl3B6THL.js +943 -0
- package/studio-dist/server/assets/{getting-started-CRxMWorQ.js → getting-started-B3lu5W7M.js} +2 -2
- package/studio-dist/server/assets/{getting-started._topic-DJKQAzYl.js → getting-started._topic-EYtxZM-Y.js} +2 -2
- package/studio-dist/server/assets/{getting-started.index-D84gec1t.js → getting-started.index-CTaXYycH.js} +2 -2
- package/studio-dist/server/assets/{graph-DDZzXM1L.js → graph-Bhmk7H8V.js} +1 -1
- package/studio-dist/server/assets/{graph-CSje3029.js → graph-D3fXCaKt.js} +8 -8
- package/studio-dist/server/assets/{graph-canvas-22bWB5-2.js → graph-canvas-DIvTodML.js} +2 -2
- package/studio-dist/server/assets/{guides-IE-19POz.js → guides-BZWFpJl-.js} +1 -1
- package/studio-dist/server/assets/{guides-D9dk1Frq.js → guides-CHBkRO6R.js} +1 -1
- package/studio-dist/server/assets/{guides.server-vcYRY5wx.js → guides.server-DX9KRkcK.js} +1 -1
- package/studio-dist/server/assets/{markdown-view-BR8dJ7aR.js → markdown-view-qrCSkVta.js} +1 -1
- package/studio-dist/server/assets/mcp-Ljf4simO.js +1103 -0
- package/studio-dist/server/assets/mcp-manager-DohRwmJU.js +50 -0
- package/studio-dist/server/assets/{panel-BR_t9iMM.js → panel-CAwz4mKp.js} +6 -4
- package/studio-dist/server/assets/plugins._service._view-DUpAo5D_.js +97 -0
- package/studio-dist/server/assets/prepaint-BxZ-pU7t.js +45 -0
- package/studio-dist/server/assets/{queries-DWoTin-q.js → queries-W4LXzTnT.js} +1 -1
- package/studio-dist/server/assets/react-CiBZPDs8.js +45 -0
- package/studio-dist/server/assets/{reports-CQ9qQ1-n.js → reports-BVNSPHU3.js} +13 -7
- package/studio-dist/server/assets/{reports-dYDEoBeq.js → reports-CGG_wRN5.js} +1 -1
- package/studio-dist/server/assets/{router-DkRHNTpE.js → router-KH1x6ryF.js} +1039 -1096
- package/studio-dist/server/assets/{routes-B6GfOew4.js → routes-Bl90FC4R.js} +333 -38
- package/studio-dist/server/assets/search-BjG5f16n.js +110 -0
- package/studio-dist/server/assets/{select-Af7Wibii.js → select-B8q9tLbl.js} +5 -4
- package/studio-dist/server/assets/{shell-Hq-hXgnT.js → shell-C5emwofr.js} +12 -3
- package/studio-dist/server/assets/{skills-B7nEuVbx.js → skills-10l0eCfP.js} +8 -8
- package/studio-dist/server/assets/{skills-B_YYL7q8.js → skills-vG6TTvP1.js} +1 -1
- package/studio-dist/server/assets/{specs-BpLUFntA.js → specs-C1P2BEao.js} +4 -4
- package/studio-dist/server/assets/{specs-view-0peMVd22.js → specs-view-csUBtMWU.js} +10 -10
- package/studio-dist/server/assets/{steps-D56DApvK.js → steps-T4wXftgd.js} +88 -45
- package/studio-dist/server/assets/store-CWlRjv9s.js +93 -0
- package/studio-dist/server/assets/{studio-CAcKp3bM.js → studio-D-ZPWSMv.js} +1567 -59
- package/studio-dist/server/assets/{studio-queries-BtRGzDdh.js → studio-queries-DC273ifg.js} +66 -124
- package/studio-dist/server/assets/{usage-COdjd1gD.js → usage-CT3IWLJc.js} +13 -30
- package/studio-dist/server/assets/{usage-f6pqE1tm.js → usage-D4t_ibR8.js} +1 -1
- package/studio-dist/server/assets/{useAnchoredPopupScrollLock-DlBKHRw7.js → useAnchoredPopupScrollLock-BchJDJYg.js} +2 -2
- package/studio-dist/server/assets/useBlocker-CQtANHK8.js +111 -0
- package/studio-dist/server/assets/{useMutation-DzTZGenE.js → useMutation-0HbcKUsQ.js} +2 -2
- package/studio-dist/server/assets/usePopupHandleStore-B3SNGTic.js +26 -0
- package/studio-dist/server/assets/{vault-BDuIUq0F.js → vault-BIytrudF.js} +10 -117
- package/studio-dist/server/assets/{vault-BVLp6zu3.js → vault-MINXmyXA.js} +1 -1
- package/studio-dist/server/assets/{views-flRUr21z.js → views-DrmY_3J5.js} +7 -4
- package/studio-dist/server/assets/{warnings-CDy9pdgL.js → warnings-BVZCDbIz.js} +2 -2
- package/studio-dist/server/assets/{workflow-D9GKI2EV.js → workflow-DFdqnMtW.js} +57 -50
- package/studio-dist/server/server.js +2 -2
- package/tool-manifest.yaml +85 -0
- package/src/cli/commands/factory/factory.ts +0 -311
- package/src/cli/commands/studio/factory-credential.ts +0 -35
- package/src/cli/commands/studio/factory-git-tokens.ts +0 -40
- package/src/cli/commands/studio/factory-relay.ts +0 -18
- package/src/cli/commands/studio/repository-add.ts +0 -116
- package/src/cli/commands/studio/workset-session.ts +0 -164
- 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 -123
- package/src/lib/factory/attach.ts +0 -178
- package/src/lib/factory/broker.ts +0 -187
- package/src/lib/factory/bun-commands.ts +0 -39
- package/src/lib/factory/client.ts +0 -113
- package/src/lib/factory/clone-url.ts +0 -39
- package/src/lib/factory/command.ts +0 -77
- package/src/lib/factory/credential-store.ts +0 -153
- package/src/lib/factory/frames.ts +0 -77
- package/src/lib/factory/git-auth.ts +0 -61
- package/src/lib/factory/git-credential-store.ts +0 -181
- package/src/lib/factory/ids.ts +0 -68
- package/src/lib/factory/outcomes/actions.ts +0 -130
- package/src/lib/factory/outcomes/index.ts +0 -457
- package/src/lib/factory/outcomes/lifecycle.ts +0 -212
- package/src/lib/factory/outcomes/runs.ts +0 -81
- package/src/lib/factory/prepare.ts +0 -55
- 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 -498
- package/src/lib/factory/runner/state.ts +0 -233
- package/src/lib/factory/runner/workflow.ts +0 -546
- package/src/lib/factory/runtime.ts +0 -1081
- 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-D9cw6szy.css +0 -2
- package/studio-dist/client/assets/artifacts-WD2ZXYrx.js +0 -1
- package/studio-dist/client/assets/button-Br0O1sXw.js +0 -1
- package/studio-dist/client/assets/combobox-DA7RAUUZ.js +0 -1
- package/studio-dist/client/assets/factory-DGS0E16C.js +0 -6
- package/studio-dist/client/assets/fields-6aXBpFhJ.js +0 -1
- package/studio-dist/client/assets/getting-started-Clde4w6P.js +0 -1
- package/studio-dist/client/assets/getting-started._topic-BiunccbT.js +0 -1
- package/studio-dist/client/assets/getting-started.index-DpiNoGw8.js +0 -1
- package/studio-dist/client/assets/graph-B_TCBVbu.js +0 -2
- package/studio-dist/client/assets/guides-Du_RtJxP.js +0 -1
- package/studio-dist/client/assets/index-Df8L1LQa.js +0 -40
- package/studio-dist/client/assets/panel-dbmCx7Mx.js +0 -1
- package/studio-dist/client/assets/react-3QStrcDO.js +0 -27
- package/studio-dist/client/assets/report-url-XRL0x1SY.js +0 -1
- package/studio-dist/client/assets/reports-r3IK7Doz.js +0 -1
- package/studio-dist/client/assets/routes-C0A5LTFc.js +0 -1
- package/studio-dist/client/assets/select-CnaMd617.js +0 -1
- package/studio-dist/client/assets/skills-CzjzHpBT.js +0 -1
- package/studio-dist/client/assets/specs-view-BnCLA0gW.js +0 -1
- package/studio-dist/client/assets/spinner-Dcm3fqK1.js +0 -1
- package/studio-dist/client/assets/steps-C0p2N1Pb.js +0 -1
- package/studio-dist/client/assets/store-Dw34catY.js +0 -1
- package/studio-dist/client/assets/studio-Cpz_HRHp.js +0 -100
- package/studio-dist/client/assets/studio-queries-ibmpFo6R.js +0 -2
- package/studio-dist/client/assets/useAnchoredPopupScrollLock-Bj-FWb8z.js +0 -1
- package/studio-dist/client/assets/useMutation-aAr2uiay.js +0 -1
- package/studio-dist/client/assets/vault-BGcxkSIY.js +0 -1
- package/studio-dist/client/assets/warnings-R1cE1rLf.js +0 -1
- package/studio-dist/client/assets/workflow-C2qTrMDH.js +0 -1
- package/studio-dist/server/assets/actions-DYSv-9VV.js +0 -60
- package/studio-dist/server/assets/artifacts-DnF9L3dZ.js +0 -216
- package/studio-dist/server/assets/factory-C7Ybg0xG.js +0 -3075
- package/studio-dist/server/assets/factory-Df5uAHjb.js +0 -116
- package/studio-dist/server/assets/react-CdqSUhaL.js +0 -89
- package/studio-dist/server/assets/report-url-BUXPcE_8.js +0 -9
- package/studio-dist/server/assets/search-BJnWLfkG.js +0 -55
- package/studio-dist/server/assets/spinner-CdwJW4VB.js +0 -20
- package/studio-dist/server/assets/store-Cs17okNG.js +0 -280
- /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
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { isBranchName } from "../../runtime/pending-records";
|
|
2
|
+
|
|
3
|
+
export { isBranchName };
|
|
4
|
+
|
|
1
5
|
/** A Delivery Branch template: a fixed prefix ending in `/`, `{workset}`, and optional `{ticket}`. */
|
|
2
6
|
export type BranchTemplate = string;
|
|
3
7
|
|
|
@@ -14,18 +18,6 @@ export interface BranchTemplateSetting {
|
|
|
14
18
|
diagnostic: string | null;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
|
-
/** True when `name` passes `git check-ref-format --branch`, checked without Git. */
|
|
18
|
-
function isBranchName(name: string): boolean {
|
|
19
|
-
if (!name || name === "@" || name.startsWith("-") || name.endsWith("/") || name.endsWith(".")) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
// oxlint-disable-next-line no-control-regex -- control characters are invalid in refs
|
|
23
|
-
if (/[\u0000- \u007f~^:?*[\\]|\.\.|@\{|\/\//.test(name)) return false;
|
|
24
|
-
return name
|
|
25
|
-
.split("/")
|
|
26
|
-
.every((part) => part !== "" && !part.startsWith(".") && !part.endsWith(".lock"));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
21
|
/** The rule a template breaks, or null when it is valid. */
|
|
30
22
|
function brokenRule(template: string): string | null {
|
|
31
23
|
const names = [...template.matchAll(PLACEHOLDER)].map((match) => match[1]!);
|
|
@@ -14,8 +14,9 @@ export type HasRef = (ref: string) => Promise<boolean>;
|
|
|
14
14
|
export type ListRefs = (prefixes: string[]) => Promise<string[]>;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* A local merge check, without fetch
|
|
18
|
-
*
|
|
17
|
+
* A local merge check, without fetch: a merge commit or a default-branch commit containing the
|
|
18
|
+
* head settles `merged`; on Git without `merge-tree --write-tree`, commits matched by patch
|
|
19
|
+
* identity read as `squashed`. A head on the default branch's own line
|
|
19
20
|
* is `open`: it may be a fast-forward, but then its commits are already there and continuing
|
|
20
21
|
* on it is safe.
|
|
21
22
|
*/
|
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
configuredProtectedPatterns,
|
|
5
|
+
configuredTicketFormat,
|
|
6
|
+
workingRepoGit,
|
|
7
|
+
type TicketSetting,
|
|
8
|
+
type WorkingRepoGit,
|
|
9
|
+
} from "./branches";
|
|
10
|
+
import { sameRepository } from "./record";
|
|
11
|
+
import { parseRemote, repositoryPath, type RemoteRepo } from "./remote";
|
|
12
|
+
import type { ArtifactType } from "./staging/artifact-type";
|
|
13
|
+
import type { Workflow } from "../workflow/declaration";
|
|
14
|
+
import type { FrameworkContext } from "../orchestrator/framework-context";
|
|
15
|
+
import type { CapabilityConfig, LinkedRepository } from "../orchestrator/types";
|
|
16
|
+
import {
|
|
17
|
+
linkedCheckoutsOf,
|
|
18
|
+
umbrellaChildrenOf,
|
|
19
|
+
type EntryCheckout,
|
|
20
|
+
type OriginReader,
|
|
21
|
+
} from "../orchestrator/umbrella-checkouts";
|
|
5
22
|
|
|
6
23
|
export interface WorkingRepoInfo {
|
|
7
24
|
path: string;
|
|
8
25
|
/** Full repository path from the `origin` remote (`acme/platform/api`), or null without one. */
|
|
9
26
|
slug: string | null;
|
|
10
|
-
forgeRepo: ForgeRepo | null;
|
|
11
27
|
git: WorkingRepoGit;
|
|
12
28
|
/** Set when the Working Repository is an Umbrella Repository: its children's repository paths. */
|
|
13
29
|
umbrellaChildren?: string[];
|
|
@@ -21,17 +37,123 @@ export interface DeliveryEnvironment {
|
|
|
21
37
|
/** The companion's ticket setting; absent means `none`. */
|
|
22
38
|
ticket?: TicketSetting;
|
|
23
39
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
40
|
+
* Path of the repository's checkout linked on this machine: the Working Repository, a
|
|
41
|
+
* Repository Link, or an Umbrella Repository child. The only way a repository is inspected.
|
|
26
42
|
*/
|
|
27
|
-
hostOf?: (repository: string) => Promise<string | null>;
|
|
28
|
-
/** Path of a local checkout of the repository: the Working Repository or a linked one. */
|
|
29
43
|
checkoutOf?: (repository: string) => Promise<string | null>;
|
|
30
44
|
/** The companion's Git mode is `auto`: merge checks fetch before reading local refs. */
|
|
31
45
|
gitAutoMode?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The declared artifact type the companion's submit handles, whose change folders the delivery
|
|
48
|
+
* commands then work on; absent for the built-in type.
|
|
49
|
+
*/
|
|
50
|
+
artifactType?: ArtifactType;
|
|
51
|
+
/** The companion's Delivery Path, read once with `artifactType`; loaded on demand when absent. */
|
|
52
|
+
workflow?: Workflow;
|
|
32
53
|
}
|
|
33
54
|
|
|
34
55
|
/** `dir` relative to the companion, with forward slashes. */
|
|
35
56
|
export function companionRelative(environment: DeliveryEnvironment, dir: string): string {
|
|
36
57
|
return path.relative(environment.companionPath, dir).split(path.sep).join("/");
|
|
37
58
|
}
|
|
59
|
+
|
|
60
|
+
export interface LinkedEnvironmentDeps {
|
|
61
|
+
workingRepoGit?: (repoPath: string) => WorkingRepoGit;
|
|
62
|
+
loadLinkedRepositories?: (context: FrameworkContext) => Promise<LinkedRepository[]>;
|
|
63
|
+
/** Reads an Umbrella Repository child's `origin`; raw config by default, as worktree planning reads it. */
|
|
64
|
+
readChildOrigin?: OriginReader;
|
|
65
|
+
/** True when the companion's Git mode is `auto`. */
|
|
66
|
+
loadGitAutoMode?: (context: FrameworkContext) => Promise<boolean>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function defaultLoadLinkedRepositories(
|
|
70
|
+
context: FrameworkContext,
|
|
71
|
+
): Promise<LinkedRepository[]> {
|
|
72
|
+
return (await context.workingRepoStore.load()).repos;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function defaultLoadGitAutoMode(context: FrameworkContext): Promise<boolean> {
|
|
76
|
+
return (await context.configStore.load()).git === "auto";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** A linked repository's checkout with its parsed `origin` remote. */
|
|
80
|
+
interface LinkedCheckout {
|
|
81
|
+
remote: RemoteRepo;
|
|
82
|
+
path: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The checkouts whose `origin` names a repository. */
|
|
86
|
+
function withRemotes(checkouts: readonly EntryCheckout[]): LinkedCheckout[] {
|
|
87
|
+
return checkouts.flatMap(({ path: checkout, remote }) =>
|
|
88
|
+
remote ? [{ remote, path: checkout }] : [],
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The delivery environment of a resolved companion context: the Working Repository at
|
|
94
|
+
* `repoPath` with its `origin` identity, and the checkouts the companion's registry links on
|
|
95
|
+
* this machine, read once on the first lookup of another repository.
|
|
96
|
+
*/
|
|
97
|
+
export async function linkedDeliveryEnvironment(
|
|
98
|
+
context: FrameworkContext,
|
|
99
|
+
capabilities: CapabilityConfig[],
|
|
100
|
+
repoPath: string | undefined,
|
|
101
|
+
deps: LinkedEnvironmentDeps = {},
|
|
102
|
+
): Promise<DeliveryEnvironment> {
|
|
103
|
+
const openGit = deps.workingRepoGit ?? workingRepoGit;
|
|
104
|
+
const readOrigin = (checkout: string) => openGit(checkout).remoteUrl();
|
|
105
|
+
let workingRepo: WorkingRepoInfo | null = null;
|
|
106
|
+
// An Umbrella Repository has no `origin` of its own; its children name the repositories.
|
|
107
|
+
const ownChildren = repoPath
|
|
108
|
+
? withRemotes(await umbrellaChildrenOf(repoPath, deps.readChildOrigin))
|
|
109
|
+
: [];
|
|
110
|
+
if (repoPath) {
|
|
111
|
+
const git = openGit(repoPath);
|
|
112
|
+
const remote = ownChildren.length > 0 ? null : await git.remoteUrl();
|
|
113
|
+
const parsed = remote ? parseRemote(remote) : null;
|
|
114
|
+
workingRepo = {
|
|
115
|
+
path: repoPath,
|
|
116
|
+
slug: parsed ? repositoryPath(parsed) : null,
|
|
117
|
+
git,
|
|
118
|
+
...(ownChildren.length > 0
|
|
119
|
+
? { umbrellaChildren: ownChildren.map((child) => repositoryPath(child.remote)) }
|
|
120
|
+
: {}),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let linkedRemotes: Promise<LinkedCheckout[]> | undefined;
|
|
125
|
+
// Read once, and only when a repository other than the Working Repository is looked up.
|
|
126
|
+
const linked = (): Promise<LinkedCheckout[]> =>
|
|
127
|
+
(linkedRemotes ??= (async () => {
|
|
128
|
+
// An unreadable registry only loses links; the Working Repository remains.
|
|
129
|
+
const repositories = await (deps.loadLinkedRepositories ?? defaultLoadLinkedRepositories)(
|
|
130
|
+
context,
|
|
131
|
+
).catch(() => []);
|
|
132
|
+
// The Working Repository's own entry is skipped; an umbrella's children are in `ownChildren`.
|
|
133
|
+
const checkouts = await Promise.all(
|
|
134
|
+
repositories
|
|
135
|
+
.filter((repository) => repository.path !== repoPath)
|
|
136
|
+
.map((repository) => linkedCheckoutsOf(repository, readOrigin, deps.readChildOrigin)),
|
|
137
|
+
);
|
|
138
|
+
return [...ownChildren, ...withRemotes(checkouts.flat())];
|
|
139
|
+
})());
|
|
140
|
+
const checkoutOf = async (repository: string): Promise<string | null> => {
|
|
141
|
+
if (workingRepo?.slug && sameRepository(workingRepo.slug, repository)) return workingRepo.path;
|
|
142
|
+
const match = (await linked()).find(({ remote }) =>
|
|
143
|
+
sameRepository(repositoryPath(remote), repository),
|
|
144
|
+
);
|
|
145
|
+
return match?.path ?? null;
|
|
146
|
+
};
|
|
147
|
+
const gitAutoMode = await (deps.loadGitAutoMode ?? defaultLoadGitAutoMode)(context).catch(
|
|
148
|
+
() => false,
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
companionPath: context.companionPath,
|
|
153
|
+
workingRepo,
|
|
154
|
+
protectedPatterns: configuredProtectedPatterns(capabilities),
|
|
155
|
+
ticket: configuredTicketFormat(capabilities),
|
|
156
|
+
checkoutOf,
|
|
157
|
+
gitAutoMode,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Merge state from a local checkout: whether a delivery branch's head reached the default
|
|
3
|
-
* branch. Only `git` is started. Local queries never reach the
|
|
4
|
-
* (`GIT_NO_LAZY_FETCH`); the fetch
|
|
5
|
-
* and
|
|
3
|
+
* branch, by ancestry or by content. Only `git` is started. Local queries never reach the
|
|
4
|
+
* network (`GIT_NO_LAZY_FETCH`); the fetch and the pull-ref listing run only when the caller
|
|
5
|
+
* decides to, never prompt, and use the user's own remote and credential setup unchanged.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { spawn } from "node:child_process";
|
|
9
|
+
import { randomUUID } from "node:crypto";
|
|
9
10
|
import fs from "node:fs/promises";
|
|
10
11
|
import path from "node:path";
|
|
11
12
|
|
|
@@ -21,26 +22,78 @@ export interface ProcessResult {
|
|
|
21
22
|
export type SpawnProcess = (
|
|
22
23
|
command: string,
|
|
23
24
|
args: readonly string[],
|
|
24
|
-
options: {
|
|
25
|
+
options: {
|
|
26
|
+
cwd: string;
|
|
27
|
+
env: NodeJS.ProcessEnv;
|
|
28
|
+
input?: string;
|
|
29
|
+
timeoutMs?: number;
|
|
30
|
+
/** Kills the process once aborted; the result then counts as timed out. */
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
},
|
|
25
33
|
) => Promise<ProcessResult>;
|
|
26
34
|
|
|
27
35
|
export interface PatchMatch {
|
|
28
36
|
/** The commit on the default branch the delivery matched. */
|
|
29
37
|
commit: string;
|
|
30
|
-
/**
|
|
31
|
-
|
|
38
|
+
/**
|
|
39
|
+
* `fast-forward`: the head is on the default branch's own line, which a branch without commits
|
|
40
|
+
* of its own is too. `merge`: a merge commit brought a head never pushed as its branch, as the
|
|
41
|
+
* merge of a branch it was started from does.
|
|
42
|
+
*/
|
|
43
|
+
style: "squash" | "rebase" | "fast-forward" | "merge";
|
|
32
44
|
}
|
|
33
45
|
|
|
34
46
|
export interface FetchResult {
|
|
35
47
|
ok: boolean;
|
|
36
48
|
message?: string;
|
|
49
|
+
/** The delivery branch no longer exists on `origin`. */
|
|
50
|
+
branchDeleted?: boolean;
|
|
51
|
+
/** The delivery branch is missing on `origin` because its head was never pushed. */
|
|
52
|
+
branchUnpushed?: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The first default-branch commit holding a delivery's content. */
|
|
56
|
+
export interface ContainingCommit {
|
|
57
|
+
commit: string;
|
|
58
|
+
/** Its committer time (ISO 8601). */
|
|
59
|
+
committedAt: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* - a commit: the first on the default branch's first-parent line that contains the head
|
|
64
|
+
* - `none`: no candidate commit contains it
|
|
65
|
+
* - `unknown`: Git cannot tell: no `merge-tree --write-tree`, a missing object, a timeout, a
|
|
66
|
+
* head whose tree equals its merge base's (no content of its own), more candidates than
|
|
67
|
+
* {@link CONTAINMENT_LIMIT} without a hit, or a search past its time budget
|
|
68
|
+
*/
|
|
69
|
+
export type Containment = ContainingCommit | "none" | "unknown";
|
|
70
|
+
|
|
71
|
+
/** A pull or merge request head the remote advertises. */
|
|
72
|
+
export interface PullRef {
|
|
73
|
+
number: number;
|
|
74
|
+
/** `refs/pull/<n>/head` (GitHub) or `refs/merge-requests/<n>/head` (GitLab). Azure DevOps advertises neither. */
|
|
75
|
+
ref: "pull" | "merge-requests";
|
|
76
|
+
commit: string;
|
|
37
77
|
}
|
|
38
78
|
|
|
39
79
|
export interface MergeGit {
|
|
40
80
|
/** True when the path is a Git work tree. */
|
|
41
81
|
isRepository(): Promise<boolean>;
|
|
82
|
+
/** The URL of `origin`, or null without one. */
|
|
83
|
+
originUrl(): Promise<string | null>;
|
|
42
84
|
/** `origin/<branch>`, else the local branch; null when neither exists. */
|
|
43
85
|
tip(branch: string): Promise<string | null>;
|
|
86
|
+
/** The local branch alone; null when it does not exist. */
|
|
87
|
+
localTip(branch: string): Promise<string | null>;
|
|
88
|
+
/** `origin/<branch>` alone, as last fetched; null when it does not exist. */
|
|
89
|
+
remoteTip(branch: string): Promise<string | null>;
|
|
90
|
+
/**
|
|
91
|
+
* The work tree that has `branch` checked out and holds modified tracked files; null without
|
|
92
|
+
* one. Untracked files do not count.
|
|
93
|
+
*/
|
|
94
|
+
dirtyWorktree(branch: string): Promise<string | null>;
|
|
95
|
+
/** True when `candidate` is another commit that descends from `base`. */
|
|
96
|
+
aheadOf(base: string, candidate: string): Promise<boolean>;
|
|
44
97
|
/** True when the commit exists locally, e.g. a recorded head after its branch was deleted. */
|
|
45
98
|
hasCommit(commit: string): Promise<boolean>;
|
|
46
99
|
/** True when `commit` is contained in `origin/<defaultBranch>`. */
|
|
@@ -48,30 +101,92 @@ export interface MergeGit {
|
|
|
48
101
|
/**
|
|
49
102
|
* True when `commit`, already contained in `origin/<defaultBranch>`, lies on its
|
|
50
103
|
* first-parent line: a fast-forward, or a branch that never had commits of its own.
|
|
51
|
-
* False when a merge commit brought it in.
|
|
104
|
+
* False when a merge commit brought it in; null when Git could not tell.
|
|
105
|
+
*/
|
|
106
|
+
onFirstParent(commit: string, defaultBranch: string): Promise<boolean | null>;
|
|
107
|
+
/**
|
|
108
|
+
* True when every entry of the local branch's reflog is `head`: the branch never moved since
|
|
109
|
+
* it was created there. False when one differs; null without a reflog or when Git fails.
|
|
52
110
|
*/
|
|
53
|
-
|
|
111
|
+
neverAdvanced(branch: string, head: string): Promise<boolean | null>;
|
|
54
112
|
/**
|
|
55
113
|
* The commit on `origin/<defaultBranch>` that carries the delivery's changes by patch
|
|
56
114
|
* identity: every branch commit (rebase), else the whole branch diff (squash). Null in a
|
|
57
115
|
* partial clone, without a match, or above {@link PATCH_MATCH_LIMIT} upstream commits.
|
|
58
116
|
*/
|
|
59
117
|
patchMatch(head: string, defaultBranch: string): Promise<PatchMatch | null>;
|
|
118
|
+
/** True when this Git has `merge-tree --write-tree` (2.38 or later); asked once per process. */
|
|
119
|
+
supportsContainment(): Promise<boolean>;
|
|
120
|
+
/**
|
|
121
|
+
* True when merging `head` into `commit` changes nothing: the merge is clean and yields
|
|
122
|
+
* `commit`'s own tree. Null when Git cannot tell (missing object, timeout, no support).
|
|
123
|
+
*/
|
|
124
|
+
contains(commit: string, head: string): Promise<boolean | null>;
|
|
125
|
+
/**
|
|
126
|
+
* The oldest commit on `origin/<defaultBranch>`'s first-parent line after the merge base that
|
|
127
|
+
* contains `head`, among those committed at most a day before `head`, at most
|
|
128
|
+
* {@link CONTAINMENT_LIMIT}. For a head that is not an ancestor of the default branch.
|
|
129
|
+
*/
|
|
130
|
+
firstContaining(head: string, defaultBranch: string): Promise<Containment>;
|
|
60
131
|
/** When `origin` was last fetched (ISO 8601), or null when unknown. */
|
|
61
132
|
lastFetchedAt(): Promise<string | null>;
|
|
62
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
* Fetches the default branch, then the delivery branch; a missing branch is not a failure but
|
|
135
|
+
* `branchDeleted`.
|
|
136
|
+
*/
|
|
63
137
|
fetch(defaultBranch: string, branch: string): Promise<FetchResult>;
|
|
138
|
+
/** The pull and merge request heads `origin` advertises; null when the listing failed. */
|
|
139
|
+
pullRefs(): Promise<PullRef[] | null>;
|
|
140
|
+
/** Fetches one PR head, leaving no ref and `FETCH_HEAD` untouched; its commit, or null. */
|
|
141
|
+
fetchPullHead(number: number, ref: PullRef["ref"]): Promise<string | null>;
|
|
64
142
|
}
|
|
65
143
|
|
|
66
144
|
export interface MergeGitDeps {
|
|
67
145
|
spawn?: SpawnProcess;
|
|
68
146
|
env?: NodeJS.ProcessEnv;
|
|
147
|
+
/** Candidate commits tested for containment at most; {@link CONTAINMENT_LIMIT} by default. */
|
|
148
|
+
containmentLimit?: number;
|
|
149
|
+
/** Wall time one containment search may take; 5 s by default. */
|
|
150
|
+
containmentBudgetMs?: number;
|
|
151
|
+
/** Once aborted, running Git commands are killed and new ones fail at once. */
|
|
152
|
+
signal?: AbortSignal;
|
|
69
153
|
}
|
|
70
154
|
|
|
71
155
|
/** Upstream commits compared by patch identity at most; more is asked instead. */
|
|
72
156
|
const PATCH_MATCH_LIMIT = 500;
|
|
157
|
+
/** Default-branch commits tested for containment at most. */
|
|
158
|
+
export const CONTAINMENT_LIMIT = 200;
|
|
159
|
+
/** Wall time one containment search may take; past it the answer is `unknown`. */
|
|
160
|
+
const CONTAINMENT_BUDGET_MS = 5_000;
|
|
161
|
+
/** Heads no candidate contained, by checkout, head and default tip; the answer cannot change. */
|
|
162
|
+
const notContainedBySpawn = new WeakMap<SpawnProcess, Set<string>>();
|
|
163
|
+
const NOT_CONTAINED_MAX = 1_000;
|
|
164
|
+
|
|
165
|
+
/** `spawnFn`'s set in {@link notContainedBySpawn}, created on first use. */
|
|
166
|
+
function notContainedMemo(spawnFn: SpawnProcess): Set<string> {
|
|
167
|
+
let memo = notContainedBySpawn.get(spawnFn);
|
|
168
|
+
if (!memo) {
|
|
169
|
+
memo = new Set();
|
|
170
|
+
notContainedBySpawn.set(spawnFn, memo);
|
|
171
|
+
}
|
|
172
|
+
return memo;
|
|
173
|
+
}
|
|
174
|
+
/** Candidates committed this long before the head still count: clocks and rebases differ. */
|
|
175
|
+
const CONTAINMENT_SLACK_SECONDS = 24 * 60 * 60;
|
|
73
176
|
const FETCH_BUDGET_MS = 20_000;
|
|
74
177
|
const QUERY_TIMEOUT_MS = 15_000;
|
|
178
|
+
const COMMIT_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
179
|
+
|
|
180
|
+
/** `merge-tree --write-tree` support, probed once per process for each spawner. */
|
|
181
|
+
const containmentSupport = new WeakMap<SpawnProcess, Promise<boolean>>();
|
|
182
|
+
|
|
183
|
+
/** True for `git version` output of Git 2.38 or later. */
|
|
184
|
+
function hasWriteTree(version: string): boolean {
|
|
185
|
+
const match = /git version (\d+)\.(\d+)/.exec(version);
|
|
186
|
+
if (!match) return false;
|
|
187
|
+
const [major, minor] = [Number(match[1]), Number(match[2])];
|
|
188
|
+
return major > 2 || (major === 2 && minor >= 38);
|
|
189
|
+
}
|
|
75
190
|
|
|
76
191
|
export const spawnProcess: SpawnProcess = (command, args, options) =>
|
|
77
192
|
new Promise((resolve) => {
|
|
@@ -80,12 +195,20 @@ export const spawnProcess: SpawnProcess = (command, args, options) =>
|
|
|
80
195
|
env: options.env,
|
|
81
196
|
stdio: ["pipe", "pipe", "pipe"],
|
|
82
197
|
timeout: options.timeoutMs,
|
|
198
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
83
199
|
});
|
|
84
200
|
const stdout: Buffer[] = [];
|
|
85
201
|
const stderr: Buffer[] = [];
|
|
86
202
|
child.stdout.on("data", (chunk: Buffer) => stdout.push(chunk));
|
|
87
203
|
child.stderr.on("data", (chunk: Buffer) => stderr.push(chunk));
|
|
88
|
-
child.on("error", (error) =>
|
|
204
|
+
child.on("error", (error) =>
|
|
205
|
+
resolve({
|
|
206
|
+
code: -1,
|
|
207
|
+
stdout: "",
|
|
208
|
+
stderr: error.message,
|
|
209
|
+
...(options.signal?.aborted ? { timedOut: true } : {}),
|
|
210
|
+
}),
|
|
211
|
+
);
|
|
89
212
|
child.on("close", (code, signal) =>
|
|
90
213
|
resolve({
|
|
91
214
|
code: code ?? -1,
|
|
@@ -130,7 +253,10 @@ export function localGitEnv(env: NodeJS.ProcessEnv = process.env): NodeJS.Proces
|
|
|
130
253
|
}
|
|
131
254
|
|
|
132
255
|
export function mergeGit(repoPath: string, deps: MergeGitDeps = {}): MergeGit {
|
|
133
|
-
const
|
|
256
|
+
const baseSpawn = deps.spawn ?? spawnProcess;
|
|
257
|
+
const spawnFn: SpawnProcess = deps.signal
|
|
258
|
+
? (command, args, options) => baseSpawn(command, args, { ...options, signal: deps.signal })
|
|
259
|
+
: baseSpawn;
|
|
134
260
|
const base = gitEnvironment(deps.env ?? process.env) as NodeJS.ProcessEnv;
|
|
135
261
|
const promptless = promptlessEnv(base);
|
|
136
262
|
const localEnv: NodeJS.ProcessEnv = { ...promptless, GIT_NO_LAZY_FETCH: "1" };
|
|
@@ -147,6 +273,51 @@ export function mergeGit(repoPath: string, deps: MergeGitDeps = {}): MergeGit {
|
|
|
147
273
|
(await value("config", "--get", "remote.origin.promisor")) === "true" ||
|
|
148
274
|
(await value("config", "--get", "extensions.partialClone")) !== null;
|
|
149
275
|
|
|
276
|
+
const supportsContainment = (): Promise<boolean> => {
|
|
277
|
+
let known = containmentSupport.get(baseSpawn);
|
|
278
|
+
if (!known) {
|
|
279
|
+
known = git(["version"]).then((result) => {
|
|
280
|
+
// A killed probe proves nothing about this Git.
|
|
281
|
+
if (result.timedOut) containmentSupport.delete(baseSpawn);
|
|
282
|
+
return result.code === 0 && hasWriteTree(result.stdout);
|
|
283
|
+
});
|
|
284
|
+
containmentSupport.set(baseSpawn, known);
|
|
285
|
+
}
|
|
286
|
+
return known;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
const contains = async (commit: string, head: string): Promise<boolean | null> => {
|
|
290
|
+
if (!(await supportsContainment())) return null;
|
|
291
|
+
const tree = await value("rev-parse", "--verify", "--quiet", `${commit}^{tree}`);
|
|
292
|
+
if (!tree) return null;
|
|
293
|
+
const merged = await git(["merge-tree", "--write-tree", "--no-messages", commit, head]);
|
|
294
|
+
if (merged.timedOut) return null;
|
|
295
|
+
// 1: the merge conflicts; anything else is Git failing, e.g. on a missing object.
|
|
296
|
+
if (merged.code === 1) return false;
|
|
297
|
+
if (merged.code !== 0) return null;
|
|
298
|
+
return merged.stdout.split("\n")[0]?.trim() === tree;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
/** Network Git: never prompts, no background maintenance, the user's credentials unchanged. */
|
|
302
|
+
const networkEnv = async (): Promise<NodeJS.ProcessEnv> => {
|
|
303
|
+
const env: NodeJS.ProcessEnv = withGitConfig(
|
|
304
|
+
{ ...promptless, GCM_INTERACTIVE: "never" },
|
|
305
|
+
{ "maintenance.auto": "false", "gc.auto": "0" },
|
|
306
|
+
);
|
|
307
|
+
// A user's own SSH command wins; otherwise SSH must not ask for a passphrase.
|
|
308
|
+
if (
|
|
309
|
+
!base.GIT_SSH_COMMAND &&
|
|
310
|
+
!base.GIT_SSH &&
|
|
311
|
+
!(await value("config", "--get", "core.sshCommand"))
|
|
312
|
+
) {
|
|
313
|
+
env.GIT_SSH_COMMAND = "ssh -o BatchMode=yes";
|
|
314
|
+
}
|
|
315
|
+
return env;
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const network = async (args: readonly string[]): Promise<ProcessResult> =>
|
|
319
|
+
spawnFn("git", args, { cwd: repoPath, env: await networkEnv(), timeoutMs: FETCH_BUDGET_MS });
|
|
320
|
+
|
|
150
321
|
/** Patch ids of `log -p` over a range, keyed by patch id. */
|
|
151
322
|
const rangePatchIds = async (range: string): Promise<Map<string, string> | null> => {
|
|
152
323
|
const log = await git(["log", "-p", "--no-merges", "--no-color", "--no-ext-diff", range]);
|
|
@@ -160,9 +331,41 @@ export function mergeGit(repoPath: string, deps: MergeGitDeps = {}): MergeGit {
|
|
|
160
331
|
async isRepository() {
|
|
161
332
|
return (await value("rev-parse", "--is-inside-work-tree")) === "true";
|
|
162
333
|
},
|
|
334
|
+
originUrl() {
|
|
335
|
+
return value("config", "--get", "remote.origin.url");
|
|
336
|
+
},
|
|
163
337
|
async tip(branch) {
|
|
164
338
|
return (await verify(remoteRef(branch))) ?? (await verify(`refs/heads/${branch}`));
|
|
165
339
|
},
|
|
340
|
+
localTip(branch) {
|
|
341
|
+
return verify(`refs/heads/${branch}`);
|
|
342
|
+
},
|
|
343
|
+
remoteTip(branch) {
|
|
344
|
+
return verify(remoteRef(branch));
|
|
345
|
+
},
|
|
346
|
+
async dirtyWorktree(branch) {
|
|
347
|
+
const listed = await value("worktree", "list", "--porcelain");
|
|
348
|
+
for (const entry of (listed ?? "").split("\n\n")) {
|
|
349
|
+
const lines = entry.split("\n");
|
|
350
|
+
const dir = lines.find((line) => line.startsWith("worktree "))?.slice("worktree ".length);
|
|
351
|
+
if (!dir || !lines.includes(`branch refs/heads/${branch}`)) continue;
|
|
352
|
+
// oxlint-disable-next-line no-await-in-loop -- a branch is checked out in one work tree
|
|
353
|
+
const status = await git([
|
|
354
|
+
"--no-optional-locks",
|
|
355
|
+
"-C",
|
|
356
|
+
dir,
|
|
357
|
+
"status",
|
|
358
|
+
"--porcelain",
|
|
359
|
+
"--untracked-files=no",
|
|
360
|
+
]);
|
|
361
|
+
if (status.code === 0 && status.stdout.trim()) return dir;
|
|
362
|
+
}
|
|
363
|
+
return null;
|
|
364
|
+
},
|
|
365
|
+
async aheadOf(ancestor, candidate) {
|
|
366
|
+
if (ancestor === candidate) return false;
|
|
367
|
+
return (await git(["merge-base", "--is-ancestor", ancestor, candidate])).code === 0;
|
|
368
|
+
},
|
|
166
369
|
async hasCommit(commit) {
|
|
167
370
|
return (await git(["cat-file", "-e", `${commit}^{commit}`])).code === 0;
|
|
168
371
|
},
|
|
@@ -178,11 +381,21 @@ export function mergeGit(repoPath: string, deps: MergeGitDeps = {}): MergeGit {
|
|
|
178
381
|
remoteRef(defaultBranch),
|
|
179
382
|
`^${commit}`,
|
|
180
383
|
]);
|
|
181
|
-
if (line.code !== 0) return
|
|
384
|
+
if (line.code !== 0) return null;
|
|
182
385
|
const oldest = line.stdout.trim().split("\n").at(-1);
|
|
183
386
|
// Nothing listed: the head is the default branch's tip.
|
|
184
387
|
if (!oldest) return true;
|
|
185
|
-
|
|
388
|
+
const parent = await value("rev-parse", `${oldest}^1`);
|
|
389
|
+
return parent ? parent === commit : null;
|
|
390
|
+
},
|
|
391
|
+
async neverAdvanced(branch, head) {
|
|
392
|
+
const reflog = await git(["reflog", "show", "--format=%H", `refs/heads/${branch}`, "--"]);
|
|
393
|
+
if (reflog.code !== 0) return null;
|
|
394
|
+
const entries = reflog.stdout
|
|
395
|
+
.split("\n")
|
|
396
|
+
.map((entry) => entry.trim())
|
|
397
|
+
.filter(Boolean);
|
|
398
|
+
return entries.length > 0 ? entries.every((entry) => entry === head) : null;
|
|
186
399
|
},
|
|
187
400
|
async patchMatch(head, defaultBranch) {
|
|
188
401
|
if (await isPartialClone()) return null;
|
|
@@ -213,6 +426,55 @@ export function mergeGit(repoPath: string, deps: MergeGitDeps = {}): MergeGit {
|
|
|
213
426
|
const squash = entry ? upstreamIds.get(entry[0]) : undefined;
|
|
214
427
|
return squash ? { commit: squash, style: "squash" } : null;
|
|
215
428
|
},
|
|
429
|
+
supportsContainment,
|
|
430
|
+
contains,
|
|
431
|
+
async firstContaining(head, defaultBranch) {
|
|
432
|
+
if (!(await supportsContainment())) return "unknown";
|
|
433
|
+
const upstream = remoteRef(defaultBranch);
|
|
434
|
+
const tip = await verify(upstream);
|
|
435
|
+
const notContained = notContainedMemo(baseSpawn);
|
|
436
|
+
const key = `${repoPath}\0${head}\0${tip}`;
|
|
437
|
+
// Unchanged head and default tip: a repeated refresh does not test every candidate again.
|
|
438
|
+
if (tip && notContained.has(key)) return "none";
|
|
439
|
+
const mergeBase = await value("merge-base", head, upstream);
|
|
440
|
+
const headTime = Number(await value("show", "-s", "--format=%ct", head));
|
|
441
|
+
if (!mergeBase || !headTime) return "unknown";
|
|
442
|
+
// Like a branch without commits of its own on the ancestry path: every later commit
|
|
443
|
+
// would "contain" it, so only the user can tell.
|
|
444
|
+
const [baseTree, headTree] = await Promise.all([
|
|
445
|
+
value("rev-parse", "--verify", "--quiet", `${mergeBase}^{tree}`),
|
|
446
|
+
value("rev-parse", "--verify", "--quiet", `${head}^{tree}`),
|
|
447
|
+
]);
|
|
448
|
+
if (!baseTree || baseTree === headTree) return "unknown";
|
|
449
|
+
const listed = await git([
|
|
450
|
+
"log",
|
|
451
|
+
"--first-parent",
|
|
452
|
+
"--reverse",
|
|
453
|
+
"--format=%H %ct %cI",
|
|
454
|
+
`${mergeBase}..${upstream}`,
|
|
455
|
+
"--",
|
|
456
|
+
]);
|
|
457
|
+
if (listed.code !== 0) return "unknown";
|
|
458
|
+
const candidates = listed.stdout
|
|
459
|
+
.split("\n")
|
|
460
|
+
.map((line) => line.trim().split(" "))
|
|
461
|
+
.filter(([, time]) => Number(time) >= headTime - CONTAINMENT_SLACK_SECONDS);
|
|
462
|
+
const limit = deps.containmentLimit ?? CONTAINMENT_LIMIT;
|
|
463
|
+
const deadline = Date.now() + (deps.containmentBudgetMs ?? CONTAINMENT_BUDGET_MS);
|
|
464
|
+
for (const [commit, , committedAt] of candidates.slice(0, limit)) {
|
|
465
|
+
if (Date.now() >= deadline) return "unknown";
|
|
466
|
+
// oxlint-disable-next-line no-await-in-loop -- oldest first, stops at the first hit
|
|
467
|
+
const answer = await contains(commit!, head);
|
|
468
|
+
if (answer === null) return "unknown";
|
|
469
|
+
if (answer) return { commit: commit!, committedAt: new Date(committedAt!).toISOString() };
|
|
470
|
+
}
|
|
471
|
+
if (candidates.length > limit) return "unknown";
|
|
472
|
+
if (tip) {
|
|
473
|
+
if (notContained.size >= NOT_CONTAINED_MAX) notContained.clear();
|
|
474
|
+
notContained.add(key);
|
|
475
|
+
}
|
|
476
|
+
return "none";
|
|
477
|
+
},
|
|
216
478
|
async lastFetchedAt() {
|
|
217
479
|
const fetchHead = await value("rev-parse", "--git-path", "FETCH_HEAD");
|
|
218
480
|
if (!fetchHead) return null;
|
|
@@ -225,19 +487,7 @@ export function mergeGit(repoPath: string, deps: MergeGitDeps = {}): MergeGit {
|
|
|
225
487
|
},
|
|
226
488
|
async fetch(defaultBranch, branch) {
|
|
227
489
|
const deadline = Date.now() + FETCH_BUDGET_MS;
|
|
228
|
-
|
|
229
|
-
const env: NodeJS.ProcessEnv = withGitConfig(
|
|
230
|
-
{ ...promptless, GCM_INTERACTIVE: "never" },
|
|
231
|
-
{ "maintenance.auto": "false", "gc.auto": "0" },
|
|
232
|
-
);
|
|
233
|
-
// A user's own SSH command wins; otherwise SSH must not ask for a passphrase.
|
|
234
|
-
if (
|
|
235
|
-
!base.GIT_SSH_COMMAND &&
|
|
236
|
-
!base.GIT_SSH &&
|
|
237
|
-
!(await value("config", "--get", "core.sshCommand"))
|
|
238
|
-
) {
|
|
239
|
-
env.GIT_SSH_COMMAND = "ssh -o BatchMode=yes";
|
|
240
|
-
}
|
|
490
|
+
const env = await networkEnv();
|
|
241
491
|
const fetchRef = async (name: string): Promise<ProcessResult> => {
|
|
242
492
|
// Names come from the shared Delivery Record: never fetch one Git would not accept.
|
|
243
493
|
if ((await git(["check-ref-format", `refs/heads/${name}`])).code !== 0) {
|
|
@@ -264,10 +514,44 @@ export function mergeGit(repoPath: string, deps: MergeGitDeps = {}): MergeGit {
|
|
|
264
514
|
if (branch === defaultBranch) return { ok: true };
|
|
265
515
|
const delivery = await fetchRef(branch);
|
|
266
516
|
// A branch deleted after its merge is expected; its recorded head still answers.
|
|
267
|
-
if (delivery.code !== 0 &&
|
|
268
|
-
return
|
|
517
|
+
if (delivery.code !== 0 && /couldn't find remote ref/i.test(delivery.stderr)) {
|
|
518
|
+
return { ok: true, branchDeleted: true };
|
|
269
519
|
}
|
|
520
|
+
if (delivery.code !== 0) return fetchFailure(delivery);
|
|
270
521
|
return { ok: true };
|
|
271
522
|
},
|
|
523
|
+
async pullRefs() {
|
|
524
|
+
const listed = await network([
|
|
525
|
+
"ls-remote",
|
|
526
|
+
"origin",
|
|
527
|
+
"refs/pull/*/head",
|
|
528
|
+
"refs/merge-requests/*/head",
|
|
529
|
+
]);
|
|
530
|
+
if (listed.code !== 0) return null;
|
|
531
|
+
return listed.stdout.split("\n").flatMap((line) => {
|
|
532
|
+
const [commit, name] = line.trim().split(/\s+/);
|
|
533
|
+
const match = name ? /^refs\/(pull|merge-requests)\/(\d+)\/head$/.exec(name) : null;
|
|
534
|
+
if (!commit || !match || !COMMIT_ID.test(commit)) return [];
|
|
535
|
+
return [{ number: Number(match[2]), ref: match[1] as PullRef["ref"], commit }];
|
|
536
|
+
});
|
|
537
|
+
},
|
|
538
|
+
async fetchPullHead(number, ref) {
|
|
539
|
+
if (!Number.isSafeInteger(number) || number <= 0) return null;
|
|
540
|
+
// Into a private ref removed again, not `FETCH_HEAD`: its time tells when origin was
|
|
541
|
+
// last fetched, and the user may be about to merge it.
|
|
542
|
+
const target = `refs/mate/pull-head/${randomUUID()}`;
|
|
543
|
+
const fetched = await network([
|
|
544
|
+
"fetch",
|
|
545
|
+
"--no-tags",
|
|
546
|
+
"--no-recurse-submodules",
|
|
547
|
+
"--no-write-fetch-head",
|
|
548
|
+
"origin",
|
|
549
|
+
`+refs/${ref}/${number}/head:${target}`,
|
|
550
|
+
]);
|
|
551
|
+
if (fetched.code !== 0) return null;
|
|
552
|
+
const head = await verify(target);
|
|
553
|
+
await git(["update-ref", "-d", target]);
|
|
554
|
+
return head;
|
|
555
|
+
},
|
|
272
556
|
};
|
|
273
557
|
}
|