dsh-client-auto-continue 0.14.2 → 0.14.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/lib/index.js CHANGED
@@ -637,6 +637,7 @@ var MANUAL_NOTIFICATION_REASON = "manual:notification";
637
637
  var isLoopReason = (reason) => reason === LOOP_COMPLETED_REASON || reason === LOOP_SILENT_REASON;
638
638
  var STREAM_NEAR_DUPLICATE_MAX_CHARS = 2048;
639
639
  var STREAM_TAIL_MAX_CHARS = 4096;
640
+ var visibleText = (text) => text.replace(/\p{Cf}/gu, "").trim();
640
641
  function snapshotSessionEvents(session) {
641
642
  const compatible = session;
642
643
  const snapshot = compatible.snapshotEvents;
@@ -843,6 +844,8 @@ var AutoContinueRunner = class {
843
844
  const state = this.state(sessionId);
844
845
  if (state.tools.recordCall(event)) {
845
846
  state.shortRun = 0;
847
+ state.sameTextRun = 0;
848
+ state.lastAssistantText = "";
846
849
  if (this.tracksOutput(state, event)) state.turnOutput = "visible";
847
850
  }
848
851
  } else if (event.type === "tool/result") {
@@ -857,7 +860,7 @@ var AutoContinueRunner = class {
857
860
  const state = this.state(sessionId);
858
861
  if (this.tracksOutput(state, event)) {
859
862
  const chunk = event.data.chunk;
860
- const visible = chunk.type === "text-delta" && chunk.text.trim() !== "" || chunk.type === "tool-call-delta" || chunk.type === "block-end" && this.hasVisibleContent([chunk.block]) || chunk.type === "block-start" && chunk.blockType !== "reasoning" && chunk.blockType !== "text";
863
+ const visible = chunk.type === "text-delta" && visibleText(chunk.text) !== "" || chunk.type === "tool-call-delta" || chunk.type === "block-end" && this.hasVisibleContent([chunk.block]) || chunk.type === "block-start" && chunk.blockType !== "reasoning" && chunk.blockType !== "text";
861
864
  if (visible) state.turnOutput = "visible";
862
865
  else if (state.turnOutput === "empty" && chunk.type !== "usage" && chunk.type !== "finish") state.turnOutput = "silent";
863
866
  }
@@ -882,7 +885,7 @@ var AutoContinueRunner = class {
882
885
  if (part === null || typeof part !== "object") return true;
883
886
  const block = part;
884
887
  if (block.type === "reasoning") return false;
885
- if (block.type === "text") return typeof block.text !== "string" || block.text.trim() !== "";
888
+ if (block.type === "text") return typeof block.text !== "string" || visibleText(block.text) !== "";
886
889
  return true;
887
890
  });
888
891
  }
@@ -896,7 +899,7 @@ var AutoContinueRunner = class {
896
899
  return event.data.chunk.type === "text-delta" ? event.data.chunk.text : "";
897
900
  }
898
901
  normalizedSegment(text) {
899
- return text.replace(/\s+/g, " ").trim();
902
+ return visibleText(text).replace(/\s+/g, " ");
900
903
  }
901
904
  isNearDuplicateSegment(left, right) {
902
905
  if (left === right) return true;
@@ -987,12 +990,12 @@ var AutoContinueRunner = class {
987
990
  onAssistantMessage(sessionId, state, event) {
988
991
  if (!this.getConfig().loopGuard) return;
989
992
  const text = this.assistantText(event);
990
- const trimmed = text.trim();
993
+ const trimmed = visibleText(text);
991
994
  if (trimmed !== "" && trimmed === state.lastAssistantText) {
992
995
  state.sameTextRun += 1;
993
996
  } else {
994
997
  state.lastAssistantText = trimmed;
995
- state.sameTextRun = 1;
998
+ state.sameTextRun = trimmed === "" ? 0 : 1;
996
999
  }
997
1000
  if (trimmed.length < this.getConfig().loopShortChars) {
998
1001
  const now = Date.now();
@@ -22,7 +22,7 @@ export interface SettingsScopeSnapshot<T> {
22
22
  user: unknown;
23
23
  revision: number | undefined;
24
24
  writable: boolean;
25
- mode: 'host' | 'memory';
25
+ mode?: 'host' | 'memory';
26
26
  }
27
27
  /** Stable subset shared by settings scopes and DSH 0.1.7 configuration forms. */
28
28
  export interface SettingsScope<T> {
@@ -10,7 +10,9 @@
10
10
  * default — and whether the user layer carries it (presence, not value
11
11
  * equality, marks an override).
12
12
  */
13
- import type { SettingsScope, SnapshotStore } from './dsh-store-compat.ts';
13
+ import type { SettingsScope, SettingsScopeSnapshot, SnapshotStore } from './dsh-store-compat.ts';
14
+ /** Current forms omit mode; legacy memory scopes still cannot persist settings. */
15
+ export declare function canWriteSettings(snapshot: SettingsScopeSnapshot<unknown>): boolean;
14
16
  /** The write one field's staged text performs when the card is saved. */
15
17
  export type FieldWrite = {
16
18
  kind: 'set';
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.14.2",
4
+ "version": "0.14.3",
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 0.1.7 && node tests/settings-host-live.mjs 0.2.0 && node tests/settings-host-live.mjs 0.2.1 && node tests/profile-compatibility.mjs 0.2.0 && node tests/profile-compatibility.mjs 0.2.1 && node tests/client-settings-services.mjs 0.2.0 && node tests/client-settings-services.mjs 0.2.1 && node tests/boot-scan-host-live.mjs 0.2.0-rc.2 && node tests/boot-scan-host-live.mjs 0.2.1",
50
- "test": "node tests/scan-on-boot.mjs && node tests/boot-scan-isolation.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/composer-toggle.mjs && node tests/settings-notifications.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/settings-host-live.mjs 0.2.1 && node tests/profile-compatibility.mjs 0.2.0 && node tests/profile-compatibility.mjs 0.2.1 && node tests/client-settings-services.mjs 0.2.0 && node tests/client-settings-services.mjs 0.2.1 && node tests/boot-scan-host-live.mjs 0.2.0-rc.2 && node tests/boot-scan-host-live.mjs 0.2.1 && node tests/settings-host-live.mjs 0.2.1-rc.2 && node tests/profile-compatibility.mjs 0.2.1-rc.2",
50
+ "test": "node tests/loop-guard-progress.mjs && node tests/scan-on-boot.mjs && node tests/boot-scan-isolation.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/composer-toggle.mjs && node tests/settings-notifications.mjs && node tests/prepare-github-package.mjs",
51
51
  "prepack": "npm run build"
52
52
  },
53
53
  "keywords": [
@@ -24,7 +24,7 @@ export interface SettingsScopeSnapshot<T> {
24
24
  user: unknown;
25
25
  revision: number | undefined;
26
26
  writable: boolean;
27
- mode: 'host' | 'memory';
27
+ mode?: 'host' | 'memory';
28
28
  }
29
29
 
30
30
  /** Stable subset shared by settings scopes and DSH 0.1.7 configuration forms. */
@@ -27,6 +27,7 @@ import {
27
27
  import { startBridge } from './bridge.ts';
28
28
  import { AutoContinueComposerToggle } from './composer-toggle.tsx';
29
29
  import type { SettingsScope } from './dsh-store-compat.ts';
30
+ import { canWriteSettings } from './settings-form.ts';
30
31
 
31
32
  /** Dictionary namespace owned by this plugin. */
32
33
  const NS = 'auto-continue';
@@ -122,7 +123,7 @@ function mountSettings(ctx: ClientContext, scope: SettingsScope<AutoContinueSett
122
123
  const syncLocale = (): void => {
123
124
  const active = ctx.locale.getLocale().active;
124
125
  const snapshot = scope.getSnapshot();
125
- if (snapshot.status !== 'ready' || !snapshot.writable || snapshot.mode !== 'host') return;
126
+ if (!canWriteSettings(snapshot)) return;
126
127
  // A genuine language switch is the only thing that earns a fresh budget: the
127
128
  // attempt count must survive matching snapshots, because the writing page's
128
129
  // own acknowledgement arrives as a match (see above). Tracking `mirroredLocale`
@@ -43,7 +43,7 @@ export const zh = {
43
43
  'composer.scope': '控制当前配置下所有会话的自动继续,修改立即保存。',
44
44
  'composer.saving': '正在保存自动继续设置…',
45
45
  'composer.saveFailed': '保存失败,请重试',
46
- 'field.pausedHint': '恢复意外中断的会话。关闭并保存后,全局暂停恢复并取消已排队的继续。',
46
+ 'field.pausedHint': '恢复意外中断的会话。关闭并保存后,全局暂停恢复并取消已排队的继续。循环守卫独立运行;如需停止自动打断,请同时关闭循环守卫。',
47
47
  'field.continueText': '继续文本',
48
48
  'field.continueTextHint': '中断后自动发送的消息内容。',
49
49
  'default.continueText': LOCALIZED_TEXT_DEFAULTS.zh.continueText,
@@ -180,7 +180,7 @@ export const en: Record<SettingsCardKey, string> = {
180
180
  'composer.scope': 'Controls auto-continue for all sessions in this profile. Changes save immediately.',
181
181
  'composer.saving': 'Saving auto-continue setting…',
182
182
  'composer.saveFailed': 'Could not save. Try again.',
183
- 'field.pausedHint': 'Resume interrupted sessions. Turn off and save to pause recovery globally and cancel queued continuations.',
183
+ 'field.pausedHint': 'Resume interrupted sessions. Turn off and save to pause recovery globally and cancel queued continuations. The loop guard stays active; turn it off separately to stop automatic interruptions.',
184
184
  'field.continueText': 'Continue text',
185
185
  'field.continueTextHint': 'Message automatically sent after an interruption.',
186
186
  'default.continueText': LOCALIZED_TEXT_DEFAULTS.en.continueText,
@@ -23,6 +23,7 @@ import {
23
23
  import type { SettingsCardKey } from './locales.ts';
24
24
  import {
25
25
  booleanField,
26
+ canWriteSettings,
26
27
  CardForm,
27
28
  numberField,
28
29
  textField,
@@ -186,7 +187,7 @@ export class AutoContinueSettingsCardController {
186
187
  private async save(): Promise<void> {
187
188
  const state = this.form.shell();
188
189
  const snapshot = this.scope.getSnapshot();
189
- if (this.disposed || !state.available || !state.writable || !state.dirty || state.invalid || state.saving || snapshot.mode !== 'host') return;
190
+ if (this.disposed || !state.available || !state.writable || !state.dirty || state.invalid || state.saving) return;
190
191
  const sequence = ++this.saveSequence;
191
192
  const before = snapshot.value?.notify ?? DEFAULT_CONFIG.notify;
192
193
  const target = this.form.field('notify').text;
@@ -212,7 +213,7 @@ export class AutoContinueSettingsCardController {
212
213
  return {
213
214
  visible: snapshot.status === 'ready' && (snapshot.value?.showComposerToggle ?? DEFAULT_CONFIG.showComposerToggle),
214
215
  enabled: !(snapshot.value?.paused ?? DEFAULT_CONFIG.paused),
215
- writable: snapshot.status === 'ready' && snapshot.writable && snapshot.mode === 'host',
216
+ writable: canWriteSettings(snapshot),
216
217
  saving: this.composerSaving,
217
218
  failed: this.composerFailed,
218
219
  };
@@ -10,7 +10,12 @@
10
10
  * default — and whether the user layer carries it (presence, not value
11
11
  * equality, marks an override).
12
12
  */
13
- import type { SettingsScope, SnapshotStore } from './dsh-store-compat.ts';
13
+ import type { SettingsScope, SettingsScopeSnapshot, SnapshotStore } from './dsh-store-compat.ts';
14
+
15
+ /** Current forms omit mode; legacy memory scopes still cannot persist settings. */
16
+ export function canWriteSettings(snapshot: SettingsScopeSnapshot<unknown>): boolean {
17
+ return snapshot.status === 'ready' && snapshot.writable && (snapshot.mode === undefined || snapshot.mode === 'host');
18
+ }
14
19
 
15
20
  /** The write one field's staged text performs when the card is saved. */
16
21
  export type FieldWrite = { kind: 'set'; value: unknown } | { kind: 'clear' };
@@ -162,7 +167,7 @@ export class CardForm<T> {
162
167
  const snapshot = this.scope.getSnapshot();
163
168
  return {
164
169
  available: snapshot.status === 'ready',
165
- writable: snapshot.writable,
170
+ writable: canWriteSettings(snapshot),
166
171
  dirty: this.plan().length > 0,
167
172
  invalid: this.plan().some((item) => item.run === undefined),
168
173
  saving: this.saving,
@@ -214,7 +219,7 @@ export class CardForm<T> {
214
219
  const plan = this.plan();
215
220
  const writes = plan.flatMap((item) => (item.run === undefined ? [] : [item.run]));
216
221
  const snapshot = this.scope.getSnapshot();
217
- if (plan.length === 0 || this.saving || writes.length !== plan.length || snapshot.status !== 'ready' || !snapshot.writable || snapshot.mode !== 'host') return false;
222
+ if (plan.length === 0 || this.saving || writes.length !== plan.length || !canWriteSettings(snapshot)) return false;
218
223
  // Keep the staged edits this save writes. A field can be staged again
219
224
  // while a write is pending, so clear it only if that exact edit remains.
220
225
  const edits = plan.map(({ field, staged }) => ({ field, staged }));
@@ -101,6 +101,9 @@ const STREAM_NEAR_DUPLICATE_MAX_CHARS = 2_048;
101
101
  /** Bound unfinished text copied between token chunks when a provider emits no paragraph break. */
102
102
  const STREAM_TAIL_MAX_CHARS = 4_096;
103
103
 
104
+ /** Ignore invisible formatting only for detection, never rewrite the stored message. */
105
+ const visibleText = (text: string): string => text.replace(/\p{Cf}/gu, '').trim();
106
+
104
107
  /** 通知桥事件: host 引擎产生, browser 侧订阅展示(Notification / 动作按钮)。 */
105
108
  export interface HostNotice {
106
109
  /** 稳定标识(供 browser 去重)。 */
@@ -425,6 +428,8 @@ export class AutoContinueRunner {
425
428
  // 任何新鲜调用都代表进展(即使缺关联 id);旧帧重放不能清短句 streak。
426
429
  if (state.tools.recordCall(event)) {
427
430
  state.shortRun = 0;
431
+ state.sameTextRun = 0;
432
+ state.lastAssistantText = '';
428
433
  if (this.tracksOutput(state, event)) state.turnOutput = 'visible';
429
434
  }
430
435
  } else if (event.type === 'tool/result') {
@@ -439,7 +444,7 @@ export class AutoContinueRunner {
439
444
  const state = this.state(sessionId);
440
445
  if (this.tracksOutput(state, event)) {
441
446
  const chunk = event.data.chunk;
442
- const visible = (chunk.type === 'text-delta' && chunk.text.trim() !== '') ||
447
+ const visible = (chunk.type === 'text-delta' && visibleText(chunk.text) !== '') ||
443
448
  chunk.type === 'tool-call-delta' ||
444
449
  (chunk.type === 'block-end' && this.hasVisibleContent([chunk.block])) ||
445
450
  (chunk.type === 'block-start' && chunk.blockType !== 'reasoning' && chunk.blockType !== 'text');
@@ -470,7 +475,7 @@ export class AutoContinueRunner {
470
475
  if (part === null || typeof part !== 'object') return true;
471
476
  const block = part as { type?: unknown; text?: unknown };
472
477
  if (block.type === 'reasoning') return false;
473
- if (block.type === 'text') return typeof block.text !== 'string' || block.text.trim() !== '';
478
+ if (block.type === 'text') return typeof block.text !== 'string' || visibleText(block.text) !== '';
474
479
  return true;
475
480
  });
476
481
  }
@@ -490,7 +495,7 @@ export class AutoContinueRunner {
490
495
  }
491
496
 
492
497
  private normalizedSegment(text: string): string {
493
- return text.replace(/\s+/g, ' ').trim();
498
+ return visibleText(text).replace(/\s+/g, ' ');
494
499
  }
495
500
 
496
501
  private isNearDuplicateSegment(left: string, right: string): boolean {
@@ -599,14 +604,14 @@ export class AutoContinueRunner {
599
604
  ): void {
600
605
  if (!this.getConfig().loopGuard) return;
601
606
  const text = this.assistantText(event);
602
- const trimmed = text.trim();
607
+ const trimmed = visibleText(text);
603
608
  // 相同文本重复(不限长度): 模型反复输出完全相同的消息是最强的循环信号,
604
609
  // 例如 "Let me test variants of the regex..." 连续 7 遍
605
610
  if (trimmed !== '' && trimmed === state.lastAssistantText) {
606
611
  state.sameTextRun += 1;
607
612
  } else {
608
613
  state.lastAssistantText = trimmed;
609
- state.sameTextRun = 1;
614
+ state.sameTextRun = trimmed === '' ? 0 : 1;
610
615
  }
611
616
  // 短句计数(长度 < loopShortChars 且落在时间窗内): 空转信号
612
617
  if (trimmed.length < this.getConfig().loopShortChars) {