pi-web-ui 0.114.0 → 0.114.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 +28 -0
- package/README.md +187 -187
- package/README.zh-CN.md +227 -227
- package/README.zh-TW.md +227 -227
- package/bin/device-hub-cli.mjs +577 -577
- package/bin/frp-manager.mjs +1573 -1573
- package/bin/pi-device-hub.mjs +9 -9
- package/bin/pi-web-ui.mjs +4081 -4073
- package/deploy/nginx-subpath.conf +100 -100
- package/deploy/pi-web-ui.service +36 -36
- package/dist/server/agent-service.js +131 -55
- package/dist/server/attachments.js +51 -5
- package/dist/server/canvas/canvas-agent-tool.js +3 -3
- package/dist/server/canvas/canvas-cards.js +1 -1
- package/dist/server/canvas/canvas-orchestrator.js +3 -3
- package/dist/server/canvas/canvas-scheduled-task.js +45 -0
- package/dist/server/canvas/canvas-validation.js +1 -1
- package/dist/server/client-state.js +6 -2
- package/dist/server/compaction-instructions.js +8 -8
- package/dist/server/device-center/connector.js +33 -14
- package/dist/server/device-center/desktop-page.js +228 -228
- package/dist/server/device-center/hub-page.js +64 -64
- package/dist/server/device-center/hub.js +2 -1
- package/dist/server/device-center/local-hub.js +92 -0
- package/dist/server/device-center/local.js +60 -7
- package/dist/server/device-center/native-desktop/macos.js +190 -190
- package/dist/server/device-center/native-desktop/windows.js +116 -116
- package/dist/server/device-center/path-portal.js +1 -1
- package/dist/server/device-center/relay.js +45 -8
- package/dist/server/dispatch-domain-handlers.js +1 -0
- package/dist/server/dsh/dsh-agent-service.js +5 -1
- package/dist/server/dsh/runtime/cordis.yml +1 -1
- package/dist/server/dsh/runtime/custom-prompt.mjs +33 -33
- package/dist/server/dsh/runtime/goal-rpc.mjs +1309 -1309
- package/dist/server/dsh/runtime/launcher.mjs +235 -235
- package/dist/server/dsh/runtime/override.patch.yml +89 -89
- package/dist/server/dsh/runtime/runtime-root.mjs +405 -405
- package/dist/server/engine-probe.js +36 -6
- package/dist/server/eval-tool.js +135 -135
- package/dist/server/global-loader.js +40 -2
- package/dist/server/index.js +56 -32
- package/dist/server/patch-bash-process.js +125 -0
- package/dist/server/patch-tool.js +9 -9
- package/dist/server/patch-turn-end-boundary.js +3 -3
- package/dist/server/persona-chain.js +8 -8
- package/dist/server/plugins.js +26 -2
- package/dist/server/preset-fields.js +7 -0
- package/dist/server/preset-share.js +1 -0
- package/dist/server/prompt-templates.js +106 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/remote-ssh-service.js +39 -39
- package/dist/server/resolve-global-sdk.js +2 -0
- package/dist/server/schedule-agent-tool.js +39 -21
- package/dist/server/scheduler-tasks.js +45 -9
- package/dist/server/scm-commitmsg.js +10 -10
- package/dist/server/settings-service.js +6 -0
- package/dist/server/setup-page.js +620 -620
- package/dist/server/text-quote.js +9 -0
- package/dist/server/tool-manager.js +2 -1
- package/dist/server/universal/drivers/claude-code.js +5 -0
- package/dist/server/universal/drivers/codex.js +336 -0
- package/dist/server/universal/index.js +1 -0
- package/dist/server/universal/universal-attachments.js +24 -1
- package/dist/server/universal/universal-session.js +23 -0
- package/dist/server/vision-bridge.js +18 -18
- package/docs/device-center.md +148 -142
- package/docs/device-desktop.md +48 -48
- package/docs/dsh-engine.md +493 -493
- package/extensions/webui.ts +335 -335
- package/package.json +2 -2
- package/plugin-sdk/README.md +174 -174
- package/plugin-sdk/client-utils.mjs +279 -279
- package/plugin-sdk/import-check.mjs +210 -210
- package/plugin-sdk/index.d.ts +698 -698
- package/plugin-sdk/index.mjs +696 -696
- package/plugin-sdk/package.json +13 -13
- package/plugin-sdk/ssh-host-trust.mjs +225 -225
- package/plugins/catalog.json +10 -0
- package/themes/aetheris.css +501 -501
- package/themes/ayu-light.css +116 -116
- package/themes/bases/flow-base.css +1357 -1357
- package/themes/bases/obsidian-base.css +895 -895
- package/themes/bases/statusbar-flat-base.css +112 -112
- package/themes/bases/zhujian-base.css +688 -688
- package/themes/bases/zhupi-base.css +660 -660
- package/themes/catppuccin-latte.css +119 -119
- package/themes/catppuccin.css +116 -116
- package/themes/claude-code-dark.css +147 -147
- package/themes/codex.css +114 -114
- package/themes/cyberpunk.css +50 -50
- package/themes/dark-teal.css +264 -264
- package/themes/dazzle.css +38 -38
- package/themes/everforest-light.css +115 -115
- package/themes/flow-light.css +164 -164
- package/themes/flow.css +161 -161
- package/themes/geist.css +114 -114
- package/themes/gruvbox-light.css +115 -115
- package/themes/kanagawa-lotus.css +115 -115
- package/themes/md-preview.css +24 -24
- package/themes/mist.css +166 -166
- package/themes/nord.css +107 -107
- package/themes/one-dark.css +106 -106
- package/themes/paper.css +174 -174
- package/themes/rose-pine-dawn.css +114 -114
- package/themes/sakura.css +166 -166
- package/themes/solarized-light.css +114 -114
- package/themes/tokyo-night.css +115 -115
- package/themes/translucent.css +85 -85
- package/themes/transparent.css +116 -116
- package/themes/vs-code-dark.css +147 -147
- package/themes/wallpaper-flow.css +382 -382
- package/themes/wallpaper-obsidian.css +74 -74
- package/themes/white.css +164 -164
- package/themes/zhujian-dark.css +115 -115
- package/themes/zhujian.css +114 -114
- package/themes/zhupi-dark.css +115 -115
- package/themes/zhupi.css +114 -114
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/BgTasksModal-BcXJ20RO.js +1 -0
- package/web/dist/assets/BgTasksModal-DjQmiKnE.js +1 -0
- package/web/dist/assets/{CanvasStudio-BEJZE5BI.js → CanvasStudio-PI9pid0Y.js} +3 -3
- package/web/dist/assets/{CanvasStudio-CgUNHqos.js → CanvasStudio-nf5-HxLM.js} +3 -3
- package/web/dist/assets/DeviceCenter-CYttJw2a.js +3 -0
- package/web/dist/assets/DeviceCenter-DPe4sz74.js +3 -0
- package/web/dist/assets/DeviceGroups-D2rogxEN.js +1 -0
- package/web/dist/assets/Dropdown-ZLS04O8p.js +1 -0
- package/web/dist/assets/FilePreview-C9Ut4Lq6.js +2 -0
- package/web/dist/assets/FilePreview-CvK3ZzX5.js +2 -0
- package/web/dist/assets/GlobalSearchModal-C5e-OCw2.js +1 -0
- package/web/dist/assets/GlobalSearchModal-H7pFK2UC.js +1 -0
- package/web/dist/assets/GroupConversation-C2wNM0dQ.js +1 -0
- package/web/dist/assets/GroupConversation-ChN3TWQK.js +1 -0
- package/web/dist/assets/ModelConfigModal-DDZccDYt.js +2 -0
- package/web/dist/assets/PiSetupModal-DHbqfx8T.js +1 -0
- package/web/dist/assets/ProviderOAuthControls-C-MK36Dk.js +1 -0
- package/web/dist/assets/SCMPanel-buTGziDB.js +2 -0
- package/web/dist/assets/SCMPanel-kx-SCL2s.js +2 -0
- package/web/dist/assets/SettingsModal-BsUF8jqr.js +20 -0
- package/web/dist/assets/SettingsModal-D357Ky7P.js +20 -0
- package/web/dist/assets/{TerminalPanel-DL20uKgU.js → TerminalPanel-BBuM_Sez.js} +2 -2
- package/web/dist/assets/{TerminalPanel-D6cPRFei.js → TerminalPanel-D6x6xz8Q.js} +2 -2
- package/web/dist/assets/TuiOverlayModal-CdbGV3Za.js +1 -0
- package/web/dist/assets/TuiOverlayModal-d6x9u25n.js +1 -0
- package/web/dist/assets/app-globals-DcyO0UPi.js +1 -0
- package/web/dist/assets/{desktop-DPyTy4M3.js → desktop-YguLbrX1.js} +1 -1
- package/web/dist/assets/fi-DaSO0Q-m.js +325 -0
- package/web/dist/assets/index-BPvpea8t.js +85 -0
- package/web/dist/assets/index-D6u8xH0o.js +85 -0
- package/web/dist/assets/index-DDZMv6LO.css +1 -0
- package/web/dist/assets/{plugin-host-CqA4yW6w.js → plugin-host-BRBg6zmQ.js} +1 -1
- package/web/dist/assets/theme-DDl-Oy1b.js +1 -0
- package/web/dist/index.html +37 -36
- package/web/dist/sw.js +179 -179
- package/web/public/sw.js +179 -179
- package/dist/gh-comment-781.md +0 -5
- package/dist/server/device-center/local-page.js +0 -17
- package/dist/server/device-center/smoke-preview.js +0 -3
- package/dist/server/durable/durable-capabilities.js +0 -11
- package/dist/server/markers/builtins/services.js +0 -123
- package/dist/server/markers/builtins/todo.js +0 -189
- package/dist/server/markers-list-tool.js +0 -34
- package/dist/server/orchestrator.js +0 -109
- package/dist/server/system-prompt-soul.js +0 -41
- package/dist/server/univer-service.js +0 -448
- package/dist/server/universal/drivers/dsh-driver.js +0 -379
- package/dist/test-artifact.md +0 -9
- package/dist/test-preview-modal.md +0 -11
- package/dist/test-report.html +0 -20
- package/web/dist/assets/BgTasksModal-CS7UNzcw.js +0 -1
- package/web/dist/assets/BgTasksModal-Dk-tp78W.js +0 -1
- package/web/dist/assets/DeviceCenter-C8_CbxQ3.js +0 -3
- package/web/dist/assets/DeviceCenter-CVblvhNX.js +0 -3
- package/web/dist/assets/Dropdown-Oug0DDte.js +0 -1
- package/web/dist/assets/FilePreview-CvdX6nr6.js +0 -2
- package/web/dist/assets/FilePreview-kCZhfBAF.js +0 -2
- package/web/dist/assets/GlobalSearchModal-BLH63yYP.js +0 -1
- package/web/dist/assets/GlobalSearchModal-DAkvlvp6.js +0 -1
- package/web/dist/assets/GroupConversation-Cgo4xbpa.js +0 -1
- package/web/dist/assets/GroupConversation-DZ71jEi8.js +0 -1
- package/web/dist/assets/ModelConfigModal-BpWdFdQC.js +0 -2
- package/web/dist/assets/PiSetupModal-mkWPSxMj.js +0 -1
- package/web/dist/assets/ProviderOAuthControls-VK_jqXYS.js +0 -1
- package/web/dist/assets/SCMPanel-BP1TUT-V.js +0 -2
- package/web/dist/assets/SCMPanel-BscPm9kf.js +0 -2
- package/web/dist/assets/SettingsModal-C8UgMjVM.js +0 -20
- package/web/dist/assets/SettingsModal-VynB7jNb.js +0 -20
- package/web/dist/assets/TuiOverlayModal-Dst3BmT8.js +0 -1
- package/web/dist/assets/TuiOverlayModal-NCkpNtTp.js +0 -1
- package/web/dist/assets/UniversalPathPicker-CfQFc_c3.js +0 -1
- package/web/dist/assets/UniversalPathPicker-DwxwNcFw.js +0 -1
- package/web/dist/assets/app-globals-CnO6KlEM.js +0 -325
- package/web/dist/assets/index-CPgAH5q7.js +0 -83
- package/web/dist/assets/index-Cje8iugL.js +0 -83
- package/web/dist/assets/index-DnKeiDbj.css +0 -1
- package/web/dist/assets/theme-BqdAjEjF.js +0 -1
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/** Bound native shell output draining without changing shell selection (issue #794). */
|
|
2
|
+
import { registerHooks } from "node:module";
|
|
3
|
+
export const SENTINEL = "// pi-web-ui #794: bounded shell lifecycle v1";
|
|
4
|
+
// Kept as JavaScript source because this compatibility patch runs inside the SDK.
|
|
5
|
+
// The SDK still owns shell discovery, environment, process groups and tree killing.
|
|
6
|
+
export const SHELL_WAIT_SOURCE = `function waitForShellLifecycle(child, { onData, signal, timeout, timeoutMs, kill }) {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
let settled = false;
|
|
9
|
+
let exited = false;
|
|
10
|
+
let exitCode = null;
|
|
11
|
+
let stopError;
|
|
12
|
+
let executionTimer;
|
|
13
|
+
let drainTimer;
|
|
14
|
+
let idleTimer;
|
|
15
|
+
let stopTimer;
|
|
16
|
+
const cleanup = () => {
|
|
17
|
+
clearTimeout(executionTimer);
|
|
18
|
+
clearTimeout(drainTimer);
|
|
19
|
+
clearTimeout(idleTimer);
|
|
20
|
+
clearTimeout(stopTimer);
|
|
21
|
+
signal?.removeEventListener("abort", onAbort);
|
|
22
|
+
child.removeListener("exit", onExit);
|
|
23
|
+
child.removeListener("close", onClose);
|
|
24
|
+
child.removeListener("error", onError);
|
|
25
|
+
for (const stream of [child.stdout, child.stderr]) {
|
|
26
|
+
stream?.removeListener("data", onOutput);
|
|
27
|
+
stream?.destroy();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const finish = (error) => {
|
|
31
|
+
if (settled) return;
|
|
32
|
+
settled = true;
|
|
33
|
+
cleanup();
|
|
34
|
+
if (error) reject(error);
|
|
35
|
+
else resolve(exitCode);
|
|
36
|
+
};
|
|
37
|
+
const stop = (error) => {
|
|
38
|
+
if (settled || stopError) return;
|
|
39
|
+
stopError = error;
|
|
40
|
+
clearTimeout(executionTimer);
|
|
41
|
+
clearTimeout(drainTimer);
|
|
42
|
+
clearTimeout(idleTimer);
|
|
43
|
+
// Killing is best effort; inherited handles must never prevent settlement.
|
|
44
|
+
stopTimer = setTimeout(() => finish(stopError), 1000);
|
|
45
|
+
try { kill(); } catch { /* preserve the original timeout/cancellation */ }
|
|
46
|
+
};
|
|
47
|
+
const onAbort = () => stop(new Error("aborted"));
|
|
48
|
+
const armIdle = () => {
|
|
49
|
+
clearTimeout(idleTimer);
|
|
50
|
+
idleTimer = setTimeout(() => finish(stopError), 100);
|
|
51
|
+
};
|
|
52
|
+
const onOutput = (data) => {
|
|
53
|
+
if (settled || stopError) return;
|
|
54
|
+
try { onData(data); } catch (error) { stop(error); return; }
|
|
55
|
+
if (exited) armIdle();
|
|
56
|
+
};
|
|
57
|
+
const onExit = (code) => {
|
|
58
|
+
exited = true;
|
|
59
|
+
exitCode = code;
|
|
60
|
+
clearTimeout(executionTimer);
|
|
61
|
+
if (stopError) { finish(stopError); return; }
|
|
62
|
+
// Preserve the SDK's quiet-period drain, but never extend this hard cap.
|
|
63
|
+
drainTimer = setTimeout(() => {
|
|
64
|
+
try { onData(Buffer.from("\\n[Output collection stopped: inherited pipes remained open after the shell exited.]\\n")); }
|
|
65
|
+
catch (error) { finish(error); return; }
|
|
66
|
+
finish();
|
|
67
|
+
}, 1000);
|
|
68
|
+
armIdle();
|
|
69
|
+
};
|
|
70
|
+
const onClose = (code) => {
|
|
71
|
+
exitCode = code;
|
|
72
|
+
finish(stopError);
|
|
73
|
+
};
|
|
74
|
+
const onError = (error) => finish(stopError ?? error);
|
|
75
|
+
child.once("exit", onExit);
|
|
76
|
+
child.once("close", onClose);
|
|
77
|
+
child.once("error", onError);
|
|
78
|
+
child.stdout?.on("data", onOutput);
|
|
79
|
+
child.stderr?.on("data", onOutput);
|
|
80
|
+
if (timeoutMs !== undefined) {
|
|
81
|
+
executionTimer = setTimeout(() => stop(new Error("timeout:" + timeout)), timeoutMs);
|
|
82
|
+
}
|
|
83
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
84
|
+
if (signal?.aborted) onAbort();
|
|
85
|
+
});
|
|
86
|
+
}`;
|
|
87
|
+
const OLD_LIFECYCLE = / let timedOut = false;\r?\n[\s\S]*? finally \{[\s\S]*?signal\.removeEventListener\("abort", onAbort\);\r?\n \}/;
|
|
88
|
+
const REPLACEMENT = ` try {
|
|
89
|
+
const exitCode = await waitForShellLifecycle(child, {
|
|
90
|
+
onData, signal, timeout, timeoutMs,
|
|
91
|
+
kill: () => { if (child.pid) killProcessTree(child.pid); },
|
|
92
|
+
});
|
|
93
|
+
const signalCode = child.signalCode;
|
|
94
|
+
return { exitCode: exitCode ?? (signalCode ? 128 + (osConstants.signals[signalCode] ?? 0) : 1) };
|
|
95
|
+
} finally {
|
|
96
|
+
if (child.pid) untrackDetachedChildPid(child.pid);
|
|
97
|
+
}`;
|
|
98
|
+
export function patchBashProcessSource(source) {
|
|
99
|
+
if (source.includes(SENTINEL))
|
|
100
|
+
return { code: source, status: "already" };
|
|
101
|
+
if (!source.includes('from "../../utils/child-process.js"') || !OLD_LIFECYCLE.test(source)) {
|
|
102
|
+
return { code: source, status: "unsupported" };
|
|
103
|
+
}
|
|
104
|
+
const code = source
|
|
105
|
+
.replace(/import \{ waitForChildProcess \} from "\.\.\/\.\.\/utils\/child-process\.js";\r?\n/, "")
|
|
106
|
+
.replace(OLD_LIFECYCLE, REPLACEMENT);
|
|
107
|
+
return { code: `${code}\n${SENTINEL}\n${SHELL_WAIT_SOURCE}\n`, status: "patched" };
|
|
108
|
+
}
|
|
109
|
+
/* SDK sources are transformed in memory before compilation, never on disk. */
|
|
110
|
+
export function registerBashProcessPatch() {
|
|
111
|
+
registerHooks({
|
|
112
|
+
load(url, context, nextLoad) {
|
|
113
|
+
const loaded = nextLoad(url, context);
|
|
114
|
+
if (!url.replaceAll("\\\\", "/").endsWith("/@earendil-works/pi-coding-agent/dist/core/tools/bash.js"))
|
|
115
|
+
return loaded;
|
|
116
|
+
if (loaded.source == null)
|
|
117
|
+
return loaded;
|
|
118
|
+
const source = typeof loaded.source === "string" ? loaded.source : new TextDecoder().decode(loaded.source);
|
|
119
|
+
const result = patchBashProcessSource(source);
|
|
120
|
+
if (result.status === "unsupported")
|
|
121
|
+
console.warn(`[bash-process] SDK lifecycle patch not applied (unrecognized source): ${url}`);
|
|
122
|
+
return { ...loaded, source: result.code };
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
}
|
|
@@ -22,15 +22,15 @@ export function makePatchTool(options) {
|
|
|
22
22
|
name: PATCH_TOOL_NAME,
|
|
23
23
|
promptSnippet: "apply content-hashed, line-anchored patches to files",
|
|
24
24
|
label: "Apply Hashline patch",
|
|
25
|
-
description: `Apply content-hashed, line-anchored patches to workspace files — prevents stale edits, line drift, and indentation hallucination.
|
|
26
|
-
Each file section starts with \`[path#TAG]\` (or \`[path]\` if the hash is unknown yet). Operations:
|
|
27
|
-
- \`PUT N.=M:\` replace lines N..M (inclusive) with the following \`+TEXT\` lines.
|
|
28
|
-
- \`PUT N*:\` replace the syntactic block starting at line N (closing brace/indent auto-resolved).
|
|
29
|
-
- \`PUT <N:\` / \`PUT >N:\` insert before / after line N (\`<1\` = head, \`>$\` = end).
|
|
30
|
-
- \`CUT N.=M [@name]\` / \`CUT N* [@name]\` delete lines into a register; \`PUT <N @name\` / \`PUT >N @name\` paste it.
|
|
31
|
-
- \`REM\` delete file; \`MV dest/path\` move/rename.
|
|
32
|
-
- Create a file: bare \`[path]\` header (no tag) on a nonexistent path + \`PUT <1:\` / \`PUT >$:\` \`+TEXT\` content.
|
|
33
|
-
- Body rows under \`:\` headers MUST start with \`+\` (\`+\` alone = blank line). Divergence triggers a 3-way merge.
|
|
25
|
+
description: `Apply content-hashed, line-anchored patches to workspace files — prevents stale edits, line drift, and indentation hallucination.
|
|
26
|
+
Each file section starts with \`[path#TAG]\` (or \`[path]\` if the hash is unknown yet). Operations:
|
|
27
|
+
- \`PUT N.=M:\` replace lines N..M (inclusive) with the following \`+TEXT\` lines.
|
|
28
|
+
- \`PUT N*:\` replace the syntactic block starting at line N (closing brace/indent auto-resolved).
|
|
29
|
+
- \`PUT <N:\` / \`PUT >N:\` insert before / after line N (\`<1\` = head, \`>$\` = end).
|
|
30
|
+
- \`CUT N.=M [@name]\` / \`CUT N* [@name]\` delete lines into a register; \`PUT <N @name\` / \`PUT >N @name\` paste it.
|
|
31
|
+
- \`REM\` delete file; \`MV dest/path\` move/rename.
|
|
32
|
+
- Create a file: bare \`[path]\` header (no tag) on a nonexistent path + \`PUT <1:\` / \`PUT >$:\` \`+TEXT\` content.
|
|
33
|
+
- Body rows under \`:\` headers MUST start with \`+\` (\`+\` alone = blank line). Divergence triggers a 3-way merge.
|
|
34
34
|
Success returns the next anchor tag and live LSP diagnostics.`,
|
|
35
35
|
parameters: Type.Object({
|
|
36
36
|
patch: Type.String({
|
|
@@ -20,9 +20,9 @@ import { fileURLToPath } from "node:url";
|
|
|
20
20
|
import { sdkCopies } from "./sdk-origin.js";
|
|
21
21
|
export const TARGET_PATTERN = /if\s*\(!messageEntryId\)\s*\{\s*this\._extensionRunner\.emitError\(\{\s*extensionPath:\s*"<boundary>",\s*event:\s*"turn_end",\s*error:\s*"turn_end could not resolve the persisted assistant entry ID",\s*\}\);\s*return false;\s*\}/;
|
|
22
22
|
export const PATCHED_SENTINEL = "// pi-web-ui patch (issue #411: silent turn_end on aborted turns)";
|
|
23
|
-
export const REPLACEMENT = `if (!messageEntryId) {
|
|
24
|
-
${PATCHED_SENTINEL}
|
|
25
|
-
return false;
|
|
23
|
+
export const REPLACEMENT = `if (!messageEntryId) {
|
|
24
|
+
${PATCHED_SENTINEL}
|
|
25
|
+
return false;
|
|
26
26
|
}`;
|
|
27
27
|
/**
|
|
28
28
|
* 纯函数:给定 agent-session.js 内容,返回打补丁后的内容。
|
|
@@ -52,12 +52,12 @@ export const PI_DOC_PATHS = (() => {
|
|
|
52
52
|
* programs wait for input that never comes. Legacy Chinese files are often
|
|
53
53
|
* GBK/GB2312 — read them with the right encoding, never paste mojibake into
|
|
54
54
|
* reasoning/answers. */
|
|
55
|
-
export const WINDOWS_PERSONA = `You are a coding agent running on Windows. The bash tool runs Git Bash (bash.exe), not PowerShell. Follow these rules to avoid hanging the session:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
- ALWAYS pass a timeout parameter to the bash tool (in seconds). There is NO default timeout — a command that never finishes (servers, watchers, infinite loops, slow downloads/installs) will hang the entire conversation indefinitely. Pick a generous timeout for long-running work, but never omit it.
|
|
60
|
-
- NEVER run interactive or foreground long-running commands through the bash tool (vi, less, top, python -, node -, npm run dev, sleep 10000). For servers/daemons use background execution with output redirected to a log file, then poll the log; stop them when done.
|
|
61
|
-
- In the interactive terminal (TTY) — which is Git Bash too, not PowerShell — NEVER use heredocs (<<'EOF' ... EOF) or here-strings, and NEVER start interactive programs (vi, less, python -, node -, npm init): they wait for keyboard input that never arrives and hang the terminal forever. Prefer writing a temp script file (e.g. .pi-tmp.sh) and running it non-interactively. ALWAYS pass a timeout to long-running commands (e.g. \`timeout 120 npm run dev\`).
|
|
62
|
-
|
|
55
|
+
export const WINDOWS_PERSONA = `You are a coding agent running on Windows. The bash tool runs Git Bash (bash.exe), not PowerShell. Follow these rules to avoid hanging the session:
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
- ALWAYS pass a timeout parameter to the bash tool (in seconds). There is NO default timeout — a command that never finishes (servers, watchers, infinite loops, slow downloads/installs) will hang the entire conversation indefinitely. Pick a generous timeout for long-running work, but never omit it.
|
|
60
|
+
- NEVER run interactive or foreground long-running commands through the bash tool (vi, less, top, python -, node -, npm run dev, sleep 10000). For servers/daemons use background execution with output redirected to a log file, then poll the log; stop them when done.
|
|
61
|
+
- In the interactive terminal (TTY) — which is Git Bash too, not PowerShell — NEVER use heredocs (<<'EOF' ... EOF) or here-strings, and NEVER start interactive programs (vi, less, python -, node -, npm init): they wait for keyboard input that never arrives and hang the terminal forever. Prefer writing a temp script file (e.g. .pi-tmp.sh) and running it non-interactively. ALWAYS pass a timeout to long-running commands (e.g. \`timeout 120 npm run dev\`).
|
|
62
|
+
|
|
63
63
|
Many legacy Chinese text files (.html/.txt/.md/.log, exported documents) are GBK/GB2312 encoded: the read tool decodes UTF-8 only and will show mojibake (乱码) for them. If a file's content looks garbled, read it through the terminal instead: in Git Bash use \`cat file | iconv -f GBK -t UTF-8\` (or \`iconv -f GBK -t UTF-8 file\`); in cmd use \`chcp 65001 && type file\`; in PowerShell use \`Get-Content -Encoding Default file\`. Never paste mojibake into your reasoning or answer — describe the decoded content instead.`;
|
package/dist/server/plugins.js
CHANGED
|
@@ -733,6 +733,28 @@ function parseSettingsSchema(raw) {
|
|
|
733
733
|
const type = (typeof o.type === "string" && o.type ? o.type : optionsFrom ? "select" : "");
|
|
734
734
|
if (!key || !SETTING_TYPES.has(type) || out.some((x) => x.key === key))
|
|
735
735
|
continue;
|
|
736
|
+
let options;
|
|
737
|
+
if (Array.isArray(o.options)) {
|
|
738
|
+
const parsed = [];
|
|
739
|
+
for (const opt of o.options) {
|
|
740
|
+
if (typeof opt === "string") {
|
|
741
|
+
parsed.push(opt);
|
|
742
|
+
}
|
|
743
|
+
else if (opt && typeof opt === "object" && typeof opt.value === "string") {
|
|
744
|
+
const val = opt.value;
|
|
745
|
+
const item = { value: val };
|
|
746
|
+
if (typeof opt.label === "string") {
|
|
747
|
+
item.label = opt.label;
|
|
748
|
+
}
|
|
749
|
+
if (typeof opt.labelEn === "string") {
|
|
750
|
+
item.labelEn = opt.labelEn;
|
|
751
|
+
}
|
|
752
|
+
parsed.push(item);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
if (parsed.length > 0)
|
|
756
|
+
options = parsed;
|
|
757
|
+
}
|
|
736
758
|
const field = {
|
|
737
759
|
key,
|
|
738
760
|
type: type,
|
|
@@ -740,7 +762,7 @@ function parseSettingsSchema(raw) {
|
|
|
740
762
|
...(o.default !== undefined ? { default: o.default } : {}),
|
|
741
763
|
...(typeof o.min === "number" ? { min: o.min } : {}),
|
|
742
764
|
...(typeof o.max === "number" ? { max: o.max } : {}),
|
|
743
|
-
...(
|
|
765
|
+
...(options ? { options } : {}),
|
|
744
766
|
...(type === "select" && optionsFrom ? { optionsFrom } : {}),
|
|
745
767
|
...(typeof o.hint === "string" ? { hint: o.hint } : {}),
|
|
746
768
|
};
|
|
@@ -896,7 +918,9 @@ function cleanNonSecretSettingsField(f, v, lang) {
|
|
|
896
918
|
}
|
|
897
919
|
return { value: v === undefined ? (f.default ?? "") : s };
|
|
898
920
|
}
|
|
899
|
-
|
|
921
|
+
const hasOptions = Array.isArray(f.options);
|
|
922
|
+
const allowedValues = f.options?.map((opt) => (typeof opt === "string" ? opt : opt.value));
|
|
923
|
+
if (v !== undefined && (!hasOptions || !allowedValues?.includes(s)))
|
|
900
924
|
return {
|
|
901
925
|
error: pick(lang, `${f.label} 值非法`, `Invalid value for ${f.label}`, "plugins.settings.invalid.value", {
|
|
902
926
|
"f.label": f.label,
|
|
@@ -47,6 +47,7 @@ export const PRESET_FIELD_GROUPS = {
|
|
|
47
47
|
"toolWatchdogTimeoutMs",
|
|
48
48
|
"questionnaireEnabled",
|
|
49
49
|
"questionPresentation",
|
|
50
|
+
"toolApprovalPresentation",
|
|
50
51
|
"questionTimeoutSeconds",
|
|
51
52
|
"editSoftEnabled",
|
|
52
53
|
"terminalToolsEnabled",
|
|
@@ -280,6 +281,12 @@ export const PRESET_FIELD_META = {
|
|
|
280
281
|
hintZh: "当前对话弹出、全部弹出或仅队列",
|
|
281
282
|
hintEn: "Current conversation, all popups, or manual queue",
|
|
282
283
|
},
|
|
284
|
+
toolApprovalPresentation: {
|
|
285
|
+
labelZh: "工具审批提醒方式",
|
|
286
|
+
labelEn: "Tool approval reminders",
|
|
287
|
+
hintZh: "当前对话弹出、全部弹出或仅队列",
|
|
288
|
+
hintEn: "Current conversation, all popups, or manual queue",
|
|
289
|
+
},
|
|
283
290
|
questionTimeoutSeconds: {
|
|
284
291
|
labelZh: "子代理问卷等待期限",
|
|
285
292
|
labelEn: "Subagent question timeout",
|
|
@@ -248,6 +248,7 @@ const PRESET_FIELD_KINDS = {
|
|
|
248
248
|
toolWatchdogTimeoutMs: "number",
|
|
249
249
|
questionnaireEnabled: "bool",
|
|
250
250
|
questionPresentation: "questionPresentation",
|
|
251
|
+
toolApprovalPresentation: "questionPresentation",
|
|
251
252
|
questionTimeoutSeconds: "questionTimeout",
|
|
252
253
|
editSoftEnabled: "bool",
|
|
253
254
|
terminalToolsEnabled: "bool",
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { writeJsonAtomicSync } from "./atomic-file.js";
|
|
4
|
+
export function parseStoredTemplate(value) {
|
|
5
|
+
if (!value || typeof value !== "object")
|
|
6
|
+
throw new Error("Invalid template");
|
|
7
|
+
const raw = value;
|
|
8
|
+
if (typeof raw.id !== "string" || !raw.id || raw.id.length > 200)
|
|
9
|
+
throw new Error("Invalid template id");
|
|
10
|
+
if (raw.hidden === true)
|
|
11
|
+
return { id: raw.id, hidden: true };
|
|
12
|
+
const result = { id: raw.id };
|
|
13
|
+
for (const key of ["icon", "title", "desc", "prompt", "command"]) {
|
|
14
|
+
if (raw[key] !== undefined) {
|
|
15
|
+
if (typeof raw[key] !== "string" || raw[key].length > (key === "prompt" ? 100_000 : 1000)) {
|
|
16
|
+
throw new Error(`Invalid template ${key}`);
|
|
17
|
+
}
|
|
18
|
+
result[key] = raw[key];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (!result.title?.trim() || !result.prompt?.trim())
|
|
22
|
+
throw new Error("Title and prompt are required");
|
|
23
|
+
if (result.command) {
|
|
24
|
+
result.command = result.command.trim().replace(/^\//, "").toLowerCase();
|
|
25
|
+
if (!/^[a-z][a-z0-9_-]*$/.test(result.command))
|
|
26
|
+
throw new Error("Invalid template command");
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
/** Mutations read the latest file and commit atomically before returning new state. */
|
|
31
|
+
export function registerPromptTemplateRoutes(app, dataDir) {
|
|
32
|
+
const file = join(dataDir, "prompt-templates.json");
|
|
33
|
+
const load = () => {
|
|
34
|
+
try {
|
|
35
|
+
const data = JSON.parse(readFileSync(file, "utf8"));
|
|
36
|
+
if (!Array.isArray(data))
|
|
37
|
+
throw new Error("Invalid template file");
|
|
38
|
+
return data.map(parseStoredTemplate);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (error.code === "ENOENT")
|
|
42
|
+
return [];
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
app.get("/api/prompt-templates", (_req, res) => {
|
|
47
|
+
try {
|
|
48
|
+
res.setHeader("Cache-Control", "no-store");
|
|
49
|
+
res.json({ templates: load() });
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
res.status(500).json({ error: String(error) });
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
app.post("/api/prompt-templates", (req, res) => {
|
|
56
|
+
// Browser writes must be JSON, preventing cross-origin form submissions.
|
|
57
|
+
if (!req.is("application/json") || req.headers["sec-fetch-site"] === "cross-site") {
|
|
58
|
+
res.status(403).json({ error: "Cross-site template write rejected" });
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const body = req.body ?? {};
|
|
63
|
+
let templates = load();
|
|
64
|
+
switch (body.action) {
|
|
65
|
+
case "upsert": {
|
|
66
|
+
const tpl = parseStoredTemplate(body.template);
|
|
67
|
+
if (tpl.command && templates.some((t) => t.id !== tpl.id && t.command === tpl.command)) {
|
|
68
|
+
throw new Error("Template command already exists");
|
|
69
|
+
}
|
|
70
|
+
templates = [...templates.filter((t) => t.id !== tpl.id), tpl];
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
case "remove":
|
|
74
|
+
if (typeof body.id !== "string")
|
|
75
|
+
throw new Error("Invalid template id");
|
|
76
|
+
templates = templates.filter((t) => t.id !== body.id);
|
|
77
|
+
break;
|
|
78
|
+
case "reset":
|
|
79
|
+
templates = [];
|
|
80
|
+
break;
|
|
81
|
+
case "migrate": {
|
|
82
|
+
if (!Array.isArray(body.templates))
|
|
83
|
+
throw new Error("Invalid migration");
|
|
84
|
+
for (const value of body.templates) {
|
|
85
|
+
const tpl = parseStoredTemplate(value);
|
|
86
|
+
if (templates.some((t) => t.id === tpl.id))
|
|
87
|
+
continue;
|
|
88
|
+
if (tpl.command && templates.some((t) => t.command === tpl.command))
|
|
89
|
+
tpl.command = "";
|
|
90
|
+
templates.push(tpl);
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
default:
|
|
95
|
+
throw new Error("Unknown template action");
|
|
96
|
+
}
|
|
97
|
+
if (templates.length > 500)
|
|
98
|
+
throw new Error("Too many templates");
|
|
99
|
+
writeJsonAtomicSync(file, templates);
|
|
100
|
+
res.json({ templates });
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
res.status(400).json({ error: String(error) });
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
@@ -777,27 +777,27 @@ export class RemoteSshService {
|
|
|
777
777
|
const pName = params.profileName?.trim() || `${hydrated.username}@${hydrated.host}`;
|
|
778
778
|
await this.saveProfile(pName, hydrated);
|
|
779
779
|
}
|
|
780
|
-
const probeScript = `
|
|
781
|
-
echo "===SYSTEM==="
|
|
782
|
-
uname -s
|
|
783
|
-
uname -m
|
|
784
|
-
uname -n
|
|
785
|
-
echo "$USER"
|
|
786
|
-
echo "$HOME"
|
|
787
|
-
(nproc 2>/dev/null || grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo "1")
|
|
788
|
-
(awk '/MemTotal/ {print int($2/1024)}' /proc/meminfo 2>/dev/null || free -m 2>/dev/null | awk '/Mem:/ {print $2}' || sysctl -n hw.memsize 2>/dev/null | awk '{print int($1/1024/1024)}' || echo "0")
|
|
789
|
-
echo "===GIT==="
|
|
790
|
-
which git 2>/dev/null && git --version 2>/dev/null || echo "NONE"
|
|
791
|
-
echo "===NODE==="
|
|
792
|
-
which node 2>/dev/null && node -v 2>/dev/null || echo "NONE"
|
|
793
|
-
echo "===BASH==="
|
|
794
|
-
which bash 2>/dev/null || echo "NONE"
|
|
795
|
-
echo "===PYTHON==="
|
|
796
|
-
(which python3 2>/dev/null && python3 --version 2>/dev/null) || (which python 2>/dev/null && python --version 2>/dev/null) || echo "NONE"
|
|
797
|
-
echo "===PKG==="
|
|
798
|
-
for p in apt-get dnf yum apk pacman brew; do
|
|
799
|
-
if command -v $p >/dev/null 2>&1; then echo "$p"; break; fi
|
|
800
|
-
done
|
|
780
|
+
const probeScript = `
|
|
781
|
+
echo "===SYSTEM==="
|
|
782
|
+
uname -s
|
|
783
|
+
uname -m
|
|
784
|
+
uname -n
|
|
785
|
+
echo "$USER"
|
|
786
|
+
echo "$HOME"
|
|
787
|
+
(nproc 2>/dev/null || grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo "1")
|
|
788
|
+
(awk '/MemTotal/ {print int($2/1024)}' /proc/meminfo 2>/dev/null || free -m 2>/dev/null | awk '/Mem:/ {print $2}' || sysctl -n hw.memsize 2>/dev/null | awk '{print int($1/1024/1024)}' || echo "0")
|
|
789
|
+
echo "===GIT==="
|
|
790
|
+
which git 2>/dev/null && git --version 2>/dev/null || echo "NONE"
|
|
791
|
+
echo "===NODE==="
|
|
792
|
+
which node 2>/dev/null && node -v 2>/dev/null || echo "NONE"
|
|
793
|
+
echo "===BASH==="
|
|
794
|
+
which bash 2>/dev/null || echo "NONE"
|
|
795
|
+
echo "===PYTHON==="
|
|
796
|
+
(which python3 2>/dev/null && python3 --version 2>/dev/null) || (which python 2>/dev/null && python --version 2>/dev/null) || echo "NONE"
|
|
797
|
+
echo "===PKG==="
|
|
798
|
+
for p in apt-get dnf yum apk pacman brew; do
|
|
799
|
+
if command -v $p >/dev/null 2>&1; then echo "$p"; break; fi
|
|
800
|
+
done
|
|
801
801
|
`;
|
|
802
802
|
try {
|
|
803
803
|
const output = await this.execCommand(client, probeScript);
|
|
@@ -1093,24 +1093,24 @@ done
|
|
|
1093
1093
|
}
|
|
1094
1094
|
const conn = this.getConnection(connectionId);
|
|
1095
1095
|
const tool = shellQuotePosix(requested);
|
|
1096
|
-
const installScript = `
|
|
1097
|
-
if command -v apt-get >/dev/null 2>&1; then
|
|
1098
|
-
export DEBIAN_FRONTEND=noninteractive
|
|
1099
|
-
( [ "$(id -u)" -eq 0 ] && apt-get update -y && apt-get install -y ${tool} ) || ( sudo -n apt-get update -y && sudo -n apt-get install -y ${tool} )
|
|
1100
|
-
elif command -v dnf >/dev/null 2>&1; then
|
|
1101
|
-
( [ "$(id -u)" -eq 0 ] && dnf install -y ${tool} ) || sudo -n dnf install -y ${tool}
|
|
1102
|
-
elif command -v yum >/dev/null 2>&1; then
|
|
1103
|
-
( [ "$(id -u)" -eq 0 ] && yum install -y ${tool} ) || sudo -n yum install -y ${tool}
|
|
1104
|
-
elif command -v apk >/dev/null 2>&1; then
|
|
1105
|
-
( [ "$(id -u)" -eq 0 ] && apk add ${tool} ) || sudo -n apk add ${tool}
|
|
1106
|
-
elif command -v pacman >/dev/null 2>&1; then
|
|
1107
|
-
( [ "$(id -u)" -eq 0 ] && pacman -S --noconfirm ${tool} ) || sudo -n pacman -S --noconfirm ${tool}
|
|
1108
|
-
elif command -v brew >/dev/null 2>&1; then
|
|
1109
|
-
brew install ${tool}
|
|
1110
|
-
else
|
|
1111
|
-
echo "未检测到支持的包管理器 (apt/dnf/yum/apk/pacman/brew),请手动安装 ${tool}"
|
|
1112
|
-
exit 1
|
|
1113
|
-
fi
|
|
1096
|
+
const installScript = `
|
|
1097
|
+
if command -v apt-get >/dev/null 2>&1; then
|
|
1098
|
+
export DEBIAN_FRONTEND=noninteractive
|
|
1099
|
+
( [ "$(id -u)" -eq 0 ] && apt-get update -y && apt-get install -y ${tool} ) || ( sudo -n apt-get update -y && sudo -n apt-get install -y ${tool} )
|
|
1100
|
+
elif command -v dnf >/dev/null 2>&1; then
|
|
1101
|
+
( [ "$(id -u)" -eq 0 ] && dnf install -y ${tool} ) || sudo -n dnf install -y ${tool}
|
|
1102
|
+
elif command -v yum >/dev/null 2>&1; then
|
|
1103
|
+
( [ "$(id -u)" -eq 0 ] && yum install -y ${tool} ) || sudo -n yum install -y ${tool}
|
|
1104
|
+
elif command -v apk >/dev/null 2>&1; then
|
|
1105
|
+
( [ "$(id -u)" -eq 0 ] && apk add ${tool} ) || sudo -n apk add ${tool}
|
|
1106
|
+
elif command -v pacman >/dev/null 2>&1; then
|
|
1107
|
+
( [ "$(id -u)" -eq 0 ] && pacman -S --noconfirm ${tool} ) || sudo -n pacman -S --noconfirm ${tool}
|
|
1108
|
+
elif command -v brew >/dev/null 2>&1; then
|
|
1109
|
+
brew install ${tool}
|
|
1110
|
+
else
|
|
1111
|
+
echo "未检测到支持的包管理器 (apt/dnf/yum/apk/pacman/brew),请手动安装 ${tool}"
|
|
1112
|
+
exit 1
|
|
1113
|
+
fi
|
|
1114
1114
|
`;
|
|
1115
1115
|
try {
|
|
1116
1116
|
const output = await this.execCommand(conn.client, installScript);
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
* 让服务起不来。它必须在任何 SDK 静态 import **之前**被加载(`--import <本文件>`,
|
|
26
26
|
* 或前台启动时在 import 服务入口之前先 import 它)。
|
|
27
27
|
*/
|
|
28
|
+
import { registerBashProcessPatch } from "./patch-bash-process.js";
|
|
28
29
|
import { existsSync, readFileSync } from "node:fs";
|
|
29
30
|
import { registerHooks } from "node:module";
|
|
30
31
|
import { dirname, join } from "node:path";
|
|
@@ -149,6 +150,7 @@ export function registerGlobalSdkPreference(mode = process.env.PI_WEB_SDK, fromF
|
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
152
|
// ---- 副作用:被 `--import` 加载时立刻生效 --------------------------------
|
|
153
|
+
registerBashProcessPatch();
|
|
152
154
|
const used = registerGlobalSdkPreference();
|
|
153
155
|
if (used) {
|
|
154
156
|
console.log(`[pi-web-ui] following a newer pi SDK on this machine: ${used.path} (v${used.version}; ` +
|
|
@@ -85,13 +85,17 @@ function taskLine(t, lang) {
|
|
|
85
85
|
? "启用"
|
|
86
86
|
: "on";
|
|
87
87
|
const once = t.oneShot ? (lang === "zh" ? " · 单次" : " · one-shot") : "";
|
|
88
|
-
const target = t.
|
|
88
|
+
const target = t.target === "canvas"
|
|
89
89
|
? lang === "zh"
|
|
90
|
-
? ` ·
|
|
91
|
-
: ` ·
|
|
92
|
-
:
|
|
93
|
-
?
|
|
94
|
-
|
|
90
|
+
? ` · 画布→${t.graphId}`
|
|
91
|
+
: ` · canvas→${t.graphId}`
|
|
92
|
+
: t.conversationId
|
|
93
|
+
? lang === "zh"
|
|
94
|
+
? ` · 汇报→对话${t.conversationId}`
|
|
95
|
+
: ` · reports→${t.conversationId}`
|
|
96
|
+
: lang === "zh"
|
|
97
|
+
? " · 无头执行"
|
|
98
|
+
: " · headless";
|
|
95
99
|
const last = t.lastRun
|
|
96
100
|
? lang === "zh"
|
|
97
101
|
? ` · 上次${t.lastRun.ok ? "成功" : `失败(${t.lastRun.error ?? "未知错误"})`}`
|
|
@@ -109,11 +113,12 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
|
|
|
109
113
|
const noStore = () => text(pick(getLang(), "当前引擎不支持定时任务(调度存储未接入)。", "Scheduled tasks are not wired for the current engine.", "sched.not.wired"));
|
|
110
114
|
return defineTool({
|
|
111
115
|
name: SCHEDULE_TOOL_NAME,
|
|
112
|
-
label: "Manage scheduled
|
|
113
|
-
description: "Create, list, or cancel
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
|
|
116
|
+
label: "Manage scheduled tasks",
|
|
117
|
+
description: "Create, list, or cancel persistent scheduled tasks. Without graphId, delivers a required prompt to the current conversation; " +
|
|
118
|
+
"if unavailable, falls back to the project's active conversation or a headless run. With graphId, runs that existing canvas; " +
|
|
119
|
+
"prompt is optional and otherwise uses the graph's input. Canvas tasks do not bind a conversation or override node models. " +
|
|
120
|
+
"One-shot by default; recurring=true repeats. Minimum delay 60s.",
|
|
121
|
+
promptSnippet: "Create, list, or cancel conversation or canvas schedules",
|
|
117
122
|
promptGuidelines: [
|
|
118
123
|
"Use action=create for periodic checks, delayed reminders, and scheduled summaries — never sleep loops (they cannot push messages back)",
|
|
119
124
|
"Use action=list to inspect existing tasks and action=cancel to stop one by id",
|
|
@@ -127,8 +132,11 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
|
|
|
127
132
|
schedule: Type.Optional(Type.String({
|
|
128
133
|
description: 'create: when to fire — 5-field cron ("0 * * * *" hourly) or relative delay ("in 30m", "in 1h", "30m"). Minimum 60s.',
|
|
129
134
|
})),
|
|
135
|
+
graphId: Type.Optional(Type.String({
|
|
136
|
+
description: "create: existing canvas graph id; when provided, targets the canvas instead of a conversation.",
|
|
137
|
+
})),
|
|
130
138
|
prompt: Type.Optional(Type.String({
|
|
131
|
-
description: "create: instruction
|
|
139
|
+
description: "create: instruction for the conversation or canvas. Required for conversations; omit for canvas to use graph input. Max 8000 chars.",
|
|
132
140
|
})),
|
|
133
141
|
label: Type.Optional(Type.String({
|
|
134
142
|
description: "create: short name shown in the background-tasks panel. Defaults to the prompt head.",
|
|
@@ -159,8 +167,10 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
|
|
|
159
167
|
if (parsed.kind === "interval" && Number(parsed.spec) < SCHEDULER_MIN_INTERVAL_MS) {
|
|
160
168
|
return text(pick(getLang(), `间隔太短(最短 60s,防 token 烧穿)。`, `Interval too short (minimum 60s, prevents token burn).`, "sched.task.interval.too.short"));
|
|
161
169
|
}
|
|
170
|
+
const isCanvas = p.graphId !== undefined;
|
|
171
|
+
const graphId = String(p.graphId ?? "").trim();
|
|
162
172
|
const prompt = String(p.prompt ?? "").trim();
|
|
163
|
-
if (!prompt) {
|
|
173
|
+
if (!prompt && !isCanvas) {
|
|
164
174
|
return text(pick(getLang(), "触发指令(prompt)不能为空:写清楚触发时要检查什么、汇报什么。", "Prompt must not be empty: say what to check and report on fire.", "sched.task.empty.prompt"));
|
|
165
175
|
}
|
|
166
176
|
const cwd = String(host.cwd() ?? "").trim();
|
|
@@ -168,14 +178,16 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
|
|
|
168
178
|
return text(pick(getLang(), "当前没有工作目录,无法创建定时任务。", "No working directory, cannot create the scheduled task.", "sched.task.no.cwd"));
|
|
169
179
|
}
|
|
170
180
|
const labelRaw = typeof p.label === "string" ? p.label.trim().slice(0, 80) : "";
|
|
171
|
-
const name = labelRaw || prompt.split("\n")[0].slice(0, 40) || "定时任务";
|
|
181
|
+
const name = labelRaw || prompt.split("\n")[0].slice(0, 40) || (isCanvas ? `Canvas ${graphId}` : "定时任务");
|
|
172
182
|
const convId = (ownerConversationId ?? "").trim() || String(host.activeConversationId() ?? "").trim();
|
|
173
183
|
// 稳定绑定(issue #231):owner 对话的落盘会话文件 —— 压缩/重启后靠它重认同一会话,
|
|
174
184
|
// 内存对话 id(c1/c2…)只做首选唤醒键。宿主没实现 conversationInfo 时按原来只绑 id。
|
|
175
185
|
let bindCwd = cwd;
|
|
176
186
|
let bindSessionFile = "";
|
|
177
187
|
try {
|
|
178
|
-
const info =
|
|
188
|
+
const info = isCanvas
|
|
189
|
+
? undefined
|
|
190
|
+
: host.conversationInfo?.((ownerConversationId ?? "").trim() || convId || undefined);
|
|
179
191
|
if (info) {
|
|
180
192
|
if (String(info.cwd ?? "").trim())
|
|
181
193
|
bindCwd = String(info.cwd).trim();
|
|
@@ -192,6 +204,8 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
|
|
|
192
204
|
try {
|
|
193
205
|
task = store.upsert({
|
|
194
206
|
name,
|
|
207
|
+
target: isCanvas ? "canvas" : "conversation",
|
|
208
|
+
...(isCanvas ? { graphId } : {}),
|
|
195
209
|
cwd: bindCwd,
|
|
196
210
|
kind: parsed.kind,
|
|
197
211
|
spec: parsed.spec,
|
|
@@ -216,13 +230,17 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
|
|
|
216
230
|
const whenLine = L === "zh"
|
|
217
231
|
? `触发:${parsed.kind === "cron" ? `cron ${parsed.spec}` : describeIntervalMs(Number(parsed.spec))},下次 ${fmtTime(next, L)}${recurring ? "(周期)" : "(单次,触发后自动删除)"}`
|
|
218
232
|
: `Fires: ${parsed.kind === "cron" ? `cron ${parsed.spec}` : `every ${Math.round(Number(parsed.spec) / 1000)}s`}, next ${fmtTime(next, L)}${recurring ? " (recurring)" : " (one-shot, auto-deleted after firing)"}`;
|
|
219
|
-
const targetLine =
|
|
233
|
+
const targetLine = isCanvas
|
|
220
234
|
? L === "zh"
|
|
221
|
-
?
|
|
222
|
-
: `
|
|
223
|
-
:
|
|
224
|
-
?
|
|
225
|
-
|
|
235
|
+
? `目标:画布 ${graphId};${prompt ? "使用提供的触发指令" : "使用图自带输入"},模型由画布节点配置。`
|
|
236
|
+
: `Target: canvas ${graphId}; ${prompt ? "uses the supplied instruction" : "uses the graph's input"}, with models configured by canvas nodes.`
|
|
237
|
+
: convId
|
|
238
|
+
? L === "zh"
|
|
239
|
+
? `汇报:触发时自动唤醒本对话(${convId});压缩/重启后按会话文件自动重绑,原对话不在时先回落同项目活跃对话(明确提示),无存活对话才无头执行。`
|
|
240
|
+
: `Reports: wakes this conversation (${convId}) on fire; re-binds by session file after compaction/restart, falls back to the project's active conversation (with a visible note), headless only with no live conversation.`
|
|
241
|
+
: L === "zh"
|
|
242
|
+
? "汇报:无头执行,报告进调度面板历史(创建时没拿到对话 id)。"
|
|
243
|
+
: "Reports: headless run, report in panel history (no conversation id captured at creation).";
|
|
226
244
|
const tail = L === "zh"
|
|
227
245
|
? `取消:schedule(action="cancel", id="${task.id}"),或后台任务面板手动取消;查看:schedule(action="list")。`
|
|
228
246
|
: `Cancel: schedule(action="cancel", id="${task.id}"), or from the background-tasks panel; inspect: schedule(action="list").`;
|