dsh-client-auto-continue 0.11.3 → 0.11.5

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.
@@ -69,13 +69,19 @@ export declare class AutoContinueRunner {
69
69
  private onHostEvent;
70
70
  /** 从 assistant/message 事件提取纯文本。 */
71
71
  private assistantText;
72
+ private assistantChunkText;
73
+ private normalizedSegment;
74
+ private isNearDuplicateSegment;
75
+ private withinEditDistance;
76
+ private noteStreamSegment;
77
+ private onAssistantChunk;
72
78
  private onAssistantMessage;
73
79
  /** 两个循环信号的公共检查; 命中且本回合未打断过则打断。 */
74
80
  private checkLoop;
75
81
  /**
76
82
  * 打断运行中的回合: cancel(带来源标记)+ 进冷却。
77
- * 随后的 turn/end aborted 会因 loopCancelled 走「可恢复中断」路径,
78
- * 用 loopText 重启回合——不会与用户手动停止混淆。
83
+ * 只有随后持久化的 turn/end 精确携带专属 hook cause 时,
84
+ * 才会用 loopText 重启回合——DSH 的 first-cause 语义保证用户 Stop 优先。
79
85
  */
80
86
  private interruptLoop;
81
87
  private onSessionEvent;
@@ -61,7 +61,7 @@ export declare const AutoContinueSchema: z<Schemastery.ObjectS<{
61
61
  loopWindowMs: z<number, number>;
62
62
  /** Consecutive short sentences trip the loop guard. */
63
63
  loopShortCount: z<number, number>;
64
- /** Consecutive identical short sentences trip the loop guard (strongest spinning signal). */
64
+ /** Consecutive identical assistant messages trip the loop guard (strongest signal; also used for streamed intra-message repetition). */
65
65
  loopRepeatText: z<number, number>;
66
66
  /** Consecutive identical tool calls with identical arguments AND results trip the loop guard. */
67
67
  loopToolRepeat: z<number, number>;
@@ -114,7 +114,7 @@ export declare const AutoContinueSchema: z<Schemastery.ObjectS<{
114
114
  loopWindowMs: z<number, number>;
115
115
  /** Consecutive short sentences trip the loop guard. */
116
116
  loopShortCount: z<number, number>;
117
- /** Consecutive identical short sentences trip the loop guard (strongest spinning signal). */
117
+ /** Consecutive identical assistant messages trip the loop guard (strongest signal; also used for streamed intra-message repetition). */
118
118
  loopRepeatText: z<number, number>;
119
119
  /** Consecutive identical tool calls with identical arguments AND results trip the loop guard. */
120
120
  loopToolRepeat: z<number, number>;
@@ -74,7 +74,7 @@ export interface AutoContinueSettings {
74
74
  loopShortCount?: number;
75
75
  /** Consecutive identical tool calls with identical arguments AND identical results trip the loop guard. */
76
76
  loopToolRepeat?: number;
77
- /** Consecutive identical short sentences trip the loop guard (strongest spinning signal). */
77
+ /** Consecutive identical assistant messages trip the loop guard (strongest signal; also used for streamed intra-message repetition). */
78
78
  loopRepeatText?: number;
79
79
  /** Text sent after the loop guard cancels and restarts a turn (supports {tool}). */
80
80
  loopText?: string;
@@ -152,21 +152,92 @@ export interface ToolResultFacts {
152
152
  ok: boolean;
153
153
  /** 工具输出的文本摘要(截断)。 */
154
154
  excerpt: string;
155
+ /** 完整模型可见内容 + 错误状态的定长稳定指纹(loop guard 比较用)。 */
156
+ identity: string;
155
157
  }
156
- /** 从 tool/result 事件载荷提取成功与否与文本摘要。 */
157
- export declare function toolResultFacts(data: {
158
+ interface ToolResultData {
159
+ turn?: unknown;
160
+ step?: unknown;
158
161
  error?: {
159
162
  name?: string;
160
163
  code?: string;
161
164
  };
162
165
  message?: {
166
+ source?: {
167
+ kind?: string;
168
+ callId?: unknown;
169
+ };
163
170
  content?: Array<{
164
171
  type?: string;
172
+ toolCallId?: unknown;
165
173
  content?: unknown;
166
174
  isError?: boolean;
167
175
  }>;
168
176
  };
169
- }): ToolResultFacts;
177
+ }
178
+ /**
179
+ * 取工具结果的关联 id。新版 DSH 的权威位置是 message.source.callId,
180
+ * 同时接受模型可见 block 上的 toolCallId;两者冲突时宁可忽略,不猜测配对。
181
+ */
182
+ export declare function toolResultCallId(data: ToolResultData): string | undefined;
183
+ /** 从 tool/result 事件载荷提取成功与否与文本摘要。 */
184
+ export declare function toolResultFacts(data: ToolResultData): ToolResultFacts;
185
+ /** loop guard 在后续 step 边界确认的连续重复信号。 */
186
+ export interface ToolRepeatSignal {
187
+ tool: string;
188
+ count: number;
189
+ }
190
+ export type ToolGuardState = {
191
+ kind: 'none';
192
+ } | {
193
+ kind: 'pending';
194
+ tool: string;
195
+ } | {
196
+ kind: 'done';
197
+ tool: string;
198
+ result: string;
199
+ } | {
200
+ kind: 'failed';
201
+ tool: string;
202
+ };
203
+ /**
204
+ * 每个会话的工具调用关联器。
205
+ *
206
+ * 集中封装事件关联、step 边界确认、护栏读取与重置。内部按 callId 配对,
207
+ * 乱序结果先缓存、再按调用顺序推进 loop 计数。队列和去重 id 都有硬上限;
208
+ * 超限或载荷无法关联时会打断重复计数,宁可漏报也不误杀健康回合。
209
+ */
210
+ export declare class ToolInvocationTracker {
211
+ private readonly pendingById;
212
+ private readonly pendingInOrder;
213
+ private readonly seenCalls;
214
+ private readonly seenInOrder;
215
+ private latest;
216
+ private run;
217
+ private repeatSignal;
218
+ private lastEventSeq;
219
+ reset(): void;
220
+ /** 新回合边界:清空工具态,同时把重放水位推进到 turn/start。 */
221
+ startTurn(seq: number): void;
222
+ /** 回合已结束:保留最后一次调用的护栏,丢弃不再可用的 loop 关联态。 */
223
+ resetRepeat(): void;
224
+ recordCall(event: SessionEvent<'tool/call'>): boolean;
225
+ recordResult(event: SessionEvent<'tool/result'>): ToolRepeatSignal | undefined;
226
+ guard(): ToolGuardState;
227
+ lastTool(): string | undefined;
228
+ /** 下一模型 step 是稳定边界;此前 replacement/新调用会先清除候选。 */
229
+ confirmRepeatAtStep(seq: number): ToolRepeatSignal | undefined;
230
+ /** 非工具 surface range replacement(如 compaction summary)同样终止旧工具证据。 */
231
+ recordSurfaceReplacement(seq: number): void;
232
+ restore(events: readonly SessionEvent[], untilSeq: number): void;
233
+ private acceptEventSeq;
234
+ private breakCorrelation;
235
+ private invalidateRunHistory;
236
+ private trim;
237
+ private drainCompleted;
238
+ private advanceRun;
239
+ private refreshRepeatSignal;
240
+ }
170
241
  /** 自适应退避: 同一会话连续失败时的有效冷却间隔。 */
171
242
  export declare function effectiveCooldown(consecutive: number, base: number, factor: number, max: number): number;
172
243
  export declare function sleep(ms: number): Promise<void>;
@@ -196,12 +267,10 @@ export declare function emptyDayStats(): DayStats;
196
267
  export interface SessionState {
197
268
  /** 连续自动「继续」次数; 成功回合或用户手动介入后归零。 */
198
269
  consecutive: number;
199
- /** 上次自动「继续」时间戳。 */
200
- lastAutoAt: number;
201
270
  /** 上次自动「继续」尝试(成功或失败)时间戳; 防止失败场景下的快速重试循环。 */
202
271
  lastAttemptAt: number;
203
- /** 我们上次自动发送的文本(用于识别自己的回显)。 */
204
- lastSentText: string;
272
+ /** 尚未回显到会话事件流的自动发送消息 ID。 */
273
+ pendingEchoMessageIds: Map<string, number>;
205
274
  /** 宽限期定时器(进行中的待发送)。 */
206
275
  pendingTimer: ReturnType<typeof setTimeout> | undefined;
207
276
  /** 宿主权威 running 位(来自 host/session-status 与回合事件)。 */
@@ -214,10 +283,8 @@ export interface SessionState {
214
283
  lastFailure: FailureFacts | undefined;
215
284
  /** 最近一次失败的发生时间(模板 {elapsed} 与恢复统计用)。 */
216
285
  lastFailureAt: number;
217
- /** 失败前最后一次工具调用的名称(模板 {tool} 与幂等护栏用)。 */
218
- lastTool: string | undefined;
219
- /** 上一步工具调用的结果状态: 'pending' = 已发起未见结果(可能已部分执行)。 */
220
- lastToolResult: 'pending' | ToolResultFacts | undefined;
286
+ /** callId 精确配对的工具调用、幂等护栏与 loop 重复态。 */
287
+ tools: ToolInvocationTracker;
221
288
  /** 失败回合的编号(模板 {turn})。 */
222
289
  lastTurn: number | undefined;
223
290
  /** 我们最近一次自动发送的时间戳; 0 = 没有待确认的恢复。 */
@@ -230,29 +297,24 @@ export interface SessionState {
230
297
  lastAssistantText: string;
231
298
  /** 连续相同文本消息数(最强空转信号, 不限长度)。 */
232
299
  sameTextRun: number;
233
- /**
234
- * 工具重复信号(loop guard 信号 2: 死循环)。
235
- * 只有「同工具 + 同参数 + 同结果」的连续调用才累计; 参数或结果有变化视为有进展, 计数重置。
236
- */
237
- toolRun: {
238
- /** 工具名 + 参数(用于判定是否同一调用)。 */
239
- key: string;
240
- /** 连续相同调用数(结果确认后更新)。 */
241
- count: number;
242
- /** 上次该调用的结果摘要(比较用)。 */
243
- lastResult: string | undefined;
244
- /** 本次调用等待结果确认。 */
245
- waiting: boolean;
246
- } | undefined;
300
+ /** 流式消息尚未闭合的有界尾段(assistant/chunk 增量分段检测用)。 */
301
+ streamTail: string;
302
+ /** 流式消息最近一个长段的归一化文本。 */
303
+ streamLastSegment: string;
304
+ /** 流式消息内连续近似重复长段计数。 */
305
+ streamRepeatRun: number;
247
306
  /** 本回合已触发过 loop guard(防重复打断)。 */
248
307
  loopFired: boolean;
249
308
  /** loop 重启的延迟定时器(冷却结束后再 schedule)。 */
250
309
  loopRetryTimer: ReturnType<typeof setTimeout> | undefined;
251
- /** 我们主动 cancel 过本回合(区分用户停止)。 */
252
- loopCancelled: boolean;
253
310
  }
254
311
  export declare const freshState: () => SessionState;
255
312
  export declare const RECOVERY_WINDOW_MS: number;
256
313
  export declare const ECHO_WINDOW_MS: number;
314
+ /** Track an identified plugin message before handing it to the host queue. */
315
+ export declare function trackPendingEcho(state: SessionState, messageId: string): void;
316
+ /** Roll back tracking when the host rejects a queued message. */
317
+ export declare function forgetPendingEcho(state: SessionState, messageId: string): void;
318
+ /** Match and consume one plugin-owned `user/message` event by stable message ID. */
257
319
  export declare function isOurEcho(state: SessionState, event: SessionEvent): boolean;
258
320
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-client-auto-continue",
3
3
  "description": "DSH Web UI plugin: automatically sends a localized continue prompt when a request is interrupted by network errors or other non-human causes",
4
- "version": "0.11.3",
4
+ "version": "0.11.5",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/types/index.d.ts",
@@ -73,7 +73,7 @@ export const zh = {
73
73
  'stats.gaveUp': '停止(达上限)',
74
74
  'stats.looped': '循环打断',
75
75
  'field.loopGuard': '循环守卫',
76
- 'field.loopGuardHint': '检测运行中的回合空转: 连续短句且无工具调用, 或连续调用相同工具时, 自动取消并用循环提示文本重启回合。',
76
+ 'field.loopGuardHint': '检测运行中的回合空转: 连续短句且无工具调用、流式消息内连续复读, 或连续调用相同工具时, 自动取消并用循环提示文本重启回合。',
77
77
  'field.loopShortChars': '短句长度上限 (字符)',
78
78
  'field.loopShortCharsHint': '模型消息文本短于该值计为一条短句(空转信号)。',
79
79
  'field.loopWindowMs': '短句时间窗 (ms)',
@@ -81,7 +81,7 @@ export const zh = {
81
81
  'field.loopShortCount': '连续短句阈值',
82
82
  'field.loopShortCountHint': '时间窗内连续多少条短句且期间无工具调用时判定空转循环。',
83
83
  'field.loopRepeatText': '相同消息重复次数',
84
- 'field.loopRepeatTextHint': '连续输出多少条完全相同的消息时判定空转(最强信号, 不限长度, 如模型反复说同一句话)。',
84
+ 'field.loopRepeatTextHint': '连续输出多少条完全相同的消息时判定空转(最强信号, 不限长度, 也用于流式消息内连续复读段落)。',
85
85
  'field.loopToolRepeat': '同工具重复次数',
86
86
  'field.loopToolRepeatHint': '同工具+同参数+同结果的连续调用多少次时判定死循环; 参数或结果有变化视为有进展。',
87
87
  'field.loopText': '循环提示文本',
@@ -182,7 +182,7 @@ export const en: Record<SettingsCardKey, string> = {
182
182
  'stats.gaveUp': 'Gave up (cap)',
183
183
  'stats.looped': 'Loops broken',
184
184
  'field.loopGuard': 'Loop guard',
185
- 'field.loopGuardHint': 'Detects a running turn spinning in place — many short sentences with no tool calls, or the same tool repeating — cancels it and restarts with the loop text.',
185
+ 'field.loopGuardHint': 'Detects a running turn spinning in place — many short sentences with no tool calls, repeated paragraphs inside one streamed assistant message, or the same tool repeating — then cancels and restarts with the loop text.',
186
186
  'field.loopShortChars': 'Short-sentence max (chars)',
187
187
  'field.loopShortCharsHint': 'A model message shorter than this counts as a short sentence (spinning signal).',
188
188
  'field.loopWindowMs': 'Short-sentence window (ms)',
@@ -190,7 +190,7 @@ export const en: Record<SettingsCardKey, string> = {
190
190
  'field.loopShortCount': 'Short-sentence threshold',
191
191
  'field.loopShortCountHint': 'How many consecutive short sentences inside the window, with no tool call, trip the loop guard.',
192
192
  'field.loopRepeatText': 'Identical message count',
193
- 'field.loopRepeatTextHint': 'How many consecutive identical messages trip the guard (strongest signal, any length, e.g. the model repeating the same line).',
193
+ 'field.loopRepeatTextHint': 'How many consecutive identical messages trip the guard (strongest signal, any length; also used for repeated paragraphs inside one streamed assistant message).',
194
194
  'field.loopToolRepeat': 'Same-tool repeat count',
195
195
  'field.loopToolRepeatHint': 'How many consecutive calls of the same tool with identical arguments and results trip the loop guard; a changed argument or result counts as progress.',
196
196
  'field.loopText': 'Loop text',