@uniqbit/mate-core 0.18.5 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/claude-capability-plugins/companion-mentions/.claude-plugin/marketplace.json +14 -0
- package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +8 -0
- package/claude-capability-plugins/companion-mentions/hooks/companion.ts +457 -0
- package/claude-capability-plugins/companion-mentions/hooks/hooks.json +1 -0
- package/claude-capability-plugins/companion-mentions/hooks/register.ts +403 -0
- package/claude-plugin/hooks/companion-instructions.mjs +9 -0
- package/claude-plugin/hooks/hooks.json +50 -2
- package/claude-plugin/hooks/rtk-worktree-git.mjs +58 -0
- package/claude-plugin/hooks/session-attention.mjs +10 -0
- package/claude-plugin/hooks/session-end.mjs +9 -0
- package/claude-plugin/hooks/session-guidance.mjs +1 -1
- package/claude-plugin/hooks/tokensave-route.mjs +52 -0
- package/opencode-plugin/src/server.ts +25 -3
- package/opencode-plugin/src/tui.tsx +3 -1
- package/opencode-plugin/tui.tsx +4 -1
- package/package.json +53 -15
- package/src/brand/art.generated.ts +69 -0
- package/src/brand/index.ts +12 -0
- package/src/brand/palette.ts +19 -0
- package/src/brand/svg.generated.ts +8 -0
- package/src/brand/terminal.ts +88 -0
- package/src/brand/types.ts +33 -0
- package/src/cli/commands/artifact/apply-context.ts +275 -0
- package/src/cli/commands/artifact/artifact.ts +12 -0
- package/src/cli/commands/artifact/delivery/archive.ts +125 -0
- package/src/cli/commands/artifact/delivery/branch-flags.ts +55 -0
- package/src/cli/commands/artifact/delivery/environment.ts +147 -0
- package/src/cli/commands/artifact/delivery/link.ts +210 -0
- package/src/cli/commands/artifact/delivery/output.ts +104 -0
- package/src/cli/commands/artifact/finish/command.ts +83 -8
- package/src/cli/commands/artifact/finish/engine.ts +91 -14
- package/src/cli/commands/artifact/finish/finisher.ts +10 -0
- package/src/cli/commands/artifact/finish/git.ts +132 -19
- package/src/cli/commands/artifact/finish/openspec.ts +180 -138
- package/src/cli/commands/artifact/finish/secret-scan.ts +43 -0
- package/src/cli/commands/artifact/finish/worktree-cleanup.ts +92 -0
- package/src/cli/commands/artifact/pending/command.ts +31 -3
- package/src/cli/commands/artifact/pending/discovery.ts +21 -57
- package/src/cli/commands/cap/graphify.ts +52 -3
- package/src/cli/commands/cap/index-cmd.ts +71 -15
- package/src/cli/commands/cap/openspec.ts +13 -25
- package/src/cli/commands/cap/tokensave.ts +7 -5
- package/src/cli/commands/companion/companion.ts +1 -1
- package/src/cli/commands/companion/link.ts +50 -5
- package/src/cli/commands/companion/open.ts +101 -51
- package/src/cli/commands/companion/sync.ts +10 -0
- package/src/cli/commands/companion/tui.ts +17 -7
- package/src/cli/commands/companion/update.ts +144 -66
- package/src/cli/commands/doctor.ts +317 -7
- package/src/cli/commands/factory/factory.ts +311 -0
- package/src/cli/commands/install.ts +180 -45
- package/src/cli/commands/launch/claude.ts +2 -0
- package/src/cli/commands/launch/shared.ts +48 -16
- package/src/cli/commands/plugin/install.ts +36 -15
- package/src/cli/commands/plugin/plugin.ts +3 -2
- package/src/cli/commands/report/adapter.ts +11 -2
- package/src/cli/commands/report/contract.ts +21 -0
- package/src/cli/commands/report/highlight.ts +34 -4
- package/src/cli/commands/report/index.ts +186 -171
- package/src/cli/commands/report/markdown.ts +105 -0
- package/src/cli/commands/report/palette.ts +118 -0
- package/src/cli/commands/report/renderer.ts +456 -153
- package/src/cli/commands/report/types.ts +16 -0
- package/src/cli/commands/session/context.ts +102 -0
- package/src/cli/commands/session/prepare.ts +32 -4
- package/src/cli/commands/session/registry.ts +90 -0
- package/src/cli/commands/setup.ts +50 -24
- package/src/cli/commands/shared/companion-selection.ts +3 -1
- package/src/cli/commands/studio/access.ts +6 -14
- package/src/cli/commands/studio/areas.ts +112 -33
- package/src/cli/commands/studio/companion-add.ts +87 -0
- package/src/cli/commands/studio/companion-removal.ts +86 -0
- package/src/cli/commands/studio/factory-credential.ts +35 -0
- package/src/cli/commands/studio/factory-git-tokens.ts +40 -0
- package/src/cli/commands/studio/factory-relay.ts +18 -0
- package/src/cli/commands/studio/graph-model.ts +61 -0
- package/src/cli/commands/studio/graph.ts +336 -0
- package/src/cli/commands/studio/index.ts +33 -6
- package/src/cli/commands/studio/mate-inventory.ts +1 -1
- package/src/cli/commands/studio/openspec-cli.ts +10 -58
- package/src/cli/commands/studio/payload.ts +292 -20
- package/src/cli/commands/studio/repository-add.ts +116 -0
- package/src/cli/commands/studio/routes.ts +47 -6
- package/src/cli/commands/studio/selection.ts +170 -17
- package/src/cli/commands/studio/server.ts +552 -327
- package/src/cli/commands/studio/services.ts +120 -0
- package/src/cli/commands/studio/skill-files.ts +133 -0
- package/src/cli/commands/studio/studio-app.ts +67 -0
- package/src/cli/commands/studio/terminal-assets.ts +21 -33
- package/src/cli/commands/studio/terminal.ts +128 -16
- package/src/cli/commands/studio/vault.ts +218 -44
- package/src/cli/commands/studio/views/model.ts +13 -0
- package/src/cli/commands/studio/views/vault/markdown-tree.ts +599 -0
- package/src/cli/commands/studio/views/vault/view.ts +185 -0
- package/src/cli/commands/studio/workset-session.ts +164 -0
- package/src/cli/commands/unwrap.ts +19 -0
- package/src/cli/commands/update.ts +55 -9
- package/src/cli/commands/vscode/release-vsix.json +4 -0
- package/src/cli/commands/vscode/setup.ts +213 -0
- package/src/cli/commands/vscode/vsix.ts +114 -0
- package/src/cli/commands/working/cleanup.ts +83 -18
- package/src/cli/commands/working/link.ts +76 -0
- package/src/cli/commands/working/working.ts +10 -0
- package/src/cli/commands/working/worktree.ts +547 -0
- package/src/cli/commands/wrap.ts +38 -20
- package/src/cli/companion-link-wizard.tsx +2 -0
- package/src/cli/companion-selector.tsx +2 -0
- package/src/cli/confirm.ts +2 -0
- package/src/cli/install-plan.tsx +127 -160
- package/src/cli/launch-selector.tsx +2 -0
- package/src/cli/main.ts +48 -5
- package/src/cli/parse-flags.ts +32 -6
- package/src/cli/repo-list-table.tsx +2 -0
- package/src/cli/setup-selector.tsx +86 -151
- package/src/cli/usage.ts +20 -1
- package/src/create-mate.ts +5 -4
- package/src/hooks/companion-instructions.ts +198 -0
- package/src/hooks/hook-io.ts +78 -0
- package/src/hooks/rtk-worktree-git.ts +48 -0
- package/src/hooks/session-banner.ts +24 -30
- package/src/hooks/session-end.ts +10 -0
- package/src/hooks/session-guidance.ts +18 -22
- package/src/hooks/session-prepare.ts +137 -34
- package/src/hooks/session-register.ts +199 -0
- package/src/hooks/tokensave-route.ts +30 -0
- package/src/hooks/validate-artifact-path.ts +121 -25
- package/src/index.ts +4 -0
- package/src/lib/apply-context/fingerprint.ts +174 -0
- package/src/lib/apply-context/protocol.ts +193 -0
- package/src/lib/change-layout.ts +154 -0
- package/src/lib/components/confirm-prompt.tsx +21 -9
- package/src/lib/components/select-menu.tsx +10 -3
- package/src/lib/components/spinner.tsx +4 -2
- package/src/lib/components/startup-progress.tsx +227 -41
- package/src/lib/components/text-input-display.tsx +2 -0
- package/src/lib/components/wizard-footer.tsx +2 -0
- package/src/lib/components/wizard-header.tsx +16 -12
- package/src/lib/context-mode-package.ts +24 -11
- package/src/lib/delivery/archive-change.ts +165 -0
- package/src/lib/delivery/branch-template.ts +122 -0
- package/src/lib/delivery/branches.ts +152 -0
- package/src/lib/delivery/checkout.ts +102 -0
- package/src/lib/delivery/environment.ts +37 -0
- package/src/lib/delivery/forge.ts +279 -0
- package/src/lib/delivery/merge-git.ts +273 -0
- package/src/lib/delivery/overlap.ts +209 -0
- package/src/lib/delivery/record-delivery.ts +392 -0
- package/src/lib/delivery/record.ts +417 -0
- package/src/lib/delivery/refresh.ts +288 -0
- package/src/lib/delivery/repository-access.ts +141 -0
- package/src/lib/delivery/resolve-branch.ts +430 -0
- package/src/lib/delivery/stages.ts +111 -0
- package/src/lib/delivery/token.ts +24 -0
- package/src/lib/factory/attach-client.ts +123 -0
- package/src/lib/factory/attach.ts +178 -0
- package/src/lib/factory/broker.ts +187 -0
- package/src/lib/factory/bun-commands.ts +39 -0
- package/src/lib/factory/client.ts +113 -0
- package/src/lib/factory/clone-url.ts +39 -0
- package/src/lib/factory/command.ts +77 -0
- package/src/lib/factory/credential-store.ts +153 -0
- package/src/lib/factory/frames.ts +77 -0
- package/src/lib/factory/git-auth.ts +61 -0
- package/src/lib/factory/git-credential-store.ts +181 -0
- package/src/lib/factory/ids.ts +68 -0
- package/src/lib/factory/keyed-serial.ts +27 -0
- package/src/lib/factory/outcomes/actions.ts +130 -0
- package/src/lib/factory/outcomes/index.ts +457 -0
- package/src/lib/factory/outcomes/lifecycle.ts +212 -0
- package/src/lib/factory/outcomes/runs.ts +81 -0
- package/src/lib/factory/outcomes/sessions.ts +60 -0
- package/src/lib/factory/prepare.ts +55 -0
- package/src/lib/factory/pty.ts +103 -0
- package/src/lib/factory/runner/companion-context.ts +178 -0
- package/src/lib/factory/runner/control.ts +92 -0
- package/src/lib/factory/runner/harness-agent.ts +250 -0
- package/src/lib/factory/runner/live.ts +159 -0
- package/src/lib/factory/runner/questions.ts +22 -0
- package/src/lib/factory/runner/rank.ts +26 -0
- package/src/lib/factory/runner/run-policy.ts +12 -0
- package/src/lib/factory/runner/run.ts +199 -0
- package/src/lib/factory/runner/scheduler.ts +498 -0
- package/src/lib/factory/runner/state.ts +233 -0
- package/src/lib/factory/runner/workflow.ts +546 -0
- package/src/lib/factory/runtime.ts +1081 -0
- package/src/lib/factory/sandbox.ts +292 -0
- package/src/lib/factory/worktree-branch.ts +17 -0
- package/src/lib/frontmatter.ts +18 -0
- package/src/lib/install.ts +66 -14
- package/src/lib/live-progress.ts +36 -0
- package/src/lib/member-choices.ts +67 -0
- package/src/lib/opencode-plugin-package.ts +5 -5
- package/src/lib/opencode-server.ts +238 -0
- package/src/lib/openspec-cli.ts +116 -0
- package/src/lib/openspec-scopes.ts +86 -0
- package/src/lib/orchestrator/adapters/base.ts +55 -22
- package/src/lib/orchestrator/adapters/claude-args.ts +50 -0
- package/src/lib/orchestrator/adapters/claude.ts +201 -43
- package/src/lib/orchestrator/adapters/opencode.ts +55 -2
- package/src/lib/orchestrator/checkout-adoption.ts +125 -0
- package/src/lib/orchestrator/companion-hub.ts +6 -1
- package/src/lib/orchestrator/companion-registry-store.ts +6 -2
- package/src/lib/orchestrator/config-store.ts +3 -2
- package/src/lib/orchestrator/editor.ts +32 -26
- package/src/lib/orchestrator/engine-floor.ts +48 -0
- package/src/lib/orchestrator/framework-context.ts +26 -14
- package/src/lib/orchestrator/global-config-store.ts +11 -0
- package/src/lib/orchestrator/launcher.ts +49 -3
- package/src/lib/orchestrator/openspec-store.ts +14 -54
- package/src/lib/orchestrator/projection-claude-commands.ts +36 -0
- package/src/lib/orchestrator/projection-claude-entry.ts +42 -21
- package/src/lib/orchestrator/projection-claude-links.ts +230 -0
- package/src/lib/orchestrator/projection-claude-skills.ts +39 -131
- package/src/lib/orchestrator/projection-companion-link.ts +12 -1
- package/src/lib/orchestrator/projection-entries.ts +121 -51
- package/src/lib/orchestrator/projection-opencode-copies.ts +93 -32
- package/src/lib/orchestrator/projection-openspec-store.ts +54 -9
- package/src/lib/orchestrator/projection-runtime-documents.ts +81 -49
- package/src/lib/orchestrator/projection-types.ts +63 -1
- package/src/lib/orchestrator/refresh-working-claude-links.ts +89 -0
- package/src/lib/orchestrator/registry-checkouts.ts +177 -0
- package/src/lib/orchestrator/repository-link.ts +216 -57
- package/src/lib/orchestrator/serving-claude-wrap.ts +43 -0
- package/src/lib/orchestrator/session-context-link.ts +73 -0
- package/src/lib/orchestrator/session-prepare.ts +87 -12
- package/src/lib/orchestrator/setup-compatibilities.ts +56 -70
- package/src/lib/orchestrator/types.ts +16 -2
- package/src/lib/orchestrator/umbrella-checkouts.ts +102 -0
- package/src/lib/orchestrator/working-repo-projection.ts +73 -10
- package/src/lib/orchestrator/workspace-document.ts +105 -0
- package/src/lib/orchestrator/workspace-inventory.ts +5 -1
- package/src/lib/orchestrator/wrap-pass.ts +23 -1
- package/src/lib/package-paths.ts +37 -0
- package/src/lib/public-npm.ts +105 -43
- package/src/lib/runtime-directory-refresh.ts +17 -1
- package/src/lib/session-attribution.ts +52 -0
- package/src/lib/session-state.ts +355 -0
- package/src/lib/session-stop.ts +64 -0
- package/src/lib/update-checker.ts +7 -1
- package/src/lib/usage/aggregate.ts +202 -0
- package/src/lib/usage/cache.ts +87 -0
- package/src/lib/usage/claude-pricing.ts +71 -0
- package/src/lib/usage/claude.ts +189 -0
- package/src/lib/usage/collect.ts +56 -0
- package/src/lib/usage/opencode.ts +188 -0
- package/src/lib/usage/records.ts +80 -0
- package/src/lib/usage/rtk-database.ts +72 -0
- package/src/lib/usage/savings.ts +209 -0
- package/src/lib/usage/scope.ts +182 -0
- package/src/lib/usage/source.ts +102 -0
- package/src/lib/usage/types.ts +143 -0
- package/src/lib/usage/window.ts +37 -0
- package/src/lib/workset/factory-local.ts +157 -0
- package/src/lib/workset/record.ts +547 -0
- package/src/lib/workset/repositories.ts +148 -0
- package/src/lib/workset/stage.ts +148 -0
- package/src/lib/workset/stages.ts +113 -0
- package/src/lib/workset/worktree-include.ts +161 -0
- package/src/lib/workset/worktree-index.ts +120 -0
- package/src/lib/workset/worktree.ts +1388 -0
- package/src/opencode/background-server.ts +145 -0
- package/src/opencode/companion-hooks.ts +151 -9
- package/src/opencode/companion-policy.ts +54 -22
- package/src/opencode/enter-worktree.ts +320 -0
- package/src/opencode/projected-guidance.ts +6 -2
- package/src/opencode/session-prepare.ts +2 -1
- package/src/opencode/session-register.ts +176 -0
- package/src/opencode/tui.tsx +24 -27
- package/src/plugins.ts +1 -0
- package/src/runtime/artifact-refusal.ts +63 -0
- package/src/runtime/claude-bg-isolation.ts +138 -0
- package/src/runtime/claude-delivery-plan.ts +121 -11
- package/src/runtime/commit-attribution-guard.ts +181 -0
- package/src/runtime/companion-git.ts +62 -12
- package/src/runtime/companion-guidance.ts +37 -12
- package/src/runtime/companion-instructions.ts +340 -0
- package/src/runtime/companion-lock.ts +30 -7
- package/src/runtime/current-branch.ts +24 -0
- package/src/runtime/entered-worktree.ts +24 -0
- package/src/runtime/env.ts +59 -8
- package/src/runtime/error-message.ts +4 -0
- package/src/runtime/git-layout.ts +366 -0
- package/src/runtime/git-tracked.ts +60 -0
- package/src/runtime/index.ts +29 -0
- package/src/runtime/launch-env-guard.ts +65 -0
- package/src/runtime/managed-block.ts +117 -0
- package/src/runtime/markdown-scan.ts +266 -0
- package/src/runtime/opencode-server-record.ts +136 -0
- package/src/runtime/physical-path.ts +111 -0
- package/src/runtime/policy.ts +50 -2
- package/src/runtime/projected-flag.ts +7 -0
- package/src/runtime/projected-guidance.ts +1 -0
- package/src/runtime/projection.ts +40 -6
- package/src/runtime/repo-destination.ts +72 -0
- package/src/runtime/repo-local.ts +29 -2
- package/src/runtime/rtk-git-guard.ts +66 -0
- package/src/runtime/runtime-directory.ts +5 -0
- package/src/runtime/runtime-document-manifest.ts +290 -29
- package/src/runtime/runtime-document-manifest.typecheck.ts +10 -0
- package/src/runtime/secret-guard.ts +169 -0
- package/src/runtime/secret-patterns.ts +397 -0
- package/src/runtime/secret-policy-weakening.ts +122 -0
- package/src/runtime/secret-scan.ts +90 -0
- package/src/runtime/serving-claude-wrap.ts +41 -0
- package/src/runtime/session-context.ts +99 -0
- package/src/runtime/session-kind.ts +13 -0
- package/src/runtime/session-registry.ts +434 -0
- package/src/runtime/shell-heredoc.ts +81 -0
- package/src/runtime/tokensave-route.ts +157 -0
- package/src/runtime/umbrella-folder.ts +56 -0
- package/src/runtime/wrap-state.ts +80 -15
- package/src/runtime/write-atomic.ts +64 -0
- package/src/studio.ts +163 -0
- package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +14 -10
- package/src/templates/capabilities/openspec-cap/mate-minimal/templates/spec.md +3 -5
- package/src/templates/capabilities/openspec-cap/mate-v1/schema.yaml +18 -102
- package/src/templates/capabilities/openspec-cap/mate-v1/templates/spec.md +3 -5
- package/src/templates/capabilities/openspec-cap/openspec-conventions.yaml +20 -14
- package/src/templates/mate-skills/THIRD-PARTY-NOTICES.md +40 -0
- package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +217 -0
- package/src/templates/mate-skills/agents/mate-apply-change/references/mate-compact-apply.md +47 -0
- package/src/templates/mate-skills/agents/mate-apply-change/references/openspec-apply-change.md +200 -0
- package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +81 -0
- package/src/templates/mate-skills/agents/{mate-openspec-backfill → mate-backfill-spec}/SKILL.md +11 -4
- package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +110 -0
- package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +70 -0
- package/src/templates/mate-skills/agents/mate-explore-change/references/openspec-explore.md +350 -0
- package/src/templates/mate-skills/agents/mate-grill-me/SKILL.md +11 -4
- package/src/templates/mate-skills/agents/mate-grill-with-docs/SKILL.md +2 -2
- package/src/templates/mate-skills/agents/mate-interview-me/SKILL.md +12 -5
- package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +106 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/mate-revise.md +45 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-propose.md +169 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-update-change.md +103 -0
- package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +271 -0
- package/src/templates/mate-skills/{claude/mate-artifact-publish → agents/mate-publish-artifact}/references/openspec.md +8 -5
- package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +105 -20
- package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +91 -68
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +217 -0
- package/src/templates/mate-skills/claude/mate-apply-change/references/mate-compact-apply.md +47 -0
- package/src/templates/mate-skills/claude/mate-apply-change/references/openspec-apply-change.md +200 -0
- package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +81 -0
- package/src/templates/mate-skills/claude/{mate-openspec-backfill → mate-backfill-spec}/SKILL.md +11 -4
- package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +110 -0
- package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +70 -0
- package/src/templates/mate-skills/claude/mate-explore-change/references/openspec-explore.md +350 -0
- package/src/templates/mate-skills/claude/mate-grill-me/SKILL.md +11 -4
- package/src/templates/mate-skills/claude/mate-grill-with-docs/SKILL.md +2 -2
- package/src/templates/mate-skills/claude/mate-interview-me/SKILL.md +12 -5
- package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +106 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/mate-revise.md +45 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-propose.md +169 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-update-change.md +103 -0
- package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +271 -0
- package/src/templates/mate-skills/{agents/mate-artifact-publish → claude/mate-publish-artifact}/references/openspec.md +8 -5
- package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +105 -20
- package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +91 -68
- package/src/templates/mate-skills/openspec-references.ts +142 -0
- package/src/templates/root/TEMPLATE_AGENTS.md +2 -2
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +4581 -397
- package/src/tools/setup/capabilities/companion-mentions.ts +27 -0
- package/src/tools/setup/capabilities/context-mode.ts +56 -7
- package/src/tools/setup/capabilities/graphify-gate.ts +31 -0
- package/src/tools/setup/capabilities/graphify-secrets.ts +243 -0
- package/src/tools/setup/capabilities/graphify.ts +46 -7
- package/src/tools/setup/capabilities/openspec.ts +163 -272
- package/src/tools/setup/capabilities/react-doctor.ts +8 -1
- package/src/tools/setup/capabilities/rtk.ts +97 -1
- package/src/tools/setup/capabilities/tokensave.ts +113 -71
- package/src/tools/setup/context-services.ts +9 -17
- package/src/tools/setup/dynamic-plugins/audiences.ts +65 -21
- package/src/tools/setup/dynamic-plugins/frozen.ts +32 -13
- package/src/tools/setup/dynamic-plugins/hydrate.ts +8 -7
- package/src/tools/setup/dynamic-plugins/install.ts +46 -48
- package/src/tools/setup/dynamic-plugins/loader.ts +11 -7
- package/src/tools/setup/dynamic-plugins/paths.ts +30 -10
- package/src/tools/setup/dynamic-plugins/verify.ts +10 -7
- package/src/tools/setup/dynamic-plugins/workspaces.ts +153 -0
- package/src/tools/setup/engine.ts +100 -23
- package/src/tools/setup/install-contract.ts +8 -0
- package/src/tools/setup/managed-output.ts +51 -0
- package/src/tools/setup/mate-skill-copies.ts +51 -0
- package/src/tools/setup/mate.ts +88 -13
- package/src/tools/setup/package-managers/uv.ts +73 -11
- package/src/tools/setup/plugin.ts +40 -0
- package/src/tools/setup/plugins/gitignore.ts +15 -9
- package/src/tools/setup/plugins/guidance.ts +7 -4
- package/src/tools/setup/providers/agent-file-sections.ts +4 -2
- package/src/tools/setup/providers/claude-attribution.ts +65 -0
- package/src/tools/setup/providers/claude-plugin-folders.ts +625 -0
- package/src/tools/setup/providers/claude-plugin-hooks.ts +89 -19
- package/src/tools/setup/providers/claude-worktree-plugins.ts +122 -0
- package/src/tools/setup/providers/claude.ts +332 -8
- package/src/tools/setup/providers/opencode.ts +180 -1
- package/src/tools/setup/utils.ts +22 -6
- package/src/tools/setup/working-repo-cleanup.ts +30 -2
- package/src/tools/setup/working-repo-local-state.ts +252 -75
- package/src/tools/setup.ts +196 -28
- package/studio-dist/client/assets/app-D9cw6szy.css +2 -0
- package/studio-dist/client/assets/artifacts-WD2ZXYrx.js +1 -0
- package/studio-dist/client/assets/button-Br0O1sXw.js +1 -0
- package/studio-dist/client/assets/combobox-DA7RAUUZ.js +1 -0
- package/studio-dist/client/assets/companion-view-CrabvxS8.js +1 -0
- package/studio-dist/client/assets/dist-Dm7MtyHc.js +5 -0
- package/studio-dist/client/assets/factory-DGS0E16C.js +6 -0
- package/studio-dist/client/assets/fields-6aXBpFhJ.js +1 -0
- package/studio-dist/client/assets/getting-started-Clde4w6P.js +1 -0
- package/studio-dist/client/assets/getting-started-D6kgWwWZ.js +1 -0
- package/studio-dist/client/assets/getting-started._topic-BiunccbT.js +1 -0
- package/studio-dist/client/assets/getting-started.index-DpiNoGw8.js +1 -0
- package/studio-dist/client/assets/graph-B_TCBVbu.js +2 -0
- package/studio-dist/client/assets/graph-canvas-Ba37Y5AE.js +3242 -0
- package/studio-dist/client/assets/guides-Du_RtJxP.js +1 -0
- package/studio-dist/client/assets/index-Df8L1LQa.js +40 -0
- package/studio-dist/client/assets/jsx-runtime-MZURdZre.js +1 -0
- package/studio-dist/client/assets/markdown-view-BOX6x0rL.js +1 -0
- package/studio-dist/client/assets/panel-dbmCx7Mx.js +1 -0
- package/studio-dist/client/assets/preload-helper-BLdHbfdN.js +1 -0
- package/studio-dist/client/assets/queries-RvHeXY12.js +1 -0
- package/studio-dist/client/assets/react-3QStrcDO.js +27 -0
- package/studio-dist/client/assets/report-url-XRL0x1SY.js +1 -0
- package/studio-dist/client/assets/reports-r3IK7Doz.js +1 -0
- package/studio-dist/client/assets/routes-C0A5LTFc.js +1 -0
- package/studio-dist/client/assets/select-CnaMd617.js +1 -0
- package/studio-dist/client/assets/skills-CzjzHpBT.js +1 -0
- package/studio-dist/client/assets/specs-B0ldF_6J.js +1 -0
- package/studio-dist/client/assets/specs-view-BnCLA0gW.js +1 -0
- package/studio-dist/client/assets/spinner-Dcm3fqK1.js +1 -0
- package/studio-dist/client/assets/steps-C0p2N1Pb.js +1 -0
- package/studio-dist/client/assets/store-Dw34catY.js +1 -0
- package/studio-dist/client/assets/studio-Cpz_HRHp.js +100 -0
- package/studio-dist/client/assets/studio-queries-ibmpFo6R.js +2 -0
- package/studio-dist/client/assets/terminal-eU5fzQzv.css +1 -0
- package/studio-dist/client/assets/usage-C2QJ_0IZ.js +55 -0
- package/studio-dist/client/assets/useAnchoredPopupScrollLock-Bj-FWb8z.js +1 -0
- package/studio-dist/client/assets/useMutation-aAr2uiay.js +1 -0
- package/studio-dist/client/assets/useSelector-AYcH7lB0.js +2 -0
- package/studio-dist/client/assets/vault-BGcxkSIY.js +1 -0
- package/studio-dist/client/assets/warnings-R1cE1rLf.js +1 -0
- package/studio-dist/client/assets/wasm-inline-C2en61B5.js +1 -0
- package/studio-dist/client/assets/workflow-C2qTrMDH.js +1 -0
- package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-Bn896ZYj.js +122 -0
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +162 -0
- package/studio-dist/server/assets/actions-D8erOphH.js +44 -0
- package/studio-dist/server/assets/actions-DYSv-9VV.js +60 -0
- package/studio-dist/server/assets/artifacts-DnF9L3dZ.js +216 -0
- package/studio-dist/server/assets/button-CgOIVdmD.js +10240 -0
- package/studio-dist/server/assets/combobox-DV_s9W0s.js +483 -0
- package/studio-dist/server/assets/companion-view-BKVXD3TO.js +39 -0
- package/studio-dist/server/assets/companions-C7fctnU9.js +31 -0
- package/studio-dist/server/assets/createServerRpc-bFKFpGFG.js +11 -0
- package/studio-dist/server/assets/dist-DpJWKyCm.js +5582 -0
- package/studio-dist/server/assets/empty-plugin-adapters-Cipd4ZH4.js +4 -0
- package/studio-dist/server/assets/factory-C7Ybg0xG.js +3075 -0
- package/studio-dist/server/assets/factory-Df5uAHjb.js +116 -0
- package/studio-dist/server/assets/fields-BbieQTD0.js +1190 -0
- package/studio-dist/server/assets/getting-started-B136TP57.js +4 -0
- package/studio-dist/server/assets/getting-started-CRxMWorQ.js +67 -0
- package/studio-dist/server/assets/getting-started._topic-DJKQAzYl.js +13 -0
- package/studio-dist/server/assets/getting-started.index-D84gec1t.js +13 -0
- package/studio-dist/server/assets/graph-CSje3029.js +801 -0
- package/studio-dist/server/assets/graph-DDZzXM1L.js +16 -0
- package/studio-dist/server/assets/graph-canvas-22bWB5-2.js +21066 -0
- package/studio-dist/server/assets/graph-wire-BdSUx0G5.js +58 -0
- package/studio-dist/server/assets/guides-D9dk1Frq.js +13 -0
- package/studio-dist/server/assets/guides-IE-19POz.js +5 -0
- package/studio-dist/server/assets/guides.server-vcYRY5wx.js +66 -0
- package/studio-dist/server/assets/jsx-runtime-Bt0s0YKS.js +451 -0
- package/studio-dist/server/assets/markdown-view-BR8dJ7aR.js +105 -0
- package/studio-dist/server/assets/model-PyPALjii.js +18 -0
- package/studio-dist/server/assets/panel-BR_t9iMM.js +169 -0
- package/studio-dist/server/assets/queries-DWoTin-q.js +32 -0
- package/studio-dist/server/assets/react-CdqSUhaL.js +89 -0
- package/studio-dist/server/assets/redirect-BaZ_QyqF.js +39 -0
- package/studio-dist/server/assets/report-url-BUXPcE_8.js +9 -0
- package/studio-dist/server/assets/reports-CQ9qQ1-n.js +141 -0
- package/studio-dist/server/assets/reports-dYDEoBeq.js +18 -0
- package/studio-dist/server/assets/router-DkRHNTpE.js +11638 -0
- package/studio-dist/server/assets/routes-B6GfOew4.js +473 -0
- package/studio-dist/server/assets/search-BJnWLfkG.js +55 -0
- package/studio-dist/server/assets/select-Af7Wibii.js +1609 -0
- package/studio-dist/server/assets/shell-Hq-hXgnT.js +53 -0
- package/studio-dist/server/assets/skills-B7nEuVbx.js +267 -0
- package/studio-dist/server/assets/skills-B_YYL7q8.js +28 -0
- package/studio-dist/server/assets/specs-BpLUFntA.js +51 -0
- package/studio-dist/server/assets/specs-view-0peMVd22.js +426 -0
- package/studio-dist/server/assets/spinner-CdwJW4VB.js +20 -0
- package/studio-dist/server/assets/start-h3ICWwd2.js +36 -0
- package/studio-dist/server/assets/steps-D56DApvK.js +181 -0
- package/studio-dist/server/assets/store-Cs17okNG.js +280 -0
- package/studio-dist/server/assets/studio-CAcKp3bM.js +10340 -0
- package/studio-dist/server/assets/studio-queries-BtRGzDdh.js +1451 -0
- package/studio-dist/server/assets/usage-COdjd1gD.js +25570 -0
- package/studio-dist/server/assets/usage-f6pqE1tm.js +24 -0
- package/studio-dist/server/assets/useAnchoredPopupScrollLock-DlBKHRw7.js +756 -0
- package/studio-dist/server/assets/useMutation-DzTZGenE.js +690 -0
- package/studio-dist/server/assets/useSelector-DUmCUXAs.js +3387 -0
- package/studio-dist/server/assets/utils-C9CX1kcy.js +221 -0
- package/studio-dist/server/assets/vault-BDuIUq0F.js +1035 -0
- package/studio-dist/server/assets/vault-BVLp6zu3.js +85 -0
- package/studio-dist/server/assets/views-flRUr21z.js +80 -0
- package/studio-dist/server/assets/warnings-CDy9pdgL.js +24 -0
- package/studio-dist/server/assets/wasm-inline-CNeBKGwC.js +3 -0
- package/studio-dist/server/assets/workflow-D9GKI2EV.js +680 -0
- package/studio-dist/server/server.js +16640 -0
- package/wrappers/bin/graphify +52 -4
- package/wrappers/bin/openspec +33 -9
- package/wrappers/lib/graphify-gate.mjs +8 -0
- package/src/cli/commands/report/collector.ts +0 -288
- package/src/cli/commands/studio/views/client.ts +0 -654
- package/src/cli/commands/studio/views/companion-picker.tsx +0 -95
- package/src/cli/commands/studio/views/companion-selector.tsx +0 -94
- package/src/cli/commands/studio/views/dashboard/changes.tsx +0 -107
- package/src/cli/commands/studio/views/dashboard/index.tsx +0 -19
- package/src/cli/commands/studio/views/document.tsx +0 -842
- package/src/cli/commands/studio/views/error.tsx +0 -20
- package/src/cli/commands/studio/views/reports/index.tsx +0 -49
- package/src/cli/commands/studio/views/selection-fields.tsx +0 -14
- package/src/cli/commands/studio/views/skills/index.tsx +0 -87
- package/src/cli/commands/studio/views/specs/index.tsx +0 -157
- package/src/cli/commands/studio/views/styles.ts +0 -519
- package/src/cli/commands/studio/views/terminal.tsx +0 -484
- package/src/cli/commands/studio/views/vault/state.ts +0 -43
- package/src/cli/commands/studio/views/warnings.tsx +0 -21
- package/src/cli/commands/studio/views/workflow/index.tsx +0 -21
- package/src/cli/commands/studio/views/workflow/steps.ts +0 -337
- package/src/cli/commands/studio/views/workflow/transcript.tsx +0 -190
- package/src/lib/components/theme.ts +0 -2
- package/src/templates/mate-skills/agents/mate-artifact-publish/SKILL.md +0 -185
- package/src/templates/mate-skills/claude/mate-artifact-publish/SKILL.md +0 -185
- package/src/tools/setup/git-utils.ts +0 -30
- package/src/tools/setup/runtime-documents.ts +0 -291
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/** A Delivery Branch template: a fixed prefix ending in `/`, `{workset}`, and optional `{ticket}`. */
|
|
2
|
+
export type BranchTemplate = string;
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_BRANCH_TEMPLATE: BranchTemplate = "workset/{ticket}-{workset}";
|
|
5
|
+
|
|
6
|
+
const PLACEHOLDER = /\{([^{}]*)\}/g;
|
|
7
|
+
const SEPARATORS = new Set(["-", "_", "/"]);
|
|
8
|
+
// Any case, as `isJiraKey` accepts it; see `matchBranchTemplate` for an all-lowercase one.
|
|
9
|
+
const TICKET_KEY = "[A-Za-z][A-Za-z0-9]+-\\d+";
|
|
10
|
+
|
|
11
|
+
export interface BranchTemplateSetting {
|
|
12
|
+
template: BranchTemplate;
|
|
13
|
+
/** Set for an invalid value, which counts as the default. */
|
|
14
|
+
diagnostic: string | null;
|
|
15
|
+
}
|
|
16
|
+
|
|
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
|
+
/** The rule a template breaks, or null when it is valid. */
|
|
30
|
+
function brokenRule(template: string): string | null {
|
|
31
|
+
const names = [...template.matchAll(PLACEHOLDER)].map((match) => match[1]!);
|
|
32
|
+
const unknown = names.find((name) => name !== "workset" && name !== "ticket");
|
|
33
|
+
if (unknown !== undefined) {
|
|
34
|
+
return `unknown placeholder {${unknown}}; only {workset} and {ticket} exist`;
|
|
35
|
+
}
|
|
36
|
+
if (names.filter((name) => name === "workset").length !== 1) {
|
|
37
|
+
return "{workset} must appear exactly once";
|
|
38
|
+
}
|
|
39
|
+
if (names.filter((name) => name === "ticket").length > 1) {
|
|
40
|
+
return "{ticket} may appear at most once";
|
|
41
|
+
}
|
|
42
|
+
if (/[{}]/.test(template.replace(PLACEHOLDER, ""))) return "a brace is not part of a placeholder";
|
|
43
|
+
if (!branchTemplatePrefix(template).endsWith("/")) {
|
|
44
|
+
return "a fixed prefix ending in / must precede the first placeholder";
|
|
45
|
+
}
|
|
46
|
+
const samples = [
|
|
47
|
+
applyBranchTemplate(template, "acme-fix"),
|
|
48
|
+
applyBranchTemplate(template, "acme-fix", "ABC-123"),
|
|
49
|
+
];
|
|
50
|
+
if (!samples.every(isBranchName)) return "it does not yield a valid Git branch name";
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** A configured template; absent means the default, invalid the default with a diagnostic. */
|
|
55
|
+
export function parseBranchTemplate(value: unknown): BranchTemplateSetting {
|
|
56
|
+
if (value === undefined) return { template: DEFAULT_BRANCH_TEMPLATE, diagnostic: null };
|
|
57
|
+
const rule = typeof value === "string" ? brokenRule(value) : "it is not a string";
|
|
58
|
+
if (rule === null) return { template: value as string, diagnostic: null };
|
|
59
|
+
return {
|
|
60
|
+
template: DEFAULT_BRANCH_TEMPLATE,
|
|
61
|
+
diagnostic: `Invalid branchTemplate ${JSON.stringify(value)} on the openspec capability: ${rule}; ${DEFAULT_BRANCH_TEMPLATE} applies.`,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The branch a template names for a Workset. Without a ticket, `{ticket}` and one adjacent
|
|
67
|
+
* separator go, the following one first: `workset/{ticket}-{workset}` → `workset/<id>`.
|
|
68
|
+
*/
|
|
69
|
+
export function applyBranchTemplate(
|
|
70
|
+
template: BranchTemplate,
|
|
71
|
+
worksetId: string,
|
|
72
|
+
ticket?: string | null,
|
|
73
|
+
): string {
|
|
74
|
+
const shaped = ticket ? template.replace("{ticket}", ticket) : withoutTicket(template);
|
|
75
|
+
return shaped.replace("{workset}", worksetId);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The template without `{ticket}` and one adjacent separator; the prefix's own `/` stays. */
|
|
79
|
+
function withoutTicket(template: BranchTemplate): string {
|
|
80
|
+
const at = template.indexOf("{ticket}");
|
|
81
|
+
if (at < 0) return template;
|
|
82
|
+
const end = at + "{ticket}".length;
|
|
83
|
+
if (SEPARATORS.has(template[end] ?? "")) return template.slice(0, at) + template.slice(end + 1);
|
|
84
|
+
const separatorBefore =
|
|
85
|
+
at > branchTemplatePrefix(template).length && SEPARATORS.has(template[at - 1]!);
|
|
86
|
+
return template.slice(0, separatorBefore ? at - 1 : at) + template.slice(end);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The fixed text before the first placeholder, e.g. `feature/`; scopes ref listing. */
|
|
90
|
+
export function branchTemplatePrefix(template: BranchTemplate): string {
|
|
91
|
+
const at = template.indexOf("{");
|
|
92
|
+
return at < 0 ? template : template.slice(0, at);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function escape(literal: string): string {
|
|
96
|
+
return literal.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Whether `branch` is the template's branch for the Workset, and with which ticket: null for
|
|
101
|
+
* the name without one, else the key as written.
|
|
102
|
+
*/
|
|
103
|
+
export function matchBranchTemplate(
|
|
104
|
+
template: BranchTemplate,
|
|
105
|
+
branch: string,
|
|
106
|
+
worksetId: string,
|
|
107
|
+
): { ticket: string | null } | null {
|
|
108
|
+
if (branch === applyBranchTemplate(template, worksetId)) return { ticket: null };
|
|
109
|
+
if (!template.includes("{ticket}")) return null;
|
|
110
|
+
const source = template
|
|
111
|
+
.split(/(\{ticket\}|\{workset\})/)
|
|
112
|
+
.map((part) => {
|
|
113
|
+
if (part === "{ticket}") return `(${TICKET_KEY})`;
|
|
114
|
+
return escape(part === "{workset}" ? worksetId : part);
|
|
115
|
+
})
|
|
116
|
+
.join("");
|
|
117
|
+
const ticket = new RegExp(`^${source}$`).exec(branch)?.[1];
|
|
118
|
+
if (!ticket) return null;
|
|
119
|
+
// After {workset}, an all-lowercase key reads as the tail of a longer Workset id: `fix-login-2`.
|
|
120
|
+
const trailing = template.indexOf("{ticket}") > template.indexOf("{workset}");
|
|
121
|
+
return trailing && ticket === ticket.toLowerCase() ? null : { ticket };
|
|
122
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
|
|
4
|
+
import { readCompanionConfig } from "../orchestrator/config-store";
|
|
5
|
+
import type { CapabilityConfig, TicketFormat } from "../orchestrator/types";
|
|
6
|
+
import { parseBranchTemplate, type BranchTemplateSetting } from "./branch-template";
|
|
7
|
+
import { deliveryCheckout } from "./checkout";
|
|
8
|
+
|
|
9
|
+
export type { TicketFormat };
|
|
10
|
+
|
|
11
|
+
const execFileAsync = promisify(execFile);
|
|
12
|
+
|
|
13
|
+
export type ProtectionReason = "default" | "pattern";
|
|
14
|
+
|
|
15
|
+
export interface BranchProtection {
|
|
16
|
+
protected: boolean;
|
|
17
|
+
reason: ProtectionReason | null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ProtectionOptions {
|
|
21
|
+
defaultBranch: string;
|
|
22
|
+
/** Configured glob patterns; `*` stays within one path segment, `**` crosses segments. */
|
|
23
|
+
patterns: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function globToRegExp(pattern: string): RegExp {
|
|
27
|
+
const source = pattern
|
|
28
|
+
.split("**")
|
|
29
|
+
.map((part) =>
|
|
30
|
+
part
|
|
31
|
+
.split("*")
|
|
32
|
+
.map((literal) => literal.replace(/[.+?^${}()|[\]\\]/g, "\\$&"))
|
|
33
|
+
.join("[^/]*"),
|
|
34
|
+
)
|
|
35
|
+
.join(".*");
|
|
36
|
+
return new RegExp(`^${source}$`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** A branch is protected when it is the default branch or matches a pattern. */
|
|
40
|
+
export function classifyBranch(branch: string, options: ProtectionOptions): BranchProtection {
|
|
41
|
+
if (branch === options.defaultBranch) return { protected: true, reason: "default" };
|
|
42
|
+
if (options.patterns.some((pattern) => globToRegExp(pattern).test(branch))) {
|
|
43
|
+
return { protected: true, reason: "pattern" };
|
|
44
|
+
}
|
|
45
|
+
return { protected: false, reason: null };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Protected-branch patterns from the companion's openspec capability config. */
|
|
49
|
+
export function configuredProtectedPatterns(capabilities: readonly CapabilityConfig[]): string[] {
|
|
50
|
+
const openspec = capabilities.find((capability) => capability.name === "openspec");
|
|
51
|
+
const patterns = openspec?.protectedBranches;
|
|
52
|
+
return Array.isArray(patterns)
|
|
53
|
+
? patterns.filter((pattern): pattern is string => typeof pattern === "string")
|
|
54
|
+
: [];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface TicketSetting {
|
|
58
|
+
format: TicketFormat;
|
|
59
|
+
/** Set for a value Mate does not know, which counts as `none`. */
|
|
60
|
+
diagnostic: string | null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The openspec capability's `ticket` setting; absent or unknown means `none`. */
|
|
64
|
+
export function configuredTicketFormat(capabilities: readonly CapabilityConfig[]): TicketSetting {
|
|
65
|
+
const value = capabilities.find((capability) => capability.name === "openspec")?.ticket;
|
|
66
|
+
if (value === undefined || value === "none") return { format: "none", diagnostic: null };
|
|
67
|
+
if (value === "jira") return { format: "jira", diagnostic: null };
|
|
68
|
+
return {
|
|
69
|
+
format: "none",
|
|
70
|
+
diagnostic: `Unknown ticket setting ${JSON.stringify(value)} on the openspec capability; expected none or jira, so tickets are off.`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Why `--ticket` is refused while the companion's tickets are off. */
|
|
75
|
+
export const TICKETS_OFF =
|
|
76
|
+
"tickets are off for this companion; set `ticket: jira` on the openspec capability (mate setup --ticket jira) to use one.";
|
|
77
|
+
|
|
78
|
+
/** The ticket setting in a companion's `framework.yaml`, as `mate artifact link` reads it. */
|
|
79
|
+
export async function companionTicketFormat(companionPath: string): Promise<TicketFormat> {
|
|
80
|
+
const config = await readCompanionConfig(companionPath);
|
|
81
|
+
return configuredTicketFormat(config.capabilities ?? []).format;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The openspec capability's `branchTemplate`; absent or invalid means the default. */
|
|
85
|
+
export function configuredBranchTemplate(
|
|
86
|
+
capabilities: readonly CapabilityConfig[],
|
|
87
|
+
): BranchTemplateSetting {
|
|
88
|
+
const openspec = capabilities.find((capability) => capability.name === "openspec");
|
|
89
|
+
return parseBranchTemplate(openspec?.branchTemplate);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The Delivery Branch template in a companion's `framework.yaml`, with its diagnostic. */
|
|
93
|
+
export async function companionBranchTemplate(
|
|
94
|
+
companionPath: string,
|
|
95
|
+
): Promise<BranchTemplateSetting> {
|
|
96
|
+
const config = await readCompanionConfig(companionPath);
|
|
97
|
+
return configuredBranchTemplate(config.capabilities ?? []);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Read-only local Git queries against a Working Repository. Nothing here touches the network. */
|
|
101
|
+
export interface WorkingRepoGit {
|
|
102
|
+
/** Checked-out branch, or null in a detached HEAD. */
|
|
103
|
+
currentBranch(): Promise<string | null>;
|
|
104
|
+
/** `origin/HEAD`, then an existing `origin/main` or `origin/master`, then `init.defaultBranch`, then `main`. */
|
|
105
|
+
defaultBranch(): Promise<string>;
|
|
106
|
+
/** The `origin` remote URL, or null without one. */
|
|
107
|
+
remoteUrl(): Promise<string | null>;
|
|
108
|
+
/** One-line summaries of commits on HEAD that no remote-tracking branch contains. */
|
|
109
|
+
unpushedCommits(): Promise<string[]>;
|
|
110
|
+
/** True when the branch exists locally or as `origin/<branch>`. */
|
|
111
|
+
branchExists(branch: string): Promise<boolean>;
|
|
112
|
+
/** True when the ref (`refs/heads/<b>`, `refs/remotes/origin/<b>`) resolves. */
|
|
113
|
+
hasRef(ref: string): Promise<boolean>;
|
|
114
|
+
/** Full names of the refs under the given prefixes; empty when Git fails. */
|
|
115
|
+
listRefs?(prefixes: string[]): Promise<string[]>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function workingRepoGit(repoPath: string): WorkingRepoGit {
|
|
119
|
+
const run = async (...args: string[]): Promise<string | null> => {
|
|
120
|
+
try {
|
|
121
|
+
const { stdout } = await execFileAsync("git", args, { cwd: repoPath });
|
|
122
|
+
return stdout.trim();
|
|
123
|
+
} catch {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// Ref queries are the ones a Delivery Branch resolves through.
|
|
129
|
+
const { hasRef, listRefs, defaultBranch } = deliveryCheckout(repoPath);
|
|
130
|
+
|
|
131
|
+
const currentBranch = async (): Promise<string | null> =>
|
|
132
|
+
(await run("symbolic-ref", "--quiet", "--short", "HEAD")) || null;
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
currentBranch,
|
|
136
|
+
defaultBranch,
|
|
137
|
+
async remoteUrl() {
|
|
138
|
+
return (await run("remote", "get-url", "origin")) || null;
|
|
139
|
+
},
|
|
140
|
+
async unpushedCommits() {
|
|
141
|
+
const log = await run("log", "--oneline", "HEAD", "--not", "--remotes");
|
|
142
|
+
return log ? log.split("\n").filter(Boolean) : [];
|
|
143
|
+
},
|
|
144
|
+
async branchExists(branch: string) {
|
|
145
|
+
return (
|
|
146
|
+
(await hasRef(`refs/heads/${branch}`)) || (await hasRef(`refs/remotes/origin/${branch}`))
|
|
147
|
+
);
|
|
148
|
+
},
|
|
149
|
+
hasRef,
|
|
150
|
+
listRefs,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
localGitEnv,
|
|
3
|
+
mergeGit,
|
|
4
|
+
spawnProcess,
|
|
5
|
+
type MergeGit,
|
|
6
|
+
type ProcessResult,
|
|
7
|
+
} from "./merge-git";
|
|
8
|
+
import { localMergeEvidence } from "./refresh";
|
|
9
|
+
|
|
10
|
+
/** True when the ref resolves in the checkout. */
|
|
11
|
+
export type HasRef = (ref: string) => Promise<boolean>;
|
|
12
|
+
|
|
13
|
+
/** Full names of the refs under the given prefixes, e.g. `refs/heads/workset/`. */
|
|
14
|
+
export type ListRefs = (prefixes: string[]) => Promise<string[]>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A local merge check, without fetch or forge: a merge commit settles `merged`, commits
|
|
18
|
+
* matched on the default branch read as `squashed`. A head on the default branch's own line
|
|
19
|
+
* is `open`: it may be a fast-forward, but then its commits are already there and continuing
|
|
20
|
+
* on it is safe.
|
|
21
|
+
*/
|
|
22
|
+
export type MergeProbeResult = "merged" | "squashed" | "open";
|
|
23
|
+
|
|
24
|
+
/** The local Git a Delivery Branch resolves in: refs, the default branch, and merge checks. */
|
|
25
|
+
export interface DeliveryCheckout {
|
|
26
|
+
hasRef: HasRef;
|
|
27
|
+
listRefs: ListRefs;
|
|
28
|
+
/** `origin/HEAD`, then an existing `origin/main` or `origin/master`, then `init.defaultBranch`, then `main`. */
|
|
29
|
+
defaultBranch(): Promise<string>;
|
|
30
|
+
/** Null when the checkout cannot check merges; the branch then counts as never checked. */
|
|
31
|
+
mergeProbe(branch: string, recordedHead: string | undefined): Promise<MergeProbeResult | null>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Runs `git` in the checkout. `env` is the environment local queries need; a runner with
|
|
36
|
+
* its own Git policy (another user, extra `-c` settings) may keep its own instead.
|
|
37
|
+
*/
|
|
38
|
+
export type CheckoutRunner = (
|
|
39
|
+
args: readonly string[],
|
|
40
|
+
options: { env: NodeJS.ProcessEnv; input?: string; timeoutMs?: number },
|
|
41
|
+
) => Promise<ProcessResult>;
|
|
42
|
+
|
|
43
|
+
/** A {@link ListRefs} over a Git runner that answers stdout, or null on failure. */
|
|
44
|
+
function listRefsWith(git: (args: string[]) => Promise<string | null>): ListRefs {
|
|
45
|
+
return async (prefixes) => {
|
|
46
|
+
const stdout = await git(["for-each-ref", "--format=%(refname)", ...prefixes]);
|
|
47
|
+
return stdout ? stdout.split("\n").filter(Boolean) : [];
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The default branch over a Git runner that answers trimmed stdout, or null on failure. */
|
|
52
|
+
async function defaultBranchWith(
|
|
53
|
+
run: (...args: string[]) => Promise<string | null>,
|
|
54
|
+
): Promise<string> {
|
|
55
|
+
const remoteHead = await run("symbolic-ref", "--quiet", "--short", "refs/remotes/origin/HEAD");
|
|
56
|
+
if (remoteHead) return remoteHead.replace(/^origin\//, "");
|
|
57
|
+
for (const candidate of ["main", "master"]) {
|
|
58
|
+
// oxlint-disable-next-line no-await-in-loop -- the steps are a decision chain
|
|
59
|
+
if (await run("rev-parse", "--verify", "--quiet", `refs/remotes/origin/${candidate}`)) {
|
|
60
|
+
return candidate;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return (await run("config", "--get", "init.defaultBranch")) || "main";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The merge check over local merge queries; see {@link MergeProbeResult}. */
|
|
67
|
+
export async function probeMerge(
|
|
68
|
+
git: MergeGit,
|
|
69
|
+
defaultBranch: string,
|
|
70
|
+
branch: string,
|
|
71
|
+
recordedHead: string | undefined,
|
|
72
|
+
): Promise<MergeProbeResult> {
|
|
73
|
+
const evidence = await localMergeEvidence(git, defaultBranch, branch, recordedHead);
|
|
74
|
+
if (evidence.merged) return "merged";
|
|
75
|
+
const style = evidence.suggestion?.style;
|
|
76
|
+
return style === "squash" || style === "rebase" ? "squashed" : "open";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The checkout at `path`, every query through one runner, so a caller's Git policy reaches
|
|
81
|
+
* ref lookups and merge checks alike. Without `run`, `git` is spawned in `path`.
|
|
82
|
+
*/
|
|
83
|
+
export function deliveryCheckout(path: string, run?: CheckoutRunner): DeliveryCheckout {
|
|
84
|
+
const git: CheckoutRunner =
|
|
85
|
+
run ?? ((args, options) => spawnProcess("git", args, { cwd: path, ...options }));
|
|
86
|
+
const env = localGitEnv();
|
|
87
|
+
const stdout = async (...args: string[]): Promise<string | null> => {
|
|
88
|
+
const result = await git(args, { env });
|
|
89
|
+
return result.code === 0 ? result.stdout.trim() || null : null;
|
|
90
|
+
};
|
|
91
|
+
let defaultBranch: Promise<string> | undefined;
|
|
92
|
+
const merges = mergeGit(path, { spawn: (_command, args, options) => git(args, options) });
|
|
93
|
+
const checkout: DeliveryCheckout = {
|
|
94
|
+
hasRef: async (ref) =>
|
|
95
|
+
(await git(["rev-parse", "--verify", "--quiet", ref], { env })).code === 0,
|
|
96
|
+
listRefs: listRefsWith((args) => stdout(...args)),
|
|
97
|
+
defaultBranch: () => (defaultBranch ??= defaultBranchWith(stdout)),
|
|
98
|
+
mergeProbe: async (branch, recordedHead) =>
|
|
99
|
+
probeMerge(merges, await checkout.defaultBranch(), branch, recordedHead),
|
|
100
|
+
};
|
|
101
|
+
return checkout;
|
|
102
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
import type { TicketSetting, WorkingRepoGit } from "./branches";
|
|
4
|
+
import type { ForgeRepo } from "./forge";
|
|
5
|
+
|
|
6
|
+
export interface WorkingRepoInfo {
|
|
7
|
+
path: string;
|
|
8
|
+
/** Full repository path from the `origin` remote (`acme/platform/api`), or null without one. */
|
|
9
|
+
slug: string | null;
|
|
10
|
+
forgeRepo: ForgeRepo | null;
|
|
11
|
+
git: WorkingRepoGit;
|
|
12
|
+
/** Set when the Working Repository is an Umbrella Repository: its children's repository paths. */
|
|
13
|
+
umbrellaChildren?: string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The companion, the Working Repository with its remote identity, and protected-branch patterns. */
|
|
17
|
+
export interface DeliveryEnvironment {
|
|
18
|
+
companionPath: string;
|
|
19
|
+
workingRepo: WorkingRepoInfo | null;
|
|
20
|
+
protectedPatterns: string[];
|
|
21
|
+
/** The companion's ticket setting; absent means `none`. */
|
|
22
|
+
ticket?: TicketSetting;
|
|
23
|
+
/**
|
|
24
|
+
* Host of a repository other than the Working Repository, from a linked checkout's
|
|
25
|
+
* `origin` remote, else the Working Repository's host; null when neither is known.
|
|
26
|
+
*/
|
|
27
|
+
hostOf?: (repository: string) => Promise<string | null>;
|
|
28
|
+
/** Path of a local checkout of the repository: the Working Repository or a linked one. */
|
|
29
|
+
checkoutOf?: (repository: string) => Promise<string | null>;
|
|
30
|
+
/** The companion's Git mode is `auto`: merge checks fetch before reading local refs. */
|
|
31
|
+
gitAutoMode?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** `dir` relative to the companion, with forward slashes. */
|
|
35
|
+
export function companionRelative(environment: DeliveryEnvironment, dir: string): string {
|
|
36
|
+
return path.relative(environment.companionPath, dir).split(path.sep).join("/");
|
|
37
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forge adapters answer read-only questions about a repository and its Delivery Branch:
|
|
3
|
+
* the default branch and which PR has it as head; branch protection is never asked. GitHub
|
|
4
|
+
* (github.com) is the only adapter; every other host falls back to asking the user. Every failure is returned, never thrown, and the token
|
|
5
|
+
* is scrubbed from anything a failure carries.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { errorMessage } from "../../runtime/error-message";
|
|
9
|
+
import { pickProvenance, type MergeProvenance, type MergeState } from "./record";
|
|
10
|
+
|
|
11
|
+
export interface ForgeRepo {
|
|
12
|
+
host: string;
|
|
13
|
+
/** Every path segment before the repository; nested groups keep theirs (`acme/platform`). */
|
|
14
|
+
owner: string;
|
|
15
|
+
repo: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface PullCandidate {
|
|
19
|
+
number: number;
|
|
20
|
+
url: string;
|
|
21
|
+
state: MergeState;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface PullDetail extends MergeProvenance {
|
|
25
|
+
number: number;
|
|
26
|
+
url: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type PullClassification =
|
|
30
|
+
| { kind: "merged"; pr: PullDetail }
|
|
31
|
+
| { kind: "open"; pr: PullDetail }
|
|
32
|
+
| { kind: "closed-unmerged"; pr: PullDetail }
|
|
33
|
+
| { kind: "ambiguous"; candidates: PullCandidate[] }
|
|
34
|
+
| { kind: "none" };
|
|
35
|
+
|
|
36
|
+
export type ForgeFailureReason = "permission" | "rate-limit" | "auth" | "network" | "unexpected";
|
|
37
|
+
|
|
38
|
+
export interface ForgeFailure {
|
|
39
|
+
reason: ForgeFailureReason;
|
|
40
|
+
message: string;
|
|
41
|
+
/** The fine-grained read permission a `permission` failure lacks. */
|
|
42
|
+
permission?: string;
|
|
43
|
+
/** The HTTP status the forge answered, when it answered. */
|
|
44
|
+
status?: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type ForgeOutcome<T> = { ok: true; value: T } | { ok: false; failure: ForgeFailure };
|
|
48
|
+
|
|
49
|
+
export interface ForgeAdapter {
|
|
50
|
+
id: string;
|
|
51
|
+
defaultBranch(repo: ForgeRepo): Promise<ForgeOutcome<string>>;
|
|
52
|
+
/** Classifies the PRs whose head is `branch`; `prNumber` picks one of several. */
|
|
53
|
+
pullsForBranch(
|
|
54
|
+
repo: ForgeRepo,
|
|
55
|
+
branch: string,
|
|
56
|
+
prNumber?: number,
|
|
57
|
+
): Promise<ForgeOutcome<PullClassification>>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type FetchLike = (
|
|
61
|
+
url: string,
|
|
62
|
+
init?: { headers?: Record<string, string> },
|
|
63
|
+
) => Promise<Response>;
|
|
64
|
+
|
|
65
|
+
export interface ForgeDeps {
|
|
66
|
+
fetch?: FetchLike;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Parses SSH, scp-style, and HTTPS remotes; credentials in a URL are discarded. */
|
|
70
|
+
export function parseRemote(url: string): ForgeRepo | null {
|
|
71
|
+
const cleaned = url.trim();
|
|
72
|
+
let host: string;
|
|
73
|
+
let remotePath: string;
|
|
74
|
+
if (/^[a-z][a-z\d+.-]*:\/\//i.test(cleaned)) {
|
|
75
|
+
try {
|
|
76
|
+
const parsed = new URL(cleaned);
|
|
77
|
+
host = parsed.hostname;
|
|
78
|
+
remotePath = parsed.pathname;
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
// `user@` is optional: an SSH config alias such as `work:org/repo` has none.
|
|
84
|
+
const scp = /^(?:[^/\s@]+@)?([^/\s:]{2,}):(.+)$/.exec(cleaned);
|
|
85
|
+
if (!scp) return null;
|
|
86
|
+
host = scp[1];
|
|
87
|
+
remotePath = scp[2];
|
|
88
|
+
}
|
|
89
|
+
if (!host) return null;
|
|
90
|
+
return forgeRepoOf(host, remotePath.replace(/\.git\/?$/, ""));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Splits a repository path at its last segment; null below two segments. */
|
|
94
|
+
export function forgeRepoOf(host: string, path: string): ForgeRepo | null {
|
|
95
|
+
const parts = path.split("/").filter(Boolean);
|
|
96
|
+
if (parts.length < 2) return null;
|
|
97
|
+
return {
|
|
98
|
+
host: host.toLowerCase(),
|
|
99
|
+
owner: parts.slice(0, -1).join("/"),
|
|
100
|
+
repo: parts.at(-1) as string,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The repository's identity: its full path on the host, `owner/repo`. */
|
|
105
|
+
export function repositoryPath(repo: ForgeRepo): string {
|
|
106
|
+
return `${repo.owner}/${repo.repo}`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The adapter for a remote's host, or null when the host has none. */
|
|
110
|
+
export function forgeFor(
|
|
111
|
+
repo: ForgeRepo,
|
|
112
|
+
token: string,
|
|
113
|
+
deps: ForgeDeps = {},
|
|
114
|
+
): ForgeAdapter | null {
|
|
115
|
+
return repo.host === "github.com" ? githubForge(token, deps) : null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Replaces every occurrence of the token, so no failure text can carry it. */
|
|
119
|
+
function redactToken(text: string, token: string): string {
|
|
120
|
+
return token ? text.split(token).join("[redacted]") : text;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const GITHUB_API = "https://api.github.com";
|
|
124
|
+
|
|
125
|
+
interface GithubPull {
|
|
126
|
+
number: number;
|
|
127
|
+
html_url: string;
|
|
128
|
+
state: string;
|
|
129
|
+
merged_at: string | null;
|
|
130
|
+
merge_commit_sha?: string | null;
|
|
131
|
+
merged_by?: { login?: string } | null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function candidateState(pull: GithubPull): PullCandidate["state"] {
|
|
135
|
+
if (pull.merged_at) return "merged";
|
|
136
|
+
return pull.state === "open" ? "open" : "closed-unmerged";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function detail(pull: GithubPull): PullDetail {
|
|
140
|
+
return {
|
|
141
|
+
number: pull.number,
|
|
142
|
+
url: pull.html_url,
|
|
143
|
+
...pickProvenance({
|
|
144
|
+
mergedAt: pull.merged_at ?? undefined,
|
|
145
|
+
mergeCommit: (pull.merged_at && pull.merge_commit_sha) || undefined,
|
|
146
|
+
mergedBy: pull.merged_by?.login,
|
|
147
|
+
}),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function repoPath(repo: ForgeRepo): string {
|
|
152
|
+
return `/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.repo)}`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function githubForge(token: string, deps: ForgeDeps = {}): ForgeAdapter {
|
|
156
|
+
const fetchFn: FetchLike = deps.fetch ?? ((url, init) => fetch(url, init));
|
|
157
|
+
|
|
158
|
+
async function get<T>(apiPath: string, permission: string): Promise<ForgeOutcome<T>> {
|
|
159
|
+
let response: Response;
|
|
160
|
+
try {
|
|
161
|
+
response = await fetchFn(`${GITHUB_API}${apiPath}`, {
|
|
162
|
+
headers: {
|
|
163
|
+
accept: "application/vnd.github+json",
|
|
164
|
+
authorization: `Bearer ${token}`,
|
|
165
|
+
"x-github-api-version": "2022-11-28",
|
|
166
|
+
"user-agent": "mate-cli",
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
} catch (error) {
|
|
170
|
+
return {
|
|
171
|
+
ok: false,
|
|
172
|
+
failure: {
|
|
173
|
+
reason: "network",
|
|
174
|
+
message: redactToken(`GitHub request failed: ${errorMessage(error)}`, token),
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
const fail = (
|
|
179
|
+
reason: ForgeFailureReason,
|
|
180
|
+
message: string,
|
|
181
|
+
extra: Pick<ForgeFailure, "permission"> = {},
|
|
182
|
+
): ForgeOutcome<T> => ({
|
|
183
|
+
ok: false,
|
|
184
|
+
failure: {
|
|
185
|
+
reason,
|
|
186
|
+
message: redactToken(message, token),
|
|
187
|
+
...extra,
|
|
188
|
+
...(response.ok ? {} : { status: response.status }),
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
if (response.ok) {
|
|
192
|
+
try {
|
|
193
|
+
return { ok: true, value: (await response.json()) as T };
|
|
194
|
+
} catch (error) {
|
|
195
|
+
return fail(
|
|
196
|
+
"unexpected",
|
|
197
|
+
`GitHub answered with an unreadable body: ${errorMessage(error)}`,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (response.status === 401) return fail("auth", "GitHub rejected the token (401).");
|
|
202
|
+
if (response.status === 403 && response.headers.get("x-ratelimit-remaining") === "0") {
|
|
203
|
+
return fail("rate-limit", "GitHub API rate limit reached (403).");
|
|
204
|
+
}
|
|
205
|
+
if (response.status === 403 || response.status === 404) {
|
|
206
|
+
return fail(
|
|
207
|
+
"permission",
|
|
208
|
+
`GitHub refused the request (${response.status}); the token needs ${permission} on this repository.`,
|
|
209
|
+
{ permission },
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
return fail("unexpected", `GitHub answered ${response.status}.`);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
id: "github",
|
|
217
|
+
async defaultBranch(repo) {
|
|
218
|
+
const result = await get<{ default_branch?: string }>(repoPath(repo), "Metadata: read");
|
|
219
|
+
if (!result.ok) return result;
|
|
220
|
+
const branch = result.value.default_branch;
|
|
221
|
+
return branch
|
|
222
|
+
? { ok: true, value: branch }
|
|
223
|
+
: {
|
|
224
|
+
ok: false,
|
|
225
|
+
failure: { reason: "unexpected", message: "GitHub named no default branch." },
|
|
226
|
+
};
|
|
227
|
+
},
|
|
228
|
+
async pullsForBranch(repo, branch, prNumber) {
|
|
229
|
+
const head = encodeURIComponent(`${repo.owner}:${branch}`);
|
|
230
|
+
const listPulls = (target: string) =>
|
|
231
|
+
get<GithubPull[]>(
|
|
232
|
+
`${target}/pulls?head=${head}&state=all&per_page=100`,
|
|
233
|
+
"Pull requests: read",
|
|
234
|
+
);
|
|
235
|
+
let listed = await listPulls(repoPath(repo));
|
|
236
|
+
if (!listed.ok) return listed;
|
|
237
|
+
let pullRepo = repoPath(repo);
|
|
238
|
+
if (listed.value.length === 0) {
|
|
239
|
+
// A fork's PR is opened on its parent; the head stays `<fork owner>:<branch>`.
|
|
240
|
+
const metadata = await get<{ parent?: { full_name?: string } }>(
|
|
241
|
+
repoPath(repo),
|
|
242
|
+
"Metadata: read",
|
|
243
|
+
);
|
|
244
|
+
const parent = metadata.ok ? metadata.value.parent?.full_name : undefined;
|
|
245
|
+
if (parent) {
|
|
246
|
+
pullRepo = `/repos/${parent.split("/").map(encodeURIComponent).join("/")}`;
|
|
247
|
+
listed = await listPulls(pullRepo);
|
|
248
|
+
if (!listed.ok) return listed;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const pulls =
|
|
252
|
+
prNumber === undefined
|
|
253
|
+
? listed.value
|
|
254
|
+
: listed.value.filter((entry) => entry.number === prNumber);
|
|
255
|
+
if (pulls.length === 0) return { ok: true, value: { kind: "none" } };
|
|
256
|
+
if (pulls.length > 1) {
|
|
257
|
+
return {
|
|
258
|
+
ok: true,
|
|
259
|
+
value: {
|
|
260
|
+
kind: "ambiguous",
|
|
261
|
+
candidates: pulls
|
|
262
|
+
.map((entry) => ({
|
|
263
|
+
number: entry.number,
|
|
264
|
+
url: entry.html_url,
|
|
265
|
+
state: candidateState(entry),
|
|
266
|
+
}))
|
|
267
|
+
.toSorted((a, b) => a.number - b.number),
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
const [only] = pulls;
|
|
272
|
+
const state = candidateState(only);
|
|
273
|
+
if (state !== "merged") return { ok: true, value: { kind: state, pr: detail(only) } };
|
|
274
|
+
// The list omits the merger; only the single-PR endpoint carries it.
|
|
275
|
+
const full = await get<GithubPull>(`${pullRepo}/pulls/${only.number}`, "Pull requests: read");
|
|
276
|
+
return { ok: true, value: { kind: "merged", pr: detail(full.ok ? full.value : only) } };
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
}
|