evolcore 0.0.39 → 0.0.41-test.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/README.md +31 -20
  3. package/bin/codex-managed-hook.mjs +11 -0
  4. package/bin/ec-safe-output.js +25 -3
  5. package/dist/agents/baseagent-availability.js +1 -0
  6. package/dist/agents/claude-runner.js +53 -152
  7. package/dist/agents/codex-runner.js +485 -241
  8. package/dist/agents/ecagent-runner.js +48 -18
  9. package/dist/agents/gemini-runner.js +27 -8
  10. package/dist/agents/runner-types.js +39 -9
  11. package/dist/aun/ability-device-routing.js +26 -0
  12. package/dist/aun/aid/client.js +1 -1
  13. package/dist/aun/aid/control-aid.js +23 -98
  14. package/dist/aun/aid/ownership-operation.js +1 -3
  15. package/dist/aun/group/identity.js +8 -0
  16. package/dist/aun/group/invite-service.js +6 -0
  17. package/dist/aun/msg/managed-operation.js +4 -4
  18. package/dist/aun/msg/p2p.js +28 -12
  19. package/dist/aun/storage/download.js +30 -0
  20. package/dist/aun/storage/index.js +14 -6
  21. package/dist/channels/aun.js +99 -52
  22. package/dist/channels/daemon.js +24 -4
  23. package/dist/channels/dingtalk.js +8 -2
  24. package/dist/channels/feishu.js +6 -1
  25. package/dist/channels/wecom.js +7 -3
  26. package/dist/cli/agent-command.js +2 -0
  27. package/dist/cli/agent-create.js +121 -23
  28. package/dist/cli/agent.js +10 -3
  29. package/dist/cli/aid-bind-command.js +4 -1
  30. package/dist/cli/aun-commands.js +82 -22
  31. package/dist/cli/daemon-commands.js +260 -26
  32. package/dist/cli/index.js +25 -13
  33. package/dist/cli/memory-command.js +33 -14
  34. package/dist/cli/restart-monitor.js +52 -13
  35. package/dist/cli/session-command.js +128 -13
  36. package/dist/cli/stats.js +60 -4
  37. package/dist/cli/task-context.js +1 -0
  38. package/dist/cli/trigger-command.js +2 -2
  39. package/dist/config/access-policy.js +2 -0
  40. package/dist/config/config-field-policy.js +1 -0
  41. package/dist/config/config-operation-service.js +17 -6
  42. package/dist/config/gateway-config.js +1 -1
  43. package/dist/config/peer-role-resolver.js +10 -8
  44. package/dist/contracts/ecweb-service-protocol.js +44 -0
  45. package/dist/core/agent-application-service.js +11 -1
  46. package/dist/core/agent-ipc-registration.js +4 -0
  47. package/dist/core/agent-runtime.js +6 -0
  48. package/dist/core/auth/agent-delegation.js +87 -9
  49. package/dist/core/auth/auth-gateway.js +3 -1
  50. package/dist/core/auth/authorization-audit.js +25 -4
  51. package/dist/core/auth/debug-context.js +5 -1
  52. package/dist/core/auth/operation-catalog.js +24 -0
  53. package/dist/core/command/agent-control.js +91 -12
  54. package/dist/core/command/command-handler.js +64 -47
  55. package/dist/core/command/connect-menu.js +23 -2
  56. package/dist/core/command/menu-catalog.js +49 -12
  57. package/dist/core/command/menu-handler.js +110 -105
  58. package/dist/core/command/menu-protocol.js +29 -3
  59. package/dist/core/command/role-menu.js +7 -6
  60. package/dist/core/command/slash-gate.js +22 -5
  61. package/dist/core/command/slash-handler.js +121 -102
  62. package/dist/core/event-catalog.js +17 -0
  63. package/dist/core/interaction-router.js +2 -1
  64. package/dist/core/ipc-registration.js +44 -8
  65. package/dist/core/memory/batch-meta.js +2 -0
  66. package/dist/core/memory/consolidation-context.js +42 -51
  67. package/dist/core/memory/consolidation-ops-records.js +39 -7
  68. package/dist/core/memory/consolidation-trigger.js +72 -65
  69. package/dist/core/memory/consolidation.js +226 -20
  70. package/dist/core/memory/memory-writer.js +160 -34
  71. package/dist/core/memory/relation-idle-monitor.js +287 -0
  72. package/dist/core/memory/relation-sweep.js +206 -0
  73. package/dist/core/message/aun-ipc-sender.js +31 -5
  74. package/dist/core/message/aun-request-registry.js +97 -3
  75. package/dist/core/message/im-renderer.js +4 -0
  76. package/dist/core/message/message-admission.js +8 -4
  77. package/dist/core/message/message-bridge.js +96 -53
  78. package/dist/core/message/message-log.js +72 -0
  79. package/dist/core/message/message-queue.js +11 -5
  80. package/dist/core/message/outbound.js +70 -0
  81. package/dist/core/message/peer-mode.js +7 -2
  82. package/dist/core/message/response-engine.js +633 -191
  83. package/dist/core/model/model-catalog.js +7 -6
  84. package/dist/core/ownership/owner-resolver.js +384 -178
  85. package/dist/core/permission/ec-command-parser.js +129 -8
  86. package/dist/core/permission/tool-policy.js +35 -14
  87. package/dist/core/role/runtime-policy.js +64 -0
  88. package/dist/core/session/session-capsule.js +197 -0
  89. package/dist/core/session/session-manager.js +172 -18
  90. package/dist/core/session/session-mapper.js +2 -0
  91. package/dist/core/system-session/memory.js +3 -18
  92. package/dist/ecweb/basic-settings-service.js +709 -0
  93. package/dist/ecweb/providers-service.js +172 -0
  94. package/dist/index.js +95 -7
  95. package/dist/ipc.js +100 -19
  96. package/dist/stats/budget.js +1 -1
  97. package/dist/stats/db.js +48 -0
  98. package/dist/stats/index.js +3 -3
  99. package/dist/stats/price-resolver.js +304 -5
  100. package/dist/stats/query.js +328 -3
  101. package/dist/stats/writer.js +79 -6
  102. package/dist/trigger/application-service.js +12 -0
  103. package/dist/trigger/authorization.js +2 -2
  104. package/dist/trigger/feedback.js +18 -7
  105. package/dist/trigger/history.js +36 -0
  106. package/dist/trigger/manager.js +20 -3
  107. package/dist/trigger/parser.js +6 -3
  108. package/dist/trigger/patch.js +1 -1
  109. package/dist/trigger/scheduler.js +3 -0
  110. package/dist/trigger/system-definitions.js +43 -7
  111. package/dist/trigger/validation.js +13 -5
  112. package/dist/utils/ecweb-supervisor.js +31 -10
  113. package/dist/utils/error-utils.js +22 -4
  114. package/dist/utils/evolcore-version.js +3 -2
  115. package/dist/utils/host-info.js +52 -0
  116. package/dist/utils/npm-ops.js +2 -1
  117. package/dist/utils/package-version-info.js +1 -1
  118. package/dist/utils/upgrade-jobs.js +45 -5
  119. package/ecagent/dist/harness/agent-harness.js +4 -1
  120. package/kits/docs/INDEX.md +1 -1
  121. package/kits/docs/aun/ABILITY_CALLING.md +20 -2
  122. package/kits/docs/evolcore/INDEX.md +3 -2
  123. package/kits/docs/evolcore/agent-create.md +3 -2
  124. package/kits/docs/evolcore/agent.md +1 -1
  125. package/kits/docs/evolcore/aid.md +29 -12
  126. package/kits/docs/evolcore/config.md +9 -7
  127. package/kits/docs/evolcore/event.md +1 -0
  128. package/kits/docs/evolcore/fs.md +5 -0
  129. package/kits/docs/evolcore/memory-architecture.md +3 -4
  130. package/kits/docs/evolcore/memory-consolidation.md +28 -7
  131. package/kits/docs/evolcore/memory-tags.md +1 -1
  132. package/kits/docs/evolcore/memory.md +1 -1
  133. package/kits/docs/evolcore/menu-client.md +1 -1
  134. package/kits/docs/evolcore/menu-protocol.md +38 -0
  135. package/kits/docs/evolcore/msg.md +18 -2
  136. package/kits/docs/evolcore/session.md +14 -0
  137. package/kits/eck_manifest.json +3 -3
  138. package/kits/rules/04-relation.md +3 -2
  139. package/kits/schemas/agent-config.schema.13.json +20 -1
  140. package/kits/skills/aid-ability/SKILL.md +35 -6
  141. package/kits/templates/memory-consolidation/generalize.md +32 -4
  142. package/kits/templates/memory-consolidation/notes.md +2 -2
  143. package/kits/templates/memory-consolidation/promote.md +10 -2
  144. package/kits/templates/session-capsule/recovery.md +5 -0
  145. package/kits/templates/session-capsule/renew.md +5 -0
  146. package/kits/templates/system-fragments/baseagent.md +5 -0
  147. package/kits/templates/system-fragments/bootstrap.md +6 -6
  148. package/kits/templates/system-fragments/channel.md +1 -1
  149. package/kits/templates/system-fragments/memory.md +12 -3
  150. package/kits/templates/system-fragments/session.md +1 -1
  151. package/kits/{rules/07-memory-and-thread.md → templates/system-fragments/thread.md} +17 -80
  152. package/package.json +3 -3
  153. package/dist/stats/billing.js +0 -215
