pi-web-ui 0.114.0 → 0.114.2
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 +45 -0
- package/bin/pi-web-ui.mjs +15 -7
- package/dist/server/agent-service.js +190 -65
- package/dist/server/attachments.js +48 -2
- package/dist/server/canvas/canvas-agent-tool.js +3 -3
- package/dist/server/canvas/canvas-cards.js +1 -1
- 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/communicate-tool.js +37 -11
- package/dist/server/device-center/connector.js +33 -14
- package/dist/server/device-center/hub-page.js +1 -1
- 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/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/durable/durable-event-projector.js +19 -3
- package/dist/server/durable/durable-models.js +134 -65
- package/dist/server/engine-probe.js +36 -6
- package/dist/server/global-loader.js +40 -2
- package/dist/server/index.js +56 -32
- package/dist/server/model-resolver.js +4 -1
- package/dist/server/patch-bash-process.js +125 -0
- 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/resolve-global-sdk.js +2 -0
- package/dist/server/schedule-agent-tool.js +49 -26
- package/dist/server/scheduler-tasks.js +129 -11
- package/dist/server/settings-service.js +6 -0
- 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 +42 -18
- package/docs/device-center.md +9 -3
- package/package.json +2 -2
- package/plugins/catalog.json +10 -0
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/BgTasksModal-BIlQ89vr.js +1 -0
- package/web/dist/assets/BgTasksModal-Ck2sjlPM.js +1 -0
- package/web/dist/assets/{CanvasStudio-BEJZE5BI.js → CanvasStudio-B3W6b_rA.js} +3 -3
- package/web/dist/assets/{CanvasStudio-CgUNHqos.js → CanvasStudio-Csv1Sj1-.js} +3 -3
- package/web/dist/assets/DeviceCenter-BQdDcO8A.js +3 -0
- package/web/dist/assets/DeviceCenter-CHRKL0Vy.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-B9xoU6ON.js +2 -0
- package/web/dist/assets/FilePreview-DUQpVZkH.js +2 -0
- package/web/dist/assets/GlobalSearchModal-BXEGvUZq.js +1 -0
- package/web/dist/assets/GlobalSearchModal-CnVPmfOI.js +1 -0
- package/web/dist/assets/GroupConversation-CyIpQzDd.js +1 -0
- package/web/dist/assets/GroupConversation-DgYV3uYS.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-imYI2Ecw.js +2 -0
- package/web/dist/assets/SCMPanel-sVZcV7dR.js +2 -0
- package/web/dist/assets/SettingsModal-Xw1Yoi3_.js +20 -0
- package/web/dist/assets/SettingsModal-mb4e34-0.js +20 -0
- package/web/dist/assets/{TerminalPanel-DL20uKgU.js → TerminalPanel-CLkJJvxg.js} +2 -2
- package/web/dist/assets/{TerminalPanel-D6cPRFei.js → TerminalPanel-DpcIellm.js} +2 -2
- package/web/dist/assets/TuiOverlayModal-4-fFAZe7.js +1 -0
- package/web/dist/assets/TuiOverlayModal-DCu01lks.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-Cdh3sibd.js +85 -0
- package/web/dist/assets/index-DDZMv6LO.css +1 -0
- package/web/dist/assets/index-DWw_SxRq.js +85 -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 +10 -9
- package/web/dist/sw.js +1 -1
- 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
|
@@ -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.",
|
|
@@ -138,7 +146,9 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
|
|
|
138
146
|
})),
|
|
139
147
|
id: Type.Optional(Type.String({ description: "cancel: task id from action=list." })),
|
|
140
148
|
}),
|
|
141
|
-
execute: async (_id, p) => {
|
|
149
|
+
execute: async (_id, p, signal) => {
|
|
150
|
+
signal?.throwIfAborted();
|
|
151
|
+
const source = host.executionSource?.();
|
|
142
152
|
const action = (p.action ?? "").trim().toLowerCase();
|
|
143
153
|
if (!action) {
|
|
144
154
|
return text(pick(getLang(), "schedule 工具缺少 action 参数(可选:create, list, cancel)。", "schedule tool requires an action parameter (one of: create, list, cancel).", "sched.action.missing"));
|
|
@@ -159,23 +169,28 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
|
|
|
159
169
|
if (parsed.kind === "interval" && Number(parsed.spec) < SCHEDULER_MIN_INTERVAL_MS) {
|
|
160
170
|
return text(pick(getLang(), `间隔太短(最短 60s,防 token 烧穿)。`, `Interval too short (minimum 60s, prevents token burn).`, "sched.task.interval.too.short"));
|
|
161
171
|
}
|
|
172
|
+
const isCanvas = p.graphId !== undefined;
|
|
173
|
+
const graphId = String(p.graphId ?? "").trim();
|
|
162
174
|
const prompt = String(p.prompt ?? "").trim();
|
|
163
|
-
if (!prompt) {
|
|
175
|
+
if (!prompt && !isCanvas) {
|
|
164
176
|
return text(pick(getLang(), "触发指令(prompt)不能为空:写清楚触发时要检查什么、汇报什么。", "Prompt must not be empty: say what to check and report on fire.", "sched.task.empty.prompt"));
|
|
165
177
|
}
|
|
166
|
-
const cwd = String(host.cwd() ?? "").trim();
|
|
178
|
+
const cwd = String(source?.cwd ?? host.cwd() ?? "").trim();
|
|
167
179
|
if (!cwd) {
|
|
168
180
|
return text(pick(getLang(), "当前没有工作目录,无法创建定时任务。", "No working directory, cannot create the scheduled task.", "sched.task.no.cwd"));
|
|
169
181
|
}
|
|
170
182
|
const labelRaw = typeof p.label === "string" ? p.label.trim().slice(0, 80) : "";
|
|
171
|
-
const name = labelRaw || prompt.split("\n")[0].slice(0, 40) || "定时任务";
|
|
172
|
-
const convId =
|
|
183
|
+
const name = labelRaw || prompt.split("\n")[0].slice(0, 40) || (isCanvas ? `Canvas ${graphId}` : "定时任务");
|
|
184
|
+
const convId = source?.conversationId ??
|
|
185
|
+
((ownerConversationId ?? "").trim() || String(host.activeConversationId() ?? "").trim());
|
|
173
186
|
// 稳定绑定(issue #231):owner 对话的落盘会话文件 —— 压缩/重启后靠它重认同一会话,
|
|
174
187
|
// 内存对话 id(c1/c2…)只做首选唤醒键。宿主没实现 conversationInfo 时按原来只绑 id。
|
|
175
188
|
let bindCwd = cwd;
|
|
176
|
-
let bindSessionFile = "";
|
|
189
|
+
let bindSessionFile = source?.sessionFile ?? "";
|
|
177
190
|
try {
|
|
178
|
-
const info =
|
|
191
|
+
const info = isCanvas || source
|
|
192
|
+
? undefined
|
|
193
|
+
: host.conversationInfo?.((ownerConversationId ?? "").trim() || convId || undefined);
|
|
179
194
|
if (info) {
|
|
180
195
|
if (String(info.cwd ?? "").trim())
|
|
181
196
|
bindCwd = String(info.cwd).trim();
|
|
@@ -190,8 +205,11 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
|
|
|
190
205
|
const recurring = p.recurring === true;
|
|
191
206
|
let task;
|
|
192
207
|
try {
|
|
208
|
+
signal?.throwIfAborted();
|
|
193
209
|
task = store.upsert({
|
|
194
210
|
name,
|
|
211
|
+
target: isCanvas ? "canvas" : "conversation",
|
|
212
|
+
...(isCanvas ? { graphId } : {}),
|
|
195
213
|
cwd: bindCwd,
|
|
196
214
|
kind: parsed.kind,
|
|
197
215
|
spec: parsed.spec,
|
|
@@ -199,9 +217,10 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
|
|
|
199
217
|
conversationId: convId,
|
|
200
218
|
sessionFile: bindSessionFile,
|
|
201
219
|
oneShot: !recurring,
|
|
202
|
-
});
|
|
220
|
+
}, source?.sessionFile ? { sessionFile: source.sessionFile, toolCallId: _id } : undefined);
|
|
203
221
|
}
|
|
204
222
|
catch (err) {
|
|
223
|
+
signal?.throwIfAborted();
|
|
205
224
|
const L = getLang();
|
|
206
225
|
if (err instanceof SchedulerValidationError) {
|
|
207
226
|
return text(L === "zh" ? err.messageZh : err.messageEn);
|
|
@@ -216,13 +235,17 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
|
|
|
216
235
|
const whenLine = L === "zh"
|
|
217
236
|
? `触发:${parsed.kind === "cron" ? `cron ${parsed.spec}` : describeIntervalMs(Number(parsed.spec))},下次 ${fmtTime(next, L)}${recurring ? "(周期)" : "(单次,触发后自动删除)"}`
|
|
218
237
|
: `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 =
|
|
238
|
+
const targetLine = isCanvas
|
|
220
239
|
? L === "zh"
|
|
221
|
-
?
|
|
222
|
-
: `
|
|
223
|
-
:
|
|
224
|
-
?
|
|
225
|
-
|
|
240
|
+
? `目标:画布 ${graphId};${prompt ? "使用提供的触发指令" : "使用图自带输入"},模型由画布节点配置。`
|
|
241
|
+
: `Target: canvas ${graphId}; ${prompt ? "uses the supplied instruction" : "uses the graph's input"}, with models configured by canvas nodes.`
|
|
242
|
+
: convId
|
|
243
|
+
? L === "zh"
|
|
244
|
+
? `汇报:触发时自动唤醒本对话(${convId});压缩/重启后按会话文件自动重绑,原对话不在时先回落同项目活跃对话(明确提示),无存活对话才无头执行。`
|
|
245
|
+
: `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.`
|
|
246
|
+
: L === "zh"
|
|
247
|
+
? "汇报:无头执行,报告进调度面板历史(创建时没拿到对话 id)。"
|
|
248
|
+
: "Reports: headless run, report in panel history (no conversation id captured at creation).";
|
|
226
249
|
const tail = L === "zh"
|
|
227
250
|
? `取消:schedule(action="cancel", id="${task.id}"),或后台任务面板手动取消;查看:schedule(action="list")。`
|
|
228
251
|
: `Cancel: schedule(action="cancel", id="${task.id}"), or from the background-tasks panel; inspect: schedule(action="list").`;
|
|
@@ -86,18 +86,26 @@ export function normalizeSchedulerInput(input, now = Date.now()) {
|
|
|
86
86
|
}
|
|
87
87
|
spec = String(ms);
|
|
88
88
|
}
|
|
89
|
+
if (input.target !== undefined && input.target !== "conversation" && input.target !== "canvas") {
|
|
90
|
+
throw new SchedulerValidationError("invalid_target", "任务目标非法", "Invalid task target");
|
|
91
|
+
}
|
|
92
|
+
const graphId = String(input.graphId ?? "").trim();
|
|
93
|
+
const target = input.target ?? (graphId ? "canvas" : "conversation");
|
|
94
|
+
if (target === "canvas" && (!/^[A-Za-z0-9._-]{1,64}$/.test(graphId) || graphId === "." || graphId === "..")) {
|
|
95
|
+
throw new SchedulerValidationError("invalid_graph_id", "画布工程 id 非法或为空", "Invalid or missing canvas graph id");
|
|
96
|
+
}
|
|
89
97
|
const prompt = String(input.prompt ?? "").trim();
|
|
90
|
-
if (!prompt) {
|
|
98
|
+
if (!prompt && target === "conversation") {
|
|
91
99
|
throw new SchedulerValidationError("empty_prompt", "触发指令(prompt)不能为空", "Trigger instruction (prompt) cannot be empty");
|
|
92
100
|
}
|
|
93
101
|
if (prompt.length > 8000) {
|
|
94
102
|
throw new SchedulerValidationError("prompt_too_long", "触发指令超长(>8000 字),请裁剪后重试", "Trigger instruction too long (>8000 characters), please shorten and retry");
|
|
95
103
|
}
|
|
96
|
-
const model = String(input.model ?? "").trim();
|
|
104
|
+
const model = target === "canvas" ? "" : String(input.model ?? "").trim();
|
|
97
105
|
if (model && !model.includes("/")) {
|
|
98
106
|
throw new SchedulerValidationError("invalid_model", "模型格式非法(应为 provider/id)", "Invalid model format (expected provider/id)");
|
|
99
107
|
}
|
|
100
|
-
const thinkingLevel = String(input.thinkingLevel ?? "").trim();
|
|
108
|
+
const thinkingLevel = target === "canvas" ? "" : String(input.thinkingLevel ?? "").trim();
|
|
101
109
|
const catchUp = input.catchUp === "once" ? "once" : "skip";
|
|
102
110
|
const conversationId = String(input.conversationId ?? "")
|
|
103
111
|
.trim()
|
|
@@ -109,6 +117,8 @@ export function normalizeSchedulerInput(input, now = Date.now()) {
|
|
|
109
117
|
.slice(0, 1024);
|
|
110
118
|
return {
|
|
111
119
|
id,
|
|
120
|
+
target,
|
|
121
|
+
...(target === "canvas" ? { graphId } : {}),
|
|
112
122
|
name,
|
|
113
123
|
description,
|
|
114
124
|
cwd,
|
|
@@ -119,8 +129,8 @@ export function normalizeSchedulerInput(input, now = Date.now()) {
|
|
|
119
129
|
model,
|
|
120
130
|
thinkingLevel,
|
|
121
131
|
catchUp,
|
|
122
|
-
conversationId,
|
|
123
|
-
sessionFile,
|
|
132
|
+
conversationId: target === "canvas" ? "" : conversationId,
|
|
133
|
+
sessionFile: target === "canvas" ? "" : sessionFile,
|
|
124
134
|
oneShot: input.oneShot === true,
|
|
125
135
|
createdAt: now,
|
|
126
136
|
updatedAt: now,
|
|
@@ -160,6 +170,17 @@ export function describeIntervalMs(ms) {
|
|
|
160
170
|
const d = Math.floor(s / 86400);
|
|
161
171
|
return `每 ${d} 天`;
|
|
162
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
|
+
}
|
|
163
184
|
function sanitizeHistory(v) {
|
|
164
185
|
if (!Array.isArray(v))
|
|
165
186
|
return [];
|
|
@@ -175,6 +196,9 @@ function sanitizeHistory(v) {
|
|
|
175
196
|
ok: rec.ok === true,
|
|
176
197
|
durationMs: typeof rec.durationMs === "number" && Number.isFinite(rec.durationMs) ? rec.durationMs : 0,
|
|
177
198
|
...(typeof rec.conversationId === "string" && rec.conversationId ? { conversationId: rec.conversationId } : {}),
|
|
199
|
+
...(rec.target === "canvas" || rec.target === "conversation" ? { target: rec.target } : {}),
|
|
200
|
+
...(typeof rec.graphId === "string" && rec.graphId ? { graphId: rec.graphId.slice(0, 64) } : {}),
|
|
201
|
+
...(typeof rec.runId === "string" && rec.runId ? { runId: rec.runId.slice(0, 128) } : {}),
|
|
178
202
|
...(typeof rec.error === "string" && rec.error ? { error: rec.error.slice(0, 500) } : {}),
|
|
179
203
|
...(rec.manual === true ? { manual: true } : {}),
|
|
180
204
|
});
|
|
@@ -259,6 +283,8 @@ export class SchedulerStore {
|
|
|
259
283
|
try {
|
|
260
284
|
const task = normalizeSchedulerInput({
|
|
261
285
|
id,
|
|
286
|
+
target: r.target,
|
|
287
|
+
graphId: r.graphId,
|
|
262
288
|
name: r.name,
|
|
263
289
|
description: r.description,
|
|
264
290
|
cwd: r.cwd,
|
|
@@ -276,7 +302,12 @@ export class SchedulerStore {
|
|
|
276
302
|
task.createdAt = typeof r.createdAt === "number" && Number.isFinite(r.createdAt) ? r.createdAt : Date.now();
|
|
277
303
|
task.updatedAt =
|
|
278
304
|
typeof r.updatedAt === "number" && Number.isFinite(r.updatedAt) ? r.updatedAt : task.createdAt;
|
|
279
|
-
next.set(id, {
|
|
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
|
+
});
|
|
280
311
|
}
|
|
281
312
|
catch {
|
|
282
313
|
// 单条坏记录跳过,不影响其他任务
|
|
@@ -319,6 +350,8 @@ export class SchedulerStore {
|
|
|
319
350
|
const history = sanitizeHistory(t.history);
|
|
320
351
|
return {
|
|
321
352
|
id: t.id,
|
|
353
|
+
target: t.target ?? "conversation",
|
|
354
|
+
...(t.graphId ? { graphId: t.graphId } : {}),
|
|
322
355
|
name: t.name,
|
|
323
356
|
description: t.description,
|
|
324
357
|
cwd: t.cwd,
|
|
@@ -332,6 +365,8 @@ export class SchedulerStore {
|
|
|
332
365
|
conversationId: t.conversationId,
|
|
333
366
|
sessionFile: t.sessionFile ?? "",
|
|
334
367
|
oneShot: t.oneShot,
|
|
368
|
+
...(t.origin ? { origin: { ...t.origin } } : {}),
|
|
369
|
+
...(t.startedAt !== undefined ? { startedAt: t.startedAt } : {}),
|
|
335
370
|
createdAt: t.createdAt,
|
|
336
371
|
updatedAt: t.updatedAt,
|
|
337
372
|
nextFire: !t.enabled ? null : (this.nextFire.get(t.id) ?? computeNextFire(t, Math.max(now, t.updatedAt))),
|
|
@@ -346,17 +381,32 @@ export class SchedulerStore {
|
|
|
346
381
|
* issue #231:面板编辑不带绑定字段(conversationId/sessionFile 缺席)时保留旧绑定 ——
|
|
347
382
|
* 否则用户在面板改个名字就会把 AI 任务的会话绑定洗掉,下次触发直接变无头。
|
|
348
383
|
* 字段显式出现(含空串)仍按全量语义覆盖。 */
|
|
349
|
-
upsert(input) {
|
|
384
|
+
upsert(input, origin) {
|
|
385
|
+
if (origin !== undefined && !validOrigin(origin))
|
|
386
|
+
throw new Error("Invalid scheduled-task creation origin");
|
|
350
387
|
const prev = this.tasks.get(String(input.id ?? "").trim());
|
|
351
|
-
const task = normalizeSchedulerInput(
|
|
388
|
+
const task = normalizeSchedulerInput({
|
|
389
|
+
...input,
|
|
390
|
+
...(prev && input.target === undefined && input.graphId === undefined
|
|
391
|
+
? { target: prev.target, graphId: prev.graphId }
|
|
392
|
+
: {}),
|
|
393
|
+
});
|
|
394
|
+
if (origin)
|
|
395
|
+
task.origin = { ...origin };
|
|
352
396
|
if (prev) {
|
|
397
|
+
task.origin = prev.origin;
|
|
398
|
+
task.startedAt = prev.startedAt;
|
|
353
399
|
task.createdAt = prev.createdAt;
|
|
354
400
|
task.updatedAt = Date.now();
|
|
355
|
-
if (
|
|
401
|
+
if (task.target !== "canvas" &&
|
|
402
|
+
prev.target !== "canvas" &&
|
|
403
|
+
input.conversationId === undefined &&
|
|
404
|
+
input.sessionFile === undefined) {
|
|
356
405
|
task.conversationId = prev.conversationId;
|
|
357
406
|
task.sessionFile = prev.sessionFile ?? "";
|
|
358
407
|
}
|
|
359
408
|
}
|
|
409
|
+
this.opts.validateTask?.(task);
|
|
360
410
|
const history = prev?.history ? sanitizeHistory(prev.history) : [];
|
|
361
411
|
this.save(new Map(this.tasks).set(task.id, { ...task, history }));
|
|
362
412
|
// spec/cwd/开关变了 → 按现在重排下次触发
|
|
@@ -364,6 +414,54 @@ export class SchedulerStore {
|
|
|
364
414
|
this.changed();
|
|
365
415
|
return task;
|
|
366
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
|
+
}
|
|
367
465
|
remove(id) {
|
|
368
466
|
const ok = this.tasks.has(id);
|
|
369
467
|
if (ok) {
|
|
@@ -396,7 +494,7 @@ export class SchedulerStore {
|
|
|
396
494
|
* 与历史)。无变化回 false(调用方免一次落盘+推送);未知任务回 false。 */
|
|
397
495
|
rebind(id, binding) {
|
|
398
496
|
const prev = this.tasks.get(id);
|
|
399
|
-
if (!prev)
|
|
497
|
+
if (!prev || prev.target === "canvas")
|
|
400
498
|
return false;
|
|
401
499
|
const t = { ...prev };
|
|
402
500
|
let dirty = false;
|
|
@@ -453,6 +551,16 @@ export class SchedulerStore {
|
|
|
453
551
|
if (!task)
|
|
454
552
|
return { ok: false, error: "任务不存在" };
|
|
455
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
|
+
}
|
|
456
564
|
this.running.add(id);
|
|
457
565
|
this.changed();
|
|
458
566
|
const startedAt = Date.now();
|
|
@@ -471,10 +579,15 @@ export class SchedulerStore {
|
|
|
471
579
|
at: Date.now(),
|
|
472
580
|
ok: result.ok,
|
|
473
581
|
durationMs,
|
|
582
|
+
target: task.target ?? "conversation",
|
|
583
|
+
...(task.graphId ? { graphId: task.graphId } : {}),
|
|
584
|
+
...(result.runId ? { runId: result.runId } : {}),
|
|
474
585
|
...(result.conversationId ? { conversationId: result.conversationId } : {}),
|
|
475
586
|
...(result.error ? { error: result.error.slice(0, 500) } : {}),
|
|
476
587
|
...(manual ? { manual } : {}),
|
|
477
588
|
});
|
|
589
|
+
if (task.oneShot)
|
|
590
|
+
this.remove(id);
|
|
478
591
|
}
|
|
479
592
|
catch (err) {
|
|
480
593
|
result = {
|
|
@@ -488,7 +601,12 @@ export class SchedulerStore {
|
|
|
488
601
|
// 仅推进内存调度,使用执行期间更新后的配置,不伪造成功历史。
|
|
489
602
|
// 进程重启后仍可能补跑:本地记录与外部副作用不保证跨进程 exactly-once。
|
|
490
603
|
const cur = this.tasks.get(id);
|
|
491
|
-
if (cur &&
|
|
604
|
+
if (cur && task.oneShot) {
|
|
605
|
+
// A failed history/removal write must not repeat an already attempted one-shot.
|
|
606
|
+
this.tasks.set(id, { ...cur, enabled: false });
|
|
607
|
+
this.nextFire.delete(id);
|
|
608
|
+
}
|
|
609
|
+
else if (cur && cur.enabled && !manual) {
|
|
492
610
|
this.nextFire.set(id, computeNextFire(cur, Date.now()) ?? Date.now() + TICK_MS);
|
|
493
611
|
}
|
|
494
612
|
this.running.delete(id);
|
|
@@ -466,6 +466,7 @@ export class SettingsService {
|
|
|
466
466
|
subagentDefaultModel: this.settings.subagentDefaultModel ?? null,
|
|
467
467
|
subagentMaxDepth: this.settings.subagentMaxDepth ?? 0,
|
|
468
468
|
questionPresentation: this.settings.questionPresentation ?? "queue",
|
|
469
|
+
toolApprovalPresentation: this.settings.toolApprovalPresentation ?? "all",
|
|
469
470
|
questionTimeoutSeconds: this.settings.questionTimeoutSeconds ?? 240,
|
|
470
471
|
subagentAutoWakeMaxTurns: this.settings.subagentAutoWakeMaxTurns ?? defaultSubagentAutoWakeMaxTurns(),
|
|
471
472
|
steeringMode: this.settings.steeringMode,
|
|
@@ -756,6 +757,11 @@ export class SettingsService {
|
|
|
756
757
|
throw new Error("Invalid questionnaire presentation");
|
|
757
758
|
next.questionPresentation = partial.questionPresentation;
|
|
758
759
|
}
|
|
760
|
+
if (partial.toolApprovalPresentation !== undefined) {
|
|
761
|
+
if (!["queue", "all", "manual"].includes(partial.toolApprovalPresentation))
|
|
762
|
+
throw new Error("Invalid tool approval presentation");
|
|
763
|
+
next.toolApprovalPresentation = partial.toolApprovalPresentation;
|
|
764
|
+
}
|
|
759
765
|
if (partial.questionTimeoutSeconds !== undefined) {
|
|
760
766
|
const seconds = partial.questionTimeoutSeconds;
|
|
761
767
|
if (!Number.isSafeInteger(seconds) || seconds < 0 || seconds > 86400)
|
|
@@ -159,6 +159,15 @@ export function splitQuotedPrompt(value) {
|
|
|
159
159
|
attachments.push({ type: "conversation", name: title });
|
|
160
160
|
return "";
|
|
161
161
|
});
|
|
162
|
+
text = text.replace(/(?:^|\n\n)?<canvas-ref id="([^"]*)" title="([^"]*)">[\s\S]*?<\/canvas-ref>/g, (_, id, title) => {
|
|
163
|
+
const decode = (s) => s
|
|
164
|
+
.replace(/"/g, '"')
|
|
165
|
+
.replace(/</g, "<")
|
|
166
|
+
.replace(/>/g, ">")
|
|
167
|
+
.replace(/&/g, "&");
|
|
168
|
+
attachments.push({ type: "canvas", path: decode(id), name: decode(title) || decode(id) });
|
|
169
|
+
return "";
|
|
170
|
+
});
|
|
162
171
|
text = text.replace(/(?:^|\n\n)?<vision-bridge>[\s\S]*?<\/vision-bridge>/g, () => {
|
|
163
172
|
attachments.push({ type: "vision-bridge", name: "视觉转写" });
|
|
164
173
|
return "";
|
|
@@ -124,7 +124,8 @@ export const AGENT_TOOL_CATALOG = [
|
|
|
124
124
|
group: "subagent",
|
|
125
125
|
defaultOn: true,
|
|
126
126
|
dshVisible: false,
|
|
127
|
-
descKey: "
|
|
127
|
+
descKey: "communicateEnabledDesc",
|
|
128
|
+
offHintKey: "communicateOffHint",
|
|
128
129
|
},
|
|
129
130
|
{
|
|
130
131
|
name: EDIT_SOFT_TOOL_NAME,
|
|
@@ -19,6 +19,7 @@ import { delimiter, isAbsolute, join } from "node:path";
|
|
|
19
19
|
import { BaseAgentDriver } from "../driver-base.js";
|
|
20
20
|
import { resolveProviderCredential, listCustomModelsFromConfig, isModelProtocolSupportedByEngine, } from "../../model-resolver.js";
|
|
21
21
|
import { discoverDiskSkills } from "../../skill-discovery.js";
|
|
22
|
+
import { formatUnavailableCanvasReference } from "../universal-attachments.js";
|
|
22
23
|
/**
|
|
23
24
|
* 探测可执行文件路径:若传入了绝对路径或在系统 PATH 中找到则直接使用;
|
|
24
25
|
* 若未找到(尤其在 macOS launchd/GUI 等精简 PATH 环境),则自动扫描系统及版本管理器的常见安装目录。
|
|
@@ -197,6 +198,10 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
|
|
|
197
198
|
if (attachments && attachments.length > 0) {
|
|
198
199
|
const notes = [];
|
|
199
200
|
for (const att of attachments) {
|
|
201
|
+
if (att.mode === "canvas") {
|
|
202
|
+
notes.push(formatUnavailableCanvasReference(att));
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
200
205
|
if (att.path) {
|
|
201
206
|
const lineRange = att.lines ? ` (行 ${att.lines.start}-${att.lines.end})` : "";
|
|
202
207
|
notes.push(`[文件引用: ${att.path}${lineRange}]`);
|