evolcore 0.0.43-test.5 → 0.0.43-test.6
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 +47 -0
- package/bin/ecmsg.js +126 -43
- package/dist/agents/baseagent-availability.js +19 -4
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +19 -4
- package/dist/agents/codex/app-server-client.js +14 -3
- package/dist/agents/codex-runner.js +6 -6
- package/dist/aun/group/invite-service.js +3 -2
- package/dist/aun/service-proxy.js +18 -6
- package/dist/channels/aun.js +73 -10
- package/dist/cli/agent-create.js +16 -6
- package/dist/cli/aun-commands.js +9 -1
- package/dist/cli/daemon-commands.js +30 -1
- package/dist/cli/ecmsg-gateway.js +3 -1
- package/dist/cli/init.js +75 -0
- package/dist/cli/provider-command.js +1 -1
- package/dist/cli/restart-monitor.js +24 -5
- package/dist/cli/task-context.js +38 -1
- package/dist/cli/watch-logs.js +6 -4
- package/dist/config/boot-log.js +6 -4
- package/dist/config/builtin-roles.js +2 -2
- package/dist/config/config-manager.js +1 -1
- package/dist/config/peer-role-resolver.js +1 -1
- package/dist/config/provider-identity-migration.js +92 -17
- package/dist/config/provider-local-sync.js +2 -0
- package/dist/config/providers-config.js +13 -0
- package/dist/config/providers-management.js +100 -10
- package/dist/config/role-service.js +8 -8
- package/dist/config/role-store.js +22 -22
- package/dist/config/schema-migration.js +80 -87
- package/dist/config/snapshot.js +70 -41
- package/dist/core/agent-runtime.js +44 -7
- package/dist/core/baseagent-loader.js +114 -11
- package/dist/core/channel-loader.js +36 -13
- package/dist/core/channel-runtime.js +112 -42
- package/dist/core/command/command-handler.js +5 -5
- package/dist/core/command/menu-handler.js +8 -3
- package/dist/core/command/menu-protocol.js +82 -11
- package/dist/core/command/role-menu.js +27 -15
- package/dist/core/daemon-control.js +42 -15
- package/dist/core/daemon-lifecycle.js +411 -67
- package/dist/core/handoff/dispatcher.js +9 -3
- package/dist/core/handoff/runtime.js +130 -42
- package/dist/core/handoff/store.js +190 -2
- package/dist/core/handoff/types.js +5 -0
- package/dist/core/initialization/service.js +4 -4
- package/dist/core/ipc-registration.js +5 -4
- package/dist/core/lifecycle-notice.js +10 -4
- package/dist/core/message/aun-ipc-sender.js +2 -2
- package/dist/core/message/message-bridge.js +53 -4
- package/dist/core/message/message-queue.js +46 -4
- package/dist/core/message/pending-hints.js +4 -10
- package/dist/core/message/response-engine.js +10 -2
- package/dist/core/message/send-routing.js +12 -2
- package/dist/core/ownership/owner-resolver.js +1 -0
- package/dist/core/permission/ec-command-parser.js +11 -1
- package/dist/core/session/adapters/claude-session-file-adapter.js +24 -0
- package/dist/core/session/adapters/codex-session-file-adapter.js +80 -0
- package/dist/core/session/adapters/ecagent-session-file-adapter.js +22 -0
- package/dist/core/session/adapters/gemini-session-file-adapter.js +39 -0
- package/dist/core/session/session-fs-store.js +164 -3
- package/dist/core/session/session-idle-monitor.js +9 -1
- package/dist/core/session/session-manager.js +36 -2
- package/dist/directory/owner-directory-admission.js +26 -1
- package/dist/directory/owner-directory-cache.js +57 -16
- package/dist/directory/owner-directory-query-operation.js +4 -1
- package/dist/ecweb/runtime/lifecycle.js +9 -7
- package/dist/ecweb/runtime/supervisor.js +44 -27
- package/dist/index.js +548 -251
- package/dist/proxy/manager.js +38 -17
- package/dist/proxy/service-supervisor.js +65 -31
- package/dist/trigger/application-service.js +3 -1
- package/dist/trigger/audit.js +19 -4
- package/dist/trigger/authorization.js +14 -5
- package/dist/trigger/history.js +176 -7
- package/dist/trigger/manager.js +1 -3
- package/dist/trigger/scheduler.js +78 -5
- package/dist/utils/cross-platform.js +152 -4
- package/dist/utils/host-info.js +11 -8
- package/dist/utils/npm-ops.js +48 -0
- package/dist/utils/process-introspect.js +64 -1
- package/dist/utils/startup-trace.js +160 -19
- package/kits/docs/aun/ABILITY_CALLING.md +3 -3
- package/kits/docs/evolcore/INDEX.md +3 -2
- package/kits/docs/evolcore/ctl.md +2 -1
- package/kits/docs/evolcore/group.md +2 -2
- package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
- package/kits/docs/evolcore/msg.md +13 -6
- package/kits/docs/evolcore/provider.md +21 -3
- package/kits/docs/evolcore/response.md +1 -1
- package/kits/eck_manifest.json +19 -7
- package/kits/eck_message_manifest.json +3 -3
- package/kits/rules/06-channel.md +5 -6
- package/kits/schemas/daemon.schema.1.json +5 -0
- package/kits/schemas/daemon.schema.2.json +5 -0
- package/kits/schemas/daemon.schema.3.json +2 -1
- package/kits/schemas/daemon.schema.4.json +2 -1
- package/kits/schemas/daemon.schema.5.json +2 -1
- package/kits/schemas/daemon.schema.6.json +1 -1
- package/kits/schemas/daemon.schema.7.json +1 -1
- package/kits/schemas/daemon.schema.8.json +2 -1
- package/kits/schemas/daemon.schema.9.json +2 -1
- package/kits/schemas/role-registry.schema.1.json +2 -2
- package/kits/schemas/single-session.schema.1.json +1 -1
- package/kits/schemas/single-session.schema.2.json +1 -1
- package/kits/schemas/single-session.schema.3.json +1 -1
- package/kits/skills/aid-ability/SKILL.md +7 -7
- package/kits/skills/ec-group/SKILL.md +8 -5
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/system-fragments/commands.md +5 -5
- package/kits/templates/system-fragments/reply.md +2 -1
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +1 -1
- package/package.json +4 -3
package/dist/channels/aun.js
CHANGED
|
@@ -407,6 +407,7 @@ const AUN_PERMANENT_STRING_CODES = new Set([
|
|
|
407
407
|
const AUN_RETRYABLE_STRING_CODES = new Set([
|
|
408
408
|
'network_error', 'connection_error', 'timeout', 'timed_out', 'rate_limited',
|
|
409
409
|
'too_many_requests', 'temporarily_unavailable', 'server_error', 'aun_not_connected',
|
|
410
|
+
'contact_directory_unavailable', 'contact_ownership_unavailable',
|
|
410
411
|
]);
|
|
411
412
|
function errorRecord(value) {
|
|
412
413
|
return value && typeof value === 'object' && !Array.isArray(value)
|
|
@@ -498,6 +499,8 @@ export function classifyAunSendFailure(value, fallback = 'AUN send failed') {
|
|
|
498
499
|
const retryByName = /(?:timeout|connection|rate.?limit|temporar(?:y|ily)|unavailable|network|socket)/i.test(details.name ?? '');
|
|
499
500
|
const relayTargetMissing = text.includes('relay_target_not_found') || text.includes('relay target not found');
|
|
500
501
|
const rpcHandlerTimeout = numericCode === -32004 && /rpc handler timeout/i.test(text);
|
|
502
|
+
const gatewayWarming = numericCode === -32020
|
|
503
|
+
&& details.message === 'Gateway is warming; retry via another gateway';
|
|
501
504
|
// -32013 is otherwise permanent, but "client signature cert unavailable" is
|
|
502
505
|
// the gateway failing to resolve the signer's certificate while the local
|
|
503
506
|
// cert is valid and auth succeeded. It clears server-side, so keep the
|
|
@@ -550,6 +553,7 @@ export function classifyAunSendFailure(value, fallback = 'AUN send failed') {
|
|
|
550
553
|
else if (AUN_RETRYABLE_ERROR_CODES.has(numericCode ?? Number.NaN)
|
|
551
554
|
|| transientHttpStatus
|
|
552
555
|
|| rpcHandlerTimeout
|
|
556
|
+
|| gatewayWarming
|
|
553
557
|
|| signatureCertUnavailable
|
|
554
558
|
|| AUN_RETRYABLE_STRING_CODES.has(stringCode)
|
|
555
559
|
|| retryByName
|
|
@@ -908,7 +912,9 @@ export class AUNChannel {
|
|
|
908
912
|
if (!beforeSend) {
|
|
909
913
|
const blocked = this.appContactOutboundBlock(params.to, { chatType: 'private' }, payload, params);
|
|
910
914
|
if (blocked) {
|
|
911
|
-
throw Object.assign(new Error(blocked.error), {
|
|
915
|
+
throw Object.assign(new Error(blocked.error), {
|
|
916
|
+
code: blocked.code, retryable: blocked.status === 'retry',
|
|
917
|
+
});
|
|
912
918
|
}
|
|
913
919
|
}
|
|
914
920
|
}
|
|
@@ -1641,6 +1647,15 @@ export class AUNChannel {
|
|
|
1641
1647
|
logger.warn(`${this.logPrefix()} topic.renamed failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1642
1648
|
});
|
|
1643
1649
|
}
|
|
1650
|
+
/** Quiesce callbacks before the shared resolver is detached, while offline sends still work. */
|
|
1651
|
+
prepareShutdown() {
|
|
1652
|
+
this.intentionalDisconnect = true;
|
|
1653
|
+
this.configuredOwnerBindEpoch++;
|
|
1654
|
+
this.stopOwnerDirectoryRefresh();
|
|
1655
|
+
if (this.reconnectTimer)
|
|
1656
|
+
clearTimeout(this.reconnectTimer);
|
|
1657
|
+
this.reconnectTimer = null;
|
|
1658
|
+
}
|
|
1644
1659
|
stopOwnerDirectoryRefresh() {
|
|
1645
1660
|
this.ownerDirectoryWatch?.stop();
|
|
1646
1661
|
this.ownerDirectoryWatch = undefined;
|
|
@@ -1756,13 +1771,15 @@ export class AUNChannel {
|
|
|
1756
1771
|
const selfAid = this.config.aid.replace(/^@/, '');
|
|
1757
1772
|
const client = this.client;
|
|
1758
1773
|
logger.debug(`${this.logPrefix()} getOwnerDirectoryRuntime called: selfAid=${selfAid}, connected=${this.connected}, pureIdentity=${!!this.config.pureIdentity}`);
|
|
1759
|
-
if (!client || !this.connected || this.config.pureIdentity) {
|
|
1774
|
+
if (!client || !this.connected || this.intentionalDisconnect || this.config.pureIdentity) {
|
|
1760
1775
|
logger.debug(`${this.logPrefix()} getOwnerDirectoryRuntime early return: client=${!!client}, connected=${this.connected}, pureIdentity=${!!this.config.pureIdentity}`);
|
|
1761
1776
|
return;
|
|
1762
1777
|
}
|
|
1763
1778
|
// Let Core and the SDK reuse valid consensus; explicit authorization/bind operations
|
|
1764
1779
|
// own their fresh checks. Material changes invalidate the SDK cache themselves.
|
|
1765
1780
|
const ownership = await ownerResolver.refresh(selfAid, { allowTransient: true, source: 'directory.runtime' });
|
|
1781
|
+
if (this.intentionalDisconnect || this.client !== client || !this.connected)
|
|
1782
|
+
return;
|
|
1766
1783
|
const ownerAid = ownerResolver.owner(selfAid);
|
|
1767
1784
|
logger.info(`${this.logPrefix()} ownerResolver result: selfAid=${selfAid}, ownerAid=${ownerAid || 'undefined'}`);
|
|
1768
1785
|
if (ownership.refreshFailure) {
|
|
@@ -2315,10 +2332,27 @@ export class AUNChannel {
|
|
|
2315
2332
|
setAidStatsCollector(collector) {
|
|
2316
2333
|
this.aidStatsCollector = collector;
|
|
2317
2334
|
}
|
|
2335
|
+
transportListeners = new Set();
|
|
2336
|
+
onTransportState(listener) {
|
|
2337
|
+
this.transportListeners.add(listener);
|
|
2338
|
+
return () => { this.transportListeners.delete(listener); };
|
|
2339
|
+
}
|
|
2318
2340
|
setAidStatus(status, extra) {
|
|
2341
|
+
const wasReady = this.aidState.status === 'connected';
|
|
2319
2342
|
this.aidState.status = status;
|
|
2320
2343
|
if (extra)
|
|
2321
2344
|
Object.assign(this.aidState, extra);
|
|
2345
|
+
const ready = status === 'connected';
|
|
2346
|
+
if (ready !== wasReady) {
|
|
2347
|
+
for (const listener of this.transportListeners) {
|
|
2348
|
+
try {
|
|
2349
|
+
listener(ready);
|
|
2350
|
+
}
|
|
2351
|
+
catch (error) {
|
|
2352
|
+
logger.warn(`${this.logPrefix()} transport listener failed: ${error}`);
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2322
2356
|
}
|
|
2323
2357
|
async connect() {
|
|
2324
2358
|
this.intentionalDisconnect = false;
|
|
@@ -4602,7 +4636,8 @@ export class AUNChannel {
|
|
|
4602
4636
|
if (!config)
|
|
4603
4637
|
return undefined;
|
|
4604
4638
|
const lifecycle = resolveAgentLifecycle(config);
|
|
4605
|
-
|
|
4639
|
+
// Legacy Owner hints are initialization inputs; active Agents need no automatic bind reconciliation.
|
|
4640
|
+
if (lifecycle === null || lifecycle === 'active')
|
|
4606
4641
|
return undefined;
|
|
4607
4642
|
return firstConfiguredOwner(config);
|
|
4608
4643
|
}
|
|
@@ -5299,15 +5334,38 @@ export class AUNChannel {
|
|
|
5299
5334
|
if (decision.allow)
|
|
5300
5335
|
return undefined;
|
|
5301
5336
|
return { status: decision.reason === 'unavailable' ? 'retry' : 'permanent',
|
|
5302
|
-
code: '
|
|
5337
|
+
code: decision.reason === 'unavailable' ? 'CONTACT_DIRECTORY_UNAVAILABLE' : 'CONTACT_DENIED',
|
|
5338
|
+
error: `联系人准入未通过:${decision.reason}` };
|
|
5303
5339
|
}
|
|
5304
5340
|
async prepareAppContactOutbound(channelId, delivery, payload, params) {
|
|
5305
5341
|
if (delivery.chatType === 'private' && !this.config.pureIdentity
|
|
5306
|
-
&& !this.hasContactControlPermit(channelId, payload, params)
|
|
5342
|
+
&& !this.hasContactControlPermit(channelId, payload, params)
|
|
5343
|
+
&& !this.acceptsVerifiedOwnership(channelId, payload, params)) {
|
|
5307
5344
|
await ownerResolver.refresh(this.config.aid, { maxAgeMs: OWNERSHIP_CACHE_MAX_AGE_MS, allowTransient: true });
|
|
5308
5345
|
}
|
|
5309
5346
|
return this.appContactOutboundBlock(channelId, delivery, payload, params);
|
|
5310
5347
|
}
|
|
5348
|
+
/**
|
|
5349
|
+
* A caller that already holds the consensus may skip the refresh round-trip.
|
|
5350
|
+
*
|
|
5351
|
+
* Only lifecycle notices qualify, and only toward their own Owner. Shutdown is
|
|
5352
|
+
* the reason this exists: the offline notice runs while the daemon is tearing
|
|
5353
|
+
* down, so a network refresh would outlive the AUN connection it needs.
|
|
5354
|
+
* Admission itself is unchanged — the block below still demands a live
|
|
5355
|
+
* consensus in the resolver cache, so this skips the check of the cache's
|
|
5356
|
+
* freshness, never the requirement that a consensus exists.
|
|
5357
|
+
*/
|
|
5358
|
+
acceptsVerifiedOwnership(channelId, payload, params) {
|
|
5359
|
+
if (params?.ownershipVerified !== true)
|
|
5360
|
+
return false;
|
|
5361
|
+
const notice = payload;
|
|
5362
|
+
if (!notice || notice.type !== 'notice'
|
|
5363
|
+
|| (notice.subtype !== 'agent.online' && notice.subtype !== 'agent.offline'))
|
|
5364
|
+
return false;
|
|
5365
|
+
// Even if the flag ever leaked, it cannot widen admission: the target must be
|
|
5366
|
+
// the Owner the live consensus names, which admission allows unconditionally.
|
|
5367
|
+
return currentContactBinding(this.config.aid)?.owner_aid === channelId;
|
|
5368
|
+
}
|
|
5311
5369
|
async sendAunPayload(channelId, payload, context, label) {
|
|
5312
5370
|
const delivery = this.requireDelivery(channelId, context);
|
|
5313
5371
|
const blocked = await this.prepareAppContactOutbound(channelId, delivery, payload);
|
|
@@ -5904,7 +5962,7 @@ export class AUNChannel {
|
|
|
5904
5962
|
code: 'INVALID_REQUEST_TTL',
|
|
5905
5963
|
};
|
|
5906
5964
|
}
|
|
5907
|
-
const contactBlock = await this.prepareAppContactOutbound(args.to, { chatType: 'private' }, finalPayload, { encrypt: args.encrypt, rawPayload: preserveRawPayload });
|
|
5965
|
+
const contactBlock = await this.prepareAppContactOutbound(args.to, { chatType: 'private' }, finalPayload, { encrypt: args.encrypt, rawPayload: preserveRawPayload, ownershipVerified: args.ownershipVerified === true });
|
|
5908
5966
|
if (contactBlock)
|
|
5909
5967
|
return { ok: false, code: contactBlock.code, error: contactBlock.error };
|
|
5910
5968
|
if (preserveRawPayload && jsonUtf8Size(finalPayload) > AUN_MAX_PAYLOAD_SIZE) {
|
|
@@ -6052,6 +6110,7 @@ export class AUNChannel {
|
|
|
6052
6110
|
// Preserve the notice verbatim: no session state, topic name or mentions.
|
|
6053
6111
|
rawPayload: true,
|
|
6054
6112
|
ttl,
|
|
6113
|
+
ownershipVerified: args.ownershipVerified,
|
|
6055
6114
|
});
|
|
6056
6115
|
}
|
|
6057
6116
|
/** Public contracts use this AID's existing authenticated storage connection. */
|
|
@@ -7464,8 +7523,8 @@ export class AUNChannel {
|
|
|
7464
7523
|
async sendCustomPayload(channelId, payload, context) {
|
|
7465
7524
|
// Validate the route even when disconnected; callers must never be able
|
|
7466
7525
|
// to bypass the fail-closed AUN routing contract. This compatibility API
|
|
7467
|
-
// is
|
|
7468
|
-
//
|
|
7526
|
+
// is best-effort while offline except for Menu responses, whose callers
|
|
7527
|
+
// must receive the failure to retry or report the delivery outcome.
|
|
7469
7528
|
const delivery = this.requireDelivery(channelId, context);
|
|
7470
7529
|
context = this.withDelivery(context, delivery);
|
|
7471
7530
|
// SDK 0.3.0 E2EE requires payload to be an object
|
|
@@ -7485,6 +7544,11 @@ export class AUNChannel {
|
|
|
7485
7544
|
return;
|
|
7486
7545
|
}
|
|
7487
7546
|
if (!this.connected || !this.client) {
|
|
7547
|
+
if (payloadObj.type === 'menu.response') {
|
|
7548
|
+
throw Object.assign(new Error('AUN channel is not connected'), {
|
|
7549
|
+
name: 'AUNSendError', code: 'AUN_NOT_CONNECTED', retryable: true,
|
|
7550
|
+
});
|
|
7551
|
+
}
|
|
7488
7552
|
logger.debug(`${this.logPrefix()} Custom payload skipped while disconnected: channel=${channelId}`);
|
|
7489
7553
|
return;
|
|
7490
7554
|
}
|
|
@@ -7497,8 +7561,7 @@ export class AUNChannel {
|
|
|
7497
7561
|
* 传入预算时到点就往下走,不再等 SDK。
|
|
7498
7562
|
*/
|
|
7499
7563
|
async disconnect(clientCloseBudgetMs) {
|
|
7500
|
-
this.
|
|
7501
|
-
this.configuredOwnerBindEpoch++;
|
|
7564
|
+
this.prepareShutdown();
|
|
7502
7565
|
if (this.client) {
|
|
7503
7566
|
unregisterSameOwnerClient(this.config.aid, this.client);
|
|
7504
7567
|
ownerResolver.detachClient(this.config.aid, this.client);
|
package/dist/cli/agent-create.js
CHANGED
|
@@ -26,6 +26,7 @@ import { creationOwnershipBinding } from '../core/ownership/owner-resolver.js';
|
|
|
26
26
|
import { getCatalog, getProviderCatalog, resolveCatalogModel, catalogEfforts, assertCatalogSelectable } from '../core/model/model-catalog.js';
|
|
27
27
|
import { resolveProviderId, resolveProviderServiceForBaseagent } from '../config/providers.js';
|
|
28
28
|
import { claimAgentCreation, claimAgentCreationAsync, readAgentCreationClaim, updateAgentCreationClaim } from '../core/agent-creation-claim.js';
|
|
29
|
+
import { initializationRuntimePlan } from '../config/providers-config.js';
|
|
29
30
|
/** Select the creation lifecycle independently of --non-interactive. */
|
|
30
31
|
export function resolveAgentCreateMode(args) {
|
|
31
32
|
if (args.includes('--initialize') && args.includes('--bootstrap')) {
|
|
@@ -970,6 +971,12 @@ export function readInitialization(aid) {
|
|
|
970
971
|
if (fingerprint !== record.fingerprint)
|
|
971
972
|
throw new InitializationStateError('fingerprint_mismatch');
|
|
972
973
|
}
|
|
974
|
+
try {
|
|
975
|
+
initializationRuntimePlan(record);
|
|
976
|
+
}
|
|
977
|
+
catch {
|
|
978
|
+
throw new InitializationStateError('invalid_record');
|
|
979
|
+
}
|
|
973
980
|
return record;
|
|
974
981
|
}
|
|
975
982
|
export function saveInitialization(record) {
|
|
@@ -1251,13 +1258,15 @@ export class AgentInitializationService {
|
|
|
1251
1258
|
usable: complete && this.deps.usable(aid), initialization: summary,
|
|
1252
1259
|
};
|
|
1253
1260
|
}
|
|
1254
|
-
start(plan, actor, dryRun = false) {
|
|
1261
|
+
start(plan, actor, dryRun = false, providerMigration) {
|
|
1255
1262
|
if (this.deps.authorize && !this.deps.authorize(actor))
|
|
1256
1263
|
failure('NOT_ALLOWED');
|
|
1257
|
-
validateInitializationPlan(plan);
|
|
1258
1264
|
plan = JSON.parse(JSON.stringify(plan));
|
|
1259
|
-
|
|
1265
|
+
assertAgentAidAvailable(plan.aid);
|
|
1260
1266
|
const existing = readInitialization(plan.aid);
|
|
1267
|
+
if (!existing)
|
|
1268
|
+
validateInitializationPlan(initializationRuntimePlan({ plan, providerMigration }));
|
|
1269
|
+
const fingerprint = initializationFingerprint(plan);
|
|
1261
1270
|
if (existing) {
|
|
1262
1271
|
if (recordMode(existing) !== 'supplied' || existing.actor !== actor || existing.fingerprint !== fingerprint)
|
|
1263
1272
|
failure('INITIALIZE_PLAN_CONFLICT');
|
|
@@ -1276,6 +1285,7 @@ export class AgentInitializationService {
|
|
|
1276
1285
|
}
|
|
1277
1286
|
const r = {
|
|
1278
1287
|
version: 1, operationId: `init-${randomBytes(12).toString('hex')}`, actor, plan, fingerprint,
|
|
1288
|
+
...(providerMigration ? { providerMigration } : {}),
|
|
1279
1289
|
status: 'in_progress', phase: 'planned', startedAt: Date.now(), updatedAt: Date.now(),
|
|
1280
1290
|
};
|
|
1281
1291
|
const claim = claimAgentCreation({
|
|
@@ -1434,7 +1444,7 @@ export class AgentInitializationService {
|
|
|
1434
1444
|
if (r.status === 'cancelled')
|
|
1435
1445
|
failure('INITIALIZE_CANCELLED');
|
|
1436
1446
|
if (r.status !== 'complete' && !this.running.has(aid)) {
|
|
1437
|
-
validateInitializationPlan(r
|
|
1447
|
+
validateInitializationPlan(initializationRuntimePlan(r));
|
|
1438
1448
|
r.status = 'in_progress';
|
|
1439
1449
|
if (r.bindAttempt?.state === 'unknown') {
|
|
1440
1450
|
// A prior local diagnostic (for example TARGET_CHANGED after a
|
|
@@ -1596,7 +1606,7 @@ export class AgentInitializationService {
|
|
|
1596
1606
|
// they do on initial creation. Only explicit plan overrides are frozen.
|
|
1597
1607
|
if (config && r.plan.provider !== undefined
|
|
1598
1608
|
&& (typeof baseagentConfig?.provider !== 'string'
|
|
1599
|
-
|| resolveProviderId(baseagentConfig.provider) !== resolveProviderId(r.
|
|
1609
|
+
|| resolveProviderId(baseagentConfig.provider) !== resolveProviderId(initializationRuntimePlan(r).provider)))
|
|
1600
1610
|
failure('INITIALIZE_TARGET_CHANGED');
|
|
1601
1611
|
if (config && r.plan.chatmode !== undefined
|
|
1602
1612
|
&& ['private', 'group', 'nothuman'].some(scope => config.chatmode?.[scope] !== r.plan.chatmode?.[scope])) {
|
|
@@ -1749,7 +1759,7 @@ export class AgentInitializationService {
|
|
|
1749
1759
|
return true;
|
|
1750
1760
|
}
|
|
1751
1761
|
async run(r) {
|
|
1752
|
-
const p = r
|
|
1762
|
+
const p = initializationRuntimePlan(r);
|
|
1753
1763
|
// Resume from the durable checkpoint. In particular, never call aidCreate
|
|
1754
1764
|
// again after the bind/activation stages have created the local config.
|
|
1755
1765
|
if (!r.configSaved) {
|
package/dist/cli/aun-commands.js
CHANGED
|
@@ -1770,9 +1770,10 @@ Commands:
|
|
|
1770
1770
|
online <from> <target-aid> [<target-aid>...] 查询在线状态
|
|
1771
1771
|
history <from> [<target-aid>|selector] [筛选选项] 查询本地消息历史
|
|
1772
1772
|
|
|
1773
|
-
托管会话简化语法(EVOLCORE_SESSION_ID
|
|
1773
|
+
托管会话简化语法(EVOLCORE_SESSION_ID 已设时;正式回复请用 ecmsg send):
|
|
1774
1774
|
send <text> --thread <id> from/to 从运行时上下文与话题索引自动推断
|
|
1775
1775
|
send <text> 发送到当前会话对端
|
|
1776
|
+
ecmsg send '<text>' [--thread <id>|--to <对端ID>] 统一入口,跨话题自动建复查
|
|
1776
1777
|
|
|
1777
1778
|
Options:
|
|
1778
1779
|
--text-from-file <path> 从文件读取文本(UTF-8),用于超长消息或避免 Shell 转义
|
|
@@ -2584,6 +2585,7 @@ visitor 不开放历史;群权限仍由托管会话校验。`);
|
|
|
2584
2585
|
send <from> <group-id> <text> 发送群文本
|
|
2585
2586
|
send <from> <group-id> --file <path> [--as <type>] 发送群文件
|
|
2586
2587
|
send <from> <group-id> --payload <json> 发送自定义 payload
|
|
2588
|
+
(托管会话发消息统一用 ecmsg send '<text>' --to <群ID>,见 ecmsg --help)
|
|
2587
2589
|
pull <from> <group-id> [--after-seq N] [--limit N] --app <name> 拉取群消息(必须使用独立 slot)
|
|
2588
2590
|
ack <from> <group-id> <seq> [--app <name>] 确认已读
|
|
2589
2591
|
history <from> <group-id> [options] 查询本地群消息历史(只读)
|
|
@@ -3643,6 +3645,12 @@ export function resolveManagedSendArgv(argv, routing) {
|
|
|
3643
3645
|
text.push(...argv.slice(index + 1));
|
|
3644
3646
|
break;
|
|
3645
3647
|
}
|
|
3648
|
+
// `--to` / `--from` 是网关选项,托管发送用位置参数表达 from/to。它们不在
|
|
3649
|
+
// 取值表里,落到下面就会进 text —— 正文会变成「--to x.agentid.cn 你好」,
|
|
3650
|
+
// 消息照常送达,于是没人发现发错了。这里明确拒绝,让调用方改写法。
|
|
3651
|
+
if (flag === '--to' || flag === '--from') {
|
|
3652
|
+
throw new Error(`${flag} is not supported by managed send; use positional from/to, or \`ecmsg send --to <aid>\``);
|
|
3653
|
+
}
|
|
3646
3654
|
if (flag === '--app' || flag === '--aun-path')
|
|
3647
3655
|
throw new Error(`${flag} is not allowed for managed sends`);
|
|
3648
3656
|
if (booleanFlags.has(flag))
|
|
@@ -1511,6 +1511,28 @@ function renderStatusOverview(snapshot) {
|
|
|
1511
1511
|
['Memory', `${Number.isFinite(totalMemory) ? `${formatBytes(totalMemory)} 主机总量` : '主机信息不可用'}${processMemory}`],
|
|
1512
1512
|
];
|
|
1513
1513
|
renderStatusFields(overviewFields);
|
|
1514
|
+
const startup = snapshot.daemon.startup;
|
|
1515
|
+
if (startup) {
|
|
1516
|
+
const phases = { classifying: '识别待恢复任务(控制面可用)', recovering: '优先恢复进行中任务', loading: '加载其余 Agent', ready: '正常 Ready', failed: '启动未就绪(关键模块失败)' };
|
|
1517
|
+
const states = { waiting: '等待前置阶段', starting: '启动中', recovering: '恢复运行中任务', ready: '已就绪', failed: '失败', disabled: '已禁用' };
|
|
1518
|
+
const agents = startup.agents;
|
|
1519
|
+
renderStatusFields([
|
|
1520
|
+
['启动进度', phases[startup.phase]],
|
|
1521
|
+
['已加载', `Runner ${agents.filter(agent => agent.runner === 'ready').length}/${agents.length}`
|
|
1522
|
+
+ ` · AUN ${agents.filter(agent => agent.aun).length}/${agents.length}`
|
|
1523
|
+
+ ` · 恢复登记 ${agents.filter(agent => agent.recovery).length}/${agents.length}`
|
|
1524
|
+
+ ` · Trigger ${startup.triggers.loaded}/${startup.triggers.total}`],
|
|
1525
|
+
['ECWeb 启动', states[startup.ecweb]],
|
|
1526
|
+
...(startup.priorityRelease === 'timeout' || startup.optionalRelease === 'timeout'
|
|
1527
|
+
? [['启动放行', '已按等待预算放行后续模块;正常 Ready 仍按实际条件判断']] : []),
|
|
1528
|
+
]);
|
|
1529
|
+
if (startup.phase !== 'ready') {
|
|
1530
|
+
renderStatusTable(['Agent', '启动组', 'Runner', 'AUN', '恢复登记', 'Trigger'], agents.map(agent => [
|
|
1531
|
+
agent.aid, startup.phase === 'classifying' ? '待判断' : agent.priority ? '优先恢复' : '空闲', states[agent.runner], agent.aun ? '已连接' : '等待连接',
|
|
1532
|
+
agent.recovery ? '完成' : '等待恢复', states[agent.trigger],
|
|
1533
|
+
]));
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1514
1536
|
const baseagents = snapshot.baseagents?.items;
|
|
1515
1537
|
const activity = snapshot.activity;
|
|
1516
1538
|
if (activity) {
|
|
@@ -1781,6 +1803,7 @@ async function collectStatusSnapshot() {
|
|
|
1781
1803
|
build: statusResponse?.build
|
|
1782
1804
|
? { runtimeMode: statusResponse.build.runtimeMode, version: statusResponse.build.version ?? null } : null,
|
|
1783
1805
|
queue: statusResponse?.queue ?? { pending: null, processing: null },
|
|
1806
|
+
startup: statusResponse?.startup,
|
|
1784
1807
|
restartMonitorPids: restartMonitors.map(item => item.record.pid),
|
|
1785
1808
|
},
|
|
1786
1809
|
baseagents: statusResponse?.baseagents ?? { source: 'unavailable', items: [] },
|
|
@@ -1816,7 +1839,7 @@ async function collectStatusSnapshot() {
|
|
|
1816
1839
|
? { source: 'runtime+history', ...statusResponse.triggers }
|
|
1817
1840
|
: { source: 'unavailable', enabled: null, today: { calls: null, failures: null } },
|
|
1818
1841
|
proxy: statusResponse?.serviceProxy ?? { source: 'unavailable', items: [] },
|
|
1819
|
-
ecweb, diagnostics,
|
|
1842
|
+
ecweb: { ...ecweb, startupState: statusResponse?.startup?.ecweb }, diagnostics,
|
|
1820
1843
|
};
|
|
1821
1844
|
}
|
|
1822
1845
|
function renderStatusHeader(snapshot) {
|
|
@@ -3315,6 +3338,12 @@ function renderEcwebStatus(status) {
|
|
|
3315
3338
|
console.log(` 命令行输入 ${MAIN_CLI_BIN} watch web/${WEB_CLI_BIN} 获取配对码`);
|
|
3316
3339
|
}
|
|
3317
3340
|
}
|
|
3341
|
+
else if (status.startupState === 'waiting') {
|
|
3342
|
+
console.log('🔭 ECWeb: 等待优先恢复组放行,将与空闲 Agent 一起启动');
|
|
3343
|
+
}
|
|
3344
|
+
else if (status.startupState === 'starting' && status.status !== 'process-not-ready') {
|
|
3345
|
+
console.log('🔭 ECWeb: 正在启动,等待健康检查');
|
|
3346
|
+
}
|
|
3318
3347
|
else if (status.status === 'process-not-ready') {
|
|
3319
3348
|
if (status.reason === 'daemon-not-ready') {
|
|
3320
3349
|
const detail = status.readinessError ? `:${status.readinessError}` : '';
|
|
@@ -139,7 +139,9 @@ export function buildDownstreamArgv(route, text, passthrough) {
|
|
|
139
139
|
const argv = targetAsPositional
|
|
140
140
|
? [scope, 'send', route.self, route.peer.id, ...text, ...passthrough]
|
|
141
141
|
: [scope, 'send', route.self, ...text, ...passthrough];
|
|
142
|
-
|
|
142
|
+
// 首次联系:主话题还没被创建,带上 --thread 反而会被下游判成"话题不存在",
|
|
143
|
+
// 所以按普通私聊发出,会话随这条消息建立,也就不建复查。
|
|
144
|
+
if (route.crossTopic && route.threadId && !route.firstContact) {
|
|
143
145
|
argv.push('--thread', route.threadId);
|
|
144
146
|
if (route.checkEveryMs)
|
|
145
147
|
argv.push('--check-every', formatDuration(route.checkEveryMs));
|
package/dist/cli/init.js
CHANGED
|
@@ -100,6 +100,72 @@ function buildDefaults(chosen, available, projectsDefaultPath) {
|
|
|
100
100
|
function writeDefaults(chosen, available, projectsDefaultPath) {
|
|
101
101
|
saveDefaultsSafe(buildDefaults(chosen, available, projectsDefaultPath));
|
|
102
102
|
}
|
|
103
|
+
export async function importProvidersForCliInit(available, options = {}) {
|
|
104
|
+
const { providerFromBaseagent } = await import('../config/providers-import.js');
|
|
105
|
+
const { importOrMergeBaseagentProvider, readProvidersSnapshot } = await import('../config/providers-management.js');
|
|
106
|
+
const { readProvidersFile } = await import('../config/providers.js');
|
|
107
|
+
const { resolveProviderId, resolveProviderServiceForBaseagent } = await import('../config/providers-config.js');
|
|
108
|
+
const { ConfigTarget, mutateConfig } = await import('../config/config-manager.js');
|
|
109
|
+
const imported = [];
|
|
110
|
+
const warnings = [];
|
|
111
|
+
for (const baseagent of available) {
|
|
112
|
+
let value;
|
|
113
|
+
try {
|
|
114
|
+
value = (options.source ?? providerFromBaseagent)(baseagent);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
warnings.push({ baseagent, code: 'LOCAL_PROVIDER_SOURCE_UNAVAILABLE' });
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const result = await importOrMergeBaseagentProvider({ revision: readProvidersSnapshot().revision, value });
|
|
122
|
+
imported.push({ baseagent, providerId: result.providerId, merged: result.merged });
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
const code = error.code;
|
|
126
|
+
warnings.push({ baseagent, code: ['PROVIDER_CONFLICT', 'PROVIDER_ID_COLLISION', 'CONFLICT'].includes(code ?? '') ? code : 'PROVIDER_IMPORT_FAILED' });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const snapshot = readProvidersSnapshot();
|
|
130
|
+
const registry = readProvidersFile();
|
|
131
|
+
mutateConfig(ConfigTarget.Defaults, undefined, defaults => {
|
|
132
|
+
if (readProvidersSnapshot().revision !== snapshot.revision)
|
|
133
|
+
throw new Error('Providers changed during CLI initialization; retry');
|
|
134
|
+
defaults.baseagents ??= {};
|
|
135
|
+
for (const baseagent of available) {
|
|
136
|
+
const selection = defaults.baseagents[baseagent] ??= {};
|
|
137
|
+
const usable = (providerId) => {
|
|
138
|
+
try {
|
|
139
|
+
return !!resolveProviderServiceForBaseagent(providerId, baseagent, undefined, registry).apiKey?.trim();
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const providerId = selection.provider && usable(selection.provider) ? resolveProviderId(selection.provider, registry)
|
|
146
|
+
: imported.find(item => item.baseagent === baseagent)?.providerId ?? Object.keys(registry.providers).find(usable);
|
|
147
|
+
if (providerId && usable(providerId))
|
|
148
|
+
selection.provider = providerId;
|
|
149
|
+
else
|
|
150
|
+
warnings.push({ baseagent, code: 'PROVIDER_REQUIRED' });
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
if (!options.quiet) {
|
|
154
|
+
for (const item of imported)
|
|
155
|
+
console.log(`✓ Provider ${item.merged ? '已合并' : '已导入'}: ${item.baseagent} → ${item.providerId}`);
|
|
156
|
+
const messages = {
|
|
157
|
+
LOCAL_PROVIDER_SOURCE_UNAVAILABLE: '未找到可导入的本机连接或有效凭据',
|
|
158
|
+
PROVIDER_REQUIRED: '最终仍缺少可用 Provider',
|
|
159
|
+
PROVIDER_CONFLICT: 'Provider 域名配置冲突,未覆盖原配置',
|
|
160
|
+
PROVIDER_ID_COLLISION: 'Provider ID 冲突,未覆盖原配置',
|
|
161
|
+
CONFLICT: '配置已变更,请重试导入',
|
|
162
|
+
PROVIDER_IMPORT_FAILED: 'Provider 导入失败,未返回凭据详情',
|
|
163
|
+
};
|
|
164
|
+
for (const item of warnings)
|
|
165
|
+
console.warn(`⚠ ${item.baseagent}: ${messages[item.code]}(${item.code});可使用 ec provider import 或 ECWEB 检查并补齐。`);
|
|
166
|
+
}
|
|
167
|
+
return { imported, warnings };
|
|
168
|
+
}
|
|
103
169
|
function hasCompletedInitConfig() {
|
|
104
170
|
const p = resolvePaths();
|
|
105
171
|
const daemon = loadDaemonConfig();
|
|
@@ -442,6 +508,7 @@ export async function cmdInit(options) {
|
|
|
442
508
|
await runInteractive();
|
|
443
509
|
}
|
|
444
510
|
// ── 共享 tail(单一出口):提示创建 agent + 生成控制 AID ──
|
|
511
|
+
await importProvidersForCliInit(available);
|
|
445
512
|
return initTail({
|
|
446
513
|
nonInteractive: options?.nonInteractive,
|
|
447
514
|
autoStart: options?.autoStart,
|
|
@@ -854,6 +921,13 @@ export async function cmdInitNonInteractive(opts, dependencies = {}) {
|
|
|
854
921
|
catch (e) {
|
|
855
922
|
fail('IO_ERROR', `failed to write defaults.json: ${e?.message || e}`, EXIT_RUNTIME, format);
|
|
856
923
|
}
|
|
924
|
+
let providers;
|
|
925
|
+
try {
|
|
926
|
+
providers = await importProvidersForCliInit(available, { quiet: format === 'json', source: dependencies.providerSource });
|
|
927
|
+
}
|
|
928
|
+
catch {
|
|
929
|
+
fail('PROVIDER_SETUP_FAILED', 'Provider 扫描或默认选择保存失败,请检查配置后重试;未返回凭据详情', EXIT_RUNTIME, format);
|
|
930
|
+
}
|
|
857
931
|
// ── 8. 控制 AID:缺失则生成 ──
|
|
858
932
|
let controlAid = existingCfg.aid;
|
|
859
933
|
if (!controlAid) {
|
|
@@ -927,6 +1001,7 @@ export async function cmdInitNonInteractive(opts, dependencies = {}) {
|
|
|
927
1001
|
ownerAid,
|
|
928
1002
|
ecwebEnabled: opts.ecweb === true || ecwebService(existingCfg.services)?.enabled === true,
|
|
929
1003
|
baseagent: chosenBaseagent,
|
|
1004
|
+
providers,
|
|
930
1005
|
projectsDefaultPath: projectsDefaultPath ?? null,
|
|
931
1006
|
defaultsPath: p.defaultsConfig,
|
|
932
1007
|
daemonConfigPath: p.daemonConfig,
|
|
@@ -26,7 +26,7 @@ function providerText(command, data) {
|
|
|
26
26
|
}
|
|
27
27
|
lines.push(`全局默认基座:${label(data.activeBaseagent)}`);
|
|
28
28
|
lines.push(data.selection ? `本次默认选择:${label(data.selection.provider)} / ${label(data.selection.model)}` : '本次默认选择:未重新选择');
|
|
29
|
-
lines.push(`待处理:${data.pending?.length ? data.pending.map(label).join('、') : '无'}`, `告警:${data.warnings?.length ? data.warnings.map(label).join('、') : '无'}`,
|
|
29
|
+
lines.push(`待处理:${data.pending?.length ? data.pending.map(label).join('、') : '无'}`, `告警:${data.warnings?.length ? data.warnings.map(label).join('、') : '无'}`, `备份版本:${data.backup ? label(data.backup) : data.warnings?.includes('CONFIG_SNAPSHOTS_DISABLED') ? '无(配置快照已关闭)' : '无(未产生变更)'}`);
|
|
30
30
|
}
|
|
31
31
|
else if (command.operation === 'list') {
|
|
32
32
|
const entries = Object.entries(data.providers ?? {});
|
|
@@ -20,6 +20,7 @@ import { DAEMON_SHUTDOWN_TIMEOUT_MS, requestDaemonShutdown, stopCodexAppServerOr
|
|
|
20
20
|
import { getProcessStartTime, invalidateProcessSnapshot, startTimeMatches } from '../utils/process-introspect.js';
|
|
21
21
|
import { DEFAULT_ECWEB_PORT, ecwebService, serviceRuntimeMode } from '../config/daemon-services.js';
|
|
22
22
|
import { stopEcwebForRestart } from '../ecweb/runtime/lifecycle.js';
|
|
23
|
+
import { StartupTracer, STARTUP_TRACE_ID_ENV } from '../utils/startup-trace.js';
|
|
23
24
|
const execFileAsync = promisify(execFile);
|
|
24
25
|
/** Read-only check performed before stopping the current daemon. */
|
|
25
26
|
function preflightDataMigration(root, log) {
|
|
@@ -222,6 +223,14 @@ export async function cmdRestartMonitor() {
|
|
|
222
223
|
};
|
|
223
224
|
// Keep this path available for a failed read-only preflight so a stale
|
|
224
225
|
// restart request cannot be replayed by a later daemon startup.
|
|
226
|
+
const trace = new StartupTracer('restart-monitor', {
|
|
227
|
+
traceId: process.env[STARTUP_TRACE_ID_ENV] || undefined,
|
|
228
|
+
firstPhase: 'monitor.bootstrap',
|
|
229
|
+
});
|
|
230
|
+
delete process.env[STARTUP_TRACE_ID_ENV];
|
|
231
|
+
trace.setMeta('operation', 'restart');
|
|
232
|
+
process.once('exit', () => trace.finish(false));
|
|
233
|
+
trace.mark('monitor.preflight');
|
|
225
234
|
log(`Restart monitor started (requestId=${requestId})`);
|
|
226
235
|
// 升级成功时记下版本变化,回执里要告诉 agent 实际跑的是哪个版本。
|
|
227
236
|
let upgradeVersions;
|
|
@@ -268,6 +277,7 @@ export async function cmdRestartMonitor() {
|
|
|
268
277
|
}
|
|
269
278
|
}
|
|
270
279
|
updateRestartMonitorPhase(process.pid, 'accepted');
|
|
280
|
+
trace.mark('monitor.stopDaemon');
|
|
271
281
|
log('Restart monitor accepted after migration preflight and monitor election');
|
|
272
282
|
if (upgradeJob) {
|
|
273
283
|
updateUpgradeJob(upgradeJob.jobId, { status: 'restart-started', success: true, phase: 'restart' }, '预检通过,已进入重启执行;不代表新进程已就绪');
|
|
@@ -441,6 +451,7 @@ export async function cmdRestartMonitor() {
|
|
|
441
451
|
cleanupPendingFile(pendingFile, log, hasCorrelatedRequest ? requestId : undefined);
|
|
442
452
|
process.exit(1);
|
|
443
453
|
}
|
|
454
|
+
trace.mark('monitor.packageUpgrade');
|
|
444
455
|
let upgradeBackup = null;
|
|
445
456
|
let upgrade;
|
|
446
457
|
if (applyPackageUpgrades) {
|
|
@@ -503,6 +514,7 @@ export async function cmdRestartMonitor() {
|
|
|
503
514
|
}
|
|
504
515
|
// 编译在 daemon 停止之后、拉起之前:此时没有活进程占着 dist/,
|
|
505
516
|
// 失败还能回滚到上一份可用产物,因此这一步整体是可撤销的。
|
|
517
|
+
trace.mark('monitor.sourceBuild');
|
|
506
518
|
const buildOutcome = await buildSourcesTransactionally(log);
|
|
507
519
|
if (buildOutcome.status === 'failed') {
|
|
508
520
|
const message = `服务未重启:${buildOutcome.reason ?? '构建失败'}`;
|
|
@@ -516,6 +528,7 @@ export async function cmdRestartMonitor() {
|
|
|
516
528
|
log(`↩ ${buildOutcome.reason ?? '已回滚'};继续以上一版本启动`);
|
|
517
529
|
await notifyDaemonOwners(p, `⚠️ ${buildOutcome.reason ?? '已回滚'},正在以上一版本启动服务`, log);
|
|
518
530
|
}
|
|
531
|
+
trace.mark('monitor.dataMigration');
|
|
519
532
|
const migration = applyPendingDataMigration(p.root, log);
|
|
520
533
|
if (!migration.ok) {
|
|
521
534
|
const message = `服务未重启:用户数据迁移失败(${migration.reason ?? 'unknown error'})`;
|
|
@@ -527,7 +540,7 @@ export async function cmdRestartMonitor() {
|
|
|
527
540
|
// daemon's own launcher and ECWeb's stale-instance cleanup, which could
|
|
528
541
|
// leave ServiceProxy pointed at a dead PID.
|
|
529
542
|
// 启动并检测 ready signal
|
|
530
|
-
let started = await spawnAndWaitReady(p, log, READY_TIMEOUT);
|
|
543
|
+
let started = await spawnAndWaitReady(p, log, READY_TIMEOUT, trace);
|
|
531
544
|
if (started) {
|
|
532
545
|
if (upgrade.status === 'upgraded' || upgrade.status === 'failed') {
|
|
533
546
|
await recordPackageUpgrade(MAIN_PACKAGE_NAME, {
|
|
@@ -565,7 +578,7 @@ export async function cmdRestartMonitor() {
|
|
|
565
578
|
}, log);
|
|
566
579
|
if (await restoreDistBackup(upgradeBackup, log)) {
|
|
567
580
|
await notifyDaemonOwners(p, `⚠️ 升级到 ${upgradeVersions.to} 后启动失败,正在回滚到 ${upgradeVersions.from} 重试...`, log);
|
|
568
|
-
started = await spawnAndWaitReady(p, log, READY_TIMEOUT);
|
|
581
|
+
started = await spawnAndWaitReady(p, log, READY_TIMEOUT, trace);
|
|
569
582
|
if (started) {
|
|
570
583
|
const reason = `升级到 ${upgradeVersions.to} 后启动失败,已回滚到 ${upgradeVersions.from}`;
|
|
571
584
|
await recordPackageUpgrade(MAIN_PACKAGE_NAME, {
|
|
@@ -586,7 +599,7 @@ export async function cmdRestartMonitor() {
|
|
|
586
599
|
const reverted = await revertToPreviousBuild(log);
|
|
587
600
|
if (reverted) {
|
|
588
601
|
await notifyDaemonOwners(p, '⚠️ 新编译产物启动失败,正在回滚到上一版本重试...', log);
|
|
589
|
-
started = await spawnAndWaitReady(p, log, READY_TIMEOUT);
|
|
602
|
+
started = await spawnAndWaitReady(p, log, READY_TIMEOUT, trace);
|
|
590
603
|
if (started) {
|
|
591
604
|
const reason = '新编译产物启动失败,已回滚到上一个可用版本';
|
|
592
605
|
log(`✓ ${reason}`);
|
|
@@ -664,7 +677,7 @@ export async function cmdRestartMonitor() {
|
|
|
664
677
|
continue;
|
|
665
678
|
}
|
|
666
679
|
// claude 正常完成但服务没自动启动,尝试 spawn
|
|
667
|
-
started = await spawnAndWaitReady(p, log, READY_TIMEOUT);
|
|
680
|
+
started = await spawnAndWaitReady(p, log, READY_TIMEOUT, trace);
|
|
668
681
|
if (started) {
|
|
669
682
|
log(`✓ Self-heal succeeded on attempt ${attempt}`);
|
|
670
683
|
markRequestReady();
|
|
@@ -1096,7 +1109,8 @@ function cleanupPendingFile(filePath, log, requestId) {
|
|
|
1096
1109
|
/**
|
|
1097
1110
|
* 启动新进程并等待 ready.signal
|
|
1098
1111
|
*/
|
|
1099
|
-
async function spawnAndWaitReady(p, log, timeout) {
|
|
1112
|
+
async function spawnAndWaitReady(p, log, timeout, trace) {
|
|
1113
|
+
trace.mark('monitor.spawnDaemon');
|
|
1100
1114
|
const ecweb = ecwebService(loadDaemonConfig().services);
|
|
1101
1115
|
const requireEcweb = ecweb?.enabled === true && serviceRuntimeMode(ecweb) === 'managed';
|
|
1102
1116
|
const ecwebPort = ecweb?.port ?? DEFAULT_ECWEB_PORT;
|
|
@@ -1128,6 +1142,7 @@ async function spawnAndWaitReady(p, log, timeout) {
|
|
|
1128
1142
|
...process.env,
|
|
1129
1143
|
EVOLCORE_HOME: p.root,
|
|
1130
1144
|
EVOLCORE_LAUNCHED_BY: 'restart-monitor',
|
|
1145
|
+
[STARTUP_TRACE_ID_ENV]: trace.id,
|
|
1131
1146
|
[RESTART_REQUEST_ID_ENV]: '',
|
|
1132
1147
|
LOG_LEVEL: process.env.LOG_LEVEL || 'INFO',
|
|
1133
1148
|
MESSAGE_LOG: process.env.MESSAGE_LOG || 'true',
|
|
@@ -1136,6 +1151,8 @@ async function spawnAndWaitReady(p, log, timeout) {
|
|
|
1136
1151
|
}
|
|
1137
1152
|
});
|
|
1138
1153
|
const childPid = child.pid;
|
|
1154
|
+
trace.setMeta('daemonPid', String(childPid));
|
|
1155
|
+
trace.mark('monitor.waitReady');
|
|
1139
1156
|
if (foreground) {
|
|
1140
1157
|
foregroundDaemonExit = new Promise(resolve => {
|
|
1141
1158
|
child.once('error', () => resolve(1));
|
|
@@ -1160,12 +1177,14 @@ async function spawnAndWaitReady(p, log, timeout) {
|
|
|
1160
1177
|
}
|
|
1161
1178
|
if (fs.existsSync(p.readySignal)) {
|
|
1162
1179
|
log('Daemon ready; managed services are supervised independently');
|
|
1180
|
+
trace.finish(true);
|
|
1163
1181
|
return true;
|
|
1164
1182
|
}
|
|
1165
1183
|
}
|
|
1166
1184
|
const ping = await ipcQuery(p.socket, { type: 'ping' }, platform.isWindows ? 5_000 : 1_000);
|
|
1167
1185
|
if (ping?.pong === true && ping.pid === childPid && platform.isProcessRunning(childPid)) {
|
|
1168
1186
|
log(`Daemon IPC is ready (PID: ${childPid}); startup finalization and managed services continue in background`);
|
|
1187
|
+
trace.finish(true);
|
|
1169
1188
|
return true;
|
|
1170
1189
|
}
|
|
1171
1190
|
log(`Daemon ready signal not received within ${timeout / 1000}s and identified IPC is unavailable`);
|