@restregular/dsh-powerup 0.11.0 → 0.13.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 +40 -1
- package/client.js +721 -57
- package/index.js +328 -7
- package/lib/direct-ask.js +115 -0
- package/lib/progress-manager.js +49 -7
- package/lib/progress-tool.js +13 -4
- package/lib/task-resume.js +271 -0
- package/package.json +4 -2
package/lib/progress-tool.js
CHANGED
|
@@ -262,10 +262,11 @@ export function finishReport(text, finish) {
|
|
|
262
262
|
* @param {object} options.llm the Host `ctx.llm` service
|
|
263
263
|
* @param {{provider: string, model: string, reasoningEffort?: string, maxTokens?: number}} options.route
|
|
264
264
|
* @param {string} options.context compact transcript
|
|
265
|
+
* @param {string} [options.requirements] extra user-authored requirements appended to the system prompt
|
|
265
266
|
* @param {AbortSignal} [options.signal]
|
|
266
|
-
* @returns {Promise<object>} a normalized progress report
|
|
267
|
+
* @returns {Promise<object>} a normalized progress report (with `raw` = original model text)
|
|
267
268
|
*/
|
|
268
|
-
export async function generateProgress({ llm, route, context, signal }) {
|
|
269
|
+
export async function generateProgress({ llm, route, context, requirements, signal }) {
|
|
269
270
|
if (llm === null || typeof llm !== 'object' || typeof llm.prepareCall !== 'function') {
|
|
270
271
|
throw new ProgressError('LLM_UNAVAILABLE', 'the llm service is unavailable');
|
|
271
272
|
}
|
|
@@ -286,10 +287,13 @@ export async function generateProgress({ llm, route, context, signal }) {
|
|
|
286
287
|
'---',
|
|
287
288
|
'Return only the JSON progress object described in your instructions.',
|
|
288
289
|
].join('\n');
|
|
290
|
+
const extra = typeof requirements === 'string' && requirements.trim() !== ''
|
|
291
|
+
? `\n\nAdditional requirements from the user (follow them strictly):\n${requirements.trim()}`
|
|
292
|
+
: '';
|
|
289
293
|
const options = {
|
|
290
294
|
...call.config,
|
|
291
295
|
messages: [{ role: 'user', content: [{ type: 'text', text: prompt }] }],
|
|
292
|
-
system: PROGRESS_SYSTEM_PROMPT,
|
|
296
|
+
system: PROGRESS_SYSTEM_PROMPT + extra,
|
|
293
297
|
purpose: 'task-progress',
|
|
294
298
|
...(signal === undefined ? {} : { signal }),
|
|
295
299
|
};
|
|
@@ -304,5 +308,10 @@ export async function generateProgress({ llm, route, context, signal }) {
|
|
|
304
308
|
finish = chunk.reason;
|
|
305
309
|
}
|
|
306
310
|
}
|
|
307
|
-
|
|
311
|
+
const cleanedText = finishReport(text, finish);
|
|
312
|
+
const report = parseProgressReport(cleanedText);
|
|
313
|
+
// Keep the exact model output so the user can inspect it later. History is a
|
|
314
|
+
// user-produced artifact and must never be silently discarded.
|
|
315
|
+
report.raw = cleanedText;
|
|
316
|
+
return report;
|
|
308
317
|
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-powerup — task-aware restart / shutdown helpers.
|
|
3
|
+
*
|
|
4
|
+
* Plain JS, dependency-free so the offline suites can exercise it. The Host
|
|
5
|
+
* passes live services in at call time; nothing here imports `@deepseek-ai/*`
|
|
6
|
+
* at module load.
|
|
7
|
+
*
|
|
8
|
+
* Two responsibilities:
|
|
9
|
+
* 1. Snapshot unfinished work (live running Agents plus running background
|
|
10
|
+
* jobs) so a restart/close request can refuse the normal path.
|
|
11
|
+
* 2. Persist a small "pending resume" queue to disk when a forced restart /
|
|
12
|
+
* close is requested with `resume: true`, and replay it on the next
|
|
13
|
+
* successful application startup by sending each session a continuation
|
|
14
|
+
* prompt through `sessionController.prompt` (which resumes cold sessions).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** Central store file name, next to prompts.json / mask-rules.json. */
|
|
18
|
+
export const TASK_RESUME_FILE = 'task-resume.json';
|
|
19
|
+
|
|
20
|
+
/** Default continuation prompt; the user sees it as a real user message. */
|
|
21
|
+
export const DEFAULT_RESUME_PROMPT = '继续之前未完成的任务。';
|
|
22
|
+
|
|
23
|
+
/** Max number of records kept in the queue, so a corrupt file cannot explode startup. */
|
|
24
|
+
const MAX_RECORDS = 500;
|
|
25
|
+
|
|
26
|
+
/** Max characters kept for a session title in the queue. */
|
|
27
|
+
const TITLE_LIMIT = 200;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Clamp arbitrary text to a single line of bounded length (control chars gone).
|
|
31
|
+
* @param {unknown} value
|
|
32
|
+
* @param {number} [limit]
|
|
33
|
+
* @returns {string}
|
|
34
|
+
*/
|
|
35
|
+
export function cleanText(value, limit = TITLE_LIMIT) {
|
|
36
|
+
if (typeof value !== 'string') return '';
|
|
37
|
+
return value
|
|
38
|
+
.replace(/[\u0000-\u001f\u007f]+/gu, ' ')
|
|
39
|
+
.replace(/\s+/gu, ' ')
|
|
40
|
+
.trim()
|
|
41
|
+
.slice(0, limit);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Collect unfinished work from live Host services.
|
|
46
|
+
* @param {{agents?: any, jobs?: any, sessionTitle?: any}} services
|
|
47
|
+
* @returns {Array<{id: string, title: string, kind: 'agent'|'job', running: boolean}>}
|
|
48
|
+
*/
|
|
49
|
+
export function collectRunningTasks(services = {}) {
|
|
50
|
+
const tasks = [];
|
|
51
|
+
const agents = services.agents;
|
|
52
|
+
const sessionTitle = services.sessionTitle;
|
|
53
|
+
try {
|
|
54
|
+
const list = typeof agents?.list === 'function' ? agents.list() : [];
|
|
55
|
+
for (const agent of Array.isArray(list) ? list : []) {
|
|
56
|
+
if (agent === null || typeof agent !== 'object') continue;
|
|
57
|
+
// Cold sessions are never `running`; only the live driver knows.
|
|
58
|
+
if (agent.status !== 'running') continue;
|
|
59
|
+
const id = typeof agent.id === 'string' ? agent.id : agent.session?.id;
|
|
60
|
+
if (typeof id !== 'string' || id === '') continue;
|
|
61
|
+
tasks.push({
|
|
62
|
+
id,
|
|
63
|
+
title: taskTitle(agent, sessionTitle),
|
|
64
|
+
kind: 'agent',
|
|
65
|
+
running: true,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
} catch {
|
|
69
|
+
/* A service that is still warming up contributes no tasks. */
|
|
70
|
+
}
|
|
71
|
+
const jobs = services.jobs;
|
|
72
|
+
try {
|
|
73
|
+
const list = typeof jobs?.list === 'function' ? jobs.list() : [];
|
|
74
|
+
for (const job of Array.isArray(list) ? list : []) {
|
|
75
|
+
if (job === null || typeof job !== 'object') continue;
|
|
76
|
+
if (job.status !== 'running') continue;
|
|
77
|
+
const id = typeof job.id === 'string' ? job.id : '';
|
|
78
|
+
if (id === '') continue;
|
|
79
|
+
// Avoid duplicating the same work when a job view carries its owner.
|
|
80
|
+
if (tasks.some((task) => task.id === id)) continue;
|
|
81
|
+
tasks.push({
|
|
82
|
+
id,
|
|
83
|
+
title: cleanText(job.title ?? job.kind ?? 'background job', TITLE_LIMIT),
|
|
84
|
+
kind: 'job',
|
|
85
|
+
running: true,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
} catch {
|
|
89
|
+
/* Optional service. */
|
|
90
|
+
}
|
|
91
|
+
return tasks.slice(0, MAX_RECORDS);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Best-effort human label for one live Agent. */
|
|
95
|
+
function taskTitle(agent, sessionTitle) {
|
|
96
|
+
// The canonical title lives on the `sessionTitle` service, not on Session.
|
|
97
|
+
// `agent.session.title()` does not exist — using it silently yields 'session'.
|
|
98
|
+
if (sessionTitle !== null && typeof sessionTitle?.get === 'function' && agent.session !== undefined) {
|
|
99
|
+
try {
|
|
100
|
+
const snapshot = sessionTitle.get(agent.session);
|
|
101
|
+
const value = typeof snapshot === 'string'
|
|
102
|
+
? snapshot
|
|
103
|
+
: snapshot?.title ?? snapshot?.text;
|
|
104
|
+
if (typeof value === 'string' && value.trim() !== '') return cleanText(value);
|
|
105
|
+
} catch {
|
|
106
|
+
/* fall through */
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
const header = agent.session?.header?.();
|
|
111
|
+
const value = typeof header === 'string' ? header : header?.title;
|
|
112
|
+
if (typeof value === 'string' && value.trim() !== '') return cleanText(value);
|
|
113
|
+
} catch {
|
|
114
|
+
/* fall through */
|
|
115
|
+
}
|
|
116
|
+
return 'session';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Read the pending-resume queue from a JSON file.
|
|
121
|
+
* @param {string} filePath
|
|
122
|
+
* @returns {Array<object>}
|
|
123
|
+
*/
|
|
124
|
+
export function readResumeQueue(filePath, readFile) {
|
|
125
|
+
try {
|
|
126
|
+
const parsed = JSON.parse(readFile(filePath, 'utf8'));
|
|
127
|
+
if (!Array.isArray(parsed)) return [];
|
|
128
|
+
return parsed.filter((record) => record !== null && typeof record === 'object'
|
|
129
|
+
&& typeof record.sessionId === 'string' && record.sessionId !== '').slice(0, MAX_RECORDS);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
if (error?.code === 'ENOENT') return [];
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Build one resume record.
|
|
138
|
+
* @param {{sessionId: string, title?: string, prompt?: string, forcedAt?: number}} input
|
|
139
|
+
* @returns {{sessionId: string, requestId: string, title: string, prompt: string, createdAt: number}}
|
|
140
|
+
*/
|
|
141
|
+
export function createResumeRecord(input, randomUUID) {
|
|
142
|
+
const sessionId = typeof input?.sessionId === 'string' ? input.sessionId : '';
|
|
143
|
+
if (sessionId === '') throw new TypeError('sessionId is required');
|
|
144
|
+
const prompt = cleanText(input.prompt, 4000) || DEFAULT_RESUME_PROMPT;
|
|
145
|
+
return {
|
|
146
|
+
sessionId,
|
|
147
|
+
requestId: typeof randomUUID === 'function' ? randomUUID() : `resume-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
148
|
+
title: cleanText(input.title),
|
|
149
|
+
prompt,
|
|
150
|
+
createdAt: Number.isFinite(input.forcedAt) ? input.forcedAt : Date.now(),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Append resume records to the queue, deduplicated by sessionId.
|
|
156
|
+
* @param {Array<object>} queue
|
|
157
|
+
* @param {Array<object>} records
|
|
158
|
+
* @returns {Array<object>}
|
|
159
|
+
*/
|
|
160
|
+
export function mergeResumeQueue(queue, records) {
|
|
161
|
+
const merged = Array.isArray(queue) ? queue.slice() : [];
|
|
162
|
+
const seen = new Set(merged.map((record) => record.sessionId));
|
|
163
|
+
for (const record of Array.isArray(records) ? records : []) {
|
|
164
|
+
if (record === null || typeof record !== 'object') continue;
|
|
165
|
+
if (typeof record.sessionId !== 'string' || record.sessionId === '') continue;
|
|
166
|
+
if (seen.has(record.sessionId)) continue;
|
|
167
|
+
seen.add(record.sessionId);
|
|
168
|
+
merged.push(record);
|
|
169
|
+
}
|
|
170
|
+
return merged.slice(-MAX_RECORDS);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Cancel each running live Agent and kill each running job. Best effort: the
|
|
175
|
+
* restart proceeds even if one cancellation fails.
|
|
176
|
+
* @param {{agents?: any, jobs?: any}} services
|
|
177
|
+
* @param {string} [reason]
|
|
178
|
+
* @returns {{cancelledAgents: string[], killedJobs: string[], errors: string[]}}
|
|
179
|
+
*/
|
|
180
|
+
export function stopUnfinishedTasks(services = {}, reason = 'dsh-powerup forced app action') {
|
|
181
|
+
const result = { cancelledAgents: [], killedJobs: [], errors: [] };
|
|
182
|
+
const agents = services.agents;
|
|
183
|
+
try {
|
|
184
|
+
const list = typeof agents?.list === 'function' ? agents.list() : [];
|
|
185
|
+
for (const agent of Array.isArray(list) ? list : []) {
|
|
186
|
+
if (agent?.status !== 'running') continue;
|
|
187
|
+
const id = typeof agent.id === 'string' ? agent.id : agent.session?.id;
|
|
188
|
+
try {
|
|
189
|
+
if (typeof agent.cancel !== 'function') continue;
|
|
190
|
+
agent.cancel({ kind: 'user', reason }, { keepInbox: false });
|
|
191
|
+
if (typeof id === 'string' && id !== '') result.cancelledAgents.push(id);
|
|
192
|
+
} catch (error) {
|
|
193
|
+
result.errors.push(`agent ${id ?? '?'}: ${String(error?.message ?? error)}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
} catch (error) {
|
|
197
|
+
result.errors.push(`agents: ${String(error?.message ?? error)}`);
|
|
198
|
+
}
|
|
199
|
+
const jobs = services.jobs;
|
|
200
|
+
try {
|
|
201
|
+
const list = typeof jobs?.list === 'function' ? jobs.list() : [];
|
|
202
|
+
for (const job of Array.isArray(list) ? list : []) {
|
|
203
|
+
if (job?.status !== 'running') continue;
|
|
204
|
+
const id = typeof job.id === 'string' ? job.id : '';
|
|
205
|
+
if (id === '') continue;
|
|
206
|
+
try {
|
|
207
|
+
const owner = typeof job.sessionId === 'string' ? job.sessionId : typeof job.owner === 'string' ? job.owner : undefined;
|
|
208
|
+
jobs.kill(id, owner, reason);
|
|
209
|
+
result.killedJobs.push(id);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
result.errors.push(`job ${id}: ${String(error?.message ?? error)}`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
} catch (error) {
|
|
215
|
+
result.errors.push(`jobs: ${String(error?.message ?? error)}`);
|
|
216
|
+
}
|
|
217
|
+
return result;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Replay pending resumes once startup is committed. Each prompt is sent
|
|
222
|
+
* through `sessionController.prompt`, which resumes a cold session internally.
|
|
223
|
+
* A record is removed from the queue only after its prompt is accepted.
|
|
224
|
+
*
|
|
225
|
+
* @param {{sessionController?: any, readFile: Function, writeFile: Function, mkdir: Function, dirname: Function, randomUUID: Function, logger?: Function}} deps
|
|
226
|
+
* @returns {Promise<{delivered: string[], failed: Array<{sessionId: string, error: string}>, remaining: number}>}
|
|
227
|
+
*/
|
|
228
|
+
export async function replayPendingResumes(deps) {
|
|
229
|
+
const { readFile, writeFile, mkdir, dirname, randomUUID } = deps;
|
|
230
|
+
const filePath = deps.filePath;
|
|
231
|
+
const queue = readResumeQueue(filePath, readFile);
|
|
232
|
+
if (queue.length === 0) return { delivered: [], failed: [], remaining: 0 };
|
|
233
|
+
|
|
234
|
+
const result = { delivered: [], failed: [], remaining: 0 };
|
|
235
|
+
const pending = [];
|
|
236
|
+
const controller = deps.sessionController;
|
|
237
|
+
|
|
238
|
+
for (const record of queue) {
|
|
239
|
+
if (controller === null || typeof controller?.prompt !== 'function') {
|
|
240
|
+
pending.push(record);
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
const signal = deps.signal ?? new AbortController().signal;
|
|
244
|
+
try {
|
|
245
|
+
await controller.prompt({
|
|
246
|
+
requestId: randomUUID(),
|
|
247
|
+
sessionId: record.sessionId,
|
|
248
|
+
mode: 'queue',
|
|
249
|
+
content: [{ type: 'text', text: record.prompt || DEFAULT_RESUME_PROMPT }],
|
|
250
|
+
}, signal);
|
|
251
|
+
result.delivered.push(record.sessionId);
|
|
252
|
+
} catch (error) {
|
|
253
|
+
result.failed.push({ sessionId: record.sessionId, error: String(error?.message ?? error) });
|
|
254
|
+
pending.push(record);
|
|
255
|
+
if (typeof deps.logger === 'function') {
|
|
256
|
+
deps.logger(`[dsh-powerup] resume prompt failed for ${record.sessionId}: ${String(error?.message ?? error)}`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
result.remaining = pending.length;
|
|
262
|
+
try {
|
|
263
|
+
mkdir(dirname(filePath), { recursive: true });
|
|
264
|
+
writeFile(filePath, JSON.stringify(pending, null, 2) + '\n', 'utf8');
|
|
265
|
+
} catch (error) {
|
|
266
|
+
if (typeof deps.logger === 'function') {
|
|
267
|
+
deps.logger(`[dsh-powerup] could not persist resume queue: ${String(error?.message ?? error)}`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return result;
|
|
271
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@restregular/dsh-powerup",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "为 DeepSeek Harness 提供一组可选的小型增强:轨迹右键菜单与步骤引用、后台任务停止原因、插件一键安装、侧边栏图标网格、会话切换、定位当前会话、工作区提示词、旁路模型生成的结构化任务进度;所有功能均可在 Power-Up 页面独立开关。 · Opt-in upgrades for DeepSeek Harness: Trajectory context menu and step references, job stop reasons, one-click plugin install, an adaptive sidebar launcher, session switching, locating the current session, workspace prompts, and non-blocking model-generated structured task progress — each toggled independently on the Power-Up page.",
|
|
5
5
|
"icon": "./icon.svg",
|
|
6
6
|
"type": "module",
|
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
"lib/step-tool.js",
|
|
24
24
|
"lib/progress-tool.js",
|
|
25
25
|
"lib/progress-manager.js",
|
|
26
|
+
"lib/task-resume.js",
|
|
27
|
+
"lib/direct-ask.js",
|
|
26
28
|
"locale/*.json",
|
|
27
29
|
"icon.svg",
|
|
28
30
|
"README.md",
|
|
@@ -96,7 +98,7 @@
|
|
|
96
98
|
"node": ">=22.13.0"
|
|
97
99
|
},
|
|
98
100
|
"scripts": {
|
|
99
|
-
"test": "node test/smoke.mjs && node test/host.mjs && node test/progress.mjs"
|
|
101
|
+
"test": "node test/smoke.mjs && node test/host.mjs && node test/progress.mjs && node test/task-resume.mjs && node test/direct-ask.mjs"
|
|
100
102
|
},
|
|
101
103
|
"license": "MIT",
|
|
102
104
|
"author": "RestRegular"
|