@uniqbit/mate-core 1.0.0-canary.9 → 1.0.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/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/vscode/release-vsix.json +2 -2
- package/src/cli/commands/working/cleanup.ts +1 -18
- package/src/cli/companion-link-wizard.tsx +158 -91
- package/src/cli/usage.ts +1 -1
- package/src/lib/agent-credential.ts +131 -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/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/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
|
@@ -4,10 +4,13 @@ import type { StudioInventory, StudioInventoryCompanion } from "./inventory";
|
|
|
4
4
|
|
|
5
5
|
export type StudioView =
|
|
6
6
|
| "dashboard"
|
|
7
|
+
| "chat"
|
|
8
|
+
| "work"
|
|
7
9
|
| "workflow"
|
|
8
10
|
| "getting-started"
|
|
9
11
|
| "specs"
|
|
10
12
|
| "skills"
|
|
13
|
+
| "mcp"
|
|
11
14
|
| "vault"
|
|
12
15
|
| "reports"
|
|
13
16
|
| "usage"
|
|
@@ -16,10 +19,13 @@ export type StudioView =
|
|
|
16
19
|
|
|
17
20
|
export const STUDIO_VIEWS: readonly StudioView[] = [
|
|
18
21
|
"dashboard",
|
|
22
|
+
"chat",
|
|
23
|
+
"work",
|
|
19
24
|
"workflow",
|
|
20
25
|
"getting-started",
|
|
21
26
|
"specs",
|
|
22
27
|
"skills",
|
|
28
|
+
"mcp",
|
|
23
29
|
"vault",
|
|
24
30
|
"reports",
|
|
25
31
|
"usage",
|
|
@@ -34,9 +40,9 @@ export const STUDIO_MODES: readonly StudioMode[] = ["engineering", "analysis"];
|
|
|
34
40
|
|
|
35
41
|
/** Views only the mode is offered, in navigation order. */
|
|
36
42
|
export const MODE_VIEWS: Readonly<Record<StudioMode, readonly StudioView[]>> = {
|
|
37
|
-
engineering: ["dashboard", "workflow", "skills", "getting-started"],
|
|
43
|
+
engineering: ["dashboard", "work", "workflow", "skills", "mcp", "getting-started"],
|
|
38
44
|
// The same `dashboard` id; `Content` renders each mode's own Overview.
|
|
39
|
-
analysis: ["dashboard"],
|
|
45
|
+
analysis: ["dashboard", "chat"],
|
|
40
46
|
};
|
|
41
47
|
|
|
42
48
|
/** Views every mode is offered, in navigation order. */
|
|
@@ -55,8 +61,16 @@ export const LANDING_VIEW: Readonly<Record<StudioMode, StudioView>> = {
|
|
|
55
61
|
analysis: "dashboard",
|
|
56
62
|
};
|
|
57
63
|
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
/** Views the server offers only when started for them; never read from a request. */
|
|
65
|
+
export interface StudioOffers {
|
|
66
|
+
readonly chat?: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function viewsFor(mode: StudioMode, offers: StudioOffers = {}): readonly StudioView[] {
|
|
70
|
+
return [
|
|
71
|
+
...MODE_VIEWS[mode].filter((view) => view !== "chat" || offers.chat === true),
|
|
72
|
+
...SHARED_VIEWS,
|
|
73
|
+
];
|
|
60
74
|
}
|
|
61
75
|
|
|
62
76
|
/** How Studio was started; fixed for the server's life, never read from a request. */
|
|
@@ -69,6 +83,11 @@ export interface StudioModePolicy {
|
|
|
69
83
|
readonly profile: StudioProfile;
|
|
70
84
|
readonly enabled: readonly StudioMode[];
|
|
71
85
|
readonly defaultMode: StudioMode;
|
|
86
|
+
/**
|
|
87
|
+
* The Analysis chat: under the standard profile only on a local-only Studio; always under the
|
|
88
|
+
* appliance profile, where Studio's access token and origin check guard it.
|
|
89
|
+
*/
|
|
90
|
+
readonly chat: boolean;
|
|
72
91
|
}
|
|
73
92
|
|
|
74
93
|
const POLICIES: Readonly<Record<StudioProfile, StudioModePolicy>> = {
|
|
@@ -76,16 +95,24 @@ const POLICIES: Readonly<Record<StudioProfile, StudioModePolicy>> = {
|
|
|
76
95
|
profile: "standard",
|
|
77
96
|
enabled: Object.freeze(["engineering", "analysis"] as const),
|
|
78
97
|
defaultMode: "engineering",
|
|
98
|
+
chat: false,
|
|
79
99
|
}),
|
|
80
100
|
appliance: Object.freeze({
|
|
81
101
|
profile: "appliance",
|
|
82
102
|
enabled: Object.freeze(["analysis"] as const),
|
|
83
103
|
defaultMode: "analysis",
|
|
104
|
+
chat: true,
|
|
84
105
|
}),
|
|
85
106
|
};
|
|
86
107
|
|
|
87
|
-
export function modePolicy(
|
|
88
|
-
|
|
108
|
+
export function modePolicy(
|
|
109
|
+
profile: StudioProfile = "standard",
|
|
110
|
+
offers: StudioOffers = {},
|
|
111
|
+
): StudioModePolicy {
|
|
112
|
+
const policy = POLICIES[profile];
|
|
113
|
+
return offers.chat === true && profile === "standard"
|
|
114
|
+
? Object.freeze({ ...policy, chat: true })
|
|
115
|
+
: policy;
|
|
89
116
|
}
|
|
90
117
|
|
|
91
118
|
const STANDARD_POLICY = modePolicy("standard");
|
|
@@ -201,8 +228,10 @@ export function effectiveMode(requested: StudioMode | null, policy: StudioModePo
|
|
|
201
228
|
}
|
|
202
229
|
|
|
203
230
|
/** A view the mode is not offered reads as the mode's landing view. */
|
|
204
|
-
function readView(value: string | null, mode: StudioMode): StudioView {
|
|
205
|
-
return viewsFor(mode).includes(value as StudioView)
|
|
231
|
+
function readView(value: string | null, mode: StudioMode, offers: StudioOffers): StudioView {
|
|
232
|
+
return viewsFor(mode, offers).includes(value as StudioView)
|
|
233
|
+
? (value as StudioView)
|
|
234
|
+
: LANDING_VIEW[mode];
|
|
206
235
|
}
|
|
207
236
|
|
|
208
237
|
function readText(value: string | null): string | null {
|
|
@@ -239,7 +268,7 @@ function readVault(params: URLSearchParams, policy: StudioModePolicy): StudioVau
|
|
|
239
268
|
*/
|
|
240
269
|
export function parse(url: URL, policy: StudioModePolicy = STANDARD_POLICY): StudioSelection {
|
|
241
270
|
const base = readBase(url.searchParams, policy);
|
|
242
|
-
const view = readView(url.searchParams.get(VIEW_PARAM), base.studioMode);
|
|
271
|
+
const view = readView(url.searchParams.get(VIEW_PARAM), base.studioMode, policy);
|
|
243
272
|
if (view === "vault") return readVault(url.searchParams, policy);
|
|
244
273
|
return { ...base, view };
|
|
245
274
|
}
|
|
@@ -267,8 +296,12 @@ export function switchView(selection: StudioSelection, view: StudioView): Studio
|
|
|
267
296
|
* Keeps the view, and the vault's target with it, when the mode is offered the
|
|
268
297
|
* view; otherwise lands on the mode's landing view.
|
|
269
298
|
*/
|
|
270
|
-
export function switchMode(
|
|
271
|
-
|
|
299
|
+
export function switchMode(
|
|
300
|
+
selection: StudioSelection,
|
|
301
|
+
studioMode: StudioMode,
|
|
302
|
+
offers: StudioOffers = {},
|
|
303
|
+
): StudioSelection {
|
|
304
|
+
if (viewsFor(studioMode, offers).includes(selection.view)) {
|
|
272
305
|
return { ...selection, studioMode, refresh: false };
|
|
273
306
|
}
|
|
274
307
|
return switchView({ ...selection, studioMode }, LANDING_VIEW[studioMode]);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createStudioAccess,
|
|
3
3
|
exchangeStudioToken,
|
|
4
|
+
isLoopbackHostname,
|
|
4
5
|
normalizeOrigin,
|
|
5
6
|
readBearer,
|
|
6
7
|
studioAddress,
|
|
@@ -19,6 +20,7 @@ import {
|
|
|
19
20
|
import { collectStudioInventory, type StudioInventory } from "./inventory";
|
|
20
21
|
import { assembleCompanionPayload, type StudioCompanionResponse } from "./payload";
|
|
21
22
|
import { createReportStore, isReportId, REPORT_LIMITS, type ReportStore } from "./reports";
|
|
23
|
+
import { ConfigError } from "../../../lib/orchestrator/types";
|
|
22
24
|
import { WorksetError } from "../../../lib/workset/record";
|
|
23
25
|
import type { PluginService, StudioSocketHandler } from "../../../tools/setup/service";
|
|
24
26
|
import { registeredServices } from "../../../tools/setup/service-registry";
|
|
@@ -32,6 +34,9 @@ import {
|
|
|
32
34
|
NO_SERVICES,
|
|
33
35
|
} from "./service-host";
|
|
34
36
|
import {
|
|
37
|
+
CHAT_CREDENTIAL_ROUTE,
|
|
38
|
+
CHAT_ROUTE,
|
|
39
|
+
CHAT_SESSION_ROUTE,
|
|
35
40
|
REPORTS_ROUTE,
|
|
36
41
|
REPORT_VIEW_PREFIX,
|
|
37
42
|
SERVICE_ASSET_PREFIX,
|
|
@@ -59,6 +64,18 @@ import {
|
|
|
59
64
|
type StudioProfile,
|
|
60
65
|
} from "./selection";
|
|
61
66
|
import { errorMessage } from "../../../runtime/error-message";
|
|
67
|
+
import { physicalPath } from "../../../runtime/physical-path";
|
|
68
|
+
import {
|
|
69
|
+
CHAT_EFFORTS,
|
|
70
|
+
CHAT_HARNESSES,
|
|
71
|
+
CHAT_MODELS,
|
|
72
|
+
type ChatAgent,
|
|
73
|
+
renderPrompt,
|
|
74
|
+
} from "../../../lib/studio-chat/agent";
|
|
75
|
+
import { AgentCredentialError, checkedCredential } from "../../../lib/agent-credential";
|
|
76
|
+
import { type ChatCredentials, createChatCredentials } from "../../../lib/studio-chat/credential";
|
|
77
|
+
import { chatSession } from "../../../lib/studio-chat/session";
|
|
78
|
+
import { ChatTurns } from "../../../lib/studio-chat/turns";
|
|
62
79
|
import type { SpecGraphCache } from "./graph";
|
|
63
80
|
import { createStudioSnapshotCache, type StudioSnapshotCache } from "./snapshot";
|
|
64
81
|
import type { StudioPage } from "./views/model";
|
|
@@ -71,6 +88,7 @@ import {
|
|
|
71
88
|
} from "./terminal";
|
|
72
89
|
import type { StudioServices } from "./services";
|
|
73
90
|
import type { UsageCache } from "../../../lib/usage/cache";
|
|
91
|
+
import { createWorkServices } from "./work";
|
|
74
92
|
import { studioAppAsset, type StudioApp } from "./studio-app";
|
|
75
93
|
import { terminalAsset } from "./terminal-assets";
|
|
76
94
|
import {
|
|
@@ -146,6 +164,9 @@ export interface StudioServerDeps {
|
|
|
146
164
|
homeDir?: string;
|
|
147
165
|
terminal?: Partial<TerminalRegistryOptions>;
|
|
148
166
|
launchableAgents?: typeof launchableAgents;
|
|
167
|
+
chatAgent?: ChatAgent;
|
|
168
|
+
chatCredentials?: ChatCredentials;
|
|
169
|
+
chatTurns?: ChatTurns;
|
|
149
170
|
/** The plugin services Studio mounts; the registered plugins' when absent. */
|
|
150
171
|
services?: readonly PluginService[];
|
|
151
172
|
/** The environment services read their connection from; `process.env` when absent. */
|
|
@@ -207,6 +228,7 @@ open this address with <code>?token=</code> followed by that value.</p></main></
|
|
|
207
228
|
*/
|
|
208
229
|
type RouteKind =
|
|
209
230
|
| { kind: "read"; methods: readonly string[] }
|
|
231
|
+
| { kind: "chat"; methods: readonly string[] }
|
|
210
232
|
| { kind: "write"; methods: readonly string[]; writable?: string }
|
|
211
233
|
| { kind: "terminal"; methods: readonly string[]; privileged: boolean }
|
|
212
234
|
| { kind: "session"; methods: readonly string[] };
|
|
@@ -214,8 +236,11 @@ type RouteKind =
|
|
|
214
236
|
const ORIGIN_REASON = {
|
|
215
237
|
write: "a change must come from Studio's own page",
|
|
216
238
|
terminal: "the terminal is reachable only from Studio's own page",
|
|
239
|
+
chat: "the chat is reachable only from Studio's own page",
|
|
217
240
|
} as const;
|
|
218
241
|
|
|
242
|
+
const CHAT_OFF_REASON = "the chat is offered only when Studio listens on localhost alone";
|
|
243
|
+
|
|
219
244
|
const READS = ["GET", "HEAD"] as const;
|
|
220
245
|
|
|
221
246
|
/** A service route by the access its method declares; a WebSocket is guarded like a write. */
|
|
@@ -241,6 +266,11 @@ function routeOf(
|
|
|
241
266
|
const { pathname } = url;
|
|
242
267
|
if (pathname === REPORTS_ROUTE && method === "POST")
|
|
243
268
|
return { kind: "session", methods: ["POST"] };
|
|
269
|
+
if (pathname === CHAT_ROUTE) return { kind: "chat", methods: ["POST"] };
|
|
270
|
+
if (pathname === CHAT_SESSION_ROUTE) return { kind: "chat", methods: ["GET"] };
|
|
271
|
+
if (pathname === CHAT_CREDENTIAL_ROUTE) {
|
|
272
|
+
return { kind: "chat", methods: ["GET", "HEAD", "PUT", "DELETE"] };
|
|
273
|
+
}
|
|
244
274
|
if (service) return serviceRouteKind(service, method);
|
|
245
275
|
// A service that is not mounted answers nothing, whatever the method.
|
|
246
276
|
if (pathname.startsWith(SERVICE_ROUTE_PREFIX)) return { kind: "read", methods: [method] };
|
|
@@ -261,6 +291,11 @@ function routeOf(
|
|
|
261
291
|
return { kind: "read", methods: READS };
|
|
262
292
|
}
|
|
263
293
|
|
|
294
|
+
function oneOf<T extends string>(allowed: readonly T[], value: unknown): T | undefined | null {
|
|
295
|
+
if (value === undefined) return undefined;
|
|
296
|
+
return allowed.includes(value as T) ? (value as T) : null;
|
|
297
|
+
}
|
|
298
|
+
|
|
264
299
|
function refused(reason: string, status: number): Response {
|
|
265
300
|
return new Response(JSON.stringify({ reason }), {
|
|
266
301
|
status,
|
|
@@ -324,6 +359,8 @@ async function readCapped(request: Request, limit: number): Promise<string | nul
|
|
|
324
359
|
return over ? null : Buffer.concat(chunks).toString("utf8");
|
|
325
360
|
}
|
|
326
361
|
|
|
362
|
+
export const CHAT_LIMITS = { bodyBytes: 256 * 1024, messages: 100 } as const;
|
|
363
|
+
|
|
327
364
|
const TOKEN_REASON =
|
|
328
365
|
"Studio's access token is required; open the address Studio printed when it started";
|
|
329
366
|
|
|
@@ -360,6 +397,7 @@ export interface StudioFetchOptions extends Pick<
|
|
|
360
397
|
publicOrigin?: string | null;
|
|
361
398
|
/** Enables the terminal; the invocation sets its default detach window. */
|
|
362
399
|
terminal?: boolean;
|
|
400
|
+
chat?: boolean;
|
|
363
401
|
/** Studio's built application; paths the handler does not serve itself go to it. */
|
|
364
402
|
app?: StudioApp | null;
|
|
365
403
|
}
|
|
@@ -385,7 +423,7 @@ export function createStudioFetch(
|
|
|
385
423
|
/** Created on the first Graph request, so other views never load the graph index. */
|
|
386
424
|
let graphs: Promise<SpecGraphCache> | null = null;
|
|
387
425
|
const writable = options.writable === true;
|
|
388
|
-
const policy = modePolicy(options.profile ?? "standard");
|
|
426
|
+
const policy = modePolicy(options.profile ?? "standard", { chat: options.chat === true });
|
|
389
427
|
const reports = deps.reports ?? createReportStore();
|
|
390
428
|
const env = deps.env ?? process.env;
|
|
391
429
|
// Created before the terminal and the services, so neither needs the other.
|
|
@@ -412,6 +450,15 @@ export function createStudioFetch(
|
|
|
412
450
|
collectInventory: inventory,
|
|
413
451
|
launchCompanion,
|
|
414
452
|
launchableAgents: (companionPath) => agentsFor(companionPath),
|
|
453
|
+
...(writable
|
|
454
|
+
? {
|
|
455
|
+
reserveWork: (companionPath, action, subject) =>
|
|
456
|
+
work.reserveStart(companionPath, {
|
|
457
|
+
kind: action.subject === "change" ? "change" : "workset",
|
|
458
|
+
name: subject,
|
|
459
|
+
}),
|
|
460
|
+
}
|
|
461
|
+
: {}),
|
|
415
462
|
}),
|
|
416
463
|
mateCommand: process.argv.slice(0, 2),
|
|
417
464
|
sessions,
|
|
@@ -464,6 +511,133 @@ export function createStudioFetch(
|
|
|
464
511
|
});
|
|
465
512
|
};
|
|
466
513
|
|
|
514
|
+
const chatTurns = deps.chatTurns ?? new ChatTurns();
|
|
515
|
+
let chatCredentials: ChatCredentials | null = deps.chatCredentials ?? null;
|
|
516
|
+
const credentialsForChat = () =>
|
|
517
|
+
(chatCredentials ??= createChatCredentials({ appliance: options.profile === "appliance" }));
|
|
518
|
+
let chatAgent: Promise<ChatAgent> | null = deps.chatAgent
|
|
519
|
+
? Promise.resolve(deps.chatAgent)
|
|
520
|
+
: null;
|
|
521
|
+
const chatCompanion = async (digest: unknown) =>
|
|
522
|
+
typeof digest === "string" && COMPANION_DIGEST_PATTERN.test(digest)
|
|
523
|
+
? selectedCompanion(digest, inventory)
|
|
524
|
+
: null;
|
|
525
|
+
const chatTurn = async (request: Request, server?: StudioUpgrader): Promise<Response> => {
|
|
526
|
+
const busy = () =>
|
|
527
|
+
chatTurns.stopped
|
|
528
|
+
? json({ reason: "Studio stopped" }, 503)
|
|
529
|
+
: json({ reason: "Studio is already answering two questions; try again shortly" }, 429);
|
|
530
|
+
if (chatTurns.full) return busy();
|
|
531
|
+
const raw = await readCapped(request, CHAT_LIMITS.bodyBytes);
|
|
532
|
+
if (raw === null) return json({ reason: "the conversation exceeds the size limit" }, 413);
|
|
533
|
+
let body: {
|
|
534
|
+
companion?: unknown;
|
|
535
|
+
messages?: unknown;
|
|
536
|
+
harness?: unknown;
|
|
537
|
+
model?: unknown;
|
|
538
|
+
effort?: unknown;
|
|
539
|
+
};
|
|
540
|
+
try {
|
|
541
|
+
body = JSON.parse(raw) as typeof body;
|
|
542
|
+
} catch {
|
|
543
|
+
return json({ reason: "a chat request needs a JSON body" }, 400);
|
|
544
|
+
}
|
|
545
|
+
if (!body || typeof body !== "object" || !Array.isArray(body.messages)) {
|
|
546
|
+
return json({ reason: "a chat request needs a companion and its messages" }, 400);
|
|
547
|
+
}
|
|
548
|
+
if (body.messages.length > CHAT_LIMITS.messages) {
|
|
549
|
+
return json({ reason: `a conversation holds at most ${CHAT_LIMITS.messages} messages` }, 413);
|
|
550
|
+
}
|
|
551
|
+
const selected = await chatCompanion(body.companion);
|
|
552
|
+
if (!selected) return json({ reason: NO_COMPANION }, 400);
|
|
553
|
+
const harness = oneOf(CHAT_HARNESSES, body.harness);
|
|
554
|
+
if (harness === null)
|
|
555
|
+
return json({ reason: `the harness must be one of ${CHAT_HARNESSES.join(", ")}` }, 400);
|
|
556
|
+
const models = CHAT_MODELS[harness ?? "claude-code"].map(({ id }) => id);
|
|
557
|
+
const model = oneOf(models, body.model);
|
|
558
|
+
const effort = oneOf(CHAT_EFFORTS, body.effort);
|
|
559
|
+
if (model === null)
|
|
560
|
+
return json({ reason: `the model must be one of ${models.join(", ")}` }, 400);
|
|
561
|
+
if (effort === null)
|
|
562
|
+
return json({ reason: `the effort must be one of ${CHAT_EFFORTS.join(", ")}` }, 400);
|
|
563
|
+
const { createUIMessageStreamResponse, safeValidateUIMessages } = await import("ai");
|
|
564
|
+
const messages = await safeValidateUIMessages({ messages: body.messages });
|
|
565
|
+
if (!messages.success) return json({ reason: "the conversation is not valid" }, 400);
|
|
566
|
+
if (renderPrompt(messages.data) === null) {
|
|
567
|
+
return json({ reason: "the conversation must end with a question" }, 400);
|
|
568
|
+
}
|
|
569
|
+
chatAgent ??= import("../../../lib/studio-chat/harness-chat-agent")
|
|
570
|
+
.then(({ createHarnessChatAgent }) => {
|
|
571
|
+
const credentials = credentialsForChat();
|
|
572
|
+
return createHarnessChatAgent({ credential: () => credentials.auth() });
|
|
573
|
+
})
|
|
574
|
+
.catch((error: unknown) => {
|
|
575
|
+
chatAgent = null;
|
|
576
|
+
throw error;
|
|
577
|
+
});
|
|
578
|
+
let agent: ChatAgent;
|
|
579
|
+
try {
|
|
580
|
+
agent = await chatAgent;
|
|
581
|
+
} catch (error) {
|
|
582
|
+
return json({ reason: `the chat agent could not load: ${errorMessage(error)}` }, 503);
|
|
583
|
+
}
|
|
584
|
+
const turn = chatTurns.begin(request.signal);
|
|
585
|
+
if (!turn) return busy();
|
|
586
|
+
let stream: ReturnType<ChatAgent["turn"]>;
|
|
587
|
+
try {
|
|
588
|
+
stream = agent.turn({
|
|
589
|
+
companionPath: selected.path,
|
|
590
|
+
messages: messages.data,
|
|
591
|
+
signal: turn.signal,
|
|
592
|
+
...(harness ? { harness } : {}),
|
|
593
|
+
...(model ? { model } : {}),
|
|
594
|
+
...(effort ? { effort } : {}),
|
|
595
|
+
});
|
|
596
|
+
} catch (error) {
|
|
597
|
+
turn.abandon();
|
|
598
|
+
return json({ reason: `the chat agent did not start: ${errorMessage(error)}` }, 500);
|
|
599
|
+
}
|
|
600
|
+
// A turn may be quiet while the agent reads; the stream's keep-alives hold the connection.
|
|
601
|
+
server?.timeout?.(request, 0);
|
|
602
|
+
return createUIMessageStreamResponse({
|
|
603
|
+
stream: turn.track(stream),
|
|
604
|
+
keepAliveMs: 15_000,
|
|
605
|
+
headers: { "cache-control": "no-store" },
|
|
606
|
+
});
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
const chatCredential = async (request: Request): Promise<Response> => {
|
|
610
|
+
try {
|
|
611
|
+
const credentials = credentialsForChat();
|
|
612
|
+
if (request.method === "PUT") {
|
|
613
|
+
const raw = await readCapped(request, 16_384);
|
|
614
|
+
if (raw === null) return json({ reason: "the credential exceeds the size limit" }, 413);
|
|
615
|
+
let body: unknown = null;
|
|
616
|
+
try {
|
|
617
|
+
body = JSON.parse(raw);
|
|
618
|
+
} catch {}
|
|
619
|
+
if (!body || typeof body !== "object") {
|
|
620
|
+
return json({ reason: "a credential needs a JSON body with kind and value" }, 400);
|
|
621
|
+
}
|
|
622
|
+
const { kind, value } = body as { kind?: unknown; value?: unknown };
|
|
623
|
+
await credentials.set(checkedCredential(kind, value));
|
|
624
|
+
} else if (request.method === "DELETE") {
|
|
625
|
+
credentials.clear();
|
|
626
|
+
}
|
|
627
|
+
return json(credentials.status());
|
|
628
|
+
} catch (error) {
|
|
629
|
+
if (error instanceof AgentCredentialError) return json({ reason: error.message }, 400);
|
|
630
|
+
return json({ reason: "the chat credential could not be stored" }, 500);
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
const chatSessionReport = async (url: URL): Promise<Response> => {
|
|
635
|
+
if (!(await chatCompanion(url.searchParams.get(COMPANION_PARAM)))) {
|
|
636
|
+
return json({ reason: NO_COMPANION }, 400);
|
|
637
|
+
}
|
|
638
|
+
return json(chatSession());
|
|
639
|
+
};
|
|
640
|
+
|
|
467
641
|
/** One document's model, with the terminal state its address needs. */
|
|
468
642
|
const collectPage = async (url: URL): Promise<StudioPage> => {
|
|
469
643
|
const page = await collectStudioPage(url, policy, inventory, snapshots, writable);
|
|
@@ -562,6 +736,26 @@ export function createStudioFetch(
|
|
|
562
736
|
};
|
|
563
737
|
|
|
564
738
|
let usage: Promise<UsageCache> | undefined = deps.usage && Promise.resolve(deps.usage);
|
|
739
|
+
const work = createWorkServices({
|
|
740
|
+
writable,
|
|
741
|
+
inputFor: async (companionPath, refresh = false) => {
|
|
742
|
+
const url = new URL("http://studio.local/");
|
|
743
|
+
url.searchParams.set(COMPANION_PARAM, companionDigest(companionPath));
|
|
744
|
+
if (refresh) url.searchParams.set(REFRESH_PARAM, "1");
|
|
745
|
+
const page = await collectPage(url);
|
|
746
|
+
const payload = page.payload;
|
|
747
|
+
const targeted = page.terminal?.target?.path === companionPath;
|
|
748
|
+
return {
|
|
749
|
+
changes: payload?.changes ?? [],
|
|
750
|
+
shipped: payload?.shipped ?? [],
|
|
751
|
+
...(payload?.skillInventory ? { skills: payload.skillInventory } : {}),
|
|
752
|
+
terminalAgents: targeted ? (page.terminal?.agents ?? []) : [],
|
|
753
|
+
linkedRepositories: payload?.linkedRepositories ?? [],
|
|
754
|
+
...(payload?.ticketFormat ? { ticketFormat: payload.ticketFormat } : {}),
|
|
755
|
+
};
|
|
756
|
+
},
|
|
757
|
+
});
|
|
758
|
+
|
|
565
759
|
const studioServices: StudioServices = {
|
|
566
760
|
writable,
|
|
567
761
|
services: () => services.summaries(),
|
|
@@ -570,9 +764,16 @@ export function createStudioFetch(
|
|
|
570
764
|
return folder !== undefined && !deletableWithin(companionPath, folder);
|
|
571
765
|
},
|
|
572
766
|
addsCompanions: () => services.companions !== null,
|
|
767
|
+
physicalPath: (companionPath) => physicalPath(path.resolve(companionPath)),
|
|
573
768
|
modePolicy: policy,
|
|
574
769
|
page: collectPage,
|
|
575
770
|
callService,
|
|
771
|
+
work: async (digest) => work.work(await companionPathOf(digest)),
|
|
772
|
+
workAction: async (digest, request) => {
|
|
773
|
+
const result = await work.act(await companionPathOf(digest), request);
|
|
774
|
+
if (result.ok && request.action !== "share-preview") boardChanged(digest);
|
|
775
|
+
return result;
|
|
776
|
+
},
|
|
576
777
|
vault: async (digest, request) => {
|
|
577
778
|
const { vaultView } = await import("./views/vault/view");
|
|
578
779
|
return vaultView(vault, await companionPathOf(digest), request);
|
|
@@ -594,6 +795,20 @@ export function createStudioFetch(
|
|
|
594
795
|
if (!writable) throw new VaultPathError("start Studio with --writable to enable saving");
|
|
595
796
|
return vault.save(await companionPathOf(digest), filePath, content, token);
|
|
596
797
|
},
|
|
798
|
+
mcpManager: async (digest) => {
|
|
799
|
+
const { readMcpManagerView } = await import("./mcp-manager");
|
|
800
|
+
return readMcpManagerView(await companionPathOf(digest), env);
|
|
801
|
+
},
|
|
802
|
+
mcpManagerPreview: async (digest, next) => {
|
|
803
|
+
await companionPathOf(digest);
|
|
804
|
+
const { previewMcpManager } = await import("./mcp-manager");
|
|
805
|
+
return previewMcpManager(next, env);
|
|
806
|
+
},
|
|
807
|
+
mcpManagerSave: async (digest, next, token) => {
|
|
808
|
+
if (!writable) throw new ConfigError("start Studio with --writable to enable saving");
|
|
809
|
+
const { saveMcpManagerView } = await import("./mcp-manager");
|
|
810
|
+
return saveMcpManagerView(await companionPathOf(digest), next, token, env);
|
|
811
|
+
},
|
|
597
812
|
graph: async (digest) => {
|
|
598
813
|
const companionPath = await companionPathOf(digest);
|
|
599
814
|
graphs ??= import("./graph").then(({ createSpecGraphCache }) => createSpecGraphCache());
|
|
@@ -696,6 +911,20 @@ export function createStudioFetch(
|
|
|
696
911
|
return html(TOKEN_REQUIRED_PAGE, 401);
|
|
697
912
|
}
|
|
698
913
|
if (route.kind === "read") return null;
|
|
914
|
+
if (route.kind === "chat") {
|
|
915
|
+
if (!policy.chat) return refused(CHAT_OFF_REASON, 404);
|
|
916
|
+
// A browser sends no Origin on a same-origin GET; its fetch metadata, when it sends any,
|
|
917
|
+
// names the page instead. A cross-site GET cannot read the answer without CORS anyway.
|
|
918
|
+
const site = request.headers.get("sec-fetch-site");
|
|
919
|
+
const fromPage =
|
|
920
|
+
(request.method === "GET" || request.method === "HEAD") && !request.headers.has("origin")
|
|
921
|
+
? site === null || site === "same-origin"
|
|
922
|
+
: access.originMatches(request, acceptedOrigin);
|
|
923
|
+
if (!fromPage) {
|
|
924
|
+
return refused(ORIGIN_REASON.chat, 403);
|
|
925
|
+
}
|
|
926
|
+
return access.hasToken(request) ? null : refused(TOKEN_REASON, 401);
|
|
927
|
+
}
|
|
699
928
|
if (route.kind === "terminal" && !terminal) {
|
|
700
929
|
return refused("start Studio with --writable --terminal to enable the terminal", 404);
|
|
701
930
|
}
|
|
@@ -744,6 +973,12 @@ export function createStudioFetch(
|
|
|
744
973
|
if (route.kind === "session") return publishReport(request);
|
|
745
974
|
const refusal = refusalFor(route, request, url, acceptedOrigin);
|
|
746
975
|
if (refusal) return respond(refusal);
|
|
976
|
+
if (route.kind === "chat") {
|
|
977
|
+
if (url.pathname === CHAT_CREDENTIAL_ROUTE) return respond(await chatCredential(request));
|
|
978
|
+
return url.pathname === CHAT_SESSION_ROUTE
|
|
979
|
+
? chatSessionReport(url)
|
|
980
|
+
: chatTurn(request, server);
|
|
981
|
+
}
|
|
747
982
|
|
|
748
983
|
if (url.pathname === STUDIO_PING_ROUTE) {
|
|
749
984
|
return respond(new Response(null, { status: 204, headers: { "cache-control": "no-store" } }));
|
|
@@ -894,7 +1129,7 @@ export function createStudioFetch(
|
|
|
894
1129
|
handler.ready = ready;
|
|
895
1130
|
handler.close = async () => {
|
|
896
1131
|
vault.stop();
|
|
897
|
-
await terminal?.stopAll();
|
|
1132
|
+
await Promise.all([terminal?.stopAll(), chatTurns.stopAll()]);
|
|
898
1133
|
await (await ready).close();
|
|
899
1134
|
};
|
|
900
1135
|
return handler;
|
|
@@ -1067,6 +1302,14 @@ function reportOrigin(hostname: string, port: number): string {
|
|
|
1067
1302
|
return `http://${wildcard ? "127.0.0.1" : urlHost(hostname)}:${port}`;
|
|
1068
1303
|
}
|
|
1069
1304
|
|
|
1305
|
+
export function localOnly(hostname: string, options: StudioServerOptions): boolean {
|
|
1306
|
+
return (
|
|
1307
|
+
isLoopbackHostname(hostname) &&
|
|
1308
|
+
!options.publicOrigin &&
|
|
1309
|
+
(options.allowedHosts ?? []).length === 0
|
|
1310
|
+
);
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1070
1313
|
/**
|
|
1071
1314
|
* A bind failure propagates: the caller reports it and exits rather than
|
|
1072
1315
|
* opening a browser at a URL nothing answers.
|
|
@@ -1094,6 +1337,7 @@ export function startStudioServer(
|
|
|
1094
1337
|
publicOrigin: options.publicOrigin,
|
|
1095
1338
|
reportOrigin: () => reportOrigin(hostname, boundPort),
|
|
1096
1339
|
terminal: options.terminal === true,
|
|
1340
|
+
chat: localOnly(hostname, options),
|
|
1097
1341
|
detachMinutes: options.detachMinutes,
|
|
1098
1342
|
launchCompanion: options.launchCompanion,
|
|
1099
1343
|
noGit: options.noGit,
|
|
@@ -3,6 +3,12 @@ import type { FrictionState, MarkState } from "../../../runtime/friction-vocabul
|
|
|
3
3
|
import type { UsageRequest } from "../../../lib/usage/cache";
|
|
4
4
|
import type { UsageResponse } from "../../../lib/usage/types";
|
|
5
5
|
import type { StudioSpecGraph } from "./graph";
|
|
6
|
+
import type {
|
|
7
|
+
McpManagerPreview,
|
|
8
|
+
McpManagerSaveResult,
|
|
9
|
+
McpManagerState,
|
|
10
|
+
McpManagerView,
|
|
11
|
+
} from "./mcp-manager";
|
|
6
12
|
import type { StoredReport } from "./reports";
|
|
7
13
|
import type { StudioServiceSummary } from "./service-host";
|
|
8
14
|
import type { SkillAgent, SkillPreview } from "./skill-files";
|
|
@@ -11,6 +17,7 @@ import type { VaultConflict, VaultSaved } from "./vault";
|
|
|
11
17
|
import type { StudioPage } from "./views/model";
|
|
12
18
|
import type { MdNode } from "./views/vault/markdown-tree";
|
|
13
19
|
import type { VaultEntry, VaultView, VaultViewRequest } from "./views/vault/view";
|
|
20
|
+
import type { StudioWorkPayload, WorkRequest, WorkResult } from "./work";
|
|
14
21
|
|
|
15
22
|
/**
|
|
16
23
|
* What Studio's application may ask of the server it runs in. Core creates one
|
|
@@ -27,6 +34,8 @@ export interface StudioServices {
|
|
|
27
34
|
* Studio deletes only folders inside that source's folder.
|
|
28
35
|
*/
|
|
29
36
|
keepsFolder(companionPath: string): boolean;
|
|
37
|
+
/** The companion's path with links followed, as the chat's sandbox resolves it. */
|
|
38
|
+
physicalPath(companionPath: string): string;
|
|
30
39
|
/** Whether a mounted service adds companions by Git URL (its `companions` source). */
|
|
31
40
|
addsCompanions(): boolean;
|
|
32
41
|
/** The startup profile's Studio modes; every page selection is resolved through it. */
|
|
@@ -38,6 +47,13 @@ export interface StudioServices {
|
|
|
38
47
|
* caller's own guard stands for origin and token; the route's `writable` refusal applies.
|
|
39
48
|
*/
|
|
40
49
|
callService(request: Request): Promise<Response>;
|
|
50
|
+
/** The Work view's model for a registered companion; reads local Git refs only. */
|
|
51
|
+
work(companionDigest: string): Promise<StudioWorkPayload>;
|
|
52
|
+
/**
|
|
53
|
+
* One Work action, rechecked on the server: write mode, Workset and ownership. A refusal
|
|
54
|
+
* is a typed result, never a partial write.
|
|
55
|
+
*/
|
|
56
|
+
workAction(companionDigest: string, request: WorkRequest): Promise<WorkResult>;
|
|
41
57
|
/** The vault page: the bounded tree and the open folder or file. */
|
|
42
58
|
vault(companionDigest: string, request: VaultViewRequest): Promise<VaultView>;
|
|
43
59
|
/** A folder's entries, when first expanded; `null` when the listed tree lacks it. */
|
|
@@ -59,6 +75,16 @@ export interface StudioServices {
|
|
|
59
75
|
content: string,
|
|
60
76
|
token?: string,
|
|
61
77
|
): Promise<VaultSaved | VaultConflict>;
|
|
78
|
+
/** The companion's MCP servers, groups and audience selections; variables by name and set state, never a value. */
|
|
79
|
+
mcpManager(companionDigest: string): Promise<McpManagerView>;
|
|
80
|
+
/** Effective sets and variable states for unsaved state, or core's validation error; reads and writes nothing. */
|
|
81
|
+
mcpManagerPreview(companionDigest: string, next: McpManagerState): Promise<McpManagerPreview>;
|
|
82
|
+
/** Saves the whole next state; needs `writable`. A stale token is a conflict, not an error. */
|
|
83
|
+
mcpManagerSave(
|
|
84
|
+
companionDigest: string,
|
|
85
|
+
next: McpManagerState,
|
|
86
|
+
token: string,
|
|
87
|
+
): Promise<McpManagerSaveResult>;
|
|
62
88
|
/** The spec graph of the companion's canonical specs and archives; read-only, rebuilt when they change. */
|
|
63
89
|
graph(companionDigest: string): Promise<StudioSpecGraph>;
|
|
64
90
|
/** A registered companion's published reports, newest first; no paths or content. */
|
|
@@ -8,7 +8,13 @@ import {
|
|
|
8
8
|
readAudienceSelection,
|
|
9
9
|
} from "../../../tools/setup/dynamic-plugins/audiences";
|
|
10
10
|
import type { StudioInventory, StudioInventoryCompanion } from "./inventory";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
findAction,
|
|
13
|
+
promptArgs,
|
|
14
|
+
skillInstalledFor,
|
|
15
|
+
type StudioAction,
|
|
16
|
+
SUBJECT_PATTERN,
|
|
17
|
+
} from "./actions";
|
|
12
18
|
import { collectSkillInventory, type StudioSkillInventory } from "./mate-inventory";
|
|
13
19
|
import { listSpecs } from "./openspec-cli";
|
|
14
20
|
import { resolveCompanion } from "./selection";
|
|
@@ -94,6 +100,11 @@ export interface LaunchResolverOptions {
|
|
|
94
100
|
skillInventory?: (companionPath: string) => Promise<StudioSkillInventory>;
|
|
95
101
|
/** Whether the companion has a canonical spec for this capability, read at launch. */
|
|
96
102
|
specExists?: (companionPath: string, capability: string) => Promise<boolean>;
|
|
103
|
+
reserveWork?: (
|
|
104
|
+
companionPath: string,
|
|
105
|
+
action: StudioAction,
|
|
106
|
+
subject: string,
|
|
107
|
+
) => Promise<string | null>;
|
|
97
108
|
}
|
|
98
109
|
|
|
99
110
|
async function specInCompanion(companionPath: string, capability: string): Promise<boolean> {
|
|
@@ -151,15 +162,21 @@ export function createLaunchResolver(
|
|
|
151
162
|
if (!action) return { reason: "the requested action is not registered" };
|
|
152
163
|
const subject = request.subject;
|
|
153
164
|
if (typeof subject !== "string" || !SUBJECT_PATTERN.test(subject)) {
|
|
154
|
-
return { reason:
|
|
165
|
+
return { reason: `the action subject is not a valid ${action.subject} name` };
|
|
155
166
|
}
|
|
156
167
|
if (!skillInstalledFor(await skills(companion.path), action.skill, agent as TerminalAgent)) {
|
|
157
168
|
return {
|
|
158
169
|
reason: `the ${action.skill} skill is not installed for ${agent} in this companion`,
|
|
159
170
|
};
|
|
160
171
|
}
|
|
161
|
-
if (
|
|
162
|
-
|
|
172
|
+
if (action.subject === "spec") {
|
|
173
|
+
if (!(await specExists(companion.path, subject))) {
|
|
174
|
+
return { reason: `this companion has no spec named ${subject}` };
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
if (!options.reserveWork) return { reason: "Work starts are not available here" };
|
|
178
|
+
const refusal = await options.reserveWork(companion.path, action, subject);
|
|
179
|
+
if (refusal) return { reason: refusal };
|
|
163
180
|
}
|
|
164
181
|
return { ...launch, promptArgs: promptArgs(action, agent as TerminalAgent, subject) };
|
|
165
182
|
};
|