evolcore 0.0.43-test.6 → 0.0.43-test.8
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 +95 -0
- package/bin/ecmsg.js +188 -58
- package/dist/agent-template/jobs.js +62 -0
- package/dist/agent-template/runtime.js +214 -0
- package/dist/agent-template/service.js +465 -0
- package/dist/agent-template/tool-runner.js +45 -0
- package/dist/agent-template/types.js +5 -0
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/claude-runner.js +1 -1
- package/dist/agents/codex/app-server-client.js +22 -0
- package/dist/agents/codex-runner.js +69 -2
- package/dist/aun/aid/agentmd.js +56 -1
- package/dist/aun/aid/client.js +3 -1
- package/dist/aun/menu/client.js +3 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/channels/aun.js +277 -49
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +7 -3
- package/dist/cli/agent-template.js +124 -0
- package/dist/cli/aun-commands.js +2 -2
- package/dist/cli/ctl-command.js +2 -1
- package/dist/cli/daemon-commands.js +11 -66
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +35 -2
- package/dist/cli/events-command.js +109 -0
- package/dist/cli/index.js +60 -14
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/net-check.js +1 -1
- package/dist/cli/restart-monitor.js +160 -83
- package/dist/cli/services-command.js +137 -0
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +103 -13
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/boot-log.js +8 -8
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +0 -7
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/schema-migration.js +45 -15
- package/dist/config-store.js +2 -1
- package/dist/core/agent-ipc-registration.js +25 -4
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +106 -10
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-authorizer.js +2 -0
- package/dist/core/auth/operation-catalog.js +29 -0
- package/dist/core/baseagent-loader.js +60 -130
- package/dist/core/channel-loader.js +10 -1
- package/dist/core/channel-runtime.js +20 -12
- package/dist/core/command/agent-control.js +12 -2
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/agent-template-menu.js +147 -0
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +80 -17
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +468 -0
- package/dist/core/command/menu-catalog.js +15 -0
- package/dist/core/command/menu-handler.js +216 -90
- package/dist/core/command/menu-protocol.js +71 -13
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +34 -42
- package/dist/core/command/team-workspace-bootstrap.js +350 -0
- package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
- package/dist/core/command/team-workspace-initializer.js +2 -0
- package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
- package/dist/core/command/team-workspace-job-store.js +88 -0
- package/dist/core/command/team-workspace-management-service.js +2 -0
- package/dist/core/command/team-workspace-management-store.js +96 -0
- package/dist/core/command/team-workspace-management.js +265 -0
- package/dist/core/command/team-workspace-members-menu.js +88 -0
- package/dist/core/command/team-workspace-store.js +612 -0
- package/dist/core/command/team-workspace-team.js +193 -0
- package/dist/core/daemon-control.js +22 -5
- package/dist/core/daemon-lifecycle.js +323 -191
- package/dist/core/handoff/runtime.js +45 -13
- package/dist/core/invoke/executors/index.js +13 -0
- package/dist/core/invoke/executors/media.js +283 -0
- package/dist/core/invoke/executors/text.js +198 -0
- package/dist/core/invoke/invoke-service.js +157 -0
- package/dist/core/invoke/style-router.js +48 -0
- package/dist/core/invoke/types.js +19 -0
- package/dist/core/ipc-registration.js +50 -7
- package/dist/core/legacy-rename.js +41 -0
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +252 -17
- package/dist/core/message/im-renderer.js +116 -85
- package/dist/core/message/message-bridge.js +4 -0
- package/dist/core/message/message-queue.js +66 -15
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/pending-hints.js +29 -5
- package/dist/core/message/response-engine.js +194 -61
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +50 -5
- package/dist/core/ownership/owner-resolver.js +7 -0
- package/dist/core/pack-auth.js +94 -0
- package/dist/core/pack-install.js +194 -0
- package/dist/core/permission/ec-command-parser.js +51 -17
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/rate-window.js +48 -0
- package/dist/core/relation/peer-identity.js +28 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +67 -28
- package/dist/core/session/session-idle-monitor.js +59 -19
- package/dist/core/session/session-manager.js +13 -4
- package/dist/core/task/task-recovery-service.js +13 -2
- package/dist/core/thread/command-parser.js +9 -2
- package/dist/core/thread/thread-operation.js +21 -2
- package/dist/core/thread/thread-route.js +13 -2
- package/dist/core/thread/thread-service.js +52 -3
- package/dist/directory/owner-directory-admission.js +40 -53
- package/dist/directory/owner-directory-cache.js +89 -113
- package/dist/directory/owner-directory-query-operation.js +8 -10
- package/dist/eck/kit-renderer.js +7 -5
- package/dist/eck/message-renderer.js +2 -0
- package/dist/ecweb/basic-settings-service.js +1 -1
- package/dist/ecweb/message-context-service.js +0 -4
- package/dist/ecweb/runtime/lifecycle.js +6 -2
- package/dist/ecweb/runtime/supervisor.js +19 -4
- package/dist/event-center/admission-materializer.js +124 -0
- package/dist/event-center/bus-gate.js +154 -0
- package/dist/event-center/bus-host.js +307 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +127 -0
- package/dist/event-center/daemon.js +44 -0
- package/dist/event-center/directory-source.js +55 -0
- package/dist/event-center/dispatcher.js +157 -0
- package/dist/event-center/event-log.js +110 -0
- package/dist/event-center/index-generator.js +73 -0
- package/dist/event-center/ipc-operation.js +423 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +207 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +463 -0
- package/dist/event-center/runtime.js +837 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +51 -0
- package/dist/event-center/validation.js +435 -0
- package/dist/index.js +424 -135
- package/dist/ipc.js +106 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +5 -1
- package/dist/proxy/service-supervisor.js +13 -4
- package/dist/response-system/engines/v1/index.js +0 -1
- package/dist/response-system/engines/v1/proactive-flow.js +4 -2
- package/dist/response-system/modes/single-session/index.js +1 -1
- package/dist/services/dispatcher.js +100 -0
- package/dist/services/idempotency.js +90 -0
- package/dist/services/identity.js +52 -0
- package/dist/services/index-generator.js +70 -0
- package/dist/services/index.js +449 -0
- package/dist/services/ipc-operation.js +550 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +215 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +98 -0
- package/dist/services/script-runner.js +422 -0
- package/dist/services/service-payload.js +70 -0
- package/dist/services/types.js +18 -0
- package/dist/services/validation.js +297 -0
- package/dist/trigger/application-service.js +18 -0
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/scheduler.js +38 -0
- package/dist/trigger/script-sandbox.js +170 -24
- package/dist/utils/cross-platform.js +24 -10
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +6 -3
- package/dist/utils/process-introspect.js +45 -9
- package/dist/utils/startup-trace.js +74 -37
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +9 -15
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +3 -1
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/agent.md +22 -1
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/event-center.md +227 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +5 -3
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-protocol.md +28 -1
- package/kits/docs/evolcore/msg.md +21 -9
- package/kits/docs/evolcore/provider.md +3 -1
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +294 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/docs/evolcore/thread-chain.md +15 -3
- package/kits/eck_manifest.json +26 -0
- package/kits/rules/02-navigation.md +10 -1
- package/kits/rules/06-channel.md +1 -0
- package/kits/schemas/_meta.json +17 -6
- package/kits/schemas/agent-config.schema.19.json +5 -7
- package/kits/schemas/agent-config.schema.20.json +936 -0
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/skills/.switches.json +1 -5
- package/kits/skills/ability/SKILL.md +56 -0
- package/kits/skills/ability/references/calling.md +56 -0
- package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
- package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
- package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
- package/kits/skills/ec-agent-create/SKILL.md +0 -1
- package/kits/skills/ec-group/SKILL.md +5 -8
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/personal-assistant/SKILL.md +6 -6
- package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
- package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
- package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
- package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/message-fragments/item.md +1 -1
- package/kits/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/reply.md +1 -5
- package/kits/templates/system-fragments/thread.md +13 -10
- package/package.json +5 -6
- package/scripts/agent-template/index.mjs +40 -0
- package/scripts/agent-template/inspect.mjs +240 -0
- package/scripts/agent-template/overlay.mjs +71 -0
- package/scripts/agent-template/pack.mjs +169 -0
- package/scripts/agent-template/shared/common.mjs +235 -0
- package/scripts/agent-template/shared/evolcore.mjs +75 -0
- package/scripts/agent-template/shared/plan.mjs +129 -0
- package/scripts/agent-template/shared/team-schema.json +70 -0
- package/scripts/agent-template/shared/template-contract.mjs +154 -0
- package/scripts/agent-template/shared/template-package.mjs +265 -0
- package/scripts/agent-template/shared/template-runtime.mjs +80 -0
- package/scripts/agent-template/shared/template.mjs +142 -0
- package/dist/cli/pa-workspace-command.js +0 -225
- package/dist/core/command/pa-workspace-store.js +0 -468
- package/dist/core/relation/pa-team.js +0 -132
- package/kits/docs/evolcore/pa-workspace.md +0 -51
- package/kits/skills/aid-ability/SKILL.md +0 -244
- package/kits/skills/ec-ability/SKILL.md +0 -67
- package/kits/skills/ec-ability/references/workflows.md +0 -15
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 事件包 / 服务包运维命令的授权判定。
|
|
3
|
+
*
|
|
4
|
+
* 权限模型(主机终端 > 同 AID > 跨 AID 逐级收紧):
|
|
5
|
+
*
|
|
6
|
+
* | 调用方 | 只读命令 | 需管理的命令 |
|
|
7
|
+
* | --- | --- | --- |
|
|
8
|
+
* | 主机终端(control token) | ✅ | ✅ |
|
|
9
|
+
* | 托管会话,目标 = 自己 AID | ✅ | owner / admin |
|
|
10
|
+
* | 托管会话,目标 ≠ 自己 AID | ✅ | 三重 owner |
|
|
11
|
+
*
|
|
12
|
+
* 「三重 owner」= ① 执行方 agent 的角色是 owner(admin 不够)② 执行方与目标
|
|
13
|
+
* AID 的协议 owner 是同一个 ③ 不是 daemon 控制面上的直接调用(那种走主机终端分支)。
|
|
14
|
+
*
|
|
15
|
+
* 为什么跨 AID 要额外一层:`pack add` 等于给目标 agent 安装一段以后会以它的身份
|
|
16
|
+
* 执行的代码。同 AID 是"自己装给自己的",跨 AID 则是"用别人的身份执行",
|
|
17
|
+
* 只有同一个 Owner 名下的两个 agent 之间才存在这种正当性。
|
|
18
|
+
*
|
|
19
|
+
* 为什么不读 `/public` 或名录里的转发关系:那些都是会被拷贝、会变的展示信息;
|
|
20
|
+
* 协议 owner 归属(`ownerResolver`)才是唯一可信判据。
|
|
21
|
+
*/
|
|
22
|
+
import { getProtocolOwner } from './ownership/owner-resolver.js';
|
|
23
|
+
const MANAGING_ROLES = new Set(['owner', 'admin']);
|
|
24
|
+
export function authorizePackTarget(input) {
|
|
25
|
+
// 主机终端:人自己在操作,OS 账户可读 control.token 就是信任边界。
|
|
26
|
+
if (input.caller.kind === 'local-control')
|
|
27
|
+
return { allowed: true };
|
|
28
|
+
const selfAid = input.caller.selfAid;
|
|
29
|
+
if (!selfAid) {
|
|
30
|
+
return { allowed: false, code: 'NOT_ALLOWED', error: '当前任务身份不可用;托管会话需要 sessionId 与 delegationToken' };
|
|
31
|
+
}
|
|
32
|
+
if (!input.requiresManagement)
|
|
33
|
+
return { allowed: true };
|
|
34
|
+
const role = input.caller.peerRole;
|
|
35
|
+
if (input.targetAid === selfAid) {
|
|
36
|
+
return role && MANAGING_ROLES.has(role)
|
|
37
|
+
? { allowed: true }
|
|
38
|
+
: {
|
|
39
|
+
allowed: false,
|
|
40
|
+
code: 'ROLE_ACCESS_DENIED',
|
|
41
|
+
error: `管理本机事件/服务包需要 owner 或 admin 身份(当前 ${role ?? 'none'})`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// 跨 AID:三重 owner —— 执行方本人、目标 AID、本机 daemon 都必须归属同一个 Owner。
|
|
45
|
+
if (role !== 'owner') {
|
|
46
|
+
return {
|
|
47
|
+
allowed: false,
|
|
48
|
+
code: 'ROLE_ACCESS_DENIED',
|
|
49
|
+
error: `跨 AID 管理需要 owner 身份(当前 ${role ?? 'none'};admin 不足以操作其它 agent)`,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const selfOwner = getProtocolOwner(selfAid);
|
|
53
|
+
const targetOwner = getProtocolOwner(input.targetAid);
|
|
54
|
+
if (!selfOwner || !targetOwner) {
|
|
55
|
+
return {
|
|
56
|
+
allowed: false,
|
|
57
|
+
code: 'OWNERSHIP_UNAVAILABLE',
|
|
58
|
+
error: `跨 AID 管理需要双方都有协议 owner 归属(self=${selfOwner ?? 'none'}, target=${targetOwner ?? 'none'})`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (selfOwner !== targetOwner) {
|
|
62
|
+
return {
|
|
63
|
+
allowed: false,
|
|
64
|
+
code: 'CROSS_AGENT_DENIED',
|
|
65
|
+
error: `跨 AID 管理要求两个 agent 属于同一个 Owner(self owner=${selfOwner}, target owner=${targetOwner})`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
// 第三重:本机 daemon 也必须归属同一个 Owner——否则是"别人的机器替别人装包"。
|
|
69
|
+
if (input.daemonAid && input.daemonAid !== selfAid) {
|
|
70
|
+
const daemonOwner = getProtocolOwner(input.daemonAid);
|
|
71
|
+
if (!daemonOwner) {
|
|
72
|
+
return {
|
|
73
|
+
allowed: false,
|
|
74
|
+
code: 'OWNERSHIP_UNAVAILABLE',
|
|
75
|
+
error: `跨 AID 管理需要本机 daemon(${input.daemonAid})的协议 owner 归属`,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (daemonOwner !== selfOwner) {
|
|
79
|
+
return {
|
|
80
|
+
allowed: false,
|
|
81
|
+
code: 'CROSS_AGENT_DENIED',
|
|
82
|
+
error: `跨 AID 管理要求本机 daemon 也属于同一 Owner(daemon owner=${daemonOwner}, self owner=${selfOwner})`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return { allowed: true };
|
|
87
|
+
}
|
|
88
|
+
/** 命令 → 是否需要管理权限。未列出的命令按"只读"处理。 */
|
|
89
|
+
export function isManagingEventsCommand(command) {
|
|
90
|
+
return command === 'pack' || command === 'rules';
|
|
91
|
+
}
|
|
92
|
+
export function isManagingServicesCommand(command) {
|
|
93
|
+
return command === 'pack' || command === 'enable' || command === 'disable';
|
|
94
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 事件包 / 服务包的受控安装与卸载。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要这一层:`agents/<aid>/events` 与 `agents/<aid>/services` 是 L 类受保护路径,
|
|
5
|
+
* agent 自己的 Write / Bash 一律被 `checkLClassWrite` 拒(提示语就写着"请使用对应的
|
|
6
|
+
* EvolCore 受控命令")。所以安装包必须由 daemon 代写——agent 只负责把包目录放在
|
|
7
|
+
* 普通工作区里,然后调 `ec events pack add` / `ec services pack add`。
|
|
8
|
+
*
|
|
9
|
+
* 这一层只做文件系统搬运:校验仍由各模块的加载器(pack-loader / pack-manager)在
|
|
10
|
+
* reload 时完成,安装时不重复实现一套语义,避免两套规则漂移。
|
|
11
|
+
*/
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
/** 包安装期间的运行时产物:不该被拷进新包,也不该被 `pack add` 覆盖。 */
|
|
15
|
+
const PACK_RUNTIME_ENTRIES = new Set(['ledger.jsonl', '.idempotency.jsonl', 'logs', '.state.json', '.index.md']);
|
|
16
|
+
/** 包名:英文短横线/下划线,防止 `..` 或路径分隔符把写入引出目标根。 */
|
|
17
|
+
const PACK_NAME = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
18
|
+
function assertPackName(name) {
|
|
19
|
+
if (!PACK_NAME.test(name)) {
|
|
20
|
+
throw Object.assign(new Error(`invalid pack name: ${name} (expected ${PACK_NAME})`), { code: 'INVALID_PACK_NAME' });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** 递归列出源目录里的常规文件(相对路径)。符号链接一律拒绝:包必须自包含。 */
|
|
24
|
+
function collectFiles(root) {
|
|
25
|
+
const out = [];
|
|
26
|
+
const walk = (dir, prefix) => {
|
|
27
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
28
|
+
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
29
|
+
const absolute = path.join(dir, entry.name);
|
|
30
|
+
if (entry.isSymbolicLink()) {
|
|
31
|
+
throw Object.assign(new Error(`pack must not contain symlinks: ${relative}`), { code: 'PACK_CONTAINS_SYMLINK' });
|
|
32
|
+
}
|
|
33
|
+
if (entry.isDirectory()) {
|
|
34
|
+
if (PACK_RUNTIME_ENTRIES.has(entry.name))
|
|
35
|
+
continue;
|
|
36
|
+
walk(absolute, relative);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (!entry.isFile())
|
|
40
|
+
continue;
|
|
41
|
+
if (PACK_RUNTIME_ENTRIES.has(entry.name))
|
|
42
|
+
continue;
|
|
43
|
+
out.push(relative);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
walk(root, '');
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 安装一个包:先复制到 `.pending-<rand>`,再整体 rename 到位。
|
|
51
|
+
* 中途失败不会留下半个包(对加载器而言"目录存在但缺文件"= invalid,会污染台账)。
|
|
52
|
+
*/
|
|
53
|
+
export function installPack(request) {
|
|
54
|
+
const sourceDir = path.resolve(request.sourceDir);
|
|
55
|
+
if (!fs.existsSync(sourceDir) || !fs.statSync(sourceDir).isDirectory()) {
|
|
56
|
+
throw Object.assign(new Error(`source directory not found: ${sourceDir}`), { code: 'PACK_SOURCE_NOT_FOUND' });
|
|
57
|
+
}
|
|
58
|
+
const manifestPath = path.join(sourceDir, request.manifestFile);
|
|
59
|
+
let migratedFrom;
|
|
60
|
+
if (!fs.existsSync(manifestPath)) {
|
|
61
|
+
const legacyPath = request.legacyManifestFile ? path.join(sourceDir, request.legacyManifestFile) : undefined;
|
|
62
|
+
if (!legacyPath || !fs.existsSync(legacyPath)) {
|
|
63
|
+
throw Object.assign(new Error(`source is missing ${request.manifestFile}: ${sourceDir}`), { code: 'PACK_MANIFEST_NOT_FOUND' });
|
|
64
|
+
}
|
|
65
|
+
// 旧名一次性改名,之后流程与规范名完全一致。
|
|
66
|
+
fs.renameSync(legacyPath, manifestPath);
|
|
67
|
+
migratedFrom = request.legacyManifestFile;
|
|
68
|
+
}
|
|
69
|
+
const name = request.name?.trim() || path.basename(sourceDir);
|
|
70
|
+
assertPackName(name);
|
|
71
|
+
const targetRoot = path.resolve(request.targetRoot);
|
|
72
|
+
const targetDir = path.join(targetRoot, name);
|
|
73
|
+
// 已安装的判定看 manifest,不看目录是否存在:`pack remove` 会留下归档日志目录,
|
|
74
|
+
// 那是个"残留目录"而不是"已安装的包",应当允许直接装回去。
|
|
75
|
+
if (fs.existsSync(path.join(targetDir, request.manifestFile))) {
|
|
76
|
+
throw Object.assign(new Error(`pack already installed: ${name} (run "pack remove ${name}" first)`), { code: 'PACK_ALREADY_EXISTS' });
|
|
77
|
+
}
|
|
78
|
+
const files = collectFiles(sourceDir);
|
|
79
|
+
fs.mkdirSync(targetRoot, { recursive: true });
|
|
80
|
+
// 残留目录(只有 logs/ 等运行时产物):原地写回,不删目录也不动归档日志。
|
|
81
|
+
if (fs.existsSync(targetDir)) {
|
|
82
|
+
for (const relative of files) {
|
|
83
|
+
const destination = path.join(targetDir, relative);
|
|
84
|
+
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
85
|
+
fs.copyFileSync(path.join(sourceDir, relative), destination);
|
|
86
|
+
}
|
|
87
|
+
return { pack: name, dir: targetDir, files: files.length, intoArchived: true, ...(migratedFrom ? { migratedFrom } : {}) };
|
|
88
|
+
}
|
|
89
|
+
// 首次安装:写临时目录再整体 rename,避免中途失败留下半个包。
|
|
90
|
+
const pending = path.join(targetRoot, `.pending-${name}-${process.pid}-${Date.now()}`);
|
|
91
|
+
try {
|
|
92
|
+
for (const relative of files) {
|
|
93
|
+
const destination = path.join(pending, relative);
|
|
94
|
+
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
95
|
+
fs.copyFileSync(path.join(sourceDir, relative), destination);
|
|
96
|
+
}
|
|
97
|
+
fs.renameSync(pending, targetDir);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
fs.rmSync(pending, { recursive: true, force: true });
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
return { pack: name, dir: targetDir, files: files.length, ...(migratedFrom ? { migratedFrom } : {}) };
|
|
104
|
+
}
|
|
105
|
+
/** 卸载后在包目录留下的标记文件:加载器据此跳过"只有归档历史"的空壳目录。 */
|
|
106
|
+
export const PACK_ARCHIVED_MARKER = '.archived';
|
|
107
|
+
function archiveStamp(now = new Date()) {
|
|
108
|
+
const pad = (value, width = 2) => String(value).padStart(width, '0');
|
|
109
|
+
return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 卸载一个包。
|
|
113
|
+
*
|
|
114
|
+
* 默认**归档**运行时产物而不是删除:`logs/` 下的日志与 `ledger.jsonl` 整体移进
|
|
115
|
+
* `logs/archive-<时间戳>/`,然后删掉 manifest 与脚本,目录里只留这份归档和一个
|
|
116
|
+
* `.archived` 标记。这样重新安装不会和上次的日志混在一起(新旧各在各的目录),
|
|
117
|
+
* 想彻底删干净用 `purge`。
|
|
118
|
+
*/
|
|
119
|
+
export function removePack(options) {
|
|
120
|
+
assertPackName(options.pack);
|
|
121
|
+
const targetRoot = path.resolve(options.targetRoot);
|
|
122
|
+
const targetDir = path.join(targetRoot, options.pack);
|
|
123
|
+
if (!fs.existsSync(targetDir)) {
|
|
124
|
+
return { pack: options.pack, dir: targetDir, removed: false };
|
|
125
|
+
}
|
|
126
|
+
if (options.purge === true) {
|
|
127
|
+
fs.rmSync(targetDir, { recursive: true, force: true });
|
|
128
|
+
return { pack: options.pack, dir: targetDir, removed: true };
|
|
129
|
+
}
|
|
130
|
+
// ① 归档:logs/ 下的日志 + 包根下的 ledger / 幂等记录,一起移进归档子目录。
|
|
131
|
+
const logsDir = path.join(targetDir, 'logs');
|
|
132
|
+
const archiveName = `archive-${archiveStamp()}`;
|
|
133
|
+
const archiveDir = path.join(logsDir, archiveName);
|
|
134
|
+
const archived = [];
|
|
135
|
+
const moveInto = (from) => {
|
|
136
|
+
if (!fs.existsSync(from))
|
|
137
|
+
return;
|
|
138
|
+
fs.mkdirSync(archiveDir, { recursive: true });
|
|
139
|
+
fs.renameSync(from, path.join(archiveDir, path.basename(from)));
|
|
140
|
+
archived.push(path.basename(from));
|
|
141
|
+
};
|
|
142
|
+
try {
|
|
143
|
+
for (const entry of fs.readdirSync(logsDir, { withFileTypes: true })) {
|
|
144
|
+
if (entry.isDirectory() && entry.name.startsWith('archive-'))
|
|
145
|
+
continue;
|
|
146
|
+
const absolute = path.join(logsDir, entry.name);
|
|
147
|
+
if (entry.isDirectory()) {
|
|
148
|
+
fs.rmSync(absolute, { recursive: true, force: true });
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
moveInto(absolute);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch { /* logs/ 不存在:没有可归档的日志 */ }
|
|
155
|
+
for (const name of ['ledger.jsonl', '.idempotency.jsonl']) {
|
|
156
|
+
moveInto(path.join(targetDir, name));
|
|
157
|
+
}
|
|
158
|
+
// ② 删声明与脚本(保留 logs/ 与 .archived)。
|
|
159
|
+
for (const relative of collectFiles(targetDir)) {
|
|
160
|
+
fs.rmSync(path.join(targetDir, relative), { force: true });
|
|
161
|
+
}
|
|
162
|
+
for (const entry of fs.readdirSync(targetDir, { withFileTypes: true })) {
|
|
163
|
+
if (entry.name === 'logs' || entry.name === PACK_ARCHIVED_MARKER)
|
|
164
|
+
continue;
|
|
165
|
+
fs.rmSync(path.join(targetDir, entry.name), { recursive: true, force: true });
|
|
166
|
+
}
|
|
167
|
+
// ③ 标记:加载器据此把这些目录当作"已卸载、留了历史",不报 invalid。
|
|
168
|
+
if (archived.length > 0) {
|
|
169
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
170
|
+
fs.writeFileSync(path.join(targetDir, PACK_ARCHIVED_MARKER), JSON.stringify({ archivedAt: new Date().toISOString(), archive: `logs/${archiveName}`, files: archived }, null, 2) + String.fromCharCode(10), 'utf8');
|
|
171
|
+
return { pack: options.pack, dir: targetDir, removed: true, archivedTo: `logs/${archiveName}` };
|
|
172
|
+
}
|
|
173
|
+
// 没有任何运行时产物:目录已成空壳,直接删掉。
|
|
174
|
+
fs.rmSync(targetDir, { recursive: true, force: true });
|
|
175
|
+
return { pack: options.pack, dir: targetDir, removed: true };
|
|
176
|
+
}
|
|
177
|
+
/** `pack list`:列出目标根下看起来像包的目录。 */
|
|
178
|
+
export function listPackDirs(targetRoot, manifestFile) {
|
|
179
|
+
let entries;
|
|
180
|
+
try {
|
|
181
|
+
entries = fs.readdirSync(path.resolve(targetRoot), { withFileTypes: true });
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return [];
|
|
185
|
+
}
|
|
186
|
+
return entries
|
|
187
|
+
.filter(entry => entry.isDirectory() && !entry.name.startsWith('.') && !entry.name.startsWith('_'))
|
|
188
|
+
.sort((left, right) => left.name.localeCompare(right.name))
|
|
189
|
+
.map(entry => ({
|
|
190
|
+
pack: entry.name,
|
|
191
|
+
dir: path.join(path.resolve(targetRoot), entry.name),
|
|
192
|
+
installed: fs.existsSync(path.join(path.resolve(targetRoot), entry.name, manifestFile)),
|
|
193
|
+
}));
|
|
194
|
+
}
|
|
@@ -386,11 +386,12 @@ const APPLY_PATCH_EXECUTABLE_BASENAMES = new Set([
|
|
|
386
386
|
'apply_patch.ps1',
|
|
387
387
|
]);
|
|
388
388
|
const EVOLCORE_SUBCOMMANDS = new Set([
|
|
389
|
-
'ability', 'agent', 'aid', 'bench', 'config', 'peer', 'ctl', 'data', 'diag', 'diagnose',
|
|
389
|
+
'ability', 'agent', 'aid', 'bench', 'config', 'events', 'services', 'peer', 'ctl', 'data', 'diag', 'diagnose',
|
|
390
390
|
'fs', 'gateway', 'group', 'init', 'link-rules', 'logs', 'menu-client',
|
|
391
391
|
'mode', 'model', 'msg', 'mv', 'net', 'queue', 'response', 'restart',
|
|
392
392
|
'restart-monitor', 'rpc', 'start', 'stats', 'status', 'stop', 'storage', 'task',
|
|
393
|
-
'trigger', 'proxy', 'version', 'watch', 'session', '
|
|
393
|
+
'trigger', 'proxy', 'version', 'watch', 'session', 'team', 'upgrade', 'update',
|
|
394
|
+
'directory', 'getmeta', 'integrity', 'invoke', 'memory', 'provider', 'role', 'skill', 'thread',
|
|
394
395
|
]);
|
|
395
396
|
// Development/install entrypoints that are part of this repository's CLI.
|
|
396
397
|
// Only these exact relative paths are canonicalized; arbitrary Node scripts
|
|
@@ -3388,6 +3389,7 @@ export function containsLiteralManagedTmpDirOutsideSendContent(argv) {
|
|
|
3388
3389
|
const READ_ONLY_SUBCOMMANDS = new Set([
|
|
3389
3390
|
'thread.list', 'thread.show', 'thread.history', 'thread.peers',
|
|
3390
3391
|
'thread.summary', 'msg.history', 'msg.online', 'trigger.list', 'trigger.show',
|
|
3392
|
+
'events.status', 'events.ledger', 'events.tail', 'events.doctor', 'events.allowlist:show',
|
|
3391
3393
|
'directory.list', 'directory.info', 'aid.show', 'aid.list', 'aid.lookup',
|
|
3392
3394
|
'peer.list', 'help', 'status',
|
|
3393
3395
|
]);
|
|
@@ -3416,7 +3418,7 @@ export function isReadOnlyEcCommand(toolName, input) {
|
|
|
3416
3418
|
export function containsUnresolvedManagedTmpDirReference(argv) {
|
|
3417
3419
|
return argv.some(value => /(?:\\\$TMPDIR|\\\$\{TMPDIR\})/i.test(value));
|
|
3418
3420
|
}
|
|
3419
|
-
function hasExecutableProactiveSendPayload(argv, scope, bodyStart = 5) {
|
|
3421
|
+
function hasExecutableProactiveSendPayload(argv, scope, bodyStart = 5, options = {}) {
|
|
3420
3422
|
if (!argv || argv[0] !== 'ec' || argv[1] !== scope || argv[2] !== 'send')
|
|
3421
3423
|
return false;
|
|
3422
3424
|
const positionals = [];
|
|
@@ -3448,8 +3450,16 @@ function hasExecutableProactiveSendPayload(argv, scope, bodyStart = 5) {
|
|
|
3448
3450
|
const operand = argv[++index];
|
|
3449
3451
|
if (operand === undefined || operand.startsWith('--'))
|
|
3450
3452
|
return false;
|
|
3451
|
-
if (value === '--file' || value === '--text-from-file')
|
|
3452
|
-
|
|
3453
|
+
if (value === '--file' || value === '--text-from-file') {
|
|
3454
|
+
// 文件附件同样是向对端的意图表达:它和正文一起出现时不改变语义,
|
|
3455
|
+
// 单独出现时也把内容真实投递给了对端。只保留路径的确定性校验。
|
|
3456
|
+
if (!options.allowAttachment || !isDeterministicFilePath(operand))
|
|
3457
|
+
return false;
|
|
3458
|
+
if (modes.has('file'))
|
|
3459
|
+
return false;
|
|
3460
|
+
modes.set('file', operand);
|
|
3461
|
+
continue;
|
|
3462
|
+
}
|
|
3453
3463
|
if (value === '--app' || value === '--aun-path')
|
|
3454
3464
|
return false;
|
|
3455
3465
|
if (value === '--format' && operand !== 'json')
|
|
@@ -3470,7 +3480,13 @@ function hasExecutableProactiveSendPayload(argv, scope, bodyStart = 5) {
|
|
|
3470
3480
|
modes.set('payload-file', operand);
|
|
3471
3481
|
}
|
|
3472
3482
|
}
|
|
3473
|
-
|
|
3483
|
+
// 正文、链接、payload、payload-file 之间互斥;文件附件允许和正文一起出现。
|
|
3484
|
+
const contentModes = [...modes.keys()].filter(key => key !== 'file');
|
|
3485
|
+
if (contentModes.length > 1)
|
|
3486
|
+
return false;
|
|
3487
|
+
if (contentModes.length > 0 && positionals.length > 0)
|
|
3488
|
+
return false;
|
|
3489
|
+
if (contentModes.length > 0 && modes.has('file'))
|
|
3474
3490
|
return false;
|
|
3475
3491
|
if (modes.has('link')) {
|
|
3476
3492
|
try {
|
|
@@ -3492,6 +3508,8 @@ function hasExecutableProactiveSendPayload(argv, scope, bodyStart = 5) {
|
|
|
3492
3508
|
}
|
|
3493
3509
|
if (modes.has('payload-file'))
|
|
3494
3510
|
return true;
|
|
3511
|
+
if (modes.has('file'))
|
|
3512
|
+
return true;
|
|
3495
3513
|
return positionals.join(' ').length > 0;
|
|
3496
3514
|
}
|
|
3497
3515
|
function parseEvolcoreSendArgv(argv) {
|
|
@@ -3575,16 +3593,21 @@ export function isExactEvolcoreSendCommandForSession(toolName, input, channelId,
|
|
|
3575
3593
|
// 托管简化式:目标就是当前会话对端,无需在 argv 里写 from/to。
|
|
3576
3594
|
// 这正是 `ecmsg send '<正文>'` 归一后的形态,必须被认作意图表达。
|
|
3577
3595
|
if (isManagedSimplifiedSend(argv)) {
|
|
3578
|
-
return hasExecutableProactiveSendPayload(argv, argv[1], 3);
|
|
3596
|
+
return hasExecutableProactiveSendPayload(argv, argv[1], 3, { allowAttachment: true });
|
|
3579
3597
|
}
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3598
|
+
// 完整式:argv[3]/argv[4] 必须是本人和当前会话目标。这里不复用
|
|
3599
|
+
// parseEvolcoreSendArgv:带 --file 的合法发送会被它归类成 file 动作,
|
|
3600
|
+
// 门禁据此误判"本轮没有发送",正文+文件一起回复的回合永远清不了计数。
|
|
3583
3601
|
const expectedScope = chatType === 'group' ? 'group' : 'msg';
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3602
|
+
if (argv[1] !== expectedScope || argv[2] !== 'send')
|
|
3603
|
+
return false;
|
|
3604
|
+
const sourceId = argv[3];
|
|
3605
|
+
const targetId = argv[4];
|
|
3606
|
+
if (!sourceId || !targetId || sourceId.startsWith('--') || targetId.startsWith('--'))
|
|
3607
|
+
return false;
|
|
3608
|
+
return sourceId === selfAid
|
|
3609
|
+
&& targetId === channelId
|
|
3610
|
+
&& hasExecutableProactiveSendPayload(argv, expectedScope, 5, { allowAttachment: true });
|
|
3588
3611
|
}
|
|
3589
3612
|
/**
|
|
3590
3613
|
* 逐项诊断 proactive 发送命令被拒的具体原因。只读 argv 与(可选的)会话参数,
|
|
@@ -3596,8 +3619,11 @@ export function describeProactiveSendCommandFailure(toolName, input, session) {
|
|
|
3596
3619
|
return undefined;
|
|
3597
3620
|
const commandText = [input.command, input.input, ...(Array.isArray(input.commandArgv) ? input.commandArgv : [])]
|
|
3598
3621
|
.filter((value) => typeof value === 'string').join(' ');
|
|
3599
|
-
|
|
3622
|
+
// `ecmsg send` 是 `ec msg send` 的同义词,诊断必须同样认得,否则别名写法
|
|
3623
|
+
// 被拒时只会掉进"上一轮未包含意图表达"的笼统提示,模型拿不到可操作原因。
|
|
3624
|
+
if (!/\bec(?:\.cmd|\.exe)?\s+(?:group|msg)\s+send\b|\becmsg(?:\.cmd|\.exe|\.ps1)?\s+send\b/i.test(commandText)) {
|
|
3600
3625
|
return undefined;
|
|
3626
|
+
}
|
|
3601
3627
|
const result = parseProactiveToolCommand(toolName, input);
|
|
3602
3628
|
if (!result)
|
|
3603
3629
|
return '当前汇报命令未通过规范解析:只支持单次、字面量的发送调用,请将发送作为独立工具调用。';
|
|
@@ -3612,6 +3638,13 @@ export function describeProactiveSendCommandFailure(toolName, input, session) {
|
|
|
3612
3638
|
// --help / -h 是只读的参数查询,不是发送调用,更不该计入 proactive 违规计数。
|
|
3613
3639
|
if (argv.includes('--help') || argv.includes('-h'))
|
|
3614
3640
|
return undefined;
|
|
3641
|
+
// 托管简化式(`ecmsg send '<正文>'`):from/to 由当前会话推断,
|
|
3642
|
+
// 不应再按"缺少发送者与目标"给建议,只可能是发送内容或参数无效。
|
|
3643
|
+
if (isManagedSimplifiedSend(argv)) {
|
|
3644
|
+
return '发送命令被拒:正文或参数无效——正文不能为空(或带 --file/--text-from-file 等发送内容);'
|
|
3645
|
+
+ '--link 的值必须是 http(s) URL;--payload 的值必须是 JSON 对象;'
|
|
3646
|
+
+ '--file/--text-from-file 的值必须是确定的文件路径。';
|
|
3647
|
+
}
|
|
3615
3648
|
const scope = argv[1];
|
|
3616
3649
|
const prefix = '发送命令被拒:';
|
|
3617
3650
|
const expectedForm = `ec ${scope} send ${session?.selfAid ?? '<selfAid>'} `
|
|
@@ -3654,8 +3687,9 @@ export function describeProactiveSendCommandFailure(toolName, input, session) {
|
|
|
3654
3687
|
return `${prefix}目标必须是当前会话${scope === 'group' ? '群' : '对端'} ${session.channelId},命令里写的是 ${to};`
|
|
3655
3688
|
+ `要联系其他对象请走 --thread 跨话题发送(ec thread list <对方AID> 选中话题后加 --check-every)。`;
|
|
3656
3689
|
}
|
|
3657
|
-
return `${prefix}
|
|
3658
|
-
+ '
|
|
3690
|
+
return `${prefix}发送者与目标正确,但正文或参数无效——正文不能为空(或带 --file/--text-from-file 等发送内容);`
|
|
3691
|
+
+ '--link 的值必须是 http(s) URL;--payload 的值必须是 JSON 对象;--payload-file 的值必须是确定的文件路径;'
|
|
3692
|
+
+ '--file/--text-from-file 的值必须是确定的文件路径。';
|
|
3659
3693
|
}
|
|
3660
3694
|
/** 与 CLI `isValidAid` 同一规则;parser 不依赖 AID 模块,避免引入身份存储副作用。 */
|
|
3661
3695
|
function looksLikeAid(value) {
|
|
@@ -49,6 +49,8 @@ const L_CLASS_RELATIVE_PATTERNS = [
|
|
|
49
49
|
/^backups\/config(?:\/|$)/,
|
|
50
50
|
/^agents\/[^/]+\/triggers(?:\/|$)/,
|
|
51
51
|
/^agents\/[^/]+\/roles(?:\/|$)/,
|
|
52
|
+
/^agents\/[^/]+\/events(?:\/|$)/,
|
|
53
|
+
/^agents\/[^/]+\/services(?:\/|$)/,
|
|
52
54
|
];
|
|
53
55
|
const L_CLASS_REFERENCE_PATTERNS = [
|
|
54
56
|
/(?:^|[^A-Za-z0-9_.-])daemon\.json(?=$|[^A-Za-z0-9_.-])/,
|
|
@@ -56,6 +58,8 @@ const L_CLASS_REFERENCE_PATTERNS = [
|
|
|
56
58
|
/(?:^|[^A-Za-z0-9_.-])backups[\\/]config(?:[\\/]|$|[\s"';&|<>)},])/,
|
|
57
59
|
/(?:^|[^A-Za-z0-9_.-])agents[\\/][^/\\\s"']+[\\/]triggers(?:[\\/]|$|[\s"';&|<>)},])/,
|
|
58
60
|
/(?:^|[^A-Za-z0-9_.-])agents[\\/][^/\\\s"']+[\\/]roles(?:[\\/]|$|[\s"';&|<>)},])/,
|
|
61
|
+
/(?:^|[^A-Za-z0-9_.-])agents[\\/][^/\\\s"']+[\\/]events(?:[\\/]|$|[\s"';&|<>)},])/,
|
|
62
|
+
/(?:^|[^A-Za-z0-9_.-])agents[\\/][^/\\\s"']+[\\/]services(?:[\\/]|$|[\s"';&|<>)},])/,
|
|
59
63
|
];
|
|
60
64
|
function normalizeForComparison(value) {
|
|
61
65
|
const resolved = path.resolve(value);
|
|
@@ -438,6 +442,10 @@ export function getLClassWritePatterns(root = resolveRoot()) {
|
|
|
438
442
|
return [
|
|
439
443
|
path.join(absoluteRoot, 'agents', '*', 'triggers'),
|
|
440
444
|
path.join(absoluteRoot, 'agents', '*', 'triggers') + '/**',
|
|
445
|
+
path.join(absoluteRoot, 'agents', '*', 'events'),
|
|
446
|
+
path.join(absoluteRoot, 'agents', '*', 'events') + '/**',
|
|
447
|
+
path.join(absoluteRoot, 'agents', '*', 'services'),
|
|
448
|
+
path.join(absoluteRoot, 'agents', '*', 'services') + '/**',
|
|
441
449
|
path.join(absoluteRoot, 'agents', '*', 'roles') + '/**',
|
|
442
450
|
];
|
|
443
451
|
}
|
|
@@ -606,7 +614,7 @@ export function getExistingLClassReadOnlyTargets(root = resolveRoot(), options =
|
|
|
606
614
|
}
|
|
607
615
|
const ownRoot = path.join(agentsDir, selfAid);
|
|
608
616
|
for (const relative of [
|
|
609
|
-
'config.json', 'contact.json', 'contact-operations.jsonl', 'roles', 'triggers',
|
|
617
|
+
'config.json', 'contact.json', 'contact-operations.jsonl', 'roles', 'triggers', 'events', 'services',
|
|
610
618
|
])
|
|
611
619
|
addExistingTarget(targets, path.join(ownRoot, relative));
|
|
612
620
|
try {
|
|
@@ -625,6 +633,8 @@ export function getExistingLClassReadOnlyTargets(root = resolveRoot(), options =
|
|
|
625
633
|
if (!entry.isDirectory())
|
|
626
634
|
continue;
|
|
627
635
|
addExistingTarget(targets, path.join(agentsDir, entry.name, 'triggers'));
|
|
636
|
+
addExistingTarget(targets, path.join(agentsDir, entry.name, 'events'));
|
|
637
|
+
addExistingTarget(targets, path.join(agentsDir, entry.name, 'services'));
|
|
628
638
|
addExistingTarget(targets, path.join(agentsDir, entry.name, 'roles'));
|
|
629
639
|
}
|
|
630
640
|
}
|
|
@@ -1017,7 +1027,7 @@ export function lClassGrantIncludesProtectedPath(value, options = {}) {
|
|
|
1017
1027
|
// relations/<peer> 本身时才覆盖它,更深的路径(如 relations/<peer>/memory/…)不会。
|
|
1018
1028
|
if (segments[2] === 'relations')
|
|
1019
1029
|
return segments.length <= 4;
|
|
1020
|
-
return ['config.json', 'contact.json', 'contact-operations.jsonl', 'roles', 'triggers']
|
|
1030
|
+
return ['config.json', 'contact.json', 'contact-operations.jsonl', 'roles', 'triggers', 'events', 'services']
|
|
1021
1031
|
.includes(segments[2]);
|
|
1022
1032
|
}
|
|
1023
1033
|
return false;
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import { CODEX_HEADER_ENV_PREFIX, SERVICE_SESSION_ENV_NAMES } from '../../product.js';
|
|
2
|
+
const SERVICE_SESSION_ENV = new Set(SERVICE_SESSION_ENV_NAMES);
|
|
3
|
+
/** Preserve infrastructure and application settings without inheriting task authority. */
|
|
4
|
+
export function sanitizeServiceEnvironment(input) {
|
|
5
|
+
return Object.fromEntries(Object.entries(input).filter(([name]) => {
|
|
6
|
+
const normalized = name.toUpperCase();
|
|
7
|
+
return !SERVICE_SESSION_ENV.has(normalized) && !normalized.startsWith(CODEX_HEADER_ENV_PREFIX);
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
1
10
|
const SHELL_CODE_INJECTION_ENV = new Set([
|
|
2
11
|
'BASH_ENV',
|
|
3
12
|
'BASHOPTS',
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 分钟/小时双窗口限流,按 key 独立计数。
|
|
3
|
+
*
|
|
4
|
+
* 事件侧与服务侧共用同一份算法:两侧都是「按来源 AID 限制调用频率」,
|
|
5
|
+
* 差别只在额度来源(services-config.json 的 rateLimit vs events-config.json 的 rateLimit)。
|
|
6
|
+
* 抽出来是为了避免两套滑动窗口各自漂移——限流行为不一致比没有限流更难排查。
|
|
7
|
+
*/
|
|
8
|
+
const MINUTE_MS = 60_000;
|
|
9
|
+
const HOUR_MS = 3_600_000;
|
|
10
|
+
export class RateWindow {
|
|
11
|
+
windows = new Map();
|
|
12
|
+
/** 记一次消费;超限时不计数并给出 retryAfter。 */
|
|
13
|
+
consume(key, quota, now = Date.now()) {
|
|
14
|
+
let window = this.windows.get(key);
|
|
15
|
+
if (!window) {
|
|
16
|
+
window = { minuteStart: now, minuteCount: 0, hourStart: now, hourCount: 0 };
|
|
17
|
+
this.windows.set(key, window);
|
|
18
|
+
}
|
|
19
|
+
if (now - window.minuteStart >= MINUTE_MS) {
|
|
20
|
+
window.minuteStart = now;
|
|
21
|
+
window.minuteCount = 0;
|
|
22
|
+
}
|
|
23
|
+
if (now - window.hourStart >= HOUR_MS) {
|
|
24
|
+
window.hourStart = now;
|
|
25
|
+
window.hourCount = 0;
|
|
26
|
+
}
|
|
27
|
+
if (window.minuteCount >= quota.perMinute) {
|
|
28
|
+
return { allow: false, retryAfter: Math.max(1, Math.ceil((window.minuteStart + MINUTE_MS - now) / 1000)) };
|
|
29
|
+
}
|
|
30
|
+
if (window.hourCount >= quota.perHour) {
|
|
31
|
+
return { allow: false, retryAfter: Math.max(1, Math.ceil((window.hourStart + HOUR_MS - now) / 1000)) };
|
|
32
|
+
}
|
|
33
|
+
window.minuteCount++;
|
|
34
|
+
window.hourCount++;
|
|
35
|
+
return { allow: true };
|
|
36
|
+
}
|
|
37
|
+
/** 定期清理空窗口,避免长期运行后按 AID 无限增长。 */
|
|
38
|
+
prune(now = Date.now()) {
|
|
39
|
+
for (const [key, window] of this.windows) {
|
|
40
|
+
if (now - window.hourStart >= HOUR_MS && now - window.minuteStart >= HOUR_MS)
|
|
41
|
+
this.windows.delete(key);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** 清空全部窗口(配置切换 / 关闭时)。 */
|
|
45
|
+
reset() {
|
|
46
|
+
this.windows.clear();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -155,6 +155,14 @@ export class PeerIdentityCache {
|
|
|
155
155
|
const peerKey = formatPeerKey(channelType, peerId);
|
|
156
156
|
return path.join(agentDir, 'relations', peerKey, 'peer-identity.json');
|
|
157
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* 本端 AID 不是「对端」。agentDir 恒为 <agentsDir>/<selfAid>,因此可以直接
|
|
160
|
+
* 从目录名判断;命中时所有写盘路径都必须跳过,避免建出 `aun#<self>/`。
|
|
161
|
+
*/
|
|
162
|
+
static isSelfPeer(peerId, agentDir) {
|
|
163
|
+
const selfAid = path.basename(path.normalize(agentDir)).trim().toLowerCase();
|
|
164
|
+
return !!selfAid && selfAid === String(peerId || '').trim().toLowerCase();
|
|
165
|
+
}
|
|
158
166
|
/**
|
|
159
167
|
* 从文件读取缓存
|
|
160
168
|
* @returns PeerIdentity | null(缓存不存在)
|
|
@@ -246,6 +254,8 @@ export class PeerIdentityCache {
|
|
|
246
254
|
lastCheckedAt: now,
|
|
247
255
|
source,
|
|
248
256
|
};
|
|
257
|
+
if (this.isSelfPeer(peerId, agentDir))
|
|
258
|
+
return identity;
|
|
249
259
|
const filePath = this.getFilePath(channelType, peerId, agentDir);
|
|
250
260
|
try {
|
|
251
261
|
fs.mkdirSync(path.join(path.dirname(filePath), 'shared'), { recursive: true });
|
|
@@ -284,6 +294,8 @@ export class PeerIdentityCache {
|
|
|
284
294
|
lastCheckedAt: Date.now(),
|
|
285
295
|
source: 'unknown',
|
|
286
296
|
};
|
|
297
|
+
if (this.isSelfPeer(peerId, agentDir))
|
|
298
|
+
return identity;
|
|
287
299
|
const filePath = this.getFilePath(channelType, peerId, agentDir);
|
|
288
300
|
try {
|
|
289
301
|
fs.mkdirSync(path.join(path.dirname(filePath), 'shared'), { recursive: true });
|
|
@@ -329,6 +341,22 @@ export class PeerIdentityCache {
|
|
|
329
341
|
};
|
|
330
342
|
}
|
|
331
343
|
peerId = peerId.trim();
|
|
344
|
+
// 本端不是「对端」。跨话题自派会走 AUN 一跳(发给本端),若照常解析并落盘,
|
|
345
|
+
// relations/ 下就会多出 `aun#<self>/` 这种「我↔我」目录,污染对端名录和
|
|
346
|
+
// 后续的关系判定。这里只返回内存身份,不读也不写关系缓存。
|
|
347
|
+
if (this.isSelfPeer(peerId, agentDir)) {
|
|
348
|
+
return {
|
|
349
|
+
aid: peerId,
|
|
350
|
+
type: 'agent',
|
|
351
|
+
isMachine: true,
|
|
352
|
+
isAgent: true,
|
|
353
|
+
agentMdHash: '',
|
|
354
|
+
agentMdUpdatedAt: 0,
|
|
355
|
+
verifiedAt: 0,
|
|
356
|
+
lastCheckedAt: Date.now(),
|
|
357
|
+
source: 'unknown',
|
|
358
|
+
};
|
|
359
|
+
}
|
|
332
360
|
// 1. 缓存检查
|
|
333
361
|
if (!forceRefresh && !this.needsRefresh(channelType, peerId, agentDir)) {
|
|
334
362
|
const cached = this.get(channelType, peerId, agentDir);
|