dsh-client-auto-continue 0.17.4 → 0.19.0

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +230 -281
  3. package/README.ru.md +382 -0
  4. package/README.zh.md +229 -279
  5. package/docs/auto-continue-workflow.archify.json +3 -3
  6. package/docs/auto-continue-workflow.en.archify.json +3 -3
  7. package/docs/auto-continue-workflow.en.html +1 -1
  8. package/docs/auto-continue-workflow.html +1 -1
  9. package/docs/auto-continue-workflow.ru.svg +530 -0
  10. package/docs/banner-ru-dark.svg +38 -0
  11. package/docs/banner-ru.svg +38 -0
  12. package/docs/demo-ru-static.svg +115 -0
  13. package/docs/demo-ru.svg +147 -0
  14. package/docs/releases/v0.18.0.md +58 -0
  15. package/docs/releases/v0.19.0.md +62 -0
  16. package/docs/social-preview.png +0 -0
  17. package/docs/social-preview.svg +30 -1
  18. package/lib/client.js +347 -100
  19. package/lib/client.js.map +3 -3
  20. package/lib/index.js +790 -49
  21. package/lib/types/client/auto-continue-icon.d.ts +7 -0
  22. package/lib/types/client/bridge.d.ts +2 -0
  23. package/lib/types/client/composer-toggle.d.ts +2 -0
  24. package/lib/types/client/locales.d.ts +19 -0
  25. package/lib/types/client/settings-card.d.ts +8 -0
  26. package/lib/types/host/connectivity.d.ts +4 -0
  27. package/lib/types/host/engine.d.ts +97 -5
  28. package/lib/types/index.d.ts +64 -0
  29. package/lib/types/shared/core.d.ts +54 -1
  30. package/locale/ru.json +6 -0
  31. package/package.json +6 -4
  32. package/scripts/build-docs-assets.mjs +126 -0
  33. package/src/client/auto-continue-icon.tsx +6 -27
  34. package/src/client/bridge.ts +26 -6
  35. package/src/client/composer-toggle.tsx +22 -11
  36. package/src/client/index.ts +5 -1
  37. package/src/client/locales.ts +241 -38
  38. package/src/client/settings-card.tsx +31 -4
  39. package/src/client/settings-notifications.ts +3 -2
  40. package/src/client/styles.ts +17 -19
  41. package/src/host/connectivity.ts +54 -0
  42. package/src/host/engine.ts +852 -40
  43. package/src/host/settings-migration.ts +1 -1
  44. package/src/index.ts +26 -1
  45. package/src/shared/core.ts +94 -3
@@ -49,7 +49,7 @@ export function migrateLegacySettings(
49
49
  if (disposed) return;
50
50
  // YAML errors may quote other plugins' secrets, so do not log the source
51
51
  // or parser exception. Leave the original document available for repair.
52
- migration.logger.error('[auto-continue] Could not import settings-legacy.yaml; automatic recovery and loop guard are held until the file/profile can be read and saved, then restart the host');
52
+ migration.logger.error('[auto-continue] Could not import settings-legacy.yaml. Automatic recovery and loop guard are paused. Check the legacy settings file and profile permissions, then restart DSH.');
53
53
  };
54
54
  // Do not return this task to Cordis: profile edits require the owning entry
55
55
  // to be active, and Loader.await() must not wait for this migration itself.
package/src/index.ts CHANGED
@@ -23,17 +23,23 @@ import type {} from '@deepseek-ai/dsh-settings';
23
23
 
24
24
  /** Settings namespace of the auto-continue plugin (lowercase kebab-case). */
25
25
  export const AUTO_CONTINUE_NS = 'auto-continue';
26
+ /** Interval for SSE comment frames on the status bridge, so idle connections are not dropped. */
27
+ const BRIDGE_HEARTBEAT_MS = 20_000;
26
28
 
27
29
  /** Wire schema; blank localized text fields tell resolveConfig() to select the active locale's defaults. */
