evolcore 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/CHANGELOG.md +44 -793
  2. package/dist/agents/claude-runner.js +197 -17
  3. package/dist/agents/codex-runner.js +46 -3
  4. package/dist/aun/outbox.js +8 -0
  5. package/dist/channels/aun.js +21 -4
  6. package/dist/channels/contact-bind-code.js +134 -0
  7. package/dist/channels/dingtalk.js +979 -149
  8. package/dist/channels/feishu.js +130 -54
  9. package/dist/channels/wecom-card.js +101 -0
  10. package/dist/channels/wecom-onboarding.js +82 -0
  11. package/dist/channels/wecom-state.js +191 -0
  12. package/dist/channels/wecom.js +755 -163
  13. package/dist/cli/agent-command.js +2 -1
  14. package/dist/cli/aun-commands.js +88 -33
  15. package/dist/cli/bench.js +2 -2
  16. package/dist/cli/contact.js +71 -0
  17. package/dist/cli/ctl-command.js +2 -2
  18. package/dist/cli/daemon-commands.js +77 -214
  19. package/dist/cli/handoff-command.js +2 -2
  20. package/dist/cli/help.js +9 -5
  21. package/dist/cli/index.js +132 -116
  22. package/dist/cli/init-channel.js +92 -97
  23. package/dist/cli/init.js +63 -26
  24. package/dist/cli/model.js +2 -1
  25. package/dist/cli/net-check.js +2 -2
  26. package/dist/cli/queue-command.js +30 -6
  27. package/dist/cli/raw-key-input.js +25 -0
  28. package/dist/cli/response.js +5 -6
  29. package/dist/cli/restart-monitor.js +25 -1
  30. package/dist/cli/stats.js +6 -4
  31. package/dist/cli/trigger-command.js +55 -15
  32. package/dist/cli/version.js +6 -1
  33. package/dist/config/builtin-role-templates.js +22 -10
  34. package/dist/config/builtin-roles.js +7 -1
  35. package/dist/config/config-manager.js +221 -17
  36. package/dist/config/contact-alias.js +68 -0
  37. package/dist/config/contact-book-store.js +454 -0
  38. package/dist/config/contact-book-v2-startup.js +35 -0
  39. package/dist/config/contact-book.js +156 -303
  40. package/dist/config/contact-operation-service.js +110 -0
  41. package/dist/config/peer-role-resolver.js +133 -54
  42. package/dist/config/role-ranks.js +18 -0
  43. package/dist/config/role-service.js +16 -19
  44. package/dist/config/role-store.js +16 -5
  45. package/dist/config/roles.js +10 -1
  46. package/dist/config-store.js +0 -2
  47. package/dist/core/auth/authorization-audit.js +10 -1
  48. package/dist/core/auth/operation-authorizer.js +2 -0
  49. package/dist/core/auth/operation-catalog.js +56 -0
  50. package/dist/core/command/command-handler.js +105 -10
  51. package/dist/core/command/connect-menu.js +374 -0
  52. package/dist/core/command/menu-handler.js +114 -16
  53. package/dist/core/command/role-menu.js +128 -29
  54. package/dist/core/command/slash-handler.js +28 -18
  55. package/dist/core/daemon-file-cache.js +12 -6
  56. package/dist/core/event-catalog.js +70 -0
  57. package/dist/core/evolagent-registry.js +0 -1
  58. package/dist/core/evolagent.js +20 -9
  59. package/dist/core/message/im-renderer.js +2 -0
  60. package/dist/core/message/message-bridge.js +79 -8
  61. package/dist/core/message/message-queue.js +10 -0
  62. package/dist/core/message/message-utils.js +8 -2
  63. package/dist/core/message/response-engine.js +269 -25
  64. package/dist/core/message/send-receipt.js +24 -0
  65. package/dist/core/message/stream-debouncer.js +11 -2
  66. package/dist/core/permission/tool-policy.js +47 -15
  67. package/dist/core/protected-paths.js +2 -0
  68. package/dist/core/session/session-fs-store.js +44 -3
  69. package/dist/core/session/session-manager.js +61 -5
  70. package/dist/index.js +62 -6
  71. package/dist/ipc.js +34 -5
  72. package/dist/stats/billing.js +20 -8
  73. package/dist/trigger/manager.js +3 -0
  74. package/dist/trigger/parser.js +77 -2
  75. package/dist/trigger/patch.js +8 -1
  76. package/dist/trigger/scheduler.js +3 -1
  77. package/dist/trigger/validation.js +13 -0
  78. package/dist/utils/aid-bind.js +43 -29
  79. package/dist/utils/instance-registry.js +14 -7
  80. package/dist/utils/log-writer.js +46 -0
  81. package/dist/utils/media-cache.js +4 -1
  82. package/dist/utils/model-prices.jsonl +6 -3
  83. package/dist/utils/restart-safety.js +31 -0
  84. package/dist/utils/system-memory.js +62 -0
  85. package/kits/docs/INDEX.md +2 -1
  86. package/kits/docs/evolcore/INDEX.md +5 -3
  87. package/kits/docs/evolcore/agent.md +9 -1
  88. package/kits/docs/evolcore/aid.md +5 -2
  89. package/kits/docs/evolcore/contact.md +57 -0
  90. package/kits/docs/evolcore/fs.md +9 -0
  91. package/kits/docs/evolcore/group.md +12 -3
  92. package/kits/docs/evolcore/model.md +4 -1
  93. package/kits/docs/evolcore/msg.md +9 -3
  94. package/kits/docs/evolcore/response.md +16 -21
  95. package/kits/docs/evolcore/rpc.md +2 -0
  96. package/kits/docs/evolcore/stats.md +15 -2
  97. package/kits/docs/evolcore/storage.md +1 -0
  98. package/kits/docs/evolcore/trigger.md +17 -2
  99. package/kits/eck_manifest.json +12 -0
  100. package/kits/migrations/migrate-contact-book-v2.mjs +747 -0
  101. package/kits/schemas/_meta.json +7 -4
  102. package/kits/schemas/agent-config.schema.6.json +322 -0
  103. package/kits/schemas/contact-book.schema.2.json +43 -0
  104. package/kits/schemas/relation-config.schema.5.json +47 -0
  105. package/kits/schemas/role-config.schema.1.json +1 -0
  106. package/kits/schemas/role-registry.schema.1.json +2 -2
  107. package/kits/templates/roles/admin.json +1 -0
  108. package/kits/templates/roles/member.json +1 -0
  109. package/kits/templates/roles/owner.json +1 -0
  110. package/kits/templates/roles/visitor.json +1 -0
  111. package/kits/templates/system-fragments/commands.md +3 -1
  112. package/package.json +4 -4
  113. package/assets/brand/evolcore/README.md +0 -19
  114. package/assets/brand/evolcore/evolcore-app-icon.png +0 -0
  115. package/assets/brand/evolcore/evolcore-app-icon.svg +0 -13
  116. package/assets/brand/evolcore/evolcore-brand-board.png +0 -0
  117. package/assets/brand/evolcore/evolcore-brand-board.svg +0 -126
  118. package/assets/brand/evolcore/evolcore-logo-kit.zip +0 -0
  119. package/assets/brand/evolcore/evolcore-logo-reverse.png +0 -0
  120. package/assets/brand/evolcore/evolcore-logo-reverse.svg +0 -14
  121. package/assets/brand/evolcore/evolcore-logo.png +0 -0
  122. package/assets/brand/evolcore/evolcore-logo.svg +0 -14
  123. package/assets/brand/evolcore/evolcore-mark.png +0 -0
  124. package/assets/brand/evolcore/evolcore-mark.svg +0 -10