@@ -31,6 +31,8 @@ import { rotateStdoutLog } from '../utils/log-writer.js';
31
31
  import { inspectDataMigrationRequirement } from '../core/data-migration.js';
32
32
  import { isInitCancelledError, printInitCancelHint } from './init-cancel.js';
33
33
  import { computeBuildId } from '../utils/evolcore-version.js';
34
+ import { readHostInfo } from '../utils/host-info.js';
35
+ import { queryStatusActivity, queryStatusActivityByAgent } from '../stats/query.js';
34
36
  import { listCodexAppServerProcesses, unregisterCodexAppServerProcess } from '../agents/codex/app-server-registry.js';
35
37
  import { DEFAULT_ECWEB_PORT, ecwebService, setEcwebEnabled } from '../config/daemon-services.js';
36
38
  import { checkCodexProjectPath, inspectCodexManagedHook, ensureCodexManagedHook, runCodexHookLaunchDiagnostic, } from '../agents/codex/diagnostics.js';
@@ -301,7 +303,20 @@ async function requireFreshSourceBuild() {
301
303
  async function launchPackageLifecycle(source, log, options = {}) {
302
304
  const correlated = options.requestId ?? process.env[RESTART_REQUEST_ID_ENV];
303
305
  const upgradeJobId = correlated ? readRestartRequest(path.join(daemonControlDir(), 'restart-pending.json'), correlated)?.upgradeJobId : undefined;
304
- if (!options.prepared && !upgradeJobId)
306
+ let configuredAutoUpgrade = true;
307
+ if (!upgradeJobId && options.applyPackageUpgrades === undefined) {
308
+ try {
309
+ configuredAutoUpgrade = loadDaemonConfig().upgrade?.autoOnStart !== false;
310
+ }
311
+ catch {
312
+ configuredAutoUpgrade = false;
313
+ log('Could not read autoOnStart; skipping automatic package upgrade');
314
+ }
315
+ }
316
+ const applyPackageUpgrades = upgradeJobId
317
+ ? true
318
+ : options.applyPackageUpgrades ?? configuredAutoUpgrade;
319
+ if (!options.prepared && !upgradeJobId && applyPackageUpgrades)
305
320
  await ensureFreshPackageVersionInfo(undefined, { source, log });
306
321
  const root = resolvePaths().root;
307
322
  const launch = platform.resolveMonitorLaunch(getPackageRoot(), path.join(root, 'data', 'monitor-stage'));
@@ -313,7 +328,12 @@ async function launchPackageLifecycle(source, log, options = {}) {
313
328
  return { ok: false, reason: 'RESTART_ENTRY_MISSING' };
314
329
  }
315
330
  const requestId = options.requestId ?? process.env[RESTART_REQUEST_ID_ENV];
316
- const args = [...launch.args, 'restart-monitor', ...(options.clear ? ['--clear'] : [])];
331
+ const args = [
332
+ ...launch.args,
333
+ 'restart-monitor',
334
+ ...(options.clear ? ['--clear'] : []),
335
+ applyPackageUpgrades ? '--apply-package-upgrades' : '--skip-package-upgrades',
336
+ ];
317
337
  const env = {
318
338
  ...options.env,
319
339
  [RUNTIME_HOME_ENV]: root,
@@ -758,7 +778,7 @@ export async function cmdStart(opts = {}) {
758
778
  // 这条路由 restart-monitor 拉起 daemon,同样靠覆盖文件把 --as-mode 带过去
759
779
  const overrideFile = writeAsModeOverride(opts.asMode);
760
780
  const launched = await launchPackageLifecycle('start', console.log, {
761
- prepared: true, foreground: opts.foreground, env: buildDaemonEnv(p, opts),
781
+ prepared: true, foreground: opts.foreground, env: buildDaemonEnv(p, opts), applyPackageUpgrades: true,
762
782
  });
763
783
  if (!launched.ok) {
764
784
  if (!launched.pending)
@@ -1291,7 +1311,180 @@ function showConfigChannels(config) {
1291
1311
  console.log(' (no channels configured)');
1292
1312
  }
1293
1313
  }
1294
- export async function cmdStatus() {
1314
+ function showLiveChannels(status) {
1315
+ const channels = status?.channels;
1316
+ if (!channels || typeof channels !== 'object' || Array.isArray(channels))
1317
+ return false;
1318
+ const entries = Object.entries(channels);
1319
+ console.log('🔌 Channels (live status):');
1320
+ if (entries.length === 0) {
1321
+ console.log(' (no channel instances loaded)');
1322
+ return true;
1323
+ }
1324
+ for (const [name, channel] of entries) {
1325
+ const state = channel?.connected === true ? '✓ Connected'
1326
+ : channel?.connected === false ? '✗ Disconnected' : '? Unknown';
1327
+ const type = typeof channel?.channelType === 'string' ? ` (${channel.channelType})` : '';
1328
+ console.log(` ${name}: ${state}${type}`);
1329
+ }
1330
+ return true;
1331
+ }
1332
+ function localDayStartMs(now = new Date()) {
1333
+ return new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();
1334
+ }
1335
+ function statusActivityJson(window) {
1336
+ return {
1337
+ received: window.received,
1338
+ sent: window.sent,
1339
+ completed: window.completed,
1340
+ errors: window.errors,
1341
+ interrupts: window.interrupts,
1342
+ avgResponseMs: window.avgResponseMs,
1343
+ modelCalls: window.modelCalls,
1344
+ tokens: window.tokens,
1345
+ cost: window.cost,
1346
+ };
1347
+ }
1348
+ function readLocalPackageVersion() {
1349
+ try {
1350
+ const pkg = JSON.parse(fs.readFileSync(path.join(getPackageRoot(), 'package.json'), 'utf8'));
1351
+ return typeof pkg.version === 'string' ? pkg.version : null;
1352
+ }
1353
+ catch {
1354
+ return null;
1355
+ }
1356
+ }
1357
+ async function cmdStatusJson() {
1358
+ const p = resolvePaths();
1359
+ const started = Date.now();
1360
+ const instanceStatus = scanInstances();
1361
+ const aliveMains = instanceStatus.mains.filter(instance => instance.alive);
1362
+ let ipcError;
1363
+ const pingPromise = probeDaemon(p.socket, DAEMON_PROBE_TIMEOUT_MS, true).catch(error => {
1364
+ ipcError = error;
1365
+ return null;
1366
+ });
1367
+ const [ping, statusResponse, aidsResponse, agentsResponse, agentStatsResponse] = await Promise.all([
1368
+ pingPromise,
1369
+ ipcQuery(p.socket, { type: 'status' }).catch(() => null),
1370
+ ipcQuery(p.socket, { type: 'aun-aids' }).catch(() => null),
1371
+ ipcQuery(p.socket, { type: 'evolagent.list' }).catch(() => null),
1372
+ ipcQuery(p.socket, { type: 'agent-stats' }).catch(() => null),
1373
+ ]);
1374
+ const now = Date.now();
1375
+ const runningPid = ping?.pid ?? aliveMains[0]?.record.pid ?? null;
1376
+ const mainRecord = runningPid ? aliveMains.find(instance => instance.record.pid === runningPid)?.record : undefined;
1377
+ const statusAvailable = !!statusResponse;
1378
+ const overallStatus = statusAvailable
1379
+ ? 'running'
1380
+ : platform.isWindows && ipcError instanceof IpcTransportError
1381
+ && ['ENOENT', 'ECONNREFUSED'].includes(ipcError.code)
1382
+ ? 'stopped'
1383
+ : 'unknown';
1384
+ const todayStart = localDayStartMs(new Date(now));
1385
+ const lastHourActivity = queryStatusActivity(p.root, now - 3_600_000, now);
1386
+ const todayActivity = statusResponse?.activity?.today ?? queryStatusActivity(p.root, todayStart, now);
1387
+ const daemonLastHourActivity = statusResponse?.activity?.lastHour;
1388
+ const effectiveLastHourActivity = daemonLastHourActivity ?? lastHourActivity;
1389
+ const agents = agentsResponse?.agents ?? [];
1390
+ const agentStats = new Map((agentStatsResponse?.stats ?? []).map((item) => [item.aid, item]));
1391
+ const statusAgents = Array.isArray(statusResponse?.agents) ? statusResponse.agents : null;
1392
+ const agentUsage = statusAgents
1393
+ ? new Map()
1394
+ : queryStatusActivityByAgent(p.root, todayStart, now, agents.map((agent) => String(agent.aid ?? agent.name ?? '')));
1395
+ const diagnostics = [];
1396
+ if (!statusAvailable) {
1397
+ diagnostics.push({ code: 'DAEMON_IPC_UNAVAILABLE', message: ipcError instanceof Error ? ipcError.message : 'daemon status unavailable' });
1398
+ }
1399
+ const agentItems = statusAgents ?? agents.map((agent) => {
1400
+ const aid = String(agent.aid ?? agent.name ?? '');
1401
+ const runtime = agentStats.get(aid);
1402
+ const usage = agentUsage.get(aid) ?? queryStatusActivity(p.root, todayStart, now, aid);
1403
+ return {
1404
+ aid,
1405
+ name: agent.name ?? aid,
1406
+ status: agent.status ?? 'unknown',
1407
+ baseagent: agent.baseagent ?? null,
1408
+ model: agent.model ?? null,
1409
+ effort: agent.effort ?? null,
1410
+ queue: runtime ? { pending: runtime.queued ?? 0, processing: runtime.processing ?? 0 } : null,
1411
+ usage: {
1412
+ calls: usage.modelCalls,
1413
+ tokens: usage.tokens,
1414
+ cost: usage.cost,
1415
+ },
1416
+ };
1417
+ });
1418
+ const channels = Object.entries(statusResponse?.channels ?? {})
1419
+ .filter(([, channel]) => channel?.channelType !== 'aun')
1420
+ .map(([name, channel]) => ({
1421
+ name,
1422
+ type: channel?.channelType ?? name,
1423
+ status: channel?.status ?? (channel?.connected ? 'connected' : 'disconnected'),
1424
+ connected: channel?.connected ?? false,
1425
+ }));
1426
+ const aunItems = (aidsResponse?.aids ?? []).map((aid) => ({
1427
+ aid: aid.aid,
1428
+ channelName: aid.channelName,
1429
+ status: aid.status ?? 'unknown',
1430
+ connected: aid.status === 'connected',
1431
+ queue: aid.queueStatus ? {
1432
+ pending: aid.queueStatus.queued ?? 0,
1433
+ processing: aid.queueStatus.processing ?? 0,
1434
+ } : null,
1435
+ reconnectCount: aid.reconnectCount ?? 0,
1436
+ }));
1437
+ const host = statusResponse?.host ?? readHostInfo(readLocalPackageVersion());
1438
+ const ecwebEntry = readEcwebInstanceEntries(p)[0];
1439
+ const ecweb = ecwebEntry
1440
+ ? { source: 'instance-record', status: platform.isProcessRunning(ecwebEntry.record.pid) ? 'running' : 'unknown', port: ecwebEntry.record.port, url: `http://localhost:${ecwebEntry.record.port}` }
1441
+ : { source: 'instance-record', status: 'stopped', port: null, url: null };
1442
+ const triggerSummary = statusResponse?.triggers
1443
+ ? { source: 'runtime+history', ...statusResponse.triggers }
1444
+ : { source: 'unavailable', enabled: null, today: { calls: null, failures: null } };
1445
+ const build = statusResponse?.build
1446
+ ? { runtimeMode: statusResponse.build.runtimeMode, version: statusResponse.build.version ?? null }
1447
+ : null;
1448
+ const output = {
1449
+ schemaVersion: 1,
1450
+ generatedAt: new Date(now).toISOString(),
1451
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
1452
+ overall: {
1453
+ status: overallStatus,
1454
+ degraded: !statusAvailable || statusResponse?.agentRuntime?.state === 'error',
1455
+ },
1456
+ host,
1457
+ daemon: {
1458
+ pid: runningPid,
1459
+ uptimeMs: ping?.uptime ?? statusResponse?.uptime ?? null,
1460
+ ipc: { reachable: statusAvailable, latencyMs: Date.now() - started },
1461
+ runMode: statusResponse?.runMode ?? mainRecord?.runMode ?? null,
1462
+ build,
1463
+ queue: statusResponse?.queue ?? { pending: null, processing: null },
1464
+ },
1465
+ baseagents: statusResponse?.baseagents ?? { source: 'unavailable', items: [] },
1466
+ activity: {
1467
+ lastHour: statusActivityJson(effectiveLastHourActivity),
1468
+ today: statusActivityJson(todayActivity),
1469
+ },
1470
+ agents: {
1471
+ source: statusAvailable ? 'daemon+stats-db' : 'stats-db',
1472
+ items: agentItems,
1473
+ },
1474
+ aun: { source: aidsResponse ? 'daemon' : 'unavailable', items: aunItems },
1475
+ channels: { source: statusAvailable ? 'daemon' : 'unavailable', items: channels },
1476
+ controlAid: statusResponse?.controlAid ?? null,
1477
+ triggers: triggerSummary,
1478
+ ecweb,
1479
+ diagnostics,
1480
+ };
1481
+ console.log(JSON.stringify(output, null, 2));
1482
+ }
1483
+ export async function cmdStatus(options = {}) {
1484
+ if (options.format === 'json') {
1485
+ await cmdStatusJson();
1486
+ return;
1487
+ }
1295
1488
  const p = resolvePaths();
1296
1489
  const status = scanInstances();
1297
1490
  const aliveMains = status.mains.filter(m => m.alive);
@@ -1300,13 +1493,19 @@ export async function cmdStatus() {
1300
1493
  // query can otherwise wait behind the same IPC/event-loop delay and make the
1301
1494
  // total `ec status` time the sum of several individual timeouts.
1302
1495
  let ipcFailure;
1496
+ let agentsQueryFailure;
1303
1497
  const pingPromise = probeDaemon(p.socket, DAEMON_PROBE_TIMEOUT_MS, true).catch(error => {
1304
1498
  ipcFailure = error;
1305
1499
  return null;
1306
1500
  });
1307
1501
  const statusPromise = ipcQuery(p.socket, { type: 'status' }).catch(() => null);
1308
1502
  const aidsPromise = ipcQuery(p.socket, { type: 'aun-aids' }).catch(() => null);
1309
- const agentsPromise = ipcQuery(p.socket, { type: 'evolagent.list' }).catch(() => null);
1503
+ const agentsPromise = process.env.EVOLCORE_SESSION_ID
1504
+ ? Promise.resolve({ ok: false, error: 'per-agent listing requires a local control token' })
1505
+ : ipcQuery(p.socket, { type: 'evolagent.list' }, 5_000).catch(error => {
1506
+ agentsQueryFailure = error;
1507
+ return null;
1508
+ });
1310
1509
  // Only the ping is needed to decide whether to show the live-daemon
1311
1510
  // sections. The remaining responses continue in parallel while local
1312
1511
  // process/session information is rendered.
@@ -1373,26 +1572,35 @@ export async function cmdStatus() {
1373
1572
  // 实例副本在唯一的当前实例已存在时属于迁移来源,不应误报。
1374
1573
  let orphanCount = 0;
1375
1574
  try {
1376
- const { agents } = loadAllAgents();
1575
+ // When the daemon is reachable, use its loaded Agent view instead of
1576
+ // reopening protected defaults.json and daemon.json from the CLI.
1577
+ const [agentResponse, liveStatus] = await Promise.all([agentsPromise, statusPromise]);
1578
+ if (!agentResponse?.ok || !Array.isArray(agentResponse.agents))
1579
+ throw new Error('Agent list unavailable');
1377
1580
  const configChannelNames = new Set();
1378
1581
  const configuredByAgentType = new Map();
1379
- for (const cfg of agents) {
1582
+ for (const cfg of agentResponse.agents) {
1583
+ if (typeof cfg.aid !== 'string' || !cfg.aid)
1584
+ continue;
1380
1585
  // AUN 是从 agent 自身 AID 隐式派生的内建通道,不出现在 cfg.channels 里。
1381
1586
  // 不补这条,所有 aun#<aid>#main 会话都会被误判成 orphan。
1382
1587
  configChannelNames.add(`aun#${cfg.aid}#main`);
1383
- for (const inst of cfg.channels) {
1384
- // effective key: <type>#<selfAID>#<name>
1385
- const channelKey = `${inst.type}#${cfg.aid}#${inst.name}`;
1588
+ for (const channelKey of Array.isArray(cfg.channels) ? cfg.channels : []) {
1589
+ if (typeof channelKey !== 'string')
1590
+ continue;
1386
1591
  configChannelNames.add(channelKey);
1387
- const identity = `${inst.type}\0${cfg.aid}`;
1592
+ const [type, aid] = channelKey.split('#');
1593
+ if (!type || !aid)
1594
+ continue;
1595
+ const identity = `${type}\0${aid}`;
1388
1596
  configuredByAgentType.set(identity, [...(configuredByAgentType.get(identity) ?? []), channelKey]);
1389
1597
  }
1390
1598
  }
1391
1599
  // The daemon control identity owns AUN transcripts but deliberately
1392
1600
  // has no Agent config, so include it explicitly in route validity.
1393
- const daemonConfig = readJsonFile(p.daemonConfig);
1394
- if (daemonConfig?.aid)
1395
- configChannelNames.add(`aun#${daemonConfig.aid}#main`);
1601
+ const controlAid = liveStatus?.controlAid?.aid;
1602
+ if (typeof controlAid === 'string' && controlAid)
1603
+ configChannelNames.add(`aun#${controlAid}#main`);
1396
1604
  for (const chat of chatDirs) {
1397
1605
  const channelKey = chat.channelKey;
1398
1606
  if (!channelKey || configChannelNames.has(channelKey) || isNonAgentSessionChannel(channelKey))
@@ -1484,6 +1692,7 @@ export async function cmdStatus() {
1484
1692
  // Channel status. A running daemon is authoritative and avoids reading
1485
1693
  // protected config files from the CLI's potentially sandboxed process.
1486
1694
  let agentsResponse = null;
1695
+ let liveAgentRuntime = null;
1487
1696
  if (pid) {
1488
1697
  console.log('');
1489
1698
  const [statusResponse, aidsResponse, agentResponse] = await Promise.all([
@@ -1492,6 +1701,7 @@ export async function cmdStatus() {
1492
1701
  agentsPromise,
1493
1702
  ]);
1494
1703
  agentsResponse = agentResponse;
1704
+ liveAgentRuntime = statusResponse?.agentRuntime ?? null;
1495
1705
  if (statusResponse) {
1496
1706
  if (statusResponse.build) {
1497
1707
  if (statusResponse.build.runtimeMode === 'source') {
@@ -1511,6 +1721,16 @@ export async function cmdStatus() {
1511
1721
  console.log(` Build ID: runtime=unavailable (daemon 未提供 build identity) dist=${computeBuildId(path.join(getPackageRoot(), 'dist')) ?? '?'}`);
1512
1722
  console.log(' ⚠ 当前 daemon 未提供 build ID;请重启到包含 build identity 的版本后再判断源码行为。');
1513
1723
  }
1724
+ if (!statusResponse) {
1725
+ const config = readStatusDefaultsConfig(p.defaultsConfig);
1726
+ if (config) {
1727
+ console.log('🔌 Channels (live status unavailable; configuration is stale):');
1728
+ showConfigChannels(config);
1729
+ }
1730
+ else {
1731
+ console.log('🔌 Channels: live status unavailable');
1732
+ }
1733
+ }
1514
1734
  // 🔑 AUN AIDs 表格(详细 AUN 实例状态)
1515
1735
  try {
1516
1736
  if (aidsResponse?.ok && aidsResponse.aids?.length > 0) {
@@ -1558,17 +1778,17 @@ export async function cmdStatus() {
1558
1778
  if (pid) {
1559
1779
  try {
1560
1780
  const agentResult = agentsResponse;
1561
- if (agentResult?.ok && agentResult.agents?.length > 0) {
1781
+ if (agentResult?.ok && Array.isArray(agentResult.agents)) {
1562
1782
  const agents = agentResult.agents;
1563
- if (agents.length > 0) {
1564
- console.log('');
1565
- console.log('🤖 EvolAgents:');
1566
- for (const a of agents) {
1567
- const statusIcon = a.status === 'running' ? '●' : a.status === 'error' ? '✗' : a.status === 'disabled' ? '○' : '◌';
1568
- const channels = summarizeChannelFingerprints(a.channels || []);
1569
- const shortName = a.name.replace(/\.agentid\.pub$/, '');
1570
- console.log(` ${statusIcon} ${shortName.padEnd(20)} ${a.status.padEnd(10)} ${channels}`);
1571
- }
1783
+ console.log('');
1784
+ console.log('🤖 EvolAgents (live status):');
1785
+ if (agents.length === 0)
1786
+ console.log(' (no agents loaded)');
1787
+ for (const a of agents) {
1788
+ const statusIcon = a.status === 'running' ? '●' : a.status === 'error' ? '✗' : a.status === 'disabled' ? '○' : '◌';
1789
+ const channels = summarizeChannelFingerprints(a.channels || []);
1790
+ const shortName = a.name.replace(/\.agentid\.pub$/, '');
1791
+ console.log(` ${statusIcon} ${shortName.padEnd(20)} ${a.status.padEnd(10)} ${channels}`);
1572
1792
  }
1573
1793
  }
1574
1794
  else {
@@ -1578,7 +1798,18 @@ export async function cmdStatus() {
1578
1798
  const agents = diskRegistry.list();
1579
1799
  if (agents.length > 0) {
1580
1800
  console.log('');
1581
- console.log('🤖 EvolAgents (live status unavailable; stale configuration):');
1801
+ const detail = typeof agentResult?.error === 'string'
1802
+ ? agentResult.error
1803
+ : agentsQueryFailure instanceof Error ? agentsQueryFailure.message : 'IPC request failed';
1804
+ const running = Number.isFinite(liveAgentRuntime?.runningAgents) ? liveAgentRuntime.runningAgents : null;
1805
+ const runnable = Number.isFinite(liveAgentRuntime?.runnableAgents) ? liveAgentRuntime.runnableAgents : null;
1806
+ if (running !== null && runnable !== null) {
1807
+ console.log(`🤖 EvolAgents (live aggregate: ${running} running / ${runnable} runnable):`);
1808
+ console.log(` Per-agent details unavailable (${detail}); following entries are stale configuration only:`);
1809
+ }
1810
+ else {
1811
+ console.log(`🤖 EvolAgents (live status unavailable: ${detail}; stale configuration):`);
1812
+ }
1582
1813
  for (const a of agents) {
1583
1814
  const diskStatus = a.status === 'disabled' || a.status === 'error' ? a.status : 'unknown';
1584
1815
  const channels = summarizeChannelFingerprints(a.channels || []);
@@ -2965,7 +3196,7 @@ async function printEcwebStatus(p) {
2965
3196
  console.log('');
2966
3197
  if (aliveEntries.length > 0) {
2967
3198
  const visibleEntry = aliveEntries[0];
2968
- console.log(`🔭 ECWeb: 进程存活 (PID: ${visibleEntry.record.pid}) 但 HTTP 未就绪 (端口 ${visibleEntry.record.port}),查看 logs/watch-web.log`);
3199
+ console.log(`🔭 ECWeb: 进程存活 (PID: ${visibleEntry.record.pid}) 但 HTTP 未就绪 (端口 ${visibleEntry.record.port}),查看 logs/ecweb-daemon.log`);
2969
3200
  }
2970
3201
  else if (occupiedPids.size > 0) {
2971
3202
  console.log(`🔭 ECWeb: 端口仍被未登记进程占用 (PID: ${[...occupiedPids].join(', ')}),请先执行 ec restart`);
@@ -2973,6 +3204,9 @@ async function printEcwebStatus(p) {
2973
3204
  else if (entries.length > 0) {
2974
3205
  console.log('🔭 ECWeb: instance 记录存在,但宿主 PID 不可见且 HTTP 未就绪');
2975
3206
  }
3207
+ else if (externalUrl) {
3208
+ console.log('🔭 ECWeb: 已启用但未运行,查看 logs/ecweb-daemon.log');
3209
+ }
2976
3210
  else {
2977
3211
  console.log('🔭 ECWeb: 未运行');
2978
3212
  }
package/dist/cli/index.js CHANGED
@@ -82,7 +82,7 @@ function printLifecycleHelp(command) {
82
82
  start: `用法: ec start [--foreground] [--diagnose|-d] [--debug] [--as-mode dev|install]\n\n --foreground 前台运行,适合 systemd 或容器直接管理\n --diagnose, -d 以诊断模式启动 daemon\n --debug 调试模式:注册调试 IPC,可在宿主终端以任意 session 身份发命令\n --as-mode 覆盖运行模式判定(仅本次启动生效,不写配置):\n install = 按安装模式(校验随包文件完整性,篡改自动恢复)\n dev = 按开发模式(不校验随包文件)`,
83
83
  stop: '用法: ec stop\n\n停止当前 EVOLCORE_HOME 下运行的 EvolCore 服务。',
84
84
  restart: `用法: ec restart [--clear] [--diagnose|-d]\n\n --clear 同时清理跨 HOME 残留的 EvolCore 主进程\n --diagnose, -d 以诊断模式启动新 daemon`,
85
- status: '用法: ec status\n\n查看 daemon、agent、渠道与会话运行状态。',
85
+ status: '用法: ec status [--format json]\n\n查看 daemon、Agent、渠道与队列运行状态。JSON 模式输出结构化状态快照。',
86
86
  logs: `用法: ec logs [选项]\n\n --level <error|warn|info|debug> 最低日志级别\n --module <name> 只显示指定模块\n --raw 原始输出\n --no-color 禁用颜色`,
87
87
  watch: `用法: ec watch [logs|log|aid|msg|diag|web|session]\n\n ec watch 打开监控选择菜单\n ec watch logs 选择日志类型后监控\n ec watch log <类型...> 直接监控指定日志类型\n ec watch aid 监控 AID 连接\n ec watch msg 打开消息 TUI\n ec watch diag 实时诊断消息生命周期(AUN→daemon→任务)\n ec watch web 安装/升级并启动 EC Web\n ec watch session ec watch web 的兼容别名`,
88
88
  'restart-monitor': '用法: ec restart-monitor\n\n运行内 daemon 重启与升级监控器。',
@@ -266,21 +266,33 @@ export async function main(args) {
266
266
  printLifecycleHelp('status');
267
267
  break;
268
268
  }
269
- if (process.env.EVOLCORE_SESSION_ID) {
270
- const sessionId = process.env.EVOLCORE_SESSION_ID;
271
- const delegationToken = readDelegationCredential();
272
- const result = await ipcQuery(resolvePaths().socket, {
273
- type: 'status.auth', sessionId, delegationToken,
274
- });
275
- if (!result?.ok) {
276
- console.error(`❌ ${result?.error || 'status is not allowed in this task'}`);
269
+ {
270
+ const statusArgs = strippedArgs.slice(1);
271
+ const formatValue = getArgValue(statusArgs, '--format');
272
+ const validStatusArgs = statusArgs.length === 0
273
+ || (statusArgs.length === 2 && statusArgs[0] === '--format' && formatValue === 'json');
274
+ if (!validStatusArgs) {
275
+ console.error('用法: ec status [--format json]');
277
276
  process.exitCode = 1;
278
277
  break;
279
278
  }
280
- await cmdStatus();
281
- }
282
- else {
283
- await cmdStatus();
279
+ const format = formatValue;
280
+ if (process.env.EVOLCORE_SESSION_ID) {
281
+ const sessionId = process.env.EVOLCORE_SESSION_ID;
282
+ const delegationToken = readDelegationCredential();
283
+ const result = await ipcQuery(resolvePaths().socket, {
284
+ type: 'status.auth', sessionId, delegationToken, argv: ['status', ...statusArgs],
285
+ });
286
+ if (!result?.ok) {
287
+ console.error(`❌ ${result?.error || 'status is not allowed in this task'}`);
288
+ process.exitCode = 1;
289
+ break;
290
+ }
291
+ await cmdStatus({ format });
292
+ }
293
+ else {
294
+ await cmdStatus({ format });
295
+ }
284
296
  }
285
297
  break;
286
298
  case 'logs':
@@ -43,11 +43,12 @@ ec memory note drop <slug>
43
43
  ec memory note list
44
44
 
45
45
  ec memory create --scope <relation|agent|owner> --slug <slug> --desc '<description>' \\
46
- --tags '<tag1>,<tag2>' [--keywords '<kw1>,<kw2>'] [--replaces '<path1>,<path2>'] '<content>'
46
+ --tags '<tag1>,<tag2>' [--keywords '<kw1>,<kw2>'] [--replaces '<path1>,<path2>'] \\
47
+ [--peer <peerKey>] [--reason '<why>'] [--generalized-from <path>] [--promoted-from <path>] '<content>'
47
48
 
48
- ec memory update <path> [--tags '<tag1>,<tag2>'] [--touch]
49
+ ec memory update <path> [--tags '<tag1>,<tag2>'] [--touch] [--reason '<why>']
49
50
 
50
- ec memory archive <path...>
51
+ ec memory archive <path...> [--reason '<why>']
51
52
 
52
53
  ec memory consolidate [--mode <notes|generalize|promote|profile|forget>]
53
54
 
@@ -168,8 +169,9 @@ export function resolveMemoryCommandArgv(argv) {
168
169
  const kind = noteSub ? `note.${noteSub}` : argv[1];
169
170
  const known = {
170
171
  note: ['--slug', '--tags', '--speakers'], 'note.update': ['--slug', '--tags'],
171
- 'note.drop': [], 'note.list': [], create: ['--scope', '--slug', '--desc', '--tags', '--keywords', '--replaces', '--peer'],
172
- update: ['--tags', '--touch'], archive: [], demote: ['--scope'], consolidate: ['--mode'],
172
+ 'note.drop': [], 'note.list': [],
173
+ create: ['--scope', '--slug', '--desc', '--tags', '--keywords', '--replaces', '--peer', '--reason', '--generalized-from', '--promoted-from'],
174
+ update: ['--tags', '--touch', '--reason'], archive: ['--reason'], demote: ['--scope'], consolidate: ['--mode'],
173
175
  };
174
176
  // feedback 已移除:旧会话/旧文档可能还在调用,给一句能照做的说明而不是泛化的非法命令。
175
177
  if (kind === 'feedback') {
@@ -209,17 +211,19 @@ export function resolveMemoryCommandArgv(argv) {
209
211
  throw new Error('--peer requires relation scope');
210
212
  return { type, scope, slug: required(flags.get('--slug'), '--slug'), description: required(flags.get('--desc'), '--desc'),
211
213
  content: required(content, 'content'), tags: parseTags(flags.get('--tags')), keywords: parseTags(flags.get('--keywords')),
212
- replaces: parseTags(flags.get('--replaces')), targetPeerKey: flags.get('--peer') };
214
+ replaces: parseTags(flags.get('--replaces')), targetPeerKey: flags.get('--peer'),
215
+ reason: flags.get('--reason'), generalizedFrom: flags.get('--generalized-from'), promotedFrom: flags.get('--promoted-from') };
213
216
  }
214
217
  if (kind === 'update') {
215
218
  if (!flags.has('--tags') && !flags.has('--touch'))
216
219
  throw new Error('No memory changes supplied');
217
- return { type, filePath: required(positional[0], 'path'), tags: parseTags(flags.get('--tags')), touch: flags.has('--touch') };
220
+ return { type, filePath: required(positional[0], 'path'), tags: parseTags(flags.get('--tags')), touch: flags.has('--touch'),
221
+ reason: flags.get('--reason') };
218
222
  }
219
223
  if (kind === 'archive') {
220
224
  if (!positional.length)
221
225
  throw new Error('Memory paths are required');
222
- return { type, filePaths: positional };
226
+ return { type, filePaths: positional, reason: flags.get('--reason') };
223
227
  }
224
228
  if (kind === 'demote') {
225
229
  const scope = flags.get('--scope') ?? 'agent';
@@ -240,9 +244,9 @@ const USAGE = {
240
244
  note: "ec memory note --slug <slug> [--tags '<tag1>,<tag2>'] [--speakers '<aid1>,<aid2>'] '<正文>'",
241
245
  noteUpdate: "ec memory note update <slug> [--slug <新slug>] [--tags '<tag1>,<tag2>'] ['<新正文>']",
242
246
  noteDrop: 'ec memory note drop <slug>',
243
- create: "ec memory create --scope <relation|agent|owner> --slug <slug> --desc '<描述>' --tags '<tag1>,<tag2>' [--keywords '<kw1>,<kw2>'] [--replaces '<路径1>,<路径2>'] [--peer <peerKey>] '<正文>'",
244
- update: "ec memory update <路径> [--tags '<tag1>,<tag2>'] [--touch](至少给一项)",
245
- archive: 'ec memory archive <路径...>',
247
+ create: "ec memory create --scope <relation|agent|owner> --slug <slug> --desc '<描述>' --tags '<tag1>,<tag2>' [--keywords '<kw1>,<kw2>'] [--replaces '<路径1>,<路径2>'] [--peer <peerKey>] [--reason '<为什么>'] [--generalized-from <路径>] [--promoted-from <路径>] '<正文>'",
248
+ update: "ec memory update <路径> [--tags '<tag1>,<tag2>'] [--touch] [--reason '<为什么>'](至少给一项)",
249
+ archive: "ec memory archive <路径...> [--reason '<为什么>']",
246
250
  };
247
251
  /**
248
252
  * 统一失败出口。JSON 模式与 `ec fs` / `ec response` 一致:stdout 输出 `{ ok: false, code, error }`;
@@ -406,6 +410,7 @@ async function cmdMemoryNoteList(args, json) {
406
410
  async function cmdMemoryCreate(args, json) {
407
411
  const { flags, positional } = parseCliArgs(args, [
408
412
  '--scope', '--slug', '--desc', '--tags', '--keywords', '--replaces', '--peer',
413
+ '--reason', '--generalized-from', '--promoted-from',
409
414
  ], json);
410
415
  const content = positional.join(' ').trim();
411
416
  const scope = flags.get('--scope');
@@ -415,6 +420,9 @@ async function cmdMemoryCreate(args, json) {
415
420
  const keywordsRaw = flags.get('--keywords');
416
421
  const replacesRaw = flags.get('--replaces');
417
422
  const targetPeerKey = flags.get('--peer');
423
+ const reason = flags.get('--reason');
424
+ const generalizedFrom = flags.get('--generalized-from');
425
+ const promotedFrom = flags.get('--promoted-from');
418
426
  if (!scope || !['agent', 'relation', 'owner'].includes(scope)) {
419
427
  failWithUsage(json, '--scope 必须是 agent / relation / owner 之一', USAGE.create);
420
428
  }
@@ -429,6 +437,12 @@ async function cmdMemoryCreate(args, json) {
429
437
  if (targetPeerKey !== undefined && scope !== 'relation') {
430
438
  failWithUsage(json, '--peer 只在 --scope relation 时有效', USAGE.create);
431
439
  }
440
+ if (generalizedFrom !== undefined && scope !== 'agent') {
441
+ failWithUsage(json, '--generalized-from 只在 --scope agent 时有效', USAGE.create);
442
+ }
443
+ if (promotedFrom !== undefined && scope !== 'owner') {
444
+ failWithUsage(json, '--promoted-from 只在 --scope owner 时有效', USAGE.create);
445
+ }
432
446
  const { socketPath, ...session } = requireManagedSession('ec memory create', flags, json);
433
447
  const result = await queryDaemon(socketPath, {
434
448
  type: 'memory.create', argv: ['memory', 'create', ...args], ...session, scope, slug, description: desc,
@@ -437,6 +451,9 @@ async function cmdMemoryCreate(args, json) {
437
451
  keywords: parseTags(keywordsRaw),
438
452
  replaces: replacesRaw ? replacesRaw.split(',').map(s => s.trim()).filter(Boolean) : undefined,
439
453
  targetPeerKey: targetPeerKey ?? undefined,
454
+ reason: reason ?? undefined,
455
+ generalizedFrom: generalizedFrom ?? undefined,
456
+ promotedFrom: promotedFrom ?? undefined,
440
457
  }, 15_000);
441
458
  reportResult(result, json, (r) => {
442
459
  if (r.filePath)
@@ -447,10 +464,11 @@ async function cmdMemoryCreate(args, json) {
447
464
  });
448
465
  }
449
466
  async function cmdMemoryConsolidatedUpdate(args, json) {
450
- const { flags, positional } = parseCliArgs(args, ['--tags', '--touch'], json);
467
+ const { flags, positional } = parseCliArgs(args, ['--tags', '--touch', '--reason'], json);
451
468
  const filePath = positional[0];
452
469
  const tagsRaw = flags.get('--tags');
453
470
  const touch = flags.has('--touch');
471
+ const reason = flags.get('--reason');
454
472
  if (!filePath)
455
473
  failWithUsage(json, '必须提供要修改的记忆文件路径', USAGE.update);
456
474
  if (tagsRaw === undefined && !touch)
@@ -458,19 +476,20 @@ async function cmdMemoryConsolidatedUpdate(args, json) {
458
476
  const { socketPath, ...session } = requireManagedSession('ec memory update', flags, json);
459
477
  const result = await queryDaemon(socketPath, {
460
478
  type: 'memory.update', argv: ['memory', 'update', ...args], ...session, filePath,
461
- tags: parseTags(tagsRaw), touch,
479
+ tags: parseTags(tagsRaw), touch, reason: reason ?? undefined,
462
480
  }, 15_000);
463
481
  reportResult(result, json, () => {
464
482
  console.log(`✓ 已更新: ${filePath}`);
465
483
  });
466
484
  }
467
485
  async function cmdMemoryArchive(args, json) {
468
- const { flags, positional } = parseCliArgs(args, [], json);
486
+ const { flags, positional } = parseCliArgs(args, ['--reason'], json);
469
487
  if (positional.length === 0)
470
488
  failWithUsage(json, '必须提供至少一个要归档的文件路径', USAGE.archive);
471
489
  const { socketPath, ...session } = requireManagedSession('ec memory archive', flags, json);
472
490
  const result = await queryDaemon(socketPath, {
473
491
  type: 'memory.archive', argv: ['memory', 'archive', ...args], ...session, filePaths: positional,
492
+ reason: flags.get('--reason') ?? undefined,
474
493
  }, 15_000);
475
494
  reportResult(result, json, (r) => {
476
495
  const archived = r.archived ?? positional;