pi-web-ui 0.114.1 → 0.114.3

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.
Files changed (130) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +187 -187
  3. package/README.zh-CN.md +227 -227
  4. package/README.zh-TW.md +227 -227
  5. package/bin/device-hub-cli.mjs +577 -577
  6. package/bin/frp-manager.mjs +1573 -1573
  7. package/bin/pi-device-hub.mjs +9 -9
  8. package/bin/pi-web-ui.mjs +4081 -4081
  9. package/deploy/nginx-subpath.conf +100 -100
  10. package/deploy/pi-web-ui.service +36 -36
  11. package/dist/server/agent-service.js +88 -15
  12. package/dist/server/attachments.js +6 -6
  13. package/dist/server/canvas/canvas-orchestrator.js +3 -3
  14. package/dist/server/communicate-tool.js +37 -11
  15. package/dist/server/compaction-instructions.js +8 -8
  16. package/dist/server/context-usage.js +105 -0
  17. package/dist/server/device-center/desktop-page.js +228 -228
  18. package/dist/server/device-center/hub-page.js +64 -64
  19. package/dist/server/device-center/native-desktop/macos.js +190 -190
  20. package/dist/server/device-center/native-desktop/windows.js +116 -116
  21. package/dist/server/dsh/runtime/cordis.yml +1 -1
  22. package/dist/server/dsh/runtime/custom-prompt.mjs +33 -33
  23. package/dist/server/dsh/runtime/goal-rpc.mjs +1309 -1309
  24. package/dist/server/dsh/runtime/launcher.mjs +235 -235
  25. package/dist/server/dsh/runtime/override.patch.yml +89 -89
  26. package/dist/server/dsh/runtime/runtime-root.mjs +405 -405
  27. package/dist/server/durable/durable-event-projector.js +19 -3
  28. package/dist/server/durable/durable-models.js +134 -65
  29. package/dist/server/eval-tool.js +135 -135
  30. package/dist/server/model-resolver.js +4 -1
  31. package/dist/server/patch-bash-process.js +89 -89
  32. package/dist/server/patch-tool.js +9 -9
  33. package/dist/server/patch-turn-end-boundary.js +3 -3
  34. package/dist/server/persona-chain.js +8 -8
  35. package/dist/server/protocol-version.js +1 -1
  36. package/dist/server/remote-ssh-service.js +39 -39
  37. package/dist/server/schedule-agent-tool.js +11 -6
  38. package/dist/server/scheduler-tasks.js +84 -2
  39. package/dist/server/scm-commitmsg.js +10 -10
  40. package/dist/server/setup-page.js +620 -620
  41. package/dist/server/universal/universal-session.js +19 -18
  42. package/dist/server/vision-bridge.js +18 -18
  43. package/docs/device-center.md +148 -148
  44. package/docs/device-desktop.md +48 -48
  45. package/docs/dsh-engine.md +493 -493
  46. package/extensions/webui.ts +335 -335
  47. package/package.json +1 -1
  48. package/plugin-sdk/README.md +174 -174
  49. package/plugin-sdk/client-utils.mjs +279 -279
  50. package/plugin-sdk/import-check.mjs +210 -210
  51. package/plugin-sdk/index.d.ts +698 -698
  52. package/plugin-sdk/index.mjs +696 -696
  53. package/plugin-sdk/package.json +13 -13
  54. package/plugin-sdk/ssh-host-trust.mjs +225 -225
  55. package/themes/aetheris.css +501 -501
  56. package/themes/ayu-light.css +116 -116
  57. package/themes/bases/flow-base.css +1357 -1357
  58. package/themes/bases/obsidian-base.css +895 -895
  59. package/themes/bases/statusbar-flat-base.css +112 -112
  60. package/themes/bases/zhujian-base.css +688 -688
  61. package/themes/bases/zhupi-base.css +660 -660
  62. package/themes/catppuccin-latte.css +119 -119
  63. package/themes/catppuccin.css +116 -116
  64. package/themes/claude-code-dark.css +147 -147
  65. package/themes/codex.css +114 -114
  66. package/themes/cyberpunk.css +50 -50
  67. package/themes/dark-teal.css +264 -264
  68. package/themes/dazzle.css +38 -38
  69. package/themes/everforest-light.css +115 -115
  70. package/themes/flow-light.css +164 -164
  71. package/themes/flow.css +161 -161
  72. package/themes/geist.css +114 -114
  73. package/themes/gruvbox-light.css +115 -115
  74. package/themes/kanagawa-lotus.css +115 -115
  75. package/themes/md-preview.css +24 -24
  76. package/themes/mist.css +166 -166
  77. package/themes/nord.css +107 -107
  78. package/themes/one-dark.css +106 -106
  79. package/themes/paper.css +174 -174
  80. package/themes/rose-pine-dawn.css +114 -114
  81. package/themes/sakura.css +166 -166
  82. package/themes/solarized-light.css +114 -114
  83. package/themes/tokyo-night.css +115 -115
  84. package/themes/translucent.css +85 -85
  85. package/themes/transparent.css +116 -116
  86. package/themes/vs-code-dark.css +147 -147
  87. package/themes/wallpaper-flow.css +382 -382
  88. package/themes/wallpaper-obsidian.css +74 -74
  89. package/themes/white.css +164 -164
  90. package/themes/zhujian-dark.css +115 -115
  91. package/themes/zhujian.css +114 -114
  92. package/themes/zhupi-dark.css +115 -115
  93. package/themes/zhupi.css +114 -114
  94. package/web/dist/.build-assets.json +1 -1
  95. package/web/dist/assets/{BgTasksModal-BcXJ20RO.js → BgTasksModal-BvnUHjFe.js} +1 -1
  96. package/web/dist/assets/{BgTasksModal-DjQmiKnE.js → BgTasksModal-DSC8ncW3.js} +1 -1
  97. package/web/dist/assets/{CanvasStudio-PI9pid0Y.js → CanvasStudio-BSg9ghPV.js} +2 -2
  98. package/web/dist/assets/{CanvasStudio-nf5-HxLM.js → CanvasStudio-DxW7C3Sz.js} +2 -2
  99. package/web/dist/assets/{DeviceCenter-CYttJw2a.js → DeviceCenter-Bmgr-Bwm.js} +1 -1
  100. package/web/dist/assets/{DeviceCenter-DPe4sz74.js → DeviceCenter-Cl9MBXaH.js} +1 -1
  101. package/web/dist/assets/{DeviceGroups-D2rogxEN.js → DeviceGroups-aeLD2msl.js} +1 -1
  102. package/web/dist/assets/{Dropdown-ZLS04O8p.js → Dropdown-D1Jl35dw.js} +1 -1
  103. package/web/dist/assets/{FilePreview-C9Ut4Lq6.js → FilePreview-6CqoDF_P.js} +1 -1
  104. package/web/dist/assets/{FilePreview-CvK3ZzX5.js → FilePreview-CJa27G_Q.js} +1 -1
  105. package/web/dist/assets/{GlobalSearchModal-C5e-OCw2.js → GlobalSearchModal-CJX35rZL.js} +1 -1
  106. package/web/dist/assets/{GlobalSearchModal-H7pFK2UC.js → GlobalSearchModal-CMW0xz0P.js} +1 -1
  107. package/web/dist/assets/{GroupConversation-C2wNM0dQ.js → GroupConversation-Cq4daBFb.js} +1 -1
  108. package/web/dist/assets/{GroupConversation-ChN3TWQK.js → GroupConversation-DoELa83U.js} +1 -1
  109. package/web/dist/assets/{ModelConfigModal-DDZccDYt.js → ModelConfigModal-Bp7tfKYh.js} +1 -1
  110. package/web/dist/assets/{PiSetupModal-DHbqfx8T.js → PiSetupModal-DD8srwBJ.js} +1 -1
  111. package/web/dist/assets/{ProviderOAuthControls-C-MK36Dk.js → ProviderOAuthControls-C6tfXb88.js} +1 -1
  112. package/web/dist/assets/{SCMPanel-kx-SCL2s.js → SCMPanel-CghgsyBN.js} +1 -1
  113. package/web/dist/assets/{SCMPanel-buTGziDB.js → SCMPanel-D8-8aqwC.js} +1 -1
  114. package/web/dist/assets/{SettingsModal-BsUF8jqr.js → SettingsModal-BbBe2rYo.js} +1 -1
  115. package/web/dist/assets/{SettingsModal-D357Ky7P.js → SettingsModal-qETiVPKj.js} +1 -1
  116. package/web/dist/assets/{TerminalPanel-BBuM_Sez.js → TerminalPanel-Da-Xs4Wk.js} +1 -1
  117. package/web/dist/assets/{TerminalPanel-D6x6xz8Q.js → TerminalPanel-DnS4tFQO.js} +1 -1
  118. package/web/dist/assets/{TuiOverlayModal-CdbGV3Za.js → TuiOverlayModal-CGyGkKYl.js} +1 -1
  119. package/web/dist/assets/{TuiOverlayModal-d6x9u25n.js → TuiOverlayModal-CpBKjG6x.js} +1 -1
  120. package/web/dist/assets/{desktop-YguLbrX1.js → desktop-7EvUHhKQ.js} +1 -1
  121. package/web/dist/assets/{fi-DaSO0Q-m.js → fi-NyN-ZrgD.js} +2 -2
  122. package/web/dist/assets/{index-D6u8xH0o.js → index-DK3F5ZJo.js} +50 -50
  123. package/web/dist/assets/{index-BPvpea8t.js → index-DQMii2he.js} +50 -50
  124. package/web/dist/assets/index-vwBnwzkr.css +1 -0
  125. package/web/dist/assets/{plugin-host-BRBg6zmQ.js → plugin-host-BCnX3P8U.js} +1 -1
  126. package/web/dist/assets/{theme-DDl-Oy1b.js → theme-D2DMH6tH.js} +1 -1
  127. package/web/dist/index.html +35 -35
  128. package/web/dist/sw.js +179 -179
  129. package/web/public/sw.js +179 -179
  130. package/web/dist/assets/index-DDZMv6LO.css +0 -1
