@hugesb/dsh-stream-agent 0.3.1 → 0.3.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 +125 -0
- package/README.en.md +3 -3
- package/README.md +3 -3
- package/dist/entry/loop.js +332 -21
- package/dist/entry/mock-provider.js +20 -7
- package/dist/kernel/parser.js +488 -39
- package/dist/kernel/render.js +25 -3
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/scripts/release.mjs +20 -7
- package/scripts/repair-session-logs.mjs +105 -10
- package/src/entry/loop.ts +332 -21
- package/src/entry/mock-provider.ts +20 -7
- package/src/kernel/parser.ts +488 -39
- package/src/kernel/render.ts +25 -3
- package/src/version.ts +1 -1
- package/test/host-conformance.test.ts +418 -0
- package/test/kernel/parser.test.ts +3 -2
- package/test/v032-conflict.test.ts +191 -0
- package/test/v032-truncation.test.ts +291 -0
package/dist/entry/loop.js
CHANGED
|
@@ -97,12 +97,19 @@ export function finishMessage(finish ) {
|
|
|
97
97
|
|
|
98
98
|
|
|
99
99
|
|
|
100
|
-
/** 镜像 types.d.ts:538-580 GenerateOptions
|
|
100
|
+
/** 镜像 types.d.ts:538-580 GenerateOptions(驱动器发出的请求形状)。
|
|
101
|
+
* v0.3.2:assistant 消息的 messages 项带可选 source(宿主 forAdapter 读
|
|
102
|
+
* `message.source.replayState`,缺失即 TypeError → 流 error → 回合中断;
|
|
103
|
+
* 类型镜像 dsh-llm typert.host.js AssistantProviderMetadata)。 */
|
|
101
104
|
|
|
102
105
|
|
|
103
106
|
|
|
104
107
|
|
|
105
|
-
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
106
113
|
|
|
107
114
|
|
|
108
115
|
|
|
@@ -520,6 +527,52 @@ export const DEFAULT_NATIVE_RESULT_LIMIT = 6000;
|
|
|
520
527
|
* 整块丢弃旧段(ADR-001:整块丢弃路线,显式缓存重置点,原文句柄化可回取)。 */
|
|
521
528
|
export const DEFAULT_SEGMENT_MAX_CHARS = 160_000;
|
|
522
529
|
|
|
530
|
+
/** v0.3.2:单步正文落追加区的上限(字符)。prose 通常很短;超长只截断历史摘要,
|
|
531
|
+
* 当期 assistant/message 仍完整落盘(不改变可读输出)。 */
|
|
532
|
+
export const STEP_PROSE_COMMIT_LIMIT = 4000;
|
|
533
|
+
|
|
534
|
+
/** v0.3.2:同一回合内"输出被截断 → 要求续写"的最大次数。超过即如实 blocked,
|
|
535
|
+
* 不无限重试(真机 max-tokens 截断的恢复路径需要重发完整命令,次数有界)。 */
|
|
536
|
+
export const MAX_TRUNCATION_RETRIES = 4;
|
|
537
|
+
|
|
538
|
+
/** v0.3.2:可转正进追加区的易变尾前缀(事实类)。瞬态指令(nudge/degraded/error)不转正。 */
|
|
539
|
+
const DURABLE_TAIL_PREFIXES = [
|
|
540
|
+
'[tf-stream:observation',
|
|
541
|
+
'[tf-stream:peek',
|
|
542
|
+
'[tf-stream:tool-result',
|
|
543
|
+
'[tf-stream:replay',
|
|
544
|
+
];
|
|
545
|
+
|
|
546
|
+
/** v0.3.2:正文归一化(连续空行压成一个;去首尾空白)——避免 "\n\n\n\n" 的空消息污染正文。 */
|
|
547
|
+
export function normalizeProse(text ) {
|
|
548
|
+
return text.replace(/\r\n/g, '\n').replace(/\n{3,}/g, '\n\n').trim();
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/** 截断到上限(保留尾部标记,便于台账核对)。 */
|
|
552
|
+
function capText(text , limit ) {
|
|
553
|
+
return text.length <= limit ? text : `${text.slice(0, limit)}…(截断 ${text.length - limit} 字符)`;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* v0.3.2:输出截断的续写注入。带已生成内容尾部(≤800 字符)——正文命令被 max-tokens
|
|
558
|
+
* 截断时,模型可以从断点继续,而不是从头重写整个文件。
|
|
559
|
+
*/
|
|
560
|
+
function truncationNudge(truncation ) {
|
|
561
|
+
const tail = truncation.raw.length <= 800
|
|
562
|
+
? truncation.raw
|
|
563
|
+
: `…${truncation.raw.slice(truncation.raw.length - 800)}`;
|
|
564
|
+
const head = truncation.reason === 'max-tokens'
|
|
565
|
+
? '上一条请求的输出触及 max tokens 上限,在句子/命令中途被截断。'
|
|
566
|
+
: `上一条请求的输出在命令中途被截断(${truncation.reason})。`;
|
|
567
|
+
return [
|
|
568
|
+
`[tf-stream:truncated reason=${truncation.reason}] ${head}`,
|
|
569
|
+
'已完整闭合的命令都已执行,不要重复执行;未闭合的命令没有被执行。',
|
|
570
|
+
'请从断点继续:把被截断的命令用**新 id**完整重发(正文命令必须给出完整内容,不能只给片段),',
|
|
571
|
+
'然后继续未完成的工作;任务确实已完成则输出 tf-final(summary 写最终答案原文)。',
|
|
572
|
+
tail !== '' ? `已生成部分的尾部(供续写定位):\n${tail}` : '',
|
|
573
|
+
].filter((line) => line !== '').join('\n');
|
|
574
|
+
}
|
|
575
|
+
|
|
523
576
|
// ---------------------------------------------------------------------------
|
|
524
577
|
// ② SingleStreamDriver
|
|
525
578
|
// ---------------------------------------------------------------------------
|
|
@@ -644,6 +697,8 @@ export class SingleStreamDriver {
|
|
|
644
697
|
#requestCount = 0;
|
|
645
698
|
#reentryCount = 0;
|
|
646
699
|
#finalNudges = 0;
|
|
700
|
+
/** v0.3.2:上次 nudge 时的 ok 命令数(进度感知护栏的基准点;null = 本回合尚未 nudge)。 */
|
|
701
|
+
#nudgeMark = null;
|
|
647
702
|
#finalOnlyRequests = 0;
|
|
648
703
|
#deltaCursor = 0; // O3 directoryDelta 游标(obs seq 空间)
|
|
649
704
|
#usage = { inputTokens: 0, outputTokens: 0 };
|
|
@@ -685,6 +740,29 @@ export class SingleStreamDriver {
|
|
|
685
740
|
#pendingReplays = [];
|
|
686
741
|
#replays = 0;
|
|
687
742
|
#replayCapped = false;
|
|
743
|
+
/**
|
|
744
|
+
* v0.3.2 连续性问题(真机 session-e4b9a89c):请求之间模型看不到自己上一步的正文、
|
|
745
|
+
* 命令与命令结果——0.3.x 只把观测注入"易变尾"一次(#reportedObservations 永不重放),
|
|
746
|
+
* 易变尾每请求重建、从不进追加区。于是第 2 个请求之后模型看到的只有 system + 任务 +
|
|
747
|
+
* 句柄目录行,模型侧原话"history is truncated / I don't have their content in context",
|
|
748
|
+
* 随后重复读同一文件、用占位 final 收场。修复:每步的正文 + 命令摘要落进追加区
|
|
749
|
+
*(assistant/message 语义),已发出的易变尾在下一请求装配后转正为历史(只追加,前缀单调)。
|
|
750
|
+
*/
|
|
751
|
+
#lastStepDigest
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
= null;
|
|
758
|
+
/** 已随请求发出、尚未转正进追加区的易变尾(含 step 归属,跨回合不转正)。 */
|
|
759
|
+
#deliveredTail = null;
|
|
760
|
+
/** 本步被截断的事实(parser truncated 事件 / finish=max-tokens);非空即强制续写一次。 */
|
|
761
|
+
#truncation = null;
|
|
762
|
+
#truncationRetries = 0;
|
|
763
|
+
/** 本步命令 id 与原生调用(摘要用;流开始时重置) */
|
|
764
|
+
#stepCommandIds = [];
|
|
765
|
+
#stepNatives = [];
|
|
688
766
|
/** v0.3.1:当前流内的 prose 累积(parser 的 text 事件拼接;落盘 assistant/message 的正文)。
|
|
689
767
|
* 0.3.0 落盘的是整段原文(含 tf-* 标记与 DSML 噪声)——桌面端过程区把协议标记渲染成乱码,
|
|
690
768
|
* 本版起落盘纯 prose:命令事实在台账(plugin:tf-agent/*),会话日志只留用户可读内容。 */
|
|
@@ -811,6 +889,13 @@ export class SingleStreamDriver {
|
|
|
811
889
|
if (selection.reasoningEffort !== undefined) this.#cfg.reasoningEffort = selection.reasoningEffort;
|
|
812
890
|
}
|
|
813
891
|
|
|
892
|
+
/** v0.3.2:assistant 消息宿主来源的实时值(写入时取,不缓存;applySelection 后随动)。
|
|
893
|
+
* 会话日志与请求装配共用;kind 固定 'model'。空串由 makeAssistantMessage 兜底为
|
|
894
|
+
* 'unknown'(宿主校验拒绝空字符串)。 */
|
|
895
|
+
modelSource() {
|
|
896
|
+
return { kind: 'model', provider: this.#cfg.provider, model: this.#cfg.model };
|
|
897
|
+
}
|
|
898
|
+
|
|
814
899
|
/** Agent 层接线:会话 id(请求路由 stamp)与任务 id(gate 凭据绑定)。 */
|
|
815
900
|
setIdentity(sessionId , taskId ) {
|
|
816
901
|
this.#sessionId = sessionId;
|
|
@@ -1053,6 +1138,11 @@ export class SingleStreamDriver {
|
|
|
1053
1138
|
} finally {
|
|
1054
1139
|
// K4:回合收束前等待在途命令清理完成(0 后置写),再释放回合 signal。
|
|
1055
1140
|
await this.#drain();
|
|
1141
|
+
// v0.3.2:回合已结束但最后一步的易变尾还没轮到"下一请求"转正——在此收编,
|
|
1142
|
+
// 保证下个回合(或 resume 后的同会话)仍能看到最后一步的观测事实。
|
|
1143
|
+
if (this.#deliveredTail !== null && this.#deliveredTail.turn === turn) {
|
|
1144
|
+
this.#commitDeliveredTail();
|
|
1145
|
+
}
|
|
1056
1146
|
if (this.#turnController === controller) this.#turnController = null;
|
|
1057
1147
|
}
|
|
1058
1148
|
}
|
|
@@ -1065,6 +1155,7 @@ export class SingleStreamDriver {
|
|
|
1065
1155
|
// 不重置的话,多任务长会话会在第 N 个回合被历史累计计数误杀(F7 长会话测试实抓)。
|
|
1066
1156
|
this.#reentryCount = 0;
|
|
1067
1157
|
this.#finalNudges = 0;
|
|
1158
|
+
this.#nudgeMark = null;
|
|
1068
1159
|
this.#finalOnlyRequests = 0;
|
|
1069
1160
|
// v0.3.1:final 收束闸的回合级状态(命令序按回合重置——上一回合的 final 不得收敛本回合)
|
|
1070
1161
|
this.#cmdOrder = 0;
|
|
@@ -1074,9 +1165,14 @@ export class SingleStreamDriver {
|
|
|
1074
1165
|
this.#pendingReplays = [];
|
|
1075
1166
|
this.#replays = 0;
|
|
1076
1167
|
this.#replayCapped = false;
|
|
1168
|
+
this.#truncationRetries = 0;
|
|
1169
|
+
this.#truncation = null;
|
|
1077
1170
|
let reason = { kind: 'blocked', detail: 'turn loop exited without convergence' };
|
|
1078
1171
|
|
|
1079
1172
|
while (true) {
|
|
1173
|
+
// v0.3.2:上一步的正文 + 命令摘要先落追加区(assistant/message 语义),再发下一请求。
|
|
1174
|
+
// 顺序刻意为"摘要 → 易变尾":模型看到的时间线与真实发生顺序一致。
|
|
1175
|
+
this.#commitStepDigest();
|
|
1080
1176
|
// ---- steer 注入(修复限制 2):运行中到达的 steer 在下一请求(内建的"下一步")生效
|
|
1081
1177
|
// ——进追加区(只追加,前缀单调不破);流内不打断:当前流早已跑完才会走到这里。
|
|
1082
1178
|
if (this.#pendingSteers.length > 0) {
|
|
@@ -1098,6 +1194,9 @@ export class SingleStreamDriver {
|
|
|
1098
1194
|
|
|
1099
1195
|
// ---- REQUEST:装配 + O6 preflight(render() 内置断言,违反即抛 → fail-closed)----
|
|
1100
1196
|
const messages = this.#renderer.render();
|
|
1197
|
+
// v0.3.2:刚刚发出去的易变尾(上一步的观测/错误/原生结果)转正为追加区历史——
|
|
1198
|
+
// 下一次请求仍可见(缓存读),不再"注入一次就消失"。只追加,前缀单调性不变。
|
|
1199
|
+
this.#commitDeliveredTail();
|
|
1101
1200
|
const stableHash = this.#renderer.stableHash();
|
|
1102
1201
|
this.#stableHashes.push(stableHash);
|
|
1103
1202
|
const fullHash = renderHash(messages);
|
|
@@ -1137,6 +1236,16 @@ export class SingleStreamDriver {
|
|
|
1137
1236
|
// ---- 收束判定(仅三种重入事由:失败/拒绝、high 观测、peek 需求)----
|
|
1138
1237
|
const issues = this.#collectIssues();
|
|
1139
1238
|
const injections = this.#buildInjections(issues, level);
|
|
1239
|
+
// v0.3.2 截断修复:输出在命令中途被截断(max-tokens / 流异常终止 / DSML 块未闭合)时,
|
|
1240
|
+
// 0.3.1 只记一条 truncated 台账、不产生任何重入事由——模型以为任务结束,用户看到
|
|
1241
|
+
// 半截输出。这里强制一次续写注入(带上已生成内容尾部,便于从断点续写);
|
|
1242
|
+
// 回合级上限 MAX_TRUNCATION_RETRIES,超限如实 blocked,不无限烧请求。
|
|
1243
|
+
if (this.#truncation !== null && level !== 'final-only' && this.#truncationRetries < MAX_TRUNCATION_RETRIES) {
|
|
1244
|
+
this.#truncationRetries += 1;
|
|
1245
|
+
injections.blocks.push({ role: 'user', content: truncationNudge(this.#truncation) });
|
|
1246
|
+
this.#record({ seq: ++DRIVER_SEQ, kind: 'fault', fault: 'output-truncated', detail: `${this.#truncation.reason}(第 ${this.#truncationRetries} 次续写)` });
|
|
1247
|
+
this.#ledgerWrite('plugin:tf-agent/fault', { fault: 'output-truncated', reason: this.#truncation.reason, retry: this.#truncationRetries, turn });
|
|
1248
|
+
}
|
|
1140
1249
|
// 饥饿防线(07 号结果 §3.6 上报的断链,08 号评测前按其建议修复):
|
|
1141
1250
|
// 升格骨架接入注入通路(按 high 观测同款格式;final-only 档不注入——预算已枯竭)。
|
|
1142
1251
|
const promoted = this.#obs.noteStep(injections.highInjected);
|
|
@@ -1214,9 +1323,14 @@ export class SingleStreamDriver {
|
|
|
1214
1323
|
const needsReentry = issues.length > 0 || injections.blocks.length > 0 || prematureFinal !== undefined || pendingSteerCount > 0;
|
|
1215
1324
|
|
|
1216
1325
|
if (prematureFinal !== undefined && lastFinal !== undefined) {
|
|
1326
|
+
// v0.3.2:计划门槛拒绝时附上计划快照——模型看不到计划内容就无法验收
|
|
1327
|
+
//(真机里计划只在创建那一步的易变尾出现过一次,随后彻底消失)。
|
|
1328
|
+
const planBlock = prematureFinal.includes('计划') ? this.#planSnapshot() : '';
|
|
1217
1329
|
injections.blocks.push({
|
|
1218
1330
|
role: 'user' ,
|
|
1219
|
-
content: `[tf-stream:error id=${lastFinal.cmdId} cmd=tf-final] ${prematureFinal}\n
|
|
1331
|
+
content: `[tf-stream:error id=${lastFinal.cmdId} cmd=tf-final] ${prematureFinal}\n`
|
|
1332
|
+
+ (planBlock !== '' ? `当前计划:\n${planBlock}\n` : '')
|
|
1333
|
+
+ '建议:先取回所需结果(tf-peek)或补齐未完成命令,然后在流末尾用新 id 重发 tf-final;summary 必须包含最终答案原文(数字/行内容/路径/结论),不得占位。',
|
|
1220
1334
|
});
|
|
1221
1335
|
this.#record({ seq: ++DRIVER_SEQ, kind: 'fault', fault: 'premature-final', detail: prematureFinal });
|
|
1222
1336
|
this.#ledgerWrite('plugin:tf-agent/fault', { fault: 'premature-final', detail: prematureFinal, turn });
|
|
@@ -1250,7 +1364,14 @@ export class SingleStreamDriver {
|
|
|
1250
1364
|
}
|
|
1251
1365
|
|
|
1252
1366
|
const finalOnlyGate = level === 'final-only' && this.#finalOnlyRequests >= 1;
|
|
1253
|
-
|
|
1367
|
+
// v0.3.2:nudge 进度感知护栏。nudge 不再是一次性预算——被提示后模型**继续产出**
|
|
1368
|
+
// (新 ok 命令)就不算"提示失效",绝不因此中断生产性工作;只有"零产出的连续
|
|
1369
|
+
// nudge"(真打转)才 blocked。整体仍由 maxReentries / O5 预算阶梯兜底。
|
|
1370
|
+
// 真机取证(session-8f22c7a0):旧语义下 nudge 在写文件步被消耗,随后的崩溃步
|
|
1371
|
+
// (或任何无注入的写步)直接 nudgeExhausted → 任务中断。
|
|
1372
|
+
const okCommandCount = [...this.#commands.values()].filter((r) => r.status === 'ok').length;
|
|
1373
|
+
const progressSinceNudge = this.#nudgeMark === null || okCommandCount > this.#nudgeMark;
|
|
1374
|
+
const nudgeExhausted = !needsReentry && !finalSeen && this.#finalNudges >= 1 && !progressSinceNudge;
|
|
1254
1375
|
if (this.#aborted || finalOnlyGate || nudgeExhausted || this.#reentryCount >= this.#cfg.maxReentries) {
|
|
1255
1376
|
if (this.#aborted) {
|
|
1256
1377
|
reason = { kind: 'aborted', reason: this.#abortReason instanceof Error ? this.#abortReason.message : String(this.#abortReason ?? 'cancelled') };
|
|
@@ -1291,8 +1412,10 @@ export class SingleStreamDriver {
|
|
|
1291
1412
|
this.#record({ seq: ++DRIVER_SEQ, kind: 'fault', fault: 'degraded-delivery' });
|
|
1292
1413
|
this.#ledgerWrite('plugin:tf-agent/fault', { fault: 'degraded-delivery', turn });
|
|
1293
1414
|
} else {
|
|
1294
|
-
// 无重入事由但也没 tf-final
|
|
1415
|
+
// 无重入事由但也没 tf-final:进度感知提示(护栏防无限循环——真打转由
|
|
1416
|
+
// nudgeExhausted 的"零产出"判定收束,不靠提示次数)。
|
|
1295
1417
|
this.#finalNudges += 1;
|
|
1418
|
+
this.#nudgeMark = [...this.#commands.values()].filter((r) => r.status === 'ok').length;
|
|
1296
1419
|
tail = [{
|
|
1297
1420
|
role: 'user' ,
|
|
1298
1421
|
content: rejectedFinal !== undefined
|
|
@@ -1305,6 +1428,12 @@ export class SingleStreamDriver {
|
|
|
1305
1428
|
this.#injectedChars += tail.reduce((n, b) => n + b.content.length, 0);
|
|
1306
1429
|
if (level === 'final-only') this.#finalOnlyRequests += 1;
|
|
1307
1430
|
this.#renderer.setTail(tail);
|
|
1431
|
+
// v0.3.2:这批尾块会随下一请求发出;发出后由 #commitDeliveredTail 转正为历史。
|
|
1432
|
+
this.#deliveredTail = {
|
|
1433
|
+
turn,
|
|
1434
|
+
step,
|
|
1435
|
+
blocks: tail.map((b) => ({ role: (b.role ?? 'user') , content: b.content })),
|
|
1436
|
+
};
|
|
1308
1437
|
this.#reentryCount += 1;
|
|
1309
1438
|
}
|
|
1310
1439
|
|
|
@@ -1347,6 +1476,10 @@ export class SingleStreamDriver {
|
|
|
1347
1476
|
// 新流:隐式写序的流内序号清零(跨流依赖仍由 depends_on 显式声明)
|
|
1348
1477
|
this.#streamSeqCounter = 0;
|
|
1349
1478
|
this.#streamWrites = [];
|
|
1479
|
+
// v0.3.2:本步摘要与截断事实(续写注入 + 追加区转录用)
|
|
1480
|
+
this.#stepCommandIds = [];
|
|
1481
|
+
this.#stepNatives = [];
|
|
1482
|
+
this.#truncation = null;
|
|
1350
1483
|
const parser = new TfStreamParser();
|
|
1351
1484
|
const controller = new AbortController();
|
|
1352
1485
|
this.#activeControllers.add(controller);
|
|
@@ -1493,6 +1626,23 @@ export class SingleStreamDriver {
|
|
|
1493
1626
|
// 流终止:冲刷 parser(truncated / done)
|
|
1494
1627
|
for (const event of parser.end()) this.#handleParserEvent(event, turn, step);
|
|
1495
1628
|
|
|
1629
|
+
// v0.3.2:finish=max-tokens 本身就是"输出被截断"的硬信号(即使命令恰好闭合,
|
|
1630
|
+
// 正文也可能停在半句)。与 parser 的 truncated 事件合并成一次续写事由。
|
|
1631
|
+
if (finish.kind === 'max-tokens' && this.#truncation === null) {
|
|
1632
|
+
this.#truncation = { reason: 'max-tokens', raw: this.#streamProse };
|
|
1633
|
+
}
|
|
1634
|
+
// 本步摘要:下一步请求装配前落追加区(#commitStepDigest)
|
|
1635
|
+
this.#stepNatives = (finish.kind === 'stop' || finish.kind === 'tool-calls')
|
|
1636
|
+
? [...natives.values()].map((c) => ({ id: c.id, name: c.name ?? 'unknown' }))
|
|
1637
|
+
: [];
|
|
1638
|
+
this.#lastStepDigest = {
|
|
1639
|
+
turn,
|
|
1640
|
+
step,
|
|
1641
|
+
prose: this.#streamProse,
|
|
1642
|
+
cmdIds: [...this.#stepCommandIds],
|
|
1643
|
+
natives: [...this.#stepNatives],
|
|
1644
|
+
};
|
|
1645
|
+
|
|
1496
1646
|
// 会话落盘:assistant 消息(成功 → assistant/message;error/aborted → attempt / 中断消息)
|
|
1497
1647
|
// v0.3.0:原生 tool_call 通道要在**同一条** assistant 消息里广告 tool-call 块,
|
|
1498
1648
|
// 否则随后宿主写出的 tool/call 在 v4 格式校验里没有生命周期 → 历史加载被判 corrupt。
|
|
@@ -1506,7 +1656,9 @@ export class SingleStreamDriver {
|
|
|
1506
1656
|
const reasoningText = reasoningParts.join('\n');
|
|
1507
1657
|
let settlement ;
|
|
1508
1658
|
try {
|
|
1509
|
-
|
|
1659
|
+
// v0.3.2:落盘正文归一化(去纯空白消息 / 压缩连续空行)——0.3.1 常见 "\n\n\n\n"
|
|
1660
|
+
// 空气泡,桌面端过程区看起来就是"被截断的空白"。
|
|
1661
|
+
settlement = this.#ports.events?.assistantMessage(turn, step, normalizeProse(this.#streamProse), {
|
|
1510
1662
|
finish,
|
|
1511
1663
|
usage: usageSeen,
|
|
1512
1664
|
toolCalls: nativeAds,
|
|
@@ -1552,6 +1704,8 @@ export class SingleStreamDriver {
|
|
|
1552
1704
|
case 'truncated':
|
|
1553
1705
|
this.#record({ seq: ++DRIVER_SEQ, kind: 'truncated', raw: event.raw, reason: event.reason });
|
|
1554
1706
|
this.#ledgerWrite('plugin:tf-agent/fault', { fault: 'truncated-command', reason: event.reason });
|
|
1707
|
+
// v0.3.2:截断不再只是台账——本步结束前由 #turnLoop 强制一次续写注入。
|
|
1708
|
+
this.#truncation = { reason: event.reason, raw: event.raw };
|
|
1555
1709
|
break;
|
|
1556
1710
|
case 'cycle':
|
|
1557
1711
|
// 环上的命令永不就绪 → 收束判定以结构化错误重入
|
|
@@ -1574,6 +1728,8 @@ export class SingleStreamDriver {
|
|
|
1574
1728
|
// v0.3.1:回合级命令序(跨请求单调)。final 之后又发过非 final 命令 → 那条 final 过期
|
|
1575
1729
|
//(模型写完 final 又继续干活;旧答案不能当成交付内容)。
|
|
1576
1730
|
const order = ++this.#cmdOrder;
|
|
1731
|
+
// v0.3.2:本步摘要(含重复 id 的命令——模型确实发过它们,历史要如实)
|
|
1732
|
+
this.#stepCommandIds.push(cmd.id);
|
|
1577
1733
|
if (cmd.name !== 'tf-final') this.#lastNonFinalOrder = order;
|
|
1578
1734
|
const prev = this.#commands.get(cmd.id);
|
|
1579
1735
|
if (prev !== undefined) {
|
|
@@ -1705,6 +1861,71 @@ export class SingleStreamDriver {
|
|
|
1705
1861
|
return out;
|
|
1706
1862
|
}
|
|
1707
1863
|
|
|
1864
|
+
/**
|
|
1865
|
+
* v0.3.2:把上一步的正文 + 命令摘要落进追加区(assistant/message 语义)。
|
|
1866
|
+
*
|
|
1867
|
+
* 为什么必须有:渲染器只持有"稳定前缀 + 追加区 + 易变尾"。0.3.x 从不往追加区写
|
|
1868
|
+
* assistant/工具事实,易变尾又每请求重建——模型在第 2 个请求起就只看到 system + 任务 +
|
|
1869
|
+
* 句柄目录行。真机 session-e4b9a89c 里模型的原话是"The history is truncated. I don't see
|
|
1870
|
+
* the plan content",随后反复重读、计划无法验收、9 步后 blocked。
|
|
1871
|
+
*
|
|
1872
|
+
* 对齐内建 dsh-agent-loop 的语义:`session.deriveMessages()` 每步都把完整的
|
|
1873
|
+
* assistant/message(含 tool-call 块)与 tool/result 回放给模型;这里用压缩摘要
|
|
1874
|
+
*(id/命令/目标/状态/句柄/字符数)落追加区,原结果由随后的易变尾转正承载。
|
|
1875
|
+
*/
|
|
1876
|
+
#commitStepDigest() {
|
|
1877
|
+
const digest = this.#lastStepDigest;
|
|
1878
|
+
this.#lastStepDigest = null;
|
|
1879
|
+
if (digest === null) return;
|
|
1880
|
+
const prose = normalizeProse(digest.prose);
|
|
1881
|
+
if (prose !== '') {
|
|
1882
|
+
// v0.3.2:assistant 历史块必须带 source(宿主 forAdapter 无防护读
|
|
1883
|
+
// source.replayState;缺失 = 请求崩溃。provider/model 取驱动器实时路由)。
|
|
1884
|
+
this.#renderer.appendHistory({ role: 'assistant', content: capText(prose, STEP_PROSE_COMMIT_LIMIT), source: this.modelSource() });
|
|
1885
|
+
}
|
|
1886
|
+
const lines = [];
|
|
1887
|
+
for (const id of digest.cmdIds) {
|
|
1888
|
+
const rec = this.#commands.get(id);
|
|
1889
|
+
if (rec === undefined) continue;
|
|
1890
|
+
const target = rec.cmd.attrs['path'] ?? rec.cmd.attrs['cmd'] ?? rec.cmd.attrs['pattern']
|
|
1891
|
+
?? rec.cmd.attrs['handle'] ?? rec.cmd.attrs['summary'] ?? '';
|
|
1892
|
+
const detail = rec.detail !== undefined && rec.detail !== '' ? ` · ${capText(rec.detail, 120)}` : '';
|
|
1893
|
+
lines.push(
|
|
1894
|
+
`- ${id} ${rec.cmd.name}${target !== '' ? ` ${capText(target, 120)}` : ''} → ${rec.status}`
|
|
1895
|
+
+ `${rec.handle !== undefined ? ` handle=${rec.handle}` : ''}${detail}`,
|
|
1896
|
+
);
|
|
1897
|
+
}
|
|
1898
|
+
for (const native of digest.natives) {
|
|
1899
|
+
lines.push(`- native ${native.name} (callId=${native.id}) → 已执行,结果见随后注入块`);
|
|
1900
|
+
}
|
|
1901
|
+
if (lines.length === 0) return;
|
|
1902
|
+
this.#renderer.appendHistory({
|
|
1903
|
+
role: 'user',
|
|
1904
|
+
content: `[tf-stream:step step=${digest.step} 上一步动作与结果]\n${lines.join('\n')}`,
|
|
1905
|
+
});
|
|
1906
|
+
}
|
|
1907
|
+
|
|
1908
|
+
/** v0.3.2:把已随请求发出的易变尾转正为追加区历史(下一请求仍可见,不再一次性蒸发)。
|
|
1909
|
+
* 只转正"事实类"块(观测/peek/原生结果/回灌);nudge / degraded / error 这类
|
|
1910
|
+
* 瞬态指令不回灌历史——否则下一回合模型会把过期的"预算告急""final 被拒"当现状。 */
|
|
1911
|
+
#commitDeliveredTail() {
|
|
1912
|
+
const delivered = this.#deliveredTail;
|
|
1913
|
+
this.#deliveredTail = null;
|
|
1914
|
+
if (delivered === null) return;
|
|
1915
|
+
for (const block of delivered.blocks) {
|
|
1916
|
+
if (!DURABLE_TAIL_PREFIXES.some((prefix) => block.content.startsWith(prefix))) continue;
|
|
1917
|
+
this.#renderer.appendHistory({ role: block.role, content: block.content });
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
/** F5 计划快照(final 被计划门槛拒绝时随注入一起给出,模型不必凭记忆猜验收项)。 */
|
|
1922
|
+
#planSnapshot() {
|
|
1923
|
+
if (this.#plan === null) return '';
|
|
1924
|
+
return [...this.#plan.items.entries()]
|
|
1925
|
+
.map(([id, item]) => `- [${id}] ${item.text}(${item.status})`)
|
|
1926
|
+
.join('\n');
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1708
1929
|
/** 派发所有就绪命令(依赖全部 ok、未派发),并发上限 maxParallelToolCalls。
|
|
1709
1930
|
* 隐式写序(上游 ThinkFlow 语义):任何命令隐式等待同流内先闭合且尚未 ok 的 tf-write——
|
|
1710
1931
|
* 先写后读不会读到旧内容;写族自身按 FIFO 排队(同流多写不再并发竞态)。 */
|
|
@@ -2266,9 +2487,13 @@ export class SingleStreamDriver {
|
|
|
2266
2487
|
const fp = full === null ? 'unavailable' : contentFingerprint(full);
|
|
2267
2488
|
blocks.push({
|
|
2268
2489
|
role: 'user',
|
|
2490
|
+
// v0.3.2 文案修正:写入正文不回灌——跨流步骤后"全文已在你的上下文中"是假的
|
|
2491
|
+
// (真机 session-8f22c7a0:模型自述 "I don't have the exact text visible",
|
|
2492
|
+
// 被迫全量重写四个文件)。如实说明 + 给 tf-peek 取回路径。
|
|
2269
2493
|
content: `[tf-stream:receipt handle=${obs.handle ?? ''} path=${rec.cmd.attrs['path']} lines=${lines} sha256=${fp}]`
|
|
2270
|
-
+ `\n该路径由你本任务的 tf-write
|
|
2271
|
-
+
|
|
2494
|
+
+ `\n该路径由你本任务的 tf-write 写入,写入成功(写失败会有 [tf-stream:error];没有错误注入即写成功)。`
|
|
2495
|
+
+ `写入正文不回灌(回验纪律)——若它是在更早的流步骤写的,你当前上下文里没有原文。`
|
|
2496
|
+
+ `需要原文(全量或行段)用 tf-peek handle="${obs.handle}" 取回;需要修改用 tf-edit 的 OLD 精确字面量可先 tf-peek 取回后再改。`,
|
|
2272
2497
|
});
|
|
2273
2498
|
highInjected = true;
|
|
2274
2499
|
continue;
|
|
@@ -2506,7 +2731,13 @@ function finishDetail(finish ) {
|
|
|
2506
2731
|
|
|
2507
2732
|
/** RenderMessage → GenerateOptions.messages 线格式(loop-built 请求:首条 system 携带系统提示)。 */
|
|
2508
2733
|
function toWireMessages(messages ) {
|
|
2509
|
-
|
|
2734
|
+
// v0.3.2:assistant 消息必须携带 source(宿主 LlmRuntime.forAdapter 无防护读
|
|
2735
|
+
// `message.source.replayState`,GitHub master 同源;缺失 = 流 error → 回合中断)。
|
|
2736
|
+
return messages.map((m) => ({
|
|
2737
|
+
role: m.role,
|
|
2738
|
+
content: [{ type: 'text' , text: m.content }],
|
|
2739
|
+
...(m.source === undefined ? {} : { source: { ...m.source } }),
|
|
2740
|
+
}));
|
|
2510
2741
|
}
|
|
2511
2742
|
|
|
2512
2743
|
/**
|
|
@@ -2542,6 +2773,22 @@ export function normalizeStreamShim(inner )
|
|
|
2542
2773
|
// 会话事件写入器(真实宿主路径;形状镜像内建 loop 的 append 调用)
|
|
2543
2774
|
// ---------------------------------------------------------------------------
|
|
2544
2775
|
|
|
2776
|
+
/**
|
|
2777
|
+
* 会话日志 assistant 消息的 model source(v0.3.2 修复)。
|
|
2778
|
+
* 宿主校验器(dsh-session assertMessageEventShape → hasProviderModel)要求
|
|
2779
|
+
* `source = {kind:'model', provider:<非空字符串>, model:<非空字符串>}`;缺 provider/model
|
|
2780
|
+
* 的日志在读取时抛 `message must have model source`,整条会话被判 corrupt——桌面端
|
|
2781
|
+
* 表现为"历史加载失败"。0.3.1 及更早版本只写了 `{kind:'model'}`,本类型把实时
|
|
2782
|
+
* provider/model 带进写入路径(applySelection 换模后随动)。
|
|
2783
|
+
*/
|
|
2784
|
+
/** v0.3.2:assistant 消息的宿主来源(会话日志 source 与请求装配的 RenderMessage.source
|
|
2785
|
+
* 共用)。kind 固定 'model'(宿主 forAdapter/validateReplay 都先读 source.kind)。 */
|
|
2786
|
+
|
|
2787
|
+
|
|
2788
|
+
|
|
2789
|
+
|
|
2790
|
+
|
|
2791
|
+
|
|
2545
2792
|
/**
|
|
2546
2793
|
* 从 duck-typed Session 构造 TurnEventWriter。
|
|
2547
2794
|
* 事件形状对照:turn/start {turn}(:731)、step/start {turn,step}(:757)、
|
|
@@ -2550,8 +2797,12 @@ export function normalizeStreamShim(inner )
|
|
|
2550
2797
|
* assistant/attempt {turn,step,stream}(:924)。assistant message 形状镜像
|
|
2551
2798
|
* dsh-llm createAssistantMessage(lib/types/message.js:64-73):{id, role:'assistant',
|
|
2552
2799
|
* content:[{type:'text',text}], source:{kind:'model', provider, model}}(探针 C 实测可写)。
|
|
2800
|
+
*
|
|
2801
|
+
* v0.3.2:modelInfo 在**写入时**调用(不缓存)——applySelection 运行时换模后随动;
|
|
2802
|
+
* 缺省(离线/无模型路由信息)时 provider/model 落 'unknown',保证日志形状仍可通过
|
|
2803
|
+
* 宿主校验(空字符串同样会被 hasProviderModel 拒绝)。
|
|
2553
2804
|
*/
|
|
2554
|
-
export function createSessionEventWriter(session ) {
|
|
2805
|
+
export function createSessionEventWriter(session , modelInfo ) {
|
|
2555
2806
|
const s = session ;
|
|
2556
2807
|
if (s === undefined || typeof s.append !== 'function') return undefined;
|
|
2557
2808
|
const append = (type , data , opts ) => {
|
|
@@ -2578,7 +2829,7 @@ export function createSessionEventWriter(session )
|
|
|
2578
2829
|
// 中断但有部分正文:assistant/message + interrupted(镜像内建 :891-905)
|
|
2579
2830
|
return appendSettling('assistant/message', {
|
|
2580
2831
|
turn, step,
|
|
2581
|
-
message: makeAssistantMessage(text, [], reasoning),
|
|
2832
|
+
message: makeAssistantMessage(text, [], reasoning, modelInfo?.()),
|
|
2582
2833
|
interrupted: true,
|
|
2583
2834
|
...usageField,
|
|
2584
2835
|
stream: [],
|
|
@@ -2592,7 +2843,7 @@ export function createSessionEventWriter(session )
|
|
|
2592
2843
|
}
|
|
2593
2844
|
return appendSettling('assistant/message', {
|
|
2594
2845
|
turn, step,
|
|
2595
|
-
message: makeAssistantMessage(text, toolCalls, reasoning),
|
|
2846
|
+
message: makeAssistantMessage(text, toolCalls, reasoning, modelInfo?.()),
|
|
2596
2847
|
...usageField,
|
|
2597
2848
|
stream: [],
|
|
2598
2849
|
}, { surfaceOp: 'append' });
|
|
@@ -2604,7 +2855,7 @@ export function createSessionEventWriter(session )
|
|
|
2604
2855
|
// (宿主校验器用严格相等比对 name/arguments)。
|
|
2605
2856
|
append('assistant/message', {
|
|
2606
2857
|
turn, step,
|
|
2607
|
-
message: makeAssistantMessage('', calls),
|
|
2858
|
+
message: makeAssistantMessage('', calls, undefined, modelInfo?.()),
|
|
2608
2859
|
stream: [],
|
|
2609
2860
|
}, { surfaceOp: 'append' });
|
|
2610
2861
|
},
|
|
@@ -2659,7 +2910,7 @@ export function createSessionEventWriter(session )
|
|
|
2659
2910
|
finalAnswer(turn, step, text) {
|
|
2660
2911
|
append('assistant/message', {
|
|
2661
2912
|
turn, step,
|
|
2662
|
-
message: makeAssistantMessage(text),
|
|
2913
|
+
message: makeAssistantMessage(text, [], undefined, modelInfo?.()),
|
|
2663
2914
|
stream: [],
|
|
2664
2915
|
}, { surfaceOp: 'append' });
|
|
2665
2916
|
},
|
|
@@ -2671,17 +2922,24 @@ export function createSessionEventWriter(session )
|
|
|
2671
2922
|
|
|
2672
2923
|
|
|
2673
2924
|
|
|
2674
|
-
|
|
2925
|
+
/**
|
|
2926
|
+
* 构造 assistant 消息(形状镜像 dsh-llm createAssistantMessage,lib/types/message.js:64-73)。
|
|
2927
|
+
* v0.3.2:source 必须携带非空 provider/model(宿主 hasProviderModel 校验,缺了整条日志
|
|
2928
|
+
* 判 corrupt);缺写入方未提供或为空串时落 'unknown'——日志保持可加载,不谎报模型。
|
|
2929
|
+
*/
|
|
2930
|
+
function makeAssistantMessage(text , toolCalls = [], reasoning , modelInfo ) {
|
|
2675
2931
|
const content = [];
|
|
2676
2932
|
// v0.3.1:reasoning 块在首位(镜像内建 BlockAssembler 的流序:思考先于正文)。
|
|
2677
2933
|
if (reasoning !== undefined && reasoning.trim() !== '') content.push({ type: 'reasoning', text: reasoning });
|
|
2678
2934
|
if (text.length > 0) content.push({ type: 'text', text });
|
|
2679
2935
|
for (const call of toolCalls) content.push({ type: 'tool-call', id: call.id, name: call.name, arguments: call.arguments });
|
|
2936
|
+
const provider = modelInfo?.provider !== undefined && modelInfo.provider !== '' ? modelInfo.provider : 'unknown';
|
|
2937
|
+
const model = modelInfo?.model !== undefined && modelInfo.model !== '' ? modelInfo.model : 'unknown';
|
|
2680
2938
|
return {
|
|
2681
2939
|
id: randomUUID(),
|
|
2682
2940
|
role: 'assistant',
|
|
2683
2941
|
content,
|
|
2684
|
-
source: { kind: 'model' },
|
|
2942
|
+
source: { kind: 'model', provider, model },
|
|
2685
2943
|
};
|
|
2686
2944
|
}
|
|
2687
2945
|
|
|
@@ -2703,9 +2961,15 @@ function makeAssistantMessage(text , toolCalls
|
|
|
2703
2961
|
|
|
2704
2962
|
|
|
2705
2963
|
|
|
2706
|
-
|
|
2964
|
+
|
|
2707
2965
|
|
|
2708
2966
|
|
|
2967
|
+
|
|
2968
|
+
|
|
2969
|
+
|
|
2970
|
+
|
|
2971
|
+
|
|
2972
|
+
|
|
2709
2973
|
|
|
2710
2974
|
|
|
2711
2975
|
|
|
@@ -2729,6 +2993,8 @@ export class StreamLoopAgent {
|
|
|
2729
2993
|
#selection ;
|
|
2730
2994
|
#disposeScope ;
|
|
2731
2995
|
#disposed = false;
|
|
2996
|
+
/** v0.3.2:agent/status 发射出口(宿主事件总线;缺省 = 不发)。 */
|
|
2997
|
+
#emitStatus = undefined;
|
|
2732
2998
|
|
|
2733
2999
|
constructor(deps ) {
|
|
2734
3000
|
this.id = deps.id;
|
|
@@ -2736,6 +3002,7 @@ export class StreamLoopAgent {
|
|
|
2736
3002
|
this.#driver = deps.driver;
|
|
2737
3003
|
this.#storedHandle = deps.storedHandle;
|
|
2738
3004
|
this.#warning = deps.onWarning ?? (() => {});
|
|
3005
|
+
this.#emitStatus = deps.emitStatus;
|
|
2739
3006
|
this.#selection = deps.modelSelection ?? { provider: '', model: '' };
|
|
2740
3007
|
// 作用域 key = agent 实例本身(镜像内建 createScope(loopCtx, this))。宿主工具执行器
|
|
2741
3008
|
// selectExecutor(input.agent) 与守卫 chainLayers(exec.agent) 都按 scopeChainOf(agent)
|
|
@@ -2810,6 +3077,23 @@ export class StreamLoopAgent {
|
|
|
2810
3077
|
if (this.#status === 'idle') this.#startNextTurn();
|
|
2811
3078
|
}
|
|
2812
3079
|
|
|
3080
|
+
/** v0.3.2:桌面端命令路径的通知注入(dsh-user-approval setPolicy:127 实测调用
|
|
3081
|
+
* `agent.inject(...)`——0.3.1 缺这个方法,改审批策略的命令以
|
|
3082
|
+
* "agent.inject is not a function" 报错收场)。镜像内建 send(input,'next-step',false):
|
|
3083
|
+
* 落盘 + 并入"下一步"装配,但**不唤醒空闲 agent**(通知型注入不该自己开回合)。
|
|
3084
|
+
* pendingSteers 在 runTurn 的每次请求前消费(含下一回合首请求)——无论运行中还是
|
|
3085
|
+
* 空闲都走同一通道,下一请求必然可见;steer/inject 的区别只在唤醒,与内建一致。 */
|
|
3086
|
+
inject(message ) {
|
|
3087
|
+
if (this.#disposed) throw new Error(`agent "${this.id}": inject after dispose`);
|
|
3088
|
+
const text = message.content
|
|
3089
|
+
.map((block) => (typeof block === 'object' && block !== null && 'text' in block && typeof (block ).text === 'string' ? (block ).text : ''))
|
|
3090
|
+
.join('\n');
|
|
3091
|
+
debugTrace('inject', { id: this.id, chars: text.length, running: this.#status === 'running' });
|
|
3092
|
+
this.#appendSessionEvent('user/message', message, { surfaceOp: 'append' });
|
|
3093
|
+
if (text.trim() === '') return;
|
|
3094
|
+
this.#driver.pushSteer(text, message);
|
|
3095
|
+
}
|
|
3096
|
+
|
|
2813
3097
|
/** 桌面端空内容续跑路径读取的 inbox 面(prompt:37548)。修复限制 2 后:
|
|
2814
3098
|
* nextStep 如实暴露尚未消费的 steer(已注入装配历史的从队列移除);
|
|
2815
3099
|
* nextTurn 恒为空(单流没有跨回合排队注入)。 */
|
|
@@ -2858,11 +3142,23 @@ export class StreamLoopAgent {
|
|
|
2858
3142
|
}
|
|
2859
3143
|
}
|
|
2860
3144
|
|
|
3145
|
+
/** v0.3.2:运行态转换统一出口(只在真正变化时发 agent/status,镜像内建 setPhase 语义)。
|
|
3146
|
+
* 发射失败不阻断回合(fail-open,告警不静默)。 */
|
|
3147
|
+
#setStatus(next ) {
|
|
3148
|
+
if (this.#status === next) return;
|
|
3149
|
+
this.#status = next;
|
|
3150
|
+
try {
|
|
3151
|
+
this.#emitStatus?.({ agent: this, status: next });
|
|
3152
|
+
} catch (error) {
|
|
3153
|
+
this.#warning(`agent "${this.id}": agent/status 发射失败(不阻断回合)`, error);
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
3156
|
+
|
|
2861
3157
|
/** 开下一回合(inbox 逐条串行驱动)。 */
|
|
2862
3158
|
#startNextTurn() {
|
|
2863
3159
|
const next = this.#inbox.shift();
|
|
2864
3160
|
if (next === undefined) return;
|
|
2865
|
-
this.#
|
|
3161
|
+
this.#setStatus('running');
|
|
2866
3162
|
this.#running = (async () => {
|
|
2867
3163
|
try {
|
|
2868
3164
|
this.#driver.pushUserTask(next.text);
|
|
@@ -2874,7 +3170,7 @@ export class StreamLoopAgent {
|
|
|
2874
3170
|
} finally {
|
|
2875
3171
|
this.#running = undefined;
|
|
2876
3172
|
if (this.#cancelCause !== undefined) {
|
|
2877
|
-
this.#
|
|
3173
|
+
this.#setStatus('idle');
|
|
2878
3174
|
if (!this.#cancelCause.keepInbox) this.#inbox.length = 0;
|
|
2879
3175
|
this.#cancelCause = undefined;
|
|
2880
3176
|
return;
|
|
@@ -2883,7 +3179,7 @@ export class StreamLoopAgent {
|
|
|
2883
3179
|
this.#startNextTurn();
|
|
2884
3180
|
return;
|
|
2885
3181
|
}
|
|
2886
|
-
this.#
|
|
3182
|
+
this.#setStatus('idle');
|
|
2887
3183
|
}
|
|
2888
3184
|
})();
|
|
2889
3185
|
}
|
|
@@ -3213,6 +3509,16 @@ export function createStreamAgentFactory(deps )
|
|
|
3213
3509
|
model: args.agentOptions.model ?? '',
|
|
3214
3510
|
reasoningEffort: args.agentOptions.reasoningEffort,
|
|
3215
3511
|
},
|
|
3512
|
+
// v0.3.2(UI 卡住修复):宿主事件总线在位(cordis ctx.emit)才接 agent/status。
|
|
3513
|
+
// 桌面端 dsh-api-session-controller 监听它转发 api-session/status(running 布尔),
|
|
3514
|
+
// 客户端据此收起"运行中"指示——不接线 = 回合结束后 UI 永远转圈。
|
|
3515
|
+
...(typeof (deps.ctx ).emit === 'function'
|
|
3516
|
+
? {
|
|
3517
|
+
emitStatus: (payload ) => {
|
|
3518
|
+
(deps.ctx ).emit('agent/status', payload);
|
|
3519
|
+
},
|
|
3520
|
+
}
|
|
3521
|
+
: {}),
|
|
3216
3522
|
onWarning: warning,
|
|
3217
3523
|
});
|
|
3218
3524
|
debugTrace('agent.constructed');
|
|
@@ -3612,6 +3918,10 @@ export default function apply(ctx
|
|
|
3612
3918
|
}
|
|
3613
3919
|
};
|
|
3614
3920
|
const intentSeqState = intentsEnabled ? loadIntentState() : { seq: 0 };
|
|
3921
|
+
// v0.3.2(会话日志 model source 修复):writer 在 driver 之前构造,provider/model
|
|
3922
|
+
// 却要到**写入时**才取实时值(applySelection 换模后随动)——用可变持有者回填。
|
|
3923
|
+
// 写入只发生在回合协程内(构造早已完成),时序安全。
|
|
3924
|
+
let driverRef ;
|
|
3615
3925
|
const driver = new SingleStreamDriver(
|
|
3616
3926
|
{
|
|
3617
3927
|
stream: (options) => llm.stream(options),
|
|
@@ -3640,11 +3950,12 @@ export default function apply(ctx
|
|
|
3640
3950
|
},
|
|
3641
3951
|
}
|
|
3642
3952
|
: {}),
|
|
3643
|
-
events: createSessionEventWriter(session),
|
|
3953
|
+
events: createSessionEventWriter(session, () => driverRef?.modelSource()),
|
|
3644
3954
|
onWarning: warning,
|
|
3645
3955
|
},
|
|
3646
3956
|
cfg,
|
|
3647
3957
|
);
|
|
3958
|
+
driverRef = driver;
|
|
3648
3959
|
// K2:会话工作区解析(tf-code resolve 透传用)。会话 header.cwd(会话原始目录)
|
|
3649
3960
|
// 优先,缺省回退宿主 workingDirectory 服务的部署默认目录;两者都不可得则不传,
|
|
3650
3961
|
// 由宿主按自己的默认语义解析。插件不复制宿主的优先级规则。
|