pi-web-ui 0.113.1 → 0.114.0
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 +43 -1
- package/README.md +117 -246
- package/README.zh-CN.md +145 -217
- package/README.zh-TW.md +145 -217
- package/bin/device-hub-cli.mjs +577 -0
- package/bin/pi-device-hub.mjs +9 -0
- package/bin/pi-web-ui.mjs +47 -15
- package/dist/server/agent-service-daemon.js +102 -24
- package/dist/server/agent-service.js +2289 -1120
- package/dist/server/approval-rules.js +29 -3
- package/dist/server/ask-user-question-tool.js +8 -8
- package/dist/server/atomic-file.js +35 -14
- package/dist/server/attachment-store.js +71 -35
- package/dist/server/attachments.js +18 -8
- package/dist/server/canvas/canvas-agent-tool.js +65 -15
- package/dist/server/canvas/canvas-dispatch.js +61 -20
- package/dist/server/canvas/canvas-orchestrator.js +516 -199
- package/dist/server/canvas/canvas-scheduler.js +99 -0
- package/dist/server/canvas/canvas-store.js +107 -54
- package/dist/server/canvas/canvas-validation.js +131 -0
- package/dist/server/canvas/canvas-workspace.js +284 -0
- package/dist/server/client-id-utils.js +8 -0
- package/dist/server/client-state.js +104 -22
- package/dist/server/communicate-tool.js +76 -0
- package/dist/server/compact-context-tool.js +2 -3
- package/dist/server/compaction-instructions.js +75 -0
- package/dist/server/compaction-markers.js +7 -2
- package/dist/server/compaction-state.js +84 -0
- package/dist/server/composer-drafts.js +43 -40
- package/dist/server/context-evidence.js +346 -0
- package/dist/server/conversation-communication.js +368 -0
- package/dist/server/conversation-read-tool.js +3 -4
- package/dist/server/conversation-tool-names.js +14 -0
- package/dist/server/conversation-tool.js +57 -0
- package/dist/server/delegate-mode.js +17 -4
- package/dist/server/device-center/bot-catalog.js +88 -0
- package/dist/server/device-center/bot-execution.js +106 -0
- package/dist/server/device-center/bots.js +170 -0
- package/dist/server/device-center/collab-service.js +153 -0
- package/dist/server/device-center/collab-tool.js +184 -0
- package/dist/server/device-center/connector.js +332 -0
- package/dist/server/device-center/desktop-linux.js +372 -0
- package/dist/server/device-center/desktop-native.js +413 -0
- package/dist/server/device-center/desktop-page.js +232 -0
- package/dist/server/device-center/desktop-setup.js +30 -0
- package/dist/server/device-center/desktop.js +387 -0
- package/dist/server/device-center/device-portals.js +241 -0
- package/dist/server/device-center/execution-failure.js +70 -0
- package/dist/server/device-center/executor.js +371 -0
- package/dist/server/device-center/file-sync.js +493 -0
- package/dist/server/device-center/hub-auth.js +69 -0
- package/dist/server/device-center/hub-page.js +68 -0
- package/dist/server/device-center/hub-setup.js +214 -0
- package/dist/server/device-center/hub.js +829 -0
- package/dist/server/device-center/local-page.js +17 -0
- package/dist/server/device-center/local.js +476 -0
- package/dist/server/device-center/main.js +118 -0
- package/dist/server/device-center/native-desktop/macos.js +192 -0
- package/dist/server/device-center/native-desktop/windows.js +118 -0
- package/dist/server/device-center/path-portal.js +120 -0
- package/dist/server/device-center/relay.js +959 -0
- package/dist/server/device-center/runtime.js +253 -0
- package/dist/server/device-center/smoke-preview.js +3 -0
- package/dist/server/device-center/store.js +122 -0
- package/dist/server/device-center/task-error.js +14 -0
- package/dist/server/device-center/transfers.js +293 -0
- package/dist/server/device-center/workspaces.js +45 -0
- package/dist/server/dispatch-domain-handlers.js +83 -27
- package/dist/server/dsh/dsh-agent-service.js +277 -158
- package/dist/server/dsh/dsh-client.js +12 -2
- package/dist/server/durable/durable-agent-service.js +1 -1
- package/dist/server/evidence-tool-hooks.js +49 -0
- package/dist/server/file-save.js +95 -0
- package/dist/server/file-transfer-routes.js +97 -47
- package/dist/server/files-service.js +38 -26
- package/dist/server/goal-review-gate.js +16 -6
- package/dist/server/goal-service.js +54 -30
- package/dist/server/http-proxy.js +120 -0
- package/dist/server/index.js +229 -223
- package/dist/server/load-timing.js +31 -0
- package/dist/server/mcp-bridge.js +219 -94
- package/dist/server/mcp-hot-reload.js +31 -5
- package/dist/server/mcp-manager.js +192 -93
- package/dist/server/mcp-oauth-login.js +169 -0
- package/dist/server/mcp-oauth-ui.js +137 -0
- package/dist/server/mcp-oauth.js +395 -0
- package/dist/server/mcp-project-runtime.js +207 -0
- package/dist/server/message-window.js +74 -21
- package/dist/server/net-guard.js +122 -20
- package/dist/server/payload-limits.js +17 -0
- package/dist/server/pending-question.js +82 -0
- package/dist/server/plan-mode.js +338 -137
- package/dist/server/plugin-assets.js +8 -4
- package/dist/server/plugin-chat-attachments.js +48 -0
- package/dist/server/plugin-facilities.js +67 -220
- package/dist/server/plugin-installer.js +2 -1
- package/dist/server/plugin-removal.js +49 -0
- package/dist/server/plugin-secrets.js +179 -0
- package/dist/server/plugins.js +262 -92
- package/dist/server/preset-fields.js +49 -0
- package/dist/server/preset-plugin-dependencies.js +57 -0
- package/dist/server/preset-share.js +112 -72
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/queue-modes.js +10 -0
- package/dist/server/remote-ssh-service.js +160 -67
- package/dist/server/request-context.js +164 -0
- package/dist/server/sandbox-data.js +655 -0
- package/dist/server/sandbox-engines.js +7 -0
- package/dist/server/sandbox-runtime-gate.js +41 -0
- package/dist/server/sandbox-service.js +139 -698
- package/dist/server/sandbox-tool.js +21 -4
- package/dist/server/scheduler-tasks.js +63 -48
- package/dist/server/serialize.js +48 -19
- package/dist/server/session-branch.js +25 -3
- package/dist/server/session-parser.js +28 -18
- package/dist/server/session-scan.js +130 -0
- package/dist/server/session-search.js +51 -37
- package/dist/server/settings-service.js +267 -111
- package/dist/server/setup-config.js +58 -0
- package/dist/server/skill-maintenance.js +112 -24
- package/dist/server/subagent-helpers.js +4 -1
- package/dist/server/subagent-notify.js +4 -1
- package/dist/server/subagent-security-gate.js +52 -11
- package/dist/server/subagent-task.js +27 -0
- package/dist/server/subagents.js +217 -46
- package/dist/server/tabs.js +9 -1
- package/dist/server/terminals.js +467 -363
- package/dist/server/tool-guards.js +42 -6
- package/dist/server/tool-manager.js +47 -20
- package/dist/server/tool-overrides.js +13 -11
- package/dist/server/tool-prompt-overrides.js +32 -2
- package/dist/server/tool-prompts.js +1 -1
- package/dist/server/turn-timing.js +11 -0
- package/dist/server/universal/session-store.js +48 -6
- package/dist/server/universal/universal-service.js +1 -1
- package/dist/server/universal/universal-session.js +334 -231
- package/dist/server/uploads.js +64 -5
- package/dist/server/worktree-service.js +32 -24
- package/dist/server/ws-pending-queue.js +73 -27
- package/docs/device-center.md +142 -0
- package/docs/device-desktop.md +48 -0
- package/package.json +4 -1
- package/plugin-sdk/index.d.ts +28 -6
- package/plugin-sdk/ssh-host-trust.mjs +225 -0
- package/plugins/catalog.json +1 -1
- package/themes/aetheris.css +1 -107
- package/themes/ayu-light.css +5 -29
- package/themes/bases/flow-base.css +0 -6
- package/themes/bases/statusbar-flat-base.css +112 -0
- package/themes/bases/zhujian-base.css +1 -0
- package/themes/bases/zhupi-base.css +1 -0
- package/themes/catppuccin-latte.css +4 -27
- package/themes/catppuccin.css +4 -35
- package/themes/claude-code-dark.css +1 -0
- package/themes/codex.css +4 -28
- package/themes/cyberpunk.css +3 -61
- package/themes/dark-teal.css +0 -1
- package/themes/dazzle.css +3 -73
- package/themes/everforest-light.css +4 -27
- package/themes/geist.css +4 -28
- package/themes/gruvbox-light.css +4 -27
- package/themes/kanagawa-lotus.css +4 -27
- package/themes/md-preview.css +3 -213
- package/themes/mist.css +4 -24
- package/themes/nord.css +4 -35
- package/themes/one-dark.css +4 -37
- package/themes/paper.css +4 -16
- package/themes/rose-pine-dawn.css +4 -28
- package/themes/sakura.css +4 -24
- package/themes/solarized-light.css +4 -27
- package/themes/tokyo-night.css +3 -34
- package/themes/white.css +4 -26
- package/themes/zhujian-dark.css +1 -0
- package/themes/zhupi-dark.css +1 -0
- package/web/dist/.build-assets.json +1 -0
- package/web/dist/assets/BgTasksModal-CS7UNzcw.js +1 -0
- package/web/dist/assets/BgTasksModal-Dk-tp78W.js +1 -0
- package/web/dist/assets/CanvasStudio-BEJZE5BI.js +1579 -0
- package/web/dist/assets/CanvasStudio-CgUNHqos.js +1579 -0
- package/web/dist/assets/DeviceCenter-C8_CbxQ3.js +3 -0
- package/web/dist/assets/DeviceCenter-CVblvhNX.js +3 -0
- package/web/dist/assets/Dropdown-Oug0DDte.js +1 -0
- package/web/dist/assets/FilePreview-CvdX6nr6.js +2 -0
- package/web/dist/assets/FilePreview-kCZhfBAF.js +2 -0
- package/web/dist/assets/GlobalSearchModal-BLH63yYP.js +1 -0
- package/web/dist/assets/GlobalSearchModal-DAkvlvp6.js +1 -0
- package/web/dist/assets/GroupConversation-Cgo4xbpa.js +1 -0
- package/web/dist/assets/GroupConversation-DZ71jEi8.js +1 -0
- package/web/dist/assets/ModelConfigModal-BpWdFdQC.js +2 -0
- package/web/dist/assets/PiSetupModal-mkWPSxMj.js +1 -0
- package/web/dist/assets/ProviderOAuthControls-VK_jqXYS.js +1 -0
- package/web/dist/assets/SCMPanel-BP1TUT-V.js +2 -0
- package/web/dist/assets/SCMPanel-BscPm9kf.js +2 -0
- package/web/dist/assets/SettingsModal-C8UgMjVM.js +20 -0
- package/web/dist/assets/SettingsModal-VynB7jNb.js +20 -0
- package/web/dist/assets/TerminalPanel-D6cPRFei.js +3 -0
- package/web/dist/assets/TerminalPanel-DL20uKgU.js +3 -0
- package/web/dist/assets/TuiOverlayModal-Dst3BmT8.js +1 -0
- package/web/dist/assets/TuiOverlayModal-NCkpNtTp.js +1 -0
- package/web/dist/assets/UniversalPathPicker-CfQFc_c3.js +1 -0
- package/web/dist/assets/UniversalPathPicker-DwxwNcFw.js +1 -0
- package/web/dist/assets/app-globals-CnO6KlEM.js +325 -0
- package/web/dist/assets/desktop-DPyTy4M3.js +1 -0
- package/web/dist/assets/es-DWMIuDU2.js +2 -0
- package/web/dist/assets/index-CPgAH5q7.js +83 -0
- package/web/dist/assets/index-Cje8iugL.js +83 -0
- package/web/dist/assets/index-DnKeiDbj.css +1 -0
- package/web/dist/assets/markdown-BggnuQ4H.js +40 -0
- package/web/dist/assets/markdown-C8LL_u4z.css +1 -0
- package/web/dist/assets/math-1uRJCsA9.js +257 -0
- package/web/dist/assets/math-BorAY7qD.css +1 -0
- package/web/dist/assets/plugin-host-CqA4yW6w.js +1 -0
- package/web/dist/assets/shortcut-stack-hhrDyRBn.js +1 -0
- package/web/dist/assets/theme-BqdAjEjF.js +1 -0
- package/web/dist/assets/uuid-BzDIGCwP.js +1 -0
- package/web/dist/index.html +15 -9
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/TerminalPanel-Ci55JtJL.js +0 -3
- package/web/dist/assets/index-ByiO9f-N.js +0 -2008
- package/web/dist/assets/index-ycGLh4a4.css +0 -1
- package/web/dist/assets/markdown-BJZlfvdP.js +0 -296
- package/web/dist/assets/markdown-DSNUiDzp.css +0 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/** FIFO slots; cancelled waiters never consume execution capacity. */
|
|
2
|
+
export class CanvasExecutionQueue {
|
|
3
|
+
limit;
|
|
4
|
+
active = 0;
|
|
5
|
+
waiters = [];
|
|
6
|
+
constructor(limit) {
|
|
7
|
+
this.limit = limit;
|
|
8
|
+
}
|
|
9
|
+
async acquire(signal) {
|
|
10
|
+
signal.throwIfAborted();
|
|
11
|
+
if (this.active >= this.limit) {
|
|
12
|
+
await new Promise((resolve, reject) => {
|
|
13
|
+
const wake = () => {
|
|
14
|
+
signal.removeEventListener("abort", abort);
|
|
15
|
+
resolve();
|
|
16
|
+
};
|
|
17
|
+
const abort = () => {
|
|
18
|
+
this.waiters = this.waiters.filter((w) => w !== wake);
|
|
19
|
+
reject(signal.reason);
|
|
20
|
+
};
|
|
21
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
22
|
+
this.waiters.push(wake);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
else
|
|
26
|
+
this.active++;
|
|
27
|
+
if (signal.aborted) {
|
|
28
|
+
this.release();
|
|
29
|
+
signal.throwIfAborted();
|
|
30
|
+
}
|
|
31
|
+
let released = false;
|
|
32
|
+
return () => {
|
|
33
|
+
if (released)
|
|
34
|
+
return;
|
|
35
|
+
released = true;
|
|
36
|
+
this.release();
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
release() {
|
|
40
|
+
const next = this.waiters.shift();
|
|
41
|
+
if (next)
|
|
42
|
+
next();
|
|
43
|
+
else
|
|
44
|
+
this.active--;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Decision edges are feedback, never prerequisites of a forward join. */
|
|
48
|
+
export function isCanvasBackedge(edge) {
|
|
49
|
+
return edge.type === "review" || edge.type === "reject" || edge.type === "loop_back" || edge.sourcePort === "reject";
|
|
50
|
+
}
|
|
51
|
+
export function canvasCondition(node, graph) {
|
|
52
|
+
if (node.role === "ai_judge" || node.config?.aiJudge === true) {
|
|
53
|
+
if (node.aiVerdict === undefined)
|
|
54
|
+
throw new Error("AI judge returned no explicit decision");
|
|
55
|
+
return node.aiVerdict;
|
|
56
|
+
}
|
|
57
|
+
const input = graph.edges
|
|
58
|
+
.filter((e) => e.targetNodeId === node.id && e.active !== false)
|
|
59
|
+
.map((e) => e.lastHandoffSummary ?? "")
|
|
60
|
+
.join("\n") ||
|
|
61
|
+
node.lastOutputSummary ||
|
|
62
|
+
"";
|
|
63
|
+
const tokens = String(node.config?.condition ?? "")
|
|
64
|
+
.split(/[\s,,、/()]+/)
|
|
65
|
+
.filter(Boolean);
|
|
66
|
+
return tokens.length === 0 || tokens.some((token) => input.includes(token));
|
|
67
|
+
}
|
|
68
|
+
/** Wait for every forward path to resolve, then join only the selected paths. */
|
|
69
|
+
export function canvasReadiness(graph, node) {
|
|
70
|
+
const incoming = graph.edges.filter((e) => e.targetNodeId === node.id && !isCanvasBackedge(e));
|
|
71
|
+
if (!incoming.length)
|
|
72
|
+
return "ready";
|
|
73
|
+
if (incoming.some((e) => e.active === undefined))
|
|
74
|
+
return "wait";
|
|
75
|
+
return incoming.some((e) => e.active === true) ? "ready" : "skip";
|
|
76
|
+
}
|
|
77
|
+
export function validateCanvasTopology(graph) {
|
|
78
|
+
const ids = new Set(graph.nodes.map((n) => n.id));
|
|
79
|
+
if (ids.size !== graph.nodes.length)
|
|
80
|
+
throw new Error("Duplicate canvas node id");
|
|
81
|
+
for (const edge of graph.edges)
|
|
82
|
+
if (!ids.has(edge.sourceNodeId) || !ids.has(edge.targetNodeId))
|
|
83
|
+
throw new Error("Canvas edge references a missing node");
|
|
84
|
+
const visiting = new Set(), visited = new Set();
|
|
85
|
+
const visit = (id) => {
|
|
86
|
+
if (visiting.has(id))
|
|
87
|
+
throw new Error("Canvas forward cycle requires an explicit rework edge");
|
|
88
|
+
if (visited.has(id))
|
|
89
|
+
return;
|
|
90
|
+
visiting.add(id);
|
|
91
|
+
for (const edge of graph.edges)
|
|
92
|
+
if (edge.sourceNodeId === id && !isCanvasBackedge(edge))
|
|
93
|
+
visit(edge.targetNodeId);
|
|
94
|
+
visiting.delete(id);
|
|
95
|
+
visited.add(id);
|
|
96
|
+
};
|
|
97
|
+
for (const id of ids)
|
|
98
|
+
visit(id);
|
|
99
|
+
}
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
import { existsSync, mkdirSync, readdirSync, readFileSync, unlinkSync } from "node:fs";
|
|
8
8
|
import { join } from "node:path";
|
|
9
9
|
import { writeJsonAtomicSync } from "../atomic-file.js";
|
|
10
|
-
/**
|
|
10
|
+
/** Reliable first-run template: explicit input, implementation, verification, and human acceptance. */
|
|
11
11
|
export function createDefaultCanvasGraph(id = "default") {
|
|
12
12
|
const now = Date.now();
|
|
13
13
|
return {
|
|
14
14
|
id,
|
|
15
|
-
name: "
|
|
15
|
+
name: "开发 · 测试 · 人工验收",
|
|
16
16
|
viewport: { x: 50, y: 50, zoom: 1 },
|
|
17
17
|
status: "idle",
|
|
18
18
|
createdAt: now,
|
|
@@ -20,62 +20,61 @@ export function createDefaultCanvasGraph(id = "default") {
|
|
|
20
20
|
nodes: [
|
|
21
21
|
{
|
|
22
22
|
id: "node_architect",
|
|
23
|
-
title: "
|
|
24
|
-
role: "
|
|
23
|
+
title: "需求与验收条件",
|
|
24
|
+
role: "trigger",
|
|
25
25
|
x: 80,
|
|
26
26
|
y: 180,
|
|
27
27
|
width: 300,
|
|
28
28
|
engine: "pi",
|
|
29
|
-
model: "
|
|
29
|
+
model: "",
|
|
30
30
|
cwd: ".",
|
|
31
31
|
useWorktree: false,
|
|
32
|
-
|
|
33
|
-
instruction: "
|
|
32
|
+
config: { payload: "请填写任务目标、修改范围与验收条件,再运行流程。" },
|
|
33
|
+
instruction: "将任务目标与验收条件交接下游。",
|
|
34
34
|
status: "idle",
|
|
35
35
|
},
|
|
36
36
|
{
|
|
37
37
|
id: "node_fe",
|
|
38
|
-
title: "
|
|
38
|
+
title: "实现工程师",
|
|
39
39
|
role: "coder",
|
|
40
40
|
x: 480,
|
|
41
41
|
y: 60,
|
|
42
42
|
width: 300,
|
|
43
|
-
engine: "
|
|
44
|
-
model: "
|
|
45
|
-
cwd: "
|
|
46
|
-
useWorktree:
|
|
47
|
-
systemPromptOverride: "
|
|
48
|
-
instruction: "
|
|
43
|
+
engine: "pi",
|
|
44
|
+
model: "",
|
|
45
|
+
cwd: ".",
|
|
46
|
+
useWorktree: false,
|
|
47
|
+
systemPromptOverride: "根据任务与验收条件实现最小必要改动,检查现有约定并提供文件、验证命令和结果。",
|
|
48
|
+
instruction: "完成上游任务 {{上游摘要}},交付可验证的实现与完整证据。",
|
|
49
49
|
status: "idle",
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
52
|
id: "node_be",
|
|
53
|
-
title: "
|
|
54
|
-
role: "
|
|
55
|
-
x:
|
|
56
|
-
y:
|
|
53
|
+
title: "测试与代码审查",
|
|
54
|
+
role: "tester",
|
|
55
|
+
x: 880,
|
|
56
|
+
y: 180,
|
|
57
57
|
width: 300,
|
|
58
|
-
engine: "
|
|
59
|
-
model: "
|
|
60
|
-
cwd: "
|
|
61
|
-
useWorktree:
|
|
62
|
-
systemPromptOverride: "
|
|
63
|
-
instruction: "
|
|
58
|
+
engine: "pi",
|
|
59
|
+
model: "",
|
|
60
|
+
cwd: ".",
|
|
61
|
+
useWorktree: false,
|
|
62
|
+
systemPromptOverride: "审查实现,运行相关检查,明确记录通过、失败和未验证项。不得编造测试结果。",
|
|
63
|
+
instruction: "验证上游产物 {{上游摘要}},提供检查命令、结果和剩余风险交给人工验收。",
|
|
64
64
|
status: "idle",
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
67
|
id: "node_qa",
|
|
68
|
-
title: "
|
|
69
|
-
role: "
|
|
70
|
-
x:
|
|
68
|
+
title: "人工验收",
|
|
69
|
+
role: "human",
|
|
70
|
+
x: 1280,
|
|
71
71
|
y: 180,
|
|
72
72
|
width: 300,
|
|
73
|
-
engine: "
|
|
74
|
-
model: "
|
|
73
|
+
engine: "pi",
|
|
74
|
+
model: "",
|
|
75
75
|
cwd: ".",
|
|
76
76
|
useWorktree: false,
|
|
77
|
-
|
|
78
|
-
instruction: "运行测试套件并自动修复失败项,把验证结论交接归档。",
|
|
77
|
+
instruction: "检查实现与测试证据,批准完成或手动调整流程后重跑。",
|
|
79
78
|
status: "idle",
|
|
80
79
|
},
|
|
81
80
|
],
|
|
@@ -85,28 +84,21 @@ export function createDefaultCanvasGraph(id = "default") {
|
|
|
85
84
|
sourceNodeId: "node_architect",
|
|
86
85
|
targetNodeId: "node_fe",
|
|
87
86
|
type: "handoff",
|
|
88
|
-
label: "
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
id: "edge_arch_to_be",
|
|
92
|
-
sourceNodeId: "node_architect",
|
|
93
|
-
targetNodeId: "node_be",
|
|
94
|
-
type: "handoff",
|
|
95
|
-
label: "派发后端路由与数据契约",
|
|
87
|
+
label: "任务与验收条件",
|
|
96
88
|
},
|
|
97
89
|
{
|
|
98
|
-
id: "
|
|
90
|
+
id: "edge_fe_to_be",
|
|
99
91
|
sourceNodeId: "node_fe",
|
|
100
|
-
targetNodeId: "
|
|
92
|
+
targetNodeId: "node_be",
|
|
101
93
|
type: "handoff",
|
|
102
|
-
label: "
|
|
94
|
+
label: "实现与验证证据",
|
|
103
95
|
},
|
|
104
96
|
{
|
|
105
97
|
id: "edge_be_to_qa",
|
|
106
98
|
sourceNodeId: "node_be",
|
|
107
99
|
targetNodeId: "node_qa",
|
|
108
100
|
type: "handoff",
|
|
109
|
-
label: "
|
|
101
|
+
label: "检查结果与待验收产物",
|
|
110
102
|
},
|
|
111
103
|
],
|
|
112
104
|
};
|
|
@@ -190,16 +182,39 @@ export function saveCanvasGraph(dataDir, graph, opts) {
|
|
|
190
182
|
const dir = ensureCanvasDir(dataDir);
|
|
191
183
|
const path = join(dir, `${graph.id}.json`);
|
|
192
184
|
let diskRev = 0;
|
|
185
|
+
let disk;
|
|
193
186
|
if (existsSync(path)) {
|
|
194
187
|
try {
|
|
195
|
-
|
|
188
|
+
disk = JSON.parse(readFileSync(path, "utf8"));
|
|
189
|
+
diskRev = disk.rev ?? 0;
|
|
196
190
|
}
|
|
197
191
|
catch {
|
|
198
192
|
diskRev = 0;
|
|
199
193
|
}
|
|
200
194
|
}
|
|
201
195
|
if (opts?.expectedRev !== undefined && opts.expectedRev !== diskRev) {
|
|
202
|
-
return { conflict: true, graph:
|
|
196
|
+
return { conflict: true, graph: disk ?? graph };
|
|
197
|
+
}
|
|
198
|
+
if (disk) {
|
|
199
|
+
// Topology saves never replace authoritative execution state with a browser's stale snapshot.
|
|
200
|
+
graph.status = disk.status;
|
|
201
|
+
graph.run = disk.run;
|
|
202
|
+
const existingNodes = new Map(disk.nodes.map((node) => [node.id, node]));
|
|
203
|
+
for (const node of graph.nodes) {
|
|
204
|
+
const prior = existingNodes.get(node.id);
|
|
205
|
+
if (!prior)
|
|
206
|
+
continue;
|
|
207
|
+
for (const field of RUNTIME_FIELDS)
|
|
208
|
+
node[field] = prior[field];
|
|
209
|
+
}
|
|
210
|
+
const existingEdges = new Map(disk.edges.map((edge) => [edge.id, edge]));
|
|
211
|
+
for (const edge of graph.edges) {
|
|
212
|
+
const prior = existingEdges.get(edge.id);
|
|
213
|
+
if (!prior)
|
|
214
|
+
continue;
|
|
215
|
+
for (const field of ["lastHandoffSummary", "currentLoopCount", "runId", "active"])
|
|
216
|
+
edge[field] = prior[field];
|
|
217
|
+
}
|
|
203
218
|
}
|
|
204
219
|
graph.rev = diskRev + 1;
|
|
205
220
|
graph.updatedAt = Date.now();
|
|
@@ -210,22 +225,22 @@ const RUNTIME_FIELDS = [
|
|
|
210
225
|
"status",
|
|
211
226
|
"currentAction",
|
|
212
227
|
"lastOutputSummary",
|
|
213
|
-
"
|
|
214
|
-
"
|
|
215
|
-
"
|
|
216
|
-
"
|
|
228
|
+
"error",
|
|
229
|
+
"aiVerdict",
|
|
230
|
+
"runId",
|
|
231
|
+
"attempt",
|
|
232
|
+
"artifact",
|
|
233
|
+
"actualEngine",
|
|
234
|
+
"actualModel",
|
|
217
235
|
];
|
|
218
236
|
/** 运行态落盘:只合并运行字段,拓扑(nodes 增删/edges/坐标/指令)以磁盘版为准,防 stale 回滚(F1)。不推进 rev。 */
|
|
219
237
|
export function saveCanvasRuntimeState(dataDir, runtime) {
|
|
220
238
|
assertSafeGraphId(runtime.id);
|
|
221
239
|
const dir = ensureCanvasDir(dataDir);
|
|
222
240
|
const path = join(dir, `${runtime.id}.json`);
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
runtime.updatedAt = Date.now();
|
|
226
|
-
writeJsonAtomicSync(path, runtime);
|
|
241
|
+
// Runtime updates never create a graph: deletion is authoritative.
|
|
242
|
+
if (!existsSync(path))
|
|
227
243
|
return;
|
|
228
|
-
}
|
|
229
244
|
let disk;
|
|
230
245
|
try {
|
|
231
246
|
disk = JSON.parse(readFileSync(path, "utf8"));
|
|
@@ -241,12 +256,50 @@ export function saveCanvasRuntimeState(dataDir, runtime) {
|
|
|
241
256
|
for (const f of RUNTIME_FIELDS)
|
|
242
257
|
n[f] = r[f];
|
|
243
258
|
}
|
|
259
|
+
const runtimeEdges = new Map(runtime.edges.map((e) => [e.id, e]));
|
|
260
|
+
for (const edge of disk.edges) {
|
|
261
|
+
const source = runtimeEdges.get(edge.id);
|
|
262
|
+
if (!source)
|
|
263
|
+
continue;
|
|
264
|
+
for (const key of ["lastHandoffSummary", "currentLoopCount", "runId", "active"]) {
|
|
265
|
+
edge[key] = source[key];
|
|
266
|
+
}
|
|
267
|
+
}
|
|
244
268
|
disk.status = runtime.status;
|
|
269
|
+
disk.run = runtime.run;
|
|
245
270
|
disk.updatedAt = Date.now();
|
|
246
271
|
writeJsonAtomicSync(path, disk);
|
|
247
272
|
// 回填调用方,使广播带上最新 rev/拓扑
|
|
248
273
|
runtime.rev = disk.rev;
|
|
249
274
|
}
|
|
275
|
+
/** Called once when the server starts; persisted runs cannot still own a live engine session. */
|
|
276
|
+
export function markInterruptedCanvasRuns(dataDir) {
|
|
277
|
+
const dir = ensureCanvasDir(dataDir);
|
|
278
|
+
for (const file of readdirSync(dir).filter((name) => name.endsWith(".json"))) {
|
|
279
|
+
const path = join(dir, file);
|
|
280
|
+
try {
|
|
281
|
+
const graph = JSON.parse(readFileSync(path, "utf8"));
|
|
282
|
+
const interrupted = graph.status === "running" ||
|
|
283
|
+
graph.nodes?.some((node) => node.status === "running" || node.status === "queued");
|
|
284
|
+
if (!interrupted)
|
|
285
|
+
continue;
|
|
286
|
+
graph.status = "paused";
|
|
287
|
+
if (graph.run) {
|
|
288
|
+
graph.run.error = "Server restarted; the previous run was interrupted. Restart the run to continue.";
|
|
289
|
+
graph.run.finishedAt = Date.now();
|
|
290
|
+
}
|
|
291
|
+
for (const node of graph.nodes)
|
|
292
|
+
if (node.status === "running" || node.status === "queued") {
|
|
293
|
+
node.status = "paused";
|
|
294
|
+
node.currentAction = "Server restarted; run interrupted";
|
|
295
|
+
}
|
|
296
|
+
writeJsonAtomicSync(path, graph);
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
console.error(`[canvas] Could not recover ${file}:`, error);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
250
303
|
/** 删除画布工程 */
|
|
251
304
|
export function deleteCanvasGraph(dataDir, id) {
|
|
252
305
|
assertSafeGraphId(id);
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { isSafeGraphId } from "./canvas-store.js";
|
|
2
|
+
const roles = new Set([
|
|
3
|
+
"architect",
|
|
4
|
+
"coder",
|
|
5
|
+
"reviewer",
|
|
6
|
+
"tester",
|
|
7
|
+
"devops",
|
|
8
|
+
"custom",
|
|
9
|
+
"trigger",
|
|
10
|
+
"planner",
|
|
11
|
+
"researcher",
|
|
12
|
+
"writer",
|
|
13
|
+
"analyst",
|
|
14
|
+
"condition",
|
|
15
|
+
"ai_judge",
|
|
16
|
+
"loop",
|
|
17
|
+
"human",
|
|
18
|
+
"knowledge",
|
|
19
|
+
"tool",
|
|
20
|
+
"code",
|
|
21
|
+
"api",
|
|
22
|
+
"merge",
|
|
23
|
+
"memory",
|
|
24
|
+
"evaluator",
|
|
25
|
+
"end",
|
|
26
|
+
"subflow",
|
|
27
|
+
"cron",
|
|
28
|
+
"webhook",
|
|
29
|
+
"transform",
|
|
30
|
+
"pstack",
|
|
31
|
+
"skill",
|
|
32
|
+
]);
|
|
33
|
+
const engines = new Set(["pi", "dsh", "claude", "durable"]);
|
|
34
|
+
const edges = new Set([
|
|
35
|
+
"handoff",
|
|
36
|
+
"review",
|
|
37
|
+
"parallel",
|
|
38
|
+
"condition_true",
|
|
39
|
+
"condition_false",
|
|
40
|
+
"loop_back",
|
|
41
|
+
"approve",
|
|
42
|
+
"reject",
|
|
43
|
+
]);
|
|
44
|
+
const states = new Set([
|
|
45
|
+
"idle",
|
|
46
|
+
"queued",
|
|
47
|
+
"running",
|
|
48
|
+
"waiting_approval",
|
|
49
|
+
"done",
|
|
50
|
+
"error",
|
|
51
|
+
"paused",
|
|
52
|
+
"skipped",
|
|
53
|
+
"cancelled",
|
|
54
|
+
]);
|
|
55
|
+
/** Validate untrusted graphs before rendering, persisting, or dispatching work. */
|
|
56
|
+
export function assertCanvasGraph(value) {
|
|
57
|
+
if (!value || typeof value !== "object")
|
|
58
|
+
throw new Error("Invalid canvas graph");
|
|
59
|
+
const g = value;
|
|
60
|
+
if (!isSafeGraphId(g.id) || typeof g.name !== "string" || g.name.length > 300)
|
|
61
|
+
throw new Error("Invalid canvas id or name");
|
|
62
|
+
if (!Array.isArray(g.nodes) || !Array.isArray(g.edges) || g.nodes.length > 200 || g.edges.length > 1000)
|
|
63
|
+
throw new Error("Canvas supports up to 200 nodes and 1000 edges");
|
|
64
|
+
if (!g.viewport || ![g.viewport.x, g.viewport.y, g.viewport.zoom].every(Number.isFinite) || g.viewport.zoom <= 0)
|
|
65
|
+
throw new Error("Invalid canvas viewport");
|
|
66
|
+
const ids = new Set();
|
|
67
|
+
for (const n of g.nodes) {
|
|
68
|
+
if (!n || !isSafeGraphId(n.id) || ids.has(n.id))
|
|
69
|
+
throw new Error("Invalid or duplicate canvas node id");
|
|
70
|
+
ids.add(n.id);
|
|
71
|
+
if (typeof n.title !== "string" || !roles.has(n.role) || !engines.has(n.engine) || !states.has(n.status))
|
|
72
|
+
throw new Error(`Invalid node ${n.id}`);
|
|
73
|
+
if (typeof n.cwd !== "string" ||
|
|
74
|
+
typeof n.model !== "string" ||
|
|
75
|
+
typeof n.useWorktree !== "boolean" ||
|
|
76
|
+
![n.x, n.y].every(Number.isFinite))
|
|
77
|
+
throw new Error(`Invalid node configuration: ${n.id}`);
|
|
78
|
+
if (n.config &&
|
|
79
|
+
(typeof n.config !== "object" ||
|
|
80
|
+
Array.isArray(n.config) ||
|
|
81
|
+
Object.values(n.config).some((v) => v !== undefined && !["string", "number", "boolean"].includes(typeof v))))
|
|
82
|
+
throw new Error(`Invalid node parameters: ${n.id}`);
|
|
83
|
+
for (const key of ["instruction", "systemPromptOverride"])
|
|
84
|
+
if (n[key] !== undefined && typeof n[key] !== "string")
|
|
85
|
+
throw new Error(`Invalid node instruction: ${n.id}`);
|
|
86
|
+
}
|
|
87
|
+
const edgeIds = new Set();
|
|
88
|
+
const connections = new Set();
|
|
89
|
+
const forward = new Map(g.nodes.map((node) => [node.id, []]));
|
|
90
|
+
const indegree = new Map(g.nodes.map((node) => [node.id, 0]));
|
|
91
|
+
for (const e of g.edges) {
|
|
92
|
+
if (!e ||
|
|
93
|
+
!isSafeGraphId(e.id) ||
|
|
94
|
+
edgeIds.has(e.id) ||
|
|
95
|
+
!ids.has(e.sourceNodeId) ||
|
|
96
|
+
!ids.has(e.targetNodeId) ||
|
|
97
|
+
e.sourceNodeId === e.targetNodeId ||
|
|
98
|
+
!edges.has(e.type))
|
|
99
|
+
throw new Error("Invalid or duplicate canvas edge");
|
|
100
|
+
edgeIds.add(e.id);
|
|
101
|
+
const connection = JSON.stringify([
|
|
102
|
+
e.sourceNodeId,
|
|
103
|
+
e.targetNodeId,
|
|
104
|
+
e.type,
|
|
105
|
+
e.sourcePort ?? "result",
|
|
106
|
+
e.targetPort ?? "contract",
|
|
107
|
+
]);
|
|
108
|
+
if (connections.has(connection))
|
|
109
|
+
throw new Error("Duplicate canvas connection");
|
|
110
|
+
connections.add(connection);
|
|
111
|
+
if (!["reject", "review", "loop_back"].includes(e.type)) {
|
|
112
|
+
forward.get(e.sourceNodeId).push(e.targetNodeId);
|
|
113
|
+
indegree.set(e.targetNodeId, indegree.get(e.targetNodeId) + 1);
|
|
114
|
+
}
|
|
115
|
+
if (e.maxLoopRetries !== undefined &&
|
|
116
|
+
(!Number.isInteger(e.maxLoopRetries) || e.maxLoopRetries < 0 || e.maxLoopRetries > 20))
|
|
117
|
+
throw new Error("Loop retry limit must be between 0 and 20");
|
|
118
|
+
}
|
|
119
|
+
const queue = [...indegree].filter(([, degree]) => degree === 0).map(([id]) => id);
|
|
120
|
+
let visited = 0;
|
|
121
|
+
for (let index = 0; index < queue.length; index++) {
|
|
122
|
+
visited++;
|
|
123
|
+
for (const next of forward.get(queue[index])) {
|
|
124
|
+
indegree.set(next, indegree.get(next) - 1);
|
|
125
|
+
if (indegree.get(next) === 0)
|
|
126
|
+
queue.push(next);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (visited !== g.nodes.length)
|
|
130
|
+
throw new Error("Canvas forward edges contain a cycle; use an explicit bounded reject/review edge");
|
|
131
|
+
}
|