evolcore 0.0.43-test.6 → 0.0.43-test.8

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 (249) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/bin/ecmsg.js +188 -58
  3. package/dist/agent-template/jobs.js +62 -0
  4. package/dist/agent-template/runtime.js +214 -0
  5. package/dist/agent-template/service.js +465 -0
  6. package/dist/agent-template/tool-runner.js +45 -0
  7. package/dist/agent-template/types.js +5 -0
  8. package/dist/agents/baseagent-availability.js +1 -1
  9. package/dist/agents/claude-runner.js +1 -1
  10. package/dist/agents/codex/app-server-client.js +22 -0
  11. package/dist/agents/codex-runner.js +69 -2
  12. package/dist/aun/aid/agentmd.js +56 -1
  13. package/dist/aun/aid/client.js +3 -1
  14. package/dist/aun/menu/client.js +3 -2
  15. package/dist/aun/msg/p2p.js +6 -1
  16. package/dist/channels/aun.js +277 -49
  17. package/dist/cli/agent-command.js +5 -0
  18. package/dist/cli/agent-create.js +7 -3
  19. package/dist/cli/agent-template.js +124 -0
  20. package/dist/cli/aun-commands.js +2 -2
  21. package/dist/cli/ctl-command.js +2 -1
  22. package/dist/cli/daemon-commands.js +11 -66
  23. package/dist/cli/daemon-lifecycle-client.js +61 -0
  24. package/dist/cli/ecmsg-gateway.js +35 -2
  25. package/dist/cli/events-command.js +109 -0
  26. package/dist/cli/index.js +60 -14
  27. package/dist/cli/invoke-command.js +182 -0
  28. package/dist/cli/managed-command-guard.js +6 -1
  29. package/dist/cli/net-check.js +1 -1
  30. package/dist/cli/restart-monitor.js +160 -83
  31. package/dist/cli/services-command.js +137 -0
  32. package/dist/cli/team-workspace-command.js +134 -0
  33. package/dist/cli/thread-command.js +103 -13
  34. package/dist/cli/watch-msg.js +1 -1
  35. package/dist/config/boot-log.js +8 -8
  36. package/dist/config/config-field-policy.js +2 -2
  37. package/dist/config/config-manager.js +0 -7
  38. package/dist/config/invoke-ipc-service.js +118 -0
  39. package/dist/config/schema-migration.js +45 -15
  40. package/dist/config-store.js +2 -1
  41. package/dist/core/agent-ipc-registration.js +25 -4
  42. package/dist/core/agent-reload-coordinator.js +6 -4
  43. package/dist/core/agent-runtime.js +106 -10
  44. package/dist/core/auth/delegation-authorization.js +66 -0
  45. package/dist/core/auth/operation-authorizer.js +2 -0
  46. package/dist/core/auth/operation-catalog.js +29 -0
  47. package/dist/core/baseagent-loader.js +60 -130
  48. package/dist/core/channel-loader.js +10 -1
  49. package/dist/core/channel-runtime.js +20 -12
  50. package/dist/core/command/agent-control.js +12 -2
  51. package/dist/core/command/agent-storage-menu.js +1 -1
  52. package/dist/core/command/agent-template-menu.js +147 -0
  53. package/dist/core/command/chatmode-config.js +2 -36
  54. package/dist/core/command/command-handler.js +80 -17
  55. package/dist/core/command/data-root-resolver.js +32 -23
  56. package/dist/core/command/eventcenter-menu.js +468 -0
  57. package/dist/core/command/menu-catalog.js +15 -0
  58. package/dist/core/command/menu-handler.js +216 -90
  59. package/dist/core/command/menu-protocol.js +71 -13
  60. package/dist/core/command/menu-query-batch.js +194 -0
  61. package/dist/core/command/slash-gate.js +1 -1
  62. package/dist/core/command/slash-handler.js +34 -42
  63. package/dist/core/command/team-workspace-bootstrap.js +350 -0
  64. package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
  65. package/dist/core/command/team-workspace-initializer.js +2 -0
  66. package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
  67. package/dist/core/command/team-workspace-job-store.js +88 -0
  68. package/dist/core/command/team-workspace-management-service.js +2 -0
  69. package/dist/core/command/team-workspace-management-store.js +96 -0
  70. package/dist/core/command/team-workspace-management.js +265 -0
  71. package/dist/core/command/team-workspace-members-menu.js +88 -0
  72. package/dist/core/command/team-workspace-store.js +612 -0
  73. package/dist/core/command/team-workspace-team.js +193 -0
  74. package/dist/core/daemon-control.js +22 -5
  75. package/dist/core/daemon-lifecycle.js +323 -191
  76. package/dist/core/handoff/runtime.js +45 -13
  77. package/dist/core/invoke/executors/index.js +13 -0
  78. package/dist/core/invoke/executors/media.js +283 -0
  79. package/dist/core/invoke/executors/text.js +198 -0
  80. package/dist/core/invoke/invoke-service.js +157 -0
  81. package/dist/core/invoke/style-router.js +48 -0
  82. package/dist/core/invoke/types.js +19 -0
  83. package/dist/core/ipc-registration.js +50 -7
  84. package/dist/core/legacy-rename.js +41 -0
  85. package/dist/core/memory/consolidation.js +7 -5
  86. package/dist/core/message/aun-ipc-sender.js +252 -17
  87. package/dist/core/message/im-renderer.js +116 -85
  88. package/dist/core/message/message-bridge.js +4 -0
  89. package/dist/core/message/message-queue.js +66 -15
  90. package/dist/core/message/message-utils.js +10 -2
  91. package/dist/core/message/peer-mode.js +7 -34
  92. package/dist/core/message/pending-hints.js +29 -5
  93. package/dist/core/message/response-engine.js +194 -61
  94. package/dist/core/message/send-options.js +7 -4
  95. package/dist/core/message/send-routing.js +50 -5
  96. package/dist/core/ownership/owner-resolver.js +7 -0
  97. package/dist/core/pack-auth.js +94 -0
  98. package/dist/core/pack-install.js +194 -0
  99. package/dist/core/permission/ec-command-parser.js +51 -17
  100. package/dist/core/permission/protected-paths.js +12 -2
  101. package/dist/core/permission/shell-environment.js +9 -0
  102. package/dist/core/rate-window.js +48 -0
  103. package/dist/core/relation/peer-identity.js +28 -0
  104. package/dist/core/session/session-file-health.js +243 -0
  105. package/dist/core/session/session-fs-store.js +67 -28
  106. package/dist/core/session/session-idle-monitor.js +59 -19
  107. package/dist/core/session/session-manager.js +13 -4
  108. package/dist/core/task/task-recovery-service.js +13 -2
  109. package/dist/core/thread/command-parser.js +9 -2
  110. package/dist/core/thread/thread-operation.js +21 -2
  111. package/dist/core/thread/thread-route.js +13 -2
  112. package/dist/core/thread/thread-service.js +52 -3
  113. package/dist/directory/owner-directory-admission.js +40 -53
  114. package/dist/directory/owner-directory-cache.js +89 -113
  115. package/dist/directory/owner-directory-query-operation.js +8 -10
  116. package/dist/eck/kit-renderer.js +7 -5
  117. package/dist/eck/message-renderer.js +2 -0
  118. package/dist/ecweb/basic-settings-service.js +1 -1
  119. package/dist/ecweb/message-context-service.js +0 -4
  120. package/dist/ecweb/runtime/lifecycle.js +6 -2
  121. package/dist/ecweb/runtime/supervisor.js +19 -4
  122. package/dist/event-center/admission-materializer.js +124 -0
  123. package/dist/event-center/bus-gate.js +154 -0
  124. package/dist/event-center/bus-host.js +307 -0
  125. package/dist/event-center/bus-resolver.js +120 -0
  126. package/dist/event-center/center-config.js +127 -0
  127. package/dist/event-center/daemon.js +44 -0
  128. package/dist/event-center/directory-source.js +55 -0
  129. package/dist/event-center/dispatcher.js +157 -0
  130. package/dist/event-center/event-log.js +110 -0
  131. package/dist/event-center/index-generator.js +73 -0
  132. package/dist/event-center/ipc-operation.js +423 -0
  133. package/dist/event-center/ledger.js +52 -0
  134. package/dist/event-center/pack-loader.js +207 -0
  135. package/dist/event-center/pack-manager.js +85 -0
  136. package/dist/event-center/registry.js +463 -0
  137. package/dist/event-center/runtime.js +837 -0
  138. package/dist/event-center/script-runner.js +356 -0
  139. package/dist/event-center/types.js +51 -0
  140. package/dist/event-center/validation.js +435 -0
  141. package/dist/index.js +424 -135
  142. package/dist/ipc.js +106 -12
  143. package/dist/paths.js +20 -0
  144. package/dist/product.js +14 -0
  145. package/dist/proxy/manager.js +5 -1
  146. package/dist/proxy/service-supervisor.js +13 -4
  147. package/dist/response-system/engines/v1/index.js +0 -1
  148. package/dist/response-system/engines/v1/proactive-flow.js +4 -2
  149. package/dist/response-system/modes/single-session/index.js +1 -1
  150. package/dist/services/dispatcher.js +100 -0
  151. package/dist/services/idempotency.js +90 -0
  152. package/dist/services/identity.js +52 -0
  153. package/dist/services/index-generator.js +70 -0
  154. package/dist/services/index.js +449 -0
  155. package/dist/services/ipc-operation.js +550 -0
  156. package/dist/services/ledger.js +52 -0
  157. package/dist/services/message-log.js +112 -0
  158. package/dist/services/pack-manager.js +215 -0
  159. package/dist/services/reply.js +55 -0
  160. package/dist/services/router.js +98 -0
  161. package/dist/services/script-runner.js +422 -0
  162. package/dist/services/service-payload.js +70 -0
  163. package/dist/services/types.js +18 -0
  164. package/dist/services/validation.js +297 -0
  165. package/dist/trigger/application-service.js +18 -0
  166. package/dist/trigger/event-source.js +1 -1
  167. package/dist/trigger/ipc-service.js +3 -1
  168. package/dist/trigger/scheduler.js +38 -0
  169. package/dist/trigger/script-sandbox.js +170 -24
  170. package/dist/utils/cross-platform.js +24 -10
  171. package/dist/utils/evolcore-version.js +69 -27
  172. package/dist/utils/instance-registry.js +19 -13
  173. package/dist/utils/npm-ops.js +2 -1
  174. package/dist/utils/package-version-info.js +6 -3
  175. package/dist/utils/process-introspect.js +45 -9
  176. package/dist/utils/startup-trace.js +74 -37
  177. package/dist/utils/windows-shell-trust.js +80 -6
  178. package/kits/docs/INDEX.md +2 -2
  179. package/kits/docs/aun/ABILITY_CALLING.md +9 -15
  180. package/kits/docs/context-assembly.md +1 -1
  181. package/kits/docs/evolcore/INDEX.md +3 -1
  182. package/kits/docs/evolcore/ability.md +4 -0
  183. package/kits/docs/evolcore/agent.md +22 -1
  184. package/kits/docs/evolcore/aid.md +1 -1
  185. package/kits/docs/evolcore/event-center.md +227 -0
  186. package/kits/docs/evolcore/file-navigation.md +10 -264
  187. package/kits/docs/evolcore/fs.md +5 -3
  188. package/kits/docs/evolcore/group.md +1 -1
  189. package/kits/docs/evolcore/memory-architecture.md +2 -0
  190. package/kits/docs/evolcore/menu-protocol.md +28 -1
  191. package/kits/docs/evolcore/msg.md +21 -9
  192. package/kits/docs/evolcore/provider.md +3 -1
  193. package/kits/docs/evolcore/response.md +5 -5
  194. package/kits/docs/evolcore/services.md +294 -0
  195. package/kits/docs/evolcore/task.md +2 -0
  196. package/kits/docs/evolcore/team-workspace.md +41 -0
  197. package/kits/docs/evolcore/thread-chain.md +15 -3
  198. package/kits/eck_manifest.json +26 -0
  199. package/kits/rules/02-navigation.md +10 -1
  200. package/kits/rules/06-channel.md +1 -0
  201. package/kits/schemas/_meta.json +17 -6
  202. package/kits/schemas/agent-config.schema.19.json +5 -7
  203. package/kits/schemas/agent-config.schema.20.json +936 -0
  204. package/kits/schemas/relation-config.schema.12.json +2 -3
  205. package/kits/schemas/role-config.schema.2.json +4 -4
  206. package/kits/skills/.switches.json +1 -5
  207. package/kits/skills/ability/SKILL.md +56 -0
  208. package/kits/skills/ability/references/calling.md +56 -0
  209. package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
  210. package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
  211. package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
  212. package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
  213. package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
  214. package/kits/skills/ec-agent-create/SKILL.md +0 -1
  215. package/kits/skills/ec-group/SKILL.md +5 -8
  216. package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
  217. package/kits/skills/ec-service-proxy/SKILL.md +34 -5
  218. package/kits/skills/ec-trigger/SKILL.md +4 -4
  219. package/kits/skills/personal-assistant/SKILL.md +6 -6
  220. package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
  221. package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
  222. package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
  223. package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
  224. package/kits/skills/thread-ops/SKILL.md +10 -10
  225. package/kits/templates/message-fragments/item.md +1 -1
  226. package/kits/templates/system-fragments/channel.md +3 -3
  227. package/kits/templates/system-fragments/commands.md +5 -3
  228. package/kits/templates/system-fragments/reply.md +1 -5
  229. package/kits/templates/system-fragments/thread.md +13 -10
  230. package/package.json +5 -6
  231. package/scripts/agent-template/index.mjs +40 -0
  232. package/scripts/agent-template/inspect.mjs +240 -0
  233. package/scripts/agent-template/overlay.mjs +71 -0
  234. package/scripts/agent-template/pack.mjs +169 -0
  235. package/scripts/agent-template/shared/common.mjs +235 -0
  236. package/scripts/agent-template/shared/evolcore.mjs +75 -0
  237. package/scripts/agent-template/shared/plan.mjs +129 -0
  238. package/scripts/agent-template/shared/team-schema.json +70 -0
  239. package/scripts/agent-template/shared/template-contract.mjs +154 -0
  240. package/scripts/agent-template/shared/template-package.mjs +265 -0
  241. package/scripts/agent-template/shared/template-runtime.mjs +80 -0
  242. package/scripts/agent-template/shared/template.mjs +142 -0
  243. package/dist/cli/pa-workspace-command.js +0 -225
  244. package/dist/core/command/pa-workspace-store.js +0 -468
  245. package/dist/core/relation/pa-team.js +0 -132
  246. package/kits/docs/evolcore/pa-workspace.md +0 -51
  247. package/kits/skills/aid-ability/SKILL.md +0 -244
  248. package/kits/skills/ec-ability/SKILL.md +0 -67
  249. package/kits/skills/ec-ability/references/workflows.md +0 -15
