evolcore 0.0.46 → 0.0.47
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 +38 -0
- package/dist/agents/claude-runner.js +9 -1
- package/dist/agents/codex/app-server-client.js +32 -23
- package/dist/aun/group/fs-download.js +1 -1
- package/dist/channels/aun.js +19 -8
- package/dist/channels/daemon.js +1 -1
- package/dist/cli/daemon-commands.js +27 -39
- package/dist/cli/daemon-lifecycle-client.js +17 -3
- package/dist/cli/init-channel.js +2 -2
- package/dist/cli/init.js +7 -1
- package/dist/cli/restart-monitor.js +104 -28
- package/dist/cli/task-context.js +83 -15
- package/dist/cli/upgrade-command.js +4 -2
- package/dist/config/config-manager.js +29 -17
- package/dist/config/peer-book-store.js +18 -10
- package/dist/config/provider-identity-migration.js +157 -5
- package/dist/config/schema-migration.js +123 -16
- package/dist/config/schema-registry.js +6 -2
- package/dist/core/agent-runtime.js +6 -5
- package/dist/core/auth/agent-delegation.js +8 -3
- package/dist/core/auth/delegation-diagnostics.js +56 -15
- package/dist/core/auth/operation-authorizer.js +1 -1
- package/dist/core/command/menu-handler.js +4 -4
- package/dist/core/command/slash-handler.js +4 -6
- package/dist/core/daemon-bootstrap.js +11 -9
- package/dist/core/daemon-control.js +1 -3
- package/dist/core/daemon-lifecycle.js +50 -40
- package/dist/core/evolagent-registry.js +8 -2
- package/dist/core/host-snapshot.js +9 -4
- package/dist/core/initialization/service.js +22 -4
- package/dist/core/ipc-registration.js +4 -3
- package/dist/core/memory/consolidation.js +6 -6
- package/dist/core/ownership/owner-resolver.js +27 -10
- package/dist/core/relation/peer-identity.js +5 -1
- package/dist/core/relation/same-owner-proof.js +2 -1
- package/dist/core/session/adapters/claude-session-file-adapter.js +1 -1
- package/dist/core/session/session-file-health.js +36 -7
- package/dist/core/task/task-image-resources.js +1 -1
- package/dist/ecweb/runtime/lifecycle.js +64 -15
- package/dist/ecweb/runtime/supervisor.js +2 -15
- package/dist/index.js +37 -34
- package/dist/ipc.js +2 -1
- package/dist/trigger/scheduler.js +4 -0
- package/dist/trigger/state.js +7 -0
- package/dist/utils/aid-bind.js +155 -18
- package/dist/utils/atomic-write.js +3 -3
- package/dist/utils/cross-platform.js +24 -5
- package/dist/utils/error-utils.js +13 -0
- package/dist/utils/instance-registry.js +61 -0
- package/dist/utils/process-introspect.js +152 -7
- package/dist/utils/upgrade-jobs.js +4 -4
- package/kits/docs/evolcore/aid.md +3 -1
- package/kits/docs/evolcore/provider.md +10 -2
- package/package.json +2 -2
|
@@ -157,13 +157,35 @@ export async function repairCodexSessionProvider(options) {
|
|
|
157
157
|
const { DatabaseSync } = requireFromHere('node:sqlite');
|
|
158
158
|
const directory = rollout + '.provider-repair';
|
|
159
159
|
const journalFile = path.join(directory, 'intent.json');
|
|
160
|
+
const assertIndexedRolloutPath = (indexedPath) => {
|
|
161
|
+
const context = `thread=${threadId}, database=${JSON.stringify(database)},`
|
|
162
|
+
+ ` index=${JSON.stringify(indexedPath)}, rollout=${JSON.stringify(rollout)}`;
|
|
163
|
+
let indexedRealPath;
|
|
164
|
+
let rolloutRealPath;
|
|
165
|
+
try {
|
|
166
|
+
// Windows Codex stores verbatim paths (\\?\) in SQLite. Resolve both
|
|
167
|
+
// through the filesystem instead of comparing their textual spelling.
|
|
168
|
+
indexedRealPath = fs.realpathSync.native(indexedPath);
|
|
169
|
+
rolloutRealPath = fs.realpathSync.native(rollout);
|
|
170
|
+
}
|
|
171
|
+
catch (cause) {
|
|
172
|
+
throw new Error(`Codex thread index rollout path cannot be resolved (${context}): `
|
|
173
|
+
+ (cause instanceof Error ? cause.message : String(cause)), { cause });
|
|
174
|
+
}
|
|
175
|
+
if (indexedRealPath !== rolloutRealPath) {
|
|
176
|
+
throw new Error(`Codex thread index rollout path mismatch (${context})`);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
160
179
|
const readIndex = () => {
|
|
161
180
|
const db = new DatabaseSync(database, { readOnly: true });
|
|
162
181
|
try {
|
|
163
182
|
const row = db.prepare('SELECT model_provider, rollout_path FROM threads WHERE id = ?').get(threadId);
|
|
164
|
-
if (!row
|
|
165
|
-
|
|
166
|
-
|
|
183
|
+
if (!row)
|
|
184
|
+
throw new Error(`Codex thread index row is missing (thread=${threadId})`);
|
|
185
|
+
if (typeof row.model_provider !== 'string' || typeof row.rollout_path !== 'string') {
|
|
186
|
+
throw new Error(`Codex thread index fields are invalid (thread=${threadId})`);
|
|
187
|
+
}
|
|
188
|
+
assertIndexedRolloutPath(row.rollout_path);
|
|
167
189
|
return row;
|
|
168
190
|
}
|
|
169
191
|
finally {
|
|
@@ -192,12 +214,13 @@ export async function repairCodexSessionProvider(options) {
|
|
|
192
214
|
const apply = (intent) => {
|
|
193
215
|
const backupRoot = path.join(directory, path.basename(path.dirname(intent.backup)));
|
|
194
216
|
if (intent.version !== 1 || intent.threadId !== threadId || intent.database !== database
|
|
195
|
-
|| intent.rollout !== rollout ||
|
|
217
|
+
|| intent.rollout !== rollout || typeof intent.indexedPath !== 'string'
|
|
196
218
|
|| intent.backup !== path.join(backupRoot, 'before.snapshot')
|
|
197
219
|
|| intent.next !== path.join(backupRoot, 'after.snapshot')
|
|
198
220
|
|| !/^evolcore_registry_[a-f0-9]{20}$/.test(intent.provider)) {
|
|
199
221
|
throw new Error('Invalid Codex Provider repair journal');
|
|
200
222
|
}
|
|
223
|
+
assertIndexedRolloutPath(intent.indexedPath);
|
|
201
224
|
assertRepairFile(intent.backup, directory);
|
|
202
225
|
const original = fs.readFileSync(intent.backup);
|
|
203
226
|
const replacement = rewriteCodexProvider(original, threadId, intent.provider);
|
|
@@ -264,9 +287,15 @@ export async function repairCodexSessionProvider(options) {
|
|
|
264
287
|
}
|
|
265
288
|
const bytes = fs.readFileSync(rollout);
|
|
266
289
|
const current = readIndex();
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
290
|
+
const rolloutProvider = codexMetadata(bytes, threadId).provider;
|
|
291
|
+
if (rolloutProvider !== provider || current.model_provider !== provider) {
|
|
292
|
+
// Codex 0.164 can resume with a new Provider by updating only the index.
|
|
293
|
+
// Allow its stale header to catch up when the index already names our
|
|
294
|
+
// resolved Provider; unrelated disagreements still fail closed.
|
|
295
|
+
if (rolloutProvider !== current.model_provider && current.model_provider !== provider) {
|
|
296
|
+
throw new Error('Codex Provider repair rejected: rollout and index disagree'
|
|
297
|
+
+ ` (thread=${threadId}, rollout=${JSON.stringify(rolloutProvider)},`
|
|
298
|
+
+ ` index=${JSON.stringify(current.model_provider)}, target=${JSON.stringify(provider)})`);
|
|
270
299
|
}
|
|
271
300
|
const backupRoot = path.join(directory, randomUUID());
|
|
272
301
|
fs.mkdirSync(backupRoot, { mode: 0o700 });
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import sharp from 'sharp';
|
|
5
4
|
import { agentDataDir } from '../../paths.js';
|
|
6
5
|
import { checkProtectedPathAccess, isSameOrDescendant } from '../permission/protected-paths.js';
|
|
7
6
|
export const TASK_IMAGE_CHUNK_BYTES = 192 * 1024;
|
|
@@ -65,6 +64,7 @@ export class TaskImageResources {
|
|
|
65
64
|
finally {
|
|
66
65
|
await handle.close();
|
|
67
66
|
}
|
|
67
|
+
const { default: sharp } = await import('sharp');
|
|
68
68
|
const metadata = await sharp(bytes, { limitInputPixels: 40_000_000 }).metadata();
|
|
69
69
|
const mimeType = IMAGE_MIMES[metadata.format ?? ''];
|
|
70
70
|
if (!mimeType || !metadata.width || !metadata.height)
|
|
@@ -3,7 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import { createServer } from 'node:net';
|
|
4
4
|
import { execFileSync } from 'node:child_process';
|
|
5
5
|
import { parseEcwebInstanceRecord, matchesEcwebInstanceHealth } from '../../contracts/ecweb-instance.js';
|
|
6
|
-
import {
|
|
6
|
+
import { getProcessSnapshotAsync, getProcessStartTime, getProcessStartTimeAsync, startTimeMatches } from '../../utils/process-introspect.js';
|
|
7
7
|
import * as platform from '../../utils/cross-platform.js';
|
|
8
8
|
import { resolveGlobalPkg } from '../../utils/npm-ops.js';
|
|
9
9
|
import { resolveEcwebLaunchCommand } from './launch.js';
|
|
@@ -23,20 +23,58 @@ async function sameProcess(identity) {
|
|
|
23
23
|
* Prefer a cooperative IPC request for supervised children on every platform.
|
|
24
24
|
* Windows taskkill without /F cannot invoke Node's SIGTERM handler; only
|
|
25
25
|
* POSIX can use SIGTERM when no parent-child IPC channel is available.
|
|
26
|
-
* The
|
|
27
|
-
*
|
|
26
|
+
* The captured ChildProcess IPC channel cannot address a reused PID. Its
|
|
27
|
+
* exit event confirms termination without a delayed OS liveness poll.
|
|
28
28
|
*/
|
|
29
29
|
const IPC_GRACEFUL_STOP_MS = 3_000;
|
|
30
30
|
const POSIX_GRACEFUL_STOP_MS = 1_000;
|
|
31
31
|
const FORCED_STOP_MS = 2_000;
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
function requestChildShutdown(child, timeoutMs) {
|
|
33
|
+
return new Promise(resolve => {
|
|
34
|
+
if (child.exitCode != null || child.signalCode != null) {
|
|
35
|
+
resolve({ signalSent: false, exited: true });
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
let signalSent = false;
|
|
39
|
+
let settled = false;
|
|
40
|
+
const finish = (exited) => {
|
|
41
|
+
if (settled)
|
|
42
|
+
return;
|
|
43
|
+
settled = true;
|
|
44
|
+
clearTimeout(timer);
|
|
45
|
+
child.removeListener('exit', onExit);
|
|
46
|
+
resolve({ signalSent, exited });
|
|
47
|
+
};
|
|
48
|
+
const onExit = () => finish(true);
|
|
49
|
+
const timer = setTimeout(() => finish(false), timeoutMs);
|
|
50
|
+
// Subscribe before sending: the child may exit immediately on receipt.
|
|
51
|
+
child.once('exit', onExit);
|
|
52
|
+
try {
|
|
53
|
+
if (!child.connected) {
|
|
54
|
+
finish(false);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
signalSent = true;
|
|
58
|
+
// A false return means IPC backpressure, not a failed delivery.
|
|
59
|
+
child.send({ type: 'ecweb.shutdown' }, error => { if (error)
|
|
60
|
+
finish(false); });
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
signalSent = false;
|
|
64
|
+
finish(false);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export async function stopEcwebProcess(identity, timeoutMs = FORCED_STOP_MS, onTiming, child) {
|
|
69
|
+
const supervisedChild = child?.pid === identity.pid ? child : undefined;
|
|
70
|
+
const waitForExit = async (force, budgetMs, target) => {
|
|
34
71
|
const startMs = Date.now();
|
|
35
|
-
let detail = `pid=${identity.pid}; timeoutMs=${budgetMs}${
|
|
72
|
+
let detail = `pid=${identity.pid}; timeoutMs=${budgetMs}${target ? '; transport=ipc; exitObserver=child' : ''}`;
|
|
36
73
|
try {
|
|
37
|
-
const signalSent =
|
|
38
|
-
|
|
39
|
-
|
|
74
|
+
const { signalSent, exited } = target ? await requestChildShutdown(target, budgetMs) : {
|
|
75
|
+
signalSent: platform.killProcessOnly(identity.pid, force),
|
|
76
|
+
exited: await platform.waitForProcessExit(identity.pid, budgetMs),
|
|
77
|
+
};
|
|
40
78
|
detail += `; signalSent=${signalSent}; exited=${exited}`;
|
|
41
79
|
return exited;
|
|
42
80
|
}
|
|
@@ -51,10 +89,10 @@ export async function stopEcwebProcess(identity, timeoutMs = FORCED_STOP_MS, onT
|
|
|
51
89
|
catch { }
|
|
52
90
|
}
|
|
53
91
|
};
|
|
54
|
-
if (
|
|
92
|
+
if (supervisedChild) {
|
|
55
93
|
// Ask our actual child first. Fresh OS identity queries are only needed
|
|
56
94
|
// before falling back to PID-addressed signals, including on IPC failure.
|
|
57
|
-
if (await waitForExit(false, IPC_GRACEFUL_STOP_MS,
|
|
95
|
+
if (await waitForExit(false, IPC_GRACEFUL_STOP_MS, supervisedChild))
|
|
58
96
|
return;
|
|
59
97
|
if (!await sameProcess(identity))
|
|
60
98
|
return;
|
|
@@ -73,8 +111,6 @@ export async function stopEcwebProcess(identity, timeoutMs = FORCED_STOP_MS, onT
|
|
|
73
111
|
}
|
|
74
112
|
function commandLineFor(pid) {
|
|
75
113
|
try {
|
|
76
|
-
if (platform.isWindows)
|
|
77
|
-
return getProcessSnapshot({ fresh: true }).commandLines.get(pid) ?? null;
|
|
78
114
|
return execFileSync('ps', ['-ww', '-p', String(pid), '-o', 'command='], {
|
|
79
115
|
encoding: 'utf8', timeout: 3_000, stdio: ['ignore', 'pipe', 'ignore'],
|
|
80
116
|
}).trim() || null;
|
|
@@ -157,13 +193,24 @@ export async function stopEcwebForRestart(paths, port, log) {
|
|
|
157
193
|
const launch = resolveEcwebLaunchCommand([], { installedPkg: installed });
|
|
158
194
|
const entries = [launch?.entry, installed ? path.join(path.dirname(installed.path), 'dist', 'index.js') : undefined]
|
|
159
195
|
.filter((entry) => !!entry);
|
|
196
|
+
let windowsListeners;
|
|
160
197
|
for (const targetPort of ports) {
|
|
161
198
|
for (const pid of platform.findProcessByPort(targetPort)) {
|
|
162
199
|
if (identities.has(pid))
|
|
163
200
|
continue;
|
|
164
|
-
|
|
165
|
-
|
|
201
|
+
// Observe creation time and command line together, rather than starting
|
|
202
|
+
// per-PID PowerShell/WMIC and then querying the whole table again. This
|
|
203
|
+
// snapshot only identifies candidates; stopEcwebProcess rechecks identity.
|
|
204
|
+
const snapshot = platform.isWindows
|
|
205
|
+
? windowsListeners ??= await getProcessSnapshotAsync({ fresh: true }) : undefined;
|
|
206
|
+
const startedAt = snapshot ? snapshot.startedAt.get(pid) ?? null : getProcessStartTime(pid);
|
|
207
|
+
const commandLine = snapshot ? snapshot.commandLines.get(pid) ?? null : commandLineFor(pid);
|
|
166
208
|
if (startedAt === null || !commandLine || !matchesEcwebCommand(commandLine, paths.root, entries)) {
|
|
209
|
+
// A listener can exit between netstat/lsof and the identity query.
|
|
210
|
+
// Recheck ownership instead of rejecting a stale PID. The final scan
|
|
211
|
+
// and exclusive bind must still prove the port was actually released.
|
|
212
|
+
if (!(await platform.findProcessByPortAsync(targetPort)).includes(pid))
|
|
213
|
+
continue;
|
|
167
214
|
throw new Error(`ECWeb 端口 ${targetPort} 被身份未确认的进程占用 (PID: ${pid});未终止该进程`);
|
|
168
215
|
}
|
|
169
216
|
let health;
|
|
@@ -174,6 +221,8 @@ export async function stopEcwebForRestart(paths, port, log) {
|
|
|
174
221
|
}
|
|
175
222
|
catch { }
|
|
176
223
|
if (!matchesEcwebInstanceHealth(health, { pid, port: targetPort })) {
|
|
224
|
+
if (!(await platform.findProcessByPortAsync(targetPort)).includes(pid))
|
|
225
|
+
continue;
|
|
177
226
|
throw new Error(`ECWeb 端口 ${targetPort} 的服务身份无法确认 (PID: ${pid});未终止该进程`);
|
|
178
227
|
}
|
|
179
228
|
identities.set(pid, { pid, startedAt });
|
|
@@ -246,21 +246,8 @@ export function createEcwebSupervisor(options) {
|
|
|
246
246
|
logFd = null;
|
|
247
247
|
};
|
|
248
248
|
const stopTrackedProcess = (identity, onTiming) => {
|
|
249
|
-
const target = child?.pid === identity.pid ? child :
|
|
250
|
-
|
|
251
|
-
try {
|
|
252
|
-
if (!target.connected)
|
|
253
|
-
return false;
|
|
254
|
-
// The callback handles an asynchronously closed channel without an
|
|
255
|
-
// unhandled child 'error' event. Exit confirmation remains separate.
|
|
256
|
-
target.send({ type: 'ecweb.shutdown' }, () => { });
|
|
257
|
-
return true;
|
|
258
|
-
}
|
|
259
|
-
catch {
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
} : undefined;
|
|
263
|
-
return stopEcwebProcess(identity, undefined, onTiming, requestShutdown);
|
|
249
|
+
const target = child?.pid === identity.pid ? child : undefined;
|
|
250
|
+
return stopEcwebProcess(identity, undefined, onTiming, target);
|
|
264
251
|
};
|
|
265
252
|
const killActive = async (onTiming) => {
|
|
266
253
|
intentionalStop = true;
|
package/dist/index.js
CHANGED
|
@@ -36,6 +36,7 @@ import { AUNChannelPlugin } from './channels/aun.js';
|
|
|
36
36
|
import { registerAbilityPlatform } from './ability/daemon.js';
|
|
37
37
|
import { assertAunEncryptionSeedPolicy } from './aun/aid/encryption-seed-policy.js';
|
|
38
38
|
import { BindService } from './utils/aid-bind.js';
|
|
39
|
+
import { ecwebInitializationService } from './core/initialization/service.js';
|
|
39
40
|
import { buildEnvelope } from './core/message/message-utils.js';
|
|
40
41
|
import { ResponseEngine } from './core/message/response-engine.js';
|
|
41
42
|
import { MessageQueue } from './core/message/message-queue.js';
|
|
@@ -259,7 +260,6 @@ async function main() {
|
|
|
259
260
|
let startupCancelled = false;
|
|
260
261
|
let cancelStartupClassification = () => { };
|
|
261
262
|
let normalTaskState = 'pending';
|
|
262
|
-
let startupEcwebState = 'waiting';
|
|
263
263
|
const priorityStartupGate = new StartupGate();
|
|
264
264
|
const normalStartupGate = new StartupGate();
|
|
265
265
|
const waitForBackgroundStartup = async () => await normalStartupGate.promise !== 'cancelled' && !startupCancelled;
|
|
@@ -287,6 +287,8 @@ async function main() {
|
|
|
287
287
|
// ECWeb has one lifecycle owner: the daemon. The CLI may have started an
|
|
288
288
|
// instance just before spawning us; the supervisor adopts it when healthy,
|
|
289
289
|
// otherwise starts one and keeps it alive for the daemon's lifetime.
|
|
290
|
+
// Start independently once its configuration is loaded; Agent readiness
|
|
291
|
+
// does not gate the UI, and HTTP health does not gate task readiness.
|
|
290
292
|
trace.mark('daemon.ecwebSupervisor');
|
|
291
293
|
let ecwebSupervisor = null;
|
|
292
294
|
const ecwebConfig = ecwebService(daemonCfg.services);
|
|
@@ -302,20 +304,16 @@ async function main() {
|
|
|
302
304
|
});
|
|
303
305
|
onShutdown(() => ecwebSupervisor?.stop());
|
|
304
306
|
const removeEcwebConfigListener = onConfigWrite(({ target }) => {
|
|
305
|
-
if (target !== ConfigTarget.Process || !ecwebSupervisor)
|
|
307
|
+
if (startupCancelled || target !== ConfigTarget.Process || !ecwebSupervisor)
|
|
306
308
|
return;
|
|
307
309
|
try {
|
|
308
310
|
const service = ecwebService(loadDaemonConfig().services);
|
|
309
|
-
void
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
runtimeMode: service ? serviceRuntimeMode(service) : 'managed',
|
|
316
|
-
restart: service?.runtime?.restart,
|
|
317
|
-
health: service?.health,
|
|
318
|
-
});
|
|
311
|
+
void ecwebSupervisor.configure({
|
|
312
|
+
enabled: service?.enabled === true,
|
|
313
|
+
port: service?.port ?? DEFAULT_ECWEB_PORT,
|
|
314
|
+
runtimeMode: service ? serviceRuntimeMode(service) : 'managed',
|
|
315
|
+
restart: service?.runtime?.restart,
|
|
316
|
+
health: service?.health,
|
|
319
317
|
}).catch((error) => logger.warn(`ECWeb 配置热应用失败: ${error?.message || error}`));
|
|
320
318
|
}
|
|
321
319
|
catch (error) {
|
|
@@ -323,25 +321,19 @@ async function main() {
|
|
|
323
321
|
}
|
|
324
322
|
});
|
|
325
323
|
onShutdown(removeEcwebConfigListener);
|
|
326
|
-
void trace.track('daemon.ecwebLaunch', async (
|
|
327
|
-
phase('waiting', 'priority Ready');
|
|
328
|
-
await priorityStartupGate.promise;
|
|
324
|
+
void trace.track('daemon.ecwebLaunch', async () => {
|
|
329
325
|
if (startupCancelled)
|
|
330
326
|
return false;
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
startupEcwebState = 'starting';
|
|
334
|
-
await ecwebSupervisor.start();
|
|
335
|
-
startupEcwebState = 'ready';
|
|
336
|
-
}
|
|
337
|
-
}, undefined, { initialPhase: 'waiting' }).catch((error) => {
|
|
338
|
-
startupEcwebState = 'failed';
|
|
327
|
+
await ecwebSupervisor.start();
|
|
328
|
+
}, undefined, { initialPhase: 'running' }).catch((error) => {
|
|
339
329
|
logger.warn(`ECWeb supervisor 启动失败(不影响 daemon 主流程): ${error?.message || error}`);
|
|
340
330
|
});
|
|
341
331
|
}
|
|
342
332
|
if (bindBootstrapMode && process.env.EVOLCORE_WEB_INIT !== '1' && daemonCfg.aid && loadAllAgents().agents.length === 0) {
|
|
343
333
|
priorityStartupGate.settle('ready');
|
|
344
334
|
await runBindBootstrapDaemon(daemonCfg);
|
|
335
|
+
// The pairing-only daemon has no Agent task gate.
|
|
336
|
+
normalStartupGate.settle('ready');
|
|
345
337
|
return;
|
|
346
338
|
}
|
|
347
339
|
// ── EvolAgent Registry:加载 agents/<aid>/config.json ──
|
|
@@ -528,7 +520,7 @@ async function main() {
|
|
|
528
520
|
baseagent.loaded = loaded.has(baseagent.id);
|
|
529
521
|
};
|
|
530
522
|
let configureRunnerCallbacks;
|
|
531
|
-
const agentDelegationRegistry =
|
|
523
|
+
const agentDelegationRegistry = await AgentDelegationRegistry.createAsync();
|
|
532
524
|
process.env[DAEMON_RUNTIME_EPOCH_ENV] = agentDelegationRegistry.getRuntimeEpoch();
|
|
533
525
|
const startupRunnersStartedAtMs = Date.now();
|
|
534
526
|
trace.mark('daemon.agentRunnerDispatch');
|
|
@@ -688,6 +680,7 @@ async function main() {
|
|
|
688
680
|
receiverAid: daemonCfg.aid,
|
|
689
681
|
getAvailableBaseagents: detectAvailableBaseagents,
|
|
690
682
|
getUptimeSeconds: () => Math.floor(process.uptime()),
|
|
683
|
+
handleAppBindRequest: (payload, senderAid, encrypted) => ecwebInitializationService.handleAppBindRequest(payload, senderAid, encrypted),
|
|
691
684
|
})
|
|
692
685
|
: null;
|
|
693
686
|
bindService?.startCleanup();
|
|
@@ -696,6 +689,8 @@ async function main() {
|
|
|
696
689
|
});
|
|
697
690
|
let initializationServiceForOwnerRecovery;
|
|
698
691
|
const stopOwnerNotifications = ownerResolver.onChange((subjectAid, ownerAid) => {
|
|
692
|
+
if (startupCancelled)
|
|
693
|
+
return;
|
|
699
694
|
permissionGateway.revalidatePendingApprovals(subjectAid);
|
|
700
695
|
if (agentRegistry.get(subjectAid)) {
|
|
701
696
|
try {
|
|
@@ -1197,12 +1192,11 @@ async function main() {
|
|
|
1197
1192
|
let pendingShutdownTraceId;
|
|
1198
1193
|
trace.mark('daemon.baseagentProbe');
|
|
1199
1194
|
refreshLoadedBaseagents();
|
|
1200
|
-
const getStatusSnapshot = () => {
|
|
1195
|
+
const getStatusSnapshot = (agents) => {
|
|
1201
1196
|
const now = Date.now();
|
|
1202
1197
|
const todayStart = new Date(new Date(now).getFullYear(), new Date(now).getMonth(), new Date(now).getDate()).getTime();
|
|
1203
1198
|
const lastHour = queryStatusActivity(paths.root, now - 3_600_000, now);
|
|
1204
1199
|
const today = queryStatusActivity(paths.root, todayStart, now);
|
|
1205
|
-
const agents = agentRegistry.list();
|
|
1206
1200
|
const usageByAgent = queryStatusActivityByAgent(paths.root, todayStart, now, agents.map(agent => agent.aid));
|
|
1207
1201
|
return {
|
|
1208
1202
|
activity: { lastHour, today },
|
|
@@ -1233,7 +1227,7 @@ async function main() {
|
|
|
1233
1227
|
};
|
|
1234
1228
|
};
|
|
1235
1229
|
// 主机信息唯一出口:CLI、菜单、ecweb 都读这一份,别各自探测。
|
|
1236
|
-
//
|
|
1230
|
+
// 启动时先提供缓存;版本与虚拟化探测的子进程在正常 Ready 后刷新。
|
|
1237
1231
|
const hostProvider = createHostSnapshotProvider({
|
|
1238
1232
|
messageQueue,
|
|
1239
1233
|
statsCollector,
|
|
@@ -1242,11 +1236,16 @@ async function main() {
|
|
|
1242
1236
|
runMode: devMode ? 'dev' : 'install',
|
|
1243
1237
|
getSystemCpuPercent: () => ipcServer.getSystemCpuPercent(),
|
|
1244
1238
|
getControlAidState: () => controlChannel?.getAidState(),
|
|
1239
|
+
autoProbe: false,
|
|
1245
1240
|
});
|
|
1241
|
+
void waitForBackgroundStartup().then(admitted => {
|
|
1242
|
+
if (admitted)
|
|
1243
|
+
return hostProvider.refresh();
|
|
1244
|
+
}).catch(error => logger.warn(`[HostSnapshot] background probe failed: ${error}`));
|
|
1246
1245
|
trace.mark('daemon.ipcCreate');
|
|
1247
1246
|
const ipcServer = new IpcServer(resolvePaths().socket, createIpcStatusProvider({
|
|
1248
1247
|
channelInstances,
|
|
1249
|
-
getChannelRuntimeSnapshot:
|
|
1248
|
+
getChannelRuntimeSnapshot: agents => channelLoader.getSnapshot(agents.flatMap(info => {
|
|
1250
1249
|
const agent = agentRegistry.get(info.aid);
|
|
1251
1250
|
return agent ? [agent] : [];
|
|
1252
1251
|
})),
|
|
@@ -1263,8 +1262,7 @@ async function main() {
|
|
|
1263
1262
|
: priorityStartupGate.status === 'pending' ? 'recovering' : 'loading',
|
|
1264
1263
|
priorityRelease: priorityStartupGate.status,
|
|
1265
1264
|
optionalRelease: normalStartupGate.status,
|
|
1266
|
-
ecweb:
|
|
1267
|
-
: ecwebSupervisor?.status().state ?? 'disabled',
|
|
1265
|
+
ecweb: ecwebSupervisor?.status().state ?? 'disabled',
|
|
1268
1266
|
backgroundRecovery: {
|
|
1269
1267
|
handoff: startupHandoffRecovery?.status() ?? { completed: 0, total: triggerStartupAgents.length, retrying: 0 },
|
|
1270
1268
|
sessionIdle: sessionIdleRestoreState,
|
|
@@ -1286,7 +1284,7 @@ async function main() {
|
|
|
1286
1284
|
}),
|
|
1287
1285
|
daemonAid: daemonCfg.aid,
|
|
1288
1286
|
getControlAidState: () => controlChannel?.getAidState(),
|
|
1289
|
-
getHost: () => hostProvider.
|
|
1287
|
+
getHost: () => hostProvider.getHost(),
|
|
1290
1288
|
baseagents: baseagentSnapshot,
|
|
1291
1289
|
getTriggerSummary: () => {
|
|
1292
1290
|
const now = new Date();
|
|
@@ -1903,7 +1901,7 @@ async function main() {
|
|
|
1903
1901
|
let taskReadinessSettled = false;
|
|
1904
1902
|
const finishPriorityStartup = trace.startTask('daemon.priorityTaskReady', undefined, { summary: true });
|
|
1905
1903
|
priorityStartupGate.releaseAfter(9_000, () => {
|
|
1906
|
-
logger.warn('[startup] Priority recovery still pending after 9s; admitting idle Agents
|
|
1904
|
+
logger.warn('[startup] Priority recovery still pending after 9s; admitting idle Agents without reporting Ready');
|
|
1907
1905
|
});
|
|
1908
1906
|
void priorityStartupGate.promise.then(outcome => {
|
|
1909
1907
|
trace.setMeta('priorityRelease', outcome);
|
|
@@ -1990,7 +1988,7 @@ async function main() {
|
|
|
1990
1988
|
fs.writeFileSync(readySignalPath, String(Date.now()));
|
|
1991
1989
|
logger.info(`✓ Ready signal written: ${readySignalPath}`);
|
|
1992
1990
|
trace.setMeta('channelInstances', String(channelInstances.length));
|
|
1993
|
-
trace.setMeta('agents', String(agentRegistry.
|
|
1991
|
+
trace.setMeta('agents', String(agentRegistry.allAgents().length));
|
|
1994
1992
|
trace.ready();
|
|
1995
1993
|
// 配置 reload 走 IPC `evolagent.reload` 触发,不再用 watchFile。
|
|
1996
1994
|
// 双 rename 原子写下 watchFile 的语义会被破坏,且新结构有 N 个 config.json 要监控;
|
|
@@ -2001,7 +1999,12 @@ async function main() {
|
|
|
2001
1999
|
beginShutdown: () => lifecycleNotices.beginShutdown(),
|
|
2002
2000
|
sendOffline: signal => lifecycleNotices.sendOffline(signal),
|
|
2003
2001
|
},
|
|
2004
|
-
stopOwnership: () =>
|
|
2002
|
+
stopOwnership: () => {
|
|
2003
|
+
// IPC shutdown does not invoke the signal-only onShutdown callbacks.
|
|
2004
|
+
// Retire contact sync before resolver teardown emits invalidations.
|
|
2005
|
+
stopOwnerNotifications();
|
|
2006
|
+
ownerResolver.stop();
|
|
2007
|
+
},
|
|
2005
2008
|
ipcServer,
|
|
2006
2009
|
readySignalPath,
|
|
2007
2010
|
bindService,
|
package/dist/ipc.js
CHANGED
|
@@ -7,7 +7,6 @@ import os from 'os';
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { execFile } from 'node:child_process';
|
|
9
9
|
import { logger, logOwnershipEvent } from './utils/logger.js';
|
|
10
|
-
import { withMenuProcessingTime, logMenuRequestCompleted, logMenuRequestReceived } from './core/command/menu-protocol.js';
|
|
11
10
|
import { fileCache } from './core/daemon-file-cache.js';
|
|
12
11
|
import { DAEMON_RUNTIME_EPOCH_ENV, isTrustedFullAccessRuntimeContext } from './cli/task-context.js';
|
|
13
12
|
import { HANDOFF_QUERY_MAX_LIMIT, HANDOFF_STATES } from './core/handoff/types.js';
|
|
@@ -2847,6 +2846,8 @@ export class IpcServer {
|
|
|
2847
2846
|
}
|
|
2848
2847
|
}
|
|
2849
2848
|
case 'menu.exec': {
|
|
2849
|
+
// IPC clients such as the restart monitor never execute menus.
|
|
2850
|
+
const { withMenuProcessingTime, logMenuRequestCompleted, logMenuRequestReceived } = await import('./core/command/menu-protocol.js');
|
|
2850
2851
|
const request = cmd.payload && typeof cmd.payload === 'object' && !Array.isArray(cmd.payload)
|
|
2851
2852
|
? cmd.payload
|
|
2852
2853
|
: { type: 'menu.invalid' };
|
|
@@ -1530,6 +1530,7 @@ export class TriggerRuntimeScheduler {
|
|
|
1530
1530
|
startedAt: run.startedAt,
|
|
1531
1531
|
executionSessionId: session.id,
|
|
1532
1532
|
executionDeadlineAt: run.executionDeadlineAt,
|
|
1533
|
+
resume: true,
|
|
1533
1534
|
});
|
|
1534
1535
|
let execution = await this.runRecoveredExecutionAttempt(definition, runtime, session);
|
|
1535
1536
|
this.state.completeExecutionAttempt(definition.id, run.runId, attemptId, attemptSummaryFromExecution(attempt, attemptId, execution));
|
|
@@ -1562,6 +1563,9 @@ export class TriggerRuntimeScheduler {
|
|
|
1562
1563
|
trigger: definition,
|
|
1563
1564
|
runId: run.runId,
|
|
1564
1565
|
attemptId: run.attemptId,
|
|
1566
|
+
// Keep run/attempt/session identity while giving this continuation its
|
|
1567
|
+
// own durable queue claim and response slot. Never erase inbound dedup.
|
|
1568
|
+
deliveryId: `${run.attemptId}:resume:${run.resumeCount}`,
|
|
1565
1569
|
firedAt: source.firedAt,
|
|
1566
1570
|
projectPath: session.projectPath,
|
|
1567
1571
|
baseagent: session.baseagent,
|
package/dist/trigger/state.js
CHANGED
|
@@ -58,6 +58,13 @@ export class TriggerRunStateStore {
|
|
|
58
58
|
if (existing) {
|
|
59
59
|
if (input.executionSessionId)
|
|
60
60
|
existing.executionSessionId = input.executionSessionId;
|
|
61
|
+
if (input.resume) {
|
|
62
|
+
// Suspension may have settled the old delivery as cancelled. The
|
|
63
|
+
// recovery event preserves that history; its logical attempt resumes.
|
|
64
|
+
existing.status = 'running';
|
|
65
|
+
delete existing.finishedAt;
|
|
66
|
+
delete existing.error;
|
|
67
|
+
}
|
|
61
68
|
}
|
|
62
69
|
else {
|
|
63
70
|
attempts.push({
|