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
@@ -0,0 +1,126 @@
1
+ // Generate the README images in docs/: banners and the social preview. The
2
+ // workflow map is an Archify export (docs/auto-continue-workflow.*), not built here. Every SVG is standalone (system font stack, no external
3
+ // references). Run `npm run docs:assets`, then render the social preview PNG:
4
+ // rsvg-convert -w 1280 -h 640 docs/social-preview.svg -o docs/social-preview.png
5
+ import { writeFileSync } from 'node:fs';
6
+ import { dirname, join } from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+
9
+ const docs = join(dirname(fileURLToPath(import.meta.url)), '..', 'docs');
10
+ const FONT = "-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', 'PingFang SC', 'Microsoft YaHei', sans-serif";
11
+ const MONO = "ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace";
12
+
13
+ const esc = (text) => String(text).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
14
+ const write = (name, svg) => {
15
+ writeFileSync(join(docs, name), `${svg.trim()}\n`);
16
+ console.log(`wrote docs/${name}`);
17
+ };
18
+
19
+ // The mark: a circular arrow wrapped around a play triangle.
20
+ const mark = (color) => `
21
+ <path d="M49 17A24 24 0 1 0 56 38" fill="none" stroke="${color}" stroke-width="5" stroke-linecap="round"/>
22
+ <path d="M49 6v12H37" fill="none" stroke="${color}" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/>
23
+ <path d="M27 22l16 10-16 10Z" fill="${color}" stroke="${color}" stroke-width="2" stroke-linejoin="round"/>`;
24
+
25
+ const THEMES = {
26
+ light: { bg: '#f4f4f5', tile: '#e4e4e7', ink: '#24262b', muted: '#545961', rule: '#d4d4d8' },
27
+ dark: { bg: '#141414', tile: '#23262c', ink: '#f4f4f5', muted: '#b9bec8', rule: '#37393e' },
28
+ };
29
+
30
+ // ---------------------------------------------------------------- banners
31
+
32
+ const BANNER_COPY = {
33
+ en: {
34
+ desc: 'A DeepSeek Harness plugin by HsiangNianian. Recover interrupted sessions, at your own pace.',
35
+ tagline: 'Recover interrupted sessions, at your own pace.',
36
+ compact: 'Interrupted? Keep going.',
37
+ },
38
+ zh: {
39
+ desc: 'HsiangNianian 的 DeepSeek Harness 插件。恢复意外中断的会话,按你的节奏继续。',
40
+ tagline: '恢复意外中断的会话,按你的节奏继续。',
41
+ compact: '会话意外中断?接着来。',
42
+ },
43
+ ru: {
44
+ desc: 'Плагин DeepSeek Harness от HsiangNianian. Возвращает прерванные сессии к работе в вашем темпе.',
45
+ tagline: 'Возвращает прерванные сессии к работе.',
46
+ compact: 'Прервалось? Продолжаем.',
47
+ },
48
+ };
49
+
50
+ function banner(lang, themeName) {
51
+ const t = THEMES[themeName];
52
+ const c = BANNER_COPY[lang];
53
+ return `
54
+ <svg xmlns="http://www.w3.org/2000/svg" width="960" height="260" viewBox="0 0 960 260" role="img" lang="${lang}" aria-labelledby="title description">
55
+ <title id="title">dsh-auto-continue</title>
56
+ <desc id="description">${esc(c.desc)}</desc>
57
+ <style>
58
+ text { font-family: ${FONT}; }
59
+ .wordmark { font-size: 46px; font-weight: 650; letter-spacing: -1.5px; }
60
+ .tagline { font-size: 24px; }
61
+ .compact { display: none; }
62
+ @media (max-width: 520px) {
63
+ .eyebrow { font-size: 23px; letter-spacing: 0; }
64
+ .wordmark { font-size: 49px; }
65
+ .tagline { font-size: 32px; }
66
+ .credit { font-size: 25px; }
67
+ .full { display: none; }
68
+ .compact { display: inline; }
69
+ }
70
+ </style>
71
+ <rect width="960" height="260" rx="18" fill="${t.bg}"/>
72
+ <rect x="40" y="48" width="112" height="112" rx="28" fill="${t.tile}"/>
73
+ <g transform="translate(57 64) scale(1.25)">${mark(t.ink)}
74
+ </g>
75
+ <g fill="${t.ink}">
76
+ <text class="eyebrow" x="188" y="61" fill="${t.muted}" font-size="15" letter-spacing="1.6">DEEPSEEK HARNESS PLUGIN</text>
77
+ <text class="wordmark" x="185" y="118">dsh-auto-continue</text>
78
+ <text class="tagline full" x="188" y="163" fill="${t.muted}">${esc(c.tagline)}</text>
79
+ <text class="tagline compact" x="188" y="163" fill="${t.muted}">${esc(c.compact)}</text>
80
+ </g>
81
+ <path d="M40 200H920" stroke="${t.rule}"/>
82
+ <text class="credit" x="40" y="236" fill="${t.muted}" font-size="16">by HsiangNianian</text>
83
+ <!-- A broken thread joining back into one line. -->
84
+ <g fill="none" stroke="${t.muted}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
85
+ <path d="M700 230h44m12 0h3m12 0h3m12 0h126"/>
86
+ <path d="m902 224 10 6-10 6"/>
87
+ </g>
88
+ </svg>`;
89
+ }
90
+
91
+ for (const lang of ['en', 'zh', 'ru']) {
92
+ const suffix = lang === 'en' ? '' : `-${lang}`;
93
+ write(`banner${suffix}.svg`, banner(lang, 'light'));
94
+ write(`banner${suffix}-dark.svg`, banner(lang, 'dark'));
95
+ }
96
+
97
+ // ---------------------------------------------------------- social preview
98
+
99
+ write('social-preview.svg', `
100
+ <svg xmlns="http://www.w3.org/2000/svg" width="1280" height="640" viewBox="0 0 1280 640" role="img" lang="en" aria-labelledby="title">
101
+ <title id="title">dsh-auto-continue: recover interrupted DeepSeek Harness sessions</title>
102
+ <style>
103
+ text { font-family: ${FONT}; }
104
+ </style>
105
+ <rect width="1280" height="640" fill="${THEMES.dark.bg}"/>
106
+ <rect x="96" y="128" width="168" height="168" rx="42" fill="${THEMES.dark.tile}"/>
107
+ <g transform="translate(120 150) scale(1.9)">${mark(THEMES.dark.ink)}
108
+ </g>
109
+ <text x="320" y="160" fill="${THEMES.dark.muted}" font-size="22" letter-spacing="2.4">DEEPSEEK HARNESS PLUGIN</text>
110
+ <text x="316" y="240" fill="${THEMES.dark.ink}" font-size="74" font-weight="650" letter-spacing="-2">dsh-auto-continue</text>
111
+ <text x="320" y="300" fill="${THEMES.dark.muted}" font-size="32">Recover interrupted sessions, at your own pace.</text>
112
+ <g font-size="22" fill="${THEMES.dark.ink}">
113
+ <rect x="320" y="356" width="214" height="50" rx="25" fill="none" stroke="${THEMES.dark.rule}" stroke-width="2"/>
114
+ <text x="427" y="389" text-anchor="middle">Error recovery</text>
115
+ <rect x="550" y="356" width="214" height="50" rx="25" fill="none" stroke="${THEMES.dark.rule}" stroke-width="2"/>
116
+ <text x="657" y="389" text-anchor="middle">Startup scan</text>
117
+ <rect x="780" y="356" width="250" height="50" rx="25" fill="none" stroke="${THEMES.dark.rule}" stroke-width="2"/>
118
+ <text x="905" y="389" text-anchor="middle">Autonomous loop</text>
119
+ </g>
120
+ <path d="M96 520H1184" stroke="${THEMES.dark.rule}" stroke-width="2"/>
121
+ <text x="96" y="572" fill="${THEMES.dark.muted}" font-size="24">github.com/HsiangNianian/dsh-auto-continue</text>
122
+ <g fill="none" stroke="${THEMES.dark.muted}" stroke-width="3" stroke-linecap="round" stroke-linejoin="round">
123
+ <path d="M884 564h60m16 0h4m16 0h4m16 0h168"/>
124
+ <path d="m1172 556 12 8-12 8"/>
125
+ </g>
126
+ </svg>`);
@@ -1,35 +1,14 @@
1
1
  /**
2
- * Auto-continue glyph.
2
+ * Auto-continue glyph: a single-stroke infinity loop.
3
3
  *
4
- * Prefers the host's own icon so the composer label matches the surrounding
5
- * DSH chrome; older hosts without the primitives module get an equivalent
6
- * inline stroke icon. The icon stays visible when the label text is hidden at
7
- * narrow widths.
4
+ * Deliberately not the host's refresh icon. Refresh reads as "start over",
5
+ * auto-continue means "keep going without stopping" (#86). Drawn on a 16px grid
6
+ * with a 2px margin so both loops stay distinct at 14px.
8
7
  */
