@restregular/dsh-powerup 0.13.0 → 0.15.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 +26 -19
- package/client.js +648 -153
- package/index.js +80 -30
- package/lib/direct-ask.js +13 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -483,12 +483,21 @@ async function handle(req, res, ctx) {
|
|
|
483
483
|
if (req.method === 'POST') {
|
|
484
484
|
try {
|
|
485
485
|
const body = await readJsonBody(req);
|
|
486
|
-
|
|
486
|
+
// Keep the flat list form; accept {requirements: [...]} or a bare array.
|
|
487
|
+
const list = Array.isArray(body?.requirements)
|
|
487
488
|
? body.requirements
|
|
488
|
-
:
|
|
489
|
+
: Array.isArray(body) ? body : [];
|
|
490
|
+
const records = list.filter((r) => r !== null && typeof r === 'object')
|
|
491
|
+
.map((r) => ({
|
|
492
|
+
id: typeof r.id === 'string' && r.id !== '' ? r.id : `req-${randomUUID()}`,
|
|
493
|
+
title: typeof r.title === 'string' ? r.title : '',
|
|
494
|
+
text: typeof r.text === 'string' ? r.text : '',
|
|
495
|
+
workspaceId: typeof r.workspaceId === 'string' ? r.workspaceId : '',
|
|
496
|
+
enabled: r.enabled !== false,
|
|
497
|
+
}));
|
|
489
498
|
mkdirSync(dirname(filePath), { recursive: true });
|
|
490
|
-
writeFileSync(filePath, JSON.stringify(
|
|
491
|
-
sendJson(res, { ok: true, requirements });
|
|
499
|
+
writeFileSync(filePath, JSON.stringify(records, null, 2) + '\n', 'utf8');
|
|
500
|
+
sendJson(res, { ok: true, requirements: records });
|
|
492
501
|
} catch (error) {
|
|
493
502
|
sendJson(res, { ok: false, error: String(error?.message ?? error) }, 500);
|
|
494
503
|
}
|
|
@@ -499,7 +508,12 @@ async function handle(req, res, ctx) {
|
|
|
499
508
|
return;
|
|
500
509
|
}
|
|
501
510
|
try {
|
|
502
|
-
|
|
511
|
+
let raw;
|
|
512
|
+
try { raw = JSON.parse(readFileSync(filePath, 'utf8')); } catch { raw = undefined; }
|
|
513
|
+
let records = [];
|
|
514
|
+
if (Array.isArray(raw)) records = raw;
|
|
515
|
+
else if (raw !== null && typeof raw === 'object' && Array.isArray(raw.records)) records = raw.records;
|
|
516
|
+
sendJson(res, { ok: true, requirements: records });
|
|
503
517
|
} catch (error) {
|
|
504
518
|
sendJson(res, { ok: false, error: String(error?.message ?? error) }, 500);
|
|
505
519
|
}
|
|
@@ -547,6 +561,7 @@ async function handle(req, res, ctx) {
|
|
|
547
561
|
}
|
|
548
562
|
const sessionId = typeof body?.sessionId === 'string' ? body.sessionId.trim() : '';
|
|
549
563
|
const context = Array.isArray(body?.context) ? body.context : [];
|
|
564
|
+
const history = Array.isArray(body?.history) ? body.history : [];
|
|
550
565
|
const prompt = buildAskPrompt({ question: cleanAskText(body?.question), context });
|
|
551
566
|
if (prompt === '') {
|
|
552
567
|
sendJson(res, { ok: false, code: 'invalid-request', error: 'question is required' }, 400);
|
|
@@ -578,7 +593,7 @@ async function handle(req, res, ctx) {
|
|
|
578
593
|
const timer = setTimeout(() => controller.abort(), 90_000);
|
|
579
594
|
timer.unref?.();
|
|
580
595
|
try {
|
|
581
|
-
const answer = await directAsk({ llm, route, prompt, signal: controller.signal });
|
|
596
|
+
const answer = await directAsk({ llm, route, prompt, history, signal: controller.signal });
|
|
582
597
|
sendJson(res, { ok: true, answer: answer.text, finish: answer.finish ?? null });
|
|
583
598
|
} catch (error) {
|
|
584
599
|
sendJson(res, { ok: false, code: error?.code ?? 'ask-failed', error: String(error?.message ?? error) }, 500);
|
|
@@ -612,11 +627,15 @@ async function handle(req, res, ctx) {
|
|
|
612
627
|
return;
|
|
613
628
|
}
|
|
614
629
|
try {
|
|
615
|
-
//
|
|
616
|
-
//
|
|
630
|
+
// The panel sends the full (possibly user-edited) requirements text in
|
|
631
|
+
// `requirements`. It is used verbatim. The older `requirementIds`
|
|
632
|
+
// selection remains as a fallback for clients that send it.
|
|
617
633
|
if (typeof body?.requirements === 'string') {
|
|
618
|
-
ctx.
|
|
619
|
-
ctx.
|
|
634
|
+
ctx.__powerupProgressText = ctx.__powerupProgressText ?? {};
|
|
635
|
+
ctx.__powerupProgressText[sessionId] = body.requirements;
|
|
636
|
+
} else if (Array.isArray(body?.requirementIds)) {
|
|
637
|
+
ctx.__powerupProgressSelection = ctx.__powerupProgressSelection ?? {};
|
|
638
|
+
ctx.__powerupProgressSelection[sessionId] = body.requirementIds.map(String);
|
|
620
639
|
}
|
|
621
640
|
const view = action === 'start'
|
|
622
641
|
? manager.start(sessionId)
|
|
@@ -904,21 +923,43 @@ export function apply(ctx) {
|
|
|
904
923
|
// The progress side call needs both `llm` and `sessionQuery`. Wait for them
|
|
905
924
|
// through inject so a late-provided service still creates the manager.
|
|
906
925
|
ctx.inject(['llm', 'sessionQuery'], (scope) => {
|
|
907
|
-
// Requirements are
|
|
908
|
-
//
|
|
909
|
-
//
|
|
910
|
-
const requirementsFor = (sessionId,
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
if (typeof
|
|
914
|
-
|
|
915
|
-
const
|
|
916
|
-
|
|
926
|
+
// Requirements are a flat list of records: {id,title,text,workspaceId,enabled}.
|
|
927
|
+
// workspaceId '' = global. The panel sends the ids it wants; the Host only
|
|
928
|
+
// includes records visible to the session's workspace and explicitly picked.
|
|
929
|
+
const requirementsFor = (sessionId, selectedIds, editedText) => {
|
|
930
|
+
// A panel-edited full text wins verbatim (the user may freely modify the
|
|
931
|
+
// concatenated requirements before generating).
|
|
932
|
+
if (typeof editedText === 'string' && editedText.trim() !== '') return editedText;
|
|
933
|
+
if (editedText === '') return ''; // user cleared everything on purpose
|
|
934
|
+
const file = storePath(PROGRESS_REQUIREMENTS_FILE);
|
|
935
|
+
let raw;
|
|
936
|
+
try {
|
|
937
|
+
raw = JSON.parse(readFileSync(file, 'utf8'));
|
|
938
|
+
} catch {
|
|
939
|
+
raw = undefined;
|
|
940
|
+
}
|
|
941
|
+
let all = [];
|
|
942
|
+
if (Array.isArray(raw)) all = raw;
|
|
943
|
+
else if (raw !== null && typeof raw === 'object' && Array.isArray(raw.records)) all = raw.records;
|
|
944
|
+
else if (raw !== null && typeof raw === 'object') {
|
|
945
|
+
// Legacy object form ({global, workspaces, sessions}) migrated on read.
|
|
946
|
+
const migrated = [];
|
|
947
|
+
if (typeof raw.global === 'string' && raw.global.trim() !== '') {
|
|
948
|
+
migrated.push({ id: 'legacy-global', title: '通用要求', text: raw.global, workspaceId: '', enabled: true });
|
|
949
|
+
}
|
|
950
|
+
const ws = raw.workspaces ?? {};
|
|
951
|
+
for (const [wid, text] of Object.entries(ws)) {
|
|
952
|
+
if (typeof text === 'string' && text.trim() !== '') {
|
|
953
|
+
migrated.push({ id: `legacy-ws-${wid}`, title: '工作区要求', text, workspaceId: wid, enabled: true });
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
all = migrated;
|
|
957
|
+
}
|
|
917
958
|
let workspaceId = '';
|
|
918
959
|
try {
|
|
919
960
|
const registry = scope.get('workspaceRegistry');
|
|
920
|
-
const
|
|
921
|
-
for (const item of Array.isArray(
|
|
961
|
+
const list = typeof registry?.list === 'function' ? registry.list() : [];
|
|
962
|
+
for (const item of Array.isArray(list) ? list : []) {
|
|
922
963
|
if (Array.isArray(item?.sessionIds) && item.sessionIds.includes(sessionId)) {
|
|
923
964
|
workspaceId = typeof item.id === 'string' ? item.id : '';
|
|
924
965
|
break;
|
|
@@ -927,13 +968,17 @@ export function apply(ctx) {
|
|
|
927
968
|
} catch {
|
|
928
969
|
/* workspace layer is optional */
|
|
929
970
|
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
971
|
+
const ids = Array.isArray(selectedIds) ? new Set(selectedIds.map(String)) : null;
|
|
972
|
+
const parts = [];
|
|
973
|
+
for (const record of all) {
|
|
974
|
+
if (record === null || typeof record !== 'object') continue;
|
|
975
|
+
if (record.enabled === false) continue;
|
|
976
|
+
if (typeof record.text !== 'string' || record.text.trim() === '') continue;
|
|
977
|
+
const wid = typeof record.workspaceId === 'string' ? record.workspaceId : '';
|
|
978
|
+
if (wid !== '' && wid !== workspaceId) continue; // workspace isolation
|
|
979
|
+
if (ids !== null && !ids.has(String(record.id))) continue; // panel selection
|
|
980
|
+
parts.push(record.text.trim());
|
|
935
981
|
}
|
|
936
|
-
if (typeof override === 'string' && override.trim() !== '') parts.push(override.trim());
|
|
937
982
|
return parts.join('\n\n');
|
|
938
983
|
};
|
|
939
984
|
// Persist progress history to disk so it survives restarts and refreshes.
|
|
@@ -949,7 +994,11 @@ export function apply(ctx) {
|
|
|
949
994
|
? selection
|
|
950
995
|
: undefined;
|
|
951
996
|
},
|
|
952
|
-
getRequirements: (sessionId) => requirementsFor(
|
|
997
|
+
getRequirements: (sessionId) => requirementsFor(
|
|
998
|
+
sessionId,
|
|
999
|
+
ctx.__powerupProgressSelection?.[sessionId],
|
|
1000
|
+
ctx.__powerupProgressText?.[sessionId],
|
|
1001
|
+
),
|
|
953
1002
|
onHistoryChange: (sessionId, history) => {
|
|
954
1003
|
try {
|
|
955
1004
|
const all = readJsonObject(historyPath);
|
|
@@ -977,7 +1026,8 @@ export function apply(ctx) {
|
|
|
977
1026
|
return originalPoll(sessionId);
|
|
978
1027
|
};
|
|
979
1028
|
ctx.__powerupProgress = manager;
|
|
980
|
-
ctx.
|
|
1029
|
+
ctx.__powerupProgressSelection = ctx.__powerupProgressSelection ?? {};
|
|
1030
|
+
ctx.__powerupProgressText = ctx.__powerupProgressText ?? {};
|
|
981
1031
|
scope.effect(() => () => {
|
|
982
1032
|
if (ctx.__powerupProgress === manager) ctx.__powerupProgress = undefined;
|
|
983
1033
|
}, 'dsh-powerup: progress manager');
|
package/lib/direct-ask.js
CHANGED
|
@@ -71,10 +71,11 @@ export function buildAskPrompt(input = {}) {
|
|
|
71
71
|
* @param {object} options.llm Host `ctx.llm` service
|
|
72
72
|
* @param {{provider: string, model: string, reasoningEffort?: string}} options.route
|
|
73
73
|
* @param {string} options.prompt assembled prompt from {@link buildAskPrompt}
|
|
74
|
+
* @param {Array<{role:'user'|'assistant', text:string}>} [options.history] prior turns for continuous Q&A
|
|
74
75
|
* @param {AbortSignal} [options.signal]
|
|
75
76
|
* @returns {Promise<{text: string, finish: string|undefined}>}
|
|
76
77
|
*/
|
|
77
|
-
export async function directAsk({ llm, route, prompt, signal, maxTokens }) {
|
|
78
|
+
export async function directAsk({ llm, route, prompt, history, signal, maxTokens }) {
|
|
78
79
|
if (llm === null || typeof llm !== 'object' || typeof llm.prepareCall !== 'function') {
|
|
79
80
|
throw new DirectAskError('LLM_UNAVAILABLE', 'the llm service is unavailable');
|
|
80
81
|
}
|
|
@@ -90,9 +91,19 @@ export async function directAsk({ llm, route, prompt, signal, maxTokens }) {
|
|
|
90
91
|
maxTokens: Number.isFinite(maxTokens) ? maxTokens : DIRECT_ASK_MAX_TOKENS,
|
|
91
92
|
};
|
|
92
93
|
const call = await llm.prepareCall(config, signal);
|
|
94
|
+
const messages = [];
|
|
95
|
+
for (const turn of Array.isArray(history) ? history : []) {
|
|
96
|
+
if (turn === null || typeof turn !== 'object') continue;
|
|
97
|
+
const role = turn.role === 'assistant' ? 'assistant' : turn.role === 'user' ? 'user' : null;
|
|
98
|
+
if (role === null) continue;
|
|
99
|
+
const text = cleanAskText(turn.text);
|
|
100
|
+
if (text === '') continue;
|
|
101
|
+
messages.push({ role, content: [{ type: 'text', text }] });
|
|
102
|
+
}
|
|
103
|
+
messages.push({ role: 'user', content: [{ type: 'text', text: question }] });
|
|
93
104
|
const options = {
|
|
94
105
|
...call.config,
|
|
95
|
-
messages
|
|
106
|
+
messages,
|
|
96
107
|
system: DIRECT_ASK_SYSTEM_PROMPT,
|
|
97
108
|
purpose: 'powerup-direct-ask',
|
|
98
109
|
...(signal === undefined ? {} : { signal }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@restregular/dsh-powerup",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.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",
|