dsh-client-auto-continue 0.12.0 → 0.12.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/lib/index.js CHANGED
@@ -631,6 +631,7 @@ var LOOP_GUARD_CANCEL_CAUSE = {
631
631
  };
632
632
  var LOOP_COMPLETED_REASON = "turn/end:completed";
633
633
  var LOOP_SILENT_REASON = "turn/end:loop-silent";
634
+ var MANUAL_NOTIFICATION_REASON = "manual:notification";
634
635
  var isLoopReason = (reason) => reason === LOOP_COMPLETED_REASON || reason === LOOP_SILENT_REASON;
635
636
  var STREAM_NEAR_DUPLICATE_MAX_CHARS = 2048;
636
637
  var STREAM_TAIL_MAX_CHARS = 4096;
@@ -798,12 +799,31 @@ var AutoContinueRunner = class {
798
799
  }
799
800
  return state;
800
801
  }
802
+ /** Mark a child session and clear queued grace/cooldown sends. */
803
+ markSubagent(sessionId, state) {
804
+ state.subagent = true;
805
+ this.cancelPending(sessionId, "子代理会话");
806
+ }
807
+ /** Read durable origin from the live agent for direct action paths as well. */
808
+ isSubagent(sessionId, state) {
809
+ if (state.subagent) return true;
810
+ const agent = this.ctx.agents.get(sessionId);
811
+ if (agent?.session?.header?.origin !== "subagent") return false;
812
+ this.markSubagent(sessionId, state);
813
+ return true;
814
+ }
801
815
  /**
802
816
  * 事件入口(host 单实例): 预处理工具调用/结果/模型消息(护栏与循环信号),
803
817
  * 然后交给回合状态机。
804
818
  */