9
- import type { ComponentType } from 'react';
10
-
11
- interface IconProps {
12
- className?: string;
13
- }
14
-
15
- const primitives = (() => {
16
- try {
17
- return require('@deepseek-ai/dsh-client-ui-primitives') as {
18
- IconRefreshOutlineRegular?: ComponentType<IconProps>;
19
- };
20
- } catch {
21
- return {};
22
- }
23
- })();
24
-
25
- const HostRefresh = primitives.IconRefreshOutlineRegular;
26
-
27
8
  export function AutoContinueIcon() {
28
- if (HostRefresh) return <HostRefresh />;
29
9
  return (
30
- <svg className="dshAcComposerIconFallback" viewBox="0 0 16 16" aria-hidden="true">
31
- <path d="M13.25 8a5.25 5.25 0 1 1-1.54-3.71" />
32
- <path d="M13.25 3.1v3.3h-3.3" />
10
+ <svg className="dshAcGlyph" viewBox="0 0 16 16" aria-hidden="true">
11
+ <path d="M8 8C7 5.6 6.1 4.6 4.8 4.6C3.1 4.6 2 6.1 2 8C2 9.9 3.1 11.4 4.8 11.4C6.1 11.4 7 10.4 8 8C9 5.6 9.9 4.6 11.2 4.6C12.9 4.6 14 6.1 14 8C14 9.9 12.9 11.4 11.2 11.4C9.9 11.4 9 10.4 8 8Z" />
33
12
  </svg>
34
13
  );
35
14
  }
