evolcore 0.0.12 → 0.0.14

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 (116) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/bin/codex-managed-hook.mjs +4 -1
  3. package/bin/ec-safe-output.js +26 -7
  4. package/bin/install-codex-managed-hooks.mjs +201 -0
  5. package/dist/agents/claude-runner.js +105 -11
  6. package/dist/agents/codex-app-server-client.js +176 -7
  7. package/dist/agents/codex-runner.js +248 -84
  8. package/dist/agents/ecagent-runner.js +21 -2
  9. package/dist/agents/gemini-runner.js +9 -4
  10. package/dist/aun/aid/control-aid.js +36 -13
  11. package/dist/aun/aid/store.js +13 -7
  12. package/dist/aun/group-fs-download.js +56 -0
  13. package/dist/aun/group-identity.js +1 -2
  14. package/dist/aun/msg/group.js +11 -33
  15. package/dist/aun/msg/index.js +1 -2
  16. package/dist/aun/msg/managed-operation.js +176 -55
  17. package/dist/aun/msg/upload.js +16 -1
  18. package/dist/aun/outbox.js +31 -2
  19. package/dist/aun/rpc/client.js +66 -0
  20. package/dist/aun/rpc/index.js +1 -2
  21. package/dist/aun/storage/{upload.js → client.js} +11 -2
  22. package/dist/aun/storage/index.js +1 -2
  23. package/dist/channels/aun.js +514 -150
  24. package/dist/channels/daemon.js +2 -0
  25. package/dist/cli/agent.js +9 -96
  26. package/dist/cli/aun-commands.js +1 -1
  27. package/dist/cli/cli-argv.js +10 -0
  28. package/dist/cli/config.js +9 -17
  29. package/dist/cli/ctl-command.js +1 -1
  30. package/dist/cli/daemon-commands.js +39 -24
  31. package/dist/cli/fs-command.js +65 -19
  32. package/dist/cli/init.js +77 -8
  33. package/dist/cli/queue-command.js +42 -0
  34. package/dist/cli/restart-monitor.js +3 -14
  35. package/dist/cli/task-context.js +172 -0
  36. package/dist/cli/trigger-command.js +7 -0
  37. package/dist/config/access-policy.js +1 -2
  38. package/dist/config/builtin-roles.js +7 -0
  39. package/dist/config/config-manager.js +27 -3
  40. package/dist/config/contact-book-store.js +7 -2
  41. package/dist/config/peer-role-resolver.js +6 -2
  42. package/dist/config/role-migration-startup.js +53 -0
  43. package/dist/config/role-store.js +1 -1
  44. package/dist/core/auth/agent-delegation.js +1 -1
  45. package/dist/core/auth/auth-gateway.js +30 -1
  46. package/dist/core/auth/authorization-audit.js +47 -0
  47. package/dist/core/auth/operation-authorizer.js +1 -0
  48. package/dist/core/auth/operation-catalog.js +10 -1
  49. package/dist/core/bootstrap-messages.js +9 -2
  50. package/dist/core/bootstrap-service.js +8 -1
  51. package/dist/core/command/command-handler.js +201 -51
  52. package/dist/core/command/menu-catalog.js +4 -0
  53. package/dist/core/command/menu-handler.js +85 -18
  54. package/dist/core/command/menu-protocol.js +23 -2
  55. package/dist/core/command/slash-handler.js +58 -10
  56. package/dist/core/event-catalog.js +8 -0
  57. package/dist/core/handoff/runtime.js +12 -1
  58. package/dist/core/handoff/store.js +5 -1
  59. package/dist/core/interaction-router.js +10 -0
  60. package/dist/core/message/im-renderer.js +34 -1
  61. package/dist/core/message/message-bridge.js +68 -13
  62. package/dist/core/message/message-log.js +2 -0
  63. package/dist/core/message/message-queue.js +267 -39
  64. package/dist/core/message/message-utils.js +81 -4
  65. package/dist/core/message/response-engine.js +242 -48
  66. package/dist/core/message/stream-debouncer.js +10 -2
  67. package/dist/core/permission/approval-gateway.js +1 -0
  68. package/dist/core/permission/ec-command-parser.js +649 -18
  69. package/dist/core/permission/index.js +1 -1
  70. package/dist/core/permission/mode.js +15 -0
  71. package/dist/core/permission/readonly-shell-query.js +148 -8
  72. package/dist/core/permission/sandbox-runtime.js +21 -0
  73. package/dist/core/permission/tool-policy.js +266 -56
  74. package/dist/core/protected-paths.js +107 -2
  75. package/dist/core/runtime-lock.js +101 -0
  76. package/dist/core/session/session-manager.js +21 -2
  77. package/dist/core/session/session-mapper.js +20 -1
  78. package/dist/eck/detect.js +18 -1
  79. package/dist/eck/group-rules-sync.js +15 -44
  80. package/dist/index.js +191 -89
  81. package/dist/ipc.js +16 -3
  82. package/dist/paths.js +3 -0
  83. package/dist/response-system/engines/v1/proactive-flow.js +92 -8
  84. package/dist/response-system/modes/single-session/index.js +3 -0
  85. package/dist/trigger/feedback.js +64 -11
  86. package/dist/trigger/history.js +42 -7
  87. package/dist/trigger/manager.js +21 -1
  88. package/dist/trigger/parser.js +14 -2
  89. package/dist/trigger/scheduler.js +1 -0
  90. package/dist/trigger/validation.js +67 -6
  91. package/dist/utils/ecweb-supervisor.js +332 -0
  92. package/dist/utils/error-utils.js +17 -0
  93. package/dist/utils/logger.js +37 -4
  94. package/kits/docs/evolcore/trigger.md +17 -1
  95. package/kits/migrations/migrate-contact-book-v2.mjs +1 -2
  96. package/kits/schemas/role-config.schema.1.json +1 -0
  97. package/kits/templates/roles/admin.json +7 -0
  98. package/kits/templates/roles/member.json +8 -1
  99. package/kits/templates/roles/visitor.json +2 -0
  100. package/package.json +1 -1
  101. package/dist/aun/msg/payload-type.js +0 -27
  102. package/dist/aun/rpc/caller.js +0 -42
  103. package/dist/aun/rpc/connection.js +0 -25
  104. package/dist/aun/storage/manage.js +0 -10
  105. package/dist/config/access-policy-domain.js +0 -18
  106. package/dist/config/config-batch-get.js +0 -11
  107. package/dist/config/owner-policy.js +0 -4
  108. package/dist/config/role-config-v4-startup.js +0 -32
  109. package/dist/config/role-config-v5-startup.js +0 -27
  110. package/dist/core/auth/trigger-authorization.js +0 -15
  111. package/dist/core/interaction-registration.js +0 -10
  112. package/dist/core/permission/execution-sandbox.js +0 -16
  113. package/dist/core/relation/peer-key.js +0 -1
  114. package/dist/core/session/session-key.js +0 -24
  115. package/dist/eck/baseagent-caps.js +0 -18
  116. package/dist/eck/rules-loader.js +0 -28
