evolcore 0.0.40 → 0.0.41-test.1
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 +94 -1
- package/bin/codex-managed-hook.mjs +11 -0
- package/bin/ec-safe-output.js +11 -1
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/baseagent.js +20 -43
- package/dist/agents/claude-runner.js +197 -197
- package/dist/agents/codex-runner.js +535 -259
- package/dist/agents/ecagent-runner.js +31 -12
- package/dist/agents/gemini-runner.js +27 -7
- package/dist/agents/runner-types.js +11 -3
- package/dist/aun/ability-device-routing.js +26 -0
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/group/fs-download.js +39 -0
- package/dist/aun/group/identity.js +36 -13
- package/dist/aun/group/operations.js +5 -0
- package/dist/aun/msg/managed-operation.js +72 -11
- package/dist/aun/msg/p2p.js +32 -7
- package/dist/aun/service-proxy.js +36 -12
- package/dist/aun/storage/download.js +30 -0
- package/dist/aun/storage/index.js +14 -6
- package/dist/channels/aun.js +367 -24
- package/dist/channels/daemon.js +39 -5
- package/dist/cli/agent-command.js +2 -0
- package/dist/cli/agent-create.js +98 -19
- package/dist/cli/agent.js +10 -3
- package/dist/cli/aun-commands.js +85 -41
- package/dist/cli/daemon-commands.js +678 -688
- package/dist/cli/fs-command.js +64 -2
- package/dist/cli/index.js +48 -4
- package/dist/cli/managed-command-guard.js +4 -0
- package/dist/cli/model.js +40 -40
- package/dist/cli/proxy-command.js +92 -0
- package/dist/cli/restart-monitor.js +17 -0
- package/dist/cli/role.js +85 -0
- package/dist/cli/session-command.js +128 -13
- package/dist/cli/stats.js +60 -4
- package/dist/cli/trigger-command.js +2 -2
- package/dist/config/access-policy.js +8 -1
- package/dist/config/boot-log.js +38 -1
- package/dist/config/config-field-policy.js +5 -32
- package/dist/config/config-manager.js +46 -39
- package/dist/config/config-operation-service.js +8 -11
- package/dist/config/contact-book-store.js +47 -21
- package/dist/config/contact-book.js +18 -12
- package/dist/config/contact-operation-service.js +3 -4
- package/dist/config/contact-request-service.js +11 -0
- package/dist/config/daemon-services.js +11 -0
- package/dist/config/gateway-config.js +89 -595
- package/dist/config/peer-role-resolver.js +15 -11
- package/dist/config/providers-config.js +12 -7
- package/dist/config/providers-import.js +3 -21
- package/dist/config/resolved-config-op.js +3 -0
- package/dist/config/role-command-service.js +166 -0
- package/dist/config/role-request-service.js +193 -0
- package/dist/config/schema-migration.js +686 -25
- package/dist/config-store.js +79 -3
- package/dist/contracts/ecweb-instance.js +41 -0
- package/dist/contracts/ecweb-service-protocol.js +3 -1
- package/dist/core/agent-application-service.js +11 -1
- package/dist/core/agent-ipc-registration.js +4 -0
- package/dist/core/agent-runtime.js +1 -1
- package/dist/core/auth/agent-delegation.js +82 -6
- package/dist/core/auth/auth-gateway.js +1 -1
- package/dist/core/auth/authorization-audit.js +37 -9
- package/dist/core/auth/delegation-authorization.js +3 -1
- package/dist/core/auth/operation-authorizer.js +15 -0
- package/dist/core/auth/operation-catalog.js +39 -6
- package/dist/core/command/agent-control.js +94 -19
- package/dist/core/command/agent-storage-menu.js +5 -3
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +105 -145
- package/dist/core/command/connect-menu.js +31 -2
- package/dist/core/command/data-root-resolver.js +5 -4
- package/dist/core/command/memory-slash.js +16 -8
- package/dist/core/command/menu-catalog.js +6 -6
- package/dist/core/command/menu-handler.js +87 -163
- package/dist/core/command/menu-protocol.js +9 -2
- package/dist/core/command/role-menu.js +148 -30
- package/dist/core/command/slash-gate.js +13 -10
- package/dist/core/command/slash-handler.js +157 -352
- package/dist/core/daemon-control.js +8 -14
- package/dist/core/event-catalog.js +15 -0
- package/dist/core/evolagent-registry.js +4 -4
- package/dist/core/evolagent.js +2 -2
- package/dist/core/inference/text-inference.js +31 -40
- package/dist/core/ipc-registration.js +24 -3
- package/dist/core/memory/consolidation-context.js +51 -5
- package/dist/core/memory/consolidation-ops-records.js +1 -1
- package/dist/core/memory/consolidation-trigger.js +190 -190
- package/dist/core/memory/consolidation.js +316 -29
- package/dist/core/memory/forget-log.js +96 -0
- package/dist/core/memory/index-manager.js +27 -5
- package/dist/core/memory/memory-admin.js +45 -5
- package/dist/core/memory/memory-writer.js +163 -18
- package/dist/core/memory/relation-idle-monitor.js +119 -58
- package/dist/core/memory/relation-sweep.js +44 -39
- package/dist/core/message/aun-ipc-sender.js +34 -7
- package/dist/core/message/aun-request-registry.js +97 -3
- package/dist/core/message/im-renderer.js +11 -4
- package/dist/core/message/message-admission.js +97 -8
- package/dist/core/message/message-bridge.js +71 -24
- package/dist/core/message/message-log.js +55 -0
- package/dist/core/message/message-queue.js +5 -5
- package/dist/core/message/response-engine.js +387 -144
- package/dist/core/model/catalog-service.js +4 -2
- package/dist/core/model/config-scope.js +24 -64
- package/dist/core/model/field-scope.js +1 -1
- package/dist/core/model/model-catalog.js +37 -47
- package/dist/core/model/model-diagnostics.js +4 -3
- package/dist/core/model/model-fallback.js +10 -7
- package/dist/core/model/model-permission.js +3 -2
- package/dist/core/ownership/owner-resolver.js +25 -23
- package/dist/core/permission/ec-command-parser.js +138 -5
- package/dist/core/permission/sandbox-runtime.js +18 -1
- package/dist/core/permission/tool-policy.js +42 -10
- package/dist/core/relation/peer-identity.js +64 -1
- package/dist/core/role/runtime-policy.js +72 -13
- package/dist/core/session/session-capsule.js +197 -0
- package/dist/core/session/session-idle-monitor.js +1 -1
- package/dist/core/session/session-manager.js +168 -14
- package/dist/core/session/session-mapper.js +2 -0
- package/dist/core/session/session-renew.js +3 -3
- package/dist/core/skill/index-generator.js +15 -5
- package/dist/core/system-session/memory.js +6 -1
- package/dist/core/thread/thread-service.js +19 -6
- package/dist/directory/owner-directory-admission.js +95 -0
- package/dist/directory/owner-directory-authorization.js +309 -0
- package/dist/directory/owner-directory-cache.js +635 -0
- package/dist/eck/kit-renderer.js +2 -2
- package/dist/ecweb/basic-settings-service.js +33 -40
- package/dist/ecweb/message-context-service.js +110 -0
- package/dist/index.js +79 -17
- package/dist/ipc.js +189 -17
- package/dist/paths.js +4 -0
- package/dist/proxy/command.js +122 -0
- package/dist/proxy/ipc-service.js +68 -0
- package/dist/proxy/manager.js +485 -0
- package/dist/proxy/service-supervisor.js +603 -0
- package/dist/response-system/engines/v1/proactive-flow.js +16 -6
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +15 -0
- package/dist/stats/index.js +2 -2
- package/dist/stats/price-resolver.js +304 -5
- package/dist/stats/query.js +82 -3
- package/dist/stats/writer.js +38 -5
- package/dist/trigger/feedback.js +18 -7
- package/dist/trigger/manager.js +20 -3
- package/dist/trigger/parser.js +6 -3
- package/dist/trigger/patch.js +1 -1
- package/dist/trigger/system-definitions.js +43 -7
- package/dist/trigger/validation.js +13 -5
- package/dist/utils/cross-platform.js +14 -0
- package/dist/utils/ecweb-supervisor.js +258 -83
- package/dist/utils/error-utils.js +16 -2
- package/dist/utils/logger.js +24 -5
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +5 -3
- package/dist/utils/upgrade-jobs.js +45 -5
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/aun/ABILITY_CALLING.md +20 -2
- package/kits/docs/channels/aun.md +9 -0
- package/kits/docs/evolcore/INDEX.md +2 -1
- package/kits/docs/evolcore/agent-create.md +3 -2
- package/kits/docs/evolcore/agent.md +1 -1
- package/kits/docs/evolcore/config.md +18 -7
- package/kits/docs/evolcore/contact.md +3 -0
- package/kits/docs/evolcore/event.md +1 -0
- package/kits/docs/evolcore/fs.md +16 -0
- package/kits/docs/evolcore/memory-architecture.md +2 -2
- package/kits/docs/evolcore/memory-consolidation.md +32 -8
- package/kits/docs/evolcore/memory.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +36 -0
- package/kits/docs/evolcore/model.md +23 -20
- package/kits/docs/evolcore/msg.md +21 -8
- package/kits/docs/evolcore/session.md +14 -0
- package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
- package/kits/schemas/_meta.json +37 -4
- package/kits/schemas/agent-config.schema.13.json +23 -3
- package/kits/schemas/agent-config.schema.16.json +891 -0
- package/kits/schemas/daemon.schema.9.json +366 -0
- package/kits/schemas/defaults.schema.5.json +406 -127
- package/kits/schemas/relation-config.schema.11.json +260 -0
- package/kits/schemas/role-config.schema.1.json +7 -7
- package/kits/skills/.switches.json +3 -7
- package/kits/skills/aid-ability/SKILL.md +35 -6
- package/kits/skills/ec-service-proxy/SKILL.md +118 -0
- package/kits/skills/ec-trigger/SKILL.md +13 -5
- package/kits/skills/personal-assistant/SKILL.md +176 -0
- package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
- package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
- package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
- package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
- package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
- package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
- package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
- package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
- package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
- package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
- package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
- package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
- package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
- package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
- package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
- package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
- package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
- package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
- package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
- package/kits/templates/memory-consolidation/forget.md +19 -6
- package/kits/templates/memory-consolidation/notes.md +1 -1
- package/kits/templates/memory-consolidation/profile.md +2 -2
- package/kits/templates/memory-consolidation/promote.md +20 -3
- package/kits/templates/roles/member.json +8 -1
- package/kits/templates/session-capsule/recovery.md +5 -0
- package/kits/templates/session-capsule/renew.md +5 -0
- package/kits/templates/system-fragments/baseagent.md +2 -2
- package/kits/templates/system-fragments/bootstrap.md +6 -6
- package/kits/templates/system-fragments/channel.md +1 -1
- package/kits/templates/system-fragments/memory.md +4 -4
- package/package.json +7 -3
- package/dist/stats/billing.js +0 -215
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* relation-idle-monitor.ts — 关系级空闲 / 兜底计时
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* 内容驱动的记忆整理(notes → generalize → promote)以关系为单位(selfAid + peerKey;
|
|
5
|
+
* 群聊按 groupId 算一个关系)。每个关系一个计时器,看两个时间点:
|
|
6
6
|
*
|
|
7
|
-
* 空闲
|
|
8
|
-
* 兜底
|
|
7
|
+
* 空闲 lastActivityAt + idleHours(默认 1) 每次活动往后推
|
|
8
|
+
* 兜底 firstUnsweptAt + maxUnconsolidatedHours(默认 8) 不往后推
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* 「活动」= 真实入站、往该关系 pending/ 写了一条 note、群链按发言人写入了该关系。
|
|
11
|
+
* owner 插话(owner-inject)、系统渠道、后台会话、trigger 的入站本身不算;但这些轮次里写的 note 算,
|
|
12
|
+
* 所以它们产出的 note 同样进入计时。
|
|
12
13
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* 空闲到期拉起的链只跑候选攒够一批的步骤,兜底到期拉起的链有 1 条候选就跑(见 relation-sweep.ts)。
|
|
15
|
+
* 链结束后按结果续兜底时钟:
|
|
16
|
+
* - 有步骤被推迟:兜底按原起点继续;链运行期间没有新活动时,这一轮空闲记为已消费
|
|
17
|
+
* (空闲早已过期,不记会立刻再触发),等下一次活动或兜底
|
|
18
|
+
* - 有步骤失败:从现在起重新计兜底时钟,最快 maxUnconsolidatedHours 后重试,不会连环重试
|
|
19
|
+
*
|
|
20
|
+
* 到期后交给 startSweep(关系整理链),链跑完回调 onSweepFinished。同一关系同时只跑一条链;
|
|
21
|
+
* 链开始时清空 firstUnsweptAt,链运行期间的活动算新一轮。
|
|
22
|
+
* 状态落盘,重启后恢复;中断的链按「原兜底时钟仍在」处理,启动后立即重跑。
|
|
16
23
|
*/
|
|
17
24
|
import fs from 'fs';
|
|
18
25
|
import path from 'path';
|
|
@@ -20,15 +27,28 @@ import { formatPeerKey } from '../relation/peer-identity.js';
|
|
|
20
27
|
import { isNonAgentSessionChannel } from '../system-channels.js';
|
|
21
28
|
import { atomicWriteJson, decodeDirSegment, tryParseChannelSessionKey } from '../session/session-fs-store.js';
|
|
22
29
|
import { logger } from '../../utils/logger.js';
|
|
23
|
-
import { DEFAULT_MAX_UNCONSOLIDATED_HOURS, DEFAULT_RELATION_IDLE_HOURS } from './consolidation-trigger.js';
|
|
30
|
+
import { DEFAULT_MAX_UNCONSOLIDATED_HOURS, DEFAULT_RELATION_IDLE_HOURS, isConsolidatableRelation, } from './consolidation-trigger.js';
|
|
24
31
|
const HOUR_MS = 60 * 60 * 1000;
|
|
25
32
|
/** setTimeout 的上限约 24.8 天;更远的到期时间分段等。 */
|
|
26
33
|
const MAX_TIMER_MS = 2 ** 31 - 1;
|
|
27
|
-
/**
|
|
34
|
+
/** 没有待整理活动、超过这么久没动静的条目不再落盘(路由信息下次入站会重新带上)。 */
|
|
28
35
|
const PRUNE_AFTER_MS = 7 * 24 * HOUR_MS;
|
|
29
36
|
const SAVE_DEBOUNCE_MS = 1000;
|
|
37
|
+
/** 路由换成整理会话的任务上下文字段(channel / channelId / peerId / chatType …);没有路由时为空。 */
|
|
38
|
+
export function taskContextOfRoute(route) {
|
|
39
|
+
if (!route)
|
|
40
|
+
return {};
|
|
41
|
+
return {
|
|
42
|
+
channel: route.channel,
|
|
43
|
+
channelId: route.channelId,
|
|
44
|
+
peerId: route.peerId,
|
|
45
|
+
chatType: route.chatType,
|
|
46
|
+
...(route.channelKey ? { channelKey: route.channelKey } : {}),
|
|
47
|
+
...(route.threadId ? { threadId: route.threadId } : {}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
30
50
|
/**
|
|
31
|
-
*
|
|
51
|
+
* 把一条入站日志换算成关系活动;不是真实关系入站时返回 undefined。
|
|
32
52
|
*
|
|
33
53
|
* chatDir 形如 `<sessionsDir>/<selfAid>/sessions/<type>#<name>#<channelId>`,
|
|
34
54
|
* channelType / 渠道实例名 / selfAid 都从路径取——日志条目本身只有 from/to。
|
|
@@ -80,6 +100,9 @@ function relationKey(selfAid, peerKey) {
|
|
|
80
100
|
function positiveHours(value, fallback) {
|
|
81
101
|
return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : fallback;
|
|
82
102
|
}
|
|
103
|
+
function numberOrUndefined(value) {
|
|
104
|
+
return typeof value === 'number' ? value : undefined;
|
|
105
|
+
}
|
|
83
106
|
export class RelationIdleMonitor {
|
|
84
107
|
deps;
|
|
85
108
|
entries = new Map();
|
|
@@ -90,7 +113,7 @@ export class RelationIdleMonitor {
|
|
|
90
113
|
this.deps = deps;
|
|
91
114
|
this.now = deps.now ?? Date.now;
|
|
92
115
|
}
|
|
93
|
-
/**
|
|
116
|
+
/** 加载落盘状态。中断的链按「原兜底时钟仍在」恢复。兼容 version 1(lastInboundAt)。 */
|
|
94
117
|
load() {
|
|
95
118
|
let raw;
|
|
96
119
|
try {
|
|
@@ -99,21 +122,27 @@ export class RelationIdleMonitor {
|
|
|
99
122
|
catch {
|
|
100
123
|
return;
|
|
101
124
|
}
|
|
102
|
-
if (!raw || raw.version !== 1 || !Array.isArray(raw.entries))
|
|
125
|
+
if (!raw || (raw.version !== 1 && raw.version !== 2) || !Array.isArray(raw.entries))
|
|
103
126
|
return;
|
|
104
127
|
for (const item of raw.entries) {
|
|
105
128
|
if (!item?.selfAid || !item?.peerKey)
|
|
106
129
|
continue;
|
|
130
|
+
const lastActivityAt = numberOrUndefined(item.lastActivityAt) ?? numberOrUndefined(item.lastInboundAt);
|
|
131
|
+
const firstUnsweptAt = numberOrUndefined(item.firstUnsweptAt);
|
|
107
132
|
const entry = {
|
|
108
133
|
selfAid: item.selfAid,
|
|
109
134
|
peerKey: item.peerKey,
|
|
110
|
-
...(
|
|
111
|
-
...(
|
|
135
|
+
...(lastActivityAt !== undefined ? { lastActivityAt } : {}),
|
|
136
|
+
...(firstUnsweptAt !== undefined ? { firstUnsweptAt } : {}),
|
|
137
|
+
...(item.idleConsumed === true ? { idleConsumed: true } : {}),
|
|
112
138
|
...(item.route ? { route: item.route } : {}),
|
|
113
139
|
};
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
|
|
140
|
+
// 上次进程退出时链还在跑:那一轮没跑完,兜底时钟按链开始前的起点恢复,空闲立即到期重跑
|
|
141
|
+
const sweepingSince = numberOrUndefined(item.sweepingSince);
|
|
142
|
+
if (sweepingSince !== undefined) {
|
|
143
|
+
const clock = numberOrUndefined(item.sweepClockFrom) ?? sweepingSince;
|
|
144
|
+
entry.firstUnsweptAt = Math.min(entry.firstUnsweptAt ?? clock, clock);
|
|
145
|
+
entry.idleConsumed = undefined;
|
|
117
146
|
}
|
|
118
147
|
this.entries.set(relationKey(entry.selfAid, entry.peerKey), entry);
|
|
119
148
|
}
|
|
@@ -136,53 +165,74 @@ export class RelationIdleMonitor {
|
|
|
136
165
|
this.saveTimer = undefined;
|
|
137
166
|
this.saveNow();
|
|
138
167
|
}
|
|
139
|
-
/**
|
|
140
|
-
|
|
168
|
+
/** 关系有一次活动(入站、写 note、被群链写入)。 */
|
|
169
|
+
recordActivity(activity) {
|
|
170
|
+
if (!isConsolidatableRelation(activity.peerKey))
|
|
171
|
+
return;
|
|
141
172
|
const at = this.now();
|
|
142
|
-
const entry = this.ensureEntry(
|
|
143
|
-
entry.
|
|
173
|
+
const entry = this.ensureEntry(activity.selfAid, activity.peerKey);
|
|
174
|
+
entry.lastActivityAt = at;
|
|
144
175
|
if (entry.firstUnsweptAt === undefined)
|
|
145
176
|
entry.firstUnsweptAt = at;
|
|
146
|
-
entry.
|
|
177
|
+
entry.idleConsumed = undefined;
|
|
178
|
+
if (activity.route)
|
|
179
|
+
entry.route = activity.route;
|
|
147
180
|
this.schedule(entry);
|
|
148
181
|
this.scheduleSave();
|
|
149
182
|
}
|
|
150
183
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
184
|
+
* 启动时补登:关系 pending/ 里有 note 却没有兜底时钟(部署前写的、计时状态丢失、
|
|
185
|
+
* 上一轮因不能整理而作废后没有新活动)时,按最老 note 的时间补一次活动。
|
|
186
|
+
* 已有时钟或链在跑的不动。最老 note 已满兜底时长的,start() 后立即强制整理。
|
|
153
187
|
*/
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (!this.deps.canSweep(selfAid, peerKey))
|
|
188
|
+
seedPending(selfAid, peerKey, oldestNoteAt) {
|
|
189
|
+
if (!isConsolidatableRelation(peerKey))
|
|
157
190
|
return;
|
|
158
191
|
const entry = this.ensureEntry(selfAid, peerKey);
|
|
159
|
-
if (entry.sweepingSince !== undefined)
|
|
160
|
-
entry.sweepRequested = true;
|
|
192
|
+
if (entry.firstUnsweptAt !== undefined || entry.sweepingSince !== undefined)
|
|
161
193
|
return;
|
|
162
|
-
|
|
163
|
-
|
|
194
|
+
entry.firstUnsweptAt = oldestNoteAt;
|
|
195
|
+
entry.lastActivityAt = Math.max(entry.lastActivityAt ?? 0, oldestNoteAt);
|
|
196
|
+
entry.idleConsumed = undefined;
|
|
197
|
+
this.schedule(entry);
|
|
198
|
+
this.scheduleSave();
|
|
164
199
|
}
|
|
165
200
|
/** 整理链结束(无论成败、无论起没起会话)。 */
|
|
166
|
-
onSweepFinished(selfAid, peerKey) {
|
|
201
|
+
onSweepFinished(selfAid, peerKey, outcome = {}) {
|
|
167
202
|
const entry = this.entries.get(relationKey(selfAid, peerKey));
|
|
168
203
|
if (!entry || entry.sweepingSince === undefined)
|
|
169
204
|
return;
|
|
205
|
+
const startedAt = entry.sweepingSince;
|
|
206
|
+
const clockFrom = entry.sweepClockFrom;
|
|
170
207
|
entry.sweepingSince = undefined;
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
208
|
+
entry.sweepClockFrom = undefined;
|
|
209
|
+
let restoreAt;
|
|
210
|
+
// 推迟:这一轮没整理完,兜底按原起点继续
|
|
211
|
+
if (outcome.deferred && clockFrom !== undefined)
|
|
212
|
+
restoreAt = clockFrom;
|
|
213
|
+
// 失败:从现在起重新计兜底,避免原起点早已过期导致连环重试
|
|
214
|
+
if (outcome.failed)
|
|
215
|
+
restoreAt = Math.min(restoreAt ?? this.now(), this.now());
|
|
216
|
+
if (restoreAt !== undefined) {
|
|
217
|
+
entry.firstUnsweptAt = Math.min(entry.firstUnsweptAt ?? restoreAt, restoreAt);
|
|
218
|
+
// 链运行期间没有新活动:这一轮空闲已经用掉,等下一次活动或兜底
|
|
219
|
+
if ((entry.lastActivityAt ?? 0) <= startedAt)
|
|
220
|
+
entry.idleConsumed = true;
|
|
175
221
|
}
|
|
176
222
|
this.schedule(entry);
|
|
177
223
|
this.scheduleSave();
|
|
178
224
|
}
|
|
225
|
+
/** 关系最近一次入站记下的路由(定时检查拉起 profile / forget 时复用)。 */
|
|
226
|
+
routeOf(selfAid, peerKey) {
|
|
227
|
+
return this.entries.get(relationKey(selfAid, peerKey))?.route;
|
|
228
|
+
}
|
|
179
229
|
/** 测试与诊断用:当前状态快照。 */
|
|
180
230
|
snapshot(selfAid, peerKey) {
|
|
181
231
|
const entry = this.entries.get(relationKey(selfAid, peerKey));
|
|
182
232
|
if (!entry)
|
|
183
233
|
return undefined;
|
|
184
234
|
const { timer: _timer, ...rest } = entry;
|
|
185
|
-
return { ...rest, dueAt: this.
|
|
235
|
+
return { ...rest, dueAt: this.due(entry)?.at };
|
|
186
236
|
}
|
|
187
237
|
ensureEntry(selfAid, peerKey) {
|
|
188
238
|
const key = relationKey(selfAid, peerKey);
|
|
@@ -193,15 +243,18 @@ export class RelationIdleMonitor {
|
|
|
193
243
|
}
|
|
194
244
|
return entry;
|
|
195
245
|
}
|
|
196
|
-
/**
|
|
197
|
-
|
|
246
|
+
/** 下一次到期:空闲(已消费则不计)与兜底取较早者。没有待整理活动时不计时。 */
|
|
247
|
+
due(entry) {
|
|
198
248
|
if (entry.firstUnsweptAt === undefined)
|
|
199
249
|
return undefined;
|
|
200
250
|
const timing = this.deps.getTiming(entry.selfAid);
|
|
201
251
|
const idleMs = positiveHours(timing?.idleHours, DEFAULT_RELATION_IDLE_HOURS) * HOUR_MS;
|
|
202
252
|
const maxMs = positiveHours(timing?.maxUnconsolidatedHours, DEFAULT_MAX_UNCONSOLIDATED_HOURS) * HOUR_MS;
|
|
203
|
-
const
|
|
204
|
-
|
|
253
|
+
const forceAt = entry.firstUnsweptAt + maxMs;
|
|
254
|
+
const idleAt = entry.idleConsumed
|
|
255
|
+
? Infinity
|
|
256
|
+
: (entry.lastActivityAt ?? entry.firstUnsweptAt) + idleMs;
|
|
257
|
+
return { at: Math.min(idleAt, forceAt), forceAt };
|
|
205
258
|
}
|
|
206
259
|
schedule(entry) {
|
|
207
260
|
if (entry.timer)
|
|
@@ -209,46 +262,52 @@ export class RelationIdleMonitor {
|
|
|
209
262
|
entry.timer = undefined;
|
|
210
263
|
if (!this.active || entry.sweepingSince !== undefined)
|
|
211
264
|
return;
|
|
212
|
-
const due = this.
|
|
213
|
-
if (due
|
|
265
|
+
const due = this.due(entry);
|
|
266
|
+
if (!due)
|
|
214
267
|
return;
|
|
215
|
-
const delay = Math.max(0, Math.min(due - this.now(), MAX_TIMER_MS));
|
|
268
|
+
const delay = Math.max(0, Math.min(due.at - this.now(), MAX_TIMER_MS));
|
|
216
269
|
entry.timer = setTimeout(() => {
|
|
217
270
|
entry.timer = undefined;
|
|
218
271
|
// 分段等待:还没到真正的到期时间就再排一次
|
|
219
|
-
|
|
272
|
+
const current = this.due(entry);
|
|
273
|
+
if (!current)
|
|
274
|
+
return;
|
|
275
|
+
if (current.at > this.now()) {
|
|
220
276
|
this.schedule(entry);
|
|
221
277
|
return;
|
|
222
278
|
}
|
|
223
|
-
this.fire(entry);
|
|
279
|
+
this.fire(entry, this.now() >= current.forceAt);
|
|
224
280
|
}, delay);
|
|
225
281
|
entry.timer.unref?.();
|
|
226
282
|
}
|
|
227
|
-
fire(entry) {
|
|
283
|
+
fire(entry, force) {
|
|
228
284
|
if (!this.active || entry.sweepingSince !== undefined)
|
|
229
285
|
return;
|
|
230
286
|
if (!this.deps.canSweep(entry.selfAid, entry.peerKey)) {
|
|
231
|
-
//
|
|
287
|
+
// 现在整理不了(开关关闭、首次设定未完成等):这一轮作废,等下一次活动重新计时
|
|
232
288
|
entry.firstUnsweptAt = undefined;
|
|
289
|
+
entry.idleConsumed = undefined;
|
|
233
290
|
this.scheduleSave();
|
|
234
291
|
return;
|
|
235
292
|
}
|
|
236
|
-
this.begin(entry,
|
|
293
|
+
this.begin(entry, force);
|
|
237
294
|
}
|
|
238
|
-
begin(entry,
|
|
295
|
+
begin(entry, force) {
|
|
239
296
|
if (entry.timer)
|
|
240
297
|
clearTimeout(entry.timer);
|
|
241
298
|
entry.timer = undefined;
|
|
242
299
|
entry.sweepingSince = this.now();
|
|
300
|
+
entry.sweepClockFrom = entry.firstUnsweptAt;
|
|
243
301
|
entry.firstUnsweptAt = undefined;
|
|
302
|
+
entry.idleConsumed = undefined;
|
|
244
303
|
this.scheduleSave();
|
|
245
|
-
logger.info(`[Memory] 关系整理链开始(aid=${entry.selfAid},peerKey=${entry.peerKey})`);
|
|
304
|
+
logger.info(`[Memory] 关系整理链开始(aid=${entry.selfAid},peerKey=${entry.peerKey},${force ? '兜底到期' : '空闲到期'})`);
|
|
246
305
|
try {
|
|
247
|
-
this.deps.startSweep({ selfAid: entry.selfAid, peerKey: entry.peerKey, route: entry.route,
|
|
306
|
+
this.deps.startSweep({ selfAid: entry.selfAid, peerKey: entry.peerKey, route: entry.route, force });
|
|
248
307
|
}
|
|
249
308
|
catch (error) {
|
|
250
309
|
logger.warn(`[Memory] 关系整理链启动失败(peerKey=${entry.peerKey}): ${error?.message}`);
|
|
251
|
-
this.onSweepFinished(entry.selfAid, entry.peerKey);
|
|
310
|
+
this.onSweepFinished(entry.selfAid, entry.peerKey, { failed: true });
|
|
252
311
|
}
|
|
253
312
|
}
|
|
254
313
|
scheduleSave() {
|
|
@@ -265,20 +324,22 @@ export class RelationIdleMonitor {
|
|
|
265
324
|
const entries = [];
|
|
266
325
|
for (const entry of this.entries.values()) {
|
|
267
326
|
const pending = entry.firstUnsweptAt !== undefined || entry.sweepingSince !== undefined;
|
|
268
|
-
if (!pending && (entry.
|
|
327
|
+
if (!pending && (entry.lastActivityAt === undefined || now - entry.lastActivityAt > PRUNE_AFTER_MS))
|
|
269
328
|
continue;
|
|
270
329
|
entries.push({
|
|
271
330
|
selfAid: entry.selfAid,
|
|
272
331
|
peerKey: entry.peerKey,
|
|
273
|
-
...(entry.
|
|
332
|
+
...(entry.lastActivityAt !== undefined ? { lastActivityAt: entry.lastActivityAt } : {}),
|
|
274
333
|
...(entry.firstUnsweptAt !== undefined ? { firstUnsweptAt: entry.firstUnsweptAt } : {}),
|
|
334
|
+
...(entry.idleConsumed ? { idleConsumed: true } : {}),
|
|
275
335
|
...(entry.sweepingSince !== undefined ? { sweepingSince: entry.sweepingSince } : {}),
|
|
336
|
+
...(entry.sweepClockFrom !== undefined ? { sweepClockFrom: entry.sweepClockFrom } : {}),
|
|
276
337
|
...(entry.route ? { route: entry.route } : {}),
|
|
277
338
|
});
|
|
278
339
|
}
|
|
279
340
|
try {
|
|
280
341
|
fs.mkdirSync(path.dirname(this.deps.statePath), { recursive: true });
|
|
281
|
-
atomicWriteJson(this.deps.statePath, { version:
|
|
342
|
+
atomicWriteJson(this.deps.statePath, { version: 2, entries });
|
|
282
343
|
}
|
|
283
344
|
catch (error) {
|
|
284
345
|
logger.warn(`[Memory] 关系空闲状态落盘失败: ${error?.message}`);
|
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* relation-sweep.ts — 关系整理链
|
|
3
3
|
*
|
|
4
|
-
* 一个关系空闲 /
|
|
4
|
+
* 一个关系空闲 / 兜底到期后,对它依次跑内容驱动的三步:
|
|
5
5
|
*
|
|
6
|
-
* notes → generalize → promote(仅 owner
|
|
6
|
+
* notes → generalize → promote(仅 owner 关系)
|
|
7
7
|
*
|
|
8
|
-
* 每一步在上一步收尾之后才判定要不要做(notes 新产出的 to-generalize 要被第 2
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* 每一步在上一步收尾之后才判定要不要做(notes 新产出的 to-generalize 要被第 2 步看到):
|
|
9
|
+
* - 兜底到期(force):有 1 条候选就跑
|
|
10
|
+
* - 空闲到期:候选攒够 memory.minBatchItems 才跑,不够的推迟(结果标 deferred)
|
|
11
|
+
* 没有候选的步骤跳过,一个都不跑就一个会话都不起。所有步骤走同一个整理队列,同 agent 串行。
|
|
12
|
+
* 触发来源记为 `relation-idle`,静默不反馈。画像与关系层遗忘是时间驱动的,由全局定时检查负责。
|
|
13
|
+
*
|
|
14
|
+
* 结果里的 deferred / failed 交给监视器决定兜底时钟怎么续(见 relation-idle-monitor.ts)。
|
|
11
15
|
*
|
|
12
16
|
* 链中途收到新入站不中断:兜底本就发生在聊天进行中,主会话只写 pending,链写 consolidated。
|
|
13
17
|
*
|
|
14
|
-
* 群聊 notes 会按发言人用 `--peer`
|
|
15
|
-
*
|
|
16
|
-
* 由调用方各自补一轮整理(不再继续传播)。
|
|
18
|
+
* 群聊 notes 会按发言人用 `--peer` 把记忆写进发言人自己的关系。链结束时把这些关系交给
|
|
19
|
+
* onSweepFinished 的 touchedPeerKeys,由调用方记为该关系的一次活动。
|
|
17
20
|
*/
|
|
18
21
|
import { logger } from '../../utils/logger.js';
|
|
19
|
-
import { RELATION_SWEEP_ORDER,
|
|
22
|
+
import { RELATION_SWEEP_ORDER, judgeRelationMode } from './consolidation-trigger.js';
|
|
23
|
+
import { taskContextOfRoute } from './relation-idle-monitor.js';
|
|
20
24
|
/** 单步整理会话迟迟不收尾时,链最多等这么久就放弃(整理会话自身 15 分钟超时,留余量)。 */
|
|
21
25
|
const DEFAULT_STEP_WATCHDOG_MS = 30 * 60_000;
|
|
22
26
|
/**
|
|
@@ -40,11 +44,11 @@ let sweepSeq = 0;
|
|
|
40
44
|
export class RelationSweepRunner {
|
|
41
45
|
deps;
|
|
42
46
|
sweeps = new Map();
|
|
43
|
-
|
|
47
|
+
judgeMode;
|
|
44
48
|
stepWatchdogMs;
|
|
45
49
|
constructor(deps) {
|
|
46
50
|
this.deps = deps;
|
|
47
|
-
this.
|
|
51
|
+
this.judgeMode = deps.judgeMode ?? judgeRelationMode;
|
|
48
52
|
this.stepWatchdogMs = deps.stepWatchdogMs ?? DEFAULT_STEP_WATCHDOG_MS;
|
|
49
53
|
}
|
|
50
54
|
/** 开始一条整理链。保证之后恰好调用一次 onSweepFinished。 */
|
|
@@ -55,6 +59,8 @@ export class RelationSweepRunner {
|
|
|
55
59
|
request,
|
|
56
60
|
remaining: [...RELATION_SWEEP_ORDER],
|
|
57
61
|
ran: [],
|
|
62
|
+
deferred: false,
|
|
63
|
+
failed: false,
|
|
58
64
|
touched: new Set(),
|
|
59
65
|
step: 0,
|
|
60
66
|
};
|
|
@@ -71,12 +77,12 @@ export class RelationSweepRunner {
|
|
|
71
77
|
const state = this.currentStep(info.relationSweepId, info.sessionId);
|
|
72
78
|
if (!state)
|
|
73
79
|
return;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
state.touched.add(peerKey);
|
|
78
|
-
}
|
|
80
|
+
for (const peerKey of info.touchedPeerKeys) {
|
|
81
|
+
if (peerKey !== state.request.peerKey)
|
|
82
|
+
state.touched.add(peerKey);
|
|
79
83
|
}
|
|
84
|
+
if (!info.success)
|
|
85
|
+
state.failed = true;
|
|
80
86
|
this.stepDone(state);
|
|
81
87
|
}
|
|
82
88
|
/** 排队后拉起失败的通知(来自 ConsolidationQueue.setLaunchFailedListener)。 */
|
|
@@ -84,6 +90,7 @@ export class RelationSweepRunner {
|
|
|
84
90
|
const state = this.currentStep(params.relationSweepId);
|
|
85
91
|
if (!state)
|
|
86
92
|
return;
|
|
93
|
+
state.failed = true;
|
|
87
94
|
this.stepDone(state);
|
|
88
95
|
}
|
|
89
96
|
/** 回调对应的是某条链**正在等的那一步**时返回该链;过期步骤、无关会话返回 undefined。 */
|
|
@@ -119,35 +126,29 @@ export class RelationSweepRunner {
|
|
|
119
126
|
void this.advance(state);
|
|
120
127
|
}
|
|
121
128
|
async advance(state) {
|
|
122
|
-
const { selfAid, peerKey, route } = state.request;
|
|
129
|
+
const { selfAid, peerKey, route, force } = state.request;
|
|
123
130
|
while (state.remaining.length > 0) {
|
|
124
131
|
const mode = state.remaining.shift();
|
|
125
132
|
const agent = this.deps.getAgent(selfAid);
|
|
126
133
|
const memoryConfig = agent?.config?.memory;
|
|
127
|
-
let
|
|
134
|
+
let verdict = 'none';
|
|
128
135
|
try {
|
|
129
|
-
|
|
136
|
+
verdict = this.judgeMode({ mode, selfAid, peerKey, ownerAid: state.ownerAid, config: memoryConfig, force });
|
|
130
137
|
}
|
|
131
138
|
catch (error) {
|
|
132
139
|
logger.warn(`[Memory] 关系整理链判定失败(peerKey=${peerKey},mode=${mode}): ${error?.message}`);
|
|
133
140
|
}
|
|
134
|
-
if (
|
|
141
|
+
if (verdict === 'defer') {
|
|
142
|
+
state.deferred = true;
|
|
135
143
|
continue;
|
|
136
|
-
|
|
144
|
+
}
|
|
145
|
+
if (verdict !== 'run')
|
|
146
|
+
continue;
|
|
147
|
+
if (!agent?.baseagent) {
|
|
148
|
+
state.failed = true;
|
|
137
149
|
break;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
peerKey,
|
|
141
|
-
baseagent: agent.baseagent,
|
|
142
|
-
...(route ? {
|
|
143
|
-
channel: route.channel,
|
|
144
|
-
channelId: route.channelId,
|
|
145
|
-
peerId: route.peerId,
|
|
146
|
-
chatType: route.chatType,
|
|
147
|
-
...(route.channelKey ? { channelKey: route.channelKey } : {}),
|
|
148
|
-
...(route.threadId ? { threadId: route.threadId } : {}),
|
|
149
|
-
} : {}),
|
|
150
|
-
};
|
|
150
|
+
}
|
|
151
|
+
const taskCtx = { selfAid, peerKey, baseagent: agent.baseagent, ...taskContextOfRoute(route) };
|
|
151
152
|
// 先挂上等待标记再入队:会话可能在 enqueue 返回前就收尾,收尾回调要能认出这一步
|
|
152
153
|
const token = ++state.step;
|
|
153
154
|
state.waiting = mode;
|
|
@@ -158,8 +159,6 @@ export class RelationSweepRunner {
|
|
|
158
159
|
mode,
|
|
159
160
|
triggeredBy: 'relation-idle',
|
|
160
161
|
ownerAid: state.ownerAid,
|
|
161
|
-
forgetAfterDays: memoryConfig?.forgetAfterDays,
|
|
162
|
-
...(mode === 'forget' ? { scopeOverride: 'relation' } : {}),
|
|
163
162
|
relationSweepId: stepTag(state.id, token),
|
|
164
163
|
});
|
|
165
164
|
}
|
|
@@ -175,6 +174,7 @@ export class RelationSweepRunner {
|
|
|
175
174
|
if (!launched) {
|
|
176
175
|
// 立即拉起失败:这一步作废,继续下一步
|
|
177
176
|
state.waiting = undefined;
|
|
177
|
+
state.failed = true;
|
|
178
178
|
continue;
|
|
179
179
|
}
|
|
180
180
|
state.ran.push(mode);
|
|
@@ -182,6 +182,7 @@ export class RelationSweepRunner {
|
|
|
182
182
|
state.waitingSessionId = launched.executionSessionId;
|
|
183
183
|
state.watchdog = setTimeout(() => {
|
|
184
184
|
logger.warn(`[Memory] 关系整理链等待收尾超时,跳过该步(peerKey=${peerKey},mode=${mode})`);
|
|
185
|
+
state.failed = true;
|
|
185
186
|
this.stepDone(state);
|
|
186
187
|
}, this.stepWatchdogMs);
|
|
187
188
|
state.watchdog.unref?.();
|
|
@@ -193,11 +194,15 @@ export class RelationSweepRunner {
|
|
|
193
194
|
if (!this.sweeps.delete(state.id))
|
|
194
195
|
return;
|
|
195
196
|
const { selfAid, peerKey } = state.request;
|
|
196
|
-
if (state.ran.length > 0) {
|
|
197
|
-
logger.info(`[Memory] 关系整理链结束(aid=${selfAid},peerKey=${peerKey}):${state.ran.join(' → ')}`
|
|
197
|
+
if (state.ran.length > 0 || state.deferred) {
|
|
198
|
+
logger.info(`[Memory] 关系整理链结束(aid=${selfAid},peerKey=${peerKey}):${state.ran.join(' → ') || '无'}`
|
|
199
|
+
+ `${state.deferred ? ',有步骤候选不足已推迟' : ''}${state.failed ? ',有步骤失败' : ''}`);
|
|
198
200
|
}
|
|
199
201
|
try {
|
|
200
|
-
this.deps.onSweepFinished({
|
|
202
|
+
this.deps.onSweepFinished({
|
|
203
|
+
selfAid, peerKey, ran: state.ran, deferred: state.deferred, failed: state.failed,
|
|
204
|
+
touchedPeerKeys: [...state.touched],
|
|
205
|
+
});
|
|
201
206
|
}
|
|
202
207
|
catch (error) {
|
|
203
208
|
logger.warn(`[Memory] 关系整理链结束回调失败(peerKey=${peerKey}): ${error?.message}`);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveAunSendDevice } from '../../aun/ability-device-routing.js';
|
|
1
2
|
import crypto from 'crypto';
|
|
2
3
|
import { authorizeDelegatedAunMsgSend, } from '../auth/agent-delegation.js';
|
|
3
4
|
import { formatChannelKey, tryParseChannelKey } from '../channel-loader.js';
|
|
@@ -5,7 +6,7 @@ import { AUN_HANDOFF_MARKER_FIELD } from '../../channels/aun.js';
|
|
|
5
6
|
import { classifyAunPayloadForLog } from './message-log.js';
|
|
6
7
|
import { isValidAunDeliveryForChannel } from './outbound.js';
|
|
7
8
|
import { isHClassPath } from '../permission/protected-paths.js';
|
|
8
|
-
import { evaluateOutboundContactAdmission } from './message-admission.js';
|
|
9
|
+
import { ensureOutboundContactForSend, evaluateOutboundContactAdmission } from './message-admission.js';
|
|
9
10
|
import { normalizeAunMentionEntries, withAunAttention } from '../../aun/msg/mention-schema.js';
|
|
10
11
|
import { resolveManagedSendArgv } from '../../cli/aun-commands.js';
|
|
11
12
|
import { readTriggerLocalFile, resolveAttachmentLocalPath } from '../../trigger/local-files.js';
|
|
@@ -14,7 +15,8 @@ import { sameGroupAid } from '../../aun/group/identity.js';
|
|
|
14
15
|
import { resolveThreadRouteTarget } from '../thread/thread-route.js';
|
|
15
16
|
import { isTopicThreadId, parseMainTopicId, safeFormatMainTopicId, sessionLocalTopicId } from '../thread/topic-id.js';
|
|
16
17
|
import { ThreadService } from '../thread/thread-service.js';
|
|
17
|
-
import { getAunRequestRegistry, requestTtlSeconds } from './aun-request-registry.js';
|
|
18
|
+
import { getAunRequestRegistry, requestDiagnostics, requestTtlSeconds } from './aun-request-registry.js';
|
|
19
|
+
import { parseJsonObjectArgument } from '../permission/ec-command-parser.js';
|
|
18
20
|
const TASK_ID_MESSAGE_PAYLOAD_TYPES = new Set(['text', 'link', 'image', 'video', 'voice', 'file']);
|
|
19
21
|
/** payload.debug 只是诊断字段:取不到时照常发送,不带 debug。 */
|
|
20
22
|
async function resolveOutboundDebug(resolver, sessionId) {
|
|
@@ -242,18 +244,21 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
242
244
|
});
|
|
243
245
|
const sender = async (params) => {
|
|
244
246
|
let textFile;
|
|
247
|
+
let payloadFile;
|
|
245
248
|
try {
|
|
246
249
|
if (params.argv !== undefined) {
|
|
247
250
|
const command = resolveManagedSendArgv(params.argv);
|
|
248
251
|
textFile = command.textFile;
|
|
252
|
+
payloadFile = command.payloadFile;
|
|
249
253
|
params = { ...params, ...command };
|
|
250
254
|
}
|
|
251
255
|
else if (!params.aid || !params.to || !params.scope) {
|
|
252
256
|
return { ok: false, code: 'INVALID_REQUEST', error: 'Managed AUN sends require command parameters' };
|
|
253
257
|
}
|
|
258
|
+
params.deviceId = resolveAunSendDevice(params.deviceId, params.scope, params.payload);
|
|
254
259
|
}
|
|
255
260
|
catch (error) {
|
|
256
|
-
return { ok: false, code: 'INVALID_ARGUMENT', error: error instanceof Error ? error.message : String(error) };
|
|
261
|
+
return { ok: false, code: error.code ?? 'INVALID_ARGUMENT', error: error instanceof Error ? error.message : String(error) };
|
|
257
262
|
}
|
|
258
263
|
// 活跃任务走内存上下文;调试会话(--as-session)和已结束的会话没有内存记录,
|
|
259
264
|
// 这时从会话本身重建,否则跨话题复查会静默不创建(getTaskRuntimeContext 返回 null)。
|
|
@@ -331,7 +336,7 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
331
336
|
? { selfAid: delegation.grant.selfAid, projectPath: runtime.projectPath,
|
|
332
337
|
sessionRuntimeDir: delegation.grant.sessionRuntimeDir, cwd: runtime.projectPath }
|
|
333
338
|
: undefined;
|
|
334
|
-
if ((textFile || params.file) && !fileScope)
|
|
339
|
+
if ((textFile || payloadFile || params.file) && !fileScope)
|
|
335
340
|
throw new Error('Current task project context is unavailable');
|
|
336
341
|
if (textFile) {
|
|
337
342
|
const text = new TextDecoder('utf-8', { fatal: true }).decode(readTriggerLocalFile(textFile, fileScope));
|
|
@@ -339,9 +344,14 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
339
344
|
throw new Error('Message file must contain nonempty UTF-8 text');
|
|
340
345
|
params.payload = { type: 'text', text };
|
|
341
346
|
}
|
|
347
|
+
if (payloadFile) {
|
|
348
|
+
const raw = new TextDecoder('utf-8', { fatal: true }).decode(readTriggerLocalFile(payloadFile, fileScope));
|
|
349
|
+
params.payload = parseJsonObjectArgument(raw, '--payload-file');
|
|
350
|
+
}
|
|
342
351
|
if (params.file) {
|
|
343
352
|
params.file = { ...params.file, filePath: resolveAttachmentLocalPath(params.file.filePath, fileScope) };
|
|
344
353
|
}
|
|
354
|
+
params.deviceId = resolveAunSendDevice(params.deviceId, params.scope, params.payload);
|
|
345
355
|
if (params.payload && params.rawPayload !== true)
|
|
346
356
|
params.payload = withAunAttention(params.payload);
|
|
347
357
|
const currentRelation = runtime?.channel === 'aun' && runtime.selfAid === params.aid
|
|
@@ -351,7 +361,11 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
351
361
|
? params.payload.thread_id.trim() : params.thread ?? (currentRelation ? runtime?.threadId : undefined);
|
|
352
362
|
}
|
|
353
363
|
catch (error) {
|
|
354
|
-
return {
|
|
364
|
+
return {
|
|
365
|
+
ok: false,
|
|
366
|
+
code: error?.code ?? 'INVALID_LOCAL_FILE',
|
|
367
|
+
error: error instanceof Error ? error.message : String(error),
|
|
368
|
+
};
|
|
355
369
|
}
|
|
356
370
|
const inst = channelInstances.find((candidate) => {
|
|
357
371
|
if (candidate.channelType !== 'aun')
|
|
@@ -372,7 +386,13 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
372
386
|
return { ok: false, error: `AUN channel not found for ${params.aid}`, code: 'AUN_CHANNEL_NOT_FOUND' };
|
|
373
387
|
}
|
|
374
388
|
if (params.scope === 'msg') {
|
|
375
|
-
const admission =
|
|
389
|
+
const admission = params.argv !== undefined
|
|
390
|
+
? await ensureOutboundContactForSend({
|
|
391
|
+
selfAid: params.aid,
|
|
392
|
+
targetAid: params.to,
|
|
393
|
+
actorId: delegation.grant?.actorId ?? 'managed-outbound-send',
|
|
394
|
+
})
|
|
395
|
+
: await evaluateOutboundContactAdmission({ selfAid: params.aid, targetAid: params.to });
|
|
376
396
|
if (!admission.allow) {
|
|
377
397
|
return { ok: false, error: admission.error, code: admission.code };
|
|
378
398
|
}
|
|
@@ -469,6 +489,7 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
469
489
|
preparedRequest = getAunRequestRegistry().prepare({
|
|
470
490
|
selfAid: params.aid,
|
|
471
491
|
targetAid: params.to,
|
|
492
|
+
targetDeviceId: params.deviceId,
|
|
472
493
|
payload,
|
|
473
494
|
timeoutMs: params.timeoutMs ?? 60_000,
|
|
474
495
|
...(runtime && delegation.grant ? { origin: {
|
|
@@ -602,6 +623,7 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
602
623
|
}
|
|
603
624
|
const sent = await ch.sendDaemonMsg({
|
|
604
625
|
to: params.to,
|
|
626
|
+
deviceId: params.deviceId,
|
|
605
627
|
payload,
|
|
606
628
|
rawPayload: params.rawPayload,
|
|
607
629
|
ttl: requestTtl,
|
|
@@ -616,7 +638,10 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
616
638
|
const request = getAunRequestRegistry().markFailed(params.aid, preparedRequest.requestId, transportError);
|
|
617
639
|
if (request?.state === 'completed') {
|
|
618
640
|
return { ok: true, request_id: preparedRequest.requestId, request_state: request.state,
|
|
619
|
-
|
|
641
|
+
...(request.responsePayload ? { response: request.responsePayload } : {}),
|
|
642
|
+
...(request.responses ? { responses: request.responses } : {}),
|
|
643
|
+
...(request ? { request_diagnostics: requestDiagnostics(request) } : {}),
|
|
644
|
+
transport_error: transportError, retryable: false, sent: true };
|
|
620
645
|
}
|
|
621
646
|
return { ...sent, ok: false, request_id: preparedRequest.requestId, request_state: request?.state ?? 'failed' };
|
|
622
647
|
}
|
|
@@ -627,6 +652,8 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
627
652
|
request_id: preparedRequest.requestId,
|
|
628
653
|
request_state: completed?.state ?? 'unknown',
|
|
629
654
|
...(completed?.responsePayload ? { response: completed.responsePayload } : {}),
|
|
655
|
+
...(completed?.responses ? { responses: completed.responses } : {}),
|
|
656
|
+
...(completed ? { request_diagnostics: requestDiagnostics(completed) } : {}),
|
|
630
657
|
};
|
|
631
658
|
}
|
|
632
659
|
if (params.thread && params.checkEveryMs !== undefined && sent.ok && sent.message_id && threadRoute) {
|