@spencerboucher/switchyard 0.13.0 → 0.14.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/README.md +4 -3
- package/dist/bridge/agent-channel.js +26 -0
- package/dist/bridge/resource-snapshot.js +47 -0
- package/dist/bridge/switchyard-bridge.js +11 -0
- package/dist/bridge/switchyard-terminal.js +39 -5
- package/dist/policies/worker.js +2084 -1725
- package/dist/switchyard.mjs +3670 -2388
- package/package.json +1 -1
- package/web-dist/assets/AutomationView-CcxKiLxM.js +2 -0
- package/web-dist/assets/{AutomationView-Cg7yk8nb.js.map → AutomationView-CcxKiLxM.js.map} +1 -1
- package/web-dist/assets/{jsx-runtime-D13aM9HY.js → Button-BKQW9doW.js} +2 -2
- package/web-dist/assets/Button-BKQW9doW.js.map +1 -0
- package/web-dist/assets/Card-WONLvqGM.js +2 -0
- package/web-dist/assets/{Card-sHm0eI2Q.js.map → Card-WONLvqGM.js.map} +1 -1
- package/web-dist/assets/Checkbox-D18Ch0n4.js +2 -0
- package/web-dist/assets/{Checkbox-CEvKyfJz.js.map → Checkbox-D18Ch0n4.js.map} +1 -1
- package/web-dist/assets/Copy-D6U5ewFc.js +2 -0
- package/web-dist/assets/{Copy-BHOLVthK.js.map → Copy-D6U5ewFc.js.map} +1 -1
- package/web-dist/assets/{DangerZone-og55TRug.js → DangerZone-Ch2KNmob.js} +2 -2
- package/web-dist/assets/{DangerZone-og55TRug.js.map → DangerZone-Ch2KNmob.js.map} +1 -1
- package/web-dist/assets/InteractionCard-Bd4Cr_Zi.js +4 -0
- package/web-dist/assets/InteractionCard-Bd4Cr_Zi.js.map +1 -0
- package/web-dist/assets/Menu-CDIEOsaM.js +2 -0
- package/web-dist/assets/Menu-CDIEOsaM.js.map +1 -0
- package/web-dist/assets/Overlay-QSBH5woa.js +2 -0
- package/web-dist/assets/Overlay-QSBH5woa.js.map +1 -0
- package/web-dist/assets/Priority-PUuNGK2s.js +2 -0
- package/web-dist/assets/{Priority-xSUsxoXm.js.map → Priority-PUuNGK2s.js.map} +1 -1
- package/web-dist/assets/SegmentedControl-D2kj3j7u.js +2 -0
- package/web-dist/assets/SegmentedControl-D2kj3j7u.js.map +1 -0
- package/web-dist/assets/Select-CpWLZnId.js +2 -0
- package/web-dist/assets/{Select-C5xlhWYb.js.map → Select-CpWLZnId.js.map} +1 -1
- package/web-dist/assets/Switch-DHX-YYPr.js +2 -0
- package/web-dist/assets/{Switch-dVcf-7Je.js.map → Switch-DHX-YYPr.js.map} +1 -1
- package/web-dist/assets/Tabs-BplxI0Eb.js +184 -0
- package/web-dist/assets/Tabs-BplxI0Eb.js.map +1 -0
- package/web-dist/assets/TextArea-BQPdfjO_.js +2 -0
- package/web-dist/assets/{TextArea-D8WB5GD8.js.map → TextArea-BQPdfjO_.js.map} +1 -1
- package/web-dist/assets/TextLink-CCc3WEdm.js +2 -0
- package/web-dist/assets/{TextLink-CrfA8AeH.js.map → TextLink-CCc3WEdm.js.map} +1 -1
- package/web-dist/assets/UINodeRenderer-Bxq4kPwg.js +4 -0
- package/web-dist/assets/UINodeRenderer-Bxq4kPwg.js.map +1 -0
- package/web-dist/assets/arrow-down-YwTzxo-r.js +2 -0
- package/web-dist/assets/{arrow-down-C-iLrN8I.js.map → arrow-down-YwTzxo-r.js.map} +1 -1
- package/web-dist/assets/arrow-up-Bzh112dp.js +2 -0
- package/web-dist/assets/{arrow-up-Dj-VTKx4.js.map → arrow-up-Bzh112dp.js.map} +1 -1
- package/web-dist/assets/attention-BwQ0PjVB.js +2 -0
- package/web-dist/assets/attention-BwQ0PjVB.js.map +1 -0
- package/web-dist/assets/automations-BSV9KuSH.js +2 -0
- package/web-dist/assets/automations-BSV9KuSH.js.map +1 -0
- package/web-dist/assets/board-C8N8_GS0.js +10 -0
- package/web-dist/assets/{board-aS6ooJpx.js.map → board-C8N8_GS0.js.map} +1 -1
- package/web-dist/assets/calendar-clock-CwOgyN2z.js +2 -0
- package/web-dist/assets/{calendar-clock-B8zE4JsX.js.map → calendar-clock-CwOgyN2z.js.map} +1 -1
- package/web-dist/assets/chevron-right-aaHL5Igi.js +2 -0
- package/web-dist/assets/{chevron-right-evVLS6hq.js.map → chevron-right-aaHL5Igi.js.map} +1 -1
- package/web-dist/assets/code-BmxcCLin.js +25 -0
- package/web-dist/assets/code-BmxcCLin.js.map +1 -0
- package/web-dist/assets/{describe-w4KmQFfU.js → describe-Nw-EGTvb.js} +3 -3
- package/web-dist/assets/{describe-w4KmQFfU.js.map → describe-Nw-EGTvb.js.map} +1 -1
- package/web-dist/assets/drafts-CbBiiFKw.js +13 -0
- package/web-dist/assets/drafts-CbBiiFKw.js.map +1 -0
- package/web-dist/assets/enroll-2bd2qhh1.js +2 -0
- package/web-dist/assets/{enroll-DPKdD0en.js.map → enroll-2bd2qhh1.js.map} +1 -1
- package/web-dist/assets/external-link-CI-Uzhfh.js +2 -0
- package/web-dist/assets/{external-link-3jjTxo92.js.map → external-link-CI-Uzhfh.js.map} +1 -1
- package/web-dist/assets/hand-HCdmhGph.js +2 -0
- package/web-dist/assets/{hand-UPoHamrn.js.map → hand-HCdmhGph.js.map} +1 -1
- package/web-dist/assets/index-5cSRL594.js +11 -0
- package/web-dist/assets/index-5cSRL594.js.map +1 -0
- package/web-dist/assets/index-f4tQ91xN.css +2 -0
- package/web-dist/assets/key-round-DIA3lje5.js +2 -0
- package/web-dist/assets/{key-round-VDbE9E4X.js.map → key-round-DIA3lje5.js.map} +1 -1
- package/web-dist/assets/link-2-D6l0YZ-8.js +2 -0
- package/web-dist/assets/{link-2-CaMlUDRG.js.map → link-2-D6l0YZ-8.js.map} +1 -1
- package/web-dist/assets/logic-CzU-NdeO.js +2 -0
- package/web-dist/assets/{logic-B46fwD-8.js.map → logic-CzU-NdeO.js.map} +1 -1
- package/web-dist/assets/more-tcGYFcpM.js +2 -0
- package/web-dist/assets/more-tcGYFcpM.js.map +1 -0
- package/web-dist/assets/pencil-BtK08_f_.js +2 -0
- package/web-dist/assets/{pencil-DI8QbCN8.js.map → pencil-BtK08_f_.js.map} +1 -1
- package/web-dist/assets/play-j138GLHB.js +2 -0
- package/web-dist/assets/{play-CjoDg3ws.js.map → play-j138GLHB.js.map} +1 -1
- package/web-dist/assets/plus-D935l0Os.js +2 -0
- package/web-dist/assets/{plus-BLP-wIYD.js.map → plus-D935l0Os.js.map} +1 -1
- package/web-dist/assets/{policyLogic-7OOzM_xa.js → policyLogic-4ByNprLE.js} +2 -2
- package/web-dist/assets/{policyLogic-7OOzM_xa.js.map → policyLogic-4ByNprLE.js.map} +1 -1
- package/web-dist/assets/preload-helper-dybNq0aL.js +3 -0
- package/web-dist/assets/preload-helper-dybNq0aL.js.map +1 -0
- package/web-dist/assets/presence-BnGwJNSq.js +2 -0
- package/web-dist/assets/{presence-05bJD5G3.js.map → presence-BnGwJNSq.js.map} +1 -1
- package/web-dist/assets/queue-BH_AgQ1C.js +2 -0
- package/web-dist/assets/queue-BH_AgQ1C.js.map +1 -0
- package/web-dist/assets/registry-D8Ph1G2W.js +2 -0
- package/web-dist/assets/registry-D8Ph1G2W.js.map +1 -0
- package/web-dist/assets/{repo-BA_bnCvu.js → repo-Pn-s_Ggk.js} +2 -2
- package/web-dist/assets/{repo-BA_bnCvu.js.map → repo-Pn-s_Ggk.js.map} +1 -1
- package/web-dist/assets/settings-DjBmhTW8.js +9 -0
- package/web-dist/assets/settings-DjBmhTW8.js.map +1 -0
- package/web-dist/assets/states-f12WE0Zx.js +58 -0
- package/web-dist/assets/states-f12WE0Zx.js.map +1 -0
- package/web-dist/assets/terminal-DKqo1lis.js +2 -0
- package/web-dist/assets/{terminal-BOV_MXPZ.js.map → terminal-DKqo1lis.js.map} +1 -1
- package/web-dist/assets/terminal-login-BSJdzvzq.js +2 -0
- package/web-dist/assets/{terminal-login-C0n8cXqn.js.map → terminal-login-BSJdzvzq.js.map} +1 -1
- package/web-dist/assets/timer-CyFp7DQs.js +2 -0
- package/web-dist/assets/{timer-BCIucSXh.js.map → timer-CyFp7DQs.js.map} +1 -1
- package/web-dist/assets/useBreakpoint-kT0J1Dnk.js +2 -0
- package/web-dist/assets/{useBreakpoint-CYDIV-KM.js.map → useBreakpoint-kT0J1Dnk.js.map} +1 -1
- package/web-dist/assets/useNow-Cul-GfCg.js +2 -0
- package/web-dist/assets/useNow-Cul-GfCg.js.map +1 -0
- package/web-dist/assets/useResource-Bzqxz-K_.js +2 -0
- package/web-dist/assets/{useResource-DHtFcID5.js.map → useResource-Bzqxz-K_.js.map} +1 -1
- package/web-dist/index.html +13 -12
- package/web-dist/sw.js +1 -1
- package/web-dist/sw.js.map +1 -1
- package/web-dist/assets/AutomationView-Cg7yk8nb.js +0 -2
- package/web-dist/assets/Card-sHm0eI2Q.js +0 -2
- package/web-dist/assets/Checkbox-CEvKyfJz.js +0 -2
- package/web-dist/assets/Copy-BHOLVthK.js +0 -2
- package/web-dist/assets/InteractionCard-B-yhxwKs.js +0 -6
- package/web-dist/assets/InteractionCard-B-yhxwKs.js.map +0 -1
- package/web-dist/assets/Menu-Cyt18mF2.js +0 -2
- package/web-dist/assets/Menu-Cyt18mF2.js.map +0 -1
- package/web-dist/assets/Overlay-BPNYBq3V.js +0 -2
- package/web-dist/assets/Overlay-BPNYBq3V.js.map +0 -1
- package/web-dist/assets/Priority-xSUsxoXm.js +0 -2
- package/web-dist/assets/SegmentedControl-DaBwumC0.js +0 -2
- package/web-dist/assets/SegmentedControl-DaBwumC0.js.map +0 -1
- package/web-dist/assets/Select-C5xlhWYb.js +0 -2
- package/web-dist/assets/Switch-dVcf-7Je.js +0 -2
- package/web-dist/assets/Tabs-93APobOB.js +0 -184
- package/web-dist/assets/Tabs-93APobOB.js.map +0 -1
- package/web-dist/assets/TextArea-D8WB5GD8.js +0 -2
- package/web-dist/assets/TextLink-CrfA8AeH.js +0 -2
- package/web-dist/assets/arrow-down-C-iLrN8I.js +0 -2
- package/web-dist/assets/arrow-up-Dj-VTKx4.js +0 -2
- package/web-dist/assets/attention-C8rfu6Uw.js +0 -2
- package/web-dist/assets/attention-C8rfu6Uw.js.map +0 -1
- package/web-dist/assets/automations-DQxUzi5Q.js +0 -2
- package/web-dist/assets/automations-DQxUzi5Q.js.map +0 -1
- package/web-dist/assets/board-aS6ooJpx.js +0 -10
- package/web-dist/assets/calendar-clock-B8zE4JsX.js +0 -2
- package/web-dist/assets/chevron-right-evVLS6hq.js +0 -2
- package/web-dist/assets/code-Zr5DqwWI.js +0 -25
- package/web-dist/assets/code-Zr5DqwWI.js.map +0 -1
- package/web-dist/assets/enroll-DPKdD0en.js +0 -2
- package/web-dist/assets/external-link-3jjTxo92.js +0 -2
- package/web-dist/assets/hand-UPoHamrn.js +0 -2
- package/web-dist/assets/index-DFNY2EUd.css +0 -2
- package/web-dist/assets/index-DPScWz2I.js +0 -11
- package/web-dist/assets/index-DPScWz2I.js.map +0 -1
- package/web-dist/assets/jsx-runtime-D13aM9HY.js.map +0 -1
- package/web-dist/assets/key-round-VDbE9E4X.js +0 -2
- package/web-dist/assets/link-2-CaMlUDRG.js +0 -2
- package/web-dist/assets/logic-B46fwD-8.js +0 -2
- package/web-dist/assets/more-CiyGP5GD.js +0 -2
- package/web-dist/assets/more-CiyGP5GD.js.map +0 -1
- package/web-dist/assets/pencil-DI8QbCN8.js +0 -2
- package/web-dist/assets/play-CjoDg3ws.js +0 -2
- package/web-dist/assets/plus-BLP-wIYD.js +0 -2
- package/web-dist/assets/preload-helper-B2m1UyXR.js +0 -13
- package/web-dist/assets/preload-helper-B2m1UyXR.js.map +0 -1
- package/web-dist/assets/presence-05bJD5G3.js +0 -2
- package/web-dist/assets/queue-BcbJqzTY.js +0 -2
- package/web-dist/assets/queue-BcbJqzTY.js.map +0 -1
- package/web-dist/assets/settings-D03MF_Kx.js +0 -7
- package/web-dist/assets/settings-D03MF_Kx.js.map +0 -1
- package/web-dist/assets/shared-Bxc2JM1K.js +0 -3
- package/web-dist/assets/shared-Bxc2JM1K.js.map +0 -1
- package/web-dist/assets/states-DynH8-o6.js +0 -58
- package/web-dist/assets/states-DynH8-o6.js.map +0 -1
- package/web-dist/assets/terminal-BOV_MXPZ.js +0 -2
- package/web-dist/assets/terminal-login-C0n8cXqn.js +0 -2
- package/web-dist/assets/timer-BCIucSXh.js +0 -2
- package/web-dist/assets/useBreakpoint-CYDIV-KM.js +0 -2
- package/web-dist/assets/useNow-0tMsLHnB.js +0 -2
- package/web-dist/assets/useNow-0tMsLHnB.js.map +0 -1
- package/web-dist/assets/useResource-DHtFcID5.js +0 -2
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
A coding agent has to run where your repositories, toolchains and logins are: your laptop, a workstation, a home server. You, on the other hand, are not always sitting in front of that machine. Switchyard keeps the agents where the work is and lets you follow along from anywhere: start a session from your phone, answer the question it asks while you are on your laptop, take over from a terminal, and get a notification when the result is ready for review. Every client looks at the same live session, and closing one never stops the work.
|
|
6
6
|
|
|
7
|
-
On top of interactive sessions it adds tasks, a board, scheduled automations and a review flow, so an agent can work through a backlog while you are away and hand everything back for you to accept.
|
|
7
|
+
On top of interactive sessions it adds tasks, a board, scheduled automations and a review flow, so an agent can work through a backlog while you are away and hand everything back for you to accept. Switchyard aims to preserve continuity with your evolving Pi setup: plugins own their workflows and optional adapters translate supported interactions, not arbitrary custom terminal UIs. See [plugin ownership](docs/plugin-boundaries.md).
|
|
8
8
|
|
|
9
9
|
## How it fits together
|
|
10
10
|
|
|
@@ -118,7 +118,7 @@ switchyard up
|
|
|
118
118
|
```sh
|
|
119
119
|
docker run -d --name switchyard -p 127.0.0.1:7400:7400 -v switchyard-data:/data \
|
|
120
120
|
-e SWITCHYARD_PUBLIC_URL=https://switchyard.example.com \
|
|
121
|
-
ghcr.io/justmytwospence/switchyard:0.
|
|
121
|
+
ghcr.io/justmytwospence/switchyard:0.14.0
|
|
122
122
|
# Single sign-on is required off localhost: see docs/auth.md
|
|
123
123
|
```
|
|
124
124
|
|
|
@@ -132,7 +132,7 @@ switchyard host install-service # launchd on macOS, a systemd user service on
|
|
|
132
132
|
|
|
133
133
|
Settings › Hosts › Add host shows these three commands with your token filled in. To build from source instead, see [docs/development.md](docs/development.md).
|
|
134
134
|
|
|
135
|
-
[docs/deployment.md](docs/deployment.md) has recipes for Caddy, Traefik, nginx and Tailscale, a compose file, and every setting. A typed Node client for scripts and CI
|
|
135
|
+
[docs/deployment.md](docs/deployment.md) has recipes for Caddy, Traefik, nginx and Tailscale, a compose file, and every setting. A typed Node client for scripts and CI accompanies the release; see [docs/client-sdk.md](docs/client-sdk.md) for its API and limitations.
|
|
136
136
|
|
|
137
137
|
## Security model
|
|
138
138
|
|
|
@@ -157,6 +157,7 @@ Switchyard is young and moving quickly. It is tested against Pi `>=1.4.0 <1.6.0`
|
|
|
157
157
|
| [Deployment](docs/deployment.md) | Single machine, server, reverse proxies, VPNs, hosts, environment reference, privilege model |
|
|
158
158
|
| [Sign-in and devices](docs/auth.md) | The owner model, single sign-on, passkeys, terminal approval, single sign-on, host enrollment, revocation |
|
|
159
159
|
| [CLI](docs/cli.md) | Every `switchyard` command and credentials |
|
|
160
|
+
| [Keyboard shortcuts](docs/keyboard-shortcuts.md) | Vim-style app navigation, palette controls and the `?` help sheet |
|
|
160
161
|
| [Terminal sessions](docs/terminal-sessions.md) | Pi's own TUI for every session, from any terminal, and the herdr integration |
|
|
161
162
|
| [Operations](docs/operations.md) | Backup, restore, migrations, retention, logs, health, diagnostics |
|
|
162
163
|
| [Policies](docs/policies.md) | Agent tools, guardrails, approvals and budgets |
|
|
@@ -309,6 +309,32 @@ export function createAgentChannel(options) {
|
|
|
309
309
|
noteHumanInput(r.args.humanInputId);
|
|
310
310
|
receipt(r, { humanInputId: r.args.humanInputId });
|
|
311
311
|
}
|
|
312
|
+
else if (r.method === "resources.snapshot") {
|
|
313
|
+
const handler = handlers.get(r.method);
|
|
314
|
+
if (!handler || !options.getCapabilities().resourceSnapshot)
|
|
315
|
+
throw channelError("unsupported_capability", "Resource inspection is unavailable");
|
|
316
|
+
if (!r.args ||
|
|
317
|
+
typeof r.args !== "object" ||
|
|
318
|
+
Array.isArray(r.args) ||
|
|
319
|
+
Object.keys(r.args).length !== 0)
|
|
320
|
+
throw channelError("invalid_request", "Resource inspection expects empty arguments");
|
|
321
|
+
const binding = configuration;
|
|
322
|
+
const result = await handler(r.args, r);
|
|
323
|
+
if (configuration !== binding || r.nativeSessionId !== syncNative())
|
|
324
|
+
throw channelError("conflict", "Bridge binding changed during resource inspection");
|
|
325
|
+
const frame = {
|
|
326
|
+
type: "bridge.receipt",
|
|
327
|
+
requestId: r.requestId,
|
|
328
|
+
runtimeId: r.runtimeId,
|
|
329
|
+
nativeSessionId: r.nativeSessionId,
|
|
330
|
+
bindingId: r.bindingId,
|
|
331
|
+
ok: true,
|
|
332
|
+
result,
|
|
333
|
+
};
|
|
334
|
+
if (Buffer.byteLength(JSON.stringify(frame), "utf8") > 128 * 1024)
|
|
335
|
+
throw channelError("invalid_request", "Resource snapshot exceeds bridge frame limit");
|
|
336
|
+
receipt(r, result);
|
|
337
|
+
}
|
|
312
338
|
else {
|
|
313
339
|
const handler = handlers.get(r.method);
|
|
314
340
|
if (!handler)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { isAbsolute } from "node:path";
|
|
2
|
+
/** Only provenance and guard booleans cross the bridge; never settings or draft contents. */
|
|
3
|
+
export function resourceSnapshot(pi, ctx, pendingDialogs = 0) {
|
|
4
|
+
const paths = new Set();
|
|
5
|
+
const add = (source) => {
|
|
6
|
+
const path = source.sourceInfo?.path;
|
|
7
|
+
if (typeof path === "string" && !path.startsWith("builtin:") && isAbsolute(path)) {
|
|
8
|
+
if (path.length > 4096)
|
|
9
|
+
throw new Error("Resource path exceeds 4096 characters");
|
|
10
|
+
paths.add(path);
|
|
11
|
+
if (paths.size > 2048)
|
|
12
|
+
throw new Error("Resource snapshot exceeds 2048 paths");
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
for (const tool of pi.getAllTools?.() ?? [])
|
|
16
|
+
add(tool);
|
|
17
|
+
for (const command of pi.getCommands?.() ?? []) {
|
|
18
|
+
if (command.source === "extension")
|
|
19
|
+
add(command);
|
|
20
|
+
}
|
|
21
|
+
let projectTrusted = null;
|
|
22
|
+
try {
|
|
23
|
+
const trust = ctx.isProjectTrusted?.();
|
|
24
|
+
if (typeof trust === "boolean")
|
|
25
|
+
projectTrusted = trust;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// Unknown trust must never authorize project discovery.
|
|
29
|
+
}
|
|
30
|
+
let hasEditorDraft = true;
|
|
31
|
+
try {
|
|
32
|
+
const text = ctx.ui?.getEditorText?.();
|
|
33
|
+
if (typeof text === "string")
|
|
34
|
+
hasEditorDraft = text.length > 0;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// Inspection remains available; a full reload must fail closed without a draft guard.
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
cwd: ctx.cwd,
|
|
41
|
+
projectTrusted,
|
|
42
|
+
reportedExtensionPaths: [...paths].sort(),
|
|
43
|
+
hasEditorDraft,
|
|
44
|
+
pendingDialogs,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=resource-snapshot.js.map
|
|
@@ -14,6 +14,7 @@ import { LineSplitter } from "./lines.js";
|
|
|
14
14
|
import { createMessageDelivery } from "./message-delivery.js";
|
|
15
15
|
import { modelInfo } from "./pi-model.js";
|
|
16
16
|
import { installPolicyHooks } from "./policy.js";
|
|
17
|
+
import { resourceSnapshot } from "./resource-snapshot.js";
|
|
17
18
|
export default function switchyardBridge(pi) {
|
|
18
19
|
const socketPath = process.env.SWITCHYARD_BRIDGE_SOCKET;
|
|
19
20
|
if (!socketPath)
|
|
@@ -24,6 +25,7 @@ export default function switchyardBridge(pi) {
|
|
|
24
25
|
let ctx = null;
|
|
25
26
|
let dialogs = 0;
|
|
26
27
|
let toolPolicy = false;
|
|
28
|
+
let snapshotRegistered = false;
|
|
27
29
|
const channel = createAgentChannel({
|
|
28
30
|
send: (record) => {
|
|
29
31
|
try {
|
|
@@ -44,9 +46,16 @@ export default function switchyardBridge(pi) {
|
|
|
44
46
|
messageDelivery: true,
|
|
45
47
|
editorDraftGuard: true,
|
|
46
48
|
toolPolicy,
|
|
49
|
+
resourceSnapshot: snapshotRegistered,
|
|
47
50
|
}),
|
|
48
51
|
policyRequired: process.env.SWITCHYARD_POLICY_REQUIRED === "1",
|
|
49
52
|
});
|
|
53
|
+
const removeSnapshot = channel.registerCommand("resources.snapshot", () => {
|
|
54
|
+
if (!ctx)
|
|
55
|
+
throw new Error("Session is not ready");
|
|
56
|
+
return resourceSnapshot(pi, ctx, dialogs);
|
|
57
|
+
});
|
|
58
|
+
snapshotRegistered = true;
|
|
50
59
|
toolPolicy = installPolicyHooks(pi, channel);
|
|
51
60
|
registerAgentTools(pi, channel);
|
|
52
61
|
const delivery = createMessageDelivery(pi, {
|
|
@@ -179,6 +188,8 @@ export default function switchyardBridge(pi) {
|
|
|
179
188
|
channel.noteHumanInput();
|
|
180
189
|
});
|
|
181
190
|
pi.on("session_shutdown", () => {
|
|
191
|
+
snapshotRegistered = false;
|
|
192
|
+
removeSnapshot();
|
|
182
193
|
delivery.close();
|
|
183
194
|
channel.close();
|
|
184
195
|
try {
|
|
@@ -23,6 +23,7 @@ import { LineSplitter } from "./lines.js";
|
|
|
23
23
|
import { createMessageDelivery } from "./message-delivery.js";
|
|
24
24
|
import { modelInfo } from "./pi-model.js";
|
|
25
25
|
import { installPolicyHooks } from "./policy.js";
|
|
26
|
+
import { resourceSnapshot } from "./resource-snapshot.js";
|
|
26
27
|
const PATCHED = Symbol.for("switchyard.terminal");
|
|
27
28
|
const WRAPPED = Symbol.for("switchyard.terminal.wrapped");
|
|
28
29
|
const REMOTE_UI_CHANNEL = "switchyard.remote-ui.v1";
|
|
@@ -117,6 +118,7 @@ export default function switchyardTerminal(pi) {
|
|
|
117
118
|
let remoteBacked = 0;
|
|
118
119
|
let nativeDialogs = 0;
|
|
119
120
|
let toolPolicy = false;
|
|
121
|
+
let snapshotRegistered = false;
|
|
120
122
|
const channel = createAgentChannel({
|
|
121
123
|
send: (record) => {
|
|
122
124
|
try {
|
|
@@ -144,9 +146,16 @@ export default function switchyardTerminal(pi) {
|
|
|
144
146
|
}
|
|
145
147
|
})(),
|
|
146
148
|
toolPolicy,
|
|
149
|
+
resourceSnapshot: snapshotRegistered,
|
|
147
150
|
}),
|
|
148
151
|
policyRequired: process.env.SWITCHYARD_POLICY_REQUIRED === "1",
|
|
149
152
|
});
|
|
153
|
+
const removeSnapshot = channel.registerCommand("resources.snapshot", () => {
|
|
154
|
+
if (!ctx)
|
|
155
|
+
throw new Error("Session is not ready");
|
|
156
|
+
return resourceSnapshot(pi, ctx, nativeDialogs + pending.size);
|
|
157
|
+
});
|
|
158
|
+
snapshotRegistered = true;
|
|
150
159
|
toolPolicy = installPolicyHooks(pi, channel);
|
|
151
160
|
registerAgentTools(pi, channel);
|
|
152
161
|
const delivery = createMessageDelivery(pi, {
|
|
@@ -668,14 +677,37 @@ export default function switchyardTerminal(pi) {
|
|
|
668
677
|
});
|
|
669
678
|
return;
|
|
670
679
|
}
|
|
671
|
-
case "reload":
|
|
672
|
-
|
|
673
|
-
|
|
680
|
+
case "reload": {
|
|
681
|
+
const guard = (c) => {
|
|
682
|
+
if (!c)
|
|
683
|
+
return "Session is not ready";
|
|
684
|
+
if (!c.isIdle() || c.hasPendingMessages?.())
|
|
685
|
+
return "Wait for Pi to become idle";
|
|
686
|
+
const snapshot = resourceSnapshot(pi, c, nativeDialogs + pending.size);
|
|
687
|
+
if (snapshot.pendingDialogs > 0)
|
|
688
|
+
return "Answer the open dialog first";
|
|
689
|
+
if (snapshot.hasEditorDraft)
|
|
690
|
+
return "Clear the terminal editor draft before reloading";
|
|
691
|
+
return null;
|
|
692
|
+
};
|
|
693
|
+
const error = guard(ctx);
|
|
694
|
+
if (error) {
|
|
695
|
+
respond(id, type, undefined, error);
|
|
674
696
|
return;
|
|
675
697
|
}
|
|
676
|
-
|
|
677
|
-
|
|
698
|
+
runInternal(async (c) => {
|
|
699
|
+
// Recheck at the actual command boundary, not just when queued by the host.
|
|
700
|
+
const error = guard(c);
|
|
701
|
+
if (error || typeof c.reload !== "function") {
|
|
702
|
+
respond(id, type, undefined, error ?? "This Pi cannot reload extensions");
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
respond(id, type);
|
|
706
|
+
await c.reload();
|
|
707
|
+
return;
|
|
708
|
+
});
|
|
678
709
|
return;
|
|
710
|
+
}
|
|
679
711
|
case "complete": {
|
|
680
712
|
const text = String(cmd.text ?? "");
|
|
681
713
|
if (!completer?.getSuggestions || !/^\/\S+ /.test(text) || text.includes("\n")) {
|
|
@@ -916,6 +948,8 @@ export default function switchyardTerminal(pi) {
|
|
|
916
948
|
send({ type: "ui_prompt", event: event.type, kind: event.kind, title: event.title ?? null });
|
|
917
949
|
});
|
|
918
950
|
on("session_shutdown", () => {
|
|
951
|
+
snapshotRegistered = false;
|
|
952
|
+
removeSnapshot();
|
|
919
953
|
delivery.close();
|
|
920
954
|
channel.close();
|
|
921
955
|
});
|