evolcore 0.0.43-test.2 → 0.0.43-test.4

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 (173) hide show
  1. package/CHANGELOG.md +44 -1
  2. package/bin/ecmsg.js +229 -0
  3. package/bin/install-codex-managed-hooks.mjs +130 -8
  4. package/dist/ability/application-service.js +37 -0
  5. package/dist/ability/resources.js +28 -0
  6. package/dist/ability/runtime.js +6 -1
  7. package/dist/agents/claude-runner.js +7 -5
  8. package/dist/agents/codex/app-server-client.js +0 -12
  9. package/dist/agents/codex-runner.js +0 -37
  10. package/dist/agents/ecagent-runner.js +138 -36
  11. package/dist/aun/aid/agentmd.js +52 -13
  12. package/dist/aun/menu/client.js +8 -7
  13. package/dist/aun/menu/index.js +1 -1
  14. package/dist/aun/menu/transport.js +8 -5
  15. package/dist/aun/msg/p2p.js +4 -2
  16. package/dist/aun/service-proxy.js +3 -0
  17. package/dist/channels/aun.js +105 -53
  18. package/dist/channels/daemon.js +14 -2
  19. package/dist/cli/agent-command.js +5 -0
  20. package/dist/cli/agent-create.js +31 -11
  21. package/dist/cli/agent.js +9 -3
  22. package/dist/cli/aun-commands.js +19 -21
  23. package/dist/cli/daemon-commands.js +30 -18
  24. package/dist/cli/directory.js +98 -56
  25. package/dist/cli/getmeta-command.js +2 -1
  26. package/dist/cli/index.js +1 -1
  27. package/dist/cli/init.js +13 -5
  28. package/dist/cli/peer.js +2 -1
  29. package/dist/cli/task-context.js +3 -1
  30. package/dist/cli/trigger-command.js +20 -14
  31. package/dist/config/access-policy.js +0 -1
  32. package/dist/config/boot-log.js +12 -2
  33. package/dist/config/builtin-role-templates.js +2 -2
  34. package/dist/config/builtin-roles.js +2 -1
  35. package/dist/config/config-field-policy.js +7 -0
  36. package/dist/config/config-manager.js +30 -10
  37. package/dist/config/peer-role-resolver.js +23 -1
  38. package/dist/config/role-schema.js +25 -1
  39. package/dist/config/role-service.js +9 -4
  40. package/dist/config/role-store.js +30 -8
  41. package/dist/config/schema-migration.js +121 -0
  42. package/dist/core/agent-application-service.js +11 -0
  43. package/dist/core/agent-ipc-registration.js +2 -0
  44. package/dist/core/agent-runtime.js +41 -9
  45. package/dist/core/auth/auth-gateway.js +14 -4
  46. package/dist/core/auth/operation-authorizer.js +19 -1
  47. package/dist/core/auth/operation-catalog.js +12 -2
  48. package/dist/core/baseagent-loader.js +11 -3
  49. package/dist/core/bootstrap-service.js +8 -0
  50. package/dist/core/channel-loader.js +61 -23
  51. package/dist/core/channel-runtime.js +5 -0
  52. package/dist/core/command/agent-control.js +5 -2
  53. package/dist/core/command/agentmd-menu-request.js +50 -0
  54. package/dist/core/command/agentmd-menu.js +156 -0
  55. package/dist/core/command/chatmode-config.js +46 -0
  56. package/dist/core/command/command-handler.js +44 -17
  57. package/dist/core/command/daemon-diagnostics.js +2 -1
  58. package/dist/core/command/menu-catalog.js +14 -1
  59. package/dist/core/command/menu-handler.js +74 -24
  60. package/dist/core/command/menu-protocol.js +8 -0
  61. package/dist/core/command/role-menu.js +23 -9
  62. package/dist/core/command/slash-handler.js +52 -47
  63. package/dist/core/daemon-lifecycle.js +43 -17
  64. package/dist/core/event-catalog.js +19 -0
  65. package/dist/core/evolagent-registry.js +3 -0
  66. package/dist/core/evolagent.js +5 -4
  67. package/dist/core/ipc-registration.js +6 -0
  68. package/dist/core/lifecycle-notice.js +185 -0
  69. package/dist/core/message/aun-ipc-sender.js +30 -24
  70. package/dist/core/message/contact-admission.js +1 -19
  71. package/dist/core/message/im-renderer.js +81 -40
  72. package/dist/core/message/message-admission.js +21 -62
  73. package/dist/core/message/message-bridge.js +18 -5
  74. package/dist/core/message/message-utils.js +9 -0
  75. package/dist/core/message/peer-mode.js +16 -8
  76. package/dist/core/message/response-engine.js +67 -47
  77. package/dist/core/model/model-capabilities.js +37 -0
  78. package/dist/core/model/model-catalog.js +6 -2
  79. package/dist/core/ownership/owner-resolver.js +74 -36
  80. package/dist/core/permission/ec-command-parser.js +62 -13
  81. package/dist/core/plugin-lifecycle.js +6 -2
  82. package/dist/core/relation/pa-team.js +132 -0
  83. package/dist/core/role/runtime-policy.js +4 -3
  84. package/dist/core/thread/thread-service.js +6 -4
  85. package/dist/directory/owner-directory-admission.js +0 -3
  86. package/dist/directory/owner-directory-cache.js +201 -17
  87. package/dist/directory/owner-directory-markdown.js +44 -21
  88. package/dist/directory/owner-directory-policy.js +1 -1
  89. package/dist/directory/owner-directory-query-operation.js +218 -98
  90. package/dist/directory/owner-directory-request-operation.js +76 -0
  91. package/dist/directory/owner-directory-scope.js +35 -4
  92. package/dist/directory/owner-directory-search.js +76 -23
  93. package/dist/directory/owner-directory-store.js +5 -38
  94. package/dist/directory/owner-directory-text.js +60 -0
  95. package/dist/eck/kit-renderer.js +6 -3
  96. package/dist/eck/message-renderer.js +2 -5
  97. package/dist/ecweb/message-context-service.js +4 -0
  98. package/dist/ecweb/runtime/lifecycle.js +29 -5
  99. package/dist/ecweb/runtime/supervisor.js +83 -27
  100. package/dist/index.js +209 -38
  101. package/dist/paths.js +4 -2
  102. package/dist/product.js +1 -0
  103. package/dist/proxy/service-supervisor.js +377 -141
  104. package/dist/response-system/engines/v1/index.js +2 -4
  105. package/dist/response-system/modes/single-session/index.js +1 -1
  106. package/dist/trigger/audit.js +3 -2
  107. package/dist/trigger/authorization.js +2 -3
  108. package/dist/trigger/history.js +4 -3
  109. package/dist/trigger/ipc-service.js +24 -19
  110. package/dist/trigger/manager.js +3 -5
  111. package/dist/trigger/parser.js +4 -21
  112. package/dist/trigger/patch.js +3 -15
  113. package/dist/trigger/scheduler.js +53 -13
  114. package/dist/trigger/validation.js +0 -13
  115. package/dist/utils/error-utils.js +15 -5
  116. package/dist/utils/macos-autostart.js +31 -0
  117. package/dist/utils/model-prices.jsonl +15 -8
  118. package/dist/utils/process-introspect.js +21 -1
  119. package/dist/utils/startup-trace.js +7 -1
  120. package/dist/utils/windows-autostart.js +1 -0
  121. package/ecagent/README.md +18 -0
  122. package/ecagent/dist/harness/agent-harness.d.ts +2 -0
  123. package/ecagent/dist/harness/agent-harness.js +24 -8
  124. package/ecagent/dist/harness/compaction/branch-summarization.js +1 -1
  125. package/ecagent/dist/harness/compaction/compaction.js +7 -4
  126. package/ecagent/dist/harness/types.d.ts +1 -0
  127. package/kits/docs/channels/aun.md +1 -1
  128. package/kits/docs/context-assembly.md +1 -1
  129. package/kits/docs/evolcore/INDEX.md +5 -2
  130. package/kits/docs/evolcore/directory.md +125 -35
  131. package/kits/docs/evolcore/ecweb-lifecycle.md +26 -0
  132. package/kits/docs/evolcore/file-navigation.md +279 -0
  133. package/kits/docs/evolcore/menu-protocol.md +1 -0
  134. package/kits/docs/evolcore/model.md +5 -3
  135. package/kits/docs/evolcore/msg.md +1 -0
  136. package/kits/docs/evolcore/peer.md +2 -1
  137. package/kits/docs/evolcore/response.md +4 -2
  138. package/kits/docs/evolcore/task.md +2 -0
  139. package/kits/docs/evolcore/thread-chain.md +1 -1
  140. package/kits/docs/evolcore/tool-authorization.md +4 -1
  141. package/kits/docs/evolcore/trigger.md +10 -7
  142. package/kits/docs/identity/ROLE_DETAIL.md +2 -0
  143. package/kits/eck_manifest.json +6 -23
  144. package/kits/eck_manifest.memory.json +26 -1
  145. package/kits/rules/01-overview.md +42 -44
  146. package/kits/rules/02-navigation.md +44 -53
  147. package/kits/rules/03-identity.md +21 -25
  148. package/kits/rules/04-relation.md +23 -33
  149. package/kits/rules/05-venue.md +24 -25
  150. package/kits/schemas/_meta.json +10 -10
  151. package/kits/schemas/agent-config.schema.19.json +10 -6
  152. package/kits/schemas/relation-config.schema.12.json +2 -2
  153. package/kits/schemas/role-config.schema.2.json +5 -5
  154. package/kits/schemas/role-registry.schema.1.json +3 -2
  155. package/kits/skills/ec-service-proxy/SKILL.md +10 -0
  156. package/kits/skills/ec-trigger/SKILL.md +1 -1
  157. package/kits/templates/soul/00-GUIDE.md +20 -42
  158. package/kits/templates/system-fragments/channel.md +2 -2
  159. package/kits/templates/system-fragments/commands.md +1 -1
  160. package/kits/templates/system-fragments/directory-contacts.md +1 -1
  161. package/kits/templates/system-fragments/identity.md +0 -1
  162. package/kits/templates/system-fragments/personal-assistant.md +2 -17
  163. package/kits/templates/system-fragments/reply.md +7 -0
  164. package/kits/templates/system-fragments/session.md +6 -2
  165. package/package.json +18 -13
  166. package/dist/eck/paactive-context.js +0 -45
  167. package/dist/response-system/engines/v1/paactive-flow.js +0 -18
  168. package/kits/eck_manifest.paactive.json +0 -528
  169. package/kits/eck_message_manifest.paactive.json +0 -233
  170. package/kits/templates/message-fragments/paactive/item.md +0 -3
  171. package/kits/templates/system-fragments/paactive/channel.md +0 -25
  172. package/kits/templates/system-fragments/paactive/reply.md +0 -25
  173. package/kits/templates/system-fragments/paactive/session.md +0 -32
