pi-kot 0.1.21 → 0.1.22
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/bin/pi-kot.mjs +148 -0
- package/client/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/client/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/client/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/client/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/client/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/client/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/client/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/client/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/client/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/client/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/client/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/client/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/client/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/client/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/client/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/client/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/client/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/client/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/client/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/client/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/client/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/client/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/client/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/client/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/client/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/client/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/client/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/client/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/client/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/client/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/client/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/client/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/client/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/client/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/client/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/client/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/client/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/client/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/client/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/client/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/client/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/client/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/client/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/client/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/client/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/client/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/client/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/client/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/client/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/client/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/client/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/client/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/client/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/client/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/client/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/client/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/client/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/client/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/client/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/client/assets/index-CE_Na97I.js +75 -0
- package/client/assets/index-CE_Na97I.js.map +1 -0
- package/client/assets/index-QP95zkpd.css +1 -0
- package/client/assets/rolldown-runtime-QTnfLwEv.js +1 -0
- package/client/assets/vendor-codemirror-CD3uCqRj.js +48 -0
- package/client/assets/vendor-codemirror-CD3uCqRj.js.map +1 -0
- package/client/assets/vendor-icons-W8thHNMl.js +2 -0
- package/client/assets/vendor-icons-W8thHNMl.js.map +1 -0
- package/client/assets/vendor-katex-4z5K3dyr.js +260 -0
- package/client/assets/vendor-katex-4z5K3dyr.js.map +1 -0
- package/client/assets/vendor-katex-CYlHEDRF.css +1 -0
- package/client/assets/vendor-markdown-BSzxNR_7.js +35 -0
- package/client/assets/vendor-markdown-BSzxNR_7.js.map +1 -0
- package/client/assets/vendor-prism-CQGp13s2.js +4 -0
- package/client/assets/vendor-prism-CQGp13s2.js.map +1 -0
- package/client/assets/vendor-xterm-BrP-ENHg.css +1 -0
- package/client/assets/vendor-xterm-DXwh06H3.js +36 -0
- package/client/assets/vendor-xterm-DXwh06H3.js.map +1 -0
- package/client/index.html +23 -0
- package/package.json +5 -3
- package/server/ask-user-question/envelope.d.ts +11 -0
- package/server/ask-user-question/envelope.d.ts.map +1 -0
- package/server/ask-user-question/envelope.js +41 -0
- package/server/ask-user-question/envelope.js.map +1 -0
- package/server/ask-user-question/plan-mode-question-tool.d.ts +26 -0
- package/server/ask-user-question/plan-mode-question-tool.d.ts.map +1 -0
- package/server/ask-user-question/plan-mode-question-tool.js +273 -0
- package/server/ask-user-question/plan-mode-question-tool.js.map +1 -0
- package/server/ask-user-question/prompt-strings.d.ts +4 -0
- package/server/ask-user-question/prompt-strings.d.ts.map +1 -0
- package/server/ask-user-question/prompt-strings.js +18 -0
- package/server/ask-user-question/prompt-strings.js.map +1 -0
- package/server/ask-user-question/registry.d.ts +39 -0
- package/server/ask-user-question/registry.d.ts.map +1 -0
- package/server/ask-user-question/registry.js +124 -0
- package/server/ask-user-question/registry.js.map +1 -0
- package/server/ask-user-question/tool.d.ts +4 -0
- package/server/ask-user-question/tool.d.ts.map +1 -0
- package/server/ask-user-question/tool.js +68 -0
- package/server/ask-user-question/tool.js.map +1 -0
- package/server/ask-user-question/types.d.ts +50 -0
- package/server/ask-user-question/types.d.ts.map +1 -0
- package/server/ask-user-question/types.js +7 -0
- package/server/ask-user-question/types.js.map +1 -0
- package/server/ask-user-question/validate.d.ts +3 -0
- package/server/ask-user-question/validate.d.ts.map +1 -0
- package/server/ask-user-question/validate.js +67 -0
- package/server/ask-user-question/validate.js.map +1 -0
- package/server/clone-provider.d.ts +55 -0
- package/server/clone-provider.d.ts.map +1 -0
- package/server/clone-provider.js +172 -0
- package/server/clone-provider.js.map +1 -0
- package/server/compaction-cards.d.ts +62 -0
- package/server/compaction-cards.d.ts.map +1 -0
- package/server/compaction-cards.js +180 -0
- package/server/compaction-cards.js.map +1 -0
- package/server/compaction-continuation.d.ts +112 -0
- package/server/compaction-continuation.d.ts.map +1 -0
- package/server/compaction-continuation.js +65 -0
- package/server/compaction-continuation.js.map +1 -0
- package/server/config-store.d.ts +97 -0
- package/server/config-store.d.ts.map +1 -0
- package/server/config-store.js +351 -0
- package/server/config-store.js.map +1 -0
- package/server/config.d.ts +24 -0
- package/server/config.d.ts.map +1 -0
- package/server/config.js +67 -0
- package/server/config.js.map +1 -0
- package/server/event-stream.d.ts +28 -0
- package/server/event-stream.d.ts.map +1 -0
- package/server/event-stream.js +153 -0
- package/server/event-stream.js.map +1 -0
- package/server/extension-manager.d.ts +116 -0
- package/server/extension-manager.d.ts.map +1 -0
- package/server/extension-manager.js +586 -0
- package/server/extension-manager.js.map +1 -0
- package/server/extension-scanner.d.ts +26 -0
- package/server/extension-scanner.d.ts.map +1 -0
- package/server/extension-scanner.js +107 -0
- package/server/extension-scanner.js.map +1 -0
- package/server/extension-ui-bridge.d.ts +35 -0
- package/server/extension-ui-bridge.d.ts.map +1 -0
- package/server/extension-ui-bridge.js +228 -0
- package/server/extension-ui-bridge.js.map +1 -0
- package/server/file-manager.d.ts +79 -0
- package/server/file-manager.d.ts.map +1 -0
- package/server/file-manager.js +535 -0
- package/server/file-manager.js.map +1 -0
- package/server/file-searcher.d.ts +29 -0
- package/server/file-searcher.d.ts.map +1 -0
- package/server/file-searcher.js +318 -0
- package/server/file-searcher.js.map +1 -0
- package/server/git-operations.d.ts +346 -0
- package/server/git-operations.d.ts.map +1 -0
- package/server/git-operations.js +884 -0
- package/server/git-operations.js.map +1 -0
- package/server/hunk-stager.d.ts +56 -0
- package/server/hunk-stager.d.ts.map +1 -0
- package/server/hunk-stager.js +137 -0
- package/server/hunk-stager.js.map +1 -0
- package/server/index.d.ts +21 -0
- package/server/index.d.ts.map +1 -0
- package/server/index.js +262 -0
- package/server/index.js.map +1 -0
- package/server/mcp/config.d.ts +23 -0
- package/server/mcp/config.d.ts.map +1 -0
- package/server/mcp/config.js +139 -0
- package/server/mcp/config.js.map +1 -0
- package/server/mcp/manager.d.ts +40 -0
- package/server/mcp/manager.d.ts.map +1 -0
- package/server/mcp/manager.js +435 -0
- package/server/mcp/manager.js.map +1 -0
- package/server/mcp/stdio-trust.d.ts +5 -0
- package/server/mcp/stdio-trust.d.ts.map +1 -0
- package/server/mcp/stdio-trust.js +78 -0
- package/server/mcp/stdio-trust.js.map +1 -0
- package/server/mcp/tool-bridge.d.ts +33 -0
- package/server/mcp/tool-bridge.d.ts.map +1 -0
- package/server/mcp/tool-bridge.js +138 -0
- package/server/mcp/tool-bridge.js.map +1 -0
- package/server/orchestration/config.d.ts +5 -0
- package/server/orchestration/config.d.ts.map +1 -0
- package/server/orchestration/config.js +35 -0
- package/server/orchestration/config.js.map +1 -0
- package/server/orchestration/event-bridge.d.ts +32 -0
- package/server/orchestration/event-bridge.d.ts.map +1 -0
- package/server/orchestration/event-bridge.js +110 -0
- package/server/orchestration/event-bridge.js.map +1 -0
- package/server/orchestration/inbox.d.ts +9 -0
- package/server/orchestration/inbox.d.ts.map +1 -0
- package/server/orchestration/inbox.js +186 -0
- package/server/orchestration/inbox.js.map +1 -0
- package/server/orchestration/init.d.ts +2 -0
- package/server/orchestration/init.d.ts.map +1 -0
- package/server/orchestration/init.js +22 -0
- package/server/orchestration/init.js.map +1 -0
- package/server/orchestration/store.d.ts +33 -0
- package/server/orchestration/store.d.ts.map +1 -0
- package/server/orchestration/store.js +331 -0
- package/server/orchestration/store.js.map +1 -0
- package/server/orchestration/tools.d.ts +15 -0
- package/server/orchestration/tools.d.ts.map +1 -0
- package/server/orchestration/tools.js +621 -0
- package/server/orchestration/tools.js.map +1 -0
- package/server/orchestration/types.d.ts +68 -0
- package/server/orchestration/types.d.ts.map +1 -0
- package/server/orchestration/types.js +43 -0
- package/server/orchestration/types.js.map +1 -0
- package/server/orchestration/worker-lifecycle.d.ts +15 -0
- package/server/orchestration/worker-lifecycle.d.ts.map +1 -0
- package/server/orchestration/worker-lifecycle.js +45 -0
- package/server/orchestration/worker-lifecycle.js.map +1 -0
- package/server/path-refs.d.ts +5 -0
- package/server/path-refs.d.ts.map +1 -0
- package/server/path-refs.js +249 -0
- package/server/path-refs.js.map +1 -0
- package/server/routes/_schemas.d.ts +16 -0
- package/server/routes/_schemas.d.ts.map +1 -0
- package/server/routes/_schemas.js +12 -0
- package/server/routes/_schemas.js.map +1 -0
- package/server/routes/ask-user-question.d.ts +3 -0
- package/server/routes/ask-user-question.d.ts.map +1 -0
- package/server/routes/ask-user-question.js +105 -0
- package/server/routes/ask-user-question.js.map +1 -0
- package/server/routes/auth.d.ts +8 -0
- package/server/routes/auth.d.ts.map +1 -0
- package/server/routes/auth.js +225 -0
- package/server/routes/auth.js.map +1 -0
- package/server/routes/config.d.ts +3 -0
- package/server/routes/config.d.ts.map +1 -0
- package/server/routes/config.js +602 -0
- package/server/routes/config.js.map +1 -0
- package/server/routes/control.d.ts +3 -0
- package/server/routes/control.d.ts.map +1 -0
- package/server/routes/control.js +365 -0
- package/server/routes/control.js.map +1 -0
- package/server/routes/exec.d.ts +3 -0
- package/server/routes/exec.d.ts.map +1 -0
- package/server/routes/exec.js +426 -0
- package/server/routes/exec.js.map +1 -0
- package/server/routes/extension-commands.d.ts +22 -0
- package/server/routes/extension-commands.d.ts.map +1 -0
- package/server/routes/extension-commands.js +178 -0
- package/server/routes/extension-commands.js.map +1 -0
- package/server/routes/extensions.d.ts +8 -0
- package/server/routes/extensions.d.ts.map +1 -0
- package/server/routes/extensions.js +414 -0
- package/server/routes/extensions.js.map +1 -0
- package/server/routes/files.d.ts +3 -0
- package/server/routes/files.d.ts.map +1 -0
- package/server/routes/files.js +835 -0
- package/server/routes/files.js.map +1 -0
- package/server/routes/git.d.ts +3 -0
- package/server/routes/git.d.ts.map +1 -0
- package/server/routes/git.js +1058 -0
- package/server/routes/git.js.map +1 -0
- package/server/routes/mcp.d.ts +3 -0
- package/server/routes/mcp.d.ts.map +1 -0
- package/server/routes/mcp.js +403 -0
- package/server/routes/mcp.js.map +1 -0
- package/server/routes/orchestration.d.ts +3 -0
- package/server/routes/orchestration.d.ts.map +1 -0
- package/server/routes/orchestration.js +251 -0
- package/server/routes/orchestration.js.map +1 -0
- package/server/routes/projects.d.ts +3 -0
- package/server/routes/projects.d.ts.map +1 -0
- package/server/routes/projects.js +421 -0
- package/server/routes/projects.js.map +1 -0
- package/server/routes/prompt.d.ts +3 -0
- package/server/routes/prompt.d.ts.map +1 -0
- package/server/routes/prompt.js +311 -0
- package/server/routes/prompt.js.map +1 -0
- package/server/routes/session-extensions.d.ts +11 -0
- package/server/routes/session-extensions.d.ts.map +1 -0
- package/server/routes/session-extensions.js +171 -0
- package/server/routes/session-extensions.js.map +1 -0
- package/server/routes/sessions.d.ts +3 -0
- package/server/routes/sessions.d.ts.map +1 -0
- package/server/routes/sessions.js +706 -0
- package/server/routes/sessions.js.map +1 -0
- package/server/routes/skills.d.ts +14 -0
- package/server/routes/skills.d.ts.map +1 -0
- package/server/routes/skills.js +448 -0
- package/server/routes/skills.js.map +1 -0
- package/server/routes/stream.d.ts +3 -0
- package/server/routes/stream.d.ts.map +1 -0
- package/server/routes/stream.js +112 -0
- package/server/routes/stream.js.map +1 -0
- package/server/routes/terminal.d.ts +28 -0
- package/server/routes/terminal.d.ts.map +1 -0
- package/server/routes/terminal.js +211 -0
- package/server/routes/terminal.js.map +1 -0
- package/server/routes/tunnel.d.ts +13 -0
- package/server/routes/tunnel.d.ts.map +1 -0
- package/server/routes/tunnel.js +231 -0
- package/server/routes/tunnel.js.map +1 -0
- package/server/session-alerts.d.ts +28 -0
- package/server/session-alerts.d.ts.map +1 -0
- package/server/session-alerts.js +38 -0
- package/server/session-alerts.js.map +1 -0
- package/server/session-store.d.ts +164 -0
- package/server/session-store.d.ts.map +1 -0
- package/server/session-store.js +754 -0
- package/server/session-store.js.map +1 -0
- package/server/skill-policy.d.ts +47 -0
- package/server/skill-policy.d.ts.map +1 -0
- package/server/skill-policy.js +178 -0
- package/server/skill-policy.js.map +1 -0
- package/server/terminal-provider.d.ts +54 -0
- package/server/terminal-provider.d.ts.map +1 -0
- package/server/terminal-provider.js +220 -0
- package/server/terminal-provider.js.map +1 -0
- package/server/tool-policy.d.ts +39 -0
- package/server/tool-policy.d.ts.map +1 -0
- package/server/tool-policy.js +121 -0
- package/server/tool-policy.js.map +1 -0
- package/server/tunnel/executable-search.d.ts +43 -0
- package/server/tunnel/executable-search.d.ts.map +1 -0
- package/server/tunnel/executable-search.js +148 -0
- package/server/tunnel/executable-search.js.map +1 -0
- package/server/tunnel/install-help.d.ts +19 -0
- package/server/tunnel/install-help.d.ts.map +1 -0
- package/server/tunnel/install-help.js +47 -0
- package/server/tunnel/install-help.js.map +1 -0
- package/server/tunnel/providers/ngrok.d.ts +31 -0
- package/server/tunnel/providers/ngrok.d.ts.map +1 -0
- package/server/tunnel/providers/ngrok.js +461 -0
- package/server/tunnel/providers/ngrok.js.map +1 -0
- package/server/tunnel/registry.d.ts +13 -0
- package/server/tunnel/registry.d.ts.map +1 -0
- package/server/tunnel/registry.js +56 -0
- package/server/tunnel/registry.js.map +1 -0
- package/server/tunnel/service.d.ts +13 -0
- package/server/tunnel/service.d.ts.map +1 -0
- package/server/tunnel/service.js +156 -0
- package/server/tunnel/service.js.map +1 -0
- package/server/tunnel/types.d.ts +163 -0
- package/server/tunnel/types.d.ts.map +1 -0
- package/server/tunnel/types.js +214 -0
- package/server/tunnel/types.js.map +1 -0
- package/server/ui-settings-store.d.ts +25 -0
- package/server/ui-settings-store.d.ts.map +1 -0
- package/server/ui-settings-store.js +91 -0
- package/server/ui-settings-store.js.map +1 -0
- package/server/workspace-store.d.ts +25 -0
- package/server/workspace-store.d.ts.map +1 -0
- package/server/workspace-store.js +157 -0
- package/server/workspace-store.js.map +1 -0
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
import { spawn, execSync } from "node:child_process";
|
|
2
|
+
import { errorSchema } from "./_schemas.js";
|
|
3
|
+
import { getSession } from "../session-store.js";
|
|
4
|
+
/**
|
|
5
|
+
* Cross-platform shell resolution.
|
|
6
|
+
* - Windows: uses ComSpec (cmd.exe) which is always set by the OS.
|
|
7
|
+
* - Unix: uses SHELL env var, fallback /bin/sh.
|
|
8
|
+
*/
|
|
9
|
+
function resolveShell() {
|
|
10
|
+
const isWin = process.platform === "win32";
|
|
11
|
+
if (isWin) {
|
|
12
|
+
return {
|
|
13
|
+
shell: process.env.ComSpec ?? "cmd.exe",
|
|
14
|
+
argsTemplate: (cmd) => ["/d", "/s", "/c", cmd],
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
shell: process.env.SHELL ?? "/bin/sh",
|
|
19
|
+
argsTemplate: (cmd) => ["-c", cmd],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
23
|
+
/**
|
|
24
|
+
* BashOperations that spawns a shell process with sandboxed env.
|
|
25
|
+
* The onData callback receives stdout/stderr chunks as they arrive.
|
|
26
|
+
*/
|
|
27
|
+
function createBashOps(workspacePath, timeoutSignal) {
|
|
28
|
+
const shellConfig = resolveShell();
|
|
29
|
+
return {
|
|
30
|
+
exec: (command, _cwd, options) => {
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
const isWin = process.platform === "win32";
|
|
33
|
+
const proc = spawn(shellConfig.shell, shellConfig.argsTemplate(command), {
|
|
34
|
+
cwd: workspacePath,
|
|
35
|
+
env: {
|
|
36
|
+
...process.env,
|
|
37
|
+
PI_API_KEY: undefined,
|
|
38
|
+
},
|
|
39
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
40
|
+
// On Unix: detach so the shell+command become their own
|
|
41
|
+
// process group. Killing the group leader with a negative
|
|
42
|
+
// PID terminates ALL descendants (ping, long-running tools,
|
|
43
|
+
// etc.), not just the shell wrapper.
|
|
44
|
+
// On Windows: detached:true would create a new console window
|
|
45
|
+
// AND disconnect stdout/stderr pipes from the parent (so the
|
|
46
|
+
// SDK never receives any output). We skip detached on Windows
|
|
47
|
+
// and fall back to proc.kill() directly.
|
|
48
|
+
detached: !isWin,
|
|
49
|
+
windowsHide: true,
|
|
50
|
+
});
|
|
51
|
+
const kill = () => {
|
|
52
|
+
if (isWin) {
|
|
53
|
+
// Windows: use execSync for taskkill so the command runs
|
|
54
|
+
// to completion (synchronously) before we proceed. The
|
|
55
|
+
// async spawn() path lets the orphan process survive.
|
|
56
|
+
try {
|
|
57
|
+
proc.kill("SIGTERM");
|
|
58
|
+
}
|
|
59
|
+
catch { }
|
|
60
|
+
try {
|
|
61
|
+
execSync(`taskkill /F /T /PID ${proc.pid} 2>nul`, {
|
|
62
|
+
windowsHide: true,
|
|
63
|
+
timeout: 5000,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch { }
|
|
67
|
+
setTimeout(() => {
|
|
68
|
+
try {
|
|
69
|
+
proc.kill("SIGKILL");
|
|
70
|
+
}
|
|
71
|
+
catch { }
|
|
72
|
+
try {
|
|
73
|
+
execSync(`taskkill /F /T /PID ${proc.pid} 2>nul`, {
|
|
74
|
+
windowsHide: true,
|
|
75
|
+
timeout: 5000,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch { }
|
|
79
|
+
}, 2000);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
// Unix: process group kill via negative PID
|
|
83
|
+
const pgid = proc.pid;
|
|
84
|
+
if (pgid === undefined)
|
|
85
|
+
return;
|
|
86
|
+
try {
|
|
87
|
+
process.kill(-pgid, "SIGTERM");
|
|
88
|
+
}
|
|
89
|
+
catch { }
|
|
90
|
+
setTimeout(() => {
|
|
91
|
+
try {
|
|
92
|
+
process.kill(-pgid, "SIGKILL");
|
|
93
|
+
}
|
|
94
|
+
catch { }
|
|
95
|
+
}, 2000);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const signal = options.signal ?? timeoutSignal;
|
|
99
|
+
const onAbort = () => kill();
|
|
100
|
+
if (signal.aborted || timeoutSignal.aborted) {
|
|
101
|
+
kill();
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// Listen on the SDK's signal so the agent can abort us
|
|
105
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
106
|
+
// Also listen on our own timeout signal so client disconnect
|
|
107
|
+
// (req.raw.on("close") → timeoutController.abort()) kills the process
|
|
108
|
+
if (signal !== timeoutSignal) {
|
|
109
|
+
timeoutSignal.addEventListener("abort", onAbort, { once: true });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
options.onData = options.onData ?? (() => { });
|
|
113
|
+
proc.stdout?.on("data", (data) => options.onData(data));
|
|
114
|
+
proc.stderr?.on("data", (data) => options.onData(data));
|
|
115
|
+
proc.on("error", (err) => reject(err));
|
|
116
|
+
proc.on("close", (code) => resolve({ exitCode: code }));
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
export const execRoutes = async (fastify) => {
|
|
122
|
+
/**
|
|
123
|
+
* Sync exec — fire-and-forget. Returns final output after command finishes.
|
|
124
|
+
* The chat input's `!` / `!!` prefix dispatches here.
|
|
125
|
+
*/
|
|
126
|
+
fastify.post("/sessions/:id/exec", {
|
|
127
|
+
schema: {
|
|
128
|
+
description: "Run a one-shot bash command in the session's project cwd " +
|
|
129
|
+
"(the chat input's `!` / `!!` prefix dispatches here). The " +
|
|
130
|
+
"result is added to the session's in-memory context AND " +
|
|
131
|
+
"persisted to the session JSONL. With " +
|
|
132
|
+
"`excludeFromContext: true` (the `!!` prefix) the result " +
|
|
133
|
+
"is recorded but kept out of the next turn's LLM input. " +
|
|
134
|
+
"Output is captured whole — no streaming for v1.",
|
|
135
|
+
tags: ["sessions"],
|
|
136
|
+
params: {
|
|
137
|
+
type: "object",
|
|
138
|
+
required: ["id"],
|
|
139
|
+
properties: { id: { type: "string" } },
|
|
140
|
+
},
|
|
141
|
+
body: {
|
|
142
|
+
type: "object",
|
|
143
|
+
required: ["command"],
|
|
144
|
+
additionalProperties: false,
|
|
145
|
+
properties: {
|
|
146
|
+
command: { type: "string", minLength: 1, maxLength: 4096 },
|
|
147
|
+
excludeFromContext: { type: "boolean" },
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
response: {
|
|
151
|
+
200: {
|
|
152
|
+
type: "object",
|
|
153
|
+
required: ["exitCode", "output", "durationMs", "truncated", "cancelled"],
|
|
154
|
+
properties: {
|
|
155
|
+
exitCode: { type: ["integer", "null"] },
|
|
156
|
+
output: { type: "string" },
|
|
157
|
+
durationMs: { type: "integer" },
|
|
158
|
+
truncated: { type: "boolean" },
|
|
159
|
+
cancelled: { type: "boolean" },
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
404: errorSchema,
|
|
163
|
+
500: errorSchema,
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
}, async (req, reply) => {
|
|
167
|
+
const live = getSession(req.params.id);
|
|
168
|
+
if (live === undefined) {
|
|
169
|
+
return reply.code(404).send({ error: "session_not_found" });
|
|
170
|
+
}
|
|
171
|
+
const { command, excludeFromContext = false } = req.body;
|
|
172
|
+
const started = Date.now();
|
|
173
|
+
const workspacePath = live.workspacePath;
|
|
174
|
+
const timeoutController = new AbortController();
|
|
175
|
+
const timer = setTimeout(() => timeoutController.abort(), DEFAULT_TIMEOUT_MS);
|
|
176
|
+
try {
|
|
177
|
+
const bashOps = createBashOps(workspacePath, timeoutController.signal);
|
|
178
|
+
const result = await live.session.executeBash(command, undefined, {
|
|
179
|
+
excludeFromContext,
|
|
180
|
+
operations: bashOps,
|
|
181
|
+
});
|
|
182
|
+
const durationMs = Date.now() - started;
|
|
183
|
+
live.lastActivityAt = new Date();
|
|
184
|
+
// Cross-tab refetch trigger
|
|
185
|
+
for (const c of live.clients) {
|
|
186
|
+
try {
|
|
187
|
+
c.send({ type: "user_bash_result" });
|
|
188
|
+
}
|
|
189
|
+
catch { /* best-effort */ }
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
exitCode: result.exitCode === undefined ? null : result.exitCode,
|
|
193
|
+
output: result.output,
|
|
194
|
+
durationMs,
|
|
195
|
+
truncated: result.truncated,
|
|
196
|
+
cancelled: result.cancelled,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
return reply.code(500).send({
|
|
201
|
+
error: "exec_failed",
|
|
202
|
+
message: err instanceof Error ? err.message : String(err),
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
clearTimeout(timer);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
/**
|
|
210
|
+
* Streaming exec — fires SSE events (exec_start → exec_update ×N → exec_end)
|
|
211
|
+
* so the client can render live terminal output. Calls executeBash so output
|
|
212
|
+
* also lands in LLM context.
|
|
213
|
+
*/
|
|
214
|
+
fastify.post("/sessions/:id/exec-stream", {
|
|
215
|
+
schema: {
|
|
216
|
+
description: "Run a one-shot bash command and stream output via SSE " +
|
|
217
|
+
"(exec_start → exec_update ×N → exec_end). " +
|
|
218
|
+
"Same semantics as POST /sessions/:id/exec but with live output.",
|
|
219
|
+
tags: ["sessions"],
|
|
220
|
+
params: {
|
|
221
|
+
type: "object",
|
|
222
|
+
required: ["id"],
|
|
223
|
+
properties: { id: { type: "string" } },
|
|
224
|
+
},
|
|
225
|
+
body: {
|
|
226
|
+
type: "object",
|
|
227
|
+
required: ["command"],
|
|
228
|
+
additionalProperties: false,
|
|
229
|
+
properties: {
|
|
230
|
+
command: { type: "string", minLength: 1, maxLength: 4096 },
|
|
231
|
+
excludeFromContext: { type: "boolean" },
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
response: {
|
|
235
|
+
200: {
|
|
236
|
+
type: "object",
|
|
237
|
+
required: ["exitCode", "output", "durationMs", "truncated", "cancelled"],
|
|
238
|
+
properties: {
|
|
239
|
+
exitCode: { type: ["integer", "null"] },
|
|
240
|
+
output: { type: "string" },
|
|
241
|
+
durationMs: { type: "integer" },
|
|
242
|
+
truncated: { type: "boolean" },
|
|
243
|
+
cancelled: { type: "boolean" },
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
404: errorSchema,
|
|
247
|
+
500: errorSchema,
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
}, async (req, reply) => {
|
|
251
|
+
const live = getSession(req.params.id);
|
|
252
|
+
if (live === undefined) {
|
|
253
|
+
return reply.code(404).send({ error: "session_not_found" });
|
|
254
|
+
}
|
|
255
|
+
const { command, excludeFromContext = false } = req.body;
|
|
256
|
+
const started = Date.now();
|
|
257
|
+
const workspacePath = live.workspacePath;
|
|
258
|
+
const timeoutController = new AbortController();
|
|
259
|
+
const timer = setTimeout(() => timeoutController.abort(), DEFAULT_TIMEOUT_MS);
|
|
260
|
+
let execReject;
|
|
261
|
+
let cancelTimer;
|
|
262
|
+
try {
|
|
263
|
+
// Send exec_start to SSE
|
|
264
|
+
live.clients.forEach((c) => {
|
|
265
|
+
try {
|
|
266
|
+
c.send({
|
|
267
|
+
type: "exec_start",
|
|
268
|
+
sessionId: live.sessionId,
|
|
269
|
+
command,
|
|
270
|
+
excludeFromContext,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
catch { /* best-effort */ }
|
|
274
|
+
});
|
|
275
|
+
// Run the command with a wrapper that fans stdout chunks to SSE.
|
|
276
|
+
const baseOps = createBashOps(workspacePath, timeoutController.signal);
|
|
277
|
+
const streamingOps = {
|
|
278
|
+
exec: (cmd, cwd, options) => {
|
|
279
|
+
const origOnData = options.onData;
|
|
280
|
+
options.onData = (data) => {
|
|
281
|
+
live.clients.forEach((c) => {
|
|
282
|
+
try {
|
|
283
|
+
c.send({
|
|
284
|
+
type: "exec_update",
|
|
285
|
+
sessionId: live.sessionId,
|
|
286
|
+
output: data.toString(),
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
catch { /* best-effort */ }
|
|
290
|
+
});
|
|
291
|
+
origOnData?.(data);
|
|
292
|
+
};
|
|
293
|
+
return baseOps.exec(cmd, cwd, options);
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
// ── Cancel / abort handling ──
|
|
297
|
+
//
|
|
298
|
+
// Three-layer strategy, in order:
|
|
299
|
+
// 1. abortBash() — SDK's official bash abort
|
|
300
|
+
// 2. taskkill /F/T — brute-force process tree kill
|
|
301
|
+
// 3. Force reject — if the process genuinely won't die
|
|
302
|
+
// (antivirus / permissions / Win quirk), a 3s
|
|
303
|
+
// fallback promise rejects so the route handler can
|
|
304
|
+
// send exec_end and return immediately.
|
|
305
|
+
//
|
|
306
|
+
live.currentExecAbort = () => {
|
|
307
|
+
// Layer 1: SDK abort (aborts _bashAbortController signal)
|
|
308
|
+
try {
|
|
309
|
+
live.session.abortBash();
|
|
310
|
+
}
|
|
311
|
+
catch { }
|
|
312
|
+
// Layer 2: timeout abort (triggers kill() via AbortSignal)
|
|
313
|
+
try {
|
|
314
|
+
timeoutController.abort();
|
|
315
|
+
}
|
|
316
|
+
catch { }
|
|
317
|
+
// Layer 3: force-reject after 3s if process won't die
|
|
318
|
+
cancelTimer = setTimeout(() => {
|
|
319
|
+
execReject?.(new Error("exec cancel timed out — process may still be alive"));
|
|
320
|
+
}, 3000);
|
|
321
|
+
};
|
|
322
|
+
// Race executeBash against the cancel fallback
|
|
323
|
+
const execPromise = live.session.executeBash(command, undefined, {
|
|
324
|
+
excludeFromContext,
|
|
325
|
+
operations: streamingOps,
|
|
326
|
+
});
|
|
327
|
+
const result = await new Promise((resolve, reject) => {
|
|
328
|
+
execReject = reject;
|
|
329
|
+
execPromise.then(resolve).catch(reject);
|
|
330
|
+
}).finally(() => {
|
|
331
|
+
clearTimeout(cancelTimer);
|
|
332
|
+
});
|
|
333
|
+
const durationMs = Date.now() - started;
|
|
334
|
+
live.lastActivityAt = new Date();
|
|
335
|
+
// Send exec_end to SSE
|
|
336
|
+
const cancelled = timeoutController.signal.aborted;
|
|
337
|
+
live.clients.forEach((c) => {
|
|
338
|
+
try {
|
|
339
|
+
c.send({
|
|
340
|
+
type: "exec_end",
|
|
341
|
+
sessionId: live.sessionId,
|
|
342
|
+
exitCode: result.exitCode ?? null,
|
|
343
|
+
output: result.output,
|
|
344
|
+
cancelled,
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
catch { /* best-effort */ }
|
|
348
|
+
});
|
|
349
|
+
// Cross-tab refetch trigger
|
|
350
|
+
for (const c of live.clients) {
|
|
351
|
+
try {
|
|
352
|
+
c.send({ type: "user_bash_result" });
|
|
353
|
+
}
|
|
354
|
+
catch { /* best-effort */ }
|
|
355
|
+
}
|
|
356
|
+
return {
|
|
357
|
+
exitCode: result.exitCode === undefined ? null : result.exitCode,
|
|
358
|
+
output: result.output,
|
|
359
|
+
durationMs,
|
|
360
|
+
truncated: result.truncated,
|
|
361
|
+
cancelled,
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
catch (err) {
|
|
365
|
+
// Send exec_end with error
|
|
366
|
+
try {
|
|
367
|
+
live.clients.forEach((c) => {
|
|
368
|
+
try {
|
|
369
|
+
c.send({
|
|
370
|
+
type: "exec_end",
|
|
371
|
+
sessionId: live.sessionId,
|
|
372
|
+
exitCode: null,
|
|
373
|
+
output: "",
|
|
374
|
+
cancelled: timeoutController.signal.aborted,
|
|
375
|
+
error: err instanceof Error ? err.message : String(err),
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
catch { /* best-effort */ }
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
catch { /* socket already torn down */ }
|
|
382
|
+
return reply.code(500).send({
|
|
383
|
+
error: "exec_failed",
|
|
384
|
+
message: err instanceof Error ? err.message : String(err),
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
finally {
|
|
388
|
+
clearTimeout(timer);
|
|
389
|
+
clearTimeout(cancelTimer);
|
|
390
|
+
live.currentExecAbort = undefined;
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
/**
|
|
394
|
+
* Cancel a running streaming exec command.
|
|
395
|
+
*/
|
|
396
|
+
fastify.post("/sessions/:id/exec-cancel", {
|
|
397
|
+
schema: {
|
|
398
|
+
description: "Cancel the currently running streaming exec command for this session.",
|
|
399
|
+
tags: ["sessions"],
|
|
400
|
+
params: {
|
|
401
|
+
type: "object",
|
|
402
|
+
required: ["id"],
|
|
403
|
+
properties: { id: { type: "string" } },
|
|
404
|
+
},
|
|
405
|
+
response: {
|
|
406
|
+
200: {
|
|
407
|
+
type: "object",
|
|
408
|
+
properties: { cancelled: { type: "boolean" } },
|
|
409
|
+
},
|
|
410
|
+
404: errorSchema,
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
}, async (req, reply) => {
|
|
414
|
+
const live = getSession(req.params.id);
|
|
415
|
+
if (live === undefined) {
|
|
416
|
+
return reply.code(404).send({ error: "session_not_found" });
|
|
417
|
+
}
|
|
418
|
+
const abort = live.currentExecAbort;
|
|
419
|
+
if (abort !== undefined) {
|
|
420
|
+
abort();
|
|
421
|
+
return { cancelled: true };
|
|
422
|
+
}
|
|
423
|
+
return { cancelled: false };
|
|
424
|
+
});
|
|
425
|
+
};
|
|
426
|
+
//# sourceMappingURL=exec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../../src/routes/exec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjD;;;;GAIG;AACH,SAAS,YAAY;IACnB,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;IAC3C,IAAI,KAAK,EAAE,CAAC;QACV,OAAO;YACL,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,SAAS;YACvC,YAAY,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC;SACvD,CAAC;IACJ,CAAC;IACD,OAAO;QACL,KAAK,EAAE,OAAO,CAAC,GAAG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,CAAC;QACpC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,KAAK,EAAE,CAAC;YACR,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;QAC7B,CAAC;QACD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC,CACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extension Command Routes — invoke registered extension commands
|
|
3
|
+
* (`/rewind`, etc.) through the extension runner's command system, with
|
|
4
|
+
* `ctx.ui` bridged to the browser GUI via SSE events + REST callbacks.
|
|
5
|
+
*
|
|
6
|
+
* This is the generic mechanism: any extension that registers a command
|
|
7
|
+
* with `pi.registerCommand()` automatically becomes available through
|
|
8
|
+
* the web GUI without pi-kot-specific integration code.
|
|
9
|
+
*
|
|
10
|
+
* Flow:
|
|
11
|
+
* 1. GUI sends `POST /sessions/:id/command { command: "rewind" }`
|
|
12
|
+
* 2. Server looks up the command in the extension runner
|
|
13
|
+
* 3. Server installs a bridge `ExtensionUIContext` that sends
|
|
14
|
+
* `extension_ui_select` / `extension_ui_confirm` / etc. over SSE
|
|
15
|
+
* 4. Extension calls `ctx.ui.select()` → bridge creates a pending
|
|
16
|
+
* promise, sends SSE event → GUI renders selector → user responds
|
|
17
|
+
* via `POST /extension-ui/respond` → promise resolves
|
|
18
|
+
* 5. Extension completes → `extension_ui_done` SSE event sent
|
|
19
|
+
*/
|
|
20
|
+
import type { FastifyPluginAsync } from "fastify";
|
|
21
|
+
export declare const extensionCommandRoutes: FastifyPluginAsync;
|
|
22
|
+
//# sourceMappingURL=extension-commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension-commands.d.ts","sourceRoot":"","sources":["../../src/routes/extension-commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AASlD,eAAO,MAAM,sBAAsB,EAAE,kBA8KpC,CAAC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extension Command Routes — invoke registered extension commands
|
|
3
|
+
* (`/rewind`, etc.) through the extension runner's command system, with
|
|
4
|
+
* `ctx.ui` bridged to the browser GUI via SSE events + REST callbacks.
|
|
5
|
+
*
|
|
6
|
+
* This is the generic mechanism: any extension that registers a command
|
|
7
|
+
* with `pi.registerCommand()` automatically becomes available through
|
|
8
|
+
* the web GUI without pi-kot-specific integration code.
|
|
9
|
+
*
|
|
10
|
+
* Flow:
|
|
11
|
+
* 1. GUI sends `POST /sessions/:id/command { command: "rewind" }`
|
|
12
|
+
* 2. Server looks up the command in the extension runner
|
|
13
|
+
* 3. Server installs a bridge `ExtensionUIContext` that sends
|
|
14
|
+
* `extension_ui_select` / `extension_ui_confirm` / etc. over SSE
|
|
15
|
+
* 4. Extension calls `ctx.ui.select()` → bridge creates a pending
|
|
16
|
+
* promise, sends SSE event → GUI renders selector → user responds
|
|
17
|
+
* via `POST /extension-ui/respond` → promise resolves
|
|
18
|
+
* 5. Extension completes → `extension_ui_done` SSE event sent
|
|
19
|
+
*/
|
|
20
|
+
import { getSession } from "../session-store.js";
|
|
21
|
+
import { createBridgeUIContext, resolveExtensionUIRequest, cancelAllPendingRequests, } from "../extension-ui-bridge.js";
|
|
22
|
+
import { buildSnapshot } from "../event-stream.js";
|
|
23
|
+
export const extensionCommandRoutes = async (fastify) => {
|
|
24
|
+
// ── POST /sessions/:id/command — invoke an extension command ─────
|
|
25
|
+
fastify.post("/sessions/:id/command", {
|
|
26
|
+
schema: {
|
|
27
|
+
description: "Invoke a registered extension command (e.g. /rewind). " +
|
|
28
|
+
"Returns 202 immediately. The command's interactive steps " +
|
|
29
|
+
"(select, confirm, input, notify) are bridged to the GUI " +
|
|
30
|
+
"via SSE events. The command completes asynchronously and " +
|
|
31
|
+
"a final `extension_ui_done` event is sent over SSE.",
|
|
32
|
+
tags: ["extensions"],
|
|
33
|
+
params: {
|
|
34
|
+
type: "object",
|
|
35
|
+
required: ["id"],
|
|
36
|
+
properties: { id: { type: "string" } },
|
|
37
|
+
},
|
|
38
|
+
body: {
|
|
39
|
+
type: "object",
|
|
40
|
+
required: ["command"],
|
|
41
|
+
properties: {
|
|
42
|
+
command: { type: "string" },
|
|
43
|
+
args: { type: "string" },
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
response: {
|
|
47
|
+
202: {
|
|
48
|
+
type: "object",
|
|
49
|
+
properties: { accepted: { type: "boolean" } },
|
|
50
|
+
},
|
|
51
|
+
400: {
|
|
52
|
+
type: "object",
|
|
53
|
+
properties: { error: { type: "string" } },
|
|
54
|
+
},
|
|
55
|
+
404: {
|
|
56
|
+
type: "object",
|
|
57
|
+
properties: { error: { type: "string" } },
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
}, async (req, reply) => {
|
|
62
|
+
const sessionId = req.params.id;
|
|
63
|
+
const { command: commandName, args = "" } = req.body;
|
|
64
|
+
const live = getSession(sessionId);
|
|
65
|
+
if (live === undefined) {
|
|
66
|
+
return reply.code(404).send({ error: "session_not_found" });
|
|
67
|
+
}
|
|
68
|
+
const runner = live.session.extensionRunner;
|
|
69
|
+
const cmd = runner.getCommand(commandName);
|
|
70
|
+
if (cmd === undefined) {
|
|
71
|
+
return reply.code(404).send({ error: `command_not_found: ${commandName}` });
|
|
72
|
+
}
|
|
73
|
+
// Accept immediately — command runs async
|
|
74
|
+
await reply.code(202).send({ accepted: true });
|
|
75
|
+
// Install the UI bridge and run the command in the background
|
|
76
|
+
const originalUI = runner.getUIContext();
|
|
77
|
+
const bridge = createBridgeUIContext(live.clients, sessionId);
|
|
78
|
+
runner.setUIContext(bridge);
|
|
79
|
+
// Helper to send a done/fail event over SSE
|
|
80
|
+
const sendDone = (result) => {
|
|
81
|
+
for (const client of live.clients) {
|
|
82
|
+
try {
|
|
83
|
+
client.send({
|
|
84
|
+
type: "extension_ui_done",
|
|
85
|
+
sessionId,
|
|
86
|
+
command: commandName,
|
|
87
|
+
...result,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
live.clients.delete(client);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
// Run the command in background, restore original UI context after
|
|
96
|
+
(async () => {
|
|
97
|
+
try {
|
|
98
|
+
const ctx = runner.createCommandContext();
|
|
99
|
+
req.log.info({ sessionId, commandName }, "Running extension command");
|
|
100
|
+
await cmd.handler(args, ctx);
|
|
101
|
+
sendDone({ status: "ok" });
|
|
102
|
+
// Emit a snapshot so the UI refreshes messages after tree navigation
|
|
103
|
+
try {
|
|
104
|
+
const snapshot = buildSnapshot(live);
|
|
105
|
+
for (const client of live.clients) {
|
|
106
|
+
client.send(snapshot);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// best-effort
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
115
|
+
// Notify the GUI about the failure
|
|
116
|
+
for (const client of live.clients) {
|
|
117
|
+
try {
|
|
118
|
+
client.send({
|
|
119
|
+
type: "extension_ui_notify",
|
|
120
|
+
sessionId,
|
|
121
|
+
message: `Command "${commandName}" failed: ${msg}`,
|
|
122
|
+
notificationType: "error",
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
live.clients.delete(client);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
sendDone({ status: "error", message: msg });
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
runner.setUIContext(originalUI);
|
|
133
|
+
cancelAllPendingRequests();
|
|
134
|
+
}
|
|
135
|
+
})();
|
|
136
|
+
});
|
|
137
|
+
// ── POST /sessions/:id/extension-ui/respond — respond to a bridge interaction ──
|
|
138
|
+
fastify.post("/sessions/:id/extension-ui/respond", {
|
|
139
|
+
schema: {
|
|
140
|
+
description: "Respond to a pending extension UI interaction (select, confirm, input). " +
|
|
141
|
+
"The `requestId` comes from the `extension_ui_*` SSE event. " +
|
|
142
|
+
"The `value` type depends on the interaction: string for select/input, " +
|
|
143
|
+
"boolean for confirm.",
|
|
144
|
+
tags: ["extensions"],
|
|
145
|
+
params: {
|
|
146
|
+
type: "object",
|
|
147
|
+
required: ["id"],
|
|
148
|
+
properties: { id: { type: "string" } },
|
|
149
|
+
},
|
|
150
|
+
body: {
|
|
151
|
+
type: "object",
|
|
152
|
+
required: ["requestId", "value"],
|
|
153
|
+
properties: {
|
|
154
|
+
requestId: { type: "string" },
|
|
155
|
+
value: { type: ["string", "boolean", "number"] },
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
response: {
|
|
159
|
+
200: {
|
|
160
|
+
type: "object",
|
|
161
|
+
properties: { resolved: { type: "boolean" } },
|
|
162
|
+
},
|
|
163
|
+
404: {
|
|
164
|
+
type: "object",
|
|
165
|
+
properties: { error: { type: "string" } },
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
}, async (req, reply) => {
|
|
170
|
+
const { requestId, value } = req.body;
|
|
171
|
+
const resolved = resolveExtensionUIRequest(requestId, value);
|
|
172
|
+
if (!resolved) {
|
|
173
|
+
return reply.code(404).send({ error: "request_not_found_or_expired" });
|
|
174
|
+
}
|
|
175
|
+
return { resolved: true };
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
//# sourceMappingURL=extension-commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension-commands.js","sourceRoot":"","sources":["../../src/routes/extension-commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EACzB,wBAAwB,GACzB,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