evolcore 0.0.1 → 0.0.2
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.
- package/CHANGELOG.md +813 -0
- package/LICENSE +21 -0
- package/MIGRATION-0.5.0.md +378 -0
- package/README.md +318 -14
- package/ROLE_ACCESS_CONTROL.md +174 -0
- package/assets/.env.template +4 -0
- package/assets/brand/evolcore/README.md +19 -0
- package/assets/brand/evolcore/evolcore-app-icon.png +0 -0
- package/assets/brand/evolcore/evolcore-app-icon.svg +13 -0
- package/assets/brand/evolcore/evolcore-brand-board.png +0 -0
- package/assets/brand/evolcore/evolcore-brand-board.svg +126 -0
- package/assets/brand/evolcore/evolcore-logo-kit.zip +0 -0
- package/assets/brand/evolcore/evolcore-logo-reverse.png +0 -0
- package/assets/brand/evolcore/evolcore-logo-reverse.svg +14 -0
- package/assets/brand/evolcore/evolcore-logo.png +0 -0
- package/assets/brand/evolcore/evolcore-logo.svg +14 -0
- package/assets/brand/evolcore/evolcore-mark.png +0 -0
- package/assets/brand/evolcore/evolcore-mark.svg +10 -0
- package/bin/ec-safe-output.js +161 -0
- package/bin/ec.js +29 -0
- package/dist/agents/baseagent.js +163 -0
- package/dist/agents/claude-runner.js +2385 -0
- package/dist/agents/codex-app-server-client.js +448 -0
- package/dist/agents/codex-runner.js +2639 -0
- package/dist/agents/gemini-runner.js +666 -0
- package/dist/agents/runner-types.js +75 -0
- package/dist/aun/aid/agentmd.js +216 -0
- package/dist/aun/aid/client.js +132 -0
- package/dist/aun/aid/control-aid.js +91 -0
- package/dist/aun/aid/identity.js +518 -0
- package/dist/aun/aid/index.js +4 -0
- package/dist/aun/aid/store.js +74 -0
- package/dist/aun/aid/types.js +1 -0
- package/dist/aun/aid/validation.js +21 -0
- package/dist/aun/group-identity.js +10 -0
- package/dist/aun/msg/group-index.js +6 -0
- package/dist/aun/msg/group.js +1231 -0
- package/dist/aun/msg/history.js +123 -0
- package/dist/aun/msg/index.js +5 -0
- package/dist/aun/msg/p2p.js +393 -0
- package/dist/aun/msg/payload-type.js +27 -0
- package/dist/aun/msg/upload.js +137 -0
- package/dist/aun/outbox.js +160 -0
- package/dist/aun/rpc/caller.js +42 -0
- package/dist/aun/rpc/connection.js +25 -0
- package/dist/aun/rpc/index.js +2 -0
- package/dist/aun/service-proxy.js +225 -0
- package/dist/aun/storage/download.js +29 -0
- package/dist/aun/storage/index.js +3 -0
- package/dist/aun/storage/manage.js +10 -0
- package/dist/aun/storage/upload.js +68 -0
- package/dist/channels/aun.js +4147 -0
- package/dist/channels/daemon.js +422 -0
- package/dist/channels/dingtalk.js +649 -0
- package/dist/channels/feishu.js +1789 -0
- package/dist/channels/qqbot.js +409 -0
- package/dist/channels/wechat.js +817 -0
- package/dist/channels/wecom.js +565 -0
- package/dist/cli/agent-command.js +641 -0
- package/dist/cli/agent.js +1059 -0
- package/dist/cli/aun-commands.js +1948 -0
- package/dist/cli/bench.js +1228 -0
- package/dist/cli/cli-argv.js +66 -0
- package/dist/cli/code-stats.js +329 -0
- package/dist/cli/command-log.js +82 -0
- package/dist/cli/config-selector.js +69 -0
- package/dist/cli/config.js +261 -0
- package/dist/cli/ctl-command.js +62 -0
- package/dist/cli/daemon-commands.js +2887 -0
- package/dist/cli/fs-command.js +1447 -0
- package/dist/cli/handoff-command.js +302 -0
- package/dist/cli/help.js +31 -0
- package/dist/cli/index.js +358 -0
- package/dist/cli/init-channel.js +1377 -0
- package/dist/cli/init.js +553 -0
- package/dist/cli/link-rules.js +240 -0
- package/dist/cli/model.js +590 -0
- package/dist/cli/net-check.js +723 -0
- package/dist/cli/queue-command.js +126 -0
- package/dist/cli/response.js +345 -0
- package/dist/cli/restart-monitor.js +456 -0
- package/dist/cli/stats.js +607 -0
- package/dist/cli/task-context.js +80 -0
- package/dist/cli/trigger-command.js +505 -0
- package/dist/cli/version.js +88 -0
- package/dist/cli/watch-logs.js +33 -0
- package/dist/cli/watch-msg.js +673 -0
- package/dist/config/boot-log.js +266 -0
- package/dist/config/builtin-role-templates.js +30 -0
- package/dist/config/builtin-roles.js +85 -0
- package/dist/config/config-batch-get.js +11 -0
- package/dist/config/config-field-policy.js +261 -0
- package/dist/config/config-manager.js +916 -0
- package/dist/config/config-operation-service.js +384 -0
- package/dist/config/contact-book.js +371 -0
- package/dist/config/gateway-config.js +858 -0
- package/dist/config/lifecycle.js +17 -0
- package/dist/config/mention-mode.js +27 -0
- package/dist/config/merge.js +161 -0
- package/dist/config/owner-policy.js +4 -0
- package/dist/config/peer-role-resolver.js +139 -0
- package/dist/config/resolved-config-op.js +483 -0
- package/dist/config/role-config-v4-startup.js +32 -0
- package/dist/config/role-config-v5-startup.js +27 -0
- package/dist/config/role-schema.js +105 -0
- package/dist/config/role-service.js +159 -0
- package/dist/config/role-store.js +204 -0
- package/dist/config/roles.js +55 -0
- package/dist/config/schema-registry.js +154 -0
- package/dist/config/snapshot.js +598 -0
- package/dist/config-store.js +503 -0
- package/dist/core/auth/agent-delegation.js +111 -0
- package/dist/core/auth/auth-gateway.js +166 -0
- package/dist/core/auth/authenticated-actor.js +6 -0
- package/dist/core/auth/authorization-audit.js +110 -0
- package/dist/core/auth/operation-authorizer.js +718 -0
- package/dist/core/auth/operation-catalog.js +675 -0
- package/dist/core/baseagent-loader.js +54 -0
- package/dist/core/bootstrap-service.js +175 -0
- package/dist/core/capability/capability-manager.js +316 -0
- package/dist/core/capability/providers/claude-capability-provider.js +176 -0
- package/dist/core/capability/providers/codex-capability-provider.js +148 -0
- package/dist/core/capability/providers/gemini-capability-provider.js +10 -0
- package/dist/core/capability/types.js +27 -0
- package/dist/core/causation/audit.js +103 -0
- package/dist/core/causation/aun-association.js +111 -0
- package/dist/core/causation/context.js +93 -0
- package/dist/core/causation/index.js +4 -0
- package/dist/core/causation/types.js +2 -0
- package/dist/core/channel-loader.js +277 -0
- package/dist/core/command/agent-control.js +616 -0
- package/dist/core/command/cli-intent-parser.js +225 -0
- package/dist/core/command/command-handler.js +1638 -0
- package/dist/core/command/menu-handler.js +3354 -0
- package/dist/core/command/menu-protocol.js +247 -0
- package/dist/core/command/role-menu.js +1524 -0
- package/dist/core/command/slash-gate.js +148 -0
- package/dist/core/command/slash-handler.js +3056 -0
- package/dist/core/daemon-file-cache.js +216 -0
- package/dist/core/event-bus.js +32 -0
- package/dist/core/event-catalog.js +740 -0
- package/dist/core/evolagent-registry.js +546 -0
- package/dist/core/evolagent.js +331 -0
- package/dist/core/handoff/dispatcher.js +229 -0
- package/dist/core/handoff/mutex.js +46 -0
- package/dist/core/handoff/runtime.js +324 -0
- package/dist/core/handoff/store.js +537 -0
- package/dist/core/handoff/types.js +12 -0
- package/dist/core/inference/text-inference.js +173 -0
- package/dist/core/interaction-registration.js +10 -0
- package/dist/core/interaction-router.js +278 -0
- package/dist/core/message/create-status.js +67 -0
- package/dist/core/message/im-renderer.js +657 -0
- package/dist/core/message/items-formatter.js +76 -0
- package/dist/core/message/logical-queue-bridge.js +123 -0
- package/dist/core/message/message-bridge.js +803 -0
- package/dist/core/message/message-cache.js +56 -0
- package/dist/core/message/message-log.js +339 -0
- package/dist/core/message/message-processor.js +4 -0
- package/dist/core/message/message-queue.js +1436 -0
- package/dist/core/message/message-utils.js +70 -0
- package/dist/core/message/peer-mode.js +105 -0
- package/dist/core/message/pending-hints.js +232 -0
- package/dist/core/message/response-depth.js +33 -0
- package/dist/core/message/response-engine.js +3776 -0
- package/dist/core/message/response-snapshot.js +83 -0
- package/dist/core/message/stream-debouncer.js +130 -0
- package/dist/core/message/stream-idle-monitor.js +124 -0
- package/dist/core/model/config-scope.js +162 -0
- package/dist/core/model/field-scope.js +78 -0
- package/dist/core/model/model-catalog.js +227 -0
- package/dist/core/model/model-diagnostics.js +182 -0
- package/dist/core/model/model-permission.js +90 -0
- package/dist/core/permission/approval-gateway.js +1017 -0
- package/dist/core/permission/ec-command-parser.js +347 -0
- package/dist/core/permission/execution-sandbox.js +16 -0
- package/dist/core/permission/index.js +6 -0
- package/dist/core/permission/mode.js +24 -0
- package/dist/core/permission/sandbox-runtime.js +265 -0
- package/dist/core/permission/tool-policy.js +987 -0
- package/dist/core/permission/unix-socket-policy.js +99 -0
- package/dist/core/protected-paths.js +330 -0
- package/dist/core/relation/peer-identity.js +222 -0
- package/dist/core/relation/peer-key.js +1 -0
- package/dist/core/role/runtime-policy.js +141 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +218 -0
- package/dist/core/session/adapters/codex-session-file-adapter.js +333 -0
- package/dist/core/session/adapters/gemini-session-file-adapter.js +181 -0
- package/dist/core/session/session-file-adapter.js +7 -0
- package/dist/core/session/session-file-health.js +45 -0
- package/dist/core/session/session-fs-store.js +232 -0
- package/dist/core/session/session-key.js +24 -0
- package/dist/core/session/session-manager.js +1587 -0
- package/dist/core/session/session-mapper.js +100 -0
- package/dist/core/session/session-renew.js +314 -0
- package/dist/core/session/session-title.js +128 -0
- package/dist/core/session/session-turn-coordinator.js +205 -0
- package/dist/core/session/session-turns.js +67 -0
- package/dist/core/system-channels.js +29 -0
- package/dist/eck/baseagent-caps.js +18 -0
- package/dist/eck/detect.js +47 -0
- package/dist/eck/group-rules-sync.js +345 -0
- package/dist/eck/init.js +77 -0
- package/dist/eck/kit-renderer.js +359 -0
- package/dist/eck/manifest-engine.js +446 -0
- package/dist/eck/message-renderer.js +199 -0
- package/dist/eck/rules-loader.js +28 -0
- package/dist/index.js +2870 -4
- package/dist/ipc.js +748 -0
- package/dist/paths.js +262 -0
- package/dist/product.js +18 -0
- package/dist/response-system/context-builder.js +71 -0
- package/dist/response-system/coordinator.js +117 -0
- package/dist/response-system/decision-executor.js +86 -0
- package/dist/response-system/engines/v1/index.js +21 -0
- package/dist/response-system/engines/v1/interactive-flow.js +27 -0
- package/dist/response-system/engines/v1/proactive-flow.js +137 -0
- package/dist/response-system/engines/v1/types.js +1 -0
- package/dist/response-system/extensions.js +41 -0
- package/dist/response-system/index.js +6 -0
- package/dist/response-system/modes/index.js +7 -0
- package/dist/response-system/modes/single-session/index.js +72 -0
- package/dist/response-system/queues/fifo-queue.js +44 -0
- package/dist/response-system/queues/index.js +6 -0
- package/dist/response-system/queues/lifo-queue.js +42 -0
- package/dist/response-system/queues/priority-queue.js +63 -0
- package/dist/response-system/registry.js +97 -0
- package/dist/response-system/resolver.js +37 -0
- package/dist/response-system/selector.js +23 -0
- package/dist/response-system/types.js +7 -0
- package/dist/stats/billing.js +151 -0
- package/dist/stats/budget.js +93 -0
- package/dist/stats/db.js +403 -0
- package/dist/stats/eck-vars.js +89 -0
- package/dist/stats/index.js +11 -0
- package/dist/stats/normalizer.js +80 -0
- package/dist/stats/price-resolver.js +138 -0
- package/dist/stats/query.js +763 -0
- package/dist/stats/role-budget.js +168 -0
- package/dist/stats/writer.js +151 -0
- package/dist/trigger/anomaly-store.js +258 -0
- package/dist/trigger/audit.js +152 -0
- package/dist/trigger/event-source.js +119 -0
- package/dist/trigger/feedback.js +685 -0
- package/dist/trigger/history.js +290 -0
- package/dist/trigger/manager.js +291 -0
- package/dist/trigger/parser.js +520 -0
- package/dist/trigger/patch.js +148 -0
- package/dist/trigger/scheduler.js +1600 -0
- package/dist/trigger/script-executor.js +155 -0
- package/dist/trigger/state.js +145 -0
- package/dist/trigger/types.js +1 -0
- package/dist/trigger/validation.js +621 -0
- package/dist/types.js +12 -0
- package/dist/utils/aid-bind.js +299 -0
- package/dist/utils/atomic-write.js +95 -0
- package/dist/utils/avatar-upload.js +123 -0
- package/dist/utils/cross-platform.js +297 -0
- package/dist/utils/ecweb-utils.js +73 -0
- package/dist/utils/error-dict.json +153 -0
- package/dist/utils/error-utils.js +349 -0
- package/dist/utils/instance-registry.js +437 -0
- package/dist/utils/locale.js +21 -0
- package/dist/utils/log-writer.js +224 -0
- package/dist/utils/logger.js +89 -0
- package/dist/utils/markdown-to-plain-text.js +20 -0
- package/dist/utils/media-cache.js +271 -0
- package/dist/utils/model-prices.jsonl +17 -0
- package/dist/utils/npm-ops.js +210 -0
- package/dist/utils/process-introspect.js +133 -0
- package/dist/utils/process-tree-stats.js +271 -0
- package/dist/utils/project-path.js +74 -0
- package/dist/utils/stats.js +410 -0
- package/dist/utils/tool-summary.js +284 -0
- package/dist/utils/welcome.js +268 -0
- package/kits/docs/GUIDE.md +20 -0
- package/kits/docs/INDEX.md +65 -0
- package/kits/docs/aun/CHEATSHEET.md +19 -0
- package/kits/docs/aun/SYNC_PROTOCOL.md +15 -0
- package/kits/docs/channels/aun.md +65 -0
- package/kits/docs/channels/feishu.md +56 -0
- package/kits/docs/context-assembly.md +366 -0
- package/kits/docs/eck_templates/GUIDE.template.md +22 -0
- package/kits/docs/eck_templates/INDEX.template.md +28 -0
- package/kits/docs/eck_templates/path-registry.template.md +33 -0
- package/kits/docs/eck_templates/runtime.template.md +19 -0
- package/kits/docs/evolcore/INDEX.md +66 -0
- package/kits/docs/evolcore/agent.md +69 -0
- package/kits/docs/evolcore/aid.md +49 -0
- package/kits/docs/evolcore/config.md +149 -0
- package/kits/docs/evolcore/ctl.md +46 -0
- package/kits/docs/evolcore/event.md +216 -0
- package/kits/docs/evolcore/fs-architecture.md +1215 -0
- package/kits/docs/evolcore/fs.md +101 -0
- package/kits/docs/evolcore/group-fs.md +17 -0
- package/kits/docs/evolcore/group-rules.md +226 -0
- package/kits/docs/evolcore/group.md +141 -0
- package/kits/docs/evolcore/model.md +47 -0
- package/kits/docs/evolcore/msg.md +130 -0
- package/kits/docs/evolcore/response.md +80 -0
- package/kits/docs/evolcore/rpc.md +35 -0
- package/kits/docs/evolcore/self-summary.md +29 -0
- package/kits/docs/evolcore/stats.md +70 -0
- package/kits/docs/evolcore/storage.md +49 -0
- package/kits/docs/evolcore/trigger.md +524 -0
- package/kits/docs/identity/AID_PROFILE_SPEC.md +26 -0
- package/kits/docs/identity/PATH_OPS.md +16 -0
- package/kits/docs/identity/ROLE_DETAIL.md +23 -0
- package/kits/docs/identity/identity-tools.md +26 -0
- package/kits/docs/path-registry.md +43 -0
- package/kits/docs/prompt-loading-architecture.md +266 -0
- package/kits/docs/venues/aun-group.md +45 -0
- package/kits/docs/venues/aun-private.md +10 -0
- package/kits/docs/venues/client-desktop.md +10 -0
- package/kits/docs/venues/client-mobile.md +10 -0
- package/kits/docs/venues/feishu-group.md +13 -0
- package/kits/docs/venues/feishu-private.md +9 -0
- package/kits/docs/venues/group.md +25 -0
- package/kits/docs/venues/private.md +10 -0
- package/kits/eck_manifest.auxiliary.json +43 -0
- package/kits/eck_manifest.json +191 -0
- package/kits/eck_message_manifest.json +63 -0
- package/kits/migrations/README-role-config-v4.md +32 -0
- package/kits/migrations/migrate-role-config-v4.mjs +623 -0
- package/kits/migrations/migrate-role-config-v5.mjs +346 -0
- package/kits/migrations/rename-config-file.mjs +99 -0
- package/kits/rules/01-overview.md +142 -0
- package/kits/rules/02-navigation.md +76 -0
- package/kits/rules/03-identity.md +34 -0
- package/kits/rules/04-relation.md +59 -0
- package/kits/rules/05-venue.md +44 -0
- package/kits/rules/06-channel.md +59 -0
- package/kits/schemas/_meta.json +29 -0
- package/kits/schemas/agent-config.schema.1.json +177 -0
- package/kits/schemas/agent-config.schema.2.json +239 -0
- package/kits/schemas/agent-config.schema.3.json +119 -0
- package/kits/schemas/agent-config.schema.4.json +208 -0
- package/kits/schemas/agent-config.schema.5.json +326 -0
- package/kits/schemas/contact-book.schema.1.json +36 -0
- package/kits/schemas/daemon.schema.1.json +90 -0
- package/kits/schemas/defaults.schema.1.json +81 -0
- package/kits/schemas/menu-exec-schema-commands.md +208 -0
- package/kits/schemas/migrations/README.md +28 -0
- package/kits/schemas/relation-config.schema.1.json +158 -0
- package/kits/schemas/relation-config.schema.2.json +73 -0
- package/kits/schemas/relation-config.schema.3.json +50 -0
- package/kits/schemas/relation-config.schema.4.json +47 -0
- package/kits/schemas/role-config.schema.1.json +200 -0
- package/kits/schemas/role-registry.schema.1.json +35 -0
- package/kits/schemas/single-session.schema.1.json +31 -0
- package/kits/templates/bootstrap-welcome.md +15 -0
- package/kits/templates/message-fragments/handoff-request-to-target.md +13 -0
- package/kits/templates/message-fragments/handoff-response-to-origin.md +10 -0
- package/kits/templates/message-fragments/inject-default.md +2 -0
- package/kits/templates/message-fragments/item.md +2 -0
- package/kits/templates/roles/admin.json +8 -0
- package/kits/templates/roles/member.json +40 -0
- package/kits/templates/roles/owner.json +8 -0
- package/kits/templates/roles/visitor.json +39 -0
- package/kits/templates/system-fragments/baseagent.md +14 -0
- package/kits/templates/system-fragments/bootstrap.md +16 -0
- package/kits/templates/system-fragments/channel.md +48 -0
- package/kits/templates/system-fragments/commands.md +26 -0
- package/kits/templates/system-fragments/identity.md +11 -0
- package/kits/templates/system-fragments/relation.md +19 -0
- package/kits/templates/system-fragments/session.md +53 -0
- package/kits/templates/system-fragments/venue.md +31 -0
- package/package.json +50 -15
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import { resolvePeerRoleDetail } from '../config/peer-role-resolver.js';
|
|
2
|
+
const DEFAULT_WATCHDOG_MS = 11 * 60 * 1000;
|
|
3
|
+
export class DaemonChannel {
|
|
4
|
+
sessionManager;
|
|
5
|
+
messageQueue;
|
|
6
|
+
channelName = 'daemon';
|
|
7
|
+
channelKey = 'daemon';
|
|
8
|
+
capabilities = {
|
|
9
|
+
file: true,
|
|
10
|
+
image: false,
|
|
11
|
+
interaction: false,
|
|
12
|
+
markdown: true,
|
|
13
|
+
thought: true,
|
|
14
|
+
status: true,
|
|
15
|
+
thread: true,
|
|
16
|
+
};
|
|
17
|
+
pending = new Map();
|
|
18
|
+
watchdogMs;
|
|
19
|
+
totalExecutionMs;
|
|
20
|
+
constructor(sessionManager, messageQueue, opts = {}) {
|
|
21
|
+
this.sessionManager = sessionManager;
|
|
22
|
+
this.messageQueue = messageQueue;
|
|
23
|
+
this.watchdogMs = normalizeWatchdogMs(opts.watchdogMs);
|
|
24
|
+
this.totalExecutionMs = normalizeTotalExecutionMs(opts.totalExecutionMs);
|
|
25
|
+
}
|
|
26
|
+
async converse(prompt, ctx) {
|
|
27
|
+
const runId = ctx.runId;
|
|
28
|
+
const pendingId = ctx.attemptId ?? runId;
|
|
29
|
+
const messageId = pendingId;
|
|
30
|
+
const startedAt = Date.now();
|
|
31
|
+
const promise = new Promise((resolve) => {
|
|
32
|
+
const watchdogTimer = setTimeout(() => this.watchdogTimeout(pendingId), this.watchdogMs);
|
|
33
|
+
watchdogTimer.unref?.();
|
|
34
|
+
const totalExecutionTimer = setTimeout(() => this.totalExecutionTimeout(pendingId), this.totalExecutionMs);
|
|
35
|
+
totalExecutionTimer.unref?.();
|
|
36
|
+
this.pending.set(pendingId, {
|
|
37
|
+
resolve,
|
|
38
|
+
startedAt,
|
|
39
|
+
watchdogTimer,
|
|
40
|
+
totalExecutionTimer,
|
|
41
|
+
waitingForAction: false,
|
|
42
|
+
onStateChange: ctx.onStateChange,
|
|
43
|
+
messageId,
|
|
44
|
+
abortSignal: ctx.signal,
|
|
45
|
+
runId,
|
|
46
|
+
acc: { text: '', files: [], anomalies: [], toolCallCount: 0, seenToolCallIds: new Set() },
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
const message = {
|
|
50
|
+
channel: this.channelName,
|
|
51
|
+
channelType: this.channelName,
|
|
52
|
+
channelId: ctx.session.channelId,
|
|
53
|
+
selfAID: ctx.trigger.agentAid,
|
|
54
|
+
baseagent: ctx.baseagent,
|
|
55
|
+
threadId: ctx.session.threadId || '',
|
|
56
|
+
chatType: 'private',
|
|
57
|
+
peerId: `trigger:${ctx.trigger.id}`,
|
|
58
|
+
peerName: ctx.trigger.name,
|
|
59
|
+
peerType: 'system',
|
|
60
|
+
content: prompt,
|
|
61
|
+
messageId,
|
|
62
|
+
timestamp: Date.now(),
|
|
63
|
+
source: 'trigger',
|
|
64
|
+
causation: ctx.causation,
|
|
65
|
+
replyContext: { metadata: { triggerRunId: runId, triggerAttemptId: pendingId } },
|
|
66
|
+
triggerMeta: {
|
|
67
|
+
triggerId: ctx.trigger.id,
|
|
68
|
+
runId,
|
|
69
|
+
attemptId: ctx.attemptId,
|
|
70
|
+
triggerName: ctx.trigger.name,
|
|
71
|
+
fireTime: ctx.firedAt,
|
|
72
|
+
boundSessionId: ctx.session.id,
|
|
73
|
+
modelOverride: ctx.trigger.execution.model,
|
|
74
|
+
effortOverride: ctx.trigger.execution.effort,
|
|
75
|
+
permissionModeOverride: ctx.trigger.execution.permissionMode,
|
|
76
|
+
originPeerId: ctx.trigger.origin?.peerId,
|
|
77
|
+
originChannelKey: ctx.trigger.origin?.channelKey,
|
|
78
|
+
originChannelType: ctx.trigger.origin?.channelType
|
|
79
|
+
?? (ctx.trigger.origin?.channelKey ? channelTypeFromKey(ctx.trigger.origin.channelKey) : undefined),
|
|
80
|
+
originControl: ctx.trigger.origin?.channelKey === 'daemon',
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
const onAbort = () => {
|
|
84
|
+
const reason = ctx.signal?.reason instanceof Error
|
|
85
|
+
? ctx.signal.reason.message
|
|
86
|
+
: 'trigger execution cancelled';
|
|
87
|
+
const slot = this.pending.get(pendingId);
|
|
88
|
+
if (!slot || slot.terminalClaim)
|
|
89
|
+
return;
|
|
90
|
+
slot.acc.error = { reason: 'cancelled', text: reason };
|
|
91
|
+
if (!this.claimTerminal(slot, 'error'))
|
|
92
|
+
return;
|
|
93
|
+
const barrier = this.cancelDelivery(messageId);
|
|
94
|
+
slot.cancellationBarrier = barrier;
|
|
95
|
+
const finalize = () => this.settleTerminal(pendingId, slot);
|
|
96
|
+
void barrier.then(finalize, finalize);
|
|
97
|
+
};
|
|
98
|
+
const slot = this.pending.get(pendingId);
|
|
99
|
+
if (slot && ctx.signal) {
|
|
100
|
+
slot.abortListener = onAbort;
|
|
101
|
+
ctx.signal.addEventListener('abort', onAbort, { once: true });
|
|
102
|
+
}
|
|
103
|
+
if (ctx.signal?.aborted)
|
|
104
|
+
onAbort();
|
|
105
|
+
if (!slot?.terminalClaim) {
|
|
106
|
+
void this.messageQueue.enqueue(ctx.session.id, message, ctx.projectPath, {
|
|
107
|
+
interruptible: false,
|
|
108
|
+
agentName: ctx.trigger.agentAid,
|
|
109
|
+
sessionKeyField: ctx.session.sessionKey,
|
|
110
|
+
selfAID: ctx.trigger.agentAid,
|
|
111
|
+
role: this.triggerOriginRole(ctx.trigger),
|
|
112
|
+
signal: ctx.signal,
|
|
113
|
+
}).catch((err) => {
|
|
114
|
+
if (ctx.signal?.aborted)
|
|
115
|
+
return;
|
|
116
|
+
this.fail(pendingId, 'enqueue_error', err?.message || String(err));
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return promise;
|
|
120
|
+
}
|
|
121
|
+
async send(envelope, payload) {
|
|
122
|
+
const runId = this.runIdFromEnvelope(envelope);
|
|
123
|
+
if (!runId)
|
|
124
|
+
return;
|
|
125
|
+
const slot = this.pending.get(runId);
|
|
126
|
+
if (!slot || slot.terminalClaim)
|
|
127
|
+
return;
|
|
128
|
+
if (payload.kind !== 'status.requires_action')
|
|
129
|
+
this.resetWatchdog(runId, slot);
|
|
130
|
+
switch (payload.kind) {
|
|
131
|
+
case 'activity.batch':
|
|
132
|
+
for (const item of payload.items) {
|
|
133
|
+
if (item.kind === 'tool_call')
|
|
134
|
+
this.recordToolCall(slot, item.call_id);
|
|
135
|
+
}
|
|
136
|
+
break;
|
|
137
|
+
case 'result.text':
|
|
138
|
+
if (payload.isFinal)
|
|
139
|
+
slot.acc.text = payload.text;
|
|
140
|
+
else
|
|
141
|
+
slot.acc.text += payload.text;
|
|
142
|
+
break;
|
|
143
|
+
case 'result.file':
|
|
144
|
+
slot.acc.files.push({ path: payload.filePath, name: payload.fileName });
|
|
145
|
+
break;
|
|
146
|
+
case 'result.error':
|
|
147
|
+
slot.acc.error = { reason: payload.reason, text: payload.text };
|
|
148
|
+
this.finish(runId, 'error', { errorType: payload.reason ?? 'result_error' });
|
|
149
|
+
break;
|
|
150
|
+
case 'system.error':
|
|
151
|
+
slot.acc.error = { reason: payload.subtype, text: payload.text };
|
|
152
|
+
this.finish(runId, 'error', { errorType: payload.subtype });
|
|
153
|
+
break;
|
|
154
|
+
case 'status.progress':
|
|
155
|
+
if (payload.metadata?.activityType === 'execution_anomaly') {
|
|
156
|
+
this.recordExecutionAnomaly(runId, payload.metadata?.anomaly);
|
|
157
|
+
}
|
|
158
|
+
if (slot.waitingForAction && payload.metadata?.state === 'processing') {
|
|
159
|
+
slot.waitingForAction = false;
|
|
160
|
+
slot.onStateChange?.('running', payload.metadata);
|
|
161
|
+
this.resetWatchdog(runId, slot);
|
|
162
|
+
}
|
|
163
|
+
if (payload.metadata?.activityType === 'tool_call')
|
|
164
|
+
this.recordToolCall(slot, payload.metadata.callId);
|
|
165
|
+
break;
|
|
166
|
+
case 'status.requires_action':
|
|
167
|
+
slot.waitingForAction = true;
|
|
168
|
+
if (slot.watchdogTimer)
|
|
169
|
+
clearTimeout(slot.watchdogTimer);
|
|
170
|
+
slot.watchdogTimer = undefined;
|
|
171
|
+
slot.onStateChange?.('requires_action', payload.metadata);
|
|
172
|
+
break;
|
|
173
|
+
case 'status.completed':
|
|
174
|
+
this.finish(runId, 'success', payload.metadata);
|
|
175
|
+
break;
|
|
176
|
+
case 'status.error':
|
|
177
|
+
if (payload.metadata?.message) {
|
|
178
|
+
slot.acc.error = {
|
|
179
|
+
reason: payload.metadata.errorType ?? 'status_error',
|
|
180
|
+
text: payload.metadata.message,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
this.finish(runId, 'error', payload.metadata);
|
|
184
|
+
break;
|
|
185
|
+
case 'status.interrupted':
|
|
186
|
+
{
|
|
187
|
+
const reason = typeof payload.metadata?.reason === 'string' ? payload.metadata.reason : 'interrupted';
|
|
188
|
+
slot.acc.error = { reason, text: `trigger execution interrupted: ${reason}` };
|
|
189
|
+
}
|
|
190
|
+
this.finish(runId, 'interrupted', payload.metadata);
|
|
191
|
+
break;
|
|
192
|
+
case 'status.timeout':
|
|
193
|
+
this.finish(runId, 'timeout', payload.metadata);
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
recordExecutionActivity(pendingId) {
|
|
198
|
+
const slot = this.pending.get(pendingId);
|
|
199
|
+
if (!slot || slot.terminalClaim)
|
|
200
|
+
return false;
|
|
201
|
+
this.resetWatchdog(pendingId, slot);
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
async getOrCreateConversationSession(trigger, projectPath, baseagent, runId, attemptId) {
|
|
205
|
+
const channelId = `trigger:${trigger.id}`;
|
|
206
|
+
const threadId = trigger.execution.thread === 'per_run'
|
|
207
|
+
? `trigger:${trigger.id}:${attemptId ?? runId}`
|
|
208
|
+
: `trigger:${trigger.id}`;
|
|
209
|
+
return await this.sessionManager.getOrCreateSession(this.channelName, channelId, projectPath, threadId, { channelKey: this.channelKey, peerId: `trigger:${trigger.id}`, peerName: trigger.name }, trigger.name, undefined, 'private', baseagent, trigger.agentAid, this.channelName, 'system');
|
|
210
|
+
}
|
|
211
|
+
/** Internal Trigger audit hook. It does not emit user-visible output. */
|
|
212
|
+
recordExecutionAnomaly(runId, value) {
|
|
213
|
+
const slot = this.pending.get(runId);
|
|
214
|
+
if (!slot || slot.terminalClaim)
|
|
215
|
+
return false;
|
|
216
|
+
const anomaly = normalizeExecutionAnomaly(value);
|
|
217
|
+
if (!anomaly)
|
|
218
|
+
return false;
|
|
219
|
+
slot.acc.anomalies.push(anomaly);
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
runIdFromEnvelope(envelope) {
|
|
223
|
+
const metadata = envelope.replyContext?.metadata;
|
|
224
|
+
const pendingId = metadata?.triggerAttemptId ?? metadata?.triggerRunId;
|
|
225
|
+
return typeof pendingId === 'string' ? pendingId : undefined;
|
|
226
|
+
}
|
|
227
|
+
recordToolCall(slot, callId) {
|
|
228
|
+
if (typeof callId !== 'string' || !callId) {
|
|
229
|
+
slot.acc.toolCallCount += 1;
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (slot.acc.seenToolCallIds.has(callId))
|
|
233
|
+
return;
|
|
234
|
+
slot.acc.seenToolCallIds.add(callId);
|
|
235
|
+
slot.acc.toolCallCount += 1;
|
|
236
|
+
}
|
|
237
|
+
triggerOriginRole(trigger) {
|
|
238
|
+
const origin = trigger.origin;
|
|
239
|
+
if (!origin?.peerId)
|
|
240
|
+
return undefined;
|
|
241
|
+
if (origin.channelKey === 'daemon')
|
|
242
|
+
return 'owner';
|
|
243
|
+
const channelType = origin.channelType
|
|
244
|
+
?? (origin.channelKey ? channelTypeFromKey(origin.channelKey) : undefined);
|
|
245
|
+
if (!channelType)
|
|
246
|
+
return undefined;
|
|
247
|
+
return resolvePeerRoleDetail({
|
|
248
|
+
selfAid: trigger.agentAid,
|
|
249
|
+
channelKey: origin.channelKey,
|
|
250
|
+
channelType,
|
|
251
|
+
chatType: 'private',
|
|
252
|
+
actorId: origin.peerId,
|
|
253
|
+
conversationId: origin.peerId,
|
|
254
|
+
}).effectiveRole ?? undefined;
|
|
255
|
+
}
|
|
256
|
+
finish(runId, status, metadata) {
|
|
257
|
+
const slot = this.pending.get(runId);
|
|
258
|
+
if (!slot || !this.claimTerminal(slot, status, metadata))
|
|
259
|
+
return;
|
|
260
|
+
this.settleTerminal(runId, slot);
|
|
261
|
+
}
|
|
262
|
+
claimTerminal(slot, outcome, metadata) {
|
|
263
|
+
if (slot.terminalClaim)
|
|
264
|
+
return false;
|
|
265
|
+
slot.terminalClaim = { outcome, metadata };
|
|
266
|
+
if (slot.watchdogTimer)
|
|
267
|
+
clearTimeout(slot.watchdogTimer);
|
|
268
|
+
clearTimeout(slot.totalExecutionTimer);
|
|
269
|
+
if (slot.abortListener)
|
|
270
|
+
slot.abortSignal?.removeEventListener('abort', slot.abortListener);
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
settleTerminal(runId, slot) {
|
|
274
|
+
if (this.pending.get(runId) !== slot || !slot.terminalClaim)
|
|
275
|
+
return;
|
|
276
|
+
this.pending.delete(runId);
|
|
277
|
+
const { outcome: status, metadata } = slot.terminalClaim;
|
|
278
|
+
const durationMs = typeof metadata?.durationMs === 'number'
|
|
279
|
+
? metadata.durationMs
|
|
280
|
+
: Math.max(0, Date.now() - slot.startedAt);
|
|
281
|
+
const completedToolCallCount = typeof metadata?.toolCallCount === 'number' && Number.isFinite(metadata.toolCallCount)
|
|
282
|
+
? Math.max(0, Math.trunc(metadata.toolCallCount))
|
|
283
|
+
: 0;
|
|
284
|
+
const text = slot.acc.text;
|
|
285
|
+
const outcome = status === 'success' && (slot.acc.error || !text.trim()) ? (slot.acc.error ? 'error' : 'noop') : status;
|
|
286
|
+
slot.resolve({
|
|
287
|
+
outcome,
|
|
288
|
+
text,
|
|
289
|
+
files: slot.acc.files,
|
|
290
|
+
error: slot.acc.error,
|
|
291
|
+
...(slot.acc.anomalies.length ? { anomalies: slot.acc.anomalies } : {}),
|
|
292
|
+
meta: {
|
|
293
|
+
runId: slot.runId,
|
|
294
|
+
durationMs,
|
|
295
|
+
numTurns: typeof metadata?.numTurns === 'number' ? metadata.numTurns : undefined,
|
|
296
|
+
tokenUsage: isObject(metadata?.tokenUsage) ? metadata.tokenUsage : undefined,
|
|
297
|
+
contextUsage: metadata?.contextUsage,
|
|
298
|
+
toolCallCount: Math.max(slot.acc.toolCallCount, completedToolCallCount),
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
fail(runId, reason, text) {
|
|
303
|
+
const slot = this.pending.get(runId);
|
|
304
|
+
if (!slot || slot.terminalClaim)
|
|
305
|
+
return;
|
|
306
|
+
slot.acc.error = { reason, text };
|
|
307
|
+
this.finish(runId, 'error');
|
|
308
|
+
}
|
|
309
|
+
watchdogTimeout(runId) {
|
|
310
|
+
const slot = this.pending.get(runId);
|
|
311
|
+
if (!slot || slot.terminalClaim)
|
|
312
|
+
return;
|
|
313
|
+
slot.acc.error = {
|
|
314
|
+
reason: 'daemon_watchdog_timeout',
|
|
315
|
+
text: `daemon conversation watchdog timed out after ${this.watchdogMs}ms`,
|
|
316
|
+
};
|
|
317
|
+
if (!this.claimTerminal(slot, 'error', {
|
|
318
|
+
errorType: 'daemon_watchdog_timeout',
|
|
319
|
+
watchdogMs: this.watchdogMs,
|
|
320
|
+
}))
|
|
321
|
+
return;
|
|
322
|
+
this.cancelDeliveryInBackground(slot);
|
|
323
|
+
this.settleTerminal(runId, slot);
|
|
324
|
+
}
|
|
325
|
+
resetWatchdog(runId, slot) {
|
|
326
|
+
if (slot.waitingForAction || slot.terminalClaim)
|
|
327
|
+
return;
|
|
328
|
+
if (slot.watchdogTimer)
|
|
329
|
+
clearTimeout(slot.watchdogTimer);
|
|
330
|
+
slot.watchdogTimer = setTimeout(() => this.watchdogTimeout(runId), this.watchdogMs);
|
|
331
|
+
slot.watchdogTimer.unref?.();
|
|
332
|
+
}
|
|
333
|
+
totalExecutionTimeout(runId) {
|
|
334
|
+
const slot = this.pending.get(runId);
|
|
335
|
+
if (!slot || slot.terminalClaim)
|
|
336
|
+
return;
|
|
337
|
+
slot.acc.error = {
|
|
338
|
+
reason: 'daemon_total_execution_timeout',
|
|
339
|
+
text: `daemon conversation exceeded total execution limit of ${this.totalExecutionMs}ms`,
|
|
340
|
+
};
|
|
341
|
+
if (!this.claimTerminal(slot, 'timeout', {
|
|
342
|
+
errorType: 'daemon_total_execution_timeout',
|
|
343
|
+
totalExecutionMs: this.totalExecutionMs,
|
|
344
|
+
}))
|
|
345
|
+
return;
|
|
346
|
+
this.cancelDeliveryInBackground(slot);
|
|
347
|
+
this.settleTerminal(runId, slot);
|
|
348
|
+
}
|
|
349
|
+
cancelDeliveryInBackground(slot) {
|
|
350
|
+
const cancellation = this.cancelDelivery(slot.messageId);
|
|
351
|
+
slot.cancellationBarrier = cancellation;
|
|
352
|
+
void cancellation.then(() => undefined, () => undefined);
|
|
353
|
+
}
|
|
354
|
+
async cancelDelivery(messageId) {
|
|
355
|
+
const queue = this.messageQueue;
|
|
356
|
+
if (queue.cancel?.(messageId))
|
|
357
|
+
return;
|
|
358
|
+
if (queue.cancelActiveAndWait) {
|
|
359
|
+
await queue.cancelActiveAndWait(messageId);
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
queue.cancelActive?.(messageId);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
function isObject(value) {
|
|
366
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
367
|
+
}
|
|
368
|
+
function normalizeWatchdogMs(value) {
|
|
369
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0
|
|
370
|
+
? value
|
|
371
|
+
: DEFAULT_WATCHDOG_MS;
|
|
372
|
+
}
|
|
373
|
+
function normalizeTotalExecutionMs(value) {
|
|
374
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0
|
|
375
|
+
? value
|
|
376
|
+
: 60 * 60 * 1000;
|
|
377
|
+
}
|
|
378
|
+
function channelTypeFromKey(channelKey) {
|
|
379
|
+
const idx = channelKey.indexOf('#');
|
|
380
|
+
return idx > 0 ? channelKey.slice(0, idx) : channelKey;
|
|
381
|
+
}
|
|
382
|
+
function normalizeExecutionAnomaly(value) {
|
|
383
|
+
if (!isObject(value))
|
|
384
|
+
return undefined;
|
|
385
|
+
const allowedCodes = new Set([
|
|
386
|
+
'runtime_permission_denied',
|
|
387
|
+
'operation_blocked',
|
|
388
|
+
'capability_unavailable',
|
|
389
|
+
]);
|
|
390
|
+
const code = value.code;
|
|
391
|
+
const effect = value.effect;
|
|
392
|
+
if (typeof code !== 'string' || !allowedCodes.has(code))
|
|
393
|
+
return undefined;
|
|
394
|
+
if (effect !== 'operation_skipped' && effect !== 'fallback_used')
|
|
395
|
+
return undefined;
|
|
396
|
+
const occurredAt = typeof value.occurredAt === 'number' && Number.isFinite(value.occurredAt)
|
|
397
|
+
? value.occurredAt
|
|
398
|
+
: Date.now();
|
|
399
|
+
const toolName = nonEmptyString(value.toolName);
|
|
400
|
+
const requestId = nonEmptyString(value.requestId);
|
|
401
|
+
const policy = normalizeApproverPolicy(value.policy);
|
|
402
|
+
const summary = nonEmptyString(value.summary);
|
|
403
|
+
return {
|
|
404
|
+
code: code,
|
|
405
|
+
severity: 'warning',
|
|
406
|
+
phase: 'execution',
|
|
407
|
+
occurredAt,
|
|
408
|
+
effect,
|
|
409
|
+
...(toolName ? { toolName } : {}),
|
|
410
|
+
...(requestId ? { requestId } : {}),
|
|
411
|
+
...(policy ? { policy } : {}),
|
|
412
|
+
...(summary ? { summary: summary.slice(0, 512) } : {}),
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
function nonEmptyString(value) {
|
|
416
|
+
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
417
|
+
}
|
|
418
|
+
function normalizeApproverPolicy(value) {
|
|
419
|
+
return value === 'requester' || value === 'agent_manager' || value === 'agent_owner'
|
|
420
|
+
? value
|
|
421
|
+
: undefined;
|
|
422
|
+
}
|