@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
|
@@ -0,0 +1,1050 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { isChangeName } from "../../change-layout";
|
|
5
|
+
import { pathIsDirectory } from "../../fs-utils";
|
|
6
|
+
import { scopedRepositories } from "../../openspec-scopes";
|
|
7
|
+
import {
|
|
8
|
+
companionGit,
|
|
9
|
+
describeGitFailure,
|
|
10
|
+
LITERAL_PATHSPECS,
|
|
11
|
+
nulPaths,
|
|
12
|
+
type CompanionGit,
|
|
13
|
+
} from "../../../runtime/companion-git";
|
|
14
|
+
import {
|
|
15
|
+
readSubmittedFolders,
|
|
16
|
+
updateSubmittedFolders,
|
|
17
|
+
type SubmittedFolder,
|
|
18
|
+
} from "../../../runtime/companion-git-state";
|
|
19
|
+
import { errorMessage } from "../../../runtime/error-message";
|
|
20
|
+
import { isSubmittedName } from "../../../runtime/pending-records";
|
|
21
|
+
import { isWithin } from "../../../runtime/physical-path";
|
|
22
|
+
import { contentDigest, folderDigest, ownFiles } from "../../../runtime/submitted-arrivals";
|
|
23
|
+
import type { PublicationSecretScan } from "../../../runtime/publication-secret-scan";
|
|
24
|
+
import type { SecretFinding } from "../../../runtime/secret-scan";
|
|
25
|
+
import {
|
|
26
|
+
DELIVERY_FILE,
|
|
27
|
+
findDelivery,
|
|
28
|
+
isCommitId,
|
|
29
|
+
readDeliveryRecord,
|
|
30
|
+
readOrUnlinkedRecord,
|
|
31
|
+
upsertDelivery,
|
|
32
|
+
withoutStage,
|
|
33
|
+
writeDeliveryRecord,
|
|
34
|
+
type DeliveryRecord,
|
|
35
|
+
type SubmissionState,
|
|
36
|
+
} from "../record";
|
|
37
|
+
import { isSettled } from "../refresh";
|
|
38
|
+
import { recordDir, sourceDir, type ArtifactType } from "./artifact-type";
|
|
39
|
+
import { deliveryGroupFor, type DeliveryGroupName } from "./naming";
|
|
40
|
+
import { sourcePathOf, staleParts, STALE_SCAN_LIMIT } from "./pending";
|
|
41
|
+
import { commitToPending } from "./pending-edit";
|
|
42
|
+
import {
|
|
43
|
+
defaultRef,
|
|
44
|
+
fetchPendingBranches,
|
|
45
|
+
pendingPlace,
|
|
46
|
+
pendingRef,
|
|
47
|
+
stagingRemote,
|
|
48
|
+
type StagingRemote,
|
|
49
|
+
} from "./refs";
|
|
50
|
+
import { defaultArtifactType } from "./registry";
|
|
51
|
+
import { linkedContentPaths } from "./worktree";
|
|
52
|
+
|
|
53
|
+
/** Bound on one submit or drop push, every fetch, command and push included. */
|
|
54
|
+
const SUBMIT_BUDGET_MS = 120_000;
|
|
55
|
+
|
|
56
|
+
export interface SubmitDeps {
|
|
57
|
+
/** Git for one directory, network included. */
|
|
58
|
+
git?: (cwd: string) => CompanionGit;
|
|
59
|
+
/** The changes' artifact type; OpenSpec by default. */
|
|
60
|
+
artifactType?: ArtifactType;
|
|
61
|
+
/** Scans `paths` under `root` with the companion's policy; the publication scan by default. */
|
|
62
|
+
scan?: (root: string, paths: string[], policyPath: string) => Promise<PublicationSecretScan>;
|
|
63
|
+
newTransaction?: () => string;
|
|
64
|
+
tmpRoot?: string;
|
|
65
|
+
/** Home of Mate's local companion state; `HOME` by default. */
|
|
66
|
+
stateHome?: string;
|
|
67
|
+
now?: () => Date;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const defaultGit = (cwd: string): CompanionGit =>
|
|
71
|
+
companionGit(cwd, { prompt: "never", budgetMs: SUBMIT_BUDGET_MS });
|
|
72
|
+
|
|
73
|
+
/** SHA-256 over a folder's relative file paths and contents; sync compares it later. */
|
|
74
|
+
export { folderDigest };
|
|
75
|
+
|
|
76
|
+
/** A change's state as its Delivery Record says; `active` without one or with a damaged one. */
|
|
77
|
+
export async function submissionState(changeDir: string): Promise<SubmissionState> {
|
|
78
|
+
const record = await readDeliveryRecord(changeDir).catch(() => null);
|
|
79
|
+
return record?.state ?? "active";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Writes `state` into change `name`'s Delivery Record, creating an unlinked one when absent. */
|
|
83
|
+
export async function writeSubmissionState(
|
|
84
|
+
changeDir: string,
|
|
85
|
+
name: string,
|
|
86
|
+
state: SubmissionState,
|
|
87
|
+
): Promise<void> {
|
|
88
|
+
const record = await readOrUnlinkedRecord(changeDir, name);
|
|
89
|
+
await writeDeliveryRecord(changeDir, { ...record, state });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The Delivery Group of local change `name` after its Delivery Record. */
|
|
93
|
+
export async function groupOfChange(
|
|
94
|
+
companionPath: string,
|
|
95
|
+
name: string,
|
|
96
|
+
type: ArtifactType = defaultArtifactType(),
|
|
97
|
+
): Promise<DeliveryGroupName> {
|
|
98
|
+
const dir = sourceDir(companionPath, type, name);
|
|
99
|
+
const record = await readDeliveryRecord(dir).catch(() => null);
|
|
100
|
+
return deliveryGroupFor(name, record, await scopedRepositories(dir));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface LocalMember {
|
|
104
|
+
name: string;
|
|
105
|
+
state: SubmissionState;
|
|
106
|
+
group: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The active members of `group` not in `names`: submitting `names` waits for them. */
|
|
110
|
+
export function waitingMembers(
|
|
111
|
+
members: readonly LocalMember[],
|
|
112
|
+
group: string,
|
|
113
|
+
names: readonly string[],
|
|
114
|
+
): string[] {
|
|
115
|
+
return members
|
|
116
|
+
.filter(
|
|
117
|
+
(member) =>
|
|
118
|
+
member.group === group && member.state === "active" && !names.includes(member.name),
|
|
119
|
+
)
|
|
120
|
+
.map((member) => member.name);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Every local source folder of `type` with its state and Delivery Group, by name. */
|
|
124
|
+
export async function localMembers(
|
|
125
|
+
companionPath: string,
|
|
126
|
+
type: ArtifactType = defaultArtifactType(),
|
|
127
|
+
): Promise<LocalMember[]> {
|
|
128
|
+
const root = path.join(companionPath, ...type.source.split("/"));
|
|
129
|
+
const archive = recordDir(companionPath, type);
|
|
130
|
+
let entries;
|
|
131
|
+
try {
|
|
132
|
+
entries = await fs.readdir(root, { withFileTypes: true });
|
|
133
|
+
} catch {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
const names = entries
|
|
137
|
+
.filter((entry) => entry.isDirectory() && isChangeName(entry.name))
|
|
138
|
+
.map((entry) => entry.name)
|
|
139
|
+
.filter((name) => path.join(root, name) !== archive)
|
|
140
|
+
.toSorted();
|
|
141
|
+
return Promise.all(
|
|
142
|
+
names.map(async (name) => {
|
|
143
|
+
const dir = sourceDir(companionPath, type, name);
|
|
144
|
+
const record = await readDeliveryRecord(dir).catch(() => null);
|
|
145
|
+
return {
|
|
146
|
+
name,
|
|
147
|
+
state: record?.state ?? "active",
|
|
148
|
+
group: deliveryGroupFor(name, record, await scopedRepositories(dir)).group,
|
|
149
|
+
};
|
|
150
|
+
}),
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export type PendingFailure =
|
|
155
|
+
| "no-remote"
|
|
156
|
+
| "fetch-failed"
|
|
157
|
+
| "secret"
|
|
158
|
+
| "push-failed"
|
|
159
|
+
/** The remote refused this user's push to the pending branch. */
|
|
160
|
+
| "not-permitted"
|
|
161
|
+
/** The pending branch kept moving through every rebuild. */
|
|
162
|
+
| "conflict"
|
|
163
|
+
| "failed";
|
|
164
|
+
|
|
165
|
+
export interface PendingCommit {
|
|
166
|
+
status: "pushed" | "unchanged" | "failed";
|
|
167
|
+
reason?: PendingFailure;
|
|
168
|
+
/** The commit this run pushed. */
|
|
169
|
+
commit: string | null;
|
|
170
|
+
/** The branch submitted changes wait on, once known. */
|
|
171
|
+
pendingBranch: string | null;
|
|
172
|
+
secretFindings?: SecretFinding[];
|
|
173
|
+
/** Why it failed, for `failed`. */
|
|
174
|
+
detail?: string;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function failed(
|
|
178
|
+
reason: PendingFailure,
|
|
179
|
+
detail: string,
|
|
180
|
+
remote: StagingRemote | null,
|
|
181
|
+
): PendingCommit {
|
|
182
|
+
return {
|
|
183
|
+
status: "failed",
|
|
184
|
+
reason,
|
|
185
|
+
commit: null,
|
|
186
|
+
pendingBranch: remote?.pendingBranch ?? null,
|
|
187
|
+
detail,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Writes the change into the pending checkout `dir`; returns the paths it touched. */
|
|
192
|
+
type Stage = (dir: string, remote: StagingRemote) => Promise<string[]>;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* {@link commitToPending} as submit and drop report it: no commit when nothing changed, and a
|
|
196
|
+
* thrown failure reported as `failed`.
|
|
197
|
+
*/
|
|
198
|
+
async function commitStaged(
|
|
199
|
+
companionPath: string,
|
|
200
|
+
subject: string,
|
|
201
|
+
stage: Stage,
|
|
202
|
+
deps: SubmitDeps,
|
|
203
|
+
): Promise<PendingCommit> {
|
|
204
|
+
try {
|
|
205
|
+
const result = await commitToPending(
|
|
206
|
+
{ companionPath, subject, edit: stage },
|
|
207
|
+
{ ...deps, git: deps.git ?? defaultGit },
|
|
208
|
+
);
|
|
209
|
+
const pendingBranch = result.remote?.pendingBranch ?? null;
|
|
210
|
+
if (result.status === "pushed") {
|
|
211
|
+
return { status: "pushed", commit: result.commit, pendingBranch };
|
|
212
|
+
}
|
|
213
|
+
if (result.status !== "failed") return { status: "unchanged", commit: null, pendingBranch };
|
|
214
|
+
return {
|
|
215
|
+
...failed(
|
|
216
|
+
result.reason === "commit-failed" ? "failed" : result.reason,
|
|
217
|
+
result.detail,
|
|
218
|
+
result.remote,
|
|
219
|
+
),
|
|
220
|
+
...(result.reason === "secret" ? { secretFindings: result.secretFindings } : {}),
|
|
221
|
+
};
|
|
222
|
+
} catch (error) {
|
|
223
|
+
return failed("failed", errorMessage(error), null);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** `target` below `dir`, refused when it would leave `dir`. */
|
|
228
|
+
function within(dir: string, relative: string): string {
|
|
229
|
+
const target = path.join(dir, ...relative.split("/"));
|
|
230
|
+
if (target === dir || !isWithin(target, dir)) {
|
|
231
|
+
throw new Error(`${relative} lies outside the companion`);
|
|
232
|
+
}
|
|
233
|
+
return target;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export interface GroupPush extends PendingCommit {
|
|
237
|
+
group: string;
|
|
238
|
+
/** The folders the commit carries, by change name. */
|
|
239
|
+
changes: string[];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* The Delivery Record change `name` is pushed with: `state: submitted`, an earlier block and
|
|
244
|
+
* its recorded `submit` steps cleared, and a delta base the default branch holds, so publication can tell a requirement
|
|
245
|
+
* changed since: the recorded one, or where it left the default branch when it is a local
|
|
246
|
+
* commit, else `tip`, the fetched default tip. Written locally only once the push succeeded, so
|
|
247
|
+
* a failed push leaves the record, its state included, as it was. Throws on a damaged record.
|
|
248
|
+
*/
|
|
249
|
+
async function preparedRecord(
|
|
250
|
+
git: CompanionGit,
|
|
251
|
+
changeDir: string,
|
|
252
|
+
name: string,
|
|
253
|
+
tip: string,
|
|
254
|
+
): Promise<DeliveryRecord> {
|
|
255
|
+
const record = await readOrUnlinkedRecord(changeDir, name);
|
|
256
|
+
let specBase = record.specBase ?? (isCommitId(tip) ? tip : undefined);
|
|
257
|
+
if (record.specBase && isCommitId(record.specBase) && isCommitId(tip)) {
|
|
258
|
+
const shared = await git.run(["merge-base", record.specBase, tip]);
|
|
259
|
+
const commit = shared.stdout.trim();
|
|
260
|
+
if (shared.status === 0 && isCommitId(commit)) specBase = commit;
|
|
261
|
+
}
|
|
262
|
+
const next: DeliveryRecord = { ...record, state: "submitted", ...(specBase ? { specBase } : {}) };
|
|
263
|
+
delete next.blocked;
|
|
264
|
+
// A resubmission runs the steps before `mate-submit-change` again.
|
|
265
|
+
return withoutStage(next, "submit");
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* `record` with the final merge results `pending`, the same change's record on the pending
|
|
270
|
+
* branch, holds for the same deliveries and `record` lacks: an answer or a merge recorded there
|
|
271
|
+
* from another machine survives a resubmit.
|
|
272
|
+
*/
|
|
273
|
+
function withPendingSettlements(
|
|
274
|
+
record: DeliveryRecord,
|
|
275
|
+
pending: DeliveryRecord | null,
|
|
276
|
+
): DeliveryRecord {
|
|
277
|
+
if (!pending) return record;
|
|
278
|
+
let next = record;
|
|
279
|
+
for (const delivery of record.deliveries) {
|
|
280
|
+
if (!delivery.branch || isSettled(delivery)) continue;
|
|
281
|
+
const settled = findDelivery(pending, delivery.repository);
|
|
282
|
+
if (
|
|
283
|
+
!settled?.merge ||
|
|
284
|
+
!isSettled(settled) ||
|
|
285
|
+
settled.branch !== delivery.branch ||
|
|
286
|
+
Boolean(settled.direct) !== Boolean(delivery.direct)
|
|
287
|
+
) {
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
next = upsertDelivery(next, delivery.repository, {
|
|
291
|
+
...(settled.pr ? { pr: settled.pr } : {}),
|
|
292
|
+
...(settled.head ? { head: settled.head } : {}),
|
|
293
|
+
merge: settled.merge,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
return next;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* The files below the companion folder `relative` its own Git would add: tracked and untracked,
|
|
301
|
+
* ignored ones left out. Throws on a symbolic link, submodule or nested repository, which would
|
|
302
|
+
* stop every later temporary worktree of the pending branch, and on a folder with no such file.
|
|
303
|
+
*/
|
|
304
|
+
async function submittableFiles(
|
|
305
|
+
git: CompanionGit,
|
|
306
|
+
companionPath: string,
|
|
307
|
+
relative: string,
|
|
308
|
+
): Promise<string[]> {
|
|
309
|
+
const listed = await git.run([
|
|
310
|
+
...LITERAL_PATHSPECS,
|
|
311
|
+
"ls-files",
|
|
312
|
+
"-z",
|
|
313
|
+
"--cached",
|
|
314
|
+
"--others",
|
|
315
|
+
"--exclude-standard",
|
|
316
|
+
"--",
|
|
317
|
+
`${relative}/`,
|
|
318
|
+
]);
|
|
319
|
+
if (listed.status !== 0) throw new Error(`git ls-files ${relative} failed`);
|
|
320
|
+
const files: string[] = [];
|
|
321
|
+
for (const file of new Set(nulPaths(listed.stdout))) {
|
|
322
|
+
// An untracked nested repository is listed as its directory.
|
|
323
|
+
const nested = file.endsWith("/");
|
|
324
|
+
// oxlint-disable-next-line no-await-in-loop -- a handful of files per change
|
|
325
|
+
const stat = nested ? null : await fs.lstat(path.join(companionPath, file)).catch(() => null);
|
|
326
|
+
if (!nested && stat === null) continue;
|
|
327
|
+
if (nested || !stat!.isFile()) {
|
|
328
|
+
throw new Error(
|
|
329
|
+
`${file.replace(/\/$/, "")} is a symbolic link, submodule or nested Git repository; Mate does not submit it. Remove it from ${relative} and submit again.`,
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
files.push(file);
|
|
333
|
+
}
|
|
334
|
+
if (files.length === 0) {
|
|
335
|
+
throw new Error(`${relative} holds no file Git would add; check the companion's .gitignore.`);
|
|
336
|
+
}
|
|
337
|
+
return files;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* The content of the regular file `file` below the companion, read without following a
|
|
342
|
+
* symbolic link: a file swapped for a link after it was listed must not push what it points to.
|
|
343
|
+
*/
|
|
344
|
+
async function readSubmittable(
|
|
345
|
+
companionPath: string,
|
|
346
|
+
folder: string,
|
|
347
|
+
file: string,
|
|
348
|
+
): Promise<Buffer> {
|
|
349
|
+
const source = path.join(companionPath, ...file.split("/"));
|
|
350
|
+
const parent = await fs.realpath(path.dirname(source));
|
|
351
|
+
if (!isWithin(parent, await fs.realpath(path.join(companionPath, ...folder.split("/"))))) {
|
|
352
|
+
throw new Error(`${file} lies outside ${folder}; Mate does not submit it.`);
|
|
353
|
+
}
|
|
354
|
+
const handle = await fs
|
|
355
|
+
.open(source, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0))
|
|
356
|
+
.catch((error: NodeJS.ErrnoException) => {
|
|
357
|
+
throw error.code === "ELOOP"
|
|
358
|
+
? new Error(`${file} is a symbolic link; Mate does not submit it.`)
|
|
359
|
+
: error;
|
|
360
|
+
});
|
|
361
|
+
try {
|
|
362
|
+
if (!(await handle.stat()).isFile()) {
|
|
363
|
+
throw new Error(`${file} is no regular file; Mate does not submit it.`);
|
|
364
|
+
}
|
|
365
|
+
return await handle.readFile();
|
|
366
|
+
} finally {
|
|
367
|
+
await handle.close();
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** {@link contentDigest} of `files` without the Delivery Record, which settlements and blocks rewrite. */
|
|
372
|
+
function contentOnly(files: readonly (readonly [string, Uint8Array])[]): string {
|
|
373
|
+
return contentDigest(files.filter(([file]) => file !== DELIVERY_FILE));
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* {@link contentOnly} of folder `relative` in the pending checkout `dir`; null when the pending
|
|
378
|
+
* branch does not hold the folder.
|
|
379
|
+
*/
|
|
380
|
+
async function pendingContent(
|
|
381
|
+
git: CompanionGit,
|
|
382
|
+
dir: string,
|
|
383
|
+
relative: string,
|
|
384
|
+
): Promise<string | null> {
|
|
385
|
+
const files = await ownFiles(git, dir, relative);
|
|
386
|
+
if (files === null) throw new Error(`git ls-files ${relative} failed`);
|
|
387
|
+
if (files.length === 0) return null;
|
|
388
|
+
return folderDigest(
|
|
389
|
+
path.join(dir, ...relative.split("/")),
|
|
390
|
+
files.filter((file) => file !== DELIVERY_FILE),
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export interface PushOptions {
|
|
395
|
+
/** Changes of the push staged only when the pending branch does not hold their folder. */
|
|
396
|
+
ifMissing?: readonly string[];
|
|
397
|
+
/**
|
|
398
|
+
* Changes submitted by name: one the pending branch records blocked is pushed again even
|
|
399
|
+
* unchanged, and takes the default tip as delta base when {@link acceptsBlock} allows it.
|
|
400
|
+
*/
|
|
401
|
+
acknowledge?: readonly string[];
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* True when the change at `folder` in `ref`, a commit or tree of the pending checkout `work`,
|
|
406
|
+
* has stale parts and overwrites none of the parts that changed between `base` and `tip`: its author, shown the
|
|
407
|
+
* conflict, submitted it again, and what remains stale (a removal, a plain rename) replaces no
|
|
408
|
+
* one's text. A part it would overwrite still needs `mate artifact resolve`.
|
|
409
|
+
*/
|
|
410
|
+
export async function acceptsBlock(
|
|
411
|
+
type: ArtifactType,
|
|
412
|
+
work: CompanionGit,
|
|
413
|
+
ref: string,
|
|
414
|
+
folder: string,
|
|
415
|
+
base: string,
|
|
416
|
+
tip: string,
|
|
417
|
+
): Promise<boolean> {
|
|
418
|
+
const stale = await staleParts(type, work, ref, folder, base, tip);
|
|
419
|
+
// Nothing stale: the block has another cause, which a new base would not lift.
|
|
420
|
+
return (
|
|
421
|
+
stale.length > 0 &&
|
|
422
|
+
stale.length < STALE_SCAN_LIMIT &&
|
|
423
|
+
stale.every((part) => part.overwrites === false)
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** {@link acceptsBlock} for the folder as staged in the pending checkout `work`. */
|
|
428
|
+
async function stagedAccepts(
|
|
429
|
+
type: ArtifactType,
|
|
430
|
+
work: CompanionGit,
|
|
431
|
+
folder: string,
|
|
432
|
+
base: string,
|
|
433
|
+
tip: string,
|
|
434
|
+
): Promise<boolean> {
|
|
435
|
+
await work.run([...LITERAL_PATHSPECS, "add", "-f", "-A", "--", folder]);
|
|
436
|
+
const tree = (await work.run(["write-tree"])).stdout.trim();
|
|
437
|
+
return isCommitId(tree) && acceptsBlock(type, work, tree, folder, base, tip);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Pushes the local folders of `names`, changes of one Delivery Group, in one commit on the
|
|
442
|
+
* pending branch, each with `state: submitted`, replacing their earlier copies there. Only files
|
|
443
|
+
* the companion does not ignore are copied. A folder the pending branch holds with other content
|
|
444
|
+
* than this checkout last submitted or took (a teammate resolved or revised it) is never
|
|
445
|
+
* replaced: it stays as it is there when only the local Delivery Record differs, else the push
|
|
446
|
+
* fails. A change of `options.acknowledge` the pending branch records blocked takes the default
|
|
447
|
+
* tip as delta base when it overwrites no stale part. A final merge result the pending branch
|
|
448
|
+
* records for a delivery, and the local record lacks, is kept. Only on success are the local records of the folders it carries set `submitted` and
|
|
449
|
+
* each folder's digest recorded as submitted from this checkout. The checkout is not touched
|
|
450
|
+
* otherwise.
|
|
451
|
+
*/
|
|
452
|
+
async function pushGroup(
|
|
453
|
+
companionPath: string,
|
|
454
|
+
group: string,
|
|
455
|
+
names: readonly string[],
|
|
456
|
+
deps: SubmitDeps = {},
|
|
457
|
+
options: PushOptions = {},
|
|
458
|
+
): Promise<GroupPush> {
|
|
459
|
+
const type = deps.artifactType ?? defaultArtifactType();
|
|
460
|
+
const paths = names.map((name) => sourcePathOf(type, name));
|
|
461
|
+
const gitFor = deps.git ?? defaultGit;
|
|
462
|
+
const local = gitFor(companionPath);
|
|
463
|
+
// Refused before any fetch, so nothing of the group is copied or pushed.
|
|
464
|
+
const unnamed = names.filter((name) => !isSubmittedName(name));
|
|
465
|
+
if (unnamed.length > 0) {
|
|
466
|
+
const detail = `${unnamed.join(", ")} cannot be submitted under that name: a submitted change's name starts with a letter, digit or \`_\` and holds only those, \`.\` and \`-\`. Rename the change, then submit it.`;
|
|
467
|
+
return { ...failed("failed", detail, null), group, changes: [...names] };
|
|
468
|
+
}
|
|
469
|
+
const listed: string[][] = [];
|
|
470
|
+
try {
|
|
471
|
+
for (const relative of paths) {
|
|
472
|
+
// oxlint-disable-next-line no-await-in-loop -- one folder at a time
|
|
473
|
+
listed.push(await submittableFiles(local, companionPath, relative));
|
|
474
|
+
}
|
|
475
|
+
} catch (error) {
|
|
476
|
+
return { ...failed("failed", errorMessage(error), null), group, changes: [...names] };
|
|
477
|
+
}
|
|
478
|
+
const submitted = readSubmittedFolders(companionPath, deps.stateHome);
|
|
479
|
+
// The digests of exactly the bytes pushed, so an edit made meanwhile counts as unsubmitted.
|
|
480
|
+
const digests = new Map<string, Pick<SubmittedFolder, "digest" | "content">>();
|
|
481
|
+
const records = new Map<string, DeliveryRecord>();
|
|
482
|
+
const pushed = await commitStaged(
|
|
483
|
+
companionPath,
|
|
484
|
+
`chore(${type.name}): submit ${group}`,
|
|
485
|
+
async (dir, remote) => {
|
|
486
|
+
// A rebuilt attempt decides again on the new tip.
|
|
487
|
+
digests.clear();
|
|
488
|
+
records.clear();
|
|
489
|
+
const work = gitFor(dir);
|
|
490
|
+
const tip = await local.run([
|
|
491
|
+
"rev-parse",
|
|
492
|
+
"--verify",
|
|
493
|
+
"-q",
|
|
494
|
+
`${defaultRef(remote)}^{commit}`,
|
|
495
|
+
]);
|
|
496
|
+
const staged: string[] = [];
|
|
497
|
+
for (const [index, name] of names.entries()) {
|
|
498
|
+
const folder = sourcePathOf(type, name);
|
|
499
|
+
const files: [string, Buffer][] = [];
|
|
500
|
+
for (const file of listed[index]!) {
|
|
501
|
+
files.push([
|
|
502
|
+
path.posix.relative(folder, file),
|
|
503
|
+
// oxlint-disable-next-line no-await-in-loop -- one file at a time
|
|
504
|
+
await readSubmittable(companionPath, folder, file),
|
|
505
|
+
]);
|
|
506
|
+
}
|
|
507
|
+
// oxlint-disable-next-line no-await-in-loop -- one folder at a time
|
|
508
|
+
const theirs = await pendingContent(work, dir, folder);
|
|
509
|
+
const unchanged = options.ifMissing?.includes(name) === true;
|
|
510
|
+
const pending =
|
|
511
|
+
theirs === null
|
|
512
|
+
? null
|
|
513
|
+
: // oxlint-disable-next-line no-await-in-loop -- one folder at a time
|
|
514
|
+
await readDeliveryRecord(within(dir, folder)).catch(() => null);
|
|
515
|
+
const blocked = options.acknowledge?.includes(name) === true && Boolean(pending?.blocked);
|
|
516
|
+
if (theirs !== null) {
|
|
517
|
+
// A blocked change submitted again by name may accept its conflict, even unchanged.
|
|
518
|
+
if (unchanged && !blocked) continue;
|
|
519
|
+
const mine = submitted[folder]?.content;
|
|
520
|
+
const here = contentOnly(files);
|
|
521
|
+
// Never submitted or taken here: only the same content may be pushed over it.
|
|
522
|
+
if (mine === undefined && theirs !== here) {
|
|
523
|
+
throw new Error(
|
|
524
|
+
`${name} is on ${pendingPlace(remote)} with other content than ${folder} here, which this checkout never submitted or took, and submitting would overwrite that. Move ${folder} aside, run \`mate artifact take ${name}\`, redo your edit there and submit it`,
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
if (mine !== undefined && theirs !== mine) {
|
|
528
|
+
// Only the local record differs: the pending branch's version stands.
|
|
529
|
+
if (here === mine) continue;
|
|
530
|
+
throw new Error(
|
|
531
|
+
`${name} changed on ${pendingPlace(remote)} since this checkout submitted it (a teammate resolved or revised it), and submitting would overwrite that. Move ${folder} aside, run \`mate artifact take ${name}\`, redo your edit there and submit it`,
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
// oxlint-disable-next-line no-await-in-loop -- one folder at a time
|
|
536
|
+
const prepared = await preparedRecord(
|
|
537
|
+
local,
|
|
538
|
+
sourceDir(companionPath, type, name),
|
|
539
|
+
name,
|
|
540
|
+
tip.stdout.trim(),
|
|
541
|
+
);
|
|
542
|
+
let record = withPendingSettlements(prepared, pending);
|
|
543
|
+
const defaultTip = tip.stdout.trim();
|
|
544
|
+
const base =
|
|
545
|
+
blocked && isCommitId(defaultTip) && record.specBase !== defaultTip
|
|
546
|
+
? record.specBase
|
|
547
|
+
: undefined;
|
|
548
|
+
if (blocked && unchanged) {
|
|
549
|
+
// The pending branch holds this very delta. Not accepted: it stays as it is, blocked.
|
|
550
|
+
// oxlint-disable-next-line no-await-in-loop -- one folder at a time
|
|
551
|
+
if (!base || !(await acceptsBlock(type, work, "HEAD", folder, base, defaultTip))) {
|
|
552
|
+
continue;
|
|
553
|
+
}
|
|
554
|
+
record = { ...record, specBase: defaultTip };
|
|
555
|
+
}
|
|
556
|
+
records.set(name, record);
|
|
557
|
+
// oxlint-disable-next-line no-await-in-loop -- one folder at a time
|
|
558
|
+
await fs.rm(within(dir, folder), { recursive: true, force: true });
|
|
559
|
+
const copied: [string, Buffer][] = [];
|
|
560
|
+
for (const [relative, read] of files) {
|
|
561
|
+
const target = within(dir, `${folder}/${relative}`);
|
|
562
|
+
let content = read;
|
|
563
|
+
// oxlint-disable-next-line no-await-in-loop -- one file at a time
|
|
564
|
+
await fs.mkdir(path.dirname(target), { recursive: true });
|
|
565
|
+
if (relative === DELIVERY_FILE) {
|
|
566
|
+
// oxlint-disable-next-line no-await-in-loop -- same file
|
|
567
|
+
await writeDeliveryRecord(path.dirname(target), record);
|
|
568
|
+
// oxlint-disable-next-line no-await-in-loop -- same file
|
|
569
|
+
content = await fs.readFile(target);
|
|
570
|
+
} else {
|
|
571
|
+
// oxlint-disable-next-line no-await-in-loop -- same file
|
|
572
|
+
await fs.writeFile(target, content);
|
|
573
|
+
}
|
|
574
|
+
copied.push([relative, content]);
|
|
575
|
+
}
|
|
576
|
+
// A change that never had a record gets one, so its state travels with it.
|
|
577
|
+
if (!copied.some(([relative]) => relative === DELIVERY_FILE)) {
|
|
578
|
+
const target = within(dir, folder);
|
|
579
|
+
// oxlint-disable-next-line no-await-in-loop -- one folder at a time
|
|
580
|
+
await writeDeliveryRecord(target, record);
|
|
581
|
+
// oxlint-disable-next-line no-await-in-loop -- same folder
|
|
582
|
+
const written = await fs.readFile(path.join(target, DELIVERY_FILE));
|
|
583
|
+
copied.push([DELIVERY_FILE, written]);
|
|
584
|
+
}
|
|
585
|
+
// Edited since the block: the delta as it is pushed decides.
|
|
586
|
+
// oxlint-disable-next-line no-await-in-loop -- one folder at a time
|
|
587
|
+
if (base && !unchanged && (await stagedAccepts(type, work, folder, base, defaultTip))) {
|
|
588
|
+
record = { ...record, specBase: defaultTip };
|
|
589
|
+
records.set(name, record);
|
|
590
|
+
const target = within(dir, folder);
|
|
591
|
+
// oxlint-disable-next-line no-await-in-loop -- same folder
|
|
592
|
+
await writeDeliveryRecord(target, record);
|
|
593
|
+
// oxlint-disable-next-line no-await-in-loop -- same folder
|
|
594
|
+
const written = await fs.readFile(path.join(target, DELIVERY_FILE));
|
|
595
|
+
copied.splice(
|
|
596
|
+
copied.findIndex(([relative]) => relative === DELIVERY_FILE),
|
|
597
|
+
1,
|
|
598
|
+
[DELIVERY_FILE, written],
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
digests.set(name, { digest: contentDigest(copied), content: contentOnly(copied) });
|
|
602
|
+
staged.push(folder);
|
|
603
|
+
}
|
|
604
|
+
return staged;
|
|
605
|
+
},
|
|
606
|
+
deps,
|
|
607
|
+
);
|
|
608
|
+
if (pushed.status === "failed") return { ...pushed, group, changes: [...names] };
|
|
609
|
+
for (const [name, record] of records) {
|
|
610
|
+
// oxlint-disable-next-line no-await-in-loop -- one folder at a time
|
|
611
|
+
await writeDeliveryRecord(sourceDir(companionPath, type, name), record);
|
|
612
|
+
}
|
|
613
|
+
const submittedAt = (deps.now?.() ?? new Date()).toISOString();
|
|
614
|
+
const folders: Record<string, SubmittedFolder> = {};
|
|
615
|
+
for (const [name, digest] of digests) {
|
|
616
|
+
folders[sourcePathOf(type, name)] = { ...digest, submittedAt };
|
|
617
|
+
}
|
|
618
|
+
updateSubmittedFolders(companionPath, folders, [], deps.stateHome);
|
|
619
|
+
return { ...pushed, group, changes: [...records.keys()] };
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* True when `relative` holds untracked or changed files in the checkout `git` runs in; null when
|
|
624
|
+
* Git cannot tell.
|
|
625
|
+
*/
|
|
626
|
+
async function hasLocalWork(git: CompanionGit, relative: string): Promise<boolean | null> {
|
|
627
|
+
const status = await git.run([
|
|
628
|
+
...LITERAL_PATHSPECS,
|
|
629
|
+
"status",
|
|
630
|
+
"--porcelain",
|
|
631
|
+
"-z",
|
|
632
|
+
"--untracked-files=all",
|
|
633
|
+
"--",
|
|
634
|
+
relative,
|
|
635
|
+
]);
|
|
636
|
+
return status.status === 0 ? status.stdout.length > 0 : null;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* True when the local folder `relative` should be pushed again with its group: it differs from
|
|
641
|
+
* what this checkout last submitted of it, committed since or not, or was never submitted here
|
|
642
|
+
* and holds local work. One unchanged since its own submit stays as the pending branch has it,
|
|
643
|
+
* where a teammate may have resolved it since. Null when Git cannot tell: neither pushing nor
|
|
644
|
+
* skipping it is safe.
|
|
645
|
+
*/
|
|
646
|
+
async function editedSinceSubmit(
|
|
647
|
+
git: CompanionGit,
|
|
648
|
+
companionPath: string,
|
|
649
|
+
relative: string,
|
|
650
|
+
submitted: Record<string, SubmittedFolder>,
|
|
651
|
+
): Promise<boolean | null> {
|
|
652
|
+
const recorded = submitted[relative];
|
|
653
|
+
if (!recorded) return hasLocalWork(git, relative);
|
|
654
|
+
const files = await ownFiles(git, companionPath, relative);
|
|
655
|
+
if (!files) return null;
|
|
656
|
+
const dir = path.join(companionPath, ...relative.split("/"));
|
|
657
|
+
return (await folderDigest(dir, files)) !== recorded.digest;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* True when local change `name` holds work the pending branch lacks: it is not `submitted` here
|
|
662
|
+
* (a teammate's submitted change may share its name), or was edited since this checkout
|
|
663
|
+
* submitted or took it.
|
|
664
|
+
*/
|
|
665
|
+
export async function hasUnsubmittedWork(
|
|
666
|
+
companionPath: string,
|
|
667
|
+
name: string,
|
|
668
|
+
deps: Pick<SubmitDeps, "git" | "artifactType" | "stateHome"> = {},
|
|
669
|
+
): Promise<boolean> {
|
|
670
|
+
const type = deps.artifactType ?? defaultArtifactType();
|
|
671
|
+
if ((await submissionState(sourceDir(companionPath, type, name))) !== "submitted") return true;
|
|
672
|
+
const relative = sourcePathOf(type, name);
|
|
673
|
+
const submitted = readSubmittedFolders(companionPath, deps.stateHome);
|
|
674
|
+
if (!submitted[relative]) return false;
|
|
675
|
+
const git = (deps.git ?? defaultGit)(companionPath);
|
|
676
|
+
return (await editedSinceSubmit(git, companionPath, relative, submitted)) === true;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* The `submitted` members of `groups`, those in `named` left out, that {@link submitGroups} pushes
|
|
681
|
+
* as edited. Call it before refreshing them: a refresh rewrites `delivery.yaml`, which the
|
|
682
|
+
* comparison covers. A member Git cannot judge is left out, since {@link submitGroups} fails its
|
|
683
|
+
* group. `recordOnly`: only its Delivery Record differs from what this checkout last submitted or
|
|
684
|
+
* took, so its content already passed a check.
|
|
685
|
+
*/
|
|
686
|
+
export async function editedSubmittedMembers(
|
|
687
|
+
companionPath: string,
|
|
688
|
+
groups: ReadonlySet<string>,
|
|
689
|
+
named: readonly string[],
|
|
690
|
+
deps: Pick<SubmitDeps, "git" | "artifactType" | "stateHome"> = {},
|
|
691
|
+
): Promise<(LocalMember & { recordOnly: boolean })[]> {
|
|
692
|
+
const type = deps.artifactType ?? defaultArtifactType();
|
|
693
|
+
const git = (deps.git ?? defaultGit)(companionPath);
|
|
694
|
+
const submitted = readSubmittedFolders(companionPath, deps.stateHome);
|
|
695
|
+
const edited: (LocalMember & { recordOnly: boolean })[] = [];
|
|
696
|
+
for (const member of await localMembers(companionPath, type)) {
|
|
697
|
+
if (member.state !== "submitted" || !groups.has(member.group)) continue;
|
|
698
|
+
if (named.includes(member.name)) continue;
|
|
699
|
+
const relative = sourcePathOf(type, member.name);
|
|
700
|
+
// oxlint-disable-next-line no-await-in-loop -- a few members per group
|
|
701
|
+
if ((await editedSinceSubmit(git, companionPath, relative, submitted)) !== true) continue;
|
|
702
|
+
const content = submitted[relative]?.content;
|
|
703
|
+
// oxlint-disable-next-line no-await-in-loop -- a few members per group
|
|
704
|
+
const files = content === undefined ? null : await ownFiles(git, companionPath, relative);
|
|
705
|
+
const recordOnly =
|
|
706
|
+
files !== null &&
|
|
707
|
+
// oxlint-disable-next-line no-await-in-loop -- a few members per group
|
|
708
|
+
(await folderDigest(
|
|
709
|
+
path.join(companionPath, ...relative.split("/")),
|
|
710
|
+
files.filter((file) => file !== DELIVERY_FILE),
|
|
711
|
+
)) === content;
|
|
712
|
+
edited.push({ ...member, recordOnly });
|
|
713
|
+
}
|
|
714
|
+
return edited;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/** What {@link submitGroups} hands {@link pushGroup} for one group. */
|
|
718
|
+
interface PushPlan {
|
|
719
|
+
/** The local members it pushes. */
|
|
720
|
+
pushed: string[];
|
|
721
|
+
/** Those of {@link pushed} staged only when the pending branch lacks them. */
|
|
722
|
+
ifMissing: string[];
|
|
723
|
+
/** Members Git cannot judge: the group fails. */
|
|
724
|
+
unknown: string[];
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
async function planPush(
|
|
728
|
+
git: CompanionGit,
|
|
729
|
+
companionPath: string,
|
|
730
|
+
type: ArtifactType,
|
|
731
|
+
inGroup: readonly LocalMember[],
|
|
732
|
+
names: readonly string[],
|
|
733
|
+
submitted: Record<string, SubmittedFolder>,
|
|
734
|
+
): Promise<PushPlan> {
|
|
735
|
+
const plan: PushPlan = { pushed: [], ifMissing: [], unknown: [] };
|
|
736
|
+
for (const member of inGroup) {
|
|
737
|
+
const named = names.includes(member.name);
|
|
738
|
+
if (member.state === "dropped" && !named) continue;
|
|
739
|
+
const edited =
|
|
740
|
+
(named && member.state !== "submitted") ||
|
|
741
|
+
// oxlint-disable-next-line no-await-in-loop -- a few members per group
|
|
742
|
+
(await editedSinceSubmit(git, companionPath, sourcePathOf(type, member.name), submitted));
|
|
743
|
+
if (edited === null) plan.unknown.push(member.name);
|
|
744
|
+
else if (edited || named) plan.pushed.push(member.name);
|
|
745
|
+
if (edited === false && named) plan.ifMissing.push(member.name);
|
|
746
|
+
}
|
|
747
|
+
return plan;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* The members of `group` whose local folder submitting `names` puts on the pending branch, as
|
|
752
|
+
* {@link submitGroups} and {@link pushGroup} decide: pushed, and not kept as the pending branch
|
|
753
|
+
* has it (`onPending`), which a folder named unchanged is, and one whose content equals what this
|
|
754
|
+
* checkout last submitted. Null when Git cannot tell, as the push then fails.
|
|
755
|
+
*/
|
|
756
|
+
export async function localPushes(
|
|
757
|
+
companionPath: string,
|
|
758
|
+
group: string,
|
|
759
|
+
names: readonly string[],
|
|
760
|
+
onPending: ReadonlySet<string>,
|
|
761
|
+
deps: Pick<SubmitDeps, "git" | "artifactType" | "stateHome"> = {},
|
|
762
|
+
): Promise<string[] | null> {
|
|
763
|
+
const type = deps.artifactType ?? defaultArtifactType();
|
|
764
|
+
const git = (deps.git ?? defaultGit)(companionPath);
|
|
765
|
+
const inGroup = (await localMembers(companionPath, type)).filter(
|
|
766
|
+
(member) => member.group === group,
|
|
767
|
+
);
|
|
768
|
+
const submitted = readSubmittedFolders(companionPath, deps.stateHome);
|
|
769
|
+
const plan = await planPush(git, companionPath, type, inGroup, names, submitted);
|
|
770
|
+
if (plan.unknown.length > 0) return null;
|
|
771
|
+
const carried: string[] = [];
|
|
772
|
+
for (const name of plan.pushed) {
|
|
773
|
+
const relative = sourcePathOf(type, name);
|
|
774
|
+
const mine = submitted[relative]?.content;
|
|
775
|
+
if (onPending.has(name)) {
|
|
776
|
+
if (plan.ifMissing.includes(name)) continue;
|
|
777
|
+
if (mine !== undefined) {
|
|
778
|
+
// oxlint-disable-next-line no-await-in-loop -- a few members per group
|
|
779
|
+
const files = await ownFiles(git, companionPath, relative);
|
|
780
|
+
if (files === null) return null;
|
|
781
|
+
const own = files.filter((file) => file !== DELIVERY_FILE);
|
|
782
|
+
// oxlint-disable-next-line no-await-in-loop -- same member
|
|
783
|
+
if ((await folderDigest(path.join(companionPath, ...relative.split("/")), own)) === mine) {
|
|
784
|
+
continue;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
carried.push(name);
|
|
789
|
+
}
|
|
790
|
+
return carried;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
export type GroupStatus = "pushed" | "unchanged" | "waiting" | "failed";
|
|
794
|
+
|
|
795
|
+
export interface GroupSubmission {
|
|
796
|
+
group: string;
|
|
797
|
+
status: GroupStatus;
|
|
798
|
+
/** Local members of the group still `active` and not submitted with it, which it waits for. */
|
|
799
|
+
waitingFor: string[];
|
|
800
|
+
/** Set unless the group waits. */
|
|
801
|
+
push?: GroupPush;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* Submits the Delivery Groups of `names`, each whole and in one commit that sets its changes
|
|
806
|
+
* `submitted`. A group waits, pushing and changing nothing, while a local member that is not
|
|
807
|
+
* named is still `active`: a Workset lands together or not at all. A dropped member comes back
|
|
808
|
+
* only when named. Members already submitted, named or not, are pushed again only when edited
|
|
809
|
+
* since this checkout submitted or took them, so a teammate's later edit on the pending branch
|
|
810
|
+
* is never overwritten by a stale local copy; a named one the pending branch no longer holds is
|
|
811
|
+
* pushed again as it is.
|
|
812
|
+
*/
|
|
813
|
+
export async function submitGroups(
|
|
814
|
+
companionPath: string,
|
|
815
|
+
names: readonly string[],
|
|
816
|
+
options: SubmitDeps = {},
|
|
817
|
+
): Promise<GroupSubmission[]> {
|
|
818
|
+
const type = options.artifactType ?? defaultArtifactType();
|
|
819
|
+
const members = await localMembers(companionPath, type);
|
|
820
|
+
const local = (options.git ?? defaultGit)(companionPath);
|
|
821
|
+
const groups = [
|
|
822
|
+
...new Set(
|
|
823
|
+
names.flatMap((name) => members.find((member) => member.name === name)?.group ?? []),
|
|
824
|
+
),
|
|
825
|
+
];
|
|
826
|
+
const submissions: GroupSubmission[] = [];
|
|
827
|
+
for (const group of groups) {
|
|
828
|
+
const inGroup = members.filter((member) => member.group === group);
|
|
829
|
+
const waitingFor = waitingMembers(inGroup, group, names);
|
|
830
|
+
if (waitingFor.length > 0) {
|
|
831
|
+
submissions.push({ group, status: "waiting", waitingFor });
|
|
832
|
+
continue;
|
|
833
|
+
}
|
|
834
|
+
const submitted = readSubmittedFolders(companionPath, options.stateHome);
|
|
835
|
+
// oxlint-disable-next-line no-await-in-loop -- one group at a time
|
|
836
|
+
const { pushed, ifMissing, unknown } = await planPush(
|
|
837
|
+
local,
|
|
838
|
+
companionPath,
|
|
839
|
+
type,
|
|
840
|
+
inGroup,
|
|
841
|
+
names,
|
|
842
|
+
submitted,
|
|
843
|
+
);
|
|
844
|
+
if (unknown.length > 0) {
|
|
845
|
+
const detail = `Git could not tell whether ${unknown.join(", ")} changed locally; nothing was pushed.`;
|
|
846
|
+
const push: GroupPush = { ...failed("failed", detail, null), group, changes: [] };
|
|
847
|
+
submissions.push({ group, status: "failed", waitingFor, push });
|
|
848
|
+
continue;
|
|
849
|
+
}
|
|
850
|
+
// oxlint-disable-next-line no-await-in-loop -- one push per group, in order
|
|
851
|
+
const push = await pushGroup(companionPath, group, pushed, options, {
|
|
852
|
+
ifMissing,
|
|
853
|
+
acknowledge: names,
|
|
854
|
+
});
|
|
855
|
+
submissions.push({ group, status: push.status, waitingFor, push });
|
|
856
|
+
}
|
|
857
|
+
return submissions;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
export interface DropResult {
|
|
861
|
+
change: string;
|
|
862
|
+
status: "dropped" | "refused";
|
|
863
|
+
/** The change's Delivery Group, once known. */
|
|
864
|
+
group: string | null;
|
|
865
|
+
/** Whether this run removed the folder from the pending branch. */
|
|
866
|
+
pushed: boolean;
|
|
867
|
+
commit: string | null;
|
|
868
|
+
reason?: PendingFailure | "missing";
|
|
869
|
+
message: string;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* Drops change `name`: sets `state: dropped` in its local folder, when this checkout has one,
|
|
874
|
+
* and removes its folder from the pending branch by a commit pushed without force, from any
|
|
875
|
+
* machine. The folder stays in the pending branch's history.
|
|
876
|
+
*/
|
|
877
|
+
export async function dropSubmitted(
|
|
878
|
+
companionPath: string,
|
|
879
|
+
name: string,
|
|
880
|
+
deps: SubmitDeps = {},
|
|
881
|
+
): Promise<DropResult> {
|
|
882
|
+
const type = deps.artifactType ?? defaultArtifactType();
|
|
883
|
+
const refused = (message: string, reason: DropResult["reason"]): DropResult => ({
|
|
884
|
+
change: name,
|
|
885
|
+
status: "refused",
|
|
886
|
+
group: null,
|
|
887
|
+
pushed: false,
|
|
888
|
+
commit: null,
|
|
889
|
+
reason,
|
|
890
|
+
message,
|
|
891
|
+
});
|
|
892
|
+
if (!isChangeName(name)) return refused(`mate: "${name}" is no change name.`, "missing");
|
|
893
|
+
const localDir = sourceDir(companionPath, type, name);
|
|
894
|
+
const local = await pathIsDirectory(localDir);
|
|
895
|
+
let group = local ? (await groupOfChange(companionPath, name, type)).group : null;
|
|
896
|
+
|
|
897
|
+
let found = false;
|
|
898
|
+
const removed = await commitStaged(
|
|
899
|
+
companionPath,
|
|
900
|
+
`chore(${type.name}): drop ${name}`,
|
|
901
|
+
async (dir) => {
|
|
902
|
+
const target = within(dir, sourcePathOf(type, name));
|
|
903
|
+
found = await pathIsDirectory(target);
|
|
904
|
+
if (!found) return [];
|
|
905
|
+
if (!group) {
|
|
906
|
+
const record = await readDeliveryRecord(target).catch(() => null);
|
|
907
|
+
group = deliveryGroupFor(name, record, await scopedRepositories(target)).group;
|
|
908
|
+
}
|
|
909
|
+
await fs.rm(target, { recursive: true, force: true });
|
|
910
|
+
return [sourcePathOf(type, name)];
|
|
911
|
+
},
|
|
912
|
+
deps,
|
|
913
|
+
);
|
|
914
|
+
// Without an upstream there is no pending branch to remove it from: dropped here alone.
|
|
915
|
+
if (removed.status === "failed" && removed.reason === "no-remote" && local) {
|
|
916
|
+
await writeSubmissionState(localDir, name, "dropped");
|
|
917
|
+
updateSubmittedFolders(companionPath, {}, [sourcePathOf(type, name)], deps.stateHome);
|
|
918
|
+
return {
|
|
919
|
+
change: name,
|
|
920
|
+
status: "dropped",
|
|
921
|
+
group,
|
|
922
|
+
pushed: false,
|
|
923
|
+
commit: null,
|
|
924
|
+
message: `Dropped ${name} locally; the companion has no upstream.`,
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
if (removed.status === "failed") {
|
|
928
|
+
return {
|
|
929
|
+
...refused(
|
|
930
|
+
`mate: removing ${name} from the pending branch failed: ${removed.detail ?? removed.reason}.`,
|
|
931
|
+
removed.reason,
|
|
932
|
+
),
|
|
933
|
+
group,
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
if (!found && !local) return refused(`mate: ${name} is neither local nor submitted.`, "missing");
|
|
937
|
+
// Only after the pending branch let go of it, so a failed removal leaves the state as it was.
|
|
938
|
+
if (local) await writeSubmissionState(localDir, name, "dropped");
|
|
939
|
+
updateSubmittedFolders(companionPath, {}, [sourcePathOf(type, name)], deps.stateHome);
|
|
940
|
+
const place = removed.pendingBranch ?? "the pending branch";
|
|
941
|
+
return {
|
|
942
|
+
change: name,
|
|
943
|
+
status: "dropped",
|
|
944
|
+
group,
|
|
945
|
+
pushed: removed.status === "pushed",
|
|
946
|
+
commit: removed.commit,
|
|
947
|
+
message: found
|
|
948
|
+
? `Dropped ${name}: removed it from ${place}${local ? " and set its local state to dropped" : ""}.`
|
|
949
|
+
: `Dropped ${name} locally; ${place} does not hold it.`,
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
export interface TakeResult {
|
|
954
|
+
change: string;
|
|
955
|
+
status: "taken" | "refused";
|
|
956
|
+
/** The folder in the checkout, relative to the companion. */
|
|
957
|
+
path: string | null;
|
|
958
|
+
reason?: "no-remote" | "fetch-failed" | "missing" | "exists" | "failed";
|
|
959
|
+
message: string;
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* Takes submitted change `name` into the checkout: writes its folder as the fetched pending
|
|
964
|
+
* branch has it, untracked, and records it as submitted from this checkout, so an edit is
|
|
965
|
+
* submitted again like one of the checkout's own and the folder gives way once its archive
|
|
966
|
+
* arrives. Refused while the checkout holds a folder of that name; nothing is pushed.
|
|
967
|
+
*/
|
|
968
|
+
export async function takeSubmitted(
|
|
969
|
+
companionPath: string,
|
|
970
|
+
name: string,
|
|
971
|
+
deps: SubmitDeps = {},
|
|
972
|
+
): Promise<TakeResult> {
|
|
973
|
+
const type = deps.artifactType ?? defaultArtifactType();
|
|
974
|
+
const refused = (reason: TakeResult["reason"], message: string): TakeResult => ({
|
|
975
|
+
change: name,
|
|
976
|
+
status: "refused",
|
|
977
|
+
path: null,
|
|
978
|
+
reason,
|
|
979
|
+
message,
|
|
980
|
+
});
|
|
981
|
+
if (!isChangeName(name)) return refused("missing", `mate: "${name}" is no change name.`);
|
|
982
|
+
const relative = sourcePathOf(type, name);
|
|
983
|
+
const dir = sourceDir(companionPath, type, name);
|
|
984
|
+
if (await pathIsDirectory(dir)) {
|
|
985
|
+
return refused("exists", `mate: ${relative} is in this checkout already; nothing was taken.`);
|
|
986
|
+
}
|
|
987
|
+
const git = (deps.git ?? defaultGit)(companionPath);
|
|
988
|
+
const remote = await stagingRemote(git);
|
|
989
|
+
if (!remote) return refused("no-remote", "mate: the companion has no upstream.");
|
|
990
|
+
const fetched = await fetchPendingBranches(git, remote);
|
|
991
|
+
if ("error" in fetched) return refused("fetch-failed", `mate: ${fetched.error}`);
|
|
992
|
+
// One commit for every read: a ref could move between the check and the write.
|
|
993
|
+
const tip = (
|
|
994
|
+
await git.run(["rev-parse", "--verify", "-q", `${pendingRef(remote)}^{commit}`])
|
|
995
|
+
).stdout.trim();
|
|
996
|
+
const record = isCommitId(tip)
|
|
997
|
+
? await git.run(["show", "--end-of-options", `${tip}:${relative}/${DELIVERY_FILE}`])
|
|
998
|
+
: null;
|
|
999
|
+
if (record?.status !== 0 || !/^state:\s*submitted\s*$/m.test(record.stdout)) {
|
|
1000
|
+
return refused("missing", `mate: ${name} is not submitted on ${pendingPlace(remote)}.`);
|
|
1001
|
+
}
|
|
1002
|
+
// Anyone may push the inbox: a link there must not reach the checkout, where it is followed.
|
|
1003
|
+
const linked = await linkedContentPaths(git, tip, [relative]);
|
|
1004
|
+
if (linked === null || linked.length > 0) {
|
|
1005
|
+
return refused(
|
|
1006
|
+
"failed",
|
|
1007
|
+
linked === null
|
|
1008
|
+
? `mate: reading ${relative} on ${pendingPlace(remote)} failed; nothing was taken.`
|
|
1009
|
+
: `mate: ${pendingPlace(remote)} holds a symbolic link or submodule at ${linked.join(", ")}; Mate does not take it.`,
|
|
1010
|
+
);
|
|
1011
|
+
}
|
|
1012
|
+
// The work tree only: the index stays as it is, so the folder is untracked like a submitted one.
|
|
1013
|
+
const written = await git.run([
|
|
1014
|
+
...LITERAL_PATHSPECS,
|
|
1015
|
+
"restore",
|
|
1016
|
+
`--source=${tip}`,
|
|
1017
|
+
"--worktree",
|
|
1018
|
+
"--",
|
|
1019
|
+
`${relative}/`,
|
|
1020
|
+
]);
|
|
1021
|
+
const files = written.status === 0 ? await ownFiles(git, companionPath, relative) : null;
|
|
1022
|
+
if (!files || files.length === 0) {
|
|
1023
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
1024
|
+
return refused(
|
|
1025
|
+
"failed",
|
|
1026
|
+
`mate: writing ${relative} failed; nothing was taken. ${describeGitFailure(written)}`,
|
|
1027
|
+
);
|
|
1028
|
+
}
|
|
1029
|
+
updateSubmittedFolders(
|
|
1030
|
+
companionPath,
|
|
1031
|
+
{
|
|
1032
|
+
[relative]: {
|
|
1033
|
+
digest: await folderDigest(dir, files),
|
|
1034
|
+
content: await folderDigest(
|
|
1035
|
+
dir,
|
|
1036
|
+
files.filter((file) => file !== DELIVERY_FILE),
|
|
1037
|
+
),
|
|
1038
|
+
submittedAt: (deps.now?.() ?? new Date()).toISOString(),
|
|
1039
|
+
},
|
|
1040
|
+
},
|
|
1041
|
+
[],
|
|
1042
|
+
deps.stateHome,
|
|
1043
|
+
);
|
|
1044
|
+
return {
|
|
1045
|
+
change: name,
|
|
1046
|
+
status: "taken",
|
|
1047
|
+
path: relative,
|
|
1048
|
+
message: `Took ${name} into ${relative} as ${pendingPlace(remote)} has it. Edit it, then submit it again with \`mate artifact submit ${name}\`.`,
|
|
1049
|
+
};
|
|
1050
|
+
}
|