evolcore 0.0.43-test.4 → 0.0.43-test.6

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 (186) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/bin/ecmsg.js +437 -91
  3. package/dist/agents/baseagent-availability.js +19 -4
  4. package/dist/agents/baseagent.js +2 -2
  5. package/dist/agents/claude-runner.js +19 -4
  6. package/dist/agents/codex/app-server-client.js +14 -3
  7. package/dist/agents/codex-runner.js +18 -23
  8. package/dist/aun/aid/agentmd.js +25 -0
  9. package/dist/aun/aid/control-aid.js +15 -0
  10. package/dist/aun/aid/identity.js +8 -0
  11. package/dist/aun/aid/ownership-operation.js +12 -3
  12. package/dist/aun/group/invite-service.js +3 -2
  13. package/dist/aun/service-proxy.js +18 -6
  14. package/dist/channels/aun.js +99 -23
  15. package/dist/channels/daemon.js +2 -2
  16. package/dist/cli/agent-create.js +19 -7
  17. package/dist/cli/aid-bind-command.js +3 -0
  18. package/dist/cli/aun-commands.js +19 -4
  19. package/dist/cli/code-stats.js +451 -213
  20. package/dist/cli/ctl-command.js +1 -3
  21. package/dist/cli/daemon-commands.js +42 -4
  22. package/dist/cli/directory.js +3 -1
  23. package/dist/cli/ecmsg-gateway.js +206 -0
  24. package/dist/cli/index.js +6 -0
  25. package/dist/cli/init.js +120 -13
  26. package/dist/cli/provider-command.js +82 -5
  27. package/dist/cli/restart-monitor.js +35 -24
  28. package/dist/cli/stats.js +8 -1
  29. package/dist/cli/task-context.js +41 -1
  30. package/dist/cli/watch-logs.js +6 -4
  31. package/dist/config/boot-log.js +16 -3
  32. package/dist/config/builtin-roles.js +2 -2
  33. package/dist/config/config-manager.js +5 -14
  34. package/dist/config/daemon-services.js +1 -0
  35. package/dist/config/peer-role-resolver.js +6 -6
  36. package/dist/config/provider-identity-migration.js +277 -0
  37. package/dist/config/provider-identity.js +37 -0
  38. package/dist/config/provider-ipc-service.js +40 -3
  39. package/dist/config/provider-local-sync.js +155 -0
  40. package/dist/config/providers-config.js +45 -4
  41. package/dist/config/providers-management.js +242 -76
  42. package/dist/config/providers.js +4 -1
  43. package/dist/config/role-service.js +8 -8
  44. package/dist/config/role-store.js +22 -22
  45. package/dist/config/schema-migration.js +143 -86
  46. package/dist/config/snapshot.js +70 -41
  47. package/dist/core/agent-runtime.js +48 -9
  48. package/dist/core/auth/auth-gateway.js +5 -3
  49. package/dist/core/auth/delegation-diagnostics.js +6 -2
  50. package/dist/core/auth/operation-authorizer.js +3 -1
  51. package/dist/core/auth/operation-catalog.js +6 -4
  52. package/dist/core/baseagent-loader.js +114 -11
  53. package/dist/core/channel-loader.js +36 -13
  54. package/dist/core/channel-runtime.js +112 -42
  55. package/dist/core/command/cli-intent-parser.js +2 -1
  56. package/dist/core/command/command-handler.js +16 -11
  57. package/dist/core/command/menu-handler.js +8 -3
  58. package/dist/core/command/menu-protocol.js +80 -7
  59. package/dist/core/command/provider-menu.js +4 -2
  60. package/dist/core/command/role-menu.js +29 -17
  61. package/dist/core/command/slash-handler.js +52 -16
  62. package/dist/core/daemon-control.js +42 -15
  63. package/dist/core/daemon-lifecycle.js +411 -67
  64. package/dist/core/handoff/dispatcher.js +9 -3
  65. package/dist/core/handoff/runtime.js +139 -45
  66. package/dist/core/handoff/store.js +190 -2
  67. package/dist/core/handoff/types.js +5 -0
  68. package/dist/core/initialization/service.js +7 -6
  69. package/dist/core/ipc-registration.js +5 -4
  70. package/dist/core/lifecycle-notice.js +10 -4
  71. package/dist/core/message/aun-ipc-sender.js +83 -5
  72. package/dist/core/message/message-admission.js +2 -0
  73. package/dist/core/message/message-bridge.js +53 -4
  74. package/dist/core/message/message-queue.js +46 -4
  75. package/dist/core/message/pending-hints.js +4 -10
  76. package/dist/core/message/response-engine.js +33 -25
  77. package/dist/core/message/send-options.js +40 -0
  78. package/dist/core/message/send-routing.js +320 -0
  79. package/dist/core/ownership/owner-resolver.js +112 -8
  80. package/dist/core/permission/ec-command-parser.js +159 -16
  81. package/dist/core/permission/readonly-shell-query.js +66 -7
  82. package/dist/core/permission/tool-error-code.js +13 -1
  83. package/dist/core/permission/tool-policy.js +74 -20
  84. package/dist/core/relation/same-owner-proof.js +131 -0
  85. package/dist/core/session/adapters/claude-session-file-adapter.js +24 -0
  86. package/dist/core/session/adapters/codex-session-file-adapter.js +80 -0
  87. package/dist/core/session/adapters/ecagent-session-file-adapter.js +22 -0
  88. package/dist/core/session/adapters/gemini-session-file-adapter.js +39 -0
  89. package/dist/core/session/session-fs-store.js +164 -3
  90. package/dist/core/session/session-idle-monitor.js +103 -17
  91. package/dist/core/session/session-manager.js +105 -18
  92. package/dist/core/thread/thread-route.js +5 -2
  93. package/dist/directory/owner-directory-admission.js +26 -1
  94. package/dist/directory/owner-directory-cache.js +739 -109
  95. package/dist/directory/owner-directory-markdown.js +146 -36
  96. package/dist/directory/owner-directory-query-operation.js +6 -3
  97. package/dist/directory/owner-directory-scope.js +12 -0
  98. package/dist/directory/owner-directory-search.js +5 -1
  99. package/dist/directory/owner-directory-store.js +28 -0
  100. package/dist/ecweb/basic-settings-service.js +15 -1
  101. package/dist/ecweb/message-context-service.js +2 -2
  102. package/dist/ecweb/providers-service.js +3 -1
  103. package/dist/ecweb/runtime/lifecycle.js +26 -15
  104. package/dist/ecweb/runtime/supervisor.js +120 -51
  105. package/dist/index.js +551 -250
  106. package/dist/paths.js +2 -1
  107. package/dist/proxy/manager.js +40 -17
  108. package/dist/proxy/service-supervisor.js +67 -33
  109. package/dist/response-system/engines/v1/proactive-flow.js +4 -0
  110. package/dist/trigger/application-service.js +4 -1
  111. package/dist/trigger/audit.js +19 -4
  112. package/dist/trigger/authorization.js +14 -5
  113. package/dist/trigger/event-source.js +4 -0
  114. package/dist/trigger/feedback.js +26 -2
  115. package/dist/trigger/history.js +176 -7
  116. package/dist/trigger/manager.js +1 -3
  117. package/dist/trigger/scheduler.js +81 -8
  118. package/dist/trigger/system-definitions.js +2 -2
  119. package/dist/trigger/validation.js +4 -0
  120. package/dist/utils/autostart.js +2 -2
  121. package/dist/utils/cross-platform.js +188 -12
  122. package/dist/utils/host-info.js +11 -8
  123. package/dist/utils/npm-ops.js +48 -0
  124. package/dist/utils/process-introspect.js +64 -1
  125. package/dist/utils/public-suffix.js +5811 -0
  126. package/dist/utils/startup-trace.js +160 -19
  127. package/dist/utils/windows-autostart.js +41 -7
  128. package/ecagent/dist/harness/env/nodejs.js +46 -2
  129. package/kits/docs/aun/ABILITY_CALLING.md +6 -6
  130. package/kits/docs/channels/aun.md +1 -1
  131. package/kits/docs/channels/feishu.md +2 -2
  132. package/kits/docs/context-assembly.md +20 -4
  133. package/kits/docs/evolcore/INDEX.md +5 -3
  134. package/kits/docs/evolcore/agent.md +2 -2
  135. package/kits/docs/evolcore/aid.md +8 -2
  136. package/kits/docs/evolcore/ctl.md +15 -5
  137. package/kits/docs/evolcore/directory.md +48 -15
  138. package/kits/docs/evolcore/group.md +8 -8
  139. package/kits/docs/evolcore/memory-consolidation.md +1 -1
  140. package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
  141. package/kits/docs/evolcore/menu-protocol.md +32 -3
  142. package/kits/docs/evolcore/msg.md +38 -30
  143. package/kits/docs/evolcore/provider.md +57 -5
  144. package/kits/docs/evolcore/response.md +2 -2
  145. package/kits/docs/evolcore/thread-chain.md +11 -13
  146. package/kits/docs/evolcore/tool-authorization.md +17 -0
  147. package/kits/docs/evolcore/trigger.md +2 -2
  148. package/kits/docs/identity/ROLE_DETAIL.md +1 -1
  149. package/kits/docs/prompt-loading-architecture.md +30 -20
  150. package/kits/eck_manifest.auxiliary.json +5 -5
  151. package/kits/eck_manifest.json +44 -32
  152. package/kits/eck_manifest.memory.json +18 -18
  153. package/kits/eck_message_manifest.json +3 -3
  154. package/kits/rules/01-overview.md +1 -1
  155. package/kits/rules/06-channel.md +7 -8
  156. package/kits/schemas/_meta.json +7 -1
  157. package/kits/schemas/daemon.schema.1.json +5 -0
  158. package/kits/schemas/daemon.schema.2.json +5 -0
  159. package/kits/schemas/daemon.schema.3.json +2 -1
  160. package/kits/schemas/daemon.schema.4.json +2 -1
  161. package/kits/schemas/daemon.schema.5.json +2 -1
  162. package/kits/schemas/daemon.schema.6.json +1 -1
  163. package/kits/schemas/daemon.schema.7.json +1 -1
  164. package/kits/schemas/daemon.schema.8.json +2 -1
  165. package/kits/schemas/daemon.schema.9.json +2 -1
  166. package/kits/schemas/providers.schema.2.json +74 -0
  167. package/kits/schemas/role-registry.schema.1.json +2 -2
  168. package/kits/schemas/single-session.schema.1.json +1 -1
  169. package/kits/schemas/single-session.schema.2.json +1 -1
  170. package/kits/schemas/single-session.schema.3.json +1 -1
  171. package/kits/skills/aid-ability/SKILL.md +7 -7
  172. package/kits/skills/ec-agent-create/SKILL.md +1 -0
  173. package/kits/skills/ec-group/SKILL.md +8 -5
  174. package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
  175. package/kits/skills/ec-service-proxy/SKILL.md +3 -10
  176. package/kits/skills/ec-trigger/SKILL.md +9 -9
  177. package/kits/skills/ec-trigger/references/examples.md +1 -1
  178. package/kits/skills/thread-ops/SKILL.md +10 -10
  179. package/kits/templates/system-fragments/channel.md +5 -5
  180. package/kits/templates/system-fragments/commands.md +7 -6
  181. package/kits/templates/system-fragments/directory-contacts.md +10 -3
  182. package/kits/templates/system-fragments/personal-assistant.md +22 -3
  183. package/kits/templates/system-fragments/reply.md +48 -28
  184. package/kits/templates/system-fragments/session.md +3 -10
  185. package/kits/templates/system-fragments/thread.md +5 -5
  186. package/package.json +4 -4