@@ -729,7 +729,9 @@ export class TriggerRuntimeScheduler {
729
729
  return { branch: branchFromReply(reply), script: null, processing, reply };
730
730
  }
731
731
  try {
732
- const runtimeBaseagent = this.runtime.getBaseagent?.() || this.runtime.baseagent;
732
+ const runtimeBaseagent = definition.execution.baseagent
733
+ ?? this.runtime.getBaseagent?.()
734
+ ?? this.runtime.baseagent;
733
735
  const originPath = causation.trigger?.path ?? [];
734
736
  logger.info(`[Trigger] execution context triggerId=${definition.id}`
735
737
  + ` triggerRunId=${runId}`
@@ -360,6 +360,7 @@ function normalizeExecution(value, _opts) {
360
360
  prompt: type === 'script' ? optionalString(raw.prompt) : requiredString(raw.prompt, 'execution.prompt'),
361
361
  script: type === 'script' ? normalizeScript(raw.script) : undefined,
362
362
  thread: type === 'trigger_session' ? (thread ?? 'by_trigger') : thread,
363
+ baseagent: normalizeExecutionBaseagent(raw.baseagent),
363
364
  model: optionalString(raw.model),
364
365
  effort: normalizeEffort(raw.effort),
365
366
  permissionMode: normalizeTriggerPermissionMode(raw.permissionMode),
@@ -368,6 +369,14 @@ function normalizeExecution(value, _opts) {
368
369
  };
369
370
  return execution;
370
371
  }
372
+ function normalizeExecutionBaseagent(value) {
373
+ if (value === undefined)
374
+ return undefined;
375
+ if (typeof value !== 'string' || !value.trim()) {
376
+ throw new Error('execution.baseagent must be a non-empty string');
377
+ }
378
+ return value.trim();
379
+ }
371
380
  function normalizeExecutionThread(value) {
372
381
  const thread = optionalString(value);
373
382
  if (thread === undefined)
@@ -533,6 +542,8 @@ function validateTriggerSemantics(definition) {
533
542
  throw new Error('execution.prompt is not allowed when execution.type=script');
534
543
  if (execution.thread !== undefined)
535
544
  throw new Error('execution.thread is not allowed when execution.type=script');
545
+ if (execution.baseagent !== undefined)
546
+ throw new Error('execution.baseagent is only allowed when execution.type=trigger_session');
536
547
  }
537
548
  if (execution.type === 'trigger_session') {
538
549
  if (!execution.prompt)
@@ -547,6 +558,8 @@ function validateTriggerSemantics(definition) {
547
558
  throw new Error('execution.script is not allowed when execution.type=target_session');
548
559
  if (execution.thread !== undefined)
549
560
  throw new Error('execution.thread is not allowed when execution.type=target_session');
561
+ if (execution.baseagent !== undefined)
562
+ throw new Error('execution.baseagent is only allowed when execution.type=trigger_session');
550
563
  if (definition.feedback.strategy === 'silent')
551
564
  throw new Error('feedback.strategy=silent is not allowed when execution.type=target_session');
552
565
  }
@@ -133,56 +133,70 @@ export class BindService {
133
133
  return fail('TASK_NOT_FOUND', 'binding task not found');
134
134
  if (payload.bindType !== task.bindType)
135
135
  return fail('BIND_TYPE_MISMATCH', 'bindType mismatch');
136
- if (Date.now() > task.expiresAt) {
136
+ if (!fromAid)
137
+ return fail('INTERNAL_ERROR', 'missing AUN sender');
138
+ if (task.status === 'pending' && Date.now() > task.expiresAt) {
137
139
  task.status = 'expired';
138
140
  task.finishedAt ??= task.expiresAt;
139
141
  return fail('TASK_EXPIRED', 'binding task expired');
140
142
  }
141
- if (task.status === 'bound')
143
+ if (task.status === 'bound') {
144
+ // The owner write and task transition necessarily happen before the caller
145
+ // can send bind.response. If that send fails, the App retries the same
146
+ // authenticated request. Replay the original success only to the AID that
147
+ // completed the bind; other senders must not receive daemonInfo.
148
+ if (task.boundAid === fromAid && task.boundResponse)
149
+ return task.boundResponse;
142
150
  return fail('ALREADY_BOUND', 'binding task already completed');
151
+ }
143
152
  if (task.status !== 'pending')
144
153
  return fail('TASK_NOT_FOUND', 'binding task is not pending');
145
154
  if (!timingSafeTokenEqual(payload.token, task.tokenHash)) {
146
155
  return fail('INVALID_TOKEN', 'invalid token');
147
156
  }
148
- if (!fromAid)
149
- return fail('INTERNAL_ERROR', 'missing AUN sender');
150
157
  try {
158
+ // Build and retain the exact response before committing the bind so a
159
+ // post-commit transport failure can be recovered by an idempotent retry.
160
+ const response = this.buildSuccessResponse(task);
151
161
  this.applyOwnerBinding(task, fromAid);
152
162
  task.status = 'bound';
153
163
  task.boundAid = fromAid;
154
164
  task.boundName = payload.clientName;
165
+ task.boundResponse = response;
155
166
  task.finishedAt = Date.now();
156
- const details = task.bindType === 'agent' ? this.buildAgentBindDetails(task) : null;
157
- return {
158
- type: 'bind.response',
159
- bindType: task.bindType,
160
- success: true,
161
- daemonInfo: {
162
- daemonAid: task.receiverAid,
163
- ...(task.bindType === 'agent' ? { agentAid: task.targetAid } : {}),
164
- bindType: task.bindType,
165
- ...(task.bindType === 'daemon'
166
- ? {
167
- version: readEvolcoreVersion(),
168
- platform: getPlatform(),
169
- uptime: this.opts.getUptimeSeconds(),
170
- baseagents: this.opts.getAvailableBaseagents(),
171
- }
172
- : {
173
- active_baseagent: details.baseagent.active_baseagent,
174
- model: details.baseagent.model,
175
- effort: details.baseagent.effort,
176
- channels: details.channels,
177
- agentName: task.agentName,
178
- }),
179
- },
180
- };
167
+ return response;
181
168
  }
182
169
  catch (e) {
183
170
  return fail('INTERNAL_ERROR', e?.message || String(e));
184
171
  }
185
172
  }
173
+ buildSuccessResponse(task) {
174
+ const details = task.bindType === 'agent' ? this.buildAgentBindDetails(task) : null;
175
+ return {
176
+ type: 'bind.response',
177
+ bindType: task.bindType,
178
+ success: true,
179
+ daemonInfo: {
180
+ daemonAid: task.receiverAid,
181
+ ...(task.bindType === 'agent' ? { agentAid: task.targetAid } : {}),
182
+ bindType: task.bindType,
183
+ ...(task.bindType === 'daemon'
184
+ ? {
185
+ version: readEvolcoreVersion(),
186
+ platform: getPlatform(),
187
+ uptime: this.opts.getUptimeSeconds(),
188
+ baseagents: this.opts.getAvailableBaseagents(),
189
+ }
190
+ : {
191
+ active_baseagent: details.baseagent.active_baseagent,
192
+ model: details.baseagent.model,
193
+ effort: details.baseagent.effort,
194
+ channels: details.channels,
195
+ agentName: task.agentName,
196
+ }),
197
+ },
198
+ };
199
+ }
186
200
  buildAgentBindDetails(task) {
187
201
  const agent = loadAgent(task.targetAid);
188
202
  const config = resolveEffective({ self: task.targetAid }, { expand: true });
@@ -14,6 +14,7 @@ import { spawnSync } from 'child_process';
14
14
  import { resolvePaths } from '../paths.js';
15
15
  import { isProcessRunning, killProcess, isWindows, findProcesses } from './cross-platform.js';
16
16
  import { getProcessStartTime, startTimeMatches } from './process-introspect.js';
17
+ import { isConfirmedLeakedTestDaemon, runtimeHomeFromEnv } from './restart-safety.js';
17
18
  // ── Helpers ──
18
19
  function instanceDir() {
19
20
  return resolvePaths().instanceDir;
@@ -339,10 +340,11 @@ function killPid(pid) {
339
340
  * 用途:检测跨 HOME 残留的 evolcore 主进程(例如测试套件 spawn 后未清理、
340
341
  * 旧版本 pidfile 模式遗留等),由 cmdStart/cmdRestart 在启动前提示用户。
341
342
  *
342
- * Linux 下额外读取 /proc/<pid>/environ 提取 EVOLCORE_HOME 用于展示。
343
+ * Linux 下额外读取 /proc/<pid>/environ 提取 EVOLCORE_HOME
344
+ * 并对 Vitest 泄漏的 restart-monitor daemon 做严格标记。
343
345
  * Windows / macOS 取不到环境变量时 evolcoreHome 为 null。
344
346
  *
345
- * 不会主动 kill——清理由调用方决定(cmdRestart --kill-orphans 才执行)。
347
+ * 不会主动 kill——清理由调用方决定。
346
348
  */
347
349
  export function findOrphanProcesses() {
348
350
  // 1. 已登记 PID(自己 HOME 下的 main + 自己进程)
@@ -367,10 +369,12 @@ export function findOrphanProcesses() {
367
369
  // 三次验证:排除 ecweb(/ecweb/dist/index.js)
368
370
  if (/[\\/]ecweb[\\/]dist[\\/]index\.js/.test(cmdline))
369
371
  continue;
372
+ const processEnv = readProcessEnvironment(pid);
370
373
  orphans.push({
371
374
  pid,
372
- evolcoreHome: readEvolcoreHome(pid),
375
+ evolcoreHome: processEnv ? runtimeHomeFromEnv(processEnv) : null,
373
376
  cmdline,
377
+ confirmedTestDaemon: processEnv ? isConfirmedLeakedTestDaemon(processEnv) : false,
374
378
  });
375
379
  }
376
380
  return orphans;
@@ -418,16 +422,19 @@ function readCmdline(pid) {
418
422
  }
419
423
  }
420
424
  }
421
- function readEvolcoreHome(pid) {
425
+ function readProcessEnvironment(pid) {
422
426
  // Linux: /proc/<pid>/environ
423
427
  if (!isWindows && process.platform !== 'darwin') {
424
428
  try {
425
429
  const env = fs.readFileSync(`/proc/${pid}/environ`, 'utf-8');
430
+ const result = {};
426
431
  for (const entry of env.split('\0')) {
427
- if (entry.startsWith('EVOLCORE_HOME='))
428
- return entry.slice('EVOLCORE_HOME='.length);
432
+ const separator = entry.indexOf('=');
433
+ if (separator <= 0)
434
+ continue;
435
+ result[entry.slice(0, separator)] = entry.slice(separator + 1);
429
436
  }
430
- return null;
437
+ return result;
431
438
  }
432
439
  catch {
433
440
  return null;
@@ -24,6 +24,52 @@ import path from 'path';
24
24
  import { clearInterval as clearNativeInterval, clearTimeout as clearNativeTimeout, setInterval as setNativeInterval, setTimeout as setNativeTimeout, } from 'node:timers';
25
25
  const HOUR_MS = 60 * 60 * 1000;
26
26
  const DAY_MS = 24 * HOUR_MS;
27
+ /**
28
+ * Rotate the daemon's redirected stdout before a launcher opens it for append.
29
+ * stdout is owned by the launcher rather than LogWriter, so both start and
30
+ * restart paths must call this after the previous daemon has exited.
31
+ */
32
+ export function rotateStdoutLog(logDir, options = {}) {
33
+ const maxSize = options.maxSize ?? 10 * 1024 * 1024;
34
+ const retentionMs = options.retentionMs ?? 7 * DAY_MS;
35
+ const now = options.now ?? Date.now();
36
+ const stdoutLog = path.join(logDir, 'stdout.log');
37
+ let rotatedPath = null;
38
+ try {
39
+ if (fs.statSync(stdoutLog).size > maxSize) {
40
+ const timestamp = new Date(now).toISOString().replace(/[:.]/g, '').slice(0, 15);
41
+ const baseArchive = `${stdoutLog}.${timestamp}`;
42
+ let archive = baseArchive;
43
+ let suffix = 1;
44
+ while (fs.existsSync(archive))
45
+ archive = `${baseArchive}.${suffix++}`;
46
+ fs.renameSync(stdoutLog, archive);
47
+ rotatedPath = archive;
48
+ }
49
+ }
50
+ catch {
51
+ // Missing/unreadable stdout must not prevent the daemon from starting.
52
+ }
53
+ const removedArchives = [];
54
+ const cutoff = now - retentionMs;
55
+ try {
56
+ for (const name of fs.readdirSync(logDir)) {
57
+ if (!name.startsWith('stdout.log.'))
58
+ continue;
59
+ const full = path.join(logDir, name);
60
+ try {
61
+ const stat = fs.lstatSync(full);
62
+ if (stat.isSymbolicLink() || stat.mtimeMs < cutoff) {
63
+ fs.unlinkSync(full);
64
+ removedArchives.push(full);
65
+ }
66
+ }
67
+ catch { }
68
+ }
69
+ }
70
+ catch { }
71
+ return { rotatedPath, removedArchives };
72
+ }
27
73
  export class LogWriter {
28
74
  baseName;
29
75
  logDir;
@@ -183,7 +183,10 @@ export async function safeFetch(url, opts) {
183
183
  const controller = new AbortController();
184
184
  const timer = setTimeout(() => controller.abort(), timeout);
185
185
  try {
186
- const res = await fetch(url, { signal: controller.signal });
186
+ const res = await fetch(url, {
187
+ signal: controller.signal,
188
+ redirect: opts?.rejectRedirects ? 'error' : 'follow',
189
+ });
187
190
  if (!res.ok)
188
191
  throw new Error(`Download failed: ${res.status} ${res.statusText}`);
189
192
  // 检查 Content-Length(如果可用)
@@ -3,9 +3,12 @@
3
3
  {"model":"claude-opus-4-6","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":15,"price_output":75,"price_cache_creation":18.75,"price_cache_read":1.5}
4
4
  {"model":"claude-sonnet-4-6","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":3,"price_output":15,"price_cache_creation":3.75,"price_cache_read":0.3}
5
5
  {"model":"claude-haiku-4-5-20251001","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":0.8,"price_output":4,"price_cache_creation":1,"price_cache_read":0.08}
6
- {"model":"gpt-5.5","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":2,"price_output":10,"price_cache_creation":0,"price_cache_read":0}
7
- {"model":"gpt-5.4","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":2,"price_output":10,"price_cache_creation":0,"price_cache_read":0}
8
- {"model":"gpt-5.3-codex","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":2,"price_output":10,"price_cache_creation":0,"price_cache_read":0}
6
+ {"model":"gpt-5.6-sol","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":5,"price_output":30,"price_cache_creation":6.25,"price_cache_read":0.5,"tiers":[{"up_to_input_tokens":272000,"price_input":5,"price_output":30,"price_cache_creation":6.25,"price_cache_read":0.5},{"up_to_input_tokens":null,"price_input":10,"price_output":45,"price_cache_creation":12.5,"price_cache_read":1}]}
7
+ {"model":"gpt-5.6-terra","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":2.5,"price_output":15,"price_cache_creation":3.125,"price_cache_read":0.25,"tiers":[{"up_to_input_tokens":272000,"price_input":2.5,"price_output":15,"price_cache_creation":3.125,"price_cache_read":0.25},{"up_to_input_tokens":null,"price_input":5,"price_output":22.5,"price_cache_creation":6.25,"price_cache_read":0.5}]}
8
+ {"model":"gpt-5.6-luna","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":1,"price_output":6,"price_cache_creation":1.25,"price_cache_read":0.1,"tiers":[{"up_to_input_tokens":272000,"price_input":1,"price_output":6,"price_cache_creation":1.25,"price_cache_read":0.1},{"up_to_input_tokens":null,"price_input":2,"price_output":9,"price_cache_creation":2.5,"price_cache_read":0.2}]}
9
+ {"model":"gpt-5.5","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":5,"price_output":30,"price_cache_creation":0,"price_cache_read":0.5,"tiers":[{"up_to_input_tokens":272000,"price_input":5,"price_output":30,"price_cache_creation":0,"price_cache_read":0.5},{"up_to_input_tokens":null,"price_input":10,"price_output":45,"price_cache_creation":0,"price_cache_read":1}]}
10
+ {"model":"gpt-5.4","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":2.5,"price_output":15,"price_cache_creation":0,"price_cache_read":0.25,"tiers":[{"up_to_input_tokens":272000,"price_input":2.5,"price_output":15,"price_cache_creation":0,"price_cache_read":0.25},{"up_to_input_tokens":null,"price_input":5,"price_output":22.5,"price_cache_creation":0,"price_cache_read":0.5}]}
11
+ {"model":"gpt-5.3-codex","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":1.75,"price_output":14,"price_cache_creation":0,"price_cache_read":0.175}
9
12
  {"model":"deepseek-v4-pro","effective_from":0,"billing_fn":"per_token_deepseek_v1","currency":"CNY","price_cache_hit":0.5,"price_cache_miss":2,"price_output":8}
10
13
  {"model":"deepseek-v4-flash","effective_from":0,"billing_fn":"per_token_deepseek_v1","currency":"CNY","price_cache_hit":0.1,"price_cache_miss":0.5,"price_output":2}
11
14
  {"model":"deepseek-v3.2","effective_from":0,"billing_fn":"per_token_deepseek_v1","currency":"CNY","price_cache_hit":0.5,"price_cache_miss":2,"price_output":8}
@@ -0,0 +1,31 @@
1
+ const REAL_RESTART_TEST_OVERRIDE = 'EVOLCORE_ALLOW_REAL_RESTART_IN_TEST';
2
+ export function isRestartTestRuntime(env = process.env) {
3
+ return env.VITEST === 'true'
4
+ || env.EVOLCORE_TEST === '1';
5
+ }
6
+ /**
7
+ * Unit tests must never detach a real restart-monitor/daemon pair by accident.
8
+ * Dedicated process-level integration tests can opt in explicitly.
9
+ */
10
+ export function shouldSuppressRealRestart(env = process.env) {
11
+ return isRestartTestRuntime(env) && env[REAL_RESTART_TEST_OVERRIDE] !== '1';
12
+ }
13
+ export function runtimeHomeFromEnv(env) {
14
+ return env.EVOLCORE_HOME || null;
15
+ }
16
+ /**
17
+ * Strict classifier used before automatically killing leaked test daemons.
18
+ * All markers must agree so a legitimate secondary runtime is never mistaken
19
+ * for a disposable test process.
20
+ */
21
+ export function isConfirmedLeakedTestDaemon(env) {
22
+ const home = runtimeHomeFromEnv(env);
23
+ if (!home || !/[\\/]evolcore-test-[^\\/]+$/.test(home))
24
+ return false;
25
+ const launchedBy = env.EVOLCORE_LAUNCHED_BY;
26
+ const testRuntime = env.VITEST === 'true'
27
+ || env.EVOLCORE_TEST === '1';
28
+ return testRuntime
29
+ && env.NODE_ENV === 'test'
30
+ && launchedBy === 'restart-monitor';
31
+ }
@@ -0,0 +1,62 @@
1
+ import fs from 'fs';
2
+ import os from 'os';
3
+ function readNumber(filePath) {
4
+ try {
5
+ const value = Number(fs.readFileSync(filePath, 'utf8').trim());
6
+ return Number.isFinite(value) && value >= 0 ? value : null;
7
+ }
8
+ catch {
9
+ return null;
10
+ }
11
+ }
12
+ export function parseCgroupV2MemoryStat(input) {
13
+ const values = new Map();
14
+ for (const line of input.split('\n')) {
15
+ const [key, raw] = line.trim().split(/\s+/, 2);
16
+ const value = Number(raw);
17
+ if (key && Number.isFinite(value) && value >= 0)
18
+ values.set(key, value);
19
+ }
20
+ return values;
21
+ }
22
+ /**
23
+ * System memory for the current container/host namespace.
24
+ *
25
+ * Linux cgroup v2 uses memory.current - memory.stat:file so the value matches
26
+ * common host/container dashboards: anonymous + kernel memory, excluding
27
+ * reclaimable filesystem page cache. Other environments fall back to the
28
+ * portable total - available calculation exposed by Node.js.
29
+ */
30
+ export function readSystemMemoryUsage(cgroupRoot = '/sys/fs/cgroup') {
31
+ const memTotal = os.totalmem();
32
+ const memAvailable = os.freemem();
33
+ if (process.platform === 'linux') {
34
+ const current = readNumber(`${cgroupRoot}/memory.current`);
35
+ if (current !== null) {
36
+ try {
37
+ const stat = parseCgroupV2MemoryStat(fs.readFileSync(`${cgroupRoot}/memory.stat`, 'utf8'));
38
+ const fileCache = stat.get('file');
39
+ if (fileCache !== undefined) {
40
+ const memUsed = Math.max(0, current - fileCache);
41
+ return {
42
+ memTotal,
43
+ memUsed,
44
+ memFree: Math.max(0, memTotal - memUsed),
45
+ memAvailable,
46
+ memorySource: 'cgroup-v2-current-minus-file',
47
+ cgroupCurrent: current,
48
+ fileCache,
49
+ };
50
+ }
51
+ }
52
+ catch { /* fall through to portable OS metrics */ }
53
+ }
54
+ }
55
+ return {
56
+ memTotal,
57
+ memUsed: Math.max(0, memTotal - memAvailable),
58
+ memFree: memAvailable,
59
+ memAvailable,
60
+ memorySource: 'os-total-minus-available',
61
+ };
62
+ }
@@ -25,6 +25,7 @@
25
25
  | 文档 | 路径 | 说明 |
26
26
  |------|------|------|
27
27
  | 命令集目录 | `evolcore/INDEX.md` | msg/group/agent/aid/storage/ctl/rpc/bench 全集索引 |
28
+ | 联系人命令 | `evolcore/contact.md` | Contact Book 拉黑与托管会话权限边界 |
28
29
 
29
30
  ## 身份
30
31
 
@@ -46,7 +47,7 @@
46
47
 
47
48
  | 文档 | 路径 | 说明 |
48
49
  |------|------|------|
49
- | Trigger 命令手册 | `evolcore/trigger.md` | 创建、管理、运行定时与事件 trigger |
50
+ | Trigger 命令手册 | `evolcore/trigger.md` | 使用 `create` 创建并管理、运行定时与事件 trigger;`set` 为兼容别名 |
50
51
  | EventBus 事件目录 | `evolcore/event.md` | event source 可监听事件、payload、filter 与循环防护规则 |
51
52
 
52
53
  ## ECK 模板
@@ -4,8 +4,9 @@
4
4
  运行时 evolcore 会通过 `commands` fragment 按当前场景(有无 peer/group、对端角色)
5
5
  注入一张精简能力卡,指向本目录下对应文档;需要完整用法时 Read 对应文档。
6
6
 
7
- > 命令通用约定:以自己 AID 为发送者;必须走 CLI,不在会话里直接输出对外消息;
8
- > `--format json` 所有命令通用;`--app <name>` 指定应用 slot(独立消费通道)。
7
+ > 对外通信命令以自己的 AID 为发送者;当前渠道是否需要 CLI 回复,以运行时注入的
8
+ > `channel` 规则为准。参数不是全局通用的:`--format json` 仅用于对应帮助中明确支持的命令,
9
+ > `--app <name>` 仅用于消息 pull/ack、消费类 RPC 和明确支持 app slot 的文件操作。
9
10
 
10
11
  ## 如何使用本索引
11
12
 
@@ -34,6 +35,7 @@
34
35
  | `ec fs` | AUN 文件系统统一入口 | 上传/下载/看文件/列目录/删文件/配额/群空间 | 任意有渠道场景 | `fs.md` |
35
36
  | `ec storage` | 文件存储底层调试入口 | storage 调试/旧命令/底层上传下载 | 任意有渠道场景 | `storage.md` |
36
37
  | `ec agent` | EvolAgent 生命周期 | 创建/启停/热重载/改配置 | 管理员(owner/admin) | `agent.md` |
38
+ | `ec contact` | Contact Book 与访问控制 | 拉黑/解除拉黑/查拉黑 | Agent owner/admin | `contact.md` |
37
39
  | `ec rpc` | 底层 AUN RPC(逃生通道) | 直接调协议方法 | 高级/兜底 | `rpc.md` |
38
40
 
39
41
  ## 会话自管理类(不连 AUN,操作当前会话)
@@ -50,7 +52,7 @@
50
52
  | `ec response` | 响应模式管理(按作用域持久化) | 切换响应模式/列响应模式/看当前模式/改响应配置 | `response.md` |
51
53
  | `ec config` | 配置体系底层入口(读写/快照/回滚) | 看配置/改配置/查字段/查schema/校验/快照/回滚/历史/启动记录 | `config.md` |
52
54
  | `ec stats` | Token 用量与费用统计 | 用量/费用/统计/预算/token/cost | `stats.md` |
53
- | `ec trigger` | 定时与事件触发器管理 | 触发器/定时任务/cron/提醒/定时检查/自动执行/巡检/禁用 trigger/删除 trigger | `trigger.md` |
55
+ | `ec trigger` | 定时与事件触发器管理(创建用 `create`,`set` 为兼容别名) | 触发器/定时任务/cron/提醒/定时检查/自动执行/巡检/禁用 trigger/删除 trigger | `trigger.md` |
54
56
  | `ec trigger event` | EventBus 事件目录 | 事件触发/事件目录/EventBus/source.type=event/filter.match | `event.md` |
55
57
 
56
58
  ## 开发者工具(非 agent 会话能力)
@@ -10,6 +10,8 @@ ec agent list
10
10
 
11
11
  # 查看 agent 详情(身份 + 配置 + 连接 + 会话 + 路径)
12
12
  ec agent show <aid>
13
+ # 简写,等价于 show
14
+ ec agent <aid>
13
15
 
14
16
  # 创建 agent(交互式)
15
17
  ec agent new [aid]
@@ -27,6 +29,12 @@ ec agent disable <aid>
27
29
  ec agent get <aid> <key>
28
30
  ec agent set <aid> <key> <val>
29
31
 
32
+ # 修改 agent.md 显示名称
33
+ ec agent rename <aid> "<name>"
34
+
35
+ # 标记 bootstrap 完成,进入 active 状态
36
+ ec agent ready <aid>
37
+
30
38
  # 热重载配置(无参数 = 全量 resync:扫磁盘,新增上线/删除下线/修改热更新)
31
39
  ec agent reload [aid]
32
40
 
@@ -65,5 +73,5 @@ ec agent delete <aid> [--purge]
65
73
 
66
74
  ## 通用约定
67
75
 
68
- - `--format json` — 输出 JSON
76
+ - `--format json` — 用于 `list/show/new/enable/disable/get/set/rename/ready/reload/delete` 的结构化输出
69
77
  - `--help` / `-h` — 各子命令均支持,查看详细用法
@@ -12,7 +12,7 @@ ec aid list [筛选选项] [--no-verify]
12
12
  ec aid show <aid>
13
13
 
14
14
  # 创建新 AID 身份
15
- ec aid new <aid>
15
+ ec aid new <aid> [--force]
16
16
 
17
17
  # 远程探测 AID(是否存在 + 网关 + agent.md)
18
18
  ec aid lookup <aid>
@@ -42,8 +42,11 @@ ec aid delete <aid>
42
42
  - `ec aid delete --orphan` — 清理无私钥的外部 AID 缓存
43
43
  - `ec aid delete --no-cert` — 清理无私钥也无公钥证书的孤儿目录
44
44
  - `ec aid delete --unrecoverable` — 清理云端公钥已变更、本地不可恢复的 AID
45
+ - `--skip-pki` — 仅用于 `--unrecoverable`,跳过 PKI 探测并按本地自检结果判断;有误删风险
45
46
 
46
47
  ## 通用约定
47
48
 
48
- - `--format json` — 输出 JSON
49
+ - `--format json` — 对支持结构化结果的子命令输出 JSON
50
+ - `--aun-path <path>` — 指定 AUN keystore 根;未传时可由 `AUN_HOME` 提供
51
+ - `aid delete --orphan|--no-cert|--unrecoverable` 默认 dry-run,`--yes` 才执行删除
49
52
  - `--help` / `-h` — 各子命令均支持
@@ -0,0 +1,57 @@
1
+ # ec contact — Agent 联系人与访问控制
2
+
3
+ `ec contact` 管理指定 Agent 的 Contact Book v2。它只接受 AUN AID 主键,并只负责 AUN 私聊拉黑状态;角色统一由 relation `config.json role` 管理。
4
+
5
+ ## 命令
6
+
7
+ ```bash
8
+ ec contact block <aid> --self <agent-aid>
9
+ ec contact unblock <aid> --self <agent-aid>
10
+ ec contact list --blocked --self <agent-aid>
11
+ ```
12
+
13
+ 所有命令都要求显式 `--self`,支持 `--format json`。
14
+
15
+ ## 约束
16
+
17
+ - `<aid>` 和 `--self` 必须是合法 AID。
18
+ - `block/unblock` 只改变本 Agent 的入站接收策略,不代表对端也拉黑了本 Agent。
19
+ - Agent owner 不能被拉黑。
20
+ - `list --blocked` 只列出当前 blocked contact,并返回 `contactRevision`。
21
+
22
+ ## 权限边界
23
+
24
+ 直接从本机终端运行时,这是本地管理命令。
25
+
26
+ 从 Agent 活动任务执行时,CLI 不直接写文件,而是携带当前 session delegation token 调用 daemon `contact.op`:
27
+
28
+ | 操作 | owner | admin | 普通角色 |
29
+ |---|---:|---:|---:|
30
+ | `list --blocked` | 允许 | 允许 | 拒绝 |
31
+ | `block` / `unblock` | 允许 | 允许 | 拒绝 |
32
+
33
+ 缺少、伪造、撤销或跨会话 delegation token 时失败关闭。托管调用的 `--self` 必须等于当前任务所属 Agent。
34
+
35
+ 角色管理使用 Role Menu relation assignment;admin 的授予和撤销必须由 owner 执行。
36
+
37
+ ## JSON 输出
38
+
39
+ 拉黑成功:
40
+
41
+ ```json
42
+ {
43
+ "ok": true,
44
+ "operation": "set-blocked",
45
+ "selfAid": "bot.agentid.pub",
46
+ "primaryId": "peer.agentid.pub",
47
+ "blocked": true,
48
+ "changed": true,
49
+ "contactRevision": "..."
50
+ }
51
+ ```
52
+
53
+ ## 拉黑后的消息行为
54
+
55
+ - AUN 外部入站在 MessageBridge 的业务入口被拦截,不进入 menu/auth/command/session/queue/LLM。
56
+ - 对 `ai`、`bot`、`agent`、`service` 类型的私聊对端,可限频返回 `[rejection] Not accepting messages from you.`。
57
+ - 入站正文中的 `[rejection]` 没有协议控制语义。发送者未被本 Agent 拉黑时,该文本正常进入响应式会话。
@@ -41,12 +41,15 @@ ec fs umount <AID>:<path> # 卸载挂载点
41
41
 
42
42
  - `--format json`:结构化输出
43
43
  - `--as <aid>`:显式指定操作者
44
+ - `--aun-path <path>`:指定 AUN keystore 根
45
+ - `--app <name>`:指定 AUN app slot
44
46
  - `--overwrite` / `--force`:`cp/mv/ln` 覆盖目标;`rm` 强制删除
45
47
  - `-r` / `--recursive`:`rm/cp` 递归
46
48
  - `-p` / `--parents`:`mkdir` 自动创建父目录
47
49
  - `-L` / `--follow`:`stat` 跟随末级软链
48
50
  - `--token <token>`:读取 personal storage 时携带访问 token
49
51
  - `--content-type <mime>`:上传时指定 MIME
52
+ - `--public`:上传后公开可读(personal storage)
50
53
  - `--max-bytes <n>`:`cat` 最大直接输出字节数,默认 1MB
51
54
  - `--head-bytes <n>`:`cat` 二进制头部字节数,默认 256
52
55
  - `--visibility public|private`:`chmod` 可见性
@@ -54,6 +57,12 @@ ec fs umount <AID>:<path> # 卸载挂载点
54
57
  - `-m aid:<aid>:<perms>` / `-x aid:<aid>`:`setfacl` 增删 ACL
55
58
  - `--source <AID>:<path>` / `--volume <id>`:`mount` 来源
56
59
  - `--expires <time>`:`mount/token/ACL` 过期时间,Unix 秒或 ISO 日期
60
+ - `--require-approval`:挂载需要来源 owner 审批
61
+ - `--max-uses <n>`:ACL 最大使用次数
62
+ - `--max-reads <n>`:访问 token 最大读取次数
63
+ - `--readonly` / `--readwrite`:挂载为只读或读写
64
+ - `--name <glob>` / `--type <f|d|l>`:`find` 名称或类型过滤
65
+ - `--size <expr>` / `--mtime <expr>`:`find` 大小或修改时间过滤
57
66
 
58
67
  ## 示例
59
68
 
@@ -38,11 +38,19 @@ ec group send <from> <group-id> "通知" --mention alice.agentid.pub,bob.agentid
38
38
  > 若正文**精确等于**某个 flag 名(如要发送文本 `--encrypt`),用 `--` 分隔:
39
39
  > `ec group send <from> <group-id> -- --encrypt`
40
40
 
41
+ 发送选项还包括:
42
+
43
+ - `--no-encrypt`:强制明文,优先于 `--encrypt`
44
+ - `--thread <id>`:指定话题 ID
45
+ - `--return <required|none>`:跨会话回流策略
46
+ - `--content-type <mime>`:覆盖文件 MIME
47
+ - `--transcript <text>`:语音转写,仅 `--as voice`
48
+
41
49
  ## 群管理
42
50
 
43
51
  ```bash
44
52
  # 创建群
45
- ec group create <from> "<name>" [--visibility public|private] [--description "<desc>"] [--join-mode <mode>]
53
+ ec group create <from> "<name>" [--visibility public|private] [--description "<desc>"] [--join-mode <mode>] [--group-id <aid>]
46
54
 
47
55
  # 列出我加入的群
48
56
  ec group list <from> [--size <N>]
@@ -126,8 +134,9 @@ ec group unban <from> <group-id> <member-aid>
126
134
  ## 通用约定
127
135
 
128
136
  - `<from>` 必须是合法 AID(入口统一校验,格式错直接报错)
129
- - `--format json` — 所有子命令通用
130
- - `--app <name>` — 指应用 slot(独立消费通道,不影响 daemon)
137
+ - `--format json` — 对支持结构化结果的子命令输出 JSON
138
+ - `--app <name>` — `pull` / `ack` 指定独立消费 slot
139
+ - `--aun-path <path>` — 指定 AUN keystore 根
131
140
  - `--encrypt` — 仅 send,启用端到端加密(群聊默认明文)
132
141
  - `create` 会通过 SDK 自动生成并导入群 `group_aid` 身份。
133
142
  - `owner` 会走 SDK 的群主转让授权签名流程,需要本机有该群 `group_aid` 的私钥;若网关返回 `pending_rekey`,CLI 会在本机存在新群主私钥时自动调用完成步骤,否则输出“已发起,等待新群主完成 rekey”。
@@ -14,7 +14,7 @@ ec model current [--self <aid>] [--peer <peer>] [--role <role>]
14
14
  # 查看单个模型详情
15
15
  ec model info <model-id> [--self <aid>]
16
16
 
17
- # 设置模型,可同时设置推理强度
17
+ # 设置模型,可同时设置推理强度;本机终端写操作需要 --self
18
18
  ec model use <model-id> --self <aid> [--peer <peer>] [--effort <level>]
19
19
 
20
20
  # 设置推理强度:low | medium | high | xhigh | max | auto
@@ -38,6 +38,9 @@ ec model check [--self <aid>]
38
38
 
39
39
  生效优先级为关系、角色、agent、defaults。`--peer` 可使用 `channelType#channelId`;裸 AID 按 `aun#<aid>` 处理。
40
40
 
41
+ 在 EvolCore 托管会话中,省略 `--self`、`--peer`、`--role` 时,`list/current/use/effort/reset`
42
+ 会通过 `ec ctl` 作用于当前会话;显式 selector 仍按上表访问持久化作用域。本机终端不具备该隐式当前会话语义。
43
+
41
44
  ## 输出与权限
42
45
 
43
46
  - 所有子命令支持 `--format json`。