dsh-client-auto-continue 0.15.0 → 0.17.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 (46) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +37 -21
  3. package/README.zh.md +34 -21
  4. package/docs/releases/v0.16.0.md +75 -0
  5. package/docs/releases/v0.17.0.md +62 -0
  6. package/docs/screenshots/01-settings-section.png +0 -0
  7. package/docs/screenshots/01-settings-section.zh.png +0 -0
  8. package/docs/screenshots/02-settings-card.png +0 -0
  9. package/docs/screenshots/02-settings-card.zh.png +0 -0
  10. package/docs/screenshots/07-card-panels.png +0 -0
  11. package/docs/screenshots/07-card-panels.zh.png +0 -0
  12. package/docs/screenshots/08-composer-toggle.png +0 -0
  13. package/docs/screenshots/08-composer-toggle.zh.png +0 -0
  14. package/docs/screenshots/README.md +8 -8
  15. package/docs/third-party-notices.md +19 -0
  16. package/lib/client.js +474 -133
  17. package/lib/client.js.map +4 -4
  18. package/lib/index.js +7560 -117
  19. package/lib/types/client/auto-continue-icon.d.ts +1 -0
  20. package/lib/types/client/bridge.d.ts +3 -1
  21. package/lib/types/client/composer-toggle.d.ts +6 -4
  22. package/lib/types/client/index.d.ts +1 -1
  23. package/lib/types/client/locales.d.ts +11 -8
  24. package/lib/types/client/mode-menu.d.ts +19 -0
  25. package/lib/types/client/native-toast.d.ts +17 -0
  26. package/lib/types/client/settings-card.d.ts +6 -5
  27. package/lib/types/host/engine.d.ts +2 -0
  28. package/lib/types/host/settings-migration.d.ts +14 -0
  29. package/lib/types/index.d.ts +14 -8
  30. package/lib/types/shared/core.d.ts +13 -1
  31. package/locale/en.json +6 -0
  32. package/locale/zh.json +6 -0
  33. package/package.json +24 -14
  34. package/src/client/auto-continue-icon.tsx +35 -0
  35. package/src/client/bridge.ts +35 -4
  36. package/src/client/composer-toggle.tsx +66 -14
  37. package/src/client/index.ts +4 -2
  38. package/src/client/locales.ts +32 -26
  39. package/src/client/mode-menu.tsx +110 -0
  40. package/src/client/native-toast.tsx +44 -0
  41. package/src/client/settings-card.tsx +156 -41
  42. package/src/client/styles.ts +61 -37
  43. package/src/host/engine.ts +54 -12
  44. package/src/host/settings-migration.ts +117 -0
  45. package/src/index.ts +63 -12
  46. package/src/shared/core.ts +23 -1
@@ -4,13 +4,15 @@
4
4
  * Since 0.8.0 the auto-continue ENGINE runs inside the host process (single
5
5
  * instance — see src/host/engine.ts), so this half only:
6
6
  * - registers the `auto-continue` settings card in the available plugin UI,
7
- * - adds a native composer switch backed by the same global pause setting,
7
+ * - adds a per-session composer switch and mode menu backed by host settings,
8
8
  * - subscribes to the host status bridge (SSE) and shows browser
9
9
  * notifications with action buttons (Resume now / Pause 1h) via the bridge
10
10
  * action endpoint,
11
11
  * - feeds the card's stats / paused-sessions panels from the bridge state.
12
12
  */
13
13
  import type { Context as ClientContext } from '@deepseek-ai/cordis';
14
+ // Type-only: the slot service is declared by the renderer in newer DSH SDKs.
15
+ import type {} from '@deepseek-ai/dsh-client-ui-renderer/client';
14
16
  // Type-only: pulls the locale plugin's Context merge (ctx.locale).
15
17
  import type {} from '@deepseek-ai/dsh-client-locale/client';
16
18
  // Type-only: pulls the settings-surface SlotMap merge and ctx.settingsScope.
@@ -152,7 +154,7 @@ function mountSettings(ctx: ClientContext, scope: SettingsScope<AutoContinueSett
152
154
  name: 'conversation.input.left',
153
155
  id: 'auto-continue',
154
156
  locale: NS,
155
- inject: () => controller.injectComposer(),
157
+ inject: (sessionId) => controller.injectComposer(sessionId),
156
158
  },
157
159
  AutoContinueComposerToggle,
158
160
  ),
@@ -7,14 +7,6 @@ import { LOCALIZED_TEXT_DEFAULTS } from '../shared/core.ts';
7
7
 
8
8
  /** 简体中文词典(键集的事实来源)。 */
