evolcore 0.0.50 → 0.0.51
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 +39 -2
- package/bin/ec-build.mjs +60 -0
- package/bin/ecmsg.js +65 -63
- package/dist/ability/caller/command.js +24 -15
- package/dist/ability/caller/contract.js +24 -9
- package/dist/ability/caller/credential-files.js +132 -0
- package/dist/ability/caller/daemon.js +32 -7
- package/dist/ability/caller/schema-view.js +157 -0
- package/dist/ability/caller/service.js +202 -63
- package/dist/ability/interop-v1.js +156 -113
- package/dist/agent-template/jobs.js +14 -110
- package/dist/agent-template/runtime.js +331 -193
- package/dist/agent-template/service.js +1029 -1104
- package/dist/agent-template/share.js +103 -0
- package/dist/agent-template/tool-runner.js +25 -0
- package/dist/agent-template/types.js +10 -3
- package/dist/agents/claude/availability.js +94 -0
- package/dist/agents/claude/capability-provider.js +154 -0
- package/dist/agents/claude/index.js +145 -0
- package/dist/agents/{claude-runner.js → claude/runner.js} +74 -158
- package/dist/agents/claude/session-file-adapter.js +246 -0
- package/dist/agents/codex/app-server-client.js +90 -10
- package/dist/agents/codex/availability.js +164 -0
- package/dist/agents/codex/capability-provider.js +138 -0
- package/dist/agents/codex/cli.js +38 -0
- package/dist/agents/codex/index.js +345 -0
- package/dist/agents/codex/mcp-elicitation.js +135 -0
- package/dist/agents/{codex-runner.js → codex/runner.js} +648 -382
- package/dist/agents/codex/session-file-adapter.js +834 -0
- package/dist/agents/dsh/availability.js +28 -0
- package/dist/agents/dsh/capability-provider.js +56 -0
- package/dist/agents/dsh/desktop-locations.ps1 +66 -0
- package/dist/agents/dsh/desktop-probe.cjs +37 -0
- package/dist/agents/dsh/index.js +98 -0
- package/dist/agents/dsh/installation.js +400 -0
- package/dist/agents/dsh/resources.js +755 -0
- package/dist/agents/dsh/runner.js +1183 -0
- package/dist/agents/dsh/runtime/README.md +243 -0
- package/dist/agents/dsh/runtime/authorization.js +23 -0
- package/dist/agents/dsh/runtime/bridge.js +837 -0
- package/dist/agents/dsh/runtime/config.js +271 -0
- package/dist/agents/dsh/runtime/entry.js +229 -0
- package/dist/agents/dsh/runtime/session-inspector.js +340 -0
- package/dist/agents/dsh/runtime/tool-policy.js +49 -0
- package/dist/agents/dsh/session-file-adapter.js +145 -0
- package/dist/agents/ecagent/index.js +215 -0
- package/dist/agents/{ecagent-runner.js → ecagent/runner.js} +592 -106
- package/dist/agents/ecagent/session-file-adapter.js +134 -0
- package/dist/agents/gemini/index.js +55 -10
- package/dist/agents/gemini/{gemini-runner.js → runner.js} +4 -9
- package/dist/aun/ability-device-routing.js +11 -17
- package/dist/aun/aid/agentmd.js +27 -1
- package/dist/aun/aid/managed-operation.js +6 -4
- package/dist/aun/group/invite-service.js +1 -1
- package/dist/aun/menu/client.js +1 -1
- package/dist/aun/msg/history.js +1 -1
- package/dist/aun/msg/managed-operation.js +93 -21
- package/dist/aun/msg/p2p.js +6 -6
- package/dist/aun/service-proxy.js +1 -1
- package/dist/aun/storage/index.js +242 -0
- package/dist/build-identity.json +1 -1
- package/dist/channels/aun.js +180 -43
- package/dist/channels/daemon.js +3 -2
- package/dist/channels/dingtalk.js +1 -1
- package/dist/channels/feishu.js +9 -9
- package/dist/channels/qqbot.js +1 -1
- package/dist/channels/wechat.js +2 -2
- package/dist/channels/wecom.js +1 -1
- package/dist/{agents/claude-gateway → claude-gateway}/agent-registration.js +13 -13
- package/dist/{agents/claude-gateway → claude-gateway}/binding.js +3 -3
- package/dist/{agents/claude-gateway → claude-gateway}/inbox.js +1 -1
- package/dist/{agents/claude-gateway → claude-gateway}/index.js +2 -2
- package/dist/{agents/claude-gateway → claude-gateway}/listing.js +3 -3
- package/dist/{agents/claude-gateway → claude-gateway}/router.js +4 -4
- package/dist/{agents/claude-gateway → claude-gateway}/sessions.js +2 -2
- package/dist/{agents/claude-gateway → claude-gateway}/terminal.js +1 -1
- package/dist/{agents/claude-gateway → claude-gateway}/transcript.js +1 -1
- package/dist/cli/ability-command.js +8 -5
- package/dist/cli/ability-output.js +182 -0
- package/dist/cli/agent-command.js +1 -1
- package/dist/cli/agent-create.js +123 -42
- package/dist/cli/agent-template.js +400 -29
- package/dist/cli/agent.js +14 -11
- package/dist/cli/aun-commands.js +167 -111
- package/dist/cli/daemon-commands.js +38 -8
- package/dist/cli/data-command.js +1 -1
- package/dist/cli/debug-mode.js +9 -0
- package/dist/cli/directory.js +1 -2
- package/dist/cli/ecmsg-gateway.js +55 -19
- package/dist/cli/fs-command.js +67 -39
- package/dist/cli/index.js +25 -11
- package/dist/cli/init.js +124 -29
- package/dist/cli/managed-command-guard.js +2 -0
- package/dist/cli/model.js +1 -1
- package/dist/cli/restart-monitor.js +2 -2
- package/dist/cli/services-command.js +24 -1
- package/dist/cli/skill-command.js +4 -4
- package/dist/cli/task-context.js +24 -14
- package/dist/cli/team-workspace-command.js +50 -52
- package/dist/cli/thread-command.js +3 -2
- package/dist/cli/trigger-command.js +47 -12
- package/dist/cli/watch-logs.js +2 -1
- package/dist/config/boot-log.js +3 -0
- package/dist/config/builtin-role-templates.js +1 -1
- package/dist/config/config-field-policy.js +10 -6
- package/dist/config/config-manager.js +33 -12
- package/dist/config/gateway-config.js +21 -37
- package/dist/config/invoke-ipc-service.js +1 -1
- package/dist/config/owner-config.js +5 -3
- package/dist/config/peer-book-store.js +2 -3
- package/dist/config/peer-book.js +2 -2
- package/dist/config/peer-role-resolver.js +2 -2
- package/dist/config/provider-identity-migration.js +24 -105
- package/dist/config/provider-ipc-service.js +13 -3
- package/dist/config/provider-local-sync.js +4 -1
- package/dist/config/provider-menu-request.js +21 -3
- package/dist/config/provider-templates.js +1 -1
- package/dist/config/providers-config.js +39 -15
- package/dist/config/providers-import.js +3 -3
- package/dist/config/providers-management.js +74 -99
- package/dist/config/schema-migration.js +177 -11
- package/dist/config/schema-registry.js +1 -1
- package/dist/config-store.js +38 -50
- package/dist/core/{agent-application-service.js → agent/agent-application-service.js} +9 -9
- package/dist/core/{agent-create-status.js → agent/agent-create-status.js} +112 -4
- package/dist/core/{agent-creation-claim.js → agent/agent-creation-claim.js} +3 -3
- package/dist/core/{agent-ipc-registration.js → agent/agent-ipc-registration.js} +102 -25
- package/dist/core/{agent-reload-coordinator.js → agent/agent-reload-coordinator.js} +61 -1
- package/dist/core/{agent-runtime.js → agent/agent-runtime.js} +53 -27
- package/dist/core/{evolagent-registry.js → agent/evolagent-registry.js} +12 -12
- package/dist/core/{evolagent.js → agent/evolagent.js} +11 -11
- package/dist/core/auth/agent-delegation.js +1 -8
- package/dist/core/auth/delegation-authorization.js +28 -0
- package/dist/core/auth/operation-authorizer.js +7 -4
- package/dist/core/auth/operation-catalog.js +34 -5
- package/dist/core/baseagent/baseagent-availability.js +197 -0
- package/dist/core/baseagent/baseagent-capability-adapter.js +288 -0
- package/dist/core/baseagent/baseagent-config-shared.js +56 -0
- package/dist/core/baseagent/baseagent-identity.js +68 -0
- package/dist/core/{baseagent-loader.js → baseagent/baseagent-loader.js} +62 -6
- package/dist/core/baseagent/baseagent-model-defaults.js +26 -0
- package/dist/{agents → core/baseagent}/baseagent-plugin-descriptor.js +107 -24
- package/dist/core/baseagent/baseagent-plugin-loader.js +367 -0
- package/dist/core/baseagent/baseagent.js +157 -0
- package/dist/{agents → core/baseagent}/runner-types.js +36 -4
- package/dist/core/capability/capability-manager.js +79 -30
- package/dist/core/capability/providers/claude-capability-provider.js +2 -154
- package/dist/core/capability/providers/codex-capability-provider.js +2 -136
- package/dist/core/{channel-loader.js → channel/channel-loader.js} +226 -38
- package/dist/core/{channel-runtime.js → channel/channel-runtime.js} +18 -18
- package/dist/core/command/agent-control.js +60 -15
- package/dist/core/command/agent-template-menu.js +21 -9
- package/dist/core/command/agentmd-menu-request.js +19 -8
- package/dist/core/command/agentmd-menu.js +14 -5
- package/dist/core/command/command-handler.js +127 -57
- package/dist/core/command/context-policy-menu.js +122 -0
- package/dist/core/command/data-root-resolver.js +157 -20
- package/dist/core/command/memory-slash.js +6 -6
- package/dist/core/command/menu-catalog.js +80 -20
- package/dist/core/command/menu-handler.js +305 -25
- package/dist/core/command/menu-protocol.js +42 -8
- package/dist/core/command/menu-query-batch.js +9 -5
- package/dist/core/command/provider-menu.js +7 -11
- package/dist/core/command/role-menu.js +1 -1
- package/dist/core/command/skill-slash.js +17 -5
- package/dist/core/command/slash-gate.js +2 -4
- package/dist/core/command/slash-handler.js +127 -96
- package/dist/core/command/team-workspace-team.js +3 -3
- package/dist/core/command/topic-slash.js +10 -10
- package/dist/core/{daemon-bootstrap.js → daemon/daemon-bootstrap.js} +14 -14
- package/dist/core/{daemon-control.js → daemon/daemon-control.js} +46 -20
- package/dist/core/{daemon-lifecycle.js → daemon/daemon-lifecycle.js} +15 -15
- package/dist/core/{host-snapshot.js → daemon/host-snapshot.js} +3 -3
- package/dist/core/{ipc-registration.js → daemon/ipc-registration.js} +98 -38
- package/dist/core/{lifecycle-notice.js → daemon/lifecycle-notice.js} +4 -5
- package/dist/core/file-integrity/store.js +1 -1
- package/dist/core/handoff/ipc-registration.js +3 -3
- package/dist/core/handoff/runtime.js +1 -1
- package/dist/{agents → core/inference}/request-identity.js +2 -2
- package/dist/core/inference/text-inference.js +4 -4
- package/dist/core/{bootstrap-messages.js → initialization/bootstrap-messages.js} +10 -10
- package/dist/core/{bootstrap-service.js → initialization/bootstrap-service.js} +24 -23
- package/dist/core/initialization/service.js +54 -9
- package/dist/core/invoke/executors/media.js +1 -1
- package/dist/core/invoke/executors/text.js +1 -1
- package/dist/core/memory/consolidation-context.js +1 -1
- package/dist/core/memory/consolidation-trigger.js +9 -3
- package/dist/core/memory/consolidation.js +4 -4
- package/dist/core/memory/memory-admin.js +6 -6
- package/dist/core/memory/memory-writer.js +1 -1
- package/dist/core/memory/relation-idle-monitor.js +1 -1
- package/dist/core/message/aun-ipc-sender.js +114 -75
- package/dist/core/message/aun-request-registry.js +13 -5
- package/dist/core/message/auto-mention-gate.js +1 -1
- package/dist/core/message/contact-admission.js +1 -1
- package/dist/core/message/im-renderer.js +19 -0
- package/dist/core/{interaction-router.js → message/interaction-router.js} +4 -4
- package/dist/core/message/items-formatter.js +5 -5
- package/dist/core/message/message-admission.js +1 -1
- package/dist/core/message/message-bridge.js +135 -54
- package/dist/core/message/message-queue.js +83 -4
- package/dist/core/message/message-utils.js +1 -1
- package/dist/core/message/peer-mode.js +1 -1
- package/dist/core/message/response-engine.js +347 -163
- package/dist/core/message/send-options.js +9 -6
- package/dist/core/message/send-routing.js +45 -109
- package/dist/core/message/stream-idle-monitor.js +1 -1
- package/dist/core/{data-migration.js → migration/data-migration.js} +29 -1
- package/dist/core/model/catalog-service.js +29 -8
- package/dist/core/model/model-capabilities.js +88 -0
- package/dist/core/model/model-catalog.js +14 -3
- package/dist/core/model/model-diagnostics.js +4 -4
- package/dist/core/ownership/owner-resolver.js +95 -15
- package/dist/core/{pack-auth.js → pack/pack-auth.js} +30 -3
- package/dist/core/{pack-install.js → pack/pack-install.js} +95 -17
- package/dist/core/permission/approval-gateway.js +9 -18
- package/dist/core/permission/ec-command-parser.js +70 -34
- package/dist/core/permission/managed-file.js +234 -0
- package/dist/core/permission/protected-paths.js +56 -0
- package/dist/core/permission/sandbox-runtime.js +267 -3
- package/dist/core/permission/session-path-grants.js +1 -1
- package/dist/core/permission/shell-environment.js +15 -1
- package/dist/core/plugin/plugin-lifecycle.js +442 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +2 -246
- package/dist/core/session/adapters/codex-session-file-adapter.js +2 -566
- package/dist/core/session/adapters/ecagent-session-file-adapter.js +2 -134
- package/dist/core/{background-session → session/background}/session-cleanup.js +2 -2
- package/dist/core/{background-session → session/background}/types.js +1 -1
- package/dist/core/session/session-file-health.js +2 -272
- package/dist/core/session/session-idle-monitor.js +1 -1
- package/dist/core/session/session-manager.js +29 -2
- package/dist/core/session/session-terminal.js +185 -0
- package/dist/core/session/session-title.js +8 -11
- package/dist/core/{system-session → session/system}/memory.js +43 -9
- package/dist/core/{system-session → session/system}/registry.js +1 -1
- package/dist/core/{system-session → session/system}/types.js +1 -1
- package/dist/core/skill/index-generator.js +1 -0
- package/dist/core/task/task-activity-store.js +112 -0
- package/dist/core/task/task-recovery-service.js +2 -2
- package/dist/core/thread/ipc-operation.js +2 -2
- package/dist/core/thread/thread-operation.js +2 -1
- package/dist/core/thread/thread-route.js +5 -3
- package/dist/core/thread/thread-service.js +14 -4
- package/dist/directory/{owner-directory-admission.js → admission.js} +3 -3
- package/dist/directory/{owner-directory-cache.js → cache.js} +90 -8
- package/dist/directory/{owner-directory-markdown.js → markdown.js} +2 -2
- package/dist/directory/{owner-directory-query-operation.js → query-operation.js} +83 -9
- package/dist/directory/{owner-directory-search.js → search.js} +50 -2
- package/dist/directory/{owner-directory-store.js → store.js} +2 -2
- package/dist/eck/kit-renderer.js +1 -1
- package/dist/eck/manifest-engine.js +64 -2
- package/dist/eck/message-renderer.js +35 -0
- package/dist/ecweb/basic-settings-service.js +9 -3
- package/dist/{contracts → ecweb/contracts}/ecweb-service-protocol.js +2 -1
- package/dist/ecweb/dsh-native-service.js +413 -0
- package/dist/ecweb/providers-service.js +1 -1
- package/dist/ecweb/runtime/lifecycle.js +1 -1
- package/dist/ecweb/runtime/supervisor.js +1 -1
- package/dist/event-center/center-config.js +2 -2
- package/dist/event-center/dispatcher.js +1 -1
- package/dist/event-center/ipc-operation.js +12 -3
- package/dist/event-center/pack-loader.js +2 -2
- package/dist/event-center/registry.js +6 -6
- package/dist/event-center/runtime.js +2 -2
- package/dist/index.js +71 -42
- package/dist/ipc.js +103 -10
- package/dist/outputs/authorization.js +27 -0
- package/dist/outputs/events.js +10 -1
- package/dist/outputs/panel-cards.js +960 -0
- package/dist/paths.js +12 -0
- package/dist/pay/command.js +1 -1
- package/dist/pay/runtime.js +18 -10
- package/dist/response-system/engines/v1/proactive-flow.js +1 -1
- package/dist/services/dispatcher.js +2 -2
- package/dist/services/host/main.js +10 -1
- package/dist/services/host/protocol.js +9 -2
- package/dist/services/host/resident.js +37 -0
- package/dist/services/host-client.js +12 -0
- package/dist/services/host-recycle.js +8 -3
- package/dist/services/host-runtime.js +54 -15
- package/dist/services/index.js +83 -19
- package/dist/services/ipc-operation.js +303 -38
- package/dist/services/pack-manager.js +2 -2
- package/dist/services/router.js +43 -3
- package/dist/services/script-runner.js +34 -25
- package/dist/services/service-payload.js +28 -1
- package/dist/services/validation.js +28 -2
- package/dist/stats/context-usage.js +110 -0
- package/dist/stats/model-resolver.js +103 -17
- package/dist/stats/query.js +5 -0
- package/dist/trigger/application-service.js +3 -2
- package/dist/trigger/authorization.js +36 -33
- package/dist/trigger/ipc-service.js +4 -4
- package/dist/trigger/local-files.js +8 -176
- package/dist/trigger/manager.js +2 -2
- package/dist/trigger/parser.js +48 -0
- package/dist/trigger/scheduler.js +14 -2
- package/dist/trigger/script-executor.js +21 -0
- package/dist/trigger/script-sandbox.js +57 -243
- package/dist/trigger/system-definitions.js +25 -0
- package/dist/trigger/validation.js +1 -1
- package/dist/utils/atomic-write.js +88 -1
- package/dist/utils/cross-platform.js +4 -42
- package/dist/utils/error-dict.json +22 -1
- package/dist/utils/error-utils.js +193 -6
- package/dist/utils/evolcore-version.js +2 -2
- package/dist/utils/host-info.js +1 -1
- package/dist/utils/logger.js +3 -1
- package/dist/utils/media-cache.js +99 -4
- package/dist/utils/startup-trace.js +20 -4
- package/dist/utils/welcome.js +64 -20
- package/ecagent/README.md +35 -0
- package/ecagent/dist/agent-loop.js +80 -30
- package/ecagent/dist/harness/env/nodejs.d.ts +16 -0
- package/ecagent/dist/harness/env/nodejs.js +49 -20
- package/ecagent/dist/harness/messages.js +3 -2
- package/ecagent/dist/harness/types.d.ts +1 -0
- package/ecagent/dist/runtime/types.d.ts +2 -0
- package/ecagent/dist/runtime/utils/validation.d.ts +7 -1
- package/ecagent/dist/runtime/utils/validation.js +42 -0
- package/ecagent/dist/types.d.ts +2 -0
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/channels/feishu.md +1 -1
- package/kits/docs/evolcore/INDEX.md +10 -7
- package/kits/docs/evolcore/agent-create.md +2 -0
- package/kits/docs/evolcore/agent.md +100 -13
- package/kits/docs/evolcore/aid.md +19 -3
- package/kits/docs/evolcore/config.md +94 -0
- package/kits/docs/evolcore/ctl.md +2 -1
- package/kits/docs/evolcore/ec-capabilities.md +7 -10
- package/kits/docs/evolcore/ecweb-lifecycle.md +5 -1
- package/kits/docs/evolcore/event.md +1 -1
- package/kits/docs/evolcore/fs.md +49 -3
- package/kits/docs/evolcore/group.md +3 -3
- package/kits/docs/evolcore/memory-consolidation.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +24 -2
- package/kits/docs/evolcore/model.md +9 -1
- package/kits/docs/evolcore/msg.md +30 -28
- package/kits/docs/evolcore/pay.md +8 -20
- package/kits/docs/evolcore/plugin.md +74 -0
- package/kits/docs/evolcore/provider.md +8 -2
- package/kits/docs/evolcore/rpc.md +2 -2
- package/kits/docs/evolcore/skill.md +17 -1
- package/kits/docs/evolcore/stats.md +5 -0
- package/kits/docs/evolcore/storage.md +22 -0
- package/kits/docs/evolcore/thread-chain.md +19 -10
- package/kits/docs/evolcore/tool-authorization.md +4 -0
- package/kits/docs/evolcore/trigger.md +89 -13
- package/kits/docs/identity/AID_PROFILE_SPEC.md +1 -1
- package/kits/docs/venues/feishu-group.md +3 -2
- package/kits/docs/venues/feishu-private.md +3 -2
- package/kits/rules/02-navigation.md +20 -13
- package/kits/rules/06-channel.md +18 -2
- package/kits/schemas/_meta.json +8 -4
- package/kits/schemas/agent-config.schema.23.json +19 -3
- package/kits/schemas/agent-config.schema.24.json +986 -0
- package/kits/schemas/agent-config.schema.25.json +986 -0
- package/kits/schemas/daemon.schema.11.json +487 -0
- package/kits/schemas/daemon.schema.12.json +505 -0
- package/kits/schemas/defaults.schema.8.json +484 -0
- package/kits/schemas/providers.schema.1.json +1 -1
- package/kits/schemas/providers.schema.2.json +1 -1
- package/kits/schemas/providers.schema.3.json +8 -2
- package/kits/skills/.switches.json +4 -0
- package/kits/skills/ability/SKILL.md +194 -27
- package/kits/skills/ability/STRUCTURE.md +5 -0
- package/kits/skills/agent-output-cards/SKILL.md +90 -54
- package/kits/skills/agent-output-cards/examples/html-surface.json +11 -0
- package/kits/skills/agent-output-cards/examples/meeting-followups.json +16 -0
- package/kits/skills/agent-output-cards/examples/meeting-latest.json +24 -0
- package/kits/skills/agent-output-cards/examples/project-metrics.json +16 -0
- package/kits/skills/agent-output-cards/examples/quick-links.json +18 -0
- package/kits/skills/agent-output-cards/examples/surface.html +8 -0
- package/kits/skills/agent-template-project/SKILL.md +51 -0
- package/kits/skills/agent-template-project/references/01-collect-and-pack.md +174 -0
- package/kits/skills/agent-template-project/references/02-upload-and-share.md +109 -0
- package/kits/skills/agent-template-project/references/03-download-and-install.md +189 -0
- package/kits/skills/agent-template-project/references/04-upgrade-and-recovery.md +74 -0
- package/kits/skills/agent-template-project/references/05-publish-to-platform.md +62 -0
- package/kits/skills/ec-group/SKILL.md +3 -3
- package/kits/skills/ec-group-collaboration/SKILL.md +4 -4
- package/kits/skills/ec-identity/SKILL.md +9 -6
- package/kits/skills/ec-pay/SKILL.md +163 -41
- package/kits/skills/ec-provider/SKILL.md +5 -5
- package/kits/skills/ec-service-call/SKILL.md +3 -0
- package/kits/skills/ec-skill/SKILL.md +25 -9
- package/kits/skills/ec-skill/scripts/cli.mjs +7 -7
- package/kits/skills/ec-skill/scripts/skill.mjs +55 -41
- package/kits/skills/ec-skill/scripts/template/SKILL.md.tmpl +9 -0
- package/kits/skills/ec-trigger/SKILL.md +2 -2
- package/kits/skills/personal-assistant/SKILL.md +22 -22
- package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +1 -1
- package/kits/skills/scrapling-article-fetch/SKILL.md +5 -5
- package/kits/skills/thread-ops/SKILL.md +19 -9
- package/kits/skills/wechat-article-media-download/SKILL.md +2 -2
- package/kits/skills/wechat-article-reader/SKILL.md +2 -2
- package/kits/templates/system-fragments/commands.md +1 -1
- package/kits/templates/system-fragments/personal-assistant.md +2 -2
- package/kits/templates/system-fragments/reply.md +14 -9
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +10 -5
- package/package.json +6 -5
- package/scripts/agent-template/index.mjs +7 -1
- package/scripts/agent-template/inspect.mjs +81 -35
- package/scripts/agent-template/overlay.mjs +110 -4
- package/scripts/agent-template/shared/common.mjs +36 -4
- package/scripts/agent-template/shared/plan.mjs +4 -2
- package/scripts/agent-template/shared/service-packs.mjs +104 -0
- package/scripts/agent-template/shared/team-schema.json +467 -54
- package/scripts/agent-template/shared/template-contract.mjs +70 -68
- package/scripts/agent-template/shared/template-package.mjs +153 -36
- package/scripts/agent-template/shared/template-runtime.mjs +76 -64
- package/scripts/agent-template/shared/template.mjs +11 -46
- package/scripts/agent-template/team-pack.mjs +451 -35
- package/scripts/agent-template/team-preview.mjs +75 -226
- package/scripts/aid-batch/identity-batch.mjs +1 -1
- package/dist/agents/baseagent-availability.js +0 -176
- package/dist/agents/baseagent-capability-adapter.js +0 -102
- package/dist/agents/baseagent-plugin-loader.js +0 -145
- package/dist/agents/baseagent.js +0 -816
- package/dist/agents/codex/catalog.js +0 -80
- package/dist/agents/ecagent-plugin-lazy.js +0 -41
- package/dist/agents/tool-time-context.js +0 -55
- package/dist/core/legacy-rename.js +0 -41
- package/dist/core/plugin-lifecycle.js +0 -137
- package/dist/core/rate-window.js +0 -53
- package/dist/core/runner-reload-transaction.js +0 -60
- package/dist/core/runtime-lock.js +0 -90
- package/dist/core/soul.js +0 -66
- package/dist/core/system-session/grants.js +0 -40
- package/dist/directory/owner-directory-agentmd-sync.js +0 -89
- package/dist/directory/owner-directory-request-operation.js +0 -79
- package/dist/directory/owner-directory-text.js +0 -60
- package/kits/skills/ec-pay/references/pay-cli.md +0 -110
- /package/dist/agents/gemini/{gemini-capability-provider.js → capability-provider.js} +0 -0
- /package/dist/agents/gemini/{gemini-session-file-adapter.js → session-file-adapter.js} +0 -0
- /package/dist/{agents/claude-gateway → claude-gateway}/types.js +0 -0
- /package/dist/core/{system-channels.js → channel/system-channels.js} +0 -0
- /package/dist/core/{daemon-file-cache.js → daemon/daemon-file-cache.js} +0 -0
- /package/dist/core/{event-bus.js → event/event-bus.js} +0 -0
- /package/dist/core/{event-catalog.js → event/event-catalog.js} +0 -0
- /package/dist/core/{pack-ledger.js → pack/pack-ledger.js} +0 -0
- /package/dist/directory/{owner-directory-identity.js → identity.js} +0 -0
- /package/dist/directory/{owner-directory-policy.js → policy.js} +0 -0
- /package/dist/directory/{owner-directory-remarks.js → remarks.js} +0 -0
- /package/dist/directory/{owner-directory-scope.js → scope.js} +0 -0
- /package/dist/{contracts → ecweb/contracts}/ecweb-instance.js +0 -0
- /package/kits/templates/{bootstrap-welcome.md → bootstrap-intro.md} +0 -0
|
@@ -1,69 +1,147 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { MAIN_CLI_BIN } from '../product.js';
|
|
2
3
|
import { loadDefaults } from '../config-store.js';
|
|
3
|
-
import { currentVersion } from '../config/schema-registry.js';
|
|
4
|
+
import { currentVersion, loadSchema } from '../config/schema-registry.js';
|
|
5
|
+
import { mergeLayers } from '../config/merge.js';
|
|
4
6
|
import { aidLocalDir, agentConfig } from '../paths.js';
|
|
5
7
|
import { isValidAid } from '../aun/aid/validation.js';
|
|
6
8
|
import { isHClassPath, isLClassPath } from '../core/permission/protected-paths.js';
|
|
7
|
-
import { claimAgentCreation, readAgentCreationClaim, removeAgentCreationClaim } from '../core/agent-creation-claim.js';
|
|
8
|
-
import { initializationFingerprintV2, readInitialization, validateInitializationPlan
|
|
9
|
-
import { checkInitializationOwner } from '../core/agent-runtime.js';
|
|
10
|
-
import { liveOwnerDirectoryCache, readOwnerDirectoryMembership } from '../directory/
|
|
9
|
+
import { claimAgentCreation, readAgentCreationClaim, removeAgentCreationClaim } from '../core/agent/agent-creation-claim.js';
|
|
10
|
+
import { initializationFingerprintV2, readInitialization, validateInitializationPlan } from '../cli/agent-create.js';
|
|
11
|
+
import { checkInitializationOwner } from '../core/agent/agent-runtime.js';
|
|
12
|
+
import { liveOwnerDirectoryCache, readOwnerDirectoryMembership } from '../directory/admission.js';
|
|
11
13
|
import { findProcessesWithCommandLine, killProcess, isProcessRunning } from '../utils/cross-platform.js';
|
|
12
14
|
import fs from 'node:fs';
|
|
13
15
|
import path from 'node:path';
|
|
14
16
|
import { createHash } from 'node:crypto';
|
|
15
17
|
import { stringify } from 'yaml';
|
|
16
18
|
import { validateAgentMdDocument, StorageLowLevel, StorageVFS } from '@agentunion/fastaun';
|
|
17
|
-
import { listSupportedBaseagents, resolveBaseagentModelSelection, resolveLegacyBaseagentModelSelection } from '../
|
|
19
|
+
import { listSupportedBaseagents, resolveBaseagentModelSelection, resolveLegacyBaseagentModelSelection } from '../core/baseagent/baseagent.js';
|
|
18
20
|
import { ownerResolver, getDaemonOwners } from '../core/ownership/owner-resolver.js';
|
|
19
21
|
import { resolvePaths, getPackageRoot } from '../paths.js';
|
|
20
22
|
import { loadAgent, loadDaemonConfig } from '../config-store.js';
|
|
21
|
-
import { resolveEffective, notifyConfigWrite, ConfigTarget } from '../config/config-manager.js';
|
|
23
|
+
import { resolveEffective, normalizeDefaultsBehaviorCompat, notifyConfigWrite, ConfigTarget } from '../config/config-manager.js';
|
|
22
24
|
import { readProvidersSnapshot } from '../config/providers-management.js';
|
|
23
25
|
import { resolveProviderId } from '../config/providers-config.js';
|
|
24
26
|
import { resolveAllSkillStates } from '../core/skill/switch-resolver.js';
|
|
25
27
|
import { agentmdGet, agentmdUpdate } from '../aun/aid/agentmd.js';
|
|
26
28
|
import { getProviderCatalog, assertCatalogSelectable, resolveCatalogModel, catalogEfforts } from '../core/model/model-catalog.js';
|
|
27
29
|
import { AgentTemplateService } from './service.js';
|
|
28
|
-
import { templateError, templateJobAids } from './types.js';
|
|
30
|
+
import { templateError, templateJobAids, templateOwnerRequiredError } from './types.js';
|
|
29
31
|
import { refreshSkillIndex } from '../core/skill/startup.js';
|
|
30
32
|
import { TemplateJobs, templateFingerprint, writeTemplateState, assertTemplateInstallationReady, templateInstallationGate } from './jobs.js';
|
|
31
33
|
import { getAidStore, loadClient } from '../aun/aid/store.js';
|
|
32
34
|
import { creationOwnershipBinding } from '../core/ownership/owner-resolver.js';
|
|
33
|
-
import { readTeamMembersState, mutateTeamMembers } from '../core/command/team-workspace-team.js';
|
|
34
|
-
import { logger } from '../utils/logger.js';
|
|
35
35
|
import { getAunRequestRegistry } from '../core/message/aun-request-registry.js';
|
|
36
36
|
import { withFileLock } from '../utils/atomic-write.js';
|
|
37
|
+
import { executeStorageShare } from '../aun/storage/index.js';
|
|
37
38
|
import * as outbox from '../aun/outbox.js';
|
|
38
39
|
const publicTemplate = await import(new URL('../../scripts/agent-template/shared/template-runtime.mjs', import.meta.url).href);
|
|
40
|
+
/** Resolve recommendations against this host before freezing installation writes. */
|
|
41
|
+
export async function resolveTemplateModelRecommendations(input) {
|
|
42
|
+
const { config, providers, defaults, local } = input;
|
|
43
|
+
const baseagent = config.active_baseagent ?? local?.active_baseagent ?? defaults.active_baseagent ?? 'claude';
|
|
44
|
+
const block = config.baseagents?.[baseagent] ?? {};
|
|
45
|
+
const selections = structuredClone(input.selections);
|
|
46
|
+
const explicit = input.selections[baseagent] ?? {};
|
|
47
|
+
const suggested = { provider: typeof block.provider === 'string' ? block.provider : block.provider?.id,
|
|
48
|
+
model: block.model, effort: block.effort };
|
|
49
|
+
const host = defaults.baseagents?.[baseagent] ?? {};
|
|
50
|
+
const current = local?.baseagents?.[baseagent] ?? {};
|
|
51
|
+
const usable = (id) => publicTemplate.providerUsable(providers, id, baseagent);
|
|
52
|
+
let fallback = usable(current.provider) ? current : host;
|
|
53
|
+
const warnings = [];
|
|
54
|
+
const warn = (field, from, to, reason) => {
|
|
55
|
+
if (from !== undefined && from !== to)
|
|
56
|
+
warnings.push({ code: 'TEMPLATE_MODEL_FALLBACK', baseagent, field,
|
|
57
|
+
suggested: from, selected: to ?? null, message: reason });
|
|
58
|
+
};
|
|
59
|
+
const catalogs = new Map();
|
|
60
|
+
const catalogFor = async (id) => {
|
|
61
|
+
if (!usable(id))
|
|
62
|
+
return undefined;
|
|
63
|
+
if (!catalogs.has(id)) {
|
|
64
|
+
try {
|
|
65
|
+
const catalog = await getProviderCatalog(id, undefined, false, false, baseagent);
|
|
66
|
+
assertCatalogSelectable(catalog);
|
|
67
|
+
catalogs.set(id, catalog);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
catalogs.set(id, undefined);
|
|
71
|
+
} // Final validation retains actionable connection errors.
|
|
72
|
+
}
|
|
73
|
+
return catalogs.get(id);
|
|
74
|
+
};
|
|
75
|
+
const hasModel = (catalog, model) => typeof model === 'string' && !!catalog?.models.some(entry => entry.id === model || entry.id === resolveCatalogModel(catalog, model));
|
|
76
|
+
if (fallback === current && !await catalogFor(current.provider) && usable(host.provider))
|
|
77
|
+
fallback = host;
|
|
78
|
+
let provider = explicit.provider ?? (input.preferLocal && usable(current.provider) ? current.provider
|
|
79
|
+
: usable(suggested.provider) ? suggested.provider : fallback.provider);
|
|
80
|
+
let catalog = await catalogFor(provider);
|
|
81
|
+
if (!catalog && provider !== fallback.provider && usable(fallback.provider)) {
|
|
82
|
+
provider = fallback.provider;
|
|
83
|
+
catalog = await catalogFor(provider);
|
|
84
|
+
}
|
|
85
|
+
if (!catalog)
|
|
86
|
+
provider = null;
|
|
87
|
+
let model = Object.hasOwn(explicit, 'model') ? explicit.model : suggested.model;
|
|
88
|
+
if (explicit.model !== undefined && !hasModel(catalog, model)
|
|
89
|
+
&& provider !== fallback.provider && usable(fallback.provider)) {
|
|
90
|
+
const fallbackCatalog = await catalogFor(fallback.provider);
|
|
91
|
+
if (hasModel(fallbackCatalog, model)) {
|
|
92
|
+
provider = fallback.provider;
|
|
93
|
+
catalog = fallbackCatalog;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (model !== null && !hasModel(catalog, model)) {
|
|
97
|
+
const defaultModel = [current, host].find(candidate => candidate.provider === provider && hasModel(catalog, candidate.model))?.model
|
|
98
|
+
?? (hasModel(catalog, fallback.model) ? fallback.model : undefined);
|
|
99
|
+
if (defaultModel)
|
|
100
|
+
model = defaultModel;
|
|
101
|
+
else if (provider !== fallback.provider && usable(fallback.provider)) {
|
|
102
|
+
const fallbackCatalog = await catalogFor(fallback.provider);
|
|
103
|
+
if (hasModel(fallbackCatalog, fallback.model)) {
|
|
104
|
+
provider = fallback.provider;
|
|
105
|
+
catalog = fallbackCatalog;
|
|
106
|
+
model = fallback.model;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// With no configured model, keep the host runner's model discovery instead of the package value.
|
|
110
|
+
if (!hasModel(catalog, model))
|
|
111
|
+
model = null;
|
|
112
|
+
}
|
|
113
|
+
const efforts = model && catalog ? catalogEfforts(catalog, model, baseagent) : [];
|
|
114
|
+
let effort = Object.hasOwn(explicit, 'effort') ? explicit.effort : suggested.effort;
|
|
115
|
+
if (effort !== null && (effort === undefined || !efforts.includes(effort))) {
|
|
116
|
+
const defaultEffort = [current, host].find(candidate => candidate.provider === provider
|
|
117
|
+
&& candidate.model === model && efforts.includes(candidate.effort))?.effort;
|
|
118
|
+
const inherited = [current, host].find(candidate => candidate.effort !== undefined)?.effort;
|
|
119
|
+
const definition = catalog?.models.find(entry => entry.id === resolveCatalogModel(catalog, model));
|
|
120
|
+
effort = defaultEffort ?? (inherited && !efforts.includes(inherited)
|
|
121
|
+
? (efforts.includes(definition?.defaultReasoningLevel) ? definition.defaultReasoningLevel : efforts[0]) : undefined) ?? null;
|
|
122
|
+
}
|
|
123
|
+
warn('provider', explicit.provider ?? suggested.provider, provider, '建议或指定的服务商不可用,采用本机可用配置;未选中时需补充配置。');
|
|
124
|
+
warn('model', explicit.model ?? suggested.model, model, '建议或指定的模型不可用,采用本机可用配置;未选中时需补充配置。');
|
|
125
|
+
warn('effort', explicit.effort ?? suggested.effort, effort, effort === null
|
|
126
|
+
? '模板建议的推理强度不可用,清除显式强度并采用模型默认值。'
|
|
127
|
+
: '模板建议的推理强度不可用,采用目标主机同基座的默认强度。');
|
|
128
|
+
selections[baseagent] = { ...explicit, provider: provider ?? null, model: model ?? null, effort };
|
|
129
|
+
return { selections, binding: { baseagent, suggested, requested: explicit, selected: { provider: provider ?? null, model: model ?? null, effort },
|
|
130
|
+
reasons: warnings.map(warning => warning.message) }, warnings };
|
|
131
|
+
}
|
|
39
132
|
/** Host-owned transport and persisted service jobs; never borrows the Owner's identity. */
|
|
40
133
|
export function createTemplateUpdateCatalog(root, getControl) {
|
|
41
134
|
const jobs = new TemplateJobs(root);
|
|
42
135
|
return async (source, action, args, operationId) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
throw templateError('CATALOG_UNAVAILABLE', 'Configure a trusted template catalog in data/template/catalogs.json');
|
|
47
|
-
const stat = fs.statSync(configFile);
|
|
48
|
-
if (!stat.isFile() || stat.nlink !== 1 || stat.size > 64 * 1024 || process.platform !== 'win32' && (stat.mode & 0o077)) {
|
|
49
|
-
throw templateError('UNTRUSTED_CATALOG_CONFIG', 'Trusted catalog configuration must be a private ordinary file (0600)');
|
|
50
|
-
}
|
|
51
|
-
const config = JSON.parse(fs.readFileSync(configFile, 'utf8'));
|
|
52
|
-
if (config.schemaVersion !== 1 || Object.keys(config).some(key => !['schemaVersion', 'catalogs'].includes(key))
|
|
53
|
-
|| !Array.isArray(config.catalogs) || config.catalogs.some((entry) => !isValidAid(entry.aid)
|
|
54
|
-
|| Object.keys(entry).some(key => !['aid', 'publishers'].includes(key)) || !Array.isArray(entry.publishers)
|
|
55
|
-
|| !entry.publishers.length || entry.publishers.some((aid) => !isValidAid(aid)))) {
|
|
56
|
-
throw templateError('UNTRUSTED_CATALOG_CONFIG', 'Invalid trusted catalog declaration');
|
|
57
|
-
}
|
|
58
|
-
if (!config.catalogs.some((entry) => entry.aid === source.catalogAid && entry.publishers.includes(source.publisher))) {
|
|
59
|
-
throw templateError('UNTRUSTED_SOURCE', 'The catalog and publisher have not been explicitly trusted on this Host');
|
|
60
|
-
}
|
|
136
|
+
if (typeof source.registryAid !== 'string' || typeof source.key !== 'string'
|
|
137
|
+
|| !isValidAid(source.registryAid) || !isValidAid(source.key))
|
|
138
|
+
throw templateError('UNTRUSTED_SOURCE', 'Explicit registryAid and original key required');
|
|
61
139
|
const channel = getControl();
|
|
62
140
|
const selfAid = channel?.getAid();
|
|
63
141
|
if (!channel?.isConnected() || !selfAid)
|
|
64
142
|
throw templateError('AUN_DISCONNECTED', 'Real Host Control connection required');
|
|
65
|
-
if (action === 'download' && args.targetHostAid !== selfAid)
|
|
66
|
-
throw templateError('NOT_ALLOWED', '
|
|
143
|
+
if (action === 'download' && (args.targetHostAid !== selfAid || args.purpose !== 'upgrade'))
|
|
144
|
+
throw templateError('NOT_ALLOWED', 'Upgrade download must name the actual calling Host and purpose');
|
|
67
145
|
const fingerprint = templateFingerprint({ source, action, args, operationId, selfAid });
|
|
68
146
|
const file = path.join(jobs.directory, 'catalog-calls', fingerprint + '.json');
|
|
69
147
|
return withFileLock(file + '.lock', async () => {
|
|
@@ -75,7 +153,7 @@ export function createTemplateUpdateCatalog(root, getControl) {
|
|
|
75
153
|
|| request.state === 'completed' && request.responsePayload?.ok !== true))
|
|
76
154
|
request = undefined;
|
|
77
155
|
if (!request) {
|
|
78
|
-
const prepared = registry.prepare({ selfAid, targetAid: source.
|
|
156
|
+
const prepared = registry.prepare({ selfAid, targetAid: source.registryAid, timeoutMs: 20_000,
|
|
79
157
|
payload: { type, ...data, service_deadline_at_ms: Date.now() + 20_000 } });
|
|
80
158
|
if (initial) {
|
|
81
159
|
state.requestId = prepared.requestId;
|
|
@@ -83,7 +161,7 @@ export function createTemplateUpdateCatalog(root, getControl) {
|
|
|
83
161
|
writeTemplateState(file, state);
|
|
84
162
|
}
|
|
85
163
|
registry.markSending(selfAid, prepared.requestId);
|
|
86
|
-
const sent = await channel.sendDaemonMsg({ to: source.
|
|
164
|
+
const sent = await channel.sendDaemonMsg({ to: source.registryAid, payload: prepared.payload, encrypt: true,
|
|
87
165
|
ttl: 20, service: { type, requestId: prepared.requestId } });
|
|
88
166
|
if (!sent.ok) {
|
|
89
167
|
registry.markFailed(selfAid, prepared.requestId, sent.error ?? 'send failed');
|
|
@@ -100,13 +178,13 @@ export function createTemplateUpdateCatalog(root, getControl) {
|
|
|
100
178
|
if (request?.state !== 'completed')
|
|
101
179
|
request = await registry.wait(selfAid, request.requestId, 20_000);
|
|
102
180
|
if (!request || request.state !== 'completed' || !request.responsePayload) {
|
|
103
|
-
throw templateError('CATALOG_PENDING', 'Catalog reply pending; resume the original job', { requestId: request?.requestId, callerAid: selfAid, catalogAid: source.
|
|
181
|
+
throw templateError('CATALOG_PENDING', 'Catalog reply pending; resume the original job', { requestId: request?.requestId, callerAid: selfAid, catalogAid: source.registryAid });
|
|
104
182
|
}
|
|
105
183
|
const response = request.responsePayload;
|
|
106
184
|
if (response.type !== type + '.result')
|
|
107
185
|
throw templateError('INVALID_CATALOG', 'Registry response type differs from the request');
|
|
108
186
|
if (response.ok !== true)
|
|
109
|
-
throw templateError(response.error?.code ?? 'CATALOG_FAILED', response.error?.message ?? 'Catalog service rejected the actual Host Caller', { callerAid: selfAid, catalogAid: source.
|
|
187
|
+
throw templateError(response.error?.code ?? 'CATALOG_FAILED', response.error?.message ?? 'Catalog service rejected the actual Host Caller', { callerAid: selfAid, catalogAid: source.registryAid, requestId: request.requestId });
|
|
110
188
|
return response.data;
|
|
111
189
|
};
|
|
112
190
|
if (!state.businessJobId) {
|
|
@@ -123,17 +201,86 @@ export function createTemplateUpdateCatalog(root, getControl) {
|
|
|
123
201
|
throw templateError('INVALID_CATALOG', 'Registry status refers to another job');
|
|
124
202
|
if (response.state === 'completed') {
|
|
125
203
|
if (response.ok !== true)
|
|
126
|
-
throw templateError(response.error?.code ?? 'CATALOG_FAILED', 'Registry operation failed for the real Host Caller', { callerAid: selfAid, catalogAid: source.
|
|
204
|
+
throw templateError(response.error?.code ?? 'CATALOG_FAILED', 'Registry operation failed for the real Host Caller', { callerAid: selfAid, catalogAid: source.registryAid, serviceJobId: response.jobId });
|
|
127
205
|
return response.result;
|
|
128
206
|
}
|
|
129
207
|
if (!['queued', 'running'].includes(response.state))
|
|
130
208
|
throw templateError('INVALID_CATALOG', 'Unknown Registry job state');
|
|
131
209
|
await new Promise(resolve => setTimeout(resolve, 250));
|
|
132
210
|
} while (Date.now() < deadline);
|
|
133
|
-
throw templateError('CATALOG_PENDING', 'Registry job remains pending; resume the original job', { callerAid: selfAid, catalogAid: source.
|
|
211
|
+
throw templateError('CATALOG_PENDING', 'Registry job remains pending; resume the original job', { callerAid: selfAid, catalogAid: source.registryAid, serviceJobId: state.businessJobId });
|
|
134
212
|
});
|
|
135
213
|
};
|
|
136
214
|
}
|
|
215
|
+
/** Store operations use only the selected real Agent or Host connection. */
|
|
216
|
+
export function createTemplatePublicationRuntime(root, getControl, getAgentChannel) {
|
|
217
|
+
const channelFor = (aid) => {
|
|
218
|
+
const host = getControl();
|
|
219
|
+
const channel = host?.getAid() === aid ? host : getAgentChannel(aid);
|
|
220
|
+
if (!channel?.getClient() || channel.getAid() !== aid || !channel.isConnected()) {
|
|
221
|
+
throw templateError('AUN_DISCONNECTED', 'Real publication connection unavailable: ' + aid);
|
|
222
|
+
}
|
|
223
|
+
return channel;
|
|
224
|
+
};
|
|
225
|
+
return {
|
|
226
|
+
identity: async (kind, executor) => {
|
|
227
|
+
const aid = kind === 'host' ? getControl()?.getAid() : executor;
|
|
228
|
+
if (!aid)
|
|
229
|
+
throw templateError('NOT_ALLOWED', 'Selected publication identity is unavailable');
|
|
230
|
+
channelFor(aid);
|
|
231
|
+
return aid;
|
|
232
|
+
},
|
|
233
|
+
grant: async (aid, remote, registryAid, requestId) => {
|
|
234
|
+
const result = await executeStorageShare(channelFor(aid).getClient(), aid, {
|
|
235
|
+
action: 'create', requestId, path: remote, allowedAids: [registryAid], expireInSeconds: 3600, maxUses: 0,
|
|
236
|
+
}, path.join(root, 'data', 'storage-shares'));
|
|
237
|
+
if (result.state !== 'succeeded' || !result.result?.share_id)
|
|
238
|
+
throw templateError('SHARE_RESULT_UNKNOWN', 'Registry read authorization is unconfirmed; inspect its original share request', { requestId, callerAid: aid });
|
|
239
|
+
return result.result.share_id;
|
|
240
|
+
},
|
|
241
|
+
call: async (aid, registryAid, action, args, operationId) => {
|
|
242
|
+
const channel = channelFor(aid);
|
|
243
|
+
const fingerprint = templateFingerprint({ aid, registryAid, action, args, operationId });
|
|
244
|
+
const file = path.join(root, 'data', 'template', 'publication-calls', fingerprint + '.json');
|
|
245
|
+
return withFileLock(file + '.lock', async () => {
|
|
246
|
+
const state = action !== 'status' && fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : {};
|
|
247
|
+
const registry = getAunRequestRegistry();
|
|
248
|
+
let request = state.requestId ? registry.get(aid, state.requestId) : undefined;
|
|
249
|
+
if (request && request.state !== 'completed'
|
|
250
|
+
&& (request.state === 'failed' || (request.deadlineAt ?? 0) <= Date.now()))
|
|
251
|
+
request = undefined;
|
|
252
|
+
const type = 'services.templates.' + action;
|
|
253
|
+
if (!request) {
|
|
254
|
+
const prepared = registry.prepare({ selfAid: aid, targetAid: registryAid, timeoutMs: 20_000,
|
|
255
|
+
payload: { type, ...args, service_deadline_at_ms: Date.now() + 20_000 } });
|
|
256
|
+
if (action !== 'status')
|
|
257
|
+
writeTemplateState(file, { requestId: prepared.requestId });
|
|
258
|
+
registry.markSending(aid, prepared.requestId);
|
|
259
|
+
const sent = await channel.sendDaemonMsg({ to: registryAid, payload: prepared.payload, encrypt: true,
|
|
260
|
+
ttl: 20, service: { type, requestId: prepared.requestId } });
|
|
261
|
+
if (!sent.ok) {
|
|
262
|
+
registry.markFailed(aid, prepared.requestId, sent.error ?? 'send failed');
|
|
263
|
+
throw templateError('PUBLICATION_PENDING', sent.error ?? 'Publication send is unconfirmed', { requestId: prepared.requestId, callerAid: aid, upstreamCode: sent.code });
|
|
264
|
+
}
|
|
265
|
+
if (sent.message_id)
|
|
266
|
+
registry.markTransportAccepted(aid, prepared.requestId, sent.message_id, sent.status);
|
|
267
|
+
request = registry.get(aid, prepared.requestId);
|
|
268
|
+
}
|
|
269
|
+
if (request?.state !== 'completed')
|
|
270
|
+
request = await registry.wait(aid, request.requestId, 20_000);
|
|
271
|
+
if (!request || request.state !== 'completed' || !request.responsePayload) {
|
|
272
|
+
throw templateError('PUBLICATION_PENDING', 'Registry response pending; resume the original publication', { requestId: request?.requestId, callerAid: aid });
|
|
273
|
+
}
|
|
274
|
+
const response = request.responsePayload;
|
|
275
|
+
if (response.type !== type + '.result')
|
|
276
|
+
throw templateError('PUBLICATION_PENDING', 'Unexpected registry response type');
|
|
277
|
+
if (response.ok !== true)
|
|
278
|
+
throw templateError(response.error?.code ?? 'PUBLICATION_FAILED', response.error?.message ?? 'Registry rejected the real publication Caller', { remoteFailure: response.error?.code !== 'EXECUTION_UNKNOWN', callerAid: aid, registryAid, requestId: request.requestId });
|
|
279
|
+
return response.data;
|
|
280
|
+
});
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
}
|
|
137
284
|
/** Fence collection workers before runners or Trigger schedulers are loaded. */
|
|
138
285
|
export async function restoreTemplatesBeforeStartup(root) {
|
|
139
286
|
const blocked = new Set();
|
|
@@ -142,7 +289,7 @@ export async function restoreTemplatesBeforeStartup(root) {
|
|
|
142
289
|
for (const job of jobs.list()) {
|
|
143
290
|
if (['succeeded', 'cancelled'].includes(job.status) && (!job.freeze || ['released', 'transferred'].includes(job.freeze.state)))
|
|
144
291
|
continue;
|
|
145
|
-
if (['inspect', 'build'].includes(job.action)) {
|
|
292
|
+
if (['inspect', 'collect', 'build'].includes(job.action)) {
|
|
146
293
|
job.checkpoint.fenced = true;
|
|
147
294
|
jobs.save(job);
|
|
148
295
|
const worker = job.checkpoint.worker;
|
|
@@ -178,13 +325,47 @@ export async function restoreTemplatesBeforeStartup(root) {
|
|
|
178
325
|
}
|
|
179
326
|
jobs.save(job);
|
|
180
327
|
}
|
|
181
|
-
else if (
|
|
328
|
+
else if (['publish', 'list', 'detail', 'download'].includes(job.action)) {
|
|
329
|
+
if (job.status === 'failed' && !job.resumable)
|
|
330
|
+
continue;
|
|
331
|
+
job.status = 'paused';
|
|
332
|
+
job.resumable = true;
|
|
333
|
+
job.error = { code: 'RECOVERY_REQUIRED', message: 'Resume the original Store job and its saved remote operation', retryable: true };
|
|
334
|
+
jobs.save(job);
|
|
335
|
+
}
|
|
336
|
+
else if (job.action === 'pack') {
|
|
337
|
+
if (job.status === 'failed' && !job.resumable && !job.checkpoint.worker)
|
|
338
|
+
continue;
|
|
339
|
+
const worker = job.checkpoint.worker;
|
|
340
|
+
if (worker && isProcessRunning(worker.pid)) {
|
|
341
|
+
const matching = findProcessesWithCommandLine(String(worker.input).replace(/[^a-zA-Z0-9]/g, '.'))
|
|
342
|
+
.some(value => value.pid === worker.pid && value.commandLine?.includes(worker.input));
|
|
343
|
+
if (matching) {
|
|
344
|
+
killProcess(worker.pid, true);
|
|
345
|
+
for (let i = 0; i < 40 && isProcessRunning(worker.pid); i++)
|
|
346
|
+
await new Promise(resolve => setTimeout(resolve, 25));
|
|
347
|
+
}
|
|
348
|
+
if (isProcessRunning(worker.pid)) {
|
|
349
|
+
job.status = 'cancelling';
|
|
350
|
+
job.resumable = false;
|
|
351
|
+
job.error = { code: 'RECOVERY_REQUIRED', message: 'Pack worker exit is unconfirmed', retryable: true };
|
|
352
|
+
jobs.save(job);
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
delete job.checkpoint.worker;
|
|
357
|
+
job.status = 'paused';
|
|
358
|
+
job.resumable = true;
|
|
359
|
+
job.error = { code: 'RECOVERY_REQUIRED', message: 'Resume the original pack job and its saved snapshot', retryable: true };
|
|
360
|
+
jobs.save(job);
|
|
361
|
+
}
|
|
362
|
+
else if (job.action === 'upgrade' && !job.args.previewId) {
|
|
182
363
|
job.status = 'paused';
|
|
183
364
|
job.resumable = true;
|
|
184
365
|
job.error = { code: 'RECOVERY_REQUIRED', message: 'Resume the original fixed-candidate preview', retryable: true };
|
|
185
366
|
jobs.save(job);
|
|
186
367
|
}
|
|
187
|
-
else if (job.action
|
|
368
|
+
else if (['deploy', 'upgrade'].includes(job.action) && !job.committed) {
|
|
188
369
|
if (!job.checkpoint.restored)
|
|
189
370
|
for (const aid of templateJobAids(job)) {
|
|
190
371
|
const gate = templateInstallationGate(aid, undefined, root);
|
|
@@ -370,15 +551,16 @@ export function createTemplateIdentityTransport(job) {
|
|
|
370
551
|
};
|
|
371
552
|
}
|
|
372
553
|
const FIELDS = ['name', 'description', 'avatar', 'tags', 'exttype'];
|
|
373
|
-
/**
|
|
374
|
-
export function resolveTemplateSourceConfig(effective, scope = {},
|
|
554
|
+
/** Export explicit public behavior; effective runner choices still resolve inherited and legacy model bindings. */
|
|
555
|
+
export function resolveTemplateSourceConfig(effective, scope = {}, configuredLayers = [effective]) {
|
|
556
|
+
const configured = mergeLayers(configuredLayers, loadSchema('agent-config').fields);
|
|
375
557
|
const source = { ...publicTemplate.resolveMemberParameters({ config: effective }), baseagents: {} };
|
|
376
|
-
for (const field of ['chatmode', 'memory'
|
|
377
|
-
if (
|
|
378
|
-
source[field] = structuredClone(
|
|
558
|
+
for (const field of ['chatmode', 'memory']) {
|
|
559
|
+
if (configured[field] !== undefined)
|
|
560
|
+
source[field] = structuredClone(configured[field]);
|
|
379
561
|
}
|
|
380
|
-
if (
|
|
381
|
-
source.
|
|
562
|
+
if (effective.active_baseagent !== undefined)
|
|
563
|
+
source.active_baseagent = effective.active_baseagent;
|
|
382
564
|
for (const name of listSupportedBaseagents()) {
|
|
383
565
|
const configured = effective.baseagents?.[name];
|
|
384
566
|
if (!configured || typeof configured !== 'object' || Array.isArray(configured))
|
|
@@ -408,8 +590,7 @@ export function resolveTemplateSourceConfig(effective, scope = {}, declaration =
|
|
|
408
590
|
return source;
|
|
409
591
|
}
|
|
410
592
|
/** Use the SDK's ticket routing and authentication contract with a bounded data plane. */
|
|
411
|
-
export async function downloadTemplatePackage(client, file, location, shareId) {
|
|
412
|
-
const limit = 200 * 1024 * 1024;
|
|
593
|
+
export async function downloadTemplatePackage(client, file, location, shareId, limit = 200 * 1024 * 1024) {
|
|
413
594
|
const read = async (url, headers) => {
|
|
414
595
|
if (new URL(url).protocol !== 'https:')
|
|
415
596
|
throw templateError('DOWNLOAD_FAILED', 'Storage downloads require HTTPS');
|
|
@@ -496,56 +677,6 @@ export async function authorizeTemplateOwner(actor, aid, recoveryJobId) {
|
|
|
496
677
|
throw templateError('NOT_ALLOWED', 'Agent Owner required', { reason: 'AGENT_OWNER_REQUIRED' });
|
|
497
678
|
}
|
|
498
679
|
}
|
|
499
|
-
/** Read-only startup evidence. A file cannot grant Owner or Host-control privileges. */
|
|
500
|
-
export async function verifyTemplateDefinitionOwner(aid, expectedOwner) {
|
|
501
|
-
let owner;
|
|
502
|
-
try {
|
|
503
|
-
owner = await ownerResolver.refreshForAuthorization(aid);
|
|
504
|
-
}
|
|
505
|
-
catch (error) {
|
|
506
|
-
throw templateError('OWNERSHIP_UNAVAILABLE', 'Fresh Team ownership could not be checked', { cause: error.code ?? error.message });
|
|
507
|
-
}
|
|
508
|
-
if (owner.refreshFailure || owner.consensusStatus !== 'consensus') {
|
|
509
|
-
throw templateError('OWNERSHIP_UNAVAILABLE', 'Fresh Team ownership consensus is temporarily unavailable');
|
|
510
|
-
}
|
|
511
|
-
if (owner.ownerAid !== expectedOwner)
|
|
512
|
-
throw templateError('NOT_ALLOWED', 'Team definition differs from the current protocol Owner');
|
|
513
|
-
}
|
|
514
|
-
/** Read actual Owner publication through each live member's authorized directory cache. Never accepts an App ACK. */
|
|
515
|
-
export async function verifyTemplateMemberDirectory(team, member) {
|
|
516
|
-
const snapshots = {};
|
|
517
|
-
const revisions = new Set();
|
|
518
|
-
for (const self of team.members.filter(value => value.aid)) {
|
|
519
|
-
const cache = liveOwnerDirectoryCache(self.aid);
|
|
520
|
-
if (!cache)
|
|
521
|
-
throw templateError('OWNER_DIRECTORY_PENDING', 'A member directory is not connected');
|
|
522
|
-
const fetched = await cache.fetchToSharedCache({});
|
|
523
|
-
if (!await cache.applyFromSharedCache())
|
|
524
|
-
throw templateError('OWNER_DIRECTORY_PENDING', 'Fresh Owner publication could not be applied');
|
|
525
|
-
const document = fetched.contacts;
|
|
526
|
-
const snapshot = cache.readSnapshot('contacts');
|
|
527
|
-
if (!snapshot || !document?.contentDigest || snapshot.contentDigest !== document.contentDigest
|
|
528
|
-
|| snapshot.sourceRevision !== document.raw.source_revision || snapshot.ownerAid !== team.ownerAid || !snapshot.sourceRevision
|
|
529
|
-
|| !snapshot.openPaContext?.includes(member.aid))
|
|
530
|
-
throw templateError('OWNER_DIRECTORY_PENDING', 'Fresh Owner publication has not been observed');
|
|
531
|
-
for (const other of team.members.filter(value => value.aid)) {
|
|
532
|
-
if (snapshot.blockedAids?.includes(other.aid))
|
|
533
|
-
throw templateError('CONTACT_BLOCKED', 'An original Team member is blocked');
|
|
534
|
-
if (other.aid === self.aid)
|
|
535
|
-
continue;
|
|
536
|
-
const membership = readOwnerDirectoryMembership(self.aid, other.aid, true);
|
|
537
|
-
if (!membership || membership.blocked || membership.scopeExcluded
|
|
538
|
-
|| !['agent', 'assistant'].includes(membership.category) || membership.category !== 'assistant' && membership.internal !== true) {
|
|
539
|
-
throw templateError('OWNER_DIRECTORY_PENDING', 'Team membership is not in the current Owner directory');
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
snapshots[self.aid] = snapshot.snapshotId;
|
|
543
|
-
revisions.add(snapshot.sourceRevision);
|
|
544
|
-
}
|
|
545
|
-
if (revisions.size !== 1)
|
|
546
|
-
throw templateError('OWNER_DIRECTORY_PENDING', 'Members have different Owner directory revisions');
|
|
547
|
-
return { revision: [...revisions][0], snapshots };
|
|
548
|
-
}
|
|
549
680
|
export function createAgentTemplateRuntime(options) {
|
|
550
681
|
const paths = resolvePaths();
|
|
551
682
|
const requireHost = () => {
|
|
@@ -582,38 +713,42 @@ export function createAgentTemplateRuntime(options) {
|
|
|
582
713
|
};
|
|
583
714
|
const service = new AgentTemplateService({
|
|
584
715
|
root: paths.root, hostAid: loadDaemonConfig().aid ?? '', authorize: authorizeTemplateOwner,
|
|
585
|
-
|
|
716
|
+
publication: createTemplatePublicationRuntime(paths.root, options.getControl, options.getAgentChannel),
|
|
717
|
+
source: async (aid, actor, module) => {
|
|
718
|
+
if (module) {
|
|
719
|
+
const agent = options.registry.get(aid);
|
|
720
|
+
const raw = loadAgent(aid);
|
|
721
|
+
if (!agent || !raw)
|
|
722
|
+
throw templateError('NOT_FOUND', 'Source must be installed on this Host');
|
|
723
|
+
const source = { home: paths.root, packageRoot: getPackageRoot(),
|
|
724
|
+
agentDir: path.join(paths.agentsDir, aid), agentAid: aid, projectPath: agent.projectPath,
|
|
725
|
+
originalKey: raw.update?.key ?? aid, ownerAid: actor, hostAid: requireHost().getAid(), publisher: { aid: actor } };
|
|
726
|
+
if (module === 'profile')
|
|
727
|
+
Object.assign(source, await profile(aid));
|
|
728
|
+
if (module === 'config') {
|
|
729
|
+
const providers = readProvidersSnapshot();
|
|
730
|
+
const effective = structuredClone(resolveEffective({ self: aid }, {}));
|
|
731
|
+
for (const block of Object.values(effective.baseagents ?? {}))
|
|
732
|
+
if (block.provider) {
|
|
733
|
+
block.provider = resolveProviderId(block.provider, providers);
|
|
734
|
+
}
|
|
735
|
+
source.effectiveConfig = resolveTemplateSourceConfig(effective, {}, [
|
|
736
|
+
normalizeDefaultsBehaviorCompat(loadDefaults()), raw,
|
|
737
|
+
]);
|
|
738
|
+
source.providers = Object.fromEntries(Object.entries(providers.providers).map(([id, value]) => [id, { name: value.name }]));
|
|
739
|
+
}
|
|
740
|
+
if (module === 'skill')
|
|
741
|
+
source.skills = resolveAllSkillStates(source.agentDir)
|
|
742
|
+
.map(skill => ({ name: skill.name, type: skill.source, enabled: skill.enabled }));
|
|
743
|
+
return source;
|
|
744
|
+
}
|
|
586
745
|
const { targetConfig: raw, effectiveConfig, providers, ...source } = await context(aid, actor);
|
|
587
|
-
return { ...source, effectiveConfig: resolveTemplateSourceConfig(effectiveConfig, {},
|
|
746
|
+
return { ...source, effectiveConfig: resolveTemplateSourceConfig(effectiveConfig, {}, [
|
|
747
|
+
normalizeDefaultsBehaviorCompat(loadDefaults()), raw,
|
|
748
|
+
]),
|
|
588
749
|
providers: Object.fromEntries(Object.entries(providers).map(([id, value]) => [id, { name: value.name }])) };
|
|
589
750
|
}, target: context,
|
|
590
751
|
installation: createInstallationDependencies(options),
|
|
591
|
-
discovery: {
|
|
592
|
-
verifyHost: async (ownerAid, hostAid) => {
|
|
593
|
-
if (loadDaemonConfig().aid !== hostAid || requireHost().getAid() !== hostAid)
|
|
594
|
-
throw templateError('NOT_ALLOWED', 'Team definition must target the current Host identity');
|
|
595
|
-
await verifyTemplateDefinitionOwner(hostAid, ownerAid);
|
|
596
|
-
},
|
|
597
|
-
member: async (aid, ownerAid, hostAid) => {
|
|
598
|
-
if (requireHost().getAid() !== hostAid)
|
|
599
|
-
throw templateError('NOT_ALLOWED', 'Original Host identity changed');
|
|
600
|
-
const agent = options.registry.get(aid);
|
|
601
|
-
const raw = loadAgent(aid);
|
|
602
|
-
if (!agent || !raw || raw.aid !== aid || !path.isAbsolute(agent.projectPath ?? ''))
|
|
603
|
-
throw templateError('NOT_FOUND', 'Definition member is not available on this Host');
|
|
604
|
-
assertTemplateInstallationReady(aid);
|
|
605
|
-
await verifyTemplateDefinitionOwner(aid, ownerAid);
|
|
606
|
-
let card;
|
|
607
|
-
try {
|
|
608
|
-
card = await profile(aid);
|
|
609
|
-
}
|
|
610
|
-
catch (error) {
|
|
611
|
-
throw templateError('PROFILE_UNAVAILABLE', 'Definition member profile is temporarily unavailable', { cause: error.code ?? error.message });
|
|
612
|
-
}
|
|
613
|
-
return { targetAid: aid, projectPath: agent.projectPath, targetConfig: raw, profile: card.profile };
|
|
614
|
-
},
|
|
615
|
-
},
|
|
616
|
-
resolveMemberRelease: options.resolveMemberRelease,
|
|
617
752
|
updates: {
|
|
618
753
|
targets: () => options.registry.allAgents().map(agent => ({ aid: agent.aid, projectPath: agent.projectPath,
|
|
619
754
|
mode: loadAgent(agent.aid)?.update?.mode })),
|
|
@@ -637,10 +772,18 @@ export function createAgentTemplateRuntime(options) {
|
|
|
637
772
|
if (current.refreshFailure || current.consensusStatus !== 'consensus' || current.ownerAid !== notice.ownerAid) {
|
|
638
773
|
throw templateError('OWNERSHIP_UNAVAILABLE', 'Current notification Owner is not verified');
|
|
639
774
|
}
|
|
640
|
-
const host =
|
|
641
|
-
const hostAid = host
|
|
642
|
-
if (!hostAid)
|
|
643
|
-
throw templateError('AUN_DISCONNECTED', '
|
|
775
|
+
const host = options.getAgentChannel(notice.targetAid);
|
|
776
|
+
const hostAid = host?.getAid();
|
|
777
|
+
if (!host || hostAid !== notice.targetAid)
|
|
778
|
+
throw templateError('AUN_DISCONNECTED', 'Target Agent notice channel unavailable');
|
|
779
|
+
const receiptFile = path.join(paths.root, 'data', 'template', 'notifications', notice.noticeId + '.json');
|
|
780
|
+
if (fs.existsSync(receiptFile)) {
|
|
781
|
+
const previous = JSON.parse(fs.readFileSync(receiptFile, 'utf8'));
|
|
782
|
+
if (previous.ownerAid === notice.ownerAid && previous.messageId)
|
|
783
|
+
return { messageId: previous.messageId, status: 'transport-accepted' };
|
|
784
|
+
notice.outboxId ??= previous.outboxId;
|
|
785
|
+
}
|
|
786
|
+
writeTemplateState(receiptFile, notice);
|
|
644
787
|
if (notice.outboxId) {
|
|
645
788
|
const state = outbox.deliveryState(hostAid, notice.outboxId);
|
|
646
789
|
if (state.status === 'sent')
|
|
@@ -651,68 +794,49 @@ export function createAgentTemplateRuntime(options) {
|
|
|
651
794
|
outbox.removeIfRouteMatches(hostAid, entry);
|
|
652
795
|
}
|
|
653
796
|
}
|
|
654
|
-
const
|
|
655
|
-
|
|
656
|
-
|
|
797
|
+
const command = MAIN_CLI_BIN + ' agent template upgrade ' + notice.targetAid + ' --release-id ' + notice.candidate.releaseId + ' --wait 300 --format json';
|
|
798
|
+
const text = 'Agent ' + (options.registry.get(notice.targetAid)?.name ?? notice.targetAid) + ' 有可用升级:' + notice.currentVersion
|
|
799
|
+
+ ' → ' + notice.candidate.version + '。空闲时手动执行:' + command;
|
|
800
|
+
const sent = await host.sendContentPayload(notice.ownerAid, { type: 'notice', subtype: 'agent.upgrade.available', severity: 'info', text,
|
|
801
|
+
agent_aid: notice.targetAid, sent_at: Date.now(),
|
|
657
802
|
template_update: { noticeId: notice.noticeId, targetAid: notice.targetAid,
|
|
658
|
-
|
|
803
|
+
key: notice.source.key, registryAid: notice.source.registryAid, candidateVersion: notice.candidate.version,
|
|
659
804
|
candidateDigest: notice.candidate.digest,
|
|
660
|
-
menu: { name: 'template', args: {
|
|
805
|
+
command, menu: { name: 'template', action: 'upgrade', args: { targetAid: notice.targetAid, releaseId: notice.candidate.releaseId } } } }, {
|
|
661
806
|
contentKind: 'text', dedupeKey: 'template-update:' + notice.noticeId, logText: text,
|
|
662
807
|
context: { delivery: { chatType: 'private' }, metadata: { encrypted: true, source: 'daemon' } },
|
|
663
808
|
});
|
|
664
809
|
if (!sent.messageId && !sent.queued)
|
|
665
810
|
throw templateError(String(sent.code ?? 'NOTIFICATION_FAILED'), sent.error ?? 'Owner update notice failed');
|
|
811
|
+
const persisted = JSON.parse(fs.readFileSync(receiptFile, 'utf8'));
|
|
812
|
+
writeTemplateState(receiptFile, { ...persisted, ...(sent.messageId ? { messageId: sent.messageId } : {}),
|
|
813
|
+
...(sent.outboxId ? { outboxId: sent.outboxId } : {}) });
|
|
814
|
+
if (!sent.messageId)
|
|
815
|
+
writeTemplateState(receiptFile, { ...notice, outboxId: sent.outboxId });
|
|
666
816
|
return { ...(sent.messageId ? { messageId: sent.messageId } : {}), ...(sent.outboxId ? { outboxId: sent.outboxId } : {}),
|
|
667
817
|
status: sent.messageId ? 'transport-accepted' : 'queued' };
|
|
668
818
|
},
|
|
669
819
|
},
|
|
670
|
-
joining: {
|
|
671
|
-
ownership: async (aid, ownerAid, hostAid) => {
|
|
672
|
-
if (hostAid !== requireHost().getAid() || !options.registry.get(aid))
|
|
673
|
-
throw templateError('TARGET_CHANGED', 'Installed member is not on the original Host');
|
|
674
|
-
await authorizeTemplateOwner(ownerAid, aid);
|
|
675
|
-
const owner = await ownerResolver.refreshForAuthorization(aid);
|
|
676
|
-
if (owner.refreshFailure || owner.consensusStatus !== 'consensus' || owner.ownerAid !== ownerAid
|
|
677
|
-
|| !owner.consensus?.relation_version)
|
|
678
|
-
throw templateError('OWNERSHIP_REQUIRED', 'Fresh direct Owner consensus required');
|
|
679
|
-
return { aid, ownerAid, hostAid, relationVersion: owner.consensus.relation_version,
|
|
680
|
-
checkedAt: owner.checkedAt, validUntil: owner.validUntil };
|
|
681
|
-
},
|
|
682
|
-
verifyDirectory: verifyTemplateMemberDirectory,
|
|
683
|
-
addRelationships: async (team, member) => {
|
|
684
|
-
const original = team.members.filter(value => value.aid && value.aid !== member.aid);
|
|
685
|
-
for (const aid of [...team.relationshipTargets, member.aid]) {
|
|
686
|
-
await authorizeTemplateOwner(team.ownerAid, aid);
|
|
687
|
-
const current = readTeamMembersState(aid);
|
|
688
|
-
// A user clearing an original team's list pauses joining instead of recreating it.
|
|
689
|
-
if (aid !== member.aid && !current.members.some(peer => original.some(value => value.aid === peer))) {
|
|
690
|
-
throw templateError('CONFLICT', 'An original Team member list was independently cleared');
|
|
691
|
-
}
|
|
692
|
-
const additions = aid === member.aid ? original.map(value => value.aid) : [member.aid];
|
|
693
|
-
const missing = additions.filter(value => !current.members.includes(value));
|
|
694
|
-
if (missing.length)
|
|
695
|
-
mutateTeamMembers(aid, 'add', missing, current.membersRevision);
|
|
696
|
-
}
|
|
697
|
-
},
|
|
698
|
-
},
|
|
699
820
|
hold: async (aid, token) => {
|
|
700
821
|
const releaseGate = await options.coordinator.acquireForMutation(aid, token);
|
|
701
822
|
let releaseScheduler;
|
|
702
823
|
let releaseHandoff;
|
|
703
824
|
let releaseEvents;
|
|
825
|
+
let releaseServices;
|
|
704
826
|
try {
|
|
705
827
|
releaseHandoff = options.holdHandoff(aid, token);
|
|
706
828
|
releaseEvents = options.pauseEvents?.(aid, token);
|
|
829
|
+
releaseServices = options.pauseServices?.(aid, token);
|
|
707
830
|
releaseScheduler = await options.getScheduler(aid)?.pauseForMutation(token);
|
|
708
831
|
}
|
|
709
832
|
catch (error) {
|
|
833
|
+
releaseServices?.();
|
|
710
834
|
releaseEvents?.();
|
|
711
835
|
releaseHandoff?.();
|
|
712
836
|
await releaseGate();
|
|
713
837
|
throw error;
|
|
714
838
|
}
|
|
715
|
-
return async () => { await releaseScheduler?.(); releaseEvents?.(); releaseHandoff?.(); await releaseGate(); };
|
|
839
|
+
return async () => { await releaseScheduler?.(); releaseServices?.(); releaseEvents?.(); releaseHandoff?.(); await releaseGate(); };
|
|
716
840
|
},
|
|
717
841
|
reload: async (aid, jobId, restoreStopped) => {
|
|
718
842
|
notifyConfigWrite(ConfigTarget.Agent, { self: aid });
|
|
@@ -720,19 +844,22 @@ export function createAgentTemplateRuntime(options) {
|
|
|
720
844
|
await options.reloadInsideGate(aid, jobId, restoreStopped);
|
|
721
845
|
},
|
|
722
846
|
block: options.block, recoveryComplete: aid => options.recoveryComplete?.(aid, true), readProfile: profile,
|
|
847
|
+
completeCreationWelcome: options.completeCreationWelcome,
|
|
848
|
+
resolveModels: resolveTemplateModelRecommendations,
|
|
723
849
|
validateModels: async (config, refs) => {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
850
|
+
const baseagent = config.active_baseagent;
|
|
851
|
+
const ref = refs.find(ref => ref.baseagent === baseagent);
|
|
852
|
+
const block = config.baseagents?.[baseagent];
|
|
853
|
+
if (!ref?.provider || !block?.provider) {
|
|
854
|
+
throw templateError('PROVIDER_NOT_FOUND', 'Choose a Provider for ' + baseagent);
|
|
855
|
+
}
|
|
856
|
+
const catalog = await getProviderCatalog(block.provider, undefined, false, false, baseagent);
|
|
857
|
+
assertCatalogSelectable(catalog);
|
|
858
|
+
if (block.model && !catalog.models.some(m => m.id === resolveCatalogModel(catalog, block.model))) {
|
|
859
|
+
throw templateError('INVALID_ARGUMENT', 'Model is unavailable for ' + baseagent);
|
|
860
|
+
}
|
|
861
|
+
if (block.effort && (!block.model || !catalogEfforts(catalog, block.model, baseagent).includes(block.effort))) {
|
|
862
|
+
throw templateError('INVALID_ARGUMENT', 'Effort is unavailable for ' + baseagent);
|
|
736
863
|
}
|
|
737
864
|
},
|
|
738
865
|
publishProfile: async (aid, values, expected) => {
|
|
@@ -756,11 +883,16 @@ export function createAgentTemplateRuntime(options) {
|
|
|
756
883
|
throw templateError('PROFILE_NOT_CONFIRMED', 'Published profile was not confirmed');
|
|
757
884
|
}
|
|
758
885
|
},
|
|
759
|
-
upload: async (owner, remote, local, recoverExisting = false) => {
|
|
886
|
+
upload: async (owner, remote, local, recoverExisting = false, executionAgentAid) => {
|
|
887
|
+
const channel = executionAgentAid === owner ? options.getAgentChannel(owner) : requireHost();
|
|
888
|
+
if (!channel?.getClient() || executionAgentAid === owner && channel.getAid() !== owner) {
|
|
889
|
+
throw templateError('AUN_DISCONNECTED', 'Actual upload identity is unavailable');
|
|
890
|
+
}
|
|
891
|
+
let stage = 'storage.head_object';
|
|
760
892
|
try {
|
|
761
893
|
if (recoverExisting) {
|
|
762
894
|
try {
|
|
763
|
-
const existing = await
|
|
895
|
+
const existing = await channel.callClient('storage.head_object', {
|
|
764
896
|
owner_aid: owner, bucket: 'default', object_key: remote.replace(/^\/+/, ''), consistency: 'authoritative',
|
|
765
897
|
});
|
|
766
898
|
const digest = createHash('sha256').update(fs.readFileSync(local)).digest('hex');
|
|
@@ -772,17 +904,22 @@ export function createAgentTemplateRuntime(options) {
|
|
|
772
904
|
throw error;
|
|
773
905
|
}
|
|
774
906
|
}
|
|
775
|
-
|
|
907
|
+
stage = 'storage.uploadFile';
|
|
908
|
+
await channel.getClient().storage.uploadFile(local, remote, { owner, overwrite: false });
|
|
776
909
|
}
|
|
777
910
|
catch (error) {
|
|
778
911
|
const code = String(error.code ?? '');
|
|
912
|
+
const denied = /access|denied|forbidden|eacces|32004|403/i.test(code + error.message);
|
|
913
|
+
const uploaderAid = channel.getAid();
|
|
914
|
+
const grant = denied && uploaderAid !== owner
|
|
915
|
+
? ' Target Storage must grant this uploader read/write access to the template directory.' : '';
|
|
779
916
|
throw templateError(/exist|conflict|32009/i.test(code + error.message) ? 'VERSION_EXISTS'
|
|
780
|
-
:
|
|
917
|
+
: denied ? 'ACCESS_DENIED' : 'UPLOAD_FAILED', `Template upload failed at ${stage} (${uploaderAid} -> ${owner}:${remote}): ${error.message}.${grant}`, { stage, uploaderAid, location: { aid: owner, path: remote }, ...(code ? { upstreamCode: code } : {}) });
|
|
781
918
|
}
|
|
782
919
|
},
|
|
783
|
-
download: async (shareId, file, location) => {
|
|
920
|
+
download: async (shareId, file, location, maxBytes) => {
|
|
784
921
|
try {
|
|
785
|
-
await downloadTemplatePackage(requireHost().getClient(), file, location, shareId);
|
|
922
|
+
await downloadTemplatePackage(requireHost().getClient(), file, location, shareId, maxBytes);
|
|
786
923
|
}
|
|
787
924
|
catch (error) {
|
|
788
925
|
if (error.code === 'INTEGRITY_FAILED')
|
|
@@ -791,10 +928,6 @@ export function createAgentTemplateRuntime(options) {
|
|
|
791
928
|
}
|
|
792
929
|
},
|
|
793
930
|
});
|
|
794
|
-
// Runtime construction happens after the Host and local Agent registry are loaded.
|
|
795
|
-
// Discovery is optional background work; a pending definition never fences existing Agents.
|
|
796
|
-
void service.discoverTeams().catch(error => logger.warn('[Template] Team definition discovery remains pending: ' + String(error)));
|
|
797
|
-
service.startUpdateChecks();
|
|
798
931
|
return service;
|
|
799
932
|
}
|
|
800
933
|
/** The AID alone is never evidence that cancellation owns a target. */
|
|
@@ -886,9 +1019,17 @@ function createInstallationDependencies(options) {
|
|
|
886
1019
|
authorize: async (actor) => {
|
|
887
1020
|
await ownerResolver.refresh((loadDaemonConfig().aid ?? ''), { force: true, allowTransient: false, source: 'agent-team' });
|
|
888
1021
|
if (!getDaemonOwners().includes(actor))
|
|
889
|
-
throw
|
|
1022
|
+
throw templateOwnerRequiredError();
|
|
1023
|
+
},
|
|
1024
|
+
hostSnapshot: () => {
|
|
1025
|
+
const providers = readProvidersSnapshot();
|
|
1026
|
+
const defaults = structuredClone(loadDefaults() ?? {});
|
|
1027
|
+
for (const block of Object.values(defaults.baseagents ?? {})) {
|
|
1028
|
+
if (block.provider)
|
|
1029
|
+
block.provider = resolveProviderId(block.provider, providers);
|
|
1030
|
+
}
|
|
1031
|
+
return { providers: providers.providers, defaults, schemaVersion: currentVersion('agent-config') };
|
|
890
1032
|
},
|
|
891
|
-
hostSnapshot: () => ({ providers: readProvidersSnapshot().providers, defaults: loadDefaults() ?? {}, schemaVersion: currentVersion('agent-config') }),
|
|
892
1033
|
available: (aid, project) => {
|
|
893
1034
|
if (!isValidAid(aid) || typeof project !== 'string' || !path.isAbsolute(project))
|
|
894
1035
|
throw templateError('INVALID_ARGUMENT', 'Valid new AID and absolute project required');
|
|
@@ -910,9 +1051,6 @@ function createInstallationDependencies(options) {
|
|
|
910
1051
|
},
|
|
911
1052
|
validatePlan: async (plan) => {
|
|
912
1053
|
validateInitializationPlan(plan);
|
|
913
|
-
const error = await validateInitializationModelArgs(plan);
|
|
914
|
-
if (error)
|
|
915
|
-
throw templateError(error.code, error.error);
|
|
916
1054
|
},
|
|
917
1055
|
reserve: reserveTemplateTargets,
|
|
918
1056
|
prepareIdentities: (job, signal) => prepareTemplateAidBatch(pathsForIdentity(), job, loadDaemonConfig().aid ?? '', createTemplateIdentityTransport(job), signal),
|
|
@@ -942,7 +1080,7 @@ function createInstallationDependencies(options) {
|
|
|
942
1080
|
if (readInitialization(aid)?.status !== 'complete')
|
|
943
1081
|
options.initialization.resume(aid, actor, requestId);
|
|
944
1082
|
await options.initialization.settle(aid);
|
|
945
|
-
return readInitialization(aid)?.status === 'complete'
|
|
1083
|
+
return readInitialization(aid)?.status === 'complete';
|
|
946
1084
|
},
|
|
947
1085
|
ownsMember: ownsTemplateMember,
|
|
948
1086
|
stop: (aid, job) => stopTemplateMember(job, aid, options),
|