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