evolcore 0.0.41 → 0.0.42-test.0
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 +36 -0
- package/bin/codex-managed-hook.mjs +9 -5
- package/dist/agents/baseagent.js +156 -16
- package/dist/agents/claude-runner.js +10 -3
- package/dist/agents/codex/catalog.js +8 -4
- package/dist/agents/codex-runner.js +236 -59
- package/dist/agents/ecagent-runner.js +82 -13
- package/dist/aun/aid/agentmd.js +106 -27
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/aid/control-aid.js +65 -13
- package/dist/aun/aid/identity.js +70 -4
- package/dist/aun/aid/index.js +2 -2
- package/dist/aun/service-proxy.js +25 -1
- package/dist/channels/aun.js +242 -209
- package/dist/channels/dingtalk.js +1 -1
- package/dist/channels/feishu.js +1 -1
- package/dist/channels/qqbot.js +1 -1
- package/dist/channels/wechat.js +1 -1
- package/dist/channels/wecom.js +1 -1
- package/dist/cli/agent-command.js +183 -3
- package/dist/cli/agent-create.js +92 -86
- package/dist/cli/agent.js +136 -1
- package/dist/cli/aun-commands.js +137 -35
- package/dist/cli/bench.js +8 -2
- package/dist/cli/command-log.js +1 -1
- package/dist/cli/daemon-commands.js +235 -51
- package/dist/cli/debug-mode.js +1 -1
- package/dist/cli/directory.js +170 -0
- package/dist/cli/index.js +40 -30
- package/dist/cli/init-channel.js +4 -4
- package/dist/cli/init.js +47 -32
- package/dist/cli/managed-command-guard.js +4 -1
- package/dist/cli/model.js +27 -18
- package/dist/cli/pa-workspace-command.js +191 -0
- package/dist/cli/{contact.js → peer.js} +19 -25
- package/dist/cli/restart-monitor.js +11 -4
- package/dist/cli/thread-command.js +47 -18
- package/dist/cli/version.js +18 -18
- package/dist/config/access-policy.js +29 -12
- package/dist/config/boot-log.js +65 -10
- package/dist/config/builtin-roles.js +2 -4
- package/dist/config/config-field-policy.js +3 -0
- package/dist/config/config-manager.js +28 -20
- package/dist/config/{contact-bind-code.js → peer-bind-code.js} +6 -6
- package/dist/config/{contact-book-store.js → peer-book-store.js} +75 -75
- package/dist/config/{contact-book-v2-startup.js → peer-book-v2-startup.js} +2 -2
- package/dist/config/{contact-book.js → peer-book.js} +47 -47
- package/dist/config/peer-operation-service.js +132 -0
- package/dist/config/{contact-request-service.js → peer-request-service.js} +90 -90
- package/dist/config/peer-role-resolver.js +3 -3
- package/dist/config/providers-config.js +17 -8
- package/dist/config/providers.js +1 -1
- package/dist/config/schema-migration.js +336 -39
- package/dist/core/agent-application-service.js +8 -2
- package/dist/core/agent-create-status.js +4 -5
- package/dist/core/agent-ipc-registration.js +5 -4
- package/dist/core/agent-runtime.js +30 -17
- package/dist/core/auth/operation-authorizer.js +0 -24
- package/dist/core/auth/operation-catalog.js +4 -20
- package/dist/core/baseagent-loader.js +27 -3
- package/dist/core/bootstrap-service.js +5 -22
- package/dist/core/capability/capability-manager.js +52 -35
- package/dist/core/channel-loader.js +43 -2
- package/dist/core/channel-runtime.js +2 -2
- package/dist/core/command/agent-control.js +54 -18
- package/dist/core/command/command-handler.js +92 -72
- package/dist/core/command/connect-menu.js +35 -42
- package/dist/core/command/daemon-diagnostics.js +41 -5
- package/dist/core/command/data-root-error.js +10 -0
- package/dist/core/command/data-root-resolver.js +53 -13
- package/dist/core/command/menu-catalog.js +1 -0
- package/dist/core/command/menu-handler.js +163 -65
- package/dist/core/command/menu-protocol.js +52 -0
- package/dist/core/command/pa-workspace-calendar.js +223 -0
- package/dist/core/command/pa-workspace-store.js +459 -0
- package/dist/core/command/role-menu.js +2 -2
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +57 -41
- package/dist/core/daemon-lifecycle.js +90 -31
- package/dist/core/evolagent.js +6 -10
- package/dist/core/handoff/runtime.js +11 -4
- package/dist/core/host-snapshot.js +208 -0
- package/dist/core/initialization/service.js +152 -20
- package/dist/core/ipc-registration.js +33 -4
- package/dist/core/memory/batch-meta.js +27 -0
- package/dist/core/memory/consolidation-ops-records.js +44 -1
- package/dist/core/memory/consolidation.js +169 -27
- package/dist/core/message/aun-ipc-sender.js +2 -8
- package/dist/core/message/im-renderer.js +56 -3
- package/dist/core/message/message-admission.js +121 -124
- package/dist/core/message/message-bridge.js +38 -54
- package/dist/core/message/message-queue.js +7 -0
- package/dist/core/message/outbound.js +34 -9
- package/dist/core/message/response-engine.js +154 -73
- package/dist/core/model/catalog-service.js +1 -1
- package/dist/core/model/config-scope.js +2 -2
- package/dist/core/model/model-catalog.js +5 -4
- package/dist/core/model/model-diagnostics.js +6 -5
- package/dist/core/model/model-fallback.js +3 -6
- package/dist/core/model/model-permission.js +1 -1
- package/dist/core/ownership/owner-resolver.js +9 -9
- package/dist/core/permission/approval-gateway.js +1 -1
- package/dist/core/permission/ec-command-parser.js +2 -2
- package/dist/core/permission/tool-canonical.js +96 -46
- package/dist/core/permission/tool-error-code.js +41 -0
- package/dist/core/permission/tool-policy.js +71 -47
- package/dist/core/role/runtime-policy.js +1 -1
- package/dist/core/session/session-idle-monitor.js +10 -0
- package/dist/core/session/session-manager.js +2 -4
- package/dist/core/session/session-title.js +36 -8
- package/dist/core/system-session/memory.js +2 -7
- package/dist/core/thread/command-parser.js +6 -2
- package/dist/core/thread/ipc-operation.js +51 -36
- package/dist/core/thread/thread-operation.js +29 -61
- package/dist/core/thread/thread-service.js +57 -13
- package/dist/directory/canonical-digest.js +54 -0
- package/dist/directory/owner-directory-admission.js +114 -43
- package/dist/directory/owner-directory-agentmd-sync.js +89 -0
- package/dist/directory/owner-directory-cache.js +847 -459
- package/dist/directory/owner-directory-markdown.js +272 -0
- package/dist/directory/owner-directory-query-operation.js +195 -0
- package/dist/directory/owner-directory-remark-operation.js +147 -0
- package/dist/directory/owner-directory-remarks.js +145 -0
- package/dist/directory/owner-directory-scope.js +55 -0
- package/dist/directory/owner-directory-search.js +148 -0
- package/dist/directory/owner-directory-store.js +227 -0
- package/dist/eck/kit-renderer.js +1 -0
- package/dist/ecweb/basic-settings-service.js +4 -1
- package/dist/ecweb/message-context-service.js +13 -9
- package/dist/index.js +195 -37
- package/dist/ipc.js +86 -22
- package/dist/paths.js +11 -8
- package/dist/product.js +2 -0
- package/dist/proxy/manager.js +13 -2
- package/dist/proxy/service-supervisor.js +8 -1
- package/dist/trigger/history.js +23 -0
- package/dist/trigger/scheduler.js +3 -0
- package/dist/utils/atomic-write.js +21 -0
- package/dist/utils/cross-platform.js +35 -0
- package/dist/utils/ecweb-supervisor.js +42 -0
- package/dist/utils/error-utils.js +2 -1
- package/dist/utils/evolcore-version.js +19 -0
- package/dist/utils/host-info.js +242 -5
- package/dist/utils/instance-registry.js +28 -6
- package/dist/utils/logger.js +59 -14
- package/dist/utils/machine-info.js +46 -0
- package/dist/utils/process-introspect.js +166 -2
- package/dist/utils/startup-trace.js +245 -0
- package/ecagent/dist/agent-loop.js +27 -13
- package/ecagent/dist/harness/agent-harness.js +3 -3
- package/ecagent/dist/harness/types.d.ts +1 -0
- package/ecagent/dist/types.d.ts +1 -0
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +72 -0
- package/kits/docs/evolcore/INDEX.md +3 -2
- package/kits/docs/evolcore/agent-create.md +17 -27
- package/kits/docs/evolcore/agent.md +4 -1
- package/kits/docs/evolcore/aid.md +3 -1
- package/kits/docs/evolcore/config.md +16 -5
- package/kits/docs/evolcore/ctl.md +9 -0
- package/kits/docs/evolcore/ec-capabilities.md +19 -0
- package/kits/docs/evolcore/memory-consolidation-batches.md +79 -5
- package/kits/docs/evolcore/menu-exec-schema-commands.md +2 -1
- package/kits/docs/evolcore/menu-protocol.md +1 -0
- package/kits/docs/evolcore/model.md +13 -4
- package/kits/docs/evolcore/msg.md +1 -1
- package/kits/docs/evolcore/pa-workspace.md +51 -0
- package/kits/docs/evolcore/peer.md +73 -0
- package/kits/docs/evolcore/thread-chain.md +4 -1
- package/kits/eck_manifest.json +21 -0
- package/kits/rules/06-channel.md +1 -1
- package/kits/schemas/_meta.json +12 -1
- package/kits/schemas/agent-config.schema.16.json +6 -0
- package/kits/schemas/agent-config.schema.17.json +897 -0
- package/kits/schemas/daemon.schema.9.json +8 -1
- package/kits/skills/ec-agent-create/SKILL.md +2 -2
- package/kits/skills/ec-identity/SKILL.md +45 -27
- package/kits/skills/ec-service-proxy/SKILL.md +7 -2
- package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +4 -5
- package/kits/skills/thread-ops/SKILL.md +11 -11
- package/kits/templates/bootstrap-welcome.md +3 -15
- package/kits/templates/message-fragments/item.md +1 -1
- package/kits/templates/system-fragments/bootstrap.md +24 -23
- package/kits/templates/system-fragments/commands.md +12 -5
- package/kits/templates/system-fragments/thread.md +18 -3
- package/package.json +6 -4
- package/dist/config/contact-operation-service.js +0 -235
- package/dist/directory/owner-directory-authorization.js +0 -309
- package/kits/docs/evolcore/contact.md +0 -78
- /package/dist/config/{contact-alias.js → peer-alias.js} +0 -0
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 记录整理会话内的所有关键事件:
|
|
5
5
|
* - session-start / session-end:会话级别的开始/结束记录
|
|
6
|
+
* - step:生命周期各步骤的结果(含失败线索),成败都记
|
|
6
7
|
* - create / update / archive:每次写操作的结果
|
|
7
8
|
* - summary:会话结束时的汇总行
|
|
8
9
|
* - FORGET-LOG.md:按记忆作用域保留遗忘、手动归档与回撤记录
|
|
@@ -12,6 +13,10 @@
|
|
|
12
13
|
import fs from 'fs';
|
|
13
14
|
import path from 'path';
|
|
14
15
|
import { logger } from '../../utils/logger.js';
|
|
16
|
+
/** 步骤条目:生命周期诊断记录,不参与写计数与回撤。 */
|
|
17
|
+
export function isStepRecord(entry) {
|
|
18
|
+
return entry.op === 'step';
|
|
19
|
+
}
|
|
15
20
|
/** 向 ops 记录文件追加一条记录。失败静默,不影响主流程。 */
|
|
16
21
|
export function appendOpsRecord(batchDir, entry) {
|
|
17
22
|
try {
|
|
@@ -21,6 +26,23 @@ export function appendOpsRecord(batchDir, entry) {
|
|
|
21
26
|
}
|
|
22
27
|
catch { /* ignore */ }
|
|
23
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* 记一条生命周期步骤。诊断入口:每一步都要留下结果,失败时带错误码与原文。
|
|
31
|
+
*
|
|
32
|
+
* 不要用它记写操作(create/update/archive 有各自的语义与回撤信息),
|
|
33
|
+
* 也不要在没有 batchDir 的路径上调用——批次目录之外没有流水文件。
|
|
34
|
+
*/
|
|
35
|
+
export function recordStep(batchDir, step, ok, extra = {}) {
|
|
36
|
+
appendOpsRecord(batchDir, {
|
|
37
|
+
ts: new Date().toISOString(),
|
|
38
|
+
op: 'step',
|
|
39
|
+
step,
|
|
40
|
+
ok,
|
|
41
|
+
...(extra.errorCode ? { errorCode: extra.errorCode } : {}),
|
|
42
|
+
...(extra.error ? { error: extra.error } : {}),
|
|
43
|
+
...(extra.detail && Object.keys(extra.detail).length > 0 ? { detail: extra.detail } : {}),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
24
46
|
/**
|
|
25
47
|
* 扫描 ops 记录并返回汇总行(未写入文件)。
|
|
26
48
|
* 供会话结束时追加 summary 条目。
|
|
@@ -40,7 +62,9 @@ export function summarizeOpsRecords(batchDir) {
|
|
|
40
62
|
try {
|
|
41
63
|
for (const line of fs.readFileSync(filePath, 'utf-8').split('\n').filter(Boolean)) {
|
|
42
64
|
const entry = JSON.parse(line);
|
|
43
|
-
|
|
65
|
+
// step 是诊断记录:失败步骤不该算进「写操作出错数」,否则会把序号统跑偏
|
|
66
|
+
if (entry.op === 'summary' || entry.op === 'session-start' || entry.op === 'session-end'
|
|
67
|
+
|| entry.op === 'step')
|
|
44
68
|
continue;
|
|
45
69
|
if (!entry.ok) {
|
|
46
70
|
summary.errors++;
|
|
@@ -134,6 +158,25 @@ export function scopeOfMemoryDir(memoryDir) {
|
|
|
134
158
|
return 'owner';
|
|
135
159
|
return undefined;
|
|
136
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* 读回本次整理的全部步骤记录,按写入顺序返回。
|
|
163
|
+
* 供收尾时收集失败线索(哪个步骤、什么错误码、什么原文)。
|
|
164
|
+
*/
|
|
165
|
+
export function readStepRecords(batchDir) {
|
|
166
|
+
const filePath = path.join(batchDir, 'ops.jsonl');
|
|
167
|
+
if (!fs.existsSync(filePath))
|
|
168
|
+
return [];
|
|
169
|
+
try {
|
|
170
|
+
return fs.readFileSync(filePath, 'utf-8')
|
|
171
|
+
.split('\n')
|
|
172
|
+
.filter(Boolean)
|
|
173
|
+
.map(l => JSON.parse(l))
|
|
174
|
+
.filter(isStepRecord);
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
137
180
|
/**
|
|
138
181
|
* 读取 ops 记录里所有成功的写操作,按写入顺序倒序返回(最后写的先回撤)。
|
|
139
182
|
* 只返回 create / update / archive 且 ok=true 的条目。
|
|
@@ -20,8 +20,10 @@ import { formatChannelKey } from '../channel-loader.js';
|
|
|
20
20
|
import { isTopicThreadId } from '../thread/topic-id.js';
|
|
21
21
|
import { logger } from '../../utils/logger.js';
|
|
22
22
|
import { atomicWriteText } from '../../utils/atomic-write.js';
|
|
23
|
-
import { appendOpsRecord, feedbackFilePath, readFeedbackText } from './consolidation-ops-records.js';
|
|
24
|
-
import { updateBatchMeta } from './batch-meta.js';
|
|
23
|
+
import { appendOpsRecord, feedbackFilePath, readFeedbackText, recordStep } from './consolidation-ops-records.js';
|
|
24
|
+
import { updateBatchMeta, patchBatchMeta } from './batch-meta.js';
|
|
25
|
+
import { normalizeBaseagent, resolveBaseagentModelSelection } from '../../agents/baseagent.js';
|
|
26
|
+
import { resolveEffective } from '../../config/config-manager.js';
|
|
25
27
|
import { checkConsolidationCandidates, hasOwnerConsolidationCandidates, isConsolidatableRelation, judgeRelationMode, recordProfileAttempt, shouldUseMetaIndex } from './consolidation-trigger.js';
|
|
26
28
|
import { taskContextOfRoute } from './relation-idle-monitor.js';
|
|
27
29
|
/**
|
|
@@ -116,6 +118,47 @@ export function consolidationBlockedReason(selfAid) {
|
|
|
116
118
|
return undefined;
|
|
117
119
|
return `agent ${selfAid} 首次设定尚未完成(lifecycle=${lifecycle ?? String(config.lifecycle)}),完成后才能整理记忆`;
|
|
118
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* 拉起时读一遍有效的计划模型:Agent/defaults → 本机 CLI → runner 默认值。
|
|
123
|
+
*
|
|
124
|
+
* 整理会话和普通回复走同一条模型判据,
|
|
125
|
+
* 但整理是在后台静默拉起的——模型解析失败时会话在第一轮之前就失败,
|
|
126
|
+
* 不留一行「计划用哪个模型」,事后只能翻 daemon.log。这里在拉起时先读并落盘。
|
|
127
|
+
*
|
|
128
|
+
* 不抛错:配置读不出来不该阻止整理本身,但要带出可诊断的原因。
|
|
129
|
+
*/
|
|
130
|
+
function resolvePlannedModel(selfAid, baseagent) {
|
|
131
|
+
const configPath = path.join(resolveRoot(), 'agents', selfAid, 'config.json');
|
|
132
|
+
try {
|
|
133
|
+
if (!fs.existsSync(configPath)) {
|
|
134
|
+
return {
|
|
135
|
+
model: '<unconfigured>',
|
|
136
|
+
problem: { errorCode: 'model_not_configured', error: `配置文件不存在: ${configPath}` },
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const canonical = normalizeBaseagent(baseagent).canonical;
|
|
140
|
+
const effective = resolveEffective({ self: selfAid }, { cache: false });
|
|
141
|
+
const selection = resolveBaseagentModelSelection(canonical, effective.baseagents?.[canonical]);
|
|
142
|
+
if (selection?.model)
|
|
143
|
+
return { model: selection.model };
|
|
144
|
+
return {
|
|
145
|
+
model: '<unconfigured>',
|
|
146
|
+
problem: {
|
|
147
|
+
errorCode: 'model_not_configured',
|
|
148
|
+
error: `baseagents.${canonical}.model 未配置(${configPath}),整理会话启动后会立即失败`,
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
return {
|
|
154
|
+
model: '<unreadable>',
|
|
155
|
+
problem: {
|
|
156
|
+
errorCode: 'model_config_unreadable',
|
|
157
|
+
error: `读取 ${configPath} 失败: ${error instanceof Error ? error.message : String(error)}`,
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
119
162
|
/**
|
|
120
163
|
* 序列化上下文并直接创建整理会话。
|
|
121
164
|
* 失败抛错,调用方负责决定是否记录诊断或回传错误。
|
|
@@ -200,6 +243,25 @@ export async function launchConsolidation(channel, params) {
|
|
|
200
243
|
const scopeTag = params.scopeOverride ? `-${params.scopeOverride}` : '';
|
|
201
244
|
const kind = `memory-consolidate-${mode}${scopeTag}`;
|
|
202
245
|
const triggerId = `${kind}-${now.toString(36)}`;
|
|
246
|
+
const planned = resolvePlannedModel(selfAid, baseagent);
|
|
247
|
+
// 上下文已序列化:批次目录就位,之后的每一步都往 ops.jsonl 留痕。
|
|
248
|
+
// 这一步之前(校验 / 认领)失败时还没有批次目录,错误由调用方日志承载。
|
|
249
|
+
const batchDir = ctxFile.batchDir;
|
|
250
|
+
// session-start 必须是第一条:它统领整个流水。身份字段全在这里,步骤只留诊断信息。
|
|
251
|
+
appendOpsRecord(batchDir, {
|
|
252
|
+
ts: new Date().toISOString(),
|
|
253
|
+
op: 'session-start',
|
|
254
|
+
sessionId: triggerId, // launch 还没返回 sessionId,先用 triggerId 占位
|
|
255
|
+
mode,
|
|
256
|
+
triggeredBy,
|
|
257
|
+
triggerId,
|
|
258
|
+
baseagent,
|
|
259
|
+
plannedModel: planned.model,
|
|
260
|
+
});
|
|
261
|
+
// 计划模型本身就是一步:没配时会话注定在第一轮之前失败,先记下来
|
|
262
|
+
recordStep(batchDir, 'config:model', !planned.problem, {
|
|
263
|
+
...(planned.problem ?? {}),
|
|
264
|
+
});
|
|
203
265
|
// 整理会话的渠道信息(origin):发起时抓取,供反馈时直接投递到原会话渠道。
|
|
204
266
|
// 用 channelId/peerId/threadId 三要素——不依赖 evolcore sessionId,renew/`/new` 换会话也不影响送达。
|
|
205
267
|
const feedbackOrigin = effectiveCtx.channel && effectiveCtx.peerId ? {
|
|
@@ -262,14 +324,30 @@ export async function launchConsolidation(channel, params) {
|
|
|
262
324
|
});
|
|
263
325
|
}
|
|
264
326
|
catch (error) {
|
|
327
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
328
|
+
recordStep(batchDir, 'launch:failed', false, {
|
|
329
|
+
errorCode: error instanceof Error && error.name ? error.name : 'launch_failed',
|
|
330
|
+
error: message,
|
|
331
|
+
});
|
|
265
332
|
if (claimedProcessing && memoryDir)
|
|
266
333
|
restorePendingNotes(memoryDir);
|
|
267
|
-
recordConsolidationOutcome(ctxFile.contextFilePath, `启动失败: ${
|
|
334
|
+
recordConsolidationOutcome(ctxFile.contextFilePath, `启动失败: ${message}`);
|
|
335
|
+
// 批次目录已建好、流水已写。把它挂在错误对象上,队列层的 catch 才能补记
|
|
336
|
+
// 「拉起失败」那一行;否则队列只有一句 logger.warn,没有批次可查。
|
|
337
|
+
if (error && typeof error === 'object') {
|
|
338
|
+
error.consolidationBatchDir = batchDir;
|
|
339
|
+
}
|
|
268
340
|
throw error;
|
|
269
341
|
}
|
|
270
342
|
// launch() 在会话创建后即返回,sessionId 立即可用;不等会话结束。
|
|
271
343
|
// 收尾由 bg-session:completed/error/interrupted 事件驱动,这里只记录异常结局。
|
|
272
344
|
const executionSessionId = handle.sessionId;
|
|
345
|
+
// 回填真实的 sessionId(刚才用 triggerId 占位了)
|
|
346
|
+
patchBatchMeta(batchDir, {
|
|
347
|
+
...(executionSessionId ? { executionSessionId } : {}),
|
|
348
|
+
triggerId,
|
|
349
|
+
plannedModel: planned.model,
|
|
350
|
+
});
|
|
273
351
|
void handle.result.then(r => {
|
|
274
352
|
if (r.outcome !== 'completed') {
|
|
275
353
|
logger.warn(`[Memory] 整理会话未正常结束(mode=${mode},outcome=${r.outcome}): ${r.error ?? ''}`);
|
|
@@ -289,6 +367,7 @@ export async function launchConsolidation(channel, params) {
|
|
|
289
367
|
logFile: ctxFile.contextFilePath,
|
|
290
368
|
batchDir: ctxFile.batchDir,
|
|
291
369
|
executionSessionId,
|
|
370
|
+
plannedModel: planned.model,
|
|
292
371
|
waitForAgentSessionId: handle.waitForAgentSessionId,
|
|
293
372
|
};
|
|
294
373
|
}
|
|
@@ -714,13 +793,9 @@ export async function rollbackConsolidation(batchDir, selfAid) {
|
|
|
714
793
|
logger.warn(`[Memory] ${msg}`);
|
|
715
794
|
}
|
|
716
795
|
}
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
success: false,
|
|
721
|
-
movedNotes: 0,
|
|
722
|
-
checkpointWritten: false,
|
|
723
|
-
});
|
|
796
|
+
// 这里不写 session-end:回撤只是失败收尾里的一步,写一条会让批次出现两个
|
|
797
|
+
// session-end,且 summary 夹在中间,破坏「session-end 恒为最后一条」的约定。
|
|
798
|
+
// 回撤结果由调用方记成 finalize:rollback 步骤。
|
|
724
799
|
logger.info(`[Memory] 回撤完成:回撤 ${rolledBack} 条操作,${errors.length} 个失败`);
|
|
725
800
|
return { rolledBack, errors };
|
|
726
801
|
}
|
|
@@ -740,9 +815,11 @@ function relationPeerKeysOf(scopes, exclude) {
|
|
|
740
815
|
}
|
|
741
816
|
export function createConsolidationSessionFinalizer({ sessionManager, getAgent, agentMap, releaseSlot, enqueueConsolidation, sendFeedback, onSessionFinalized, }) {
|
|
742
817
|
const finalizedSessions = new Set();
|
|
743
|
-
return async (sessionId, success, models = {}) => {
|
|
818
|
+
return async (sessionId, success, models = {}, failure) => {
|
|
744
819
|
let releaseAid;
|
|
745
820
|
let finalizedInfo;
|
|
821
|
+
// 在 try 外声明:catch 里也要能往批次流水记「收尾本身抛错」
|
|
822
|
+
let batchDirForLog;
|
|
746
823
|
try {
|
|
747
824
|
if (!sessionId)
|
|
748
825
|
return;
|
|
@@ -757,10 +834,15 @@ export function createConsolidationSessionFinalizer({ sessionManager, getAgent,
|
|
|
757
834
|
if (typeof meta.relationSweepId === 'string')
|
|
758
835
|
finalizedInfo.relationSweepId = meta.relationSweepId;
|
|
759
836
|
const batchDir = (meta.consolidationBatchDir ?? meta.consolidationLogBase);
|
|
760
|
-
if (!batchDir)
|
|
837
|
+
if (!batchDir) {
|
|
838
|
+
// 没有批次目录就没有流水可写;这是链路级的断裂,至少要能在日志里对上层
|
|
839
|
+
logger.warn(`[Memory] 整理会话缺少批次目录,跳过收尾(session=${sessionId},`
|
|
840
|
+
+ `hasSession=${!!session},metadata 键=${Object.keys(meta).join(',') || '<空>'})`);
|
|
761
841
|
return;
|
|
842
|
+
}
|
|
762
843
|
finalizedSessions.add(sessionId);
|
|
763
844
|
releaseAid = session.selfAID;
|
|
845
|
+
batchDirForLog = batchDir;
|
|
764
846
|
// 先占位:后续步骤即使抛错,链也要能推进,不能卡在这一步
|
|
765
847
|
finalizedInfo = {
|
|
766
848
|
sessionId,
|
|
@@ -783,8 +865,20 @@ export function createConsolidationSessionFinalizer({ sessionManager, getAgent,
|
|
|
783
865
|
logger.warn(`[Memory] ${failureReason}(session=${sessionId}),按失败收尾`);
|
|
784
866
|
}
|
|
785
867
|
}
|
|
868
|
+
// 失败码优先用终态事件给的(如 model_not_configured);会话正常结束但没干活时
|
|
869
|
+
// failure 为空,此时仍要留一条,否则 batch.md 只知道「失败」不知道为什么。
|
|
870
|
+
const failureCode = success ? undefined : (failure?.code ?? (failureReason ? 'no_output' : 'session_failed'));
|
|
871
|
+
const failureMessage = success ? undefined : (failure?.message ?? failureReason);
|
|
786
872
|
if (!success) {
|
|
787
|
-
|
|
873
|
+
recordStep(batchDir, 'finalize:verdict', true, {
|
|
874
|
+
...(failureCode ? { errorCode: failureCode } : {}),
|
|
875
|
+
...(failureMessage ? { error: failureMessage } : {}),
|
|
876
|
+
});
|
|
877
|
+
const rollback = await rollbackConsolidation(batchDir, session.selfAID);
|
|
878
|
+
recordStep(batchDir, 'finalize:rollback', rollback.errors.length === 0, {
|
|
879
|
+
...(rollback.errors.length > 0 ? { error: rollback.errors.join('; ') } : {}),
|
|
880
|
+
detail: { rolledBack: rollback.rolledBack, errors: rollback.errors.length },
|
|
881
|
+
});
|
|
788
882
|
}
|
|
789
883
|
// 升级标签兜底:模型评估完候选却没摘标签,关系整理链会按标签计数反复拉起同一轮
|
|
790
884
|
if (success && (meta.memoryMode === 'generalize' || meta.memoryMode === 'promote')
|
|
@@ -833,17 +927,29 @@ export function createConsolidationSessionFinalizer({ sessionManager, getAgent,
|
|
|
833
927
|
const selfAid = session.selfAID;
|
|
834
928
|
const memoryConfig = selfAid ? getAgent(selfAid)?.config.memory : undefined;
|
|
835
929
|
const maxBytes = memoryConfig?.indexMaxBytes ?? 5 * 1024;
|
|
930
|
+
const failures = [];
|
|
836
931
|
for (const [scope, memoryDir] of affectedScopes) {
|
|
837
932
|
const consolidatedDir = path.join(memoryDir, 'consolidated');
|
|
838
933
|
const indexPath = path.join(memoryDir, 'MEMORY.md');
|
|
839
934
|
try {
|
|
840
935
|
await rebuildIndex(consolidatedDir, indexPath, scope, maxBytes);
|
|
841
936
|
}
|
|
842
|
-
catch {
|
|
937
|
+
catch (indexError) {
|
|
938
|
+
// 索引重建失败不影响记忆本身,但索引会和新内容不一致,必须留痕
|
|
939
|
+
failures.push(`${scope}:${memoryDir}: ${indexError?.message ?? String(indexError)}`);
|
|
940
|
+
}
|
|
843
941
|
}
|
|
942
|
+
recordStep(batchDir, 'finalize:index-rebuild', failures.length === 0, {
|
|
943
|
+
...(failures.length > 0 ? { error: failures.join('; ') } : {}),
|
|
944
|
+
detail: { scopes: affectedScopes.map(([scope]) => scope), failed: failures.length },
|
|
945
|
+
});
|
|
844
946
|
}
|
|
845
947
|
}
|
|
846
|
-
catch {
|
|
948
|
+
catch (indexOuterError) {
|
|
949
|
+
recordStep(batchDir, 'finalize:index-rebuild', false, {
|
|
950
|
+
error: indexOuterError?.message ?? String(indexOuterError),
|
|
951
|
+
});
|
|
952
|
+
}
|
|
847
953
|
// feedback 只读一次:先落 batch.md,再清 scratch/,投递复用同一份文本。
|
|
848
954
|
// 同时挂到 session-end 记录上——scratch/ 收尾即删,batch.md 那段又嵌在
|
|
849
955
|
// frontmatter 后不好按时间线翻,ops 里留一份才能 grep 到。
|
|
@@ -854,6 +960,9 @@ export function createConsolidationSessionFinalizer({ sessionManager, getAgent,
|
|
|
854
960
|
success,
|
|
855
961
|
movedNotes: completeResult.moved,
|
|
856
962
|
checkpointWritten: completeResult.checkpointWritten,
|
|
963
|
+
// 失败必须带原因:只写 success:false 的流水等于没有信息
|
|
964
|
+
...(failureCode ? { errorCode: failureCode } : {}),
|
|
965
|
+
...(failureMessage ? { error: failureMessage } : {}),
|
|
857
966
|
...(customText ? { feedbackText: customText } : {}),
|
|
858
967
|
});
|
|
859
968
|
if (success) {
|
|
@@ -949,9 +1058,15 @@ export function createConsolidationSessionFinalizer({ sessionManager, getAgent,
|
|
|
949
1058
|
...(session.agentSessionId ? { agentSessionId: session.agentSessionId } : {}),
|
|
950
1059
|
...(models.requestedModel ? { requestedModel: models.requestedModel } : {}),
|
|
951
1060
|
...(models.actualModel ? { actualModel: models.actualModel } : {}),
|
|
952
|
-
...(
|
|
1061
|
+
...(failureCode ? { errorCode: failureCode } : {}),
|
|
1062
|
+
...(failureMessage ? { failureReason: failureMessage } : {}),
|
|
953
1063
|
feedbackText: customText,
|
|
954
1064
|
});
|
|
1065
|
+
// runner 没能初始化时 agentSessionId 根本不存在。静默省略会让批次看起来
|
|
1066
|
+
// 「没有这个字段」而不是「这次没跑到那一步」,显式留个标记。
|
|
1067
|
+
if (!session.agentSessionId) {
|
|
1068
|
+
patchBatchMeta(batchDir, { agentSessionId: '<none: runner 未初始化>' });
|
|
1069
|
+
}
|
|
955
1070
|
}
|
|
956
1071
|
catch { /* 失败静默 */ }
|
|
957
1072
|
// scratch/ 是会话期临时工作区,feedback 已落 batch.md,不分成败与触发方式一律清掉
|
|
@@ -986,11 +1101,26 @@ export function createConsolidationSessionFinalizer({ sessionManager, getAgent,
|
|
|
986
1101
|
}
|
|
987
1102
|
catch (error) {
|
|
988
1103
|
logger.warn(`[Memory] 整理反馈投递失败(session=${sessionId}): ${error?.message}`);
|
|
1104
|
+
recordStep(batchDir, 'finalize:feedback', false, {
|
|
1105
|
+
errorCode: 'feedback_delivery_failed',
|
|
1106
|
+
error: error?.message ?? String(error),
|
|
1107
|
+
detail: {
|
|
1108
|
+
...(feedbackOrigin?.channelKey ? { channelKey: feedbackOrigin.channelKey } : {}),
|
|
1109
|
+
...(feedbackOrigin?.channelId ? { channelId: feedbackOrigin.channelId } : {}),
|
|
1110
|
+
},
|
|
1111
|
+
});
|
|
989
1112
|
}
|
|
990
1113
|
}
|
|
991
1114
|
}
|
|
992
1115
|
catch (error) {
|
|
993
1116
|
logger.warn(`[Memory] 整理收尾失败(session=${sessionId}): ${error?.message}`);
|
|
1117
|
+
// 收尾本身抛错:批次目录可能已进入中间状态,把错误码与栈留在流水里
|
|
1118
|
+
if (batchDirForLog) {
|
|
1119
|
+
recordStep(batchDirForLog, 'finalize:error', false, {
|
|
1120
|
+
errorCode: error?.code ?? 'finalize_threw',
|
|
1121
|
+
error: `${error?.message ?? String(error)}${error?.stack ? `\n${error.stack}` : ''}`,
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
994
1124
|
}
|
|
995
1125
|
finally {
|
|
996
1126
|
if (releaseAid && sessionId)
|
|
@@ -1119,12 +1249,16 @@ export function registerConsolidationSessionEvents({ eventBus, permissionGateway
|
|
|
1119
1249
|
void finalize(event.sessionId, true, modelsFromEvent(event));
|
|
1120
1250
|
});
|
|
1121
1251
|
eventBus.subscribe('bg-session:error', event => {
|
|
1122
|
-
|
|
1123
|
-
|
|
1252
|
+
// 事件的 error 就是机器可读的失败码(如 model_not_configured)。以前只取 models,
|
|
1253
|
+
// 把这里白白带上来的码扔掉了,结果批次里只剩一个 success:false。
|
|
1254
|
+
if (event.type === 'bg-session:error') {
|
|
1255
|
+
void finalize(event.sessionId, false, modelsFromEvent(event), { code: event.error });
|
|
1256
|
+
}
|
|
1124
1257
|
});
|
|
1125
1258
|
eventBus.subscribe('bg-session:interrupted', event => {
|
|
1126
|
-
if (event.type === 'bg-session:interrupted')
|
|
1127
|
-
void finalize(event.sessionId, false, modelsFromEvent(event));
|
|
1259
|
+
if (event.type === 'bg-session:interrupted') {
|
|
1260
|
+
void finalize(event.sessionId, false, modelsFromEvent(event), { code: 'interrupted', message: event.reason });
|
|
1261
|
+
}
|
|
1128
1262
|
});
|
|
1129
1263
|
}
|
|
1130
1264
|
export class ConsolidationQueue {
|
|
@@ -1226,17 +1360,25 @@ export class ConsolidationQueue {
|
|
|
1226
1360
|
timer.unref?.();
|
|
1227
1361
|
this.timers.set(aid, timer);
|
|
1228
1362
|
}
|
|
1229
|
-
appendOpsRecord(launched.batchDir, {
|
|
1230
|
-
ts: new Date().toISOString(),
|
|
1231
|
-
op: 'session-start',
|
|
1232
|
-
sessionId: launched.executionSessionId ?? launched.triggerId,
|
|
1233
|
-
mode: params.mode,
|
|
1234
|
-
triggeredBy: params.triggeredBy,
|
|
1235
|
-
});
|
|
1236
1363
|
return launched;
|
|
1237
1364
|
}
|
|
1238
1365
|
catch (error) {
|
|
1239
1366
|
logger.warn(`[Memory] 拉起整理会话失败(aid=${aid},mode=${params.mode}): ${error?.message}`);
|
|
1367
|
+
const failedBatchDir = error?.consolidationBatchDir;
|
|
1368
|
+
if (failedBatchDir) {
|
|
1369
|
+
recordStep(failedBatchDir, 'queue:launch', false, {
|
|
1370
|
+
errorCode: error?.code ?? error?.name ?? 'launch_failed',
|
|
1371
|
+
error: error?.message ?? String(error),
|
|
1372
|
+
detail: { aid, mode: params.mode, triggeredBy: params.triggeredBy, fromDrain },
|
|
1373
|
+
});
|
|
1374
|
+
updateBatchMeta(failedBatchDir, {
|
|
1375
|
+
status: 'failed',
|
|
1376
|
+
finishedAt: new Date().toISOString(),
|
|
1377
|
+
success: false,
|
|
1378
|
+
errorCode: error?.code ?? error?.name ?? 'launch_failed',
|
|
1379
|
+
failureReason: error?.message ?? String(error),
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1240
1382
|
this.activeAgents.delete(aid);
|
|
1241
1383
|
this.activeParams.delete(aid);
|
|
1242
1384
|
if (fromDrain && this.launchFailedListener) {
|
|
@@ -6,7 +6,7 @@ import { AUN_HANDOFF_MARKER_FIELD } from '../../channels/aun.js';
|
|
|
6
6
|
import { classifyAunPayloadForLog } from './message-log.js';
|
|
7
7
|
import { isValidAunDeliveryForChannel } from './outbound.js';
|
|
8
8
|
import { isHClassPath } from '../permission/protected-paths.js';
|
|
9
|
-
import {
|
|
9
|
+
import { evaluateOutboundContactAdmission } from './message-admission.js';
|
|
10
10
|
import { normalizeAunMentionEntries, withAunAttention } from '../../aun/msg/mention-schema.js';
|
|
11
11
|
import { resolveManagedSendArgv } from '../../cli/aun-commands.js';
|
|
12
12
|
import { readTriggerLocalFile, resolveAttachmentLocalPath } from '../../trigger/local-files.js';
|
|
@@ -389,13 +389,7 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
389
389
|
return { ok: false, error: `AUN channel not found for ${params.aid}`, code: 'AUN_CHANNEL_NOT_FOUND' };
|
|
390
390
|
}
|
|
391
391
|
if (params.scope === 'msg') {
|
|
392
|
-
const admission = params.
|
|
393
|
-
? await ensureOutboundContactForSend({
|
|
394
|
-
selfAid: params.aid,
|
|
395
|
-
targetAid: params.to,
|
|
396
|
-
actorId: delegation.grant?.actorId ?? 'managed-outbound-send',
|
|
397
|
-
})
|
|
398
|
-
: await evaluateOutboundContactAdmission({ selfAid: params.aid, targetAid: params.to });
|
|
392
|
+
const admission = await evaluateOutboundContactAdmission({ selfAid: params.aid, targetAid: params.to });
|
|
399
393
|
if (!admission.allow) {
|
|
400
394
|
return { ok: false, error: admission.error, code: admission.code };
|
|
401
395
|
}
|
|
@@ -44,6 +44,9 @@ export class IMRenderer {
|
|
|
44
44
|
subtaskItems = new WeakSet();
|
|
45
45
|
/** 本轮已投影的工具调用 call_id → 工具名;子任务只归拢到本轮可见的来源工具卡片。 */
|
|
46
46
|
toolCallNames = new Map();
|
|
47
|
+
/** Provider lifecycle events must not duplicate a synthetic preflight denial. */
|
|
48
|
+
preflightDenialCallIds = new Set();
|
|
49
|
+
toolResultCallIds = new Set();
|
|
47
50
|
/**
|
|
48
51
|
* 归拢到来源工具的子任务:call_id → 状态。
|
|
49
52
|
* running 期间到达的 tool_result(后台占位结果)先扣住,等终态合并后再发;
|
|
@@ -250,6 +253,8 @@ export class IMRenderer {
|
|
|
250
253
|
}
|
|
251
254
|
/** 添加工具调用 */
|
|
252
255
|
addToolCall(name, input, callId, descText, turn, outputTokens, assistantUuid) {
|
|
256
|
+
if (callId && this.preflightDenialCallIds.has(callId))
|
|
257
|
+
return;
|
|
253
258
|
if (this.opts.envelope.chatmode === 'proactive')
|
|
254
259
|
return;
|
|
255
260
|
this.emitProgress('tool_call', outputTokens, turn, { toolName: name, callId });
|
|
@@ -281,6 +286,8 @@ export class IMRenderer {
|
|
|
281
286
|
}
|
|
282
287
|
/** 添加工具结果 */
|
|
283
288
|
addToolResult(name, ok, result, error, callId, durationMs, descText, classification, assistantUuid) {
|
|
289
|
+
if (callId && this.preflightDenialCallIds.has(callId))
|
|
290
|
+
return;
|
|
284
291
|
if (this.opts.envelope.chatmode === 'proactive')
|
|
285
292
|
return;
|
|
286
293
|
const normalizedClassification = !ok
|
|
@@ -322,6 +329,7 @@ export class IMRenderer {
|
|
|
322
329
|
deliverToolResult(item) {
|
|
323
330
|
if (item.kind !== 'tool_result')
|
|
324
331
|
return;
|
|
332
|
+
this.toolResultCallIds.add(item.call_id);
|
|
325
333
|
if (this.opts.envelope.chatmode === 'proactive') {
|
|
326
334
|
this.emitProactiveItem(item);
|
|
327
335
|
return;
|
|
@@ -344,13 +352,14 @@ export class IMRenderer {
|
|
|
344
352
|
*/
|
|
345
353
|
resolveParentToolResult(item) {
|
|
346
354
|
if (item.kind !== 'tool_result')
|
|
347
|
-
return
|
|
355
|
+
return null;
|
|
348
356
|
const state = this.parentSubtasks.get(item.call_id);
|
|
349
357
|
if (!state)
|
|
350
358
|
return item;
|
|
351
359
|
if (state.terminal) {
|
|
352
360
|
this.parentSubtasks.delete(item.call_id);
|
|
353
|
-
|
|
361
|
+
const folded = foldSubtaskTerminal(item, state.terminal);
|
|
362
|
+
return folded.kind === 'tool_result' ? folded : null;
|
|
354
363
|
}
|
|
355
364
|
state.held = item;
|
|
356
365
|
return null;
|
|
@@ -403,6 +412,46 @@ export class IMRenderer {
|
|
|
403
412
|
this.deliverToolResult(state.held);
|
|
404
413
|
}
|
|
405
414
|
}
|
|
415
|
+
/** Project a managed pre-tool denial as the same call/result pair used by provider events. */
|
|
416
|
+
addPreflightDenial(activity) {
|
|
417
|
+
const callId = activity.callId ?? activity.correlationId ?? this.synthCallId();
|
|
418
|
+
if (this.preflightDenialCallIds.has(callId))
|
|
419
|
+
return;
|
|
420
|
+
const toolCallAlreadyVisible = this.toolCallNames.has(callId);
|
|
421
|
+
const toolResultAlreadyVisible = this.toolResultCallIds.has(callId);
|
|
422
|
+
const resultEvent = {
|
|
423
|
+
type: 'tool_result',
|
|
424
|
+
name: activity.toolName,
|
|
425
|
+
result: activity.reason,
|
|
426
|
+
isError: true,
|
|
427
|
+
error: activity.reason,
|
|
428
|
+
errorCode: 'POLICY_DENIED',
|
|
429
|
+
...(activity.errorDetailCode ? { errorDetailCode: activity.errorDetailCode } : {}),
|
|
430
|
+
callId,
|
|
431
|
+
correlationId: activity.correlationId ?? callId,
|
|
432
|
+
decision: 'deny',
|
|
433
|
+
decisionSource: 'policy',
|
|
434
|
+
...(activity.policyCode ? { policyCode: activity.policyCode } : {}),
|
|
435
|
+
reason: activity.reason,
|
|
436
|
+
executed: false,
|
|
437
|
+
executionState: 'blocked',
|
|
438
|
+
};
|
|
439
|
+
if (!toolCallAlreadyVisible) {
|
|
440
|
+
this.emit({
|
|
441
|
+
type: 'tool_use',
|
|
442
|
+
name: activity.toolName,
|
|
443
|
+
input: activity.toolInput,
|
|
444
|
+
callId,
|
|
445
|
+
correlationId: activity.correlationId ?? callId,
|
|
446
|
+
});
|
|
447
|
+
this.addToolCall(activity.toolName, activity.toolInput, callId, summarizeToolInputForDisplay(activity.toolName, activity.toolInput));
|
|
448
|
+
}
|
|
449
|
+
if (!toolResultAlreadyVisible) {
|
|
450
|
+
this.emit(resultEvent);
|
|
451
|
+
this.addToolResult(activity.toolName, false, activity.reason, activity.reason, callId, undefined, undefined, resultEvent);
|
|
452
|
+
}
|
|
453
|
+
this.preflightDenialCallIds.add(callId);
|
|
454
|
+
}
|
|
406
455
|
/** 添加进度提示 */
|
|
407
456
|
addProgress(text, opts = {}) {
|
|
408
457
|
if (this.opts.envelope.chatmode === 'proactive')
|
|
@@ -849,6 +898,9 @@ export class IMRenderer {
|
|
|
849
898
|
}
|
|
850
899
|
// ── 内部:proactive 模式(逐事件 activity.batch[1 item]) ──
|
|
851
900
|
emitProactive(event) {
|
|
901
|
+
if ((event.type === 'tool_use' || event.type === 'tool_result')
|
|
902
|
+
&& event.callId && this.preflightDenialCallIds.has(event.callId))
|
|
903
|
+
return;
|
|
852
904
|
// 对齐 interactive 的 dedup:流式 text 已推过时,complete.result 不再重复发 summary
|
|
853
905
|
if (event.type === 'complete' &&
|
|
854
906
|
!event.isError &&
|
|
@@ -885,8 +937,9 @@ export class IMRenderer {
|
|
|
885
937
|
}
|
|
886
938
|
else if (item.kind === 'tool_result') {
|
|
887
939
|
const resolved = this.resolveParentToolResult(item);
|
|
888
|
-
if (!resolved)
|
|
940
|
+
if (!resolved || resolved.kind !== 'tool_result')
|
|
889
941
|
return;
|
|
942
|
+
this.toolResultCallIds.add(resolved.call_id);
|
|
890
943
|
this.emitProactiveItem(resolved);
|
|
891
944
|
return;
|
|
892
945
|
}
|