28
30
  const settingsFields = {
29
31
  /** Active browser/UI locale mirrored by the client. */
30
32
  locale: z.string().default('en'),
33
+ /** Send continue messages with the plugin source instead of the legacy user source. */
34
+ usePluginSource: z.boolean().default(false),
31
35
  /** Text automatically sent after an interruption. */
32
36
  continueText: z.string().default(''),
33
37
  /** Text sent when the output token ceiling is reached (same placeholders as `continueText`). */
34
38
  continueTextMaxTokens: z.string().default(''),
35
39
  /** Resume observed model activity that completes without visible output. */
36
40
  resumeSilentTurns: z.boolean().default(true),
41
+ /** Resume interrupted subagent sessions when their main conversation has auto-continue enabled. Subagents never enter the autonomous loop. */
42
+ resumeSubagentSessions: z.boolean().default(false),
37
43
  /** Autonomous mode: hand the thread back to the agent after every completed turn, looping until the user stops it. The consecutive-failure cap only throttles failures, never successful completions. */
38
44
  resumeCompletedTurns: z.boolean().default(false),
39
45
  /** Text sent to resume a silent turn (same placeholders as `continueText`). */
@@ -98,6 +104,18 @@ const settingsFields = {
98
104
  loopText: z
99
105
  .string()
100
106
  .default(''),
107
+ /** Recover child (subagent / Agent Teams) sessions a restart interrupted by waking their root session once. */
108
+ resumeInterruptedChildren: z.boolean().default(false),
109
+ /** Re-arm a goal a restart left `active` but `disarmed`, when its own session is resumed. */
110
+ resumeGoals: z.boolean().default(false),
111
+ /** Also resume goals the user explicitly paused. Off by default: pausing is a human decision. */
112
+ resumePausedGoals: z.boolean().default(false),
113
+ /** Hold network-error recoveries while the host is offline; waiting does not consume the retry budget. */
114
+ pauseWhenOffline: z.boolean().default(true),
115
+ /** How often (ms) a held recovery re-checks connectivity. */
116
+ offlineCheckMs: z.natural().min(1000).default(15000),
117
+ /** Autonomous-loop round cap per session; 0 means unlimited. */
118
+ loopMaxIterations: z.natural().default(0),
101
119
  };
102
120
  export const AutoContinueSchema = z.object(settingsFields);
103
121
 
@@ -188,6 +206,7 @@ export function apply(ctx: Context, config?: AutoContinueEntryConfig): void {
188
206
  recoveryAttempts: runner.recentRecoveryAttempts(),
189
207
  sessionPolicy: {
190
208
  modes: config.sessionModes,
209
+ inheritedModes: runner.inheritedSubagentModes(),
191
210
  defaultMode: config.resumeCompletedTurns ? 'loop' : 'recover',
192
211
  paused: config.paused,
193
212
  writable: writableSettings() !== undefined,
@@ -222,9 +241,15 @@ export function apply(ctx: Context, config?: AutoContinueEntryConfig): void {
222
241
  res.write(data);
223
242
  };
224
243
  sseClients.add(send);
225
- const close = () => { res.end(); };
244
+ // Comment frames keep idle connections alive through proxies, sleep and security software (#86).
245
+ const heartbeat = setInterval(() => {
246
+ try { res.write(': ping\n\n'); } catch { /* the close handler cleans up */ }
247
+ }, BRIDGE_HEARTBEAT_MS);
248
+ heartbeat.unref?.();
249
+ const close = () => { clearInterval(heartbeat); res.end(); };
226
250
  closeClients.add(close);
227
251
  req.on('close', () => {
252
+ clearInterval(heartbeat);
228
253
  sseClients.delete(send);
229
254
  closeClients.delete(close);
230
255
  });
@@ -6,17 +6,30 @@
6
6
  */
7
7
  import type { SessionEvent, SessionId } from '@deepseek-ai/dsh-session/types';
8
8
 
9
+ export const AUTO_CONTINUE_SOURCE_KIND = 'plugin:dsh-client-auto-continue';
10
+
11
+ declare module '@deepseek-ai/dsh-llm' {
12
+ interface MessageSourceMap {
13
+ 'plugin:dsh-client-auto-continue': { kind: typeof AUTO_CONTINUE_SOURCE_KIND };
14
+ }
15
+ }
16
+
9
17
  /** Supported UI/config locales; missing and unsupported values use English. */
10
- export type AutoContinueLocale = 'en' | 'zh';
18
+ export type AutoContinueLocale = 'en' | 'zh' | 'ru';
11
19
 
12
20
  export function resolveLocale(locale: unknown): AutoContinueLocale {
13
- return typeof locale === 'string' && /^zh(?:-|$)/i.test(locale) ? 'zh' : 'en';
21
+ if (typeof locale !== 'string') return 'en';
22
+ if (/^zh(?:-|$)/i.test(locale)) return 'zh';
23
+ if (/^ru(?:-|$)/i.test(locale)) return 'ru';
24
+ return 'en';
14
25
  }
15
26
 
16
27
  export type SessionMode = 'default' | 'off' | 'recover' | 'loop';
17
28
 
18
29
  export interface SessionPolicy {
19
30
  modes: Record<string, SessionMode>;
31
+ /** Modes a child inherits from its main conversation, keyed by child id. */
32
+ inheritedModes?: Record<string, SessionMode>;
20
33
  defaultMode: 'recover' | 'loop';
21
34
  paused: boolean;
22
35
  writable: boolean;
@@ -58,18 +71,37 @@ export const LOCALIZED_TEXT_DEFAULTS = {
58
71
  loopText:
59
72
  '(You may be stuck in a loop. Stop repeating the last action and continue with a different approach.)',
60
73
  },
74
+ ru: {
75
+ continueText: 'Продолжай',
76
+ continueTextMaxTokens: 'Продолжай',
77
+ continueTextSilent:
78
+ 'Продолжай. Предыдущий ход закончился только внутренним рассуждением: ни ответа, ни вызова инструмента, поэтому пользователь ничего не увидел. Каждый ход должен заканчиваться вызовом инструмента или видимым ответом.',
79
+ continueTextLoop: 'Продолжай',
80
+ continueTextInterrupted:
81
+ 'Продолжай. Хост перезапустился, пока предыдущий ход ещё выполнялся; вызовы инструментов, незавершённые на момент перезапуска, записаны с неизвестным результатом. Продолжай с места остановки, проверяя внешнее состояние перед повтором действий с возможными побочными эффектами.',
82
+ guardPendingText:
83
+ '(Предыдущий инструмент «{tool}», возможно, не завершился. Проверь его состояние перед продолжением и не запускай его повторно.)',
84
+ guardDoneText:
85
+ '(Предыдущий инструмент «{tool}» завершился успешно. Результат: {result}; не запускай его повторно, продолжай с этого места.)',
86
+ loopText:
87
+ '(Похоже, ты застрял в цикле. Перестань повторять последнее действие и продолжай другим способом.)',
88
+ },
61
89
  } as const satisfies Record<AutoContinueLocale, Record<string, string>>;
62
90
 
63
91
  /** The `auto-continue` settings section (all fields optional on the wire; the host schema carries defaults). */
64
92
  export interface AutoContinueSettings {
65
93
  /** Active browser/UI locale mirrored by the client. */
66
94
  locale?: AutoContinueLocale;
95
+ /** Send continue messages with the plugin source instead of the legacy user source. */
96
+ usePluginSource?: boolean;
67
97
  /** Text automatically sent after an interruption. */
68
98
  continueText?: string;
69
99
  /** Text sent when the output token ceiling is reached (same placeholders as `continueText`). */
70
100
  continueTextMaxTokens?: string;
71
101
  /** Resume observed model activity that completes without visible output. */
72
102
  resumeSilentTurns?: boolean;
103
+ /** Resume interrupted subagent sessions when their main conversation has auto-continue enabled. Subagents never enter the autonomous loop. */
104
+ resumeSubagentSessions?: boolean;
73
105
  /** Autonomous mode: hand the thread back to the agent after every completed turn, looping until the user stops it. The consecutive-failure cap only throttles failures, never successful completions. */
74
106
  resumeCompletedTurns?: boolean;
75
107
  /** Text sent to resume a silent turn (same placeholders as `continueText`). */
@@ -128,6 +160,18 @@ export interface AutoContinueSettings {
128
160
  loopRepeatText?: number;
129
161
  /** Text sent after the loop guard cancels and restarts a turn (supports {tool}). */
130
162
  loopText?: string;
163
+ /** Recover child (subagent / Agent Teams) sessions that a restart interrupted by waking their root session once. */
164
+ resumeInterruptedChildren?: boolean;
165
+ /** Re-arm a goal that a restart left `active` but `disarmed`, when its own session is resumed. */
166
+ resumeGoals?: boolean;
167
+ /** Also resume goals the user explicitly paused. Off by default: pausing is a human decision. */
168
+ resumePausedGoals?: boolean;
169
+ /** Hold network-error recoveries while the host is offline; waiting does not consume the retry budget. */
170
+ pauseWhenOffline?: boolean;
171
+ /** How often (ms) a held recovery re-checks connectivity. */
172
+ offlineCheckMs?: number;
173
+ /** Autonomous-loop round cap per session; 0 means unlimited. Resets when the user sends a message or turns the loop back on. */
174
+ loopMaxIterations?: number;
131
175
  }
132
176
 
133
177
  /** Fully resolved configuration (built-in defaults + user overrides). */
@@ -137,7 +181,9 @@ export type AutoContinueConfig = Required<AutoContinueSettings>;
137
181
  export const DEFAULT_CONFIG: AutoContinueConfig = {
138
182
  locale: 'en',
139
183
  ...LOCALIZED_TEXT_DEFAULTS.en,
184
+ usePluginSource: false,
140
185
  resumeSilentTurns: true,
186
+ resumeSubagentSessions: false,
141
187
  resumeCompletedTurns: false,
142
188
  continueTextLoop: '',
143
189
  guardTools: true,
@@ -162,6 +208,12 @@ export const DEFAULT_CONFIG: AutoContinueConfig = {
162
208
  loopShortCount: 12,
163
209
  loopRepeatText: 4,
164
210
  loopToolRepeat: 5,
211
+ resumeInterruptedChildren: false,
212
+ resumeGoals: false,
213
+ resumePausedGoals: false,
214
+ pauseWhenOffline: true,
215
+ offlineCheckMs: 15000,
216
+ loopMaxIterations: 0,
165
217
  };
166
218
 
167
219
  function numberOr(value: unknown, fallback: number): number {
@@ -207,9 +259,11 @@ export function resolveConfig(section: AutoContinueSettings | undefined): AutoCo
207
259
  : localized.guardDoneText;
208
260
  return {
209
261
  locale,
262
+ usePluginSource: booleanOr(value.usePluginSource, DEFAULT_CONFIG.usePluginSource),
210
263
  continueText: text,
211
264
  continueTextMaxTokens: maxTokensText,
212
265
  resumeSilentTurns: booleanOr(value.resumeSilentTurns, DEFAULT_CONFIG.resumeSilentTurns),
266
+ resumeSubagentSessions: booleanOr(value.resumeSubagentSessions, DEFAULT_CONFIG.resumeSubagentSessions),
213
267
  resumeCompletedTurns: booleanOr(value.resumeCompletedTurns, DEFAULT_CONFIG.resumeCompletedTurns),
214
268
  continueTextSilent: silentText,
215
269
  continueTextLoop: loopText,
@@ -246,6 +300,15 @@ export function resolveConfig(section: AutoContinueSettings | undefined): AutoCo
246
300
  typeof value.loopText === 'string' && value.loopText.trim() !== ''
247
301
  ? value.loopText
248
302
  : localized.loopText,
303
+ resumeInterruptedChildren: booleanOr(
304
+ value.resumeInterruptedChildren,
305
+ DEFAULT_CONFIG.resumeInterruptedChildren,
306
+ ),
307
+ resumeGoals: booleanOr(value.resumeGoals, DEFAULT_CONFIG.resumeGoals),
308
+ resumePausedGoals: booleanOr(value.resumePausedGoals, DEFAULT_CONFIG.resumePausedGoals),
309
+ pauseWhenOffline: booleanOr(value.pauseWhenOffline, DEFAULT_CONFIG.pauseWhenOffline),
310
+ offlineCheckMs: Math.max(1000, numberOr(value.offlineCheckMs, DEFAULT_CONFIG.offlineCheckMs)),
311
+ loopMaxIterations: Math.floor(numberOr(value.loopMaxIterations, DEFAULT_CONFIG.loopMaxIterations)),
249
312
  };
250
313
  }
251
314
 
@@ -308,6 +371,16 @@ export function isTransientAgentError(message: string): boolean {
308
371
  return /network|timeout|timed ?out|econn|etimedout|socket|5\d\d|\b429\b|upstream|temporar/i.test(message);
309
372
  }
310
373
 
374
+ /**
375
+ * 失败是否属于连接层(断网/DNS/连接被拒/传输超时)。只有这类失败值得先做连通性
376
+ * 检测: 断网时续跑必然再失败一次, 白白消耗连续上限。5xx/429 等服务端错误不在此列。
377
+ */
378
+ export function isNetworkFailure(failure: FailureFacts): boolean {
379
+ if (/^(TRANSPORT|TIMEOUT|NETWORK|E(CONN|NET|HOST|AI_|NOTFOUND|TIMEDOUT|PIPE))/i.test(failure.code)) return true;
380
+ return /network|fetch failed|econn|enotfound|eai_again|etimedout|enetunreach|ehostunreach|enetdown|getaddrinfo|socket hang up|offline|could not reach|connection (reset|refused|closed)|timed? ?out/i
381
+ .test(failure.message);
382
+ }
383
+
311
384
  /** 通知上的一个操作按钮(action 标识 + 显示文案)。 */
312
385
  export interface NotifyAction {
313
386
  /** 稳定动作标识, 点击时经 onAction 回调传出。 */
@@ -920,6 +993,18 @@ export interface SessionState {
920
993
  loopRetryTimer: ReturnType<typeof setTimeout> | undefined;
921
994
  /** 冷却期恢复的延迟定时器(等到冷却结束再 schedule, 而不是丢弃这次恢复)。 */
922
995
  cooldownRetryTimer: ReturnType<typeof setTimeout> | undefined;
996
+ /** 断网挂起: 进行中的连通性检测令牌(取消时置空, 迟到的检测结果据此作废)。 */
997
+ offlineWait: object | undefined;
998
+ /** 断网挂起: 下一次连通性复检的定时器。 */
999
+ offlineTimer: ReturnType<typeof setTimeout> | undefined;
1000
+ /** 本次断网挂起开始的时间; 0 = 未挂起(只在挂起开始/结束时各记一次日志)。 */
1001
+ offlineSince: number;
1002
+ /** 自主循环已续跑的轮数(用户发消息或重新开启循环时清零)。 */
1003
+ loopIterations: number;
1004
+ /** 本轮循环上限提示已发出(每次触顶只提示一次)。 */
1005
+ loopCapNotified: boolean;
1006
+ /** 上次观察到的循环开关; 由关到开时清零轮数。 */
1007
+ loopEnabled: boolean | undefined;
923
1008
  }
924
1009
 
925
1010
  export const freshState = (): SessionState => ({
@@ -948,6 +1033,12 @@ export const freshState = (): SessionState => ({
948
1033
  loopFired: false,
949
1034
  loopRetryTimer: undefined,
950
1035
  cooldownRetryTimer: undefined,
1036
+ offlineWait: undefined,
1037
+ offlineTimer: undefined,
1038
+ offlineSince: 0,
1039
+ loopIterations: 0,
1040
+ loopCapNotified: false,
1041
+ loopEnabled: undefined,
951
1042
  });
952
1043
 
953
1044
 
@@ -983,7 +1074,7 @@ export function forgetPendingEcho(state: SessionState, messageId: string): void
983
1074
  export function isOurEcho(state: SessionState, event: SessionEvent): boolean {
984
1075
  if (event.type !== 'user/message') return false;
985
1076
  const message = event.data;
986
- if (message.source.kind !== 'user') return false;
1077
+ if (message.source.kind !== 'user' && message.source.kind !== AUTO_CONTINUE_SOURCE_KIND) return false;
987
1078
  if (state.pendingEchoMessageIds.size === 0) return false;
988
1079
  const now = Date.now();
989
1080
  prunePendingEchoMessageIds(state, now);