evolcore 0.0.49 → 0.0.50
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 +64 -1
- package/bin/ecmsg.js +9 -4
- package/dist/ability/caller/authorization.js +21 -0
- package/dist/ability/caller/command.js +164 -0
- package/dist/ability/caller/contract.js +102 -0
- package/dist/ability/caller/daemon.js +158 -0
- package/dist/ability/caller/service.js +380 -0
- package/dist/ability/command-contract.js +5 -0
- package/dist/ability/daemon.js +5 -1
- package/dist/ability/interop-v1.js +10 -3
- package/dist/ability/management.js +1 -0
- package/dist/agent-template/jobs.js +173 -1
- package/dist/agent-template/runtime.js +280 -6
- package/dist/agent-template/service.js +1159 -40
- package/dist/agent-template/types.js +2 -1
- package/dist/agents/baseagent-availability.js +27 -3
- package/dist/agents/baseagent-capability-adapter.js +102 -0
- package/dist/agents/baseagent-plugin-descriptor.js +274 -0
- package/dist/agents/baseagent-plugin-loader.js +145 -0
- package/dist/agents/baseagent.js +68 -2
- package/dist/agents/claude-gateway/agent-registration.js +389 -0
- package/dist/agents/claude-gateway/binding.js +96 -0
- package/dist/agents/claude-gateway/inbox.js +138 -0
- package/dist/agents/claude-gateway/index.js +125 -0
- package/dist/agents/claude-gateway/listing.js +330 -0
- package/dist/agents/claude-gateway/router.js +328 -0
- package/dist/agents/claude-gateway/sessions.js +128 -0
- package/dist/agents/claude-gateway/terminal.js +250 -0
- package/dist/agents/claude-gateway/transcript.js +272 -0
- package/dist/agents/claude-gateway/types.js +14 -0
- package/dist/agents/claude-runner.js +6 -10
- package/dist/agents/codex-runner.js +4 -1
- package/dist/agents/{gemini-runner.js → gemini/gemini-runner.js} +17 -17
- package/dist/{core/session/adapters → agents/gemini}/gemini-session-file-adapter.js +2 -2
- package/dist/agents/gemini/index.js +51 -0
- package/dist/aun/aid/control-aid.js +52 -32
- package/dist/aun/group/invite-service.js +6 -36
- package/dist/aun/group/operations.js +6 -0
- package/dist/aun/msg/mention-schema.js +1 -1
- package/dist/aun/msg/p2p.js +29 -1
- package/dist/aun/msg/upload.js +126 -3
- package/dist/build-identity.json +1 -1
- package/dist/channels/aun.js +537 -189
- package/dist/cli/ability-command.js +42 -0
- package/dist/cli/agent-command.js +20 -1
- package/dist/cli/agent-create.js +78 -18
- package/dist/cli/agent-template.js +5 -3
- package/dist/cli/agent.js +91 -0
- package/dist/cli/aun-commands.js +92 -34
- package/dist/cli/bench.js +5 -2
- package/dist/cli/config.js +22 -6
- package/dist/cli/daemon-commands.js +245 -101
- package/dist/cli/ecmsg-gateway.js +11 -9
- package/dist/cli/index.js +23 -4
- package/dist/cli/init.js +39 -63
- package/dist/cli/managed-command-guard.js +1 -0
- package/dist/cli/menu-client.js +32 -7
- package/dist/cli/pay-command.js +30 -0
- package/dist/cli/provider-command.js +6 -2
- package/dist/cli/restart-monitor.js +2 -2
- package/dist/cli/services-command.js +11 -9
- package/dist/cli/thread-command.js +78 -12
- package/dist/config/access-policy.js +16 -3
- package/dist/config/config-field-policy.js +17 -8
- package/dist/config/config-manager.js +86 -46
- package/dist/config/config-operation-service.js +22 -1
- package/dist/config/gateway-config.js +9 -8
- package/dist/config/owner-config.js +0 -16
- package/dist/config/peer-role-resolver.js +1 -7
- package/dist/config/providers-config.js +99 -16
- package/dist/config/providers-management.js +35 -19
- package/dist/config/resolved-config-op.js +1 -42
- package/dist/config/schema-migration.js +78 -5
- package/dist/config/schema-registry.js +52 -7
- package/dist/config-store.js +1309 -17
- package/dist/core/agent-application-service.js +220 -1
- package/dist/core/agent-ipc-registration.js +19 -2
- package/dist/core/agent-reload-coordinator.js +5 -0
- package/dist/core/agent-runtime.js +198 -54
- package/dist/core/auth/agent-delegation.js +14 -0
- package/dist/core/auth/operation-authorizer.js +16 -1
- package/dist/core/auth/operation-catalog.js +50 -7
- package/dist/core/baseagent-loader.js +30 -3
- package/dist/core/capability/capability-manager.js +16 -7
- package/dist/core/channel-runtime.js +4 -2
- package/dist/core/command/agent-control.js +20 -2
- package/dist/core/command/agent-template-menu.js +4 -3
- package/dist/core/command/cli-intent-parser.js +15 -0
- package/dist/core/command/menu-catalog.js +20 -4
- package/dist/core/command/menu-file-path.js +70 -0
- package/dist/core/command/menu-handler.js +91 -72
- package/dist/core/command/menu-protocol.js +5 -0
- package/dist/core/command/menu-query-batch.js +2 -2
- package/dist/core/command/private-mention-menu.js +71 -0
- package/dist/core/command/slash-handler.js +17 -26
- package/dist/core/command/team-workspace-bootstrap.js +2 -1
- package/dist/core/command/topic-slash.js +7 -1
- package/dist/core/daemon-bootstrap.js +0 -4
- package/dist/core/daemon-control.js +2 -1
- package/dist/core/daemon-lifecycle.js +13 -5
- package/dist/core/evolagent-registry.js +12 -7
- package/dist/core/handoff/runtime.js +1 -1
- package/dist/core/host-snapshot.js +8 -3
- package/dist/core/initialization/service.js +3 -0
- package/dist/core/interaction-router.js +130 -0
- package/dist/core/ipc-registration.js +4 -0
- package/dist/core/memory/consolidation-context.js +2 -1
- package/dist/core/memory/consolidation.js +35 -64
- package/dist/core/message/aun-ipc-sender.js +98 -21
- package/dist/core/message/aun-request-registry.js +31 -0
- package/dist/core/message/message-bridge.js +105 -6
- package/dist/core/message/message-log.js +8 -0
- package/dist/core/message/message-queue.js +5 -3
- package/dist/core/message/peer-mode.js +15 -4
- package/dist/core/message/response-engine.js +23 -8
- package/dist/core/message/send-options.js +37 -3
- package/dist/core/message/send-routing.js +11 -7
- package/dist/core/model/model-catalog.js +5 -5
- package/dist/core/ownership/owner-resolver.js +12 -86
- package/dist/core/pack-auth.js +4 -0
- package/dist/core/permission/ec-command-parser.js +182 -58
- package/dist/core/permission/protected-paths.js +64 -9
- package/dist/core/permission/services-path-acl.js +9 -2
- package/dist/core/permission/tool-policy.js +21 -9
- package/dist/core/session/adapters/claude-session-file-adapter.js +6 -2
- package/dist/core/session/adapters/codex-session-file-adapter.js +4 -0
- package/dist/core/session/session-manager.js +47 -10
- package/dist/core/session/session-mapper.js +16 -0
- package/dist/core/skill/index-generator.js +2 -3
- package/dist/core/skill/switch-resolver.js +3 -0
- package/dist/core/thread/command-parser.js +4 -1
- package/dist/core/thread/ipc-operation.js +4 -2
- package/dist/core/thread/thread-operation.js +25 -10
- package/dist/core/thread/thread-service.js +294 -55
- package/dist/core/thread/topic-id.js +52 -2
- package/dist/core/thread/types.js +15 -1
- package/dist/eck/kit-renderer.js +2 -1
- package/dist/ecweb/basic-settings-service.js +5 -9
- package/dist/ecweb/providers-service.js +4 -2
- package/dist/index.js +116 -41
- package/dist/ipc.js +58 -2
- package/dist/paths.js +48 -1
- package/dist/pay/command.js +38 -0
- package/dist/pay/protocol.js +136 -0
- package/dist/pay/runtime.js +188 -0
- package/dist/pay/service.js +384 -0
- package/dist/pay/store.js +81 -0
- package/dist/response-system/engines/v1/proactive-flow.js +29 -2
- package/dist/services/dispatcher.js +23 -5
- package/dist/services/host/main.js +388 -0
- package/dist/services/host/protocol.js +118 -0
- package/dist/services/host/resident.js +310 -0
- package/dist/services/host-client.js +386 -0
- package/dist/services/host-deploy.js +180 -0
- package/dist/services/host-launch.js +117 -0
- package/dist/services/host-recycle.js +203 -0
- package/dist/services/host-runtime.js +802 -0
- package/dist/services/idempotency.js +44 -86
- package/dist/services/index-generator.js +4 -3
- package/dist/services/index.js +176 -18
- package/dist/services/ipc-operation.js +204 -44
- package/dist/services/script-runner.js +515 -83
- package/dist/services/validation.js +109 -4
- package/dist/trigger/application-service.js +6 -4
- package/dist/trigger/local-files.js +19 -9
- package/dist/trigger/scheduler.js +22 -12
- package/dist/trigger/script-sandbox.js +51 -20
- package/dist/utils/aid-bind.js +3 -0
- package/dist/utils/evolcore-version.js +2 -2
- package/dist/utils/host-info.js +73 -0
- package/dist/utils/logger.js +2 -2
- package/dist/utils/media-cache.js +190 -43
- package/dist/utils/restart-safety.js +14 -1
- package/dist/utils/system-memory.js +113 -25
- package/dist/utils/systemd-lifecycle.js +154 -0
- package/dist/utils/windows-shell-trust.js +7 -3
- package/kits/docs/INDEX.md +3 -2
- package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +1 -0
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/evolcore/INDEX.md +7 -6
- package/kits/docs/evolcore/agent.md +36 -1
- package/kits/docs/evolcore/aid.md +20 -3
- package/kits/docs/evolcore/config.md +1 -1
- package/kits/docs/evolcore/group.md +2 -1
- package/kits/docs/evolcore/memory-tags.md +2 -0
- package/kits/docs/evolcore/menu-client.md +3 -3
- package/kits/docs/evolcore/menu-protocol.md +7 -0
- package/kits/docs/evolcore/model.md +3 -0
- package/kits/docs/evolcore/msg.md +68 -10
- package/kits/docs/evolcore/pay.md +34 -0
- package/kits/docs/evolcore/provider.md +21 -0
- package/kits/docs/evolcore/services.md +46 -18
- package/kits/docs/evolcore/thread-chain.md +2 -0
- package/kits/docs/evolcore/tool-authorization.md +10 -0
- package/kits/rules/01-overview.md +11 -32
- package/kits/rules/02-navigation.md +7 -0
- package/kits/rules/06-channel.md +3 -3
- package/kits/schemas/_meta.json +38 -5
- package/kits/schemas/agent-config.schema.21.json +974 -0
- package/kits/schemas/agent-config.schema.22.json +977 -0
- package/kits/schemas/agent-config.schema.23.json +958 -0
- package/kits/schemas/daemon.schema.10.json +373 -0
- package/kits/schemas/daemon.schema.9.json +12 -0
- package/kits/schemas/defaults.schema.7.json +472 -0
- package/kits/schemas/providers.schema.3.json +18 -2
- package/kits/schemas/relation-config.schema.13.json +289 -0
- package/kits/skills/.switches.json +13 -1
- package/kits/skills/ability/SKILL.md +229 -34
- package/kits/skills/ability/STRUCTURE.md +333 -0
- package/kits/skills/ability/references/cli.md +208 -0
- package/kits/skills/ability/references/development.md +107 -37
- package/kits/skills/ability/references/management.md +106 -46
- package/kits/skills/ability/references/runtime-protocol.md +65 -63
- package/kits/skills/agent-output-cards/SKILL.md +12 -5
- package/kits/skills/ec-group/SKILL.md +8 -6
- package/kits/skills/ec-group/TASK.md +186 -0
- package/kits/skills/ec-group/WORKLOG.md +180 -0
- package/kits/skills/ec-group-collaboration/SKILL.md +3 -3
- package/kits/skills/ec-pay/SKILL.md +101 -0
- package/kits/skills/ec-pay/references/pay-cli.md +110 -0
- package/kits/skills/ec-provider/SKILL.md +1 -1
- package/kits/skills/{ec-service-proxy → ec-proxy}/SKILL.md +8 -5
- package/kits/skills/ec-service-call/SKILL.md +135 -0
- package/kits/skills/ec-service-pack/SKILL.md +277 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/templates/memory-consolidation/notes.md +2 -2
- package/kits/templates/memory-consolidation/workflow.md +46 -0
- package/kits/templates/system-fragments/channel.md +13 -4
- package/kits/templates/system-fragments/commands.md +4 -3
- package/kits/templates/system-fragments/reply.md +1 -0
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +27 -129
- package/kits/templates/system-fragments/venue.md +16 -0
- package/package.json +4 -5
- package/scripts/agent-template/inspect.mjs +37 -23
- package/scripts/agent-template/overlay.mjs +20 -2
- package/scripts/agent-template/shared/common.mjs +16 -4
- package/scripts/agent-template/shared/team-schema.json +20 -4
- package/scripts/agent-template/shared/template-contract.mjs +53 -13
- package/scripts/agent-template/shared/template-package.mjs +90 -26
- package/scripts/agent-template/shared/template-runtime.mjs +111 -1
- package/scripts/agent-template/shared/template.mjs +65 -7
- package/scripts/agent-template/team-pack.mjs +89 -33
- package/scripts/agent-template/team-preview.mjs +249 -5
- package/kits/docs/aun/ABILITY_CALLING.md +0 -280
- package/kits/docs/evolcore/ability.md +0 -185
- package/kits/skills/ability/references/calling.md +0 -56
- package/kits/skills/ability/references/contract-checklist.md +0 -37
- package/kits/skills/ability/references/recovery.md +0 -27
- /package/dist/{core/capability/providers → agents/gemini}/gemini-capability-provider.js +0 -0
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
"$id": "urn:evolcore:agent-template:team:v1",
|
|
4
4
|
"title": "Agent 团队模板 v1",
|
|
5
5
|
"type": "object",
|
|
6
|
-
"required": ["$schema_version", "id", "
|
|
6
|
+
"required": ["$schema_version", "id", "version", "host", "agents"],
|
|
7
7
|
"additionalProperties": true,
|
|
8
8
|
"properties": {
|
|
9
9
|
"$schema_version": { "type": "integer", "const": 1, "default": 1, "title": "格式版本" },
|
|
10
|
-
"id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9._-]{0,63}$", "title": "模板 ID", "description": "稳定标识,对应 PACKAGE.id
|
|
11
|
-
"name": { "type": "string", "pattern": "^[a-z0-9][a-z0-9._-]{0,63}$", "title": "兼容模板标识(name)", "description": "过渡期保留,与 id 相同;后续版本再退役", "readOnly": true, "x-aliasOf": "id" },
|
|
10
|
+
"id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9._-]{0,63}$", "title": "模板 ID", "description": "稳定标识,对应 PACKAGE.id;旧 name 仅兼容输入,归一化后不再保留" },
|
|
12
11
|
"version": { "type": "string", "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$", "default": "1.0.0", "title": "模板版本" },
|
|
13
12
|
"title": { "type": "string", "minLength": 1, "maxLength": 64, "title": "模板显示名", "description": "发布时对应 PACKAGE.name;省略时使用模板标识" },
|
|
14
13
|
"description": { "type": "string", "maxLength": 500, "title": "模板说明" },
|
|
@@ -16,6 +15,7 @@
|
|
|
16
15
|
"host": {
|
|
17
16
|
"type": "object", "title": "主机", "required": ["platform"], "additionalProperties": false,
|
|
18
17
|
"properties": {
|
|
18
|
+
"name": { "type": "string", "minLength": 1, "maxLength": 64, "pattern": "[\\s\\S]*\\S[\\s\\S]*", "title": "魔盒主机名称", "description": "创建时发布为 Host AID 的名片显示名;省略时使用平台名主机-AID前缀,需要支持保留自定义Host名称的Core" },
|
|
19
19
|
"platform": { "type": "array", "title": "支持平台", "minItems": 1, "uniqueItems": true, "default": ["linux"], "items": { "type": "string", "enum": ["linux", "darwin", "win32"] } },
|
|
20
20
|
"config": { "type": "object", "title": "创建时的主机配置", "description": "仅创建流程使用,运行时继续由 EvolCore 配置 schema 校验", "additionalProperties": true, "properties": { "aun": { "type": "object", "title": "AUN 配置", "additionalProperties": true, "properties": { "defaultAidDomain": { "type": "string", "maxLength": 253, "pattern": "^(?![0-9]{1,3}(?:\\.[0-9]{1,3}){3}$)(?!.*\\.localhost$)[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)+$", "title": "默认 AID 域", "description": "团队身份注册与生成的 daemon 共用;省略时使用 agentid.cn" } } }, "services": { "type": "array", "title": "本地服务", "items": { "type": "object" } } } }
|
|
21
21
|
}
|
|
@@ -24,8 +24,14 @@
|
|
|
24
24
|
"type": "array", "title": "团队成员", "minItems": 1,
|
|
25
25
|
"items": {
|
|
26
26
|
"type": "object", "required": ["key", "profile"], "additionalProperties": true,
|
|
27
|
+
"oneOf": [
|
|
28
|
+
{ "properties": { "optional": { "const": false } }, "not": { "required": ["agentTemplateId"] } },
|
|
29
|
+
{ "required": ["optional", "agentTemplateId"], "properties": { "optional": { "const": true }, "profile": { "required": ["name", "description"] }, "config": { "type": "object", "additionalProperties": false, "properties": { "access": { "type": "object" } } } }, "not": { "anyOf": [{ "required": ["skills"] }, { "required": ["version"] }, { "required": ["update"] }] } }
|
|
30
|
+
],
|
|
27
31
|
"properties": {
|
|
28
32
|
"key": { "type": "string", "pattern": "^[a-z0-9][a-z0-9_-]{0,31}$", "title": "成员标识", "description": "对应资源目录与目标映射中的 key" },
|
|
33
|
+
"optional": { "type": "boolean", "title": "可选成员", "description": "默认不创建身份;用户以后从本Team成员列表安装" },
|
|
34
|
+
"agentTemplateId": { "type": "string", "pattern": "^agent_[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", "title": "Agent 模板唯一 ID", "description": "可选成员引用已确认的单Agent模板" },
|
|
29
35
|
"version": { "type": "string", "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$", "title": "Agent 版本", "description": "作者显式填写的版本声明;不自动生成或修改" },
|
|
30
36
|
"update": { "type": "object", "title": "升级参数声明", "additionalProperties": false, "required": ["mode"], "properties": { "mode": { "type": "string", "enum": ["auto", "manual", "disabled"], "title": "升级模式", "description": "仅保存声明,当前未启用升级执行机制" }, "publisher": { "type": "string", "pattern": "^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?){2,}$", "title": "发布者 AID", "description": "仅为发布者声明,不代表身份已验证" } } },
|
|
31
37
|
"profile": {
|
|
@@ -43,6 +49,15 @@
|
|
|
43
49
|
"type": "object", "title": "Agent 配置", "additionalProperties": true,
|
|
44
50
|
"description": "保留扩展配置;创建与覆盖分别执行本模式的能力边界和完整运行时校验",
|
|
45
51
|
"properties": {
|
|
52
|
+
"access": { "type": "object", "title": "访问默认设置", "description": "可选成员的安装默认值;下载模板显式字段覆盖", "additionalProperties": false, "properties": {
|
|
53
|
+
"contactAdmission": { "type": "string", "enum": ["legacy", "app-v1"], "title": "准入模式" },
|
|
54
|
+
"allowInternalContacts": { "type": "boolean", "title": "允许内部联系人" },
|
|
55
|
+
"allowExternalContacts": { "type": "boolean", "title": "允许外部联系人" },
|
|
56
|
+
"allowAllContacts": { "type": "boolean", "title": "允许所有联系人" },
|
|
57
|
+
"allowedAids": { "type": "array", "uniqueItems": true, "title": "允许 AID", "items": { "type": "string", "pattern": "^[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?){2,}$" } },
|
|
58
|
+
"deniedAids": { "type": "array", "uniqueItems": true, "title": "拒绝 AID", "items": { "type": "string", "pattern": "^[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?){2,}$" } },
|
|
59
|
+
"requestLimit": { "type": "object", "title": "请求限流", "additionalProperties": false, "properties": { "maxTimes": { "type": "integer", "minimum": 1, "maximum": 100000, "title": "次数" }, "coolDown": { "type": "integer", "minimum": 1, "maximum": 86400, "title": "冷却秒数" } } }
|
|
60
|
+
} },
|
|
46
61
|
"active_baseagent": { "type": "string", "title": "默认基座", "enum": ["claude", "codex", "gemini", "ecagent"] },
|
|
47
62
|
"baseagents": {
|
|
48
63
|
"type": "object", "title": "基座配置", "additionalProperties": {
|
|
@@ -66,7 +81,8 @@
|
|
|
66
81
|
}
|
|
67
82
|
}
|
|
68
83
|
},
|
|
69
|
-
"
|
|
84
|
+
"external_contacts": { "type": "array", "title": "外部成员", "items": { "type": "object", "required": ["aid"], "additionalProperties": false, "properties": { "aid": { "type": "string", "pattern": "^[a-z0-9][a-z0-9_-]*\\.(?:[a-z0-9-]+\\.)*[a-z0-9-]+$", "title": "AID" }, "name": { "type": "string", "minLength": 1, "title": "名称" } } } },
|
|
85
|
+
"personal_assistant": { "type": "integer", "minimum": 0, "title": "个人助理下标", "description": "创建团队时的个人助理成员下标,必须为非可选成员" },
|
|
70
86
|
"tags": { "type": "array", "title": "创建时的公共标签", "minItems": 1, "items": { "type": "string", "minLength": 1 } }
|
|
71
87
|
}
|
|
72
88
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
|
-
import { resolveMemberParameters } from './template-runtime.mjs';
|
|
3
|
+
import { resolveMemberParameters, partitionTeamMembers } from './template-runtime.mjs';
|
|
4
4
|
|
|
5
5
|
export const TEAM_SCHEMA_VERSION = 1;
|
|
6
6
|
export const PACKAGE_SCHEMA_VERSION = 1;
|
|
7
7
|
export const TEAM_SCHEMA_ID = 'urn:evolcore:agent-template:team:v1';
|
|
8
8
|
export const SELECTION_TTL_MS = 900000;
|
|
9
|
-
export const TEMPLATE_ACTIONS = ['inspect', 'build', 'push', 'pull', 'preview', 'deploy', 'status', 'resume', 'cancel', 'capabilities'
|
|
9
|
+
export const TEMPLATE_ACTIONS = ['inspect', 'build', 'push', 'pull', 'preview', 'deploy', 'status', 'resume', 'cancel', 'capabilities',
|
|
10
|
+
'register-team', 'team-members', 'prepare-member-install', 'resume-member-join',
|
|
11
|
+
'update-status', 'check-update', 'bind-update-source', 'confirm-update-source', 'preview-update', 'read-update-notice'];
|
|
10
12
|
const schema = JSON.parse(fs.readFileSync(new URL('./team-schema.json', import.meta.url), 'utf8'));
|
|
11
13
|
export const readTeamSchema = () => structuredClone(schema);
|
|
12
14
|
const record = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -20,6 +22,11 @@ const strings = { type: 'array', uniqueItems: true, items: string };
|
|
|
20
22
|
const object = (properties, required = Object.keys(properties)) => ({ type: 'object', properties, required, additionalProperties: false });
|
|
21
23
|
const members = item => ({ type: 'object', minProperties: 1, propertyNames: { pattern: MEMBER_KEY_PATTERN }, additionalProperties: item });
|
|
22
24
|
const jobId = { ...string, pattern: '^job_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' };
|
|
25
|
+
const instanceId = { ...string, pattern: '^team_[a-f0-9]{64}$' };
|
|
26
|
+
const memberKey = { ...string, pattern: MEMBER_KEY_PATTERN };
|
|
27
|
+
const memberInstallId = { ...string, pattern: '^member_install_[a-f0-9-]{36}$' };
|
|
28
|
+
const memberReferences = object({ optional: { type: 'array', items: schema.properties.agents.items },
|
|
29
|
+
external: schema.properties.external_contacts });
|
|
23
30
|
const location = object({ aid, path: { ...string, pattern: '^/[^\\\\\\u0000]*$' } });
|
|
24
31
|
const metadata = object({
|
|
25
32
|
id: schema.properties.id, name: { type: 'string', minLength: 1, maxLength: 64 },
|
|
@@ -36,10 +43,17 @@ const source = { oneOf: [
|
|
|
36
43
|
const include = object({ baseagents: strings, triggers: strings, skills: strings, files: strings, events: strings }, ['baseagents', 'triggers', 'skills', 'files']);
|
|
37
44
|
const provider = object({ provider: string, model: string, effort: { type: ['string', 'null'], minLength: 1 } }, ['provider', 'model']);
|
|
38
45
|
const selection = object({
|
|
39
|
-
target: object({ aid: { oneOf: [aid, { const: 'auto' }] }, project:
|
|
46
|
+
target: object({ aid: { oneOf: [aid, { const: 'auto' }] }, project: {
|
|
47
|
+
...string, description: 'Absolute path on the target host. Optional for create: the host allocates and freezes it during preview. Required for overwrite.',
|
|
48
|
+
} }, ['aid']),
|
|
40
49
|
providers: { type: 'object', propertyNames: { enum: ['claude', 'codex', 'gemini', 'ecagent'] }, additionalProperties: provider },
|
|
41
50
|
externalAids: { type: 'object', propertyNames: aid, additionalProperties: aid },
|
|
42
51
|
}, ['target']);
|
|
52
|
+
const updateSource = object({ catalogAid: aid, publisher: aid,
|
|
53
|
+
templateId: { ...string, pattern: '^[a-z0-9][a-z0-9._-]{0,63}$' }, memberKey });
|
|
54
|
+
const releaseId = { ...string, pattern: '^[a-f0-9]{64}$' };
|
|
55
|
+
const bindingId = { ...string, pattern: '^binding_[a-f0-9-]{36}$' };
|
|
56
|
+
const noticeId = { ...string, pattern: '^notice_[a-f0-9]{64}$' };
|
|
43
57
|
const inputSchemas = {
|
|
44
58
|
inspect: object({ members: members(object({ source: { oneOf: [
|
|
45
59
|
object({ kind: { const: 'agent' }, aid }),
|
|
@@ -48,15 +62,28 @@ const inputSchemas = {
|
|
|
48
62
|
build: object({ inspectionJobId: jobId, inventoryDigest: digest, metadata, members: members(object({ include,
|
|
49
63
|
version: schema.properties.agents.items.properties.version,
|
|
50
64
|
update: schema.properties.agents.items.properties.update,
|
|
51
|
-
}, ['include'])) }),
|
|
65
|
+
}, ['include'])), memberReferences, assistantKey: memberKey }, ['inspectionJobId', 'inventoryDigest', 'metadata', 'members']),
|
|
52
66
|
push: object({ packageId: string, location, releasedFindings: strings }),
|
|
53
|
-
pull: object({ source }),
|
|
54
|
-
preview: object({ packageId: string, installMode: { enum: ['create', 'overwrite'] }, members: members(selection), issuer: aid
|
|
67
|
+
pull: { oneOf: [object({ source }), object({ memberInstallId })] },
|
|
68
|
+
preview: object({ packageId: string, installMode: { enum: ['create', 'overwrite'] }, members: members(selection), issuer: aid,
|
|
69
|
+
memberInstallId }, ['packageId', 'installMode', 'members']),
|
|
55
70
|
deploy: object({ previewId: string, planDigest: digest }),
|
|
56
71
|
status: { oneOf: [object({ jobId }), object({ requestId: string })] },
|
|
57
72
|
resume: object({ jobId }),
|
|
58
73
|
cancel: object({ jobId }),
|
|
59
74
|
capabilities: object({}),
|
|
75
|
+
'register-team': object({ manifest: { type: 'object' }, deliveryDigest: digest }),
|
|
76
|
+
'team-members': { oneOf: [object({ instanceId }), object({ assistantAid: aid })] },
|
|
77
|
+
'prepare-member-install': object({ instanceId, memberKey, expectedRevision: digest }),
|
|
78
|
+
'resume-member-join': object({ instanceId, memberKey }),
|
|
79
|
+
'update-status': object({ targetAid: aid }),
|
|
80
|
+
'check-update': object({ targetAid: aid }),
|
|
81
|
+
'bind-update-source': object({ targetAid: aid, source: updateSource, releaseId }),
|
|
82
|
+
'confirm-update-source': object({ bindingId, planDigest: digest }),
|
|
83
|
+
'preview-update': object({ targetAid: aid, releaseId, providers: selection.properties.providers,
|
|
84
|
+
resolutions: { type: 'object', additionalProperties: { enum: ['keep-local', 'use-candidate'] } },
|
|
85
|
+
approvals: strings }, ['targetAid', 'releaseId']),
|
|
86
|
+
'read-update-notice': object({ targetAid: aid, noticeId }),
|
|
60
87
|
};
|
|
61
88
|
export const readTemplateInputSchemas = () => structuredClone(inputSchemas);
|
|
62
89
|
export const packageSchema = object({
|
|
@@ -71,7 +98,8 @@ export const packageRefSchema = object({
|
|
|
71
98
|
members: members(schema.properties.agents.items), externalAids: { ...strings, items: aid },
|
|
72
99
|
scan: object({ findings: { type: 'array', items: object({ id: string, memberKey: string, path: string, code: string, message: string }) } }),
|
|
73
100
|
excluded: { type: 'array', items: string },
|
|
74
|
-
}
|
|
101
|
+
memberReferences: { type: 'object' }, assistantKey: string,
|
|
102
|
+
}, ['packageId', 'digest', 'size', 'metadata', 'members', 'externalAids', 'scan', 'excluded']);
|
|
75
103
|
const freezeSchema = object({
|
|
76
104
|
state: { enum: ['acquiring', 'held', 'transferred', 'releasing', 'released'] },
|
|
77
105
|
generation: { type: 'integer', minimum: 1 }, frozenAt: { type: ['integer', 'null'] },
|
|
@@ -129,8 +157,14 @@ export function normalizeTeamSchema(local = {}) {
|
|
|
129
157
|
out.properties.$schema_version = structuredClone(schema.properties.$schema_version);
|
|
130
158
|
out.properties.version = structuredClone(schema.properties.version);
|
|
131
159
|
out.properties.host.properties.platform = structuredClone(schema.properties.host.properties.platform);
|
|
132
|
-
|
|
133
|
-
|
|
160
|
+
// Retired top-level name described the identifier, never the display title.
|
|
161
|
+
if (record(local.properties?.name)) {
|
|
162
|
+
const legacyId = structuredClone(local.properties.name);
|
|
163
|
+
for (const key of ['title', 'description', 'readOnly', 'x-aliasOf']) delete legacyId[key];
|
|
164
|
+
out.properties.id = merge(out.properties.id, legacyId);
|
|
165
|
+
}
|
|
166
|
+
delete out.properties.name;
|
|
167
|
+
out.required = [...new Set(out.required.map(key => key === 'name' ? 'id' : key))];
|
|
134
168
|
// Old custom forms may constrain/require issuer; carry those constraints to its canonical location.
|
|
135
169
|
const legacyDomain = local.properties?.issuer;
|
|
136
170
|
if (record(legacyDomain) || local.required?.includes('issuer')) {
|
|
@@ -220,10 +254,10 @@ export function normalizeTeam(input, { fallbackName, packageInfo } = {}) {
|
|
|
220
254
|
for (const key of ['id', 'name']) if (typeof team[key] === 'string' && team[key] !== team[key].trim()) {
|
|
221
255
|
team[key] = team[key].trim(); change(key, 'Trimmed identifier whitespace');
|
|
222
256
|
}
|
|
223
|
-
if (team.id === undefined && team.name === undefined && fallbackName) { team.
|
|
257
|
+
if (team.id === undefined && team.name === undefined && fallbackName) { team.id = fallbackName; change('id', 'Use template directory identifier'); }
|
|
224
258
|
if (team.id === undefined && team.name !== undefined) { team.id = team.name; change('id', 'Use compatible name identifier'); }
|
|
225
|
-
if (team.name === undefined && team.id !== undefined) { team.name = team.id; change('name', 'Preserve compatible name identifier'); }
|
|
226
259
|
if (team.id !== undefined && team.name !== undefined && team.id !== team.name) errors.push('team.id: conflicts with team.name');
|
|
260
|
+
if (own(team, 'name')) { delete team.name; change('name', 'Retired compatible identifier; use id'); }
|
|
227
261
|
if (legacy) {
|
|
228
262
|
const oldVersion = team.version;
|
|
229
263
|
if (oldVersion === undefined) team.version = '1.0.0';
|
|
@@ -277,6 +311,7 @@ export function normalizeTeam(input, { fallbackName, packageInfo } = {}) {
|
|
|
277
311
|
}
|
|
278
312
|
});
|
|
279
313
|
errors.push(...validateContractSchema(team, schema));
|
|
314
|
+
try { partitionTeamMembers(team); } catch (error) { errors.push(error.message); }
|
|
280
315
|
if (Array.isArray(team.agents)) {
|
|
281
316
|
const keys = new Set(); const names = new Set();
|
|
282
317
|
for (const [i, agent] of team.agents.entries()) {
|
|
@@ -313,7 +348,11 @@ export function validateTemplateRequest(request) {
|
|
|
313
348
|
if (!errors.length && request.action === 'preview') {
|
|
314
349
|
const keys = Object.keys(request.args.members);
|
|
315
350
|
if (request.args.installMode === 'overwrite' && (keys.length !== 1 || request.args.issuer !== undefined || request.args.members[keys[0]].target.aid === 'auto')) errors.push('overwrite requires one existing target and forbids issuer');
|
|
351
|
+
if (request.args.installMode === 'overwrite') for (const key of keys) {
|
|
352
|
+
if (request.args.members[key].target.project === undefined) errors.push(`args.members.${key}.target.project: required for overwrite`);
|
|
353
|
+
}
|
|
316
354
|
if (request.args.installMode === 'create' && keys.some(key => request.args.members[key].target.aid === 'auto') && !request.args.issuer) errors.push('issuer required for auto targets');
|
|
355
|
+
if (request.args.memberInstallId && (request.args.installMode !== 'create' || keys.length !== 1)) errors.push('memberInstallId requires a single new member');
|
|
317
356
|
}
|
|
318
357
|
return errors;
|
|
319
358
|
}
|
|
@@ -336,11 +375,12 @@ export function readTemplateCapabilities({ actions = TEMPLATE_ACTIONS, installMo
|
|
|
336
375
|
if (actions.some(action => !TEMPLATE_ACTIONS.includes(action))) throw contractError('INVALID_ARGUMENT', 'Unknown capability action');
|
|
337
376
|
return {
|
|
338
377
|
actions: [...actions], inputSchemas: Object.fromEntries(actions.map(action => [action, structuredClone(inputSchemas[action])])),
|
|
339
|
-
resultSchemas: Object.fromEntries(actions.map(action => [action,
|
|
378
|
+
resultSchemas: Object.fromEntries(actions.map(action => [action, ['capabilities', 'register-team', 'team-members', 'prepare-member-install', 'resume-member-join',
|
|
379
|
+
'update-status', 'bind-update-source', 'confirm-update-source', 'read-update-notice'].includes(action) ? { type: 'object' } : structuredClone(jobSchema)])),
|
|
340
380
|
packageSchema: structuredClone(packageSchema), installModes: [...installModes], platforms: [...platforms],
|
|
341
381
|
limits: { selectionTtlMs: SELECTION_TTL_MS, waitSeconds: { minimum: 0, maximum: 300 } },
|
|
342
382
|
jobPolicy: { packageRetentionMs: 604800000, previewTtlMs: 3600000, resultRetentionMs: 2592000000, event: 'template.job', unknownEffectsPinned: true },
|
|
343
|
-
features: structuredClone(features),
|
|
383
|
+
features: { singleAgentManualUpdate: true, automaticUpdateExecution: false, ...structuredClone(features) },
|
|
344
384
|
};
|
|
345
385
|
}
|
|
346
386
|
export function validateBuildSelection(inventory, args) {
|
|
@@ -6,14 +6,29 @@ import { gzipSync, gunzipSync } from 'node:zlib';
|
|
|
6
6
|
import { loadTemplate } from './template.mjs';
|
|
7
7
|
import { resolveTemplateAidDomain } from './template-contract.mjs';
|
|
8
8
|
import { AID_PATTERN, normalizeTeam, normalizeTeamSchema, validateContractSchema, readTeamSchema, packageSchema, contractDigest, canonicalJson, validateBuildSelection } from './template-contract.mjs';
|
|
9
|
-
import { BASEAGENTS, assertPublicTemplateConfig, resolveMemberParameters } from './template-runtime.mjs';
|
|
10
|
-
import { validatePackJson } from '../../../dist/event-center/validation.js';
|
|
11
|
-
import { PACK_RUNTIME_ENTRIES } from '../../../dist/core/pack-install.js';
|
|
12
|
-
import { assert, inside, readJson, regularPath, sha256, walkFiles } from './common.mjs';
|
|
9
|
+
import { BASEAGENTS, assertPublicTemplateConfig, resolveMemberParameters, partitionTeamMembers, validateAccessDeclaration } from './template-runtime.mjs';
|
|
13
10
|
|
|
14
11
|
export const PACKAGE_LIMITS = { file: 20 * 1024 * 1024, total: 200 * 1024 * 1024, entries: 20000 };
|
|
15
12
|
const record = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
16
13
|
const json = value => Buffer.from(JSON.stringify(value, null, 2) + '\n');
|
|
14
|
+
let eventPackRuntime;
|
|
15
|
+
const eventValidator = new URL('../../../dist/event-center/validation.js', import.meta.url);
|
|
16
|
+
const eventInstaller = new URL('../../../dist/core/pack-install.js', import.meta.url);
|
|
17
|
+
if (fs.existsSync(eventValidator) && fs.existsSync(eventInstaller)) {
|
|
18
|
+
const [validation, installation] = await Promise.all([import(eventValidator.href), import(eventInstaller.href)]);
|
|
19
|
+
configureTemplateEventPacks({ validatePackJson: validation.validatePackJson, runtimeEntries: installation.PACK_RUNTIME_ENTRIES });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Standalone consumers inject the real Core validator only when consuming event packs. */
|
|
23
|
+
export function configureTemplateEventPacks({ validatePackJson, runtimeEntries }) {
|
|
24
|
+
check(typeof validatePackJson === 'function' && (runtimeEntries instanceof Set || Array.isArray(runtimeEntries))
|
|
25
|
+
&& [...runtimeEntries].every(name => typeof name === 'string'), 'Real Core event-pack validation and runtime entries required');
|
|
26
|
+
eventPackRuntime = { validatePackJson, runtimeEntries: new Set(runtimeEntries) };
|
|
27
|
+
}
|
|
28
|
+
function requireEventPackRuntime() {
|
|
29
|
+
check(eventPackRuntime, 'Core event-pack validator unavailable; configureTemplateEventPacks with the installed Core runtime', 'EVENT_VALIDATOR_UNAVAILABLE');
|
|
30
|
+
return eventPackRuntime;
|
|
31
|
+
}
|
|
17
32
|
export const packageDigest = bytes => 'sha256:' + createHash('sha256').update(bytes).digest('hex');
|
|
18
33
|
function check(value, message, code = 'INVALID_ARGUMENT') {
|
|
19
34
|
if (!value) throw Object.assign(new Error(message), { code });
|
|
@@ -34,6 +49,7 @@ export function regularAncestors(file) {
|
|
|
34
49
|
}
|
|
35
50
|
}
|
|
36
51
|
export function excludedResource(name) {
|
|
52
|
+
if (name === 'prebuild-members.json') return true;
|
|
37
53
|
return name.split('/').some(part => ['.git', 'node_modules', '.claude'].includes(part)
|
|
38
54
|
|| /^\.env/.test(part) || /\.(?:pem|key|db(?:[-.].*)?)$/i.test(part));
|
|
39
55
|
}
|
|
@@ -202,7 +218,7 @@ export function inspectTemplatePackage(bytes, { digest } = {}) {
|
|
|
202
218
|
const team = normalized.team; const schema = normalizeTeamSchema(read('template/team.schema.json'));
|
|
203
219
|
const errors = validateContractSchema(team, schema);
|
|
204
220
|
check(!errors.length, errors.join('; '));
|
|
205
|
-
const keys = team.
|
|
221
|
+
const keys = partitionTeamMembers(team).inlineMembers.map(agent => agent.key);
|
|
206
222
|
for (const { path: name } of manifest) check(portableFile(name, keys), 'Unsupported portable resource: ' + name);
|
|
207
223
|
validateEventPackEntries(new Map([...entries].filter(([name]) => name.startsWith('template/'))
|
|
208
224
|
.map(([name, entry]) => [name.slice('template/'.length), entry])), keys);
|
|
@@ -211,11 +227,13 @@ export function inspectTemplatePackage(bytes, { digest } = {}) {
|
|
|
211
227
|
}
|
|
212
228
|
|
|
213
229
|
/** Directory adapter: reads exactly one keyed member and snapshots all source bytes/permissions. */
|
|
214
|
-
export function collectTemplateDirectory(templateDir, memberKey) {
|
|
230
|
+
export function collectTemplateDirectory(templateDir, memberKey, { includeWorkspace = true } = {}) {
|
|
215
231
|
regularAncestors(templateDir);
|
|
216
|
-
const { tpl, errors } = loadTemplate(templateDir);
|
|
232
|
+
const { tpl, errors } = loadTemplate(templateDir, { includeWorkspace });
|
|
217
233
|
check(!errors.length, errors.join('; '));
|
|
218
|
-
|
|
234
|
+
const declaredMember = tpl.team.agents.find(agent => agent.key === memberKey);
|
|
235
|
+
check(declaredMember?.optional !== true, 'Optional member is an ID reference, not a collectable Agent: ' + memberKey);
|
|
236
|
+
check(tpl.actualKeys.includes(memberKey), 'Unknown actual directory member: ' + memberKey);
|
|
219
237
|
const excluded = [];
|
|
220
238
|
const readOptional = relative => {
|
|
221
239
|
const file = path.join(tpl.root, ...relative.split('/'));
|
|
@@ -229,6 +247,7 @@ export function collectTemplateDirectory(templateDir, memberKey) {
|
|
|
229
247
|
baseagents: { ...defaults.baseagents, ...member.config?.baseagents } };
|
|
230
248
|
const config = {};
|
|
231
249
|
for (const name of ['chatmode', 'memory']) if (source[name] !== undefined) config[name] = source[name];
|
|
250
|
+
if (Object.hasOwn(member.config ?? {}, 'access')) config.access = validateAccessDeclaration(member.config.access);
|
|
232
251
|
config.active_baseagent = source.active_baseagent ?? 'claude'; config.baseagents = {};
|
|
233
252
|
for (const [name, sourceBlock] of Object.entries(source.baseagents)) {
|
|
234
253
|
const block = { ...defaults.baseagents?.[name], ...sourceBlock };
|
|
@@ -267,13 +286,19 @@ export function collectTemplateDirectory(templateDir, memberKey) {
|
|
|
267
286
|
}
|
|
268
287
|
|
|
269
288
|
/** One pure package planner for both runtime-agent and directory collection adapters. */
|
|
270
|
-
export function buildTemplatePackage({ metadata, members, externalAids = [], publisher, createdAt, evolcoreRange = '>=0.0.43-test.8'
|
|
271
|
-
|
|
289
|
+
export function buildTemplatePackage({ metadata, members, externalAids = [], publisher, createdAt, evolcoreRange = '>=0.0.43-test.8',
|
|
290
|
+
memberReferences: references = { optional: [], external: [] }, externalContacts, assistantKey }) {
|
|
291
|
+
const team = { $schema_version: 1, id: metadata.id, title: metadata.name, version: metadata.version,
|
|
272
292
|
...(metadata.description !== undefined ? { description: metadata.description } : {}), host: { platform: structuredClone(metadata.platforms) }, agents: [] };
|
|
273
293
|
const entries = new Map(); const excluded = []; const external = new Set(externalAids);
|
|
274
294
|
for (const [key, collected] of Object.entries(members)) {
|
|
275
295
|
const { member, include } = collected;
|
|
276
296
|
check(record(member) && record(include), 'Collected member and selection required');
|
|
297
|
+
if (member.optional === true) {
|
|
298
|
+
check(collected.entries instanceof Map && collected.entries.size === 0, 'Optional references cannot carry executable resources');
|
|
299
|
+
team.agents.push({ ...structuredClone(member), key });
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
277
302
|
check(include.baseagents.includes(member.config?.active_baseagent), 'Default baseagent is required: ' + key);
|
|
278
303
|
const chosen = structuredClone(member);
|
|
279
304
|
Object.assign(chosen, resolveMemberParameters(chosen));
|
|
@@ -296,6 +321,18 @@ export function buildTemplatePackage({ metadata, members, externalAids = [], pub
|
|
|
296
321
|
entries.set(target, { bytes: Buffer.from(entry.bytes), mode: entry.mode });
|
|
297
322
|
}
|
|
298
323
|
}
|
|
324
|
+
check(record(references) && Array.isArray(references.optional) && Array.isArray(references.external), 'Invalid member references');
|
|
325
|
+
team.agents.push(...structuredClone(references.optional));
|
|
326
|
+
if (references.external.length) team.external_contacts = structuredClone(references.external);
|
|
327
|
+
if (externalContacts !== undefined) {
|
|
328
|
+
check(Array.isArray(externalContacts), 'externalContacts must be an array');
|
|
329
|
+
check(!references.external.length || canonicalJson(references.external) === canonicalJson(externalContacts), 'Conflicting external contact declarations');
|
|
330
|
+
team.external_contacts = structuredClone(externalContacts);
|
|
331
|
+
}
|
|
332
|
+
if (assistantKey !== undefined) {
|
|
333
|
+
team.personal_assistant = team.agents.findIndex(member => member.key === assistantKey);
|
|
334
|
+
check(team.personal_assistant >= 0, 'Unknown personal assistant key');
|
|
335
|
+
}
|
|
299
336
|
const normalized = normalizeTeam(team);
|
|
300
337
|
check(!normalized.errors.length, normalized.errors.join('; '));
|
|
301
338
|
entries.set('template/team.json', { bytes: json(team), mode: 0o644 });
|
|
@@ -313,6 +350,7 @@ export function buildTemplatePackage({ metadata, members, externalAids = [], pub
|
|
|
313
350
|
if (memberReferences && evolcoreRange === '>=0.0.43-test.8') evolcoreRange = '>=0.0.43-test.8 <0.0.43 || >=0.0.44';
|
|
314
351
|
const templateFeatures = [
|
|
315
352
|
...(memberReferences ? ['member-references-v1'] : []),
|
|
353
|
+
...(team.agents.some(member => member.optional) || team.external_contacts?.length ? ['optional-members-v1'] : []),
|
|
316
354
|
...([...entries.keys()].some(name => /^template\/agents\/[^/]+\/events\//.test(name)) ? ['event-packs-v1'] : []),
|
|
317
355
|
];
|
|
318
356
|
const info = { $schema_version: 1, id: metadata.id, name: metadata.name, version: metadata.version,
|
|
@@ -320,7 +358,7 @@ export function buildTemplatePackage({ metadata, members, externalAids = [], pub
|
|
|
320
358
|
...(metadata.description !== undefined ? { description: metadata.description } : {}),
|
|
321
359
|
compat: { platforms: structuredClone(metadata.platforms), evolcore: evolcoreRange,
|
|
322
360
|
...(templateFeatures.length ? { templateFeatures } : {}),
|
|
323
|
-
baseagents: [...new Set(team.agents.flatMap(member => Object.keys(member.config
|
|
361
|
+
baseagents: [...new Set(team.agents.flatMap(member => Object.keys(member.config?.baseagents ?? {})))].sort() },
|
|
324
362
|
externalAids: [...external].sort() };
|
|
325
363
|
const manifest = [...entries].map(([name, entry]) => ({ path: name.slice('template/'.length), size: entry.bytes.length, sha256: packageDigest(entry.bytes).slice(7) }));
|
|
326
364
|
entries.set('PACKAGE.json', { bytes: json(info), mode: 0o644 });
|
|
@@ -344,12 +382,15 @@ export function exportTemplatePackage(templateDir, { publisher, createdAt = Date
|
|
|
344
382
|
const defaults = readOptional('.evolcore/agents/defaults.json');
|
|
345
383
|
const providers = readOptional('.evolcore/providers.json').providers ?? {};
|
|
346
384
|
if (team.host.config !== undefined) { delete team.host.config; excluded.push('host.config'); }
|
|
385
|
+
if (team.host.name !== undefined) { delete team.host.name; excluded.push('host.name'); }
|
|
347
386
|
for (const agent of team.agents) {
|
|
387
|
+
if (agent.optional === true) continue;
|
|
348
388
|
Object.assign(agent, resolveMemberParameters(agent));
|
|
349
389
|
const source = { ...structuredClone(defaults), ...agent.config,
|
|
350
390
|
baseagents: { ...defaults.baseagents, ...agent.config?.baseagents } };
|
|
351
391
|
const config = {};
|
|
352
392
|
for (const name of ['chatmode', 'memory']) if (source[name] !== undefined) config[name] = source[name];
|
|
393
|
+
if (Object.hasOwn(agent.config ?? {}, 'access')) config.access = validateAccessDeclaration(agent.config.access);
|
|
353
394
|
config.active_baseagent = source.active_baseagent ?? 'claude'; config.baseagents = {};
|
|
354
395
|
for (const [name, sourceBlock] of Object.entries(source.baseagents)) {
|
|
355
396
|
const block = { ...defaults.baseagents?.[name], ...sourceBlock };
|
|
@@ -372,7 +413,7 @@ export function exportTemplatePackage(templateDir, { publisher, createdAt = Date
|
|
|
372
413
|
for (const relative of tpl.files) {
|
|
373
414
|
const name = relative.split(path.sep).join('/');
|
|
374
415
|
if (['team.json', 'team.schema.json'].includes(name)) continue;
|
|
375
|
-
if (!portableFile(name, tpl.
|
|
416
|
+
if (!portableFile(name, tpl.actualKeys)) { excluded.push(name); continue; }
|
|
376
417
|
const file = path.join(tpl.root, relative);
|
|
377
418
|
entries.set('template/' + name, { bytes: fs.readFileSync(file), mode: fs.statSync(file).mode & 0o777 });
|
|
378
419
|
}
|
|
@@ -394,13 +435,14 @@ export function exportTemplatePackage(templateDir, { publisher, createdAt = Date
|
|
|
394
435
|
if (memberReferences && evolcoreRange === '>=0.0.43') evolcoreRange = '>=0.0.43-test.8 <0.0.43 || >=0.0.44';
|
|
395
436
|
const templateFeatures = [
|
|
396
437
|
...(memberReferences ? ['member-references-v1'] : []),
|
|
438
|
+
...(team.agents.some(member => member.optional) || team.external_contacts?.length ? ['optional-members-v1'] : []),
|
|
397
439
|
...([...entries.keys()].some(name => /^template\/agents\/[^/]+\/events\//.test(name)) ? ['event-packs-v1'] : []),
|
|
398
440
|
];
|
|
399
441
|
const metadata = { $schema_version: 1, id: team.id, name: team.title ?? team.id, version: team.version,
|
|
400
442
|
...(team.description !== undefined ? { description: team.description } : {}), ...(publisher ? { publisher } : {}), createdAt,
|
|
401
443
|
compat: { platforms: team.host.platform, evolcore: evolcoreRange,
|
|
402
444
|
...(templateFeatures.length ? { templateFeatures } : {}),
|
|
403
|
-
baseagents: [...new Set(team.agents.flatMap(agent => Object.keys(agent.config
|
|
445
|
+
baseagents: [...new Set(team.agents.flatMap(agent => Object.keys(agent.config?.baseagents ?? {})))] }, externalAids: [...external].sort() };
|
|
404
446
|
const manifest = [...entries].map(([name, entry]) => ({ path: name.slice('template/'.length), size: entry.bytes.length, sha256: packageDigest(entry.bytes).slice(7) }));
|
|
405
447
|
entries.set('PACKAGE.json', { bytes: json(metadata), mode: 0o644 });
|
|
406
448
|
entries.set('MANIFEST.json', { bytes: json(manifest), mode: 0o644 });
|
|
@@ -454,6 +496,8 @@ export function attachBuildEnvironment(templateDir, sourceDir) {
|
|
|
454
496
|
check(!base.errors.length, 'Invalid build environment: ' + base.errors.join('; '));
|
|
455
497
|
const teamFile = path.join(templateDir, 'team.json');
|
|
456
498
|
const team = JSON.parse(fs.readFileSync(teamFile, 'utf8'));
|
|
499
|
+
delete team.host.name;
|
|
500
|
+
if (base.tpl.team.host.name !== undefined) team.host.name = base.tpl.team.host.name;
|
|
457
501
|
team.host.config = structuredClone(base.tpl.team.host.config ?? {});
|
|
458
502
|
team.host.config.aun = { ...team.host.config.aun, defaultAidDomain: resolveTemplateAidDomain(base.tpl.team) };
|
|
459
503
|
delete team.issuer;
|
|
@@ -480,8 +524,9 @@ const TEMPLATE_EVENT_BUS_PATTERN = /^\{\{\s*(?:members\.[a-z0-9][a-z0-9_-]{0,31}
|
|
|
480
524
|
|
|
481
525
|
/** Share package definitions/assets, never runtime state, logs, backups or caches. */
|
|
482
526
|
export function isPortableEventPackResource(relative) {
|
|
527
|
+
const { runtimeEntries } = requireEventPackRuntime();
|
|
483
528
|
return relative.split('/').every(part => part && part !== '..' && !part.startsWith('.')
|
|
484
|
-
&& !
|
|
529
|
+
&& !runtimeEntries.has(part) && !['node_modules', '__pycache__'].includes(part)
|
|
485
530
|
&& !part.endsWith('_') && !part.endsWith('~') && !/\.(?:bak|pyc)$/i.test(part));
|
|
486
531
|
}
|
|
487
532
|
|
|
@@ -496,32 +541,51 @@ export function validateEventPack(raw, files, { template = false, location = 'ev
|
|
|
496
541
|
const checked = structuredClone(raw);
|
|
497
542
|
if (template && checked && typeof checked === 'object') {
|
|
498
543
|
for (const kind of ['publish', 'subscribe']) if (Array.isArray(checked[kind])) {
|
|
499
|
-
for (const entry of checked[kind]) if (entry && TEMPLATE_EVENT_BUS_PATTERN.test(entry.bus)) entry.bus =
|
|
544
|
+
for (const entry of checked[kind]) if (entry && TEMPLATE_EVENT_BUS_PATTERN.test(entry.bus)) entry.bus = packageDigest(entry.bus).slice(7, 23) + '.agentid.cn';
|
|
500
545
|
}
|
|
501
546
|
}
|
|
502
|
-
const result = validatePackJson(checked);
|
|
503
|
-
|
|
547
|
+
const result = requireEventPackRuntime().validatePackJson(checked);
|
|
548
|
+
check(result.ok, location + '/pack.json: ' + result.errors.join('; '));
|
|
504
549
|
for (const entry of result.value.subscribe) {
|
|
505
|
-
|
|
550
|
+
check(files.includes(entry.handler.script), location + ': missing handler ' + entry.handler.script);
|
|
506
551
|
}
|
|
507
552
|
return raw;
|
|
508
553
|
}
|
|
509
554
|
|
|
555
|
+
function eventPackFiles(root) {
|
|
556
|
+
const files = []; let total = 0;
|
|
557
|
+
const visit = (directory, prefix = '') => {
|
|
558
|
+
for (const entry of fs.readdirSync(directory, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
559
|
+
const relative = prefix + entry.name;
|
|
560
|
+
if (!isPortableEventPackResource(relative)) continue;
|
|
561
|
+
check(!entry.isSymbolicLink() && (entry.isFile() || entry.isDirectory()), 'Only regular event-pack files/directories: ' + relative);
|
|
562
|
+
const file = path.join(directory, entry.name);
|
|
563
|
+
if (entry.isDirectory()) visit(file, relative + '/');
|
|
564
|
+
else {
|
|
565
|
+
const size = fs.statSync(file).size; total += size;
|
|
566
|
+
check(files.length < PACKAGE_LIMITS.entries && size <= PACKAGE_LIMITS.file && total <= PACKAGE_LIMITS.total, 'Event-pack size limit exceeded', 'PACKAGE_TOO_LARGE');
|
|
567
|
+
files.push(relative);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
visit(root); return files.sort();
|
|
572
|
+
}
|
|
573
|
+
|
|
510
574
|
/** Read-only inventory: loading must not create logs or migrate source files. */
|
|
511
575
|
export function readEventPacks(eventsDir, { template = false } = {}) {
|
|
512
576
|
if (!fs.existsSync(eventsDir)) return [];
|
|
513
|
-
|
|
577
|
+
regularAncestors(eventsDir);
|
|
514
578
|
return fs.readdirSync(eventsDir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))
|
|
515
579
|
.filter(entry => !entry.name.startsWith('.') && !entry.name.startsWith('_'))
|
|
516
580
|
.flatMap(entry => {
|
|
517
|
-
|
|
581
|
+
check(!entry.isSymbolicLink(), 'Symbolic event pack: ' + entry.name);
|
|
518
582
|
if (!entry.isDirectory()) return [];
|
|
519
|
-
const dir =
|
|
583
|
+
const dir = path.join(eventsDir, entry.name);
|
|
520
584
|
if (fs.existsSync(path.join(dir, '.archived'))) return [];
|
|
521
|
-
|
|
522
|
-
const files =
|
|
523
|
-
|
|
524
|
-
const definition = validateEventPack(
|
|
585
|
+
check(EVENT_PACK_NAME_PATTERN.test(entry.name), 'Invalid event pack name: ' + entry.name);
|
|
586
|
+
const files = eventPackFiles(dir);
|
|
587
|
+
check(files.includes('pack.json'), 'Event pack missing pack.json: ' + entry.name);
|
|
588
|
+
const definition = validateEventPack(JSON.parse(fs.readFileSync(path.join(dir, 'pack.json'), 'utf8')), files, { template, location: 'events/' + entry.name });
|
|
525
589
|
return [{ id: entry.name, dir, files, definition }];
|
|
526
590
|
});
|
|
527
591
|
}
|
|
@@ -534,7 +598,7 @@ export function validateEventPackEntries(entries, keys) {
|
|
|
534
598
|
for (const id of ids) {
|
|
535
599
|
const packPrefix = prefix + id + '/';
|
|
536
600
|
const entry = entries.get(packPrefix + 'pack.json');
|
|
537
|
-
|
|
601
|
+
check(entry, 'Event pack missing pack.json: ' + prefix + id);
|
|
538
602
|
const files = [...entries.keys()].filter(name => name.startsWith(packPrefix)).map(name => name.slice(packPrefix.length));
|
|
539
603
|
validateEventPack(JSON.parse(entry.bytes.toString('utf8')), files, { template: true, location: prefix + id });
|
|
540
604
|
}
|
|
@@ -3,6 +3,115 @@ export const BASEAGENTS = ['claude', 'codex', 'gemini', 'ecagent'];
|
|
|
3
3
|
export const MEMBER_PARAMETER_FIELDS = ['version', 'update'];
|
|
4
4
|
const record = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
5
5
|
const fail = message => { throw Object.assign(new Error(message), { code: 'INVALID_ARGUMENT' }); };
|
|
6
|
+
const AID = /^[a-z0-9][a-z0-9_-]*\.(?:[a-z0-9-]+\.)*[a-z0-9-]+$/;
|
|
7
|
+
// Agent access lists follow the runtime schema; contact references retain their own contract.
|
|
8
|
+
const ACCESS_AID = /^[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?){2,}$/;
|
|
9
|
+
const TEMPLATE_ID = /^agent_[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
|
|
10
|
+
|
|
11
|
+
/** Validate author declarations without inserting runtime defaults. */
|
|
12
|
+
export function validateAccessDeclaration(access) {
|
|
13
|
+
if (!record(access)) fail('access must be an object');
|
|
14
|
+
for (const [key, value] of Object.entries(access)) {
|
|
15
|
+
if (['allowInternalContacts', 'allowExternalContacts', 'allowAllContacts'].includes(key)) {
|
|
16
|
+
if (typeof value !== 'boolean') fail('access.' + key + ' must be boolean');
|
|
17
|
+
} else if (['allowedAids', 'deniedAids'].includes(key)) {
|
|
18
|
+
if (!Array.isArray(value) || value.some(aid => typeof aid !== 'string' || !ACCESS_AID.test(aid))
|
|
19
|
+
|| new Set(value).size !== value.length) fail('access.' + key + ' must contain unique AIDs');
|
|
20
|
+
} else if (key === 'requestLimit') {
|
|
21
|
+
if (!record(value) || Object.keys(value).some(field => !['maxTimes', 'coolDown'].includes(field))) fail('access.requestLimit is invalid');
|
|
22
|
+
for (const [field, number] of Object.entries(value)) {
|
|
23
|
+
const maximum = field === 'maxTimes' ? 100000 : 86400;
|
|
24
|
+
if (!Number.isSafeInteger(number) || number < 1 || number > maximum) fail('access.requestLimit.' + field + ' is invalid');
|
|
25
|
+
}
|
|
26
|
+
} else if (key === 'contactAdmission') {
|
|
27
|
+
if (!['legacy', 'app-v1'].includes(value)) fail('access.contactAdmission is invalid');
|
|
28
|
+
} else fail('Unknown access field: ' + key);
|
|
29
|
+
}
|
|
30
|
+
return structuredClone(access);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Missing values inherit; explicit false, empty arrays and nested declarations override. */
|
|
34
|
+
export function mergeMemberDefaults(defaults, member) {
|
|
35
|
+
if (!record(defaults) || !record(member)) fail('Member defaults and template required');
|
|
36
|
+
const merge = (low, high) => {
|
|
37
|
+
if (!record(low) || !record(high)) return structuredClone(high);
|
|
38
|
+
const result = structuredClone(low);
|
|
39
|
+
for (const [key, value] of Object.entries(high)) {
|
|
40
|
+
if (['__proto__', 'prototype', 'constructor'].includes(key)) fail('Invalid configuration key');
|
|
41
|
+
result[key] = record(value) && record(result[key]) ? merge(result[key], value) : structuredClone(value);
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
for (const source of [defaults, member]) {
|
|
46
|
+
if (source.config?.access !== undefined) validateAccessDeclaration(source.config.access);
|
|
47
|
+
}
|
|
48
|
+
const result = structuredClone(member);
|
|
49
|
+
if (defaults.profile || member.profile) result.profile = merge(defaults.profile ?? {}, member.profile ?? {});
|
|
50
|
+
const low = defaults.config?.access, high = member.config?.access;
|
|
51
|
+
if (low !== undefined || high !== undefined) {
|
|
52
|
+
result.config ??= {};
|
|
53
|
+
result.config.access = high === undefined ? structuredClone(low) : merge(low ?? {}, high);
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** One partition used by authors, identity generation and delivery consumers. Never mutates input. */
|
|
59
|
+
export function partitionTeamMembers(team) {
|
|
60
|
+
if (!record(team) || !Array.isArray(team.agents) || !team.agents.length) fail('Team agents required');
|
|
61
|
+
const inlineMembers = [], optionalReferences = [], keys = new Set();
|
|
62
|
+
for (const member of team.agents) {
|
|
63
|
+
if (!record(member) || !/^[a-z0-9][a-z0-9_-]{0,31}$/.test(member.key ?? '') || keys.has(member.key)) fail('Invalid or duplicate member key');
|
|
64
|
+
keys.add(member.key);
|
|
65
|
+
if (member.optional !== undefined && typeof member.optional !== 'boolean') fail('Member optional must be boolean');
|
|
66
|
+
if (member.config?.access !== undefined) validateAccessDeclaration(member.config.access);
|
|
67
|
+
if (member.optional === true) {
|
|
68
|
+
if (Object.keys(member).some(key => !['key', 'optional', 'agentTemplateId', 'profile', 'config'].includes(key))) fail('Optional member contains executable configuration: ' + member.key);
|
|
69
|
+
if (!TEMPLATE_ID.test(member.agentTemplateId ?? '')) fail('Invalid agentTemplateId for ' + member.key);
|
|
70
|
+
if (!record(member.profile) || typeof member.profile.name !== 'string' || !member.profile.name.trim()
|
|
71
|
+
|| typeof member.profile.description !== 'string') fail('Optional member profile.name and profile.description required: ' + member.key);
|
|
72
|
+
if (member.config !== undefined && (!record(member.config) || Object.keys(member.config).some(key => key !== 'access'))) fail('Optional member config only accepts access: ' + member.key);
|
|
73
|
+
optionalReferences.push(structuredClone(member));
|
|
74
|
+
} else {
|
|
75
|
+
if (member.agentTemplateId !== undefined) fail('agentTemplateId requires optional=true: ' + member.key);
|
|
76
|
+
inlineMembers.push(structuredClone(member));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const index = team.personal_assistant ?? 0;
|
|
80
|
+
if (!Number.isInteger(index) || index < 0 || index >= team.agents.length) fail('personal_assistant: index outside agents');
|
|
81
|
+
const assistantKey = team.agents[index].key;
|
|
82
|
+
if (!inlineMembers.some(member => member.key === assistantKey)) fail('Personal assistant must be a required member');
|
|
83
|
+
if (!inlineMembers.length) fail('At least one required member is needed');
|
|
84
|
+
if (team.external_contacts !== undefined && !Array.isArray(team.external_contacts)) fail('external_contacts must be an array');
|
|
85
|
+
const externalAids = new Set();
|
|
86
|
+
const externalContacts = (team.external_contacts ?? []).map(contact => {
|
|
87
|
+
if (!record(contact) || Object.keys(contact).some(key => !['aid', 'name'].includes(key))
|
|
88
|
+
|| typeof contact.aid !== 'string' || !AID.test(contact.aid) || externalAids.has(contact.aid)
|
|
89
|
+
|| contact.name !== undefined && (typeof contact.name !== 'string' || !contact.name.trim())) fail('Invalid or duplicate external contact');
|
|
90
|
+
externalAids.add(contact.aid);
|
|
91
|
+
return { aid: contact.aid, name: contact.name ?? contact.aid };
|
|
92
|
+
});
|
|
93
|
+
return { inlineMembers, optionalReferences, externalContacts, assistantKey };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function teamMemberReferences(team) {
|
|
97
|
+
const { optionalReferences, externalContacts } = partitionTeamMembers(team);
|
|
98
|
+
return optionalReferences.length || externalContacts.length
|
|
99
|
+
? { optional: optionalReferences, external: externalContacts } : undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Keep external identity/ownership unknown until independently verified. */
|
|
103
|
+
export function createTeamContactEntries({ members, ownerAid, hostAid, externalContacts = [], selfAid, remote = false }) {
|
|
104
|
+
const owned = new Set([ownerAid, hostAid, ...members.map(member => member.aid)]);
|
|
105
|
+
if (externalContacts.some(contact => owned.has(contact.aid))) fail('External contact conflicts with a team identity');
|
|
106
|
+
const entries = members.filter(member => member.aid !== selfAid).map(member => ({
|
|
107
|
+
aid: member.aid, name: member.name, [remote ? 'owner_aid' : 'ownerAid']: ownerAid,
|
|
108
|
+
remark: '', type: 'agent', description: member.description ?? '', ownership_status: 'owned',
|
|
109
|
+
agent_md_signed_at: remote ? null : 0,
|
|
110
|
+
...(remote ? {} : { exttype: '', baseagent: '' }),
|
|
111
|
+
}));
|
|
112
|
+
return entries.concat(externalContacts.map(contact => ({ aid: contact.aid, name: contact.name ?? contact.aid,
|
|
113
|
+
ownership_status: 'unknown', agent_md_signed_at: remote ? null : 0 })));
|
|
114
|
+
}
|
|
6
115
|
|
|
7
116
|
/** Author declarations only; never generates versions or grants update authority. */
|
|
8
117
|
export function resolveMemberParameters(member) {
|
|
@@ -161,7 +270,8 @@ export function planMemberConfig({ member, vars, providers, defaults = {}, fallb
|
|
|
161
270
|
const parameters = resolveMemberParameters(member);
|
|
162
271
|
const rendered = renderValue(member, vars);
|
|
163
272
|
if (mode !== 'create_prebuilt' && (!record(rendered.config) || Object.keys(rendered.config)
|
|
164
|
-
.some(key => !['chatmode', 'memory', 'active_baseagent', 'baseagents', 'version', 'update'].includes(key)))) fail('Unsupported live-host member configuration');
|
|
273
|
+
.some(key => !['chatmode', 'memory', 'access', 'active_baseagent', 'baseagents', 'version', 'update'].includes(key)))) fail('Unsupported live-host member configuration');
|
|
274
|
+
if (rendered.config?.access !== undefined) validateAccessDeclaration(rendered.config.access);
|
|
165
275
|
const binding = bindTemplateProviders({ ...rendered.config, ...parameters }, { providers, defaults, fallbackProviders, selections, allowMissing, modelCatalog });
|
|
166
276
|
return { key: member.key, profile: rendered.profile, skills: rendered.skills ?? {}, config: binding.config, providers: binding.refs };
|
|
167
277
|
}
|