@@ -32,6 +32,8 @@ interface BridgeState {
32
32
  paused: PausedSessionView[];
33
33
  recoveryAttempts: RecoveryAttempt[];
34
34
  sessionPolicy?: SessionPolicy;
35
+ /** False while the SSE stream is down; the last known policy stays readable but not writable. */
36
+ connected: boolean;
35
37
  }
36
38
 
37
39
  interface BridgeNotice {
@@ -54,7 +56,7 @@ const EMPTY_STATS: DayStatsView = {
54
56
  byCode: {},
55
57
  };
56
58
 
57
- let state: BridgeState = { stats: EMPTY_STATS, paused: [], recoveryAttempts: [] };
59
+ let state: BridgeState = { stats: EMPTY_STATS, paused: [], recoveryAttempts: [], connected: false };
58
60
  const listeners = new Set<() => void>();
59
61
 
60
62
  /** 当前桥状态里的已暂停会话(卡片面板用)。 */
@@ -71,12 +73,17 @@ export function readRecoveryAttempts(): RecoveryAttempt[] {
71
73
  return state.recoveryAttempts;
72
74
  }
73
75
 
76
+ /** Last policy the host sent. It survives a bridge reconnect, so check {@link isBridgeConnected} before writing. */
74
77
  export function readSessionPolicy(): SessionPolicy | undefined {
75
78
  return state.sessionPolicy;
76
79
  }
77
80
 
81
+ export function isBridgeConnected(): boolean {
82
+ return state.connected;
83
+ }
84
+
78
85
  export async function setSessionMode(sessionId: string, mode: SessionMode): Promise<void> {
79
- if (!state.sessionPolicy?.writable) throw new Error('Session settings are unavailable');
86
+ if (!state.connected || !state.sessionPolicy?.writable) throw new Error('Session settings are unavailable');
80
87
  const response = await fetch('/api/auto-continue-action', {
81
88
  method: 'POST',
82
89
  headers: { 'content-type': 'application/json' },
@@ -129,6 +136,7 @@ function handleEvent(event: { type: string; notice?: BridgeNotice; stats?: DaySt
129
136
  sessionPolicy: policy && typeof policy.modes === 'object' && policy.modes !== null && !Array.isArray(policy.modes) &&
130
137
  (policy.defaultMode === 'recover' || policy.defaultMode === 'loop') && typeof policy.paused === 'boolean' && typeof policy.writable === 'boolean'
131
138
  ? policy : undefined,
139
+ connected: true,
132
140
  };
133
141
  for (const listener of listeners) listener();
134
142
  } else if (event.type === 'notice' && event.notice !== undefined) {
@@ -187,11 +195,19 @@ function showNotification(notice: BridgeNotice): void {
187
195
  export function startBridge(): () => void {
188
196
  let stopped = false;
189
197
  let controller: AbortController | undefined;
198
+ // A dropped stream (engine rebuild, sleep, a proxy closing an idle socket) keeps the
199
+ // last policy on screen so the composer does not flash to "off" while reconnecting (#86).
190
200
  const disconnected = () => {
191
- state = { ...state, sessionPolicy: undefined };
201
+ if (!state.connected) return;
202
+ state = { ...state, connected: false };
203
+ for (const listener of listeners) listener();
204
+ };
205
+ const reset = () => {
206
+ state = { ...state, sessionPolicy: undefined, connected: false };
192
207
  for (const listener of listeners) listener();
193
208
  };
194
- disconnected();
209
+ reset();
210
+ let failures = 0;
195
211
 
196
212
  const loop = async (): Promise<void> => {
197
213
  while (!stopped) {
@@ -199,6 +215,7 @@ export function startBridge(): () => void {
199
215
  try {
200
216
  const response = await fetch('/api/auto-continue-bridge', { signal: controller.signal });
201
217
  if (!response.ok || response.body === null) throw new Error(`bridge HTTP ${response.status}`);
218
+ failures = 0;
202
219
  const reader = response.body.getReader();
203
220
  const decoder = new TextDecoder();
204
221
  let buffer = '';
@@ -227,7 +244,10 @@ export function startBridge(): () => void {
227
244
  }
228
245
  if (!stopped) {
229
246
  disconnected();
230
- await new Promise((resolve) => setTimeout(resolve, 3000));
247
+ // The first retry is quick: most drops are the host rebuilding its engine.
248
+ const delay = failures === 0 ? 500 : 3000;
249
+ failures += 1;
250
+ await new Promise((resolve) => setTimeout(resolve, delay));
231
251
  }
232
252
  }
233
253
  };
@@ -236,6 +256,6 @@ export function startBridge(): () => void {
236
256
  return () => {
237
257
  stopped = true;
238
258
  controller?.abort();
239
- disconnected();
259
+ reset();
240
260
  };
241
261
  }
@@ -2,7 +2,6 @@ import { useEffect, useState } from 'react';
2
2
  import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
3
3
  import type { SnapshotStore } from './dsh-store-compat.ts';
4
4
  import { sessionMode, type SessionMode, type SessionPolicy } from '../shared/core.ts';
5
- import { NativeSwitch } from './native-switch.tsx';
6
5
  import { ModeMenu, type ModeMenuOption } from './mode-menu.tsx';
7
6
  import { AutoContinueIcon } from './auto-continue-icon.tsx';
8
7
  import { NativeToast, WarningIcon, hasNativeToast } from './native-toast.tsx';
@@ -10,6 +9,8 @@ import { NativeToast, WarningIcon, hasNativeToast } from './native-toast.tsx';
10
9
  export interface ComposerToggleState {
11
10
  visible: boolean;
12
11
  policy: SessionPolicy | undefined;
12
+ /** The bridge dropped; `policy` is the last known one and stays on screen, read-only. */
13
+ reconnecting: boolean;
13
14
  writable: boolean;
14
15
  saving: ReadonlySet<string>;
15
16
  failed: ReadonlySet<string>;
@@ -47,9 +48,16 @@ export function AutoContinueComposerToggle(props: PropsLocale<'auto-continue'> &
47
48
  const failed = state.failed.has(props.sessionId);
48
49
  const saving = state.saving.has(props.sessionId);
49
50
  const policy = state.policy;
50
- const mode = sessionMode(policy?.modes ?? {}, props.sessionId);
51
+ // A child with no mode of its own shows what it actually inherits; the host
52
+ // resolves that alongside the explicit modes so the control never reports the
53
+ // profile default while recovery is disabled by the main conversation.
54
+ const ownMode = sessionMode(policy?.modes ?? {}, props.sessionId);
55
+ const mode: SessionMode = ownMode === 'default'
56
+ ? policy?.inheritedModes?.[props.sessionId] ?? 'default'
57
+ : ownMode;
51
58
  const disabled = !policy || !state.writable || saving;
52
- const title = props.t(!policy ? 'composer.unavailable' : !state.writable ? 'chrome.readOnly' : saving ? 'composer.saving' : 'composer.scope');
59
+ const title = props.t(!policy ? 'composer.unavailable' : state.reconnecting ? 'composer.reconnecting'
60
+ : !state.writable ? 'chrome.readOnly' : saving ? 'composer.saving' : 'composer.scope');
53
61
  const modeName = props.t(`composer.${mode}`);
54
62
  const defaultName = policy
55
63
  ? `${props.t('composer.default')} (${props.t(`composer.${policy.defaultMode}`)})`
@@ -62,17 +70,20 @@ export function AutoContinueComposerToggle(props: PropsLocale<'auto-continue'> &
62
70
  { id: 'recover', label: props.t('composer.recover') },
63
71
  { id: 'loop', label: props.t('composer.loop') },
64
72
  ];
73
+ const enabled = !!policy && mode !== 'off';
74
+ // Turning on writes `default`, unless that would just inherit Off again (a child of an Off main chat).
75
+ const onMode: SessionMode = policy?.inheritedModes?.[props.sessionId] === 'off' ? 'recover' : 'default';
76
+ // One 28px icon switch plus a chevron-only mode menu: the mode name lives in the
77
+ // menu, the tooltip and the accessible name instead of taking composer width (#86).
65
78
  return (
66
79
  <div className="dshAcComposer" title={title} aria-busy={saving || undefined}>
67
80
  <span className="dshAcComposerCore">
68
- <span className="dshAcComposerLabel">
69
- <span className="dshAcComposerIcon" aria-hidden="true"><AutoContinueIcon /></span>
70
- <span className="dshAcComposerText">{props.t('composer.label')}</span>
71
- </span>
72
- <span className="dshAcSwitchTarget">
73
- <NativeSwitch checked={!!policy && mode !== 'off'} onChange={enabled => props.setMode(enabled ? 'default' : 'off')}
74
- disabled={disabled} label={props.t('composer.label')} title={title} />
75
- </span>
81
+ <button type="button" role="switch" className="dshAcIconBtn" data-state={enabled ? 'on' : 'off'}
82
+ data-stale={state.reconnecting || undefined} aria-checked={enabled}
83
+ aria-label={`${props.t('composer.label')}: ${fullModeLabel}`} title={`${modeTitle}\n${title}`}
84
+ disabled={disabled} onClick={() => props.setMode(enabled ? 'off' : onMode)}>
85
+ <AutoContinueIcon />
86
+ </button>
76
87
  <ModeMenu mode={mode} options={options} label={modeName}
77
88
  ariaLabel={modeTitle} selectLabel={props.t('composer.mode')} title={modeTitle}
78
89
  disabled={disabled} onChange={props.setMode} />
@@ -20,7 +20,7 @@ import type {} from '@deepseek-ai/dsh-client-ui-settings/client';
20
20
  // Type-only: pulls the `settings.plugin.item` SlotMap merge.
21
21
  import type {} from '@deepseek-ai/dsh-client-ui-settings-plugins/client';
22
22
  import { resolveLocale, type AutoContinueSettings } from '../shared/core.ts';
23
- import { en, zh, type SettingsCardKey } from './locales.ts';
23
+ import { en, ru, zh, type SettingsCardKey } from './locales.ts';
24
24
  import {
25
25
  AutoContinueSettingsCard,
26
26
  AutoContinueSettingsCardController,
@@ -80,7 +80,11 @@ export {
80
80
  * @param ctx - client root context.
81
81
  */
82
82
  export function apply(ctx: ClientContext): void {
83
+ // The base package types `register()` dictionaries as the built-in `zh`/`en`
84
+ // pair only; further languages (here `ru`, added by a locale plugin at
85
+ // runtime) register one locale at a time, exactly as `addLanguage` allows.
83
86
  ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'auto-continue: dictionaries');
87
+ ctx.effect(() => ctx.locale.register(NS, 'ru', ru), 'auto-continue: russian dictionary');
84
88
  ctx.effect(() => startBridge(), 'auto-continue: host bridge');
85
89
 
86
90
  // Cordis waits for ALL top-level dependencies. Requiring settingsScope here