dsh-client-auto-continue 0.7.1 → 0.7.3

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/README.md CHANGED
@@ -43,7 +43,7 @@ For [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (`dsh we
43
43
  - **Idempotency guard** — before resuming, the plugin inspects the last tool call: if its result is unconfirmed (the turn died mid-tool, e.g. a `git push` that may have gone through), the resume message tells the model to check state first and not to rerun; if the tool is confirmed done, it says so and asks not to repeat it; a failed tool gets no guard (retrying it is the point). Both guard texts are configurable (`{tool}` / `{result}` placeholders)
44
44
  - **Pause** — a global **Pause auto-continue** toggle in the settings card stops everything (live + scan) instantly; per-session pauses (e.g. via a notification button) suspend only one session until they expire. The **Resume now** notification button is the one explicit exception: pressing it is the user asking for exactly one send, pause or not
45
45
  - **Notification buttons** — notifications carry **Resume now** (send immediately, ignoring cooldown, the consecutive cap and any pause) and **Pause this session 1h** actions
46
- - **Loop guard** — watches **running** turns too: many consecutive short model messages with no tool call in between (the "Let me read…" spin), or the same tool called repeatedly, trips the guard, which cancels the turn and restarts it with a configurable loop text ("stop repeating, try another way"). The cancel carries an internal marker so it is never confused with a user stop — the restart only happens for guard-initiated cancels. Thresholds and the loop text are configurable
46
+ - **Loop guard** — watches **running** turns too. Three signals trip the guard, which cancels the turn and restarts it with a configurable loop text ("stop repeating, try another way"): the model repeating the **exact same message** several times (any length — e.g. "Let me test variants of the regex…" ×7), many short messages inside a short time window with no tool call in between (the "Let me read…" spin), or the same tool called repeatedly with the **same arguments and the same results** (a changed argument or result counts as progress). The cancel carries an internal marker so it is never confused with a user stop — the restart only happens for guard-initiated cancels. Thresholds, the time window and the loop text are configurable
47
47
  - **Stats panel** — the settings card shows today's auto-continue count, recoveries, failures, permanent skips, give-ups and loop breaks, broken down by error code, with a one-click reset
48
48
  - **Browser notifications** — optional alerts when auto-continue fires, gives up, or hits a permanent error; the browser asks for permission on first use, and nothing is shown again after a denial
49
49
 
@@ -175,8 +175,10 @@ auto-continue:
175
175
  notify: false
176
176
  loopGuard: true
177
177
  loopShortChars: 40
178
- loopShortCount: 8
179
- loopToolRepeat: 4
178
+ loopWindowMs: 30000
179
+ loopShortCount: 12
180
+ loopRepeatText: 4
181
+ loopToolRepeat: 5
180
182
  loopText: '(检测到你可能陷入循环, 请停止重复刚才的动作, 换一种方式继续)'
181
183
  ```
182
184
 
@@ -199,8 +201,10 @@ auto-continue:
199
201
  | Idempotency guard | `on` | Inspect the last tool call before resuming and steer the model (see What It Does) |
200
202
  | Loop guard | `on` | Detect a running turn spinning in place and restart it (see What It Does) |
201
203
  | Short-sentence max (chars) | `40` | A model message shorter than this counts as a short sentence (spinning signal) |
202
- | Short-sentence threshold | `8` | Consecutive short sentences with no tool call in between trip the loop guard |
203
- | Same-tool repeat count | `4` | Consecutive identical tool calls trip the loop guard |
204
+ | Short-sentence window (ms) | `30000` | Consecutive short sentences must land inside this window; normal thinking spread over time is not misjudged |
205
+ | Short-sentence threshold | `12` | Consecutive short sentences inside the window, with no tool call in between, trip the loop guard |
206
+ | Identical message count | `4` | Consecutive identical messages (any length) trip the loop guard — the strongest spinning signal |
207
+ | Same-tool repeat count | `5` | Consecutive calls of the same tool with identical arguments and results trip the loop guard |
204
208
  | Loop text | `(检测到你可能陷入循环, 请停止重复刚才的动作, 换一种方式继续)` | Text sent after the loop guard restarts a turn; `{tool}` placeholder |
205
209
  | Guard text (unconfirmed result) | `(上一步工具「{tool}」可能未完成, 先确认状态再继续, 不要重复执行)` | Appended when the last tool may have partially executed; `{tool}` placeholder |
206
210
  | Guard text (tool succeeded) | `(上一步工具「{tool}」已完成, 结果: {result}; 不要重复执行, 直接继续)` | Appended when the last tool is confirmed done; `{tool}` / `{result}` placeholders |
@@ -239,7 +243,7 @@ The plugin is browser-only and touches **no files, credentials, or network beyon
239
243
  npm run typecheck # tsc --noEmit
240
244
  npm run build # lib/client.js + lib/index.js + lib/types
241
245
  npm run watch # rebuild on change; host HMR hot-reloads without a page refresh
242
- npm run test # node tests/simulate.mjs — 34 behavioral scenarios
246
+ npm run test # node tests/simulate.mjs — 38 behavioral scenarios
243
247
  ```
244
248
 
245
249
  While `npm run watch` runs, the profile's client-hmr row polls `lib/client.js` every 500 ms and hot-reloads the plugin in the browser — no server restart needed for code changes.
package/README.zh.md CHANGED
@@ -43,7 +43,7 @@
43
43
  - **幂等护栏** — 续跑前检查上一步工具调用: 结果未确认(回合在工具执行中途夭折, 如 `git push` 可能已经推上去了)时, 续跑消息会提示模型先确认状态、不要重复执行; 工具已确认成功时说明已完成、请勿重复; 工具失败则不加护栏(重试本来就是目的)。两段护栏文本都可配置(支持 `{tool}` / `{result}` 占位符)
44
44
  - **暂停** — 设置卡片里的全局 **暂停自动继续** 开关可立即停掉一切(实时 + 扫描); 会话级暂停(如通过通知按钮)只挂起单个会话, 到期自动恢复。唯一的显式例外是通知里的 **立即续跑** 按钮——按下它等于用户明确要求发送这一次, 不受暂停限制
45
45
  - **通知按钮** — 通知带 **立即续跑**(无视冷却、连续上限与暂停, 马上发送)和 **暂停该会话 1 小时** 按钮
46
- - **循环守卫** — 连**运行中的回合**也盯着: 连续多条短句且期间无工具调用(典型的「Let me read…」空转), 或同一工具被连续反复调用, 都会触发守卫: 取消当前回合并用可配置的循环提示文本重启(「停止重复, 换一种方式」)。取消带有内部来源标记, 绝不会与用户手动停止混淆——只有守卫发起的取消才会重启。阈值与提示文本都可配置
46
+ - **循环守卫** — 连**运行中的回合**也盯着, 三个信号都会触发守卫(取消当前回合并用可配置的循环提示文本重启, 「停止重复, 换一种方式」): 模型**连续输出完全相同的消息**(不限长度, 如 "Let me test variants of the regex…" 连续 7 遍)、短时间内连续多条短句且期间无工具调用(典型的「Let me read…」空转)、或同一工具被连续反复调用且**参数与结果都相同**(参数或结果有变化视为有进展)。取消带有内部来源标记, 绝不会与用户手动停止混淆——只有守卫发起的取消才会重启。阈值、时间窗与提示文本都可配置
47
47
  - **统计面板** — 设置卡片展示今日自动继续次数、恢复成功、继续后失败、永久性跳过、达上限停止、循环打断, 按错误码统计, 可一键清零
48
48
  - **浏览器通知** — 可选: 自动继续成功 / 放弃 / 遇到永久性错误时弹出提醒; 首次使用时请求权限, 被拒绝后不再打扰
49
49
 
@@ -175,8 +175,10 @@ auto-continue:
175
175
  notify: false
176
176
  loopGuard: true
177
177
  loopShortChars: 40
178
- loopShortCount: 8
179
- loopToolRepeat: 4
178
+ loopWindowMs: 30000
179
+ loopShortCount: 12
180
+ loopRepeatText: 4
181
+ loopToolRepeat: 5
180
182
  loopText: '(检测到你可能陷入循环, 请停止重复刚才的动作, 换一种方式继续)'
181
183
  ```
182
184
 
@@ -199,8 +201,10 @@ auto-continue:
199
201
  | 幂等护栏 | 开 | 续跑前检查上一步工具调用并给出指引(见「它做什么」) |
200
202
  | 循环守卫 | 开 | 检测运行中的回合空转并重启(见「它做什么」) |
201
203
  | 短句长度上限 (字符) | `40` | 模型消息文本短于该值计为一条短句(空转信号) |
202
- | 连续短句阈值 | `8` | 连续多少条短句且期间无工具调用时判定空转循环 |
203
- | 相同工具连续次数 | `4` | 连续调用同一工具多少次时判定死循环 |
204
+ | 短句时间窗 (ms) | `30000` | 连续短句必须落在这个时间窗内; 正常思考的短文本散布在长时间里不会被误判 |
205
+ | 连续短句阈值 | `12` | 时间窗内连续多少条短句且期间无工具调用时判定空转循环 |
206
+ | 相同消息重复次数 | `4` | 连续输出多少条完全相同的消息时判定空转(不限长度, 最强信号) |
207
+ | 同工具重复次数 | `5` | 同工具+同参数+同结果的连续调用多少次时判定死循环 |
204
208
  | 循环提示文本 | `(检测到你可能陷入循环, 请停止重复刚才的动作, 换一种方式继续)` | 打断后重启回合时发送的文本; 支持 {tool} 占位符 |
205
209
  | 结果未确认时的护栏文本 | `(上一步工具「{tool}」可能未完成, 先确认状态再继续, 不要重复执行)` | 上一步工具可能已部分执行时附加; 支持 {tool} 占位符 |
206
210
  | 工具已成功时的护栏文本 | `(上一步工具「{tool}」已完成, 结果: {result}; 不要重复执行, 直接继续)` | 上一步工具已确认成功时附加; 支持 {tool} / {result} 占位符 |
@@ -239,7 +243,7 @@ auto-continue:
239
243
  npm run typecheck # tsc --noEmit
240
244
  npm run build # lib/client.js + lib/index.js + lib/types
241
245
  npm run watch # 监听变更自动重建; 宿主 HMR 免刷新热重载
242
- npm run test # node tests/simulate.mjs — 34 个行为场景
246
+ npm run test # node tests/simulate.mjs — 38 个行为场景
243
247
  ```
244
248
 
245
249
  `npm run watch` 运行时, profile 的 client-hmr 行每 500ms 轮询 `lib/client.js` 并在浏览器中热重载插件——改代码无需重启服务。
package/lib/client.js CHANGED
@@ -61,8 +61,10 @@ var DEFAULT_CONFIG = {
61
61
  paused: false,
62
62
  loopGuard: true,
63
63
  loopShortChars: 40,
64
- loopShortCount: 8,
65
- loopToolRepeat: 4,
64
+ loopWindowMs: 3e4,
65
+ loopShortCount: 12,
66
+ loopRepeatText: 4,
67
+ loopToolRepeat: 5,
66
68
  loopText: "(检测到你可能陷入循环, 请停止重复刚才的动作, 换一种方式继续)"
67
69
  };
68
70
  function numberOr(value, fallback) {
@@ -99,7 +101,9 @@ function resolveConfig(section) {
99
101
  paused: booleanOr(value.paused, DEFAULT_CONFIG.paused),
100
102
  loopGuard: booleanOr(value.loopGuard, DEFAULT_CONFIG.loopGuard),
101
103
  loopShortChars: Math.max(1, numberOr(value.loopShortChars, DEFAULT_CONFIG.loopShortChars)),
104
+ loopWindowMs: Math.max(1e3, numberOr(value.loopWindowMs, DEFAULT_CONFIG.loopWindowMs)),
102
105
  loopShortCount: Math.max(2, numberOr(value.loopShortCount, DEFAULT_CONFIG.loopShortCount)),
106
+ loopRepeatText: Math.max(2, numberOr(value.loopRepeatText, DEFAULT_CONFIG.loopRepeatText)),
103
107
  loopToolRepeat: Math.max(2, numberOr(value.loopToolRepeat, DEFAULT_CONFIG.loopToolRepeat)),
104
108
  loopText: typeof value.loopText === "string" && value.loopText.trim() !== "" ? value.loopText : DEFAULT_CONFIG.loopText
105
109
  };
@@ -331,6 +335,9 @@ var freshState = () => ({
331
335
  lastTurn: void 0,
332
336
  pendingRecoveryAt: 0,
333
337
  shortRun: 0,
338
+ lastShortAt: 0,
339
+ lastAssistantText: "",
340
+ sameTextRun: 0,
334
341
  toolRun: void 0,
335
342
  loopFired: false,
336
343
  loopCancelled: false
@@ -445,17 +452,32 @@ var AutoContinueRunner = class {
445
452
  state.lastTool = name;
446
453
  state.lastToolResult = "pending";
447
454
  state.shortRun = 0;
448
- if (state.toolRun?.name === name) {
449
- state.toolRun.count += 1;
455
+ const key = `${name}
456
+ ${frame.event.data.arguments}`;
457
+ if (state.toolRun?.key === key) {
458
+ state.toolRun.waiting = true;
450
459
  } else {
451
- state.toolRun = { name, count: 1 };
460
+ state.toolRun = { key, count: 1, lastResult: void 0, waiting: false };
452
461
  }
453
- this.checkLoop(frame.sessionId, state);
454
462
  }
455
463
  } else if (frame.event.type === "tool/result") {
456
464
  const state = this.state(frame.sessionId);
457
465
  if (state.lastToolResult === "pending") {
458
- state.lastToolResult = toolResultFacts(frame.event.data);
466
+ const facts = toolResultFacts(frame.event.data);
467
+ state.lastToolResult = facts;
468
+ const run = state.toolRun;
469
+ if (run !== void 0 && run.waiting) {
470
+ run.waiting = false;
471
+ if (run.lastResult !== void 0 && run.lastResult === facts.excerpt) {
472
+ run.count += 1;
473
+ this.checkLoop(frame.sessionId, state);
474
+ } else {
475
+ run.lastResult = facts.excerpt;
476
+ run.count = 1;
477
+ }
478
+ } else if (run !== void 0 && !run.waiting) {
479
+ run.lastResult = facts.excerpt;
480
+ }
459
481
  }
460
482
  } else if (frame.event.type === "assistant/message") {
461
483
  const state = this.state(frame.sessionId);
@@ -481,16 +503,30 @@ var AutoContinueRunner = class {
481
503
  return content.filter((part) => part.type === "text").map((part) => part.text).join("");
482
504
  }
483
505
  /**
484
- * loop guard 信号 1(空转): 连续短句且期间无工具调用。
485
- * 短句 = 模型消息文本短于 loopShortChars; 长句或工具调用都会重置计数。
506
+ * loop guard 信号 1(空转): 时间窗内连续短句且期间无工具调用。
507
+ * 短句 = 模型消息文本短于 loopShortChars; 长句、工具调用、或短句间隔超过
508
+ * loopWindowMs(正常思考的短文本散布在长时间里)都会重置计数。
486
509
  */
487
510
  onAssistantMessage(sessionId, state, event) {
488
511
  if (!this.getConfig().loopGuard) return;
489
512
  const text = this.assistantText(event);
490
- if (text.trim().length < this.getConfig().loopShortChars) {
513
+ const trimmed = text.trim();
514
+ if (trimmed !== "" && trimmed === state.lastAssistantText) {
515
+ state.sameTextRun += 1;
516
+ } else {
517
+ state.lastAssistantText = trimmed;
518
+ state.sameTextRun = 1;
519
+ }
520
+ if (trimmed.length < this.getConfig().loopShortChars) {
521
+ const now = Date.now();
522
+ if (now - state.lastShortAt > this.getConfig().loopWindowMs) {
523
+ state.shortRun = 0;
524
+ }
491
525
  state.shortRun += 1;
526
+ state.lastShortAt = now;
492
527
  } else {
493
528
  state.shortRun = 0;
529
+ state.lastShortAt = 0;
494
530
  }
495
531
  this.checkLoop(sessionId, state);
496
532
  }
@@ -500,11 +536,15 @@ var AutoContinueRunner = class {
500
536
  if (state.loopFired) return;
501
537
  if (!state.running) return;
502
538
  const config = this.getConfig();
503
- if (state.shortRun >= config.loopShortCount) {
539
+ if (state.sameTextRun >= config.loopRepeatText) {
540
+ this.log(`检测到空转循环 ${sessionId}: 连续 ${state.sameTextRun} 条相同消息`);
541
+ void this.interruptLoop(sessionId, state);
542
+ } else if (state.shortRun >= config.loopShortCount) {
504
543
  this.log(`检测到空转循环 ${sessionId}: 连续 ${state.shortRun} 条短句且无工具调用`);
505
544
  void this.interruptLoop(sessionId, state);
506
545
  } else if (state.toolRun !== void 0 && state.toolRun.count >= config.loopToolRepeat) {
507
- this.log(`检测到工具死循环 ${sessionId}: 「${state.toolRun.name}」连续 ${state.toolRun.count} 次`);
546
+ const toolName = state.toolRun.key.split("\n")[0] ?? "?";
547
+ this.log(`检测到工具死循环 ${sessionId}: 「${toolName}」连续 ${state.toolRun.count} 次(同参数同结果)`);
508
548
  void this.interruptLoop(sessionId, state);
509
549
  }
510
550
  }
@@ -541,6 +581,9 @@ var AutoContinueRunner = class {
541
581
  state.lastTool = void 0;
542
582
  state.lastToolResult = void 0;
543
583
  state.shortRun = 0;
584
+ state.lastShortAt = 0;
585
+ state.lastAssistantText = "";
586
+ state.sameTextRun = 0;
544
587
  state.toolRun = void 0;
545
588
  state.loopFired = false;
546
589
  state.loopCancelled = false;
@@ -561,6 +604,9 @@ var AutoContinueRunner = class {
561
604
  state.consecutive = 0;
562
605
  state.pendingRecoveryAt = 0;
563
606
  state.shortRun = 0;
607
+ state.lastShortAt = 0;
608
+ state.lastAssistantText = "";
609
+ state.sameTextRun = 0;
564
610
  state.toolRun = void 0;
565
611
  state.lastAttemptAt = 0;
566
612
  this.schedule(sessionId, "loop:aborted");
@@ -1050,10 +1096,14 @@ var zh = {
1050
1096
  "field.loopGuardHint": "检测运行中的回合空转: 连续短句且无工具调用, 或连续调用相同工具时, 自动取消并用循环提示文本重启回合。",
1051
1097
  "field.loopShortChars": "短句长度上限 (字符)",
1052
1098
  "field.loopShortCharsHint": "模型消息文本短于该值计为一条短句(空转信号)。",
1099
+ "field.loopWindowMs": "短句时间窗 (ms)",
1100
+ "field.loopWindowMsHint": "连续短句必须落在这个时间窗内; 正常思考的短文本散布在长时间里不会被误判。",
1053
1101
  "field.loopShortCount": "连续短句阈值",
1054
- "field.loopShortCountHint": "连续多少条短句且期间无工具调用时判定空转循环。",
1055
- "field.loopToolRepeat": "相同工具连续次数",
1056
- "field.loopToolRepeatHint": "连续调用同一工具多少次时判定死循环。",
1102
+ "field.loopShortCountHint": "时间窗内连续多少条短句且期间无工具调用时判定空转循环。",
1103
+ "field.loopRepeatText": "相同消息重复次数",
1104
+ "field.loopRepeatTextHint": "连续输出多少条完全相同的消息时判定空转(最强信号, 不限长度, 如模型反复说同一句话)。",
1105
+ "field.loopToolRepeat": "同工具重复次数",
1106
+ "field.loopToolRepeatHint": "同工具+同参数+同结果的连续调用多少次时判定死循环; 参数或结果有变化视为有进展。",
1057
1107
  "field.loopText": "循环提示文本",
1058
1108
  "field.loopTextHint": "打断后重启回合时发送的文本, 支持 {tool} 占位符。",
1059
1109
  "stats.byCode": "按错误码统计",
@@ -1131,10 +1181,14 @@ var en = {
1131
1181
  "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.",
1132
1182
  "field.loopShortChars": "Short-sentence max (chars)",
1133
1183
  "field.loopShortCharsHint": "A model message shorter than this counts as a short sentence (spinning signal).",
1184
+ "field.loopWindowMs": "Short-sentence window (ms)",
1185
+ "field.loopWindowMsHint": "Consecutive short sentences must land inside this window; normal thinking spread over time is not misjudged.",
1134
1186
  "field.loopShortCount": "Short-sentence threshold",
1135
- "field.loopShortCountHint": "How many consecutive short sentences with no tool call trip the loop guard.",
1187
+ "field.loopShortCountHint": "How many consecutive short sentences inside the window, with no tool call, trip the loop guard.",
1188
+ "field.loopRepeatText": "Identical message count",
1189
+ "field.loopRepeatTextHint": "How many consecutive identical messages trip the guard (strongest signal, any length, e.g. the model repeating the same line).",
1136
1190
  "field.loopToolRepeat": "Same-tool repeat count",
1137
- "field.loopToolRepeatHint": "How many consecutive identical tool calls trip the loop guard.",
1191
+ "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.",
1138
1192
  "field.loopText": "Loop text",
1139
1193
  "field.loopTextHint": "Text sent after the loop guard restarts a turn; supports the {tool} placeholder.",
1140
1194
  "stats.byCode": "By error code",
@@ -1544,7 +1598,9 @@ var AutoContinueSettingsCardController = class {
1544
1598
  booleanField("notify"),
1545
1599
  booleanField("loopGuard"),
1546
1600
  numberField("loopShortChars", 1),
1601
+ numberField("loopWindowMs", 1e3),
1547
1602
  numberField("loopShortCount", 2),
1603
+ numberField("loopRepeatText", 2),
1548
1604
  numberField("loopToolRepeat", 2),
1549
1605
  textField("loopText")
1550
1606
  ]);
@@ -1574,7 +1630,9 @@ var AutoContinueSettingsCardController = class {
1574
1630
  notify: this.form.field("notify"),
1575
1631
  loopGuard: this.form.field("loopGuard"),
1576
1632
  loopShortChars: this.form.field("loopShortChars"),
1633
+ loopWindowMs: this.form.field("loopWindowMs"),
1577
1634
  loopShortCount: this.form.field("loopShortCount"),
1635
+ loopRepeatText: this.form.field("loopRepeatText"),
1578
1636
  loopToolRepeat: this.form.field("loopToolRepeat"),
1579
1637
  loopText: this.form.field("loopText")
1580
1638
  };
@@ -2077,6 +2135,19 @@ function AutoContinueSettingsCard(props) {
2077
2135
  onReset: () => props.resetField("loopShortChars")
2078
2136
  }
2079
2137
  ),
2138
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
2139
+ ValueField,
2140
+ {
2141
+ id: "auto-continue-loop-window-ms",
2142
+ label: t("field.loopWindowMs"),
2143
+ hint: t("field.loopWindowMsHint"),
2144
+ numeric: true,
2145
+ ...shared,
2146
+ ...state.loopWindowMs,
2147
+ onEdit: (text) => props.edit("loopWindowMs", text),
2148
+ onReset: () => props.resetField("loopWindowMs")
2149
+ }
2150
+ ),
2080
2151
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
2081
2152
  ValueField,
2082
2153
  {
@@ -2103,6 +2174,19 @@ function AutoContinueSettingsCard(props) {
2103
2174
  onReset: () => props.resetField("loopToolRepeat")
2104
2175
  }
2105
2176
  ),
2177
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
2178
+ ValueField,
2179
+ {
2180
+ id: "auto-continue-loop-repeat-text",
2181
+ label: t("field.loopRepeatText"),
2182
+ hint: t("field.loopRepeatTextHint"),
2183
+ numeric: true,
2184
+ ...shared,
2185
+ ...state.loopRepeatText,
2186
+ onEdit: (text) => props.edit("loopRepeatText", text),
2187
+ onReset: () => props.resetField("loopRepeatText")
2188
+ }
2189
+ ),
2106
2190
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
2107
2191
  ValueField,
2108
2192
  {