@@ -53,6 +53,22 @@ export function buildCanonicalEvolcoreExecutionSpec(input) {
53
53
  export function serializeCanonicalEvolcoreExecutionSpec(spec) {
54
54
  return JSON.stringify(spec);
55
55
  }
56
+ function parsePosixSingleQuotedPatchArgument(source) {
57
+ if (!source.startsWith("'") || source.includes('\0'))
58
+ return undefined;
59
+ const segments = /'([^']*)'|\\'|"'"/gy;
60
+ let document = '';
61
+ let offset = 0;
62
+ while (offset < source.length) {
63
+ segments.lastIndex = offset;
64
+ const segment = segments.exec(source);
65
+ if (!segment)
66
+ return undefined;
67
+ document += segment[1] ?? "'";
68
+ offset = segments.lastIndex;
69
+ }
70
+ return document;
71
+ }
56
72
  function parseApplyPatchCommand(command, options = {}) {
57
73
  const input = command.trim();
58
74
  let commandText = input;
@@ -67,10 +83,27 @@ function parseApplyPatchCommand(command, options = {}) {
67
83
  const remainder = commandText.slice(executableMatch[0].length).trimStart();
68
84
  if (!remainder)
69
85
  return parseApplyPatchArgv([executable]);
86
+ const dialect = options.dialect ?? (process.platform === 'win32' ? 'powershell' : 'posix');
87
+ if (dialect === 'powershell' && remainder.startsWith("@'")) {
88
+ const body = remainder.match(/^@'\r?\n([\s\S]*)$/u)?.[1];
89
+ const lines = body?.split(/\r?\n/u);
90
+ const delimiterIndex = lines?.findIndex(line => line.startsWith("'@")) ?? -1;
91
+ if (!lines || delimiterIndex < 0 || lines[delimiterIndex].trimEnd() !== "'@"
92
+ || lines.slice(delimiterIndex + 1).some(line => line.trim() !== '')
93
+ || remainder.includes('\0')) {
94
+ return { kind: 'invalid', reason: 'PowerShell patch requires one complete single-quoted here-string without trailing commands' };
95
+ }
96
+ return parseApplyPatchArgv([executable, lines.slice(0, delimiterIndex).join('\n')]);
97
+ }
70
98
  const literal = parseLiteralShellCommand(commandText, { ...options, allowManagedTmpDir: true });
71
99
  if (literal.ok && argvUsesShellApplyPatch(literal.argv)) {
72
100
  return parseApplyPatchArgv(literal.argv);
73
101
  }
102
+ if (dialect === 'posix') {
103
+ const document = parsePosixSingleQuotedPatchArgument(remainder);
104
+ if (document !== undefined)
105
+ return parseApplyPatchArgv([executable, document]);
106
+ }
74
107
  const heredoc = remainder.match(/^<<-?\s*(?:'([^']+)'|"([^"]+)"|([^\s]+))\s*\r?\n([\s\S]*)$/u);
75
108
  if (!heredoc)
76
109
  return { kind: 'invalid', reason: 'apply_patch must use one literal patch document' };
@@ -158,6 +191,12 @@ export function parseShellApplyPatchInvocation(input, options = {}, parsedArgv)
158
191
  const carrier = rawCommandArgv
159
192
  ? resolveCodexShellCarrierArgv(rawCommandArgv)
160
193
  : resolveCodexShellCarrierString(rawCommand);
194
+ if (carrier?.parseFailure) {
195
+ const executable = leadingShellExecutable(carrier.command);
196
+ if (executable && isApplyPatchExecutable(executable)) {
197
+ return { kind: 'invalid', reason: 'apply_patch shell carrier has invalid quoting or command composition' };
198
+ }
199
+ }
161
200
  if (rawCommandArgv) {
162
201
  if (argvUsesShellApplyPatch(rawCommandArgv)) {
163
202
  return parseApplyPatchArgv(rawCommandArgv);
@@ -406,10 +445,12 @@ function stripHeredocBodies(command) {
406
445
  // This is intentionally limited to the command boundary. It is not a search
407
446
  // for `ec` anywhere in the input: quoted arguments, regexps and log text must
408
447
  // never establish an EC invocation.
409
- function hasEcCommandPrefix(command) {
448
+ const POWERSHELL_ASSIGNMENT_PREFIX = /^\$(?:[A-Za-z_][\w:]*|\{[^{}\r\n]+\})\s*=(?!=)/u;
449
+ function hasEcCommandPrefix(command, dialect = 'posix') {
410
450
  let quote = null;
411
451
  let escaped = false;
412
452
  let boundary = true;
453
+ const powerShell = dialect === 'powershell';
413
454
  for (let index = 0; index < command.length; index++) {
414
455
  const char = command[index];
415
456
  if (escaped) {
@@ -418,35 +459,77 @@ function hasEcCommandPrefix(command) {
418
459
  continue;
419
460
  }
420
461
  if (quote === 'single') {
421
- if (char === "'")
422
- quote = null;
462
+ if (powerShell ? isPowerShellSingleQuote(char) : char === "'") {
463
+ if (powerShell && isPowerShellSingleQuote(command[index + 1]))
464
+ index++;
465
+ else
466
+ quote = null;
467
+ }
423
468
  continue;
424
469
  }
425
470
  if (quote === 'double') {
426
- if (char === '\\') {
471
+ if (char === (powerShell ? '`' : '\\')) {
427
472
  escaped = true;
428
473
  continue;
429
474
  }
430
- if (char === '"')
475
+ if (powerShell ? isPowerShellDoubleQuote(char) : char === '"')
431
476
  quote = null;
432
477
  continue;
433
478
  }
434
- if (char === "'") {
479
+ if (powerShell && char === '`') {
480
+ escaped = true;
481
+ continue;
482
+ }
483
+ if (powerShell && command.startsWith('<#', index)) {
484
+ const end = command.indexOf('#>', index + 2);
485
+ if (end < 0)
486
+ return false;
487
+ index = end + 1;
488
+ continue;
489
+ }
490
+ if (powerShell && char === '#' && (index === 0 || /\s/.test(command[index - 1]))) {
491
+ const end = command.indexOf('\n', index);
492
+ if (end < 0)
493
+ return false;
494
+ index = end - 1;
495
+ continue;
496
+ }
497
+ if (powerShell && char === '@' && /['"]/.test(command[index + 1] ?? '')
498
+ && /^\r?\n/.test(command.slice(index + 2))) {
499
+ const end = new RegExp(`^${command[index + 1]}@`, 'm').exec(command.slice(index + 2));
500
+ if (!end)
501
+ return false;
502
+ index += end.index + 3;
503
+ boundary = false;
504
+ continue;
505
+ }
506
+ if (powerShell ? isPowerShellSingleQuote(char) : char === "'") {
435
507
  quote = 'single';
436
508
  boundary = false;
437
509
  continue;
438
510
  }
439
- if (char === '"') {
511
+ if (powerShell ? isPowerShellDoubleQuote(char) : char === '"') {
440
512
  quote = 'double';
441
513
  boundary = false;
442
514
  continue;
443
515
  }
516
+ if (powerShell && /[{}\r\n]/.test(char)) {
517
+ boundary = true;
518
+ continue;
519
+ }
444
520
  if (/[;&|`()<>]/.test(char)) {
445
521
  boundary = true;
446
522
  continue;
447
523
  }
448
524
  if (boundary && /\s/.test(char))
449
525
  continue;
526
+ if (boundary && powerShell && char === '$') {
527
+ const assignment = POWERSHELL_ASSIGNMENT_PREFIX.exec(command.slice(index));
528
+ if (assignment) {
529
+ index += assignment[0].length - 1;
530
+ continue;
531
+ }
532
+ }
450
533
  if (boundary && /^ec(?:\.cmd|\.exe|\.ps1)?(?=$|\s|[;&|`()<>])/i.test(command.slice(index)))
451
534
  return true;
452
535
  // `ecmsg` 是 `ec msg` 的同义词,同样算 EC 命令边界——否则
@@ -700,7 +783,7 @@ function isShellParameterExpansionStart(value) {
700
783
  }
701
784
  function hasCarrierEcCommandPrefix(command, dialect) {
702
785
  if (dialect !== 'cmd')
703
- return hasEcCommandPrefix(command);
786
+ return hasEcCommandPrefix(command, dialect);
704
787
  const input = trimShellSpacing(command);
705
788
  const inner = input.length >= 2 && input.startsWith('"') && input.endsWith('"')
706
789
  ? input.slice(1, -1)
@@ -1310,7 +1393,10 @@ function parseLiteralPowerShellCommand(command, options = {}) {
1310
1393
  ? { ...parsed, argv: normalizeEvolcoreCommandArgv(parsed.argv) }
1311
1394
  : { ...parsed, inputLength: input.length };
1312
1395
  }
1313
- const isEcCommand = hasEcCommandPrefix(input);
1396
+ const isEcCommand = hasEcCommandPrefix(input, 'powershell');
1397
+ if (isEcCommand && POWERSHELL_ASSIGNMENT_PREFIX.test(input)) {
1398
+ return parseFailure('shell-composition', input, 0, 0, 'powershell');
1399
+ }
1314
1400
  const argv = [];
1315
1401
  let token = '';
1316
1402
  let tokenStarted = false;
@@ -1605,7 +1691,17 @@ function resolveCodexPowerShellCarrierString(command) {
1605
1691
  // PowerShell credential-prefix parser sees them.
1606
1692
  const quote = nested[0];
1607
1693
  if (nested.length >= 2 && nested.endsWith(quote)) {
1608
- nested = nested.slice(1, -1);
1694
+ if (quote === '"' && /\\[\\"$`]/u.test(nested)) {
1695
+ const decoded = parseLiteralShellCommand(nested, { dialect: 'posix' });
1696
+ if (decoded.ok && decoded.argv.length === 1)
1697
+ nested = decoded.argv[0];
1698
+ else {
1699
+ failure = parseFailure('invalid-quote', nested, 0, 0, 'powershell');
1700
+ nested = nested.slice(1, -1);
1701
+ }
1702
+ }
1703
+ else
1704
+ nested = nested.slice(1, -1);
1609
1705
  }
1610
1706
  else {
1611
1707
  failure = parseFailure('invalid-quote', nested, 0, 0, 'powershell');
@@ -3101,7 +3197,7 @@ export function classifyEvolcoreShellCommand(command, options = {}) {
3101
3197
  // Only a command-boundary prefix is enough to preserve a useful syntax
3102
3198
  // error for a malformed direct EC invocation. Never scan for EC tokens in
3103
3199
  // arbitrary raw text after parsing fails.
3104
- return hasEcCommandPrefix(stripped)
3200
+ return hasEcCommandPrefix(stripped, options.dialect)
3105
3201
  ? { kind: 'composite', issue: literal.issue }
3106
3202
  : { kind: 'none' };
3107
3203
  }
@@ -3167,7 +3263,7 @@ export function resolveCanonicalEvolcoreToolInput(input, options = {}) {
3167
3263
  }
3168
3264
  if (classification.kind === 'composite')
3169
3265
  return { kind: 'invalid', ...(!parsed.ok ? { failure: parsed } : {}) };
3170
- if (!parsed.ok && hasEcCommandPrefix(command))
3266
+ if (!parsed.ok && hasEcCommandPrefix(command, dialect))
3171
3267
  return { kind: 'invalid', failure: parsed };
3172
3268
  return { kind: 'not-ec' };
3173
3269
  }
@@ -3288,17 +3384,45 @@ export function containsLiteralManagedTmpDirOutsideSendContent(argv) {
3288
3384
  return true;
3289
3385
  return literalIndexes.some(index => !textIndexes.has(index));
3290
3386
  }
3387
+ /** 只读子命令:查询类,不产生任何副作用。 */
3388
+ const READ_ONLY_SUBCOMMANDS = new Set([
3389
+ 'thread.list', 'thread.show', 'thread.history', 'thread.peers',
3390
+ 'thread.summary', 'msg.history', 'msg.online', 'trigger.list', 'trigger.show',
3391
+ 'directory.list', 'directory.info', 'aid.show', 'aid.list', 'aid.lookup',
3392
+ 'peer.list', 'help', 'status',
3393
+ ]);
3394
+ /**
3395
+ * 该工具调用是否是**只读**的 EC 命令。
3396
+ *
3397
+ * 意图表达门禁只应拦"有副作用但没表态"的调用;帮助与查询类命令既没有副作用,
3398
+ * 又往往是模型在学习正确用法时的必要动作。把它们一起拦掉,模型会不断试错,
3399
+ * 连续违规直接熔断——这在本项目已经真实发生过。
3400
+ */
3401
+ export function isReadOnlyEcCommand(toolName, input) {
3402
+ if (!['Bash', 'Shell', 'exec'].includes(toolName) || !input || typeof input !== 'object')
3403
+ return false;
3404
+ const result = parseProactiveToolCommand(toolName, input);
3405
+ if (!result?.ok)
3406
+ return false;
3407
+ const argv = result.argv;
3408
+ if (argv[0] !== 'ec')
3409
+ return false;
3410
+ if (argv.includes('--help') || argv.includes('-h'))
3411
+ return true;
3412
+ const head = `${argv[1] ?? ''}.${argv[2] ?? ''}`;
3413
+ return READ_ONLY_SUBCOMMANDS.has(head);
3414
+ }
3291
3415
  /** Shell-escaped TMPDIR references are literal text and must not authorize file paths. */
3292
3416
  export function containsUnresolvedManagedTmpDirReference(argv) {
3293
3417
  return argv.some(value => /(?:\\\$TMPDIR|\\\$\{TMPDIR\})/i.test(value));
3294
3418
  }
3295
- function hasExecutableProactiveSendPayload(argv, scope) {
3419
+ function hasExecutableProactiveSendPayload(argv, scope, bodyStart = 5) {
3296
3420
  if (!argv || argv[0] !== 'ec' || argv[1] !== scope || argv[2] !== 'send')
3297
3421
  return false;
3298
3422
  const positionals = [];
3299
3423
  const modes = new Map();
3300
3424
  let endOfOptions = false;
3301
- for (let index = 5; index < argv.length; index++) {
3425
+ for (let index = bodyStart; index < argv.length; index++) {
3302
3426
  const value = argv[index];
3303
3427
  if (endOfOptions) {
3304
3428
  positionals.push(value);
@@ -3425,6 +3549,19 @@ export function isEvolcoreSendCommandForSession(toolName, input, channelId) {
3425
3549
  return true;
3426
3550
  return parsed.targetId === channelId;
3427
3551
  }
3552
+ /**
3553
+ * 托管简化式:`ec msg|group send <正文...>`,省略 from/to,目标由当前会话决定。
3554
+ *
3555
+ * 判据是"argv[3] 不是 AID"——完整式这里一定是发送者 AID。带 `--thread` 的
3556
+ * 跨话题发送由 `isThreadRoutedEvolcoreSendCommand` 单独处理,这里排除。
3557
+ */
3558
+ function isManagedSimplifiedSend(argv) {
3559
+ if (argv[0] !== 'ec' || (argv[1] !== 'msg' && argv[1] !== 'group') || argv[2] !== 'send')
3560
+ return false;
3561
+ if (sendOptionValue(argv, '--thread'))
3562
+ return false;
3563
+ return !looksLikeAid(argv[3]);
3564
+ }
3428
3565
  /** Proactive first-send guard: exact channel kind and current target only. */
3429
3566
  export function isExactEvolcoreSendCommandForSession(toolName, input, channelId, chatType, selfAid) {
3430
3567
  // Codex app-server exposes shell items as `Shell`; the desktop custom tool
@@ -3433,14 +3570,20 @@ export function isExactEvolcoreSendCommandForSession(toolName, input, channelId,
3433
3570
  return false;
3434
3571
  const result = parseProactiveToolCommand(toolName, input);
3435
3572
  const argv = result?.ok ? result.argv : null;
3436
- const parsed = argv ? parseEvolcoreSendArgv(argv) : null;
3573
+ if (!argv)
3574
+ return false;
3575
+ // 托管简化式:目标就是当前会话对端,无需在 argv 里写 from/to。
3576
+ // 这正是 `ecmsg send '<正文>'` 归一后的形态,必须被认作意图表达。
3577
+ if (isManagedSimplifiedSend(argv)) {
3578
+ return hasExecutableProactiveSendPayload(argv, argv[1], 3);
3579
+ }
3580
+ const parsed = parseEvolcoreSendArgv(argv);
3437
3581
  if (!parsed || parsed.action !== 'send')
3438
3582
  return false;
3439
3583
  const expectedScope = chatType === 'group' ? 'group' : 'msg';
3440
3584
  return parsed.scope === expectedScope
3441
3585
  && parsed.targetId === channelId
3442
3586
  && parsed.sourceId === selfAid
3443
- && !!argv
3444
3587
  && hasExecutableProactiveSendPayload(argv, expectedScope);
3445
3588
  }
3446
3589
  /**
@@ -5,6 +5,7 @@ const MAX_PIPELINE_STAGES = 3;
5
5
  const SUPPORTED_EXECUTABLES = new Set([
6
6
  'echo', 'pwd', 'ls', 'cat', 'grep', 'rg', 'find', 'sed', 'head', 'tail', 'sort', 'uniq', 'git', 'wc', 'stat', 'lstat', 'awk',
7
7
  'bash', 'sh',
8
+ 'ps', 'pgrep', 'env',
8
9
  ]);
9
10
  const FIND_MUTATING_PRIMARY_RE = /^-(?:delete|exec|execdir|ok|okdir|fprint|fprint0|fprintf|fls)$/;
10
11
  const RG_PROCESS_SPAWNING_OPTION_RE = /^(?:--pre|--hostname-bin|--pre-glob|--search-zip)(?:=|$)/;
@@ -279,6 +280,8 @@ function analyzeGrep(args) {
279
280
  return paths;
280
281
  }
281
282
  function analyzeRg(args, hasPipelineInput = false) {
283
+ if (args.length === 1 && ['--help', '-h', '--version', '-V', '--type-list'].includes(args[0]))
284
+ return [];
282
285
  if (args.some(argument => RG_PROCESS_SPAWNING_OPTION_RE.test(argument)
283
286
  || argument === '--follow'
284
287
  // `-z` is the short form of `--search-zip`; it may also appear in a
@@ -367,15 +370,64 @@ function analyzeRg(args, hasPipelineInput = false) {
367
370
  }
368
371
  if (!filesMode && !hasExplicitPattern && !implicitPatternSeen)
369
372
  return null;
370
- // Enumeration modes ignore the incoming stream and are never stdin filters.
371
- if (hasPipelineInput && filesMode)
372
- return null;
373
373
  // Without an explicit path, ripgrep reads stdin when used after a pipe.
374
374
  // Standalone searches and `--files` still default to the current directory.
375
- if (!inputOperandSeen && !hasPipelineInput)
376
- paths.push(recursive('.'));
375
+ if (!inputOperandSeen && (!hasPipelineInput || filesMode))
376
+ paths.push({ ...recursive('.'), implicit: true });
377
377
  return paths;
378
378
  }
379
+ /** Process/environment queries have no filesystem operands or child command. */
380
+ function analyzeProcessQuery(executable, args) {
381
+ if (executable === 'env') {
382
+ // `env NAME=value command`, -S and -C can execute/change scope. Only
383
+ // printing the current environment is a passthrough query.
384
+ return args.every(arg => ['-0', '--null'].includes(arg)) ? [] : null;
385
+ }
386
+ if (executable === 'ps') {
387
+ const flags = new Set(['-e', '-A', '-a', '-x', '-f', '-l', '-w', '-ww', '--no-headers', '--headers', '--forest']);
388
+ const values = new Set(['-o', '-eo', '-efo', '--format', '-p', '--pid', '--ppid', '-u', '--user', '-U', '--User', '-C', '--sort']);
389
+ for (let index = 0; index < args.length; index++) {
390
+ const arg = args[index];
391
+ const option = arg.split('=', 1)[0];
392
+ if (values.has(option)) {
393
+ const value = arg.includes('=') ? arg.slice(arg.indexOf('=') + 1) : args[++index];
394
+ if (!value || value.startsWith('-'))
395
+ return null;
396
+ }
397
+ else if (!flags.has(arg) && !/^-[eAaxflw]+$/.test(arg) && !/^[auxflw]+$/.test(arg))
398
+ return null;
399
+ }
400
+ return [];
401
+ }
402
+ // pgrep -F/--pidfile and --logpidfile read files; -L depends on them.
403
+ // Keep only process selectors and one literal matching expression.
404
+ let pattern = false;
405
+ let optionsEnded = false;
406
+ const values = new Set(['-P', '--parent', '-u', '--euid', '-U', '--uid', '-g', '--pgroup', '-s', '--session', '-t', '--terminal', '-d', '--delimiter', '-r', '--runstates']);
407
+ const flags = new Set(['--full', '--list-full', '--list-name', '--count', '--exact', '--ignore-case', '--newest', '--oldest', '--inverse']);
408
+ for (let index = 0; index < args.length; index++) {
409
+ const arg = args[index];
410
+ if (!optionsEnded && arg === '--') {
411
+ optionsEnded = true;
412
+ continue;
413
+ }
414
+ const option = arg.split('=', 1)[0];
415
+ if (!optionsEnded && values.has(option)) {
416
+ const value = arg.includes('=') ? arg.slice(arg.indexOf('=') + 1) : args[++index];
417
+ if (!value || value.startsWith('-'))
418
+ return null;
419
+ }
420
+ else if (!optionsEnded && (flags.has(arg) || /^-[aflcxinov]+$/.test(arg))) {
421
+ continue;
422
+ }
423
+ else {
424
+ if ((!optionsEnded && arg.startsWith('-')) || pattern)
425
+ return null;
426
+ pattern = true;
427
+ }
428
+ }
429
+ return pattern ? [] : null;
430
+ }
379
431
  function analyzeFind(args) {
380
432
  if (args.some(argument => FIND_MUTATING_PRIMARY_RE.test(argument)))
381
433
  return null;
@@ -859,6 +911,12 @@ function analyzeCommand(argv, hasPipelineInput = false) {
859
911
  let accessKind = 'content';
860
912
  let purpose = 'unknown';
861
913
  switch (executable) {
914
+ case 'ps':
915
+ case 'pgrep':
916
+ case 'env':
917
+ pathOperands = analyzeProcessQuery(executable, args);
918
+ purpose = 'passthrough';
919
+ break;
862
920
  case 'echo':
863
921
  pathOperands = [];
864
922
  purpose = 'passthrough';
@@ -940,7 +998,8 @@ function analyzeCommand(argv, hasPipelineInput = false) {
940
998
  // 无路径操作数的命令是纯 stdin→stdout 变换,可安全出现在管道任意位置。
941
999
  // 对于 sort/wc/awk/grep/head/tail/sed:有路径参数时读文件,无路径参数时为 stdin 变换。
942
1000
  const stdinTransform = pathOperands.length === 0
943
- && ['sort', 'uniq', 'wc', 'awk', 'grep', 'rg', 'head', 'tail', 'sed'].includes(executable);
1001
+ && ['sort', 'uniq', 'wc', 'awk', 'grep', 'rg', 'head', 'tail', 'sed'].includes(executable)
1002
+ && !(executable === 'rg' && args.some(arg => ['--files', '--type-list', '--help', '-h', '--version', '-V'].includes(arg)));
944
1003
  // 修正 purpose:stdin 变换时统一标记,避免 'metadata-read'/'content-read' 歧义
945
1004
  const resolvedPurpose = stdinTransform ? 'stdin-transform' : purpose;
946
1005
  return {
@@ -966,7 +1025,7 @@ export function analyzeReadonlyShellQuery(command, options = {}) {
966
1025
  const argv = parseStageArgv(stages[index], options);
967
1026
  if (!argv)
968
1027
  return { kind: 'unproven', reason: 'non-literal-command' };
969
- const analyzed = analyzeCommand(argv, index > 0);
1028
+ const analyzed = analyzeCommand(argv, index > 0 || options.hasPipelineInput === true);
970
1029
  if (!analyzed)
971
1030
  return { kind: 'unproven', reason: 'unsupported-command-or-option' };
972
1031
  if (index > 0) {
@@ -44,12 +44,19 @@ const PERMISSION_ERROR_CODES = new Set([
44
44
  'APPROVAL_TIMEOUT',
45
45
  'DELEGATION_FAILED',
46
46
  ]);
47
+ const INVALID_ARGUMENT_POLICY_CODES = new Set([
48
+ 'apply_patch_invalid_argument',
49
+ 'apply_patch_unparseable',
50
+ 'file_change_invalid_argument',
51
+ ]);
47
52
  const DETAIL_CODE_BY_POLICY_CODE = {
48
53
  h_class_protection: 'H_CLASS_PROTECTION',
54
+ shell_implicit_cwd: 'IMPLICIT_CWD',
49
55
  l_class_protection: 'L_CLASS_PROTECTION',
50
56
  native_file_change_required: 'NATIVE_FILE_CHANGE_REQUIRED',
51
57
  apply_patch_invalid_argument: 'INVALID_ARGUMENT',
52
58
  apply_patch_unparseable: 'APPLY_PATCH_UNPARSEABLE',
59
+ file_change_invalid_argument: 'INVALID_ARGUMENT',
53
60
  apply_patch_workspace_escape: 'APPLY_PATCH_WORKSPACE_ESCAPE',
54
61
  ec_shell_invalid_quote: 'INVALID_QUOTE',
55
62
  ec_command_not_canonical: 'INVALID_ARGUMENT',
@@ -121,7 +128,12 @@ export function normalizeToolErrorClassification(input) {
121
128
  if (explicitPermission && facts.started)
122
129
  classificationConflict = true;
123
130
  let errorCode;
124
- if (explicitPermission) {
131
+ if (decisionSource === 'policy' && facts.blocked && !facts.started
132
+ && typeof input.policyCode === 'string' && INVALID_ARGUMENT_POLICY_CODES.has(input.policyCode)
133
+ && (explicit === undefined || explicit === 'POLICY_DENIED' || explicit === 'INVALID_ARGUMENT')) {
134
+ errorCode = 'INVALID_ARGUMENT';
135
+ }
136
+ else if (explicitPermission) {
125
137
  errorCode = exactPermissionBlock && !facts.started
126
138
  ? explicit
127
139
  : 'EXECUTION_FAILED';