9
9
  export const zh = {
10
- 'card.title': '自动继续',
11
- 'card.description': '恢复意外中断的会话,按你的节奏继续。',
12
- 'repo.star': '觉得好用的话,点个 Star 吧',
13
- 'repo.note': 'HsiangNianian 的开源插件,也欢迎反馈和 PR。',
14
- 'repo.link': 'GitHub 仓库',
15
- 'repo.aria': '在新标签页打开 HsiangNianian/dsh-auto-continue 的 GitHub 仓库',
16
- 'chrome.enabled': '已启用',
17
- 'chrome.paused': '已暂停',
18
10
  'chrome.saved': '所有更改已保存',
19
11
  'notification.title': '自动继续设置',
20
12
  'notification.enabled': '设置已保存,浏览器通知已开启。',
@@ -24,6 +16,9 @@ export const zh = {
24
16
  'notification.unsupported': '设置已保存,当前浏览器不支持通知。',
25
17
  'notification.failed': '设置已保存,但浏览器通知未能发出。请检查网站和系统的通知权限。',
26
18
  'chrome.categories': '设置类别',
19
+ 'repo.star': '觉得好用的话,点个 Star 吧',
20
+ 'repo.link': 'GitHub 仓库',
21
+ 'repo.aria': '在新标签页打开 HsiangNianian/dsh-auto-continue 的 GitHub 仓库',
27
22
  'category.general.title': '常规',
28
23
  'category.general.description': '控制自动继续的启停、显示和通知。',
29
24
  'category.recovery.title': '重试策略',
@@ -36,11 +31,18 @@ export const zh = {
36
31
  'category.safety.description': '避免重复执行工具,识别并打断无效循环。',
37
32
  'category.status.title': '状态与日志',
38
33
  'category.status.description': '查看活动记录与暂停的会话。',
39
- 'field.paused': '自动继续',
34
+ 'field.paused': '全局启用自动继续',
40
35
  'field.showComposerToggle': '在会话区显示自动继续开关',
41
- 'field.showComposerToggleHint': '默认显示。隐藏开关不会暂停自动继续;点击保存后生效。',
36
+ 'field.showComposerToggleHint': '默认显示。隐藏控件不会改变会话模式;点击保存后生效。',
42
37
  'composer.label': '自动继续',
43
- 'composer.scope': '控制当前配置下所有会话的自动继续,修改立即保存。',
38
+ 'composer.mode': '自动继续模式',
39
+ 'composer.scope': '只控制当前会话,立即保存并同步到其他标签页。关闭后也不再自动打断循环。',
40
+ 'composer.default': '跟随默认',
41
+ 'composer.off': '关闭',
42
+ 'composer.recover': '仅故障恢复',
43
+ 'composer.loop': '自主循环',
44
+ 'composer.paused': '全局已暂停',
45
+ 'composer.unavailable': '等待宿主连接',
44
46
  'composer.saving': '正在保存自动继续设置…',
45
47
  'composer.saveFailed': '保存失败,请重试',
46
48
  'field.pausedHint': '恢复意外中断的会话。关闭并保存后,全局暂停恢复并取消已排队的继续。循环守卫独立运行;如需停止自动打断,请同时关闭循环守卫。',
@@ -52,8 +54,8 @@ export const zh = {
52
54
  'default.continueTextMaxTokens': LOCALIZED_TEXT_DEFAULTS.zh.continueTextMaxTokens,
53
55
  'field.resumeSilentTurns': '续跑无输出回合',
54
56
  'field.resumeSilentTurnsHint': '已观察到模型活动但没有可见输出时续跑;不把空回合、图片或扩展内容误判为静默,冷却与连续上限照常生效。',
55
- 'field.resumeCompletedTurns': '自主循环(每个回合后都续跑)',
56
- 'field.resumeCompletedTurnsHint': '正常完成后经过宽限期自动续跑,不受恢复冷却和次数上限限制;仅有推理或显式无输出的回合仍消耗重试预算。暂停或关闭该选项可停止后续接力,手动停止或发送消息会取消当前待发送的继续提示。',
57
+ 'field.resumeCompletedTurns': '默认会话模式',
58
+ 'field.resumeCompletedTurnsHint': '用于没有单独设置模式的会话。仅故障恢复不会接力正常完成的回合;自主循环会在正常完成后继续。无输出和失败回合仍受重试预算约束。',
57
59
  'field.continueTextLoop': '自主循环的继续文本',
58
60
  'field.continueTextLoopHint': '自主循环每次续跑时发送的文本。',
59
61
  'default.continueTextLoop': LOCALIZED_TEXT_DEFAULTS.zh.continueTextLoop,
@@ -142,6 +144,7 @@ export const zh = {
142
144
  'chrome.expand': '展开设置',
143
145
  'chrome.unsaved': '未保存',
144
146
  'chrome.readOnly': '当前部署的设置只读。',
147
+ 'chrome.unavailable': '设置暂不可用。',
145
148
  'chrome.saveFailed': '部署未接受这些值, 已保留供你修改。',
146
149
  'chrome.discard': '放弃',
147
150
  'chrome.saving': '保存中…',
@@ -159,14 +162,6 @@ export type SettingsCardKey = keyof typeof zh;
159
162
 
160
163
  /** English dictionary, checked complete against the zh key set. */
161
164
  export const en: Record<SettingsCardKey, string> = {
162
- 'card.title': 'Auto continue',
163
- 'card.description': 'Resume interrupted sessions, at your pace.',
164
- 'repo.star': 'Finding it useful? Leave a Star',
165
- 'repo.note': 'By HsiangNianian. Feedback and PRs welcome.',
166
- 'repo.link': 'GitHub repo',
167
- 'repo.aria': 'Open HsiangNianian/dsh-auto-continue on GitHub in a new tab',
168
- 'chrome.enabled': 'Enabled',
169
- 'chrome.paused': 'Paused',
170
165
  'chrome.saved': 'All changes saved',
171
166
  'notification.title': 'Auto-continue settings',
172
167
  'notification.enabled': 'Settings saved. Browser notifications are on.',
@@ -176,6 +171,9 @@ export const en: Record<SettingsCardKey, string> = {
176
171
  'notification.unsupported': 'Settings saved. This browser does not support notifications.',
177
172
  'notification.failed': 'Settings saved, but the notification could not be sent. Check notification permissions for this site and your system.',
178
173
  'chrome.categories': 'Settings categories',
174
+ 'repo.star': 'Finding it useful? Leave a Star',
175
+ 'repo.link': 'GitHub repo',
176
+ 'repo.aria': 'Open HsiangNianian/dsh-auto-continue on GitHub in a new tab',
179
177
  'category.general.title': 'General',
180
178
  'category.general.description': 'Control automatic recovery, visibility, and notifications.',
181
179
  'category.recovery.title': 'Retry strategy',
@@ -188,11 +186,18 @@ export const en: Record<SettingsCardKey, string> = {
188
186
  'category.safety.description': 'Avoid duplicate tool actions and break unproductive loops.',
189
187
  'category.status.title': 'Status and logs',
190
188
  'category.status.description': 'View activity and paused sessions.',
191
- 'field.paused': 'Auto-continue',
189
+ 'field.paused': 'Enable auto-continue globally',
192
190
  'field.showComposerToggle': 'Show auto-continue switch in the composer',
193
- 'field.showComposerToggleHint': 'Shown by default. Hiding the switch does not pause auto-continue. Click Save to apply.',
191
+ 'field.showComposerToggleHint': 'Shown by default. Hiding the control does not change session modes. Click Save to apply.',
194
192
  'composer.label': 'Auto-continue',
195
- 'composer.scope': 'Controls auto-continue for all sessions in this profile. Changes save immediately.',
193
+ 'composer.mode': 'Auto-continue mode',
194
+ 'composer.scope': 'Only affects this session. Saved immediately and synced across tabs. Off also disables loop-guard interruptions here.',
195
+ 'composer.default': 'Follow default',
196
+ 'composer.off': 'Off',
197
+ 'composer.recover': 'Recovery only',
198
+ 'composer.loop': 'Autonomous loop',
199
+ 'composer.paused': 'Globally paused',
200
+ 'composer.unavailable': 'Waiting for host',
196
201
  'composer.saving': 'Saving auto-continue setting…',
197
202
  'composer.saveFailed': 'Could not save. Try again.',
198
203
  '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.',
@@ -204,8 +209,8 @@ export const en: Record<SettingsCardKey, string> = {
204
209
  'default.continueTextMaxTokens': LOCALIZED_TEXT_DEFAULTS.en.continueTextMaxTokens,
205
210
  'field.resumeSilentTurns': 'Resume silent turns',
206
211
  '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.',
207
- 'field.resumeCompletedTurns': 'Autonomous loop (continue after every turn)',
208
- '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.',
212
+ 'field.resumeCompletedTurns': 'Default session mode',
213
+ 'field.resumeCompletedTurnsHint': 'Applies to sessions without their own mode. Recovery only leaves normal completions alone; autonomous loop continues after them. Silent and failed turns still consume the retry budget.',
209
214
  'field.continueTextLoop': 'Continue text (autonomous loop)',
210
215
  'field.continueTextLoopHint': 'Text sent on each autonomous-loop continuation.',
211
216
  'default.continueTextLoop': LOCALIZED_TEXT_DEFAULTS.en.continueTextLoop,
@@ -294,6 +299,7 @@ export const en: Record<SettingsCardKey, string> = {
294
299
  'chrome.expand': 'Show settings',
295
300
  'chrome.unsaved': 'Unsaved',
296
301
  'chrome.readOnly': 'This deployment stores settings read-only.',
302
+ 'chrome.unavailable': 'Settings are unavailable.',
297
303
  'chrome.saveFailed': 'The deployment did not accept these values; they were left for you to correct.',
298
304
  'chrome.discard': 'Discard',
299
305
  'chrome.saving': 'Saving…',
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Composer mode menu.
3
+ *
4
+ * Uses the host's own `Menu` and chevron primitives whenever the running DSH
5
+ * exposes them, so the control looks and behaves like the composer's other
6
+ * dropdowns (workspace permission, model picker). Legacy hosts, and the unit
7
+ * tests' minimal module fixture, fall back to a native `<select>` over the
8
+ * same compact label.
9
+ */
10
+ import { useEffect, useState, type ComponentType, type ReactNode } from 'react';
11
+ import { isSessionMode, type SessionMode } from '../shared/core.ts';
12
+
13
+ export interface ModeMenuOption {
14
+ id: SessionMode;
15
+ label: string;
16
+ }
17
+
18
+ interface MenuProps {
19
+ open: boolean;
20
+ anchor: ReactNode;
21
+ items: readonly ModeMenuOption[];
22
+ selectedId?: string;
23
+ onSelect?: (id: string) => void;
24
+ onClose?: () => void;
25
+ side?: 'top' | 'bottom';
26
+ portal?: boolean;
27
+ }
28
+
29
+ interface ChevronProps {
30
+ className?: string;
31
+ }
32
+
33
+ const primitives = (() => {
34
+ try {
35
+ return require('@deepseek-ai/dsh-client-ui-primitives') as {
36
+ Menu?: ComponentType<MenuProps>;
37
+ IconChevronDownOutlineRegular?: ComponentType<ChevronProps>;
38
+ };
39
+ } catch {
40
+ return {};
41
+ }
42
+ })();
43
+
44
+ const HostMenu = primitives.Menu;
45
+ const HostChevron = primitives.IconChevronDownOutlineRegular;
46
+
47
+ function ChevronDown() {
48
+ if (HostChevron) return <HostChevron />;
49
+ return (
50
+ <svg className="dshAcModeChevronFallback" viewBox="0 0 16 16" aria-hidden="true">
51
+ <path d="m4.5 6.25 3.5 3.5 3.5-3.5" />
52
+ </svg>
53
+ );
54
+ }
55
+
56
+ export interface ModeMenuProps {
57
+ mode: SessionMode;
58
+ options: readonly ModeMenuOption[];
59
+ /** Short label shown on the trigger, e.g. 跟随默认. */
60
+ label: string;
61
+ /** Accessible name including the resolved mode, e.g. 自动继续模式: 跟随默认 (仅故障恢复). */
62
+ ariaLabel: string;
63
+ /** Plain menu name used by the legacy select fallback. */
64
+ selectLabel: string;
65
+ title: string;
66
+ disabled: boolean;
67
+ onChange: (mode: SessionMode) => void;
68
+ }
69
+
70
+ export function ModeMenu(props: ModeMenuProps) {
71
+ const [open, setOpen] = useState(false);
72
+ const expanded = open && !props.disabled;
73
+
74
+ useEffect(() => {
75
+ if (props.disabled) setOpen(false);
76
+ }, [props.disabled]);
77
+
78
+ const choose = (id: string) => {
79
+ setOpen(false);
80
+ if (isSessionMode(id) && id !== props.mode) props.onChange(id);
81
+ };
82
+
83
+ if (HostMenu) {
84
+ return (
85
+ <HostMenu open={expanded} side="top" portal
86
+ items={props.options} selectedId={props.mode}
87
+ onSelect={choose} onClose={() => setOpen(false)}
88
+ anchor={
89
+ <button type="button" className="dshAcModeTrigger" disabled={props.disabled}
90
+ aria-label={props.ariaLabel} aria-haspopup="menu" aria-expanded={expanded}
91
+ title={props.title} onClick={() => setOpen(value => !value)}>
92
+ <span className="dshAcModeTriggerLabel">{props.label}</span>
93
+ <span className="dshAcModeChevron" data-open={expanded} aria-hidden="true"><ChevronDown /></span>
94
+ </button>
95
+ } />
96
+ );
97
+ }
98
+
99
+ return (
100
+ <span className="dshAcModeMenu" data-disabled={props.disabled} title={props.title}>
101
+ <span className="dshAcModeTriggerLabel">{props.label}</span>
102
+ <span className="dshAcModeChevron" aria-hidden="true"><ChevronDown /></span>
103
+ <select className="dshAcComposerSelect" aria-label={props.selectLabel} disabled={props.disabled}
104
+ value={props.mode}
105
+ onChange={event => { if (isSessionMode(event.target.value)) props.onChange(event.target.value); }}>
106
+ {props.options.map(option => <option key={option.id} value={option.id}>{option.label}</option>)}
107
+ </select>
108
+ </span>
109
+ );
110
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * DSH toast bridge.
3
+ *
4
+ * The composer reports a failed session-mode save with the host's own toast
5
+ * instead of inline red text that shifts the input row. Hosts without the
6
+ * primitive (older DSH, or the unit-test fixture) keep the inline fallback.
7
+ */
8
+ import type { ComponentType, ReactNode } from 'react';
9
+
10
+ export interface ToastProps {
11
+ text: string;
12
+ icon?: ReactNode;
13
+ tone?: 'success';
14
+ onDone?: () => void;
15
+ }
16
+
17
+ interface IconProps {
18
+ className?: string;
19
+ }
20
+
21
+ const primitives = (() => {
22
+ try {
23
+ return require('@deepseek-ai/dsh-client-ui-primitives') as {
24
+ Toast?: ComponentType<ToastProps>;
25
+ IconWarningOutlineRegular?: ComponentType<IconProps>;
26
+ };
27
+ } catch {
28
+ return {};
29
+ }
30
+ })();
31
+
32
+ export const NativeToast = primitives.Toast;
33
+ export const hasNativeToast = typeof NativeToast === 'function';
34
+
35
+ export function WarningIcon() {
36
+ const Icon = primitives.IconWarningOutlineRegular;
37
+ if (Icon) return <Icon />;
38
+ return (
39
+ <svg className="dshAcToastIcon" viewBox="0 0 16 16" aria-hidden="true">
40
+ <path d="M8 2.3 14.3 13H1.7L8 2.3Z" />
41
+ <path d="M8 6.2v3.1M8 11.8v.1" />
42
+ </svg>
43
+ );
44
+ }
@@ -7,9 +7,10 @@
7
7
  * configuration section; styles live in `styles.ts` and use the DSH design
8
8
  * tokens so the card follows the active theme.
9
9
  */
10
- import { useEffect, useId, useState } from 'react';
10
+ import { useEffect, useId, useState, type ReactNode } from 'react';
11
11
  import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
12
12
  import { DEFAULT_CONFIG, type AutoContinueSettings } from './engine.ts';
13
+ import type { SessionMode } from '../shared/core.ts';
13
14
  import type { ComposerToggleFace, ComposerToggleState } from './composer-toggle.tsx';
14
15
  import { NativeSwitch } from './native-switch.tsx';
15
16
  import { createSnapshotStore, type SettingsScope, type SnapshotStore } from './dsh-store-compat.ts';
@@ -17,7 +18,9 @@ import {
17
18
  pausedSessions,
18
19
  readTodayStats,
19
20
  readRecoveryAttempts,
21
+ readSessionPolicy,
20
22
  resetTodayStats,
23
+ setSessionMode,
21
24
  subscribeBridge,
22
25
  unpauseSession,
23
26
  } from './bridge.ts';
@@ -39,6 +42,40 @@ import { prepareSettingsNotification, showSettingsNotification } from './setting
39
42
  // style bookkeeping (HMR) owns them.
40
43
  injectStyles();
41
44
 
45
+ /**
46
+ * Native plugin-settings primitives. Older hosts (and the unit-test fixture)
47
+ * do not export them; the legacy hand-built card stays as the fallback.
48
+ */
49
+ const nativeSettings = (() => {
50
+ try {
51
+ return require('@deepseek-ai/dsh-client-ui-primitives') as {
52
+ SettingsForm?: React.ComponentType<{
53
+ labels: { save: string; saving: string; saveFailed: string; readOnly: string; unavailable: string };
54
+ state: CardShell;
55
+ onSave: () => void;
56
+ onDiscard: () => void;
57
+ children: ReactNode;
58
+ }>;
59
+ SettingsValueField?: React.ComponentType<Record<string, unknown>>;
60
+ SegmentedControl?: React.ComponentType<{
61
+ id?: string;
62
+ options: ReadonlyArray<{ value: string; label: string }>;
63
+ value: string;
64
+ onChange: (value: string) => void;
65
+ label: string;
66
+ disabled?: boolean;
67
+ }>;
68
+ };
69
+ } catch {
70
+ return {};
71
+ }
72
+ })();
73
+
74
+ const NativeSettingsForm = nativeSettings.SettingsForm;
75
+ const NativeValueField = nativeSettings.SettingsValueField;
76
+ const NativeSegmentedControl = nativeSettings.SegmentedControl;
77
+ const hasNativeSettings = typeof NativeSettingsForm === 'function' && typeof NativeValueField === 'function';
78
+
42
79
  /** What the auto-continue card renders. */
43
80
  export interface AutoContinueSettingsCardState extends CardShell {
44
81
  /** Committed global state; a staged edit does not pause the engine yet. */
@@ -91,8 +128,9 @@ export class AutoContinueSettingsCardController {
91
128
  private readonly form: CardForm<AutoContinueSettings>;
92
129
  private readonly store: SnapshotStore<AutoContinueSettingsCardState>;
93
130
  private readonly composer: SnapshotStore<ComposerToggleState>;
94
- private composerSaving = false;
95
- private composerFailed = false;
131
+ private readonly composerSaving = new Set<string>();
132
+ private readonly composerFailed = new Set<string>();
133
+ private readonly stopComposer: () => void;
96
134
  private disposed = false;
97
135
  private saveSequence = 0;
98
136
  private notificationFeedback: SettingsCardKey | undefined;
@@ -139,6 +177,7 @@ export class AutoContinueSettingsCardController {
139
177
  ]);
140
178
  this.store = this.form.bind(() => this.projection(), createSnapshotStore);
141
179
  this.composer = this.form.bind(() => this.composerProjection(), createSnapshotStore);
180
+ this.stopComposer = subscribeBridge(() => this.composer.set(this.composerProjection()));
142
181
  }
143
182
 
144
183
  private projection(): AutoContinueSettingsCardState {
@@ -208,33 +247,33 @@ export class AutoContinueSettingsCardController {
208
247
  this.store.set(this.projection());
209
248
  }
210
249
 
211
- injectComposer(): ComposerToggleFace {
212
- return { hooks: { autoContinueComposer: this.composer }, setEnabled: (enabled) => void this.setEnabled(enabled) };
250
+ injectComposer(sessionId: string): ComposerToggleFace {
251
+ return { hooks: { autoContinueComposer: this.composer }, sessionId, setMode: (mode) => void this.setMode(sessionId, mode) };
213
252
  }
214
253
 
215
254
  private composerProjection(): ComposerToggleState {
216
255
  const snapshot = this.scope.getSnapshot();
256
+ const policy = readSessionPolicy();
217
257
  return {
218
258
  visible: snapshot.status === 'ready' && (snapshot.value?.showComposerToggle ?? DEFAULT_CONFIG.showComposerToggle),
219
- enabled: !(snapshot.value?.paused ?? DEFAULT_CONFIG.paused),
220
- writable: canWriteSettings(snapshot),
221
- saving: this.composerSaving,
222
- failed: this.composerFailed,
259
+ policy,
260
+ writable: canWriteSettings(snapshot) && policy?.writable === true,
261
+ saving: new Set(this.composerSaving),
262
+ failed: new Set(this.composerFailed),
223
263
  };
224
264
  }
225
265
 
226
- private async setEnabled(enabled: boolean): Promise<void> {
227
- if (this.disposed || this.composerSaving || !this.composerProjection().writable) return;
228
- this.composerSaving = true;
229
- this.composerFailed = false;
266
+ private async setMode(sessionId: string, mode: SessionMode): Promise<void> {
267
+ if (this.disposed || !sessionId || this.composerSaving.has(sessionId) || !this.composerProjection().writable) return;
268
+ this.composerSaving.add(sessionId);
269
+ this.composerFailed.delete(sessionId);
230
270
  this.composer.set(this.composerProjection());
231
271
  try {
232
- const result = await this.scope.set('paused', !enabled);
233
- this.composerFailed = result === false || this.composerProjection().enabled !== enabled;
272
+ await setSessionMode(sessionId, mode);
234
273
  } catch {
235
- this.composerFailed = true;
274
+ this.composerFailed.add(sessionId);
236
275
  } finally {
237
- this.composerSaving = false;
276
+ this.composerSaving.delete(sessionId);
238
277
  if (!this.disposed) this.composer.set(this.composerProjection());
239
278
  }
240
279
  }
@@ -242,6 +281,7 @@ export class AutoContinueSettingsCardController {
242
281
  /** Release this card's subscription to the provider-owned settings form. */
243
282
  dispose(): void {
244
283
  this.disposed = true;
284
+ this.stopComposer();
245
285
  this.form.dispose();
246
286
  }
247
287
  }
@@ -259,8 +299,6 @@ export function AutoContinueSettingsPage(props: AutoContinueSettingsCardProps) {
259
299
  );
260
300
  }
261
301
 
262
- const REPOSITORY_URL = 'https://github.com/HsiangNianian/dsh-auto-continue';
263
-
264
302
  type FieldName = Exclude<keyof AutoContinueSettingsCardState, keyof CardShell | 'enabled' | 'notificationFeedback'>;
265
303
  const groups = [
266
304
  { id: 'general', fields: ['paused', 'showComposerToggle', 'resumeSilentTurns', 'resumeCompletedTurns', 'notify'] },
@@ -278,18 +316,18 @@ const textDefaults: Partial<Record<FieldName, SettingsCardKey>> = {
278
316
  guardPendingText: 'default.guardPendingText', guardDoneText: 'default.guardDoneText', loopText: 'default.loopText',
279
317
  };
280
318
 
281
- function GitHubMark() {
282
- return <svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M12 2.4a9.8 9.8 0 0 0-3.1 19.1c.5.1.7-.2.7-.5v-1.9c-2.8.6-3.4-1.2-3.4-1.2-.5-1.1-1.1-1.4-1.1-1.4-.9-.6.1-.6.1-.6 1 0 1.5 1 1.5 1 .9 1.5 2.3 1.1 2.9.8.1-.6.4-1.1.6-1.3-2.2-.3-4.6-1.1-4.6-4.9 0-1.1.4-2 1-2.7-.1-.3-.4-1.3.1-2.7 0 0 .8-.3 2.8 1a9.5 9.5 0 0 1 5 0c1.9-1.3 2.8-1 2.8-1 .5 1.4.2 2.4.1 2.7.6.7 1 1.6 1 2.7 0 3.8-2.3 4.6-4.6 4.9.4.3.7.9.7 1.8V21c0 .3.2.6.7.5A9.8 9.8 0 0 0 12 2.4Z" /></svg>;
283
- }
319
+ const REPOSITORY_URL = 'https://github.com/HsiangNianian/dsh-auto-continue';
320
+
284
321
  function RepositoryInvite({ t }: { t: (key: SettingsCardKey) => string }) {
285
- return <aside className="dshAcRepository">
286
- <span className="dshAcStar" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="m12 3 2.78 5.63L21 9.53l-4.5 4.39 1.06 6.2L12 17.2l-5.56 2.92 1.06-6.2L3 9.53l6.22-.9L12 3Z" /></svg></span>
287
- <span className="dshAcRepositoryCopy"><strong>{t('repo.star')}</strong><span>{t('repo.note')}</span></span>
288
- <a className="dshAcGithub" href={REPOSITORY_URL} target="_blank" rel="noopener noreferrer" aria-label={t('repo.aria')}>
289
- <GitHubMark /><span className="dshAcGithubLong">{t('repo.link')}</span><span className="dshAcGithubShort">GitHub</span>
322
+ return <p className="dshAcInvite">
323
+ <span className="dshAcInviteStar" aria-hidden="true">★</span>
324
+ <span>{t('repo.star')}</span>
325
+ <a className="dshAcRepoLink" href={REPOSITORY_URL} target="_blank" rel="noopener noreferrer" aria-label={t('repo.aria')}>
326
+ <svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M12 2.4a9.8 9.8 0 0 0-3.1 19.1c.5.1.7-.2.7-.5v-1.9c-2.8.6-3.4-1.2-3.4-1.2-.5-1.1-1.1-1.4-1.1-1.4-.9-.6.1-.6.1-.6 1 0 1.5 1 1.5 1 .9 1.5 2.3 1.1 2.9.8.1-.6.4-1.1.6-1.3-2.2-.3-4.6-1.1-4.6-4.9 0-1.1.4-2 1-2.7-.1-.3-.4-1.3.1-2.7 0 0 .8-.3 2.8 1a9.5 9.5 0 0 1 5 0c1.9-1.3 2.8-1 2.8-1 .5 1.4.2 2.4.1 2.7.6.7 1 1.6 1 2.7 0 3.8-2.3 4.6-4.6 4.9.4.3.7.9.7 1.8V21c0 .3.2.6.7.5A9.8 9.8 0 0 0 12 2.4Z" /></svg>
327
+ {t('repo.link')}
290
328
  <svg className="dshAcExternal" viewBox="0 0 16 16" aria-hidden="true"><path d="M6 3h7v7M13 3 7 9M11 9v3a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1h3" /></svg>
291
329
  </a>
292
- </aside>;
330
+ </p>;
293
331
  }
294
332
 
295
333
  /** Controls edit the existing staged form; navigation never owns or discards drafts. */
@@ -312,7 +350,10 @@ function SettingField({ name, id, state, actions, disabled, t }: {
312
350
  </div>
313
351
  <div className="dshAcFieldControl">
314
352
  {state.overridden && <button type="button" className="dshAcReset" disabled={disabled} aria-label={`${t('chrome.reset')}: ${label}`} onClick={() => actions.resetField(name)}>{t('chrome.reset')}</button>}
315
- {boolean ? <span className="dshAcSwitchTarget"><NativeSwitch label={label} title={hint} disabled={disabled}
353
+ {name === 'resumeCompletedTurns' ? <select id={id} className="dshAcMode" aria-label={label} aria-describedby={`${id}-hint`}
354
+ disabled={disabled} value={String(value)} onChange={event => actions.edit(name, event.target.value)}>
355
+ <option value="false">{t('composer.recover')}</option><option value="true">{t('composer.loop')}</option>
356
+ </select> : boolean ? <span className="dshAcSwitchTarget"><NativeSwitch label={label} title={hint} disabled={disabled}
316
357
  checked={name === 'paused' ? !value : Boolean(value)} onChange={checked => actions.edit(name, String(name === 'paused' ? !checked : checked))} /></span>
317
358
  : numeric ? <input {...common} className="dshAcInput dshAcNumber" type="text" inputMode="numeric" placeholder={placeholder} />
318
359
  : <textarea {...common} className="dshAcInput dshAcTextArea" rows={name === 'retryableErrorPatterns' ? 3 : 2} placeholder={placeholder} />}
@@ -320,6 +361,68 @@ function SettingField({ name, id, state, actions, disabled, t }: {
320
361
  </div>;
321
362
  }
322
363
 
364
+
365
+ /** One field rendered with the host's own settings primitives. */
366
+ function NativeSettingField({ name, id, state, actions, disabled, t }: {
367
+ name: FieldName; id: string; state: CardFieldState; actions: CardActions; disabled: boolean;
368
+ t: (key: SettingsCardKey) => string;
369
+ }) {
370
+ const boolean = typeof DEFAULT_CONFIG[name] === 'boolean';
371
+ const numeric = typeof DEFAULT_CONFIG[name] === 'number';
372
+ const label = t(`field.${name}` as SettingsCardKey);
373
+ const hint = t(`field.${name}Hint` as SettingsCardKey);
374
+ const value = state.text === '' ? DEFAULT_CONFIG[name] : state.text === 'true';
375
+ const placeholderKey = textDefaults[name];
376
+ const placeholder = placeholderKey ? t(placeholderKey) : name === 'retryableErrorPatterns' ? t('field.retryableErrorPatternsPlaceholder') : String(DEFAULT_CONFIG[name]);
377
+ const reset = state.overridden
378
+ ? <button type="button" className="dshAcNativeReset" disabled={disabled} aria-label={`${t('chrome.reset')}: ${label}`} onClick={() => actions.resetField(name)}>{t('chrome.reset')}</button>
379
+ : null;
380
+
381
+ if (name === 'resumeCompletedTurns') {
382
+ const items = [{ value: 'false', label: t('composer.recover') }, { value: 'true', label: t('composer.loop') }];
383
+ return <div className="dshAcNativeField" data-field={name}>
384
+ <div className="dshAcNativeHead"><label className="dshAcNativeLabel" htmlFor={id}>{label}</label>{reset}</div>
385
+ {NativeSegmentedControl
386
+ ? <NativeSegmentedControl id={id} options={items} value={value ? 'true' : 'false'} onChange={next => actions.edit(name, next)} label={label} disabled={disabled} />
387
+ : <select id={id} className="dshAcMode" aria-label={label} disabled={disabled} value={String(value)} onChange={event => actions.edit(name, event.target.value)}>
388
+ <option value="false">{t('composer.recover')}</option><option value="true">{t('composer.loop')}</option>
389
+ </select>}
390
+ <p className="dshAcNativeHint" id={`${id}-hint`}>{hint}</p>
391
+ </div>;
392
+ }
393
+
394
+ if (boolean) {
395
+ return <div className="dshAcNativeField" data-field={name}>
396
+ <div className="dshAcNativeToggleRow">
397
+ <label className="dshAcNativeLabel" htmlFor={id}>{label}</label>
398
+ <span className="dshAcNativeActions">
399
+ {reset}
400
+ <NativeSwitch label={label} title={hint} disabled={disabled}
401
+ checked={name === 'paused' ? !value : Boolean(value)}
402
+ onChange={checked => actions.edit(name, String(name === 'paused' ? !checked : checked))} />
403
+ </span>
404
+ </div>
405
+ <p className="dshAcNativeHint" id={`${id}-hint`}>{hint}</p>
406
+ </div>;
407
+ }
408
+
409
+ if (numeric) {
410
+ const ValueField = NativeValueField!;
411
+ return <ValueField id={id} label={label} hint={hint} overriddenLabel={t('chrome.overridden')}
412
+ resetLabel={t('chrome.reset')} invalidLabel={t('chrome.invalidNumber')} disabled={disabled}
413
+ numeric {...state} placeholder={placeholder}
414
+ onEdit={(text: string) => actions.edit(name, text)} onReset={() => actions.resetField(name)} />;
415
+ }
416
+
417
+ return <div className="dshAcNativeField" data-field={name}>
418
+ <div className="dshAcNativeHead"><label className="dshAcNativeLabel" htmlFor={id}>{label}</label>{reset}</div>
419
+ <textarea id={id} className="dshAcNativeTextarea" rows={name === 'retryableErrorPatterns' ? 3 : 2}
420
+ disabled={disabled} value={state.text} placeholder={placeholder} aria-invalid={state.invalid || undefined}
421
+ aria-describedby={`${id}-hint`} onChange={event => actions.edit(name, event.target.value)} />
422
+ <p className="dshAcNativeHint" id={`${id}-hint`}>{state.invalid ? t('chrome.invalidNumber') : hint}</p>
423
+ </div>;
424
+ }
425
+
323
426
  /** 实时面板: 今日统计 + 已暂停会话。浏览器本地状态, 每 5 秒刷新一次。 */
324
427
  function LivePanels(props: { t: (key: SettingsCardKey) => string }) {
325
428
  const { t } = props;
@@ -453,20 +556,18 @@ function LivePanels(props: { t: (key: SettingsCardKey) => string }) {
453
556
  );
454
557
  }
455
558
 
456
- /** Native category layout, with the selected B3 repository invitation beside the introduction. */
559
+ /** Native category layout; the plugin manager above already owns the title, version and status. */
457
560
  export function AutoContinueSettingsCard(props: AutoContinueSettingsCardProps) {
458
561
  const { t } = props;
459
562
  const state = props.useAutoContinueSettingsCard(snapshot => snapshot);
460
563
  const [active, setActive] = useState<Category>('general');
461
564
  const prefix = useId();
462
565
  const group = groups.find(item => item.id === active)!;
566
+ const native = hasNativeSettings;
463
567
  if (!state.available) return null;
464
568
  return <li className="dshAcCard">
465
- <header className="dshAcHeaderFrame">
466
- <div className="dshAcIntroduction"><div className="dshAcTitleLine"><h2>{t('card.title')}</h2><span className="dshAcStatus">{t(state.enabled ? 'chrome.enabled' : 'chrome.paused')}</span></div><p>{t('card.description')}</p></div>
467
- <RepositoryInvite t={t} />
468
- </header>
469
- {!state.writable && <p className="dshAcReadOnly" role="status">{t('chrome.readOnly')}</p>}
569
+ <RepositoryInvite t={t} />
570
+ {!native && !state.writable && <p className="dshAcReadOnly" role="status">{t('chrome.readOnly')}</p>}
470
571
  <div className="dshAcLayout">
471
572
  <div className="dshAcNav" role="tablist" aria-label={t('chrome.categories')}>
472
573
  {groups.map((item, index) => {
@@ -489,13 +590,27 @@ export function AutoContinueSettingsCard(props: AutoContinueSettingsCardProps) {
489
590
  </div>
490
591
  <section className="dshAcCategory" role="tabpanel" id={`${prefix}-panel-${active}`} aria-labelledby={`${prefix}-tab-${active}`}>
491
592
  <div className="dshAcCategoryHeading"><h3>{t(`category.${active}.title`)}</h3><p>{t(`category.${active}.description`)}</p></div>
492
- {group.fields.map(name => <SettingField key={name} name={name} id={`${prefix}-${name}`} state={state[name]} actions={props} disabled={!state.writable} t={t} />)}
493
- {active === 'status' && <LivePanels t={t} />}
593
+ {native ? (
594
+ <NativeSettingsForm labels={{
595
+ save: t('chrome.save'), saving: t('chrome.saving'), saveFailed: t('chrome.saveFailed'),
596
+ readOnly: t('chrome.readOnly'), unavailable: t('chrome.unavailable'),
597
+ }} state={state} onSave={props.save} onDiscard={props.discard}>
598
+ <div className="dshAcNativeFields">
599
+ {group.fields.map(name => <NativeSettingField key={name} name={name} id={`${prefix}-${name}`} state={state[name]} actions={props} disabled={!state.writable} t={t} />)}
600
+ {active === 'status' && <LivePanels t={t} />}
601
+ </div>
602
+ </NativeSettingsForm>
603
+ ) : (
604
+ <>
605
+ {group.fields.map(name => <SettingField key={name} name={name} id={`${prefix}-${name}`} state={state[name]} actions={props} disabled={!state.writable} t={t} />)}
606
+ {active === 'status' && <LivePanels t={t} />}
607
+ <footer className="dshAcFooter" data-dirty={state.dirty}>
608
+ <p className={state.failed || state.invalid ? 'dshAcInvalid' : 'dshAcHint'} role="status">{t(state.failed ? 'chrome.saveFailed' : state.invalid ? 'chrome.invalidNumber' : state.saving ? 'chrome.saving' : state.dirty ? 'chrome.unsaved' : state.notificationFeedback ?? 'chrome.saved')}</p>
609
+ <div><button type="button" className="dshAcDiscard" disabled={!state.dirty || state.saving} onClick={props.discard}>{t('chrome.discard')}</button><button type="button" className="dshAcSave" disabled={!state.dirty || state.invalid || state.saving || !state.writable} onClick={props.save}>{t(state.saving ? 'chrome.saving' : 'chrome.save')}</button></div>
610
+ </footer>
611
+ </>
612
+ )}
494
613
  </section>
495
614
  </div>
496
- <footer className="dshAcFooter" data-dirty={state.dirty}>
497
- <p className={state.failed || state.invalid ? 'dshAcInvalid' : 'dshAcHint'} role="status">{t(state.failed ? 'chrome.saveFailed' : state.invalid ? 'chrome.invalidNumber' : state.saving ? 'chrome.saving' : state.dirty ? 'chrome.unsaved' : state.notificationFeedback ?? 'chrome.saved')}</p>
498
- <div><button type="button" className="dshAcDiscard" disabled={!state.dirty || state.saving} onClick={props.discard}>{t('chrome.discard')}</button><button type="button" className="dshAcSave" disabled={!state.dirty || state.invalid || state.saving || !state.writable} onClick={props.save}>{t(state.saving ? 'chrome.saving' : 'chrome.save')}</button></div>
499
- </footer>
500
615
  </li>;
501
616
  }