@@ -110,6 +110,37 @@ export function configureMacosAutostart(enabled, runtimeRoot) {
110
110
  }
111
111
  const file = plistPath();
112
112
  if (!enabled) {
113
+ try {
114
+ const stat = fs.lstatSync(file);
115
+ if (!stat.isFile() || stat.isSymbolicLink()) {
116
+ return { ok: false, enabled: true, error: `登录自启配置不是普通文件,已保留: ${file}` };
117
+ }
118
+ const read = spawnSync('/usr/bin/plutil', ['-convert', 'json', '-o', '-', file], { encoding: 'utf8', timeout: 15_000 });
119
+ if (read.status !== 0) {
120
+ return { ok: false, enabled: true, error: commandError(read, '无法校验 macOS 登录自启归属,已保留配置') };
121
+ }
122
+ const plist = JSON.parse(read.stdout);
123
+ const args = plist.ProgramArguments;
124
+ if (plist.Label !== MACOS_AUTOSTART_LABEL
125
+ || typeof plist.EnvironmentVariables?.EVOLCORE_HOME !== 'string'
126
+ || path.resolve(plist.EnvironmentVariables.EVOLCORE_HOME) !== path.resolve(runtimeRoot)
127
+ || !Array.isArray(args) || args.length !== 4
128
+ || args[1] !== '--no-warnings=ExperimentalWarning'
129
+ || typeof args[2] !== 'string'
130
+ || path.resolve(args[2]) !== path.join(getPackageRoot(), 'dist', 'cli', 'index.js')
131
+ || args[3] !== 'start') {
132
+ return { ok: true, enabled: false, warning: `同名 LaunchAgent 不属于当前 EvolCore 安装或运行目录,已保留: ${file}` };
133
+ }
134
+ }
135
+ catch (error) {
136
+ if (error?.code === 'ENOENT') {
137
+ if (macosAutostartInstalled()) {
138
+ return { ok: false, enabled: true, error: 'LaunchAgent 正在运行但 plist 缺失,无法核验归属,已保留。' };
139
+ }
140
+ return { ok: true, enabled: false };
141
+ }
142
+ return { ok: false, enabled: true, error: `校验 macOS 登录自启归属失败,已保留配置: ${error instanceof Error ? error.message : String(error)}` };
143
+ }
113
144
  const result = launchctl(['bootout', `${domain}/${MACOS_AUTOSTART_LABEL}`]);
114
145
  if (result.status !== 0 && macosAutostartInstalled()) {
115
146
  return {
@@ -1,16 +1,23 @@
1
+ {"model":"claude-opus-5-5","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":4,"price_output":20,"price_cache_creation":5,"price_cache_read":0.2,"context_window":1000000,"max_input_tokens":900000,"max_output_tokens":131072,"supports_cache":true,"supports_vision":true}
2
+ {"model":"claude-sonnet-5-5","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":2,"price_output":10,"price_cache_creation":2.5,"price_cache_read":0.1,"context_window":1000000,"max_input_tokens":900000,"max_output_tokens":131072,"supports_cache":true,"supports_vision":true}
3
+ {"model":"claude-haiku-5-5","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":0.1,"price_output":0.5,"price_cache_creation":0.125,"price_cache_read":0.01,"context_window":1000000,"max_input_tokens":900000,"max_output_tokens":131072,"supports_cache":true,"supports_vision":true}
4
+ {"model":"claude-fable-5-1","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":10,"price_output":50,"price_cache_creation":12.5,"price_cache_read":1,"context_window":1000000,"max_input_tokens":900000,"max_output_tokens":131072,"supports_cache":true,"supports_vision":true}
1
5
  {"model":"claude-opus-4-8","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,"context_window":1000000,"max_input_tokens":900000,"max_output_tokens":32768,"supports_cache":true,"supports_vision":true}
2
6
  {"model":"claude-opus-4-7","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,"context_window":1000000,"max_input_tokens":900000,"max_output_tokens":32768,"supports_cache":true,"supports_vision":true}
3
7
  {"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,"context_window":1000000,"max_input_tokens":900000,"max_output_tokens":32768,"supports_cache":true,"supports_vision":true}
4
8
  {"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,"context_window":200000,"max_input_tokens":180000,"max_output_tokens":16384,"supports_cache":true,"supports_vision":true}
5
9
  {"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,"context_window":200000,"max_input_tokens":180000,"max_output_tokens":16384,"supports_cache":true,"supports_vision":false}
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}],"context_window":200000,"max_input_tokens":180000,"max_output_tokens":16384}
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}],"context_window":200000,"max_input_tokens":180000,"max_output_tokens":16384}
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}],"context_window":200000,"max_input_tokens":180000,"max_output_tokens":16384}
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}],"context_window":200000,"max_input_tokens":180000,"max_output_tokens":16384}
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}],"context_window":200000,"max_input_tokens":180000,"max_output_tokens":16384}
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,"context_window":200000,"max_input_tokens":180000,"max_output_tokens":16384}
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,"context_window":1000000,"max_input_tokens":950000,"max_output_tokens":8192,"supports_cache":true}
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,"context_window":1000000,"max_input_tokens":950000,"max_output_tokens":8192,"supports_cache":true}
10
+ {"model":"gpt-6.1-sol","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":2,"price_output":10,"price_cache_creation":0,"price_cache_read":0.1,"context_window":1050000,"max_input_tokens":1000000,"max_output_tokens":32768,"supports_cache":true}
11
+ {"model":"gpt-6.1-terra","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":1,"price_output":5,"price_cache_creation":0,"price_cache_read":0.05,"context_window":1050000,"max_input_tokens":1000000,"max_output_tokens":32768,"supports_cache":true}
12
+ {"model":"gpt-6-astra","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":10,"price_output":50,"price_cache_creation":12.5,"price_cache_read":1,"context_window":1050000,"max_input_tokens":1000000,"max_output_tokens":32768,"supports_cache":true}
13
+ {"model":"gpt-5.6-sol","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":4,"price_output":20,"price_cache_creation":5,"price_cache_read":0.4,"context_window":200000,"max_input_tokens":180000,"max_output_tokens":16384,"supports_cache":true}
14
+ {"model":"gpt-5.6-cyber","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":12.5,"price_output":75,"price_cache_creation":15.625,"price_cache_read":1.25,"context_window":200000,"max_input_tokens":180000,"max_output_tokens":16384,"supports_cache":true}
15
+ {"model":"chat-latest","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,"context_window":200000,"max_input_tokens":180000,"max_output_tokens":16384,"supports_cache":true}
16
+ {"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,"context_window":200000,"max_input_tokens":180000,"max_output_tokens":16384,"supports_cache":true}
17
+ {"model":"gpt-rosalind-research","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":5,"price_output":25,"price_cache_creation":0,"price_cache_read":0.5,"context_window":128000,"max_input_tokens":120000,"max_output_tokens":8192,"supports_cache":true}
18
+ {"model":"gpt-rosalind-discovery","effective_from":0,"billing_fn":"per_token_v1","currency":"USD","price_input":5,"price_output":25,"price_cache_creation":0,"price_cache_read":0.5,"context_window":128000,"max_input_tokens":120000,"max_output_tokens":8192,"supports_cache":true}
19
+ {"model":"deepseek-v4-pro","effective_from":0,"billing_fn":"per_token_deepseek_v1","currency":"CNY","price_cache_hit":0.022,"price_cache_miss":0.66,"price_output":1.98,"context_window":1000000,"max_input_tokens":950000,"max_output_tokens":8192,"supports_cache":true,"notes":"off-peak rates, peak 2x"}
20
+ {"model":"deepseek-v4.1-flash","effective_from":0,"billing_fn":"per_token_deepseek_v1","currency":"CNY","price_cache_hit":0.015,"price_cache_miss":0.15,"price_output":0.6,"context_window":1000000,"max_input_tokens":950000,"max_output_tokens":8192,"supports_cache":true,"notes":"off-peak rates, peak 2x"}
14
21
  {"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,"context_window":128000,"max_input_tokens":120000,"max_output_tokens":8192,"supports_cache":true}
15
22
  {"model":"kimi-k2.6","effective_from":0,"billing_fn":"per_token_v1","currency":"CNY","price_input":2,"price_output":8,"price_cache_creation":0,"price_cache_read":0,"context_window":128000,"max_input_tokens":120000,"max_output_tokens":8192}
16
23
  {"model":"kimi-k2.5","effective_from":0,"billing_fn":"per_token_v1","currency":"CNY","price_input":2,"price_output":8,"price_cache_creation":0,"price_cache_read":0,"context_window":128000,"max_input_tokens":120000,"max_output_tokens":8192}
@@ -43,6 +43,15 @@ function approximateSelfStartTime() {
43
43
  const uptimeMs = Math.round(process.uptime() * 1000);
44
44
  return uptimeMs > 0 ? Date.now() - uptimeMs : Date.now();
45
45
  }
46
+ /**
47
+ * 身份校验路径上同一个 PID 会被连着查两三次(`sameProcess()` 在优雅停止前后各查一次,
48
+ * 端口候选还要再查一次),Windows 上每次都是一整个 PowerShell 进程(约 0.5–1s)。
49
+ * 启动时间对同一个 PID 是常量,缓存复用没有语义风险;PID 复用要落到同一个缓存槽里
50
+ * 需要在一个 TTL 内退出并复刻出同一个 PID,实际不可能,且 `startTimeMatches` 本身
51
+ * 有 2s 容差。TTL 取短一些,避免让「进程已换人」的判断比容差更迟钝。
52
+ */
53
+ const START_TIME_CACHE_TTL_MS = 5000;
54
+ const startTimeCache = new Map();
46
55
  /**
47
56
  * 获取进程启动时间(Unix 毫秒)。
48
57
  * 拿不到时返回 null,调用方应保守处理(不杀该 PID)。
@@ -54,11 +63,22 @@ export function getProcessStartTime(pid) {
54
63
  selfStartTime = approximateSelfStartTime();
55
64
  return selfStartTime;
56
65
  }
57
- return readProcessStartTime(pid);
66
+ const cached = startTimeCache.get(pid);
67
+ const now = Date.now();
68
+ if (cached && now - cached.at < START_TIME_CACHE_TTL_MS)
69
+ return cached.startedAt;
70
+ const startedAt = readProcessStartTime(pid);
71
+ // 只缓存成功结果:查不到往往是权限或瞬时失败,缓存成 null 会掩盖后续可查到的情形。
72
+ if (startedAt === null)
73
+ startTimeCache.delete(pid);
74
+ else
75
+ startTimeCache.set(pid, { at: now, startedAt });
76
+ return startedAt;
58
77
  }
59
78
  /** 测试用:清掉自身启动时间缓存。 */
60
79
  export function resetSelfStartTimeCache() {
61
80
  selfStartTime = null;
81
+ startTimeCache.clear();
62
82
  }
63
83
  function readProcessStartTime(pid) {
64
84
  try {
@@ -55,7 +55,13 @@ export class StartupTracer {
55
55
  constructor(source, opts = {}) {
56
56
  this.source = source;
57
57
  this.kind = opts.kind ?? 'startup';
58
- this.traceId = opts.traceId ?? newStartupTraceId();
58
+ let traceId = opts.traceId;
59
+ if (source === 'daemon' && this.kind === 'startup') {
60
+ traceId ??= process.env[STARTUP_TRACE_ID_ENV] || undefined;
61
+ // 启动关联只消费一次,不能让重启监控或其它子进程继承本次编号。
62
+ delete process.env[STARTUP_TRACE_ID_ENV];
63
+ }
64
+ this.traceId = traceId ?? newStartupTraceId();
59
65
  this.processStartMs = opts.processStartMs ?? processStartOfThisProcess();
60
66
  this.cursorStartMs = this.processStartMs;
61
67
  if (opts.firstPhase)
@@ -566,6 +566,7 @@ export function configureWindowsAutostart(enabled, runtimeRoot) {
566
566
  return {
567
567
  ok: false,
568
568
  enabled: false,
569
+ nonFatal: true,
569
570
  error: `已存在同名计划任务 \\${WINDOWS_AUTOSTART_TASK_NAME},但其启动命令不属于 EvolCore;为避免覆盖已停止配置。`,
570
571
  };
571
572
  }
package/ecagent/README.md CHANGED
@@ -60,6 +60,24 @@ pending, interruption terminates all processes in its job. Long-running managed
60
60
  services should use EvolCore's service manager rather than rely on an open Bash
61
61
  tool call. The supervisor fails closed if job assignment is unavailable.
62
62
 
63
+ ## Automatic context compaction
64
+
65
+ `AgentHarness` accepts an optional `autoCompactWindow` token threshold. When set
66
+ to a positive number, the harness checks context usage before each model request,
67
+ including requests between tool batches. It summarizes older history, persists a
68
+ compaction entry, and rebuilds the context without restarting the task or replaying
69
+ tools. The public `compact()` method still requires an idle harness.
70
+
71
+ The threshold is opt-in for standalone callers. EvolCore supplies the same
72
+ window-aware threshold used by its Claude adapter: the smaller of 650,000 tokens
73
+ and the model window minus a reserve of up to 10,000 tokens (5% for smaller
74
+ windows). EvolCore's task-start check and context-overflow recovery remain in place.
75
+
76
+ Automatic summaries inherit the active run's cancellation signal. Context estimates
77
+ ignore usage recorded before the latest compaction; retained recent messages are
78
+ estimated until a new provider response reports usage for the compacted context.
79
+ This is threshold-based summarization, not continuous history pruning.
80
+
63
81
  ## Build from source
64
82
 
65
83
  ```bash
@@ -13,6 +13,7 @@ export declare class AgentHarness<TSkill extends Skill = Skill, TPromptTemplate
13
13
  private thinkingLevel;
14
14
  private systemPrompt;
15
15
  private streamOptions;
16
+ private readonly autoCompactWindow?;
16
17
  private resources;
17
18
  private tools;
18
19
  private activeToolNames;
@@ -63,6 +64,7 @@ export declare class AgentHarness<TSkill extends Skill = Skill, TPromptTemplate
63
64
  tokensBefore: number;
64
65
  details?: unknown;
65
66
  }>;
67
+ private performCompaction;
66
68
  navigateTree(targetId: string, options?: {
67
69
  summarize?: boolean;
68
70
  customInstructions?: string;
@@ -1,6 +1,6 @@
1
1
  import { runAgentLoop } from "../agent-loop.js";
2
2
  import { collectEntriesForBranchSummary, generateBranchSummary } from "./compaction/branch-summarization.js";
3
- import { compact, DEFAULT_COMPACTION_SETTINGS, prepareCompaction } from "./compaction/compaction.js";
3
+ import { compact, DEFAULT_COMPACTION_SETTINGS, estimateContextTokens, prepareCompaction } from "./compaction/compaction.js";
4
4
  import { convertToLlm } from "./messages.js";
5
5
  import { formatPromptTemplateInvocation } from "./prompt-templates.js";
6
6
  import { formatSkillInvocation } from "./skills.js";
@@ -124,6 +124,7 @@ export class AgentHarness {
124
124
  this.models = options.models;
125
125
  this.resources = options.resources ?? {};
126
126
  this.streamOptions = cloneStreamOptions(options.streamOptions);
127
+ this.autoCompactWindow = options.autoCompactWindow;
127
128
  this.systemPrompt = options.systemPrompt;
128
129
  this.validateUniqueNames((options.tools ?? []).map((tool) => tool.name), "Duplicate tool name(s)");
129
130
  for (const tool of options.tools ?? []) {
@@ -325,9 +326,18 @@ export class AgentHarness {
325
326
  model: turnState.model,
326
327
  reasoning: turnState.thinkingLevel === "off" ? undefined : turnState.thinkingLevel,
327
328
  convertToLlm,
328
- transformContext: async (messages) => {
329
- const result = await this.emitHook({ type: "context", messages: [...messages] });
330
- return result?.messages ?? messages;
329
+ transformContext: async (messages, signal) => {
330
+ let currentMessages = messages;
331
+ signal?.throwIfAborted();
332
+ if (this.autoCompactWindow && this.autoCompactWindow > 0
333
+ && estimateContextTokens(messages).tokens >= this.autoCompactWindow) {
334
+ await this.flushPendingSessionWrites();
335
+ await this.performCompaction(undefined, signal);
336
+ signal?.throwIfAborted();
337
+ currentMessages = (await this.session.buildContext()).messages;
338
+ }
339
+ const result = await this.emitHook({ type: "context", messages: [...currentMessages] }, signal);
340
+ return result?.messages ?? currentMessages;
331
341
  },
332
342
  beforeToolCall: async ({ toolCall, args }, signal) => {
333
343
  const result = await this.emitHook({
@@ -614,8 +624,13 @@ export class AgentHarness {
614
624
  async compact(customInstructions) {
615
625
  if (this.phase !== "idle")
616
626
  throw new AgentHarnessError("busy", "compact() requires idle harness");
627
+ return this.performCompaction(customInstructions);
628
+ }
629
+ async performCompaction(customInstructions, signal) {
630
+ const previousPhase = this.phase;
617
631
  this.phase = "compaction";
618
632
  try {
633
+ signal?.throwIfAborted();
619
634
  const model = this.model;
620
635
  if (!model)
621
636
  throw new AgentHarnessError("invalid_state", "No model set for compaction");
@@ -631,16 +646,17 @@ export class AgentHarness {
631
646
  preparation,
632
647
  branchEntries,
633
648
  customInstructions,
634
- signal: new AbortController().signal,
635
- });
649
+ signal: signal ?? new AbortController().signal,
650
+ }, signal);
636
651
  if (hookResult?.cancel)
637
652
  throw new AgentHarnessError("compaction", "Compaction cancelled");
638
653
  const provided = hookResult?.compaction;
639
654
  const compactResult = provided
640
655
  ? { ok: true, value: provided }
641
- : await compact(preparation, this.models, model, customInstructions, undefined, this.thinkingLevel);
656
+ : await compact(preparation, this.models, model, customInstructions, signal, this.thinkingLevel);
642
657
  if (!compactResult.ok)
643
658
  throw compactResult.error;
659
+ signal?.throwIfAborted();
644
660
  const result = compactResult.value;
645
661
  const entryId = await this.session.appendCompaction(result.summary, result.firstKeptEntryId, result.tokensBefore, result.details, provided !== undefined);
646
662
  const entry = await this.session.getEntry(entryId);
@@ -653,7 +669,7 @@ export class AgentHarness {
653
669
  throw normalizeHarnessError(error, "compaction");
654
670
  }
655
671
  finally {
656
- this.phase = "idle";
672
+ this.phase = previousPhase;
657
673
  }
658
674
  }
659
675
  async navigateTree(targetId, options) {
@@ -151,7 +151,7 @@ export async function generateBranchSummary(entries, options) {
151
151
  timestamp: Date.now(),
152
152
  },
153
153
  ];
154
- const response = await models.completeSimple(model, { systemPrompt: SUMMARIZATION_SYSTEM_PROMPT, messages: summarizationMessages }, { signal, maxTokens: 2048 });
154
+ const response = await models.completeSimple(model, { systemPrompt: SUMMARIZATION_SYSTEM_PROMPT, messages: summarizationMessages }, { signal, maxTokens: 2048, metadata: { requestType: "branch_summary" } });
155
155
  if (response.stopReason === "aborted") {
156
156
  return err(new BranchSummaryError("aborted", response.errorMessage || "Branch summary aborted"));
157
157
  }
@@ -87,7 +87,10 @@ export function getLastAssistantUsage(entries) {
87
87
  return undefined;
88
88
  }
89
89
  function getLastAssistantUsageInfo(messages) {
90
+ const summary = messages.find((message) => message.role === "compactionSummary");
90
91
  for (let i = messages.length - 1; i >= 0; i--) {
92
+ if (summary && messages[i].timestamp <= summary.timestamp)
93
+ continue;
91
94
  const usage = getAssistantUsage(messages[i]);
92
95
  if (usage)
93
96
  return { usage, index: i };
@@ -376,8 +379,8 @@ export async function generateSummary(currentMessages, models, model, reserveTok
376
379
  },
377
380
  ];
378
381
  const completionOptions = model.reasoning && thinkingLevel && thinkingLevel !== "off"
379
- ? { maxTokens, signal, reasoning: thinkingLevel }
380
- : { maxTokens, signal };
382
+ ? { maxTokens, signal, reasoning: thinkingLevel, metadata: { requestType: "compaction" } }
383
+ : { maxTokens, signal, metadata: { requestType: "compaction" } };
381
384
  const response = await models.completeSimple(model, { systemPrompt: SUMMARIZATION_SYSTEM_PROMPT, messages: summarizationMessages }, completionOptions);
382
385
  if (response.stopReason === "aborted") {
383
386
  return err(new CompactionError("aborted", response.errorMessage || "Summarization aborted"));
@@ -512,8 +515,8 @@ async function generateTurnPrefixSummary(messages, models, model, reserveTokens,
512
515
  },
513
516
  ];
514
517
  const response = await models.completeSimple(model, { systemPrompt: SUMMARIZATION_SYSTEM_PROMPT, messages: summarizationMessages }, model.reasoning && thinkingLevel && thinkingLevel !== "off"
515
- ? { maxTokens, signal, reasoning: thinkingLevel }
516
- : { maxTokens, signal });
518
+ ? { maxTokens, signal, reasoning: thinkingLevel, metadata: { requestType: "compaction" } }
519
+ : { maxTokens, signal, metadata: { requestType: "compaction" } });
517
520
  if (response.stopReason === "aborted") {
518
521
  return err(new CompactionError("aborted", response.errorMessage || "Turn prefix summarization aborted"));
519
522
  }
@@ -610,6 +610,7 @@ export interface AgentHarnessOptions<TSkill extends Skill = Skill, TPromptTempla
610
610
  }) => string | Promise<string>);
611
611
  /** Curated stream/provider request options. Snapshotted at turn start. */
612
612
  streamOptions?: AgentHarnessStreamOptions;
613
+ autoCompactWindow?: number;
613
614
  model: Model<any>;
614
615
  thinkingLevel?: ThinkingLevel;
615
616
  activeToolNames?: string[];
@@ -57,7 +57,7 @@ AUN keystore seed 由 EvolCore 使用固定应用值管理,不再提供配置
57
57
  - **身份与信任**:每条入站消息携带发送者 AID,经四级 X.509 证书链(Root CA → Registry CA → Issuer CA → Agent)验签。
58
58
  - **agent.md 缓存**:对端名片 `https://<aid>/agent.md` 由 **AUN SDK 自动拉取并缓存**(`AgentMdManager`,带 ETag/TTL,默认 1 天内不重复探测)。缓存落在 **`$EVOLCORE_HOME/AIDs/<aid>/`**,每个 AID 两个文件:`agent.md`(带签名正文)+ `agentmd.json`(元数据:etag/last_modified/checked_at/verify_status)。本端与对端的 agent.md 都缓存于此。
59
59
  - 关系层另存一份**派生**的精简身份 `relations/<peerKey>/peer-identity.json`(type/isAgent/name),由 evolcore 从 agent.md 提取,不是 agent.md 本体。
60
- - **E2EE 加密**:可选端到端加密,回复默认跟随对端消息加密状态(密文回密文,明文回明文);keystore seed 由 EvolCore 固定管理。
60
+ - **E2EE 加密**:可选端到端加密,回复默认跟随对端消息加密状态(密文回密文,明文回明文);主动发起默认明文,只有显式 `--encrypt` 或 `aun.defaultEncrypt: true` 才加密;keystore seed 由 EvolCore 固定管理。
61
61
  - **断线重连**:SDK 内置退避策略自动重连。实时连接状态用 `ec watch aid` 查看(`ec aid` 是身份/证书管理,不显示连接状态)。
62
62
  - **群 ID 格式**:使用 `{base}.{issuer}`,如 `ontology.agentid.cn` 或 `g-12345.agentid.cn`。EvolCore 默认创建 `g-` 加五位数字(10000–99999)的名称,issuer 以群服务返回为准。群命令支持 base 简写;不再支持或转换 `group.{issuer}/{base}`,也不支持 `base@issuer`。`g-` 是名称的一部分,不应剥离,也不能仅凭群 AID 的格式判断主体类型。
63
63
  - **群 @ 处理策略**:`mention_mode=disabled|mention-only` 是群级配置,只决定哪些群消息进入 Agent LLM 上下文,不影响 AUN 协议层投递;被过滤消息仍应本地存档。
@@ -49,7 +49,7 @@ evolcore 收到消息 → 构造一份 **vars**(运行时变量,见下)→
49
49
  渲染时按 `session.sessionType`(缺省 `'main'`)依次查:`sessionManifests` 覆盖 → 内置映射 → `eck_manifest.json`(`resolveSessionManifest`)。bootstrapping 阶段固定用 `eck_manifest.json`。
50
50
  **每个 manifest 文件各自两级合并**(`$KITS/<file>` + `$ECK/<file>`),互不干扰。
51
51
 
52
- `chatMode=paactive` 是主会话的模式专用例外,不是新的 sessionType。active AUN 人类 owner/admin 私聊(含话题)使用独立的 `eck_manifest.paactive.json` 与 `eck_message_manifest.paactive.json`,由 `src/eck/paactive-context.ts` 分别构建 system/message vars;不继承 `sessionManifests.main`,也不注入 proactive 专属门禁变量。Bootstrap 与系统会话仍优先走原 manifest 选择路径。PA 的必要 manifest/片段缺失时报告上下文构建错误,不回退到另一模式提示词。
52
+ `chatMode=paactive` 是私聊文本展示分支,不是新的 `sessionType` 或独立上下文体系。active AUN 人类 Owner 私聊(含话题)继续使用按现有生命周期、sessionType 和 `sessionManifests` 选择的 system/message manifest,并复用基础 vars;`chatMode` 保持 `paactive`。派生变量 `activePush=true` 表示正式回复使用托管发送,供共用模板复用发送说明。Proactive 工具门禁变量仅在 proactive 任务注入。群聊固定 proactive;interactive 和 paactive 仅适用于私聊。
53
53
 
54
54
  ## section 字段
55
55
 
@@ -25,9 +25,11 @@
25
25
  | `ec update [status] [--format json]` | 发起/复用唯一升级任务,或查询当前升级状态 | 立即升级/升级状态 |
26
26
  | `ec restart` | 重启目标 daemon(承载当前托管会话的实例受生命周期保护) | 重启 |
27
27
  | `ec status [--format json]` | 查看运行状态、Agent、队列、渠道连接;JSON 快照 | 状态/查看状态 |
28
- | `ec logs` | 查看日志(`--level` `--module` `--raw` `--no-color`) | 日志/查看日志 |
28
+ | `ec logs` | 查看日志(`--level` `--module` `--no-color`);`--raw` 可在宿主终端或 trusted fullaccess 托管任务中使用 | 日志/查看日志 |
29
29
  | `ec diagnose` | 诊断启动环境 | 诊断/环境诊断 |
30
30
 
31
+ ECWeb 托管重启、端口占用与升级失败处理见 `ecweb-lifecycle.md`。
32
+
31
33
  Windows 上 Codex 托管任务出现 `helper_sandbox_lock_failed`、`SetNamedSecurityInfoW ... 5`、`unelevated ... cannot enforce deny-read` 或 daemon 管道 `EPERM` 时,参见 `codex-windows-sandbox.md`。
32
34
 
33
35
  ## 对外通信 / 网络类(连 AUN,以 AID 为发送者)
@@ -45,7 +47,7 @@ Windows 上 Codex 托管任务出现 `helper_sandbox_lock_failed`、`SetNamedSec
45
47
  | `ec storage` | 文件存储底层调试入口 | storage 调试/旧命令/底层上传下载 | 任意有渠道场景 | `storage.md` |
46
48
  | `ec agent` | EvolAgent 生命周期与主机信息 | 创建/启停/热重载/改配置/查主机信息 | 管理操作按目标与角色鉴权 | `agent.md`;创建流程用 `ec-agent-create` 技能,Bootstrap 参考见 `agent-create.md` |
47
49
  | `ec peer` | 对端身份与本地拉黑 | 查已登记对端、拉黑/解除拉黑 | 拉黑为 Agent 自身行为;添加联系人与审批归 Owner | `peer.md` |
48
- | `ec directory` | Owner 名录查询与本地备注 | 联系人/通讯录/名录/找人的 AID/这个人是谁/内外联系人/拉黑名单/记备注 | 有 Owner 名录授权;`remark set/rm` 仅 Owner 的个人助理 | `directory.md` |
50
+ | `ec directory` | Owner 名录查询、入录申请与本地备注 | 联系人/通讯录/名录/找人的 AID/申请添加联系人/这个人是谁/内外联系人/拉黑名单/记备注 | 查询需 Owner 名录授权;申请通过 `request` 发给本端 Owner | `directory.md` |
49
51
  | `ec rpc` | 底层 AUN RPC(逃生通道) | 直接调协议方法 | 仅宿主终端;托管会话仅可查看帮助 | `rpc.md` |
50
52
  | `ec menu-client` | 远程 Daemon Menu 请求 | 远程诊断/远程 daemon 操作/daemon 日志/监控/原始配置/跨主机 | 运维主机或具备 `ec.menu.request` 权限的托管 Agent | `menu-client.md` |
51
53
 
@@ -82,6 +84,7 @@ Windows 上 Codex 托管任务出现 `helper_sandbox_lock_failed`、`SetNamedSec
82
84
  | `ec task` | 恢复暂停或异常中断的会话任务 | 任务恢复/异常中断/继续任务/resume | `task.md` |
83
85
  | `ec skill` | EC 技能管理(新建/安装/删除/启用/禁用/校验/查路径) | 创建技能/新建 skill/安装技能/装个 skill/删除技能/禁用技能/启用技能/看看有哪些技能/技能为什么没生效 | `ec-capabilities.md` |
84
86
  | `ec pa-workspace` | 在 Owner 的 AUN 私聊中查看和维护 PA 工作区入口导航 | 个人助理工作区/工作区入口调整/产物入口/报告入口/任务入口/隐藏入口/改名入口/排序入口 | `pa-workspace.md` |
87
+ | `ec pa-workspace` | 入口导航文件的位置、格式、schema 与安全改法;含跨 Agent 入口 | 导航格式/入口格式/加个入口/产物给用户看/加个报告入口/入口指向别的助理/file-navigation/导航文件在哪 | `file-navigation.md` |
85
88
 
86
89
  ## 开发者工具(非 agent 会话能力)
87
90