dsh-client-auto-continue 0.14.3 → 0.16.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.
- package/CHANGELOG.md +35 -0
- package/README.md +44 -22
- package/README.zh.md +44 -22
- package/docs/releases/v0.16.0.md +75 -0
- package/docs/third-party-notices.md +19 -0
- package/lib/client.js +196 -49
- package/lib/client.js.map +2 -2
- package/lib/index.js +7776 -104
- package/lib/types/client/bridge.d.ts +4 -0
- package/lib/types/client/composer-toggle.d.ts +6 -4
- package/lib/types/client/index.d.ts +2 -2
- package/lib/types/client/locales.d.ts +21 -0
- package/lib/types/client/settings-card.d.ts +6 -4
- package/lib/types/host/engine.d.ts +29 -1
- package/lib/types/host/settings-migration.d.ts +14 -0
- package/lib/types/index.d.ts +22 -8
- package/lib/types/shared/core.d.ts +24 -1
- package/package.json +21 -13
- package/src/client/bridge.ts +43 -4
- package/src/client/composer-toggle.tsx +20 -12
- package/src/client/index.ts +5 -2
- package/src/client/locales.ts +56 -14
- package/src/client/settings-card.tsx +58 -18
- package/src/client/styles.ts +5 -1
- package/src/host/engine.ts +307 -24
- package/src/host/settings-migration.ts +117 -0
- package/src/index.ts +66 -12
- package/src/shared/core.ts +42 -1
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* to `/api/auto-continue-action`) and runtime state (today's stats and the
|
|
7
7
|
* paused-sessions list) consumed by the settings card's live panels.
|
|
8
8
|
*/
|
|
9
|
+
import type { RecoveryAttempt, SessionMode, SessionPolicy } from '../shared/core.ts';
|
|
9
10
|
/** 今日统计视图(与 host 引擎的 DayStats 对应)。 */
|
|
10
11
|
export interface DayStatsView {
|
|
11
12
|
date: string;
|
|
@@ -26,6 +27,9 @@ export interface PausedSessionView {
|
|
|
26
27
|
export declare function pausedSessions(): PausedSessionView[];
|
|
27
28
|
/** 当前桥状态里的今日统计(卡片面板用)。 */
|
|
28
29
|
export declare function readTodayStats(): DayStatsView;
|
|
30
|
+
export declare function readRecoveryAttempts(): RecoveryAttempt[];
|
|
31
|
+
export declare function readSessionPolicy(): SessionPolicy | undefined;
|
|
32
|
+
export declare function setSessionMode(sessionId: string, mode: SessionMode): Promise<void>;
|
|
29
33
|
/** 清零今日统计(经动作端点交给 host 引擎执行)。 */
|
|
30
34
|
export declare function resetTodayStats(): void;
|
|
31
35
|
/** 解除某个会话的暂停(经动作端点交给 host 引擎执行)。 */
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
2
2
|
import type { SnapshotStore } from './dsh-store-compat.ts';
|
|
3
|
+
import { type SessionMode, type SessionPolicy } from '../shared/core.ts';
|
|
3
4
|
export interface ComposerToggleState {
|
|
4
5
|
visible: boolean;
|
|
5
|
-
|
|
6
|
+
policy: SessionPolicy | undefined;
|
|
6
7
|
writable: boolean;
|
|
7
|
-
saving:
|
|
8
|
-
failed:
|
|
8
|
+
saving: ReadonlySet<string>;
|
|
9
|
+
failed: ReadonlySet<string>;
|
|
9
10
|
}
|
|
10
11
|
export interface ComposerToggleFace {
|
|
11
12
|
hooks: {
|
|
12
13
|
autoContinueComposer: SnapshotStore<ComposerToggleState>;
|
|
13
14
|
};
|
|
14
|
-
|
|
15
|
+
sessionId: string;
|
|
16
|
+
setMode: (mode: SessionMode) => void;
|
|
15
17
|
}
|
|
16
18
|
export declare function AutoContinueComposerToggle(props: PropsLocale<'auto-continue'> & InjectFace<ComposerToggleFace>): import("react").JSX.Element | null;
|
|
@@ -4,7 +4,7 @@
|
|
|
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
|
|
7
|
+
* - adds a per-session composer mode selector 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,
|
|
@@ -35,7 +35,7 @@ declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
|
35
35
|
}
|
|
36
36
|
/** Settings services are injected separately: neither exists in every DSH cohort. */
|
|
37
37
|
export declare const inject: string[];
|
|
38
|
-
export { pausedSessions, readTodayStats, resetTodayStats, unpauseSession, } from './bridge.ts';
|
|
38
|
+
export { pausedSessions, readTodayStats, readRecoveryAttempts, resetTodayStats, unpauseSession, } from './bridge.ts';
|
|
39
39
|
/**
|
|
40
40
|
* Plugin body: settings card + host status bridge (notifications, stats,
|
|
41
41
|
* paused sessions).
|
|
@@ -34,6 +34,12 @@ export declare const zh: {
|
|
|
34
34
|
'field.showComposerToggleHint': string;
|
|
35
35
|
'composer.label': string;
|
|
36
36
|
'composer.scope': string;
|
|
37
|
+
'composer.default': string;
|
|
38
|
+
'composer.off': string;
|
|
39
|
+
'composer.recover': string;
|
|
40
|
+
'composer.loop': string;
|
|
41
|
+
'composer.paused': string;
|
|
42
|
+
'composer.unavailable': string;
|
|
37
43
|
'composer.saving': string;
|
|
38
44
|
'composer.saveFailed': string;
|
|
39
45
|
'field.pausedHint': string;
|
|
@@ -53,6 +59,9 @@ export declare const zh: {
|
|
|
53
59
|
'field.continueTextSilent': string;
|
|
54
60
|
'field.continueTextSilentHint': string;
|
|
55
61
|
'default.continueTextSilent': "继续。你上一轮只输出了内部推理, 既没有回复也没有调用工具, 用户什么都没看到。每一轮都要以工具调用或可见回复结束。";
|
|
62
|
+
'field.continueTextInterrupted': string;
|
|
63
|
+
'field.continueTextInterruptedHint': string;
|
|
64
|
+
'default.continueTextInterrupted': "继续。宿主在你上一轮运行期间重启了; 重启时未完成的工具调用已按「结果未知」收尾。从中断处继续, 重试可能有副作用的操作前先核实外部状态。";
|
|
56
65
|
'field.guardTools': string;
|
|
57
66
|
'field.guardToolsHint': string;
|
|
58
67
|
'field.guardPendingText': string;
|
|
@@ -111,6 +120,18 @@ export declare const zh: {
|
|
|
111
120
|
'stats.byCode': string;
|
|
112
121
|
'stats.empty': string;
|
|
113
122
|
'stats.reset': string;
|
|
123
|
+
'recovery.title': string;
|
|
124
|
+
'recovery.hint': string;
|
|
125
|
+
'recovery.empty': string;
|
|
126
|
+
'recovery.count': string;
|
|
127
|
+
'recovery.consecutive': string;
|
|
128
|
+
'recovery.latest': string;
|
|
129
|
+
'recovery.reason.error': string;
|
|
130
|
+
'recovery.reason.max-tokens': string;
|
|
131
|
+
'recovery.reason.silent': string;
|
|
132
|
+
'recovery.reason.interrupted': string;
|
|
133
|
+
'recovery.reason.loop-guard': string;
|
|
134
|
+
'recovery.reason.manual': string;
|
|
114
135
|
'pause.title': string;
|
|
115
136
|
'pause.none': string;
|
|
116
137
|
'pause.clearAll': string;
|
|
@@ -18,6 +18,7 @@ export interface AutoContinueSettingsCardState extends CardShell {
|
|
|
18
18
|
resumeCompletedTurns: CardFieldState;
|
|
19
19
|
continueTextLoop: CardFieldState;
|
|
20
20
|
continueTextSilent: CardFieldState;
|
|
21
|
+
continueTextInterrupted: CardFieldState;
|
|
21
22
|
guardTools: CardFieldState;
|
|
22
23
|
guardPendingText: CardFieldState;
|
|
23
24
|
guardDoneText: CardFieldState;
|
|
@@ -55,8 +56,9 @@ export declare class AutoContinueSettingsCardController {
|
|
|
55
56
|
private readonly form;
|
|
56
57
|
private readonly store;
|
|
57
58
|
private readonly composer;
|
|
58
|
-
private composerSaving;
|
|
59
|
-
private composerFailed;
|
|
59
|
+
private readonly composerSaving;
|
|
60
|
+
private readonly composerFailed;
|
|
61
|
+
private readonly stopComposer;
|
|
60
62
|
private disposed;
|
|
61
63
|
private saveSequence;
|
|
62
64
|
private notificationFeedback;
|
|
@@ -71,9 +73,9 @@ export declare class AutoContinueSettingsCardController {
|
|
|
71
73
|
*/
|
|
72
74
|
inject(): AutoContinueSettingsCardFace;
|
|
73
75
|
private save;
|
|
74
|
-
injectComposer(): ComposerToggleFace;
|
|
76
|
+
injectComposer(sessionId: string): ComposerToggleFace;
|
|
75
77
|
private composerProjection;
|
|
76
|
-
private
|
|
78
|
+
private setMode;
|
|
77
79
|
/** Release this card's subscription to the provider-owned settings form. */
|
|
78
80
|
dispose(): void;
|
|
79
81
|
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import type { Context } from '@deepseek-ai/cordis';
|
|
16
16
|
import type { SessionId } from '@deepseek-ai/dsh-session/types';
|
|
17
|
-
import { type AutoContinueConfig, type DayStats, type NotifyAction } from '../shared/core.ts';
|
|
17
|
+
import { type AutoContinueConfig, type DayStats, type RecoveryAttempt, type NotifyAction } from '../shared/core.ts';
|
|
18
18
|
/** 通知桥事件: host 引擎产生, browser 侧订阅展示(Notification / 动作按钮)。 */
|
|
19
19
|
export interface HostNotice {
|
|
20
20
|
/** 稳定标识(供 browser 去重)。 */
|
|
@@ -34,6 +34,7 @@ export declare class AutoContinueRunner {
|
|
|
34
34
|
private readonly states;
|
|
35
35
|
private readonly pauseUntil;
|
|
36
36
|
private dayStats;
|
|
37
|
+
private readonly recoveryAttempts;
|
|
37
38
|
private readonly notices;
|
|
38
39
|
private readonly noticeListeners;
|
|
39
40
|
private readonly stateListeners;
|
|
@@ -44,8 +45,15 @@ export declare class AutoContinueRunner {
|
|
|
44
45
|
private readonly bootScannedSessions;
|
|
45
46
|
/** Also bound diagnostics when even an agent's session getter is unavailable. */
|
|
46
47
|
private readonly bootScanErrors;
|
|
48
|
+
/** 存储扫描已裁决的会话 id, 避免每轮重复冷读大日志。 */
|
|
49
|
+
private readonly storedSwept;
|
|
50
|
+
/** 存储会话的连续观察/物化失败次数, 触达 SWEEP_MAX_FAILURES 后不再重试。 */
|
|
51
|
+
private readonly storedSweepFailures;
|
|
52
|
+
private storedSweepAnnounced;
|
|
47
53
|
private bootScanTimer;
|
|
48
54
|
private wakeBootScan;
|
|
55
|
+
private storedSweep;
|
|
56
|
+
private readonly stopStoredSweep;
|
|
49
57
|
/**
|
|
50
58
|
* @param ctx - host plugin context (agents registry, session events).
|
|
51
59
|
* @param getConfig - read the current resolved configuration (entry config).
|
|
@@ -54,6 +62,7 @@ export declare class AutoContinueRunner {
|
|
|
54
62
|
private log;
|
|
55
63
|
/** 对外(状态桥): 今日统计快照。 */
|
|
56
64
|
todayStats(): DayStats;
|
|
65
|
+
recentRecoveryAttempts(): RecoveryAttempt[];
|
|
57
66
|
/** 对外(状态桥): 当前生效的会话级暂停列表。 */
|
|
58
67
|
activePauses(): {
|
|
59
68
|
sessionId: SessionId;
|
|
@@ -64,6 +73,8 @@ export declare class AutoContinueRunner {
|
|
|
64
73
|
/** 对外(状态桥): 订阅运行时状态变化(统计/暂停列表)。 */
|
|
65
74
|
subscribeState(listener: () => void): () => void;
|
|
66
75
|
private emitState;
|
|
76
|
+
private sessionConfig;
|
|
77
|
+
configurationChanged(): void;
|
|
67
78
|
/** 对外(状态桥): 消费待展示的通知。 */
|
|
68
79
|
drainNotices(): HostNotice[];
|
|
69
80
|
/** 通知动作(browser 通知按钮回传): 立即续跑 / 暂停该会话 / 解除暂停 / 清零统计。 */
|
|
@@ -137,6 +148,23 @@ export declare class AutoContinueRunner {
|
|
|
137
148
|
private bootScanLoop;
|
|
138
149
|
/** Inspect newly available sessions; process each settled startup history once. */
|
|
139
150
|
private scanInterrupted;
|
|
151
|
+
/** Bound cold reads even if a backend ignores cancellation; release late leases. */
|
|
152
|
+
private readStored;
|
|
153
|
+
/**
|
|
154
|
+
* 存储扫描: 枚举持久化会话, 把尾部命中恢复谓词的未加载会话物化为
|
|
155
|
+
* live agent。宿主重启后 agent 仅在客户端打开会话时才懒加载, 不物化
|
|
156
|
+
* 则启动扫描永远看不到它们; 谓词与上方扫描一致, 仅失败类原因。
|
|
157
|
+
*/
|
|
158
|
+
private sweepStoredSessions;
|
|
159
|
+
/**
|
|
160
|
+
* 按会话记录的 preset 组合把存储会话恢复为 live agent(镜像会话控制
|
|
161
|
+
* 器的 adopt 路径: preset 挂载 + 会话已记录的模型选择回装)。模型选择
|
|
162
|
+
* 以日志记录的 request-header 播种 agentOptions——{{model}}/{{provider}}
|
|
163
|
+
* 提示变量与首次请求路由都读它, 驱动器还会因路由吻合而自行回装日志
|
|
164
|
+
* 记录的 effort; 无落点(从未发过请求的会话)回落宿主默认。恢复时追
|
|
165
|
+
* 加的合成 turn/end(`interrupted`)随后由常规扫描按既有关卡恢复。
|
|
166
|
+
*/
|
|
167
|
+
private materializeStored;
|
|
140
168
|
/** Captured identity only: even session.id can throw when the header is damaged. */
|
|
141
169
|
private logBootScanFailure;
|
|
142
170
|
/** 从历史事件恢复上一步工具调用状态(扫描路径的幂等护栏)。 */
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { AutoContinueSettings } from '../shared/core.ts';
|
|
3
|
+
/** Recover an import interrupted between the profile save and completion file. */
|
|
4
|
+
export declare const LEGACY_SETTINGS_IMPORTED = "_legacySettingsImported";
|
|
5
|
+
export type EntrySettings = AutoContinueSettings & {
|
|
6
|
+
_legacySettingsImported?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type LiveEntrySettings = {
|
|
9
|
+
get(): EntrySettings | undefined;
|
|
10
|
+
};
|
|
11
|
+
/** Import the mixed desktop host's legacy document through the profile editor.
|
|
12
|
+
* The original file stays untouched, including other plugins' settings.
|
|
13
|
+
*/
|
|
14
|
+
export declare function migrateLegacySettings(ctx: Context, config: LiveEntrySettings, fields: readonly string[], validate: (value: AutoContinueSettings) => unknown): () => EntrySettings | undefined;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import type { Context } from '@deepseek-ai/cordis';
|
|
14
14
|
import z from '@deepseek-ai/schemastery';
|
|
15
|
+
import { type EntrySettings, type LiveEntrySettings } from './host/settings-migration.ts';
|
|
15
16
|
import { type AutoContinueSettings } from './shared/core.ts';
|
|
16
17
|
/** Settings namespace of the auto-continue plugin (lowercase kebab-case). */
|
|
17
18
|
export declare const AUTO_CONTINUE_NS = "auto-continue";
|
|
18
|
-
/** Wire schema; blank localized text fields tell resolveConfig() to select the active locale's defaults. */
|
|
19
19
|
export declare const AutoContinueSchema: z<Schemastery.ObjectS<{
|
|
20
20
|
/** Active browser/UI locale mirrored by the client. */
|
|
21
21
|
locale: z<string, string>;
|
|
@@ -31,6 +31,8 @@ export declare const AutoContinueSchema: z<Schemastery.ObjectS<{
|
|
|
31
31
|
continueTextSilent: z<string, string>;
|
|
32
32
|
/** Text sent for each autonomous-loop continuation (same placeholders as `continueText`). */
|
|
33
33
|
continueTextLoop: z<string, string>;
|
|
34
|
+
/** Text sent when a turn is recovered after a harness restart closed it as interrupted. */
|
|
35
|
+
continueTextInterrupted: z<string, string>;
|
|
34
36
|
/** Idempotency guard: inspect the last tool call before resuming and steer the model. */
|
|
35
37
|
guardTools: z<boolean, boolean>;
|
|
36
38
|
/** Guard text appended when the last tool call has no confirmed result (it may have partially executed). */
|
|
@@ -63,7 +65,9 @@ export declare const AutoContinueSchema: z<Schemastery.ObjectS<{
|
|
|
63
65
|
notify: z<boolean, boolean>;
|
|
64
66
|
/** Globally pause auto-continue: no live or scan send. */
|
|
65
67
|
paused: z<boolean, boolean>;
|
|
66
|
-
/**
|
|
68
|
+
/** Persist choices by session, including an explicit return to the profile default. */
|
|
69
|
+
sessionModes: z<import("@deepseek-ai/cosmokit").Dict<"default" | "off" | "recover" | "loop", string>, import("@deepseek-ai/cosmokit").Dict<"default" | "off" | "recover" | "loop", string>>;
|
|
70
|
+
/** Show the session mode selector in the conversation composer. */
|
|
67
71
|
showComposerToggle: z<boolean, boolean>;
|
|
68
72
|
/** Loop guard: detect a running turn spinning in place and restart it. */
|
|
69
73
|
loopGuard: z<boolean, boolean>;
|
|
@@ -94,6 +98,8 @@ export declare const AutoContinueSchema: z<Schemastery.ObjectS<{
|
|
|
94
98
|
continueTextSilent: z<string, string>;
|
|
95
99
|
/** Text sent for each autonomous-loop continuation (same placeholders as `continueText`). */
|
|
96
100
|
continueTextLoop: z<string, string>;
|
|
101
|
+
/** Text sent when a turn is recovered after a harness restart closed it as interrupted. */
|
|
102
|
+
continueTextInterrupted: z<string, string>;
|
|
97
103
|
/** Idempotency guard: inspect the last tool call before resuming and steer the model. */
|
|
98
104
|
guardTools: z<boolean, boolean>;
|
|
99
105
|
/** Guard text appended when the last tool call has no confirmed result (it may have partially executed). */
|
|
@@ -126,7 +132,9 @@ export declare const AutoContinueSchema: z<Schemastery.ObjectS<{
|
|
|
126
132
|
notify: z<boolean, boolean>;
|
|
127
133
|
/** Globally pause auto-continue: no live or scan send. */
|
|
128
134
|
paused: z<boolean, boolean>;
|
|
129
|
-
/**
|
|
135
|
+
/** Persist choices by session, including an explicit return to the profile default. */
|
|
136
|
+
sessionModes: z<import("@deepseek-ai/cosmokit").Dict<"default" | "off" | "recover" | "loop", string>, import("@deepseek-ai/cosmokit").Dict<"default" | "off" | "recover" | "loop", string>>;
|
|
137
|
+
/** Show the session mode selector in the conversation composer. */
|
|
130
138
|
showComposerToggle: z<boolean, boolean>;
|
|
131
139
|
/** Loop guard: detect a running turn spinning in place and restart it. */
|
|
132
140
|
loopGuard: z<boolean, boolean>;
|
|
@@ -144,9 +152,7 @@ export declare const AutoContinueSchema: z<Schemastery.ObjectS<{
|
|
|
144
152
|
loopText: z<string, string>;
|
|
145
153
|
}>>;
|
|
146
154
|
/** Loader config is a live reference on DSH 0.1.7, and a plain object on older hosts. */
|
|
147
|
-
export type AutoContinueEntryConfig =
|
|
148
|
-
get(): AutoContinueSettings | undefined;
|
|
149
|
-
};
|
|
155
|
+
export type AutoContinueEntryConfig = EntrySettings | LiveEntrySettings;
|
|
150
156
|
export declare const Config: z<Schemastery.ObjectS<{
|
|
151
157
|
/** Active browser/UI locale mirrored by the client. */
|
|
152
158
|
locale: z<string, string>;
|
|
@@ -162,6 +168,8 @@ export declare const Config: z<Schemastery.ObjectS<{
|
|
|
162
168
|
continueTextSilent: z<string, string>;
|
|
163
169
|
/** Text sent for each autonomous-loop continuation (same placeholders as `continueText`). */
|
|
164
170
|
continueTextLoop: z<string, string>;
|
|
171
|
+
/** Text sent when a turn is recovered after a harness restart closed it as interrupted. */
|
|
172
|
+
continueTextInterrupted: z<string, string>;
|
|
165
173
|
/** Idempotency guard: inspect the last tool call before resuming and steer the model. */
|
|
166
174
|
guardTools: z<boolean, boolean>;
|
|
167
175
|
/** Guard text appended when the last tool call has no confirmed result (it may have partially executed). */
|
|
@@ -194,7 +202,9 @@ export declare const Config: z<Schemastery.ObjectS<{
|
|
|
194
202
|
notify: z<boolean, boolean>;
|
|
195
203
|
/** Globally pause auto-continue: no live or scan send. */
|
|
196
204
|
paused: z<boolean, boolean>;
|
|
197
|
-
/**
|
|
205
|
+
/** Persist choices by session, including an explicit return to the profile default. */
|
|
206
|
+
sessionModes: z<import("@deepseek-ai/cosmokit").Dict<"default" | "off" | "recover" | "loop", string>, import("@deepseek-ai/cosmokit").Dict<"default" | "off" | "recover" | "loop", string>>;
|
|
207
|
+
/** Show the session mode selector in the conversation composer. */
|
|
198
208
|
showComposerToggle: z<boolean, boolean>;
|
|
199
209
|
/** Loop guard: detect a running turn spinning in place and restart it. */
|
|
200
210
|
loopGuard: z<boolean, boolean>;
|
|
@@ -225,6 +235,8 @@ export declare const Config: z<Schemastery.ObjectS<{
|
|
|
225
235
|
continueTextSilent: z<string, string>;
|
|
226
236
|
/** Text sent for each autonomous-loop continuation (same placeholders as `continueText`). */
|
|
227
237
|
continueTextLoop: z<string, string>;
|
|
238
|
+
/** Text sent when a turn is recovered after a harness restart closed it as interrupted. */
|
|
239
|
+
continueTextInterrupted: z<string, string>;
|
|
228
240
|
/** Idempotency guard: inspect the last tool call before resuming and steer the model. */
|
|
229
241
|
guardTools: z<boolean, boolean>;
|
|
230
242
|
/** Guard text appended when the last tool call has no confirmed result (it may have partially executed). */
|
|
@@ -257,7 +269,9 @@ export declare const Config: z<Schemastery.ObjectS<{
|
|
|
257
269
|
notify: z<boolean, boolean>;
|
|
258
270
|
/** Globally pause auto-continue: no live or scan send. */
|
|
259
271
|
paused: z<boolean, boolean>;
|
|
260
|
-
/**
|
|
272
|
+
/** Persist choices by session, including an explicit return to the profile default. */
|
|
273
|
+
sessionModes: z<import("@deepseek-ai/cosmokit").Dict<"default" | "off" | "recover" | "loop", string>, import("@deepseek-ai/cosmokit").Dict<"default" | "off" | "recover" | "loop", string>>;
|
|
274
|
+
/** Show the session mode selector in the conversation composer. */
|
|
261
275
|
showComposerToggle: z<boolean, boolean>;
|
|
262
276
|
/** Loop guard: detect a running turn spinning in place and restart it. */
|
|
263
277
|
loopGuard: z<boolean, boolean>;
|
|
@@ -7,6 +7,15 @@
|
|
|
7
7
|
import type { SessionEvent } from '@deepseek-ai/dsh-session/types';
|
|
8
8
|
/** Supported UI/config locales. Any unknown browser locale falls back to Chinese. */
|
|
9
9
|
export type AutoContinueLocale = 'en' | 'zh';
|
|
10
|
+
export type SessionMode = 'default' | 'off' | 'recover' | 'loop';
|
|
11
|
+
export interface SessionPolicy {
|
|
12
|
+
modes: Record<string, SessionMode>;
|
|
13
|
+
defaultMode: 'recover' | 'loop';
|
|
14
|
+
paused: boolean;
|
|
15
|
+
writable: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare const isSessionMode: (value: unknown) => value is SessionMode;
|
|
18
|
+
export declare function sessionMode(modes: Record<string, SessionMode>, sessionId: string): SessionMode;
|
|
10
19
|
/** Locale-owned defaults for the user-editable text fields. */
|
|
11
20
|
export declare const LOCALIZED_TEXT_DEFAULTS: {
|
|
12
21
|
readonly zh: {
|
|
@@ -14,6 +23,7 @@ export declare const LOCALIZED_TEXT_DEFAULTS: {
|
|
|
14
23
|
readonly continueTextMaxTokens: "继续";
|
|
15
24
|
readonly continueTextSilent: "继续。你上一轮只输出了内部推理, 既没有回复也没有调用工具, 用户什么都没看到。每一轮都要以工具调用或可见回复结束。";
|
|
16
25
|
readonly continueTextLoop: "继续";
|
|
26
|
+
readonly continueTextInterrupted: "继续。宿主在你上一轮运行期间重启了; 重启时未完成的工具调用已按「结果未知」收尾。从中断处继续, 重试可能有副作用的操作前先核实外部状态。";
|
|
17
27
|
readonly guardPendingText: "(上一步工具「{tool}」可能未完成, 先确认状态再继续, 不要重复执行)";
|
|
18
28
|
readonly guardDoneText: "(上一步工具「{tool}」已完成, 结果: {result}; 不要重复执行, 直接继续)";
|
|
19
29
|
readonly loopText: "(检测到你可能陷入循环, 请停止重复刚才的动作, 换一种方式继续)";
|
|
@@ -23,6 +33,7 @@ export declare const LOCALIZED_TEXT_DEFAULTS: {
|
|
|
23
33
|
readonly continueTextMaxTokens: "Continue";
|
|
24
34
|
readonly continueTextSilent: "Continue. Your previous turn ended with internal reasoning only, with no message and no tool call, so nothing reached the user. Always finish a turn with a tool call or a visible answer.";
|
|
25
35
|
readonly continueTextLoop: "Continue";
|
|
36
|
+
readonly continueTextInterrupted: "Continue. The harness was restarted while your previous turn was still running; tool calls pending at the restart are recorded with unknown outcomes. Resume where you left off, verifying external state before retrying anything that may have side effects.";
|
|
26
37
|
readonly guardPendingText: "(The previous tool \"{tool}\" may not have completed. Check its state before continuing and do not run it again.)";
|
|
27
38
|
readonly guardDoneText: "(The previous tool \"{tool}\" completed successfully. Result: {result}; do not run it again. Continue from there.)";
|
|
28
39
|
readonly loopText: "(You may be stuck in a loop. Stop repeating the last action and continue with a different approach.)";
|
|
@@ -44,6 +55,8 @@ export interface AutoContinueSettings {
|
|
|
44
55
|
continueTextSilent?: string;
|
|
45
56
|
/** Text sent for each autonomous-loop continuation (same placeholders as `continueText`). */
|
|
46
57
|
continueTextLoop?: string;
|
|
58
|
+
/** Text sent when a turn is recovered after a harness restart closed it as interrupted. */
|
|
59
|
+
continueTextInterrupted?: string;
|
|
47
60
|
/** Idempotency guard: inspect the last tool call before resuming and steer the model. */
|
|
48
61
|
guardTools?: boolean;
|
|
49
62
|
/** Guard text appended when the last tool call has no confirmed result (it may have partially executed). */
|
|
@@ -76,7 +89,9 @@ export interface AutoContinueSettings {
|
|
|
76
89
|
notify?: boolean;
|
|
77
90
|
/** Globally pause auto-continue: no live or scan send, queued pending sends cancelled. */
|
|
78
91
|
paused?: boolean;
|
|
79
|
-
/**
|
|
92
|
+
/** Persistent per-session overrides; default explicitly inherits the profile default. */
|
|
93
|
+
sessionModes?: Record<string, SessionMode>;
|
|
94
|
+
/** Show the session mode selector in the conversation composer. */
|
|
80
95
|
showComposerToggle?: boolean;
|
|
81
96
|
/** Loop guard: detect a running turn spinning in place (short talk without tools, or the same tool repeating) and restart it. */
|
|
82
97
|
loopGuard?: boolean;
|
|
@@ -255,6 +270,13 @@ export declare class ToolInvocationTracker {
|
|
|
255
270
|
/** 自适应退避: 同一会话连续失败时的有效冷却间隔。 */
|
|
256
271
|
export declare function effectiveCooldown(consecutive: number, base: number, factor: number, max: number): number;
|
|
257
272
|
export declare function sleep(ms: number): Promise<void>;
|
|
273
|
+
/** A sent recovery prompt, not proof that the following turn succeeded. */
|
|
274
|
+
export interface RecoveryAttempt {
|
|
275
|
+
sessionId: string;
|
|
276
|
+
at: number;
|
|
277
|
+
reason: 'error' | 'max-tokens' | 'silent' | 'interrupted' | 'loop-guard' | 'manual';
|
|
278
|
+
consecutive: number;
|
|
279
|
+
}
|
|
258
280
|
/** 一天的自动继续统计(host 单实例内存态)。 */
|
|
259
281
|
export interface DayStats {
|
|
260
282
|
/** 本地日期 YYYY-MM-DD。 */
|
|
@@ -287,6 +309,7 @@ export interface SessionState {
|
|
|
287
309
|
pendingEchoMessageIds: Map<string, number>;
|
|
288
310
|
/** 宽限期定时器(进行中的待发送)。 */
|
|
289
311
|
pendingTimer: ReturnType<typeof setTimeout> | undefined;
|
|
312
|
+
pendingReason?: string;
|
|
290
313
|
/** 宿主权威 running 位(来自 host/session-status 与回合事件)。 */
|
|
291
314
|
running: boolean | undefined;
|
|
292
315
|
/** 当前排队消息数(来自 session/queue 帧)。 */
|
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.
|
|
4
|
+
"version": "0.16.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/types/index.d.ts",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"tsconfig.build.json",
|
|
27
27
|
"README.md",
|
|
28
28
|
"README.zh.md",
|
|
29
|
+
"CHANGELOG.md",
|
|
29
30
|
"LICENSE"
|
|
30
31
|
],
|
|
31
32
|
"dsh": {
|
|
@@ -46,8 +47,8 @@
|
|
|
46
47
|
"build": "node build.mjs && tsc -p tsconfig.build.json",
|
|
47
48
|
"watch": "node build.mjs --watch",
|
|
48
49
|
"typecheck": "tsc --noEmit",
|
|
49
|
-
"test:runtime": "node tests/settings-host-live.mjs 0.1.7 && node tests/settings-host-live.mjs 0.2.0 && node tests/settings-host-live.mjs 0.2.1 && node tests/profile-compatibility.mjs 0.2.0 && node tests/profile-compatibility.mjs 0.2.1 && node tests/client-settings-services.mjs 0.2.0 && node tests/client-settings-services.mjs 0.2.1 && node tests/boot-scan-host-live.mjs 0.2.0-rc.2 && node tests/boot-scan-host-live.mjs 0.2.1 && node tests/settings-host-live.mjs 0.2.1-rc.2 && node tests/profile-compatibility.mjs 0.2.1-rc.2",
|
|
50
|
-
"test": "node tests/loop-guard-progress.mjs && node tests/scan-on-boot.mjs && node tests/boot-scan-isolation.mjs && node tests/silent-turn-boundaries.mjs && node tests/autonomous-loop.mjs && node tests/manual-resume-pauses.mjs && node tests/stats-freshness.mjs && 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/client-settings-form.mjs && node tests/locale-mirror-bounded.mjs && node tests/settings-card-ui.mjs && node tests/composer-toggle.mjs && node tests/settings-notifications.mjs && node tests/prepare-github-package.mjs",
|
|
50
|
+
"test:runtime": "node tests/settings-host-live.mjs 0.1.7 && node tests/settings-host-live.mjs 0.2.0 && node tests/settings-host-live.mjs 0.2.1 && node tests/profile-compatibility.mjs 0.2.0 && node tests/profile-compatibility.mjs 0.2.1 && node tests/client-settings-services.mjs 0.2.0 && node tests/client-settings-services.mjs 0.2.1 && node tests/boot-scan-host-live.mjs 0.2.0-rc.2 && node tests/boot-scan-host-live.mjs 0.2.1 && node tests/settings-host-live.mjs 0.2.1-rc.2 && node tests/profile-compatibility.mjs 0.2.1-rc.2 && node tests/boot-scan-restart-live.mjs && node tests/settings-host-live.mjs 0.2.1-rc.2 mixed && node tests/settings-migration.mjs",
|
|
51
|
+
"test": "node tests/boot-scan-stored-sweep.mjs && node tests/loop-guard-progress.mjs && node tests/scan-on-boot.mjs && node tests/boot-scan-isolation.mjs && node tests/silent-turn-boundaries.mjs && node tests/autonomous-loop.mjs && node tests/session-modes.mjs && node tests/manual-resume-pauses.mjs && node tests/stats-freshness.mjs && 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/client-settings-form.mjs && node tests/locale-mirror-bounded.mjs && node tests/settings-card-ui.mjs && node tests/composer-toggle.mjs && node tests/settings-notifications.mjs && node tests/prepare-github-package.mjs",
|
|
51
52
|
"prepack": "npm run build"
|
|
52
53
|
},
|
|
53
54
|
"keywords": [
|
|
@@ -67,16 +68,23 @@
|
|
|
67
68
|
"esbuild": "^0.25.0",
|
|
68
69
|
"typescript": "~5.8.0",
|
|
69
70
|
"@types/react": "~18.3.1",
|
|
70
|
-
"@deepseek-ai/cordis": "
|
|
71
|
-
"@deepseek-ai/dsh-client-connection": "
|
|
72
|
-
"@deepseek-ai/dsh-client-locale": "
|
|
73
|
-
"@deepseek-ai/dsh-client-ui-settings": "
|
|
74
|
-
"@deepseek-ai/dsh-client-ui-settings-plugins": "
|
|
75
|
-
"@deepseek-ai/dsh-client-ui-slots": "
|
|
76
|
-
"@deepseek-ai/dsh-session": "
|
|
77
|
-
"@deepseek-ai/dsh-settings": "
|
|
78
|
-
"@deepseek-ai/schemastery": "
|
|
79
|
-
"@types/node": "^22.0.0"
|
|
71
|
+
"@deepseek-ai/cordis": "4.0.2",
|
|
72
|
+
"@deepseek-ai/dsh-client-connection": "0.1.2-rc.1",
|
|
73
|
+
"@deepseek-ai/dsh-client-locale": "0.1.2-rc.1",
|
|
74
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.1.2-rc.1",
|
|
75
|
+
"@deepseek-ai/dsh-client-ui-settings-plugins": "0.1.2-rc.1",
|
|
76
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.1.2-rc.1",
|
|
77
|
+
"@deepseek-ai/dsh-session": "0.1.2-rc.1",
|
|
78
|
+
"@deepseek-ai/dsh-settings": "0.1.2-rc.1",
|
|
79
|
+
"@deepseek-ai/schemastery": "3.18.2",
|
|
80
|
+
"@types/node": "^22.0.0",
|
|
81
|
+
"yaml": "2.9.1",
|
|
82
|
+
"@deepseek-ai/dsh-agent": "0.1.2-rc.1",
|
|
83
|
+
"@deepseek-ai/dsh-client-store": "0.1.2-rc.1",
|
|
84
|
+
"@deepseek-ai/dsh-client-ui-renderer": "0.1.2-rc.1",
|
|
85
|
+
"@deepseek-ai/dsh-host-webserver": "0.1.2-rc.1",
|
|
86
|
+
"@deepseek-ai/dsh-llm": "0.1.2-rc.1",
|
|
87
|
+
"react-dom": "^18.2.0"
|
|
80
88
|
},
|
|
81
89
|
"license": "MIT",
|
|
82
90
|
"peerDependencies": {
|
package/src/client/bridge.ts
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* paused-sessions list) consumed by the settings card's live panels.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import type { RecoveryAttempt, SessionMode, SessionPolicy } from '../shared/core.ts';
|
|
11
|
+
|
|
10
12
|
/** 今日统计视图(与 host 引擎的 DayStats 对应)。 */
|
|
11
13
|
export interface DayStatsView {
|
|
12
14
|
date: string;
|
|
@@ -28,6 +30,8 @@ export interface PausedSessionView {
|
|
|
28
30
|
interface BridgeState {
|
|
29
31
|
stats: DayStatsView;
|
|
30
32
|
paused: PausedSessionView[];
|
|
33
|
+
recoveryAttempts: RecoveryAttempt[];
|
|
34
|
+
sessionPolicy?: SessionPolicy;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
interface BridgeNotice {
|
|
@@ -50,7 +54,7 @@ const EMPTY_STATS: DayStatsView = {
|
|
|
50
54
|
byCode: {},
|
|
51
55
|
};
|
|
52
56
|
|
|
53
|
-
let state: BridgeState = { stats: EMPTY_STATS, paused: [] };
|
|
57
|
+
let state: BridgeState = { stats: EMPTY_STATS, paused: [], recoveryAttempts: [] };
|
|
54
58
|
const listeners = new Set<() => void>();
|
|
55
59
|
|
|
56
60
|
/** 当前桥状态里的已暂停会话(卡片面板用)。 */
|
|
@@ -63,6 +67,27 @@ export function readTodayStats(): DayStatsView {
|
|
|
63
67
|
return state.stats;
|
|
64
68
|
}
|
|
65
69
|
|
|
70
|
+
export function readRecoveryAttempts(): RecoveryAttempt[] {
|
|
71
|
+
return state.recoveryAttempts;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function readSessionPolicy(): SessionPolicy | undefined {
|
|
75
|
+
return state.sessionPolicy;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function setSessionMode(sessionId: string, mode: SessionMode): Promise<void> {
|
|
79
|
+
if (!state.sessionPolicy?.writable) throw new Error('Session settings are unavailable');
|
|
80
|
+
const response = await fetch('/api/auto-continue-action', {
|
|
81
|
+
method: 'POST',
|
|
82
|
+
headers: { 'content-type': 'application/json' },
|
|
83
|
+
body: JSON.stringify({ action: 'set-session-mode', sessionId, mode }),
|
|
84
|
+
});
|
|
85
|
+
const result = await response.json();
|
|
86
|
+
if (!response.ok || result?.ok !== true || result.sessionId !== sessionId || result.mode !== mode) {
|
|
87
|
+
throw new Error('Session mode was not saved');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
66
91
|
/** 清零今日统计(经动作端点交给 host 引擎执行)。 */
|
|
67
92
|
export function resetTodayStats(): void {
|
|
68
93
|
void postAction({ action: 'reset-stats' });
|
|
@@ -94,11 +119,16 @@ async function postAction(payload: { action: string; sessionId?: string }): Prom
|
|
|
94
119
|
}
|
|
95
120
|
}
|
|
96
121
|
|
|
97
|
-
function handleEvent(event: { type: string; notice?: BridgeNotice; stats?: DayStatsView; paused?: PausedSessionView[] }): void {
|
|
122
|
+
function handleEvent(event: { type: string; notice?: BridgeNotice; stats?: DayStatsView; paused?: PausedSessionView[]; recoveryAttempts?: RecoveryAttempt[]; sessionPolicy?: SessionPolicy }): void {
|
|
98
123
|
if (event.type === 'state') {
|
|
124
|
+
const policy = event.sessionPolicy;
|
|
99
125
|
state = {
|
|
100
126
|
stats: event.stats ?? EMPTY_STATS,
|
|
101
127
|
paused: event.paused ?? [],
|
|
128
|
+
recoveryAttempts: event.recoveryAttempts ?? [],
|
|
129
|
+
sessionPolicy: policy && typeof policy.modes === 'object' && policy.modes !== null && !Array.isArray(policy.modes) &&
|
|
130
|
+
(policy.defaultMode === 'recover' || policy.defaultMode === 'loop') && typeof policy.paused === 'boolean' && typeof policy.writable === 'boolean'
|
|
131
|
+
? policy : undefined,
|
|
102
132
|
};
|
|
103
133
|
for (const listener of listeners) listener();
|
|
104
134
|
} else if (event.type === 'notice' && event.notice !== undefined) {
|
|
@@ -157,6 +187,11 @@ function showNotification(notice: BridgeNotice): void {
|
|
|
157
187
|
export function startBridge(): () => void {
|
|
158
188
|
let stopped = false;
|
|
159
189
|
let controller: AbortController | undefined;
|
|
190
|
+
const disconnected = () => {
|
|
191
|
+
state = { ...state, sessionPolicy: undefined };
|
|
192
|
+
for (const listener of listeners) listener();
|
|
193
|
+
};
|
|
194
|
+
disconnected();
|
|
160
195
|
|
|
161
196
|
const loop = async (): Promise<void> => {
|
|
162
197
|
while (!stopped) {
|
|
@@ -169,7 +204,7 @@ export function startBridge(): () => void {
|
|
|
169
204
|
let buffer = '';
|
|
170
205
|
for (;;) {
|
|
171
206
|
const { done, value } = await reader.read();
|
|
172
|
-
if (done) break;
|
|
207
|
+
if (done || stopped) break;
|
|
173
208
|
buffer += decoder.decode(value, { stream: true });
|
|
174
209
|
let idx = buffer.indexOf('\n\n');
|
|
175
210
|
while (idx !== -1) {
|
|
@@ -190,7 +225,10 @@ export function startBridge(): () => void {
|
|
|
190
225
|
} catch {
|
|
191
226
|
/* 断线: 退避重连 */
|
|
192
227
|
}
|
|
193
|
-
if (!stopped)
|
|
228
|
+
if (!stopped) {
|
|
229
|
+
disconnected();
|
|
230
|
+
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
231
|
+
}
|
|
194
232
|
}
|
|
195
233
|
};
|
|
196
234
|
void loop();
|
|
@@ -198,5 +236,6 @@ export function startBridge(): () => void {
|
|
|
198
236
|
return () => {
|
|
199
237
|
stopped = true;
|
|
200
238
|
controller?.abort();
|
|
239
|
+
disconnected();
|
|
201
240
|
};
|
|
202
241
|
}
|
|
@@ -1,33 +1,41 @@
|
|
|
1
1
|
import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
2
2
|
import type { SnapshotStore } from './dsh-store-compat.ts';
|
|
3
|
-
import {
|
|
3
|
+
import { isSessionMode, sessionMode, type SessionMode, type SessionPolicy } from '../shared/core.ts';
|
|
4
4
|
|
|
5
5
|
export interface ComposerToggleState {
|
|
6
6
|
visible: boolean;
|
|
7
|
-
|
|
7
|
+
policy: SessionPolicy | undefined;
|
|
8
8
|
writable: boolean;
|
|
9
|
-
saving:
|
|
10
|
-
failed:
|
|
9
|
+
saving: ReadonlySet<string>;
|
|
10
|
+
failed: ReadonlySet<string>;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export interface ComposerToggleFace {
|
|
14
14
|
hooks: { autoContinueComposer: SnapshotStore<ComposerToggleState> };
|
|
15
|
-
|
|
15
|
+
sessionId: string;
|
|
16
|
+
setMode: (mode: SessionMode) => void;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
export function AutoContinueComposerToggle(props: PropsLocale<'auto-continue'> & InjectFace<ComposerToggleFace>) {
|
|
19
20
|
const state = props.useAutoContinueComposer((snapshot) => snapshot);
|
|
20
|
-
if (!state.visible) return null;
|
|
21
|
-
const
|
|
21
|
+
if (!state.visible || !props.sessionId) return null;
|
|
22
|
+
const saving = state.saving.has(props.sessionId);
|
|
23
|
+
const policy = state.policy;
|
|
24
|
+
const title = props.t(!policy ? 'composer.unavailable' : !state.writable ? 'chrome.readOnly' : saving ? 'composer.saving' : 'composer.scope');
|
|
22
25
|
return (
|
|
23
26
|
<div className="dshAcComposer" title={title}>
|
|
24
27
|
<span className="dshAcComposerLabel">{props.t('composer.label')}</span>
|
|
25
|
-
<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
<select className="dshAcMode" aria-label={props.t('composer.label')} title={title}
|
|
29
|
+
disabled={!state.writable || saving} value={sessionMode(policy?.modes ?? {}, props.sessionId)}
|
|
30
|
+
onChange={event => { if (isSessionMode(event.target.value)) props.setMode(event.target.value); }}>
|
|
31
|
+
<option value="default">{props.t('composer.default')}{policy ? ` (${props.t(`composer.${policy.defaultMode}`)})` : ''}</option>
|
|
32
|
+
<option value="off">{props.t('composer.off')}</option>
|
|
33
|
+
<option value="recover">{props.t('composer.recover')}</option>
|
|
34
|
+
<option value="loop">{props.t('composer.loop')}</option>
|
|
35
|
+
</select>
|
|
36
|
+
{policy?.paused && <span className="dshAcComposerLabel">{props.t('composer.paused')}</span>}
|
|
29
37
|
<span className="dshAcComposerError" role="status">
|
|
30
|
-
{state.failed ? props.t('composer.saveFailed') : null}
|
|
38
|
+
{state.failed.has(props.sessionId) ? props.t('composer.saveFailed') : saving ? props.t('composer.saving') : !policy ? props.t('composer.unavailable') : null}
|
|
31
39
|
</span>
|
|
32
40
|
</div>
|
|
33
41
|
);
|