dsh-client-auto-continue 0.12.2 → 0.14.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 (34) hide show
  1. package/README.md +37 -21
  2. package/README.zh.md +37 -21
  3. package/docs/screenshots/01-settings-section.png +0 -0
  4. package/docs/screenshots/01-settings-section.zh.png +0 -0
  5. package/docs/screenshots/02-settings-card.png +0 -0
  6. package/docs/screenshots/02-settings-card.zh.png +0 -0
  7. package/docs/screenshots/07-card-panels.png +0 -0
  8. package/docs/screenshots/07-card-panels.zh.png +0 -0
  9. package/docs/screenshots/08-composer-toggle.png +0 -0
  10. package/docs/screenshots/08-composer-toggle.zh.png +0 -0
  11. package/docs/screenshots/README.md +27 -23
  12. package/lib/client.js +524 -1102
  13. package/lib/client.js.map +4 -4
  14. package/lib/index.js +4 -0
  15. package/lib/types/client/composer-toggle.d.ts +16 -0
  16. package/lib/types/client/index.d.ts +6 -0
  17. package/lib/types/client/locales.d.ts +31 -15
  18. package/lib/types/client/native-switch.d.ts +10 -0
  19. package/lib/types/client/settings-card.d.ts +22 -7
  20. package/lib/types/client/settings-form.d.ts +2 -2
  21. package/lib/types/client/settings-notifications.d.ts +8 -0
  22. package/lib/types/index.d.ts +8 -0
  23. package/lib/types/shared/core.d.ts +2 -0
  24. package/package.json +3 -3
  25. package/src/client/composer-toggle.tsx +34 -0
  26. package/src/client/index.ts +20 -1
  27. package/src/client/locales.ts +74 -42
  28. package/src/client/native-switch.tsx +33 -0
  29. package/src/client/settings-card.tsx +167 -614
  30. package/src/client/settings-form.ts +15 -9
  31. package/src/client/settings-notifications.ts +42 -0
  32. package/src/client/styles.ts +124 -382
  33. package/src/index.ts +2 -0
  34. package/src/shared/core.ts +4 -0
@@ -7,9 +7,11 @@
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, useState, type ReactNode } from 'react';
10
+ import { useEffect, useId, useState } from 'react';
11
11
  import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
12
- import { type AutoContinueSettings } from './engine.ts';
12
+ import { DEFAULT_CONFIG, type AutoContinueSettings } from './engine.ts';
13
+ import type { ComposerToggleFace, ComposerToggleState } from './composer-toggle.tsx';
14
+ import { NativeSwitch } from './native-switch.tsx';
13
15
  import { createSnapshotStore, type SettingsScope, type SnapshotStore } from './dsh-store-compat.ts';