@@ -31,6 +31,7 @@ import { CODEX_HOOK_TOKEN_ENV, MAIN_CLI_BIN } from '../product.js';
31
31
  import { ensureSessionRuntimeDir, getManagedTaskTempDir } from '../cli/task-context.js';
32
32
  import { buildTranscriptTurns } from '../core/session/session-transcript.js';
33
33
  import { CodexSessionFileAdapter } from '../core/session/adapters/codex-session-file-adapter.js';
34
+ import { repairCodexSessionProvider } from '../core/session/session-file-health.js';
34
35
  import { execFileSync } from 'child_process';
35
36
  import { probeCli, probeCliSync, CODEX_CLI_PROBE_TIMEOUT_MS, CODEX_CLI_PROBE_RETRY_TIMEOUT_MS } from '../utils/cross-platform.js';
36
37
  import { createHash, randomBytes } from 'crypto';
@@ -767,6 +768,65 @@ export class CodexRunner {
767
768
  }
768
769
  return existing.client;
769
770
  }
771
+ /** Called under the existing thread lock, before resume or input submission. */
772
+ async prepareSessionProvider(client, threadId, signal) {
773
+ signal?.throwIfAborted();
774
+ const provider = client.getModelProvider?.();
775
+ if (!provider || !/^evolcore_registry_[a-f0-9]{20}$/.test(provider))
776
+ return;
777
+ const sessionFile = this.findCodexSessionFile(threadId);
778
+ if (!sessionFile)
779
+ return; // Preserve the existing missing-rollout recovery behavior.
780
+ const repaired = await repairCodexSessionProvider({
781
+ codexHome: this.codexHomeDir(), threadId, sessionFile, provider,
782
+ releaseThread: async () => {
783
+ signal?.throwIfAborted();
784
+ if ([...this.activeSubagentTurns.values()].some(turn => turn.parentThreadId === threadId)) {
785
+ throw new Error('Codex Provider repair requires all descendant turns to finish');
786
+ }
787
+ const clients = new Set([
788
+ client, this.appServerClient, this.fullAccessAppServerClient,
789
+ this.threadSubscriptions.get(threadId)?.client, ...this.retiredProviderClients,
790
+ ]);
791
+ for (const owner of clients) {
792
+ if (!owner || owner !== client && owner.isRunning?.() === false)
793
+ continue;
794
+ if (!(await owner.threadLoadedList()).data.includes(threadId))
795
+ continue;
796
+ const thread = (await owner.threadRead(threadId, false)).thread;
797
+ if (!['idle', 'systemError'].includes(thread?.status?.type ?? '')) {
798
+ throw new Error('Codex Provider repair requires an idle thread');
799
+ }
800
+ try {
801
+ await owner.threadUnsubscribeAndWait(threadId, CODEX_THREAD_HANDOFF_TIMEOUT_MS);
802
+ }
803
+ catch (error) {
804
+ if (error.code !== 'CODEX_THREAD_CLOSE_TIMEOUT')
805
+ throw error;
806
+ }
807
+ if ((await owner.threadLoadedList()).data.includes(threadId)) {
808
+ // Codex can keep an unsubscribed writer alive. Its per-thread archive
809
+ // tears down that runtime synchronously; unarchive preserves the UUID.
810
+ await this.archiveThreadForHandoff(owner, owner, threadId);
811
+ }
812
+ if ((await owner.threadLoadedList()).data.includes(threadId)) {
813
+ throw new Error('Codex Provider repair could not release the thread writer');
814
+ }
815
+ }
816
+ signal?.throwIfAborted();
817
+ this.threadSubscriptions.delete(threadId);
818
+ },
819
+ });
820
+ if (repaired)
821
+ this.threadProjectPaths.delete(threadId);
822
+ }
823
+ assertResumedProvider(client, response, threadId) {
824
+ const provider = client.getModelProvider?.();
825
+ if (provider && /^evolcore_registry_[a-f0-9]{20}$/.test(provider)
826
+ && (response.thread?.id !== threadId || response.thread?.modelProvider !== provider)) {
827
+ throw new Error('Codex resume did not preserve the bound thread and current Provider');
828
+ }
829
+ }
770
830
  async archiveThreadForHandoff(sourceClient, targetClient, threadId) {
771
831
  const existing = this.threadSubscriptions.get(threadId);
772
832
  if (existing && existing.client !== sourceClient) {
@@ -2294,6 +2354,7 @@ export class CodexRunner {
2294
2354
  let previousAppServer;
2295
2355
  const openThread = async () => {
2296
2356
  if (agentSessionId) {
2357
+ await this.prepareSessionProvider(appServer, agentSessionId, operationController?.signal);
2297
2358
  // A thread may have been loaded by the other permission-mode client.
2298
2359
  // Release that one thread before asking this client to resume it.
2299
2360
  previousAppServer = await this.prepareThreadSubscription(appServer, agentSessionId);
@@ -2398,6 +2459,8 @@ export class CodexRunner {
2398
2459
  threadOptions = buildThreadOptions(true);
2399
2460
  threadResponse = await openThread();
2400
2461
  }
2462
+ if (agentSessionId)
2463
+ this.assertResumedProvider(appServer, threadResponse, agentSessionId);
2401
2464
  let threadId = threadResponse.thread?.id || agentSessionId;
2402
2465
  if (!threadId)
2403
2466
  throw new Error('Codex app-server did not return a thread id');
@@ -3001,8 +3064,9 @@ export class CodexRunner {
3001
3064
  let compactAppServer;
3002
3065
  try {
3003
3066
  const compactMode = normalizeExecutionPermissionMode(modelOverride?.permissionMode ?? this.chatModes.get(_sessionId) ?? this.currentMode);
3004
- const appServer = this.getAppServerClient(compactMode === 'fullaccess');
3067
+ const appServer = this.getAppServerClient(compactMode === 'fullaccess', modelOverride?.provider);
3005
3068
  compactAppServer = appServer;
3069
+ await this.prepareSessionProvider(appServer, agentSessionId);
3006
3070
  await this.prepareThreadSubscription(appServer, agentSessionId);
3007
3071
  this.onCompactStart?.(_sessionId);
3008
3072
  try {
@@ -3028,7 +3092,7 @@ export class CodexRunner {
3028
3092
  const compactSessionToken = this.ensureThreadCredential(agentSessionId);
3029
3093
  if (!compactSessionToken)
3030
3094
  throw new Error('Codex thread session credential is unavailable');
3031
- await appServer.threadResume(agentSessionId, _projectPath, {
3095
+ const resumed = await appServer.threadResume(agentSessionId, _projectPath, {
3032
3096
  model: compactModel,
3033
3097
  effort: compactEffort,
3034
3098
  approvalPolicy: compactPolicy,
@@ -3036,6 +3100,7 @@ export class CodexRunner {
3036
3100
  ...(executionSandbox.sandbox ? { sandbox: executionSandbox.sandbox } : {}),
3037
3101
  config: this.sanitizeThreadEnvironmentConfig(this.mergeThreadConfig(executionSandbox.permissionProfileConfig, capabilityConfig, externalToolConfig, this.buildEvolcoreShellEnvironmentConfig(_sessionId, compactSessionToken), this.buildLifecycleLockdownConfig(compactMode)), compactMode),
3038
3102
  });
3103
+ this.assertResumedProvider(appServer, resumed, agentSessionId);
3039
3104
  this.markThreadSubscribed(appServer, agentSessionId);
3040
3105
  this.threadProjectPaths.set(agentSessionId, path.resolve(_projectPath));
3041
3106
  this.bindExternalToolBoundary(agentSessionId, externalToolConfig);
@@ -4961,6 +5026,7 @@ export class CodexRunner {
4961
5026
  if (numTurns < 1)
4962
5027
  return true;
4963
5028
  const appServer = this.getAppServerClientForThread(agentSessionId);
5029
+ await this.prepareSessionProvider(appServer, agentSessionId);
4964
5030
  const previousAppServer = await this.prepareThreadSubscription(appServer, agentSessionId);
4965
5031
  let resumed = false;
4966
5032
  try {
@@ -4977,6 +5043,7 @@ export class CodexRunner {
4977
5043
  throw error;
4978
5044
  }
4979
5045
  }
5046
+ this.assertResumedProvider(appServer, resumeResponse, agentSessionId);
4980
5047
  this.markThreadSubscribed(appServer, agentSessionId);
4981
5048
  this.threadProjectPaths.set(agentSessionId, path.resolve(projectPath));
4982
5049
  resumed = true;
@@ -496,6 +496,59 @@ export function stripAgentMdSignature(content) {
496
496
  function escapeRegExp(value) {
497
497
  return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
498
498
  }
499
+ /**
500
+ * 统计一个被折行的 YAML 标量值在后续行里占用的续行数。
501
+ *
502
+ * `yaml` 的 stringify 默认按 80 列折行,历史名片里会留下
503
+ * `avatar: "https://…-2d\` + 换行 + 缩进续行 + `"` 这种写法。
504
+ * 替换字段时只改第一行、把续行留下,会让整个 frontmatter 无法解析,
505
+ * 所以这里按引号状态把续行一并算出来。
506
+ *
507
+ * 只处理以引号开头的值:未加引号的普通标量也可能跨行,但那种写法
508
+ * 目前只出现在手写名片里,按单行处理至少会在校验阶段明确报错,
509
+ * 不会静默吞掉后面的成块映射(如 ownership.statement)。
510
+ */
511
+ function countScalarContinuationLines(valueText, followingLines) {
512
+ const head = valueText.trimStart();
513
+ const quote = head[0];
514
+ if (quote !== '"' && quote !== "'")
515
+ return 0;
516
+ let open = true;
517
+ let escaped = false;
518
+ const scan = (text) => {
519
+ for (let index = 0; index < text.length; index++) {
520
+ const char = text[index];
521
+ if (quote === '"') {
522
+ if (escaped)
523
+ escaped = false;
524
+ else if (char === '\\')
525
+ escaped = true;
526
+ else if (char === '"') {
527
+ open = false;
528
+ return;
529
+ }
530
+ }
531
+ else if (char === "'") {
532
+ // 单引号串里 `''` 表示一个字面量单引号
533
+ if (text[index + 1] === "'")
534
+ index++;
535
+ else {
536
+ open = false;
537
+ return;
538
+ }
539
+ }
540
+ }
541
+ // 行尾的 `\` 转义的是换行本身,续行仍然在引号内
542
+ escaped = false;
543
+ };
544
+ scan(head.slice(1));
545
+ let continuation = 0;
546
+ while (open && continuation < followingLines.length) {
547
+ scan(followingLines[continuation] ?? '');
548
+ continuation++;
549
+ }
550
+ return continuation;
551
+ }
499
552
  function updateAgentMdFrontmatterField(content, key, value, insertAfterKey) {
500
553
  const original = content;
501
554
  const payload = stripAgentMdSignature(content);
@@ -514,7 +567,9 @@ function updateAgentMdFrontmatterField(content, key, value, insertAfterKey) {
514
567
  const fieldIndex = fmLines.findIndex(line => fieldPattern.test(lineValue(line)));
515
568
  if (fieldIndex >= 0) {
516
569
  const existingLine = fmLines[fieldIndex] ?? '';
517
- fmLines[fieldIndex] = `${key}: ${yamlDoubleQuote(value)}${lineEnding(existingLine, defaultEol)}`;
570
+ const existingText = lineValue(existingLine);
571
+ const continuation = countScalarContinuationLines(existingText.slice(existingText.indexOf(':') + 1), fmLines.slice(fieldIndex + 1).map(lineValue));
572
+ fmLines.splice(fieldIndex, 1 + continuation, `${key}: ${yamlDoubleQuote(value)}${lineEnding(existingLine, defaultEol)}`);
518
573
  }
519
574
  else {
520
575
  const anchorPattern = insertAfterKey ? new RegExp(`^${escapeRegExp(insertAfterKey)}\\s*:`) : null;
@@ -14,6 +14,8 @@ export function suppressSdkLogs() {
14
14
  const _origStderrWrite = process.stderr.write.bind(process.stderr);
15
15
  const SDK_LOG_RE = /^\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+\]\[(?:DEBUG|INFO|WARN|ERROR)\]/;
16
16
  const KEYSTORE_WARN_RE = /seed migration failed; continuing with legacy \.seed/;
17
+ // Node 自带的实验特性警告(SDK 的 SQLite store 触发),与命令结果无关。
18
+ const NODE_SQLITE_WARN_RE = /ExperimentalWarning: SQLite is an experimental feature|Use `node --trace-warnings \.\.\.` to show where the warning was created/;
17
19
  console.log = (...args) => { if (typeof args[0] === 'string' && SDK_LOG_RE.test(args[0]))
18
20
  return; _origLog(...args); };
19
21
  console.info = (...args) => { if (typeof args[0] === 'string' && SDK_LOG_RE.test(args[0]))
@@ -26,7 +28,7 @@ export function suppressSdkLogs() {
26
28
  process.stderr.write = function (chunk, encoding, callback) {
27
29
  const str = String(chunk);
28
30
  // Filter out keystore migration warnings and other SDK logs
29
- if (SDK_LOG_RE.test(str) || KEYSTORE_WARN_RE.test(str)) {
31
+ if (SDK_LOG_RE.test(str) || KEYSTORE_WARN_RE.test(str) || NODE_SQLITE_WARN_RE.test(str)) {
30
32
  if (typeof encoding === 'function') {
31
33
  encoding(); // callback is in encoding position
32
34
  }
@@ -45,7 +45,7 @@ export class ManagedMenuClient {
45
45
  const key = this.key(fromAid, event.requestId);
46
46
  const entry = this.eventHandlers.get(key);
47
47
  entry?.handler(event);
48
- if (event.event === 'upgrade.result' && entry) {
48
+ if ((event.event === 'upgrade.result' || event.event === 'template.result') && entry) {
49
49
  clearTimeout(entry.timer);
50
50
  this.eventHandlers.delete(key);
51
51
  }
@@ -106,7 +106,8 @@ export class ManagedMenuClient {
106
106
  error: { code: 'NOT_ALLOWED', message: 'Remote query was denied; authorization denial cached for up to 30 minutes or until reconnect.' },
107
107
  };
108
108
  }
109
- if (options.onEvent && request.type === 'menu.action' && request.action === 'upgrade' && request.args?.mode === 'update') {
109
+ if (options.onEvent && request.type === 'menu.action' && (request.action === 'upgrade' && request.args?.mode === 'update'
110
+ || (request.name === 'agent' || request.cmd === '/agent') && ['build', 'push', 'pull', 'deploy'].includes(String(request.action)))) {
110
111
  const existing = this.eventHandlers.get(key);
111
112
  if (existing)
112
113
  clearTimeout(existing.timer);
@@ -203,7 +203,12 @@ async function daemonMsgSendResult(args, payload, runtimeContext, daemonResult)
203
203
  request_diagnostics: daemonResult.request_diagnostics,
204
204
  transport_error: daemonResult.transport_error,
205
205
  };
206
- if (sent.message_id && !daemonResult.handoff_id && !daemonResult.log_written) {
206
+ // 跨话题自派(`--to <本端AID>`)不写出站日志:chatDir 会算成「我↔我」目录,
207
+ // daemon 侧 `sendDaemonMsg` 同样跳过;这里是对「daemon 未写日志」的兜底,
208
+ // 不跳过就会在 CLI 侧把那个目录补造出来。
209
+ const selfAddressed = String(args.to ?? '').replace(/^@/, '').toLowerCase()
210
+ === String(args.from ?? '').replace(/^@/, '').toLowerCase();
211
+ if (!selfAddressed && sent.message_id && !daemonResult.handoff_id && !daemonResult.log_written) {
207
212
  await appendMsgSendOutboundLog(args, sent, {
208
213
  payload,
209
214
  runtimeContext,