evolcore 0.0.41 → 0.0.42

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 (190) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/bin/codex-managed-hook.mjs +9 -5
  3. package/dist/agents/baseagent.js +156 -16
  4. package/dist/agents/claude-runner.js +10 -3
  5. package/dist/agents/codex/catalog.js +8 -4
  6. package/dist/agents/codex-runner.js +236 -59
  7. package/dist/agents/ecagent-runner.js +82 -13
  8. package/dist/aun/aid/agentmd.js +106 -27
  9. package/dist/aun/aid/client.js +1 -1
  10. package/dist/aun/aid/control-aid.js +65 -13
  11. package/dist/aun/aid/identity.js +70 -4
  12. package/dist/aun/aid/index.js +2 -2
  13. package/dist/aun/service-proxy.js +25 -1
  14. package/dist/channels/aun.js +242 -209
  15. package/dist/channels/dingtalk.js +1 -1
  16. package/dist/channels/feishu.js +1 -1
  17. package/dist/channels/qqbot.js +1 -1
  18. package/dist/channels/wechat.js +1 -1
  19. package/dist/channels/wecom.js +1 -1
  20. package/dist/cli/agent-command.js +183 -3
  21. package/dist/cli/agent-create.js +92 -86
  22. package/dist/cli/agent.js +136 -1
  23. package/dist/cli/aun-commands.js +137 -35
  24. package/dist/cli/bench.js +8 -2
  25. package/dist/cli/command-log.js +1 -1
  26. package/dist/cli/daemon-commands.js +235 -51
  27. package/dist/cli/debug-mode.js +1 -1
  28. package/dist/cli/directory.js +170 -0
  29. package/dist/cli/index.js +40 -30
  30. package/dist/cli/init-channel.js +4 -4
  31. package/dist/cli/init.js +47 -32
  32. package/dist/cli/managed-command-guard.js +4 -1
  33. package/dist/cli/model.js +27 -18
  34. package/dist/cli/pa-workspace-command.js +191 -0
  35. package/dist/cli/{contact.js → peer.js} +19 -25
  36. package/dist/cli/restart-monitor.js +11 -4
  37. package/dist/cli/thread-command.js +47 -18
  38. package/dist/cli/version.js +18 -18
  39. package/dist/config/access-policy.js +29 -12
  40. package/dist/config/boot-log.js +65 -10
  41. package/dist/config/builtin-roles.js +2 -4
  42. package/dist/config/config-field-policy.js +3 -0
  43. package/dist/config/config-manager.js +28 -20
  44. package/dist/config/{contact-bind-code.js → peer-bind-code.js} +6 -6
  45. package/dist/config/{contact-book-store.js → peer-book-store.js} +75 -75
  46. package/dist/config/{contact-book-v2-startup.js → peer-book-v2-startup.js} +2 -2
  47. package/dist/config/{contact-book.js → peer-book.js} +47 -47
  48. package/dist/config/peer-operation-service.js +132 -0
  49. package/dist/config/{contact-request-service.js → peer-request-service.js} +90 -90
  50. package/dist/config/peer-role-resolver.js +3 -3
  51. package/dist/config/providers-config.js +17 -8
  52. package/dist/config/providers.js +1 -1
  53. package/dist/config/schema-migration.js +336 -39
  54. package/dist/core/agent-application-service.js +8 -2
  55. package/dist/core/agent-create-status.js +4 -5
  56. package/dist/core/agent-ipc-registration.js +5 -4
  57. package/dist/core/agent-runtime.js +30 -17
  58. package/dist/core/auth/operation-authorizer.js +0 -24
  59. package/dist/core/auth/operation-catalog.js +4 -20
  60. package/dist/core/baseagent-loader.js +27 -3
  61. package/dist/core/bootstrap-service.js +5 -22
  62. package/dist/core/capability/capability-manager.js +52 -35
  63. package/dist/core/channel-loader.js +43 -2
  64. package/dist/core/channel-runtime.js +2 -2
  65. package/dist/core/command/agent-control.js +54 -18
  66. package/dist/core/command/command-handler.js +92 -72
  67. package/dist/core/command/connect-menu.js +35 -42
  68. package/dist/core/command/daemon-diagnostics.js +41 -5
  69. package/dist/core/command/data-root-error.js +10 -0
  70. package/dist/core/command/data-root-resolver.js +53 -13
  71. package/dist/core/command/menu-catalog.js +1 -0
  72. package/dist/core/command/menu-handler.js +163 -65
  73. package/dist/core/command/menu-protocol.js +52 -0
  74. package/dist/core/command/pa-workspace-calendar.js +223 -0
  75. package/dist/core/command/pa-workspace-store.js +459 -0
  76. package/dist/core/command/role-menu.js +2 -2
  77. package/dist/core/command/slash-gate.js +1 -1
  78. package/dist/core/command/slash-handler.js +57 -41
  79. package/dist/core/daemon-lifecycle.js +90 -31
  80. package/dist/core/evolagent.js +6 -10
  81. package/dist/core/handoff/runtime.js +11 -4
  82. package/dist/core/host-snapshot.js +208 -0
  83. package/dist/core/initialization/service.js +152 -20
  84. package/dist/core/ipc-registration.js +33 -4
  85. package/dist/core/memory/batch-meta.js +27 -0
  86. package/dist/core/memory/consolidation-ops-records.js +44 -1
  87. package/dist/core/memory/consolidation.js +169 -27
  88. package/dist/core/message/aun-ipc-sender.js +2 -8
  89. package/dist/core/message/im-renderer.js +56 -3
  90. package/dist/core/message/message-admission.js +121 -124
  91. package/dist/core/message/message-bridge.js +38 -54
  92. package/dist/core/message/message-queue.js +7 -0
  93. package/dist/core/message/outbound.js +34 -9
  94. package/dist/core/message/response-engine.js +154 -73
  95. package/dist/core/model/catalog-service.js +1 -1
  96. package/dist/core/model/config-scope.js +2 -2
  97. package/dist/core/model/model-catalog.js +5 -4
  98. package/dist/core/model/model-diagnostics.js +6 -5
  99. package/dist/core/model/model-fallback.js +3 -6
  100. package/dist/core/model/model-permission.js +1 -1
  101. package/dist/core/ownership/owner-resolver.js +9 -9
  102. package/dist/core/permission/approval-gateway.js +1 -1
  103. package/dist/core/permission/ec-command-parser.js +2 -2
  104. package/dist/core/permission/tool-canonical.js +96 -46
  105. package/dist/core/permission/tool-error-code.js +41 -0
  106. package/dist/core/permission/tool-policy.js +71 -47
  107. package/dist/core/role/runtime-policy.js +1 -1
  108. package/dist/core/session/session-idle-monitor.js +10 -0
  109. package/dist/core/session/session-manager.js +2 -4
  110. package/dist/core/session/session-title.js +36 -8
  111. package/dist/core/system-session/memory.js +2 -7
  112. package/dist/core/thread/command-parser.js +6 -2
  113. package/dist/core/thread/ipc-operation.js +51 -36
  114. package/dist/core/thread/thread-operation.js +29 -61
  115. package/dist/core/thread/thread-service.js +57 -13
  116. package/dist/directory/canonical-digest.js +54 -0
  117. package/dist/directory/owner-directory-admission.js +114 -43
  118. package/dist/directory/owner-directory-agentmd-sync.js +89 -0
  119. package/dist/directory/owner-directory-cache.js +847 -459
  120. package/dist/directory/owner-directory-markdown.js +272 -0
  121. package/dist/directory/owner-directory-query-operation.js +195 -0
  122. package/dist/directory/owner-directory-remark-operation.js +147 -0
  123. package/dist/directory/owner-directory-remarks.js +145 -0
  124. package/dist/directory/owner-directory-scope.js +55 -0
  125. package/dist/directory/owner-directory-search.js +148 -0
  126. package/dist/directory/owner-directory-store.js +227 -0
  127. package/dist/eck/kit-renderer.js +1 -0
  128. package/dist/ecweb/basic-settings-service.js +4 -1
  129. package/dist/ecweb/message-context-service.js +13 -9
  130. package/dist/index.js +195 -37
  131. package/dist/ipc.js +86 -22
  132. package/dist/paths.js +11 -8
  133. package/dist/product.js +2 -0
  134. package/dist/proxy/manager.js +13 -2
  135. package/dist/proxy/service-supervisor.js +8 -1
  136. package/dist/trigger/history.js +23 -0
  137. package/dist/trigger/scheduler.js +3 -0
  138. package/dist/utils/atomic-write.js +21 -0
  139. package/dist/utils/cross-platform.js +35 -0
  140. package/dist/utils/ecweb-supervisor.js +42 -0
  141. package/dist/utils/error-utils.js +2 -1
  142. package/dist/utils/evolcore-version.js +19 -0
  143. package/dist/utils/host-info.js +242 -5
  144. package/dist/utils/instance-registry.js +28 -6
  145. package/dist/utils/logger.js +59 -14
  146. package/dist/utils/machine-info.js +46 -0
  147. package/dist/utils/process-introspect.js +166 -2
  148. package/dist/utils/startup-trace.js +245 -0
  149. package/ecagent/dist/agent-loop.js +27 -13
  150. package/ecagent/dist/harness/agent-harness.js +3 -3
  151. package/ecagent/dist/harness/types.d.ts +1 -0
  152. package/ecagent/dist/types.d.ts +1 -0
  153. package/kits/docs/INDEX.md +1 -1
  154. package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +72 -0
  155. package/kits/docs/evolcore/INDEX.md +3 -2
  156. package/kits/docs/evolcore/agent-create.md +17 -27
  157. package/kits/docs/evolcore/agent.md +4 -1
  158. package/kits/docs/evolcore/aid.md +3 -1
  159. package/kits/docs/evolcore/config.md +16 -5
  160. package/kits/docs/evolcore/ctl.md +9 -0
  161. package/kits/docs/evolcore/ec-capabilities.md +19 -0
  162. package/kits/docs/evolcore/memory-consolidation-batches.md +79 -5
  163. package/kits/docs/evolcore/menu-exec-schema-commands.md +2 -1
  164. package/kits/docs/evolcore/menu-protocol.md +1 -0
  165. package/kits/docs/evolcore/model.md +13 -4
  166. package/kits/docs/evolcore/msg.md +1 -1
  167. package/kits/docs/evolcore/pa-workspace.md +51 -0
  168. package/kits/docs/evolcore/peer.md +73 -0
  169. package/kits/docs/evolcore/thread-chain.md +4 -1
  170. package/kits/eck_manifest.json +21 -0
  171. package/kits/rules/06-channel.md +1 -1
  172. package/kits/schemas/_meta.json +12 -1
  173. package/kits/schemas/agent-config.schema.16.json +6 -0
  174. package/kits/schemas/agent-config.schema.17.json +897 -0
  175. package/kits/schemas/daemon.schema.9.json +8 -1
  176. package/kits/skills/ec-agent-create/SKILL.md +2 -2
  177. package/kits/skills/ec-identity/SKILL.md +45 -27
  178. package/kits/skills/ec-service-proxy/SKILL.md +7 -2
  179. package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +4 -5
  180. package/kits/skills/thread-ops/SKILL.md +11 -11
  181. package/kits/templates/bootstrap-welcome.md +3 -15
  182. package/kits/templates/message-fragments/item.md +1 -1
  183. package/kits/templates/system-fragments/bootstrap.md +24 -23
  184. package/kits/templates/system-fragments/commands.md +12 -5
  185. package/kits/templates/system-fragments/thread.md +18 -3
  186. package/package.json +6 -4
  187. package/dist/config/contact-operation-service.js +0 -235
  188. package/dist/directory/owner-directory-authorization.js +0 -309
  189. package/kits/docs/evolcore/contact.md +0 -78
  190. /package/dist/config/{contact-alias.js → peer-alias.js} +0 -0
