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
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `ec directory
|
|
2
|
+
* `ec directory list|info`:查名录。
|
|
3
3
|
*
|
|
4
|
+
* 命令面与 `ec skill` 对齐:`list` 列举/过滤(`--filter` + 分页),`info` 看单条详情。
|
|
4
5
|
* 和 `directory.md` 的分工:注入内容给的是截断后的概览(描述 100 字、名字 32 字,
|
|
5
|
-
*
|
|
6
|
+
* 不可信条目只留名字),命令给的是完整记录和精确查找。两类使用场景:
|
|
6
7
|
*
|
|
7
8
|
* - 按描述找能力:模型已经知道大致有什么人,需要完整描述判断能不能用。
|
|
8
9
|
* - 按名字找 AID:Owner 或 PA 说"联系张三",把名字落成 AID。
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
+
* 关键词不命中时会触发一次有界同步(和准入路径共用 `lookupByAid` 与模块级单飞),
|
|
11
12
|
* 同步完再查一次——"本地没有"通常意味着"刚更新还没拉下来",而不是"没有这个人"。
|
|
12
13
|
*/
|
|
13
14
|
import fs from 'node:fs';
|
|
@@ -16,14 +17,18 @@ import { agentDir } from '../paths.js';
|
|
|
16
17
|
import { isValidAid } from '../aun/aid/validation.js';
|
|
17
18
|
import { OwnerDirectoryCache, OWNER_DIRECTORY_SCOPES } from './owner-directory-cache.js';
|
|
18
19
|
import { readAllRemarks } from './owner-directory-remarks.js';
|
|
19
|
-
import { describeEntry,
|
|
20
|
+
import { describeEntry, filterDirectory, } from './owner-directory-search.js';
|
|
20
21
|
import { isInternalEntry, ownerRefAid } from './owner-directory-scope.js';
|
|
22
|
+
import { editDistance, normalizeDirectoryText, sameDirectoryName, stripTrailingParenthetical, } from './owner-directory-text.js';
|
|
21
23
|
import { ownerResolver } from '../core/ownership/owner-resolver.js';
|
|
22
24
|
import { authorizedOwnerAid, refreshOwnerDirectory, syncOwnerDirectoryForLookup } from './owner-directory-admission.js';
|
|
23
25
|
import { getPeerSnapshot } from '../config/peer-book.js';
|
|
24
26
|
import { resolveEntryContactable } from './owner-directory-policy.js';
|
|
25
|
-
/** `
|
|
26
|
-
const
|
|
27
|
+
/** `info` 按名字命中时的默认上限。 */
|
|
28
|
+
const INFO_NAME_MATCH_LIMIT = 20;
|
|
29
|
+
/** `list` 的分页默认值与上限;与 `ec skill list` 的默认 20 条一致。 */
|
|
30
|
+
const LIST_DEFAULT_LIMIT = 20;
|
|
31
|
+
const LIST_MAX_LIMIT = 100;
|
|
27
32
|
export class DirectoryQueryError extends Error {
|
|
28
33
|
code;
|
|
29
34
|
constructor(code, message) {
|
|
@@ -32,12 +37,13 @@ export class DirectoryQueryError extends Error {
|
|
|
32
37
|
this.name = 'DirectoryQueryError';
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
|
-
/** 解析 `ec directory <
|
|
40
|
+
/** 解析 `ec directory <list|info|refresh|blocked> ...` 之后的 argv。 */
|
|
36
41
|
export function resolveDirectoryQueryCommand(argv) {
|
|
37
|
-
const [
|
|
38
|
-
|
|
42
|
+
const [rawAction, ...rest] = argv;
|
|
43
|
+
const action = rawAction;
|
|
44
|
+
if (action !== 'list' && action !== 'info'
|
|
39
45
|
&& action !== 'refresh' && action !== 'blocked') {
|
|
40
|
-
throw new DirectoryQueryError('INVALID_ACTION', 'directory requires one of:
|
|
46
|
+
throw new DirectoryQueryError('INVALID_ACTION', 'directory requires one of: list, info, refresh, blocked');
|
|
41
47
|
}
|
|
42
48
|
const selfAid = takeFlag(rest, '--self') ?? process.env.EVOLCORE_SELF_AID?.trim();
|
|
43
49
|
if (!selfAid)
|
|
@@ -47,44 +53,51 @@ export function resolveDirectoryQueryCommand(argv) {
|
|
|
47
53
|
const scope = parseScope(takeFlag(rest, '--scope'));
|
|
48
54
|
const type = takeFlag(rest, '--type')?.trim() || undefined;
|
|
49
55
|
const limit = parseLimit(takeFlag(rest, '--limit'));
|
|
56
|
+
const page = parsePage(takeFlag(rest, '--page'));
|
|
50
57
|
const ownerAid = parseOwnerFilter(takeFlag(rest, '--owner'));
|
|
51
58
|
const positional = takePositional(rest);
|
|
52
|
-
if (action === '
|
|
53
|
-
const query = positional.join(' ').trim();
|
|
54
|
-
if (!query)
|
|
55
|
-
throw new DirectoryQueryError('INVALID_ARGUMENT', 'find requires a query');
|
|
56
|
-
return {
|
|
57
|
-
action, selfAid, query,
|
|
58
|
-
...(type ? { type } : {}), ...(scope ? { scope } : {}),
|
|
59
|
-
...(ownerAid ? { ownerAid } : {}), ...(limit ? { limit } : {}),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
if (action === 'show') {
|
|
59
|
+
if (action === 'info') {
|
|
63
60
|
const target = positional.join(' ').trim();
|
|
64
61
|
if (!target)
|
|
65
|
-
throw new DirectoryQueryError('INVALID_ARGUMENT', '
|
|
62
|
+
throw new DirectoryQueryError('INVALID_ARGUMENT', 'info requires a contact AID or name');
|
|
66
63
|
// 名字里可能有空格(备注名/显示名允许),所以拼起来整体作为 target;
|
|
67
64
|
// 是不是 AID 由执行层判定,参数层不做格式假设。
|
|
68
65
|
return {
|
|
69
66
|
action, selfAid, target,
|
|
70
|
-
...(isValidAid(target) ? { aid: target } : {}),
|
|
71
67
|
...(limit ? { limit } : {}),
|
|
72
68
|
};
|
|
73
69
|
}
|
|
70
|
+
if (action === 'list') {
|
|
71
|
+
// `--filter 'a,b' --filter 'c'`:组内 OR、组间 AND。
|
|
72
|
+
const filterGroups = takeFlags(rest, '--filter')
|
|
73
|
+
.map(value => value.split(',').map(item => item.trim()).filter(Boolean))
|
|
74
|
+
.filter(group => group.length > 0);
|
|
75
|
+
// 位置参数按“多个词同时命中”处理:每个词一组(AND)。
|
|
76
|
+
const positionalGroups = positional
|
|
77
|
+
.map(token => token.trim()).filter(Boolean)
|
|
78
|
+
.map(token => [token]);
|
|
79
|
+
const filters = [...filterGroups, ...positionalGroups];
|
|
80
|
+
return {
|
|
81
|
+
action, selfAid,
|
|
82
|
+
...(filters.length > 0 ? { filters } : {}),
|
|
83
|
+
...(type ? { type } : {}), ...(scope ? { scope } : {}),
|
|
84
|
+
...(ownerAid ? { ownerAid } : {}), ...(limit ? { limit } : {}), ...(page ? { page } : {}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
74
87
|
if (positional.length > 0) {
|
|
75
88
|
throw new DirectoryQueryError('INVALID_ARGUMENT', `${action} takes no positional argument`);
|
|
76
89
|
}
|
|
77
90
|
return {
|
|
78
91
|
action, selfAid,
|
|
79
92
|
...(type ? { type } : {}), ...(scope ? { scope } : {}),
|
|
80
|
-
...(ownerAid ? { ownerAid } : {}),
|
|
93
|
+
...(ownerAid ? { ownerAid } : {}),
|
|
81
94
|
};
|
|
82
95
|
}
|
|
83
96
|
/**
|
|
84
97
|
* 执行查询。
|
|
85
98
|
*
|
|
86
99
|
* 快照优先取 channel 正在用的实例(能共享模块级单飞);拿不到时构造一个只读实例,
|
|
87
|
-
*
|
|
100
|
+
* 读本地文件即可——查询不需要网络,除非关键词未命中要触发同步。
|
|
88
101
|
*/
|
|
89
102
|
export async function executeDirectoryQueryCommand(command) {
|
|
90
103
|
const directory = path.join(agentDir(command.selfAid), 'directory');
|
|
@@ -115,80 +128,80 @@ export async function executeDirectoryQueryCommand(command) {
|
|
|
115
128
|
if (command.action === 'blocked') {
|
|
116
129
|
return directoryBlockedEntries(command, directory, ownerAid, cache, scope);
|
|
117
130
|
}
|
|
118
|
-
|
|
131
|
+
// Owner 与个人助理是顶层身份块,不在 `entries` 里;但注入的 directory.md 把
|
|
132
|
+
// 他们列在最上面,也提示了「用 ec directory info 查详情」。查询必须能查到。
|
|
133
|
+
let snapshot = withIdentityEntries(cache.readSnapshot(scope));
|
|
119
134
|
if (!snapshot) {
|
|
120
135
|
return { ok: false, code: 'NO_SNAPSHOT', error: 'directory snapshot is not available yet' };
|
|
121
136
|
}
|
|
122
|
-
const ownerRef = ownerRefAid(snapshot, ownerAid);
|
|
123
137
|
const contactable = resolveContactable(command.selfAid, cache);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
query: command.query,
|
|
128
|
-
...(command.type ? { type: command.type } : {}),
|
|
129
|
-
...(command.scope ? { scope: command.scope } : {}),
|
|
130
|
-
...(command.ownerAid ? { ownerAid: command.ownerAid } : {}),
|
|
131
|
-
...(command.limit ? { limit: command.limit } : {}),
|
|
132
|
-
});
|
|
133
|
-
let synced = false;
|
|
134
|
-
if (hits.length === 0) {
|
|
135
|
-
// 未命中通常是"刚更新还没拉下来":触发一次有界同步再看一遍。
|
|
136
|
-
synced = await syncOnce(command.selfAid);
|
|
137
|
-
snapshot = cache.readSnapshot(scope);
|
|
138
|
-
if (snapshot) {
|
|
139
|
-
hits = searchDirectory(snapshot, ownerAid, readAllRemarks(directory), {
|
|
140
|
-
query: command.query,
|
|
141
|
-
...(command.type ? { type: command.type } : {}),
|
|
142
|
-
...(command.scope ? { scope: command.scope } : {}),
|
|
143
|
-
...(command.ownerAid ? { ownerAid: command.ownerAid } : {}),
|
|
144
|
-
...(command.limit ? { limit: command.limit } : {}),
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return { ok: true, action: 'find', hits, synced };
|
|
149
|
-
}
|
|
150
|
-
if (command.action === 'show') {
|
|
151
|
-
const target = command.target ?? command.aid ?? '';
|
|
152
|
-
const lookup = (snap) => showTarget(snap, target, ownerAid, directory, contactable, command.limit);
|
|
138
|
+
if (command.action === 'info') {
|
|
139
|
+
const target = command.target ?? '';
|
|
140
|
+
const lookup = (snap) => infoTarget(snap, target, ownerAid, directory, contactable, command.limit);
|
|
153
141
|
let hit = lookup(snapshot);
|
|
154
142
|
let synced = false;
|
|
155
143
|
if (hit.entries.length === 0) {
|
|
156
|
-
//
|
|
144
|
+
// 未命中通常是"刚更新还没拉下来":触发一次有界同步再看一遍。
|
|
157
145
|
synced = await syncOnce(command.selfAid);
|
|
158
|
-
const refreshed = cache.readSnapshot(scope);
|
|
146
|
+
const refreshed = withIdentityEntries(cache.readSnapshot(scope));
|
|
159
147
|
if (refreshed)
|
|
160
148
|
hit = lookup(refreshed);
|
|
161
149
|
}
|
|
162
150
|
if (hit.entries.length === 0) {
|
|
151
|
+
const close = hit.suggestions?.length
|
|
152
|
+
? `; close matches: ${hit.suggestions.map(item => `${item.name}(${item.aid})`).join(', ')}`
|
|
153
|
+
: '';
|
|
163
154
|
return {
|
|
164
155
|
ok: false, code: 'NOT_FOUND',
|
|
165
|
-
error: `${target} is not in the directory${synced ? ' (after a sync attempt)' : ''}`,
|
|
156
|
+
error: `${target} is not in the directory${synced ? ' (after a sync attempt)' : ''}${close}`,
|
|
166
157
|
};
|
|
167
158
|
}
|
|
168
159
|
return {
|
|
169
|
-
ok: true, action: '
|
|
160
|
+
ok: true, action: 'info',
|
|
170
161
|
entries: hit.entries,
|
|
171
162
|
...(hit.entries.length === 1 ? { entry: hit.entries[0] } : {}),
|
|
172
163
|
matchedBy: hit.matchedBy,
|
|
164
|
+
...(hit.matchKind ? { matchKind: hit.matchKind } : {}),
|
|
173
165
|
...(hit.truncated ? { truncated: hit.truncated } : {}),
|
|
174
166
|
synced,
|
|
175
167
|
};
|
|
176
168
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
.
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
169
|
+
// list:过滤后分页。过滤条件为空时就是全量列举。
|
|
170
|
+
let filtered = filterDirectory(snapshot, ownerAid, readAllRemarks(directory), {
|
|
171
|
+
...(command.filters ? { filters: command.filters } : {}),
|
|
172
|
+
...(command.type ? { type: command.type } : {}),
|
|
173
|
+
...(command.scope ? { scope: command.scope } : {}),
|
|
174
|
+
...(command.ownerAid ? { ownerAid: command.ownerAid } : {}),
|
|
175
|
+
});
|
|
176
|
+
let synced = false;
|
|
177
|
+
if (filtered.length === 0 && command.filters?.length) {
|
|
178
|
+
// 不命中时才做一次有界同步:全量列举不需要网络。
|
|
179
|
+
synced = await syncOnce(command.selfAid);
|
|
180
|
+
const refreshed = withIdentityEntries(cache.readSnapshot(scope));
|
|
181
|
+
if (refreshed) {
|
|
182
|
+
snapshot = refreshed;
|
|
183
|
+
filtered = filterDirectory(snapshot, ownerAid, readAllRemarks(directory), {
|
|
184
|
+
...(command.filters ? { filters: command.filters } : {}),
|
|
185
|
+
...(command.type ? { type: command.type } : {}),
|
|
186
|
+
...(command.scope ? { scope: command.scope } : {}),
|
|
187
|
+
...(command.ownerAid ? { ownerAid: command.ownerAid } : {}),
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const limit = Math.min(command.limit ?? LIST_DEFAULT_LIMIT, LIST_MAX_LIMIT);
|
|
192
|
+
const page = command.page ?? 1;
|
|
193
|
+
const total = filtered.length;
|
|
194
|
+
const start = (page - 1) * limit;
|
|
195
|
+
const ownerRef = ownerRefAid(snapshot, ownerAid);
|
|
196
|
+
const remarks = readAllRemarks(directory);
|
|
197
|
+
const entries = filtered.slice(start, start + limit)
|
|
198
|
+
// 检索结果不带本地备注正文:要看正文用 `ec directory info <AID>`。
|
|
199
|
+
.map(entry => describeEntry(entry, ownerRef, remarks.get(entry.aid), contactable, {
|
|
200
|
+
includeLocalRemark: false,
|
|
201
|
+
}));
|
|
202
|
+
return {
|
|
203
|
+
ok: true, action: 'list', entries, page, limit, total, hasMore: start + entries.length < total,
|
|
204
|
+
};
|
|
192
205
|
}
|
|
193
206
|
/**
|
|
194
207
|
* `ec directory blocked`:列出被拉黑的主体,两个来源合并。
|
|
@@ -269,44 +282,123 @@ function readBlockedAidsFromSnapshot(directory) {
|
|
|
269
282
|
}
|
|
270
283
|
}
|
|
271
284
|
/**
|
|
272
|
-
* `
|
|
273
|
-
*
|
|
285
|
+
* 把快照顶层的 `owner` / `personal_assistant` 身份块补成可查询条目。
|
|
286
|
+
*
|
|
287
|
+
* 这两个身份块按协议**不属于** `entries`(`personal_assistant` 是身份元数据),
|
|
288
|
+
* 但注入的 `directory.md` 把 Owner 和个人助理列在最上面,并提示用
|
|
289
|
+
* `ec directory info <名字>` 看详情。只查 `entries` 会让最该查到的两个人查不到。
|
|
290
|
+
* 与已有条目同 AID 时以条目为准,避免同一个人出现两次。
|
|
291
|
+
*
|
|
292
|
+
* 两者在快照解析阶段已经和 `authorization.json` 的授权 Owner 做过一致性校验,
|
|
293
|
+
* 所以补成条目时按“已核验”处理,否则他们会被自己的归属门禁判成外部。
|
|
294
|
+
*/
|
|
295
|
+
function withIdentityEntries(snapshot) {
|
|
296
|
+
if (!snapshot)
|
|
297
|
+
return undefined;
|
|
298
|
+
const known = new Set(snapshot.entries.map(entry => entry.aid));
|
|
299
|
+
const ownerRef = snapshot.owner?.aid ?? snapshot.ownerAid;
|
|
300
|
+
const extra = [];
|
|
301
|
+
for (const field of [snapshot.owner, snapshot.personalAssistant]) {
|
|
302
|
+
if (!field?.aid || known.has(field.aid))
|
|
303
|
+
continue;
|
|
304
|
+
known.add(field.aid);
|
|
305
|
+
extra.push(identityEntry(field, ownerRef));
|
|
306
|
+
}
|
|
307
|
+
return extra.length > 0 ? { ...snapshot, entries: [...extra, ...snapshot.entries] } : snapshot;
|
|
308
|
+
}
|
|
309
|
+
function identityEntry(field, ownerAid) {
|
|
310
|
+
return {
|
|
311
|
+
aid: field.aid,
|
|
312
|
+
name: field.name || field.aid,
|
|
313
|
+
ownerAid,
|
|
314
|
+
ownership_status: 'owned',
|
|
315
|
+
...(field.agent_md_signed_at !== undefined ? { agent_md_signed_at: field.agent_md_signed_at } : {}),
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* `info` 的目标解析:合法 AID 精确匹配;否则当名字匹配,分两级——
|
|
320
|
+
* 归一后精确相等(全角/空格/结尾括号称呼不影响),没命中再按名字包含放宽。
|
|
321
|
+
* 两级都不碰描述字段:描述里提到某人(「李文江的助理」)不代表那条就是某人。
|
|
274
322
|
*
|
|
275
323
|
* 备注名优先级与渲染一致:本地备注 > 远端 remark > 远端 name。
|
|
276
324
|
*/
|
|
277
|
-
function
|
|
325
|
+
function infoTarget(snapshot, target, ownerAid, directory, contactable,
|
|
278
326
|
/** 同名多条时的上限;不传按 20 条封顶,防止一个常见名字把上下文灌满。 */
|
|
279
327
|
limit) {
|
|
280
328
|
const ownerRef = ownerRefAid(snapshot, ownerAid);
|
|
281
329
|
const remarks = readAllRemarks(directory);
|
|
282
|
-
|
|
283
|
-
|
|
330
|
+
// 兼容 `@aid` 写法(与 daemon 里委托凭据的处理一致),AID 大小写不敏感。
|
|
331
|
+
const bareTarget = target.trim().replace(/^@/, '');
|
|
332
|
+
if (isValidAid(bareTarget)) {
|
|
333
|
+
const wantedAid = normalizeDirectoryText(bareTarget);
|
|
334
|
+
const entry = snapshot.entries.find((item) => normalizeDirectoryText(item.aid) === wantedAid);
|
|
284
335
|
return {
|
|
285
336
|
matchedBy: 'aid',
|
|
286
337
|
entries: entry ? [describeEntry(entry, ownerRef, remarks.get(entry.aid), contactable)] : [],
|
|
287
338
|
};
|
|
288
339
|
}
|
|
289
|
-
const wanted = target
|
|
290
|
-
const
|
|
340
|
+
const wanted = normalizeDirectoryText(target);
|
|
341
|
+
const namesOf = (entry) => {
|
|
291
342
|
const remark = remarks.get(entry.aid);
|
|
292
343
|
// 所有叫法都参与:名录名、Owner 的备注名、本地记的每一个称呼。
|
|
293
|
-
|
|
294
|
-
.map(value => (typeof value === 'string' ? value
|
|
344
|
+
return [entry.name, entry.remark, ...(remark?.aliases ?? (remark?.remark ? [remark.remark] : []))]
|
|
345
|
+
.map(value => (typeof value === 'string' ? value : ''))
|
|
295
346
|
.filter(Boolean);
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
const
|
|
299
|
-
|
|
347
|
+
};
|
|
348
|
+
const exact = snapshot.entries.filter((entry) => namesOf(entry).some(name => sameDirectoryName(name, wanted)));
|
|
349
|
+
const matched = exact.length > 0
|
|
350
|
+
? { entries: exact, kind: 'exact' }
|
|
351
|
+
// 精确没命中才放宽到包含:中文名很少误伤,但绝不能回落到描述——
|
|
352
|
+
// 「李文江的助理」不是李文江本人。
|
|
353
|
+
: { entries: fuzzyNameMatches(snapshot, wanted, namesOf), kind: 'fuzzy' };
|
|
354
|
+
const cap = limit ?? INFO_NAME_MATCH_LIMIT;
|
|
355
|
+
const result = {
|
|
300
356
|
matchedBy: 'name',
|
|
301
|
-
entries:
|
|
302
|
-
...(
|
|
357
|
+
entries: matched.entries.slice(0, cap).map((entry) => describeEntry(entry, ownerRef, remarks.get(entry.aid), contactable)),
|
|
358
|
+
...(matched.entries.length > 0 ? { matchKind: matched.kind } : {}),
|
|
359
|
+
...(matched.entries.length > cap ? { truncated: matched.entries.length - cap } : {}),
|
|
303
360
|
};
|
|
361
|
+
if (matched.entries.length === 0) {
|
|
362
|
+
result.suggestions = nearestNames(snapshot, wanted, namesOf);
|
|
363
|
+
}
|
|
364
|
+
return result;
|
|
365
|
+
}
|
|
366
|
+
/** 名字/称呼包含查询串。长度小于 2 的查询串不做放宽,否则单个字会命中一大片。 */
|
|
367
|
+
function fuzzyNameMatches(snapshot, wanted, namesOf) {
|
|
368
|
+
if (wanted.length < 2)
|
|
369
|
+
return [];
|
|
370
|
+
return snapshot.entries.filter((entry) => namesOf(entry).some(name => {
|
|
371
|
+
const normalized = normalizeDirectoryText(name);
|
|
372
|
+
const base = normalizeDirectoryText(stripTrailingParenthetical(normalized));
|
|
373
|
+
return normalized.includes(wanted) || base.includes(wanted);
|
|
374
|
+
}));
|
|
375
|
+
}
|
|
376
|
+
/** 拼错/叫法差异时的兜底提示:按编辑距离找最多 3 个最近的名字。 */
|
|
377
|
+
function nearestNames(snapshot, wanted, namesOf) {
|
|
378
|
+
if (wanted.length < 2)
|
|
379
|
+
return [];
|
|
380
|
+
const scored = [];
|
|
381
|
+
for (const entry of snapshot.entries) {
|
|
382
|
+
let best = Number.POSITIVE_INFINITY;
|
|
383
|
+
let closest = entry.name;
|
|
384
|
+
for (const name of namesOf(entry)) {
|
|
385
|
+
const normalized = normalizeDirectoryText(stripTrailingParenthetical(normalizeDirectoryText(name)));
|
|
386
|
+
if (!normalized)
|
|
387
|
+
continue;
|
|
388
|
+
const distance = editDistance(normalized, wanted);
|
|
389
|
+
if (distance < best) {
|
|
390
|
+
best = distance;
|
|
391
|
+
closest = name;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
const threshold = wanted.length >= 5 ? 2 : 1;
|
|
395
|
+
if (best <= threshold)
|
|
396
|
+
scored.push({ aid: entry.aid, name: closest, distance: best });
|
|
397
|
+
}
|
|
398
|
+
return scored.sort((a, b) => a.distance - b.distance || a.name.localeCompare(b.name))
|
|
399
|
+
.slice(0, 3)
|
|
400
|
+
.map(({ aid, name }) => ({ aid, name }));
|
|
304
401
|
}
|
|
305
|
-
/**
|
|
306
|
-
* 一次有界同步(B 方案):用 channel 注册着的活缓存触发,和准入路径共用
|
|
307
|
-
* 模块级单飞。查询用的只读实例没有网络能力——没有活缓存时返回 false,
|
|
308
|
-
* 按未命中处理。
|
|
309
|
-
*/
|
|
310
402
|
async function syncOnce(selfAid) {
|
|
311
403
|
return syncOwnerDirectoryForLookup(selfAid);
|
|
312
404
|
}
|
|
@@ -335,15 +427,35 @@ function takeFlag(args, flag) {
|
|
|
335
427
|
}
|
|
336
428
|
return value;
|
|
337
429
|
}
|
|
430
|
+
/** 可重复的标志:`--filter 'a,b' --filter c`。 */
|
|
431
|
+
function takeFlags(args, flag) {
|
|
432
|
+
const values = [];
|
|
433
|
+
for (let index = 0; index < args.length; index++) {
|
|
434
|
+
if (args[index] !== flag)
|
|
435
|
+
continue;
|
|
436
|
+
const value = args[index + 1];
|
|
437
|
+
if (value === undefined || value.startsWith('--')) {
|
|
438
|
+
throw new DirectoryQueryError('INVALID_ARGUMENT', `${flag} requires a value`);
|
|
439
|
+
}
|
|
440
|
+
values.push(value);
|
|
441
|
+
index++;
|
|
442
|
+
}
|
|
443
|
+
return values;
|
|
444
|
+
}
|
|
445
|
+
/** 带值的标志;其余 `--xxx` 视为布尔标志(如 `--json`),不能吃掉后面的位置参数。 */
|
|
446
|
+
const VALUED_FLAGS = new Set([
|
|
447
|
+
'--self', '--type', '--scope', '--owner', '--limit', '--page', '--filter', '--format',
|
|
448
|
+
]);
|
|
338
449
|
function takePositional(args) {
|
|
339
450
|
const result = [];
|
|
340
451
|
for (let index = 0; index < args.length; index++) {
|
|
341
452
|
const arg = args[index];
|
|
342
|
-
if (arg.startsWith('--')) {
|
|
343
|
-
|
|
453
|
+
if (!arg.startsWith('--')) {
|
|
454
|
+
result.push(arg);
|
|
344
455
|
continue;
|
|
345
456
|
}
|
|
346
|
-
|
|
457
|
+
if (VALUED_FLAGS.has(arg))
|
|
458
|
+
index++;
|
|
347
459
|
}
|
|
348
460
|
return result;
|
|
349
461
|
}
|
|
@@ -380,3 +492,11 @@ function parseLimit(value) {
|
|
|
380
492
|
}
|
|
381
493
|
return Number(value);
|
|
382
494
|
}
|
|
495
|
+
function parsePage(value) {
|
|
496
|
+
if (value === undefined)
|
|
497
|
+
return undefined;
|
|
498
|
+
if (!/^\d+$/.test(value) || Number(value) <= 0) {
|
|
499
|
+
throw new DirectoryQueryError('INVALID_ARGUMENT', '--page must be a positive integer');
|
|
500
|
+
}
|
|
501
|
+
return Number(value);
|
|
502
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import crypto from 'node:crypto';
|
|
3
|
+
import { agentConfig } from '../paths.js';
|
|
4
|
+
import { isValidAid } from '../aun/aid/validation.js';
|
|
5
|
+
import { FRIEND_INVITE_TTL_MS } from '../core/message/contact-admission.js';
|
|
6
|
+
import { DirectoryQueryError } from './owner-directory-query-operation.js';
|
|
7
|
+
/** Submit the App-owned invitation protocol without mutating the directory or access policy. */
|
|
8
|
+
export function resolveDirectoryRequestCommand(argv) {
|
|
9
|
+
if (argv[0] !== 'request')
|
|
10
|
+
throw new DirectoryQueryError('INVALID_ACTION', 'directory request is required');
|
|
11
|
+
const values = new Map();
|
|
12
|
+
const positionals = [];
|
|
13
|
+
for (let index = 1; index < argv.length; index++) {
|
|
14
|
+
const token = argv[index];
|
|
15
|
+
if (!token.startsWith('-')) {
|
|
16
|
+
positionals.push(token);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (!['--self', '--note', '--format'].includes(token)) {
|
|
20
|
+
throw new DirectoryQueryError('INVALID_ARGUMENT', `未知 request 参数: ${token}`);
|
|
21
|
+
}
|
|
22
|
+
const value = argv[++index];
|
|
23
|
+
if (values.has(token) || !value?.trim() || value.startsWith('--')) {
|
|
24
|
+
throw new DirectoryQueryError('INVALID_ARGUMENT', `${token} 必须提供非空值,且不能重复`);
|
|
25
|
+
}
|
|
26
|
+
values.set(token, value.trim());
|
|
27
|
+
}
|
|
28
|
+
const selfAid = values.get('--self') ?? process.env.EVOLCORE_SELF_AID?.trim();
|
|
29
|
+
if (!selfAid || !isValidAid(selfAid)) {
|
|
30
|
+
throw new DirectoryQueryError('INVALID_ARGUMENT', '--self <agent-aid> 必须是有效的本端 Agent AID');
|
|
31
|
+
}
|
|
32
|
+
if (positionals.length !== 1 || !isValidAid(positionals[0])) {
|
|
33
|
+
throw new DirectoryQueryError('INVALID_ARGUMENT', '用法: ec directory request <target-aid> --self <agent-aid> [--note <申请说明>]');
|
|
34
|
+
}
|
|
35
|
+
if (positionals[0] === selfAid) {
|
|
36
|
+
throw new DirectoryQueryError('INVALID_ARGUMENT', '不能向本 Agent 自己发送好友申请');
|
|
37
|
+
}
|
|
38
|
+
const format = values.get('--format');
|
|
39
|
+
if (format !== undefined && format !== 'json' && format !== 'text') {
|
|
40
|
+
throw new DirectoryQueryError('INVALID_ARGUMENT', '--format 仅支持 text|json');
|
|
41
|
+
}
|
|
42
|
+
const note = values.get('--note');
|
|
43
|
+
if (note?.includes('\0')) {
|
|
44
|
+
throw new DirectoryQueryError('INVALID_ARGUMENT', '申请说明不能包含 NUL');
|
|
45
|
+
}
|
|
46
|
+
return { action: 'request', selfAid, targetAid: positionals[0], ...(note ? { note } : {}) };
|
|
47
|
+
}
|
|
48
|
+
export async function executeDirectoryRequestCommand(command, send) {
|
|
49
|
+
if (!fs.existsSync(agentConfig(command.selfAid))) {
|
|
50
|
+
return { ok: false, code: 'AGENT_NOT_FOUND', error: `Agent 不存在: ${command.selfAid}` };
|
|
51
|
+
}
|
|
52
|
+
const createdAt = Date.now();
|
|
53
|
+
const payload = {
|
|
54
|
+
type: 'friend.invite.v1',
|
|
55
|
+
schema_version: 1,
|
|
56
|
+
invite_id: `friend-invite-${crypto.randomUUID()}`,
|
|
57
|
+
applicant_aid: command.selfAid,
|
|
58
|
+
target_aid: command.targetAid,
|
|
59
|
+
created_at_ms: createdAt,
|
|
60
|
+
expires_at_ms: createdAt + FRIEND_INVITE_TTL_MS,
|
|
61
|
+
introduction: command.note ?? '你好,我想添加你为联系人。',
|
|
62
|
+
};
|
|
63
|
+
try {
|
|
64
|
+
const result = await send({ from: command.selfAid, to: command.targetAid, payload, encrypt: true });
|
|
65
|
+
if (!result.ok || !result.message_id) {
|
|
66
|
+
return { ok: false, code: String(result.code ?? 'FRIEND_INVITE_FAILED'),
|
|
67
|
+
error: `向目标 ${command.targetAid} 发送加好友申请失败:${result.error ?? '未获得消息发送回执'}` };
|
|
68
|
+
}
|
|
69
|
+
return { ok: true, action: 'request', selfAid: command.selfAid, targetAid: command.targetAid,
|
|
70
|
+
status: 'sent', message_id: result.message_id };
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
return { ok: false, code: 'FRIEND_INVITE_FAILED',
|
|
74
|
+
error: `向目标 ${command.targetAid} 发送加好友申请失败:${error instanceof Error ? error.message : String(error)}` };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -40,6 +40,27 @@ export function isMessagingType(type) {
|
|
|
40
40
|
export function ownerRefAid(snapshot, fallbackOwnerAid) {
|
|
41
41
|
return snapshot?.owner?.aid ?? fallbackOwnerAid;
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* 归属是否经过双边核验。
|
|
45
|
+
*
|
|
46
|
+
* 协议里 `ownership_status` 只有 `owned` / `unknown`:`owned` 表示 Owner 侧已经
|
|
47
|
+
* 通过 Ownership 共识确认了这条与自己的绑定关系,`unknown`(以及缺字段)都表示
|
|
48
|
+
* **没能确认**。内外判定和注入都只认 `owned`——否则一个 Agent 只要在名录里
|
|
49
|
+
* 把 `owner_aid` 写成我们的 Owner,就能拿到内部联系人的默认放行。
|
|
50
|
+
*/
|
|
51
|
+
export function isOwnershipVerified(entry) {
|
|
52
|
+
return (entry.ownership_status ?? '').trim().toLowerCase() === 'owned';
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 这条主体要不要过双边归属门禁。
|
|
56
|
+
*
|
|
57
|
+
* 只对 `type=agent` 生效:会自称“我是某某的 Agent”并据此索取内部待遇的是 Agent,
|
|
58
|
+
* 双边核验要拦的也是它。人类联系人由 Owner 在名录里直接维护,`owner_aid` 本身
|
|
59
|
+
* 就是 Owner 的明确指派;其余非消息类型(host/device/service…)不参与消息准入。
|
|
60
|
+
*/
|
|
61
|
+
function requiresOwnershipVerification(entry) {
|
|
62
|
+
return (entry.type ?? '').trim().toLowerCase() === 'agent';
|
|
63
|
+
}
|
|
43
64
|
/** 条目的 Owner AID;缺失返回 undefined。 */
|
|
44
65
|
export function entryOwnerAid(entry) {
|
|
45
66
|
const value = entry.ownerAid?.trim();
|
|
@@ -64,11 +85,21 @@ export function classifyEntry(entry, ownerRef) {
|
|
|
64
85
|
const owner = entryOwnerAid(entry);
|
|
65
86
|
if (owner === undefined)
|
|
66
87
|
return type === 'agent' ? 'unbound_agent' : 'external_human';
|
|
67
|
-
if (owner === ownerRef)
|
|
68
|
-
|
|
88
|
+
if (owner === ownerRef) {
|
|
89
|
+
const verified = !requiresOwnershipVerification(entry) || isOwnershipVerified(entry);
|
|
90
|
+
return verified ? 'internal' : 'unverified';
|
|
91
|
+
}
|
|
69
92
|
return type === 'agent' ? 'external_agent' : 'external_human';
|
|
70
93
|
}
|
|
71
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* 条目是否属于本 Owner(内部联系人)。
|
|
96
|
+
*
|
|
97
|
+
* agent 类型必须同时满足 `owner_aid` 匹配与双边核验;只看 `owner_aid` 会让一条
|
|
98
|
+
* 自称归属、实际未核验的 Agent 拿到内部联系人的默认放行。人类与其他非消息类型
|
|
99
|
+
* 以 `owner_aid` 为准(见 `requiresOwnershipVerification`)。
|
|
100
|
+
*/
|
|
72
101
|
export function isInternalEntry(entry, ownerRef) {
|
|
73
|
-
|
|
102
|
+
if (entryOwnerAid(entry) !== ownerRef)
|
|
103
|
+
return false;
|
|
104
|
+
return !requiresOwnershipVerification(entry) || isOwnershipVerified(entry);
|
|
74
105
|
}
|