dsh-client-auto-continue 0.11.6 → 0.11.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -660,6 +660,7 @@ var AutoContinueRunner = class {
660
660
  this.notices = [];
661
661
  this.noticeListeners = /* @__PURE__ */ new Set();
662
662
  this.stateListeners = /* @__PURE__ */ new Set();
663
+ this.prioritizedFollowups = /* @__PURE__ */ new Set();
663
664
  this.disposed = false;
664
665
  this.disposeSessionEvents = ctx.on("session/event", (session, event) => {
665
666
  try {
@@ -670,6 +671,30 @@ var AutoContinueRunner = class {
670
671
  );
671
672
  }
672
673
  });
674
+ this.disposeInboxEvents = ctx.on("agent/inbox/inserted", ({ agent, message }) => {
675
+ if (!this.prioritizedFollowups.delete(message.id)) return;
676
+ let removed = false;
677
+ try {
678
+ const index = agent.inbox.nextTurn.findIndex((pending) => pending.id === message.id);
679
+ if (index <= 0) return;
680
+ removed = agent.inbox.remove(message.id);
681
+ if (!removed) return;
682
+ agent.inbox.prepend("next-turn", message);
683
+ } catch (error) {
684
+ if (removed) {
685
+ try {
686
+ agent.inbox.append("next-turn", message);
687
+ } catch (rollbackError) {
688
+ console.error(
689
+ `[auto-continue] 恢复续跑消息失败 ${agent.id}: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`
690
+ );
691
+ }
692
+ }
693
+ console.error(
694
+ `[auto-continue] 调整续跑消息顺序失败 ${agent.id}: ${error instanceof Error ? error.message : String(error)}`
695
+ );
696
+ }
697
+ });
673
698
  const config = this.getConfig();
674
699
  if (config.scanOnBoot) {
675
700
  void this.bootScanLoop();
@@ -734,6 +759,8 @@ var AutoContinueRunner = class {
734
759
  if (this.disposed) return;
735
760
  this.disposed = true;
736
761
  this.disposeSessionEvents();
762
+ this.disposeInboxEvents();
763
+ this.prioritizedFollowups.clear();
737
764
  for (const state of this.states.values()) {
738
765
  if (state.pendingTimer !== void 0) clearTimeout(state.pendingTimer);
739
766
  if (state.loopRetryTimer !== void 0) clearTimeout(state.loopRetryTimer);
@@ -1230,11 +1257,14 @@ var AutoContinueRunner = class {
1230
1257
  source: { kind: "user" }
1231
1258
  });
1232
1259
  trackPendingEcho(state, message.id);
1260
+ if (agent.inbox.nextTurn.length > 0) this.prioritizedFollowups.add(message.id);
1233
1261
  try {
1234
1262
  agent.followup(message);
1235
1263
  } catch (error) {
1236
1264
  forgetPendingEcho(state, message.id);
1237
1265
  throw error;
1266
+ } finally {
1267
+ this.prioritizedFollowups.delete(message.id);
1238
1268
  }
1239
1269
  const now = Date.now();
1240
1270
  state.consecutive += 1;
@@ -24,12 +24,12 @@ export interface SettingsScopeSnapshot<T> {
24
24
  writable: boolean;
25
25
  mode: 'host' | 'memory';
26
26
  }
27
- /** Stable subset shared by the legacy and DSH 0.1.2 settings scopes. */
27
+ /** Stable subset shared by settings scopes and DSH 0.1.7 configuration forms. */
28
28
  export interface SettingsScope<T> {
29
29
  getSnapshot(): SettingsScopeSnapshot<T>;
30
30
  subscribe(listener: () => void): () => void;
31
- set(field: string, value: unknown): Promise<void>;
32
- unset(field: string): Promise<void>;
31
+ set(field: string, value: unknown): Promise<void | boolean>;
32
+ unset(field: string): Promise<void | boolean>;
33
33
  }
34
34
  export declare const createSnapshotStore: <T>(init: T, options?: {
35
35
  flush?: "raf" | "sync";
@@ -3,7 +3,7 @@
3
3
  *
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
- * - registers the `auto-continue` settings card (`settings.plugin.item`),
6
+ * - registers the `auto-continue` settings card in the available plugin UI,
7
7
  * - subscribes to the host status bridge (SSE) and shows browser
8
8
  * notifications with action buttons (Resume now / Pause 1h) via the bridge
9
9
  * action endpoint,
@@ -12,12 +12,22 @@
12
12
  import type { Context as ClientContext } from '@deepseek-ai/cordis';
13
13
  import { type SettingsCardKey } from './locales.ts';
14
14
  declare module '@deepseek-ai/dsh-client-ui-slots' {
15
+ interface SlotMap {
16
+ /** DSH 0.1.7's bundle configuration seat; only the owner props we consume. */
17
+ 'plugins.bundle.config': {
18
+ kind: 'keyed';
19
+ scope: 'root';
20
+ owner: {
21
+ readonly view: 'summary' | 'page';
22
+ };
23
+ };
24
+ }
15
25
  interface LocaleNamespaceMap {
16
26
  /** auto-continue settings-card copy. */
17
27
  'auto-continue': SettingsCardKey;
18
28
  }
19
29
  }
20
- /** Services required by this plugin. */
30
+ /** Settings services are injected separately: neither exists in every DSH cohort. */
21
31
  export declare const inject: string[];
22
32
  export { pausedSessions, readTodayStats, resetTodayStats, unpauseSession, } from './bridge.ts';
23
33
  /**
@@ -1,4 +1,4 @@
1
- import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
1
+ import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
2
2
  import { type AutoContinueSettings } from './engine.ts';
3
3
  import { type SettingsScope, type SnapshotStore } from './dsh-store-compat.ts';
4
4
  import { type CardActions, type CardFieldState, type CardShell } from './settings-form.ts';
@@ -51,9 +51,13 @@ export declare class AutoContinueSettingsCardController {
51
51
  * @returns the card's snapshot and its form actions.
52
52
  */
53
53
  inject(): AutoContinueSettingsCardFace;
54
+ /** Release this card's subscription to the provider-owned settings form. */
55
+ dispose(): void;
54
56
  }
55
57
  /** Props the renderer binds for the auto-continue plugin-configuration card. */
56
- export type AutoContinueSettingsCardProps = PropsRuntime<'settings.plugin.item'> & PropsLocale<'auto-continue'> & InjectFace<AutoContinueSettingsCardFace>;
58
+ export type AutoContinueSettingsCardProps = PropsLocale<'auto-continue'> & InjectFace<AutoContinueSettingsCardFace>;
59
+ /** The bundle page supplies no list container, unlike the legacy settings slot. */
60
+ export declare function AutoContinueSettingsPage(props: AutoContinueSettingsCardProps): import("react").JSX.Element;
57
61
  /**
58
62
  * Render the auto-continue card.
59
63
  * @param props - locale copy, the card snapshot, and its form actions.
@@ -84,6 +84,7 @@ export declare class CardForm<T> {
84
84
  private readonly specs;
85
85
  private readonly staged;
86
86
  private readonly listeners;
87
+ private readonly unsubscribe;
87
88
  private saving;
88
89
  private failed;
89
90
  /**
@@ -91,6 +92,8 @@ export declare class CardForm<T> {
91
92
  * @param specs - the section fields this card edits.
92
93
  */
93
94
  constructor(scope: SettingsScope<T>, specs: CardFieldSpec[]);
95
+ /** Release this editor's listeners without disposing the provider's shared form. */
96
+ dispose(): void;
94
97
  /** Publish a projection of this form, rebuilt whenever the scope or a draft changes. */
95
98
  bind<S>(project: () => S, createStore: (init: S) => SnapshotStore<S>): SnapshotStore<S>;
96
99
  /** Read the card-level state: what the Host serves, and what a save would do. */
@@ -36,7 +36,9 @@ export declare class AutoContinueRunner {
36
36
  private readonly notices;
37
37
  private readonly noticeListeners;
38
38
  private readonly stateListeners;
39
+ private readonly prioritizedFollowups;
39
40
  private readonly disposeSessionEvents;
41
+ private readonly disposeInboxEvents;
40
42
  private disposed;
41
43
  /**
42
44
  * @param ctx - host plugin context (agents registry, session events, settings).
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-client-auto-continue",
3
3
  "description": "DSH Web UI plugin: automatically sends a localized continue prompt when a request is interrupted by network errors or other non-human causes",
4
- "version": "0.11.6",
4
+ "version": "0.11.8",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/types/index.d.ts",
@@ -46,7 +46,7 @@
46
46
  "build": "node build.mjs && tsc -p tsconfig.build.json",
47
47
  "watch": "node build.mjs --watch",
48
48
  "typecheck": "tsc --noEmit",
49
- "test": "node tests/simulate-host.mjs && node tests/settings-host-compat.mjs && node tests/simulate-client-loader.mjs && node tests/locale-mirror-bounded.mjs && node tests/settings-card-ui.mjs && node tests/prepare-github-package.mjs",
49
+ "test": "node tests/simulate-host.mjs && node tests/settings-host-compat.mjs && node tests/simulate-client-loader.mjs && node tests/client-settings-services.mjs && node tests/locale-mirror-bounded.mjs && node tests/settings-card-ui.mjs && node tests/prepare-github-package.mjs",
50
50
  "prepack": "npm run build"
51
51
  },
52
52
  "keywords": [
@@ -27,12 +27,12 @@ export interface SettingsScopeSnapshot<T> {
27
27
  mode: 'host' | 'memory';
28
28
  }
29
29
 
30
- /** Stable subset shared by the legacy and DSH 0.1.2 settings scopes. */
30
+ /** Stable subset shared by settings scopes and DSH 0.1.7 configuration forms. */
31
31
  export interface SettingsScope<T> {
32
32
  getSnapshot(): SettingsScopeSnapshot<T>;
33
33
  subscribe(listener: () => void): () => void;
34
- set(field: string, value: unknown): Promise<void>;
35
- unset(field: string): Promise<void>;
34
+ set(field: string, value: unknown): Promise<void | boolean>;
35
+ unset(field: string): Promise<void | boolean>;
36
36
  }
37
37
 
38
38
  interface SnapshotStoreModule {
@@ -3,7 +3,7 @@
3
3
  *
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
- * - registers the `auto-continue` settings card (`settings.plugin.item`),
6
+ * - registers the `auto-continue` settings card in the available plugin UI,
7
7
  * - subscribes to the host status bridge (SSE) and shows browser
8
8
  * notifications with action buttons (Resume now / Pause 1h) via the bridge
9
9
  * action endpoint,
@@ -21,8 +21,10 @@ import { en, zh, type SettingsCardKey } from './locales.ts';
21
21
  import {
22
22
  AutoContinueSettingsCard,
23
23
  AutoContinueSettingsCardController,
24
+ AutoContinueSettingsPage,
24
25
  } from './settings-card.tsx';
25
26
  import { startBridge } from './bridge.ts';
27
+ import type { SettingsScope } from './dsh-store-compat.ts';
26
28
 
27
29
  /** Dictionary namespace owned by this plugin. */
28
30
  const NS = 'auto-continue';
@@ -31,14 +33,27 @@ const NS = 'auto-continue';
31
33
  const SETTINGS_NS = 'auto-continue';
32
34
 
33
35
  declare module '@deepseek-ai/dsh-client-ui-slots' {
36
+ interface SlotMap {
37
+ /** DSH 0.1.7's bundle configuration seat; only the owner props we consume. */
38
+ 'plugins.bundle.config': {
39
+ kind: 'keyed';
40
+ scope: 'root';
41
+ owner: { readonly view: 'summary' | 'page' };
42
+ };
43
+ }
34
44
  interface LocaleNamespaceMap {
35
45
  /** auto-continue settings-card copy. */
36
46
  'auto-continue': SettingsCardKey;
37
47
  }
38
48
  }
39
49
 
40
- /** Services required by this plugin. */
41
- export const inject = ['slots', 'locale', 'settingsScope'];
50
+ /** Shared subset of DSH 0.1.7's provider, without a new runtime dependency. */
51
+ type ConfigFormsContext = ClientContext & {
52
+ configForms: { get<T>(entryId: string): SettingsScope<T> };
53
+ };
54
+
55
+ /** Settings services are injected separately: neither exists in every DSH cohort. */
56
+ export const inject = ['slots', 'locale'];
42
57
 
43
58
  // 浏览器侧辅助(设置卡片用): 桥状态读取与暂停解除。
44
59
  export {
@@ -55,8 +70,22 @@ export {
55
70
  */
56
71
  export function apply(ctx: ClientContext): void {
57
72
  ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'auto-continue: dictionaries');
73
+ ctx.effect(() => startBridge(), 'auto-continue: host bridge');
74
+
75
+ // Cordis waits for ALL top-level dependencies. Requiring settingsScope here
76
+ // would leave DSH 0.1.7 pending forever; requiring configForms breaks older
77
+ // hosts. Separate child fibers also follow late providers and their teardown.
78
+ ctx.inject(['settingsScope'], (settingsCtx) => {
79
+ mountSettings(settingsCtx, settingsCtx.settingsScope.bind<AutoContinueSettings>({ namespace: SETTINGS_NS }));
80
+ });
81
+ ctx.inject(['configForms'], (settingsCtx) => {
82
+ const forms = (settingsCtx as ConfigFormsContext).configForms;
83
+ mountSettings(settingsCtx, forms.get<AutoContinueSettings>(SETTINGS_NS));
84
+ });
85
+ }
58
86
 
59
- const scope = ctx.settingsScope.bind<AutoContinueSettings>({ namespace: SETTINGS_NS });
87
+ /** Attach this consumer's subscriptions and card to the provider's lifecycle. */
88
+ function mountSettings(ctx: ClientContext, scope: SettingsScope<AutoContinueSettings>): void {
60
89
  /**
61
90
  * Mirror the browser locale into the host config, with a hard per-page budget.
62
91
  *
@@ -105,15 +134,11 @@ export function apply(ctx: ClientContext): void {
105
134
  ctx.on('locale/change', syncLocale);
106
135
  syncLocale();
107
136
 
108
- // 状态桥: 订阅 host 的通知与运行时状态, 弹浏览器通知并驱动卡片面板。
109
- ctx.effect(() => startBridge(), 'auto-continue: host bridge');
110
-
111
- // Plugin configuration card: one staged form over the `auto-continue`
112
- // settings namespace, contributed to the plugin-configuration section
113
- // (Settings → Plugins). Since DSH 0.1.0-rc.7 `settings.plugin.item` is a
114
- // keyed slot dispatched by the settings namespace it edits, so the entry
115
- // registers with `key` (the namespace), like the official cards.
116
137
  const controller = new AutoContinueSettingsCardController(scope);
138
+ ctx.effect(() => () => controller.dispose(), 'auto-continue: settings form');
139
+
140
+ // Slot injection waits for the matching UI declaration. Keep the old
141
+ // settings card and the new bundle page independent of service migration.
117
142
  ctx.slots.inject('settings.plugin.item', () =>
118
143
  ctx.slots.register(
119
144
  {
@@ -125,4 +150,15 @@ export function apply(ctx: ClientContext): void {
125
150
  AutoContinueSettingsCard,
126
151
  ),
127
152
  );
153
+ ctx.slots.inject('plugins.bundle.config', () =>
154
+ ctx.slots.register(
155
+ {
156
+ name: 'plugins.bundle.config',
157
+ key: 'dsh-client-auto-continue',
158
+ locale: NS,
159
+ inject: () => controller.inject(),
160
+ },
161
+ AutoContinueSettingsPage,
162
+ ),
163
+ );
128
164
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The auto-continue settings card: edits the `auto-continue` namespace fields
3
- * from the plugin-configuration section (the `settings.plugin.item` seat).
3
+ * from the legacy settings section or the bundle's plugin-manager page.
4
4
  *
5
5
  * Self-contained card chrome (disclosure header, staged fields, save/discard
6
6
  * footer) following the plugin-card store pattern of the DSH plugin
@@ -8,7 +8,7 @@
8
8
  * tokens so the card follows the active theme.
9
9
  */
10
10
  import { useEffect, useState, type ReactNode } from 'react';
11
- import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
11
+ import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
12
12
  import { type AutoContinueSettings } from './engine.ts';
13
13
  import { createSnapshotStore, type SettingsScope, type SnapshotStore } from './dsh-store-compat.ts';
14
14
  import {
@@ -148,11 +148,25 @@ export class AutoContinueSettingsCardController {
148
148
  inject(): AutoContinueSettingsCardFace {
149
149
  return { hooks: { autoContinueSettingsCard: this.store }, ...this.form.actions() };
150
150
  }
151
+
152
+ /** Release this card's subscription to the provider-owned settings form. */
153
+ dispose(): void {
154
+ this.form.dispose();
155
+ }
151
156
  }
152
157
 
153
158
  /** Props the renderer binds for the auto-continue plugin-configuration card. */
154
159
  export type AutoContinueSettingsCardProps =
155
- PropsRuntime<'settings.plugin.item'> & PropsLocale<'auto-continue'> & InjectFace<AutoContinueSettingsCardFace>;
160
+ PropsLocale<'auto-continue'> & InjectFace<AutoContinueSettingsCardFace>;
161
+
162
+ /** The bundle page supplies no list container, unlike the legacy settings slot. */
163
+ export function AutoContinueSettingsPage(props: AutoContinueSettingsCardProps) {
164
+ return (
165
+ <ul style={{ listStyle: 'none', margin: 0, padding: 0 }}>
166
+ <AutoContinueSettingsCard {...props} />
167
+ </ul>
168
+ );
169
+ }
156
170
 
157
171
  const REPOSITORY_URL = 'https://github.com/HsiangNianian/dsh-auto-continue';
158
172
  const REPOSITORY_SLUG = 'HsiangNianian/dsh-auto-continue';
@@ -128,6 +128,7 @@ export class CardForm<T> {
128
128
  private readonly specs: Map<string, CardFieldSpec>;
129
129
  private readonly staged = new Map<string, StagedEdit>();
130
130
  private readonly listeners = new Set<() => void>();
131
+ private readonly unsubscribe: () => void;
131
132
  private saving = false;
132
133
  private failed = false;
133
134
 
@@ -140,7 +141,13 @@ export class CardForm<T> {
140
141
  specs: CardFieldSpec[],
141
142
  ) {
142
143
  this.specs = new Map(specs.map((spec) => [spec.field, spec]));
143
- this.scope.subscribe(() => this.publish());
144
+ this.unsubscribe = this.scope.subscribe(() => this.publish());
145
+ }
146
+
147
+ /** Release this editor's listeners without disposing the provider's shared form. */
148
+ dispose(): void {
149
+ this.unsubscribe();
150
+ this.listeners.clear();
144
151
  }
145
152
 
146
153
  /** Publish a projection of this form, rebuilt whenever the scope or a draft changes. */
@@ -197,7 +197,9 @@ export class AutoContinueRunner {
197
197
  private readonly notices: HostNotice[] = [];
198
198
  private readonly noticeListeners = new Set<() => void>();
199
199
  private readonly stateListeners = new Set<() => void>();
200
+ private readonly prioritizedFollowups = new Set<string>();
200
201
  private readonly disposeSessionEvents: () => void;
202
+ private readonly disposeInboxEvents: () => void;
201
203
  private disposed = false;
202
204
 
203
205
  /**
@@ -220,6 +222,37 @@ export class AutoContinueRunner {
220
222
  );
221
223
  }
222
224
  });
225
+ // followup() appends before it wakes the driver. Move only this plugin's marked
226
+ // message during the synchronous insertion event, while the driver still cannot claim it.
227
+ this.disposeInboxEvents = ctx.on('agent/inbox/inserted', ({ agent, message }) => {
228
+ if (!this.prioritizedFollowups.delete(message.id)) return;
229
+ let removed = false;
230
+ try {
231
+ const index = agent.inbox.nextTurn.findIndex(pending => pending.id === message.id);
232
+ if (index <= 0) return;
233
+ removed = agent.inbox.remove(message.id);
234
+ if (!removed) return;
235
+ agent.inbox.prepend('next-turn', message);
236
+ } catch (error) {
237
+ // Preserve the continuation even if a host-side queue mutation rejects the move.
238
+ if (removed) {
239
+ try {
240
+ agent.inbox.append('next-turn', message);
241
+ } catch (rollbackError) {
242
+ console.error(
243
+ `[auto-continue] 恢复续跑消息失败 ${agent.id}: ${
244
+ rollbackError instanceof Error ? rollbackError.message : String(rollbackError)
245
+ }`,
246
+ );
247
+ }
248
+ }
249
+ console.error(
250
+ `[auto-continue] 调整续跑消息顺序失败 ${agent.id}: ${
251
+ error instanceof Error ? error.message : String(error)
252
+ }`,
253
+ );
254
+ }
255
+ });
223
256
  const config = this.getConfig();
224
257
  if (config.scanOnBoot) {
225
258
  void this.bootScanLoop();
@@ -294,6 +327,8 @@ export class AutoContinueRunner {
294
327
  if (this.disposed) return;
295
328
  this.disposed = true;
296
329
  this.disposeSessionEvents();
330
+ this.disposeInboxEvents();
331
+ this.prioritizedFollowups.clear();
297
332
  for (const state of this.states.values()) {
298
333
  if (state.pendingTimer !== undefined) clearTimeout(state.pendingTimer);
299
334
  if (state.loopRetryTimer !== undefined) clearTimeout(state.loopRetryTimer);
@@ -874,7 +909,7 @@ export class AutoContinueRunner {
874
909
  ? config.continueTextMaxTokens
875
910
  : config.continueText;
876
911
  const text = this.buildContinueText(config, state, template);
877
- // 发送: agent.followup 是排队语义(运行中会排入 inbox, 不会打断), 天然安全
912
+ // 发送: followup 负责唤醒; 同步 inbox 插入事件会在唤醒前把本消息移到已有队列之前。
878
913
  const agent = this.ctx.agents.get(sessionId);
879
914
  if (agent === undefined) {
880
915
  this.log(`跳过 ${sessionId}(${reason}): 无 live agent`);
@@ -888,11 +923,14 @@ export class AutoContinueRunner {
888
923
  });
889
924
  // `followup` may publish the matching session event synchronously.
890
925
  trackPendingEcho(state, message.id);
926
+ if (agent.inbox.nextTurn.length > 0) this.prioritizedFollowups.add(message.id);
891
927
  try {
892
928
  agent.followup(message);
893
929
  } catch (error) {
894
930
  forgetPendingEcho(state, message.id);
895
931
  throw error;
932
+ } finally {
933
+ this.prioritizedFollowups.delete(message.id);
896
934
  }
897
935
  const now = Date.now();
898
936
  state.consecutive += 1;