package/dist/cli/model.js CHANGED
@@ -11,8 +11,9 @@
11
11
  * 设计见 docs/model-command-design.md。
12
12
  */
13
13
  import { isHelpFlag, wantsHelp, getArgValue } from './help.js';
14
+ import { resolveRuntimeBaseagentModelSelection } from '../agents/baseagent.js';
14
15
  import { ModelScopeError, normalizePeer, determineScope, activeBaseagent, writeAgentModelConfig, clearAgentModelConfig, } from '../core/model/config-scope.js';
15
- import { resolveEffectiveFieldWithSource } from '../config/config-manager.js';
16
+ import { resolveEffective, resolveEffectiveFieldWithSource } from '../config/config-manager.js';
16
17
  import { getCatalog, getModelInfo, catalogEfforts, resolveCatalogModel, assertCatalogSelectable } from '../core/model/model-catalog.js';
17
18
  import { constrainResolvedModelForRole, filterModelsForRole, validateModelSelectionForRole, } from '../core/model/model-permission.js';
18
19
  import { resolvePaths } from '../paths.js';
@@ -20,10 +21,12 @@ import { daemonUnavailableMessage, queryDaemon } from './help.js';
20
21
  import { parsePeerKey } from '../core/relation/peer-identity.js';
21
22
  import { resolvePeerRoleDetail } from '../config/peer-role-resolver.js';
