evolcore 0.0.45 → 0.0.47
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 +113 -0
- package/bin/ecmsg.js +33 -23
- package/dist/ability/application-service.js +1 -2
- package/dist/ability/package.js +28 -0
- package/dist/agent-template/jobs.js +158 -36
- package/dist/agent-template/runtime.js +401 -34
- package/dist/agent-template/service.js +764 -369
- package/dist/agent-template/tool-runner.js +35 -17
- package/dist/agent-template/types.js +7 -4
- package/dist/agents/baseagent.js +10 -9
- package/dist/agents/claude-runner.js +22 -6
- package/dist/agents/codex/app-server-client.js +34 -27
- package/dist/agents/codex/diagnostics.js +18 -1
- package/dist/agents/codex-runner.js +3 -1
- package/dist/agents/ecagent-runner.js +3 -1
- package/dist/agents/gemini-runner.js +2 -1
- package/dist/aun/group/fs-download.js +1 -1
- package/dist/aun/menu/client.js +142 -182
- package/dist/aun/rpc/client.js +33 -17
- package/dist/aun/service-proxy.js +6 -23
- package/dist/channels/aun.js +675 -120
- package/dist/channels/daemon.js +1 -1
- package/dist/cli/agent-create.js +37 -10
- package/dist/cli/agent-template.js +105 -84
- package/dist/cli/agent.js +31 -18
- package/dist/cli/daemon-commands.js +42 -56
- package/dist/cli/daemon-lifecycle-client.js +55 -19
- package/dist/cli/directory.js +12 -4
- package/dist/cli/ecmsg-gateway.js +5 -2
- package/dist/cli/events-command.js +2 -1
- package/dist/cli/init-channel.js +2 -2
- package/dist/cli/init.js +57 -21
- package/dist/cli/integrity-command.js +2 -0
- package/dist/cli/managed-command-guard.js +20 -1
- package/dist/cli/menu-client.js +7 -5
- package/dist/cli/restart-monitor.js +135 -46
- package/dist/cli/services-command.js +28 -5
- package/dist/cli/task-context.js +83 -15
- package/dist/cli/upgrade-command.js +4 -2
- package/dist/config/config-field-policy.js +24 -0
- package/dist/config/config-manager.js +49 -19
- package/dist/config/peer-book-store.js +167 -127
- package/dist/config/peer-role-resolver.js +24 -4
- package/dist/config/provider-identity-migration.js +158 -6
- package/dist/config/provider-identity.js +10 -4
- package/dist/config/provider-ipc-service.js +10 -2
- package/dist/config/provider-local-sync.js +2 -2
- package/dist/config/providers-config.js +95 -10
- package/dist/config/providers-import.js +4 -6
- package/dist/config/providers.js +14 -3
- package/dist/config/role-store.js +1 -1
- package/dist/config/schema-migration.js +123 -16
- package/dist/config/schema-registry.js +6 -2
- package/dist/config-store.js +9 -1
- package/dist/core/agent-application-service.js +56 -29
- package/dist/core/agent-create-status.js +3 -1
- package/dist/core/agent-creation-claim.js +1 -0
- package/dist/core/agent-ipc-registration.js +2 -2
- package/dist/core/agent-reload-coordinator.js +38 -1
- package/dist/core/agent-runtime.js +91 -43
- package/dist/core/auth/agent-delegation.js +13 -3
- package/dist/core/auth/delegation-diagnostics.js +56 -15
- package/dist/core/auth/operation-authorizer.js +2 -2
- package/dist/core/auth/operation-catalog.js +3 -3
- package/dist/core/bootstrap-service.js +3 -0
- package/dist/core/capability/capability-manager.js +3 -1
- package/dist/core/channel-loader.js +29 -3
- package/dist/core/channel-runtime.js +1 -1
- package/dist/core/command/agent-control.js +6 -5
- package/dist/core/command/agent-template-menu.js +32 -97
- package/dist/core/command/eventcenter-menu.js +61 -13
- package/dist/core/command/menu-catalog.js +11 -4
- package/dist/core/command/menu-handler.js +39 -12
- package/dist/core/command/menu-protocol.js +8 -16
- package/dist/core/command/skill-slash.js +6 -2
- package/dist/core/command/slash-handler.js +4 -6
- package/dist/core/command/team-workspace-bootstrap.js +1 -2
- package/dist/core/command/team-workspace-management-store.js +83 -0
- package/dist/core/command/team-workspace-management.js +1 -2
- package/dist/core/command/team-workspace-team.js +26 -3
- package/dist/core/daemon-bootstrap.js +11 -9
- package/dist/core/daemon-control.js +4 -7
- package/dist/core/daemon-lifecycle.js +189 -143
- package/dist/core/evolagent-registry.js +50 -2
- package/dist/core/evolagent.js +2 -1
- package/dist/core/file-integrity/read.js +9 -16
- package/dist/core/file-integrity/store.js +94 -34
- package/dist/core/handoff/dispatcher.js +33 -7
- package/dist/core/handoff/runtime.js +8 -0
- package/dist/core/host-snapshot.js +9 -4
- package/dist/core/inference/text-inference.js +12 -2
- package/dist/core/initialization/service.js +22 -4
- package/dist/core/invoke/invoke-service.js +24 -3
- package/dist/core/ipc-registration.js +7 -3
- package/dist/core/memory/consolidation.js +6 -6
- package/dist/core/message/aun-ipc-sender.js +109 -7
- package/dist/core/message/contact-admission.js +6 -2
- package/dist/core/message/message-bridge.js +13 -0
- package/dist/core/message/message-queue.js +131 -30
- package/dist/core/message/pending-hints.js +8 -0
- package/dist/core/message/response-engine.js +48 -2
- package/dist/core/message/send-routing.js +3 -12
- package/dist/core/model/catalog-service.js +13 -0
- package/dist/core/model/model-catalog.js +57 -18
- package/dist/core/ownership/owner-resolver.js +27 -10
- package/dist/core/pack-auth.js +163 -31
- package/dist/core/pack-install.js +42 -1
- package/dist/{services/ledger.js → core/pack-ledger.js} +17 -6
- package/dist/core/permission/ec-command-parser.js +3 -1
- package/dist/core/permission/shell-environment.js +23 -0
- package/dist/core/rate-window.js +6 -1
- package/dist/core/relation/peer-identity.js +5 -1
- package/dist/core/relation/same-owner-proof.js +2 -1
- package/dist/core/session/adapters/claude-session-file-adapter.js +1 -1
- package/dist/core/session/session-file-health.js +36 -7
- package/dist/core/session/session-idle-monitor.js +0 -1
- package/dist/core/session/session-manager.js +14 -0
- package/dist/core/session/session-title.js +26 -6
- package/dist/core/skill/index-generator.js +3 -4
- package/dist/core/task/task-image-resources.js +1 -1
- package/dist/core/thread/thread-service.js +0 -1
- package/dist/core/thread/topic-id.js +8 -0
- package/dist/directory/owner-directory-admission.js +17 -0
- package/dist/directory/owner-directory-cache.js +3 -1
- package/dist/directory/owner-directory-markdown.js +145 -23
- package/dist/directory/owner-directory-policy.js +23 -0
- package/dist/directory/owner-directory-query-operation.js +20 -6
- package/dist/directory/owner-directory-search.js +47 -0
- package/dist/eck/message-renderer.js +171 -32
- package/dist/ecweb/basic-settings-service.js +7 -3
- package/dist/ecweb/providers-service.js +17 -10
- package/dist/ecweb/runtime/lifecycle.js +65 -16
- package/dist/ecweb/runtime/supervisor.js +79 -50
- package/dist/event-center/admission-materializer.js +1 -1
- package/dist/event-center/bus-gate.js +48 -4
- package/dist/event-center/bus-host.js +3 -3
- package/dist/event-center/center-config.js +57 -28
- package/dist/event-center/dispatcher.js +8 -0
- package/dist/event-center/event-log.js +69 -27
- package/dist/event-center/index-generator.js +6 -1
- package/dist/event-center/ipc-operation.js +66 -25
- package/dist/event-center/pack-loader.js +12 -55
- package/dist/event-center/pack-manager.js +5 -3
- package/dist/event-center/registry.js +48 -52
- package/dist/event-center/runtime.js +219 -81
- package/dist/event-center/script-runner.js +18 -7
- package/dist/event-center/types.js +9 -1
- package/dist/event-center/validation.js +33 -4
- package/dist/index.js +132 -75
- package/dist/ipc.js +35 -8
- package/dist/product.js +1 -0
- package/dist/proxy/manager.js +52 -11
- package/dist/proxy/service-supervisor.js +265 -67
- package/dist/services/dispatcher.js +26 -3
- package/dist/services/idempotency.js +128 -0
- package/dist/services/identity.js +3 -27
- package/dist/services/index-generator.js +5 -1
- package/dist/services/index.js +244 -45
- package/dist/services/ipc-operation.js +164 -20
- package/dist/services/pack-manager.js +37 -9
- package/dist/services/router.js +100 -31
- package/dist/services/script-runner.js +15 -4
- package/dist/services/service-payload.js +50 -2
- package/dist/services/validation.js +107 -3
- package/dist/trigger/scheduler.js +18 -4
- package/dist/trigger/script-sandbox.js +39 -2
- package/dist/trigger/state.js +7 -0
- package/dist/utils/aid-bind.js +155 -18
- package/dist/utils/atomic-write.js +3 -3
- package/dist/utils/cross-platform.js +59 -16
- package/dist/utils/error-utils.js +26 -1
- package/dist/utils/instance-registry.js +94 -35
- package/dist/utils/process-introspect.js +187 -27
- package/dist/utils/project-path.js +47 -3
- package/dist/utils/upgrade-jobs.js +4 -4
- package/dist/utils/windows-shell-trust.js +174 -68
- package/kits/docs/context-assembly.md +3 -3
- package/kits/docs/evolcore/agent.md +28 -10
- package/kits/docs/evolcore/aid.md +3 -1
- package/kits/docs/evolcore/config.md +22 -0
- package/kits/docs/evolcore/directory.md +46 -12
- package/kits/docs/evolcore/event-center.md +6 -6
- package/kits/docs/evolcore/group-collaboration.md +1 -1
- package/kits/docs/evolcore/menu-client.md +7 -5
- package/kits/docs/evolcore/menu-protocol.md +5 -3
- package/kits/docs/evolcore/msg.md +10 -3
- package/kits/docs/evolcore/provider.md +17 -5
- package/kits/docs/evolcore/services.md +145 -12
- package/kits/docs/evolcore/thread-chain.md +17 -9
- package/kits/docs/prompt-loading-architecture.md +4 -4
- package/kits/eck_message_manifest.json +46 -3
- package/kits/rules/04-relation.md +10 -2
- package/kits/rules/06-channel.md +2 -1
- package/kits/schemas/providers.schema.2.json +1 -0
- package/kits/skills/ec-group/SKILL.md +4 -0
- package/kits/skills/ec-skill/scripts/cli.mjs +1 -1
- package/kits/skills/ec-skill/scripts/skill.mjs +13 -2
- package/kits/skills/thread-ops/SKILL.md +8 -5
- package/kits/templates/message-fragments/group-batch-item.md +3 -0
- package/kits/templates/message-fragments/group-batch.md +1 -0
- package/kits/templates/message-fragments/item-group.md +4 -0
- package/kits/templates/message-fragments/item-private.md +4 -0
- package/kits/templates/message-fragments/thread-context.md +1 -1
- package/kits/templates/system-fragments/commands.md +5 -5
- package/kits/templates/system-fragments/managed-runtime.md +1 -1
- package/kits/templates/system-fragments/relation.md +11 -7
- package/package.json +3 -2
- package/scripts/agent-template/index.mjs +9 -4
- package/scripts/agent-template/inspect.mjs +16 -9
- package/scripts/agent-template/shared/plan.mjs +3 -33
- package/scripts/agent-template/shared/template-contract.mjs +186 -3
- package/scripts/agent-template/shared/template-package.mjs +119 -10
- package/scripts/agent-template/shared/template-runtime.mjs +49 -6
- package/scripts/agent-template/shared/template.mjs +5 -5
- package/scripts/agent-template/team-pack.mjs +245 -0
- package/scripts/agent-template/team-preview.mjs +111 -0
- package/scripts/aid-batch/identity-batch.mjs +143 -0
- package/dist/ability/versions.js +0 -32
- package/dist/aun/model-headers.js +0 -17
- package/dist/channels/builtin-plugins.js +0 -19
- package/dist/core/command/team-workspace-initializer.js +0 -2
- package/dist/core/command/team-workspace-job-store.js +0 -88
- package/dist/core/command/team-workspace-management-service.js +0 -2
- package/dist/core/contact-bind-registry.js +0 -27
- package/dist/event-center/ledger.js +0 -52
- package/dist/services/reply.js +0 -55
- package/kits/templates/message-fragments/item.md +0 -3
- package/scripts/agent-template/pack.mjs +0 -169
package/dist/core/pack-auth.js
CHANGED
|
@@ -1,26 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 事件包 / 服务包运维命令的授权判定。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 权限模型(四档操作 × 两类目标):
|
|
5
5
|
*
|
|
6
|
-
* |
|
|
7
|
-
* | ---
|
|
8
|
-
* |
|
|
9
|
-
* |
|
|
10
|
-
* |
|
|
6
|
+
* | 操作 | 自己 AID | 本机其他 AID |
|
|
7
|
+
* | --- | --- | --- |
|
|
8
|
+
* | `view` 查看 | member 及以上 | member 及以上 + 同 Owner |
|
|
9
|
+
* | `manage` 管理 | owner / admin | daemonOwner + fullaccess + 同 Owner |
|
|
10
|
+
* | `switch` 总闸 | daemonOwner + fullaccess | daemonOwner + fullaccess + 同 Owner |
|
|
11
|
+
* | `call` 调用 | 准入决定(本机不判)| 准入决定(本机不判) |
|
|
11
12
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
13
|
+
* 「daemonOwner + fullaccess」判两件事,缺一不可:
|
|
14
|
+
* ① 本次执行是真正的 fullaccess(`isTrustedFullAccessRuntimeContext` 的结论,
|
|
15
|
+
* 由 IPC 层算好传进来,见 `ipc.ts` 的 `packCaller`);
|
|
16
|
+
* ② 给它授权的那个身份本身是本机 daemon owner(`authorizedBy ∈ daemonOwners`)。
|
|
17
|
+
* 只判 ① 等于"谁都能自己开一个 fullaccess 会话",只判 ② 等于"daemon owner
|
|
18
|
+
* 名下的普通会话也能管理",两者都不是权限模型的意图。
|
|
14
19
|
*
|
|
15
|
-
* 为什么跨 AID
|
|
16
|
-
*
|
|
17
|
-
*
|
|
20
|
+
* 为什么跨 AID 要额外要求同 Owner:`pack add` 等于给目标 agent 安装一段以后
|
|
21
|
+
* 以它的身份执行的代码。同 AID 是"自己装给自己的",跨 AID 则是"用别人的身份
|
|
22
|
+
* 执行"。daemonOwner 说明"这台机器是我的",同 Owner 说明"这两个 agent 都是我
|
|
23
|
+
* 的"——一台机器上可能挂着多个 Owner 的 agent,前者不能推出后者。
|
|
18
24
|
*
|
|
19
25
|
* 为什么不读 `/public` 或名录里的转发关系:那些都是会被拷贝、会变的展示信息;
|
|
20
26
|
* 协议 owner 归属(`ownerResolver`)才是唯一可信判据。
|
|
21
27
|
*/
|
|
22
|
-
import { getProtocolOwner } from './ownership/owner-resolver.js';
|
|
28
|
+
import { getDaemonOwners, getProtocolOwner } from './ownership/owner-resolver.js';
|
|
29
|
+
import { getRoleRank } from '../config/roles.js';
|
|
30
|
+
import { ROLE_RANKS } from '../config/role-ranks.js';
|
|
23
31
|
const MANAGING_ROLES = new Set(['owner', 'admin']);
|
|
32
|
+
/**
|
|
33
|
+
* 查看档的角色下限:member(rank 300)及以上。
|
|
34
|
+
*
|
|
35
|
+
* 不能直接用 `getRoleRank(role) >= ROLE_RANKS.member`:`expectedRoleRank` 对任何
|
|
36
|
+
* 未列出的取值都回落到 `custom`(500),于是 `'none'`、空串、拼错的名字全都
|
|
37
|
+
* 排在 member 之上——那会把"无有效关系角色"判成可读。`none` 必须显式拒绝,
|
|
38
|
+
* 其余走等级比较(自定义角色按模板里配的 rank)。
|
|
39
|
+
*/
|
|
40
|
+
function canView(caller) {
|
|
41
|
+
const role = caller.peerRole;
|
|
42
|
+
if (!role || role === 'none')
|
|
43
|
+
return false;
|
|
44
|
+
return getRoleRank(role, caller.selfAid) >= ROLE_RANKS.member;
|
|
45
|
+
}
|
|
24
46
|
export function authorizePackTarget(input) {
|
|
25
47
|
// 主机终端:人自己在操作,OS 账户可读 control.token 就是信任边界。
|
|
26
48
|
if (input.caller.kind === 'local-control')
|
|
@@ -29,28 +51,63 @@ export function authorizePackTarget(input) {
|
|
|
29
51
|
if (!selfAid) {
|
|
30
52
|
return { allowed: false, code: 'NOT_ALLOWED', error: '当前任务身份不可用;托管会话需要 sessionId 与 delegationToken' };
|
|
31
53
|
}
|
|
32
|
-
|
|
54
|
+
// 对端调用的放行由对端的准入与 rules 决定,不是本机权限问题。
|
|
55
|
+
if (input.operation === 'call')
|
|
33
56
|
return { allowed: true };
|
|
34
|
-
const role = input.caller.peerRole;
|
|
35
57
|
if (input.targetAid === selfAid) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
58
|
+
switch (input.operation) {
|
|
59
|
+
case 'view':
|
|
60
|
+
return canView(input.caller)
|
|
61
|
+
? { allowed: true }
|
|
62
|
+
: {
|
|
63
|
+
allowed: false,
|
|
64
|
+
code: 'ROLE_ACCESS_DENIED',
|
|
65
|
+
error: `查看本机事件/服务包需要 member 及以上身份(当前 ${input.caller.peerRole ?? 'none'})`,
|
|
66
|
+
};
|
|
67
|
+
case 'manage':
|
|
68
|
+
return MANAGING_ROLES.has(input.caller.peerRole ?? '')
|
|
69
|
+
? { allowed: true }
|
|
70
|
+
: {
|
|
71
|
+
allowed: false,
|
|
72
|
+
code: 'ROLE_ACCESS_DENIED',
|
|
73
|
+
error: `管理本机事件/服务包需要 owner 或 admin 身份(当前 ${input.caller.peerRole ?? 'none'})`,
|
|
74
|
+
};
|
|
75
|
+
case 'switch':
|
|
76
|
+
return requireDaemonOwnerFullAccess(input.caller, '开关本机服务总闸需要 daemonOwner 身份的 fullaccess 执行');
|
|
77
|
+
}
|
|
43
78
|
}
|
|
44
|
-
// 跨 AID
|
|
45
|
-
|
|
79
|
+
// ── 跨 AID ──
|
|
80
|
+
const selfOwner = getProtocolOwner(selfAid);
|
|
81
|
+
const targetOwner = getProtocolOwner(input.targetAid);
|
|
82
|
+
// 跨 AID 查看:先过角色下限(member+),再看归属。顺序不能反——先查归属
|
|
83
|
+
// 会给低角色调用方一个可区分的错误码,等于泄露"这两个 agent 是否同 Owner"。
|
|
84
|
+
if (input.operation === 'view' && !canView(input.caller)) {
|
|
46
85
|
return {
|
|
47
86
|
allowed: false,
|
|
48
87
|
code: 'ROLE_ACCESS_DENIED',
|
|
49
|
-
error:
|
|
88
|
+
error: `查看其它 agent 的事件/服务包需要 member 及以上身份(当前 ${input.caller.peerRole ?? 'none'})`,
|
|
50
89
|
};
|
|
51
90
|
}
|
|
52
|
-
|
|
53
|
-
|
|
91
|
+
if (input.operation === 'view') {
|
|
92
|
+
if (!selfOwner || !targetOwner) {
|
|
93
|
+
return {
|
|
94
|
+
allowed: false,
|
|
95
|
+
code: 'OWNERSHIP_UNAVAILABLE',
|
|
96
|
+
error: `查看其它 agent 的事件/服务包需要双方都有协议 owner 归属(self=${selfOwner ?? 'none'}, target=${targetOwner ?? 'none'})`,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return selfOwner === targetOwner
|
|
100
|
+
? { allowed: true }
|
|
101
|
+
: {
|
|
102
|
+
allowed: false,
|
|
103
|
+
code: 'CROSS_AGENT_DENIED',
|
|
104
|
+
error: `查看其它 agent 的事件/服务包要求两个 agent 属于同一个 Owner(self owner=${selfOwner}, target owner=${targetOwner})`,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
// manage / switch:daemonOwner + fullaccess + 同 Owner,三者缺一不可。
|
|
108
|
+
const elevated = requireDaemonOwnerFullAccess(input.caller, '跨 AID 管理事件/服务包需要 daemonOwner 身份的 fullaccess 执行');
|
|
109
|
+
if (!elevated.allowed)
|
|
110
|
+
return elevated;
|
|
54
111
|
if (!selfOwner || !targetOwner) {
|
|
55
112
|
return {
|
|
56
113
|
allowed: false,
|
|
@@ -85,10 +142,85 @@ export function authorizePackTarget(input) {
|
|
|
85
142
|
}
|
|
86
143
|
return { allowed: true };
|
|
87
144
|
}
|
|
88
|
-
/**
|
|
89
|
-
|
|
90
|
-
|
|
145
|
+
/**
|
|
146
|
+
* 「daemonOwner + fullaccess」的完整判定。
|
|
147
|
+
*
|
|
148
|
+
* 两个条件分开检查,错误码也分开——排查时"没开 fullaccess"和"授权者不是
|
|
149
|
+
* daemon owner"是两件完全不同的事。
|
|
150
|
+
*/
|
|
151
|
+
function requireDaemonOwnerFullAccess(caller, context) {
|
|
152
|
+
if (caller.fullAccess !== true) {
|
|
153
|
+
return {
|
|
154
|
+
allowed: false,
|
|
155
|
+
code: 'FULLACCESS_REQUIRED',
|
|
156
|
+
error: `${context}(当前会话不是 fullaccess 执行)`,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const authorizer = caller.authorizedBy;
|
|
160
|
+
if (!authorizer || !getDaemonOwners().includes(authorizer)) {
|
|
161
|
+
return {
|
|
162
|
+
allowed: false,
|
|
163
|
+
code: 'DAEMON_OWNER_REQUIRED',
|
|
164
|
+
error: `${context}(授权者 ${authorizer ?? 'none'} 不是本机 daemon owner)`,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
return { allowed: true };
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* 逐个操作声明权限,不按命令名前缀归类。
|
|
171
|
+
*
|
|
172
|
+
* 以前是 `command === 'pack' || command === 'rules'`,把 `rules show` 和
|
|
173
|
+
* `pack list` 一起判成了管理命令——两个都只读,托管 member 却查不到自己的
|
|
174
|
+
* 规则表和包清单。改成按完整操作名查表后,四档边界写在数据里。
|
|
175
|
+
*
|
|
176
|
+
* 未列出的键一律按 `manage` 处理,新加命令忘了登记只会收紧、不会放开。
|
|
177
|
+
*/
|
|
178
|
+
const PACK_OPERATIONS = {
|
|
179
|
+
events: {
|
|
180
|
+
status: 'view',
|
|
181
|
+
ledger: 'view',
|
|
182
|
+
tail: 'view',
|
|
183
|
+
doctor: 'view',
|
|
184
|
+
// reload 只重扫磁盘、重建订阅,不引入新权限。
|
|
185
|
+
reload: 'view',
|
|
186
|
+
// publish 只能发 `pack.json` 里 owner 已声明的事件(runtime.publish 校验),
|
|
187
|
+
// 等于执行已授权动作;跨 AID 的接收方准入另行判定。
|
|
188
|
+
publish: 'call',
|
|
189
|
+
'rules:show': 'view',
|
|
190
|
+
'rules:add': 'manage',
|
|
191
|
+
'rules:remove': 'manage',
|
|
192
|
+
'pack:list': 'view',
|
|
193
|
+
'pack:add': 'manage',
|
|
194
|
+
'pack:remove': 'manage',
|
|
195
|
+
'pack:enable': 'manage',
|
|
196
|
+
'pack:disable': 'manage',
|
|
197
|
+
},
|
|
198
|
+
services: {
|
|
199
|
+
status: 'view',
|
|
200
|
+
types: 'view',
|
|
201
|
+
ledger: 'view',
|
|
202
|
+
tail: 'view',
|
|
203
|
+
doctor: 'view',
|
|
204
|
+
reload: 'view',
|
|
205
|
+
// call/describe/schema 的放行由对端准入决定,不是本机权限问题。
|
|
206
|
+
describe: 'call',
|
|
207
|
+
schema: 'call',
|
|
208
|
+
call: 'call',
|
|
209
|
+
// AID 级总闸:整机是否对外提供本 AID 的服务。
|
|
210
|
+
enable: 'switch',
|
|
211
|
+
disable: 'switch',
|
|
212
|
+
'pack:list': 'view',
|
|
213
|
+
'pack:add': 'manage',
|
|
214
|
+
'pack:remove': 'manage',
|
|
215
|
+
'pack:enable': 'manage',
|
|
216
|
+
'pack:disable': 'manage',
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
/** `pack` 需要带上子动作(list/add/remove/enable/disable),其余命令名本身就是操作键。 */
|
|
220
|
+
export function packOperationKey(command, action) {
|
|
221
|
+
return command === 'pack' ? `pack:${action ?? ''}` : command;
|
|
91
222
|
}
|
|
92
|
-
|
|
93
|
-
|
|
223
|
+
/** 查表得出该命令的操作档位;未登记的一律 `manage`(fail-closed)。 */
|
|
224
|
+
export function packOperation(domain, command, action) {
|
|
225
|
+
return PACK_OPERATIONS[domain][packOperationKey(command, action)] ?? 'manage';
|
|
94
226
|
}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import fs from 'node:fs';
|
|
13
13
|
import path from 'node:path';
|
|
14
|
+
import { atomicWriteJson } from '../utils/atomic-write.js';
|
|
14
15
|
/** 包安装期间的运行时产物:不该被拷进新包,也不该被 `pack add` 覆盖。 */
|
|
15
16
|
const PACK_RUNTIME_ENTRIES = new Set(['ledger.jsonl', '.idempotency.jsonl', 'logs', '.state.json', '.index.md']);
|
|
16
17
|
/** 包名:英文短横线/下划线,防止 `..` 或路径分隔符把写入引出目标根。 */
|
|
@@ -78,12 +79,16 @@ export function installPack(request) {
|
|
|
78
79
|
const files = collectFiles(sourceDir);
|
|
79
80
|
fs.mkdirSync(targetRoot, { recursive: true });
|
|
80
81
|
// 残留目录(只有 logs/ 等运行时产物):原地写回,不删目录也不动归档日志。
|
|
82
|
+
//
|
|
83
|
+
// `.archived` 标记必须一并删掉:两个加载器见到它就直接跳过(pack-loader /
|
|
84
|
+
// pack-manager),留着它会让"文件都装回来了但包永远不加载",表现像包坏了。
|
|
81
85
|
if (fs.existsSync(targetDir)) {
|
|
82
86
|
for (const relative of files) {
|
|
83
87
|
const destination = path.join(targetDir, relative);
|
|
84
88
|
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
85
89
|
fs.copyFileSync(path.join(sourceDir, relative), destination);
|
|
86
90
|
}
|
|
91
|
+
fs.rmSync(path.join(targetDir, PACK_ARCHIVED_MARKER), { force: true });
|
|
87
92
|
return { pack: name, dir: targetDir, files: files.length, intoArchived: true, ...(migratedFrom ? { migratedFrom } : {}) };
|
|
88
93
|
}
|
|
89
94
|
// 首次安装:写临时目录再整体 rename,避免中途失败留下半个包。
|
|
@@ -174,7 +179,43 @@ export function removePack(options) {
|
|
|
174
179
|
fs.rmSync(targetDir, { recursive: true, force: true });
|
|
175
180
|
return { pack: options.pack, dir: targetDir, removed: true };
|
|
176
181
|
}
|
|
177
|
-
/**
|
|
182
|
+
/**
|
|
183
|
+
* 单包启停:改 `pack.json` 的 `enabled` 字段,其余字段原样保留。
|
|
184
|
+
*
|
|
185
|
+
* 与 `installPack` / `removePack` 同属 daemon 代写——`agents/<aid>/{events,services}`
|
|
186
|
+
* 是 L 类受保护路径,agent 自己写不了。
|
|
187
|
+
*
|
|
188
|
+
* 只改这一个字段、整份重写其余内容:`name` / `description` / `listen` /
|
|
189
|
+
* `requires` 等都由包作者维护,命令不该碰。缺省语义对齐加载器——`enabled`
|
|
190
|
+
* 未写等于开启(`raw.enabled !== false`),所以 `enable` 写 `true` 而不是删字段,
|
|
191
|
+
* 文件内容始终是显式的。
|
|
192
|
+
*/
|
|
193
|
+
export function setPackEnabled(options) {
|
|
194
|
+
assertPackName(options.pack);
|
|
195
|
+
const dir = path.join(path.resolve(options.targetRoot), options.pack);
|
|
196
|
+
const manifestPath = path.join(dir, options.manifestFile);
|
|
197
|
+
let raw;
|
|
198
|
+
try {
|
|
199
|
+
raw = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
const code = error.code;
|
|
203
|
+
throw Object.assign(new Error(code === 'ENOENT'
|
|
204
|
+
? `pack not found: ${options.pack} (missing ${options.manifestFile} in ${dir})`
|
|
205
|
+
: `cannot read ${options.manifestFile} for ${options.pack}: ${error instanceof Error ? error.message : String(error)}`), { code: code === 'ENOENT' ? 'PACK_NOT_FOUND' : 'PACK_MANIFEST_UNREADABLE' });
|
|
206
|
+
}
|
|
207
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
208
|
+
throw Object.assign(new Error(`${options.manifestFile} for ${options.pack} is not a JSON object`), {
|
|
209
|
+
code: 'PACK_MANIFEST_INVALID',
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
const record = raw;
|
|
213
|
+
// 未写 `enabled` 时按加载器口径视为开启(`raw.enabled !== false`)。
|
|
214
|
+
const previous = record.enabled !== false;
|
|
215
|
+
record.enabled = options.enabled;
|
|
216
|
+
atomicWriteJson(manifestPath, record);
|
|
217
|
+
return { pack: options.pack, dir, enabled: options.enabled, previous };
|
|
218
|
+
}
|
|
178
219
|
export function listPackDirs(targetRoot, manifestFile) {
|
|
179
220
|
let entries;
|
|
180
221
|
try {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* 事件与服务包的长期生命周期台账;消息正文仍由各自的按日消息日志记录。
|
|
3
|
+
* 领域 action/字段分别约束,追加与读取共用一个实现。
|
|
4
4
|
*/
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import path from 'node:path';
|
|
7
|
-
|
|
7
|
+
class PackLedger {
|
|
8
8
|
filePath;
|
|
9
9
|
constructor(filePath) {
|
|
10
10
|
this.filePath = filePath;
|
|
@@ -18,7 +18,7 @@ export class ServiceLedger {
|
|
|
18
18
|
fs.appendFileSync(this.filePath, `${JSON.stringify(full)}\n`, 'utf8');
|
|
19
19
|
}
|
|
20
20
|
catch {
|
|
21
|
-
//
|
|
21
|
+
// 台账写失败不致命:运行继续,由台账查询入口诊断磁盘。
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
/** 读最后 N 行(CLI tail 用)。 */
|
|
@@ -43,10 +43,21 @@ export class ServiceLedger {
|
|
|
43
43
|
return out;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
export
|
|
46
|
+
export class Ledger extends PackLedger {
|
|
47
|
+
}
|
|
48
|
+
export class ServiceLedger extends PackLedger {
|
|
49
|
+
}
|
|
50
|
+
export function eventPackLedger(pack) {
|
|
51
|
+
return new Ledger(pack.paths.ledger);
|
|
52
|
+
}
|
|
53
|
+
export function servicePackLedger(pack) {
|
|
47
54
|
return new ServiceLedger(pack.paths.ledger);
|
|
48
55
|
}
|
|
49
|
-
/**
|
|
56
|
+
/** 事件中心级台账。 */
|
|
57
|
+
export function centerLedger(eventsDir) {
|
|
58
|
+
return new Ledger(path.join(eventsDir, '.center-ledger.jsonl'));
|
|
59
|
+
}
|
|
60
|
+
/** 服务路由级台账。 */
|
|
50
61
|
export function routerLedger(servicesDir) {
|
|
51
62
|
return new ServiceLedger(path.join(servicesDir, '.router-ledger.jsonl'));
|
|
52
63
|
}
|
|
@@ -3748,7 +3748,9 @@ export function isThreadRoutedEvolcoreSendCommand(toolName, input, selfAid, reso
|
|
|
3748
3748
|
else {
|
|
3749
3749
|
return false;
|
|
3750
3750
|
}
|
|
3751
|
-
|
|
3751
|
+
// 跨话题发送同样属于「向对端表达意图」,--file/--text-from-file 必须与正文同等对待;
|
|
3752
|
+
// 这里漏传 allowAttachment 会让所有带附件的 --thread 发送被误判成"没有发送内容"。
|
|
3753
|
+
if (!hasExecutableProactiveSendPayload(normalized, scope, 5, { allowAttachment: true }))
|
|
3752
3754
|
return false;
|
|
3753
3755
|
return resolveThread(scope, threadId, target);
|
|
3754
3756
|
}
|
|
@@ -36,6 +36,29 @@ export function isShellCodeInjectionEnvironmentName(name) {
|
|
|
36
36
|
|| name.startsWith('LD_')
|
|
37
37
|
|| name.startsWith('DYLD_');
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* 凭据类环境变量名:脚本不该继承的任何东西。
|
|
41
|
+
*
|
|
42
|
+
* 命名约定而非白名单——`GITHUB_TOKEN`、`AWS_SECRET_ACCESS_KEY`、`NPM_TOKEN`
|
|
43
|
+
* 这类名字不认识就是漏。宁可误杀一个业务变量(脚本自己传参即可),也不要让
|
|
44
|
+
* 一个第三方 token 悄悄进到没有隔离的脚本里。
|
|
45
|
+
*
|
|
46
|
+
* 与 `isShellCodeInjectionEnvironmentName` 分开:那个防的是命令注入,这个防的是
|
|
47
|
+
* 凭据泄漏,两者失效后果不同,调用点也不同。
|
|
48
|
+
*/
|
|
49
|
+
export function isCredentialEnvironmentName(name) {
|
|
50
|
+
const normalized = name.toUpperCase();
|
|
51
|
+
return CREDENTIAL_ENV_SUFFIXES.some(suffix => normalized.endsWith(suffix))
|
|
52
|
+
|| CREDENTIAL_ENV_PREFIXES.some(prefix => normalized.startsWith(prefix))
|
|
53
|
+
|| normalized.includes('PASSWORD')
|
|
54
|
+
|| normalized.includes('PASSWD');
|
|
55
|
+
}
|
|
56
|
+
const CREDENTIAL_ENV_SUFFIXES = [
|
|
57
|
+
'_API_KEY', '_APIKEY', '_TOKEN', '_SECRET', '_SECRET_KEY', '_CREDENTIAL', '_CREDENTIALS',
|
|
58
|
+
'_ACCESS_KEY', '_PRIVATE_KEY', '_AUTH_TOKEN',
|
|
59
|
+
];
|
|
60
|
+
/** 云厂商/包管理器的固定前缀:这些名字的后半段五花八门,按前缀更稳。 */
|
|
61
|
+
const CREDENTIAL_ENV_PREFIXES = ['AWS_', 'GCP_', 'AZURE_', 'NPM_', 'GITHUB_', 'GH_', 'DOCKER_', 'SLACK_'];
|
|
39
62
|
export function sanitizeShellExecutionEnvironment(input, options = {}) {
|
|
40
63
|
const sanitized = { ...input };
|
|
41
64
|
for (const name of Object.keys(sanitized)) {
|
package/dist/core/rate-window.js
CHANGED
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 事件侧与服务侧共用同一份算法:两侧都是「按来源 AID 限制调用频率」,
|
|
5
5
|
* 差别只在额度来源(services-config.json 的 rateLimit vs events-config.json 的 rateLimit)。
|
|
6
|
-
*
|
|
6
|
+
* 抽出来是为了避免两套实现各自漂移——限流行为不一致比没有限流更难排查。
|
|
7
|
+
*
|
|
8
|
+
* **这是固定窗口,不是滑动窗口。** 每分钟(每小时)从第一次调用起算一格,到点整体清零。
|
|
9
|
+
* 后果是边界处最多放行到 2 倍额度:59 秒用完 60 次,60 秒满血又 60 次。
|
|
10
|
+
* 对"保护订阅方脚本不被失控的发布方打爆"这个目的够用——它防的是持续过载,
|
|
11
|
+
* 不是精确配额。真要严格,得换成令牌桶或滑动日志,代价是每 key 存一条时间序列。
|
|
7
12
|
*/
|
|
8
13
|
const MINUTE_MS = 60_000;
|
|
9
14
|
const HOUR_MS = 3_600_000;
|
|
@@ -21,6 +21,9 @@ export function parseAgentMdFrontmatter(content) {
|
|
|
21
21
|
const end = lines.slice(1).findIndex(line => line.trim() === '---');
|
|
22
22
|
if (end < 0)
|
|
23
23
|
return {};
|
|
24
|
+
// Lifecycle clients only use peer-key helpers; parsing keeps the same
|
|
25
|
+
// synchronous YAML implementation without loading it into those clients.
|
|
26
|
+
const { parse: parseYaml } = requirePeerIdentityDependency('yaml');
|
|
24
27
|
try {
|
|
25
28
|
const parsed = parseYaml(lines.slice(1, end + 1).join('\n'));
|
|
26
29
|
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
@@ -64,12 +67,13 @@ function normalizeCachedIdentity(raw) {
|
|
|
64
67
|
import * as fs from 'fs';
|
|
65
68
|
import * as path from 'path';
|
|
66
69
|
import * as crypto from 'crypto';
|
|
67
|
-
import {
|
|
70
|
+
import { createRequire } from 'node:module';
|
|
68
71
|
import { logger } from '../../utils/logger.js';
|
|
69
72
|
import { agentDir as resolveAgentDir, agentMdPath } from '../../paths.js';
|
|
70
73
|
import { ConfigTarget, mutateConfig, read } from '../../config/config-manager.js';
|
|
71
74
|
import { isValidAid } from '../../aun/aid/validation.js';
|
|
72
75
|
import { resolveAunTargetKind, verifiedPeerType, } from '../../aun/group/identity.js';
|
|
76
|
+
const requirePeerIdentityDependency = createRequire(import.meta.url);
|
|
73
77
|
/**
|
|
74
78
|
* peerKey: 关系层路由键,格式 `<channelType>#<urlEncode(channelId)>`。
|
|
75
79
|
* 群聊场景下 channelId = groupId,所有发言者共用同一个 peerKey。
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createHash } from 'crypto';
|
|
2
|
-
import { agentmdGet } from '../../aun/aid/agentmd.js';
|
|
3
2
|
import { isValidAid } from '../../aun/aid/validation.js';
|
|
4
3
|
import { parseAgentMdFrontmatter } from './peer-identity.js';
|
|
5
4
|
export const SAME_OWNER_MAX_AGE_MS = 30_000;
|
|
@@ -64,6 +63,8 @@ export async function prepareSameOwnerProof(selfAid, peerAid) {
|
|
|
64
63
|
const generation = runtime.generation;
|
|
65
64
|
const startedAt = Date.now();
|
|
66
65
|
const query = async () => {
|
|
66
|
+
// Lifecycle CLI commands never need profile verification or the AUN SDK.
|
|
67
|
+
const { agentmdGet } = await import('../../aun/aid/agentmd.js');
|
|
67
68
|
const cards = await Promise.all([selfAid, peerAid].map(aid => agentmdGet(aid, { store: runtime.store, withVerification: true, remoteOnly: true })));
|
|
68
69
|
const profiles = cards.map((card, index) => {
|
|
69
70
|
if (card.source !== 'remote' || card.verification.status !== 'verified')
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* Reads Claude Agent SDK session files from ~/.claude/projects/{encodedPath}/{sessionId}.jsonl
|
|
5
5
|
* and wraps sdkListSessions for name synchronization.
|
|
6
6
|
*/
|
|
7
|
-
import { listSessions as sdkListSessions } from '@anthropic-ai/claude-agent-sdk';
|
|
8
7
|
import { encodePath } from '../../../utils/cross-platform.js';
|
|
9
8
|
import { logger } from '../../../utils/logger.js';
|
|
10
9
|
import { buildCliSessionPreview } from '../session-title.js';
|
|
@@ -207,6 +206,7 @@ export class ClaudeSessionFileAdapter {
|
|
|
207
206
|
}
|
|
208
207
|
async listSdkSessions(projectPath) {
|
|
209
208
|
try {
|
|
209
|
+
const { listSessions: sdkListSessions } = await import('@anthropic-ai/claude-agent-sdk');
|
|
210
210
|
const sessions = await sdkListSessions({ dir: projectPath });
|
|
211
211
|
return sessions.map(s => ({
|
|
212
212
|
sessionId: s.sessionId,
|
|
@@ -157,13 +157,35 @@ export async function repairCodexSessionProvider(options) {
|
|
|
157
157
|
const { DatabaseSync } = requireFromHere('node:sqlite');
|
|
158
158
|
const directory = rollout + '.provider-repair';
|
|
159
159
|
const journalFile = path.join(directory, 'intent.json');
|
|
160
|
+
const assertIndexedRolloutPath = (indexedPath) => {
|
|
161
|
+
const context = `thread=${threadId}, database=${JSON.stringify(database)},`
|
|
162
|
+
+ ` index=${JSON.stringify(indexedPath)}, rollout=${JSON.stringify(rollout)}`;
|
|
163
|
+
let indexedRealPath;
|
|
164
|
+
let rolloutRealPath;
|
|
165
|
+
try {
|
|
166
|
+
// Windows Codex stores verbatim paths (\\?\) in SQLite. Resolve both
|
|
167
|
+
// through the filesystem instead of comparing their textual spelling.
|
|
168
|
+
indexedRealPath = fs.realpathSync.native(indexedPath);
|
|
169
|
+
rolloutRealPath = fs.realpathSync.native(rollout);
|
|
170
|
+
}
|
|
171
|
+
catch (cause) {
|
|
172
|
+
throw new Error(`Codex thread index rollout path cannot be resolved (${context}): `
|
|
173
|
+
+ (cause instanceof Error ? cause.message : String(cause)), { cause });
|
|
174
|
+
}
|
|
175
|
+
if (indexedRealPath !== rolloutRealPath) {
|
|
176
|
+
throw new Error(`Codex thread index rollout path mismatch (${context})`);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
160
179
|
const readIndex = () => {
|
|
161
180
|
const db = new DatabaseSync(database, { readOnly: true });
|
|
162
181
|
try {
|
|
163
182
|
const row = db.prepare('SELECT model_provider, rollout_path FROM threads WHERE id = ?').get(threadId);
|
|
164
|
-
if (!row
|
|
165
|
-
|
|
166
|
-
|
|
183
|
+
if (!row)
|
|
184
|
+
throw new Error(`Codex thread index row is missing (thread=${threadId})`);
|
|
185
|
+
if (typeof row.model_provider !== 'string' || typeof row.rollout_path !== 'string') {
|
|
186
|
+
throw new Error(`Codex thread index fields are invalid (thread=${threadId})`);
|
|
187
|
+
}
|
|
188
|
+
assertIndexedRolloutPath(row.rollout_path);
|
|
167
189
|
return row;
|
|
168
190
|
}
|
|
169
191
|
finally {
|
|
@@ -192,12 +214,13 @@ export async function repairCodexSessionProvider(options) {
|
|
|
192
214
|
const apply = (intent) => {
|
|
193
215
|
const backupRoot = path.join(directory, path.basename(path.dirname(intent.backup)));
|
|
194
216
|
if (intent.version !== 1 || intent.threadId !== threadId || intent.database !== database
|
|
195
|
-
|| intent.rollout !== rollout ||
|
|
217
|
+
|| intent.rollout !== rollout || typeof intent.indexedPath !== 'string'
|
|
196
218
|
|| intent.backup !== path.join(backupRoot, 'before.snapshot')
|
|
197
219
|
|| intent.next !== path.join(backupRoot, 'after.snapshot')
|
|
198
220
|
|| !/^evolcore_registry_[a-f0-9]{20}$/.test(intent.provider)) {
|
|
199
221
|
throw new Error('Invalid Codex Provider repair journal');
|
|
200
222
|
}
|
|
223
|
+
assertIndexedRolloutPath(intent.indexedPath);
|
|
201
224
|
assertRepairFile(intent.backup, directory);
|
|
202
225
|
const original = fs.readFileSync(intent.backup);
|
|
203
226
|
const replacement = rewriteCodexProvider(original, threadId, intent.provider);
|
|
@@ -264,9 +287,15 @@ export async function repairCodexSessionProvider(options) {
|
|
|
264
287
|
}
|
|
265
288
|
const bytes = fs.readFileSync(rollout);
|
|
266
289
|
const current = readIndex();
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
290
|
+
const rolloutProvider = codexMetadata(bytes, threadId).provider;
|
|
291
|
+
if (rolloutProvider !== provider || current.model_provider !== provider) {
|
|
292
|
+
// Codex 0.164 can resume with a new Provider by updating only the index.
|
|
293
|
+
// Allow its stale header to catch up when the index already names our
|
|
294
|
+
// resolved Provider; unrelated disagreements still fail closed.
|
|
295
|
+
if (rolloutProvider !== current.model_provider && current.model_provider !== provider) {
|
|
296
|
+
throw new Error('Codex Provider repair rejected: rollout and index disagree'
|
|
297
|
+
+ ` (thread=${threadId}, rollout=${JSON.stringify(rolloutProvider)},`
|
|
298
|
+
+ ` index=${JSON.stringify(current.model_provider)}, target=${JSON.stringify(provider)})`);
|
|
270
299
|
}
|
|
271
300
|
const backupRoot = path.join(directory, randomUUID());
|
|
272
301
|
fs.mkdirSync(backupRoot, { mode: 0o700 });
|
|
@@ -257,7 +257,6 @@ export class SessionIdleMonitor {
|
|
|
257
257
|
this.options.eventBus.subscribe('session:created', this.onSessionCreated);
|
|
258
258
|
this.options.eventBus.subscribe('session:loop-changed', this.onSessionLoopChanged);
|
|
259
259
|
}
|
|
260
|
-
/** Subscribe first; restore cold history only after normal task Ready. */
|
|
261
260
|
activate(options = {}) {
|
|
262
261
|
if (this.active)
|
|
263
262
|
return Promise.resolve();
|
|
@@ -1028,6 +1028,20 @@ export class SessionManager {
|
|
|
1028
1028
|
this.sessionFileIndex.set(sessionId, found);
|
|
1029
1029
|
return found;
|
|
1030
1030
|
}
|
|
1031
|
+
/** Prime a known recovery route without enumerating unrelated historical Sessions. */
|
|
1032
|
+
registerSessionRoute(sessionId, route) {
|
|
1033
|
+
if (!/^meta_[A-Za-z0-9_-]+$/.test(sessionId))
|
|
1034
|
+
return;
|
|
1035
|
+
const parsed = tryParseChannelKey(route.channel);
|
|
1036
|
+
const aid = route.selfAID || parsed?.selfAID;
|
|
1037
|
+
const type = route.channelType || parsed?.type;
|
|
1038
|
+
if (!aid || !type || !route.channelId)
|
|
1039
|
+
return;
|
|
1040
|
+
const chatDir = chatDirPath(this.sessionsDir, type, route.channelId, aid, route.channel);
|
|
1041
|
+
const isThread = isTopicThreadId(route.threadId);
|
|
1042
|
+
this.rememberSessionFile(sessionId, { chatDir, isThread,
|
|
1043
|
+
metaPath: path.join(chatDir, ...(isThread ? ['_threads'] : []), `${sessionId}.jsonl`) });
|
|
1044
|
+
}
|
|
1031
1045
|
rebuildSessionFileIndex() {
|
|
1032
1046
|
this.sessionFileIndex.clear();
|
|
1033
1047
|
this.knownChatDirs = scanChatDirs(this.sessionsDir).map(entry => entry.dirPath);
|
|
@@ -4,10 +4,17 @@ const SYSTEM_PROMPT_MARKERS = [
|
|
|
4
4
|
'<system-reminder>',
|
|
5
5
|
'EvolCore Context Kit documents are shown below.',
|
|
6
6
|
];
|
|
7
|
-
// EvolCore
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
const MESSAGE_ROUTE_PREFIX_RE = /^‹[
|
|
7
|
+
// EvolCore 消息渲染器给每条入站消息加的信封前缀(kits/templates/message-fragments/)。
|
|
8
|
+
// 形态:`‹YYYY-MM-DD HH:mm:ss 偏移 … ›`(完整信封)或 `‹提醒:跨话题委托 … ›`(委托提醒)。
|
|
9
|
+
// `[^›]*` 保证只吞到第一个 `›`,真人不可能手打这种全角前缀。
|
|
10
|
+
const MESSAGE_ROUTE_PREFIX_RE = /^‹(?:\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}|提醒:)[^\n›]*›\s*/;
|
|
11
|
+
// 兼容已发布版本的历史私聊/群聊路由信封。
|
|
12
|
+
const LEGACY_MESSAGE_ROUTE_PREFIX_RE = /^‹[^›]*·\s*from:[^›]*→[^›]*self:[^›]*›\s*/;
|
|
13
|
+
// 群聊批次头:`[2026-11-09 21:04 · 群聊] 群:… · self:… · chat:…`。
|
|
14
|
+
// 批次消息第一行是它(而不是 `‹…›`),只认信封前缀会漏判。
|
|
15
|
+
const GROUP_BATCH_HEADER_RE = /^\[[^\]\n]*·\s*群聊\][^\n]*(?:\n|$)/;
|
|
16
|
+
// 批次逐行信封:`‹21:04:29 · from:… · mid:…›`
|
|
17
|
+
const BATCH_ITEM_PREFIX_RE = /^‹\d{2}:\d{2}:\d{2}[^\n›]*›\s*/;
|
|
11
18
|
/**
|
|
12
19
|
* 判断文本是否以 EvolCore 路由前缀开头,即该会话是 EvolCore 自身驱动 base agent 产生的
|
|
13
20
|
* (不是用户在终端直接发起的 CLI 会话)。用于 `/s cli` 列表把"自己的会话"排除在导入候选之外,
|
|
@@ -16,7 +23,9 @@ const MESSAGE_ROUTE_PREFIX_RE = /^‹[^›]*·\s*from:[^›]*→[^›]*self:[^
|
|
|
16
23
|
export function isEvolcoreRoutedMessage(text) {
|
|
17
24
|
if (typeof text !== 'string')
|
|
18
25
|
return false;
|
|
19
|
-
|
|
26
|
+
const trimmed = text.trimStart();
|
|
27
|
+
return MESSAGE_ROUTE_PREFIX_RE.test(trimmed) || LEGACY_MESSAGE_ROUTE_PREFIX_RE.test(trimmed)
|
|
28
|
+
|| GROUP_BATCH_HEADER_RE.test(trimmed);
|
|
20
29
|
}
|
|
21
30
|
const SHARED_SYNTHETIC_CLI_PROMPT_PREFIXES = [
|
|
22
31
|
'Use Bash exactly once to run:',
|
|
@@ -158,7 +167,18 @@ export function sanitizeSessionTitle(title) {
|
|
|
158
167
|
cleanTitle = cleanTitle.slice(0, markerIndex);
|
|
159
168
|
}
|
|
160
169
|
}
|
|
161
|
-
cleanTitle = cleanTitle.trim()
|
|
170
|
+
cleanTitle = cleanTitle.trim()
|
|
171
|
+
.replace(GROUP_BATCH_HEADER_RE, '')
|
|
172
|
+
.replace(MESSAGE_ROUTE_PREFIX_RE, '')
|
|
173
|
+
.replace(LEGACY_MESSAGE_ROUTE_PREFIX_RE, '');
|
|
174
|
+
// 群聊批次逐行信封:`‹HH:mm:ss · from:…›`;连续多条时逐行剥掉。
|
|
175
|
+
for (let i = 0; i < 20; i++) {
|
|
176
|
+
const next = cleanTitle.trimStart().replace(BATCH_ITEM_PREFIX_RE, '');
|
|
177
|
+
if (next === cleanTitle)
|
|
178
|
+
break;
|
|
179
|
+
cleanTitle = next;
|
|
180
|
+
}
|
|
181
|
+
cleanTitle = cleanTitle.replace(/\s+/g, ' ').trim();
|
|
162
182
|
if (!cleanTitle)
|
|
163
183
|
return undefined;
|
|
164
184
|
if (/^\.+$/.test(cleanTitle))
|
|
@@ -67,12 +67,11 @@ function generateOneIndex(indexDir, filename, skills, label, skillRoot) {
|
|
|
67
67
|
* 直接按目录读,不走 discoverSkillDirectories——后者按父目录扫描再按 name 匹配,
|
|
68
68
|
* 同名技能(本机覆盖内置)会读到另一份的 description。
|
|
69
69
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
70
|
+
* 内置技能是随包发布的内容:安装模式下按当前包版本校验,升级自动切换基线;
|
|
71
|
+
* 同版本带外改动会恢复,恢复不了则返回空描述,与 ECK 文档同一套策略。开发模式下不校验,
|
|
72
72
|
* agent 随手改技能可以立刻生效。
|
|
73
73
|
*
|
|
74
|
-
*
|
|
75
|
-
* 那条路径不经过本函数,目前不受台账保护(等单独的 SKILL.md 加载工具接手)。
|
|
74
|
+
* 技能正文的 ec skill load 与 /skill load 也走相同的版本基线校验。
|
|
76
75
|
*/
|
|
77
76
|
export function readSkillDescription(skillDir) {
|
|
78
77
|
const file = path.join(skillDir, 'SKILL.md');
|