evolcore 0.0.43-test.1 → 0.0.43-test.2
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 +24 -1
- package/README.md +22 -0
- package/dist/agents/claude-runner.js +26 -2
- package/dist/agents/codex/app-server-client.js +12 -0
- package/dist/agents/codex-runner.js +49 -8
- package/dist/agents/ecagent-runner.js +26 -9
- package/dist/agents/gemini-runner.js +15 -12
- package/dist/agents/tool-time-context.js +55 -0
- package/dist/aun/menu/client.js +1 -1
- package/dist/aun/model-headers.js +17 -0
- package/dist/aun/msg/p2p.js +3 -0
- package/dist/channels/aun.js +484 -43
- package/dist/channels/builtin-plugins.js +16 -11
- package/dist/channels/dingtalk.js +83 -31
- package/dist/channels/feishu.js +29 -13
- package/dist/channels/qqbot.js +32 -11
- package/dist/channels/wechat.js +13 -3
- package/dist/channels/wecom.js +67 -27
- package/dist/cli/agent-command.js +3 -86
- package/dist/cli/agent-create.js +22 -6
- package/dist/cli/agent.js +1 -79
- package/dist/cli/aun-commands.js +1 -0
- package/dist/cli/config.js +1 -1
- package/dist/cli/daemon-commands.js +47 -2
- package/dist/cli/data-command.js +9 -1
- package/dist/cli/debug-mode.js +1 -1
- package/dist/cli/diag.js +1 -1
- package/dist/cli/directory.js +77 -64
- package/dist/cli/getmeta-command.js +1 -1
- package/dist/cli/index.js +79 -22
- package/dist/cli/init.js +1 -23
- package/dist/cli/link-rules.js +1 -1
- package/dist/cli/managed-command-guard.js +0 -1
- package/dist/cli/pa-workspace-command.js +36 -2
- package/dist/cli/peer.js +1 -1
- package/dist/cli/restart-monitor.js +17 -3
- package/dist/cli/role.js +1 -1
- package/dist/cli/session-command.js +1 -1
- package/dist/cli/stats.js +2 -2
- package/dist/cli/thread-command.js +1 -1
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/access-policy.js +1 -0
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +7 -0
- package/dist/config/role-schema.js +4 -3
- package/dist/config/role-service.js +3 -3
- package/dist/config-store.js +75 -4
- package/dist/core/agent-ipc-registration.js +16 -59
- package/dist/core/auth/authorization-audit.js +52 -14
- package/dist/core/auth/operation-authorizer.js +0 -11
- package/dist/core/auth/operation-catalog.js +0 -18
- package/dist/core/channel-loader.js +152 -16
- package/dist/core/command/agent-control.js +2 -1
- package/dist/core/command/cli-intent-parser.js +0 -8
- package/dist/core/command/command-handler.js +17 -46
- package/dist/core/command/connect-menu.js +7 -3
- package/dist/core/command/menu-catalog.js +3 -2
- package/dist/core/command/menu-handler.js +51 -8
- package/dist/core/command/menu-protocol.js +20 -0
- package/dist/core/command/slash-handler.js +101 -40
- package/dist/core/daemon-file-cache.js +3 -3
- package/dist/core/evolagent-registry.js +5 -4
- package/dist/core/evolagent.js +5 -8
- package/dist/core/handoff/argv-parse.js +115 -0
- package/dist/core/handoff/ipc-registration.js +1 -1
- package/dist/core/ipc-registration.js +19 -2
- package/dist/core/memory/consolidation.js +8 -1
- package/dist/core/memory/relation-sweep.js +20 -8
- package/dist/core/message/aun-ipc-sender.js +28 -1
- package/dist/core/message/contact-admission.js +548 -0
- package/dist/core/message/im-renderer.js +69 -10
- package/dist/core/message/message-admission.js +28 -3
- package/dist/core/message/message-bridge.js +46 -5
- package/dist/core/message/message-utils.js +0 -5
- package/dist/core/message/peer-mode.js +44 -10
- package/dist/core/message/response-engine.js +268 -69
- package/dist/core/message/retry-scheduler.js +4 -0
- package/dist/core/permission/ec-command-parser.js +1 -28
- package/dist/core/permission/readonly-shell-query.js +34 -8
- package/dist/core/permission/tool-policy.js +50 -5
- package/dist/core/role/runtime-policy.js +14 -2
- package/dist/core/session/session-manager.js +9 -1
- package/dist/core/soul.js +66 -0
- package/dist/core/system-session/memory.js +2 -2
- package/dist/directory/contact-admission-paths.js +9 -0
- package/dist/directory/owner-directory-admission.js +128 -29
- package/dist/directory/owner-directory-cache.js +364 -50
- package/dist/directory/owner-directory-identity.js +60 -0
- package/dist/directory/owner-directory-markdown.js +120 -47
- package/dist/directory/owner-directory-policy.js +108 -0
- package/dist/directory/owner-directory-query-operation.js +219 -32
- package/dist/directory/owner-directory-remarks.js +29 -2
- package/dist/directory/owner-directory-search.js +50 -18
- package/dist/directory/owner-directory-store.js +150 -30
- package/dist/eck/kit-renderer.js +12 -5
- package/dist/eck/manifest-engine.js +55 -6
- package/dist/eck/message-renderer.js +5 -2
- package/dist/eck/paactive-context.js +45 -0
- package/dist/ecweb/basic-settings-service.js +2 -2
- package/dist/ecweb/message-context-service.js +24 -16
- package/dist/index.js +9 -5
- package/dist/ipc.js +1 -1
- package/dist/paths.js +26 -0
- package/dist/response-system/config-resolver.js +1 -1
- package/dist/response-system/engines/v1/index.js +4 -1
- package/dist/response-system/engines/v1/paactive-flow.js +18 -0
- package/dist/response-system/modes/single-session/index.js +7 -2
- package/dist/trigger/scheduler.js +3 -5
- package/dist/trigger/validation.js +4 -0
- package/dist/utils/error-utils.js +5 -2
- package/dist/utils/logger.js +13 -4
- package/dist/utils/npm-ops.js +2 -2
- package/dist/utils/windows-autostart.js +1 -1
- package/ecagent/dist/agent-loop.js +43 -1
- package/kits/docs/INDEX.md +1 -0
- package/kits/docs/context-assembly.md +21 -6
- package/kits/docs/eck_templates/INDEX.template.md +1 -2
- package/kits/docs/evolcore/INDEX.md +1 -1
- package/kits/docs/evolcore/agent-create.md +5 -5
- package/kits/docs/evolcore/agent.md +4 -9
- package/kits/docs/evolcore/directory.md +137 -0
- package/kits/docs/evolcore/menu-protocol.md +55 -0
- package/kits/docs/evolcore/response.md +7 -1
- package/kits/docs/evolcore/tool-authorization.md +1 -1
- package/kits/docs/evolcore/trigger.md +4 -0
- package/kits/docs/prompt-loading-architecture.md +6 -2
- package/kits/eck_manifest.auxiliary.json +1 -0
- package/kits/eck_manifest.json +57 -4
- package/kits/eck_manifest.memory.json +67 -3
- package/kits/eck_manifest.paactive.json +528 -0
- package/kits/eck_message_manifest.paactive.json +233 -0
- package/kits/rules/01-overview.md +2 -2
- package/kits/rules/03-identity.md +10 -9
- package/kits/rules/05-venue.md +2 -4
- package/kits/rules/06-channel.md +1 -1
- package/kits/schemas/_meta.json +31 -3
- package/kits/schemas/agent-config.schema.18.json +5 -0
- package/kits/schemas/agent-config.schema.19.json +924 -0
- package/kits/schemas/relation-config.schema.12.json +289 -0
- package/kits/schemas/role-config.schema.2.json +215 -0
- package/kits/skills/ec-skill/scripts/cli.mjs +3 -2
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/personal-assistant/SKILL.md +109 -53
- package/kits/skills/personal-assistant/references/02-bootstrap.md +73 -30
- package/kits/skills/personal-assistant/scripts/clean.mjs +35 -18
- package/kits/skills/personal-assistant/scripts/init.mjs +41 -2
- package/kits/skills/personal-assistant/scripts/lib/persona.mjs +185 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +55 -4
- package/kits/skills/personal-assistant/scripts/pa.mjs +173 -0
- package/kits/skills/personal-assistant/scripts/uninstall.mjs +130 -0
- package/kits/skills/personal-assistant/templates/persona-section.md +3 -3
- package/kits/templates/message-fragments/handoff-request-to-target.md +1 -1
- package/kits/templates/message-fragments/paactive/item.md +3 -0
- package/kits/templates/soul/00-GUIDE.md +61 -0
- package/kits/templates/soul/01-identity.md +5 -0
- package/kits/templates/soul/02-persona.md +11 -0
- package/kits/templates/soul/03-duties.md +5 -0
- package/kits/templates/soul/04-working-style.md +5 -0
- package/kits/templates/system-fragments/bootstrap.md +7 -7
- package/kits/templates/system-fragments/commands.md +3 -2
- package/kits/templates/system-fragments/directory-contacts.md +9 -0
- package/kits/templates/system-fragments/memory.md +1 -1
- package/kits/templates/system-fragments/paactive/channel.md +25 -0
- package/kits/templates/system-fragments/paactive/reply.md +25 -0
- package/kits/templates/system-fragments/paactive/session.md +32 -0
- package/kits/templates/system-fragments/personal-assistant.md +65 -0
- package/package.json +3 -2
- package/dist/cli/handoff-command.js +0 -353
- package/dist/directory/owner-directory-remark-operation.js +0 -147
- package/kits/docs/evolcore/self-summary.md +0 -29
|
@@ -15,11 +15,15 @@ import path from 'node:path';
|
|
|
15
15
|
import { agentDir } from '../paths.js';
|
|
16
16
|
import { isValidAid } from '../aun/aid/validation.js';
|
|
17
17
|
import { OwnerDirectoryCache, OWNER_DIRECTORY_SCOPES } from './owner-directory-cache.js';
|
|
18
|
-
import { readAllRemarks
|
|
18
|
+
import { readAllRemarks } from './owner-directory-remarks.js';
|
|
19
19
|
import { describeEntry, searchDirectory, } from './owner-directory-search.js';
|
|
20
20
|
import { isInternalEntry, ownerRefAid } from './owner-directory-scope.js';
|
|
21
21
|
import { ownerResolver } from '../core/ownership/owner-resolver.js';
|
|
22
|
-
import {
|
|
22
|
+
import { authorizedOwnerAid, refreshOwnerDirectory, syncOwnerDirectoryForLookup } from './owner-directory-admission.js';
|
|
23
|
+
import { getPeerSnapshot } from '../config/peer-book.js';
|
|
24
|
+
import { resolveEntryContactable } from './owner-directory-policy.js';
|
|
25
|
+
/** `show` 按名字命中时的默认上限。 */
|
|
26
|
+
const SHOW_NAME_MATCH_LIMIT = 20;
|
|
23
27
|
export class DirectoryQueryError extends Error {
|
|
24
28
|
code;
|
|
25
29
|
constructor(code, message) {
|
|
@@ -31,8 +35,9 @@ export class DirectoryQueryError extends Error {
|
|
|
31
35
|
/** 解析 `ec directory <find|show|list> ...` 之后的 argv。 */
|
|
32
36
|
export function resolveDirectoryQueryCommand(argv) {
|
|
33
37
|
const [action, ...rest] = argv;
|
|
34
|
-
if (action !== 'find' && action !== 'show' && action !== 'list'
|
|
35
|
-
|
|
38
|
+
if (action !== 'find' && action !== 'show' && action !== 'list'
|
|
39
|
+
&& action !== 'refresh' && action !== 'blocked') {
|
|
40
|
+
throw new DirectoryQueryError('INVALID_ACTION', 'directory requires one of: find, show, list, refresh, blocked');
|
|
36
41
|
}
|
|
37
42
|
const selfAid = takeFlag(rest, '--self') ?? process.env.EVOLCORE_SELF_AID?.trim();
|
|
38
43
|
if (!selfAid)
|
|
@@ -42,24 +47,38 @@ export function resolveDirectoryQueryCommand(argv) {
|
|
|
42
47
|
const scope = parseScope(takeFlag(rest, '--scope'));
|
|
43
48
|
const type = takeFlag(rest, '--type')?.trim() || undefined;
|
|
44
49
|
const limit = parseLimit(takeFlag(rest, '--limit'));
|
|
50
|
+
const ownerAid = parseOwnerFilter(takeFlag(rest, '--owner'));
|
|
45
51
|
const positional = takePositional(rest);
|
|
46
52
|
if (action === 'find') {
|
|
47
53
|
const query = positional.join(' ').trim();
|
|
48
54
|
if (!query)
|
|
49
55
|
throw new DirectoryQueryError('INVALID_ARGUMENT', 'find requires a query');
|
|
50
|
-
return {
|
|
56
|
+
return {
|
|
57
|
+
action, selfAid, query,
|
|
58
|
+
...(type ? { type } : {}), ...(scope ? { scope } : {}),
|
|
59
|
+
...(ownerAid ? { ownerAid } : {}), ...(limit ? { limit } : {}),
|
|
60
|
+
};
|
|
51
61
|
}
|
|
52
62
|
if (action === 'show') {
|
|
53
|
-
const
|
|
54
|
-
if (!
|
|
55
|
-
throw new DirectoryQueryError('INVALID_ARGUMENT', 'show requires a contact AID');
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
const target = positional.join(' ').trim();
|
|
64
|
+
if (!target)
|
|
65
|
+
throw new DirectoryQueryError('INVALID_ARGUMENT', 'show requires a contact AID or name');
|
|
66
|
+
// 名字里可能有空格(备注名/显示名允许),所以拼起来整体作为 target;
|
|
67
|
+
// 是不是 AID 由执行层判定,参数层不做格式假设。
|
|
68
|
+
return {
|
|
69
|
+
action, selfAid, target,
|
|
70
|
+
...(isValidAid(target) ? { aid: target } : {}),
|
|
71
|
+
...(limit ? { limit } : {}),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (positional.length > 0) {
|
|
75
|
+
throw new DirectoryQueryError('INVALID_ARGUMENT', `${action} takes no positional argument`);
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
action, selfAid,
|
|
79
|
+
...(type ? { type } : {}), ...(scope ? { scope } : {}),
|
|
80
|
+
...(ownerAid ? { ownerAid } : {}), ...(limit ? { limit } : {}),
|
|
81
|
+
};
|
|
63
82
|
}
|
|
64
83
|
/**
|
|
65
84
|
* 执行查询。
|
|
@@ -72,15 +91,30 @@ export async function executeDirectoryQueryCommand(command) {
|
|
|
72
91
|
if (!fs.existsSync(agentDir(command.selfAid))) {
|
|
73
92
|
return { ok: false, code: 'AGENT_NOT_FOUND', error: `agent ${command.selfAid} does not exist` };
|
|
74
93
|
}
|
|
75
|
-
|
|
94
|
+
// ownerAid 必须与磁盘上的授权一致:离线时 `ownerResolver` 只能给出 known owner,
|
|
95
|
+
// 可能与 authorization.json 里的 Owner 不同,那样 `scopeAccess` 会判成未授权。
|
|
96
|
+
const ownerAid = authorizedOwnerAid(directory, command.selfAid);
|
|
76
97
|
if (!ownerAid) {
|
|
77
|
-
return { ok: false, code: '
|
|
98
|
+
return { ok: false, code: 'NOT_AUTHORIZED', error: 'directory is not authorized for this agent' };
|
|
78
99
|
}
|
|
79
100
|
const cache = new OwnerDirectoryCache({ selfAid: command.selfAid, ownerAid, directory });
|
|
80
101
|
const scope = OWNER_DIRECTORY_SCOPES[0];
|
|
81
102
|
if (cache.scopeAccess(scope) !== 'authorized') {
|
|
82
103
|
return { ok: false, code: 'NOT_AUTHORIZED', error: 'directory is not authorized for this agent' };
|
|
83
104
|
}
|
|
105
|
+
// refresh 要在快照判空之前处理:它存在的意义正是"本地没有或太旧,去拉一次"。
|
|
106
|
+
if (command.action === 'refresh') {
|
|
107
|
+
const result = await refreshOwnerDirectory(command.selfAid);
|
|
108
|
+
// 拉取需要连接,重算不需要:只要本地重算成功就算成功,
|
|
109
|
+
// `pulled: false` 只表示"没有拉到新内容",不是失败。
|
|
110
|
+
if (!result.pulled && !result.regenerated) {
|
|
111
|
+
return { ok: false, code: 'REFRESH_UNAVAILABLE', error: 'directory is not available for this agent' };
|
|
112
|
+
}
|
|
113
|
+
return { ok: true, action: 'refresh', ...result };
|
|
114
|
+
}
|
|
115
|
+
if (command.action === 'blocked') {
|
|
116
|
+
return directoryBlockedEntries(command, directory, ownerAid, cache, scope);
|
|
117
|
+
}
|
|
84
118
|
let snapshot = cache.readSnapshot(scope);
|
|
85
119
|
if (!snapshot) {
|
|
86
120
|
return { ok: false, code: 'NO_SNAPSHOT', error: 'directory snapshot is not available yet' };
|
|
@@ -93,6 +127,7 @@ export async function executeDirectoryQueryCommand(command) {
|
|
|
93
127
|
query: command.query,
|
|
94
128
|
...(command.type ? { type: command.type } : {}),
|
|
95
129
|
...(command.scope ? { scope: command.scope } : {}),
|
|
130
|
+
...(command.ownerAid ? { ownerAid: command.ownerAid } : {}),
|
|
96
131
|
...(command.limit ? { limit: command.limit } : {}),
|
|
97
132
|
});
|
|
98
133
|
let synced = false;
|
|
@@ -105,6 +140,7 @@ export async function executeDirectoryQueryCommand(command) {
|
|
|
105
140
|
query: command.query,
|
|
106
141
|
...(command.type ? { type: command.type } : {}),
|
|
107
142
|
...(command.scope ? { scope: command.scope } : {}),
|
|
143
|
+
...(command.ownerAid ? { ownerAid: command.ownerAid } : {}),
|
|
108
144
|
...(command.limit ? { limit: command.limit } : {}),
|
|
109
145
|
});
|
|
110
146
|
}
|
|
@@ -112,21 +148,31 @@ export async function executeDirectoryQueryCommand(command) {
|
|
|
112
148
|
return { ok: true, action: 'find', hits, synced };
|
|
113
149
|
}
|
|
114
150
|
if (command.action === 'show') {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
151
|
+
const target = command.target ?? command.aid ?? '';
|
|
152
|
+
const lookup = (snap) => showTarget(snap, target, ownerAid, directory, contactable, command.limit);
|
|
153
|
+
let hit = lookup(snapshot);
|
|
154
|
+
let synced = false;
|
|
155
|
+
if (hit.entries.length === 0) {
|
|
156
|
+
// 与 find 同一条自愈路径:本地没有通常意味着"刚更新还没拉下来"。
|
|
157
|
+
synced = await syncOnce(command.selfAid);
|
|
118
158
|
const refreshed = cache.readSnapshot(scope);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return {
|
|
122
|
-
ok: false, code: 'NOT_FOUND',
|
|
123
|
-
error: `${command.aid} is not in the directory${synced ? ' (after a sync attempt)' : ''}`,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
const ref = ownerRefAid(refreshed, ownerAid);
|
|
127
|
-
return { ok: true, action: 'show', entry: describeEntry(found, ref, readRemark(directory, found.aid), contactable) };
|
|
159
|
+
if (refreshed)
|
|
160
|
+
hit = lookup(refreshed);
|
|
128
161
|
}
|
|
129
|
-
|
|
162
|
+
if (hit.entries.length === 0) {
|
|
163
|
+
return {
|
|
164
|
+
ok: false, code: 'NOT_FOUND',
|
|
165
|
+
error: `${target} is not in the directory${synced ? ' (after a sync attempt)' : ''}`,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
ok: true, action: 'show',
|
|
170
|
+
entries: hit.entries,
|
|
171
|
+
...(hit.entries.length === 1 ? { entry: hit.entries[0] } : {}),
|
|
172
|
+
matchedBy: hit.matchedBy,
|
|
173
|
+
...(hit.truncated ? { truncated: hit.truncated } : {}),
|
|
174
|
+
synced,
|
|
175
|
+
};
|
|
130
176
|
}
|
|
131
177
|
const typeFilter = command.type?.trim().toLowerCase();
|
|
132
178
|
const scopeFilter = command.scope ?? 'internal';
|
|
@@ -144,6 +190,118 @@ export async function executeDirectoryQueryCommand(command) {
|
|
|
144
190
|
.map(entry => describeEntry(entry, ownerRef, remarks.get(entry.aid), contactable));
|
|
145
191
|
return { ok: true, action: 'list', entries };
|
|
146
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* `ec directory blocked`:列出被拉黑的主体,两个来源合并。
|
|
195
|
+
*
|
|
196
|
+
* - `contacts.json` 的 `blocked_aids`:Owner 侧发布的拉黑,跨 Agent 生效;
|
|
197
|
+
* - `peers.json` 的 `blocked`:本端自己拉的,只对本 agent 生效。
|
|
198
|
+
*
|
|
199
|
+
* 两者都会让消息被拒,但语义不同,所以输出里标 `source`。名录里有这个 AID 时
|
|
200
|
+
* 补上名字,没在名录里也要列出来——拉黑的对象不一定还在名录里。
|
|
201
|
+
*/
|
|
202
|
+
function directoryBlockedEntries(command, directory, ownerAid, cache, scope) {
|
|
203
|
+
const snapshot = cache.readSnapshot(scope);
|
|
204
|
+
const ownerRef = ownerRefAid(snapshot, ownerAid);
|
|
205
|
+
const remarks = readAllRemarks(directory);
|
|
206
|
+
const contactable = resolveContactable(command.selfAid, cache);
|
|
207
|
+
const sources = new Map();
|
|
208
|
+
for (const aid of readBlockedAidsFromSnapshot(directory)) {
|
|
209
|
+
if (!sources.has(aid))
|
|
210
|
+
sources.set(aid, new Set());
|
|
211
|
+
sources.get(aid).add('owner');
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
for (const aid of getPeerSnapshot(command.selfAid).blockedIndex) {
|
|
215
|
+
if (!aid)
|
|
216
|
+
continue;
|
|
217
|
+
if (!sources.has(aid))
|
|
218
|
+
sources.set(aid, new Set());
|
|
219
|
+
sources.get(aid).add('local');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
// peers.json 坏了不影响名录侧的拉黑:能列多少列多少。
|
|
224
|
+
}
|
|
225
|
+
const entries = [...sources.entries()].map(([aid, sourceSet]) => {
|
|
226
|
+
const entry = snapshot?.entries.find(item => item.aid === aid);
|
|
227
|
+
const name = entry?.name ?? null;
|
|
228
|
+
return {
|
|
229
|
+
aid,
|
|
230
|
+
name,
|
|
231
|
+
...(entry?.type !== undefined ? { type: entry.type } : {}),
|
|
232
|
+
...(entry ? { internal: isInternalEntry(entry, ownerRef) } : {}),
|
|
233
|
+
inDirectory: !!entry,
|
|
234
|
+
source: [...sourceSet].sort().join(','),
|
|
235
|
+
// 黑名单条目一律不可联系;这里给的是"名录层面的可联系性",两者取与。
|
|
236
|
+
contactable: false,
|
|
237
|
+
...(entry ? { contactableForEntry: contactable(entry) } : {}),
|
|
238
|
+
};
|
|
239
|
+
}).sort((a, b) => a.aid.localeCompare(b.aid));
|
|
240
|
+
return { ok: true, action: 'blocked', entries };
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* 读本地快照文件里的 `blocked_aids`。
|
|
244
|
+
*
|
|
245
|
+
* 快照对象(`OwnerDirectorySnapshot`)不保留这一项——准入只关心条目,拉黑
|
|
246
|
+
* 走的是另一条判据;这里为 `ec directory blocked` 直接读原始文件。格式按协议是
|
|
247
|
+
* `{ target_type: 'aid'|'group', target_id }`,也容忍纯字符串数组。
|
|
248
|
+
*/
|
|
249
|
+
function readBlockedAidsFromSnapshot(directory) {
|
|
250
|
+
try {
|
|
251
|
+
const raw = JSON.parse(fs.readFileSync(path.join(directory, 'contacts.json'), 'utf8'));
|
|
252
|
+
const list = raw?.blockedAids
|
|
253
|
+
?? raw?.blocked_aids;
|
|
254
|
+
if (!Array.isArray(list))
|
|
255
|
+
return [];
|
|
256
|
+
const aids = [];
|
|
257
|
+
for (const item of list) {
|
|
258
|
+
const aid = typeof item === 'string'
|
|
259
|
+
? item
|
|
260
|
+
: (item && typeof item === 'object' && typeof item.target_id === 'string'
|
|
261
|
+
? String(item.target_id) : '');
|
|
262
|
+
if (aid && isValidAid(aid))
|
|
263
|
+
aids.push(aid);
|
|
264
|
+
}
|
|
265
|
+
return aids;
|
|
266
|
+
}
|
|
267
|
+
catch {
|
|
268
|
+
return [];
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* `show` 的目标解析:合法 AID 精确匹配;否则当名字匹配(显示名或本地备注名,
|
|
273
|
+
* 精确等于,不模糊),多个同名时全部返回。
|
|
274
|
+
*
|
|
275
|
+
* 备注名优先级与渲染一致:本地备注 > 远端 remark > 远端 name。
|
|
276
|
+
*/
|
|
277
|
+
function showTarget(snapshot, target, ownerAid, directory, contactable,
|
|
278
|
+
/** 同名多条时的上限;不传按 20 条封顶,防止一个常见名字把上下文灌满。 */
|
|
279
|
+
limit) {
|
|
280
|
+
const ownerRef = ownerRefAid(snapshot, ownerAid);
|
|
281
|
+
const remarks = readAllRemarks(directory);
|
|
282
|
+
if (isValidAid(target)) {
|
|
283
|
+
const entry = snapshot.entries.find((item) => item.aid === target);
|
|
284
|
+
return {
|
|
285
|
+
matchedBy: 'aid',
|
|
286
|
+
entries: entry ? [describeEntry(entry, ownerRef, remarks.get(entry.aid), contactable)] : [],
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
const wanted = target.trim();
|
|
290
|
+
const matches = snapshot.entries.filter((entry) => {
|
|
291
|
+
const remark = remarks.get(entry.aid);
|
|
292
|
+
// 所有叫法都参与:名录名、Owner 的备注名、本地记的每一个称呼。
|
|
293
|
+
const names = [entry.name, entry.remark, ...(remark?.aliases ?? [remark?.remark ?? ''])]
|
|
294
|
+
.map(value => (typeof value === 'string' ? value.trim() : ''))
|
|
295
|
+
.filter(Boolean);
|
|
296
|
+
return names.includes(wanted);
|
|
297
|
+
});
|
|
298
|
+
const cap = limit ?? SHOW_NAME_MATCH_LIMIT;
|
|
299
|
+
return {
|
|
300
|
+
matchedBy: 'name',
|
|
301
|
+
entries: matches.slice(0, cap).map((entry) => describeEntry(entry, ownerRef, remarks.get(entry.aid), contactable)),
|
|
302
|
+
...(matches.length > cap ? { truncated: matches.length - cap } : {}),
|
|
303
|
+
};
|
|
304
|
+
}
|
|
147
305
|
/**
|
|
148
306
|
* 一次有界同步(B 方案):用 channel 注册着的活缓存触发,和准入路径共用
|
|
149
307
|
* 模块级单飞。查询用的只读实例没有网络能力——没有活缓存时返回 false,
|
|
@@ -152,9 +310,20 @@ export async function executeDirectoryQueryCommand(command) {
|
|
|
152
310
|
async function syncOnce(selfAid) {
|
|
153
311
|
return syncOwnerDirectoryForLookup(selfAid);
|
|
154
312
|
}
|
|
155
|
-
/**
|
|
313
|
+
/**
|
|
314
|
+
* 这条名录条目现在能不能联系。
|
|
315
|
+
*
|
|
316
|
+
* 逐条判定而不是整份一个布尔:内部条目看内部档,外部条目看外部档,白名单与
|
|
317
|
+
* 黑名单各自优先。只算一次 `allowExternalContacts` 就套给所有条目,会把
|
|
318
|
+
* 内部联系人一起标成"不可联系"。
|
|
319
|
+
*/
|
|
156
320
|
function resolveContactable(selfAid, cache) {
|
|
157
|
-
|
|
321
|
+
const snapshot = cache.readSnapshot(OWNER_DIRECTORY_SCOPES[0]);
|
|
322
|
+
const ownerRef = ownerRefAid(snapshot, ownerResolver.owner(selfAid) ?? '');
|
|
323
|
+
return entry => resolveEntryContactable(selfAid, snapshot, {
|
|
324
|
+
aid: entry.aid,
|
|
325
|
+
internal: isInternalEntry(entry, ownerRef),
|
|
326
|
+
});
|
|
158
327
|
}
|
|
159
328
|
function takeFlag(args, flag) {
|
|
160
329
|
const index = args.indexOf(flag);
|
|
@@ -185,6 +354,24 @@ function parseScope(value) {
|
|
|
185
354
|
return value;
|
|
186
355
|
throw new DirectoryQueryError('INVALID_ARGUMENT', '--scope must be internal, external or all');
|
|
187
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* `--owner <aid|unbound>`:按条目归属过滤。
|
|
359
|
+
*
|
|
360
|
+
* `unbound` 是保留值,表示"名录里没有 owner_aid 的条目"——那批人内外判断不了,
|
|
361
|
+
* 列出来通常是排查用。其余值必须是合法 AID。
|
|
362
|
+
*/
|
|
363
|
+
function parseOwnerFilter(value) {
|
|
364
|
+
if (value === undefined)
|
|
365
|
+
return undefined;
|
|
366
|
+
const trimmed = value.trim();
|
|
367
|
+
if (!trimmed)
|
|
368
|
+
throw new DirectoryQueryError('INVALID_ARGUMENT', '--owner requires a value');
|
|
369
|
+
if (trimmed === 'unbound')
|
|
370
|
+
return trimmed;
|
|
371
|
+
if (!isValidAid(trimmed))
|
|
372
|
+
throw new DirectoryQueryError('INVALID_ARGUMENT', `invalid --owner AID: ${trimmed}`);
|
|
373
|
+
return trimmed;
|
|
374
|
+
}
|
|
188
375
|
function parseLimit(value) {
|
|
189
376
|
if (value === undefined)
|
|
190
377
|
return undefined;
|
|
@@ -57,15 +57,37 @@ export function parseRemarkFile(text, expectedAid) {
|
|
|
57
57
|
const declaredAid = fields.aid;
|
|
58
58
|
if (!declaredAid || declaredAid !== expectedAid)
|
|
59
59
|
return undefined;
|
|
60
|
-
|
|
60
|
+
// 称呼可以有多个:`remark: 蒋总, 老蒋`。统一按中英文逗号、顿号与空白切分。
|
|
61
|
+
const aliases = splitAliases(fields.remark);
|
|
62
|
+
const remark = aliases.length > 0 ? fields.remark : undefined;
|
|
61
63
|
const updatedAt = /^\d+$/.test(fields.updated_at ?? '') ? Number(fields.updated_at) : undefined;
|
|
62
64
|
return {
|
|
63
65
|
aid: declaredAid,
|
|
64
66
|
...(remark !== undefined ? { remark } : {}),
|
|
67
|
+
...(aliases.length > 0 ? { aliases } : {}),
|
|
65
68
|
...(body ? { body } : {}),
|
|
66
69
|
...(updatedAt !== undefined ? { updatedAt } : {}),
|
|
67
70
|
};
|
|
68
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* 拆分称呼:中英文逗号、顿号、分号与空白都算分隔符,去重保序。
|
|
74
|
+
*
|
|
75
|
+
* 只写一个称呼时行为与以前完全一致(返回单元素数组)。
|
|
76
|
+
*/
|
|
77
|
+
export function splitAliases(value) {
|
|
78
|
+
if (!value)
|
|
79
|
+
return [];
|
|
80
|
+
const seen = new Set();
|
|
81
|
+
const out = [];
|
|
82
|
+
for (const part of String(value).split(/[,,、;;\s]+/)) {
|
|
83
|
+
const alias = part.trim();
|
|
84
|
+
if (!alias || seen.has(alias))
|
|
85
|
+
continue;
|
|
86
|
+
seen.add(alias);
|
|
87
|
+
out.push(alias);
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
69
91
|
export function serializeRemarkFile(remark) {
|
|
70
92
|
const lines = ['---', `aid: ${remark.aid}`];
|
|
71
93
|
if (remark.remark)
|
|
@@ -138,8 +160,13 @@ export function removeRemark(directory, aid) {
|
|
|
138
160
|
atomicRemove(file);
|
|
139
161
|
return true;
|
|
140
162
|
}
|
|
163
|
+
/** 备注清单。`remark` 是称呼、`body` 是正文,两者可独立存在。 */
|
|
141
164
|
export function listRemarks(directory) {
|
|
142
165
|
return [...readAllRemarks(directory).values()]
|
|
143
|
-
.map(({ aid, remark }) => ({
|
|
166
|
+
.map(({ aid, remark, body }) => ({
|
|
167
|
+
aid,
|
|
168
|
+
...(remark !== undefined ? { remark } : {}),
|
|
169
|
+
...(body !== undefined ? { body } : {}),
|
|
170
|
+
}))
|
|
144
171
|
.sort((a, b) => a.aid.localeCompare(b.aid));
|
|
145
172
|
}
|
|
@@ -23,10 +23,6 @@ const WEIGHT = {
|
|
|
23
23
|
descriptionContains: 150,
|
|
24
24
|
exactType: 100,
|
|
25
25
|
};
|
|
26
|
-
/** 这个人就是当前 agent 的个人助理。 */
|
|
27
|
-
export function isPersonalAssistantSnapshot(selfAid, snapshot) {
|
|
28
|
-
return !!snapshot?.personalAssistant?.aid && snapshot.personalAssistant.aid === selfAid;
|
|
29
|
-
}
|
|
30
26
|
export function searchDirectory(snapshot, ownerAid, remarks, options) {
|
|
31
27
|
if (!snapshot)
|
|
32
28
|
return [];
|
|
@@ -38,6 +34,7 @@ export function searchDirectory(snapshot, ownerAid, remarks, options) {
|
|
|
38
34
|
// 默认查全部:注入里的外部条目只有名字,模型要靠 find 才能拿到 AID。
|
|
39
35
|
const scope = options.scope ?? 'all';
|
|
40
36
|
const typeFilter = options.type?.trim().toLowerCase();
|
|
37
|
+
const ownerFilter = options.ownerAid?.trim().toLowerCase();
|
|
41
38
|
const hits = [];
|
|
42
39
|
for (const entry of snapshot.entries) {
|
|
43
40
|
const internal = isInternalEntry(entry, ownerRef);
|
|
@@ -47,15 +44,21 @@ export function searchDirectory(snapshot, ownerAid, remarks, options) {
|
|
|
47
44
|
continue;
|
|
48
45
|
if (typeFilter && (entry.type ?? '').toLowerCase() !== typeFilter)
|
|
49
46
|
continue;
|
|
50
|
-
|
|
47
|
+
if (ownerFilter) {
|
|
48
|
+
const entryOwner = (entry.ownerAid ?? '').trim().toLowerCase();
|
|
49
|
+
if (ownerFilter === 'unbound' ? entryOwner !== '' : entryOwner !== ownerFilter)
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
// 三段叫法**同时参与搜索**:名录名、Owner 写的备注名、自己记的称呼。
|
|
53
|
+
// 谁都不顶替谁——Owner 口语里任何一个叫法落到这里都必须能搜到,否则下一次
|
|
54
|
+
// 他换一种叫法提到同一个人,就又得重新翻一遍。
|
|
51
55
|
const remark = remarks?.get(entry.aid);
|
|
52
|
-
const
|
|
53
|
-
const effectiveDescription = remark?.body ?? entry.description;
|
|
56
|
+
const localNote = remark?.body;
|
|
54
57
|
let score = 0;
|
|
55
58
|
const matched = new Set();
|
|
56
59
|
let allTokensHit = true;
|
|
57
60
|
for (const token of tokens) {
|
|
58
|
-
const best = scoreToken(token, entry,
|
|
61
|
+
const best = scoreToken(token, entry, remark, localNote);
|
|
59
62
|
if (best.score === 0) {
|
|
60
63
|
allTokensHit = false;
|
|
61
64
|
break;
|
|
@@ -71,8 +74,13 @@ export function searchDirectory(snapshot, ownerAid, remarks, options) {
|
|
|
71
74
|
...(entry.type !== undefined ? { type: entry.type } : {}),
|
|
72
75
|
...(entry.exttype !== undefined ? { exttype: entry.exttype } : {}),
|
|
73
76
|
...(entry.baseagent !== undefined ? { baseagent: entry.baseagent } : {}),
|
|
74
|
-
...(
|
|
75
|
-
|
|
77
|
+
...(remark?.remark !== undefined
|
|
78
|
+
? { remark: remark.remark }
|
|
79
|
+
: entry.remark !== undefined ? { remark: entry.remark } : {}),
|
|
80
|
+
...(remark?.aliases !== undefined ? { aliases: remark.aliases } : {}),
|
|
81
|
+
...(entry.remark !== undefined ? { ownerRemark: entry.remark } : {}),
|
|
82
|
+
...(entry.description !== undefined ? { description: entry.description } : {}),
|
|
83
|
+
...(localNote !== undefined ? { localRemark: localNote } : {}),
|
|
76
84
|
internal,
|
|
77
85
|
matched: [...matched],
|
|
78
86
|
score,
|
|
@@ -85,7 +93,7 @@ export function searchDirectory(snapshot, ownerAid, remarks, options) {
|
|
|
85
93
|
|| a.aid.localeCompare(b.aid));
|
|
86
94
|
return hits.slice(0, limit);
|
|
87
95
|
}
|
|
88
|
-
function scoreToken(token, entry, remark,
|
|
96
|
+
function scoreToken(token, entry, remark, localNote) {
|
|
89
97
|
const aid = entry.aid.toLowerCase();
|
|
90
98
|
const name = entry.name.toLowerCase();
|
|
91
99
|
const exttype = (entry.exttype ?? '').toLowerCase();
|
|
@@ -97,8 +105,13 @@ function scoreToken(token, entry, remark, description) {
|
|
|
97
105
|
return { score: WEIGHT.exactName, field: 'name' };
|
|
98
106
|
if (aid.startsWith(token) || name.startsWith(token))
|
|
99
107
|
return { score: WEIGHT.prefix, field: 'prefix' };
|
|
100
|
-
|
|
108
|
+
// 任何叫法精确命中都算:名录名、Owner 写的备注名、自己记的每一个称呼。
|
|
109
|
+
const localAliases = remark?.aliases ?? (remark?.remark ? [remark.remark] : []);
|
|
110
|
+
if (localAliases.some(alias => alias.toLowerCase() === token)) {
|
|
101
111
|
return { score: WEIGHT.exactRemark, field: 'remark' };
|
|
112
|
+
}
|
|
113
|
+
if (entry.remark && entry.remark.toLowerCase() === token)
|
|
114
|
+
return { score: WEIGHT.exactRemark, field: 'ownerRemark' };
|
|
102
115
|
// AID 的域段先于普通包含判定:`find agentid.cn` 是"列出这个域",不是"名字里有这段字"。
|
|
103
116
|
const domain = aid.slice(aid.indexOf('.') + 1);
|
|
104
117
|
if (domain.includes(token))
|
|
@@ -107,30 +120,49 @@ function scoreToken(token, entry, remark, description) {
|
|
|
107
120
|
return { score: WEIGHT.contains, field: 'name' };
|
|
108
121
|
if (exttype === token || baseagent === token)
|
|
109
122
|
return { score: WEIGHT.exactExttype, field: 'exttype' };
|
|
110
|
-
if (description && description.toLowerCase().includes(token)) {
|
|
123
|
+
if (entry.description && entry.description.toLowerCase().includes(token)) {
|
|
111
124
|
return { score: WEIGHT.descriptionContains, field: 'description' };
|
|
112
125
|
}
|
|
113
|
-
|
|
126
|
+
// 本地备注正文与远端描述并列参与:它是 PA 自己记的"什么事该找他",是找人的主要线索之一。
|
|
127
|
+
if (localNote && localNote.toLowerCase().includes(token)) {
|
|
128
|
+
return { score: WEIGHT.descriptionContains, field: 'localNote' };
|
|
129
|
+
}
|
|
130
|
+
if (localAliases.some(alias => alias.toLowerCase().includes(token))) {
|
|
114
131
|
return { score: WEIGHT.descriptionContains, field: 'remark' };
|
|
115
132
|
}
|
|
133
|
+
if (entry.remark && entry.remark.toLowerCase().includes(token)) {
|
|
134
|
+
return { score: WEIGHT.descriptionContains, field: 'ownerRemark' };
|
|
135
|
+
}
|
|
116
136
|
if (type === token)
|
|
117
137
|
return { score: WEIGHT.exactType, field: 'type' };
|
|
118
138
|
return { score: 0, field: '' };
|
|
119
139
|
}
|
|
120
|
-
/**
|
|
140
|
+
/**
|
|
141
|
+
* 单个条目的完整记录,用于 `show`。描述与备注不截断。
|
|
142
|
+
*
|
|
143
|
+
* `contactable` 传的是"这条目能不能联系"的判定函数,不是统一布尔:内部与外部
|
|
144
|
+
* 受不同开关约束,白名单与黑名单又各自优先,算一次再套给所有条目必然错。
|
|
145
|
+
* 传布尔时按原样使用(老调用方与单测)。
|
|
146
|
+
*/
|
|
121
147
|
export function describeEntry(entry, ownerRef, remark, contactable) {
|
|
148
|
+
const internal = isInternalEntry(entry, ownerRef);
|
|
149
|
+
const contactableValue = typeof contactable === 'function' ? contactable(entry) : contactable;
|
|
122
150
|
return {
|
|
123
151
|
aid: entry.aid,
|
|
124
152
|
name: entry.name,
|
|
125
153
|
type: entry.type ?? null,
|
|
126
154
|
exttype: entry.exttype ?? null,
|
|
127
155
|
baseagent: entry.baseagent ?? null,
|
|
156
|
+
// 远端字段与本地备注并列返回,不互相覆盖:调用方要判断"对方本来是什么样"
|
|
157
|
+
// 和"我记了什么"是两件事。要在渲染里二选一由调用方决定。
|
|
128
158
|
remark: remark?.remark ?? entry.remark ?? null,
|
|
129
|
-
|
|
159
|
+
aliases: remark?.aliases ?? null,
|
|
160
|
+
description: entry.description ?? null,
|
|
161
|
+
localRemark: remark?.body ?? null,
|
|
130
162
|
ownershipStatus: entry.ownership_status ?? null,
|
|
131
163
|
agentMdSignedAt: entry.agent_md_signed_at ?? null,
|
|
132
|
-
internal
|
|
133
|
-
contactable,
|
|
164
|
+
internal,
|
|
165
|
+
contactable: contactableValue,
|
|
134
166
|
remarkSource: remark ? 'local' : 'remote',
|
|
135
167
|
};
|
|
136
168
|
}
|