22
23
  import { AGENT_DELEGATION_TOKEN_ENV, readDelegationCredential } from '../core/auth/agent-delegation.js';
24
+ import { resolveRuntimeStringField } from '../core/role/runtime-policy.js';
23
25
  import { formatModelCheck, runModelCheck } from '../core/model/model-diagnostics.js';
24
26
  const ALL_EFFORTS = ['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max', 'auto'];
25
27
  const SCOPE_LABEL = {
26
28
  global: '全局', agent: 'agent级', role: '角色级', relation: '关系级',
29
+ cli: '本机 CLI', runner: 'runner 默认',
27
30
  };
28
31
  /** 输出 JSON 并退出(success=false 时 exit 1)。 */
29
32
  function emit(formatJson, payload, textFn) {
@@ -145,26 +148,33 @@ function modelScopeFromSource(source) {
145
148
  return layer;
146
149
  return undefined;
147
150
  }
148
- function resolveModelConfig(sel, baseagent) {
151
+ async function resolveModelConfig(sel, baseagent) {
149
152
  const effortKey = 'effort';
150
153
  const model = resolveEffectiveFieldWithSource(`baseagents.${baseagent}.model`, sel, { cache: true });
151
154
  const effort = resolveEffectiveFieldWithSource(`baseagents.${baseagent}.${effortKey}`, sel, { cache: true });
155
+ const selection = await resolveRuntimeBaseagentModelSelection(baseagent, resolveEffective(sel, { cache: true }).baseagents?.[baseagent]);
152
156
  const modelDecision = sel.role
153
157
  ? constrainResolvedModelForRole({
154
158
  role: sel.role,
155
159
  baseagent,
156
- model: model.value,
160
+ model: selection?.model ?? model.value,
157
161
  selfAid: sel.self,
158
162
  })
159
- : { model: model.value, constrained: false };
163
+ : { model: selection?.model ?? model.value, constrained: false };
160
164
  const effectiveModel = modelDecision.model;
161
- const modelSource = modelDecision.constrained ? 'role' : modelScopeFromSource(model.source);
162
- const source = effectiveModel !== undefined ? modelSource : modelScopeFromSource(effort.source);
163
- // 模型只在 Agent 级配置,角色策略只做约束。
164
- const scopes = ['role', 'agent'];
165
+ const source = modelDecision.constrained ? 'role'
166
+ : selection?.modelSource === 'configured' ? modelScopeFromSource(model.source)
167
+ : selection?.modelSource;
168
+ const scopes = ['role', 'agent', 'global', 'cli', 'runner'];
169
+ const effectiveEffort = sel.role ? resolveRuntimeStringField({
170
+ selfAid: sel.self,
171
+ role: sel.role,
172
+ field: `baseagents.${baseagent}.effort`,
173
+ configuredValue: selection?.effort ?? effort.value,
174
+ }).effectiveValue : selection?.effort ?? effort.value;
165
175
  return {
166
176
  model: effectiveModel,
167
- effort: effort.value,
177
+ effort: effectiveEffort,
168
178
  source,
169
179
  chain: scopes.map(scope => ({
170
180
  scope,
@@ -180,12 +190,11 @@ Commands:
180
190
  current 显示 Agent 级模型(经角色约束)+ 来源
181
191
  info <model-id> 查看单个模型详情(厂商/上下文/价格/模态/effort/状态)
182
192
  use <model-id> 设置 Agent 级模型(需 --self)
183
- reset 清除 Agent 级模型与推理强度;清除后该 Agent 无模型可用
193
+ reset 清除 Agent 级模型与推理强度,回落到较低优先级配置
184
194
  effort <level> 设置 Agent 级推理强度(low|medium|high|xhigh|max|auto)
185
195
  check 诊断网关连通性与模型可用性(分阶段输出进度)
186
196
 
187
- 模型参数只在 Agent 级配置(agents/<aid>/config.json 的 baseagents.<ba>.{model,effort})。
188
- 关系级与 defaults 都不承载模型;Agent 级未设置模型即无模型可用。
197
+ 模型解析顺序:Agent 配置 → defaults → 本机 CLI 配置 → runner 默认模型。
189
198
  (无参数) 本机 CLI 只读 catalog,不允许写入
190
199
  --self <aid> Agent 级(读写)
191
200
  --self <aid> --role <role> 按角色策略预览有效模型(只读)
@@ -235,7 +244,7 @@ async function cmdList(args, formatJson) {
235
244
  const effectiveSel = selectorWithRole(sel, role);
236
245
  const ba = activeBaseagent(sel.self);
237
246
  const cat = await getCatalog(sel.self, ba);
238
- const resolved = resolveModelConfig(effectiveSel, ba);
247
+ const resolved = await resolveModelConfig(effectiveSel, ba);
239
248
  const allowedModelIds = role
240
249
  ? filterModelsForRole(role, ba, cat.models.map(m => m.id), model => resolveCatalogModel(cat, model), sel.self)
241
250
  : null;
@@ -254,7 +263,7 @@ async function cmdList(args, formatJson) {
254
263
  models,
255
264
  }, () => {
256
265
  const lines = [];
257
- lines.push(`当前生效: ${resolved.model ?? '(未配置,Agent 级未设置模型,无模型可用)'}` +
266
+ lines.push(`当前生效: ${resolved.model ?? '(未配置)'}` +
258
267
  (resolved.source ? ` (来源: ${SCOPE_LABEL[resolved.source]})` : ''));
259
268
  lines.push('');
260
269
  if (resolved.model && !cat.models.some(m => m.id === resolved.model))
@@ -279,7 +288,7 @@ async function cmdCurrent(args, formatJson) {
279
288
  const sel = parseSelector(args, formatJson);
280
289
  const ba = activeBaseagent(sel.self);
281
290
  const role = explicitOrDerivedRole(args, sel);
282
- const resolved = resolveModelConfig(selectorWithRole(sel, role), ba);
291
+ const resolved = await resolveModelConfig(selectorWithRole(sel, role), ba);
283
292
  emit(formatJson, {
284
293
  ok: true,
285
294
  model: resolved.model ?? null,
@@ -289,7 +298,7 @@ async function cmdCurrent(args, formatJson) {
289
298
  chain: resolved.chain.map((c) => ({ scope: c.scope, model: c.model ?? null, hit: c.hit })),
290
299
  }, () => {
291
300
  const lines = [];
292
- lines.push(`当前生效模型: ${resolved.model ?? '(未配置,Agent 级未设置模型,无模型可用)'}`);
301
+ lines.push(`当前生效模型: ${resolved.model ?? '(未配置)'}`);
293
302
  lines.push(`推理强度: ${resolved.effort ?? 'auto'}`);
294
303
  lines.push(`来源: ${resolved.source ? SCOPE_LABEL[resolved.source] : '无'}`);
295
304
  const chain = resolved.chain.map((c) => `${SCOPE_LABEL[c.scope]}${c.hit ? ' ✓' : ''}${c.model ? `(${c.model})` : ''}`).join(' > ');
@@ -406,7 +415,7 @@ async function cmdEffort(args, formatJson) {
406
415
  if (val) {
407
416
  const cat = await getCatalog(sel.self, ba);
408
417
  assertCatalogSelectable(cat);
409
- const model = resolveModelConfig(selectorWithRole(sel, explicitOrDerivedRole(args, sel)), ba).model;
418
+ const model = (await resolveModelConfig(selectorWithRole(sel, explicitOrDerivedRole(args, sel)), ba)).model;
410
419
  if (!model || !catalogEfforts(cat, model, ba).includes(val))
411
420
  fail(formatJson, 'INVALID_EFFORT', `当前模型目录未声明支持推理强度: ${val}`);
412
421
  }
@@ -439,7 +448,7 @@ async function cmdReset(args, formatJson) {
439
448
  emit(formatJson, {
440
449
  ok: true, scope: 'agent', self: sel.self ?? null, peerKey: sel.peerKey ?? null,
441
450
  }, () => {
442
- return `✓ 已清除 Agent 级模型设置(该 Agent 所有会话下条消息生效,无模型可用直到重新设置)`;
451
+ return `✓ 已清除 Agent 级模型设置(该 Agent 所有会话下条消息起回落到较低优先级配置)`;
443
452
  });
444
453
  }
445
454
  async function cmdCheck(args, formatJson) {
@@ -0,0 +1,191 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { spawn } from 'node:child_process';
4
+ import { authorizeLocalCommand } from './task-context.js';
5
+ import { bindPaWorkspace, paWorkspaceStore, readPaWorkspaceNavigation, updatePaWorkspaceNavigation } from '../core/command/pa-workspace-store.js';
6
+ import { getPackageRoot } from '../paths.js';
7
+ const USAGE = `用法: ec pa-workspace init --workspace <绝对路径> [--force] [--with-triggers]
8
+ ec pa-workspace bind --workspace <已有工作区绝对路径>
9
+ ec pa-workspace navigation show
10
+ ec pa-workspace navigation update --expected-revision <n> --entries-json <json>
11
+
12
+ 仅限当前 Agent 的 AUN owner 私聊托管会话。`;
13
+ const MAX_SKILL_OUTPUT_CHARS = 2 * 1024 * 1024;
14
+ export class PaWorkspaceCommandError extends Error {
15
+ code;
16
+ details;
17
+ constructor(code, message, details) {
18
+ super(message);
19
+ this.code = code;
20
+ this.details = details;
21
+ this.name = 'PaWorkspaceCommandError';
22
+ }
23
+ }
24
+ function sanitizedInitializationResult(value) {
25
+ const output = {};
26
+ for (const key of ['mode', 'version', 'created', 'errors', 'triggers', 'occupancy']) {
27
+ if (value[key] !== undefined)
28
+ output[key] = value[key];
29
+ }
30
+ return output;
31
+ }
32
+ function runSkillInitialization(args) {
33
+ const packageRoot = getPackageRoot();
34
+ const script = path.join(packageRoot, 'kits', 'skills', 'personal-assistant', 'scripts', 'init.mjs');
35
+ if (!fs.existsSync(script)) {
36
+ return Promise.reject(new PaWorkspaceCommandError('NOT_CONFIGURED', 'EvolCore personal-assistant initialization script is unavailable'));
37
+ }
38
+ return new Promise((resolve, reject) => {
39
+ const child = spawn(process.execPath, [script, ...args], {
40
+ cwd: packageRoot,
41
+ windowsHide: true,
42
+ stdio: ['ignore', 'pipe', 'pipe'],
43
+ });
44
+ let stdout = '';
45
+ let stderr = '';
46
+ let outputTooLarge = false;
47
+ const collect = (current, chunk) => {
48
+ if (current.length + chunk.length > MAX_SKILL_OUTPUT_CHARS) {
49
+ outputTooLarge = true;
50
+ child.kill();
51
+ return current;
52
+ }
53
+ return current + chunk;
54
+ };
55
+ child.stdout.setEncoding('utf8').on('data', chunk => { stdout = collect(stdout, String(chunk)); });
56
+ child.stderr.setEncoding('utf8').on('data', chunk => { stderr = collect(stderr, String(chunk)); });
57
+ child.once('error', error => reject(new PaWorkspaceCommandError('SKILL_INIT_FAILED', error.message)));
58
+ child.once('close', code => {
59
+ if (outputTooLarge) {
60
+ reject(new PaWorkspaceCommandError('SKILL_INIT_OUTPUT_TOO_LARGE', 'Personal-assistant initialization output exceeded its limit'));
61
+ return;
62
+ }
63
+ resolve({ code, stdout, stderr });
64
+ });
65
+ });
66
+ }
67
+ /** Runs the unmodified Skill initializer and registers its exact workspace only after success. */
68
+ export async function initializePaWorkspace(input) {
69
+ if (!path.isAbsolute(input.workspacePath)) {
70
+ throw new PaWorkspaceCommandError('INVALID_ARGUMENT', '--workspace must be an absolute path');
71
+ }
72
+ const workspacePath = path.resolve(input.workspacePath);
73
+ const args = [
74
+ '--workspace', workspacePath,
75
+ '--owner', input.ownerAid,
76
+ '--json',
77
+ ...(input.force ? ['--force'] : []),
78
+ ...(input.withTriggers ? ['--with-triggers', '--self', input.paAid] : []),
79
+ ];
80
+ const result = await runSkillInitialization(args);
81
+ let initialized;
82
+ try {
83
+ initialized = JSON.parse(result.stdout);
84
+ }
85
+ catch {
86
+ throw new PaWorkspaceCommandError('SKILL_INIT_FAILED', 'Personal-assistant Skill returned an invalid result', {
87
+ exitCode: result.code,
88
+ });
89
+ }
90
+ if ((result.code !== 0 && result.code !== 10) || initialized.ok !== true) {
91
+ throw new PaWorkspaceCommandError(typeof initialized.code === 'string' ? initialized.code : 'SKILL_INIT_FAILED', 'Personal-assistant initialization did not complete; no Core workspace binding was created', { exitCode: result.code, ...sanitizedInitializationResult(initialized) });
92
+ }
93
+ const state = bindPaWorkspace(input.paAid, input.ownerAid, workspacePath);
94
+ return {
95
+ workspaceId: state.workspaceId,
96
+ navigationRevision: state.navigationRevision,
97
+ initialization: sanitizedInitializationResult(initialized),
98
+ };
99
+ }
100
+ function value(args, flag) {
101
+ const index = args.indexOf(flag);
102
+ return index >= 0 ? args[index + 1] : undefined;
103
+ }
104
+ function assertOwnerPrivateRuntime(context) {
105
+ if (context.channel !== 'aun' || context.chatType !== 'private' || context.peerRole !== 'owner'
106
+ || !context.selfAid || !context.peerId) {
107
+ throw Object.assign(new Error('PA workspace changes require the current Agent owner in an AUN private chat'), { code: 'NOT_ALLOWED' });
108
+ }
109
+ }
110
+ function output(value) {
111
+ process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
112
+ }
113
+ export async function cmdPaWorkspace(args) {
114
+ if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
115
+ console.log(USAGE);
116
+ return;
117
+ }
118
+ try {
119
+ const context = await authorizeLocalCommand(['pa-workspace', ...args]);
120
+ assertOwnerPrivateRuntime(context);
121
+ if (args[0] === 'init') {
122
+ let workspacePath;
123
+ let force = false;
124
+ let withTriggers = false;
125
+ for (let index = 1; index < args.length; index++) {
126
+ const argument = args[index];
127
+ if (argument === '--workspace')
128
+ workspacePath = args[++index];
129
+ else if (argument === '--force')
130
+ force = true;
131
+ else if (argument === '--with-triggers')
132
+ withTriggers = true;
133
+ else
134
+ throw new PaWorkspaceCommandError('INVALID_ARGUMENT', USAGE);
135
+ }
136
+ if (!workspacePath)
137
+ throw new PaWorkspaceCommandError('INVALID_ARGUMENT', USAGE);
138
+ output({ ok: true, ...await initializePaWorkspace({
139
+ paAid: context.selfAid,
140
+ ownerAid: context.peerId,
141
+ workspacePath,
142
+ force,
143
+ withTriggers,
144
+ }) });
145
+ return;
146
+ }
147
+ if (args[0] === 'bind') {
148
+ if (args.length !== 3 || args[1] !== '--workspace' || !args[2])
149
+ throw Object.assign(new Error(USAGE), { code: 'INVALID_ARGUMENT' });
150
+ const state = bindPaWorkspace(context.selfAid, context.peerId, args[2]);
151
+ output({ ok: true, workspaceId: state.workspaceId, navigationRevision: state.navigationRevision });
152
+ return;
153
+ }
154
+ if (args[0] === 'navigation' && args[1] === 'show' && args.length === 2) {
155
+ output({ ok: true, ...readPaWorkspaceNavigation(context.selfAid) });
156
+ return;
157
+ }
158
+ if (args[0] === 'navigation' && args[1] === 'update') {
159
+ const expected = value(args, '--expected-revision');
160
+ const entriesJson = value(args, '--entries-json');
161
+ if (!expected || !entriesJson || args.length !== 6 || !/^\d+$/.test(expected))
162
+ throw Object.assign(new Error(USAGE), { code: 'INVALID_ARGUMENT' });
163
+ let entries;
164
+ try {
165
+ entries = JSON.parse(entriesJson);
166
+ }
167
+ catch {
168
+ throw Object.assign(new Error('--entries-json must contain valid JSON'), { code: 'INVALID_ARGUMENT' });
169
+ }
170
+ output({ ok: true, ...updatePaWorkspaceNavigation(context.selfAid, Number(expected), entries) });
171
+ return;
172
+ }
173
+ if (args[0] === 'navigation' && args[1] === 'status' && args.length === 2) {
174
+ const state = paWorkspaceStore.require(context.selfAid);
175
+ output({ ok: true, workspaceId: state.workspaceId, navigationRevision: state.navigationRevision, entries: state.entries });
176
+ return;
177
+ }
178
+ throw Object.assign(new Error(USAGE), { code: 'INVALID_ARGUMENT' });
179
+ }
180
+ catch (error) {
181
+ const source = error;
182
+ const result = {
183
+ ok: false,
184
+ code: source.code ?? 'PA_WORKSPACE_FAILED',
185
+ error: error instanceof Error ? error.message : String(error),
186
+ ...(error instanceof PaWorkspaceCommandError && error.details ? { details: error.details } : {}),
187
+ };
188
+ process.stderr.write(`${JSON.stringify(result)}\n`);
189
+ process.exitCode = 1;
190
+ }
191
+ }
@@ -1,10 +1,10 @@
1
1
  import { resolvePaths } from '../paths.js';
2
2
  import { loadAllAgents } from '../config-store.js';
3
- import { executeResolvedContactCommand, resolveContactCommand, } from '../config/contact-operation-service.js';
3
+ import { executeResolvedPeerCommand, resolvePeerCommand, } from '../config/peer-operation-service.js';
4
4
  import { daemonUnavailableMessage, queryDaemon } from './help.js';
5
5
  import { AGENT_DELEGATION_TOKEN_ENV, readDelegationCredential } from '../core/auth/agent-delegation.js';
6
6
  import { getArgValue, isHelpFlag, wantsHelp } from './help.js';
7
- export async function cmdContact(args) {
7
+ export async function cmdPeer(args) {
8
8
  if (args.length === 0 || isHelpFlag(args[0]) || wantsHelp(args)) {
9
9
  printHelp();
10
10
  return;
@@ -25,14 +25,14 @@ export async function cmdContact(args) {
25
25
  output(await executeAggregateList(args), json);
26
26
  return;
27
27
  }
28
- const resolved = resolveContactCommand(withDefaultSelf(args));
28
+ const resolved = resolvePeerCommand(withDefaultSelf(args));
29
29
  if (!resolved.ok) {
30
30
  const message = resolved.code === 'INVALID_SELF' && !args.includes('--self')
31
31
  ? `${resolved.reason}; multiple local Agents are configured, add --self <agent-aid>`
32
32
  : resolved.reason;
33
33
  fail(message, resolved.code);
34
34
  }
35
- const result = await executeResolvedContactCommand(resolved.command);
35
+ const result = await executeResolvedPeerCommand(resolved.command);
36
36
  if (!result.ok)
37
37
  fail(result.error, result.code, result.data);
38
38
  output(result, json);
@@ -49,8 +49,8 @@ async function runManaged(args, json) {
49
49
  if (!delegationToken)
50
50
  fail(`${AGENT_DELEGATION_TOKEN_ENV} is not set for the active task`, 'DELEGATION_REQUIRED');
51
51
  const { response, transportError } = await queryDaemon(resolvePaths().socket, {
52
- type: 'contact.op',
53
- argv: ['contact', ...args],
52
+ type: 'peer.op',
53
+ argv: ['peer', ...args],
54
54
  sessionId,
55
55
  delegationToken,
56
56
  }, 10_000);
@@ -71,25 +71,19 @@ function fail(message, code = 'INVALID_ARGUMENT', data) {
71
71
  }
72
72
  function printHelp() {
73
73
  console.log(`Usage:
74
- ec contact add <primaryId> --self <agent-aid>
75
- ec contact block <primaryId> --self <agent-aid>
76
- ec contact unblock <primaryId> --self <agent-aid>
77
- ec contact list --blocked [--self <agent-aid>]
78
- ec contact list --pending [--self <agent-aid>]
79
- ec contact list --all [--self <agent-aid>]
80
- ec contact approve <primaryId> --request-id <id> [--self <agent-aid>]
81
- ec contact reject <primaryId> --request-id <id> [--self <agent-aid>]
82
- ec contact block-request <primaryId> --request-id <id> [--self <agent-aid>]
74
+ ec peer block <primaryId> --self <agent-aid>
75
+ ec peer unblock <primaryId> --self <agent-aid>
76
+ ec peer list --blocked [--self <agent-aid>]
77
+ ec peer list --all [--self <agent-aid>]
83
78
 
84
79
  Options:
85
80
  --self <agent-aid> 本端 agent AID;省略时从当前运行环境推断
86
- --blocked 仅列出已拉黑联系人
87
- --pending 仅列出待审核联系人申请
88
- --all 列出所有联系人及状态
89
- --request-id <id> 联系人申请 ID(审批命令必填)
90
- --contact-revision <revision> 申请审批时使用的联系人版本(可选)
81
+ --blocked 仅列出已拉黑的对端
82
+ --all 列出所有已登记的对端身份
91
83
  --format json 输出 JSON
92
- --help, -h 显示帮助`);
84
+ --help, -h 显示帮助
85
+
86
+ 添加联系人、审批联系人申请由 Owner 在 Evol App 名录中完成,Agent 侧不提供入口。`);
93
87
  }
94
88
  function withDefaultSelf(args) {
95
89
  if (args.includes('--self'))
@@ -104,18 +98,18 @@ async function executeAggregateList(args) {
104
98
  const agents = loadAllAgents().agents.map(agent => agent.aid).filter(Boolean).sort();
105
99
  const results = [];
106
100
  for (const aid of agents) {
107
- const resolved = resolveContactCommand([...args, '--self', aid]);
101
+ const resolved = resolvePeerCommand([...args, '--self', aid]);
108
102
  if (!resolved.ok)
109
103
  fail(resolved.reason, resolved.code);
110
- const result = await executeResolvedContactCommand(resolved.command);
104
+ const result = await executeResolvedPeerCommand(resolved.command);
111
105
  if (!result.ok)
112
106
  fail(result.error, result.code, result.data);
113
107
  results.push(result);
114
108
  }
115
109
  return {
116
110
  ok: true,
117
- operation: args.includes('--blocked') ? 'list-blocked'
118
- : args.includes('--pending') ? 'list-pending' : 'list-all',
111
+ operation: 'list',
112
+ filter: args.includes('--blocked') ? 'blocked' : 'all',
119
113
  scope: 'all-agents',
120
114
  agents: results,
121
115
  };
@@ -12,7 +12,7 @@ import { acknowledgeUpgradeRestart, readUpgradeJob, updateUpgradeJob } from '../
12
12
  import { isValidAid } from '../aun/aid/index.js';
13
13
  import { msgSend } from '../aun/msg/index.js';
14
14
  import { scanInstances, cleanupInstances, writeRestartMonitor, removeRestartMonitor, isRestartMonitorWinner, findOrphanProcesses, killOrphans, updateRestartMonitorPhase } from '../utils/instance-registry.js';
15
- import { MAIN_PACKAGE_NAME, RESTART_REQUEST_ID_ENV } from '../product.js';
15
+ import { CHANNEL_LOGS_ENV, MAIN_PACKAGE_NAME, RESTART_REQUEST_ID_ENV } from '../product.js';
16
16
  import { readRestartRequest, updateRestartRequest, removeRestartRequest, shouldSuppressRealRestart } from '../utils/restart-safety.js';
17
17
  import { rotateStdoutLog } from '../utils/log-writer.js';
18
18
  import { applyDataMigration, finalizeDataMigration, planDataMigration, verifyDataMigration, } from '../core/data-migration.js';
@@ -325,13 +325,17 @@ export async function cmdRestartMonitor() {
325
325
  const expectedStarts = new Map(aliveMains.map(m => [m.record.pid, m.record.startedAt]));
326
326
  log(`Monitoring ${oldPids.length} main process(es): ${oldPids.join(', ')}`);
327
327
  const gracefulPid = await requestDaemonShutdown(p.socket, DAEMON_SHUTDOWN_TIMEOUT_MS, 'restart-monitor', new Set(oldPids));
328
+ log(`Graceful shutdown request ${gracefulPid === null ? 'was not accepted' : `accepted by PID ${gracefulPid}`}`);
328
329
  // 没有收到 IPC shutdown 确认的进程才走信号兜底
329
330
  for (const pid of oldPids) {
330
331
  if (pid !== gracefulPid) {
331
332
  try {
332
- platform.killProcess(pid, false);
333
+ const killed = platform.killProcessOnly(pid, false);
334
+ log(`Sent graceful termination to PID ${pid}: ${killed ? 'accepted' : 'failed'}`);
335
+ }
336
+ catch (error) {
337
+ log(`Graceful termination for PID ${pid} failed: ${error.message}`);
333
338
  }
334
- catch { }
335
339
  }
336
340
  }
337
341
  const exited = await Promise.all(oldPids.map(async (oldPid) => {
@@ -358,8 +362,10 @@ export async function cmdRestartMonitor() {
358
362
  reportPidReused(oldPid, log);
359
363
  return true;
360
364
  }
361
- platform.killProcess(oldPid, true);
365
+ const forcedKill = platform.killProcessOnly(oldPid, true);
366
+ log(`Forced termination for PID ${oldPid}: ${forcedKill ? 'accepted' : 'failed'}`);
362
367
  const forced = await platform.waitForProcessExit(oldPid, 5_000);
368
+ log(`Forced termination wait for PID ${oldPid}: ${forced ? 'exited' : 'still running'}`);
363
369
  if (isPidReused(oldPid, expectedStartedAt)) {
364
370
  reportPidReused(oldPid, log);
365
371
  return true;
@@ -1088,6 +1094,7 @@ async function spawnAndWaitReady(p, log, timeout) {
1088
1094
  LOG_LEVEL: process.env.LOG_LEVEL || 'INFO',
1089
1095
  MESSAGE_LOG: process.env.MESSAGE_LOG || 'true',
1090
1096
  EVENT_LOG: process.env.EVENT_LOG || 'true',
1097
+ [CHANNEL_LOGS_ENV]: process.env[CHANNEL_LOGS_ENV] || 'false',
1091
1098
  }
1092
1099
  });
1093
1100
  const childPid = child.pid;
@@ -4,6 +4,7 @@ import { readDelegationCredential } from '../core/auth/agent-delegation.js';
4
4
  import { canonicalizeEvolcoreCommandArgv } from '../core/permission/ec-command-parser.js';
5
5
  import { isMainSessionThreadId, resolveThreadRef } from '../core/thread/topic-id.js';
6
6
  import { parseTimeArg, TIME_ARG_FORMATS } from './cli-argv.js';
7
+ import { readTaskRuntimeContextFromEnv } from './task-context.js';
7
8
  const TOPIC_STATUSES = ['pending', 'in_progress', 'completed', 'archived'];
8
9
  const SORT_ORDERS = ['recent', 'created'];
9
10
  const HELP_TEXT = `
@@ -28,14 +29,14 @@ ec thread <command> [options]
28
29
  check-index 同 rebuild-index --check
29
30
 
30
31
  典型工作流:
31
- 1. ec agent list # 查看本机所有 agent
32
- 2. ec thread peers --self <selfAid> # 查看该 agent 的所有对端
33
- 3. ec thread list <peer> --self <selfAid> # 查看与该对端的话题列表
32
+ 1. ec thread peers # 查看有话题记录的所有对端
33
+ 2. ec thread list <peer> # 查看与该对端的话题列表(第一列即 <ref>)
34
+ 3. ec thread history <threadId> # 读该话题的历史
34
35
 
35
- <ref> 格式(所有命令统一支持):
36
- current 当前任务所在话题(托管会话自动注入)
37
- <peer> 该对端的主会话
38
- <peer>/<threadId> 指定具体话题
36
+ <ref> 格式(取 ec thread list 打印的第一列):
37
+ current 当前任务所在话题(仅托管会话)
38
+ <threadId> 话题,如 thread-1791028341906-0000-136a
39
+ main:<aidA>:<aidB> 主话题
39
40
 
40
41
  list 选项:
41
42
  --status <s> 过滤状态 (pending|in_progress|completed|archived)
@@ -77,7 +78,7 @@ label 选项:
77
78
  状态值: pending | in_progress | completed | archived
78
79
 
79
80
  --format json 以 JSON 格式输出
80
- --self <selfAid> 宿主终端必填,指定本端 AID
81
+ --self <selfAid> 宿主终端必填,指定本端 AID;托管会话由运行时注入,不写
81
82
  --help 显示帮助
82
83
  `.trim();
83
84
  function argValue(args, flag) {
@@ -104,20 +105,20 @@ async function sendThreadOp(req, commandArgv) {
104
105
  };
105
106
  return result;
106
107
  }
107
- function printResult(data, jsonFormat) {
108
+ function printResult(data, jsonFormat, opts) {
108
109
  if (jsonFormat) {
109
110
  console.log(JSON.stringify(data, null, 2));
110
111
  }
111
112
  else if (Array.isArray(data)) {
112
113
  for (const item of data) {
113
- printItem(item);
114
+ printItem(item, opts);
114
115
  }
115
116
  }
116
117
  else {
117
- printItem(data);
118
+ printItem(data, opts);
118
119
  }
119
120
  }
120
- function printItem(item) {
121
+ function printItem(item, opts) {
121
122
  if (typeof item !== 'object' || !item) {
122
123
  console.log(String(item));
123
124
  return;
@@ -147,7 +148,9 @@ function printItem(item) {
147
148
  // 否则会渲染成 `[主话题] [主会话] …`。存储值不改,避免误改用户起的名字。
148
149
  const displayName = String(obj.name ?? '').replace(/^\[(?:主会话|主话题)\]\s*/, '');
149
150
  console.log(` 名称: ${namePrefix}${displayName}`);
150
- if (obj.topicStatus)
151
+ if (isMainSessionThreadId(String(obj.threadId)))
152
+ console.log(' 状态: 不适用(主话题没有业务状态)');
153
+ else if (obj.topicStatus)
151
154
  console.log(` 状态: ${obj.topicStatus}`);
152
155
  if (obj.label)
153
156
  console.log(` 标签: ${obj.label}`);
@@ -204,11 +207,13 @@ function printItem(item) {
204
207
  if (result.hasMore) {
205
208
  const nextPage = result.page + 1;
206
209
  const peerArg = result.peer ?? '<peer>';
207
- const selfArg = result.selfAid ? `--self ${result.selfAid}` : '--self <selfAid>';
210
+ // 只回显用户实际传过的 --self:托管会话里 selfAid 由运行时注入、用户没写,
211
+ // 页脚就不该教他补一个。回显运行时值会让「不写 --self」的约定看起来没生效。
212
+ const selfArg = opts?.echoSelf ? ` --self ${opts.echoSelf}` : '';
208
213
  const sortArg = result.sort ? ` --sort ${result.sort}` : ' --sort recent';
209
214
  const statusArg = result.status ? ` --status ${result.status}` : '';
210
215
  const labelArg = result.label ? ` --label "${result.label}"` : '';
211
- console.log(`下一页: ec thread list ${peerArg} ${selfArg} --page ${nextPage} --limit ${result.limit}${sortArg}${statusArg}${labelArg}`);
216
+ console.log(`下一页: ec thread list ${peerArg}${selfArg} --page ${nextPage} --limit ${result.limit}${sortArg}${statusArg}${labelArg}`);
212
217
  }
213
218
  return;
214
219
  }
@@ -234,8 +239,10 @@ export async function runThreadCommand(args) {
234
239
  return;
235
240
  }
236
241
  const managedSessionId = process.env.EVOLCORE_SESSION_ID;
242
+ // 托管 runner 只注入任务运行时上下文,不注入 EVOLCORE_SELF_AID(后者只有 debug 模式设置)。
243
+ // 本端身份以 daemon 侧的委托凭据为准,这里取值只用于本地预检与引用解析。
237
244
  const selfAid = managedSessionId
238
- ? (process.env.EVOLCORE_SELF_AID ?? argValue(args, '--self'))
245
+ ? (process.env.EVOLCORE_SELF_AID || readTaskRuntimeContextFromEnv()?.selfAid || argValue(args, '--self'))
239
246
  : argValue(args, '--self');
240
247
  const commandArgv = canonicalizeEvolcoreCommandArgv(['ec', 'thread', ...args]).slice(1);
241
248
  const sendOp = (req) => sendThreadOp(req, commandArgv);
@@ -266,7 +273,9 @@ export async function runThreadCommand(args) {
266
273
  const peer = args[1]?.startsWith('-') ? undefined : args[1];
267
274
  // peer 是必填参数;不带 peer 没有意义(全量话题跨对端混排,含内部 daemon 话题)
268
275
  if (!peer) {
269
- console.error('用法: ec thread list <peer> [选项]\n提示: 用 ec thread peers --self <selfAid> 查看有话题的所有对端');
276
+ // 提示里的写法跟着用户实际得怎么敲走:托管会话不带 --self,宿主终端必须带。
277
+ const peersHint = argValue(args, '--self') ? 'ec thread peers --self <selfAid>' : 'ec thread peers';
278
+ console.error(`用法: ec thread list <peer> [选项]\n提示: 用 ${peersHint} 查看有话题的所有对端`);
270
279
  process.exitCode = 1;
271
280
  return;
272
281
  }
@@ -293,7 +302,7 @@ export async function runThreadCommand(args) {
293
302
  process.exitCode = 1;
294
303
  return;
295
304
  }
296
- printResult(resp.result, jsonFormat);
305
+ printResult(resp.result, jsonFormat, { echoSelf: argValue(args, '--self') });
297
306
  break;
298
307
  }
299
308
  case 'show': {
@@ -448,6 +457,26 @@ export async function runThreadCommand(args) {
448
457
  if (!target)
449
458
  return;
450
459
  const { peer, threadId } = target;
460
+ if (isMainSessionThreadId(threadId)) {
461
+ console.error('✗ 主话题没有业务状态;请将任务状态记在独立话题或摘要中。');
462
+ process.exitCode = 1;
463
+ return;
464
+ }
465
+ if (ref === 'current') {
466
+ const showArgv = canonicalizeEvolcoreCommandArgv(['ec', 'thread', 'show', 'current']).slice(1);
467
+ const current = await sendThreadOp({ op: 'show', selfAid }, showArgv);
468
+ if (!current.ok) {
469
+ console.error(`✗ ${current.error}`);
470
+ process.exitCode = 1;
471
+ return;
472
+ }
473
+ const currentThreadId = String(current.result?.threadId ?? '');
474
+ if (isMainSessionThreadId(currentThreadId)) {
475
+ console.error('✗ 当前目标是主话题,没有业务状态;请将任务状态记在摘要或独立话题中。');
476
+ process.exitCode = 1;
477
+ return;
478
+ }
479
+ }
451
480
  const resp = await sendOp({ op: 'status', selfAid, peer, threadId, topicStatus: statusVal });
452
481
  if (!resp.ok) {
453
482
  console.error(`✗ ${resp.error}`);