scope-agent-workbench 0.2.0 → 0.2.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.
- package/CHANGELOG.md +41 -0
- package/bridge/agent-email-relay.mjs +160 -160
- package/bridge/app-server-websocket-transport.mjs +219 -219
- package/bridge/archive/service.mjs +130 -130
- package/bridge/auth-profile-failover.mjs +58 -58
- package/bridge/auth-profile-manager.mjs +215 -215
- package/bridge/capacity-recovery.mjs +90 -90
- package/bridge/gpu-usage-history.mjs +322 -322
- package/bridge/local/history.mjs +20 -5
- package/bridge/plugins/aliyun-dlc/monitor.mjs +236 -236
- package/bridge/plugins/aliyun-dlc/probe.mjs +701 -701
- package/bridge/private-gateway.mjs +371 -371
- package/bridge/private-start.mjs +22 -22
- package/bridge/probes/app-server-handoff-probe.mjs +87 -87
- package/bridge/probes/app-server-writer-probe.mjs +69 -69
- package/bridge/probes/assistant-search-probe.mjs +321 -321
- package/bridge/probes/dialogue-probe.mjs +462 -462
- package/bridge/probes/history-probe.mjs +430 -345
- package/bridge/probes/new-session-preflight.mjs +14 -14
- package/bridge/probes/profile-cancel-probe.mjs +17 -17
- package/bridge/probes/profile-delete-probe.mjs +26 -26
- package/bridge/probes/profile-list-probe.mjs +114 -114
- package/bridge/probes/profile-write-probe.mjs +109 -109
- package/bridge/probes/raw-context-probe.mjs +51 -51
- package/bridge/probes/remote-probe.mjs +627 -626
- package/bridge/probes/submission-probe.mjs +2 -2
- package/bridge/probes/takeover-probe.mjs +326 -326
- package/bridge/probes/vscode-open-preflight.mjs +21 -21
- package/bridge/providers/claude-interactive.py +463 -341
- package/bridge/providers/cli-command.mjs +103 -103
- package/bridge/providers/conversations.mjs +231 -231
- package/bridge/providers/native-commands.py +38 -38
- package/bridge/providers/native-session-state.mjs +14 -14
- package/bridge/providers/native-session-state.py +96 -96
- package/bridge/providers/remote-job.py +130 -130
- package/bridge/remote-app-server-command.mjs +121 -121
- package/bridge/remote-directory-listing.mjs +148 -148
- package/bridge/rollout-summary.mjs +20 -2
- package/bridge/routes/dialogue.mjs +48 -3
- package/bridge/routes/models.mjs +312 -312
- package/bridge/server.mjs +3357 -3332
- package/bridge/session-attachments.mjs +150 -150
- package/bridge/session-catalog/agy-history.py +141 -2
- package/bridge/session-catalog/catalog.mjs +17 -0
- package/bridge/session-catalog/probe.py +1207 -331
- package/bridge/session-catalog/routes.mjs +6 -0
- package/bridge/start.mjs +205 -205
- package/bridge/state-persistence.mjs +9 -1
- package/bridge/tmux-session-control.mjs +29 -29
- package/bridge/vscode-opener.mjs +157 -157
- package/bridge/web-terminal.mjs +52 -52
- package/bridge/workbench/manager-context.mjs +51 -51
- package/bridge/workbench/service.mjs +301 -301
- package/dist/client/.vite/manifest.json +4 -4
- package/dist/client/assets/{index-Enu1x0PS.js → index-BMior55c.js} +2 -2
- package/dist/client/assets/{layout-segment-context-CmJzExWq.js → layout-segment-context-DjGudgXn.js} +1 -1
- package/dist/client/assets/page-CJqXlhDs.js +551 -0
- package/dist/client/assets/page-LYzRz6_S.css +1 -0
- package/dist/client/favicon.svg +6 -6
- package/dist/server/__vite_rsc_assets_manifest.js +8 -8
- package/dist/server/index.js +7 -7
- package/dist/server/ssr/__vite_rsc_assets_manifest.js +8 -8
- package/dist/server/ssr/assets/{page-CYYyCnKD.js → page-BB9Dri2u.js} +2416 -271
- package/dist/server/ssr/assets/page-LYzRz6_S.css +1 -0
- package/dist/server/ssr/index.js +1 -1
- package/dist/server/ssr/vinext-server.json +1 -1
- package/dist/server/vinext-server.json +1 -1
- package/dist/server/wrangler.json +1 -1
- package/lib/browser-snapshot-cache.js +53 -53
- package/lib/formula-preview.js +1 -1
- package/lib/incremental-snapshot.js +300 -300
- package/lib/markdown-math.js +151 -151
- package/lib/remote-links.js +95 -95
- package/lib/runtime-config.js +70 -70
- package/lib/session-filters.js +38 -38
- package/lib/ssh-config.js +26 -26
- package/lib/stable-order.js +39 -39
- package/lib/subagent-display-prefs.ts +130 -0
- package/package.json +1 -1
- package/scripts/agent-email-relay.mjs +104 -104
- package/scripts/email-notification-cli.mjs +28 -28
- package/scripts/enable-private-access.ps1 +109 -109
- package/scripts/fixtures/native-conversations.mjs +164 -6
- package/scripts/fixtures/workbench-conversations.mjs +475 -352
- package/scripts/preview-workbench.mjs +669 -669
- package/dist/client/assets/page-COBv6VWj.css +0 -1
- package/dist/client/assets/page-DVjU6VG_.js +0 -550
- package/dist/server/ssr/assets/page-COBv6VWj.css +0 -1
package/bridge/local/history.mjs
CHANGED
|
@@ -4,18 +4,33 @@ import { readLocalDialogue } from "./dialogue.mjs";
|
|
|
4
4
|
|
|
5
5
|
export function localHistoryReader({ manager, findRollout, run = runLocalPython }) {
|
|
6
6
|
return async (body) => {
|
|
7
|
-
|
|
7
|
+
const subagentId = typeof body.subagentId === "string" ? body.subagentId.trim() : "";
|
|
8
|
+
if (!subagentId && manager.sessionRecords().some(record => record.host === body.host && record.sessionId === body.sessionId)) {
|
|
8
9
|
return readLocalDialogue(manager, body.host, body.sessionId, body);
|
|
9
10
|
}
|
|
10
11
|
// Only use a server-discovered path, never a path supplied in the request.
|
|
11
|
-
const rollout = findRollout(body.host, body.sessionId);
|
|
12
|
-
if (!rollout?.path) throw new Error("未找到本机会话历史,请刷新会话扫描");
|
|
13
|
-
const limit = Math.max(1, Math.min(100, Number(body.limit) || 10));
|
|
12
|
+
const rollout = findRollout(body.host, body.sessionId, subagentId);
|
|
13
|
+
if (!rollout?.path) throw new Error(subagentId ? "未找到对应的子代理 rollout" : "未找到本机会话历史,请刷新会话扫描");
|
|
14
|
+
const limit = Math.max(1, Math.min(100, Number(body.limit) || (subagentId ? 40 : 10)));
|
|
14
15
|
const before = body.before != null && body.before !== "" && Number.isFinite(Number(body.before))
|
|
15
16
|
? String(Math.max(0, Math.floor(Number(body.before)))) : "";
|
|
16
17
|
const result = await run(DIALOGUE_PROBE,
|
|
17
18
|
[rollout.path, String(limit), before, body.dialogueOnly ? "dialogue-only" : "full"], 30_000, 5_000_000);
|
|
18
19
|
if (result.code !== 0) throw new Error(result.stderr || "本机会话历史读取失败");
|
|
19
|
-
|
|
20
|
+
const parsed = JSON.parse(result.stdout);
|
|
21
|
+
if (!subagentId) return parsed;
|
|
22
|
+
return {
|
|
23
|
+
...parsed,
|
|
24
|
+
subagent: {
|
|
25
|
+
id: rollout.id,
|
|
26
|
+
agentNickname: rollout.agentNickname || "",
|
|
27
|
+
agentPath: rollout.agentPath || "",
|
|
28
|
+
agentRole: rollout.agentRole || "",
|
|
29
|
+
model: rollout.model || "",
|
|
30
|
+
turnState: rollout.turnState || "idle",
|
|
31
|
+
lastAction: rollout.lastAction || "",
|
|
32
|
+
lastEventAt: rollout.lastEventAt || null,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
20
35
|
};
|
|
21
36
|
}
|
|
@@ -1,236 +1,236 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { SUBMISSION_PROBE } from "./probe.mjs";
|
|
3
|
-
|
|
4
|
-
/** Read-only Aliyun scanner; all host access is injected by the trusted host. */
|
|
5
|
-
export function createSubmissionMonitor({ settings, context, notify, onScanComplete, defaultWindowDays }) {
|
|
6
|
-
let submissionScanPromise = null;
|
|
7
|
-
const empty = () => ({ scannedAt: null, scanning: false, windowDays: defaultWindowDays,
|
|
8
|
-
targetHostname: settings().enabled ? settings().host : "", items: [], calls: [], launches: [], alerts: [], hosts: [], error: null });
|
|
9
|
-
let submissionTracker = empty();
|
|
10
|
-
async function scan(
|
|
11
|
-
limit = 100,
|
|
12
|
-
windowDays = defaultWindowDays,
|
|
13
|
-
) {
|
|
14
|
-
const DLC_SSH_HOSTNAME = settings().enabled ? settings().host : "";
|
|
15
|
-
const { readSshConfig, sshAliasesForHostname, getSnapshot, runSshCommand, cleanSshError, mapLimit, findAgent, getManagement, sessionKey, heuristicSummary } = context();
|
|
16
|
-
if (!DLC_SSH_HOSTNAME) return submissionTracker;
|
|
17
|
-
if (submissionScanPromise) return submissionScanPromise;
|
|
18
|
-
submissionScanPromise = (async () => {
|
|
19
|
-
submissionTracker = {
|
|
20
|
-
...submissionTracker,
|
|
21
|
-
scanning: true,
|
|
22
|
-
error: null,
|
|
23
|
-
};
|
|
24
|
-
notify();
|
|
25
|
-
let dlcAliases = new Set([DLC_SSH_HOSTNAME]);
|
|
26
|
-
try {
|
|
27
|
-
dlcAliases = sshAliasesForHostname(
|
|
28
|
-
await readSshConfig(),
|
|
29
|
-
DLC_SSH_HOSTNAME,
|
|
30
|
-
);
|
|
31
|
-
} catch {
|
|
32
|
-
// The inventory already reports a config read failure. Keep the literal
|
|
33
|
-
// DLC host as a conservative fallback instead of scanning unrelated hosts.
|
|
34
|
-
}
|
|
35
|
-
const normalizedWindowDays = Math.max(
|
|
36
|
-
0,
|
|
37
|
-
Math.min(3650, Number(windowDays) || 0),
|
|
38
|
-
);
|
|
39
|
-
const targets = getSnapshot().hosts.filter(
|
|
40
|
-
(host) => host.reachable && dlcAliases.has(host.alias),
|
|
41
|
-
);
|
|
42
|
-
if (!targets.length) {
|
|
43
|
-
submissionTracker = {
|
|
44
|
-
...submissionTracker,
|
|
45
|
-
scanning: false,
|
|
46
|
-
targetHostname: DLC_SSH_HOSTNAME,
|
|
47
|
-
error: `当前没有指向 ${DLC_SSH_HOSTNAME} 的可连接 SSH 主机`,
|
|
48
|
-
};
|
|
49
|
-
notify();
|
|
50
|
-
return submissionTracker;
|
|
51
|
-
}
|
|
52
|
-
const scans = await mapLimit(
|
|
53
|
-
targets,
|
|
54
|
-
Math.min(4, targets.length),
|
|
55
|
-
async (host) => {
|
|
56
|
-
const result = await runSshCommand(
|
|
57
|
-
host.alias,
|
|
58
|
-
`python3 - ${Math.max(20, Math.min(500, limit))} ${normalizedWindowDays}`,
|
|
59
|
-
SUBMISSION_PROBE,
|
|
60
|
-
75_000,
|
|
61
|
-
12_000_000,
|
|
62
|
-
);
|
|
63
|
-
if (result.code !== 0) {
|
|
64
|
-
return {
|
|
65
|
-
host: host.alias,
|
|
66
|
-
filesScanned: 0,
|
|
67
|
-
totalFiles: 0,
|
|
68
|
-
submissions: [],
|
|
69
|
-
calls: [],
|
|
70
|
-
launches: [],
|
|
71
|
-
error: cleanSshError(result.stderr || result.stdout),
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
try {
|
|
75
|
-
return {
|
|
76
|
-
host: host.alias,
|
|
77
|
-
...JSON.parse(result.stdout.trim()),
|
|
78
|
-
error: null,
|
|
79
|
-
};
|
|
80
|
-
} catch {
|
|
81
|
-
return {
|
|
82
|
-
host: host.alias,
|
|
83
|
-
filesScanned: 0,
|
|
84
|
-
totalFiles: 0,
|
|
85
|
-
submissions: [],
|
|
86
|
-
calls: [],
|
|
87
|
-
launches: [],
|
|
88
|
-
error: "提交追踪结果无法解析",
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
);
|
|
93
|
-
const evidenceOwner = (hostAlias, evidence) => {
|
|
94
|
-
const host = getSnapshot().hosts.find(
|
|
95
|
-
(candidate) => candidate.alias === hostAlias,
|
|
96
|
-
);
|
|
97
|
-
const directAgent = findAgent(hostAlias, evidence.sessionId);
|
|
98
|
-
const parentAgent = host?.agents.find((agent) =>
|
|
99
|
-
(agent.subagents || []).some(
|
|
100
|
-
(subagent) => subagent.id === evidence.sessionId,
|
|
101
|
-
),
|
|
102
|
-
);
|
|
103
|
-
const activeAgent = directAgent || parentAgent || null;
|
|
104
|
-
const rollout = host?.sessions.find(
|
|
105
|
-
(session) => session.id === evidence.sessionId,
|
|
106
|
-
);
|
|
107
|
-
const managed =
|
|
108
|
-
getManagement().sessions[sessionKey(hostAlias, evidence.sessionId)] ||
|
|
109
|
-
(evidence.parentThreadId
|
|
110
|
-
? getManagement().sessions[
|
|
111
|
-
sessionKey(hostAlias, evidence.parentThreadId)
|
|
112
|
-
] || {}
|
|
113
|
-
: {});
|
|
114
|
-
const theme =
|
|
115
|
-
managed.displayName ||
|
|
116
|
-
managed.summary?.theme ||
|
|
117
|
-
(rollout ? heuristicSummary(rollout, evidence.cwd).theme : "") ||
|
|
118
|
-
evidence.sessionObjective ||
|
|
119
|
-
`${path.posix.basename(evidence.cwd || "") || "未命名"} Session`;
|
|
120
|
-
return {
|
|
121
|
-
active: Boolean(activeAgent),
|
|
122
|
-
sessionTheme: evidence.isSubagent ? `${theme} · subagent` : theme,
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
const items = scans
|
|
126
|
-
.flatMap((scan) =>
|
|
127
|
-
scan.submissions.map((item) => {
|
|
128
|
-
return {
|
|
129
|
-
...item,
|
|
130
|
-
host: scan.host,
|
|
131
|
-
...evidenceOwner(scan.host, item),
|
|
132
|
-
};
|
|
133
|
-
}),
|
|
134
|
-
)
|
|
135
|
-
.sort(
|
|
136
|
-
(a, b) =>
|
|
137
|
-
Date.parse(b.submittedAt || "") - Date.parse(a.submittedAt || ""),
|
|
138
|
-
);
|
|
139
|
-
const calls = scans
|
|
140
|
-
.flatMap((scan) =>
|
|
141
|
-
(scan.calls || []).map((call) => ({
|
|
142
|
-
...call,
|
|
143
|
-
host: scan.host,
|
|
144
|
-
...evidenceOwner(scan.host, call),
|
|
145
|
-
})),
|
|
146
|
-
)
|
|
147
|
-
.sort(
|
|
148
|
-
(a, b) =>
|
|
149
|
-
Date.parse(b.timestamp || "") - Date.parse(a.timestamp || ""),
|
|
150
|
-
);
|
|
151
|
-
const launches = scans
|
|
152
|
-
.flatMap((scan) =>
|
|
153
|
-
scan.launches.map((launch) => ({ ...launch, host: scan.host })),
|
|
154
|
-
)
|
|
155
|
-
.sort(
|
|
156
|
-
(a, b) =>
|
|
157
|
-
Date.parse(b.timestamp || "") - Date.parse(a.timestamp || ""),
|
|
158
|
-
);
|
|
159
|
-
const grouped = new Map();
|
|
160
|
-
for (const item of items) {
|
|
161
|
-
if (item.ownershipSource !== "tool-call") continue;
|
|
162
|
-
const key = `${item.host}:${item.sessionId}`;
|
|
163
|
-
const group = grouped.get(key) || {
|
|
164
|
-
host: item.host,
|
|
165
|
-
sessionId: item.sessionId,
|
|
166
|
-
sessionTheme: item.sessionTheme,
|
|
167
|
-
cwd: item.cwd,
|
|
168
|
-
total: 0,
|
|
169
|
-
failed: 0,
|
|
170
|
-
queued: 0,
|
|
171
|
-
running: 0,
|
|
172
|
-
};
|
|
173
|
-
group.total += 1;
|
|
174
|
-
if (/fail|fault|stopp|cancel|kill/i.test(item.status || "")) {
|
|
175
|
-
group.failed += 1;
|
|
176
|
-
}
|
|
177
|
-
if (/queu|enqueued|pending/i.test(item.status || "")) group.queued += 1;
|
|
178
|
-
if (/running/i.test(item.status || "")) group.running += 1;
|
|
179
|
-
grouped.set(key, group);
|
|
180
|
-
}
|
|
181
|
-
const alerts = Array.from(grouped.values())
|
|
182
|
-
.filter(
|
|
183
|
-
(group) =>
|
|
184
|
-
(group.failed >= 2 && group.queued > 0) ||
|
|
185
|
-
(group.total >= 4 && group.failed / group.total >= 0.75),
|
|
186
|
-
)
|
|
187
|
-
.sort((a, b) => b.failed - a.failed);
|
|
188
|
-
submissionTracker = {
|
|
189
|
-
scannedAt: new Date().toISOString(),
|
|
190
|
-
scanning: false,
|
|
191
|
-
windowDays: normalizedWindowDays,
|
|
192
|
-
targetHostname: DLC_SSH_HOSTNAME,
|
|
193
|
-
items,
|
|
194
|
-
calls,
|
|
195
|
-
launches,
|
|
196
|
-
alerts,
|
|
197
|
-
hosts: scans.map(
|
|
198
|
-
({
|
|
199
|
-
submissions,
|
|
200
|
-
calls: hostCalls = [],
|
|
201
|
-
launches: hostLaunches,
|
|
202
|
-
...scan
|
|
203
|
-
}) => ({
|
|
204
|
-
...scan,
|
|
205
|
-
submissions: submissions.length,
|
|
206
|
-
calls: hostCalls.length,
|
|
207
|
-
launches: hostLaunches.length,
|
|
208
|
-
}),
|
|
209
|
-
),
|
|
210
|
-
error:
|
|
211
|
-
scans.every((scan) => scan.error) && scans.length
|
|
212
|
-
? "所有在线主机的提交扫描都失败"
|
|
213
|
-
: null,
|
|
214
|
-
};
|
|
215
|
-
await onScanComplete(submissionTracker);
|
|
216
|
-
notify();
|
|
217
|
-
return submissionTracker;
|
|
218
|
-
})()
|
|
219
|
-
.catch((error) => {
|
|
220
|
-
submissionTracker = {
|
|
221
|
-
...submissionTracker,
|
|
222
|
-
scanning: false,
|
|
223
|
-
error: error.message,
|
|
224
|
-
};
|
|
225
|
-
notify();
|
|
226
|
-
return submissionTracker;
|
|
227
|
-
})
|
|
228
|
-
.finally(() => {
|
|
229
|
-
submissionScanPromise = null;
|
|
230
|
-
});
|
|
231
|
-
return submissionScanPromise;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
return { scan, busy: () => Boolean(submissionScanPromise), snapshot: () => submissionTracker,
|
|
235
|
-
reset() { if (submissionScanPromise) throw new Error("等待扫描结束后修改配置"); submissionTracker = empty(); } };
|
|
236
|
-
}
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { SUBMISSION_PROBE } from "./probe.mjs";
|
|
3
|
+
|
|
4
|
+
/** Read-only Aliyun scanner; all host access is injected by the trusted host. */
|
|
5
|
+
export function createSubmissionMonitor({ settings, context, notify, onScanComplete, defaultWindowDays }) {
|
|
6
|
+
let submissionScanPromise = null;
|
|
7
|
+
const empty = () => ({ scannedAt: null, scanning: false, windowDays: defaultWindowDays,
|
|
8
|
+
targetHostname: settings().enabled ? settings().host : "", items: [], calls: [], launches: [], alerts: [], hosts: [], error: null });
|
|
9
|
+
let submissionTracker = empty();
|
|
10
|
+
async function scan(
|
|
11
|
+
limit = 100,
|
|
12
|
+
windowDays = defaultWindowDays,
|
|
13
|
+
) {
|
|
14
|
+
const DLC_SSH_HOSTNAME = settings().enabled ? settings().host : "";
|
|
15
|
+
const { readSshConfig, sshAliasesForHostname, getSnapshot, runSshCommand, cleanSshError, mapLimit, findAgent, getManagement, sessionKey, heuristicSummary } = context();
|
|
16
|
+
if (!DLC_SSH_HOSTNAME) return submissionTracker;
|
|
17
|
+
if (submissionScanPromise) return submissionScanPromise;
|
|
18
|
+
submissionScanPromise = (async () => {
|
|
19
|
+
submissionTracker = {
|
|
20
|
+
...submissionTracker,
|
|
21
|
+
scanning: true,
|
|
22
|
+
error: null,
|
|
23
|
+
};
|
|
24
|
+
notify();
|
|
25
|
+
let dlcAliases = new Set([DLC_SSH_HOSTNAME]);
|
|
26
|
+
try {
|
|
27
|
+
dlcAliases = sshAliasesForHostname(
|
|
28
|
+
await readSshConfig(),
|
|
29
|
+
DLC_SSH_HOSTNAME,
|
|
30
|
+
);
|
|
31
|
+
} catch {
|
|
32
|
+
// The inventory already reports a config read failure. Keep the literal
|
|
33
|
+
// DLC host as a conservative fallback instead of scanning unrelated hosts.
|
|
34
|
+
}
|
|
35
|
+
const normalizedWindowDays = Math.max(
|
|
36
|
+
0,
|
|
37
|
+
Math.min(3650, Number(windowDays) || 0),
|
|
38
|
+
);
|
|
39
|
+
const targets = getSnapshot().hosts.filter(
|
|
40
|
+
(host) => host.reachable && dlcAliases.has(host.alias),
|
|
41
|
+
);
|
|
42
|
+
if (!targets.length) {
|
|
43
|
+
submissionTracker = {
|
|
44
|
+
...submissionTracker,
|
|
45
|
+
scanning: false,
|
|
46
|
+
targetHostname: DLC_SSH_HOSTNAME,
|
|
47
|
+
error: `当前没有指向 ${DLC_SSH_HOSTNAME} 的可连接 SSH 主机`,
|
|
48
|
+
};
|
|
49
|
+
notify();
|
|
50
|
+
return submissionTracker;
|
|
51
|
+
}
|
|
52
|
+
const scans = await mapLimit(
|
|
53
|
+
targets,
|
|
54
|
+
Math.min(4, targets.length),
|
|
55
|
+
async (host) => {
|
|
56
|
+
const result = await runSshCommand(
|
|
57
|
+
host.alias,
|
|
58
|
+
`python3 - ${Math.max(20, Math.min(500, limit))} ${normalizedWindowDays}`,
|
|
59
|
+
SUBMISSION_PROBE,
|
|
60
|
+
75_000,
|
|
61
|
+
12_000_000,
|
|
62
|
+
);
|
|
63
|
+
if (result.code !== 0) {
|
|
64
|
+
return {
|
|
65
|
+
host: host.alias,
|
|
66
|
+
filesScanned: 0,
|
|
67
|
+
totalFiles: 0,
|
|
68
|
+
submissions: [],
|
|
69
|
+
calls: [],
|
|
70
|
+
launches: [],
|
|
71
|
+
error: cleanSshError(result.stderr || result.stdout),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
return {
|
|
76
|
+
host: host.alias,
|
|
77
|
+
...JSON.parse(result.stdout.trim()),
|
|
78
|
+
error: null,
|
|
79
|
+
};
|
|
80
|
+
} catch {
|
|
81
|
+
return {
|
|
82
|
+
host: host.alias,
|
|
83
|
+
filesScanned: 0,
|
|
84
|
+
totalFiles: 0,
|
|
85
|
+
submissions: [],
|
|
86
|
+
calls: [],
|
|
87
|
+
launches: [],
|
|
88
|
+
error: "提交追踪结果无法解析",
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
);
|
|
93
|
+
const evidenceOwner = (hostAlias, evidence) => {
|
|
94
|
+
const host = getSnapshot().hosts.find(
|
|
95
|
+
(candidate) => candidate.alias === hostAlias,
|
|
96
|
+
);
|
|
97
|
+
const directAgent = findAgent(hostAlias, evidence.sessionId);
|
|
98
|
+
const parentAgent = host?.agents.find((agent) =>
|
|
99
|
+
(agent.subagents || []).some(
|
|
100
|
+
(subagent) => subagent.id === evidence.sessionId,
|
|
101
|
+
),
|
|
102
|
+
);
|
|
103
|
+
const activeAgent = directAgent || parentAgent || null;
|
|
104
|
+
const rollout = host?.sessions.find(
|
|
105
|
+
(session) => session.id === evidence.sessionId,
|
|
106
|
+
);
|
|
107
|
+
const managed =
|
|
108
|
+
getManagement().sessions[sessionKey(hostAlias, evidence.sessionId)] ||
|
|
109
|
+
(evidence.parentThreadId
|
|
110
|
+
? getManagement().sessions[
|
|
111
|
+
sessionKey(hostAlias, evidence.parentThreadId)
|
|
112
|
+
] || {}
|
|
113
|
+
: {});
|
|
114
|
+
const theme =
|
|
115
|
+
managed.displayName ||
|
|
116
|
+
managed.summary?.theme ||
|
|
117
|
+
(rollout ? heuristicSummary(rollout, evidence.cwd).theme : "") ||
|
|
118
|
+
evidence.sessionObjective ||
|
|
119
|
+
`${path.posix.basename(evidence.cwd || "") || "未命名"} Session`;
|
|
120
|
+
return {
|
|
121
|
+
active: Boolean(activeAgent),
|
|
122
|
+
sessionTheme: evidence.isSubagent ? `${theme} · subagent` : theme,
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
const items = scans
|
|
126
|
+
.flatMap((scan) =>
|
|
127
|
+
scan.submissions.map((item) => {
|
|
128
|
+
return {
|
|
129
|
+
...item,
|
|
130
|
+
host: scan.host,
|
|
131
|
+
...evidenceOwner(scan.host, item),
|
|
132
|
+
};
|
|
133
|
+
}),
|
|
134
|
+
)
|
|
135
|
+
.sort(
|
|
136
|
+
(a, b) =>
|
|
137
|
+
Date.parse(b.submittedAt || "") - Date.parse(a.submittedAt || ""),
|
|
138
|
+
);
|
|
139
|
+
const calls = scans
|
|
140
|
+
.flatMap((scan) =>
|
|
141
|
+
(scan.calls || []).map((call) => ({
|
|
142
|
+
...call,
|
|
143
|
+
host: scan.host,
|
|
144
|
+
...evidenceOwner(scan.host, call),
|
|
145
|
+
})),
|
|
146
|
+
)
|
|
147
|
+
.sort(
|
|
148
|
+
(a, b) =>
|
|
149
|
+
Date.parse(b.timestamp || "") - Date.parse(a.timestamp || ""),
|
|
150
|
+
);
|
|
151
|
+
const launches = scans
|
|
152
|
+
.flatMap((scan) =>
|
|
153
|
+
scan.launches.map((launch) => ({ ...launch, host: scan.host })),
|
|
154
|
+
)
|
|
155
|
+
.sort(
|
|
156
|
+
(a, b) =>
|
|
157
|
+
Date.parse(b.timestamp || "") - Date.parse(a.timestamp || ""),
|
|
158
|
+
);
|
|
159
|
+
const grouped = new Map();
|
|
160
|
+
for (const item of items) {
|
|
161
|
+
if (item.ownershipSource !== "tool-call") continue;
|
|
162
|
+
const key = `${item.host}:${item.sessionId}`;
|
|
163
|
+
const group = grouped.get(key) || {
|
|
164
|
+
host: item.host,
|
|
165
|
+
sessionId: item.sessionId,
|
|
166
|
+
sessionTheme: item.sessionTheme,
|
|
167
|
+
cwd: item.cwd,
|
|
168
|
+
total: 0,
|
|
169
|
+
failed: 0,
|
|
170
|
+
queued: 0,
|
|
171
|
+
running: 0,
|
|
172
|
+
};
|
|
173
|
+
group.total += 1;
|
|
174
|
+
if (/fail|fault|stopp|cancel|kill/i.test(item.status || "")) {
|
|
175
|
+
group.failed += 1;
|
|
176
|
+
}
|
|
177
|
+
if (/queu|enqueued|pending/i.test(item.status || "")) group.queued += 1;
|
|
178
|
+
if (/running/i.test(item.status || "")) group.running += 1;
|
|
179
|
+
grouped.set(key, group);
|
|
180
|
+
}
|
|
181
|
+
const alerts = Array.from(grouped.values())
|
|
182
|
+
.filter(
|
|
183
|
+
(group) =>
|
|
184
|
+
(group.failed >= 2 && group.queued > 0) ||
|
|
185
|
+
(group.total >= 4 && group.failed / group.total >= 0.75),
|
|
186
|
+
)
|
|
187
|
+
.sort((a, b) => b.failed - a.failed);
|
|
188
|
+
submissionTracker = {
|
|
189
|
+
scannedAt: new Date().toISOString(),
|
|
190
|
+
scanning: false,
|
|
191
|
+
windowDays: normalizedWindowDays,
|
|
192
|
+
targetHostname: DLC_SSH_HOSTNAME,
|
|
193
|
+
items,
|
|
194
|
+
calls,
|
|
195
|
+
launches,
|
|
196
|
+
alerts,
|
|
197
|
+
hosts: scans.map(
|
|
198
|
+
({
|
|
199
|
+
submissions,
|
|
200
|
+
calls: hostCalls = [],
|
|
201
|
+
launches: hostLaunches,
|
|
202
|
+
...scan
|
|
203
|
+
}) => ({
|
|
204
|
+
...scan,
|
|
205
|
+
submissions: submissions.length,
|
|
206
|
+
calls: hostCalls.length,
|
|
207
|
+
launches: hostLaunches.length,
|
|
208
|
+
}),
|
|
209
|
+
),
|
|
210
|
+
error:
|
|
211
|
+
scans.every((scan) => scan.error) && scans.length
|
|
212
|
+
? "所有在线主机的提交扫描都失败"
|
|
213
|
+
: null,
|
|
214
|
+
};
|
|
215
|
+
await onScanComplete(submissionTracker);
|
|
216
|
+
notify();
|
|
217
|
+
return submissionTracker;
|
|
218
|
+
})()
|
|
219
|
+
.catch((error) => {
|
|
220
|
+
submissionTracker = {
|
|
221
|
+
...submissionTracker,
|
|
222
|
+
scanning: false,
|
|
223
|
+
error: error.message,
|
|
224
|
+
};
|
|
225
|
+
notify();
|
|
226
|
+
return submissionTracker;
|
|
227
|
+
})
|
|
228
|
+
.finally(() => {
|
|
229
|
+
submissionScanPromise = null;
|
|
230
|
+
});
|
|
231
|
+
return submissionScanPromise;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return { scan, busy: () => Boolean(submissionScanPromise), snapshot: () => submissionTracker,
|
|
235
|
+
reset() { if (submissionScanPromise) throw new Error("等待扫描结束后修改配置"); submissionTracker = empty(); } };
|
|
236
|
+
}
|