evolcore 0.0.43-test.2 → 0.0.43-test.4
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 +44 -1
- package/bin/ecmsg.js +229 -0
- package/bin/install-codex-managed-hooks.mjs +130 -8
- package/dist/ability/application-service.js +37 -0
- package/dist/ability/resources.js +28 -0
- package/dist/ability/runtime.js +6 -1
- package/dist/agents/claude-runner.js +7 -5
- package/dist/agents/codex/app-server-client.js +0 -12
- package/dist/agents/codex-runner.js +0 -37
- package/dist/agents/ecagent-runner.js +138 -36
- package/dist/aun/aid/agentmd.js +52 -13
- package/dist/aun/menu/client.js +8 -7
- package/dist/aun/menu/index.js +1 -1
- package/dist/aun/menu/transport.js +8 -5
- package/dist/aun/msg/p2p.js +4 -2
- package/dist/aun/service-proxy.js +3 -0
- package/dist/channels/aun.js +105 -53
- package/dist/channels/daemon.js +14 -2
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +31 -11
- package/dist/cli/agent.js +9 -3
- package/dist/cli/aun-commands.js +19 -21
- package/dist/cli/daemon-commands.js +30 -18
- package/dist/cli/directory.js +98 -56
- package/dist/cli/getmeta-command.js +2 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/init.js +13 -5
- package/dist/cli/peer.js +2 -1
- package/dist/cli/task-context.js +3 -1
- package/dist/cli/trigger-command.js +20 -14
- package/dist/config/access-policy.js +0 -1
- package/dist/config/boot-log.js +12 -2
- package/dist/config/builtin-role-templates.js +2 -2
- package/dist/config/builtin-roles.js +2 -1
- package/dist/config/config-field-policy.js +7 -0
- package/dist/config/config-manager.js +30 -10
- package/dist/config/peer-role-resolver.js +23 -1
- package/dist/config/role-schema.js +25 -1
- package/dist/config/role-service.js +9 -4
- package/dist/config/role-store.js +30 -8
- package/dist/config/schema-migration.js +121 -0
- package/dist/core/agent-application-service.js +11 -0
- package/dist/core/agent-ipc-registration.js +2 -0
- package/dist/core/agent-runtime.js +41 -9
- package/dist/core/auth/auth-gateway.js +14 -4
- package/dist/core/auth/operation-authorizer.js +19 -1
- package/dist/core/auth/operation-catalog.js +12 -2
- package/dist/core/baseagent-loader.js +11 -3
- package/dist/core/bootstrap-service.js +8 -0
- package/dist/core/channel-loader.js +61 -23
- package/dist/core/channel-runtime.js +5 -0
- package/dist/core/command/agent-control.js +5 -2
- package/dist/core/command/agentmd-menu-request.js +50 -0
- package/dist/core/command/agentmd-menu.js +156 -0
- package/dist/core/command/chatmode-config.js +46 -0
- package/dist/core/command/command-handler.js +44 -17
- package/dist/core/command/daemon-diagnostics.js +2 -1
- package/dist/core/command/menu-catalog.js +14 -1
- package/dist/core/command/menu-handler.js +74 -24
- package/dist/core/command/menu-protocol.js +8 -0
- package/dist/core/command/role-menu.js +23 -9
- package/dist/core/command/slash-handler.js +52 -47
- package/dist/core/daemon-lifecycle.js +43 -17
- package/dist/core/event-catalog.js +19 -0
- package/dist/core/evolagent-registry.js +3 -0
- package/dist/core/evolagent.js +5 -4
- package/dist/core/ipc-registration.js +6 -0
- package/dist/core/lifecycle-notice.js +185 -0
- package/dist/core/message/aun-ipc-sender.js +30 -24
- package/dist/core/message/contact-admission.js +1 -19
- package/dist/core/message/im-renderer.js +81 -40
- package/dist/core/message/message-admission.js +21 -62
- package/dist/core/message/message-bridge.js +18 -5
- package/dist/core/message/message-utils.js +9 -0
- package/dist/core/message/peer-mode.js +16 -8
- package/dist/core/message/response-engine.js +67 -47
- package/dist/core/model/model-capabilities.js +37 -0
- package/dist/core/model/model-catalog.js +6 -2
- package/dist/core/ownership/owner-resolver.js +74 -36
- package/dist/core/permission/ec-command-parser.js +62 -13
- package/dist/core/plugin-lifecycle.js +6 -2
- package/dist/core/relation/pa-team.js +132 -0
- package/dist/core/role/runtime-policy.js +4 -3
- package/dist/core/thread/thread-service.js +6 -4
- package/dist/directory/owner-directory-admission.js +0 -3
- package/dist/directory/owner-directory-cache.js +201 -17
- package/dist/directory/owner-directory-markdown.js +44 -21
- package/dist/directory/owner-directory-policy.js +1 -1
- package/dist/directory/owner-directory-query-operation.js +218 -98
- package/dist/directory/owner-directory-request-operation.js +76 -0
- package/dist/directory/owner-directory-scope.js +35 -4
- package/dist/directory/owner-directory-search.js +76 -23
- package/dist/directory/owner-directory-store.js +5 -38
- package/dist/directory/owner-directory-text.js +60 -0
- package/dist/eck/kit-renderer.js +6 -3
- package/dist/eck/message-renderer.js +2 -5
- package/dist/ecweb/message-context-service.js +4 -0
- package/dist/ecweb/runtime/lifecycle.js +29 -5
- package/dist/ecweb/runtime/supervisor.js +83 -27
- package/dist/index.js +209 -38
- package/dist/paths.js +4 -2
- package/dist/product.js +1 -0
- package/dist/proxy/service-supervisor.js +377 -141
- package/dist/response-system/engines/v1/index.js +2 -4
- package/dist/response-system/modes/single-session/index.js +1 -1
- package/dist/trigger/audit.js +3 -2
- package/dist/trigger/authorization.js +2 -3
- package/dist/trigger/history.js +4 -3
- package/dist/trigger/ipc-service.js +24 -19
- package/dist/trigger/manager.js +3 -5
- package/dist/trigger/parser.js +4 -21
- package/dist/trigger/patch.js +3 -15
- package/dist/trigger/scheduler.js +53 -13
- package/dist/trigger/validation.js +0 -13
- package/dist/utils/error-utils.js +15 -5
- package/dist/utils/macos-autostart.js +31 -0
- package/dist/utils/model-prices.jsonl +15 -8
- package/dist/utils/process-introspect.js +21 -1
- package/dist/utils/startup-trace.js +7 -1
- package/dist/utils/windows-autostart.js +1 -0
- package/ecagent/README.md +18 -0
- package/ecagent/dist/harness/agent-harness.d.ts +2 -0
- package/ecagent/dist/harness/agent-harness.js +24 -8
- package/ecagent/dist/harness/compaction/branch-summarization.js +1 -1
- package/ecagent/dist/harness/compaction/compaction.js +7 -4
- package/ecagent/dist/harness/types.d.ts +1 -0
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +5 -2
- package/kits/docs/evolcore/directory.md +125 -35
- package/kits/docs/evolcore/ecweb-lifecycle.md +26 -0
- package/kits/docs/evolcore/file-navigation.md +279 -0
- package/kits/docs/evolcore/menu-protocol.md +1 -0
- package/kits/docs/evolcore/model.md +5 -3
- package/kits/docs/evolcore/msg.md +1 -0
- package/kits/docs/evolcore/peer.md +2 -1
- package/kits/docs/evolcore/response.md +4 -2
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/thread-chain.md +1 -1
- package/kits/docs/evolcore/tool-authorization.md +4 -1
- package/kits/docs/evolcore/trigger.md +10 -7
- package/kits/docs/identity/ROLE_DETAIL.md +2 -0
- package/kits/eck_manifest.json +6 -23
- package/kits/eck_manifest.memory.json +26 -1
- package/kits/rules/01-overview.md +42 -44
- package/kits/rules/02-navigation.md +44 -53
- package/kits/rules/03-identity.md +21 -25
- package/kits/rules/04-relation.md +23 -33
- package/kits/rules/05-venue.md +24 -25
- package/kits/schemas/_meta.json +10 -10
- package/kits/schemas/agent-config.schema.19.json +10 -6
- package/kits/schemas/relation-config.schema.12.json +2 -2
- package/kits/schemas/role-config.schema.2.json +5 -5
- package/kits/schemas/role-registry.schema.1.json +3 -2
- package/kits/skills/ec-service-proxy/SKILL.md +10 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/templates/soul/00-GUIDE.md +20 -42
- package/kits/templates/system-fragments/channel.md +2 -2
- package/kits/templates/system-fragments/commands.md +1 -1
- package/kits/templates/system-fragments/directory-contacts.md +1 -1
- package/kits/templates/system-fragments/identity.md +0 -1
- package/kits/templates/system-fragments/personal-assistant.md +2 -17
- package/kits/templates/system-fragments/reply.md +7 -0
- package/kits/templates/system-fragments/session.md +6 -2
- package/package.json +18 -13
- package/dist/eck/paactive-context.js +0 -45
- package/dist/response-system/engines/v1/paactive-flow.js +0 -18
- package/kits/eck_manifest.paactive.json +0 -528
- package/kits/eck_message_manifest.paactive.json +0 -233
- package/kits/templates/message-fragments/paactive/item.md +0 -3
- package/kits/templates/system-fragments/paactive/channel.md +0 -25
- package/kits/templates/system-fragments/paactive/reply.md +0 -25
- package/kits/templates/system-fragments/paactive/session.md +0 -32
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* 中文没有词边界,一律按子串匹配,不做分词。查询串按空白切成 token,
|
|
9
9
|
* **所有 token 都要命中**(AND),总分是每个 token 最佳命中字段的分数之和。
|
|
10
10
|
*/
|
|
11
|
-
import { isInternalEntry, ownerRefAid } from './owner-directory-scope.js';
|
|
11
|
+
import { isInternalEntry, isOwnershipVerified, ownerRefAid, } from './owner-directory-scope.js';
|
|
12
|
+
import { normalizeDirectoryText, stripTrailingParenthetical, } from './owner-directory-text.js';
|
|
12
13
|
const DEFAULT_LIMIT = 5;
|
|
13
14
|
const MAX_LIMIT = 50;
|
|
14
15
|
/** 各命中方式的权重。分数用于排序,不承诺对外稳定,调用方只看相对顺序。 */
|
|
@@ -94,25 +95,31 @@ export function searchDirectory(snapshot, ownerAid, remarks, options) {
|
|
|
94
95
|
return hits.slice(0, limit);
|
|
95
96
|
}
|
|
96
97
|
function scoreToken(token, entry, remark, localNote) {
|
|
97
|
-
const aid = entry.aid
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
const
|
|
98
|
+
const aid = normalizeDirectoryText(entry.aid);
|
|
99
|
+
const rawName = normalizeDirectoryText(entry.name);
|
|
100
|
+
// 名字比较忽略结尾括号称呼:`李文江(研发)` 与 `李文江` 是同一个人。
|
|
101
|
+
const name = normalizeDirectoryText(stripTrailingParenthetical(rawName));
|
|
102
|
+
const exttype = normalizeDirectoryText(entry.exttype ?? '');
|
|
103
|
+
const type = normalizeDirectoryText(entry.type ?? '');
|
|
104
|
+
const baseagent = normalizeDirectoryText(entry.baseagent ?? '');
|
|
102
105
|
if (aid === token)
|
|
103
106
|
return { score: WEIGHT.exactAid, field: 'aid' };
|
|
104
|
-
if (name === token)
|
|
107
|
+
if (name === token || rawName === token)
|
|
105
108
|
return { score: WEIGHT.exactName, field: 'name' };
|
|
106
109
|
if (aid.startsWith(token) || name.startsWith(token))
|
|
107
110
|
return { score: WEIGHT.prefix, field: 'prefix' };
|
|
108
111
|
// 任何叫法精确命中都算:名录名、Owner 写的备注名、自己记的每一个称呼。
|
|
109
|
-
const localAliases = remark?.aliases ?? (remark?.remark ? [remark.remark] : [])
|
|
110
|
-
|
|
112
|
+
const localAliases = (remark?.aliases ?? (remark?.remark ? [remark.remark] : []))
|
|
113
|
+
.map(alias => normalizeDirectoryText(alias));
|
|
114
|
+
if (localAliases.some(alias => alias === token || normalizeDirectoryText(stripTrailingParenthetical(alias)) === token)) {
|
|
111
115
|
return { score: WEIGHT.exactRemark, field: 'remark' };
|
|
112
116
|
}
|
|
113
|
-
|
|
117
|
+
const ownerRemark = normalizeDirectoryText(entry.remark ?? '');
|
|
118
|
+
if (ownerRemark && (ownerRemark === token || normalizeDirectoryText(stripTrailingParenthetical(ownerRemark)) === token)) {
|
|
114
119
|
return { score: WEIGHT.exactRemark, field: 'ownerRemark' };
|
|
115
|
-
|
|
120
|
+
}
|
|
121
|
+
// AID 的域段先于普通包含判定:`list --filter agentid.cn` 是"列出这个域",
|
|
122
|
+
// 不是"名字里有这段字"。
|
|
116
123
|
const domain = aid.slice(aid.indexOf('.') + 1);
|
|
117
124
|
if (domain.includes(token))
|
|
118
125
|
return { score: WEIGHT.domainContains, field: 'domain' };
|
|
@@ -120,23 +127,63 @@ function scoreToken(token, entry, remark, localNote) {
|
|
|
120
127
|
return { score: WEIGHT.contains, field: 'name' };
|
|
121
128
|
if (exttype === token || baseagent === token)
|
|
122
129
|
return { score: WEIGHT.exactExttype, field: 'exttype' };
|
|
123
|
-
if (entry.description && entry.description
|
|
130
|
+
if (entry.description && normalizeDirectoryText(entry.description).includes(token)) {
|
|
124
131
|
return { score: WEIGHT.descriptionContains, field: 'description' };
|
|
125
132
|
}
|
|
126
133
|
// 本地备注正文与远端描述并列参与:它是 PA 自己记的"什么事该找他",是找人的主要线索之一。
|
|
127
|
-
if (localNote && localNote
|
|
134
|
+
if (localNote && normalizeDirectoryText(localNote).includes(token)) {
|
|
128
135
|
return { score: WEIGHT.descriptionContains, field: 'localNote' };
|
|
129
136
|
}
|
|
130
|
-
if (localAliases.some(alias => alias.
|
|
137
|
+
if (localAliases.some(alias => alias.includes(token))) {
|
|
131
138
|
return { score: WEIGHT.descriptionContains, field: 'remark' };
|
|
132
139
|
}
|
|
133
|
-
if (
|
|
140
|
+
if (ownerRemark.includes(token)) {
|
|
134
141
|
return { score: WEIGHT.descriptionContains, field: 'ownerRemark' };
|
|
135
142
|
}
|
|
136
143
|
if (type === token)
|
|
137
144
|
return { score: WEIGHT.exactType, field: 'type' };
|
|
138
145
|
return { score: 0, field: '' };
|
|
139
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* `list` 的过滤:组间 AND、组内 OR。
|
|
149
|
+
*
|
|
150
|
+
* 与 `ec skill list --filter` 同一套语义(逗号分隔为 OR,多个 `--filter` 之间
|
|
151
|
+
* 为 AND),区别只是匹配字段:技能匹配名称+描述,名录还匹配 AID、备注、exttype。
|
|
152
|
+
* 组为空表示不过滤。
|
|
153
|
+
*/
|
|
154
|
+
export function filterDirectory(snapshot, ownerAid, remarks, options = {}) {
|
|
155
|
+
if (!snapshot)
|
|
156
|
+
return [];
|
|
157
|
+
const ownerRef = ownerRefAid(snapshot, ownerAid);
|
|
158
|
+
const groups = (options.filters ?? [])
|
|
159
|
+
.map(group => group.map(keyword => normalizeDirectoryText(keyword)).filter(Boolean))
|
|
160
|
+
.filter(group => group.length > 0);
|
|
161
|
+
const scope = options.scope ?? 'all';
|
|
162
|
+
const typeFilter = normalizeDirectoryText(options.type ?? '');
|
|
163
|
+
const ownerFilter = normalizeDirectoryText(options.ownerAid ?? '');
|
|
164
|
+
return snapshot.entries
|
|
165
|
+
.filter(entry => {
|
|
166
|
+
const internal = isInternalEntry(entry, ownerRef);
|
|
167
|
+
if (scope === 'internal' && !internal)
|
|
168
|
+
return false;
|
|
169
|
+
if (scope === 'external' && internal)
|
|
170
|
+
return false;
|
|
171
|
+
if (typeFilter && normalizeDirectoryText(entry.type ?? '') !== typeFilter)
|
|
172
|
+
return false;
|
|
173
|
+
if (ownerFilter) {
|
|
174
|
+
const entryOwner = normalizeDirectoryText(entry.ownerAid ?? '');
|
|
175
|
+
if (ownerFilter === 'unbound' ? entryOwner !== '' : entryOwner !== ownerFilter)
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
if (groups.length === 0)
|
|
179
|
+
return true;
|
|
180
|
+
const remark = remarks?.get(entry.aid);
|
|
181
|
+
return groups.every(group => group.some(keyword => scoreToken(keyword, entry, remark, remark?.body).score > 0));
|
|
182
|
+
})
|
|
183
|
+
.sort((a, b) => Number(isInternalEntry(b, ownerRef)) - Number(isInternalEntry(a, ownerRef))
|
|
184
|
+
|| normalizeDirectoryText(a.name).localeCompare(normalizeDirectoryText(b.name))
|
|
185
|
+
|| a.aid.localeCompare(b.aid));
|
|
186
|
+
}
|
|
140
187
|
/**
|
|
141
188
|
* 单个条目的完整记录,用于 `show`。描述与备注不截断。
|
|
142
189
|
*
|
|
@@ -144,7 +191,12 @@ function scoreToken(token, entry, remark, localNote) {
|
|
|
144
191
|
* 受不同开关约束,白名单与黑名单又各自优先,算一次再套给所有条目必然错。
|
|
145
192
|
* 传布尔时按原样使用(老调用方与单测)。
|
|
146
193
|
*/
|
|
147
|
-
export function describeEntry(entry, ownerRef, remark, contactable
|
|
194
|
+
export function describeEntry(entry, ownerRef, remark, contactable,
|
|
195
|
+
/**
|
|
196
|
+
* `includeLocalRemark` 只在详情(`info`)里打开。`list` 是检索结果,
|
|
197
|
+
* 本地备注正文可能很长,按口径不展示——要看正文用 `ec directory info <AID>`。
|
|
198
|
+
*/
|
|
199
|
+
options = {}) {
|
|
148
200
|
const internal = isInternalEntry(entry, ownerRef);
|
|
149
201
|
const contactableValue = typeof contactable === 'function' ? contactable(entry) : contactable;
|
|
150
202
|
return {
|
|
@@ -153,13 +205,18 @@ export function describeEntry(entry, ownerRef, remark, contactable) {
|
|
|
153
205
|
type: entry.type ?? null,
|
|
154
206
|
exttype: entry.exttype ?? null,
|
|
155
207
|
baseagent: entry.baseagent ?? null,
|
|
208
|
+
// Owner 绑定关系与核验状态要单独给出:list 的用途就是让调用方看清
|
|
209
|
+
// "这条到底归谁、这个归属是不是经过双边确认的"。
|
|
210
|
+
ownerAid: entry.ownerAid ?? null,
|
|
211
|
+
ownershipStatus: entry.ownership_status ?? null,
|
|
212
|
+
ownershipVerified: isOwnershipVerified(entry),
|
|
213
|
+
ownershipCheckedAt: entry.ownership_checked_at_ms ?? null,
|
|
156
214
|
// 远端字段与本地备注并列返回,不互相覆盖:调用方要判断"对方本来是什么样"
|
|
157
215
|
// 和"我记了什么"是两件事。要在渲染里二选一由调用方决定。
|
|
158
216
|
remark: remark?.remark ?? entry.remark ?? null,
|
|
159
217
|
aliases: remark?.aliases ?? null,
|
|
160
218
|
description: entry.description ?? null,
|
|
161
|
-
localRemark: remark?.body ?? null,
|
|
162
|
-
ownershipStatus: entry.ownership_status ?? null,
|
|
219
|
+
...(options.includeLocalRemark !== false ? { localRemark: remark?.body ?? null } : {}),
|
|
163
220
|
agentMdSignedAt: entry.agent_md_signed_at ?? null,
|
|
164
221
|
internal,
|
|
165
222
|
contactable: contactableValue,
|
|
@@ -167,11 +224,7 @@ export function describeEntry(entry, ownerRef, remark, contactable) {
|
|
|
167
224
|
};
|
|
168
225
|
}
|
|
169
226
|
function tokenize(query) {
|
|
170
|
-
return
|
|
171
|
-
.toLowerCase()
|
|
172
|
-
.split(/\s+/)
|
|
173
|
-
.map(token => token.trim())
|
|
174
|
-
.filter(Boolean);
|
|
227
|
+
return normalizeDirectoryText(query).split(/\s+/).filter(Boolean);
|
|
175
228
|
}
|
|
176
229
|
function clampLimit(limit) {
|
|
177
230
|
if (!Number.isSafeInteger(limit) || limit <= 0)
|
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { atomicWriteJson } from '../utils/atomic-write.js';
|
|
4
4
|
import { logger } from '../utils/logger.js';
|
|
5
|
-
import {
|
|
5
|
+
import { changedEntryFields } from './owner-directory-cache.js';
|
|
6
6
|
import { OWNER_DIRECTORY_SCOPES } from './owner-directory-scope.js';
|
|
7
7
|
// ── content_digest helpers ────────────────────────────────────────────────────
|
|
8
8
|
const CONTENT_DIGEST_RE = /^[a-f0-9]{64}$/;
|
|
@@ -112,7 +112,7 @@ export function diffSnapshots(scope, next, prev, nextMeta, prevMeta) {
|
|
|
112
112
|
else {
|
|
113
113
|
// 运行期自检:只有真正存在差异字段才记 `entry_changed`。
|
|
114
114
|
// 上游若换一种序列化(缺失 / "" / null 互换),这里不会再刷出噪音行。
|
|
115
|
-
const fields =
|
|
115
|
+
const fields = changedEntryFields(old, entry);
|
|
116
116
|
if (fields.length === 0)
|
|
117
117
|
continue;
|
|
118
118
|
lines.push({ at: now, scope, type: 'entry_changed', aid, contentDigest, prevContentDigest: prevDigest, from: old, to: entry, fields });
|
|
@@ -148,42 +148,6 @@ export function diffSnapshots(scope, next, prev, nextMeta, prevMeta) {
|
|
|
148
148
|
}
|
|
149
149
|
return lines;
|
|
150
150
|
}
|
|
151
|
-
/**
|
|
152
|
-
* 条目内容的可变字段。这是"什么算变了"的唯一定义:`entry_changed` 的判定、
|
|
153
|
-
* 变更行里的 `fields` 都从这里出,不另写一份。
|
|
154
|
-
*
|
|
155
|
-
* `ownership_checked_at_ms` 不在其中——它是探测时间而不是内容。
|
|
156
|
-
* `ownerAid` 也不在:上游对它的有无本身在抖,纳进来只会制造噪音;内外归属变化
|
|
157
|
-
* 会体现在 `ownership_status` 上。
|
|
158
|
-
*/
|
|
159
|
-
const CONTENT_FIELDS = [
|
|
160
|
-
'name', 'remark', 'description', 'type', 'exttype', 'baseagent', 'ownership_status',
|
|
161
|
-
];
|
|
162
|
-
/**
|
|
163
|
-
* 条目内容相对旧值的差异字段。空数组 = 没有实际变化。
|
|
164
|
-
*
|
|
165
|
-
* 缺失与空串视为等价:normalizeEntry 已经把恒存在的字符串字段收敛成恒 `''`,
|
|
166
|
-
* 但本地快照可能来自更早的版本(字段缺失),这里再兜一层。这同时是运行期自检——
|
|
167
|
-
* 无论上游把可选字段写成 `""`、`null` 还是不写,只要业务值相同就不会进日志。
|
|
168
|
-
*/
|
|
169
|
-
function changedFields(a, b) {
|
|
170
|
-
const changed = [];
|
|
171
|
-
for (const key of CONTENT_FIELDS) {
|
|
172
|
-
if (text(a[key]) !== text(b[key]))
|
|
173
|
-
changed.push(key);
|
|
174
|
-
}
|
|
175
|
-
if (a.agent_md_signed_at !== b.agent_md_signed_at)
|
|
176
|
-
changed.push('agent_md_signed_at');
|
|
177
|
-
// 未知字段(`extra`)单独比:它是 key→值 的映射,按规范化指纹比较,
|
|
178
|
-
// 字段顺序不同不算变化。远端新增一个字段却没有任何 `CONTENT_FIELDS` 变化时,
|
|
179
|
-
// 变更日志里只会有这一条线索,不能漏。
|
|
180
|
-
if (extraFingerprint(a.extra) !== extraFingerprint(b.extra))
|
|
181
|
-
changed.push('extra');
|
|
182
|
-
return changed;
|
|
183
|
-
}
|
|
184
|
-
function text(value) {
|
|
185
|
-
return value ?? '';
|
|
186
|
-
}
|
|
187
151
|
/**
|
|
188
152
|
* 身份块(`owner` / `personal_assistant`)是否变化。
|
|
189
153
|
*
|
|
@@ -191,6 +155,9 @@ function text(value) {
|
|
|
191
155
|
* 否则"换了 owner 或 personal assistant"这件事在变更日志里完全不可见。
|
|
192
156
|
* 两侧都缺失时不算变更(老快照没有身份块是常态,不是事件)。
|
|
193
157
|
*/
|
|
158
|
+
function text(value) {
|
|
159
|
+
return value ?? '';
|
|
160
|
+
}
|
|
194
161
|
function identityChanged(a, b) {
|
|
195
162
|
if (!a && !b)
|
|
196
163
|
return false;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 名录里的名字/关键词归一。
|
|
3
|
+
*
|
|
4
|
+
* `list`、`info`(旧 `find` / `show`)必须用同一套比较规则,否则同一个名字在
|
|
5
|
+
* 不同命令里的命中结果会不一致:
|
|
6
|
+
*
|
|
7
|
+
* - NFKC:全角字母/数字/空格 → 半角;
|
|
8
|
+
* - 去掉零宽字符:从聊天窗口复制名字时经常带进来;
|
|
9
|
+
* - 空白折叠为单个空格;
|
|
10
|
+
* - 大小写不敏感(AID 和英文名都不该区分大小写)。
|
|
11
|
+
*/
|
|
12
|
+
/** 归一后的比较基串。 */
|
|
13
|
+
export function normalizeDirectoryText(value) {
|
|
14
|
+
return String(value ?? '')
|
|
15
|
+
.normalize('NFKC')
|
|
16
|
+
.replace(/[\u200B-\u200D\uFEFF]/g, '')
|
|
17
|
+
.replace(/\s+/g, ' ')
|
|
18
|
+
.trim()
|
|
19
|
+
.toLowerCase();
|
|
20
|
+
}
|
|
21
|
+
/** 去掉名字结尾括号里的称呼:`李文江(研发)` → `李文江`。 */
|
|
22
|
+
export function stripTrailingParenthetical(value) {
|
|
23
|
+
return value.replace(/\s*[((][^()()]*[))]\s*$/, '').trim();
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 两个名字是否算同一个人:
|
|
27
|
+
* - 归一后完全相等;
|
|
28
|
+
* - 忽略结尾括号里的称呼;
|
|
29
|
+
* - 忽略名字内部的空格。
|
|
30
|
+
*/
|
|
31
|
+
export function sameDirectoryName(candidate, wanted) {
|
|
32
|
+
const right = normalizeDirectoryText(wanted);
|
|
33
|
+
if (!right)
|
|
34
|
+
return false;
|
|
35
|
+
const left = normalizeDirectoryText(candidate);
|
|
36
|
+
if (left === right)
|
|
37
|
+
return true;
|
|
38
|
+
const leftBase = normalizeDirectoryText(stripTrailingParenthetical(left));
|
|
39
|
+
const rightBase = normalizeDirectoryText(stripTrailingParenthetical(right));
|
|
40
|
+
return leftBase === rightBase
|
|
41
|
+
|| leftBase.replace(/ /g, '') === rightBase.replace(/ /g, '');
|
|
42
|
+
}
|
|
43
|
+
/** 编辑距离,用于“可能打错字/叫法接近”的提示。 */
|
|
44
|
+
export function editDistance(left, right) {
|
|
45
|
+
if (left === right)
|
|
46
|
+
return 0;
|
|
47
|
+
if (!left.length)
|
|
48
|
+
return right.length;
|
|
49
|
+
if (!right.length)
|
|
50
|
+
return left.length;
|
|
51
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
52
|
+
for (let row = 1; row <= left.length; row++) {
|
|
53
|
+
const current = [row];
|
|
54
|
+
for (let column = 1; column <= right.length; column++) {
|
|
55
|
+
current[column] = Math.min(previous[column] + 1, current[column - 1] + 1, previous[column - 1] + (left[row - 1] === right[column - 1] ? 0 : 1));
|
|
56
|
+
}
|
|
57
|
+
previous = current;
|
|
58
|
+
}
|
|
59
|
+
return previous[right.length];
|
|
60
|
+
}
|
package/dist/eck/kit-renderer.js
CHANGED
|
@@ -81,9 +81,11 @@ export function renderKitSections(ctx, manifestFile = DEFAULT_MANIFEST_FILE) {
|
|
|
81
81
|
// by agent configuration normalization while leaving explicit invalid
|
|
82
82
|
// values untouched for fail-closed manifest conditions.
|
|
83
83
|
const resolvedLifecycle = resolveAgentLifecycle({ lifecycle: ctx.vars.lifecycle });
|
|
84
|
-
const vars =
|
|
85
|
-
|
|
86
|
-
: {
|
|
84
|
+
const vars = {
|
|
85
|
+
...ctx.vars,
|
|
86
|
+
...(resolvedLifecycle === null ? {} : { lifecycle: resolvedLifecycle }),
|
|
87
|
+
activePush: ctx.vars.chatMode === 'proactive' || ctx.vars.chatMode === 'paactive',
|
|
88
|
+
};
|
|
87
89
|
const renderCtx = { ...ctx, vars };
|
|
88
90
|
const pathMappings = buildPathMappings(vars);
|
|
89
91
|
const sessionCache = getSessionCache(ctx.sessionId);
|
|
@@ -279,6 +281,7 @@ const PARAM_DESCRIPTIONS = {
|
|
|
279
281
|
osInfo: '操作系统及版本(如 Windows 11 Pro (win32 10.0.26200))',
|
|
280
282
|
threadId: '话题 ID(多话题路由时)',
|
|
281
283
|
chatMode: '会话模式(interactive=同步交互 / proactive=主动推送 / paactive=PA activity)',
|
|
284
|
+
activePush: '是否通过托管发送命令发送正式回复(true/false)',
|
|
282
285
|
isTriggerTask: '当前任务是否来源于 Trigger(true/false)',
|
|
283
286
|
proactivePreTool1stMsgChk: 'proactive 前置工具首消息检查(true/false)',
|
|
284
287
|
proactiveToolUseReminder: 'proactive 工具调用提醒(true/false)',
|
|
@@ -11,7 +11,6 @@ import { randomUUID } from 'crypto';
|
|
|
11
11
|
import { isEckSnapshotsEnabled } from '../config-store.js';
|
|
12
12
|
import { eckDebugDir } from '../paths.js';
|
|
13
13
|
import { logger } from '../utils/logger.js';
|
|
14
|
-
import { paactiveMessageManifest } from './paactive-context.js';
|
|
15
14
|
import { loadManifest, evaluateWhen, renderTemplate, loadSectionFiles, defaultModeNames, } from './manifest-engine.js';
|
|
16
15
|
const MESSAGE_MANIFEST_FILE = 'eck_message_manifest.json';
|
|
17
16
|
// ── time formatting (per IANA timezone) ──
|
|
@@ -36,8 +35,7 @@ export function formatLocalTime(epochMs, timeZone) {
|
|
|
36
35
|
}
|
|
37
36
|
// ── single item render ──
|
|
38
37
|
function renderOneItem(item, sessionVars, sessionCache, contentSentinel) {
|
|
39
|
-
const sections = loadManifest(
|
|
40
|
-
? paactiveMessageManifest(sessionVars) : MESSAGE_MANIFEST_FILE);
|
|
38
|
+
const sections = loadManifest(MESSAGE_MANIFEST_FILE);
|
|
41
39
|
// 各 modeType 当前激活的 modeName:agent config.render(经 sessionVars.renderModes 透传)
|
|
42
40
|
// 覆盖 manifest 里标 isDefault 的缺省。详见 docs/observer-insert-design.md 第二部分。
|
|
43
41
|
const defaults = defaultModeNames(sections);
|
|
@@ -277,8 +275,7 @@ export function renderMessageBody(items, sessionVars, sessionId) {
|
|
|
277
275
|
* 逐条结果 renderedParts 已是最终文本,作为字面量填入 wrapper 的 {{@loop}},不二次解析。
|
|
278
276
|
*/
|
|
279
277
|
function wrapBatch(renderedParts, sessionVars, sessionCache) {
|
|
280
|
-
const sections = loadManifest(
|
|
281
|
-
? paactiveMessageManifest(sessionVars) : MESSAGE_MANIFEST_FILE);
|
|
278
|
+
const sections = loadManifest(MESSAGE_MANIFEST_FILE);
|
|
282
279
|
const loopSection = sections.find(s => s.loop && s.enabled !== false && evaluateWhen(s.when, sessionVars));
|
|
283
280
|
if (!loopSection || !loopSection.loop || !loopSection.file)
|
|
284
281
|
return null;
|
|
@@ -6,6 +6,7 @@ import { resolveAgentLifecycle } from '../config/lifecycle.js';
|
|
|
6
6
|
import { resolveChatMode } from '../core/message/peer-mode.js';
|
|
7
7
|
import { resolvePermissionMode } from '../core/model/config-scope.js';
|
|
8
8
|
import { formatPeerKey } from '../core/relation/peer-identity.js';
|
|
9
|
+
import { preparePaTeamQualification } from '../core/relation/pa-team.js';
|
|
9
10
|
const REQUEST_FIELDS = new Set([
|
|
10
11
|
'selfAid', 'channelType', 'channelKey', 'chatType', 'actorId',
|
|
11
12
|
'conversationId', 'peerType', 'sessionId', 'displayQueries',
|
|
@@ -84,6 +85,9 @@ export function createEcwebMessageContextProvider(sessionManager, resolveRuntime
|
|
|
84
85
|
throw new MessageContextRequestError('sessionId must be an EvolCore session identifier');
|
|
85
86
|
}
|
|
86
87
|
const peerKey = formatPeerKey(identity.channelType, conversationId);
|
|
88
|
+
if (identity.channelType === 'aun' && chatType === 'private') {
|
|
89
|
+
await preparePaTeamQualification(identity.selfAid, identity.actorId);
|
|
90
|
+
}
|
|
87
91
|
const detail = resolvePeerRoleDetail({ ...identity, chatType, conversationId, peerType });
|
|
88
92
|
const role = detail.effectiveRole || 'none';
|
|
89
93
|
const candidate = sessionId ? await sessionManager.getSessionById(sessionId) : undefined;
|
|
@@ -17,16 +17,40 @@ function sameProcess(identity) {
|
|
|
17
17
|
}
|
|
18
18
|
return startTimeMatches(identity.startedAt, actual);
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Windows 上 taskkill 不带 /F 只会给控制台进程投一个 WM_CLOSE,Node 进程根本不响应,
|
|
22
|
+
* 结果是必然失败再白等满一个超时;POSIX 上 SIGTERM 仍是有效的优雅退出路径,保留。
|
|
23
|
+
*/
|
|
24
|
+
const GRACEFUL_STOP_MS = platform.isWindows ? 0 : 1_000;
|
|
25
|
+
const FORCED_STOP_MS = 2_000;
|
|
26
|
+
export async function stopEcwebProcess(identity, timeoutMs = FORCED_STOP_MS, onTiming) {
|
|
27
|
+
const waitForExit = async (force, budgetMs) => {
|
|
28
|
+
const startMs = Date.now();
|
|
29
|
+
let detail = `pid=${identity.pid}; timeoutMs=${budgetMs}`;
|
|
30
|
+
try {
|
|
31
|
+
const signalSent = platform.killProcessOnly(identity.pid, force);
|
|
32
|
+
const exited = await platform.waitForProcessExit(identity.pid, budgetMs);
|
|
33
|
+
detail += `; signalSent=${signalSent}; exited=${exited}`;
|
|
34
|
+
return exited;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
detail += `; 失败: ${error instanceof Error ? error.message : String(error)}`;
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
try {
|
|
42
|
+
onTiming?.({ phase: force ? 'forceExit' : 'gracefulExit', startMs, endMs: Date.now(), detail });
|
|
43
|
+
}
|
|
44
|
+
catch { }
|
|
45
|
+
}
|
|
46
|
+
};
|
|
21
47
|
if (!sameProcess(identity))
|
|
22
48
|
return;
|
|
23
|
-
|
|
24
|
-
if (await platform.waitForProcessExit(identity.pid, timeoutMs))
|
|
49
|
+
if (GRACEFUL_STOP_MS > 0 && await waitForExit(false, GRACEFUL_STOP_MS))
|
|
25
50
|
return;
|
|
26
51
|
if (!sameProcess(identity))
|
|
27
52
|
return;
|
|
28
|
-
|
|
29
|
-
if (await platform.waitForProcessExit(identity.pid, timeoutMs))
|
|
53
|
+
if (await waitForExit(true, timeoutMs))
|
|
30
54
|
return;
|
|
31
55
|
if (!sameProcess(identity))
|
|
32
56
|
return;
|
|
@@ -137,6 +137,9 @@ export function createEcwebSupervisor(options) {
|
|
|
137
137
|
let childStartedAt = 0;
|
|
138
138
|
let childIdentityStartedAt = null;
|
|
139
139
|
let stopping = false;
|
|
140
|
+
let stopInFlight = null;
|
|
141
|
+
const stopTimingListeners = new Set();
|
|
142
|
+
const completedStopTimings = [];
|
|
140
143
|
let checkInFlight = null;
|
|
141
144
|
let startup = null;
|
|
142
145
|
let restartInFlight = null;
|
|
@@ -148,6 +151,15 @@ export function createEcwebSupervisor(options) {
|
|
|
148
151
|
let hasBeenReady = false;
|
|
149
152
|
let configureQueue = Promise.resolve();
|
|
150
153
|
const logFile = path.join(resolvePaths().logs, 'ecweb-daemon.log');
|
|
154
|
+
const reportStopTiming = (timing) => {
|
|
155
|
+
completedStopTimings.push(timing);
|
|
156
|
+
for (const listener of stopTimingListeners) {
|
|
157
|
+
try {
|
|
158
|
+
listener(timing);
|
|
159
|
+
}
|
|
160
|
+
catch { }
|
|
161
|
+
}
|
|
162
|
+
};
|
|
151
163
|
const setActiveFromEntry = (entry, owned) => {
|
|
152
164
|
active = {
|
|
153
165
|
pid: entry.record.pid,
|
|
@@ -199,7 +211,7 @@ export function createEcwebSupervisor(options) {
|
|
|
199
211
|
catch { }
|
|
200
212
|
logFd = null;
|
|
201
213
|
};
|
|
202
|
-
const killActive = async () => {
|
|
214
|
+
const killActive = async (onTiming) => {
|
|
203
215
|
intentionalStop = true;
|
|
204
216
|
const current = active;
|
|
205
217
|
if (!current) {
|
|
@@ -208,14 +220,14 @@ export function createEcwebSupervisor(options) {
|
|
|
208
220
|
// owns the child and must not leave it behind on shutdown.
|
|
209
221
|
const pendingPid = child?.pid;
|
|
210
222
|
if (pendingPid && platform.isProcessRunning(pendingPid)) {
|
|
211
|
-
await stopEcwebProcess({ pid: pendingPid, startedAt: childIdentityStartedAt });
|
|
223
|
+
await stopEcwebProcess({ pid: pendingPid, startedAt: childIdentityStartedAt }, undefined, onTiming);
|
|
212
224
|
}
|
|
213
225
|
child = null;
|
|
214
226
|
childIdentityStartedAt = null;
|
|
215
227
|
healthy = false;
|
|
216
228
|
return;
|
|
217
229
|
}
|
|
218
|
-
await stopEcwebProcess({ pid: current.pid, startedAt: current.startedAt });
|
|
230
|
+
await stopEcwebProcess({ pid: current.pid, startedAt: current.startedAt }, undefined, onTiming);
|
|
219
231
|
removeEntriesForPid(current.pid);
|
|
220
232
|
active = null;
|
|
221
233
|
child = null;
|
|
@@ -223,6 +235,8 @@ export function createEcwebSupervisor(options) {
|
|
|
223
235
|
healthy = false;
|
|
224
236
|
};
|
|
225
237
|
const spawnEcweb = async () => {
|
|
238
|
+
if (stopping || !desiredEnabled || runtimeMode !== 'managed')
|
|
239
|
+
return;
|
|
226
240
|
intentionalStop = false;
|
|
227
241
|
hasBeenReady = false;
|
|
228
242
|
const root = resolvePaths().root;
|
|
@@ -353,6 +367,14 @@ export function createEcwebSupervisor(options) {
|
|
|
353
367
|
// Allow the child to bind and publish its instance record before treating
|
|
354
368
|
// it as crashed. Daemon readiness is not required for HTTP liveness.
|
|
355
369
|
const instance = await findHealthyInstance();
|
|
370
|
+
if (stopping) {
|
|
371
|
+
// 保留已核验的实例身份供 stop 清理,但不再接管运行状态或进入恢复分支。
|
|
372
|
+
if (instance)
|
|
373
|
+
setActiveFromEntry(instance, active?.pid === instance.record.pid ? active.owned : false);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if (!desiredEnabled || runtimeMode !== 'managed')
|
|
377
|
+
return;
|
|
356
378
|
healthy = instance !== null;
|
|
357
379
|
if (instance) {
|
|
358
380
|
launchRequested = false;
|
|
@@ -428,7 +450,11 @@ export function createEcwebSupervisor(options) {
|
|
|
428
450
|
await checkInFlight.catch(() => { });
|
|
429
451
|
if (startInFlight)
|
|
430
452
|
await startInFlight.catch(() => { });
|
|
453
|
+
if (stopping)
|
|
454
|
+
return;
|
|
431
455
|
await killActive();
|
|
456
|
+
if (stopping)
|
|
457
|
+
return;
|
|
432
458
|
failureCount = failureThreshold;
|
|
433
459
|
launchRequested = true;
|
|
434
460
|
await check();
|
|
@@ -456,8 +482,11 @@ export function createEcwebSupervisor(options) {
|
|
|
456
482
|
}
|
|
457
483
|
// Give an independently started ECWeb time to publish its instance record.
|
|
458
484
|
const existing = await waitForHealthyInstance(1_500);
|
|
459
|
-
if (stopping)
|
|
485
|
+
if (stopping) {
|
|
486
|
+
if (existing)
|
|
487
|
+
setActiveFromEntry(existing, false);
|
|
460
488
|
return;
|
|
489
|
+
}
|
|
461
490
|
if (existing) {
|
|
462
491
|
healthy = true;
|
|
463
492
|
hasBeenReady = true;
|
|
@@ -547,38 +576,65 @@ export function createEcwebSupervisor(options) {
|
|
|
547
576
|
...(running ? { pid: active.pid } : {}),
|
|
548
577
|
};
|
|
549
578
|
},
|
|
550
|
-
|
|
551
|
-
if (
|
|
552
|
-
|
|
579
|
+
stop(onTiming) {
|
|
580
|
+
if (onTiming) {
|
|
581
|
+
stopTimingListeners.add(onTiming);
|
|
582
|
+
for (const timing of completedStopTimings) {
|
|
583
|
+
try {
|
|
584
|
+
onTiming(timing);
|
|
585
|
+
}
|
|
586
|
+
catch { }
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
if (stopInFlight)
|
|
590
|
+
return stopInFlight;
|
|
553
591
|
stopping = true;
|
|
592
|
+
launchRequested = false;
|
|
554
593
|
cancelRecovery();
|
|
555
594
|
if (timer)
|
|
556
595
|
clearTimeout(timer);
|
|
557
596
|
timer = null;
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
await restartInFlight.catch(() => { });
|
|
564
|
-
await configureQueue.catch(() => { });
|
|
565
|
-
if (startInFlight) {
|
|
597
|
+
const waitForOperation = async (phase, operation) => {
|
|
598
|
+
if (!operation)
|
|
599
|
+
return;
|
|
600
|
+
const startMs = Date.now();
|
|
601
|
+
let detail;
|
|
566
602
|
try {
|
|
567
|
-
await
|
|
603
|
+
await operation;
|
|
568
604
|
}
|
|
569
|
-
catch {
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
605
|
+
catch (error) {
|
|
606
|
+
detail = `失败: ${error instanceof Error ? error.message : String(error)}`;
|
|
607
|
+
}
|
|
608
|
+
finally {
|
|
609
|
+
try {
|
|
610
|
+
onTiming?.({ phase, startMs, endMs: Date.now(), detail });
|
|
611
|
+
}
|
|
612
|
+
catch { }
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
stopInFlight = (async () => {
|
|
574
616
|
try {
|
|
575
|
-
|
|
617
|
+
await waitForOperation('startup', startup);
|
|
618
|
+
await waitForOperation('healthCheck', checkInFlight);
|
|
619
|
+
await waitForOperation('restart', restartInFlight);
|
|
620
|
+
await waitForOperation('configure', configureQueue);
|
|
621
|
+
await waitForOperation('launch', startInFlight);
|
|
622
|
+
if (runtimeMode === 'managed')
|
|
623
|
+
await killActive(reportStopTiming);
|
|
576
624
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
625
|
+
finally {
|
|
626
|
+
if (child) {
|
|
627
|
+
try {
|
|
628
|
+
child.removeAllListeners();
|
|
629
|
+
}
|
|
630
|
+
catch { }
|
|
631
|
+
child = null;
|
|
632
|
+
childStartedAt = 0;
|
|
633
|
+
}
|
|
634
|
+
closeLogStream();
|
|
635
|
+
}
|
|
636
|
+
})();
|
|
637
|
+
return stopInFlight;
|
|
582
638
|
},
|
|
583
639
|
};
|
|
584
640
|
}
|