dsh-client-auto-continue 0.11.8 → 0.12.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/README.md +111 -61
- package/README.zh.md +111 -61
- package/docs/screenshots/01-settings-section.png +0 -0
- package/docs/screenshots/01-settings-section.zh.png +0 -0
- package/docs/screenshots/02-settings-card.png +0 -0
- package/docs/screenshots/02-settings-card.zh.png +0 -0
- package/docs/screenshots/07-card-panels.png +0 -0
- package/docs/screenshots/07-card-panels.zh.png +0 -0
- package/docs/screenshots/README.md +35 -0
- package/lib/client.js +116 -10
- package/lib/client.js.map +2 -2
- package/lib/index.js +268 -99
- package/lib/types/client/locales.d.ts +12 -0
- package/lib/types/client/settings-card.d.ts +4 -0
- package/lib/types/host/engine.d.ts +20 -11
- package/lib/types/index.d.ts +161 -11
- package/lib/types/shared/core.d.ts +22 -4
- package/package.json +9 -3
- package/src/client/locales.ts +34 -10
- package/src/client/settings-card.tsx +63 -1
- package/src/client/styles.ts +2 -0
- package/src/host/engine.ts +247 -96
- package/src/index.ts +78 -27
- package/src/shared/core.ts +43 -4
package/src/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Host half of the auto-continue plugin.
|
|
3
3
|
*
|
|
4
|
-
* -
|
|
5
|
-
*
|
|
4
|
+
* - Configuration is this entry's own Loader config: `apply(ctx, config)`
|
|
5
|
+
* injects it into the engine, where `resolveConfig` merges it with the
|
|
6
|
+
* schema defaults (the browser half's settings card writes the same values).
|
|
6
7
|
* - Runs the single-instance auto-continue engine: listens to the session
|
|
7
8
|
* event firehose, sends via `agent.followup`, cancels via `agent.cancel`.
|
|
8
9
|
* - Serves a status bridge the browser half subscribes to: notifications and
|
|
@@ -11,10 +12,8 @@
|
|
|
11
12
|
*/
|
|
12
13
|
import type { Context } from '@deepseek-ai/cordis';
|
|
13
14
|
import z from '@deepseek-ai/schemastery';
|
|
14
|
-
import type { SettingsNamespace } from '@deepseek-ai/dsh-settings';
|
|
15
15
|
import { AutoContinueRunner } from './host/engine.ts';
|
|
16
16
|
import { resolveConfig, type AutoContinueSettings } from './shared/core.ts';
|
|
17
|
-
// The type-only settings import also pulls in the `ctx.settings` Context augmentation.
|
|
18
17
|
// Type-only: pulls the `ctx.webServer` Context augmentation.
|
|
19
18
|
import type {} from '@deepseek-ai/dsh-host-webserver';
|
|
20
19
|
import type {} from '@deepseek-ai/dsh-agent';
|
|
@@ -22,7 +21,6 @@ import type {} from '@deepseek-ai/dsh-session';
|
|
|
22
21
|
|
|
23
22
|
/** Settings namespace of the auto-continue plugin (lowercase kebab-case). */
|
|
24
23
|
export const AUTO_CONTINUE_NS = 'auto-continue';
|
|
25
|
-
const SETTINGS_NS = AUTO_CONTINUE_NS as SettingsNamespace;
|
|
26
24
|
|
|
27
25
|
/** Wire schema; blank localized text fields tell resolveConfig() to select the active locale's defaults. */
|
|
28
26
|
export const AutoContinueSchema = z.object({
|
|
@@ -32,6 +30,14 @@ export const AutoContinueSchema = z.object({
|
|
|
32
30
|
continueText: z.string().default(''),
|
|
33
31
|
/** Text sent when the output token ceiling is reached (same placeholders as `continueText`). */
|
|
34
32
|
continueTextMaxTokens: z.string().default(''),
|
|
33
|
+
/** Resume observed model activity that completes without visible output. */
|
|
34
|
+
resumeSilentTurns: z.boolean().default(true),
|
|
35
|
+
/** Autonomous mode: hand the thread back to the agent after every completed turn, looping until the user stops it. The consecutive-failure cap only throttles failures, never successful completions. */
|
|
36
|
+
resumeCompletedTurns: z.boolean().default(false),
|
|
37
|
+
/** Text sent to resume a silent turn (same placeholders as `continueText`). */
|
|
38
|
+
continueTextSilent: z.string().default(''),
|
|
39
|
+
/** Text sent for each autonomous-loop continuation (same placeholders as `continueText`). */
|
|
40
|
+
continueTextLoop: z.string().default(''),
|
|
35
41
|
/** Idempotency guard: inspect the last tool call before resuming and steer the model. */
|
|
36
42
|
guardTools: z.boolean().default(true),
|
|
37
43
|
/** Guard text appended when the last tool call has no confirmed result (it may have partially executed). */
|
|
@@ -48,11 +54,11 @@ export const AutoContinueSchema = z.object({
|
|
|
48
54
|
cooldownMs: z.natural().default(20000),
|
|
49
55
|
/** Max consecutive auto-continues per session before stopping. */
|
|
50
56
|
maxConsecutive: z.natural().min(1).default(3),
|
|
51
|
-
/**
|
|
57
|
+
/** Recover delayed interrupted sessions during the host startup window. */
|
|
52
58
|
scanOnBoot: z.boolean().default(true),
|
|
53
|
-
/** Max
|
|
59
|
+
/** Max eligible recoveries per scan pass (most recently active first). */
|
|
54
60
|
scanLimit: z.natural().min(1).default(8),
|
|
55
|
-
/**
|
|
61
|
+
/** Interruption freshness and duration of startup polling (ms). */
|
|
56
62
|
freshMs: z.natural().default(15 * 60 * 1000),
|
|
57
63
|
/** Log `[auto-continue]` lines to the browser console. */
|
|
58
64
|
verbose: z.boolean().default(true),
|
|
@@ -86,34 +92,61 @@ export const AutoContinueSchema = z.object({
|
|
|
86
92
|
.default(''),
|
|
87
93
|
});
|
|
88
94
|
|
|
95
|
+
/** Loader config is a live reference on DSH 0.1.7, and a plain object on older hosts. */
|
|
96
|
+
export type AutoContinueEntryConfig = AutoContinueSettings | { get(): AutoContinueSettings | undefined };
|
|
97
|
+
|
|
98
|
+
// Keep the wire schema usable by legacy Settings while exposing the live root
|
|
99
|
+
// to current Loaders. Older Schemastery releases do not have volatile().
|
|
100
|
+
const entrySchema = AutoContinueSchema as typeof AutoContinueSchema & {
|
|
101
|
+
volatile?: () => z<AutoContinueSettings, AutoContinueEntryConfig>;
|
|
102
|
+
};
|
|
103
|
+
export const Config = entrySchema.volatile?.() ?? AutoContinueSchema;
|
|
104
|
+
|
|
105
|
+
function entryConfig(config: AutoContinueEntryConfig | undefined): AutoContinueSettings | undefined {
|
|
106
|
+
return config !== undefined && 'get' in config ? config.get() : config;
|
|
107
|
+
}
|
|
108
|
+
|
|
89
109
|
/**
|
|
90
|
-
* Plugin body:
|
|
91
|
-
*
|
|
110
|
+
* Plugin body: start the single-instance engine and serve the status bridge.
|
|
111
|
+
*
|
|
112
|
+
* Configuration comes from this entry's own Loader config (merged with the
|
|
113
|
+
* schema defaults by `resolveConfig`); the current harness exposes entry
|
|
114
|
+
* config through the settings service instead of the legacy `register`/`get`
|
|
115
|
+
* namespace API this plugin was originally written against.
|
|
92
116
|
* @param ctx - host plugin context.
|
|
117
|
+
* @param config - this entry's config (may be partial / absent → defaults).
|
|
93
118
|
*/
|
|
94
|
-
export function apply(ctx: Context): void {
|
|
119
|
+
export function apply(ctx: Context, config?: AutoContinueEntryConfig): void {
|
|
120
|
+
let legacyConfig: (() => AutoContinueSettings | undefined) | undefined;
|
|
121
|
+
// Settings is optional: it must never prevent the engine or bridge starting.
|
|
122
|
+
// Hosts predating Config-derived forms still own a separate settings document.
|
|
95
123
|
ctx.inject(['settings'], (settingsCtx) => {
|
|
96
|
-
|
|
97
|
-
applies:
|
|
124
|
+
const settings = (settingsCtx as unknown as { settings: {
|
|
125
|
+
register?: (ns: string, schema: typeof AutoContinueSchema, options: { applies: string }) => unknown;
|
|
126
|
+
get?: (ns: string) => AutoContinueSettings | undefined;
|
|
127
|
+
} }).settings;
|
|
128
|
+
if (typeof settings.register !== 'function' || typeof settings.get !== 'function') return;
|
|
129
|
+
settings.register(AUTO_CONTINUE_NS, AutoContinueSchema, { applies: 'live' });
|
|
130
|
+
const read = () => settings.get!(AUTO_CONTINUE_NS);
|
|
131
|
+
legacyConfig = read;
|
|
132
|
+
settingsCtx.effect(() => () => {
|
|
133
|
+
if (legacyConfig === read) legacyConfig = undefined;
|
|
98
134
|
});
|
|
99
135
|
});
|
|
100
|
-
|
|
101
136
|
// 引擎引用: inject 回调可能重入(依赖组合变化), 顶层 effect 在 fiber 卸载时必跑。
|
|
102
137
|
// dispose 绑定必须挂在 apply 的顶层 ctx 上——挂 inject 派生 ctx 的 effect 在 config HMR
|
|
103
138
|
// 替换行时不会执行, 悬空定时器会撞上 inactive context 炸掉整个进程。
|
|
104
|
-
let
|
|
139
|
+
let disposeEngine: (() => void) | undefined;
|
|
105
140
|
|
|
106
141
|
// 单实例引擎: host 进程内监听会话事件, 所有标签页共享同一个引擎。
|
|
107
|
-
ctx.inject(['
|
|
142
|
+
ctx.inject(['agents', 'webServer'], (engineCtx) => {
|
|
108
143
|
// 回调重入时先清理旧引擎, 避免定时器与监听器叠加。
|
|
109
|
-
|
|
110
|
-
const runner = new AutoContinueRunner(engineCtx, () =>
|
|
111
|
-
resolveConfig(engineCtx.settings.get(SETTINGS_NS) as AutoContinueSettings | undefined),
|
|
112
|
-
);
|
|
113
|
-
runnerRef = runner;
|
|
144
|
+
disposeEngine?.();
|
|
145
|
+
const runner = new AutoContinueRunner(engineCtx, () => resolveConfig(legacyConfig?.() ?? entryConfig(config)));
|
|
114
146
|
|
|
115
147
|
// 状态桥: browser 侧订阅通知与运行时状态(SSE)。
|
|
116
148
|
const sseClients = new Set<(data: string) => void>();
|
|
149
|
+
const closeClients = new Set<() => void>();
|
|
117
150
|
const pushToAll = (data: string): void => {
|
|
118
151
|
for (const send of sseClients) {
|
|
119
152
|
try {
|
|
@@ -139,7 +172,7 @@ export function apply(ctx: Context): void {
|
|
|
139
172
|
pushToAll(`data: ${statePayload()}\n\n`);
|
|
140
173
|
});
|
|
141
174
|
|
|
142
|
-
engineCtx.webServer.register({
|
|
175
|
+
const stopBridge = engineCtx.webServer.register({
|
|
143
176
|
kind: 'exact',
|
|
144
177
|
path: '/api/auto-continue-bridge',
|
|
145
178
|
handler: (req, res) => {
|
|
@@ -153,12 +186,17 @@ export function apply(ctx: Context): void {
|
|
|
153
186
|
res.write(data);
|
|
154
187
|
};
|
|
155
188
|
sseClients.add(send);
|
|
156
|
-
|
|
189
|
+
const close = () => { res.end(); };
|
|
190
|
+
closeClients.add(close);
|
|
191
|
+
req.on('close', () => {
|
|
192
|
+
sseClients.delete(send);
|
|
193
|
+
closeClients.delete(close);
|
|
194
|
+
});
|
|
157
195
|
},
|
|
158
196
|
});
|
|
159
197
|
|
|
160
198
|
// 通知按钮动作: browser 点击「立即续跑 / 暂停该会话」时 POST 到这里。
|
|
161
|
-
engineCtx.webServer.register({
|
|
199
|
+
const stopActions = engineCtx.webServer.register({
|
|
162
200
|
kind: 'exact',
|
|
163
201
|
path: '/api/auto-continue-action',
|
|
164
202
|
handler: (req, res) => {
|
|
@@ -185,13 +223,26 @@ export function apply(ctx: Context): void {
|
|
|
185
223
|
});
|
|
186
224
|
},
|
|
187
225
|
});
|
|
226
|
+
let disposed = false;
|
|
227
|
+
const dispose = () => {
|
|
228
|
+
if (disposed) return;
|
|
229
|
+
disposed = true;
|
|
230
|
+
runner.dispose();
|
|
231
|
+
stopBridge();
|
|
232
|
+
stopActions();
|
|
233
|
+
for (const close of closeClients) close();
|
|
234
|
+
closeClients.clear();
|
|
235
|
+
sseClients.clear();
|
|
236
|
+
};
|
|
237
|
+
disposeEngine = dispose;
|
|
238
|
+
engineCtx.effect(() => dispose);
|
|
188
239
|
});
|
|
189
240
|
|
|
190
241
|
// 顶层生命周期绑定: fiber 卸载时清理引擎(定时器/监听器)。
|
|
191
242
|
// 挂在 apply 的 ctx 上保证 Cordis 一定会调用, 防止 inactive context 崩溃。
|
|
192
243
|
ctx.effect(() => () => {
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
244
|
+
const dispose = disposeEngine;
|
|
245
|
+
disposeEngine = undefined;
|
|
246
|
+
dispose?.();
|
|
196
247
|
});
|
|
197
248
|
}
|
package/src/shared/core.ts
CHANGED
|
@@ -14,6 +14,9 @@ export const LOCALIZED_TEXT_DEFAULTS = {
|
|
|
14
14
|
zh: {
|
|
15
15
|
continueText: '继续',
|
|
16
16
|
continueTextMaxTokens: '继续',
|
|
17
|
+
continueTextSilent:
|
|
18
|
+
'继续。你上一轮只输出了内部推理, 既没有回复也没有调用工具, 用户什么都没看到。每一轮都要以工具调用或可见回复结束。',
|
|
19
|
+
continueTextLoop: '继续',
|
|
17
20
|
guardPendingText: '(上一步工具「{tool}」可能未完成, 先确认状态再继续, 不要重复执行)',
|
|
18
21
|
guardDoneText: '(上一步工具「{tool}」已完成, 结果: {result}; 不要重复执行, 直接继续)',
|
|
19
22
|
loopText: '(检测到你可能陷入循环, 请停止重复刚才的动作, 换一种方式继续)',
|
|
@@ -21,6 +24,9 @@ export const LOCALIZED_TEXT_DEFAULTS = {
|
|
|
21
24
|
en: {
|
|
22
25
|
continueText: 'Continue',
|
|
23
26
|
continueTextMaxTokens: 'Continue',
|
|
27
|
+
continueTextSilent:
|
|
28
|
+
'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.',
|
|
29
|
+
continueTextLoop: 'Continue',
|
|
24
30
|
guardPendingText:
|
|
25
31
|
'(The previous tool "{tool}" may not have completed. Check its state before continuing and do not run it again.)',
|
|
26
32
|
guardDoneText:
|
|
@@ -38,6 +44,14 @@ export interface AutoContinueSettings {
|
|
|
38
44
|
continueText?: string;
|
|
39
45
|
/** Text sent when the output token ceiling is reached (same placeholders as `continueText`). */
|
|
40
46
|
continueTextMaxTokens?: string;
|
|
47
|
+
/** Resume observed model activity that completes without visible output. */
|
|
48
|
+
resumeSilentTurns?: boolean;
|
|
49
|
+
/** Autonomous mode: hand the thread back to the agent after every completed turn, looping until the user stops it. The consecutive-failure cap only throttles failures, never successful completions. */
|
|
50
|
+
resumeCompletedTurns?: boolean;
|
|
51
|
+
/** Text sent to resume a silent turn (same placeholders as `continueText`). */
|
|
52
|
+
continueTextSilent?: string;
|
|
53
|
+
/** Text sent for each autonomous-loop continuation (same placeholders as `continueText`). */
|
|
54
|
+
continueTextLoop?: string;
|
|
41
55
|
/** Idempotency guard: inspect the last tool call before resuming and steer the model. */
|
|
42
56
|
guardTools?: boolean;
|
|
43
57
|
/** Guard text appended when the last tool call has no confirmed result (it may have partially executed). */
|
|
@@ -50,11 +64,11 @@ export interface AutoContinueSettings {
|
|
|
50
64
|
cooldownMs?: number;
|
|
51
65
|
/** Max consecutive auto-continues per session before stopping. */
|
|
52
66
|
maxConsecutive?: number;
|
|
53
|
-
/**
|
|
67
|
+
/** Recover delayed interrupted sessions during the host startup window. */
|
|
54
68
|
scanOnBoot?: boolean;
|
|
55
|
-
/** Max
|
|
69
|
+
/** Max eligible recoveries per scan pass (most recently active first). */
|
|
56
70
|
scanLimit?: number;
|
|
57
|
-
/**
|
|
71
|
+
/** Interruption freshness and duration of startup polling (ms). */
|
|
58
72
|
freshMs?: number;
|
|
59
73
|
/** Log `[auto-continue]` lines to the browser console. */
|
|
60
74
|
verbose?: boolean;
|
|
@@ -93,6 +107,9 @@ export type AutoContinueConfig = Required<AutoContinueSettings>;
|
|
|
93
107
|
export const DEFAULT_CONFIG: AutoContinueConfig = {
|
|
94
108
|
locale: 'zh',
|
|
95
109
|
...LOCALIZED_TEXT_DEFAULTS.zh,
|
|
110
|
+
resumeSilentTurns: true,
|
|
111
|
+
resumeCompletedTurns: false,
|
|
112
|
+
continueTextLoop: '',
|
|
96
113
|
guardTools: true,
|
|
97
114
|
graceMs: 3000,
|
|
98
115
|
cooldownMs: 20000,
|
|
@@ -136,6 +153,14 @@ export function resolveConfig(section: AutoContinueSettings | undefined): AutoCo
|
|
|
136
153
|
typeof value.continueTextMaxTokens === 'string' && value.continueTextMaxTokens.trim() !== ''
|
|
137
154
|
? value.continueTextMaxTokens
|
|
138
155
|
: localized.continueTextMaxTokens;
|
|
156
|
+
const silentText =
|
|
157
|
+
typeof value.continueTextSilent === 'string' && value.continueTextSilent.trim() !== ''
|
|
158
|
+
? value.continueTextSilent
|
|
159
|
+
: localized.continueTextSilent;
|
|
160
|
+
const loopText =
|
|
161
|
+
typeof value.continueTextLoop === 'string' && value.continueTextLoop.trim() !== ''
|
|
162
|
+
? value.continueTextLoop
|
|
163
|
+
: localized.continueTextLoop;
|
|
139
164
|
const guardPendingText =
|
|
140
165
|
typeof value.guardPendingText === 'string' && value.guardPendingText.trim() !== ''
|
|
141
166
|
? value.guardPendingText
|
|
@@ -148,6 +173,10 @@ export function resolveConfig(section: AutoContinueSettings | undefined): AutoCo
|
|
|
148
173
|
locale,
|
|
149
174
|
continueText: text,
|
|
150
175
|
continueTextMaxTokens: maxTokensText,
|
|
176
|
+
resumeSilentTurns: booleanOr(value.resumeSilentTurns, DEFAULT_CONFIG.resumeSilentTurns),
|
|
177
|
+
resumeCompletedTurns: booleanOr(value.resumeCompletedTurns, DEFAULT_CONFIG.resumeCompletedTurns),
|
|
178
|
+
continueTextSilent: silentText,
|
|
179
|
+
continueTextLoop: loopText,
|
|
151
180
|
guardTools: booleanOr(value.guardTools, DEFAULT_CONFIG.guardTools),
|
|
152
181
|
guardPendingText,
|
|
153
182
|
guardDoneText,
|
|
@@ -183,7 +212,7 @@ export function resolveConfig(section: AutoContinueSettings | undefined): AutoCo
|
|
|
183
212
|
/**
|
|
184
213
|
* 视为「非人为中断」的回合结束原因, 用于启动/重连扫描。
|
|
185
214
|
* - `interrupted` 只由崩溃修复在宿主重载时写入(loop 永不实时发出), 因此仅在扫描路径处理;
|
|
186
|
-
* - 实时事件路径只对 `error` / `max-tokens` 自动续跑;
|
|
215
|
+
* - 实时事件路径只对 `error` / `max-tokens` 自动续跑; 另外续跑没有可见输出的 `completed` / `no-visible-output` 回合(不属于本类型);
|
|
187
216
|
* - `aborted`(用户停止)与 `blocked`(策略拒绝)永不自动继续。
|
|
188
217
|
*/
|
|
189
218
|
type NonHumanReason = 'error' | 'interrupted' | 'max-tokens';
|
|
@@ -813,6 +842,10 @@ export interface SessionState {
|
|
|
813
842
|
lastTurn: number | undefined;
|
|
814
843
|
/** 我们最近一次自动发送的时间戳; 0 = 没有待确认的恢复。 */
|
|
815
844
|
pendingRecoveryAt: number;
|
|
845
|
+
/** unknown: no observed start; empty: no model activity; silent: activity without visible output. */
|
|
846
|
+
turnOutput: 'unknown' | 'empty' | 'silent' | 'visible';
|
|
847
|
+
outputTurn: number | undefined;
|
|
848
|
+
outputStartSeq: number;
|
|
816
849
|
/** 当前连续短句数(loop guard 信号 1: 空转)。 */
|
|
817
850
|
shortRun: number;
|
|
818
851
|
/** 最后一条短句的时间(时间窗判定用)。 */
|
|
@@ -831,6 +864,8 @@ export interface SessionState {
|
|
|
831
864
|
loopFired: boolean;
|
|
832
865
|
/** loop 重启的延迟定时器(冷却结束后再 schedule)。 */
|
|
833
866
|
loopRetryTimer: ReturnType<typeof setTimeout> | undefined;
|
|
867
|
+
/** 冷却期恢复的延迟定时器(等到冷却结束再 schedule, 而不是丢弃这次恢复)。 */
|
|
868
|
+
cooldownRetryTimer: ReturnType<typeof setTimeout> | undefined;
|
|
834
869
|
}
|
|
835
870
|
|
|
836
871
|
export const freshState = (): SessionState => ({
|
|
@@ -846,6 +881,9 @@ export const freshState = (): SessionState => ({
|
|
|
846
881
|
tools: new ToolInvocationTracker(),
|
|
847
882
|
lastTurn: undefined,
|
|
848
883
|
pendingRecoveryAt: 0,
|
|
884
|
+
turnOutput: 'unknown',
|
|
885
|
+
outputTurn: undefined,
|
|
886
|
+
outputStartSeq: 0,
|
|
849
887
|
shortRun: 0,
|
|
850
888
|
lastShortAt: 0,
|
|
851
889
|
lastAssistantText: '',
|
|
@@ -855,6 +893,7 @@ export const freshState = (): SessionState => ({
|
|
|
855
893
|
streamRepeatRun: 0,
|
|
856
894
|
loopFired: false,
|
|
857
895
|
loopRetryTimer: undefined,
|
|
896
|
+
cooldownRetryTimer: undefined,
|
|
858
897
|
});
|
|
859
898
|
|
|
860
899
|
|