@uniqbit/mate-core 1.0.0-canary.0 → 1.0.0-canary.3
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/hooks.json +10 -1
- package/claude-plugin/hooks/tokensave-route.mjs +52 -0
- package/opencode-plugin/src/server.ts +4 -0
- package/opencode-plugin/src/tui.tsx +3 -1
- package/opencode-plugin/tui.tsx +4 -1
- package/package.json +45 -16
- package/src/brand/terminal.ts +5 -0
- package/src/cli/commands/artifact/apply-context.ts +275 -0
- package/src/cli/commands/artifact/artifact.ts +4 -0
- package/src/cli/commands/artifact/delivery/archive.ts +13 -5
- package/src/cli/commands/artifact/delivery/environment.ts +36 -13
- package/src/cli/commands/artifact/delivery/link.ts +35 -15
- package/src/cli/commands/artifact/delivery/output.ts +31 -0
- package/src/cli/commands/artifact/finish/command.ts +50 -5
- package/src/cli/commands/artifact/finish/engine.ts +44 -11
- package/src/cli/commands/artifact/finish/git.ts +132 -19
- package/src/cli/commands/artifact/finish/openspec.ts +6 -1
- package/src/cli/commands/artifact/finish/worktree-cleanup.ts +92 -0
- package/src/cli/commands/cap/index-cmd.ts +64 -15
- package/src/cli/commands/cap/tokensave.ts +7 -5
- package/src/cli/commands/companion/link.ts +14 -1
- package/src/cli/commands/companion/open.ts +16 -11
- 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 +74 -12
- package/src/cli/commands/doctor.ts +20 -5
- package/src/cli/commands/factory/factory.ts +301 -0
- package/src/cli/commands/install.ts +133 -9
- package/src/cli/commands/launch/shared.ts +16 -11
- package/src/cli/commands/report/index.ts +20 -1
- package/src/cli/commands/session/context.ts +102 -0
- package/src/cli/commands/setup.ts +44 -10
- package/src/cli/commands/studio/factory-credential.ts +49 -0
- package/src/cli/commands/studio/index.ts +29 -2
- package/src/cli/commands/studio/payload.ts +249 -15
- package/src/cli/commands/studio/routes.ts +41 -8
- package/src/cli/commands/studio/selection.ts +142 -16
- package/src/cli/commands/studio/server.ts +403 -364
- package/src/cli/commands/studio/services.ts +60 -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 +85 -15
- package/src/cli/commands/studio/views/model.ts +18 -0
- package/src/cli/commands/studio/views/vault/markdown-tree.ts +267 -0
- package/src/cli/commands/studio/views/vault/view.ts +185 -0
- package/src/cli/commands/studio/workset-session.ts +131 -0
- package/src/cli/commands/unwrap.ts +8 -0
- package/src/cli/commands/update.ts +27 -1
- package/src/cli/commands/working/cleanup.ts +10 -1
- 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 +356 -0
- 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 +18 -0
- package/src/cli/parse-flags.ts +9 -1
- package/src/cli/repo-list-table.tsx +2 -0
- package/src/cli/setup-selector.tsx +79 -20
- package/src/cli/usage.ts +11 -1
- package/src/create-mate.ts +5 -4
- package/src/hooks/tokensave-route.ts +26 -0
- package/src/lib/apply-context/fingerprint.ts +174 -0
- package/src/lib/apply-context/protocol.ts +193 -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 +13 -11
- package/src/lib/delivery/archive-change.ts +14 -2
- package/src/lib/delivery/branches.ts +29 -5
- package/src/lib/delivery/environment.ts +7 -1
- package/src/lib/delivery/forge.ts +2 -2
- package/src/lib/delivery/merge-git.ts +261 -0
- package/src/lib/delivery/overlap.ts +11 -4
- package/src/lib/delivery/record-delivery.ts +97 -10
- package/src/lib/delivery/record.ts +67 -7
- package/src/lib/delivery/refresh.ts +104 -10
- package/src/lib/delivery/repository-access.ts +46 -2
- package/src/lib/delivery/resolve-branch.ts +162 -0
- package/src/lib/delivery/token.ts +7 -41
- package/src/lib/factory/attach-client.ts +113 -0
- package/src/lib/factory/attach.ts +178 -0
- package/src/lib/factory/broker.ts +190 -0
- package/src/lib/factory/bun-commands.ts +39 -0
- package/src/lib/factory/client.ts +92 -0
- package/src/lib/factory/command.ts +61 -0
- package/src/lib/factory/credential-store.ts +153 -0
- package/src/lib/factory/frames.ts +77 -0
- package/src/lib/factory/ids.ts +58 -0
- package/src/lib/factory/keyed-serial.ts +27 -0
- package/src/lib/factory/outcomes/actions.ts +114 -0
- package/src/lib/factory/outcomes/index.ts +381 -0
- package/src/lib/factory/outcomes/lifecycle.ts +205 -0
- package/src/lib/factory/outcomes/runs.ts +81 -0
- package/src/lib/factory/outcomes/sessions.ts +38 -0
- package/src/lib/factory/prepare.ts +49 -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 +416 -0
- package/src/lib/factory/runner/state.ts +233 -0
- package/src/lib/factory/runner/workflow.ts +542 -0
- package/src/lib/factory/runtime.ts +972 -0
- package/src/lib/factory/sandbox.ts +292 -0
- package/src/lib/factory/worktree-branch.ts +17 -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/orchestrator/adapters/base.ts +55 -22
- package/src/lib/orchestrator/adapters/claude.ts +6 -1
- package/src/lib/orchestrator/config-store.ts +3 -2
- package/src/lib/orchestrator/editor.ts +29 -23
- package/src/lib/orchestrator/projection-entries.ts +56 -21
- package/src/lib/orchestrator/projection-opencode-copies.ts +32 -15
- package/src/lib/orchestrator/projection-openspec-store.ts +54 -9
- package/src/lib/orchestrator/projection-types.ts +33 -1
- package/src/lib/orchestrator/session-context-link.ts +67 -0
- package/src/lib/orchestrator/setup-compatibilities.ts +55 -12
- package/src/lib/orchestrator/types.ts +5 -0
- package/src/lib/orchestrator/working-repo-projection.ts +50 -7
- package/src/lib/orchestrator/workspace-document.ts +105 -0
- package/src/lib/package-paths.ts +29 -0
- package/src/lib/runtime-directory-refresh.ts +17 -1
- package/src/lib/workset/record.ts +513 -0
- package/src/lib/workset/repositories.ts +55 -0
- package/src/lib/workset/stage.ts +148 -0
- package/src/lib/workset/stages.ts +113 -0
- package/src/lib/workset/worktree-index.ts +116 -0
- package/src/lib/workset/worktree.ts +830 -0
- package/src/opencode/companion-hooks.ts +45 -2
- package/src/opencode/enter-worktree.ts +72 -0
- package/src/opencode/tui.tsx +21 -26
- package/src/plugins.ts +1 -0
- package/src/runtime/claude-delivery-plan.ts +22 -5
- package/src/runtime/companion-git.ts +52 -10
- package/src/runtime/companion-guidance.ts +7 -7
- package/src/runtime/companion-lock.ts +30 -7
- package/src/runtime/env.ts +48 -3
- package/src/runtime/git-layout.ts +219 -0
- package/src/runtime/index.ts +24 -0
- package/src/runtime/physical-path.ts +111 -0
- package/src/runtime/policy.ts +36 -2
- package/src/runtime/runtime-directory.ts +5 -0
- package/src/runtime/secret-guard.ts +19 -5
- package/src/runtime/secret-patterns.ts +267 -34
- package/src/runtime/session-context.ts +98 -0
- package/src/runtime/tokensave-route.ts +152 -0
- package/src/runtime/wrap-state.ts +24 -16
- package/src/studio.ts +124 -0
- package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +10 -8
- package/src/templates/capabilities/openspec-cap/mate-v1/schema.yaml +16 -98
- package/src/templates/capabilities/openspec-cap/openspec-conventions.yaml +10 -2
- package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +76 -18
- 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 +2 -0
- package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +32 -5
- package/src/templates/mate-skills/agents/mate-backfill-spec/SKILL.md +8 -1
- package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +16 -1
- package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +22 -6
- package/src/templates/mate-skills/agents/mate-explore-change/references/openspec-explore.md +2 -0
- package/src/templates/mate-skills/agents/mate-grill-me/SKILL.md +8 -1
- 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 +7 -0
- package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +55 -50
- package/src/templates/mate-skills/agents/mate-propose-change/references/mate-revise.md +47 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-propose.md +2 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-update-change.md +2 -0
- package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +29 -10
- package/src/templates/mate-skills/agents/mate-publish-artifact/references/openspec.md +4 -2
- package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +21 -0
- package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +13 -0
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +76 -18
- 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 +2 -0
- package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +32 -5
- package/src/templates/mate-skills/claude/mate-backfill-spec/SKILL.md +8 -1
- package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +16 -1
- package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +22 -6
- package/src/templates/mate-skills/claude/mate-explore-change/references/openspec-explore.md +2 -0
- package/src/templates/mate-skills/claude/mate-grill-me/SKILL.md +8 -1
- 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 +7 -0
- package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +55 -50
- package/src/templates/mate-skills/claude/mate-propose-change/references/mate-revise.md +47 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-propose.md +2 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-update-change.md +2 -0
- package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +29 -10
- package/src/templates/mate-skills/claude/mate-publish-artifact/references/openspec.md +4 -2
- package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +21 -0
- package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +13 -0
- package/src/templates/mate-skills/openspec-references.ts +2 -0
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +364 -224
- package/src/tools/setup/capabilities/companion-mentions.ts +27 -0
- package/src/tools/setup/capabilities/context-mode.ts +34 -5
- package/src/tools/setup/capabilities/graphify-secrets.ts +2 -14
- package/src/tools/setup/capabilities/graphify.ts +34 -7
- package/src/tools/setup/capabilities/openspec.ts +12 -2
- package/src/tools/setup/capabilities/react-doctor.ts +8 -1
- package/src/tools/setup/capabilities/rtk.ts +4 -0
- package/src/tools/setup/capabilities/tokensave.ts +77 -68
- package/src/tools/setup/engine.ts +3 -2
- package/src/tools/setup/install-contract.ts +8 -0
- package/src/tools/setup/mate-skill-copies.ts +51 -0
- package/src/tools/setup/package-managers/uv.ts +73 -11
- package/src/tools/setup/plugin.ts +5 -0
- package/src/tools/setup/providers/claude-plugin-hooks.ts +12 -0
- package/src/tools/setup/providers/claude-worktree-plugins.ts +122 -0
- package/src/tools/setup/providers/claude.ts +11 -5
- package/src/tools/setup/utils.ts +4 -0
- package/src/tools/setup/working-repo-cleanup.ts +29 -1
- package/src/tools/setup/working-repo-local-state.ts +252 -75
- package/src/tools/setup.ts +57 -16
- package/studio-dist/client/assets/companion-view-Csva26Ir.js +1 -0
- package/studio-dist/client/assets/delivery-path-DJMpRmiY.js +1 -0
- package/studio-dist/client/assets/dist-Dm7MtyHc.js +5 -0
- package/studio-dist/client/assets/factory-B7l9ZQyx.js +4 -0
- package/studio-dist/client/assets/index-n6uo_92S.js +40 -0
- package/studio-dist/client/assets/preload-helper-BLdHbfdN.js +1 -0
- package/studio-dist/client/assets/prepaint-CD5OpmTM.js +24 -0
- package/studio-dist/client/assets/queries-CN3JwMBX.js +1 -0
- package/studio-dist/client/assets/react-CabXf2Ds.js +1 -0
- package/studio-dist/client/assets/report-time-Dc-KOqQu.js +1 -0
- package/studio-dist/client/assets/reports-C01RsnMA.js +1 -0
- package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +1 -0
- package/studio-dist/client/assets/routes-4pbC-2Hj.js +1 -0
- package/studio-dist/client/assets/skills-CihQganl.js +1 -0
- package/studio-dist/client/assets/spec-areas-C2L48N4C.js +1 -0
- package/studio-dist/client/assets/specs-D24_35_K.js +1 -0
- package/studio-dist/client/assets/studio-DKxfi691.css +1 -0
- package/studio-dist/client/assets/studio-queries-rvbJupCy.js +3 -0
- package/studio-dist/client/assets/terminal-eU5fzQzv.css +1 -0
- package/studio-dist/client/assets/vault-Bd4CQiTK.js +1 -0
- package/studio-dist/client/assets/warnings-V_Ys51wJ.js +1 -0
- package/studio-dist/client/assets/wasm-inline-C2en61B5.js +1 -0
- package/studio-dist/client/assets/workflow-BJejeVwQ.js +1 -0
- package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-BQKuMdJW.js +3881 -0
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +85 -0
- package/studio-dist/server/assets/actions-Bvgj9eb8.js +54 -0
- package/studio-dist/server/assets/actions-D8erOphH.js +44 -0
- package/studio-dist/server/assets/companion-view-aBady57v.js +33 -0
- package/studio-dist/server/assets/createServerFn-F5sAOF8V.js +459 -0
- package/studio-dist/server/assets/createServerRpc-tK2lE9R2.js +11 -0
- package/studio-dist/server/assets/delivery-path-BkKNjgkf.js +778 -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-D6xnjedJ.js +2385 -0
- package/studio-dist/server/assets/factory-DT3UzHlh.js +68 -0
- package/studio-dist/server/assets/model-PyPALjii.js +18 -0
- package/studio-dist/server/assets/prepaint-BMke0fo1.js +41 -0
- package/studio-dist/server/assets/queries-Ag2iL8q2.js +107 -0
- package/studio-dist/server/assets/react-COs0LHn-.js +51 -0
- package/studio-dist/server/assets/report-time-DAfzln-N.js +8 -0
- package/studio-dist/server/assets/reports-BnUNJVtx.js +126 -0
- package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +34 -0
- package/studio-dist/server/assets/router-BH--drIx.js +4298 -0
- package/studio-dist/server/assets/routes-khSDK1bV.js +361 -0
- package/studio-dist/server/assets/search-JAKurDNh.js +36 -0
- package/studio-dist/server/assets/shell-CboT2f66.js +51 -0
- package/studio-dist/server/assets/skills-MWYnWoKs.js +106 -0
- package/studio-dist/server/assets/spec-areas-DcnO6vW-.js +16 -0
- package/studio-dist/server/assets/specs-DE3w8hZP.js +155 -0
- package/studio-dist/server/assets/start-BW5ovN0k.js +33 -0
- package/studio-dist/server/assets/studio-BeltxxKt.js +216 -0
- package/studio-dist/server/assets/studio-queries-CLnP9kGu.js +3365 -0
- package/studio-dist/server/assets/utils-C9CX1kcy.js +221 -0
- package/studio-dist/server/assets/vault-BGulVoNh.js +70 -0
- package/studio-dist/server/assets/vault-CuyyhLyB.js +832 -0
- package/studio-dist/server/assets/views-Bd7cRr27.js +82 -0
- package/studio-dist/server/assets/warnings-BH05rOuG.js +15 -0
- package/studio-dist/server/assets/wasm-inline-CNeBKGwC.js +3 -0
- package/studio-dist/server/assets/workflow-BSuIKWqH.js +42 -0
- package/studio-dist/server/server.js +16220 -0
- package/src/cli/commands/studio/client-asset.ts +0 -16
- package/src/cli/commands/studio/views/client.ts +0 -44
- 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 -102
- package/src/cli/commands/studio/views/dashboard/index.tsx +0 -19
- package/src/cli/commands/studio/views/document.tsx +0 -910
- package/src/cli/commands/studio/views/error.tsx +0 -20
- package/src/cli/commands/studio/views/markdown.tsx +0 -250
- package/src/cli/commands/studio/views/palette.ts +0 -134
- package/src/cli/commands/studio/views/reports/index.tsx +0 -44
- package/src/cli/commands/studio/views/selection-fields.tsx +0 -14
- package/src/cli/commands/studio/views/skills/index.tsx +0 -68
- package/src/cli/commands/studio/views/specs/index.tsx +0 -149
- package/src/cli/commands/studio/views/studio-client/actions.ts +0 -51
- package/src/cli/commands/studio/views/studio-client/companion.ts +0 -13
- package/src/cli/commands/studio/views/studio-client/index.ts +0 -32
- package/src/cli/commands/studio/views/studio-client/keys.ts +0 -3
- package/src/cli/commands/studio/views/studio-client/main.ts +0 -3
- package/src/cli/commands/studio/views/studio-client/page.ts +0 -146
- package/src/cli/commands/studio/views/studio-client/panels.ts +0 -57
- package/src/cli/commands/studio/views/studio-client/reports.ts +0 -122
- package/src/cli/commands/studio/views/studio-client/theme.ts +0 -63
- package/src/cli/commands/studio/views/studio-client/vault-editor.ts +0 -166
- package/src/cli/commands/studio/views/studio-client/vault-pane.ts +0 -202
- package/src/cli/commands/studio/views/studio-client/vault-tree.ts +0 -258
- package/src/cli/commands/studio/views/studio-client.generated.ts +0 -2
- package/src/cli/commands/studio/views/styles.ts +0 -530
- package/src/cli/commands/studio/views/terminal.tsx +0 -484
- package/src/cli/commands/studio/views/vault/state.ts +0 -41
- package/src/cli/commands/studio/views/warnings.tsx +0 -21
- package/src/cli/commands/studio/views/workflow/delivery-path.tsx +0 -370
- package/src/cli/commands/studio/views/workflow/graph.ts +0 -220
- package/src/cli/commands/studio/views/workflow/index.tsx +0 -20
- package/src/cli/commands/studio/views/workflow/steps.ts +0 -278
- package/src/lib/components/theme.ts +0 -2
- package/src/tools/setup/git-utils.ts +0 -30
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
fingerprintArtifacts,
|
|
6
|
+
type FingerprintOptions,
|
|
7
|
+
type FingerprintResult,
|
|
8
|
+
} from "../../../lib/apply-context/fingerprint";
|
|
9
|
+
import {
|
|
10
|
+
compactableTasks,
|
|
11
|
+
computeDigest,
|
|
12
|
+
encodeApplyContext,
|
|
13
|
+
fullReason,
|
|
14
|
+
isWellFormedDigest,
|
|
15
|
+
type ApplyPayload,
|
|
16
|
+
type DigestIdentity,
|
|
17
|
+
} from "../../../lib/apply-context/protocol";
|
|
18
|
+
import { hasOpenspecCapability } from "../../../lib/orchestrator/capabilities";
|
|
19
|
+
import {
|
|
20
|
+
resolveForCapability,
|
|
21
|
+
type LaunchContext,
|
|
22
|
+
} from "../../../lib/orchestrator/framework-context";
|
|
23
|
+
import type { CapabilityConfig } from "../../../lib/orchestrator/types";
|
|
24
|
+
import { WorkingRepoRequiredError } from "../../../lib/orchestrator/types";
|
|
25
|
+
import { locateOpenSpec, runOpenSpec, type RunOpenSpec } from "../../../lib/openspec-cli";
|
|
26
|
+
import { generatedHeader } from "../../../runtime/projection";
|
|
27
|
+
import { parseSecretsConfig, type SecretPolicy } from "../../../runtime/secret-patterns";
|
|
28
|
+
import { type BooleanFlagSet, parseFlags, positionalArgs, stringFlag } from "../../parse-flags";
|
|
29
|
+
import { ensureUnambiguousCompanion } from "../shared/companion-selection";
|
|
30
|
+
import { commandOutput } from "./delivery/output";
|
|
31
|
+
|
|
32
|
+
export interface ApplyContextCommandDeps {
|
|
33
|
+
cwd?: () => string;
|
|
34
|
+
ensureUnambiguousCompanion?: (cwd: string) => Promise<boolean>;
|
|
35
|
+
resolveContext?: (cwd: string) => Promise<LaunchContext>;
|
|
36
|
+
loadCapabilities?: (context: LaunchContext) => Promise<CapabilityConfig[]>;
|
|
37
|
+
loadSecretPolicy?: (context: LaunchContext) => Promise<SecretPolicy>;
|
|
38
|
+
run?: RunOpenSpec;
|
|
39
|
+
/** The upstream producer's identity; a new OpenSpec version invalidates every baseline. */
|
|
40
|
+
producer?: () => Record<string, unknown>;
|
|
41
|
+
stdout?: (line: string) => void;
|
|
42
|
+
stderr?: (line: string) => void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const BOOLEAN_FLAGS: BooleanFlagSet = new Set(["json"]);
|
|
46
|
+
|
|
47
|
+
/** Upper bound on one upstream call, as Studio uses; a hung CLI fails the command. */
|
|
48
|
+
const OPENSPEC_TIMEOUT_MS = 60_000;
|
|
49
|
+
|
|
50
|
+
/** Attempts before a context that keeps changing during collection is sent without a digest. */
|
|
51
|
+
const COLLECTION_ATTEMPTS = 3;
|
|
52
|
+
|
|
53
|
+
async function defaultLoadCapabilities(context: LaunchContext): Promise<CapabilityConfig[]> {
|
|
54
|
+
return (await context.configStore.load()).capabilities ?? [];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function defaultLoadSecretPolicy(context: LaunchContext): Promise<SecretPolicy> {
|
|
58
|
+
const config = (await context.configStore.load()) as { secrets?: unknown };
|
|
59
|
+
return parseSecretsConfig(config.secrets);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function isUnder(child: string, root: string): boolean {
|
|
63
|
+
const relative = path.relative(root, child);
|
|
64
|
+
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function physical(dir: string): Promise<string> {
|
|
68
|
+
return fs.realpath(dir).catch(() => path.resolve(dir));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The directory the wrapped `openspec instructions` runs in: the Working Repository
|
|
73
|
+
* root when the caller is inside it, outside the companion, and the root carries
|
|
74
|
+
* Mate's store pointer; otherwise the companion. Mirrors `wrappers/bin/openspec`.
|
|
75
|
+
*/
|
|
76
|
+
export async function wrappedOpenSpecCwd(
|
|
77
|
+
companionPath: string,
|
|
78
|
+
repoPath: string | undefined,
|
|
79
|
+
cwd: string,
|
|
80
|
+
): Promise<{ cwd: string; notice?: string }> {
|
|
81
|
+
if (!repoPath) return { cwd: companionPath };
|
|
82
|
+
const repoRoot = await physical(repoPath);
|
|
83
|
+
const here = await physical(cwd);
|
|
84
|
+
const companionRoot = await physical(companionPath);
|
|
85
|
+
if (!isUnder(here, repoRoot) || isUnder(here, companionRoot)) return { cwd: companionPath };
|
|
86
|
+
const pointer = path.join(repoRoot, "openspec", "config.yaml");
|
|
87
|
+
const first = await fs
|
|
88
|
+
.readFile(pointer, "utf8")
|
|
89
|
+
.then((text) => text.split("\n")[0])
|
|
90
|
+
.catch(() => undefined);
|
|
91
|
+
if (first !== undefined) {
|
|
92
|
+
return first === generatedHeader() ? { cwd: repoRoot } : { cwd: companionPath };
|
|
93
|
+
}
|
|
94
|
+
const hasYml = await fs
|
|
95
|
+
.access(path.join(repoRoot, "openspec", "config.yml"))
|
|
96
|
+
.then(() => true)
|
|
97
|
+
.catch(() => false);
|
|
98
|
+
if (hasYml) return { cwd: companionPath };
|
|
99
|
+
return {
|
|
100
|
+
cwd: companionPath,
|
|
101
|
+
notice: `openspec: no OpenSpec store pointer in ${repoRoot}, so edits are scoped to the companion — run \`mate wrap\` to enable Working Repository edit roots`,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function failureDetail(stdout: string, stderr: string): string {
|
|
106
|
+
return (stderr.trim() || stdout.trim()).split("\n").slice(-3).join("; ");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function parsePayload(stdout: string): ApplyPayload | undefined {
|
|
110
|
+
const text = stdout.trim();
|
|
111
|
+
const candidates = [text, text.slice(Math.max(0, text.indexOf("{")))];
|
|
112
|
+
for (const candidate of candidates) {
|
|
113
|
+
try {
|
|
114
|
+
const value: unknown = JSON.parse(candidate);
|
|
115
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
116
|
+
return value as ApplyPayload;
|
|
117
|
+
}
|
|
118
|
+
return undefined;
|
|
119
|
+
} catch {
|
|
120
|
+
// Try the next candidate: text before the JSON object, such as a notice.
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function sameHashes(a: FingerprintResult, b: FingerprintResult): boolean {
|
|
127
|
+
if (!a.ok || !b.ok) return false;
|
|
128
|
+
return JSON.stringify(a.raw) === JSON.stringify(b.raw);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
interface Collected {
|
|
132
|
+
payload: ApplyPayload;
|
|
133
|
+
/** Null when compaction is unavailable; `limitation` then says why. */
|
|
134
|
+
digest: string | null;
|
|
135
|
+
limitation?: string;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Fetches the payload and fingerprints its artifacts twice; a digest only when both passes
|
|
140
|
+
* agree. Retries a context that changes during collection. A string is an upstream failure.
|
|
141
|
+
*/
|
|
142
|
+
async function collect(
|
|
143
|
+
fetchPayload: () => Promise<ApplyPayload | string>,
|
|
144
|
+
identity: DigestIdentity,
|
|
145
|
+
options: FingerprintOptions,
|
|
146
|
+
): Promise<Collected | string> {
|
|
147
|
+
for (let attempt = 1; ; attempt++) {
|
|
148
|
+
const payload = await fetchPayload();
|
|
149
|
+
if (typeof payload === "string") return payload;
|
|
150
|
+
const shape = compactableTasks(payload);
|
|
151
|
+
if (!shape.ok) {
|
|
152
|
+
// A blocked payload goes out in full anyway; its missing tasks are no limitation.
|
|
153
|
+
const limitation = fullReason(payload) === null ? shape.reason : undefined;
|
|
154
|
+
return { payload, digest: null, limitation };
|
|
155
|
+
}
|
|
156
|
+
let limitation: string;
|
|
157
|
+
const first = await fingerprintArtifacts(payload, options);
|
|
158
|
+
if (first.ok) {
|
|
159
|
+
const second = await fingerprintArtifacts(payload, options);
|
|
160
|
+
if (sameHashes(first, second)) {
|
|
161
|
+
return { payload, digest: computeDigest(identity, payload, first.fingerprints) };
|
|
162
|
+
}
|
|
163
|
+
limitation = "context changed while it was collected";
|
|
164
|
+
} else {
|
|
165
|
+
limitation = first.reason;
|
|
166
|
+
// A state mismatch can be a checkbox written between the upstream read and ours.
|
|
167
|
+
if (!first.reason.includes("state differs")) return { payload, digest: null, limitation };
|
|
168
|
+
}
|
|
169
|
+
if (attempt === COLLECTION_ATTEMPTS) return { payload, digest: null, limitation };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @command mate artifact apply-context <change>
|
|
175
|
+
* @description Fetches fresh `openspec instructions apply --json` for a change, resolved as
|
|
176
|
+
* the wrapped `openspec` resolves it, and wraps it in a versioned envelope for Mate's opt-in
|
|
177
|
+
* compact apply transport. Without a matching `--since` it emits the full upstream payload
|
|
178
|
+
* with a baseline `digest`; with one it emits only `state`, `progress`, and every ordered
|
|
179
|
+
* task `{id, done}`. Warnings, a blocked state, missing artifacts, and any change to the
|
|
180
|
+
* static payload, referenced artifacts, edit context, or OpenSpec version force a full
|
|
181
|
+
* envelope. Read-only: no writes, no forge or network access, no initialization.
|
|
182
|
+
* @flags
|
|
183
|
+
* - `--json` — required; emit the envelope as JSON.
|
|
184
|
+
* - `--since <digest>` — the digest of a full envelope still held in full by the caller.
|
|
185
|
+
* @remarks Upstream failures, timeouts, and malformed output exit non-zero; nothing is cached
|
|
186
|
+
* or inferred. A full envelope with `digest: null` names its `limitation`, such as an
|
|
187
|
+
* unreadable context file or an ambiguous task location.
|
|
188
|
+
*/
|
|
189
|
+
export async function runArtifactApplyContextCommand(
|
|
190
|
+
argv: string[],
|
|
191
|
+
deps: ApplyContextCommandDeps = {},
|
|
192
|
+
): Promise<void> {
|
|
193
|
+
const { emitOut, emitErr, refuse } = commandOutput(deps);
|
|
194
|
+
const flags = parseFlags(argv, BOOLEAN_FLAGS);
|
|
195
|
+
const changes = positionalArgs(argv, BOOLEAN_FLAGS);
|
|
196
|
+
if (changes.length !== 1) return refuse("mate: artifact apply-context requires one change name.");
|
|
197
|
+
if (flags.json !== true) return refuse("mate: artifact apply-context requires --json.");
|
|
198
|
+
const since = flags.since === undefined ? undefined : stringFlag(flags.since);
|
|
199
|
+
if (flags.since !== undefined && since === undefined) {
|
|
200
|
+
return refuse("mate: --since expects a digest.");
|
|
201
|
+
}
|
|
202
|
+
const change = changes[0];
|
|
203
|
+
|
|
204
|
+
const cwd = (deps.cwd ?? (() => process.cwd()))();
|
|
205
|
+
if (!(await (deps.ensureUnambiguousCompanion ?? ensureUnambiguousCompanion)(cwd))) {
|
|
206
|
+
return refuse();
|
|
207
|
+
}
|
|
208
|
+
let context: LaunchContext;
|
|
209
|
+
try {
|
|
210
|
+
context = await (deps.resolveContext ?? ((dir: string) => resolveForCapability(dir)))(cwd);
|
|
211
|
+
} catch (err) {
|
|
212
|
+
if (err instanceof WorkingRepoRequiredError) return refuse(err.message);
|
|
213
|
+
throw err;
|
|
214
|
+
}
|
|
215
|
+
const capabilities = await (deps.loadCapabilities ?? defaultLoadCapabilities)(context);
|
|
216
|
+
if (!hasOpenspecCapability(capabilities)) {
|
|
217
|
+
return refuse("mate: the openspec capability must be enabled to read apply context.");
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const repoPath = context.repository?.path ?? process.env.MATE_REPO_PATH;
|
|
221
|
+
const target = await wrappedOpenSpecCwd(context.companionPath, repoPath, cwd);
|
|
222
|
+
if (target.notice) emitErr(target.notice);
|
|
223
|
+
const run = deps.run ?? runOpenSpec;
|
|
224
|
+
const args = ["instructions", "apply", "--change", change, "--json"];
|
|
225
|
+
|
|
226
|
+
const fetchPayload = async (): Promise<ApplyPayload | string> => {
|
|
227
|
+
const output = await run(args, { cwd: target.cwd, timeout: OPENSPEC_TIMEOUT_MS });
|
|
228
|
+
if (output.missing) return `mate: ${output.stderr}`;
|
|
229
|
+
if (output.code === null) return "mate: openspec instructions apply timed out.";
|
|
230
|
+
if (output.code !== 0) {
|
|
231
|
+
const detail = failureDetail(output.stdout, output.stderr);
|
|
232
|
+
return `mate: openspec instructions apply failed (exit code ${output.code})${detail ? `: ${detail}` : ""}`;
|
|
233
|
+
}
|
|
234
|
+
return (
|
|
235
|
+
parsePayload(output.stdout) ?? "mate: openspec instructions apply returned malformed JSON."
|
|
236
|
+
);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const producer = (
|
|
240
|
+
deps.producer ??
|
|
241
|
+
(() => {
|
|
242
|
+
const location = locateOpenSpec();
|
|
243
|
+
return { openspec: "missing" in location ? null : (location.version ?? null) };
|
|
244
|
+
})
|
|
245
|
+
)();
|
|
246
|
+
const identity: DigestIdentity = {
|
|
247
|
+
producer,
|
|
248
|
+
editContext: {
|
|
249
|
+
change,
|
|
250
|
+
cwd: await physical(target.cwd),
|
|
251
|
+
companion: await physical(context.companionPath),
|
|
252
|
+
repository: repoPath ? await physical(repoPath) : null,
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
const secretPolicy = await (deps.loadSecretPolicy ?? defaultLoadSecretPolicy)(context);
|
|
256
|
+
const allowedRoots = [context.companionPath, ...(repoPath ? [repoPath] : [])];
|
|
257
|
+
|
|
258
|
+
const collected = await collect(fetchPayload, identity, { allowedRoots, secretPolicy });
|
|
259
|
+
if (typeof collected === "string") return refuse(collected);
|
|
260
|
+
const { payload, digest, limitation } = collected;
|
|
261
|
+
|
|
262
|
+
if (since !== undefined && !isWellFormedDigest(since)) {
|
|
263
|
+
emitErr("warning: --since is not a well-formed digest; sending the full context.");
|
|
264
|
+
}
|
|
265
|
+
const envelope = encodeApplyContext({
|
|
266
|
+
payload,
|
|
267
|
+
digest,
|
|
268
|
+
limitation,
|
|
269
|
+
...(since !== undefined && isWellFormedDigest(since) ? { since } : {}),
|
|
270
|
+
});
|
|
271
|
+
if (envelope.mode === "full" && envelope.limitation) {
|
|
272
|
+
emitErr(`warning: compact updates are unavailable: ${envelope.limitation}`);
|
|
273
|
+
}
|
|
274
|
+
emitOut(JSON.stringify(envelope));
|
|
275
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { usage } from "../../usage";
|
|
2
|
+
import { runArtifactApplyContextCommand } from "./apply-context";
|
|
2
3
|
import { runArtifactArchiveCommand } from "./delivery/archive";
|
|
3
4
|
import { runArtifactLinkCommand } from "./delivery/link";
|
|
4
5
|
import { runArtifactPublishCommand } from "./finish";
|
|
@@ -38,6 +39,9 @@ export async function runArtifactCommand(
|
|
|
38
39
|
case "archive":
|
|
39
40
|
await runArtifactArchiveCommand(argv);
|
|
40
41
|
return;
|
|
42
|
+
case "apply-context":
|
|
43
|
+
await runArtifactApplyContextCommand(argv);
|
|
44
|
+
return;
|
|
41
45
|
default:
|
|
42
46
|
console.error(`Unknown artifact command: ${subcommand ?? ""}`);
|
|
43
47
|
console.error(usage());
|
|
@@ -17,6 +17,7 @@ import { resolveDeliveryEnvironment, type DeliveryEnvironmentDeps } from "./envi
|
|
|
17
17
|
import {
|
|
18
18
|
commandOutput,
|
|
19
19
|
renderDelivery,
|
|
20
|
+
renderOutcome,
|
|
20
21
|
sharedRefusalMessage,
|
|
21
22
|
unscopedDeliveryWarning,
|
|
22
23
|
} from "./output";
|
|
@@ -27,7 +28,7 @@ export interface ArchiveCommandDeps
|
|
|
27
28
|
stderr?: (line: string) => void;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
const BOOLEAN_FLAGS: BooleanFlagSet = new Set(["json", "direct", "skip-branch"]);
|
|
31
|
+
const BOOLEAN_FLAGS: BooleanFlagSet = new Set(["json", "direct", "skip-branch", "fetch"]);
|
|
31
32
|
|
|
32
33
|
function refusalMessage(refusal: DeliveryRefusal): string {
|
|
33
34
|
if (refusal.reason === "unknown-change") {
|
|
@@ -41,6 +42,7 @@ function renderHuman(result: ArchiveResult): string[] {
|
|
|
41
42
|
return [
|
|
42
43
|
result.message,
|
|
43
44
|
...result.record.deliveries.map(renderDelivery),
|
|
45
|
+
...result.outcomes.flatMap(renderOutcome),
|
|
44
46
|
` delivery: ${result.settlement.status}`,
|
|
45
47
|
];
|
|
46
48
|
}
|
|
@@ -49,19 +51,23 @@ function renderHuman(result: ArchiveResult): string[] {
|
|
|
49
51
|
* @command mate artifact archive <change>
|
|
50
52
|
* @description Archives an active change whether or not its delivery is merged, so a
|
|
51
53
|
* feature's later changes build on its canonical specs. Writes overlap, dependency, and
|
|
52
|
-
* incomplete-planning warnings to stderr before archiving, refreshes merge state from the
|
|
53
|
-
* is available, always leaves a `delivery.yaml` (unlinked when none was recorded), then
|
|
54
|
+
* incomplete-planning warnings to stderr before archiving, refreshes merge state from the
|
|
55
|
+
* forge when a token is available and from a local checkout otherwise, always leaves a `delivery.yaml` (unlinked when none was recorded), then
|
|
54
56
|
* runs `openspec archive` with the bundled CLI. Merge state is reported, never a refusal.
|
|
55
57
|
* @flags
|
|
56
58
|
* - `--repository <org/repo>` — the delivery `--branch` or `--not-applicable` records; defaults
|
|
57
59
|
* to the Working Repository.
|
|
58
60
|
* - `--branch <branch>` / `--direct` — record the delivery branch first, as `artifact link`.
|
|
59
61
|
* - `--not-applicable <reason>` — record that no branch delivers this change.
|
|
60
|
-
* - `--skip-branch` — archive with an unlinked record when the user skips the
|
|
62
|
+
* - `--skip-branch` — archive with an unlinked record marked `skipped` when the user skips the
|
|
63
|
+
* question, so publication asks again even when the record holds a ticket.
|
|
64
|
+
* - `--fetch` — fetch the default and delivery branches before the merge check even when the
|
|
65
|
+
* companion's Git mode is not `auto`.
|
|
61
66
|
* - `--json` — emit an {@link ArchiveResult}.
|
|
62
67
|
* @remarks Without a recorded delivery and none of the branch flags, nothing is archived:
|
|
63
68
|
* the result is `needs-branch`, a question rather than a refusal (exit 0), with
|
|
64
|
-
*
|
|
69
|
+
* the change's resolved Delivery Branch suggested before legacy `change/<change-name>`
|
|
70
|
+
* when either exists, so the caller can ask the user.
|
|
65
71
|
*/
|
|
66
72
|
export async function runArtifactArchiveCommand(
|
|
67
73
|
argv: string[],
|
|
@@ -99,6 +105,7 @@ export async function runArtifactArchiveCommand(
|
|
|
99
105
|
...(repository ? { repository } : {}),
|
|
100
106
|
...(delivery ? { delivery } : {}),
|
|
101
107
|
skipBranch: skip,
|
|
108
|
+
fetch: flags.fetch === true,
|
|
102
109
|
},
|
|
103
110
|
{
|
|
104
111
|
...deps,
|
|
@@ -111,6 +118,7 @@ export async function runArtifactArchiveCommand(
|
|
|
111
118
|
if ("refusal" in outcome) return refuse(refusalMessage(outcome.refusal));
|
|
112
119
|
|
|
113
120
|
const { result } = outcome;
|
|
121
|
+
for (const diagnostic of result.diagnostics) emitErr(`warning: ${diagnostic}`);
|
|
114
122
|
if (result.status === "failed") process.exitCode = 1;
|
|
115
123
|
if (json) emitOut(JSON.stringify(result));
|
|
116
124
|
else for (const line of renderHuman(result)) emitOut(line);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
workingRepoGit,
|
|
3
3
|
configuredProtectedPatterns,
|
|
4
|
+
configuredTicketFormat,
|
|
4
5
|
type WorkingRepoGit,
|
|
5
6
|
} from "../../../../lib/delivery/branches";
|
|
6
7
|
import type { DeliveryEnvironment, WorkingRepoInfo } from "../../../../lib/delivery/environment";
|
|
@@ -21,12 +22,24 @@ export interface DeliveryEnvironmentDeps {
|
|
|
21
22
|
loadCapabilities?: (context: LaunchContext) => Promise<CapabilityConfig[]>;
|
|
22
23
|
workingRepoGit?: (repoPath: string) => WorkingRepoGit;
|
|
23
24
|
loadLinkedRepositories?: (context: LaunchContext) => Promise<LinkedRepository[]>;
|
|
25
|
+
/** True when the companion's Git mode is `auto`. */
|
|
26
|
+
loadGitAutoMode?: (context: LaunchContext) => Promise<boolean>;
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
async function defaultLoadLinkedRepositories(context: LaunchContext): Promise<LinkedRepository[]> {
|
|
27
30
|
return (await context.workingRepoStore.load()).repos;
|
|
28
31
|
}
|
|
29
32
|
|
|
33
|
+
/** A linked repository's checkout with its parsed `origin` remote. */
|
|
34
|
+
interface LinkedCheckout {
|
|
35
|
+
remote: ForgeRepo;
|
|
36
|
+
path: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function defaultLoadGitAutoMode(context: LaunchContext): Promise<boolean> {
|
|
40
|
+
return (await context.configStore.load()).git === "auto";
|
|
41
|
+
}
|
|
42
|
+
|
|
30
43
|
async function defaultLoadCapabilities(context: LaunchContext): Promise<CapabilityConfig[]> {
|
|
31
44
|
const config = await context.configStore.load();
|
|
32
45
|
return config.capabilities ?? [];
|
|
@@ -73,32 +86,42 @@ export async function resolveDeliveryEnvironment(
|
|
|
73
86
|
};
|
|
74
87
|
}
|
|
75
88
|
|
|
76
|
-
let linkedRemotes: Promise<
|
|
77
|
-
// Read once, and only when a repository other than the Working Repository
|
|
78
|
-
const linked = (): Promise<
|
|
89
|
+
let linkedRemotes: Promise<LinkedCheckout[]> | undefined;
|
|
90
|
+
// Read once, and only when a repository other than the Working Repository is looked up.
|
|
91
|
+
const linked = (): Promise<LinkedCheckout[]> =>
|
|
79
92
|
(linkedRemotes ??= (async () => {
|
|
80
|
-
// An unreadable registry only loses
|
|
93
|
+
// An unreadable registry only loses hints; the Working Repository remains.
|
|
81
94
|
const repositories = await (deps.loadLinkedRepositories ?? defaultLoadLinkedRepositories)(
|
|
82
95
|
context,
|
|
83
96
|
).catch(() => []);
|
|
97
|
+
const others = repositories.filter((repository) => repository.path !== repoPath);
|
|
84
98
|
const remotes = await Promise.all(
|
|
85
|
-
|
|
86
|
-
.filter((repository) => repository.path !== repoPath)
|
|
87
|
-
.map((repository) => openGit(repository.path).remoteUrl()),
|
|
99
|
+
others.map((repository) => openGit(repository.path).remoteUrl()),
|
|
88
100
|
);
|
|
89
|
-
return
|
|
101
|
+
return others.flatMap((repository, index) => {
|
|
102
|
+
const remote = remotes[index] ? parseRemote(remotes[index]) : null;
|
|
103
|
+
return remote ? [{ remote, path: repository.path }] : [];
|
|
104
|
+
});
|
|
90
105
|
})());
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
);
|
|
95
|
-
|
|
106
|
+
const linkedMatch = async (repository: string) =>
|
|
107
|
+
(await linked()).find(({ remote }) => sameRepository(repositoryPath(remote), repository));
|
|
108
|
+
const hostOf = async (repository: string): Promise<string | null> =>
|
|
109
|
+
(await linkedMatch(repository))?.remote.host ?? workingRepo?.forgeRepo?.host ?? null;
|
|
110
|
+
const checkoutOf = async (repository: string): Promise<string | null> => {
|
|
111
|
+
if (workingRepo?.slug && sameRepository(workingRepo.slug, repository)) return workingRepo.path;
|
|
112
|
+
return (await linkedMatch(repository))?.path ?? null;
|
|
96
113
|
};
|
|
114
|
+
const gitAutoMode = await (deps.loadGitAutoMode ?? defaultLoadGitAutoMode)(context).catch(
|
|
115
|
+
() => false,
|
|
116
|
+
);
|
|
97
117
|
|
|
98
118
|
return {
|
|
99
119
|
companionPath: context.companionPath,
|
|
100
120
|
workingRepo,
|
|
101
121
|
protectedPatterns: configuredProtectedPatterns(capabilities),
|
|
122
|
+
ticket: configuredTicketFormat(capabilities),
|
|
102
123
|
hostOf,
|
|
124
|
+
checkoutOf,
|
|
125
|
+
gitAutoMode,
|
|
103
126
|
};
|
|
104
127
|
}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
type RecordDeliveryDeps,
|
|
6
6
|
} from "../../../../lib/delivery/record-delivery";
|
|
7
7
|
import { applyWarnings, type DependencyWarning } from "../../../../lib/delivery/overlap";
|
|
8
|
-
import type
|
|
8
|
+
import { isJiraKey, type MergeState } from "../../../../lib/delivery/record";
|
|
9
9
|
import { type BooleanFlagSet, parseFlags, positionalArgs, stringFlag } from "../../../parse-flags";
|
|
10
10
|
import {
|
|
11
11
|
branchFlagsFrom,
|
|
@@ -19,6 +19,7 @@ import { resolveDeliveryEnvironment, type DeliveryEnvironmentDeps } from "./envi
|
|
|
19
19
|
import {
|
|
20
20
|
commandOutput,
|
|
21
21
|
renderDelivery,
|
|
22
|
+
renderOutcome,
|
|
22
23
|
sharedRefusalMessage,
|
|
23
24
|
unscopedDeliveryWarning,
|
|
24
25
|
} from "./output";
|
|
@@ -31,6 +32,7 @@ export interface LinkCommandDeps extends DeliveryEnvironmentDeps, RecordDelivery
|
|
|
31
32
|
const BOOLEAN_FLAGS: BooleanFlagSet = new Set([
|
|
32
33
|
"json",
|
|
33
34
|
"refresh",
|
|
35
|
+
"fetch",
|
|
34
36
|
"direct",
|
|
35
37
|
"confirm-merged",
|
|
36
38
|
"confirm-open",
|
|
@@ -55,17 +57,12 @@ function refusalMessage(refusal: DeliveryRefusal): string {
|
|
|
55
57
|
|
|
56
58
|
function renderHuman(result: LinkResult): string[] {
|
|
57
59
|
const lines = [`${result.change}: ${result.settlement.status}`];
|
|
60
|
+
if (result.record.ticket) lines.push(` ticket: ${result.record.ticket}`);
|
|
58
61
|
lines.push(...result.record.deliveries.map(renderDelivery));
|
|
59
62
|
for (const repository of result.settlement.missing) {
|
|
60
63
|
lines.push(` ${repository}: no delivery recorded (named in the change's scopes)`);
|
|
61
64
|
}
|
|
62
|
-
for (const outcome of result.outcomes.
|
|
63
|
-
lines.push(` ${outcome.branch}: needs an answer (${outcome.answerReason})`);
|
|
64
|
-
if (outcome.failure) lines.push(` ${outcome.failure.message}`);
|
|
65
|
-
for (const candidate of outcome.candidates ?? []) {
|
|
66
|
-
lines.push(` #${candidate.number} ${candidate.state} ${candidate.url}`);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
65
|
+
for (const outcome of result.outcomes) lines.push(...renderOutcome(outcome));
|
|
69
66
|
return lines;
|
|
70
67
|
}
|
|
71
68
|
|
|
@@ -74,22 +71,28 @@ function renderHuman(result: LinkResult): string[] {
|
|
|
74
71
|
* @description Writes a change's Delivery Record (`delivery.yaml`), with `artifact archive`
|
|
75
72
|
* the only writer of that file, for active and archived changes. Records the delivery branch or a
|
|
76
73
|
* not-applicable reason per Working Repository, an informational PR URL, merge results
|
|
77
|
-
* from the forge (`--refresh`), or the user's answer (`--confirm-*`,
|
|
74
|
+
* from the forge or a local checkout (`--refresh`), or the user's answer (`--confirm-*`,
|
|
75
|
+
* source `user`).
|
|
78
76
|
* @flags
|
|
79
77
|
* - `--repository <org/repo>` — the delivery to edit; defaults to the Working Repository.
|
|
80
78
|
* - `--branch <branch>` — record the delivery branch; a protected branch needs `--direct`.
|
|
81
79
|
* - `--direct` — with `--branch`, record a direct delivery, settled only by the user's answer; required for a protected branch.
|
|
82
80
|
* - `--not-applicable <reason>` — no branch delivers this change in the repository.
|
|
83
81
|
* - `--pr <url>` — record the PR URL; with `--refresh`, picks that PR among several.
|
|
84
|
-
* - `--
|
|
85
|
-
*
|
|
82
|
+
* - `--ticket <KEY>` — record the change's Jira ticket (`ABC-123`), alone or with other edits;
|
|
83
|
+
* refused unless the companion's openspec capability sets `ticket: jira`.
|
|
84
|
+
* - `--refresh` — ask the forge (with `MATE_GIT_TOKEN`), then a local checkout, for the merge
|
|
85
|
+
* state of each recorded branch; a direct delivery is reported as needing the user's answer.
|
|
86
|
+
* - `--fetch` — with `--refresh`, fetch the default and delivery branches first even when the
|
|
87
|
+
* companion's Git mode is not `auto`.
|
|
86
88
|
* - `--confirm-merged` / `--confirm-open` / `--confirm-dropped` — the user's answer.
|
|
87
89
|
* - `--json` — emit an array of {@link LinkResult}, one per change.
|
|
88
90
|
* @remarks Warns, without blocking, about each `dependsOn` change that is neither archived nor
|
|
89
91
|
* fully implemented, since apply records the branch before writing code. Without an edit flag or `--refresh` it only reads the record and writes nothing.
|
|
90
|
-
* Network requests go only to the forge API
|
|
91
|
-
* another repository's default branch
|
|
92
|
-
*
|
|
92
|
+
* Network requests go only to the forge API, with `--refresh` and with `--branch` for
|
|
93
|
+
* another repository's default branch, and to `origin` through `git fetch` with `--refresh`
|
|
94
|
+
* in Git mode `auto` or with `--fetch`. Only `git` is started; no credential is read. The
|
|
95
|
+
* forge token is never printed, logged, or written.
|
|
93
96
|
*/
|
|
94
97
|
export async function runArtifactLinkCommand(
|
|
95
98
|
argv: string[],
|
|
@@ -97,15 +100,25 @@ export async function runArtifactLinkCommand(
|
|
|
97
100
|
): Promise<void> {
|
|
98
101
|
const { emitOut, emitErr, refuse } = commandOutput(deps);
|
|
99
102
|
const flags = parseFlags(argv, BOOLEAN_FLAGS);
|
|
100
|
-
const flagError = valueFlagError(flags, [
|
|
103
|
+
const flagError = valueFlagError(flags, [
|
|
104
|
+
"repository",
|
|
105
|
+
"branch",
|
|
106
|
+
"not-applicable",
|
|
107
|
+
"pr",
|
|
108
|
+
"ticket",
|
|
109
|
+
]);
|
|
101
110
|
if (flagError) return refuse(flagError);
|
|
102
111
|
const changes = positionalArgs(argv, BOOLEAN_FLAGS);
|
|
103
112
|
const branchFlags = branchFlagsFrom(flags);
|
|
104
113
|
const { branch, notApplicable } = branchFlags;
|
|
105
114
|
const pr = stringFlag(flags.pr);
|
|
115
|
+
const ticket = stringFlag(flags.ticket);
|
|
106
116
|
const confirmations = Object.keys(CONFIRMATIONS).filter((flag) => flags[flag] === true);
|
|
107
117
|
|
|
108
118
|
if (changes.length === 0) return refuse("mate: artifact link requires a change name.");
|
|
119
|
+
if (flags.fetch === true && flags.refresh !== true) {
|
|
120
|
+
return refuse("mate: --fetch needs --refresh.");
|
|
121
|
+
}
|
|
109
122
|
if (branch !== undefined && notApplicable !== undefined) {
|
|
110
123
|
return refuse("mate: --branch and --not-applicable exclude each other.");
|
|
111
124
|
}
|
|
@@ -116,11 +129,15 @@ export async function runArtifactLinkCommand(
|
|
|
116
129
|
if (pr !== undefined && !/^https?:\/\/\S+$/.test(pr)) {
|
|
117
130
|
return refuse("mate: --pr expects the PR's URL.");
|
|
118
131
|
}
|
|
132
|
+
if (ticket !== undefined && !isJiraKey(ticket)) {
|
|
133
|
+
return refuse("mate: --ticket expects a Jira key such as ABC-123.");
|
|
134
|
+
}
|
|
119
135
|
const requested = repositoryFlag(flags);
|
|
120
136
|
if ("error" in requested) return refuse(requested.error);
|
|
121
137
|
|
|
122
138
|
const environment = await resolveDeliveryEnvironment(deps);
|
|
123
139
|
if ("error" in environment) return refuse(environment.error);
|
|
140
|
+
if (environment.ticket?.diagnostic) emitErr(`warning: ${environment.ticket.diagnostic}`);
|
|
124
141
|
const repository = canonicalRepository(environment, requested.repository);
|
|
125
142
|
const confirm = confirmations.length === 1 ? CONFIRMATIONS[confirmations[0]] : undefined;
|
|
126
143
|
const delivery = deliveryEditFrom(branchFlags);
|
|
@@ -133,8 +150,10 @@ export async function runArtifactLinkCommand(
|
|
|
133
150
|
...(delivery ? { delivery } : {}),
|
|
134
151
|
...(pr !== undefined ? { pr } : {}),
|
|
135
152
|
...(confirm ? { confirm } : {}),
|
|
153
|
+
...(ticket !== undefined ? { ticket } : {}),
|
|
136
154
|
},
|
|
137
155
|
refresh: flags.refresh === true,
|
|
156
|
+
fetch: flags.fetch === true,
|
|
138
157
|
includeArchived: true,
|
|
139
158
|
},
|
|
140
159
|
deps,
|
|
@@ -142,6 +161,7 @@ export async function runArtifactLinkCommand(
|
|
|
142
161
|
if ("refusal" in outcome) return refuse(refusalMessage(outcome.refusal));
|
|
143
162
|
const results: LinkResult[] = [];
|
|
144
163
|
for (const result of "results" in outcome ? outcome.results : []) {
|
|
164
|
+
for (const diagnostic of result.diagnostics) emitErr(`warning: ${diagnostic}`);
|
|
145
165
|
const warnings = await applyWarnings(environment.companionPath, result.change);
|
|
146
166
|
for (const warning of warnings) emitErr(`warning: ${warning.message}`);
|
|
147
167
|
for (const entry of result.settlement.unscoped) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Delivery, UnscopedDelivery } from "../../../../lib/delivery/record";
|
|
2
|
+
import type { BranchOutcome } from "../../../../lib/delivery/refresh";
|
|
2
3
|
import type { DeliveryRefusal } from "../../../../lib/delivery/record-delivery";
|
|
3
4
|
|
|
4
5
|
export interface CommandOutput {
|
|
@@ -37,6 +38,33 @@ export function renderDelivery(delivery: Delivery): string {
|
|
|
37
38
|
return ` ${delivery.repository} ${branch} ${merge}${pr}`;
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
/** Lines for a refresh outcome that needs an answer or carries a failed fetch. */
|
|
42
|
+
export function renderOutcome(outcome: BranchOutcome): string[] {
|
|
43
|
+
const lines: string[] = [];
|
|
44
|
+
if (outcome.fetch && !outcome.fetch.ok) {
|
|
45
|
+
lines.push(
|
|
46
|
+
` ${outcome.branch}: ${outcome.fetch.message ?? "git fetch failed"}; local refs used`,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
if (!outcome.needsAnswer) return lines;
|
|
50
|
+
if (outcome.answerReason === "likely-merged" && outcome.suggestion) {
|
|
51
|
+
const { style, commit } = outcome.suggestion;
|
|
52
|
+
lines.push(
|
|
53
|
+
` ${outcome.branch}: likely merged (${style}, ${commit.slice(0, 12)}); needs your confirmation`,
|
|
54
|
+
);
|
|
55
|
+
} else if (outcome.answerReason === "not-on-default") {
|
|
56
|
+
const fetched = outcome.fetchedAt ? `last fetch ${outcome.fetchedAt}` : "never fetched";
|
|
57
|
+
lines.push(` ${outcome.branch}: not on the default branch (${fetched}); needs an answer`);
|
|
58
|
+
} else {
|
|
59
|
+
lines.push(` ${outcome.branch}: needs an answer (${outcome.answerReason})`);
|
|
60
|
+
}
|
|
61
|
+
if (outcome.failure) lines.push(` ${outcome.failure.message}`);
|
|
62
|
+
for (const candidate of outcome.candidates ?? []) {
|
|
63
|
+
lines.push(` #${candidate.number} ${candidate.state} ${candidate.url}`);
|
|
64
|
+
}
|
|
65
|
+
return lines;
|
|
66
|
+
}
|
|
67
|
+
|
|
40
68
|
/** Wording for the refusals `link` and `archive` share; `unknown-change` names each command. */
|
|
41
69
|
export function sharedRefusalMessage(
|
|
42
70
|
refusal: Exclude<DeliveryRefusal, { reason: "unknown-change" }>,
|
|
@@ -44,6 +72,9 @@ export function sharedRefusalMessage(
|
|
|
44
72
|
if (refusal.reason === "no-repository") {
|
|
45
73
|
return "mate: the Working Repository has no origin remote to identify it; pass --repository <org/repo>.";
|
|
46
74
|
}
|
|
75
|
+
if (refusal.reason === "tickets-off") {
|
|
76
|
+
return "mate: tickets are off for this companion; set `ticket: jira` on the openspec capability (mate setup --ticket jira) to record one.";
|
|
77
|
+
}
|
|
47
78
|
if (refusal.reason === "protected-branch") {
|
|
48
79
|
return `mate: ${refusal.branch} is a protected branch (${refusal.protection}); record it only as an explicit direct delivery with --direct.`;
|
|
49
80
|
}
|