evolcore 0.0.41-test.1 → 0.0.41-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 +49 -36
- package/dist/agents/baseagent.js +68 -6
- package/dist/agents/codex-runner.js +62 -43
- package/dist/aun/aid/agentmd.js +98 -11
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/aid/control-aid.js +26 -2
- package/dist/aun/aid/identity.js +91 -0
- package/dist/aun/aid/index.js +1 -1
- package/dist/aun/aid/managed-operation.js +1 -1
- package/dist/aun/aid/ownership-operation.js +23 -22
- package/dist/aun/menu/client.js +27 -0
- package/dist/aun/msg/p2p.js +3 -8
- package/dist/aun/service-proxy.js +17 -0
- package/dist/channels/aun.js +321 -34
- package/dist/cli/agent-command.js +5 -2
- package/dist/cli/agent-create.js +991 -233
- package/dist/cli/agent.js +49 -10
- package/dist/cli/aid-bind-command.js +48 -19
- package/dist/cli/aun-commands.js +44 -16
- package/dist/cli/daemon-commands.js +1 -0
- package/dist/cli/index.js +24 -1
- package/dist/cli/init-channel.js +1 -1
- package/dist/cli/init.js +75 -1
- package/dist/cli/managed-command-guard.js +13 -1
- package/dist/cli/provider-command.js +57 -0
- package/dist/cli/restart-monitor.js +4 -2
- package/dist/cli/stats.js +10 -3
- package/dist/cli/task-context.js +19 -0
- package/dist/config/boot-log.js +3 -2
- package/dist/config/config-field-policy.js +12 -7
- package/dist/config/config-manager.js +138 -6
- package/dist/config/owner-config.js +2 -2
- package/dist/config/peer-role-resolver.js +2 -1
- package/dist/config/provider-ipc-service.js +132 -0
- package/dist/config/provider-menu-request.js +58 -0
- package/dist/config/providers-management.js +78 -5
- package/dist/config/resolved-config-op.js +8 -1
- package/dist/config/schema-migration.js +322 -8
- package/dist/config-store.js +10 -1
- package/dist/contracts/ecweb-service-protocol.js +2 -1
- package/dist/core/agent-application-service.js +60 -11
- package/dist/core/agent-create-status.js +203 -0
- package/dist/core/agent-creation-claim.js +177 -0
- package/dist/core/agent-ipc-registration.js +39 -18
- package/dist/core/agent-runtime.js +193 -23
- package/dist/core/auth/agent-delegation.js +4 -2
- package/dist/core/auth/auth-gateway.js +66 -1
- package/dist/core/auth/authorization-audit.js +41 -5
- package/dist/core/auth/delegation-authorization.js +2 -1
- package/dist/core/auth/operation-authorizer.js +28 -6
- package/dist/core/auth/operation-catalog.js +14 -1
- package/dist/core/channel-loader.js +2 -0
- package/dist/core/command/agent-control.js +257 -14
- package/dist/core/command/cli-intent-parser.js +6 -2
- package/dist/core/command/command-handler.js +64 -55
- package/dist/core/command/memory-slash.js +1 -1
- package/dist/core/command/menu-catalog.js +5 -0
- package/dist/core/command/menu-handler.js +64 -18
- package/dist/core/command/menu-protocol.js +15 -1
- package/dist/core/command/provider-menu.js +46 -0
- package/dist/core/command/slash-handler.js +2 -1
- package/dist/core/daemon-control.js +18 -13
- package/dist/core/event-catalog.js +10 -0
- package/dist/core/evolagent-registry.js +3 -1
- package/dist/core/evolagent.js +8 -6
- package/dist/core/file-integrity/store.js +11 -0
- package/dist/core/handoff/ipc-registration.js +3 -0
- package/dist/core/initialization/service.js +491 -0
- package/dist/core/ipc-registration.js +34 -22
- package/dist/core/memory/consolidation-ops-records.js +95 -0
- package/dist/core/memory/consolidation-trigger.js +19 -2
- package/dist/core/memory/consolidation.js +19 -8
- package/dist/core/memory/memory-admin.js +1 -1
- package/dist/core/memory/relation-sweep.js +11 -6
- package/dist/core/message/aun-ipc-sender.js +73 -67
- package/dist/core/message/im-renderer.js +18 -0
- package/dist/core/message/message-bridge.js +35 -3
- package/dist/core/message/response-engine.js +32 -28
- package/dist/core/model/catalog-service.js +1 -1
- package/dist/core/model/config-scope.js +5 -7
- package/dist/core/ownership/owner-resolver.js +755 -143
- package/dist/core/permission/approval-gateway.js +103 -403
- package/dist/core/permission/ec-command-parser.js +32 -4
- package/dist/core/permission/index.js +1 -0
- package/dist/core/permission/permission-result.js +78 -0
- package/dist/core/permission/tool-policy.js +7 -43
- package/dist/core/system-session/memory.js +37 -7
- package/dist/directory/owner-directory-cache.js +2 -2
- package/dist/ecweb/init-menu.js +32 -0
- package/dist/index.js +17 -5
- package/dist/ipc.js +85 -25
- package/dist/paths.js +3 -0
- package/dist/proxy/manager.js +6 -7
- package/dist/trigger/authorization.js +27 -17
- package/dist/trigger/feedback.js +2 -3
- package/dist/trigger/ipc-service.js +105 -78
- package/dist/trigger/local-files.js +2 -1
- package/dist/trigger/manager.js +5 -3
- package/dist/trigger/scheduler.js +88 -6
- package/dist/utils/atomic-write.js +28 -0
- package/dist/utils/error-utils.js +24 -0
- package/dist/utils/logger.js +68 -1
- package/dist/utils/welcome.js +1 -1
- package/kits/docs/INDEX.md +1 -0
- package/kits/docs/aun/SDK.md +4 -1
- package/kits/docs/evolcore/INDEX.md +1 -0
- package/kits/docs/evolcore/agent.md +8 -1
- package/kits/docs/evolcore/aid.md +67 -17
- package/kits/docs/evolcore/config.md +11 -1
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/provider.md +50 -0
- package/kits/docs/identity/AID_PROFILE_SPEC.md +52 -17
- package/kits/rules/01-overview.md +3 -0
- package/kits/rules/04-relation.md +1 -1
- package/kits/schemas/_meta.json +2 -2
- package/kits/schemas/agent-config.schema.16.json +3 -3
- package/kits/schemas/relation-config.schema.11.json +17 -0
- package/kits/skills/.switches.json +8 -0
- package/kits/skills/ec-agent-create/SKILL.md +3 -0
- package/kits/skills/ec-identity/SKILL.md +2 -2
- package/kits/skills/ec-skill/scripts/skill.mjs +6 -0
- package/kits/skills/ec-trigger/SKILL.md +5 -13
- package/kits/skills/thread-ops/SKILL.md +5 -0
- package/kits/templates/system-fragments/venue.md +1 -1
- package/package.json +3 -3
- package/dist/core/memory/forget-log.js +0 -96
- package/dist/core/message/create-status.js +0 -96
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
* - session-start / session-end:会话级别的开始/结束记录
|
|
6
6
|
* - create / update / archive:每次写操作的结果
|
|
7
7
|
* - summary:会话结束时的汇总行
|
|
8
|
+
* - FORGET-LOG.md:按记忆作用域保留遗忘、手动归档与回撤记录
|
|
8
9
|
*
|
|
9
10
|
* session-end 写在 onConsolidationComplete 里,失败时可依据 ops.jsonl 逐条回撤。
|
|
10
11
|
*/
|
|
11
12
|
import fs from 'fs';
|
|
12
13
|
import path from 'path';
|
|
14
|
+
import { logger } from '../../utils/logger.js';
|
|
13
15
|
/** 向 ops 记录文件追加一条记录。失败静默,不影响主流程。 */
|
|
14
16
|
export function appendOpsRecord(batchDir, entry) {
|
|
15
17
|
try {
|
|
@@ -187,3 +189,96 @@ export function readContextBytes(batchDir) {
|
|
|
187
189
|
return 0;
|
|
188
190
|
}
|
|
189
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* 遗忘日志 FORGET-LOG.md(审计记录,不是记忆)
|
|
194
|
+
*
|
|
195
|
+
* 遗忘机制每动一条记忆,就在**该记忆所在层**的 `archive/FORGET-LOG.md` 追加一行:
|
|
196
|
+
* 时间、动作、记忆、理由、来源。理由是针对这一条记忆的,不是针对一次整理的
|
|
197
|
+
* (一次整理的总结是 feedback,记录在上面的 session-end 中)。
|
|
198
|
+
*
|
|
199
|
+
* 只记遗忘:forget 会话里的续期 / 归档 / 合并归档、它们的回撤,以及会话外的
|
|
200
|
+
* `/memory archive` / `/memory restore`。其他模式 `--replaces` 产生的归档不记——
|
|
201
|
+
* 那是记忆产生与泛化的过程,理由在 ops.jsonl。长期记忆的推迟审查(deferCandidate)
|
|
202
|
+
* 只刷 mtime,也不记。
|
|
203
|
+
*
|
|
204
|
+
* 放在 archive/ 下:archive/ 不在任何索引与召回路径上(rebuildIndex 只扫 consolidated/,
|
|
205
|
+
* `/memory list --archived` 只扫 archive/consolidated/),整理会话的读取范围也不含它。
|
|
206
|
+
* 只追加、不轮转,不随整理批次目录清理。只由 daemon 写,模型只能经 ec memory 命令间接产生行。
|
|
207
|
+
*/
|
|
208
|
+
/** 审计日志,不是记忆,不进索引。路径相对 memory 根目录。 */
|
|
209
|
+
export const FORGET_LOG_RELPATH = path.join('archive', 'FORGET-LOG.md');
|
|
210
|
+
/** 理由上限(按码点计)。超长拒绝而不截断:截断会丢意思,让模型自己缩短。 */
|
|
211
|
+
export const FORGET_REASON_MAX_CHARS = 80;
|
|
212
|
+
const HEADER = [
|
|
213
|
+
'# 遗忘日志',
|
|
214
|
+
'',
|
|
215
|
+
'> 审计记录,不是记忆,不进索引。由 daemon 追加,请勿手改。',
|
|
216
|
+
'',
|
|
217
|
+
'| 时间 | 动作 | 记忆 | 理由 | 来源 |',
|
|
218
|
+
'|---|---|---|---|---|',
|
|
219
|
+
'',
|
|
220
|
+
].join('\n');
|
|
221
|
+
export function forgetLogPath(memoryDir) {
|
|
222
|
+
return path.join(memoryDir, FORGET_LOG_RELPATH);
|
|
223
|
+
}
|
|
224
|
+
/** 理由归一:去首尾空白,换行与连续空白压成一个空格。 */
|
|
225
|
+
export function normalizeForgetReason(raw) {
|
|
226
|
+
return (raw ?? '').replace(/\s+/g, ' ').trim();
|
|
227
|
+
}
|
|
228
|
+
/** 校验理由:必填、≤80 字。返回归一后的理由,或给模型看的错误说明。 */
|
|
229
|
+
export function checkForgetReason(raw) {
|
|
230
|
+
const reason = normalizeForgetReason(raw);
|
|
231
|
+
if (!reason) {
|
|
232
|
+
return { ok: false, error: "forget 模式每条操作都要带 --reason '<理由>',说明这一条记忆为什么续期 / 归档 / 合并" };
|
|
233
|
+
}
|
|
234
|
+
const len = [...reason].length;
|
|
235
|
+
if (len > FORGET_REASON_MAX_CHARS) {
|
|
236
|
+
return { ok: false, error: `--reason 不能超过 ${FORGET_REASON_MAX_CHARS} 字(当前 ${len} 字),请缩短后重试` };
|
|
237
|
+
}
|
|
238
|
+
return { ok: true, reason };
|
|
239
|
+
}
|
|
240
|
+
/** 记忆文件路径 → slug。归档目标可能带时间戳后缀,调用方应传源路径。 */
|
|
241
|
+
export function slugOfMemoryFile(filePath) {
|
|
242
|
+
return path.basename(filePath).replace(/\.md$/, '');
|
|
243
|
+
}
|
|
244
|
+
/** 来源列:整理会话用批次目录名(带 agent AID,owner 层多 agent 共用时靠它区分)。 */
|
|
245
|
+
export function batchSourceLabel(batchDir) {
|
|
246
|
+
return batchDir ? path.basename(batchDir) : 'forget';
|
|
247
|
+
}
|
|
248
|
+
function cell(value) {
|
|
249
|
+
return normalizeForgetReason(value).replace(/\|/g, '\\|');
|
|
250
|
+
}
|
|
251
|
+
function formatLocalTime(d) {
|
|
252
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
253
|
+
const offsetMin = -d.getTimezoneOffset();
|
|
254
|
+
const sign = offsetMin >= 0 ? '+' : '-';
|
|
255
|
+
const abs = Math.abs(offsetMin);
|
|
256
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} `
|
|
257
|
+
+ `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())} `
|
|
258
|
+
+ `${sign}${pad(Math.floor(abs / 60))}:${pad(abs % 60)}`;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* 追加一行。文件不存在时先写表头。
|
|
262
|
+
* 失败只告警不抛:文件操作已经成功,不能因为日志写不进去让调用方以为操作失败。
|
|
263
|
+
* 返回是否写入成功,回撤据此决定要不要补「撤销」行。
|
|
264
|
+
*/
|
|
265
|
+
export function appendForgetLog(memoryDir, row) {
|
|
266
|
+
const line = `| ${formatLocalTime(row.now ?? new Date())} | ${cell(row.action)} | ${cell(row.slug)} | ${cell(row.reason)} | ${cell(row.source)} |\n`;
|
|
267
|
+
const filePath = forgetLogPath(memoryDir);
|
|
268
|
+
try {
|
|
269
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
270
|
+
try {
|
|
271
|
+
fs.writeFileSync(filePath, HEADER, { encoding: 'utf-8', flag: 'wx' });
|
|
272
|
+
}
|
|
273
|
+
catch (e) {
|
|
274
|
+
if (e?.code !== 'EEXIST')
|
|
275
|
+
throw e;
|
|
276
|
+
}
|
|
277
|
+
fs.appendFileSync(filePath, line, 'utf-8');
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
280
|
+
catch (e) {
|
|
281
|
+
logger.warn(`[Memory] 遗忘日志写入失败(${filePath}): ${e?.message};未记入的行: ${line.trim()}`);
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
@@ -379,7 +379,7 @@ export function checkConsolidationCandidates(params) {
|
|
|
379
379
|
.map(d => d.name)
|
|
380
380
|
: [];
|
|
381
381
|
const useMetaIndex = params.useMetaIndex ?? false;
|
|
382
|
-
for (const peerKey of peerKeys) {
|
|
382
|
+
for (const peerKey of params.ownerOnly ? [] : peerKeys) {
|
|
383
383
|
const memDir = relationMemoryDir(root, selfAid, peerKey);
|
|
384
384
|
// ① 画像到期 → profile(退避:距上次尝试不满 profileRegenDays 不再拉起)
|
|
385
385
|
if (profileDueWithMeta(memDir, now, config.profileRegenDays, useMetaIndex)
|
|
@@ -393,7 +393,7 @@ export function checkConsolidationCandidates(params) {
|
|
|
393
393
|
}
|
|
394
394
|
// ③ agent 层超期 → forget scope=agent(只审 personal/memory 自身)
|
|
395
395
|
const agentConsolidated = path.join(root, 'agents', selfAid, 'personal', 'memory', 'consolidated');
|
|
396
|
-
if (config.enableAgent && checkStale(agentConsolidated, now, config.forgetAfterDays) > 0) {
|
|
396
|
+
if (!params.ownerOnly && config.enableAgent && checkStale(agentConsolidated, now, config.forgetAfterDays) > 0) {
|
|
397
397
|
out.push({ mode: 'forget', scope: 'agent', reason: 'agent 级记忆超期' });
|
|
398
398
|
}
|
|
399
399
|
// ④ owner 层超期 → forget scope=owner(owner 层与 agent / relation 层是平行的)
|
|
@@ -415,3 +415,20 @@ export function checkConsolidationCandidates(params) {
|
|
|
415
415
|
}
|
|
416
416
|
return out;
|
|
417
417
|
}
|
|
418
|
+
export function hasOwnerConsolidationCandidates(params) {
|
|
419
|
+
const config = effectiveConfig(params.config);
|
|
420
|
+
if (!config.enableRelation || !config.enableOwner)
|
|
421
|
+
return false;
|
|
422
|
+
const root = params.root ?? resolveRoot();
|
|
423
|
+
const agentConsolidated = path.join(root, 'agents', params.selfAid, 'personal', 'memory', 'consolidated');
|
|
424
|
+
if (countTaggedIn(agentConsolidated, 'to-promote') > 0)
|
|
425
|
+
return true;
|
|
426
|
+
const ownersDir = path.join(root, 'memory', 'owner');
|
|
427
|
+
const owners = params.ownerAid ? [params.ownerAid]
|
|
428
|
+
: fs.existsSync(ownersDir) ? fs.readdirSync(ownersDir, { withFileTypes: true })
|
|
429
|
+
.filter(entry => entry.isDirectory()).map(entry => entry.name) : [];
|
|
430
|
+
const thresholds = { forgetAfterDays: config.forgetAfterDays };
|
|
431
|
+
const now = params.now ?? Date.now();
|
|
432
|
+
return owners.some(ownerAid => collectCandidates(path.join(ownersDir, ownerAid, 'consolidated'), thresholds, now)
|
|
433
|
+
.some(candidate => isDueForReview(candidate, thresholds, now)));
|
|
434
|
+
}
|
|
@@ -22,7 +22,7 @@ import { logger } from '../../utils/logger.js';
|
|
|
22
22
|
import { atomicWriteText } from '../../utils/atomic-write.js';
|
|
23
23
|
import { appendOpsRecord, feedbackFilePath, readFeedbackText } from './consolidation-ops-records.js';
|
|
24
24
|
import { updateBatchMeta } from './batch-meta.js';
|
|
25
|
-
import { checkConsolidationCandidates, isConsolidatableRelation, recordProfileAttempt, shouldUseMetaIndex } from './consolidation-trigger.js';
|
|
25
|
+
import { checkConsolidationCandidates, hasOwnerConsolidationCandidates, isConsolidatableRelation, judgeRelationMode, recordProfileAttempt, shouldUseMetaIndex } from './consolidation-trigger.js';
|
|
26
26
|
import { taskContextOfRoute } from './relation-idle-monitor.js';
|
|
27
27
|
/**
|
|
28
28
|
* 清理旧整理批次,全局保留最新的 10 个(不区分 aid 或 mode)。
|
|
@@ -644,7 +644,7 @@ function findOwnerPeerKeyFor(selfAid, ownerAid) {
|
|
|
644
644
|
export async function rollbackConsolidation(batchDir, selfAid) {
|
|
645
645
|
const { readRollbackRecords, appendOpsRecord } = await import('./consolidation-ops-records.js');
|
|
646
646
|
const { revertMemoryArchive, revertMemoryCreate, revertMemoryUpdate, sourceMemoryDirOf } = await import('./memory-writer.js');
|
|
647
|
-
const { appendForgetLog, slugOfMemoryFile } = await import('./
|
|
647
|
+
const { appendForgetLog, slugOfMemoryFile } = await import('./consolidation-ops-records.js');
|
|
648
648
|
const entries = readRollbackRecords(batchDir);
|
|
649
649
|
let rolledBack = 0;
|
|
650
650
|
const errors = [];
|
|
@@ -1298,8 +1298,6 @@ export function registerConsolidationCheckExecutor({ ipcServer, agentRegistry, e
|
|
|
1298
1298
|
if (consolidationBlockedReason(selfAid))
|
|
1299
1299
|
return { launched: [] };
|
|
1300
1300
|
recoverStaleConsolidationProcessing(selfAid);
|
|
1301
|
-
await ownerResolver.refresh(selfAid);
|
|
1302
|
-
const ownerAid = getPrimaryOwner(selfAid);
|
|
1303
1301
|
const agentCount = agentRegistry.runnableAgents().length;
|
|
1304
1302
|
const relationsDir = path.join(agentDir(selfAid), 'relations');
|
|
1305
1303
|
let relationCount = 0;
|
|
@@ -1312,12 +1310,21 @@ export function registerConsolidationCheckExecutor({ ipcServer, agentRegistry, e
|
|
|
1312
1310
|
// The relation directory is optional during initial bootstrap.
|
|
1313
1311
|
}
|
|
1314
1312
|
const useMetaIndex = shouldUseMetaIndex(agentCount, relationCount);
|
|
1313
|
+
const knownOwnerAid = ownerResolver.knownOwner(selfAid);
|
|
1315
1314
|
const candidates = checkConsolidationCandidates({
|
|
1316
|
-
selfAid,
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1315
|
+
selfAid, config: { ...agentConfig?.memory, enableOwner: false }, useMetaIndex,
|
|
1316
|
+
});
|
|
1317
|
+
const ownerCandidates = hasOwnerConsolidationCandidates({
|
|
1318
|
+
selfAid, ownerAid: knownOwnerAid, config: agentConfig?.memory,
|
|
1320
1319
|
});
|
|
1320
|
+
if (candidates.length === 0 && !ownerCandidates)
|
|
1321
|
+
return { launched: [] };
|
|
1322
|
+
await ownerResolver.refresh(selfAid);
|
|
1323
|
+
const ownerAid = getPrimaryOwner(selfAid);
|
|
1324
|
+
if (ownerCandidates)
|
|
1325
|
+
candidates.push(...checkConsolidationCandidates({
|
|
1326
|
+
selfAid, ownerAid, config: agentConfig?.memory, useMetaIndex, ownerOnly: true,
|
|
1327
|
+
}));
|
|
1321
1328
|
const launched = [];
|
|
1322
1329
|
for (const candidate of candidates) {
|
|
1323
1330
|
const route = candidate.peerKey ? getRelationRoute?.(selfAid, candidate.peerKey) : undefined;
|
|
@@ -1367,6 +1374,10 @@ export function registerRelationConsolidationEvents({ eventBus, agentRegistry, r
|
|
|
1367
1374
|
const memoryConfig = agentRegistry.get(taskCtx.selfAid)?.config?.memory;
|
|
1368
1375
|
if (memoryConfig?.enableRelation === false)
|
|
1369
1376
|
return;
|
|
1377
|
+
if (judgeRelationMode({
|
|
1378
|
+
mode: 'notes', selfAid: taskCtx.selfAid, peerKey: taskCtx.peerKey, config: memoryConfig, force: true,
|
|
1379
|
+
}) !== 'run')
|
|
1380
|
+
return;
|
|
1370
1381
|
await ownerResolver.refresh(taskCtx.selfAid);
|
|
1371
1382
|
const ownerAid = getPrimaryOwner(taskCtx.selfAid);
|
|
1372
1383
|
await enqueueConsolidation({
|
|
@@ -15,7 +15,7 @@ import { refreshMemoryMeta, readMemoryMeta } from './index-manager.js';
|
|
|
15
15
|
import { stripLegacySignature } from './memory-document.js';
|
|
16
16
|
import { moveRecord, verifyFile } from '../file-integrity/store.js';
|
|
17
17
|
import { readFmArray, readFmValue, readUpdatedAtMs, reviewWindowDays, DEFAULT_FORGET_AFTER_DAYS } from './staleness.js';
|
|
18
|
-
import { appendForgetLog, normalizeForgetReason } from './
|
|
18
|
+
import { appendForgetLog, normalizeForgetReason } from './consolidation-ops-records.js';
|
|
19
19
|
export const MEMORY_SCOPES = ['relation', 'agent', 'owner'];
|
|
20
20
|
const SLUG_RE = /^[a-zA-Z0-9][a-zA-Z0-9-]{0,63}$/;
|
|
21
21
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
import { logger } from '../../utils/logger.js';
|
|
22
22
|
import { RELATION_SWEEP_ORDER, judgeRelationMode } from './consolidation-trigger.js';
|
|
23
23
|
import { taskContextOfRoute } from './relation-idle-monitor.js';
|
|
24
|
+
import { parsePeerKey } from '../relation/peer-identity.js';
|
|
24
25
|
/** 单步整理会话迟迟不收尾时,链最多等这么久就放弃(整理会话自身 15 分钟超时,留余量)。 */
|
|
25
26
|
const DEFAULT_STEP_WATCHDOG_MS = 30 * 60_000;
|
|
26
27
|
/**
|
|
@@ -65,12 +66,7 @@ export class RelationSweepRunner {
|
|
|
65
66
|
step: 0,
|
|
66
67
|
};
|
|
67
68
|
this.sweeps.set(id, state);
|
|
68
|
-
void this.
|
|
69
|
-
.catch(() => undefined)
|
|
70
|
-
.then(ownerAid => {
|
|
71
|
-
state.ownerAid = ownerAid;
|
|
72
|
-
return this.advance(state);
|
|
73
|
-
});
|
|
69
|
+
void this.advance(state);
|
|
74
70
|
}
|
|
75
71
|
/** 整理会话收尾回调(来自 finalizer 的 onSessionFinalized)。 */
|
|
76
72
|
onSessionFinalized(info) {
|
|
@@ -133,6 +129,12 @@ export class RelationSweepRunner {
|
|
|
133
129
|
const memoryConfig = agent?.config?.memory;
|
|
134
130
|
let verdict = 'none';
|
|
135
131
|
try {
|
|
132
|
+
if (mode === 'promote') {
|
|
133
|
+
const candidateOwner = parsePeerKey(peerKey).channelId;
|
|
134
|
+
if (this.judgeMode({ mode, selfAid, peerKey, ownerAid: candidateOwner, config: memoryConfig, force }) === 'none')
|
|
135
|
+
continue;
|
|
136
|
+
state.ownerAid = await this.deps.resolveOwner(selfAid).catch(() => undefined);
|
|
137
|
+
}
|
|
136
138
|
verdict = this.judgeMode({ mode, selfAid, peerKey, ownerAid: state.ownerAid, config: memoryConfig, force });
|
|
137
139
|
}
|
|
138
140
|
catch (error) {
|
|
@@ -148,6 +150,9 @@ export class RelationSweepRunner {
|
|
|
148
150
|
state.failed = true;
|
|
149
151
|
break;
|
|
150
152
|
}
|
|
153
|
+
if (mode !== 'promote' && state.ownerAid === undefined) {
|
|
154
|
+
state.ownerAid = await this.deps.resolveOwner(selfAid).catch(() => undefined);
|
|
155
|
+
}
|
|
151
156
|
const taskCtx = { selfAid, peerKey, baseagent: agent.baseagent, ...taskContextOfRoute(route) };
|
|
152
157
|
// 先挂上等待标记再入队:会话可能在 enqueue 返回前就收尾,收尾回调要能认出这一步
|
|
153
158
|
const token = ++state.step;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolveAunSendDevice } from '../../aun/ability-device-routing.js';
|
|
2
2
|
import crypto from 'crypto';
|
|
3
|
-
import { authorizeDelegatedAunMsgSend, } from '../auth/agent-delegation.js';
|
|
3
|
+
import { authorizeDelegatedAunMsgSend, delegationFailureDetailCode, hasTrustedFullAccessDelegation, } from '../auth/agent-delegation.js';
|
|
4
4
|
import { formatChannelKey, tryParseChannelKey } from '../channel-loader.js';
|
|
5
5
|
import { AUN_HANDOFF_MARKER_FIELD } from '../../channels/aun.js';
|
|
6
6
|
import { classifyAunPayloadForLog } from './message-log.js';
|
|
@@ -17,6 +17,7 @@ import { isTopicThreadId, parseMainTopicId, safeFormatMainTopicId, sessionLocalT
|
|
|
17
17
|
import { ThreadService } from '../thread/thread-service.js';
|
|
18
18
|
import { getAunRequestRegistry, requestDiagnostics, requestTtlSeconds } from './aun-request-registry.js';
|
|
19
19
|
import { parseJsonObjectArgument } from '../permission/ec-command-parser.js';
|
|
20
|
+
import { parsePeerKey } from '../relation/peer-identity.js';
|
|
20
21
|
const TASK_ID_MESSAGE_PAYLOAD_TYPES = new Set(['text', 'link', 'image', 'video', 'voice', 'file']);
|
|
21
22
|
/** payload.debug 只是诊断字段:取不到时照常发送,不带 debug。 */
|
|
22
23
|
async function resolveOutboundDebug(resolver, sessionId) {
|
|
@@ -84,29 +85,12 @@ export function createAunHandoffSender(sessionManager, channelInstances, getOutb
|
|
|
84
85
|
};
|
|
85
86
|
}
|
|
86
87
|
async function applyManagedCrossThreadSendEffects(input) {
|
|
87
|
-
const originSessionId = input.
|
|
88
|
-
|
|
89
|
-
return { triggerError: 'origin session context unavailable' };
|
|
90
|
-
const originPeer = input.runtime?.channelId || input.targetChannelId;
|
|
88
|
+
const originSessionId = input.grant.sessionId;
|
|
89
|
+
const originPeer = parsePeerKey(input.grant.peerKey).channelId;
|
|
91
90
|
// 来源话题 id:话题用原 id;主话题用"本端+对端"拼出的规范 id(展示与持久化用)。
|
|
92
91
|
const originThreadId = isTopicThreadId(input.runtime?.threadId)
|
|
93
92
|
? input.runtime.threadId
|
|
94
93
|
: (safeFormatMainTopicId(input.selfAid, originPeer) ?? '');
|
|
95
|
-
// origin 指向复查目标对端(A),而非触发本次发送的会话对端(C)。
|
|
96
|
-
// authorizeTriggerExecution 根据 origin 对端的角色决定 trigger 能否执行;
|
|
97
|
-
// B 周期性地向 A 发消息,应检查 A 对 B 的角色,而不是 C 对 B 的角色。
|
|
98
|
-
const targetChatType = input.feedbackChatType ?? 'private';
|
|
99
|
-
const origin = {
|
|
100
|
-
channelKey: formatChannelKey({ type: 'aun', selfAID: input.selfAid, name: 'main' }),
|
|
101
|
-
channelType: 'aun',
|
|
102
|
-
channelId: input.targetChannelId,
|
|
103
|
-
session: isTopicThreadId(input.targetThreadId) ? 'thread' : 'main',
|
|
104
|
-
...(isTopicThreadId(input.targetThreadId) ? { threadId: input.targetThreadId } : {}),
|
|
105
|
-
peerId: input.targetChannelId,
|
|
106
|
-
delivery: targetChatType === 'group'
|
|
107
|
-
? { chatType: 'group', groupId: input.targetChannelId }
|
|
108
|
-
: { chatType: 'private' },
|
|
109
|
-
};
|
|
110
94
|
const triggerSeed = `${Date.now()}_${crypto.randomBytes(4).toString('hex')}`;
|
|
111
95
|
const triggerId = `trig_${triggerSeed}`;
|
|
112
96
|
const triggerName = `check-${targetTopicLabel(input.targetThreadId)}-from-${targetTopicLabel(originThreadId)}-${triggerSeed.split('_')[1]}`;
|
|
@@ -137,37 +121,33 @@ async function applyManagedCrossThreadSendEffects(input) {
|
|
|
137
121
|
let createdTriggerId;
|
|
138
122
|
let triggerError;
|
|
139
123
|
try {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
throw new Error(`trigger scheduler not found for agent: ${input.selfAid}`);
|
|
124
|
+
if (!input.createCrossThreadReviewTrigger)
|
|
125
|
+
throw new Error('cross-thread Trigger authorization is unavailable');
|
|
143
126
|
const { buildThreadCheckTrigger } = await import('../../cli/aun-commands.js');
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
operatorPeers,
|
|
169
|
-
};
|
|
170
|
-
createdTriggerId = scheduler.create(definition, [], { enable: true }).id;
|
|
127
|
+
const definition = buildThreadCheckTrigger({
|
|
128
|
+
agentAid: input.selfAid,
|
|
129
|
+
id: triggerId,
|
|
130
|
+
name: triggerName,
|
|
131
|
+
prompt,
|
|
132
|
+
everyMs: input.durationMs,
|
|
133
|
+
checkEvery: input.checkEveryLabel,
|
|
134
|
+
channelKey: formatChannelKey({ type: 'aun', selfAID: input.selfAid, name: 'main' }),
|
|
135
|
+
targetChannelId: input.targetChannelId,
|
|
136
|
+
targetThreadId: input.targetThreadId,
|
|
137
|
+
originThreadId,
|
|
138
|
+
originPeer,
|
|
139
|
+
feedbackChatType: input.feedbackChatType,
|
|
140
|
+
originalText: input.contentSummary,
|
|
141
|
+
firstSentAt: input.timestamp,
|
|
142
|
+
originThreadName,
|
|
143
|
+
targetThreadName,
|
|
144
|
+
});
|
|
145
|
+
const created = await input.createCrossThreadReviewTrigger({
|
|
146
|
+
agentAid: input.selfAid,
|
|
147
|
+
grant: input.grant,
|
|
148
|
+
definition,
|
|
149
|
+
});
|
|
150
|
+
createdTriggerId = created.id;
|
|
171
151
|
}
|
|
172
152
|
catch (error) {
|
|
173
153
|
// 失败原因随发送回执返回给调用方:只打 daemon 日志时,CLI 照样显示"已投递",
|
|
@@ -207,7 +187,7 @@ function targetTopicLabel(topicId) {
|
|
|
207
187
|
return topicId;
|
|
208
188
|
return 'main';
|
|
209
189
|
}
|
|
210
|
-
export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegationRegistry, responseEngine, handoffRuntime,
|
|
190
|
+
export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegationRegistry, responseEngine, handoffRuntime, sessionManager, createCrossThreadReviewTrigger, }) {
|
|
211
191
|
ipcServer.setAunRequestGetExecutor(async (params) => {
|
|
212
192
|
if (!params.sessionId || !params.delegationToken) {
|
|
213
193
|
return { ok: false, code: 'DELEGATION_REQUIRED', error: 'Request queries require an active delegated session' };
|
|
@@ -247,7 +227,38 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
247
227
|
let payloadFile;
|
|
248
228
|
try {
|
|
249
229
|
if (params.argv !== undefined) {
|
|
250
|
-
|
|
230
|
+
if (!params.delegationCommandHash) {
|
|
231
|
+
return {
|
|
232
|
+
ok: false,
|
|
233
|
+
code: 'INVALID_DELEGATION',
|
|
234
|
+
detail_code: 'APPROVED_COMMAND_UNAVAILABLE',
|
|
235
|
+
error: 'Managed AUN sends require an approved command hash',
|
|
236
|
+
retryable: false,
|
|
237
|
+
sent: false,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
if (!params.originSessionId) {
|
|
241
|
+
return { ok: false, code: 'DELEGATION_REQUIRED', error: 'Origin session is required', sent: false };
|
|
242
|
+
}
|
|
243
|
+
// 先核验原始命令和会话凭据,再使用 grant 补全路由;这里不消费审批。
|
|
244
|
+
const authorization = agentDelegationRegistry.validateForContext(params.delegationToken, params.originSessionId, params.delegationCommandHash);
|
|
245
|
+
if (!authorization.ok) {
|
|
246
|
+
return {
|
|
247
|
+
ok: false,
|
|
248
|
+
code: authorization.code,
|
|
249
|
+
error: authorization.reason,
|
|
250
|
+
detail_code: delegationFailureDetailCode(authorization.diagnosticCause),
|
|
251
|
+
retryable: false,
|
|
252
|
+
sent: false,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
const grant = authorization.grant;
|
|
256
|
+
const command = resolveManagedSendArgv(params.argv, {
|
|
257
|
+
selfAid: grant.selfAid,
|
|
258
|
+
peerId: grant.channelType === 'aun' && grant.chatType === 'private'
|
|
259
|
+
? parsePeerKey(grant.peerKey).channelId : undefined,
|
|
260
|
+
resolveThreadPeer: thread => resolveThreadRouteTarget(grant.selfAid, thread, 'msg')?.peer,
|
|
261
|
+
});
|
|
251
262
|
textFile = command.textFile;
|
|
252
263
|
payloadFile = command.payloadFile;
|
|
253
264
|
params = { ...params, ...command };
|
|
@@ -297,16 +308,6 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
297
308
|
? threadRef
|
|
298
309
|
: (safeFormatMainTopicId(params.aid, threadRoute.peer) ?? threadRef))
|
|
299
310
|
: undefined;
|
|
300
|
-
if (params.argv !== undefined && !params.delegationCommandHash) {
|
|
301
|
-
return {
|
|
302
|
-
ok: false,
|
|
303
|
-
code: 'INVALID_DELEGATION',
|
|
304
|
-
detail_code: 'APPROVED_COMMAND_UNAVAILABLE',
|
|
305
|
-
error: 'Managed AUN sends require an approved command hash',
|
|
306
|
-
retryable: false,
|
|
307
|
-
sent: false,
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
311
|
const isSystemEvent = params.trustedSystemEvent === true
|
|
311
312
|
&& params.payload?.type === 'event' && params.payload.event === 'topic.renamed';
|
|
312
313
|
const delegation = await authorizeDelegatedAunMsgSend(agentDelegationRegistry, {
|
|
@@ -331,10 +332,12 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
331
332
|
...(delegation.sent === false ? { sent: false } : {}),
|
|
332
333
|
};
|
|
333
334
|
}
|
|
335
|
+
const fullAccess = !!delegation.grant && hasTrustedFullAccessDelegation(delegation.grant);
|
|
334
336
|
try {
|
|
335
337
|
const fileScope = runtime?.projectPath && delegation.grant
|
|
336
338
|
? { selfAid: delegation.grant.selfAid, projectPath: runtime.projectPath,
|
|
337
|
-
sessionRuntimeDir: delegation.grant.sessionRuntimeDir, cwd: runtime.projectPath
|
|
339
|
+
sessionRuntimeDir: delegation.grant.sessionRuntimeDir, cwd: runtime.projectPath,
|
|
340
|
+
...(fullAccess ? { allowProtectedPaths: true } : {}) }
|
|
338
341
|
: undefined;
|
|
339
342
|
if ((textFile || payloadFile || params.file) && !fileScope)
|
|
340
343
|
throw new Error('Current task project context is unavailable');
|
|
@@ -405,7 +408,7 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
405
408
|
: (typeof ch.getDefaultEncrypt === 'function' ? ch.getDefaultEncrypt() : true);
|
|
406
409
|
let payload = params.payload;
|
|
407
410
|
if (params.file) {
|
|
408
|
-
if (isHClassPath(params.file.filePath)) {
|
|
411
|
+
if (isHClassPath(params.file.filePath) && !fullAccess) {
|
|
409
412
|
return {
|
|
410
413
|
ok: false,
|
|
411
414
|
error: 'H-class protected files cannot be uploaded by an agent task',
|
|
@@ -545,7 +548,6 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
545
548
|
// 承载目标侧上下文,跳过这里就会丢上下文。
|
|
546
549
|
if (threadRouted && params.checkEveryMs !== undefined && threadRoute) {
|
|
547
550
|
const effects = await applyManagedCrossThreadSendEffects({
|
|
548
|
-
triggerSchedulers,
|
|
549
551
|
runtime,
|
|
550
552
|
selfAid: params.aid,
|
|
551
553
|
targetThreadId: targetTopicId ?? params.thread ?? "",
|
|
@@ -558,6 +560,8 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
558
560
|
durationMs: params.checkEveryMs,
|
|
559
561
|
checkEveryLabel: params.checkEvery ?? '5m',
|
|
560
562
|
triggerPromptExtra: params.triggerPromptExtra,
|
|
563
|
+
grant: delegation.grant,
|
|
564
|
+
createCrossThreadReviewTrigger,
|
|
561
565
|
});
|
|
562
566
|
if (effects.triggerId)
|
|
563
567
|
response.trigger_id = effects.triggerId;
|
|
@@ -597,7 +601,6 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
597
601
|
});
|
|
598
602
|
if (params.thread && params.checkEveryMs !== undefined && sent.ok && sent.message_id && threadRoute) {
|
|
599
603
|
const effects = await applyManagedCrossThreadSendEffects({
|
|
600
|
-
triggerSchedulers,
|
|
601
604
|
runtime,
|
|
602
605
|
selfAid: params.aid,
|
|
603
606
|
targetThreadId: params.thread,
|
|
@@ -610,6 +613,8 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
610
613
|
durationMs: params.checkEveryMs,
|
|
611
614
|
checkEveryLabel: params.checkEvery ?? '5m',
|
|
612
615
|
triggerPromptExtra: params.triggerPromptExtra,
|
|
616
|
+
grant: delegation.grant,
|
|
617
|
+
createCrossThreadReviewTrigger,
|
|
613
618
|
});
|
|
614
619
|
if (effects.triggerId)
|
|
615
620
|
sent.trigger_id = effects.triggerId;
|
|
@@ -658,7 +663,6 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
658
663
|
}
|
|
659
664
|
if (params.thread && params.checkEveryMs !== undefined && sent.ok && sent.message_id && threadRoute) {
|
|
660
665
|
const effects = await applyManagedCrossThreadSendEffects({
|
|
661
|
-
triggerSchedulers,
|
|
662
666
|
runtime,
|
|
663
667
|
selfAid: params.aid,
|
|
664
668
|
targetThreadId: params.thread,
|
|
@@ -671,6 +675,8 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
671
675
|
durationMs: params.checkEveryMs,
|
|
672
676
|
checkEveryLabel: params.checkEvery ?? '5m',
|
|
673
677
|
triggerPromptExtra: params.triggerPromptExtra,
|
|
678
|
+
grant: delegation.grant,
|
|
679
|
+
createCrossThreadReviewTrigger,
|
|
674
680
|
});
|
|
675
681
|
if (effects.triggerId)
|
|
676
682
|
sent.trigger_id = effects.triggerId;
|
|
@@ -5,6 +5,22 @@ import { tagErrorTextWithEvolcoreVersion } from '../../utils/evolcore-version.js
|
|
|
5
5
|
import { DEFAULT_FLUSH_DELAY_MS } from '../../types.js';
|
|
6
6
|
import { classifyAunToolErrorCode, normalizeToolErrorClassification } from '../permission/tool-error-code.js';
|
|
7
7
|
import { foldSubtaskTerminal } from './subtask-tool-projection.js';
|
|
8
|
+
function toolApprovalMetadata(event) {
|
|
9
|
+
if (!event || event.executed !== false || !event.decisionSource || event.decisionSource === 'runner')
|
|
10
|
+
return {};
|
|
11
|
+
return { approval: {
|
|
12
|
+
decision: 'deny',
|
|
13
|
+
decisionSource: event.decisionSource,
|
|
14
|
+
requestId: event.requestId,
|
|
15
|
+
approvalRequestId: event.approvalRequestId,
|
|
16
|
+
policyCode: event.policyCode,
|
|
17
|
+
errorDetailCode: normalizeToolErrorClassification(event).errorDetailCode,
|
|
18
|
+
reason: event.reason ?? event.error,
|
|
19
|
+
approverOperatorId: event.approverOperatorId,
|
|
20
|
+
approverChannelKey: event.approverChannelKey,
|
|
21
|
+
approverPrincipalId: event.approverPrincipalId,
|
|
22
|
+
} };
|
|
23
|
+
}
|
|
8
24
|
export class IMRenderer {
|
|
9
25
|
opts;
|
|
10
26
|
itemsQueue = [];
|
|
@@ -284,6 +300,7 @@ export class IMRenderer {
|
|
|
284
300
|
: {}),
|
|
285
301
|
...(classification?.outputKind ? { output_kind: classification.outputKind } : {}),
|
|
286
302
|
...(!ok && {
|
|
303
|
+
...toolApprovalMetadata(classification),
|
|
287
304
|
error_code: classifyAunToolErrorCode({
|
|
288
305
|
...(classification ?? {}),
|
|
289
306
|
...(normalizedClassification ?? {}),
|
|
@@ -931,6 +948,7 @@ export class IMRenderer {
|
|
|
931
948
|
call_id: event.callId || this.synthCallId(),
|
|
932
949
|
name: event.name,
|
|
933
950
|
ok: false,
|
|
951
|
+
...toolApprovalMetadata(event),
|
|
934
952
|
...executionFields,
|
|
935
953
|
...(event.result !== undefined ? { result: event.result } : {}),
|
|
936
954
|
error_code: classifyAunToolErrorCode({ ...event, ...classification }),
|
|
@@ -18,7 +18,7 @@ import { resolveContactView, resolvePeerDisplayLabel, resolvePrincipal } from '.
|
|
|
18
18
|
import { findContactRequestNote, expirePendingContactRequests, reviewContactRequest, submitContactRequest, contactRequestSubmissionProtocolResult, queryOwnContactRequestStatus, } from '../../config/contact-request-service.js';
|
|
19
19
|
import { isValidAid } from '../../aun/aid/validation.js';
|
|
20
20
|
import { PeerIdentityCache, formatPeerKey } from '../relation/peer-identity.js';
|
|
21
|
-
import { ownerResolver } from '../ownership/owner-resolver.js';
|
|
21
|
+
import { ownerResolver, OWNERSHIP_CACHE_MAX_AGE_MS } from '../ownership/owner-resolver.js';
|
|
22
22
|
import { isTopicSession, sessionLocalTopicId } from '../thread/topic-id.js';
|
|
23
23
|
import { resolveEffective } from '../../config/config-manager.js';
|
|
24
24
|
import { createDecisionInferenceProvider } from '../inference/text-inference.js';
|
|
@@ -277,7 +277,7 @@ export class MessageBridge {
|
|
|
277
277
|
if (args.length === 0) {
|
|
278
278
|
const configuredOwner = ownerResolver.configuredOwnerList(selfAid)[0];
|
|
279
279
|
if (configuredOwner !== actorId) {
|
|
280
|
-
return { handled: true, status: 'not-first-owner', reply: '
|
|
280
|
+
return { handled: true, status: 'not-first-owner', reply: '仅兼容绑定目标中的首个 AID 可在 AUN 私聊发送 /bind 发起 ownership 绑定。' };
|
|
281
281
|
}
|
|
282
282
|
try {
|
|
283
283
|
const current = await ownerResolver.refresh(selfAid, { force: true });
|
|
@@ -435,7 +435,7 @@ export class MessageBridge {
|
|
|
435
435
|
}
|
|
436
436
|
}
|
|
437
437
|
aunSelfServiceBindUsage() {
|
|
438
|
-
return `用法:/bind
|
|
438
|
+
return `用法:/bind(首个兼容绑定目标发起 ownership 绑定);/bind <渠道> [实例名](联系人绑定)。支持渠道:${SELF_SERVICE_CONTACT_BIND_TYPES.join('、')}。`;
|
|
439
439
|
}
|
|
440
440
|
aunSelfServiceBindInstances(channelType, instances) {
|
|
441
441
|
const names = instances.map(instance => String(instance.name || '').trim()).filter(Boolean);
|
|
@@ -948,6 +948,17 @@ export class MessageBridge {
|
|
|
948
948
|
&& resolvedChannelType === 'aun'
|
|
949
949
|
&& !!selfAid
|
|
950
950
|
&& actorId === selfAid;
|
|
951
|
+
if (selfAid && !trustedHandoffEcho) {
|
|
952
|
+
// Admission reads Owner synchronously; wait here before classifying
|
|
953
|
+
// a sender against an expired or invalidated ownership cache.
|
|
954
|
+
const ownership = ownerResolver.snapshot(selfAid);
|
|
955
|
+
if (ownership.connected || ownership.relation) {
|
|
956
|
+
await ownerResolver.refresh(selfAid, {
|
|
957
|
+
maxAgeMs: OWNERSHIP_CACHE_MAX_AGE_MS,
|
|
958
|
+
allowTransient: true,
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
}
|
|
951
962
|
const admissionPreflight = evaluateInboundAdmissionPreflight({
|
|
952
963
|
selfAid,
|
|
953
964
|
channelKey,
|
|
@@ -976,6 +987,27 @@ export class MessageBridge {
|
|
|
976
987
|
})) {
|
|
977
988
|
return;
|
|
978
989
|
}
|
|
990
|
+
const ownershipFailure = selfAid ? ownerResolver.snapshot(selfAid) : undefined;
|
|
991
|
+
if (!trustedHandoffEcho && !admissionPreflight.context.isOwner
|
|
992
|
+
&& (admissionPreflight.allow || admissionPreflight.reason === 'restricted_mode_without_owner')
|
|
993
|
+
&& admissionPreflight.context.primaryId
|
|
994
|
+
&& !/^\s*\/(?:bind|request)(?:\s|$)/i.test(content)
|
|
995
|
+
&& ownershipFailure?.refreshFailure
|
|
996
|
+
&& admissionPreflight.context.primaryId === ownershipFailure.relation?.ownerAid) {
|
|
997
|
+
const errorCode = ownershipFailure.refreshFailure.code;
|
|
998
|
+
const notice = `Owner 身份核验未完成(${errorCode}),本次消息未执行。`;
|
|
999
|
+
if (chatType === 'private') {
|
|
1000
|
+
if (menuControl.isMenu && hasValidMenuId(menuControl)) {
|
|
1001
|
+
await this.sendAdmissionMenuResponse(admissionPreflight.context, adapter, channelName, msg, menuFailure({ id: menuControl.id }, { code: 'OWNER_UNAVAILABLE', message: notice }));
|
|
1002
|
+
}
|
|
1003
|
+
else if (!menuControl.isMenu) {
|
|
1004
|
+
await this.sendAdmissionControlReply(admissionPreflight.context, msg, sendReply, notice);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
logger.warn(`[MessageBridge] Owner verification failed before admission: self=${selfAid}`
|
|
1008
|
+
+ ` actor=${actorId} code=${errorCode} reason=${ownershipFailure.refreshFailure.reason}`);
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
979
1011
|
if (!admissionPreflight.allow) {
|
|
980
1012
|
const requestCommand = /^\s*\/request(?:\s|$)/i.test(content);
|
|
981
1013
|
if (admissionPreflight.reason === 'blocked' && admissionPreflight.context.primaryId) {
|