keel-agent 0.129.0 → 0.130.1
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/CHANGELOG.md +52 -2
- package/README.md +12 -16
- package/README.zh-CN.md +12 -16
- package/README.zh-TW.md +74 -189
- package/bin/keel.mjs +295 -55
- package/dist/packages/keel/src/adapters/sdk/prompt-render.js +3 -1
- package/dist/packages/keel/src/adapters/sdk/session-opener.js +2 -1
- package/dist/packages/keel/src/adapters/tools/guarded.js +31 -4
- package/dist/packages/keel/src/adapters/tools/patch.js +16 -0
- package/dist/packages/keel/src/app/client-assembly.js +43 -24
- package/dist/packages/keel/src/app/client-runtime.js +37 -2
- package/dist/packages/keel/src/app/connection-init.js +4 -2
- package/dist/packages/keel/src/app/conversation-content.js +14 -0
- package/dist/packages/keel/src/app/core-engine.js +6 -2
- package/dist/packages/keel/src/app/engine-coordination.js +4 -0
- package/dist/packages/keel/src/app/engine-elsewhere.js +8 -2
- package/dist/packages/keel/src/app/engine-orphans.js +8 -1
- package/dist/packages/keel/src/app/engine-sessions.js +26 -22
- package/dist/packages/keel/src/app/engine-takeover.js +13 -8
- package/dist/packages/keel/src/app/extra-handlers.js +8 -5
- package/dist/packages/keel/src/app/host-faces.js +1 -0
- package/dist/packages/keel/src/app/host-tool-mounts.js +12 -0
- package/dist/packages/keel/src/app/note-delivery.js +2 -2
- package/dist/packages/keel/src/app/session-registry.js +3 -1
- package/dist/packages/keel/src/app/session-surface.js +2 -1
- package/dist/packages/keel/src/app/subagent-model-choice.js +41 -28
- package/dist/packages/keel/src/bg-job-notice.js +1 -0
- package/dist/packages/keel/src/composer-complete-settings.js +43 -0
- package/dist/packages/keel/src/conversation-rows.js +8 -0
- package/dist/packages/keel/src/domains/background/handlers.js +1 -0
- package/dist/packages/keel/src/domains/bots/chat.js +1 -1
- package/dist/packages/keel/src/domains/snapshots/builders.js +4 -0
- package/dist/packages/keel/src/domains/turns/turn-runner.js +18 -0
- package/dist/packages/keel/src/settings-schema.js +9 -0
- package/dist/packages/keel/src/subagent-model-policy.js +49 -0
- package/dist/packages/keel/src/subagent-templates-hant.js +3 -3
- package/dist/packages/keel/src/subagent-templates.js +6 -6
- package/dist/packages/keel/src/tool-catalog.js +9 -0
- package/dist/packages/keel/src/tool-names.js +2 -0
- package/dist/server/background-task-service.js +61 -22
- package/dist/server/bg-tasks/client.js +5 -4
- package/dist/server/bg-tasks/registry.js +29 -18
- package/dist/server/bot-memory-tool.js +15 -3
- package/dist/server/client-state.js +65 -0
- package/dist/server/composer-complete-settings.js +1 -0
- package/dist/server/composer-complete.js +243 -0
- package/dist/server/control-socket.js +13 -1
- package/dist/server/conversation-import/engines/agy.js +222 -0
- package/dist/server/conversation-import/engines/claude.js +171 -0
- package/dist/server/conversation-import/engines/codex.js +178 -0
- package/dist/server/conversation-import/engines/dsh.js +240 -0
- package/dist/server/conversation-import/engines/opencode.js +160 -0
- package/dist/server/conversation-import/index.js +183 -0
- package/dist/server/conversation-import/jsonl.js +100 -0
- package/dist/server/conversation-import/messages.js +147 -0
- package/dist/server/conversation-import/sqlite.js +47 -0
- package/dist/server/conversation-import/types.js +8 -0
- package/dist/server/conversation-import-routes.js +53 -0
- package/dist/server/core-bot-adapter.js +5 -1
- package/dist/server/core-plugin-adapter.js +4 -1
- package/dist/server/core-settings-adapter.js +19 -9
- package/dist/server/custom-cli-routes.js +59 -0
- package/dist/server/custom-cli-store.js +134 -0
- package/dist/server/delegate-task.js +18 -7
- package/dist/server/device-center/bot-chat.js +34 -17
- package/dist/server/device-center/bot-creation-tool.js +8 -64
- package/dist/server/device-center/bot-drafts.js +24 -0
- package/dist/server/device-center/bot-memory.js +101 -12
- package/dist/server/device-center/bot-tool-face.js +24 -20
- package/dist/server/device-center/local.js +59 -9
- package/dist/server/durable/durable-agent-service.js +27 -0
- package/dist/server/engine-owner-route.js +43 -0
- package/dist/server/files-service.js +10 -6
- package/dist/server/index.js +236 -47
- package/dist/server/marker-service.js +19 -0
- package/dist/server/message-window.js +2 -2
- package/dist/server/multi-engine.js +1 -0
- package/dist/server/native-cli.js +3 -1
- package/dist/server/obs-recall-tool.js +173 -0
- package/dist/server/plugin-facilities.js +9 -1
- package/dist/server/plugins.js +11 -4
- package/dist/server/preset-fields.js +9 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/remote-ssh-service.js +13 -0
- package/dist/server/schedule-agent-tool.js +2 -0
- package/dist/server/scheduler-tasks.js +5 -0
- package/dist/server/settings-commit.js +2 -0
- package/dist/server/settings-service.js +2 -0
- package/dist/server/shell-activate.js +118 -1
- package/dist/server/slash-commands.js +48 -12
- package/dist/server/tool-bridge-host.js +5 -0
- package/dist/server/universal/acp/acp-driver.js +96 -22
- package/dist/server/universal/drivers/claude-acp-driver.js +3 -0
- package/dist/server/universal/internal-mcp.js +7 -3
- package/dist/server/universal/seat-takeover.js +145 -0
- package/dist/server/universal/subagent-slash.js +54 -0
- package/dist/server/universal/universal-service.js +28 -0
- package/dist/server/universal/universal-session.js +242 -88
- package/dist/server/update-service.js +12 -8
- package/package.json +20 -15
- package/plugins/catalog.json +128 -90
- package/plugins/superagent/manifest.json +2 -2
- package/themes/flow-zurich.css +2 -2
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/ApprovalRulesTab-3vnhAT9R.js +1 -0
- package/web/dist/assets/BgTasksModal-R-6kYREx.js +1 -0
- package/web/dist/assets/BgTasksModal-Wah1orF5.js +1 -0
- package/web/dist/assets/{BotDraftSettings-BcXWHOSd.js → BotDraftSettings-B1wTl7Vg.js} +1 -1
- package/web/dist/assets/BottomDock-BPFSRZ0X.js +1 -0
- package/web/dist/assets/BottomDock-CFcL5DzG.js +1 -0
- package/web/dist/assets/{CanvasStudio-KZ0MmCL7.js → CanvasStudio-B1oKuguJ.js} +3 -3
- package/web/dist/assets/CanvasStudio-DcrNIsHF.js +1579 -0
- package/web/dist/assets/CommunityThemesSection-BfG3dkJM.js +1 -0
- package/web/dist/assets/CommunityThemesSection-DtNTStEl.js +1 -0
- package/web/dist/assets/DesktopAppSettings-CmfaTYVg.js +1 -0
- package/web/dist/assets/DeviceCenter-Cu9nMKdi.js +3 -0
- package/web/dist/assets/DeviceCenter-krZV_FU1.js +3 -0
- package/web/dist/assets/{DeviceExecutionSettings-VONJ-2Ns.js → DeviceExecutionSettings-Y-8BfmMH.js} +1 -1
- package/web/dist/assets/{DeviceGroups-DUq2YZ8O.js → DeviceGroups-4KimHqYi.js} +1 -1
- package/web/dist/assets/DeviceGroups-CYtzpFAF.js +1 -0
- package/web/dist/assets/DisplayTab-D8wjw1NI.js +1 -0
- package/web/dist/assets/DisplayTab-RANS7wHY.js +1 -0
- package/web/dist/assets/{FieldRow-CHxkNX2z.js → FieldRow-BQ43ENLa.js} +1 -1
- package/web/dist/assets/FilePreview-BpE884NY.js +2 -0
- package/web/dist/assets/FilePreview-GOqWbXIs.js +2 -0
- package/web/dist/assets/GlobalSearchModal-CSKa4c7w.js +1 -0
- package/web/dist/assets/GlobalSearchModal-DS62VEMS.js +1 -0
- package/web/dist/assets/GroupConversation-BlCwRDpi.js +9 -0
- package/web/dist/assets/GroupConversation-C_qNSQDP.js +9 -0
- package/web/dist/assets/{GroupWorkItems-B-wweVMR.js → GroupWorkItems-dc5bk7A7.js} +1 -1
- package/web/dist/assets/{HintTip-lXOOr9p3.js → HintTip-DUbCHF8G.js} +1 -1
- package/web/dist/assets/LayoutTab-BFNlEaCX.js +1 -0
- package/web/dist/assets/LayoutTab-BjM3-ZvB.js +1 -0
- package/web/dist/assets/McpServersPanel-BqpKRLOw.js +1 -0
- package/web/dist/assets/McpServersPanel-CNyxnBff.js +1 -0
- package/web/dist/assets/ModelConfigModal-ChJpmTlc.js +2 -0
- package/web/dist/assets/ModelConfigModal-vYO-afkI.js +2 -0
- package/web/dist/assets/{ModelsTab-CMSi1MT-.js → ModelsTab-D21I7rkR.js} +1 -1
- package/web/dist/assets/ModelsTab-P7LvG27r.js +1 -0
- package/web/dist/assets/{NativeCliPanel-DotHqKv_.js → NativeCliPanel-Br-5ljqs.js} +2 -2
- package/web/dist/assets/NativeCliPanel-Clt94Fpy.js +5 -0
- package/web/dist/assets/{PiSetupModal-Dd0w2Koi.js → PiSetupModal-CUb5Q8-5.js} +1 -1
- package/web/dist/assets/PluginsTab-BAm_QAzW.js +2 -0
- package/web/dist/assets/PluginsTab-BRKvuS0O.js +2 -0
- package/web/dist/assets/PresetShareModal-4KRKutrA.js +11 -0
- package/web/dist/assets/PresetShareModal-Dqx8JUn3.js +11 -0
- package/web/dist/assets/{PresetsTab-BnFFB24b.js → PresetsTab-BxO9GfpC.js} +1 -1
- package/web/dist/assets/{PromptHistoryTab-CNUzjdJl.js → PromptHistoryTab-TG4YmTrg.js} +1 -1
- package/web/dist/assets/PromptHistoryTab-bKIwfcAQ.js +1 -0
- package/web/dist/assets/{PromptOverrideEditor-DZOQdWy3.js → PromptOverrideEditor-CygHvhOa.js} +1 -1
- package/web/dist/assets/PromptTab-B2_Qxr7A.js +11 -0
- package/web/dist/assets/PromptTab-DPqfCdxT.js +11 -0
- package/web/dist/assets/{ProviderOAuthControls-BSqBp-QA.js → ProviderOAuthControls-CQSqMeR1.js} +1 -1
- package/web/dist/assets/QuestionTab-0v0n7S8O.js +1 -0
- package/web/dist/assets/{QuickAskSettings-DICkDFsE.js → QuickAskSettings-BdDgXcxT.js} +2 -2
- package/web/dist/assets/QuickAskSettings-CKFJ0aCk.js +2 -0
- package/web/dist/assets/QuickTab-Dh18DG66.js +5 -0
- package/web/dist/assets/QuickTab-Vynq8Q9i.js +5 -0
- package/web/dist/assets/{ReviewTab-DRMQoVjL.js → ReviewTab-BiuGWsmU.js} +1 -1
- package/web/dist/assets/SCMPanel-B0w96H9p.js +7 -0
- package/web/dist/assets/SCMPanel-FKoXWQ_H.js +7 -0
- package/web/dist/assets/SchedulerPanel-DUgt0Fu6.js +2 -0
- package/web/dist/assets/SchedulerPanel-cQdRucUx.js +2 -0
- package/web/dist/assets/SettingsModal-BliX6Boj.js +2 -0
- package/web/dist/assets/SettingsModal-CDYhDB1i.js +2 -0
- package/web/dist/assets/SkillsTab-BGhnuZmu.js +1 -0
- package/web/dist/assets/SkillsTab-BTin11c-.js +1 -0
- package/web/dist/assets/{SoundTab-BR6gVIOZ.js → SoundTab-16yTVZkV.js} +1 -1
- package/web/dist/assets/SoundTab-gF8ZYfRH.js +1 -0
- package/web/dist/assets/{SubagentTemplatesTab-BonIA-lD.js → SubagentTemplatesTab-CiFYV-ZI.js} +1 -1
- package/web/dist/assets/SubagentTemplatesTab-DMOqN0mW.js +1 -0
- package/web/dist/assets/{TermXterm-EHBR2avX.js → TermXterm-BrPs_sPf.js} +1 -1
- package/web/dist/assets/TermXterm-JjcHbfzg.js +8 -0
- package/web/dist/assets/TerminalDockControls-D7jwYEpa.js +1 -0
- package/web/dist/assets/TerminalDockControls-vkeqMz6q.js +1 -0
- package/web/dist/assets/TerminalPanel-_4n1f4--.js +1 -0
- package/web/dist/assets/TerminalPanel-_vroAPhm.js +1 -0
- package/web/dist/assets/{ThemeMarketModal-CGaoF3NZ.js → ThemeMarketModal-CBKF2E8L.js} +1 -1
- package/web/dist/assets/ThemeMarketModal-K7A327ZQ.js +1 -0
- package/web/dist/assets/{ToggleRow-DvouPLLK.js → ToggleRow-clnL39s8.js} +1 -1
- package/web/dist/assets/ToolBridgeSettings-BsJNlw-5.js +1 -0
- package/web/dist/assets/ToolBridgeSettings-Bu2h16ZE.js +1 -0
- package/web/dist/assets/ToolsTab-BQxVX0Ye.js +4 -0
- package/web/dist/assets/ToolsTab-CeKb8Kip.js +4 -0
- package/web/dist/assets/TuiOverlayModal-BuE2FKDQ.js +1 -0
- package/web/dist/assets/TuiOverlayModal-CLzoXrSM.js +1 -0
- package/web/dist/assets/{VisionTab-HDlpKVeq.js → VisionTab-C4U4LxUk.js} +1 -1
- package/web/dist/assets/{api-client-J4QrjRw8.js → api-client--1WOIe68.js} +1 -1
- package/web/dist/assets/{canvas-client-BsNp2mr3.js → canvas-client-Bhhkh6T0.js} +1 -1
- package/web/dist/assets/{desktop-BcTQigaN.js → desktop-IxZhNpni.js} +1 -1
- package/web/dist/assets/host-icon-B-zxP_r-.js +1 -0
- package/web/dist/assets/i18n-N1glykLZ.js +225 -0
- package/web/dist/assets/index-4VhQrBDx.js +423 -0
- package/web/dist/assets/index-CS3HmHb2.js +423 -0
- package/web/dist/assets/index-Ds_pheLF.css +1 -0
- package/web/dist/assets/plugin-host-DMoSTlfw.js +1 -0
- package/web/dist/assets/{theme-7DF4yEv3.js → theme-CGrlgGnK.js} +1 -1
- package/web/dist/assets/{tool-inventory-D2UKR8Ja.js → tool-inventory-BoeketvT.js} +1 -1
- package/web/dist/assets/tool-inventory-C1RzlPP0.js +1 -0
- package/web/dist/index.html +10 -9
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/ApprovalRulesTab-BlcxVgms.js +0 -1
- package/web/dist/assets/BgTasksModal-wL4p27CE.js +0 -1
- package/web/dist/assets/BottomDock-CUnQsIDW.js +0 -1
- package/web/dist/assets/CommunityThemesSection-BAcS2VQK.js +0 -1
- package/web/dist/assets/DesktopAppSettings-BeikxSqV.js +0 -1
- package/web/dist/assets/DeviceCenter-BWKRVpWt.js +0 -3
- package/web/dist/assets/DisplayTab-B5x4nQh5.js +0 -1
- package/web/dist/assets/FilePreview-0IDddE5F.js +0 -2
- package/web/dist/assets/GlobalSearchModal-BaXs1zRG.js +0 -1
- package/web/dist/assets/GroupConversation-EaMawnF-.js +0 -9
- package/web/dist/assets/LayoutTab-8N74U83U.js +0 -1
- package/web/dist/assets/McpServersPanel-BAhwoE87.js +0 -1
- package/web/dist/assets/ModelConfigModal-i3m9glTy.js +0 -2
- package/web/dist/assets/PluginsTab-DL8j6LEI.js +0 -2
- package/web/dist/assets/PresetShareModal-BGhCpas6.js +0 -11
- package/web/dist/assets/PromptTab-DPYuPM07.js +0 -11
- package/web/dist/assets/QuestionTab-C7oF1MYO.js +0 -1
- package/web/dist/assets/QuickTab-DDaxH3XV.js +0 -1
- package/web/dist/assets/SCMPanel-CfOxsL8H.js +0 -7
- package/web/dist/assets/SchedulerPanel-BLaVSPXj.js +0 -2
- package/web/dist/assets/SettingsModal-6jgsnLF0.js +0 -2
- package/web/dist/assets/SkillsTab-C5XuZ4a-.js +0 -1
- package/web/dist/assets/TerminalDockControls-Dn51FqM9.js +0 -1
- package/web/dist/assets/TerminalPanel-D2Bpt0f_.js +0 -1
- package/web/dist/assets/ToolBridgeSettings-8vlLWWvW.js +0 -1
- package/web/dist/assets/ToolsTab-Byx7wDZe.js +0 -4
- package/web/dist/assets/TuiOverlayModal-Bj6jyAvr.js +0 -1
- package/web/dist/assets/i18n-CaWsBwiA.js +0 -225
- package/web/dist/assets/index-2jVkYOYt.css +0 -1
- package/web/dist/assets/index-KuttBaFw.js +0 -420
- package/web/dist/assets/plugin-host-C2Iki5ig.js +0 -1
package/bin/keel.mjs
CHANGED
|
@@ -91,7 +91,7 @@ const HELP_ZH = `keel v${pkg.version} — web chat for the pi coding agent
|
|
|
91
91
|
keel 启动服务器(前台,Ctrl+C 停止,自动打开浏览器)
|
|
92
92
|
keel --engine claude --port 9000 --cwd /path 启动并指定引擎 / 端口 / 工作目录 / 数据目录
|
|
93
93
|
keel --no-browser 启动但不自动打开浏览器
|
|
94
|
-
keel stop|restart|status [选项] 停止 / 重启 /
|
|
94
|
+
keel stop|restart|status [选项] 停止 / 重启 / 查看服务(前台实例与服务托管都认,按端口兜底)
|
|
95
95
|
keel upgrade [--dry-run] [--version <版本>] 升级全局安装;官方 registry 定版,镜像下载回退
|
|
96
96
|
keel update upgrade 的兼容别名
|
|
97
97
|
keel server install [选项] 安装系统服务(开机自启)并启动
|
|
@@ -162,7 +162,7 @@ Usage (keel is primary; pwu / piwebui / pi-web-ui are compatibility aliases):
|
|
|
162
162
|
keel Start server (foreground, Ctrl+C to stop, auto-opens browser)
|
|
163
163
|
keel --engine claude --port 9000 --cwd /path Start with engine/port/cwd/data-dir overrides
|
|
164
164
|
keel --no-browser Start without auto-opening browser
|
|
165
|
-
keel stop|restart|status [options]
|
|
165
|
+
keel stop|restart|status [options] Stop/restart/inspect the service or a foreground instance (port fallback)
|
|
166
166
|
keel upgrade [--dry-run] [--version <version>] Upgrade the global install; official version, mirror downloads
|
|
167
167
|
keel update Compatibility alias for upgrade
|
|
168
168
|
keel server install [options] Install system service (autostart on boot) and launch it
|
|
@@ -725,6 +725,19 @@ function winShortcutPs1Path(name) {
|
|
|
725
725
|
return join(winServiceDir(), `${name}-shortcut.ps1`);
|
|
726
726
|
}
|
|
727
727
|
|
|
728
|
+
/**
|
|
729
|
+
* 一个服务名下**所有**会写 pid 文件的启动脚本:`server install` 的看门狗(`<name>.ps1`)与
|
|
730
|
+
* 桌面快捷方式的外壳(`<name>-shortcut.ps1`)。
|
|
731
|
+
*
|
|
732
|
+
* 两处都写的是**外壳自己的** `$PID`(见 `buildWinStartPs1` / `buildWinShortcutPs1`),所以要判断
|
|
733
|
+
* 「某个 pid 是不是本服务的」就必须认这两份脚本。以前只认 `winPs1Path(name)`,而
|
|
734
|
+
* `pi-web-ui-shortcut.ps1` 并不包含 `pi-web-ui.ps1` 这段字符串,快捷方式拉起的服务永远判成
|
|
735
|
+
* 「无法核实」→ `keel stop` 跳过强杀,只能靠端口猜(issue #1078)。
|
|
736
|
+
*/
|
|
737
|
+
function winServiceScriptPaths(name) {
|
|
738
|
+
return [winPs1Path(name), winShortcutPs1Path(name)];
|
|
739
|
+
}
|
|
740
|
+
|
|
728
741
|
function winShortcutVbsPath(name) {
|
|
729
742
|
return join(winServiceDir(), `${name}-shortcut.vbs`);
|
|
730
743
|
}
|
|
@@ -1137,7 +1150,8 @@ function isWinServiceProcess(pid, name) {
|
|
|
1137
1150
|
if (image === null || !WIN_SERVICE_IMAGE_RE.test(image)) return false;
|
|
1138
1151
|
const commandLine = winPidCommandLine(pid);
|
|
1139
1152
|
if (!commandLine) return false;
|
|
1140
|
-
|
|
1153
|
+
if (commandLine.includes(SERVER_ENTRY)) return true;
|
|
1154
|
+
return name !== undefined && winServiceScriptPaths(name).some((script) => commandLine.includes(script));
|
|
1141
1155
|
}
|
|
1142
1156
|
|
|
1143
1157
|
/**
|
|
@@ -1180,14 +1194,18 @@ function stopKernelHoldingDataDir(dataDir) {
|
|
|
1180
1194
|
}
|
|
1181
1195
|
}
|
|
1182
1196
|
|
|
1183
|
-
/**
|
|
1197
|
+
/**
|
|
1198
|
+
* 停掉遗留的看门狗:pid 文件丢了也要能停(按本服务的启动脚本匹配命令行,连子树一起杀)。
|
|
1199
|
+
* 判据与 `isWinServiceProcess` 同源(`winServiceScriptPaths`):快捷方式的外壳也是本服务的一份,
|
|
1200
|
+
* 漏掉它 `stop` 之后 `restart` 会让两份外壳抢同一份数据目录。
|
|
1201
|
+
*/
|
|
1184
1202
|
function stopStrayWindowsWatchdogs(name) {
|
|
1185
|
-
const
|
|
1203
|
+
const where = winServiceScriptPaths(name)
|
|
1204
|
+
.map((script) => `$_.CommandLine -like ${psQuote(`*${script}*`)}`)
|
|
1205
|
+
.join(" -or ");
|
|
1186
1206
|
const script = [
|
|
1187
1207
|
"$ErrorActionPreference='SilentlyContinue'",
|
|
1188
|
-
`Get-CimInstance Win32_Process -Filter "Name='powershell.exe' or Name='pwsh.exe'" | Where-Object { $
|
|
1189
|
-
`*${ps1}*`,
|
|
1190
|
-
)} } | ForEach-Object { $_.ProcessId }`,
|
|
1208
|
+
`Get-CimInstance Win32_Process -Filter "Name='powershell.exe' or Name='pwsh.exe'" | Where-Object { ${where} } | ForEach-Object { $_.ProcessId }`,
|
|
1191
1209
|
].join("\n");
|
|
1192
1210
|
const res = spawnSync(
|
|
1193
1211
|
winPowershell(),
|
|
@@ -1637,7 +1655,15 @@ function uninstallWindows(opts) {
|
|
|
1637
1655
|
run("schtasks", ["/Delete", "/TN", name, "/F"], { ignoreError: true });
|
|
1638
1656
|
}
|
|
1639
1657
|
stopWinInstance(name);
|
|
1640
|
-
for (const f of [
|
|
1658
|
+
for (const f of [
|
|
1659
|
+
winCmdPath(name),
|
|
1660
|
+
winPs1Path(name),
|
|
1661
|
+
winVbsPath(name),
|
|
1662
|
+
winTaskXmlPath(name),
|
|
1663
|
+
winShortcutPs1Path(name),
|
|
1664
|
+
winShortcutVbsPath(name),
|
|
1665
|
+
winPidFilePath(name),
|
|
1666
|
+
]) {
|
|
1641
1667
|
if (existsSync(f)) rmSync(f);
|
|
1642
1668
|
}
|
|
1643
1669
|
removeShortcut(name);
|
|
@@ -1685,6 +1711,155 @@ function controlCommand(opts, cmd) {
|
|
|
1685
1711
|
});
|
|
1686
1712
|
}
|
|
1687
1713
|
|
|
1714
|
+
/**
|
|
1715
|
+
* 端口上正在监听的 PID(macOS / Linux 用 lsof,Windows 用 netstat)。
|
|
1716
|
+
* 只在「控制 socket 够不着、但端口确实有人」时当兜底用(issue #1038)。
|
|
1717
|
+
*/
|
|
1718
|
+
function listeningPidsOnPort(port) {
|
|
1719
|
+
const value = Number(port);
|
|
1720
|
+
if (!Number.isInteger(value) || value <= 0) return [];
|
|
1721
|
+
if (isWin) return winListeningPidsOnPort(value);
|
|
1722
|
+
const res = spawnSync("lsof", ["-nP", `-iTCP:${value}`, "-sTCP:LISTEN", "-t"], {
|
|
1723
|
+
windowsHide: true,
|
|
1724
|
+
encoding: "utf8",
|
|
1725
|
+
});
|
|
1726
|
+
if (res.status !== 0) return [];
|
|
1727
|
+
const pids = new Set();
|
|
1728
|
+
for (const line of String(res.stdout ?? "").split(/\r?\n/)) {
|
|
1729
|
+
const pid = Number(line.trim());
|
|
1730
|
+
if (Number.isInteger(pid) && pid > 0) pids.add(pid);
|
|
1731
|
+
}
|
|
1732
|
+
return [...pids];
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
/** 端口上的 HTTP 服务是不是 keel(/api/health 认身份)——不是自己的端口绝不杀。 */
|
|
1736
|
+
function probeKeelHealth(port, timeoutMs = 1500) {
|
|
1737
|
+
return new Promise((resolvePromise) => {
|
|
1738
|
+
const req = httpGet({ host: "127.0.0.1", port: Number(port), path: "/api/health", timeout: timeoutMs }, (res) => {
|
|
1739
|
+
let body = "";
|
|
1740
|
+
res.setEncoding("utf8");
|
|
1741
|
+
res.on("data", (chunk) => {
|
|
1742
|
+
body += chunk;
|
|
1743
|
+
if (body.length > 64 * 1024) req.destroy();
|
|
1744
|
+
});
|
|
1745
|
+
res.on("end", () => {
|
|
1746
|
+
try {
|
|
1747
|
+
const json = JSON.parse(body);
|
|
1748
|
+
resolvePromise(json && json.ok === true && typeof json.piVersion === "string" ? json : null);
|
|
1749
|
+
} catch {
|
|
1750
|
+
resolvePromise(null);
|
|
1751
|
+
}
|
|
1752
|
+
});
|
|
1753
|
+
});
|
|
1754
|
+
req.on("timeout", () => req.destroy());
|
|
1755
|
+
req.on("error", () => resolvePromise(null));
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
function killLocalPid(pid, signal = "SIGTERM") {
|
|
1760
|
+
try {
|
|
1761
|
+
process.kill(pid, signal);
|
|
1762
|
+
return true;
|
|
1763
|
+
} catch {
|
|
1764
|
+
return false;
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
async function waitUntilStopped(port, pid, timeoutMs) {
|
|
1769
|
+
const deadline = Date.now() + timeoutMs;
|
|
1770
|
+
while (Date.now() < deadline) {
|
|
1771
|
+
const listening = listeningPidsOnPort(port).length > 0;
|
|
1772
|
+
const alive = pid ? pidAlive(pid) : false;
|
|
1773
|
+
if (!listening && !alive) return true;
|
|
1774
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
1775
|
+
}
|
|
1776
|
+
return false;
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
/**
|
|
1780
|
+
* 停掉「正在跑的那个实例」——不看它是谁拉起来的(前台 `keel start` / 桌面快捷方式 / 系统服务)。
|
|
1781
|
+
*
|
|
1782
|
+
* 判定顺序(先礼后兵):
|
|
1783
|
+
* 1. 控制 socket:实例自述 pid 并自己走正常 shutdown 收场(落盘、杀子进程树、释放端口);
|
|
1784
|
+
* 2. 端口兜底:socket 够不着时按端口找持有者,**先拿 /api/health 认身份**,认不出就不动手;
|
|
1785
|
+
* 3. 都不是:如实回报「没有运行中的实例」,不再谎报「已停止」。
|
|
1786
|
+
*/
|
|
1787
|
+
async function stopRunningInstance(opts) {
|
|
1788
|
+
const port = Number(resolvedServicePort(opts));
|
|
1789
|
+
const live = await controlCommand(opts, "status");
|
|
1790
|
+
const livePid = live && live.ok && Number.isInteger(live.pid) ? live.pid : undefined;
|
|
1791
|
+
if (live && live.ok) {
|
|
1792
|
+
const ack = await controlCommand(opts, "stop");
|
|
1793
|
+
// 老内核不认 stop(回 ok:false)就别干等:直接进端口兜底
|
|
1794
|
+
const patience = ack && ack.ok ? 15_000 : 2_000;
|
|
1795
|
+
if (await waitUntilStopped(port, livePid, patience)) return { how: "instance", pid: livePid, port };
|
|
1796
|
+
}
|
|
1797
|
+
const pids = listeningPidsOnPort(port).filter((p) => p !== process.pid);
|
|
1798
|
+
if (pids.length === 0) {
|
|
1799
|
+
// 端口空着、socket 也不应答:真的没在跑(也可能 lsof 缺失,下面靠 health 兜)。
|
|
1800
|
+
const health = await probeKeelHealth(port);
|
|
1801
|
+
if (health) return { how: "unresolvable", port };
|
|
1802
|
+
return { how: "none", port };
|
|
1803
|
+
}
|
|
1804
|
+
const health = await probeKeelHealth(port);
|
|
1805
|
+
if (!health) return { how: "foreign", port, pids };
|
|
1806
|
+
for (const pid of pids) killLocalPid(pid);
|
|
1807
|
+
if (await waitUntilStopped(port, undefined, 8_000)) return { how: "port", pid: pids[0], port };
|
|
1808
|
+
for (const pid of pids) killLocalPid(pid, "SIGKILL");
|
|
1809
|
+
if (await waitUntilStopped(port, undefined, 3_000)) return { how: "port", pid: pids[0], port };
|
|
1810
|
+
return { how: "failed", port, pids };
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
/** 「到底停没停」只有一处裁定的**出口**:把真实结果原样说给人,不再一律打印「已停止」。 */
|
|
1814
|
+
function reportStopResult(name, res, { quietNone = false } = {}) {
|
|
1815
|
+
switch (res.how) {
|
|
1816
|
+
case "instance":
|
|
1817
|
+
console.log(
|
|
1818
|
+
ZH
|
|
1819
|
+
? `⏹ 已停止 ${name} 的运行中实例(PID ${res.pid ?? "未知"} · 端口 ${res.port})`
|
|
1820
|
+
: `⏹ Stopped the running ${name} instance (PID ${res.pid ?? "unknown"} · port ${res.port})`,
|
|
1821
|
+
);
|
|
1822
|
+
return true;
|
|
1823
|
+
case "port":
|
|
1824
|
+
console.log(
|
|
1825
|
+
ZH
|
|
1826
|
+
? `⏹ 已停止 ${name} 的运行中实例(按端口 ${res.port} 兜底 · PID ${res.pid})`
|
|
1827
|
+
: `⏹ Stopped the running ${name} instance (port ${res.port} fallback · PID ${res.pid})`,
|
|
1828
|
+
);
|
|
1829
|
+
return true;
|
|
1830
|
+
case "unresolvable":
|
|
1831
|
+
console.log(
|
|
1832
|
+
ZH
|
|
1833
|
+
? `⚠ 端口 ${res.port} 上还有 keel 服务应答,但找不到它的 PID(缺 lsof?):请在该终端 Ctrl+C,或用系统进程管理器结束它`
|
|
1834
|
+
: `⚠ A keel server still answers on port ${res.port} but its PID cannot be resolved (lsof missing?): press Ctrl+C in its terminal, or end it with your system process manager`,
|
|
1835
|
+
);
|
|
1836
|
+
return false;
|
|
1837
|
+
case "foreign":
|
|
1838
|
+
console.log(
|
|
1839
|
+
ZH
|
|
1840
|
+
? `· 端口 ${res.port} 被 PID ${res.pids.join(", ")} 占着,但它不是 keel 服务(/api/health 认不出)——不动它`
|
|
1841
|
+
: `· Port ${res.port} is held by PID ${res.pids.join(", ")}, which is not a keel server (/api/health did not match) — leaving it alone`,
|
|
1842
|
+
);
|
|
1843
|
+
return false;
|
|
1844
|
+
case "failed":
|
|
1845
|
+
console.error(
|
|
1846
|
+
ZH
|
|
1847
|
+
? `✖ 未能停止 ${name}:端口 ${res.port} 仍被 PID ${res.pids.join(", ")} 占用`
|
|
1848
|
+
: `✖ Failed to stop ${name}: port ${res.port} is still held by PID ${res.pids.join(", ")}`,
|
|
1849
|
+
);
|
|
1850
|
+
return false;
|
|
1851
|
+
default:
|
|
1852
|
+
// 服务托管那步已经停过了:别再补一句「没有运行中的实例」误导人
|
|
1853
|
+
if (!quietNone)
|
|
1854
|
+
console.log(
|
|
1855
|
+
ZH
|
|
1856
|
+
? `· 没有运行中的 ${name} 实例(端口 ${res.port} 空闲)`
|
|
1857
|
+
: `· No running ${name} instance (port ${res.port} is free)`,
|
|
1858
|
+
);
|
|
1859
|
+
return false;
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1688
1863
|
function isLocalLoopback(addr) {
|
|
1689
1864
|
if (!addr) return false;
|
|
1690
1865
|
const s = addr.trim().toLowerCase();
|
|
@@ -1832,7 +2007,15 @@ async function setQuiesce(opts, on) {
|
|
|
1832
2007
|
);
|
|
1833
2008
|
}
|
|
1834
2009
|
|
|
1835
|
-
|
|
2010
|
+
/**
|
|
2011
|
+
* 服务生命周期控制(status/start/restart/stop)的唯一实现。
|
|
2012
|
+
*
|
|
2013
|
+
* 两个语义必须分开(issue #1038):
|
|
2014
|
+
* - **系统服务**(launchd / systemd / Windows 登录自启)= 「以后要不要开机自启」;
|
|
2015
|
+
* - **运行中实例**(前台 `keel start` / 桌面快捷方式 / 服务拉起)= 「现在这个进程」。
|
|
2016
|
+
* 旧实现把 stop 等同于「停服务」,于是前台起的实例根本停不下来,却还打印「已停止」。
|
|
2017
|
+
*/
|
|
2018
|
+
async function controlService(action, opts) {
|
|
1836
2019
|
const name = serviceName(opts);
|
|
1837
2020
|
|
|
1838
2021
|
if (isMac) {
|
|
@@ -1898,24 +2081,42 @@ function controlService(action, opts) {
|
|
|
1898
2081
|
return;
|
|
1899
2082
|
}
|
|
1900
2083
|
if (isDefaultServiceName(name)) uninstallLegacyLaunchd();
|
|
1901
|
-
if (!loaded())
|
|
2084
|
+
if (!loaded()) {
|
|
2085
|
+
const live = await controlCommand(opts, "status");
|
|
2086
|
+
if (live && live.ok)
|
|
2087
|
+
fail(
|
|
2088
|
+
ZH
|
|
2089
|
+
? `这个实例是前台启动的(PID ${live.pid},无 launchd 托管),没法原地重启:\n` +
|
|
2090
|
+
` 在它的终端 Ctrl+C 后重新 keel start;想以后一键重启先 keel server install。`
|
|
2091
|
+
: `This instance was started in the foreground (PID ${live.pid}, no launchd supervision) and cannot be restarted in place:\n` +
|
|
2092
|
+
` press Ctrl+C in its terminal and run keel start again, or run keel server install for one-command restarts.`,
|
|
2093
|
+
);
|
|
1902
2094
|
fail(ZH ? `${label} 未加载,请先 keel server start` : `${label} not loaded, run keel server start first`);
|
|
2095
|
+
}
|
|
1903
2096
|
run("launchctl", ["kickstart", "-k", target]);
|
|
1904
2097
|
console.log(ZH ? `✅ 已重启 ${label}` : `✅ Restarted ${label}`);
|
|
1905
2098
|
return;
|
|
1906
2099
|
}
|
|
1907
2100
|
|
|
1908
2101
|
if (action === "stop") {
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
);
|
|
2102
|
+
const jobLoaded = loaded();
|
|
2103
|
+
if (jobLoaded) {
|
|
2104
|
+
run("launchctl", ["bootout", target], {
|
|
2105
|
+
ignoreError: true,
|
|
2106
|
+
silent: true,
|
|
2107
|
+
});
|
|
2108
|
+
if (isDefaultServiceName(name)) uninstallLegacyLaunchd();
|
|
2109
|
+
}
|
|
2110
|
+
// 先摘掉 launchd 托管(KeepAlive 会复活进程),再让实例自己收场。
|
|
2111
|
+
const res = await stopRunningInstance(opts);
|
|
2112
|
+
const stopped = reportStopResult(name, res, { quietNone: jobLoaded });
|
|
2113
|
+
if (jobLoaded)
|
|
2114
|
+
console.log(
|
|
2115
|
+
ZH
|
|
2116
|
+
? ` ${label} 已卸载(不再开机自启;start 恢复)`
|
|
2117
|
+
: ` ${label} unloaded (auto-start removed; start to resume)`,
|
|
2118
|
+
);
|
|
2119
|
+
if (!stopped && res.how === "failed") process.exitCode = 1;
|
|
1919
2120
|
return;
|
|
1920
2121
|
}
|
|
1921
2122
|
|
|
@@ -1923,13 +2124,48 @@ function controlService(action, opts) {
|
|
|
1923
2124
|
}
|
|
1924
2125
|
|
|
1925
2126
|
if (isLinux) {
|
|
1926
|
-
|
|
2127
|
+
const unit = `${name}.service`;
|
|
2128
|
+
const installed = () => existsSync(systemdUnitPath(name));
|
|
1927
2129
|
if (action === "status") {
|
|
1928
|
-
run("systemctl", ["status",
|
|
2130
|
+
if (installed()) run("systemctl", ["status", unit, "--no-pager"], { ignoreError: true });
|
|
2131
|
+
else
|
|
2132
|
+
console.log(
|
|
2133
|
+
ZH ? `${unit}: 未安装(运行 keel server install 安装)` : `${unit}: not installed (run keel server install)`,
|
|
2134
|
+
);
|
|
2135
|
+
return;
|
|
2136
|
+
}
|
|
2137
|
+
if (action === "stop") {
|
|
2138
|
+
const unitInstalled = installed();
|
|
2139
|
+
if (unitInstalled) {
|
|
2140
|
+
ensureRootForSystemctl();
|
|
2141
|
+
run("systemctl", ["stop", unit], { ignoreError: true, silent: true });
|
|
2142
|
+
}
|
|
2143
|
+
const res = await stopRunningInstance(opts);
|
|
2144
|
+
const stopped = reportStopResult(name, res, { quietNone: unitInstalled });
|
|
2145
|
+
if (unitInstalled)
|
|
2146
|
+
console.log(
|
|
2147
|
+
ZH
|
|
2148
|
+
? ` ${unit} 已停止(自启保留;uninstall 移除)`
|
|
2149
|
+
: ` ${unit} stopped (auto-start preserved; uninstall to remove)`,
|
|
2150
|
+
);
|
|
2151
|
+
if (!stopped && res.how === "failed") process.exitCode = 1;
|
|
1929
2152
|
return;
|
|
1930
2153
|
}
|
|
1931
|
-
|
|
1932
|
-
|
|
2154
|
+
if (action === "restart" && !installed()) {
|
|
2155
|
+
const live = await controlCommand(opts, "status");
|
|
2156
|
+
if (live && live.ok)
|
|
2157
|
+
fail(
|
|
2158
|
+
ZH
|
|
2159
|
+
? `这个实例是前台启动的(PID ${live.pid},无 systemd 托管),没法原地重启:\n` +
|
|
2160
|
+
` 在它的终端 Ctrl+C 后重新 keel start;想以后一键重启先 keel server install。`
|
|
2161
|
+
: `This instance was started in the foreground (PID ${live.pid}, no systemd supervision) and cannot be restarted in place:\n` +
|
|
2162
|
+
` press Ctrl+C in its terminal and run keel start again, or run keel server install for one-command restarts.`,
|
|
2163
|
+
);
|
|
2164
|
+
fail(ZH ? `${unit} 未安装,请先 keel server install` : `${unit} not installed, run keel server install first`);
|
|
2165
|
+
}
|
|
2166
|
+
ensureRootForSystemctl();
|
|
2167
|
+
run("systemctl", [action, unit]);
|
|
2168
|
+
console.log(`✅ ${action} ${unit}`);
|
|
1933
2169
|
return;
|
|
1934
2170
|
}
|
|
1935
2171
|
|
|
@@ -2016,10 +2252,20 @@ function controlService(action, opts) {
|
|
|
2016
2252
|
);
|
|
2017
2253
|
return;
|
|
2018
2254
|
}
|
|
2019
|
-
if (!installed)
|
|
2255
|
+
if (!installed) {
|
|
2256
|
+
const live = await controlCommand(opts, "status");
|
|
2257
|
+
if (live && live.ok)
|
|
2258
|
+
fail(
|
|
2259
|
+
ZH
|
|
2260
|
+
? `这个实例是前台启动的(PID ${live.pid},无登录自启托管),没法原地重启:\n` +
|
|
2261
|
+
` 在它的终端 Ctrl+C 后重新 keel start;想以后一键重启先 keel server install。`
|
|
2262
|
+
: `This instance was started in the foreground (PID ${live.pid}, no login auto-start supervision) and cannot be restarted in place:\n` +
|
|
2263
|
+
` press Ctrl+C in its terminal and run keel start again, or run keel server install for one-command restarts.`,
|
|
2264
|
+
);
|
|
2020
2265
|
fail(
|
|
2021
2266
|
ZH ? `${name} 不存在,请先运行 keel server install` : `${name} does not exist, run keel server install first`,
|
|
2022
2267
|
);
|
|
2268
|
+
}
|
|
2023
2269
|
stopWinInstance(name);
|
|
2024
2270
|
launchWinService(winVbsPath(name));
|
|
2025
2271
|
console.log(ZH ? `✅ 已重启 ${name}` : `✅ Restarted ${name}`);
|
|
@@ -2028,39 +2274,33 @@ function controlService(action, opts) {
|
|
|
2028
2274
|
|
|
2029
2275
|
if (action === "stop") {
|
|
2030
2276
|
const stopPort = Number(resolvedServicePort(opts));
|
|
2031
|
-
if (legacy)
|
|
2277
|
+
if (legacy)
|
|
2032
2278
|
run("schtasks", ["/End", "/TN", name], {
|
|
2033
2279
|
ignoreError: true,
|
|
2034
2280
|
silent: true,
|
|
2035
2281
|
});
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
}
|
|
2044
|
-
console.log(
|
|
2282
|
+
// 1) 先让实例自己走正常 shutdown(前台 / 快捷方式拉起的实例根本没有 watchdog 可停)
|
|
2283
|
+
const res = await stopRunningInstance(opts);
|
|
2284
|
+
// 2) Windows 特有残留:看门狗脚本、pid 文件、端口占用
|
|
2285
|
+
const win = stopWinInstance(name, stopPort);
|
|
2286
|
+
const stopped = reportStopResult(name, res, { quietNone: installed || legacy });
|
|
2287
|
+
if (!win.stopped)
|
|
2288
|
+
fail(
|
|
2045
2289
|
ZH
|
|
2046
|
-
?
|
|
2047
|
-
:
|
|
2290
|
+
? `未能停止 ${name}:端口 ${stopPort} 仍被占用(PID: ${win.remainingPids.join(", ")})`
|
|
2291
|
+
: `Failed to stop ${name}: port ${stopPort} still listening (PID: ${win.remainingPids.join(", ")})`,
|
|
2048
2292
|
);
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
if (!res.stopped) {
|
|
2053
|
-
fail(
|
|
2293
|
+
if (!stopped && res.how === "failed") process.exitCode = 1;
|
|
2294
|
+
if (legacy)
|
|
2295
|
+
console.log(
|
|
2054
2296
|
ZH
|
|
2055
|
-
?
|
|
2056
|
-
: `
|
|
2297
|
+
? ` 旧版计划任务已停用(重新 server install 可迁移到登录自启)`
|
|
2298
|
+
: ` Legacy scheduled task stopped (re-run server install to migrate to login auto-start)`,
|
|
2299
|
+
);
|
|
2300
|
+
else if (installed)
|
|
2301
|
+
console.log(
|
|
2302
|
+
ZH ? ` ${name} 自启保留(uninstall 移除)` : ` ${name} auto-start preserved (uninstall to remove)`,
|
|
2057
2303
|
);
|
|
2058
|
-
}
|
|
2059
|
-
console.log(
|
|
2060
|
-
ZH
|
|
2061
|
-
? `⏹ 已停止 ${name}(自启保留;uninstall 移除)`
|
|
2062
|
-
: `⏹ Stopped ${name} (auto-start preserved; uninstall to remove)`,
|
|
2063
|
-
);
|
|
2064
2304
|
return;
|
|
2065
2305
|
}
|
|
2066
2306
|
|
|
@@ -3990,7 +4230,7 @@ async function serverCmd(argv) {
|
|
|
3990
4230
|
if (positionals.length === 0) {
|
|
3991
4231
|
console.log(HELP);
|
|
3992
4232
|
console.log(ZH ? "--- 当前服务状态 ---" : "--- Current service status ---");
|
|
3993
|
-
controlService("status", opts);
|
|
4233
|
+
await controlService("status", opts);
|
|
3994
4234
|
return;
|
|
3995
4235
|
}
|
|
3996
4236
|
const action = positionals[0];
|
|
@@ -4053,16 +4293,16 @@ async function serverCmd(argv) {
|
|
|
4053
4293
|
}
|
|
4054
4294
|
case "start":
|
|
4055
4295
|
case "restart": {
|
|
4056
|
-
controlService(action, opts);
|
|
4296
|
+
await controlService(action, opts);
|
|
4057
4297
|
const fallbackToken = process.env.KEEL_TOKEN || "";
|
|
4058
4298
|
await printRunningServiceAccess(opts, opts.host ?? process.env.KEEL_HOST, fallbackToken);
|
|
4059
4299
|
break;
|
|
4060
4300
|
}
|
|
4061
4301
|
case "stop":
|
|
4062
|
-
controlService(action, opts);
|
|
4302
|
+
await controlService(action, opts);
|
|
4063
4303
|
break;
|
|
4064
4304
|
case "status":
|
|
4065
|
-
controlService("status", opts);
|
|
4305
|
+
await controlService("status", opts);
|
|
4066
4306
|
await printLiveStatus(opts);
|
|
4067
4307
|
break;
|
|
4068
4308
|
case "quiesce":
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ALL_AGENT_TOOL_ENTRIES } from "../../tool-catalog.js";
|
|
2
|
+
import { isRemoteWorkspaceUri, restoreWorkspaceUriFromSessionDir } from "../../remote-workspace.js";
|
|
2
3
|
/**
|
|
3
4
|
* 提示词覆写扩展(SDK 的 `before_agent_start`):按需加载生效时,把这一轮的整份系统提示词
|
|
4
5
|
* 换成宿主渲染的那一份(老实现 `pi-webui-persona` 扩展同一位置、同一语义)。
|
|
@@ -25,7 +26,8 @@ export function createPromptRenderExtension(binding) {
|
|
|
25
26
|
});
|
|
26
27
|
const botId = typeof binding.botId === "function" ? binding.botId() : binding.botId;
|
|
27
28
|
const isBot = Boolean(botId) || binding.clientId.startsWith("device-task-");
|
|
28
|
-
|
|
29
|
+
const isRemote = isRemoteWorkspaceUri(restoreWorkspaceUriFromSessionDir(ctx.cwd));
|
|
30
|
+
if (!tools && !isBot && !isRemote)
|
|
29
31
|
return undefined;
|
|
30
32
|
const rendered = binding.port.render({
|
|
31
33
|
cwd: ctx.cwd,
|
|
@@ -6,6 +6,7 @@ import { guardSession } from "../../session-turns.js";
|
|
|
6
6
|
import { prepareTranscriptForOpen } from "../../transcript-prepare.js";
|
|
7
7
|
import { calibrateSessionLeaf } from "../../session-branch.js";
|
|
8
8
|
import { conversationTitle } from "../../agent-formatters.js";
|
|
9
|
+
import { isRemoteWorkspaceUri } from "../../remote-workspace.js";
|
|
9
10
|
import { createPromptRenderExtension } from "./prompt-render.js";
|
|
10
11
|
/** 打开会话失败:必带 cwd 与目标转录,禁静默返回半成品。 */
|
|
11
12
|
export class OpenSessionError extends Error {
|
|
@@ -100,7 +101,7 @@ export async function createBranchFile(options) {
|
|
|
100
101
|
* 并把问题降级成 `modelFallbackMessage`,真正报错发生在跑第一轮时。
|
|
101
102
|
*/
|
|
102
103
|
export async function openTurnSession(opts) {
|
|
103
|
-
const cwd = resolve(opts.cwd);
|
|
104
|
+
const cwd = isRemoteWorkspaceUri(opts.cwd) ? opts.cwd : resolve(opts.cwd);
|
|
104
105
|
const agentDir = resolve(opts.agentDir);
|
|
105
106
|
const sessionFile = opts.sessionFile === undefined ? undefined : resolve(opts.sessionFile);
|
|
106
107
|
let manager;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createBashToolDefinition, createEditToolDefinition, createWriteToolDefinition, } from "@earendil-works/pi-coding-agent";
|
|
1
|
+
import { createBashToolDefinition, createEditToolDefinition, createFindToolDefinition, createGrepToolDefinition, createLsToolDefinition, createPowerShellToolDefinition, createReadToolDefinition, createWriteToolDefinition, } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
3
|
import { withToolGuard, makeLateToolGuard } from "../../tool-guards.js";
|
|
4
4
|
const BASH_TOOL_PARAMETERS = Type.Object({
|
|
@@ -48,9 +48,9 @@ export function withBashAbortHandle(def, options) {
|
|
|
48
48
|
* (老树同口径)。内核不认识 SSH,也不该认识。
|
|
49
49
|
*/
|
|
50
50
|
export function createGuardedBuiltinTools(options) {
|
|
51
|
-
// 远程工作区要用 SSH/SFTP
|
|
51
|
+
// 远程工作区要用 SSH/SFTP 的文件与命令操作(宿主注入);非远程或没注入就走本地实现(老树同口径)。
|
|
52
52
|
const remoteOps = options.remoteOpsOf?.(options.cwd);
|
|
53
|
-
const baseBash = createBashToolDefinition(options.cwd);
|
|
53
|
+
const baseBash = createBashToolDefinition(options.cwd, remoteOps?.bash ? { operations: remoteOps.bash } : undefined);
|
|
54
54
|
const bash = {
|
|
55
55
|
...baseBash,
|
|
56
56
|
parameters: BASH_TOOL_PARAMETERS,
|
|
@@ -156,10 +156,37 @@ export function createGuardedBuiltinTools(options) {
|
|
|
156
156
|
...(options.conversationId ? { conversationId: options.conversationId } : {}),
|
|
157
157
|
})
|
|
158
158
|
: bash;
|
|
159
|
-
|
|
159
|
+
const tools = [
|
|
160
160
|
withToolGuard(killableBash, { ...common, toolName: "bash" }),
|
|
161
161
|
withToolGuard(write, { ...common, toolName: "write" }),
|
|
162
162
|
withToolGuard(edit, { ...common, toolName: "edit" }),
|
|
163
163
|
];
|
|
164
|
+
if (remoteOps) {
|
|
165
|
+
if (remoteOps.read) {
|
|
166
|
+
const read = createReadToolDefinition(options.cwd, { operations: remoteOps.read });
|
|
167
|
+
tools.push(withToolGuard(read, { ...common, toolName: "read" }));
|
|
168
|
+
}
|
|
169
|
+
if (remoteOps.ls) {
|
|
170
|
+
tools.push(createLsToolDefinition(options.cwd, { operations: remoteOps.ls }));
|
|
171
|
+
}
|
|
172
|
+
if (remoteOps.find) {
|
|
173
|
+
tools.push(createFindToolDefinition(options.cwd, { operations: remoteOps.find }));
|
|
174
|
+
}
|
|
175
|
+
if (remoteOps.grepExecute) {
|
|
176
|
+
const grepExecute = remoteOps.grepExecute;
|
|
177
|
+
const baseGrep = createGrepToolDefinition(options.cwd);
|
|
178
|
+
tools.push({
|
|
179
|
+
...baseGrep,
|
|
180
|
+
execute: async (_toolCallId, params) => {
|
|
181
|
+
const text = await grepExecute((params ?? {}));
|
|
182
|
+
return { content: [{ type: "text", text }], details: undefined };
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
if (remoteOps.bash) {
|
|
187
|
+
tools.push(createPowerShellToolDefinition(options.cwd, { operations: remoteOps.bash }));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return tools;
|
|
164
191
|
}
|
|
165
192
|
export const GUARDED_BUILTIN_NAMES = ["bash", "write", "edit"];
|
|
@@ -4,6 +4,7 @@ import { Type } from "typebox";
|
|
|
4
4
|
import { pick } from "../../i18n.js";
|
|
5
5
|
import { applyHashlinePatch, formatHashlineHeader, globalSnapshotStore, } from "../../hashline-engine.js";
|
|
6
6
|
import { PATCH_TOOL_NAME } from "../../tool-names.js";
|
|
7
|
+
import { isRemoteWorkspaceUri, restoreWorkspaceUriFromSessionDir } from "../../remote-workspace.js";
|
|
7
8
|
export function makePatchTool(options) {
|
|
8
9
|
const cwd = options.cwd;
|
|
9
10
|
const getLang = options.lang ?? (() => "en");
|
|
@@ -28,6 +29,21 @@ Success returns the next anchor tag and live LSP diagnostics.`,
|
|
|
28
29
|
}),
|
|
29
30
|
async execute(_callId, params) {
|
|
30
31
|
const L = getLang();
|
|
32
|
+
if (isRemoteWorkspaceUri(restoreWorkspaceUriFromSessionDir(cwd))) {
|
|
33
|
+
return {
|
|
34
|
+
content: [
|
|
35
|
+
{
|
|
36
|
+
type: "text",
|
|
37
|
+
text: pick(L, "错误:远程 SSH 工作区不支持 patch 工具,请改用 edit 或 write 工具。", "Error: patch is not supported on remote SSH workspaces; use edit or write instead."),
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
details: {
|
|
41
|
+
ok: false,
|
|
42
|
+
summary: "Unsupported on remote SSH workspace",
|
|
43
|
+
results: [],
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
31
47
|
const patchText = typeof params?.patch === "string" ? params.patch : "";
|
|
32
48
|
if (!patchText.trim()) {
|
|
33
49
|
const emptyReport = {
|