evolcore 0.0.46 → 0.0.48
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 +93 -0
- package/bin/ec-build.mjs +86 -0
- package/dist/agent-template/jobs.js +12 -4
- package/dist/agent-template/runtime.js +139 -39
- package/dist/agent-template/service.js +66 -13
- package/dist/agents/baseagent.js +60 -20
- package/dist/agents/claude-runner.js +43 -18
- package/dist/agents/codex/app-server-client.js +32 -23
- package/dist/agents/codex-runner.js +31 -16
- package/dist/agents/ecagent-runner.js +7 -4
- package/dist/agents/gemini-runner.js +5 -2
- package/dist/agents/runner-types.js +5 -21
- package/dist/aun/aid/agentmd.js +5 -1
- package/dist/aun/group/fs-download.js +1 -1
- package/dist/aun/service-proxy.js +4 -2
- package/dist/build-identity.json +1 -0
- package/dist/channels/aun.js +100 -32
- package/dist/channels/daemon.js +10 -26
- package/dist/cli/aun-commands.js +86 -51
- package/dist/cli/code-stats.js +19 -8
- package/dist/cli/command-log.js +1 -1
- package/dist/cli/daemon-commands.js +65 -76
- package/dist/cli/daemon-lifecycle-client.js +17 -3
- package/dist/cli/directory.js +7 -1
- package/dist/cli/ecmsg-gateway.js +5 -2
- package/dist/cli/index.js +2 -8
- package/dist/cli/init-channel.js +6 -8
- package/dist/cli/init.js +74 -46
- package/dist/cli/invoke-command.js +1 -1
- package/dist/cli/provider-command.js +74 -13
- package/dist/cli/restart-monitor.js +104 -28
- package/dist/cli/role.js +61 -17
- package/dist/cli/stats.js +3 -3
- package/dist/cli/task-context.js +83 -15
- package/dist/cli/thread-command.js +16 -51
- package/dist/cli/upgrade-command.js +4 -2
- package/dist/config/boot-log.js +3 -9
- package/dist/config/builtin-roles.js +5 -7
- package/dist/config/config-manager.js +31 -23
- package/dist/config/daemon-services.js +30 -3
- package/dist/config/gateway-config.js +2 -2
- package/dist/config/invoke-ipc-service.js +6 -4
- package/dist/config/peer-bind-code.js +3 -4
- package/dist/config/peer-book-store.js +59 -218
- package/dist/config/peer-book.js +26 -27
- package/dist/config/peer-role-resolver.js +16 -1
- package/dist/config/provider-identity-migration.js +161 -6
- package/dist/config/provider-ipc-service.js +56 -11
- package/dist/config/provider-menu-request.js +24 -5
- package/dist/config/provider-templates.js +127 -0
- package/dist/config/providers-config.js +59 -8
- package/dist/config/providers-management.js +467 -49
- package/dist/config/role-command-service.js +248 -1
- package/dist/config/schema-migration.js +228 -20
- package/dist/config/schema-registry.js +6 -2
- package/dist/core/agent-application-service.js +6 -1
- package/dist/core/agent-runtime.js +10 -5
- package/dist/core/auth/agent-delegation.js +10 -4
- package/dist/core/auth/auth-gateway.js +2 -1
- package/dist/core/auth/delegation-authorization.js +3 -0
- package/dist/core/auth/delegation-diagnostics.js +56 -15
- package/dist/core/auth/operation-authorizer.js +26 -1
- package/dist/core/auth/operation-catalog.js +28 -64
- package/dist/core/capability/providers/codex-capability-provider.js +7 -8
- package/dist/core/channel-loader.js +18 -0
- package/dist/core/command/agent-control.js +32 -0
- package/dist/core/command/command-handler.js +81 -85
- package/dist/core/command/menu-catalog.js +1 -0
- package/dist/core/command/menu-handler.js +65 -153
- package/dist/core/command/menu-protocol.js +7 -1
- package/dist/core/command/provider-menu.js +13 -3
- package/dist/core/command/role-menu.js +47 -23
- package/dist/core/command/slash-handler.js +30 -49
- package/dist/core/command/team-workspace-items.js +81 -12
- package/dist/core/command/team-workspace-team.js +9 -71
- package/dist/core/command/topic-slash.js +9 -30
- package/dist/core/daemon-bootstrap.js +19 -10
- package/dist/core/daemon-control.js +8 -10
- package/dist/core/daemon-lifecycle.js +50 -40
- package/dist/core/evolagent-registry.js +22 -3
- package/dist/core/file-integrity/store.js +2 -0
- package/dist/core/handoff/runtime.js +37 -1
- package/dist/core/host-snapshot.js +9 -4
- package/dist/core/inference/text-inference.js +3 -1
- package/dist/core/initialization/service.js +31 -8
- package/dist/core/interaction-router.js +3 -0
- package/dist/core/invoke/executors/text.js +72 -19
- package/dist/core/ipc-registration.js +6 -4
- package/dist/core/memory/consolidation.js +6 -6
- package/dist/core/message/aun-ipc-sender.js +165 -55
- package/dist/core/message/im-renderer.js +1 -1
- package/dist/core/message/message-bridge.js +51 -334
- package/dist/core/message/message-log.js +5 -0
- package/dist/core/message/message-queue.js +22 -0
- package/dist/core/message/message-utils.js +8 -0
- package/dist/core/message/response-engine.js +429 -116
- package/dist/core/message/send-routing.js +5 -1
- package/dist/core/model/catalog-service.js +31 -11
- package/dist/core/model/model-capabilities.js +22 -4
- package/dist/core/model/model-catalog.js +1 -0
- package/dist/core/ownership/owner-resolver.js +355 -60
- package/dist/core/permission/protected-paths.js +6 -6
- package/dist/core/relation/peer-identity.js +28 -2
- package/dist/core/relation/same-owner-proof.js +81 -111
- package/dist/core/session/adapters/claude-session-file-adapter.js +1 -1
- package/dist/core/session/adapters/codex-session-file-adapter.js +96 -15
- package/dist/core/session/session-file-health.js +49 -14
- package/dist/core/session/session-fs-store.js +91 -35
- package/dist/core/session/session-manager.js +68 -24
- package/dist/core/session/session-mapper.js +14 -34
- package/dist/core/session/session-transcript.js +5 -1
- package/dist/core/task/task-activity-store.js +84 -0
- package/dist/core/task/task-image-resources.js +1 -1
- package/dist/core/task/task-recovery-service.js +12 -0
- package/dist/core/thread/command-parser.js +7 -12
- package/dist/core/thread/thread-context-storage.js +3 -2
- package/dist/core/thread/thread-operation.js +2 -13
- package/dist/core/thread/thread-service.js +15 -46
- package/dist/directory/owner-directory-admission.js +1 -1
- package/dist/directory/owner-directory-cache.js +45 -28
- package/dist/directory/owner-directory-markdown.js +13 -1
- package/dist/directory/owner-directory-query-operation.js +29 -3
- package/dist/directory/owner-directory-remarks.js +11 -3
- package/dist/eck/message-renderer.js +84 -24
- package/dist/ecweb/basic-settings-service.js +3 -1
- package/dist/ecweb/message-context-service.js +1 -1
- package/dist/ecweb/pairing.js +4 -3
- package/dist/ecweb/providers-service.js +26 -1
- package/dist/ecweb/runtime/lifecycle.js +82 -23
- package/dist/ecweb/runtime/proxy-access.js +74 -0
- package/dist/ecweb/runtime/supervisor.js +6 -17
- package/dist/event-center/registry.js +13 -2
- package/dist/event-center/runtime.js +103 -11
- package/dist/event-center/script-runner.js +5 -5
- package/dist/index.js +129 -93
- package/dist/ipc.js +15 -3
- package/dist/outputs/events.js +62 -0
- package/dist/outputs/protocol.js +102 -0
- package/dist/outputs/service.js +279 -0
- package/dist/paths.js +3 -0
- package/dist/proxy/manager.js +43 -13
- package/dist/services/index.js +89 -4
- package/dist/services/ipc-operation.js +4 -15
- package/dist/services/pack-manager.js +12 -1
- package/dist/services/router.js +21 -6
- package/dist/services/script-runner.js +5 -4
- package/dist/services/validation.js +1 -1
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +19 -0
- package/dist/stats/index.js +1 -1
- package/dist/stats/{price-resolver.js → model-resolver.js} +305 -24
- package/dist/stats/normalizer.js +2 -0
- package/dist/stats/query.js +35 -27
- package/dist/stats/role-budget.js +5 -2
- package/dist/stats/writer.js +10 -6
- package/dist/trigger/audit.js +7 -0
- package/dist/trigger/authorization.js +105 -11
- package/dist/trigger/feedback.js +10 -0
- package/dist/trigger/history.js +37 -11
- package/dist/trigger/ipc-service.js +12 -1
- package/dist/trigger/manager.js +1 -0
- package/dist/trigger/scheduler.js +11 -5
- package/dist/trigger/script-executor.js +2 -1
- package/dist/trigger/script-sandbox.js +9 -3
- package/dist/trigger/state.js +7 -0
- package/dist/trigger/validation.js +22 -0
- package/dist/utils/aid-bind.js +155 -18
- package/dist/utils/atomic-write.js +3 -3
- package/dist/utils/cross-platform.js +97 -31
- package/dist/utils/error-dict.json +94 -4
- package/dist/utils/error-utils.js +40 -4
- package/dist/utils/evolcore-version.js +36 -65
- package/dist/utils/instance-registry.js +61 -0
- package/dist/utils/msg-diag.js +1 -0
- package/dist/utils/process-introspect.js +158 -8
- package/dist/utils/process-tree.js +50 -2
- package/dist/utils/upgrade-jobs.js +4 -4
- package/dist/utils/windows-shell-trust.js +2 -0
- package/dist/workbench/protocol.js +80 -0
- package/dist/workbench/service.js +359 -0
- package/ecagent/dist/types.d.ts +6 -2
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +2 -2
- package/kits/docs/evolcore/aid.md +3 -1
- package/kits/docs/evolcore/config.md +12 -0
- package/kits/docs/evolcore/directory.md +22 -3
- package/kits/docs/evolcore/ecweb-lifecycle.md +15 -0
- package/kits/docs/evolcore/model.md +10 -0
- package/kits/docs/evolcore/peer.md +19 -65
- package/kits/docs/evolcore/provider.md +133 -5
- package/kits/docs/evolcore/role.md +80 -0
- package/kits/docs/evolcore/services.md +6 -6
- package/kits/docs/evolcore/team-workspace.md +1 -1
- package/kits/docs/evolcore/thread-chain.md +14 -15
- package/kits/docs/evolcore/tool-authorization.md +5 -0
- package/kits/docs/evolcore/trigger.md +10 -0
- package/kits/eck_message_manifest.json +12 -0
- package/kits/provider-templates.json +1213 -0
- package/kits/rules/04-relation.md +3 -3
- package/kits/schemas/_meta.json +14 -2
- package/kits/schemas/contact-book.schema.4.json +52 -0
- package/kits/schemas/providers.schema.3.json +200 -0
- package/kits/skills/.switches.json +4 -0
- package/kits/skills/ability/references/calling.md +1 -1
- package/kits/skills/ec-group/SKILL.md +2 -2
- package/kits/skills/ec-identity/SKILL.md +19 -72
- package/kits/skills/ec-provider/SKILL.md +221 -0
- package/kits/skills/ec-provider/scripts/check-model.mjs +80 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/skills/thread-ops/SKILL.md +34 -21
- package/kits/templates/message-fragments/group-batch-item.md +1 -1
- package/kits/templates/message-fragments/group-batch.md +1 -1
- package/kits/templates/message-fragments/inject-default.md +1 -1
- package/kits/templates/message-fragments/interrupt-insert.md +1 -0
- package/kits/templates/message-fragments/item-group.md +1 -1
- package/kits/templates/message-fragments/item-private.md +1 -1
- package/kits/templates/message-fragments/thread-context.md +1 -1
- package/kits/templates/message-fragments/trigger-session.md +1 -1
- package/kits/templates/message-fragments/trigger-thread-check.md +1 -1
- package/kits/templates/roles/admin.json +2 -19
- package/kits/templates/roles/member.json +0 -3
- package/kits/templates/system-fragments/baseagent.md +6 -0
- package/kits/templates/system-fragments/commands.md +3 -3
- package/kits/templates/system-fragments/managed-runtime.md +1 -1
- package/kits/templates/system-fragments/relation.md +1 -1
- package/kits/templates/system-fragments/thread.md +6 -5
- package/package.json +6 -4
- package/scripts/agent-template/inspect.mjs +4 -1
- package/scripts/agent-template/shared/common.mjs +2 -3
- package/scripts/agent-template/shared/template-contract.mjs +2 -1
- package/scripts/agent-template/shared/template-package.mjs +9 -2
- package/scripts/agent-template/shared/template-runtime.mjs +20 -5
- package/scripts/agent-template/team-pack.mjs +6 -3
- package/dist/cli/peer.js +0 -127
- package/dist/config/peer-operation-service.js +0 -132
- package/dist/config/peer-request-service.js +0 -532
- package/dist/core/command/connect-menu.js +0 -624
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,99 @@
|
|
|
5
5
|
|
|
6
6
|
## Unreleased
|
|
7
7
|
|
|
8
|
+
## 0.0.48 (2026-11-14)
|
|
9
|
+
|
|
10
|
+
### 成果、工作台与服务
|
|
11
|
+
|
|
12
|
+
- 新增内置成果服务,支持 Agent 产物目录的快照、分类列表、详情与增量查询,通过变更事件通知刷新。
|
|
13
|
+
- 新增内置工作台服务,提供运行概览、当前任务、最近执行及保留历史;任务明细按 Owner 私聊权限过滤。
|
|
14
|
+
- 成果与工作台查询要求加密传输和当前协议 Owner 身份,完善撤权、路径与链接检查、分页和并发限制;服务总开关默认开启,支持显式停用。
|
|
15
|
+
|
|
16
|
+
### 消息、话题与恢复
|
|
17
|
+
|
|
18
|
+
- 修复跨话题委托、自派及复查的目标和回流路由,强化发送一致性校验;同话题普通回复不再生成跨话题收件箱记录,复查支持关闭。
|
|
19
|
+
- 话题统一为 active、closed、archived 三种状态;closed 收到新消息自动重开,归档话题不再进入任务处理,私聊返回归档提示、群聊静默处理。
|
|
20
|
+
- 统一消息信封中的关系角色和来源标识,中断后新消息提示由模板渲染,并完善历史识别和主动发送诊断。
|
|
21
|
+
- 修复补充信息交互被中断后的任务状态误判,保留正确的待处理与恢复状态。
|
|
22
|
+
- 优化 Codex 历史读取、大文件并发访问与取消,减少会话列表、详情及后台查询对主线程的阻塞。
|
|
23
|
+
|
|
24
|
+
### 身份、名录与权限
|
|
25
|
+
|
|
26
|
+
- 统一 Ownership 权威证据的 30 分钟缓存与查询调度,支持可信快照跨重启恢复,初始化与敏感操作复用有效共识。
|
|
27
|
+
- 联系人名称与团队成员准入统一依据 Owner 名录;本地对端状态仅保留黑名单及跨渠道身份映射,迁移旧数据并保留备份。
|
|
28
|
+
- 黑名单管理改用 ec directory block/unblock,退役旧 ec peer、/connect 和 /request 联系人流程;准入策略查询与更新迁入 Agent 接口。
|
|
29
|
+
- 完善名录恢复与权限拒绝诊断,避免重复探测及依赖不可用时的菜单短周期重试。
|
|
30
|
+
- 新增 ec role quota 配额命令;角色定义和配额修改由 DaemonOwner 管理,并支持可信 fullaccess 操作;已有角色分配由所属 Agent Owner 管理,额度耗尽时发送加密调整申请。
|
|
31
|
+
|
|
32
|
+
### 模型、连接与统计
|
|
33
|
+
|
|
34
|
+
- 内置国产模型服务商的 API 与套餐端点模板,支持命令行、Web 及应用接入;统一同域服务合并、服务级凭据覆盖、模板输入校验和无密钥导出脱敏。
|
|
35
|
+
- 新增服务商连接补录交互,按具体错误引导修复;补录后验证目标模型真实调用,统一四种文本协议的模型可用性检查,防止凭据进入消息日志和观察者转发,完善失效、重试及备用模型切换顺序。
|
|
36
|
+
- Provider 支持独立配置模型目录路径,目录子路径不可用时尝试同源根目录;按目录地址隔离缓存,并记录上下文窗口的来源。
|
|
37
|
+
- 统一三基座自动压缩阈值计算,按窗口预留空间并将上限设为 550,000 token;Claude 与任务开始前主动压缩采用当前 Provider 目录显式窗口,缺失时不再根据模型名或历史阈值推断。
|
|
38
|
+
- 系统上下文显示实际生效的 Provider 与推理强度,改善模型调用诊断并脱敏命令日志中的密钥。
|
|
39
|
+
- 用量统计新增 Provider 维度;保存模型别名并统一模型汇总与排行,兼容旧归档,保留历史明细和已记录费用,隔离不同运行目录的别名缓存。
|
|
40
|
+
- 支持 DeepSeek 官方高峰与空闲分时计价,修正同生效时间的价格覆盖顺序;美元兑人民币汇率仅接受 3 至 15,缺失或非法时使用 7.23。
|
|
41
|
+
|
|
42
|
+
### 模板与自动化
|
|
43
|
+
|
|
44
|
+
- 模板支持原生连接来源导出与目标连接匹配,完善下载授权、嵌套凭据检查、覆盖安装、停用目标授权、Windows 写入及失败恢复。
|
|
45
|
+
- Trigger 执行区分创建者身份与投递目标,修复授权误判;支持配置单次执行总时限,并优化执行记录汇总读取。
|
|
46
|
+
- 消息接收事件保留任务因果上下文,使事件触发沿用原有链路并避免重复触发。
|
|
47
|
+
|
|
48
|
+
### 初始化与运行管理
|
|
49
|
+
|
|
50
|
+
- EC Web 默认启用本地服务及 public 代理,保留显式停用配置;未初始化主机可先启动本地 Web,首次身份准备后支持通过重启激活,修复显式启用时未写回开关的问题。
|
|
51
|
+
- 验证外网代理对应当前就绪实例后展示入口,支持外网健康检查跟随重定向;统一初始化链接,本地交互安装自动打开浏览器,完善随包 Web 依赖识别和代理状态展示。
|
|
52
|
+
- 优化 Windows 进程查询、进程快照与 Shell 信任验证重试;EC Web 停止前校验实时进程身份,临时端口占用后重试启动。
|
|
53
|
+
- 修复 Windows 会话日志残缺尾行恢复时的句柄权限问题,校验文件身份并保留已提交记录,恢复失败时停止追加。
|
|
54
|
+
- 将构建标识生成并入统一构建流程,区分运行时代码与磁盘产物,完善更新状态诊断,减少代码统计及后台查询的重复扫描。
|
|
55
|
+
- SDK 升级并固定为 @agentunion/fastaun 0.5.36,跟进 Ownership 缓存、事件消息大小、消息交付及 UDP 待机改进。
|
|
56
|
+
|
|
57
|
+
### 兼容要求
|
|
58
|
+
|
|
59
|
+
- 需要 Node.js >=22.16.0,依赖 @agentunion/fastaun 0.5.36,配套 ec-web@0.0.48。
|
|
60
|
+
- 旧话题状态 pending、in_progress、completed 按 active 读取;移除话题标签字段及 label 命令。
|
|
61
|
+
- Invoke 尚未完成,本版不将其列为可用功能;相关测试继续跳过。
|
|
62
|
+
|
|
63
|
+
## 0.0.47 (2026-11-12)
|
|
64
|
+
|
|
65
|
+
### 消息、会话与恢复
|
|
66
|
+
|
|
67
|
+
- 统一私聊、群聊和批次消息信封,明确来源关系、群角色及消息 ID;兼容旧信封,修复历史会话标题清理与导入候选识别。
|
|
68
|
+
- 队列恢复按消费账本和精确会话路由重建,跳过已覆盖历史;持久化失败保留顺序重试,恢复失败阻止不完整任务启动。
|
|
69
|
+
- Trigger 中断恢复沿用原执行尝试,使用独立投递标识继续处理,保留既有消费去重记录。
|
|
70
|
+
- 修复 Codex 0.164 已更新 Provider 索引、文件头仍旧时续聊被拒绝的问题;保留原线程、历史、备份和中断恢复,并完善冲突诊断。
|
|
71
|
+
- 修复 Windows Codex 会话索引与实际文件采用不同路径写法时的误报,区分索引缺失、字段异常与路径解析失败。
|
|
72
|
+
|
|
73
|
+
### 身份、模板与权限
|
|
74
|
+
|
|
75
|
+
- 恢复 Evol App 扫码绑定,按请求指纹复用处理结果;提交后回执丢失时保留待确认状态,避免重复提交,允许提交前失败重新检查。
|
|
76
|
+
- 恢复 active Agent 的配置补绑;EC Web 初始化与页面入口核验主机 Owner,绑定待确认期间阻止重复发起。
|
|
77
|
+
- 统一多成员模板的检查、选择冻结、打包和安装协议,支持内部成员引用;异常恢复复用已确认的身份准备、绑定及 Owner 共识结果。
|
|
78
|
+
- 区分发送方关系与群角色,群默认角色缺失时回落 visitor;服务查看要求 member 及以上,禁止为保留服务类型配置调用规则。
|
|
79
|
+
|
|
80
|
+
### 启动、升级与运行管理
|
|
81
|
+
|
|
82
|
+
- EC Web 启动不再等待 Agent 恢复;非启动必需依赖按需加载,主机信息探测移至后台,复用配置、关系扫描和状态查询快照,渠道连接并发上限设为八。
|
|
83
|
+
- 优化 Windows 进程查询和重启等待,提前请求旧进程优雅退出;通过子进程退出事件确认托管 EC Web 停止,Codex 子进程停止改用异步处理。
|
|
84
|
+
- 停机时取消待执行的所有权回调,停止耗时记录覆盖下线通知和渠道关闭阶段。
|
|
85
|
+
- 修复配置缺失时 Agent 无法停用、重复删除与卸载清理问题;修复升级监控暂存目录遗漏运行脚本,并兼容升级接口直接返回的 Menu 响应。
|
|
86
|
+
- Menu 短连接使用 SDK 标准事件接收响应,沿用渠道加密配置;远程作业等待过滤重复或乱序进度并释放连接资源。
|
|
87
|
+
|
|
88
|
+
### 配置与内部维护
|
|
89
|
+
|
|
90
|
+
- Provider 自动迁移遇到规划冲突时保留现有配置、输出具体诊断并继续启动;写入前重新校验引用和连接设置。
|
|
91
|
+
- 避免配置迁移重复写入未变化内容,完善 Windows 文件替换重试、只读属性恢复与中断回滚,保留原始失败原因。
|
|
92
|
+
- 初始化使用当前 Schema 版本;Provider 同步遵循模型启用策略,旧 ID 迁移保留接口风格、模型列表和策略。
|
|
93
|
+
- 复用权限已满足的会话临时目录,目录准备失败时返回明确的不可重试错误。
|
|
94
|
+
- 完善内置资源完整性检查,整合渠道、关系、模板、工作区和台账模块,保留旧格式迁移及写入前保护。
|
|
95
|
+
|
|
96
|
+
### 兼容要求
|
|
97
|
+
|
|
98
|
+
- 需要 Node.js >=22.16.0、@agentunion/fastaun ^0.5.35,配套 ec-web@0.0.47。
|
|
99
|
+
- Invoke 尚未完成,本版不将其列为可用功能;相关测试继续跳过。
|
|
100
|
+
|
|
8
101
|
## 0.0.46 (2026-11-11)
|
|
9
102
|
|
|
10
103
|
### 消息、会话与恢复
|
package/bin/ec-build.mjs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import crypto from 'node:crypto';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const root = fileURLToPath(new URL('../', import.meta.url));
|
|
8
|
+
|
|
9
|
+
function run(cwd, args, npmCli) {
|
|
10
|
+
return new Promise(resolve => {
|
|
11
|
+
const child = spawn(process.execPath, [npmCli, ...args], {
|
|
12
|
+
cwd,
|
|
13
|
+
env: process.env,
|
|
14
|
+
stdio: 'inherit',
|
|
15
|
+
windowsHide: true,
|
|
16
|
+
});
|
|
17
|
+
child.once('error', error => {
|
|
18
|
+
console.error(`Build could not start (${cwd}): ${error.message}`);
|
|
19
|
+
resolve(1);
|
|
20
|
+
});
|
|
21
|
+
child.once('close', code => resolve(code ?? 1));
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function build() {
|
|
26
|
+
const npmCli = process.env.npm_execpath;
|
|
27
|
+
if (!npmCli) throw new Error('Run this script through npm run build.');
|
|
28
|
+
// Core builds ecagent first because the daemon imports its emitted declarations.
|
|
29
|
+
// ECWeb is independent. Always join both: the restart monitor must not roll back
|
|
30
|
+
// while a sibling build can still write artifacts.
|
|
31
|
+
const results = await Promise.allSettled([
|
|
32
|
+
run(root, ['run', 'build:core'], npmCli),
|
|
33
|
+
run(path.join(root, 'ecweb'), ['run', 'build'], npmCli),
|
|
34
|
+
]);
|
|
35
|
+
for (const result of results) {
|
|
36
|
+
if (result.status === 'rejected') console.error(`Build failed: ${result.reason}`);
|
|
37
|
+
}
|
|
38
|
+
process.exitCode = results.some(result => result.status === 'rejected' || result.value !== 0) ? 1 : 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// The marker and embedded values must not contribute to their own content hash.
|
|
42
|
+
const excluded = new Set(['build-identity.json', 'build-identity.json.tmp']);
|
|
43
|
+
const identityBlock = /^\/\/ @evolcore-build-identity:start\r?\n[\s\S]*?^\/\/ @evolcore-build-identity:end[ \t]*(?=\r?$)/m;
|
|
44
|
+
const identitySource = (id, builtAt) => [
|
|
45
|
+
'// @evolcore-build-identity:start',
|
|
46
|
+
`export const RUNTIME_BUILD_ID = ${JSON.stringify(id)};`,
|
|
47
|
+
`export const RUNTIME_BUILD_TIME = ${JSON.stringify(builtAt)};`,
|
|
48
|
+
'// @evolcore-build-identity:end',
|
|
49
|
+
].join('\n');
|
|
50
|
+
|
|
51
|
+
/** Called by postbuild:core, including when Core is built without ECWeb. */
|
|
52
|
+
export async function writeBuildIdentity(distDir = path.join(root, 'dist')) {
|
|
53
|
+
const runtimeFile = path.join(distDir, 'utils', 'evolcore-version.js');
|
|
54
|
+
const runtimeSource = await fs.promises.readFile(runtimeFile, 'utf8');
|
|
55
|
+
if ((runtimeSource.match(new RegExp(identityBlock.source, 'gm')) ?? []).length !== 1) {
|
|
56
|
+
throw new Error('Expected one embedded build identity block in utils/evolcore-version.js');
|
|
57
|
+
}
|
|
58
|
+
const hash = crypto.createHash('sha256');
|
|
59
|
+
async function collect(directory) {
|
|
60
|
+
const entries = await fs.promises.readdir(directory, { withFileTypes: true });
|
|
61
|
+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
62
|
+
const full = path.join(directory, entry.name);
|
|
63
|
+
const relative = path.relative(distDir, full).replaceAll(path.sep, '/');
|
|
64
|
+
if (excluded.has(relative)) continue;
|
|
65
|
+
if (entry.isDirectory()) await collect(full);
|
|
66
|
+
else if (entry.isFile()) {
|
|
67
|
+
const content = relative === 'utils/evolcore-version.js'
|
|
68
|
+
? runtimeSource.replace(identityBlock, identitySource(null, null))
|
|
69
|
+
: await fs.promises.readFile(full);
|
|
70
|
+
hash.update(relative);
|
|
71
|
+
hash.update('\0');
|
|
72
|
+
hash.update(content);
|
|
73
|
+
hash.update('\0');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
await collect(distDir);
|
|
78
|
+
const identity = { id: `sha256:${hash.digest('hex').slice(0, 24)}`, builtAt: new Date().toISOString() };
|
|
79
|
+
await fs.promises.writeFile(runtimeFile,
|
|
80
|
+
runtimeSource.replace(identityBlock, identitySource(identity.id, identity.builtAt)));
|
|
81
|
+
// Publish the disk marker last; running daemons retain their imported constant.
|
|
82
|
+
const marker = path.join(distDir, 'build-identity.json');
|
|
83
|
+
await fs.promises.writeFile(marker + '.tmp', JSON.stringify(identity) + '\n');
|
|
84
|
+
await fs.promises.rename(marker + '.tmp', marker);
|
|
85
|
+
return identity;
|
|
86
|
+
}
|
|
@@ -13,7 +13,8 @@ export function templateFingerprint(value) {
|
|
|
13
13
|
export function writeTemplateState(file, value) {
|
|
14
14
|
atomicWriteJson(file, value);
|
|
15
15
|
fs.chmodSync(file, 0o600);
|
|
16
|
-
|
|
16
|
+
// Windows requires a writable handle for FlushFileBuffers/fsync.
|
|
17
|
+
const descriptor = fs.openSync(file, 'r+');
|
|
17
18
|
try {
|
|
18
19
|
fs.fsyncSync(descriptor);
|
|
19
20
|
}
|
|
@@ -67,7 +68,8 @@ export class TemplateJobs {
|
|
|
67
68
|
throw templateError('CONFLICT', 'Template job revision changed', { jobId: job.jobId });
|
|
68
69
|
}
|
|
69
70
|
if (!current.committed && job.committed && (current.status !== 'running' || !current.activating
|
|
70
|
-
|| job.status !== 'succeeded' || !Object.values(job.members).every(member => member.runtimeReady
|
|
71
|
+
|| job.status !== 'succeeded' || !Object.values(job.members).every(member => member.runtimeReady
|
|
72
|
+
|| job.checkpoint.installMode === 'overwrite' && job.checkpoint.runtimeInactive === true))) {
|
|
71
73
|
throw templateError('CONFLICT', 'Only the current prepared deployment can commit');
|
|
72
74
|
}
|
|
73
75
|
}
|
|
@@ -151,10 +153,9 @@ export class TemplateJobs {
|
|
|
151
153
|
}
|
|
152
154
|
}
|
|
153
155
|
/** Durable installation associations are checked before ordinary task dispatch. */
|
|
154
|
-
export function templateInstallationGate(aid, expectedJobId) {
|
|
156
|
+
export function templateInstallationGate(aid, expectedJobId, root = resolveRoot()) {
|
|
155
157
|
if (!aid || /[/\\\0]/.test(aid))
|
|
156
158
|
return { blocked: true, activating: false };
|
|
157
|
-
const root = resolveRoot();
|
|
158
159
|
try {
|
|
159
160
|
const file = path.join(root, 'data', 'template', 'members', templateFingerprint(aid) + '.json');
|
|
160
161
|
if (!fs.existsSync(file)) {
|
|
@@ -182,3 +183,10 @@ export function templateInstallationGate(aid, expectedJobId) {
|
|
|
182
183
|
return { blocked: true, activating: false };
|
|
183
184
|
}
|
|
184
185
|
}
|
|
186
|
+
/** Ordinary lifecycle operations cannot release an unfinished installation. */
|
|
187
|
+
export function assertTemplateInstallationReady(aid, recoveryJobId) {
|
|
188
|
+
const gate = templateInstallationGate(aid);
|
|
189
|
+
if (gate.blocked && (!recoveryJobId || gate.jobId !== recoveryJobId)) {
|
|
190
|
+
throw templateError('RECOVERY_REQUIRED', 'Template installation requires recovery through its original job', { jobId: gate.jobId });
|
|
191
|
+
}
|
|
192
|
+
}
|
|
@@ -13,7 +13,8 @@ import fs from 'node:fs';
|
|
|
13
13
|
import path from 'node:path';
|
|
14
14
|
import { createHash } from 'node:crypto';
|
|
15
15
|
import { stringify } from 'yaml';
|
|
16
|
-
import { validateAgentMdDocument } from '@agentunion/fastaun';
|
|
16
|
+
import { validateAgentMdDocument, StorageLowLevel, StorageVFS } from '@agentunion/fastaun';
|
|
17
|
+
import { resolveBaseagentModelSelection, resolveLegacyBaseagentModelSelection } from '../agents/baseagent.js';
|
|
17
18
|
import { ownerResolver, getDaemonOwners } from '../core/ownership/owner-resolver.js';
|
|
18
19
|
import { resolvePaths, getPackageRoot } from '../paths.js';
|
|
19
20
|
import { loadAgent, loadDaemonConfig } from '../config-store.js';
|
|
@@ -26,9 +27,10 @@ import { getProviderCatalog, assertCatalogSelectable, resolveCatalogModel, catal
|
|
|
26
27
|
import { AgentTemplateService } from './service.js';
|
|
27
28
|
import { templateError, templateJobAids } from './types.js';
|
|
28
29
|
import { refreshSkillIndex } from '../core/skill/startup.js';
|
|
29
|
-
import { TemplateJobs, templateFingerprint, writeTemplateState } from './jobs.js';
|
|
30
|
+
import { TemplateJobs, templateFingerprint, writeTemplateState, assertTemplateInstallationReady, templateInstallationGate } from './jobs.js';
|
|
30
31
|
import { getAidStore, loadClient } from '../aun/aid/store.js';
|
|
31
32
|
import { creationOwnershipBinding } from '../core/ownership/owner-resolver.js';
|
|
33
|
+
const publicTemplate = await import(new URL('../../scripts/agent-template/shared/template-runtime.mjs', import.meta.url).href);
|
|
32
34
|
/** Fence collection workers before runners or Trigger schedulers are loaded. */
|
|
33
35
|
export async function restoreTemplatesBeforeStartup(root) {
|
|
34
36
|
const blocked = new Set();
|
|
@@ -74,6 +76,12 @@ export async function restoreTemplatesBeforeStartup(root) {
|
|
|
74
76
|
jobs.save(job);
|
|
75
77
|
}
|
|
76
78
|
else if (job.action === 'deploy' && !job.committed) {
|
|
79
|
+
if (!job.checkpoint.restored)
|
|
80
|
+
for (const aid of templateJobAids(job)) {
|
|
81
|
+
const gate = templateInstallationGate(aid, undefined, root);
|
|
82
|
+
if (gate.blocked && (!gate.jobId || gate.jobId === job.jobId))
|
|
83
|
+
pending.add(aid);
|
|
84
|
+
}
|
|
77
85
|
job.status = 'paused';
|
|
78
86
|
job.activating = false;
|
|
79
87
|
job.resumable = true;
|
|
@@ -253,10 +261,126 @@ export function createTemplateIdentityTransport(job) {
|
|
|
253
261
|
};
|
|
254
262
|
}
|
|
255
263
|
const FIELDS = ['name', 'description', 'avatar', 'tags', 'exttype'];
|
|
256
|
-
|
|
264
|
+
/** Only public behavior and runner model choices may enter collection checkpoints. */
|
|
265
|
+
export function resolveTemplateSourceConfig(effective, scope = {}) {
|
|
266
|
+
const source = { baseagents: {} };
|
|
267
|
+
for (const field of ['chatmode', 'memory', 'active_baseagent']) {
|
|
268
|
+
if (effective[field] !== undefined)
|
|
269
|
+
source[field] = structuredClone(effective[field]);
|
|
270
|
+
}
|
|
271
|
+
for (const name of ['claude', 'codex', 'gemini', 'ecagent']) {
|
|
272
|
+
const configured = effective.baseagents?.[name];
|
|
273
|
+
if (!configured || typeof configured !== 'object' || Array.isArray(configured))
|
|
274
|
+
continue;
|
|
275
|
+
const block = {};
|
|
276
|
+
for (const field of ['provider', 'model', 'effort', 'params']) {
|
|
277
|
+
if (configured[field] !== undefined)
|
|
278
|
+
block[field] = structuredClone(configured[field]);
|
|
279
|
+
}
|
|
280
|
+
const selection = resolveBaseagentModelSelection(name, configured, scope);
|
|
281
|
+
if (selection) {
|
|
282
|
+
block.model = selection.model;
|
|
283
|
+
if (selection.effort !== undefined)
|
|
284
|
+
block.effort = selection.effort;
|
|
285
|
+
}
|
|
286
|
+
else if (name === 'codex') {
|
|
287
|
+
const effort = [configured.effort, configured.reasoning, resolveLegacyBaseagentModelSelection(name, scope)?.effort]
|
|
288
|
+
.find(value => typeof value === 'string' && value.trim());
|
|
289
|
+
if (effort)
|
|
290
|
+
block.effort = effort.trim();
|
|
291
|
+
}
|
|
292
|
+
if (name === 'gemini')
|
|
293
|
+
delete block.effort;
|
|
294
|
+
source.baseagents[name] = block;
|
|
295
|
+
}
|
|
296
|
+
publicTemplate.assertPublicTemplateConfig(source);
|
|
297
|
+
return source;
|
|
298
|
+
}
|
|
299
|
+
/** Use the SDK's ticket routing and authentication contract with a bounded data plane. */
|
|
300
|
+
export async function downloadTemplatePackage(client, file, location, shareId) {
|
|
301
|
+
const limit = 200 * 1024 * 1024;
|
|
302
|
+
const read = async (url, headers) => {
|
|
303
|
+
if (new URL(url).protocol !== 'https:')
|
|
304
|
+
throw templateError('DOWNLOAD_FAILED', 'Storage downloads require HTTPS');
|
|
305
|
+
const response = await fetch(url, { headers, redirect: 'error', signal: AbortSignal.timeout(120_000) });
|
|
306
|
+
if ([401, 403].includes(response.status))
|
|
307
|
+
throw templateError('ACCESS_DENIED', 'Storage download authorization was rejected');
|
|
308
|
+
if (!response.ok || !response.body)
|
|
309
|
+
throw templateError('DOWNLOAD_FAILED', 'Download HTTP ' + response.status);
|
|
310
|
+
const chunks = [];
|
|
311
|
+
let size = 0;
|
|
312
|
+
try {
|
|
313
|
+
if (Number(response.headers.get('content-length')) > limit)
|
|
314
|
+
throw new Error('Package exceeds 200 MiB');
|
|
315
|
+
for await (const bytes of response.body) {
|
|
316
|
+
size += bytes.byteLength;
|
|
317
|
+
if (size > limit)
|
|
318
|
+
throw new Error('Package exceeds 200 MiB');
|
|
319
|
+
chunks.push(bytes);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
catch (error) {
|
|
323
|
+
await response.body.cancel().catch(() => { });
|
|
324
|
+
throw error;
|
|
325
|
+
}
|
|
326
|
+
return Buffer.concat(chunks, size);
|
|
327
|
+
};
|
|
328
|
+
if (shareId) {
|
|
329
|
+
const value = await client.call('storage.get_by_share', { share_id: shareId, owner_aid: location.aid });
|
|
330
|
+
if (String(value.object_key ?? value.path ?? '').replace(/^\/+/, '') !== location.path.replace(/^\/+/, '')
|
|
331
|
+
|| value.owner_aid && value.owner_aid !== location.aid)
|
|
332
|
+
throw templateError('INTEGRITY_FAILED', 'Share points to another package');
|
|
333
|
+
if (typeof value.content === 'string' && value.content.length > Math.ceil(limit / 3) * 4)
|
|
334
|
+
throw new Error('Package exceeds 200 MiB');
|
|
335
|
+
const bytes = typeof value.content === 'string' ? Buffer.from(value.content, 'base64') : await read(value.download_url);
|
|
336
|
+
if (bytes.length > limit)
|
|
337
|
+
throw new Error('Package exceeds 200 MiB');
|
|
338
|
+
const handle = fs.openSync(file, 'wx', 0o600);
|
|
339
|
+
let written = false;
|
|
340
|
+
try {
|
|
341
|
+
fs.writeFileSync(handle, bytes);
|
|
342
|
+
written = true;
|
|
343
|
+
}
|
|
344
|
+
finally {
|
|
345
|
+
fs.closeSync(handle);
|
|
346
|
+
if (!written)
|
|
347
|
+
fs.rmSync(file, { force: true });
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
const lowlevel = new StorageLowLevel(client);
|
|
352
|
+
const ticket = lowlevel.createDownloadTicket.bind(lowlevel);
|
|
353
|
+
lowlevel.createDownloadTicket = async (options) => {
|
|
354
|
+
const value = await ticket(options);
|
|
355
|
+
if (value.owner_aid && value.owner_aid !== location.aid
|
|
356
|
+
|| value.object_key && value.object_key !== location.path.replace(/^\/+/, '')) {
|
|
357
|
+
throw templateError('INTEGRITY_FAILED', 'Ticket points to another package');
|
|
358
|
+
}
|
|
359
|
+
if (Number(value.size_bytes) > limit)
|
|
360
|
+
throw new Error('Package exceeds 200 MiB');
|
|
361
|
+
return value;
|
|
362
|
+
};
|
|
363
|
+
lowlevel.httpGet = read;
|
|
364
|
+
const storage = new StorageVFS(client, { lowlevel });
|
|
365
|
+
let created = false;
|
|
366
|
+
try {
|
|
367
|
+
// Reserve our own destination; SDK writes only into the reserved file.
|
|
368
|
+
fs.closeSync(fs.openSync(file, 'wx', 0o600));
|
|
369
|
+
created = true;
|
|
370
|
+
await storage.downloadFile(location.path, file, { owner: location.aid, bucket: 'default', overwrite: true, noCache: true });
|
|
371
|
+
}
|
|
372
|
+
catch (error) {
|
|
373
|
+
if (created)
|
|
374
|
+
fs.rmSync(file, { force: true });
|
|
375
|
+
throw error;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
export async function authorizeTemplateOwner(actor, aid, recoveryJobId) {
|
|
257
380
|
if (!getDaemonOwners().includes(actor))
|
|
258
381
|
throw templateError('NOT_ALLOWED', 'DaemonOwner required', { reason: 'DAEMON_OWNER_REQUIRED' });
|
|
259
|
-
|
|
382
|
+
assertTemplateInstallationReady(aid, recoveryJobId);
|
|
383
|
+
const owner = await ownerResolver.refreshForAuthorization(aid);
|
|
260
384
|
if (owner.refreshFailure || owner.consensusStatus !== 'consensus' || owner.ownerAid !== actor) {
|
|
261
385
|
throw templateError('NOT_ALLOWED', 'Agent Owner required', { reason: 'AGENT_OWNER_REQUIRED' });
|
|
262
386
|
}
|
|
@@ -292,12 +416,16 @@ export function createAgentTemplateRuntime(options) {
|
|
|
292
416
|
block.provider = resolveProviderId(block.provider, providers);
|
|
293
417
|
return { home: paths.root, packageRoot: getPackageRoot(), agentDir: path.join(paths.agentsDir, aid), agentAid: aid, targetAid: aid,
|
|
294
418
|
ownerAid: actor, hostAid: requireHost().getAid(), ...card, targetConfig: raw, effectiveConfig: config,
|
|
295
|
-
projectPath: agent.projectPath, providers: providers.providers,
|
|
419
|
+
projectPath: agent.projectPath, runtimeStatus: agent.status, providers: providers.providers,
|
|
296
420
|
publisher: { aid: actor }, skills: resolveAllSkillStates(path.join(paths.agentsDir, aid)).map(s => ({ name: s.name, type: s.source, enabled: s.enabled })) };
|
|
297
421
|
};
|
|
298
422
|
return new AgentTemplateService({
|
|
299
423
|
root: paths.root, hostAid: loadDaemonConfig().aid ?? '', authorize: authorizeTemplateOwner,
|
|
300
|
-
source:
|
|
424
|
+
source: async (aid, actor) => {
|
|
425
|
+
const { targetConfig: _raw, effectiveConfig, providers, ...source } = await context(aid, actor);
|
|
426
|
+
return { ...source, effectiveConfig: resolveTemplateSourceConfig(effectiveConfig),
|
|
427
|
+
providers: Object.fromEntries(Object.entries(providers).map(([id, value]) => [id, { name: value.name }])) };
|
|
428
|
+
}, target: context,
|
|
301
429
|
installation: createInstallationDependencies(options),
|
|
302
430
|
hold: async (aid, token) => {
|
|
303
431
|
const releaseGate = await options.coordinator.acquireForMutation(aid, token);
|
|
@@ -314,12 +442,12 @@ export function createAgentTemplateRuntime(options) {
|
|
|
314
442
|
}
|
|
315
443
|
return async () => { await releaseScheduler?.(); releaseHandoff?.(); await releaseGate(); };
|
|
316
444
|
},
|
|
317
|
-
reload: async (aid) => {
|
|
445
|
+
reload: async (aid, jobId, restoreStopped) => {
|
|
318
446
|
notifyConfigWrite(ConfigTarget.Agent, { self: aid });
|
|
319
447
|
refreshSkillIndex(path.join(paths.agentsDir, aid), aid);
|
|
320
|
-
await options.reloadInsideGate(aid);
|
|
448
|
+
await options.reloadInsideGate(aid, jobId, restoreStopped);
|
|
321
449
|
},
|
|
322
|
-
block: options.block, readProfile: profile,
|
|
450
|
+
block: options.block, recoveryComplete: aid => options.recoveryComplete?.(aid, true), readProfile: profile,
|
|
323
451
|
validateModels: async (config, refs) => {
|
|
324
452
|
for (const ref of refs) {
|
|
325
453
|
if (!ref.provider)
|
|
@@ -382,40 +510,12 @@ export function createAgentTemplateRuntime(options) {
|
|
|
382
510
|
},
|
|
383
511
|
download: async (shareId, file, location) => {
|
|
384
512
|
try {
|
|
385
|
-
|
|
386
|
-
// A share code is local to its storage issuer; owner_aid routes cross-issuer reads.
|
|
387
|
-
const value = await channel.callClient('storage.get_by_share', { share_id: shareId, owner_aid: location.aid });
|
|
388
|
-
const key = String(value.object_key ?? value.path ?? '').replace(/^\/+/, '');
|
|
389
|
-
if (key !== location.path.replace(/^\/+/, '') || value.owner_aid && value.owner_aid !== location.aid) {
|
|
390
|
-
throw templateError('INTEGRITY_FAILED', 'Share points to another package');
|
|
391
|
-
}
|
|
392
|
-
if (typeof value.content === 'string')
|
|
393
|
-
fs.writeFileSync(file, Buffer.from(value.content, 'base64'));
|
|
394
|
-
else if (typeof value.download_url === 'string') {
|
|
395
|
-
const response = await fetch(value.download_url, { signal: AbortSignal.timeout(120_000) });
|
|
396
|
-
if (!response.ok || !response.body)
|
|
397
|
-
throw new Error('Download HTTP ' + response.status);
|
|
398
|
-
const handle = fs.openSync(file, 'wx', 0o600);
|
|
399
|
-
let size = 0;
|
|
400
|
-
try {
|
|
401
|
-
for await (const bytes of response.body) {
|
|
402
|
-
size += bytes.length;
|
|
403
|
-
if (size > 200 * 1024 * 1024)
|
|
404
|
-
throw new Error('Package exceeds 200 MiB');
|
|
405
|
-
fs.writeSync(handle, bytes);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
finally {
|
|
409
|
-
fs.closeSync(handle);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
else
|
|
413
|
-
throw new Error('Share response has no content/download_url');
|
|
513
|
+
await downloadTemplatePackage(requireHost().getClient(), file, location, shareId);
|
|
414
514
|
}
|
|
415
515
|
catch (error) {
|
|
416
516
|
if (error.code === 'INTEGRITY_FAILED')
|
|
417
517
|
throw error;
|
|
418
|
-
throw templateError(/access|denied|expired|32004/i.test(String(error.code) + error.message) ? 'ACCESS_DENIED' : 'DOWNLOAD_FAILED', error.message);
|
|
518
|
+
throw templateError(/access|denied|forbidden|expired|eacces|32004|403/i.test(String(error.code) + error.message) ? 'ACCESS_DENIED' : 'DOWNLOAD_FAILED', error.message);
|
|
419
519
|
}
|
|
420
520
|
},
|
|
421
521
|
});
|
|
@@ -134,6 +134,14 @@ export class AgentTemplateService {
|
|
|
134
134
|
this.work.set(job.jobId, work);
|
|
135
135
|
}
|
|
136
136
|
async wait(jobId) { await this.work.get(jobId); }
|
|
137
|
+
async completeRecovery(aid) {
|
|
138
|
+
try {
|
|
139
|
+
await this.deps.recoveryComplete?.(aid);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
logger.warn('[Template] Recovery notification failed: ' + String(error));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
137
145
|
async query(actor, args) {
|
|
138
146
|
await this.deps.installation.authorize(actor);
|
|
139
147
|
return this.view(this.jobs.get(actor, args));
|
|
@@ -377,8 +385,22 @@ export class AgentTemplateService {
|
|
|
377
385
|
const cancel = (async () => {
|
|
378
386
|
await this.work.get(jobId);
|
|
379
387
|
const current = this.jobs.read(jobId);
|
|
380
|
-
if (current.action === 'deploy')
|
|
381
|
-
|
|
388
|
+
if (current.action === 'deploy') {
|
|
389
|
+
const overwrite = this.previewRecord(current.args.previewId).installMode === 'overwrite';
|
|
390
|
+
const aid = Object.values(current.members)[0]?.aid;
|
|
391
|
+
const release = overwrite && aid ? await this.deps.hold(aid, current.jobId) : undefined;
|
|
392
|
+
try {
|
|
393
|
+
await this.compensate(current);
|
|
394
|
+
}
|
|
395
|
+
catch (error) {
|
|
396
|
+
if (overwrite && aid && current.checkpoint.backupDir && !current.checkpoint.restored)
|
|
397
|
+
await this.deps.block(aid);
|
|
398
|
+
throw error;
|
|
399
|
+
}
|
|
400
|
+
finally {
|
|
401
|
+
await release?.();
|
|
402
|
+
}
|
|
403
|
+
}
|
|
382
404
|
else {
|
|
383
405
|
const packageId = current.checkpoint.packageId;
|
|
384
406
|
if (packageId)
|
|
@@ -446,7 +468,7 @@ export class AgentTemplateService {
|
|
|
446
468
|
this.jobs.save(job);
|
|
447
469
|
const archivePath = path.join(directory, 'package.ectpl');
|
|
448
470
|
if (source.kind === 'remote')
|
|
449
|
-
await this.step(job, () => this.deps.download(source.download
|
|
471
|
+
await this.step(job, () => this.deps.download(source.download?.shareId, archivePath, source.location));
|
|
450
472
|
else
|
|
451
473
|
fs.copyFileSync(source.path, archivePath);
|
|
452
474
|
const data = await this.executeTool(job, 'read-package', { archivePath, digest: source.digest });
|
|
@@ -648,7 +670,7 @@ export class AgentTemplateService {
|
|
|
648
670
|
this.jobs.save(job);
|
|
649
671
|
for (const [key, member] of Object.entries(job.members)) {
|
|
650
672
|
await this.step(job, () => this.deps.installation.authorize(job.actor));
|
|
651
|
-
await this.step(job, () => this.deps.reload(member.aid));
|
|
673
|
+
await this.step(job, () => this.deps.reload(member.aid, job.jobId));
|
|
652
674
|
const profile = { ...record.data.profiles[key], description: record.plans[key].description };
|
|
653
675
|
await this.publishProfile(job, key, profile, legacyProfiles);
|
|
654
676
|
}
|
|
@@ -697,6 +719,8 @@ export class AgentTemplateService {
|
|
|
697
719
|
installMode: record.installMode, committed: true, members: Object.fromEntries(Object.entries(job.members)
|
|
698
720
|
.map(([key, member]) => [key, { aid: member.aid, project: member.projectPath }])) };
|
|
699
721
|
this.jobs.save(job);
|
|
722
|
+
for (const member of Object.values(job.members))
|
|
723
|
+
await this.completeRecovery(member.aid);
|
|
700
724
|
}
|
|
701
725
|
async publishProfile(job, key, profile, legacyRecovery) {
|
|
702
726
|
const member = job.members[key];
|
|
@@ -736,26 +760,39 @@ export class AgentTemplateService {
|
|
|
736
760
|
const member = Object.values(job.members)[0];
|
|
737
761
|
const key = Object.keys(job.members)[0];
|
|
738
762
|
const release = await this.deps.hold(member.aid, job.jobId);
|
|
763
|
+
let authorized = false;
|
|
739
764
|
try {
|
|
740
|
-
await this.step(job, () => this.deps.authorize(job.actor, member.aid));
|
|
765
|
+
await this.step(job, () => this.deps.authorize(job.actor, member.aid, job.jobId));
|
|
766
|
+
authorized = true;
|
|
767
|
+
if (job.checkpoint.backupDir && !job.checkpoint.restored)
|
|
768
|
+
await this.compensate(job);
|
|
769
|
+
if (job.checkpoint.restored) {
|
|
770
|
+
delete job.checkpoint.backupDir;
|
|
771
|
+
delete job.checkpoint.originalProfile;
|
|
772
|
+
delete member.profilePublication;
|
|
773
|
+
this.jobs.save(job);
|
|
774
|
+
}
|
|
741
775
|
const current = await this.step(job, () => this.deps.target(member.aid, job.actor));
|
|
742
776
|
if (current.projectPath !== member.projectPath)
|
|
743
777
|
throw templateError('TARGET_CHANGED', 'Target project changed');
|
|
778
|
+
job.checkpoint.runtimeStopped ??= current.runtimeStatus === 'stopped';
|
|
779
|
+
job.checkpoint.runtimeInactive ??= current.targetConfig?.enabled === false || current.runtimeStatus === 'stopped';
|
|
744
780
|
await this.executeTool(job, 'overlay', { operation: 'verify', planFile: record.data.planFile });
|
|
745
781
|
const original = await this.step(job, () => this.deps.readProfile(member.aid));
|
|
746
782
|
job.checkpoint.originalProfile = original;
|
|
747
|
-
job.checkpoint.backupDir = path.join(this.cache, 'backups', job.jobId);
|
|
783
|
+
job.checkpoint.backupDir = path.join(this.cache, 'backups', job.jobId + '-' + job.attempt);
|
|
748
784
|
job.checkpoint.installMode = 'overwrite';
|
|
785
|
+
job.checkpoint.restored = false;
|
|
749
786
|
this.jobs.save(job);
|
|
750
787
|
await this.executeTool(job, 'overlay', { planFile: record.data.planFile, backupDir: job.checkpoint.backupDir });
|
|
751
788
|
job.checkpoint.resourcesApplied = true;
|
|
752
789
|
this.jobs.save(job);
|
|
753
|
-
await this.step(job, () => this.deps.reload(member.aid));
|
|
790
|
+
await this.step(job, () => this.deps.reload(member.aid, job.jobId, job.checkpoint.runtimeStopped === true));
|
|
754
791
|
await this.publishProfile(job, key, record.data.profiles[key], false);
|
|
755
792
|
job.activating = true;
|
|
756
793
|
this.jobs.save(job);
|
|
757
794
|
member.runtimeReady = this.deps.installation.ready(member.aid);
|
|
758
|
-
if (!member.runtimeReady)
|
|
795
|
+
if (!member.runtimeReady && !job.checkpoint.runtimeInactive)
|
|
759
796
|
throw templateError('RECOVERY_REQUIRED', 'Reloaded target is not ready');
|
|
760
797
|
job.committed = true;
|
|
761
798
|
job.activating = false;
|
|
@@ -765,18 +802,23 @@ export class AgentTemplateService {
|
|
|
765
802
|
job.result = { packageId: record.packageId, previewId: record.previewId, planDigest: record.planDigest,
|
|
766
803
|
installMode: 'overwrite', committed: true, members: { [key]: { aid: member.aid, project: member.projectPath } } };
|
|
767
804
|
this.jobs.save(job);
|
|
805
|
+
await this.completeRecovery(member.aid);
|
|
768
806
|
}
|
|
769
807
|
catch (error) {
|
|
770
808
|
const current = this.jobs.read(job.jobId);
|
|
771
|
-
|
|
809
|
+
if (authorized)
|
|
810
|
+
await this.compensate(current);
|
|
772
811
|
throw error;
|
|
773
812
|
}
|
|
774
813
|
finally {
|
|
775
814
|
const current = this.jobs.read(job.jobId);
|
|
776
|
-
|
|
815
|
+
try {
|
|
816
|
+
if (!current.committed && !current.checkpoint.restored && current.checkpoint.backupDir)
|
|
817
|
+
await this.deps.block(member.aid);
|
|
818
|
+
}
|
|
819
|
+
finally {
|
|
777
820
|
await release();
|
|
778
|
-
|
|
779
|
-
this.deps.block(member.aid);
|
|
821
|
+
}
|
|
780
822
|
}
|
|
781
823
|
}
|
|
782
824
|
async compensate(job) {
|
|
@@ -799,6 +841,16 @@ export class AgentTemplateService {
|
|
|
799
841
|
}
|
|
800
842
|
const member = Object.values(job.members)[0];
|
|
801
843
|
const key = Object.keys(job.members)[0];
|
|
844
|
+
await this.deps.authorize(job.actor, member.aid, job.jobId);
|
|
845
|
+
if (job.checkpoint.restored)
|
|
846
|
+
return;
|
|
847
|
+
if (!job.checkpoint.backupDir) {
|
|
848
|
+
job.checkpoint.restored = true;
|
|
849
|
+
job.activating = false;
|
|
850
|
+
this.jobs.save(job);
|
|
851
|
+
await this.completeRecovery(member.aid);
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
802
854
|
if (job.checkpoint.backupDir && fs.existsSync(path.join(job.checkpoint.backupDir, 'journal.json'))) {
|
|
803
855
|
await this.tool('overlay', { operation: 'restore', backupDir: job.checkpoint.backupDir });
|
|
804
856
|
}
|
|
@@ -814,10 +866,11 @@ export class AgentTemplateService {
|
|
|
814
866
|
await this.deps.publishProfile(member.aid, original.profile, current.profileVersion);
|
|
815
867
|
}
|
|
816
868
|
}
|
|
817
|
-
await this.deps.reload(member.aid);
|
|
869
|
+
await this.deps.reload(member.aid, job.jobId, job.checkpoint.runtimeStopped === true);
|
|
818
870
|
job.checkpoint.restored = true;
|
|
819
871
|
job.activating = false;
|
|
820
872
|
this.jobs.save(job);
|
|
873
|
+
await this.completeRecovery(member.aid);
|
|
821
874
|
}
|
|
822
875
|
}
|
|
823
876
|
let activeService;
|