@@ -9,6 +9,10 @@ import { renderCommandCardAsText, renderActionAsText } from '../interaction-rout
9
9
  */
10
10
  export function buildEnvelope(opts) {
11
11
  const taskId = opts.taskId ?? `interaction-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
12
+ const delivery = opts.delivery ?? opts.replyContext?.delivery;
13
+ const replyContext = opts.replyContext
14
+ ? { ...opts.replyContext, ...(delivery ? { delivery } : {}) }
15
+ : undefined;
12
16
  return {
13
17
  taskId,
14
18
  operationId: opts.operationId ?? taskId,
@@ -17,11 +21,86 @@ export function buildEnvelope(opts) {
17
21
  channelId: opts.channelId,
18
22
  agentName: opts.agentName ?? '<unknown>',
19
23
  chatmode: opts.chatmode ?? 'interactive',
20
- replyContext: opts.replyContext,
24
+ delivery,
25
+ replyContext,
21
26
  causation: opts.causation,
22
27
  timestamp: opts.timestamp ?? Date.now(),
23
28
  };
24
29
  }
30
+ /**
31
+ * Replace an envelope's reply context while keeping its transport route
32
+ * authoritative at the top level. A per-send context may intentionally move
33
+ * a reply to another target (for example owner approval in a private chat).
34
+ */
35
+ export function withEnvelopeReplyContext(envelope, replyContext) {
36
+ const delivery = replyContext?.delivery ?? envelope.delivery;
37
+ return {
38
+ ...envelope,
39
+ ...(delivery ? { delivery } : {}),
40
+ ...(replyContext
41
+ ? {
42
+ replyContext: {
43
+ ...replyContext,
44
+ ...(delivery ? { delivery } : {}),
45
+ },
46
+ }
47
+ : {}),
48
+ };
49
+ }
50
+ /** Runtime validation for routes persisted in envelopes, sessions, and outbox entries. */
51
+ export function isDeliveryTarget(value) {
52
+ if (!value || typeof value !== 'object' || Array.isArray(value))
53
+ return false;
54
+ const route = value;
55
+ if (route.chatType === 'private')
56
+ return true;
57
+ return route.chatType === 'group'
58
+ && typeof route.groupId === 'string'
59
+ && route.groupId.trim().length > 0;
60
+ }
61
+ /** Validate a route and ensure group routes address the enclosing channel. */
62
+ export function isDeliveryTargetForChannel(value, channelId) {
63
+ return isDeliveryTarget(value)
64
+ && (value.chatType === 'private' || value.groupId === channelId);
65
+ }
66
+ /** Compare normalized private/group delivery routes. */
67
+ export function sameDeliveryTarget(left, right) {
68
+ return left.chatType === right.chatType
69
+ && (left.chatType === 'private'
70
+ || (right.chatType === 'group' && left.groupId === right.groupId));
71
+ }
72
+ /** Resolve an outbound route from trusted, persisted session state. */
73
+ export function deliveryTargetFromSession(session) {
74
+ const channelType = session.channelType || session.channel?.split('#', 1)[0];
75
+ const strictAun = channelType?.toLowerCase() === 'aun';
76
+ if (session.chatType === 'group') {
77
+ const groupId = session.metadata?.groupId;
78
+ if (strictAun && (!groupId || groupId !== session.channelId)) {
79
+ const code = groupId ? 'AUN_OUTBOUND_ROUTE_MISMATCH' : 'AUN_OUTBOUND_ROUTE_REQUIRED';
80
+ throw Object.assign(new Error(`AUN group session has no valid persisted groupId for channelId=${session.channelId}`), { code });
81
+ }
82
+ return { chatType: 'group', groupId: groupId || session.channelId };
83
+ }
84
+ if (session.chatType === 'private')
85
+ return { chatType: 'private' };
86
+ if (strictAun) {
87
+ throw Object.assign(new Error(`AUN session has no persisted chatType for channelId=${session.channelId}`), {
88
+ code: 'AUN_OUTBOUND_ROUTE_REQUIRED',
89
+ });
90
+ }
91
+ return { chatType: 'private' };
92
+ }
93
+ /** Preserve channel-specific reply fields while filling the session route. */
94
+ export function replyContextFromSession(session, context) {
95
+ return {
96
+ ...(session.metadata?.replyContext ?? {}),
97
+ ...(context ?? {}),
98
+ // Session chatType/groupId is the persisted routing authority. The nested
99
+ // reply context can outlive a route correction, so only an explicit
100
+ // per-send context may override it.
101
+ delivery: context?.delivery ?? deliveryTargetFromSession(session),
102
+ };
103
+ }
25
104
  /**
26
105
  * 交互请求的默认回退文本
27
106
  * 当调用方未显式提供时使用,根据交互类型选择合适的渲染器。
@@ -60,9 +139,7 @@ export async function sendInteractionPayload(adapter, envelope, interaction, fal
60
139
  fallbackText: text || undefined,
61
140
  };
62
141
  try {
63
- const enriched = replyCtx
64
- ? { ...envelope, replyContext: replyCtx }
65
- : envelope;
142
+ const enriched = replyCtx ? withEnvelopeReplyContext(envelope, replyCtx) : envelope;
66
143
  const receipt = await adapter.send(enriched, payload);
67
144
  if (receipt?.status === 'suppressed')
68
145
  return false;