@@ -3,97 +3,97 @@ import { registerHooks } from "node:module";
3
3
  export const SENTINEL = "// pi-web-ui #794: bounded shell lifecycle v1";
4
4
  // Kept as JavaScript source because this compatibility patch runs inside the SDK.
5
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
- });
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
86
  }`;
87
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);
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
97
  }`;
98
98
  export function patchBashProcessSource(source) {
99
99
  if (source.includes(SENTINEL))
@@ -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.`;
@@ -8,4 +8,4 @@
8
8
  * its own copy in web/src/protocol-version.ts; scripts/check-protocol-sync.mjs
9
9
  * verifies the two never drift.
10
10
  */
11
- export const PROTOCOL_VERSION = 39;
11
+ export const PROTOCOL_VERSION = 40;
@@ -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);
@@ -146,7 +146,9 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
146
146
  })),
147
147
  id: Type.Optional(Type.String({ description: "cancel: task id from action=list." })),
148
148
  }),
149
- execute: async (_id, p) => {
149
+ execute: async (_id, p, signal) => {
150
+ signal?.throwIfAborted();
151
+ const source = host.executionSource?.();
150
152
  const action = (p.action ?? "").trim().toLowerCase();
151
153
  if (!action) {
152
154
  return text(pick(getLang(), "schedule 工具缺少 action 参数(可选:create, list, cancel)。", "schedule tool requires an action parameter (one of: create, list, cancel).", "sched.action.missing"));
@@ -173,19 +175,20 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
173
175
  if (!prompt && !isCanvas) {
174
176
  return text(pick(getLang(), "触发指令(prompt)不能为空:写清楚触发时要检查什么、汇报什么。", "Prompt must not be empty: say what to check and report on fire.", "sched.task.empty.prompt"));
175
177
  }
176
- const cwd = String(host.cwd() ?? "").trim();
178
+ const cwd = String(source?.cwd ?? host.cwd() ?? "").trim();
177
179
  if (!cwd) {
178
180
  return text(pick(getLang(), "当前没有工作目录,无法创建定时任务。", "No working directory, cannot create the scheduled task.", "sched.task.no.cwd"));
179
181
  }
180
182
  const labelRaw = typeof p.label === "string" ? p.label.trim().slice(0, 80) : "";
181
183
  const name = labelRaw || prompt.split("\n")[0].slice(0, 40) || (isCanvas ? `Canvas ${graphId}` : "定时任务");
182
- const convId = (ownerConversationId ?? "").trim() || String(host.activeConversationId() ?? "").trim();
184
+ const convId = source?.conversationId ??
185
+ ((ownerConversationId ?? "").trim() || String(host.activeConversationId() ?? "").trim());
183
186
  // 稳定绑定(issue #231):owner 对话的落盘会话文件 —— 压缩/重启后靠它重认同一会话,
184
187
  // 内存对话 id(c1/c2…)只做首选唤醒键。宿主没实现 conversationInfo 时按原来只绑 id。
185
188
  let bindCwd = cwd;
186
- let bindSessionFile = "";
189
+ let bindSessionFile = source?.sessionFile ?? "";
187
190
  try {
188
- const info = isCanvas
191
+ const info = isCanvas || source
189
192
  ? undefined
190
193
  : host.conversationInfo?.((ownerConversationId ?? "").trim() || convId || undefined);
191
194
  if (info) {
@@ -202,6 +205,7 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
202
205
  const recurring = p.recurring === true;
203
206
  let task;
204
207
  try {
208
+ signal?.throwIfAborted();
205
209
  task = store.upsert({
206
210
  name,
207
211
  target: isCanvas ? "canvas" : "conversation",
@@ -213,9 +217,10 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
213
217
  conversationId: convId,
214
218
  sessionFile: bindSessionFile,
215
219
  oneShot: !recurring,
216
- });
220
+ }, source?.sessionFile ? { sessionFile: source.sessionFile, toolCallId: _id } : undefined);
217
221
  }
218
222
  catch (err) {
223
+ signal?.throwIfAborted();
219
224
  const L = getLang();
220
225
  if (err instanceof SchedulerValidationError) {
221
226
  return text(L === "zh" ? err.messageZh : err.messageEn);
@@ -170,6 +170,17 @@ export function describeIntervalMs(ms) {
170
170
  const d = Math.floor(s / 86400);
171
171
  return `每 ${d} 天`;
172
172
  }
173
+ function validOrigin(value) {
174
+ if (!value || typeof value !== "object")
175
+ return false;
176
+ const origin = value;
177
+ return (typeof origin.sessionFile === "string" &&
178
+ origin.sessionFile.length > 0 &&
179
+ origin.sessionFile.length <= 4096 &&
180
+ typeof origin.toolCallId === "string" &&
181
+ origin.toolCallId.length > 0 &&
182
+ origin.toolCallId.length <= 1024);
183
+ }
173
184
  function sanitizeHistory(v) {
174
185
  if (!Array.isArray(v))
175
186
  return [];
@@ -291,7 +302,12 @@ export class SchedulerStore {
291
302
  task.createdAt = typeof r.createdAt === "number" && Number.isFinite(r.createdAt) ? r.createdAt : Date.now();
292
303
  task.updatedAt =
293
304
  typeof r.updatedAt === "number" && Number.isFinite(r.updatedAt) ? r.updatedAt : task.createdAt;
294
- next.set(id, { ...task, history: sanitizeHistory(r.history) });
305
+ next.set(id, {
306
+ ...task,
307
+ ...(validOrigin(r.origin) ? { origin: { ...r.origin } } : {}),
308
+ ...(typeof r.startedAt === "number" && Number.isFinite(r.startedAt) ? { startedAt: r.startedAt } : {}),
309
+ history: sanitizeHistory(r.history),
310
+ });
295
311
  }
296
312
  catch {
297
313
  // 单条坏记录跳过,不影响其他任务
@@ -349,6 +365,8 @@ export class SchedulerStore {
349
365
  conversationId: t.conversationId,
350
366
  sessionFile: t.sessionFile ?? "",
351
367
  oneShot: t.oneShot,
368
+ ...(t.origin ? { origin: { ...t.origin } } : {}),
369
+ ...(t.startedAt !== undefined ? { startedAt: t.startedAt } : {}),
352
370
  createdAt: t.createdAt,
353
371
  updatedAt: t.updatedAt,
354
372
  nextFire: !t.enabled ? null : (this.nextFire.get(t.id) ?? computeNextFire(t, Math.max(now, t.updatedAt))),
@@ -363,7 +381,9 @@ export class SchedulerStore {
363
381
  * issue #231:面板编辑不带绑定字段(conversationId/sessionFile 缺席)时保留旧绑定 ——
364
382
  * 否则用户在面板改个名字就会把 AI 任务的会话绑定洗掉,下次触发直接变无头。
365
383
  * 字段显式出现(含空串)仍按全量语义覆盖。 */
366
- upsert(input) {
384
+ upsert(input, origin) {
385
+ if (origin !== undefined && !validOrigin(origin))
386
+ throw new Error("Invalid scheduled-task creation origin");
367
387
  const prev = this.tasks.get(String(input.id ?? "").trim());
368
388
  const task = normalizeSchedulerInput({
369
389
  ...input,
@@ -371,7 +391,11 @@ export class SchedulerStore {
371
391
  ? { target: prev.target, graphId: prev.graphId }
372
392
  : {}),
373
393
  });
394
+ if (origin)
395
+ task.origin = { ...origin };
374
396
  if (prev) {
397
+ task.origin = prev.origin;
398
+ task.startedAt = prev.startedAt;
375
399
  task.createdAt = prev.createdAt;
376
400
  task.updatedAt = Date.now();
377
401
  if (task.target !== "canvas" &&
@@ -390,6 +414,54 @@ export class SchedulerStore {
390
414
  this.changed();
391
415
  return task;
392
416
  }
417
+ /** Commit cancellation before the caller discards transcript evidence. No awaits can race fire(). */
418
+ cancelUnstartedFromCalls(sessionFile, toolCallIds, commit) {
419
+ const next = new Map(this.tasks);
420
+ const removed = [];
421
+ for (const [id, task] of next) {
422
+ if (!task.origin ||
423
+ !(process.platform === "win32"
424
+ ? sameSessionFile(task.origin.sessionFile, sessionFile)
425
+ : task.origin.sessionFile === sessionFile) ||
426
+ !toolCallIds.has(task.origin.toolCallId) ||
427
+ this.running.has(id) ||
428
+ task.startedAt !== undefined ||
429
+ task.history?.length)
430
+ continue;
431
+ next.delete(id);
432
+ removed.push(id);
433
+ }
434
+ const previous = this.tasks;
435
+ if (removed.length)
436
+ this.save(next);
437
+ try {
438
+ commit?.();
439
+ }
440
+ catch (err) {
441
+ if (removed.length) {
442
+ try {
443
+ this.save(previous);
444
+ }
445
+ catch (restoreError) {
446
+ throw new Error(`Transcript update failed (${String(err)}); scheduled tasks could not be restored (${String(restoreError)}). Inspect the scheduler before retrying.`);
447
+ }
448
+ }
449
+ throw err;
450
+ }
451
+ if (!removed.length)
452
+ return 0;
453
+ for (const id of removed) {
454
+ this.nextFire.delete(id);
455
+ try {
456
+ this.opts.onTaskRemoved?.(id);
457
+ }
458
+ catch (err) {
459
+ this.reportFailure(err);
460
+ }
461
+ }
462
+ this.changed();
463
+ return removed.length;
464
+ }
393
465
  remove(id) {
394
466
  const ok = this.tasks.has(id);
395
467
  if (ok) {
@@ -479,6 +551,16 @@ export class SchedulerStore {
479
551
  if (!task)
480
552
  return { ok: false, error: "任务不存在" };
481
553
  const executor = this.opts.executor;
554
+ // Remember the attempt before any external effect, even if run-history persistence later fails.
555
+ if (task.origin && task.startedAt === undefined) {
556
+ try {
557
+ this.save(new Map(this.tasks).set(id, { ...task, startedAt: Date.now() }));
558
+ }
559
+ catch (err) {
560
+ this.reportFailure(err);
561
+ return { ok: false, error: `Failed to persist scheduled-task start: ${String(err)}` };
562
+ }
563
+ }
482
564
  this.running.add(id);
483
565
  this.changed();
484
566
  const startedAt = Date.now();
@@ -28,16 +28,16 @@ export const MAX_COMMITMSG_LEN = 200;
28
28
  /** File list cap inside the prompt (porcelain lines); the diffs carry the
29
29
  * details, the list is orientation only. */
30
30
  const MAX_FILE_LINES = 200;
31
- export const COMMITMSG_SYSTEM_PROMPT = `You write git commit messages. You receive the pending changes of a repository and output exactly one commit message: a single subject line.
32
-
33
- Rules:
34
- 1. Match the style, format and language of the repository's recent commit subjects when provided — conventional commits ("type(scope): summary"), prefixes, punctuation, language: copy what the repo actually does.
35
- 2. Describe what the change does at a glance (the user-facing effect), not a file-by-file listing.
36
- 3. The staged diff is the subject of the commit. Describe staged changes when any exist; otherwise describe the unstaged and untracked changes shown.
37
- 4. One line. No quotes, no markdown, no code fences, no "Commit message:" label, no explanation. Under 72 characters when the repository's language allows it (CJK text may naturally be shorter).
38
- 5. Never invent scope names, issue numbers or details not visible in the provided material.
39
- 6. If the repository has no commits yet, write the message in the language stated in the request.
40
-
31
+ export const COMMITMSG_SYSTEM_PROMPT = `You write git commit messages. You receive the pending changes of a repository and output exactly one commit message: a single subject line.
32
+
33
+ Rules:
34
+ 1. Match the style, format and language of the repository's recent commit subjects when provided — conventional commits ("type(scope): summary"), prefixes, punctuation, language: copy what the repo actually does.
35
+ 2. Describe what the change does at a glance (the user-facing effect), not a file-by-file listing.
36
+ 3. The staged diff is the subject of the commit. Describe staged changes when any exist; otherwise describe the unstaged and untracked changes shown.
37
+ 4. One line. No quotes, no markdown, no code fences, no "Commit message:" label, no explanation. Under 72 characters when the repository's language allows it (CJK text may naturally be shorter).
38
+ 5. Never invent scope names, issue numbers or details not visible in the provided material.
39
+ 6. If the repository has no commits yet, write the message in the language stated in the request.
40
+
41
41
  Output ONLY the subject line.`;
42
42
  /**
43
43
  * Assemble the effective system prompt from the settings-panel prefs (same