@uniqbit/mate-core 1.0.0-canary.9 → 1.0.1-canary.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/plugin.json +1 -1
- package/package.json +5 -4
- package/src/cli/agent-selector.ts +16 -0
- package/src/cli/commands/artifact/delivery/link.ts +1 -1
- package/src/cli/commands/artifact/delivery/output.ts +10 -1
- package/src/cli/commands/artifact/delivery/resolve.ts +3 -2
- package/src/cli/commands/artifact/delivery/submit.ts +9 -4
- package/src/cli/commands/artifact/delivery/take.ts +12 -9
- package/src/cli/commands/artifact/finish/command.ts +16 -14
- package/src/cli/commands/artifact/finish/engine.ts +8 -8
- package/src/cli/commands/artifact/project/command.ts +2 -3
- package/src/cli/commands/companion/hub.ts +11 -6
- package/src/cli/commands/companion/link.ts +173 -46
- package/src/cli/commands/report/contract.ts +0 -17
- package/src/cli/commands/studio/access.ts +4 -0
- package/src/cli/commands/studio/actions.ts +35 -2
- package/src/cli/commands/studio/mcp-manager.ts +162 -0
- package/src/cli/commands/studio/routes.ts +12 -0
- package/src/cli/commands/studio/selection.ts +44 -11
- package/src/cli/commands/studio/server.ts +246 -2
- package/src/cli/commands/studio/services.ts +26 -0
- package/src/cli/commands/studio/terminal-launch.ts +21 -4
- package/src/cli/commands/studio/terminal.ts +3 -14
- package/src/cli/commands/studio/work-requests.ts +9 -0
- package/src/cli/commands/studio/work.ts +473 -0
- package/src/cli/commands/triage.ts +11 -23
- package/src/cli/commands/vscode/release-vsix.json +2 -2
- package/src/cli/commands/workflow/workflow.ts +3 -2
- package/src/cli/commands/working/cleanup.ts +1 -18
- package/src/cli/companion-link-wizard.tsx +158 -91
- package/src/cli/companion-selector.ts +26 -0
- package/src/cli/usage.ts +1 -1
- package/src/lib/agent-credential.ts +131 -0
- package/src/lib/components/select-one.tsx +122 -0
- package/src/lib/credential-kinds.ts +7 -0
- package/src/lib/delivery/merge-git.ts +16 -0
- package/src/lib/delivery/record-delivery.ts +12 -6
- package/src/lib/delivery/record.ts +5 -0
- package/src/lib/delivery/refresh.ts +34 -6
- package/src/lib/delivery/staging/refs.ts +9 -4
- package/src/lib/delivery/staging/submit.ts +81 -22
- package/src/lib/mcp-manager/resolve.ts +27 -9
- package/src/lib/mcp-manager/store.ts +35 -11
- package/src/lib/mcp-manager/types.ts +14 -0
- package/src/lib/mcp-manager/validate.ts +6 -10
- package/src/lib/opencode-server.ts +2 -17
- package/src/lib/orchestrator/repo-local-store.ts +14 -0
- package/src/lib/orchestrator/repository-link.ts +80 -52
- package/src/lib/orchestrator/root-context.ts +17 -1
- package/src/lib/studio-chat/agent.ts +139 -0
- package/src/lib/studio-chat/companion-context.ts +136 -0
- package/src/lib/studio-chat/credential.ts +79 -0
- package/src/lib/studio-chat/harness-chat-agent.ts +334 -0
- package/src/lib/studio-chat/host-sandbox.ts +578 -0
- package/src/lib/studio-chat/prepare-bridges.ts +95 -0
- package/src/lib/studio-chat/session.ts +15 -0
- package/src/lib/studio-chat/turns.ts +112 -0
- package/src/lib/workflow/handoff.ts +1 -1
- package/src/lib/workflow/position.ts +29 -2
- package/src/lib/workset/claims.ts +85 -0
- package/src/lib/workset/execution.ts +71 -0
- package/src/lib/workset/git-transaction.ts +74 -0
- package/src/lib/workset/groups.ts +176 -0
- package/src/lib/workset/inventory.ts +196 -0
- package/src/lib/workset/projection.ts +237 -0
- package/src/lib/workset/record.ts +101 -36
- package/src/lib/workset/repositories.ts +24 -0
- package/src/lib/workset/sharing.ts +951 -0
- package/src/lib/workset/stages.ts +50 -14
- package/src/lib/workset/transactions.ts +158 -0
- package/src/runtime/companion-git-state.ts +1 -0
- package/src/runtime/companion-guidance.ts +2 -2
- package/src/runtime/forge-remote.ts +6 -0
- package/src/runtime/host-process.ts +28 -0
- package/src/runtime/secret-guard.ts +18 -1
- package/src/runtime/secret-patterns.ts +4 -3
- package/src/runtime/submitted-arrivals.ts +28 -2
- package/src/runtime/write-atomic.ts +2 -2
- package/src/studio.ts +52 -8
- package/src/templates/capabilities/openspec-cap/mate-full/schema.yaml +1 -1
- package/src/templates/capabilities/openspec-cap/mate-full/templates/proposal.md +1 -1
- package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +3 -2
- package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +5 -3
- package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +3 -2
- package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +5 -3
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +12 -12
- package/src/tools/setup/capabilities/mcp-manager.ts +1 -2
- package/src/tools/setup/dynamic-plugins/declarations.ts +0 -26
- package/src/tools/setup/plugins/gitignore.ts +1 -0
- package/src/tools/setup/providers/claude-format.ts +1 -5
- package/src/tools/setup/providers/claude.ts +28 -3
- package/src/tools/setup/providers/opencode.ts +7 -18
- package/src/tools/setup/providers/relative-path-warnings.ts +26 -0
- package/studio-dist/THIRD-PARTY-NOTICES.md +297 -0
- package/studio-dist/client/THIRD-PARTY-LICENSES.md +4294 -0
- package/studio-dist/client/assets/DialogTitle-DOhjDa7H.js +1 -0
- package/studio-dist/client/assets/app-CG3vCgyA.css +2 -0
- package/studio-dist/client/assets/bundle-mjs-CdK3cBzO.js +1 -0
- package/studio-dist/client/assets/button-upSzkd-q.js +1 -0
- package/studio-dist/client/assets/chat-DbaMXb8H.js +157 -0
- package/studio-dist/client/assets/cn-BCnYnarL.js +1 -0
- package/studio-dist/client/assets/combobox-cP9OsRf2.js +1 -0
- package/studio-dist/client/assets/{companion-view-C1F0_jbt.js → companion-view-B54_Lj0S.js} +1 -1
- package/studio-dist/client/assets/fields-DNZ4a89M.js +1 -0
- package/studio-dist/client/assets/friction-DgEimeDB.js +1 -0
- package/studio-dist/client/assets/getting-started-BTfYCt5s.js +1 -0
- package/studio-dist/client/assets/{getting-started-BN4aTpsz.js → getting-started-CAszmdDJ.js} +1 -1
- package/studio-dist/client/assets/getting-started._topic-CHJMf0pa.js +1 -0
- package/studio-dist/client/assets/getting-started.index-MR6HftWs.js +1 -0
- package/studio-dist/client/assets/{graph-canvas-Be5qgdDt.js → graph-canvas-BdNk2F9O.js} +1 -1
- package/studio-dist/client/assets/graph-hRijsC89.js +2 -0
- package/studio-dist/client/assets/guides-CwFnh08E.js +1 -0
- package/studio-dist/client/assets/highlighted-body-JLMTFACH-BcroQey-.js +1 -0
- package/studio-dist/client/assets/index-D5oGyvG8.js +41 -0
- package/studio-dist/client/assets/{markdown-view-dku7MGPn.js → markdown-view-CJ8JsLb7.js} +1 -1
- package/studio-dist/client/assets/marked.esm-vFuq1cCd.js +65 -0
- package/studio-dist/client/assets/mcp-BE9M-bkO.js +4 -0
- package/studio-dist/client/assets/mermaid-WFAXDIZX-BjSsakrn.js +1 -0
- package/studio-dist/client/assets/panel-CDQ6Lryw.js +1 -0
- package/studio-dist/client/assets/plugins._service._view-DRVPUAWN.js +1 -0
- package/studio-dist/client/assets/{prepaint-BkoDSw5X.js → prepaint-sD_LlrDN.js} +1 -1
- package/studio-dist/client/assets/{queries-CMvC2OkU.js → queries-COL925ML.js} +1 -1
- package/studio-dist/client/assets/react-dom-K3Hp2Cdj.js +1 -0
- package/studio-dist/client/assets/{react-BYUSgtBs.js → react-h2xQ_NSp.js} +1 -1
- package/studio-dist/client/assets/reports-BClsojkb.js +1 -0
- package/studio-dist/client/assets/routes-CJQ2MAej.js +1 -0
- package/studio-dist/client/assets/search-DhWdEiKT.js +1 -0
- package/studio-dist/client/assets/select-B2FsN9FY.js +1 -0
- package/studio-dist/client/assets/skills-SoUHk77W.js +1 -0
- package/studio-dist/client/assets/{specs-Bqd1ajyD.js → specs-C_tZnAvF.js} +1 -1
- package/studio-dist/client/assets/specs-view-C6t3Y5IT.js +1 -0
- package/studio-dist/client/assets/steps-CF3-Zpmh.js +1 -0
- package/studio-dist/client/assets/{store-BYnEU33C.js → store-pY9gU4uS.js} +1 -1
- package/studio-dist/client/assets/studio-X7bnFrRe.js +36 -0
- package/studio-dist/client/assets/studio-queries-CKtAnIKP.js +2 -0
- package/studio-dist/client/assets/usage-BaaqUpTG.js +55 -0
- package/studio-dist/client/assets/useAnchoredPopupScrollLock-BspHR7Wt.js +1 -0
- package/studio-dist/client/assets/useBlocker-BQOfcu_f.js +1 -0
- package/studio-dist/client/assets/useMutation-DKeEoP5S.js +1 -0
- package/studio-dist/client/assets/useOpenInteractionType-CtaZCaFT.js +1 -0
- package/studio-dist/client/assets/usePopupHandleStore-Bc7Q4bnF.js +1 -0
- package/studio-dist/client/assets/vault-sAPFUnPN.js +1 -0
- package/studio-dist/client/assets/{warnings-Cnw99ugO.js → warnings-D7YY1HSG.js} +1 -1
- package/studio-dist/client/assets/work-BZek_LGB.js +5 -0
- package/studio-dist/client/assets/workflow-N5boHXFz.js +1 -0
- package/studio-dist/server/THIRD-PARTY-LICENSES.md +4371 -0
- package/studio-dist/server/assets/DialogTitle-DnKSl2V0.js +421 -0
- package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-CS3QRY4Q.js → __23tanstack-start-server-fn-resolver-Bli9bpSB.js} +38 -18
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +91 -59
- package/studio-dist/server/assets/{actions-D8erOphH.js → actions-CHEFA1i9.js} +33 -1
- package/studio-dist/server/assets/{cn-DWFJaP_9.js → bundle-mjs-Ot6dQ8Pq.js} +1 -2056
- package/studio-dist/server/assets/{button-Ct_WeYLc.js → button-BqA1urbl.js} +14 -7
- package/studio-dist/server/assets/chat-zl332Tvu.js +49486 -0
- package/studio-dist/server/assets/cn-B0fl6NWK.js +2057 -0
- package/studio-dist/server/assets/{combobox-17vO5Uz8.js → combobox-iTjvPCtS.js} +7 -6
- package/studio-dist/server/assets/{companion-view-JkxnGLlp.js → companion-view-DIQ6AFIY.js} +2 -2
- package/studio-dist/server/assets/{companions-YNLsbnch.js → companions-aVwjRL8j.js} +1 -1
- package/studio-dist/server/assets/{fields-VytPpqBq.js → fields-BMap2_Ju.js} +10 -3
- package/studio-dist/server/assets/{friction-BW86PCPM.js → friction-BER50hoD.js} +2 -2
- package/studio-dist/server/assets/{friction-B6osqFSm.js → friction-BPs9KWdq.js} +8 -8
- package/studio-dist/server/assets/{getting-started-CFHSeX5h.js → getting-started-DGfRVmZ_.js} +2 -2
- package/studio-dist/server/assets/{getting-started._topic-BK2eU6AS.js → getting-started._topic-BgrBA4Vj.js} +2 -2
- package/studio-dist/server/assets/{getting-started.index-DZLuXnNO.js → getting-started.index-BaFfQ9Mn.js} +2 -2
- package/studio-dist/server/assets/{graph-BJVZBevL.js → graph-Cgzlrv3P.js} +8 -8
- package/studio-dist/server/assets/{graph-DGZHV-Ek.js → graph-DODpuOy_.js} +1 -1
- package/studio-dist/server/assets/{graph-canvas-lrNT6jbl.js → graph-canvas-DW_zU1nA.js} +2 -2
- package/studio-dist/server/assets/{guides-_G8Vucsk.js → guides-CA_EMG7E.js} +1 -1
- package/studio-dist/server/assets/{guides-CEwLOZb9.js → guides-D0SpoD32.js} +1 -1
- package/studio-dist/server/assets/{guides.server-ZWFKX2XJ.js → guides.server-DJjQuy03.js} +1 -1
- package/studio-dist/server/assets/highlighted-body-JLMTFACH-BeHllu-r.js +41 -0
- package/studio-dist/server/assets/{markdown-view-Bmjghg_Z.js → markdown-view-CvVBGMZV.js} +1 -1
- package/studio-dist/server/assets/mcp-BU0fLYyJ.js +1103 -0
- package/studio-dist/server/assets/mcp-manager-D9YctTQe.js +50 -0
- package/studio-dist/server/assets/mermaid-WFAXDIZX-B1yDN6vG.js +1 -0
- package/studio-dist/server/assets/{panel-DvRjyil3.js → panel-D1K6Bsux.js} +4 -32
- package/studio-dist/server/assets/{plugins._service._view-B32LzraG.js → plugins._service._view-DdO1nELF.js} +4 -4
- package/studio-dist/server/assets/{prepaint-BEHwKl51.js → prepaint-BB3dwSmz.js} +1 -1
- package/studio-dist/server/assets/{queries-D6Vq0AuZ.js → queries-BwiDxQy5.js} +1 -1
- package/studio-dist/server/assets/{react-CiBZPDs8.js → react-B2cLiz-i.js} +1 -1
- package/studio-dist/server/assets/{reports-Dn92pLap.js → reports-9Pr7Bz6o.js} +7 -7
- package/studio-dist/server/assets/{reports-DDaH5k0H.js → reports-Cc9M3phM.js} +1 -1
- package/studio-dist/server/assets/{router-Bjf4S9tO.js → router-DcWe0J7Y.js} +827 -548
- package/studio-dist/server/assets/{routes-B4sNiE0X.js → routes-BEXxl0py.js} +8 -8
- package/studio-dist/server/assets/{search-DKeJRvg8.js → search-bltT7gwy.js} +39 -7
- package/studio-dist/server/assets/{select-CVHYL7oR.js → select-CZvHgGCi.js} +7 -6
- package/studio-dist/server/assets/{shell-BxbYYaAk.js → shell-BQ0vMKXN.js} +13 -4
- package/studio-dist/server/assets/{skills-Bj8eOgzR.js → skills-Be_52h0i.js} +1 -1
- package/studio-dist/server/assets/{skills-B4-0qpqN.js → skills-BpGGUl6L.js} +8 -8
- package/studio-dist/server/assets/{specs-rfMug6qW.js → specs-CCGgXE-V.js} +5 -5
- package/studio-dist/server/assets/{specs-view-qi1SE1Sl.js → specs-view-DtL5JxYM.js} +12 -11
- package/studio-dist/server/assets/{steps-rger6HJc.js → steps-BWFSO6dM.js} +1 -1
- package/studio-dist/server/assets/{store-Dg9T7oWs.js → store-X7yLPp7v.js} +1 -1
- package/studio-dist/server/assets/{studio-queries-CeFfmIuM.js → studio-queries-ur1ygXi3.js} +117 -13
- package/studio-dist/server/assets/{studio-D79JzDLc.js → studio-qzH-UETC.js} +209 -180
- package/studio-dist/server/assets/{usage-Dw_UQFX-.js → usage-C1o0DLzS.js} +1 -1
- package/studio-dist/server/assets/{usage-BJgYWRCX.js → usage-DWbSPrPD.js} +10 -9
- package/studio-dist/server/assets/{useAnchoredPopupScrollLock-ciS_sEq3.js → useAnchoredPopupScrollLock-DLDmv6kM.js} +4 -135
- package/studio-dist/server/assets/useBlocker-CQtANHK8.js +111 -0
- package/studio-dist/server/assets/{useMutation-DnWK0PhO.js → useMutation-NjlA8oFY.js} +2 -2
- package/studio-dist/server/assets/useOpenInteractionType-CZYscfOb.js +136 -0
- package/studio-dist/server/assets/usePopupHandleStore-DEEXJYv0.js +26 -0
- package/studio-dist/server/assets/{vault-BzarssiL.js → vault-B_kfi1h-.js} +1 -1
- package/studio-dist/server/assets/{vault-CvlrLd2H.js → vault-dL79JlKH.js} +8 -115
- package/studio-dist/server/assets/{views-CAxwKHMK.js → views-BSGH56lb.js} +3 -3
- package/studio-dist/server/assets/{warnings-BpVCugHm.js → warnings-DtUVPV-k.js} +2 -2
- package/studio-dist/server/assets/work-D789VXGH.js +110 -0
- package/studio-dist/server/assets/work-DsCEfhmK.js +3817 -0
- package/studio-dist/server/assets/work-requests-BLhOmQFO.js +11 -0
- package/studio-dist/server/assets/{workflow-BdrzcCt8.js → workflow-BOZ2sRYg.js} +9 -9
- package/studio-dist/server/server.js +3 -3
- package/wrappers/bin/openspec +87 -2
- package/src/cli/companion-selector.tsx +0 -139
- package/studio-dist/client/assets/app-ggXJ_QVh.css +0 -2
- package/studio-dist/client/assets/button-C9SQW3kI.js +0 -1
- package/studio-dist/client/assets/cn-DC80MJV0.js +0 -1
- package/studio-dist/client/assets/combobox-D7mKYCBb.js +0 -1
- package/studio-dist/client/assets/fields-CEep8IFT.js +0 -1
- package/studio-dist/client/assets/friction-D9dBU7WN.js +0 -1
- package/studio-dist/client/assets/getting-started-BDyGvHhc.js +0 -1
- package/studio-dist/client/assets/getting-started._topic-B9ajbF4o.js +0 -1
- package/studio-dist/client/assets/getting-started.index-CYiBPtb7.js +0 -1
- package/studio-dist/client/assets/graph-ah7ZXfTa.js +0 -2
- package/studio-dist/client/assets/guides-CsL0660B.js +0 -1
- package/studio-dist/client/assets/index-zmRH87D4.js +0 -40
- package/studio-dist/client/assets/panel-COgk0vP5.js +0 -1
- package/studio-dist/client/assets/plugins._service._view-Cn3WBHab.js +0 -1
- package/studio-dist/client/assets/reports-C_AqLBYH.js +0 -1
- package/studio-dist/client/assets/routes-BokQmHtC.js +0 -1
- package/studio-dist/client/assets/search-DxidNK2M.js +0 -1
- package/studio-dist/client/assets/select-CYFCbHUd.js +0 -1
- package/studio-dist/client/assets/skills-R3vttWHM.js +0 -1
- package/studio-dist/client/assets/specs-view-znqFPx9p.js +0 -1
- package/studio-dist/client/assets/steps-tVDWn7j6.js +0 -1
- package/studio-dist/client/assets/studio-ndtFcS2Y.js +0 -100
- package/studio-dist/client/assets/studio-queries-CkUSByy7.js +0 -2
- package/studio-dist/client/assets/usage-Kuhr8dSl.js +0 -55
- package/studio-dist/client/assets/useAnchoredPopupScrollLock-dc_kP4Go.js +0 -1
- package/studio-dist/client/assets/useMutation-CqtM9COw.js +0 -1
- package/studio-dist/client/assets/vault-CSP8kwRg.js +0 -1
- package/studio-dist/client/assets/workflow-BPJAmmZi.js +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
|
|
4
|
+
import { signalProcessGroup, within } from "../../../runtime/host-process";
|
|
4
5
|
import type { LiveSessions, SessionCloseReason } from "./live-sessions";
|
|
5
6
|
import { tokensEqual } from "./access";
|
|
6
7
|
|
|
@@ -114,14 +115,6 @@ export const bunTerminalSpawn: TerminalSpawn = (request) => {
|
|
|
114
115
|
};
|
|
115
116
|
};
|
|
116
117
|
|
|
117
|
-
function signalGroup(pid: number, signal: NodeJS.Signals): void {
|
|
118
|
-
try {
|
|
119
|
-
process.kill(-pid, signal);
|
|
120
|
-
} catch {
|
|
121
|
-
/** The group is already gone. */
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
118
|
/** Keeps the newest `limit` bytes; the oldest are dropped, possibly mid-sequence. */
|
|
126
119
|
export class RingBuffer {
|
|
127
120
|
private chunks: Uint8Array[] = [];
|
|
@@ -303,7 +296,7 @@ export class TerminalRegistry {
|
|
|
303
296
|
constructor(private readonly options: TerminalRegistryOptions) {
|
|
304
297
|
this.limits = { ...TERMINAL_LIMITS, ...options.limits };
|
|
305
298
|
this.spawn = options.spawn ?? bunTerminalSpawn;
|
|
306
|
-
this.signal = options.signalGroup ??
|
|
299
|
+
this.signal = options.signalGroup ?? signalProcessGroup;
|
|
307
300
|
this.now = options.now ?? Date.now;
|
|
308
301
|
options.sessions?.closeWith((companionPath, worksetId, reason) =>
|
|
309
302
|
this.endWorkset(companionPath, worksetId, reason),
|
|
@@ -735,11 +728,7 @@ export class TerminalRegistry {
|
|
|
735
728
|
const connection = [...this.connections].find((c) => c.viewer === viewer);
|
|
736
729
|
if (connection) connection.session = null;
|
|
737
730
|
}
|
|
738
|
-
const wait = (ms: number) =>
|
|
739
|
-
Promise.race([
|
|
740
|
-
session.process.exited.then(() => true),
|
|
741
|
-
new Promise<boolean>((resolve) => setTimeout(() => resolve(false), ms)),
|
|
742
|
-
]);
|
|
731
|
+
const wait = (ms: number) => within(session.process.exited, ms);
|
|
743
732
|
session.ending = (async () => {
|
|
744
733
|
if (!session.exited) {
|
|
745
734
|
this.signal(session.process.pid, "SIGTERM");
|
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import { companionTicketFormat, TICKETS_OFF } from "../../../lib/delivery/branches";
|
|
2
|
+
import type { Operator } from "../../../lib/workset/claims";
|
|
3
|
+
import { findEntry, ownershipFacts } from "../../../lib/workset/execution";
|
|
4
|
+
import {
|
|
5
|
+
configuredOperator,
|
|
6
|
+
type GitFailure,
|
|
7
|
+
isGitBacked,
|
|
8
|
+
workGit,
|
|
9
|
+
} from "../../../lib/workset/git-transaction";
|
|
10
|
+
import {
|
|
11
|
+
activeMembers,
|
|
12
|
+
type InventoryWorkset,
|
|
13
|
+
readWorkInventory,
|
|
14
|
+
} from "../../../lib/workset/inventory";
|
|
15
|
+
import {
|
|
16
|
+
LOCAL_ONLY,
|
|
17
|
+
NO_OPERATOR,
|
|
18
|
+
projectWorkCard,
|
|
19
|
+
type WorkActionId,
|
|
20
|
+
type WorkCard,
|
|
21
|
+
type WorkContext,
|
|
22
|
+
type WorkFacts,
|
|
23
|
+
type WorkMemberStatus,
|
|
24
|
+
unsynced,
|
|
25
|
+
workActionRefusalOf,
|
|
26
|
+
} from "../../../lib/workset/projection";
|
|
27
|
+
import { createOutcome, WorksetError } from "../../../lib/workset/record";
|
|
28
|
+
import { branchProbe, linkedRepositoryIdentities } from "../../../lib/workset/repositories";
|
|
29
|
+
import { deriveWorksetStage, type WorksetStageId } from "../../../lib/workset/stage";
|
|
30
|
+
import { collectChangeFacts } from "../../../lib/workset/stages";
|
|
31
|
+
import {
|
|
32
|
+
claimGroupOf,
|
|
33
|
+
confirmShare,
|
|
34
|
+
planProblems,
|
|
35
|
+
previewShare,
|
|
36
|
+
readTeamBacklog,
|
|
37
|
+
refreshTeam,
|
|
38
|
+
type RemoteBacklog,
|
|
39
|
+
remoteOnlyEntries,
|
|
40
|
+
type SharePreview,
|
|
41
|
+
type TeamStatus,
|
|
42
|
+
} from "../../../lib/workset/sharing";
|
|
43
|
+
import { sameMembers, updateClaim } from "../../../lib/workset/transactions";
|
|
44
|
+
import { readSubmittedFolders } from "../../../runtime/companion-git-state";
|
|
45
|
+
import { pendingSubmittedChanges } from "../../../runtime/pending-records";
|
|
46
|
+
import { WORK_ACTIONS, skillInstalledFor } from "./actions";
|
|
47
|
+
import type { StudioSkillInventory } from "./mate-inventory";
|
|
48
|
+
import type { StudioChange, StudioShippedChange } from "./payload";
|
|
49
|
+
import type { TerminalAgent } from "./terminal";
|
|
50
|
+
|
|
51
|
+
export interface WorkLaunchOffer {
|
|
52
|
+
action: string;
|
|
53
|
+
subject: string;
|
|
54
|
+
label: string;
|
|
55
|
+
prompts: Partial<Record<TerminalAgent, string>>;
|
|
56
|
+
runAgents: TerminalAgent[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface StudioWorkCard extends WorkCard {
|
|
60
|
+
title: string;
|
|
61
|
+
memberNames: string[];
|
|
62
|
+
claimMemberNames: string[];
|
|
63
|
+
offers: WorkLaunchOffer[];
|
|
64
|
+
needsYou: boolean;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface StudioWorkTeam {
|
|
68
|
+
remote?: string;
|
|
69
|
+
branch?: string;
|
|
70
|
+
fetchedAt?: string;
|
|
71
|
+
failure?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface StudioWorkPayload {
|
|
75
|
+
writable: boolean;
|
|
76
|
+
operator: Operator | null;
|
|
77
|
+
gitBacked: boolean;
|
|
78
|
+
team: StudioWorkTeam;
|
|
79
|
+
cards: StudioWorkCard[];
|
|
80
|
+
linkedRepositories: string[];
|
|
81
|
+
ticketFormat: string;
|
|
82
|
+
diagnostics: string[];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface WorkInput {
|
|
86
|
+
changes: readonly StudioChange[];
|
|
87
|
+
shipped: readonly StudioShippedChange[];
|
|
88
|
+
writable: boolean;
|
|
89
|
+
skills?: StudioSkillInventory;
|
|
90
|
+
terminalAgents?: TerminalAgent[];
|
|
91
|
+
linkedRepositories?: string[];
|
|
92
|
+
ticketFormat?: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function needsPerson(card: WorkCard): boolean {
|
|
96
|
+
if (card.done || card.bucket !== "local") return false;
|
|
97
|
+
return ["human-review", "merge-wait", "publish"].includes(card.stage);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function teamOf(status: TeamStatus): StudioWorkTeam {
|
|
101
|
+
return {
|
|
102
|
+
...(status.shared ? { remote: status.shared.remote, branch: status.shared.branch } : {}),
|
|
103
|
+
...(status.fetchedAt ? { fetchedAt: status.fetchedAt } : {}),
|
|
104
|
+
...(status.failure ? { failure: status.failure.message } : {}),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const AGENTS: readonly TerminalAgent[] = ["claude", "opencode"];
|
|
109
|
+
|
|
110
|
+
function wantedOffers(
|
|
111
|
+
entry: InventoryWorkset,
|
|
112
|
+
stage: WorksetStageId,
|
|
113
|
+
members: readonly WorkMemberStatus[],
|
|
114
|
+
): { id: string; subject: string }[] {
|
|
115
|
+
const active = activeMembers(entry);
|
|
116
|
+
if (entry.record.changes.length === 0) {
|
|
117
|
+
return [
|
|
118
|
+
{ id: "explore-workset", subject: entry.id },
|
|
119
|
+
{ id: "propose-workset", subject: entry.id },
|
|
120
|
+
];
|
|
121
|
+
}
|
|
122
|
+
if (active.length === 0) {
|
|
123
|
+
const id = stage === "clarify-intent" ? "explore-workset" : "propose-workset";
|
|
124
|
+
return [{ id, subject: entry.id }];
|
|
125
|
+
}
|
|
126
|
+
if (stage === "propose") return [{ id: "propose-workset", subject: entry.id }];
|
|
127
|
+
if (stage === "human-review" || stage === "apply") {
|
|
128
|
+
const waiting = new Set(
|
|
129
|
+
members
|
|
130
|
+
.filter((member) => member.stage !== "human-review" && member.stage !== "apply")
|
|
131
|
+
.map((member) => member.name),
|
|
132
|
+
);
|
|
133
|
+
return active
|
|
134
|
+
.filter((change) => !waiting.has(change))
|
|
135
|
+
.map((change) => ({ id: "apply-change", subject: change }));
|
|
136
|
+
}
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function offersFor(facts: WorkFacts, input: WorkInput): WorkLaunchOffer[] {
|
|
141
|
+
if (!input.skills) return [];
|
|
142
|
+
return wantedOffers(facts.inventory, facts.stage.stage, facts.members).flatMap(
|
|
143
|
+
({ id, subject }) => {
|
|
144
|
+
const action = WORK_ACTIONS.find((candidate) => candidate.id === id)!;
|
|
145
|
+
const copy = AGENTS.filter((agent) => skillInstalledFor(input.skills!, action.skill, agent));
|
|
146
|
+
if (copy.length === 0) return [];
|
|
147
|
+
return [
|
|
148
|
+
{
|
|
149
|
+
action: action.id,
|
|
150
|
+
subject,
|
|
151
|
+
label: action.label,
|
|
152
|
+
prompts: Object.fromEntries(copy.map((agent) => [agent, action.prompts[agent](subject)])),
|
|
153
|
+
runAgents: copy.filter((agent) => input.terminalAgents?.includes(agent)),
|
|
154
|
+
},
|
|
155
|
+
];
|
|
156
|
+
},
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface WorkModel {
|
|
161
|
+
context: WorkContext;
|
|
162
|
+
facts: Map<string, WorkFacts>;
|
|
163
|
+
backlog: RemoteBacklog;
|
|
164
|
+
diagnostics: string[];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function readWorkModel(
|
|
168
|
+
companionPath: string,
|
|
169
|
+
input: WorkInput,
|
|
170
|
+
lastFailure?: GitFailure,
|
|
171
|
+
): Promise<WorkModel> {
|
|
172
|
+
const git = workGit(companionPath);
|
|
173
|
+
const gitBacked = await isGitBacked(git);
|
|
174
|
+
const [inventory, backlog, operator, pending] = await Promise.all([
|
|
175
|
+
readWorkInventory(companionPath),
|
|
176
|
+
readTeamBacklog(companionPath, lastFailure),
|
|
177
|
+
gitBacked ? configuredOperator(git) : Promise.resolve(null),
|
|
178
|
+
gitBacked ? pendingSubmittedChanges(companionPath) : Promise.resolve([]),
|
|
179
|
+
]);
|
|
180
|
+
const local = new Set(
|
|
181
|
+
inventory.worksets.flatMap((entry) => entry.members.map((member) => member.name)),
|
|
182
|
+
);
|
|
183
|
+
const localIds = new Set(inventory.worksets.map((entry) => entry.id));
|
|
184
|
+
const remote = remoteOnlyEntries(backlog, local);
|
|
185
|
+
const shadowed = new Set(remote.filter((entry) => localIds.has(entry.id)).map((e) => e.id));
|
|
186
|
+
const entries = [
|
|
187
|
+
...inventory.worksets.map((entry) =>
|
|
188
|
+
shadowed.has(entry.id)
|
|
189
|
+
? {
|
|
190
|
+
...entry,
|
|
191
|
+
diagnostics: [
|
|
192
|
+
...entry.diagnostics,
|
|
193
|
+
`shared work on the inbox is also named ${entry.id}; rename one of them`,
|
|
194
|
+
],
|
|
195
|
+
actionable: false,
|
|
196
|
+
}
|
|
197
|
+
: entry,
|
|
198
|
+
),
|
|
199
|
+
...remote.filter((entry) => !shadowed.has(entry.id)),
|
|
200
|
+
];
|
|
201
|
+
const published = new Set(input.shipped.map((change) => change.anchor));
|
|
202
|
+
const changeFacts = await collectChangeFacts(
|
|
203
|
+
companionPath,
|
|
204
|
+
entries.flatMap((entry) => entry.members),
|
|
205
|
+
input.changes,
|
|
206
|
+
published,
|
|
207
|
+
{ submitted: new Set(pending.map((change) => change.name)) },
|
|
208
|
+
);
|
|
209
|
+
const reads = {
|
|
210
|
+
branchHere: branchProbe(companionPath),
|
|
211
|
+
recorded: gitBacked ? readSubmittedFolders(companionPath) : {},
|
|
212
|
+
};
|
|
213
|
+
const context: WorkContext = {
|
|
214
|
+
writable: input.writable,
|
|
215
|
+
...(operator ? { operator } : {}),
|
|
216
|
+
gitBacked,
|
|
217
|
+
};
|
|
218
|
+
const facts = new Map<string, WorkFacts>();
|
|
219
|
+
await Promise.all(
|
|
220
|
+
entries.map(async (entry) => {
|
|
221
|
+
const stage = deriveWorksetStage(entry.record, entry.members, (name) =>
|
|
222
|
+
changeFacts.get(name),
|
|
223
|
+
);
|
|
224
|
+
const ownership = gitBacked
|
|
225
|
+
? await ownershipFacts(companionPath, entry, backlog, operator ?? undefined, reads)
|
|
226
|
+
: {
|
|
227
|
+
sharing: LOCAL_ONLY,
|
|
228
|
+
claim: { kind: "none" as const },
|
|
229
|
+
progress: { kind: "none" as const },
|
|
230
|
+
};
|
|
231
|
+
const members: WorkMemberStatus[] = entry.members.map((member) => {
|
|
232
|
+
const fact = changeFacts.get(member.name);
|
|
233
|
+
const memberStage = fact
|
|
234
|
+
? deriveWorksetStage({ ...entry.record, changes: [member.name] }, [member], () => fact)
|
|
235
|
+
: stage;
|
|
236
|
+
return {
|
|
237
|
+
name: member.name,
|
|
238
|
+
stage: memberStage.stage,
|
|
239
|
+
stageLabel: memberStage.label,
|
|
240
|
+
delivered: memberStage.stage === "done",
|
|
241
|
+
...(member.kind === "missing" ? { problem: "neither active nor archived" } : {}),
|
|
242
|
+
...(member.kind === "conflict" ? { problem: "listed by another Workset" } : {}),
|
|
243
|
+
};
|
|
244
|
+
});
|
|
245
|
+
facts.set(entry.id, { inventory: entry, stage, members, ...ownership });
|
|
246
|
+
}),
|
|
247
|
+
);
|
|
248
|
+
return {
|
|
249
|
+
context,
|
|
250
|
+
facts,
|
|
251
|
+
backlog,
|
|
252
|
+
diagnostics: inventory.diagnostics,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async function assembleWork(
|
|
257
|
+
companionPath: string,
|
|
258
|
+
input: WorkInput,
|
|
259
|
+
lastFailure?: GitFailure,
|
|
260
|
+
): Promise<StudioWorkPayload> {
|
|
261
|
+
const model = await readWorkModel(companionPath, input, lastFailure);
|
|
262
|
+
const cards = [...model.facts.values()]
|
|
263
|
+
.map((facts): StudioWorkCard => {
|
|
264
|
+
const card = projectWorkCard(facts, model.context);
|
|
265
|
+
const entry = facts.inventory;
|
|
266
|
+
const holdsSharedCopy = card.bucket !== "remote" && !unsynced(facts.sharing);
|
|
267
|
+
return {
|
|
268
|
+
...card,
|
|
269
|
+
title: entry.record.title,
|
|
270
|
+
memberNames: activeMembers(entry),
|
|
271
|
+
claimMemberNames: claimGroupOf(entry, model.backlog),
|
|
272
|
+
offers: holdsSharedCopy ? offersFor(facts, input) : [],
|
|
273
|
+
needsYou: needsPerson(card),
|
|
274
|
+
};
|
|
275
|
+
})
|
|
276
|
+
.toSorted((a, b) => a.id.localeCompare(b.id));
|
|
277
|
+
return {
|
|
278
|
+
writable: input.writable,
|
|
279
|
+
operator: model.context.operator ?? null,
|
|
280
|
+
gitBacked: model.context.gitBacked,
|
|
281
|
+
team: teamOf(model.backlog.status),
|
|
282
|
+
cards,
|
|
283
|
+
linkedRepositories: input.linkedRepositories ?? [],
|
|
284
|
+
ticketFormat: input.ticketFormat ?? "none",
|
|
285
|
+
diagnostics: model.diagnostics,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export type WorkRequest =
|
|
290
|
+
| { action: "capture"; text: string; repository?: string; ticket?: string }
|
|
291
|
+
| { action: "refresh" }
|
|
292
|
+
| { action: "share-preview"; workset: string; include?: string[] }
|
|
293
|
+
| { action: "share"; workset: string; hash: string; include?: string[]; key: string }
|
|
294
|
+
| { action: "claim" | "release"; workset: string; members: string[]; key: string }
|
|
295
|
+
| { action: "start-manual"; workset: string; members: string[] };
|
|
296
|
+
|
|
297
|
+
export type WorkRefusalKind = "prerequisite" | "access" | "conflict" | "stale" | "failed";
|
|
298
|
+
|
|
299
|
+
export type WorkResult =
|
|
300
|
+
| {
|
|
301
|
+
ok: true;
|
|
302
|
+
preview?: SharePreview;
|
|
303
|
+
prompts?: Partial<Record<TerminalAgent, string>>[];
|
|
304
|
+
needsTake?: string[];
|
|
305
|
+
}
|
|
306
|
+
| { ok: false; kind: WorkRefusalKind; reason: string };
|
|
307
|
+
|
|
308
|
+
export interface WorkServiceDeps {
|
|
309
|
+
writable: boolean;
|
|
310
|
+
inputFor: (companionPath: string, refresh?: boolean) => Promise<Omit<WorkInput, "writable">>;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const NOT_WRITABLE = "start Studio with --writable to change Work";
|
|
314
|
+
|
|
315
|
+
function refusal(kind: WorkRefusalKind, reason: string): WorkResult {
|
|
316
|
+
return { ok: false, kind, reason };
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function policyActionOf(
|
|
320
|
+
action: Exclude<WorkRequest["action"], "refresh" | "capture">,
|
|
321
|
+
): WorkActionId {
|
|
322
|
+
return action === "share-preview" ? "share" : action;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
async function capture(
|
|
326
|
+
companionPath: string,
|
|
327
|
+
request: Extract<WorkRequest, { action: "capture" }>,
|
|
328
|
+
): Promise<WorkResult> {
|
|
329
|
+
const ticket = request.ticket?.trim();
|
|
330
|
+
if (ticket && (await companionTicketFormat(companionPath)) !== "jira") {
|
|
331
|
+
throw new WorksetError(TICKETS_OFF);
|
|
332
|
+
}
|
|
333
|
+
await createOutcome(
|
|
334
|
+
companionPath,
|
|
335
|
+
{ text: request.text, repository: request.repository ?? "", ...(ticket ? { ticket } : {}) },
|
|
336
|
+
await linkedRepositoryIdentities(companionPath),
|
|
337
|
+
);
|
|
338
|
+
return { ok: true };
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export function createWorkServices(deps: WorkServiceDeps) {
|
|
342
|
+
const failures = new Map<string, GitFailure>();
|
|
343
|
+
|
|
344
|
+
const inputOf = async (companionPath: string): Promise<WorkInput> => ({
|
|
345
|
+
...(await deps.inputFor(companionPath)),
|
|
346
|
+
writable: deps.writable,
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
async function act(companionPath: string, request: WorkRequest): Promise<WorkResult> {
|
|
350
|
+
if (request.action === "refresh") {
|
|
351
|
+
const [refreshed] = await Promise.all([
|
|
352
|
+
refreshTeam(companionPath),
|
|
353
|
+
deps.inputFor(companionPath, true).catch(() => undefined),
|
|
354
|
+
]);
|
|
355
|
+
if ("failure" in refreshed) {
|
|
356
|
+
failures.set(companionPath, refreshed.failure);
|
|
357
|
+
return refusal("failed", refreshed.failure.message);
|
|
358
|
+
}
|
|
359
|
+
failures.delete(companionPath);
|
|
360
|
+
return { ok: true };
|
|
361
|
+
}
|
|
362
|
+
if (!deps.writable) return refusal("access", NOT_WRITABLE);
|
|
363
|
+
if (request.action === "capture") return capture(companionPath, request);
|
|
364
|
+
|
|
365
|
+
const input = await inputOf(companionPath);
|
|
366
|
+
const model = await readWorkModel(companionPath, input, failures.get(companionPath));
|
|
367
|
+
const facts = model.facts.get(request.workset);
|
|
368
|
+
if (!facts) return refusal("prerequisite", `no Workset ${request.workset}`);
|
|
369
|
+
const entry = facts.inventory;
|
|
370
|
+
const refused = workActionRefusalOf(policyActionOf(request.action), facts, model.context);
|
|
371
|
+
if (refused) return refusal(refused.kind, refused.reason);
|
|
372
|
+
const operator = model.context.operator;
|
|
373
|
+
const members = activeMembers(facts.inventory);
|
|
374
|
+
const bound =
|
|
375
|
+
request.action === "claim" || request.action === "release"
|
|
376
|
+
? claimGroupOf(entry, model.backlog)
|
|
377
|
+
: members;
|
|
378
|
+
if ("members" in request && !sameMembers(bound, request.members)) {
|
|
379
|
+
return refusal("stale", `its changes are now ${bound.join(", ")}; review it again`);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
switch (request.action) {
|
|
383
|
+
case "share-preview": {
|
|
384
|
+
const preview = await previewShare(companionPath, entry, model.backlog, {
|
|
385
|
+
include: request.include,
|
|
386
|
+
});
|
|
387
|
+
return "refusal" in preview
|
|
388
|
+
? refusal("prerequisite", preview.refusal)
|
|
389
|
+
: { ok: true, preview: preview.preview };
|
|
390
|
+
}
|
|
391
|
+
case "share": {
|
|
392
|
+
const outcome = await confirmShare(
|
|
393
|
+
companionPath,
|
|
394
|
+
{ hash: request.hash, include: request.include, transactionId: `tx-${request.key}` },
|
|
395
|
+
{
|
|
396
|
+
inventoryEntry: async (backlog) =>
|
|
397
|
+
findEntry(await readWorkInventory(companionPath), backlog, request.workset),
|
|
398
|
+
},
|
|
399
|
+
);
|
|
400
|
+
if (outcome.status === "shared") {
|
|
401
|
+
failures.delete(companionPath);
|
|
402
|
+
return { ok: true };
|
|
403
|
+
}
|
|
404
|
+
if (outcome.status === "failed") return refusal("failed", outcome.failure.message);
|
|
405
|
+
return refusal(outcome.status === "stale" ? "stale" : "conflict", outcome.reason);
|
|
406
|
+
}
|
|
407
|
+
case "claim":
|
|
408
|
+
case "release": {
|
|
409
|
+
if (!operator) return refusal("prerequisite", NO_OPERATOR);
|
|
410
|
+
const outcome = await updateClaim(companionPath, {
|
|
411
|
+
action: request.action,
|
|
412
|
+
members: request.members,
|
|
413
|
+
operator,
|
|
414
|
+
transactionId: `tx-${request.key}`,
|
|
415
|
+
workset: entry.id,
|
|
416
|
+
});
|
|
417
|
+
if (outcome.status === "accepted") {
|
|
418
|
+
failures.delete(companionPath);
|
|
419
|
+
return {
|
|
420
|
+
ok: true,
|
|
421
|
+
...(outcome.needsTake.length > 0 ? { needsTake: outcome.needsTake } : {}),
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
if (outcome.status === "failed") return refusal("failed", outcome.failure.message);
|
|
425
|
+
if (outcome.status === "stale") return refusal("stale", outcome.reason);
|
|
426
|
+
return refusal(outcome.kind, outcome.reason);
|
|
427
|
+
}
|
|
428
|
+
case "start-manual": {
|
|
429
|
+
const offers = offersFor(facts, input);
|
|
430
|
+
const needsPlan = offers.some((offer) => offer.action === "apply-change");
|
|
431
|
+
const problems = needsPlan ? await planProblems(companionPath, members) : [];
|
|
432
|
+
if (problems.length > 0) return refusal("conflict", problems.join("; "));
|
|
433
|
+
return { ok: true, prompts: offers.map((offer) => offer.prompts) };
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
async function reserveStart(
|
|
439
|
+
companionPath: string,
|
|
440
|
+
subject: { kind: "workset" | "change"; name: string },
|
|
441
|
+
): Promise<string | null> {
|
|
442
|
+
const model = await readWorkModel(
|
|
443
|
+
companionPath,
|
|
444
|
+
await inputOf(companionPath),
|
|
445
|
+
failures.get(companionPath),
|
|
446
|
+
);
|
|
447
|
+
const facts = [...model.facts.values()].find(({ inventory }) =>
|
|
448
|
+
subject.kind === "workset"
|
|
449
|
+
? inventory.id === subject.name
|
|
450
|
+
: inventory.members.some(
|
|
451
|
+
(member) => member.kind === "active" && member.name === subject.name,
|
|
452
|
+
),
|
|
453
|
+
);
|
|
454
|
+
if (!facts) return `this companion has no ${subject.kind} named ${subject.name}`;
|
|
455
|
+
const { inventory } = facts;
|
|
456
|
+
const members = activeMembers(inventory);
|
|
457
|
+
if (members.length === 0) {
|
|
458
|
+
return inventory.actionable ? null : (inventory.diagnostics[0] ?? "it cannot be started");
|
|
459
|
+
}
|
|
460
|
+
const refused = workActionRefusalOf("start-manual", facts, model.context);
|
|
461
|
+
if (refused) return refused.reason;
|
|
462
|
+
const problems = subject.kind === "change" ? await planProblems(companionPath, members) : [];
|
|
463
|
+
return problems.length > 0 ? problems.join("; ") : null;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
return {
|
|
467
|
+
async work(companionPath: string): Promise<StudioWorkPayload> {
|
|
468
|
+
return assembleWork(companionPath, await inputOf(companionPath), failures.get(companionPath));
|
|
469
|
+
},
|
|
470
|
+
act,
|
|
471
|
+
reserveStart,
|
|
472
|
+
};
|
|
473
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import readline from "node:readline/promises";
|
|
2
|
-
|
|
3
1
|
import { FRAMEWORK_NAME } from "../../framework";
|
|
4
2
|
import { FrictionRefusal } from "../../lib/friction/fields";
|
|
5
3
|
import { formatCommand } from "../../runtime/command-arg";
|
|
@@ -17,6 +15,7 @@ import {
|
|
|
17
15
|
} from "../../lib/triage/prepare";
|
|
18
16
|
import { recordTriageLauncher } from "../../lib/triage/session";
|
|
19
17
|
import { currentSession } from "../../runtime/session-id";
|
|
18
|
+
import { selectAgent } from "../agent-selector";
|
|
20
19
|
import { collectDoctorReport } from "./doctor";
|
|
21
20
|
|
|
22
21
|
interface TriageArgs {
|
|
@@ -57,35 +56,23 @@ export interface TriageDeps {
|
|
|
57
56
|
cwd?: string;
|
|
58
57
|
env?: Record<string, string | undefined>;
|
|
59
58
|
now?: Date;
|
|
60
|
-
/** Asks which agent to start; null when no terminal can ask. Defaults to a
|
|
59
|
+
/** Asks which agent to start; null when no terminal can ask. Defaults to a menu when stdin and stdout are TTYs. */
|
|
61
60
|
ask?: AskAgent | null;
|
|
62
61
|
collectDoctor?: (cwd: string) => Promise<unknown>;
|
|
63
62
|
launch?: typeof launchAgent;
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
type AskAgent = (
|
|
67
|
-
|
|
68
|
-
const askAgent: AskAgent = async (choices) => {
|
|
69
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
70
|
-
try {
|
|
71
|
-
const answer = await rl.question(`Start which agent? (${choices.join("/")}) `);
|
|
72
|
-
const picked = answer.trim().toLowerCase();
|
|
73
|
-
return choices.find((choice) => choice === picked) ?? null;
|
|
74
|
-
} finally {
|
|
75
|
-
rl.close();
|
|
76
|
-
}
|
|
77
|
-
};
|
|
65
|
+
type AskAgent = (agents: FoundAgent[]) => Promise<FoundAgent | null>;
|
|
78
66
|
|
|
79
67
|
async function chooseAgent(
|
|
80
68
|
requested: TriageAgent | null,
|
|
81
69
|
agents: FoundAgent[],
|
|
82
70
|
ask: AskAgent | null,
|
|
83
71
|
): Promise<{ found: FoundAgent } | { error: string }> {
|
|
84
|
-
|
|
85
|
-
const found = agents.find((agent) => agent.agent ===
|
|
86
|
-
return found ? { found } : { error };
|
|
87
|
-
}
|
|
88
|
-
if (requested) return pick(requested, `${TRIAGE_AGENT_NAMES[requested]} was not found on PATH.`);
|
|
72
|
+
if (requested) {
|
|
73
|
+
const found = agents.find((agent) => agent.agent === requested);
|
|
74
|
+
return found ? { found } : { error: `${TRIAGE_AGENT_NAMES[requested]} was not found on PATH.` };
|
|
75
|
+
}
|
|
89
76
|
if (agents.length === 0) {
|
|
90
77
|
return {
|
|
91
78
|
error: `No agent was found: install ${TRIAGE_AGENTS.map((id) => TRIAGE_AGENT_NAMES[id]).join(" or ")}, or start your own agent with the prompt in prompt.md.`,
|
|
@@ -94,8 +81,8 @@ async function chooseAgent(
|
|
|
94
81
|
if (agents.length === 1) return { found: agents[0]! };
|
|
95
82
|
const flags = agents.map((agent) => `--agent ${agent.agent}`).join(" or ");
|
|
96
83
|
if (!ask) return { error: `Several agents are installed; choose one with ${flags}.` };
|
|
97
|
-
const
|
|
98
|
-
return
|
|
84
|
+
const found = await ask(agents);
|
|
85
|
+
return found ? { found } : { error: `No agent chosen; choose one with ${flags}.` };
|
|
99
86
|
}
|
|
100
87
|
|
|
101
88
|
function printPaths(files: TriageSessionFiles): void {
|
|
@@ -152,7 +139,8 @@ export async function runTriageCommand(argv: string[] = [], deps: TriageDeps = {
|
|
|
152
139
|
return;
|
|
153
140
|
}
|
|
154
141
|
|
|
155
|
-
const
|
|
142
|
+
const terminal = Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
143
|
+
const ask = deps.ask === undefined ? (terminal ? selectAgent : null) : deps.ask;
|
|
156
144
|
const choice = await chooseAgent(args.agent, agents, ask);
|
|
157
145
|
if ("error" in choice) {
|
|
158
146
|
console.error(`${FRAMEWORK_NAME}: ${choice.error}`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
3
|
-
"sha512": "sha512-
|
|
2
|
+
"version": "1.0.1-canary.0",
|
|
3
|
+
"sha512": "sha512-5MM2kuh/ihpcEgM2DQhi0SeXbOahrasT0uaBgjUTdO7A5W1gComjzEcRbgqp2hikQH5K9NsrL9OiFun1Vwgx5A=="
|
|
4
4
|
}
|
|
@@ -323,8 +323,9 @@ export interface ChangeNext {
|
|
|
323
323
|
/**
|
|
324
324
|
* @command mate workflow next <change>
|
|
325
325
|
* @description Prints the stage a change is at and its next actions as a `## Next steps`
|
|
326
|
-
* section, writing nothing: the hand-off `mate workflow done` would print,
|
|
327
|
-
*
|
|
326
|
+
* section, writing nothing: the hand-off `mate workflow done` would print, less its
|
|
327
|
+
* `Start a fresh session` before apply, computed from the declaration, the change's Delivery
|
|
328
|
+
* Record and its tasks alone, whatever a session wrote.
|
|
328
329
|
* @flags
|
|
329
330
|
* - `--json` — emit a {@link ChangeNext}: `ok`, `change`, `stage`, `open`, `handoff`,
|
|
330
331
|
* `actions` and `optional`.
|
|
@@ -3,12 +3,10 @@ import fs from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
5
|
|
|
6
|
-
import { parse } from "yaml";
|
|
7
|
-
|
|
8
6
|
import { FRAMEWORK_NAME } from "../../../framework";
|
|
9
7
|
import { gitEnvironment } from "../../../runtime/companion-git";
|
|
10
8
|
import { checkoutCommonDir } from "../../../runtime/git-layout";
|
|
11
|
-
import type
|
|
9
|
+
import { localRootKind, type RootKind } from "../../../lib/orchestrator/root-context";
|
|
12
10
|
import {
|
|
13
11
|
collectWorkspaceInventory,
|
|
14
12
|
type WorkspaceInventoryPairingEntry,
|
|
@@ -60,21 +58,6 @@ export async function resolveUmbrella(cwd: string): Promise<string | null> {
|
|
|
60
58
|
return folder ? canonicalPath(folder) : null;
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
async function localRootKind(repoPath: string): Promise<RootKind | null> {
|
|
64
|
-
try {
|
|
65
|
-
const raw = await fs.readFile(
|
|
66
|
-
path.join(repoPath, `.${FRAMEWORK_NAME}`, "config", "framework.yaml"),
|
|
67
|
-
"utf8",
|
|
68
|
-
);
|
|
69
|
-
const config = parse(raw) as { type?: string } | null;
|
|
70
|
-
if (config?.type === "working" || config?.type === "hub") return config.type;
|
|
71
|
-
return "companion";
|
|
72
|
-
} catch (error) {
|
|
73
|
-
if ((error as NodeJS.ErrnoException).code === "ENOENT") return null;
|
|
74
|
-
return "companion";
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
61
|
const defaultDeps: WorkingCleanupCommandDeps = {
|
|
79
62
|
cwd: process.cwd(),
|
|
80
63
|
resolveGitRoot,
|