805
819
  onHostEvent(session, event) {
806
820
  const sessionId = session.id;
821
+ const sessionState = this.states.get(sessionId);
822
+ if (session.header?.origin === "subagent") {
823
+ this.markSubagent(sessionId, sessionState ?? this.state(sessionId));
824
+ return;
825
+ }
826
+ if (sessionState?.subagent) return;
807
827
  if ((event.type === "user/message" || event.type === "assistant/message") && typeof event.surfaceOp === "object" && event.surfaceOp !== null) {
808
828
  this.state(sessionId).tools.recordSurfaceReplacement(event.seq);
809
829
  return;
@@ -1004,6 +1024,7 @@ var AutoContinueRunner = class {
1004
1024
  * 才会用 loopText 重启回合——DSH 的 first-cause 语义保证用户 Stop 优先。
1005
1025
  */
1006
1026
  interruptLoop(sessionId, state) {
1027
+ if (this.isSubagent(sessionId, state)) return;
1007
1028
  if (state.loopFired) return;
1008
1029
  if (Date.now() - state.lastAttemptAt < this.cooldownFor(state)) {
1009
1030
  this.log(`跳过循环打断 ${sessionId}: 处于冷却期`);
@@ -1238,13 +1259,13 @@ var AutoContinueRunner = class {
1238
1259
  async resumeNow(sessionId) {
1239
1260
  if (this.disposed) return;
1240
1261
  const state = this.state(sessionId);
1241
- if (state.subagent) return;
1262
+ if (this.isSubagent(sessionId, state)) return;
1242
1263
  if (state.pendingTimer !== void 0) {
1243
1264
  clearTimeout(state.pendingTimer);
1244
1265
  state.pendingTimer = void 0;
1245
1266
  }
1246
1267
  try {
1247
- await this.fire(sessionId, "manual:notification", true);
1268
+ await this.fire(sessionId, MANUAL_NOTIFICATION_REASON, true);
1248
1269
  } catch (error) {
1249
1270
  console.error(`[auto-continue] 手动续跑异常 ${sessionId}: ${error instanceof Error ? error.message : String(error)}`);
1250
1271
  }
@@ -1262,7 +1283,7 @@ var AutoContinueRunner = class {
1262
1283
  schedule(sessionId, reason, force = false) {
1263
1284
  const state = this.state(sessionId);
1264
1285
  const config = this.getConfig();
1265
- if (state.subagent) return;
1286
+ if (this.isSubagent(sessionId, state)) return;
1266
1287
  if (config.paused) {
1267
1288
  this.log(`跳过 ${sessionId}(${reason}): 全局暂停中`);
1268
1289
  return;
@@ -1344,14 +1365,15 @@ var AutoContinueRunner = class {
1344
1365
  if (this.disposed) return;
1345
1366
  const state = this.state(sessionId);
1346
1367
  const config = this.getConfig();
1368
+ const manualResume = force && reason === MANUAL_NOTIFICATION_REASON;
1347
1369
  if (reason.endsWith(":silent") && !config.resumeSilentTurns) return;
1348
1370
  if (isLoopReason(reason) && !config.resumeCompletedTurns) return;
1349
- if (state.subagent) return;
1350
- if (config.paused) {
1371
+ if (this.isSubagent(sessionId, state)) return;
1372
+ if (config.paused && !manualResume) {
1351
1373
  this.log(`跳过 ${sessionId}(${reason}): 全局暂停中`);
1352
1374
  return;
1353
1375
  }
1354
- if (Date.now() < (this.pauseUntil.get(sessionId) ?? 0)) {
1376
+ if (!manualResume && Date.now() < (this.pauseUntil.get(sessionId) ?? 0)) {
1355
1377
  this.log(`跳过 ${sessionId}(${reason}): 会话暂停中`);
1356
1378
  return;
1357
1379
  }
@@ -68,6 +68,10 @@ export declare class AutoContinueRunner {
68
68
  handleNoticeAction(sessionId: SessionId | undefined, action: string): void;
69
69
  dispose(): void;
70
70
  private state;
71
+ /** Mark a child session and clear queued grace/cooldown sends. */
72
+ private markSubagent;
73
+ /** Read durable origin from the live agent for direct action paths as well. */
74
+ private isSubagent;
71
75
  /**
72
76
  * 事件入口(host 单实例): 预处理工具调用/结果/模型消息(护栏与循环信号),
73
77
  * 然后交给回合状态机。
@@ -289,7 +289,7 @@ export interface SessionState {
289
289
  running: boolean | undefined;
290
290
  /** 当前排队消息数(来自 session/queue 帧)。 */
291
291
  queued: number;
292
- /** 子代理会话(host/session-added 带 parentSessionId)。 */
292
+ /** 子代理会话(session header origin is `subagent`). */
293
293
  subagent: boolean;
294
294
  /** 最近一次回合失败的事实(用于分类与模板填充)。 */
295
295
  lastFailure: FailureFacts | undefined;
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.12.0",
4
+ "version": "0.12.2",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/types/index.d.ts",
@@ -46,8 +46,8 @@
46
46
  "build": "node build.mjs && tsc -p tsconfig.build.json",
47
47
  "watch": "node build.mjs --watch",
48
48
  "typecheck": "tsc --noEmit",
49
- "test:runtime": "node tests/settings-host-live.mjs",
50
- "test": "node tests/scan-on-boot.mjs && node tests/silent-turn-boundaries.mjs && node tests/autonomous-loop.mjs && node tests/stats-freshness.mjs && node tests/simulate-host.mjs && node tests/settings-host-compat.mjs && node tests/simulate-client-loader.mjs && node tests/client-settings-services.mjs && node tests/locale-mirror-bounded.mjs && node tests/settings-card-ui.mjs && node tests/prepare-github-package.mjs",
49
+ "test:runtime": "node tests/settings-host-live.mjs 0.1.7 && node tests/settings-host-live.mjs 0.2.0 && node tests/profile-compatibility.mjs && node tests/client-settings-services.mjs 0.2.0",
50
+ "test": "node tests/scan-on-boot.mjs && node tests/silent-turn-boundaries.mjs && node tests/autonomous-loop.mjs && node tests/manual-resume-pauses.mjs && node tests/stats-freshness.mjs && node tests/simulate-host.mjs && node tests/settings-host-compat.mjs && node tests/simulate-client-loader.mjs && node tests/client-settings-services.mjs && node tests/client-settings-form.mjs && node tests/locale-mirror-bounded.mjs && node tests/settings-card-ui.mjs && node tests/prepare-github-package.mjs",
51
51
  "prepack": "npm run build"
52
52
  },
53
53
  "keywords": [
@@ -81,7 +81,7 @@
81
81
  "license": "MIT",
82
82
  "peerDependencies": {
83
83
  "react": "^18.2.0",
84
- "@deepseek-ai/dsh-settings": "^0.1.0-rc.7 || ^0.1.7-0",
84
+ "@deepseek-ai/dsh-settings": "^0.1.0-rc.7 || ^0.1.7-0 || ^0.2.0-rc.1",
85
85
  "@deepseek-ai/schemastery": "^3.18.1",
86
86
  "@deepseek-ai/cordis": "^4.0.1"
87
87
  },
@@ -37,7 +37,7 @@ export const zh = {
37
37
  'field.resumeSilentTurns': '续跑无输出回合',
38
38
  'field.resumeSilentTurnsHint': '已观察到模型活动但没有可见输出时续跑;不把空回合、图片或扩展内容误判为静默,冷却与连续上限照常生效。',
39
39
  'field.resumeCompletedTurns': '自主循环(每个回合后都续跑)',
40
- 'field.resumeCompletedTurnsHint': '每个正常完成的回合结束后立即把对话交还给 Agent,无限循环直到你手动停止或发送消息。连续失败上限只对失败生效,成功的回合不计入。',
40
+ 'field.resumeCompletedTurnsHint': '正常完成后经过宽限期自动续跑,不受恢复冷却和次数上限限制;仅有推理或显式无输出的回合仍消耗重试预算。暂停或关闭该选项可停止后续接力,手动停止或发送消息会取消当前待发送的继续提示。',
41
41
  'field.continueTextLoop': '自主循环的继续文本',
42
42
  'field.continueTextLoopHint': '自主循环每次续跑时发送的文本。',
43
43
  'default.continueTextLoop': LOCALIZED_TEXT_DEFAULTS.zh.continueTextLoop,
@@ -55,9 +55,9 @@ export const zh = {
55
55
  'field.graceMs': '宽限期 (ms)',
56
56
  'field.graceMsHint': '检测到中断后等待的时长; 期间宿主自行恢复则取消。',
57
57
  'field.cooldownMs': '冷却时间 (ms)',
58
- 'field.cooldownMsHint': '同一会话两次自动「继续」的最小间隔, 失败尝试也计入。',
58
+ 'field.cooldownMsHint': '同一会话恢复尝试的最小间隔;期间出现的失败会等待剩余冷却,再进入宽限期。正常完成后的自主循环接力不受此限制。',
59
59
  'field.maxConsecutive': '最大连续次数',
60
- 'field.maxConsecutiveHint': '同一会话连续自动「继续」的上限;直到用户介入或成功回合产生已确认的可见输出才清零。',
60
+ 'field.maxConsecutiveHint': '连续恢复尝试上限;用户介入或观察到有可见输出的成功回合后清零。正常完成后的自主循环接力不计入。',
61
61
  'field.scanOnBoot': '启动恢复扫描',
62
62
  'field.scanOnBootHint': '宿主启动后在扫描时间窗内等待延迟加载的中断会话,每个已就绪会话只检查一次。',
63
63
  'field.scanLimit': '扫描会话数',
@@ -65,7 +65,7 @@ export const zh = {
65
65
  'field.freshMs': '扫描时间窗 (ms)',
66
66
  'field.freshMsHint': '只处理该时间窗内的中断;启动轮询也会在这段时间后结束。',
67
67
  'field.verbose': '详细日志',
68
- 'field.verboseHint': '在浏览器控制台输出 [auto-continue] 日志。',
68
+ 'field.verboseHint': '在 DSH 宿主日志中输出 [auto-continue] 引擎活动;CLI 用户可在运行 DSH 的终端查看。',
69
69
  'field.classify': '错误分类',
70
70
  'field.classifyHint': '仅自动恢复临时性错误(网络/超时/5xx 等); 认证/余额/模型不存在等永久性错误跳过并通知。',
71
71
  'field.retryableErrorPatterns': '自定义可恢复错误',
@@ -158,7 +158,7 @@ export const en: Record<SettingsCardKey, string> = {
158
158
  'field.resumeSilentTurns': 'Resume silent turns',
159
159
  'field.resumeSilentTurnsHint': 'Resume observed model activity without visible output. No-op turns, images and extension blocks are not treated as silent; cooldown and retry limits still apply.',
160
160
  'field.resumeCompletedTurns': 'Autonomous loop (continue after every turn)',
161
- 'field.resumeCompletedTurnsHint': 'Hand the thread back to the agent after every completed turn, looping until you press stop or send a message. The consecutive-failure cap only throttles failures; successful turns never count.',
161
+ 'field.resumeCompletedTurnsHint': 'Continue normal completions after grace, without the recovery cooldown or cap. Reasoning-only and explicit silent endings still consume the retry budget. Pause or disable this option to stop future handoffs; Stop or a manual message cancels the queued continuation.',
162
162
  'field.continueTextLoop': 'Continue text (autonomous loop)',
163
163
  'field.continueTextLoopHint': 'Text sent on each autonomous-loop continuation.',
164
164
  'default.continueTextLoop': LOCALIZED_TEXT_DEFAULTS.en.continueTextLoop,
@@ -176,9 +176,9 @@ export const en: Record<SettingsCardKey, string> = {
176
176
  'field.graceMs': 'Grace period (ms)',
177
177
  'field.graceMsHint': 'Wait after an interruption; cancelled if the host recovers on its own.',
178
178
  'field.cooldownMs': 'Cooldown (ms)',
179
- 'field.cooldownMsHint': 'Minimum interval between auto-continues per session; failed attempts count too.',
179
+ 'field.cooldownMsHint': 'Minimum interval between recovery attempts; failures during cooldown wait for the remaining interval, then grace. Normal autonomous-loop handoffs are exempt.',
180
180
  'field.maxConsecutive': 'Max consecutive',
181
- 'field.maxConsecutiveHint': 'Max consecutive auto-continues per session; resets only after user intervention or a completed turn with confirmed visible output.',
181
+ 'field.maxConsecutiveHint': 'Consecutive recovery-attempt cap; resets on user intervention or an observed completion with visible output. Normal autonomous-loop handoffs are exempt.',
182
182
  'field.scanOnBoot': 'Scan on host startup',
183
183
  'field.scanOnBootHint': 'Wait for delayed interrupted sessions during the startup scan window; inspect each settled session once.',
184
184
  'field.scanLimit': 'Scan limit',
@@ -186,7 +186,7 @@ export const en: Record<SettingsCardKey, string> = {
186
186
  'field.freshMs': 'Scan window (ms)',
187
187
  'field.freshMsHint': 'Only interruptions inside this window are considered; startup polling also ends after this duration.',
188
188
  'field.verbose': 'Verbose logs',
189
- 'field.verboseHint': 'Log [auto-continue] lines to the browser console.',
189
+ 'field.verboseHint': 'Write engine activity to DSH host logs with the [auto-continue] prefix; CLI users can read them in the terminal running DSH.',
190
190
  'field.classify': 'Classify errors',
191
191
  'field.classifyHint': 'Auto-resume transient failures only (network/timeout/5xx…); auth, balance and model errors are skipped and notified.',
192
192
  'field.retryableErrorPatterns': 'Custom retryable errors',
@@ -214,9 +214,9 @@ export class CardForm<T> {
214
214
  const plan = this.plan();
215
215
  const writes = plan.flatMap((item) => (item.run === undefined ? [] : [item.run]));
216
216
  if (plan.length === 0 || this.saving || writes.length !== plan.length) return;
217
- // Snapshot the fields this save writes, so edits staged while it is in
218
- // flight survive: only the staged keys this save actually wrote are cleared.
219
- const fields = new Set(plan.map((item) => item.field));
217
+ // Keep the staged edits this save writes. A field can be staged again
218
+ // while a write is pending, so clear it only if that exact edit remains.
219
+ const edits = plan.map(({ field, staged }) => ({ field, staged }));
220
220
  this.saving = true;
221
221
  this.failed = false;
222
222
  this.publish();
@@ -225,7 +225,9 @@ export class CardForm<T> {
225
225
  landed = (await write()) && landed;
226
226
  }
227
227
  if (landed) {
228
- for (const field of fields) this.staged.delete(field);
228
+ for (const { field, staged } of edits) {
229
+ if (this.staged.get(field) === staged) this.staged.delete(field);
230
+ }
229
231
  }
230
232
  this.saving = false;
231
233
  this.failed = !landed;
@@ -238,19 +240,19 @@ export class CardForm<T> {
238
240
  * refuses rather than dropping the edit. A staged edit that matches the
239
241
  * effective section is not a write at all.
240
242
  */
241
- private plan(): { field: string; run: (() => Promise<boolean>) | undefined }[] {
242
- const plan: { field: string; run: (() => Promise<boolean>) | undefined }[] = [];
243
+ private plan(): { field: string; staged: StagedEdit; run: (() => Promise<boolean>) | undefined }[] {
244
+ const plan: { field: string; staged: StagedEdit; run: (() => Promise<boolean>) | undefined }[] = [];
243
245
  for (const [field, staged] of this.staged) {
244
246
  const spec = this.specOf(field);
245
247
  if (staged.clear) {
246
- if (this.stored(field)) plan.push({ field, run: () => this.clear(field) });
248
+ if (this.stored(field)) plan.push({ field, staged, run: () => this.clear(field) });
247
249
  continue;
248
250
  }
249
251
  if (staged.text === spec.format(this.sectionValue(field))) continue;
250
252
  const write = spec.parse(staged.text);
251
- if (write === undefined) plan.push({ field, run: undefined });
252
- else if (write.kind === 'clear') plan.push({ field, run: () => this.clear(field) });
253
- else plan.push({ field, run: () => this.store(field, write.value) });
253
+ if (write === undefined) plan.push({ field, staged, run: undefined });
254
+ else if (write.kind === 'clear') plan.push({ field, staged, run: () => this.clear(field) });
255
+ else plan.push({ field, staged, run: () => this.store(field, write.value) });
254
256
  }
255
257
  return plan;
256
258
  }
@@ -92,6 +92,7 @@ const LOOP_GUARD_CANCEL_CAUSE = {
92
92
  */
93
93
  const LOOP_COMPLETED_REASON = 'turn/end:completed';
94
94
  const LOOP_SILENT_REASON = 'turn/end:loop-silent';
95
+ const MANUAL_NOTIFICATION_REASON = 'manual:notification';
95
96
  const isLoopReason = (reason: string): boolean =>
96
97
  reason === LOOP_COMPLETED_REASON || reason === LOOP_SILENT_REASON;
97
98
 
@@ -369,12 +370,33 @@ export class AutoContinueRunner {
369
370
  return state;
370
371
  }
371
372
 
373
+ /** Mark a child session and clear queued grace/cooldown sends. */
374
+ private markSubagent(sessionId: SessionId, state: SessionState): void {
375
+ state.subagent = true;
376
+ this.cancelPending(sessionId, '子代理会话');
377
+ }
378
+
379
+ /** Read durable origin from the live agent for direct action paths as well. */
380
+ private isSubagent(sessionId: SessionId, state: SessionState): boolean {
381
+ if (state.subagent) return true;
382
+ const agent = this.ctx.agents.get(sessionId);
383
+ if (agent?.session?.header?.origin !== 'subagent') return false;
384
+ this.markSubagent(sessionId, state);
385
+ return true;
386
+ }
387
+
372
388
  /**
373
389
  * 事件入口(host 单实例): 预处理工具调用/结果/模型消息(护栏与循环信号),
374
390
  * 然后交给回合状态机。
375
391
  */
376
392
  private onHostEvent(session: Session, event: SessionEvent): void {
377
393
  const sessionId = session.id;
394
+ const sessionState = this.states.get(sessionId);
395
+ if (session.header?.origin === 'subagent') {
396
+ this.markSubagent(sessionId, sessionState ?? this.state(sessionId));
397
+ return;
398
+ }
399
+ if (sessionState?.subagent) return;
378
400
  if (
379
401
  (event.type === 'user/message' || event.type === 'assistant/message') &&
380
402
  typeof event.surfaceOp === 'object' &&
@@ -620,6 +642,7 @@ export class AutoContinueRunner {
620
642
  * 才会用 loopText 重启回合——DSH 的 first-cause 语义保证用户 Stop 优先。
621
643
  */
622
644
  private interruptLoop(sessionId: SessionId, state: SessionState): void {
645
+ if (this.isSubagent(sessionId, state)) return;
623
646
  if (state.loopFired) return;
624
647
  // 打断本身受冷却约束: 距上次打断/发送太近时不再打断, 防止反复打断刷屏
625
648
  if (Date.now() - state.lastAttemptAt < this.cooldownFor(state)) {
@@ -906,13 +929,13 @@ export class AutoContinueRunner {
906
929
  async resumeNow(sessionId: SessionId): Promise<void> {
907
930
  if (this.disposed) return;
908
931
  const state = this.state(sessionId);
909
- if (state.subagent) return;
932
+ if (this.isSubagent(sessionId, state)) return;
910
933
  if (state.pendingTimer !== undefined) {
911
934
  clearTimeout(state.pendingTimer);
912
935
  state.pendingTimer = undefined;
913
936
  }
914
937
  try {
915
- await this.fire(sessionId, 'manual:notification', true);
938
+ await this.fire(sessionId, MANUAL_NOTIFICATION_REASON, true);
916
939
  } catch (error) {
917
940
  console.error(`[auto-continue] 手动续跑异常 ${sessionId}: ${error instanceof Error ? error.message : String(error)}`);
918
941
  }
@@ -932,7 +955,7 @@ export class AutoContinueRunner {
932
955
  private schedule(sessionId: SessionId, reason: string, force = false): void {
933
956
  const state = this.state(sessionId);
934
957
  const config = this.getConfig();
935
- if (state.subagent) return; // 子代理会话由父代理处理, 不抢跑
958
+ if (this.isSubagent(sessionId, state)) return; // 子代理会话由父代理处理, 不抢跑
936
959
  if (config.paused) {
937
960
  this.log(`跳过 ${sessionId}(${reason}): 全局暂停中`);
938
961
  return;
@@ -1025,16 +1048,17 @@ export class AutoContinueRunner {
1025
1048
  if (this.disposed) return;
1026
1049
  const state = this.state(sessionId);
1027
1050
  const config = this.getConfig();
1051
+ const manualResume = force && reason === MANUAL_NOTIFICATION_REASON;
1028
1052
  if (reason.endsWith(':silent') && !config.resumeSilentTurns) return;
1029
1053
  // 宽限期内循环被关闭: 发送前必须重新检查开关, 与 :silent 恢复同样处理。
1030
1054
  // 否则「关掉循环」后仍会多发出一次续跑。
1031
1055
  if (isLoopReason(reason) && !config.resumeCompletedTurns) return;
1032
- if (state.subagent) return; // 子代理会话由父代理处理, 不抢跑
1033
- if (config.paused) {
1056
+ if (this.isSubagent(sessionId, state)) return; // 子代理会话由父代理处理, 不抢跑
1057
+ if (config.paused && !manualResume) {
1034
1058
  this.log(`跳过 ${sessionId}(${reason}): 全局暂停中`);
1035
1059
  return;
1036
1060
  }
1037
- if (Date.now() < (this.pauseUntil.get(sessionId) ?? 0)) {
1061
+ if (!manualResume && Date.now() < (this.pauseUntil.get(sessionId) ?? 0)) {
1038
1062
  this.log(`跳过 ${sessionId}(${reason}): 会话暂停中`);
1039
1063
  return;
1040
1064
  }
@@ -830,7 +830,7 @@ export interface SessionState {
830
830
  running: boolean | undefined;
831
831
  /** 当前排队消息数(来自 session/queue 帧)。 */
832
832
  queued: number;
833
- /** 子代理会话(host/session-added 带 parentSessionId)。 */
833
+ /** 子代理会话(session header origin is `subagent`). */
834
834
  subagent: boolean;
835
835
  /** 最近一次回合失败的事实(用于分类与模板填充)。 */
836
836
  lastFailure: FailureFacts | undefined;