14
16
  import {
15
17
  pausedSessions,
@@ -29,6 +31,7 @@ import {
29
31
  type CardShell,
30
32
  } from './settings-form.ts';
31
33
  import { injectStyles } from './styles.ts';
34
+ import { prepareSettingsNotification, showSettingsNotification } from './settings-notifications.ts';
32
35
 
33
36
  // Styles must land during factory materialization so the module system's
34
37
  // style bookkeeping (HMR) owns them.
@@ -36,7 +39,12 @@ injectStyles();
36
39
 
37
40
  /** What the auto-continue card renders. */
38
41
  export interface AutoContinueSettingsCardState extends CardShell {
42
+ /** Committed global state; a staged edit does not pause the engine yet. */
43
+ enabled: boolean;
44
+ /** Feedback for the last local save, including browser permission problems. */
45
+ notificationFeedback: SettingsCardKey | undefined;
39
46
  paused: CardFieldState;
47
+ showComposerToggle: CardFieldState;
40
48
  continueText: CardFieldState;
41
49
  continueTextMaxTokens: CardFieldState;
42
50
  resumeSilentTurns: CardFieldState;
@@ -79,13 +87,23 @@ export interface AutoContinueSettingsCardFace extends CardActions {
79
87
  export class AutoContinueSettingsCardController {
80
88
  private readonly form: CardForm<AutoContinueSettings>;
81
89
  private readonly store: SnapshotStore<AutoContinueSettingsCardState>;
90
+ private readonly composer: SnapshotStore<ComposerToggleState>;
91
+ private composerSaving = false;
92
+ private composerFailed = false;
93
+ private disposed = false;
94
+ private saveSequence = 0;
95
+ private notificationFeedback: SettingsCardKey | undefined;
82
96
 
83
97
  /**
84
98
  * @param scope - the bound settings scope for the `auto-continue` namespace.
85
99
  */
86
- constructor(scope: SettingsScope<AutoContinueSettings>) {
100
+ constructor(
101
+ private readonly scope: SettingsScope<AutoContinueSettings>,
102
+ private readonly getLocale: () => string,
103
+ ) {
87
104
  this.form = new CardForm(scope, [
88
105
  booleanField('paused'),
106
+ booleanField('showComposerToggle'),
89
107
  textField('continueText'),
90
108
  textField('continueTextMaxTokens'),
91
109
  booleanField('resumeSilentTurns'),
@@ -116,12 +134,16 @@ export class AutoContinueSettingsCardController {
116
134
  textField('loopText'),
117
135
  ]);
118
136
  this.store = this.form.bind(() => this.projection(), createSnapshotStore);
137
+ this.composer = this.form.bind(() => this.composerProjection(), createSnapshotStore);
119
138
  }
120
139
 
121
140
  private projection(): AutoContinueSettingsCardState {
122
141
  return {
123
142
  ...this.form.shell(),
143
+ enabled: !(this.scope.getSnapshot().value?.paused ?? DEFAULT_CONFIG.paused),
144
+ notificationFeedback: this.notificationFeedback,
124
145
  paused: this.form.field('paused'),
146
+ showComposerToggle: this.form.field('showComposerToggle'),
125
147
  continueText: this.form.field('continueText'),
126
148
  continueTextMaxTokens: this.form.field('continueTextMaxTokens'),
127
149
  resumeSilentTurns: this.form.field('resumeSilentTurns'),
@@ -158,11 +180,63 @@ export class AutoContinueSettingsCardController {
158
180
  * @returns the card's snapshot and its form actions.
159
181
  */
160
182
  inject(): AutoContinueSettingsCardFace {
161
- return { hooks: { autoContinueSettingsCard: this.store }, ...this.form.actions() };
183
+ return { hooks: { autoContinueSettingsCard: this.store }, ...this.form.actions(), save: () => void this.save() };
184
+ }
185
+
186
+ private async save(): Promise<void> {
187
+ const state = this.form.shell();
188
+ const snapshot = this.scope.getSnapshot();
189
+ if (this.disposed || !state.available || !state.writable || !state.dirty || state.invalid || state.saving || snapshot.mode !== 'host') return;
190
+ const sequence = ++this.saveSequence;
191
+ const before = snapshot.value?.notify ?? DEFAULT_CONFIG.notify;
192
+ const target = this.form.field('notify').text;
193
+ // Start the permission prompt in the click handler, but save independently.
194
+ const permission = prepareSettingsNotification(target === '' ? DEFAULT_CONFIG.notify : target === 'true');
195
+ this.notificationFeedback = undefined;
196
+ if (!await this.form.save() || this.disposed) return;
197
+ const after = this.scope.getSnapshot().value?.notify ?? DEFAULT_CONFIG.notify;
198
+ if (!before && !after) return;
199
+ const result = await permission;
200
+ // A later save or a provider teardown makes this pending confirmation stale.
201
+ if (this.disposed || sequence !== this.saveSequence || (this.scope.getSnapshot().value?.notify ?? DEFAULT_CONFIG.notify) !== after) return;
202
+ this.notificationFeedback = showSettingsNotification(before === after ? 'saved' : after ? 'enabled' : 'disabled', this.getLocale(), result);
203
+ this.store.set(this.projection());
204
+ }
205
+
206
+ injectComposer(): ComposerToggleFace {
207
+ return { hooks: { autoContinueComposer: this.composer }, setEnabled: (enabled) => void this.setEnabled(enabled) };
208
+ }
209
+
210
+ private composerProjection(): ComposerToggleState {
211
+ const snapshot = this.scope.getSnapshot();
212
+ return {
213
+ visible: snapshot.status === 'ready' && (snapshot.value?.showComposerToggle ?? DEFAULT_CONFIG.showComposerToggle),
214
+ enabled: !(snapshot.value?.paused ?? DEFAULT_CONFIG.paused),
215
+ writable: snapshot.status === 'ready' && snapshot.writable && snapshot.mode === 'host',
216
+ saving: this.composerSaving,
217
+ failed: this.composerFailed,
218
+ };
219
+ }
220
+
221
+ private async setEnabled(enabled: boolean): Promise<void> {
222
+ if (this.disposed || this.composerSaving || !this.composerProjection().writable) return;
223
+ this.composerSaving = true;
224
+ this.composerFailed = false;
225
+ this.composer.set(this.composerProjection());
226
+ try {
227
+ const result = await this.scope.set('paused', !enabled);
228
+ this.composerFailed = result === false || this.composerProjection().enabled !== enabled;
229
+ } catch {
230
+ this.composerFailed = true;
231
+ } finally {
232
+ this.composerSaving = false;
233
+ if (!this.disposed) this.composer.set(this.composerProjection());
234
+ }
162
235
  }
163
236
 
164
237
  /** Release this card's subscription to the provider-owned settings form. */
165
238
  dispose(): void {
239
+ this.disposed = true;
166
240
  this.form.dispose();
167
241
  }
168
242
  }
@@ -181,265 +255,63 @@ export function AutoContinueSettingsPage(props: AutoContinueSettingsCardProps) {
181
255
  }
182
256
 
183
257
  const REPOSITORY_URL = 'https://github.com/HsiangNianian/dsh-auto-continue';
184
- const REPOSITORY_SLUG = 'HsiangNianian/dsh-auto-continue';
185
258
 
186
- function RelayMark() {
187
- return (
188
- <svg viewBox="0 0 48 48" aria-hidden="true" focusable="false">
189
- <path className="dshAcRelayArc" d="M9 30c4-12 10-18 19-18 5 0 9 2 12 6" />
190
- <path className="dshAcRelayArc dshAcRelayArcEcho" d="M8 35c6 3 12 3 17 0 5-3 8-8 15-9" />
191
- <circle className="dshAcRelayNode dshAcRelayNodeStart" cx="9" cy="30" r="3" />
192
- <circle className="dshAcRelayNode dshAcRelayNodeEnd" cx="40" cy="18" r="3" />
193
- <circle className="dshAcRelayPulse" cx="28" cy="12" r="2.5" />
194
- </svg>
195
- );
196
- }
197
-
198
- function ChevronMark() {
199
- return (
200
- <svg viewBox="0 0 16 16" aria-hidden="true" focusable="false">
201
- <path d="m3.5 6 4.5 4 4.5-4" />
202
- </svg>
203
- );
204
- }
259
+ type FieldName = Exclude<keyof AutoContinueSettingsCardState, keyof CardShell | 'enabled' | 'notificationFeedback'>;
260
+ const groups = [
261
+ { id: 'general', fields: ['paused', 'showComposerToggle', 'resumeSilentTurns', 'resumeCompletedTurns', 'notify'] },
262
+ { id: 'recovery', fields: ['graceMs', 'cooldownMs', 'maxConsecutive', 'classify', 'retryableErrorPatterns', 'backoffFactor', 'backoffMaxMs'] },
263
+ { id: 'startup', fields: ['scanOnBoot', 'scanLimit', 'freshMs'] },
264
+ { id: 'prompts', fields: ['continueText', 'continueTextMaxTokens', 'continueTextSilent', 'continueTextLoop', 'guardPendingText', 'guardDoneText', 'loopText'] },
265
+ { id: 'safety', fields: ['guardTools', 'loopGuard', 'loopShortChars', 'loopWindowMs', 'loopShortCount', 'loopRepeatText', 'loopToolRepeat'] },
266
+ { id: 'status', fields: ['verbose'] },
267
+ ] as const satisfies ReadonlyArray<{ id: string; fields: readonly FieldName[] }>;
268
+ type Category = typeof groups[number]['id'];
269
+ const textDefaults: Partial<Record<FieldName, SettingsCardKey>> = {
270
+ continueText: 'default.continueText', continueTextMaxTokens: 'default.continueTextMaxTokens',
271
+ continueTextSilent: 'default.continueTextSilent', continueTextLoop: 'default.continueTextLoop',
272
+ guardPendingText: 'default.guardPendingText', guardDoneText: 'default.guardDoneText', loopText: 'default.loopText',
273
+ };
205
274
 
206
275
  function GitHubMark() {
207
- return (
208
- <svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
209
- <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" />
210
- </svg>
211
- );
276
+ 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>;
212
277
  }
213
-
214
- function ExternalMark() {
215
- return (
216
- <svg viewBox="0 0 16 16" aria-hidden="true" focusable="false">
217
- <path d="M6 3h7v7M13 3 7 9" />
218
- <path d="M11 9v3a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1h3" />
219
- </svg>
220
- );
278
+ function RepositoryInvite({ t }: { t: (key: SettingsCardKey) => string }) {
279
+ return <aside className="dshAcRepository">
280
+ <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>
281
+ <span className="dshAcRepositoryCopy"><strong>{t('repo.star')}</strong><span>{t('repo.note')}</span></span>
282
+ <a className="dshAcGithub" href={REPOSITORY_URL} target="_blank" rel="noopener noreferrer" aria-label={t('repo.aria')}>
283
+ <GitHubMark /><span className="dshAcGithubLong">{t('repo.link')}</span><span className="dshAcGithubShort">GitHub</span>
284
+ <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>
285
+ </a>
286
+ </aside>;
221
287
  }
222
288
 
223
- function RelayJourney(props: { t: (key: SettingsCardKey) => string }) {
224
- return (
225
- <span className="dshAcJourney">
226
- <span className="dshAcJourneyStep dshAcJourneyInterrupted">
227
- <span className="dshAcJourneyDot" aria-hidden="true" />
228
- {props.t('flow.interrupted')}
229
- </span>
230
- <span className="dshAcJourneyLine" aria-hidden="true" />
231
- <span className="dshAcJourneyStep dshAcJourneyGrace">
232
- <span className="dshAcJourneyDot" aria-hidden="true" />
233
- {props.t('flow.grace')}
234
- </span>
235
- <span className="dshAcJourneyLine" aria-hidden="true" />
236
- <span className="dshAcJourneyStep dshAcJourneyContinue">
237
- <span className="dshAcJourneyDot" aria-hidden="true" />
238
- {props.t('flow.continue')}
239
- </span>
240
- </span>
241
- );
242
- }
243
-
244
- /** Card chrome: a disclosure header naming the plugin and what its settings govern, the controls, and the save that writes them. */
245
- function SettingsCard(props: {
289
+ /** Controls edit the existing staged form; navigation never owns or discards drafts. */
290
+ function SettingField({ name, id, state, actions, disabled, t }: {
291
+ name: FieldName; id: string; state: CardFieldState; actions: CardActions; disabled: boolean;
246
292
  t: (key: SettingsCardKey) => string;
247
- titleKey: SettingsCardKey;
248
- descriptionKey: SettingsCardKey;
249
- state: CardShell;
250
- onSave: () => void;
251
- onDiscard: () => void;
252
- children: ReactNode;
253
293
  }) {
254
- const [open, setOpen] = useState(false);
255
- const { state } = props;
256
- if (!state.available) return null;
257
- const title = props.t(props.titleKey);
258
- const blocked = !state.dirty || state.invalid || state.saving;
259
- return (
260
- <li className={open ? 'dshAcCard dshAcCardOpen' : 'dshAcCard'}>
261
- <div className="dshAcHeaderFrame">
262
- <button
263
- type="button"
264
- className="dshAcHeader"
265
- aria-expanded={open}
266
- aria-label={`${props.t(open ? 'chrome.collapse' : 'chrome.expand')}: ${title}`}
267
- title={props.t(props.descriptionKey)}
268
- onClick={() => setOpen(!open)}
269
- >
270
- <span className="dshAcRelayMark"><RelayMark /></span>
271
- <span className="dshAcHeadText">
272
- <span className="dshAcName">{title}</span>
273
- <span className="dshAcDescription">{props.t(props.descriptionKey)}</span>
274
- <RelayJourney t={props.t} />
275
- </span>
276
- {state.dirty ? (
277
- <span className="dshAcPending" title={props.t('chrome.unsaved')}>
278
- {props.t('chrome.unsaved')}
279
- </span>
280
- ) : null}
281
- <span className={open ? 'dshAcChevron dshAcChevronOpen' : 'dshAcChevron'}>
282
- <ChevronMark />
283
- </span>
284
- </button>
285
- <a
286
- className="dshAcGithub"
287
- href={REPOSITORY_URL}
288
- target="_blank"
289
- rel="noreferrer"
290
- aria-label={props.t('repo.aria')}
291
- >
292
- <span className="dshAcGithubIcon"><GitHubMark /></span>
293
- <span className="dshAcGithubText">
294
- <span className="dshAcGithubAction">{props.t('repo.star')}</span>
295
- <span className="dshAcGithubSlug">{REPOSITORY_SLUG}</span>
296
- </span>
297
- <span className="dshAcExternal"><ExternalMark /></span>
298
- </a>
299
- </div>
300
- {open ? (
301
- <div className="dshAcBody">
302
- {!state.writable ? (
303
- <p className="dshAcReadOnly" role="status">{props.t('chrome.readOnly')}</p>
304
- ) : null}
305
- {props.children}
306
- <div className="dshAcFooter">
307
- {state.failed ? (
308
- <p className="dshAcFailed" role="status">{props.t('chrome.saveFailed')}</p>
309
- ) : null}
310
- <button
311
- type="button"
312
- className="dshAcDiscard"
313
- disabled={!state.dirty || state.saving}
314
- onClick={props.onDiscard}
315
- >
316
- {props.t('chrome.discard')}
317
- </button>
318
- <button type="button" className="dshAcSave" disabled={blocked} onClick={props.onSave}>
319
- {props.t(!state.saving ? 'chrome.save' : 'chrome.saving')}
320
- </button>
321
- </div>
322
- </div>
323
- ) : null}
324
- </li>
325
- );
326
- }
327
-
328
- /** Props every field control needs regardless of its value type. */
329
- interface FieldProps {
330
- id: string;
331
- label: string;
332
- hint: string;
333
- wide?: boolean;
334
- text: string;
335
- overridden: boolean;
336
- invalid: boolean;
337
- disabled: boolean;
338
- t: (key: SettingsCardKey) => string;
339
- onEdit: (text: string) => void;
340
- onReset: () => void;
341
- }
342
-
343
- /** A staged value field; `numeric` only hints the keypad, which drafts a field accepts is decided by its spec. */
344
- function ValueField(props: FieldProps & { numeric?: boolean; multiline?: boolean; placeholder?: string }) {
345
- const className = props.invalid ? 'dshAcInput dshAcInputInvalid' : 'dshAcInput';
346
- return (
347
- <div className={props.wide === true ? 'dshAcField dshAcFieldWide' : 'dshAcField'}>
348
- <div className="dshAcHead">
349
- <label className="dshAcLabel" htmlFor={props.id}>{props.label}</label>
350
- {props.overridden ? (
351
- <span className="dshAcBadges">
352
- <span className="dshAcBadge">{props.t('chrome.overridden')}</span>
353
- <button type="button" className="dshAcReset" disabled={props.disabled} onClick={props.onReset}>
354
- {props.t('chrome.reset')}
355
- </button>
356
- </span>
357
- ) : null}
358
- </div>
359
- {props.multiline === true ? (
360
- <textarea
361
- id={props.id}
362
- className={`${className} dshAcTextArea`}
363
- aria-invalid={props.invalid || undefined}
364
- value={props.text}
365
- placeholder={props.placeholder ?? ''}
366
- disabled={props.disabled}
367
- rows={4}
368
- onChange={(event) => props.onEdit(event.target.value)}
369
- />
370
- ) : (
371
- <input
372
- id={props.id}
373
- className={className}
374
- type="text"
375
- inputMode={props.numeric === true ? 'numeric' : undefined}
376
- aria-invalid={props.invalid || undefined}
377
- value={props.text}
378
- placeholder={props.placeholder ?? ''}
379
- disabled={props.disabled}
380
- onChange={(event) => props.onEdit(event.target.value)}
381
- />
382
- )}
383
- <p className={props.invalid ? 'dshAcInvalid' : 'dshAcHint'}>
384
- {props.invalid ? props.t('chrome.invalidNumber') : props.hint}
385
- </p>
294
+ const boolean = typeof DEFAULT_CONFIG[name] === 'boolean';
295
+ const numeric = typeof DEFAULT_CONFIG[name] === 'number';
296
+ const label = t(`field.${name}` as SettingsCardKey);
297
+ const hint = t(`field.${name}Hint` as SettingsCardKey);
298
+ const value = state.text === '' ? DEFAULT_CONFIG[name] : state.text === 'true';
299
+ const placeholderKey = textDefaults[name];
300
+ const placeholder = placeholderKey ? t(placeholderKey) : name === 'retryableErrorPatterns' ? t('field.retryableErrorPatternsPlaceholder') : String(DEFAULT_CONFIG[name]);
301
+ const common = { id, disabled, 'aria-describedby': `${id}-hint`, 'aria-invalid': state.invalid || undefined, value: state.text, onChange: (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => actions.edit(name, event.target.value) };
302
+ return <div className={`dshAcField${!boolean && !numeric ? ' dshAcFieldText' : ''}`} data-field={name}>
303
+ <div className="dshAcFieldCopy">
304
+ {boolean ? <span className="dshAcLabel">{label}</span> : <label className="dshAcLabel" htmlFor={id}>{label}</label>}
305
+ <p className={state.invalid ? 'dshAcInvalid' : 'dshAcHint'} id={`${id}-hint`}>{state.invalid ? t('chrome.invalidNumber') : hint}</p>
386
306
  </div>
387
- );
388
- }
389
-
390
- /** A staged boolean field: inherit / on / off. */
391
- function BooleanField(props: FieldProps) {
392
- return (
393
- <div className={props.wide === true ? 'dshAcField dshAcFieldWide' : 'dshAcField'}>
394
- <div className="dshAcHead">
395
- <label className="dshAcLabel" htmlFor={props.id}>{props.label}</label>
396
- {props.overridden ? (
397
- <span className="dshAcBadges">
398
- <span className="dshAcBadge">{props.t('chrome.overridden')}</span>
399
- <button type="button" className="dshAcReset" disabled={props.disabled} onClick={props.onReset}>
400
- {props.t('chrome.reset')}
401
- </button>
402
- </span>
403
- ) : null}
404
- </div>
405
- <select
406
- id={props.id}
407
- className="dshAcSelect"
408
- value={props.text}
409
- disabled={props.disabled}
410
- onChange={(event) => props.onEdit(event.target.value)}
411
- >
412
- <option value="">{props.t('chrome.inherit')}</option>
413
- <option value="true">{props.t('chrome.on')}</option>
414
- <option value="false">{props.t('chrome.off')}</option>
415
- </select>
416
- <p className="dshAcHint">{props.hint}</p>
307
+ <div className="dshAcFieldControl">
308
+ {state.overridden && <button type="button" className="dshAcReset" disabled={disabled} aria-label={`${t('chrome.reset')}: ${label}`} onClick={() => actions.resetField(name)}>{t('chrome.reset')}</button>}
309
+ {boolean ? <span className="dshAcSwitchTarget"><NativeSwitch label={label} title={hint} disabled={disabled}
310
+ checked={name === 'paused' ? !value : Boolean(value)} onChange={checked => actions.edit(name, String(name === 'paused' ? !checked : checked))} /></span>
311
+ : numeric ? <input {...common} className="dshAcInput dshAcNumber" type="text" inputMode="numeric" placeholder={placeholder} />
312
+ : <textarea {...common} className="dshAcInput dshAcTextArea" rows={name === 'retryableErrorPatterns' ? 3 : 2} placeholder={placeholder} />}
417
313
  </div>
418
- );
419
- }
420
-
421
- type SettingsSectionTone = 'handoff' | 'autoloop' | 'safety' | 'recovery' | 'loop' | 'live';
422
-
423
- /** A real behavior group, not a decorative divider: each section maps to one phase of the relay. */
424
- function SettingsSection(props: {
425
- t: (key: SettingsCardKey) => string;
426
- titleKey: SettingsCardKey;
427
- descriptionKey: SettingsCardKey;
428
- tone: SettingsSectionTone;
429
- children: ReactNode;
430
- }) {
431
- return (
432
- <section className={`dshAcFormSection dshAcFormSection-${props.tone}`}>
433
- <header className="dshAcSectionHead">
434
- <span className="dshAcSectionSignal" aria-hidden="true" />
435
- <span className="dshAcSectionCopy">
436
- <span className="dshAcSectionTitle">{props.t(props.titleKey)}</span>
437
- <span className="dshAcSectionDescription">{props.t(props.descriptionKey)}</span>
438
- </span>
439
- </header>
440
- <div className="dshAcSectionGrid">{props.children}</div>
441
- </section>
442
- );
314
+ </div>;
443
315
  }
444
316
 
445
317
  /** 实时面板: 今日统计 + 已暂停会话。浏览器本地状态, 每 5 秒刷新一次。 */
@@ -549,368 +421,49 @@ function LivePanels(props: { t: (key: SettingsCardKey) => string }) {
549
421
  );
550
422
  }
551
423
 
552
- /**
553
- * Render the auto-continue card.
554
- * @param props - locale copy, the card snapshot, and its form actions.
555
- * @returns the card.
556
- */
424
+ /** Native category layout, with the selected B3 repository invitation beside the introduction. */
557
425
  export function AutoContinueSettingsCard(props: AutoContinueSettingsCardProps) {
558
426
  const { t } = props;
559
- const state = props.useAutoContinueSettingsCard((snapshot) => snapshot);
560
- const disabled = !state.writable;
561
- const shared = { t, disabled };
562
- return (
563
- <SettingsCard
564
- t={t}
565
- titleKey="card.title"
566
- descriptionKey="card.description"
567
- state={state}
568
- onSave={props.save}
569
- onDiscard={props.discard}
570
- >
571
- <div className="dshAcFormCanvas">
572
- <SettingsSection
573
- t={t}
574
- titleKey="section.handoff.title"
575
- descriptionKey="section.handoff.description"
576
- tone="handoff"
577
- >
578
- <BooleanField
579
- wide
580
- id="auto-continue-paused"
581
- label={t('field.paused')}
582
- hint={t('field.pausedHint')}
583
- {...shared}
584
- {...state.paused}
585
- onEdit={(text) => props.edit('paused', text)}
586
- onReset={() => props.resetField('paused')}
587
- />
588
- <ValueField
589
- id="auto-continue-continue-text"
590
- label={t('field.continueText')}
591
- hint={t('field.continueTextHint')}
592
- {...shared}
593
- {...state.continueText}
594
- onEdit={(text) => props.edit('continueText', text)}
595
- placeholder={t('default.continueText')}
596
- onReset={() => props.resetField('continueText')}
597
- />
598
- <ValueField
599
- id="auto-continue-continue-text-max-tokens"
600
- label={t('field.continueTextMaxTokens')}
601
- hint={t('field.continueTextMaxTokensHint')}
602
- {...shared}
603
- {...state.continueTextMaxTokens}
604
- onEdit={(text) => props.edit('continueTextMaxTokens', text)}
605
- placeholder={t('default.continueTextMaxTokens')}
606
- onReset={() => props.resetField('continueTextMaxTokens')}
607
- />
608
- <BooleanField
609
- wide
610
- id="auto-continue-resume-silent-turns"
611
- label={t('field.resumeSilentTurns')}
612
- hint={t('field.resumeSilentTurnsHint')}
613
- {...shared}
614
- {...state.resumeSilentTurns}
615
- onEdit={(text) => props.edit('resumeSilentTurns', text)}
616
- onReset={() => props.resetField('resumeSilentTurns')}
617
- />
618
- <ValueField
619
- wide
620
- id="auto-continue-continue-text-silent"
621
- label={t('field.continueTextSilent')}
622
- hint={t('field.continueTextSilentHint')}
623
- {...shared}
624
- {...state.continueTextSilent}
625
- onEdit={(text) => props.edit('continueTextSilent', text)}
626
- placeholder={t('default.continueTextSilent')}
627
- onReset={() => props.resetField('continueTextSilent')}
628
- />
629
- </SettingsSection>
630
-
631
- <SettingsSection
632
- t={t}
633
- titleKey="section.autoloop.title"
634
- descriptionKey="section.autoloop.description"
635
- tone="autoloop"
636
- >
637
- <BooleanField
638
- wide
639
- id="auto-continue-resume-completed-turns"
640
- label={t('field.resumeCompletedTurns')}
641
- hint={t('field.resumeCompletedTurnsHint')}
642
- {...shared}
643
- {...state.resumeCompletedTurns}
644
- onEdit={(text) => props.edit('resumeCompletedTurns', text)}
645
- onReset={() => props.resetField('resumeCompletedTurns')}
646
- />
647
- <ValueField
648
- wide
649
- id="auto-continue-continue-text-loop"
650
- label={t('field.continueTextLoop')}
651
- hint={t('field.continueTextLoopHint')}
652
- {...shared}
653
- {...state.continueTextLoop}
654
- onEdit={(text) => props.edit('continueTextLoop', text)}
655
- placeholder={t('default.continueTextLoop')}
656
- onReset={() => props.resetField('continueTextLoop')}
657
- />
658
- </SettingsSection>
659
-
660
- <SettingsSection
661
- t={t}
662
- titleKey="section.safety.title"
663
- descriptionKey="section.safety.description"
664
- tone="safety"
665
- >
666
- <BooleanField
667
- wide
668
- id="auto-continue-guard-tools"
669
- label={t('field.guardTools')}
670
- hint={t('field.guardToolsHint')}
671
- {...shared}
672
- {...state.guardTools}
673
- onEdit={(text) => props.edit('guardTools', text)}
674
- onReset={() => props.resetField('guardTools')}
675
- />
676
- <ValueField
677
- wide
678
- id="auto-continue-guard-pending-text"
679
- label={t('field.guardPendingText')}
680
- hint={t('field.guardPendingTextHint')}
681
- {...shared}
682
- {...state.guardPendingText}
683
- onEdit={(text) => props.edit('guardPendingText', text)}
684
- placeholder={t('default.guardPendingText')}
685
- onReset={() => props.resetField('guardPendingText')}
686
- />
687
- <ValueField
688
- wide
689
- id="auto-continue-guard-done-text"
690
- label={t('field.guardDoneText')}
691
- hint={t('field.guardDoneTextHint')}
692
- {...shared}
693
- {...state.guardDoneText}
694
- onEdit={(text) => props.edit('guardDoneText', text)}
695
- placeholder={t('default.guardDoneText')}
696
- onReset={() => props.resetField('guardDoneText')}
697
- />
698
- <ValueField
699
- id="auto-continue-grace-ms"
700
- label={t('field.graceMs')}
701
- hint={t('field.graceMsHint')}
702
- numeric
703
- {...shared}
704
- {...state.graceMs}
705
- onEdit={(text) => props.edit('graceMs', text)}
706
- onReset={() => props.resetField('graceMs')}
707
- />
708
- <ValueField
709
- id="auto-continue-cooldown-ms"
710
- label={t('field.cooldownMs')}
711
- hint={t('field.cooldownMsHint')}
712
- numeric
713
- {...shared}
714
- {...state.cooldownMs}
715
- onEdit={(text) => props.edit('cooldownMs', text)}
716
- onReset={() => props.resetField('cooldownMs')}
717
- />
718
- <ValueField
719
- id="auto-continue-max-consecutive"
720
- label={t('field.maxConsecutive')}
721
- hint={t('field.maxConsecutiveHint')}
722
- numeric
723
- {...shared}
724
- {...state.maxConsecutive}
725
- onEdit={(text) => props.edit('maxConsecutive', text)}
726
- onReset={() => props.resetField('maxConsecutive')}
727
- />
728
- </SettingsSection>
729
-
730
- <SettingsSection
731
- t={t}
732
- titleKey="section.recovery.title"
733
- descriptionKey="section.recovery.description"
734
- tone="recovery"
735
- >
736
- <BooleanField
737
- id="auto-continue-scan-on-boot"
738
- label={t('field.scanOnBoot')}
739
- hint={t('field.scanOnBootHint')}
740
- {...shared}
741
- {...state.scanOnBoot}
742
- onEdit={(text) => props.edit('scanOnBoot', text)}
743
- onReset={() => props.resetField('scanOnBoot')}
744
- />
745
- <BooleanField
746
- id="auto-continue-classify"
747
- label={t('field.classify')}
748
- hint={t('field.classifyHint')}
749
- {...shared}
750
- {...state.classify}
751
- onEdit={(text) => props.edit('classify', text)}
752
- onReset={() => props.resetField('classify')}
753
- />
754
- <ValueField
755
- id="auto-continue-scan-limit"
756
- label={t('field.scanLimit')}
757
- hint={t('field.scanLimitHint')}
758
- numeric
759
- {...shared}
760
- {...state.scanLimit}
761
- onEdit={(text) => props.edit('scanLimit', text)}
762
- onReset={() => props.resetField('scanLimit')}
763
- />
764
- <ValueField
765
- id="auto-continue-fresh-ms"
766
- label={t('field.freshMs')}
767
- hint={t('field.freshMsHint')}
768
- numeric
769
- {...shared}
770
- {...state.freshMs}
771
- onEdit={(text) => props.edit('freshMs', text)}
772
- onReset={() => props.resetField('freshMs')}
773
- />
774
- <ValueField
775
- wide
776
- id="auto-continue-retryable-error-patterns"
777
- label={t('field.retryableErrorPatterns')}
778
- hint={t('field.retryableErrorPatternsHint')}
779
- multiline
780
- {...shared}
781
- {...state.retryableErrorPatterns}
782
- onEdit={(text) => props.edit('retryableErrorPatterns', text)}
783
- placeholder={t('field.retryableErrorPatternsPlaceholder')}
784
- onReset={() => props.resetField('retryableErrorPatterns')}
785
- />
786
- <ValueField
787
- id="auto-continue-backoff-factor"
788
- label={t('field.backoffFactor')}
789
- hint={t('field.backoffFactorHint')}
790
- numeric
791
- {...shared}
792
- {...state.backoffFactor}
793
- onEdit={(text) => props.edit('backoffFactor', text)}
794
- onReset={() => props.resetField('backoffFactor')}
795
- />
796
- <ValueField
797
- id="auto-continue-backoff-max"
798
- label={t('field.backoffMaxMs')}
799
- hint={t('field.backoffMaxMsHint')}
800
- numeric
801
- {...shared}
802
- {...state.backoffMaxMs}
803
- onEdit={(text) => props.edit('backoffMaxMs', text)}
804
- onReset={() => props.resetField('backoffMaxMs')}
805
- />
806
- <BooleanField
807
- id="auto-continue-notify"
808
- label={t('field.notify')}
809
- hint={t('field.notifyHint')}
810
- {...shared}
811
- {...state.notify}
812
- onEdit={(text) => props.edit('notify', text)}
813
- onReset={() => props.resetField('notify')}
814
- />
815
- <BooleanField
816
- id="auto-continue-verbose"
817
- label={t('field.verbose')}
818
- hint={t('field.verboseHint')}
819
- {...shared}
820
- {...state.verbose}
821
- onEdit={(text) => props.edit('verbose', text)}
822
- onReset={() => props.resetField('verbose')}
823
- />
824
- </SettingsSection>
825
-
826
- <SettingsSection
827
- t={t}
828
- titleKey="section.loop.title"
829
- descriptionKey="section.loop.description"
830
- tone="loop"
831
- >
832
- <BooleanField
833
- wide
834
- id="auto-continue-loop-guard"
835
- label={t('field.loopGuard')}
836
- hint={t('field.loopGuardHint')}
837
- {...shared}
838
- {...state.loopGuard}
839
- onEdit={(text) => props.edit('loopGuard', text)}
840
- onReset={() => props.resetField('loopGuard')}
841
- />
842
- <ValueField
843
- id="auto-continue-loop-short-chars"
844
- label={t('field.loopShortChars')}
845
- hint={t('field.loopShortCharsHint')}
846
- numeric
847
- {...shared}
848
- {...state.loopShortChars}
849
- onEdit={(text) => props.edit('loopShortChars', text)}
850
- onReset={() => props.resetField('loopShortChars')}
851
- />
852
- <ValueField
853
- id="auto-continue-loop-window-ms"
854
- label={t('field.loopWindowMs')}
855
- hint={t('field.loopWindowMsHint')}
856
- numeric
857
- {...shared}
858
- {...state.loopWindowMs}
859
- onEdit={(text) => props.edit('loopWindowMs', text)}
860
- onReset={() => props.resetField('loopWindowMs')}
861
- />
862
- <ValueField
863
- id="auto-continue-loop-short-count"
864
- label={t('field.loopShortCount')}
865
- hint={t('field.loopShortCountHint')}
866
- numeric
867
- {...shared}
868
- {...state.loopShortCount}
869
- onEdit={(text) => props.edit('loopShortCount', text)}
870
- onReset={() => props.resetField('loopShortCount')}
871
- />
872
- <ValueField
873
- id="auto-continue-loop-repeat-text"
874
- label={t('field.loopRepeatText')}
875
- hint={t('field.loopRepeatTextHint')}
876
- numeric
877
- {...shared}
878
- {...state.loopRepeatText}
879
- onEdit={(text) => props.edit('loopRepeatText', text)}
880
- onReset={() => props.resetField('loopRepeatText')}
881
- />
882
- <ValueField
883
- id="auto-continue-loop-tool-repeat"
884
- label={t('field.loopToolRepeat')}
885
- hint={t('field.loopToolRepeatHint')}
886
- numeric
887
- {...shared}
888
- {...state.loopToolRepeat}
889
- onEdit={(text) => props.edit('loopToolRepeat', text)}
890
- onReset={() => props.resetField('loopToolRepeat')}
891
- />
892
- <ValueField
893
- wide
894
- id="auto-continue-loop-text"
895
- label={t('field.loopText')}
896
- hint={t('field.loopTextHint')}
897
- {...shared}
898
- {...state.loopText}
899
- onEdit={(text) => props.edit('loopText', text)}
900
- placeholder={t('default.loopText')}
901
- onReset={() => props.resetField('loopText')}
902
- />
903
- </SettingsSection>
904
-
905
- <SettingsSection
906
- t={t}
907
- titleKey="section.live.title"
908
- descriptionKey="section.live.description"
909
- tone="live"
910
- >
911
- <LivePanels t={t} />
912
- </SettingsSection>
427
+ const state = props.useAutoContinueSettingsCard(snapshot => snapshot);
428
+ const [active, setActive] = useState<Category>('general');
429
+ const prefix = useId();
430
+ const group = groups.find(item => item.id === active)!;
431
+ if (!state.available) return null;
432
+ return <li className="dshAcCard">
433
+ <header className="dshAcHeaderFrame">
434
+ <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>
435
+ <RepositoryInvite t={t} />
436
+ </header>
437
+ {!state.writable && <p className="dshAcReadOnly" role="status">{t('chrome.readOnly')}</p>}
438
+ <div className="dshAcLayout">
439
+ <div className="dshAcNav" role="tablist" aria-label={t('chrome.categories')}>
440
+ {groups.map((item, index) => {
441
+ const invalid = item.fields.some(name => state[name].invalid);
442
+ const title = t(`category.${item.id}.title`);
443
+ return <button type="button" role="tab" key={item.id} id={`${prefix}-tab-${item.id}`} data-category={item.id}
444
+ aria-controls={`${prefix}-panel-${item.id}`} aria-selected={active === item.id} tabIndex={active === item.id ? 0 : -1}
445
+ aria-label={invalid ? `${title}: ${t('chrome.invalidNumber')}` : title}
446
+ onClick={() => setActive(item.id)} onKeyDown={event => {
447
+ const offset = ['ArrowRight', 'ArrowDown'].includes(event.key) ? 1 : ['ArrowLeft', 'ArrowUp'].includes(event.key) ? -1 : 0;
448
+ if (!offset && event.key !== 'Home' && event.key !== 'End') return;
449
+ event.preventDefault();
450
+ const next = event.key === 'Home' ? 0 : event.key === 'End' ? groups.length - 1 : (index + offset + groups.length) % groups.length;
451
+ setActive(groups[next]!.id);
452
+ const button = event.currentTarget.parentElement?.querySelectorAll<HTMLButtonElement>('[role="tab"]')[next];
453
+ button?.focus();
454
+ button?.scrollIntoView({ block: 'nearest', inline: 'nearest' });
455
+ }}>{title}{invalid && <span className="dshAcInvalidMark" aria-hidden="true">!</span>}</button>;
456
+ })}
913
457
  </div>
914
- </SettingsCard>
915
- );
458
+ <section className="dshAcCategory" role="tabpanel" id={`${prefix}-panel-${active}`} aria-labelledby={`${prefix}-tab-${active}`}>
459
+ <div className="dshAcCategoryHeading"><h3>{t(`category.${active}.title`)}</h3><p>{t(`category.${active}.description`)}</p></div>
460
+ {group.fields.map(name => <SettingField key={name} name={name} id={`${prefix}-${name}`} state={state[name]} actions={props} disabled={!state.writable} t={t} />)}
461
+ {active === 'status' && <LivePanels t={t} />}
462
+ </section>
463
+ </div>
464
+ <footer className="dshAcFooter" data-dirty={state.dirty}>
465
+ <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>
466
+ <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>
467
+ </footer>
468
+ </li>;
916
469
  }