@restregular/dsh-powerup 0.6.0 → 0.7.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 +53 -9
- package/client.js +100 -6
- package/index.js +22 -1
- package/lib/step-reference.js +484 -0
- package/lib/step-tool.js +71 -0
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +18 -3
package/README.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# Power-Up
|
|
2
2
|
|
|
3
3
|
Small, opt-in upgrades for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness).
|
|
4
|
-
The upgrades include a **right-click action menu in the Trajectory view**,
|
|
5
|
-
|
|
4
|
+
The upgrades include a **right-click action menu in the Trajectory view**, a
|
|
5
|
+
**copyable step reference** that an agent can resolve back into the raw session
|
|
6
|
+
data, an optional **stop reason for background jobs**, and an in-place
|
|
7
|
+
**plugin installer**.
|
|
6
8
|
|
|
7
9
|
## Install
|
|
8
10
|
|
|
@@ -21,6 +23,8 @@ Right-click a trajectory record:
|
|
|
21
23
|
- **Quote in composer** — insert that quote into the current input box.
|
|
22
24
|
- **Open record details** — open the host's record inspector.
|
|
23
25
|
- **Fork from here** — fork the session at that record (inclusive).
|
|
26
|
+
- **Copy step reference** — copy `dsh-step:<session-id>/<step-id>`; the
|
|
27
|
+
`powerup_step_read` tool turns that string back into the raw session data.
|
|
24
28
|
- **Copy session ID**.
|
|
25
29
|
|
|
26
30
|
Right-click empty space in the ledger:
|
|
@@ -55,6 +59,34 @@ and is not clipped by any slot's stacking context; its colors come only from
|
|
|
55
59
|
|
|
56
60
|
`↑` / `↓` move, `Home` / `End` jump, `Enter` runs, `Esc` closes.
|
|
57
61
|
|
|
62
|
+
### Step references
|
|
63
|
+
|
|
64
|
+
**Copy step reference** copies a single line such as
|
|
65
|
+
`dsh-step:session-1a2b…/turn.0.step.3`. The reference carries the session id
|
|
66
|
+
plus a stable step id:
|
|
67
|
+
|
|
68
|
+
| Step id | Copied from | Resolves to |
|
|
69
|
+
| --- | --- | --- |
|
|
70
|
+
| `turn.<turn>.step.<step>` | an assistant row | every raw event between `step/start` and `step/end` |
|
|
71
|
+
| `call.<call-id>` | a tool row | that tool call and its `tool/result` |
|
|
72
|
+
| `seq.<n>` | any other raw-event row | that single event |
|
|
73
|
+
| `index.<n>` | a synthetic row | nothing — the menu disables the action |
|
|
74
|
+
|
|
75
|
+
Paste the line into the session and the agent can call
|
|
76
|
+
**`powerup_step_read`**, a read-only Host tool registered while both `tools` and
|
|
77
|
+
`sessionQuery` are composed:
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{ "ref": "dsh-step:session-1a2b…/turn.0.step.3", "requests": false }
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
It returns the raw events as JSON. Optional arguments: `before` / `after` add up
|
|
84
|
+
to 50 neighboring events on each side, and `requests: true` also includes the
|
|
85
|
+
`request/header` snapshots (the full system prompt and tool schemas), which are
|
|
86
|
+
omitted by default because they are large. The tool is workspace-agnostic: it
|
|
87
|
+
reads the session named in the reference through `ctx.sessionQuery`, so an agent
|
|
88
|
+
can open a step in a session it never had to locate on disk.
|
|
89
|
+
|
|
58
90
|
## Install a plugin
|
|
59
91
|
|
|
60
92
|
Open the built-in **Plugins** page. Every third-party card under **Installed
|
|
@@ -63,9 +95,10 @@ install dialog:
|
|
|
63
95
|
|
|
64
96
|
1. The dialog reads the package's published versions from the Host's configured
|
|
65
97
|
registries — the same list the **Add plugin** dialog offers, including the
|
|
66
|
-
npmmirror fallback.
|
|
67
|
-
|
|
68
|
-
|
|
98
|
+
npmmirror fallback. It stays on its loading state until that list has settled
|
|
99
|
+
(loaded or failed) and only then shows the chooser. Star any registry to make
|
|
100
|
+
it Power-Up's default for later installs; otherwise the list starts from the
|
|
101
|
+
Add dialog's remembered choice.
|
|
69
102
|
2. Type a version or pick one from the floating version list. The version in the
|
|
70
103
|
input is authoritative: both install actions install exactly that version, so
|
|
71
104
|
reinstalling or downgrading works. The installed version is tagged
|
|
@@ -118,6 +151,14 @@ fiber is unloaded. The panel closes; refresh the page when the install finishes.
|
|
|
118
151
|
the mark gets the full grid, so the chevrons and the amber baseline never
|
|
119
152
|
collide with a border. The reference line artwork is
|
|
120
153
|
`design/sidebar-icon.svg`; the runtime copy lives in `client.js`.
|
|
154
|
+
- **The step reference is plain coordinates plus one Host reader.** The Client
|
|
155
|
+
copies only `dsh-step:<session-id>/<step-id>` — no data, no URL, no port — so
|
|
156
|
+
the line survives restarts and can be pasted into any agent. The Host half
|
|
157
|
+
registers `powerup_step_read` when `tools` and `sessionQuery` are composed,
|
|
158
|
+
resolves the step through `sessionQuery.readSession` (raw events, ascending
|
|
159
|
+
seq), and returns the matching event window as JSON. A nested `run_code`
|
|
160
|
+
sub-call has no raw `tool/call` event of its own, so it falls back to the step
|
|
161
|
+
that owns it. Nothing is written to disk and no public route is added.
|
|
121
162
|
- **No imports from Harness Client packages.** The menu is plain React + CSS and
|
|
122
163
|
observes the trajectory package's own `data-*` contracts. If those attributes
|
|
123
164
|
change, row-specific actions degrade gracefully; session-level actions in the
|
|
@@ -186,12 +227,15 @@ fiber is unloaded. The panel closes; refresh the page when the install finishes.
|
|
|
186
227
|
## Development
|
|
187
228
|
|
|
188
229
|
```bash
|
|
189
|
-
|
|
230
|
+
npm test
|
|
190
231
|
```
|
|
191
232
|
|
|
192
|
-
|
|
193
|
-
it to a fake slot context, and checks registrations, icons, helpers,
|
|
194
|
-
tokens, the stop-reason mapping
|
|
233
|
+
`node test/smoke.mjs` loads the real Client module with React/browser doubles,
|
|
234
|
+
applies it to a fake slot context, and checks registrations, icons, helpers,
|
|
235
|
+
theme tokens, the step-reference copy path, the stop-reason mapping, the Host
|
|
236
|
+
routes, and the manifest. `node test/host.mjs` exercises the step-reference codec
|
|
237
|
+
and resolver plus the `powerup_step_read` tool against a fake `sessionQuery` and
|
|
238
|
+
a raw event log.
|
|
195
239
|
|
|
196
240
|
## License
|
|
197
241
|
|
package/client.js
CHANGED
|
@@ -69,9 +69,11 @@
|
|
|
69
69
|
|
|
70
70
|
const NS = 'dsh-powerup';
|
|
71
71
|
const SETTINGS_KEY = 'dsh-powerup:settings:v1';
|
|
72
|
-
const VERSION = '0.
|
|
72
|
+
const VERSION = '0.7.0';
|
|
73
73
|
const MENU_GAP = 8;
|
|
74
74
|
const MENU_WIDTH = 248;
|
|
75
|
+
/** Reference scheme understood by the Host's `powerup_step_read` tool. */
|
|
76
|
+
const STEP_REF_PREFIX = 'dsh-step:';
|
|
75
77
|
/** How long a one-click update's completion panel stays open when nothing restarts. */
|
|
76
78
|
const ONE_CLICK_AUTO_CLOSE_MS = 4000;
|
|
77
79
|
|
|
@@ -84,7 +86,7 @@
|
|
|
84
86
|
'page.title': 'Power-Up',
|
|
85
87
|
'page.subtitle': '给 DeepSeek Harness 加一点助推。',
|
|
86
88
|
'page.featureTitle': '轨迹右键菜单',
|
|
87
|
-
'page.featureDesc': '
|
|
89
|
+
'page.featureDesc': '在轨迹页面右键任意记录,快速复制、引用、查看详情、复制步骤引用,或从该记录 Fork 出一个新会话。',
|
|
88
90
|
'page.enabled': '已启用',
|
|
89
91
|
'page.disabled': '已停用',
|
|
90
92
|
'page.actions': '可用操作',
|
|
@@ -116,6 +118,8 @@
|
|
|
116
118
|
'action.inspectHint': '打开宿主自带的记录检查器',
|
|
117
119
|
'action.fork': '从此处 Fork 会话',
|
|
118
120
|
'action.forkHint': '带着这条记录及其之前的内容分支',
|
|
121
|
+
'action.stepRef': '复制步骤引用',
|
|
122
|
+
'action.stepRefHint': '复制「会话 ID + 步骤 ID」,Agent 用 powerup_step_read 即可取回该步骤的完整数据',
|
|
119
123
|
'action.export': '导出轨迹 JSON',
|
|
120
124
|
'action.exportHint': '把当前轨迹快照保存为 JSON 文件',
|
|
121
125
|
'action.session': '复制会话 ID',
|
|
@@ -130,6 +134,8 @@
|
|
|
130
134
|
'menu.inspect': '查看记录详情',
|
|
131
135
|
'menu.fork': '从此处 Fork 会话',
|
|
132
136
|
'menu.forkHint': '含此条',
|
|
137
|
+
'menu.stepRef': '复制步骤引用',
|
|
138
|
+
'menu.noStepRef': '这条记录没有可引用的步骤 ID',
|
|
133
139
|
'menu.export': '导出轨迹 JSON',
|
|
134
140
|
'menu.session': '复制会话 ID',
|
|
135
141
|
'menu.panel': '打开 Power-Up 页面',
|
|
@@ -146,6 +152,7 @@
|
|
|
146
152
|
'toast.empty': '这条记录没有可复制的文本',
|
|
147
153
|
'toast.actionFailed': '操作失败:{message}',
|
|
148
154
|
'toast.sessionCopied': '会话 ID 已复制',
|
|
155
|
+
'toast.stepRefCopied': '步骤引用已复制',
|
|
149
156
|
'toast.forkUnavailable': '当前宿主没有提供 Fork 接口',
|
|
150
157
|
'toast.noSession': '还没有打开会话',
|
|
151
158
|
'jobStop.title': '停止后台任务',
|
|
@@ -165,7 +172,7 @@
|
|
|
165
172
|
'update.versionLabel': '版本号',
|
|
166
173
|
'update.versionPlaceholder': '输入版本号,或从列表选择',
|
|
167
174
|
'update.loadingVersions': '正在从安装源读取版本…',
|
|
168
|
-
'update.loading': '
|
|
175
|
+
'update.loading': '正在读取插件和版本列表…',
|
|
169
176
|
'update.chooseVersion': '选择版本',
|
|
170
177
|
'update.hideVersions': '收起列表',
|
|
171
178
|
'update.versionsCount': '共 {count} 个版本',
|
|
@@ -256,7 +263,7 @@
|
|
|
256
263
|
'page.title': 'Power-Up',
|
|
257
264
|
'page.subtitle': 'A little boost for DeepSeek Harness.',
|
|
258
265
|
'page.featureTitle': 'Trajectory context menu',
|
|
259
|
-
'page.featureDesc': 'Right-click any trajectory record to copy it, quote it, open its inspector, or fork the session at that point.',
|
|
266
|
+
'page.featureDesc': 'Right-click any trajectory record to copy it, quote it, open its inspector, copy a step reference, or fork the session at that point.',
|
|
260
267
|
'page.enabled': 'Enabled',
|
|
261
268
|
'page.disabled': 'Disabled',
|
|
262
269
|
'page.actions': 'What you can do',
|
|
@@ -288,6 +295,8 @@
|
|
|
288
295
|
'action.inspectHint': 'Open the host record inspector',
|
|
289
296
|
'action.fork': 'Fork from here',
|
|
290
297
|
'action.forkHint': 'Branch with this record and everything before it',
|
|
298
|
+
'action.stepRef': 'Copy step reference',
|
|
299
|
+
'action.stepRefHint': 'Copy "session ID + step ID"; the agent can read the full step data with powerup_step_read',
|
|
291
300
|
'action.export': 'Export trajectory JSON',
|
|
292
301
|
'action.exportHint': 'Save the current trajectory snapshot as JSON',
|
|
293
302
|
'action.session': 'Copy session ID',
|
|
@@ -302,6 +311,8 @@
|
|
|
302
311
|
'menu.inspect': 'Open record details',
|
|
303
312
|
'menu.fork': 'Fork from here',
|
|
304
313
|
'menu.forkHint': 'inclusive',
|
|
314
|
+
'menu.stepRef': 'Copy step reference',
|
|
315
|
+
'menu.noStepRef': 'This record has no referenceable step ID',
|
|
305
316
|
'menu.export': 'Export trajectory JSON',
|
|
306
317
|
'menu.session': 'Copy session ID',
|
|
307
318
|
'menu.panel': 'Open the Power-Up page',
|
|
@@ -318,6 +329,7 @@
|
|
|
318
329
|
'toast.empty': 'This record has no text to copy',
|
|
319
330
|
'toast.actionFailed': 'Action failed: {message}',
|
|
320
331
|
'toast.sessionCopied': 'Session ID copied',
|
|
332
|
+
'toast.stepRefCopied': 'Step reference copied',
|
|
321
333
|
'toast.forkUnavailable': 'This host does not expose the fork API',
|
|
322
334
|
'toast.noSession': 'No session is open',
|
|
323
335
|
'jobStop.title': 'Stop background job',
|
|
@@ -337,7 +349,7 @@
|
|
|
337
349
|
'update.versionLabel': 'Version',
|
|
338
350
|
'update.versionPlaceholder': 'Type a version or pick one from the list',
|
|
339
351
|
'update.loadingVersions': 'Reading versions from the registry…',
|
|
340
|
-
'update.loading': 'Reading the plugin…',
|
|
352
|
+
'update.loading': 'Reading the plugin and its versions…',
|
|
341
353
|
'update.chooseVersion': 'Choose',
|
|
342
354
|
'update.hideVersions': 'Hide list',
|
|
343
355
|
'update.versionsCount': '{count} versions',
|
|
@@ -688,6 +700,16 @@
|
|
|
688
700
|
);
|
|
689
701
|
}
|
|
690
702
|
|
|
703
|
+
function TagIcon({ size = 16 }) {
|
|
704
|
+
return h(Icon, { size },
|
|
705
|
+
h('path', {
|
|
706
|
+
d: 'M2.9 7.2V3.6a.7.7 0 0 1 .7-.7h3.6a.7.7 0 0 1 .5.2l5.4 5.4a.9.9 0 0 1 0 1.3l-2.9 2.9a.9.9 0 0 1-1.3 0L3.1 7.7a.7.7 0 0 1-.2-.5Z',
|
|
707
|
+
stroke: 'currentColor', strokeWidth: '1.25', strokeLinejoin: 'round',
|
|
708
|
+
}),
|
|
709
|
+
h('circle', { cx: '5.5', cy: '5.5', r: '.85', fill: 'currentColor' }),
|
|
710
|
+
);
|
|
711
|
+
}
|
|
712
|
+
|
|
691
713
|
function LayoutIcon({ size = 16 }) {
|
|
692
714
|
return h(Icon, { size },
|
|
693
715
|
h('rect', {
|
|
@@ -1029,6 +1051,54 @@
|
|
|
1029
1051
|
}
|
|
1030
1052
|
}
|
|
1031
1053
|
|
|
1054
|
+
/**
|
|
1055
|
+
* The trajectory record id behind a ledger row. The DOM attribute is the
|
|
1056
|
+
* URI-encoded record id; a folded summary row appends a raw
|
|
1057
|
+
* `\0summary\0<kind>` suffix that is not part of the record identity.
|
|
1058
|
+
*/
|
|
1059
|
+
function rowRecordId(row) {
|
|
1060
|
+
const raw = row.getAttribute('data-trajectory-row-key');
|
|
1061
|
+
if (typeof raw !== 'string' || raw === '') return '';
|
|
1062
|
+
let decoded = raw;
|
|
1063
|
+
try {
|
|
1064
|
+
decoded = decodeURIComponent(raw);
|
|
1065
|
+
} catch {
|
|
1066
|
+
/* Keep the literal attribute. */
|
|
1067
|
+
}
|
|
1068
|
+
const summaryCut = decoded.indexOf('\u0000summary\u0000');
|
|
1069
|
+
return summaryCut === -1 ? decoded : decoded.slice(0, summaryCut);
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
/**
|
|
1073
|
+
* The step id a step reference carries: assistant rows resolve to their
|
|
1074
|
+
* turn/step, tool rows to their call id, raw-event rows to their seq.
|
|
1075
|
+
* Synthetic index rows have no stable identity and yield `''`.
|
|
1076
|
+
*/
|
|
1077
|
+
function rowStepId(row) {
|
|
1078
|
+
const recordId = rowRecordId(row);
|
|
1079
|
+
if (recordId === '') return '';
|
|
1080
|
+
const parts = recordId.split('\u0000');
|
|
1081
|
+
if (parts.length < 3) return '';
|
|
1082
|
+
if (parts[0] === 'assistant') {
|
|
1083
|
+
// `assistant\0T\0S` today; `assistant\0turn\0T\0step\0S` in older logs.
|
|
1084
|
+
const turn = Number(parts[1] === 'turn' ? parts[2] : parts[1]);
|
|
1085
|
+
const step = Number(parts[1] === 'turn' ? parts[4] : parts[2]);
|
|
1086
|
+
if (Number.isInteger(turn) && Number.isInteger(step) && turn >= 0 && step >= 0) {
|
|
1087
|
+
return `turn.${turn}.step.${step}`;
|
|
1088
|
+
}
|
|
1089
|
+
return '';
|
|
1090
|
+
}
|
|
1091
|
+
if (parts[1] === 'call' && parts[2] !== '') return `call.${encodeURIComponent(parts[2])}`;
|
|
1092
|
+
if (parts[1] === 'seq' && Number.isInteger(Number(parts[2]))) return `seq.${Number(parts[2])}`;
|
|
1093
|
+
return '';
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
/** The reference the Host step reader resolves: session id + step id. */
|
|
1097
|
+
function rowStepReference(sessionId, stepId) {
|
|
1098
|
+
if (typeof sessionId !== 'string' || sessionId === '' || stepId === '') return '';
|
|
1099
|
+
return `${STEP_REF_PREFIX}${sessionId}/${stepId}`;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1032
1102
|
/** The full visible content of one ledger row. */
|
|
1033
1103
|
function rowText(row) {
|
|
1034
1104
|
const cell = row.querySelector('td:nth-child(2)');
|
|
@@ -2656,13 +2726,16 @@
|
|
|
2656
2726
|
currentVersion: pkg.version ?? null,
|
|
2657
2727
|
installed: pkg.installed === true,
|
|
2658
2728
|
enabled: pkg.enabled !== false,
|
|
2659
|
-
phase: 'choose',
|
|
2660
2729
|
choices,
|
|
2661
2730
|
registryKey: choice.key,
|
|
2662
2731
|
defaultRegistryKey: starred === undefined ? null : starred.key,
|
|
2663
2732
|
versionsState: 'loading',
|
|
2664
2733
|
});
|
|
2734
|
+
// Keep the loading spinner until the mirror's version list has
|
|
2735
|
+
// settled, so the chooser never flashes with an empty list.
|
|
2665
2736
|
await loadVersions(token, name, choice, choices, false);
|
|
2737
|
+
if (tokenRef.current !== token) return;
|
|
2738
|
+
patch(token, { phase: 'choose' });
|
|
2666
2739
|
} catch (error) {
|
|
2667
2740
|
patch(token, { phase: 'error', error: errorText(error) || t('update.unknown') });
|
|
2668
2741
|
}
|
|
@@ -3612,6 +3685,8 @@
|
|
|
3612
3685
|
const quote = markdownQuote(row, t);
|
|
3613
3686
|
const hasText = text !== '';
|
|
3614
3687
|
const hasSession = typeof sessionId === 'string' && sessionId !== '';
|
|
3688
|
+
const stepId = rowStepId(row);
|
|
3689
|
+
const stepReference = rowStepReference(hasSession ? sessionId : '', stepId);
|
|
3615
3690
|
return [
|
|
3616
3691
|
{
|
|
3617
3692
|
id: 'copy',
|
|
@@ -3687,6 +3762,21 @@
|
|
|
3687
3762
|
await forkAt(ctx, forkSeq, sessionId, notify, t);
|
|
3688
3763
|
},
|
|
3689
3764
|
},
|
|
3765
|
+
{
|
|
3766
|
+
id: 'stepref',
|
|
3767
|
+
label: t('menu.stepRef'),
|
|
3768
|
+
icon: h(TagIcon, { size: 15 }),
|
|
3769
|
+
disabled: stepReference === '',
|
|
3770
|
+
title: stepReference === '' ? t('menu.noStepRef') : undefined,
|
|
3771
|
+
run: async () => {
|
|
3772
|
+
if (stepReference === '') {
|
|
3773
|
+
notify(t('menu.noStepRef'));
|
|
3774
|
+
return;
|
|
3775
|
+
}
|
|
3776
|
+
await copyText(stepReference);
|
|
3777
|
+
notify(t('toast.stepRefCopied'));
|
|
3778
|
+
},
|
|
3779
|
+
},
|
|
3690
3780
|
{
|
|
3691
3781
|
id: 'session',
|
|
3692
3782
|
label: t('menu.session'),
|
|
@@ -3790,6 +3880,7 @@
|
|
|
3790
3880
|
{ id: 'insert', icon: ComposerIcon, name: t('action.insert'), hint: t('action.insertHint') },
|
|
3791
3881
|
{ id: 'inspect', icon: InspectIcon, name: t('action.inspect'), hint: t('action.inspectHint') },
|
|
3792
3882
|
{ id: 'fork', icon: ForkIcon, name: t('action.fork'), hint: t('action.forkHint') },
|
|
3883
|
+
{ id: 'stepref', icon: TagIcon, name: t('action.stepRef'), hint: t('action.stepRefHint') },
|
|
3793
3884
|
{ id: 'export', icon: ExportIcon, name: t('action.export'), hint: t('action.exportHint') },
|
|
3794
3885
|
];
|
|
3795
3886
|
/** One label/description row with a host-styled switch. */
|
|
@@ -4051,6 +4142,9 @@
|
|
|
4051
4142
|
updateButtonLabel,
|
|
4052
4143
|
popoverPlacement,
|
|
4053
4144
|
rowKeyParts,
|
|
4145
|
+
rowRecordId,
|
|
4146
|
+
rowStepId,
|
|
4147
|
+
rowStepReference,
|
|
4054
4148
|
resolveForkSeq,
|
|
4055
4149
|
markdownQuote,
|
|
4056
4150
|
jsonSafe,
|
package/index.js
CHANGED
|
@@ -14,19 +14,27 @@
|
|
|
14
14
|
* removed
|
|
15
15
|
* POST /dsh-powerup/api/job-kill → stops one background job with an
|
|
16
16
|
* optional human reason
|
|
17
|
+
* tool powerup_step_read → resolves a `dsh-step:` reference
|
|
18
|
+
* copied from the Trajectory menu into
|
|
19
|
+
* the raw session events it identifies
|
|
17
20
|
*
|
|
18
21
|
* The Client half drives other plugins' installation through the built-in
|
|
19
22
|
* `pluginManager` Remote. Only the process restart, the self-update handoff,
|
|
20
23
|
* and the stop-with-reason kill need Host code: the built-in `job.kill` Remote
|
|
21
24
|
* hard-codes `cancelled by the user`, while the registry's own `kill` accepts
|
|
22
25
|
* a reason that settlement merges into the job's `detail` line.
|
|
26
|
+
*
|
|
27
|
+
* The step-reference tool reads `ctx.sessionQuery`; both the reference codec
|
|
28
|
+
* and the tool spec live in `lib/` so offline tests can exercise them.
|
|
23
29
|
*/
|
|
24
30
|
|
|
25
31
|
import { randomUUID } from 'node:crypto';
|
|
26
32
|
import { appendFileSync, mkdirSync, readFileSync, statSync } from 'node:fs';
|
|
27
33
|
import { dirname, join } from 'node:path';
|
|
28
34
|
import { homedir } from 'node:os';
|
|
35
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
29
36
|
import { describeRestart, requestRestart } from './lib/restart.js';
|
|
37
|
+
import { createStepReadTool } from './lib/step-tool.js';
|
|
30
38
|
|
|
31
39
|
/** Prefix owned by this plugin. */
|
|
32
40
|
const ROUTE = '/dsh-powerup/api';
|
|
@@ -451,7 +459,9 @@ async function handle(req, res, ctx) {
|
|
|
451
459
|
}
|
|
452
460
|
|
|
453
461
|
/**
|
|
454
|
-
* Mount the restart and self-update routes once the Web server exists
|
|
462
|
+
* Mount the restart and self-update routes once the Web server exists, and
|
|
463
|
+
* register the step-reference reader once both the tool registry and the
|
|
464
|
+
* session-query service are composed.
|
|
455
465
|
* @param {import('@deepseek-ai/cordis').Context} ctx
|
|
456
466
|
*/
|
|
457
467
|
export function apply(ctx) {
|
|
@@ -468,6 +478,17 @@ export function apply(ctx) {
|
|
|
468
478
|
'dsh-powerup: restart and self-update routes',
|
|
469
479
|
);
|
|
470
480
|
});
|
|
481
|
+
ctx.inject(['tools', 'sessionQuery'], (scope) => {
|
|
482
|
+
const tools = scope.get('tools');
|
|
483
|
+
if (tools === undefined || typeof tools.register !== 'function') return;
|
|
484
|
+
scope.effect(
|
|
485
|
+
() => tools.register(createStepReadTool(defineTool, {
|
|
486
|
+
// Re-read the service at call time: the scope owns the live instance.
|
|
487
|
+
getSessionQuery: () => scope.get('sessionQuery'),
|
|
488
|
+
})),
|
|
489
|
+
'dsh-powerup: step reference reader',
|
|
490
|
+
);
|
|
491
|
+
});
|
|
471
492
|
}
|
|
472
493
|
|
|
473
494
|
/** Exported for tests only; the Host never reads this. */
|
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Power-Up step references.
|
|
3
|
+
*
|
|
4
|
+
* A reference copied from the Trajectory context menu has the shape
|
|
5
|
+
*
|
|
6
|
+
* dsh-step:<session-id>/<step-id>
|
|
7
|
+
*
|
|
8
|
+
* and identifies one unit of a session log:
|
|
9
|
+
*
|
|
10
|
+
* turn.<turn>.step.<step> one assistant step: every raw event between
|
|
11
|
+
* `step/start` and `step/end` (assistant message,
|
|
12
|
+
* tool calls, tool results, attempts)
|
|
13
|
+
* call.<call-id> one tool call plus its result
|
|
14
|
+
* seq.<n> one raw event
|
|
15
|
+
* index.<n> a synthetic ledger row with no stable identity
|
|
16
|
+
*
|
|
17
|
+
* The model-facing `powerup_step_read` tool resolves a reference through
|
|
18
|
+
* `ctx.sessionQuery`, so an agent only needs the copied string.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** Reference scheme, including the trailing colon. */
|
|
22
|
+
export const STEP_REF_PREFIX = 'dsh-step:';
|
|
23
|
+
|
|
24
|
+
/** Reference scheme without the separator. */
|
|
25
|
+
export const STEP_REF_SCHEME = 'dsh-step';
|
|
26
|
+
|
|
27
|
+
/** Model-facing tool that resolves these references. */
|
|
28
|
+
export const STEP_READ_TOOL_NAME = 'powerup_step_read';
|
|
29
|
+
|
|
30
|
+
/** Neighbor bound; matches the session-query default `readWindowMax`. */
|
|
31
|
+
export const MAX_CONTEXT_EVENTS = 50;
|
|
32
|
+
|
|
33
|
+
/** The raw event types that snapshot the whole request envelope. */
|
|
34
|
+
const REQUEST_EVENT_TYPES = new Set(['request/header']);
|
|
35
|
+
|
|
36
|
+
/** A reference that cannot be parsed or resolved. */
|
|
37
|
+
export class StepReferenceError extends Error {
|
|
38
|
+
/**
|
|
39
|
+
* @param {string} code stable machine code, included in the message
|
|
40
|
+
* @param {string} message model-readable explanation
|
|
41
|
+
* @param {{ cause?: unknown }} [options]
|
|
42
|
+
*/
|
|
43
|
+
constructor(code, message, options = {}) {
|
|
44
|
+
super(`${code}: ${message}`);
|
|
45
|
+
this.name = 'StepReferenceError';
|
|
46
|
+
this.code = code;
|
|
47
|
+
if (options.cause !== undefined) this.cause = options.cause;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Build the reference an agent can paste back into `powerup_step_read`.
|
|
53
|
+
* @param {string} sessionId
|
|
54
|
+
* @param {string} stepId normalized step id
|
|
55
|
+
* @returns {string}
|
|
56
|
+
*/
|
|
57
|
+
export function formatStepReference(sessionId, stepId) {
|
|
58
|
+
if (typeof sessionId !== 'string' || sessionId.trim() === '') {
|
|
59
|
+
throw new StepReferenceError('STEP_REF_INVALID', 'a step reference needs a session id');
|
|
60
|
+
}
|
|
61
|
+
if (typeof stepId !== 'string' || stepId.trim() === '') {
|
|
62
|
+
throw new StepReferenceError('STEP_REF_INVALID', 'a step reference needs a step id');
|
|
63
|
+
}
|
|
64
|
+
return `${STEP_REF_PREFIX}${sessionId.trim()}/${stepId.trim()}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Split a reference into its session id and step id.
|
|
69
|
+
* @param {string} ref
|
|
70
|
+
* @returns {{ sessionId: string, stepId: string }}
|
|
71
|
+
*/
|
|
72
|
+
export function parseStepReference(ref) {
|
|
73
|
+
if (typeof ref !== 'string') {
|
|
74
|
+
throw new StepReferenceError('STEP_REF_INVALID', 'a step reference is a string copied from the Trajectory menu');
|
|
75
|
+
}
|
|
76
|
+
const text = ref.trim();
|
|
77
|
+
if (!text.toLowerCase().startsWith(STEP_REF_PREFIX)) {
|
|
78
|
+
throw new StepReferenceError(
|
|
79
|
+
'STEP_REF_INVALID',
|
|
80
|
+
`a step reference starts with ${STEP_REF_PREFIX} (use Copy step reference in the Trajectory menu)`,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
const rest = text.slice(STEP_REF_PREFIX.length);
|
|
84
|
+
const slash = rest.indexOf('/');
|
|
85
|
+
if (slash <= 0 || slash === rest.length - 1) {
|
|
86
|
+
throw new StepReferenceError('STEP_REF_INVALID', 'a step reference is dsh-step:<sessionId>/<stepId>');
|
|
87
|
+
}
|
|
88
|
+
const sessionId = rest.slice(0, slash).trim();
|
|
89
|
+
const stepId = rest.slice(slash + 1).trim();
|
|
90
|
+
if (sessionId === '' || stepId === '') {
|
|
91
|
+
throw new StepReferenceError('STEP_REF_INVALID', 'a step reference is dsh-step:<sessionId>/<stepId>');
|
|
92
|
+
}
|
|
93
|
+
return { sessionId, stepId };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** @param {string} text */
|
|
97
|
+
function canonicalStepId(text) {
|
|
98
|
+
let match = /^turn\.(\d+)\.step\.(\d+)$/u.exec(text);
|
|
99
|
+
if (match !== null) return `turn.${Number(match[1])}.step.${Number(match[2])}`;
|
|
100
|
+
match = /^call\.(.+)$/u.exec(text);
|
|
101
|
+
if (match !== null) {
|
|
102
|
+
let callId = match[1];
|
|
103
|
+
try {
|
|
104
|
+
callId = decodeURIComponent(callId);
|
|
105
|
+
} catch {
|
|
106
|
+
/* Keep the literal text. */
|
|
107
|
+
}
|
|
108
|
+
return `call.${encodeURIComponent(callId)}`;
|
|
109
|
+
}
|
|
110
|
+
match = /^seq\.(\d+)$/u.exec(text);
|
|
111
|
+
if (match !== null) return `seq.${Number(match[1])}`;
|
|
112
|
+
match = /^index\.(\d+)$/u.exec(text);
|
|
113
|
+
if (match !== null) return `index.${Number(match[1])}`;
|
|
114
|
+
return '';
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Turn anything a row exposes — the DOM row key (`encodeURIComponent` of the
|
|
119
|
+
* trajectory record id, optionally with a `\0summary\0` fold suffix), a raw
|
|
120
|
+
* record id, or an already-normalized step id — into the canonical step id.
|
|
121
|
+
* @param {string} value
|
|
122
|
+
* @returns {string} canonical id, or `''` when the value carries no usable identity
|
|
123
|
+
*/
|
|
124
|
+
export function normalizeStepId(value) {
|
|
125
|
+
if (typeof value !== 'string') return '';
|
|
126
|
+
const text = value.trim();
|
|
127
|
+
if (text === '') return '';
|
|
128
|
+
const known = canonicalStepId(text);
|
|
129
|
+
if (known !== '') return known;
|
|
130
|
+
let decoded = text;
|
|
131
|
+
try {
|
|
132
|
+
decoded = decodeURIComponent(text);
|
|
133
|
+
} catch {
|
|
134
|
+
/* The value is already raw. */
|
|
135
|
+
}
|
|
136
|
+
const summaryCut = decoded.indexOf('\u0000summary\u0000');
|
|
137
|
+
if (summaryCut !== -1) decoded = decoded.slice(0, summaryCut);
|
|
138
|
+
const parts = decoded.split('\u0000');
|
|
139
|
+
if (parts.length < 3) return '';
|
|
140
|
+
if (parts[0] === 'assistant') {
|
|
141
|
+
// `assistant\0turn\0T\0step\0S` (older shape) and `assistant\0T\0S`.
|
|
142
|
+
const turn = Number(parts[1] === 'turn' ? parts[2] : parts[1]);
|
|
143
|
+
const step = Number(parts[1] === 'turn' ? parts[4] : parts[2]);
|
|
144
|
+
if (Number.isInteger(turn) && Number.isInteger(step) && turn >= 0 && step >= 0) {
|
|
145
|
+
return `turn.${turn}.step.${step}`;
|
|
146
|
+
}
|
|
147
|
+
return '';
|
|
148
|
+
}
|
|
149
|
+
if (parts[1] === 'call' && parts[2] !== '') return `call.${encodeURIComponent(parts[2])}`;
|
|
150
|
+
if (parts[1] === 'seq' && Number.isInteger(Number(parts[2]))) return `seq.${Number(parts[2])}`;
|
|
151
|
+
if (parts[1] === 'index' && Number.isInteger(Number(parts[2]))) return `index.${Number(parts[2])}`;
|
|
152
|
+
return '';
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Parse a canonical step id into the descriptor the resolver understands.
|
|
157
|
+
* @param {string} stepId
|
|
158
|
+
* @returns {{ kind: 'step', turn: number, step: number }
|
|
159
|
+
* | { kind: 'call', callId: string }
|
|
160
|
+
* | { kind: 'seq', seq: number }
|
|
161
|
+
* | { kind: 'index', index: number }
|
|
162
|
+
* | null}
|
|
163
|
+
*/
|
|
164
|
+
export function parseStepId(stepId) {
|
|
165
|
+
const normalized = normalizeStepId(stepId);
|
|
166
|
+
if (normalized === '') return null;
|
|
167
|
+
let match = /^turn\.(\d+)\.step\.(\d+)$/u.exec(normalized);
|
|
168
|
+
if (match !== null) return { kind: 'step', turn: Number(match[1]), step: Number(match[2]) };
|
|
169
|
+
match = /^call\.(.+)$/u.exec(normalized);
|
|
170
|
+
if (match !== null) {
|
|
171
|
+
let callId = match[1];
|
|
172
|
+
try {
|
|
173
|
+
callId = decodeURIComponent(callId);
|
|
174
|
+
} catch {
|
|
175
|
+
/* Keep the literal text. */
|
|
176
|
+
}
|
|
177
|
+
return { kind: 'call', callId };
|
|
178
|
+
}
|
|
179
|
+
match = /^seq\.(\d+)$/u.exec(normalized);
|
|
180
|
+
if (match !== null) return { kind: 'seq', seq: Number(match[1]) };
|
|
181
|
+
match = /^index\.(\d+)$/u.exec(normalized);
|
|
182
|
+
if (match !== null) return { kind: 'index', index: Number(match[1]) };
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Canonical id for a parsed step descriptor.
|
|
188
|
+
* @param {ReturnType<typeof parseStepId>} step
|
|
189
|
+
* @returns {string}
|
|
190
|
+
*/
|
|
191
|
+
export function stepIdOf(step) {
|
|
192
|
+
if (step === null || step === undefined) return '';
|
|
193
|
+
if (step.kind === 'step') return `turn.${step.turn}.step.${step.step}`;
|
|
194
|
+
if (step.kind === 'call') return `call.${encodeURIComponent(step.callId)}`;
|
|
195
|
+
if (step.kind === 'seq') return `seq.${step.seq}`;
|
|
196
|
+
if (step.kind === 'index') return `index.${step.index}`;
|
|
197
|
+
return '';
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** @param {unknown} event @param {number} turn @param {number} step */
|
|
201
|
+
function belongsToStep(event, turn, step) {
|
|
202
|
+
const data = event?.data;
|
|
203
|
+
return data !== null && typeof data === 'object' && data.turn === turn && data.step === step;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The toolCallId a `tool/result` event answers.
|
|
208
|
+
* @param {any} data
|
|
209
|
+
* @returns {string}
|
|
210
|
+
*/
|
|
211
|
+
function resultCallId(data) {
|
|
212
|
+
const message = data?.message;
|
|
213
|
+
if (message !== null && typeof message === 'object') {
|
|
214
|
+
if (typeof message.toolCallId === 'string' && message.toolCallId !== '') return message.toolCallId;
|
|
215
|
+
const callId = message.source?.callId;
|
|
216
|
+
if (typeof callId === 'string' && callId !== '') return callId;
|
|
217
|
+
}
|
|
218
|
+
if (typeof data?.callId === 'string' && data.callId !== '') return data.callId;
|
|
219
|
+
return '';
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Depth-bounded scan for a call id, used only for nested sub-calls that never
|
|
224
|
+
* become their own raw `tool/call` event.
|
|
225
|
+
* @param {unknown} value
|
|
226
|
+
* @param {string} callId
|
|
227
|
+
* @param {Set<unknown>} seen
|
|
228
|
+
* @param {number} depth
|
|
229
|
+
* @returns {boolean}
|
|
230
|
+
*/
|
|
231
|
+
function mentionsCallId(value, callId, seen, depth) {
|
|
232
|
+
if (depth > 9 || value === null || typeof value !== 'object') return false;
|
|
233
|
+
if (seen.has(value)) return false;
|
|
234
|
+
seen.add(value);
|
|
235
|
+
if (value.callId === callId || value.toolCallId === callId) return true;
|
|
236
|
+
for (const key of Object.keys(value)) {
|
|
237
|
+
if (key === 'schema' || key === 'tools' || key === 'system') continue;
|
|
238
|
+
if (mentionsCallId(value[key], callId, seen, depth + 1)) return true;
|
|
239
|
+
}
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Index range of every raw event that belongs to one turn/step.
|
|
245
|
+
* @param {readonly any[]} events
|
|
246
|
+
* @param {number} turn
|
|
247
|
+
* @param {number} step
|
|
248
|
+
* @returns {{ startIndex: number, endIndex: number, resolved: object } | null}
|
|
249
|
+
*/
|
|
250
|
+
function findStepRange(events, turn, step) {
|
|
251
|
+
let first = -1;
|
|
252
|
+
let start = -1;
|
|
253
|
+
let end = -1;
|
|
254
|
+
let last = -1;
|
|
255
|
+
for (let index = 0; index < events.length; index += 1) {
|
|
256
|
+
const event = events[index];
|
|
257
|
+
if (!belongsToStep(event, turn, step)) continue;
|
|
258
|
+
if (first === -1) first = index;
|
|
259
|
+
last = index;
|
|
260
|
+
if (event.type === 'step/start' && start === -1) start = index;
|
|
261
|
+
if (event.type === 'step/end') end = index;
|
|
262
|
+
}
|
|
263
|
+
if (first === -1) return null;
|
|
264
|
+
const from = start === -1 ? first : start;
|
|
265
|
+
const to = end === -1 ? last : end;
|
|
266
|
+
return {
|
|
267
|
+
startIndex: Math.min(from, to),
|
|
268
|
+
endIndex: Math.max(from, to),
|
|
269
|
+
resolved: { kind: 'step', turn, step },
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Locate the raw event range behind a parsed step id.
|
|
275
|
+
* @param {readonly any[]} events raw session events, ascending by seq
|
|
276
|
+
* @param {ReturnType<typeof parseStepId>} step
|
|
277
|
+
* @returns {{ startIndex: number, endIndex: number, resolved: object } | null}
|
|
278
|
+
*/
|
|
279
|
+
export function resolveStepRange(events, step) {
|
|
280
|
+
if (!Array.isArray(events) || events.length === 0) return null;
|
|
281
|
+
if (step === null || step === undefined) return null;
|
|
282
|
+
if (step.kind === 'index') {
|
|
283
|
+
throw new StepReferenceError(
|
|
284
|
+
'STEP_REF_SYNTHETIC',
|
|
285
|
+
'this ledger row has a synthetic index id (no stable event or call identity), so it cannot be resolved',
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
if (step.kind === 'seq') {
|
|
289
|
+
const index = events.findIndex((event) => event?.seq === step.seq);
|
|
290
|
+
return index === -1 ? null : { startIndex: index, endIndex: index, resolved: { kind: 'seq', seq: step.seq } };
|
|
291
|
+
}
|
|
292
|
+
if (step.kind === 'call') {
|
|
293
|
+
let callIndex = -1;
|
|
294
|
+
let resultIndex = -1;
|
|
295
|
+
for (let index = 0; index < events.length; index += 1) {
|
|
296
|
+
const event = events[index];
|
|
297
|
+
if (event?.type === 'tool/call' && event.data?.callId === step.callId) {
|
|
298
|
+
if (callIndex === -1) callIndex = index;
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (event?.type === 'tool/result' && resultCallId(event.data) === step.callId) resultIndex = index;
|
|
302
|
+
}
|
|
303
|
+
if (callIndex !== -1 || resultIndex !== -1) {
|
|
304
|
+
const from = callIndex === -1 ? resultIndex : callIndex;
|
|
305
|
+
const to = resultIndex === -1 ? callIndex : Math.max(resultIndex, callIndex);
|
|
306
|
+
const owner = events[from]?.data;
|
|
307
|
+
const resolved = { kind: 'call', callId: step.callId };
|
|
308
|
+
if (Number.isInteger(owner?.turn)) resolved.turn = owner.turn;
|
|
309
|
+
if (Number.isInteger(owner?.step)) resolved.step = owner.step;
|
|
310
|
+
return {
|
|
311
|
+
startIndex: Math.min(from, to),
|
|
312
|
+
endIndex: Math.max(from, to),
|
|
313
|
+
resolved,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
// A nested sub-call (PTC/run_code child) is not its own raw event; fall
|
|
317
|
+
// back to the step that owns it so the step still answers the reference.
|
|
318
|
+
for (let index = 0; index < events.length; index += 1) {
|
|
319
|
+
const event = events[index];
|
|
320
|
+
if (!mentionsCallId(event, step.callId, new Set(), 0)) continue;
|
|
321
|
+
const data = event?.data;
|
|
322
|
+
if (Number.isInteger(data?.turn) && Number.isInteger(data?.step)) {
|
|
323
|
+
const range = findStepRange(events, data.turn, data.step);
|
|
324
|
+
if (range !== null) {
|
|
325
|
+
return {
|
|
326
|
+
startIndex: range.startIndex,
|
|
327
|
+
endIndex: range.endIndex,
|
|
328
|
+
resolved: { kind: 'step', turn: data.turn, step: data.step, viaCallId: step.callId },
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return {
|
|
333
|
+
startIndex: index,
|
|
334
|
+
endIndex: index,
|
|
335
|
+
resolved: { kind: 'event', seq: event.seq, viaCallId: step.callId },
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
return findStepRange(events, step.turn, step.step);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** @param {unknown} value @param {number} fallback */
|
|
344
|
+
function neighborCount(value, fallback = 0) {
|
|
345
|
+
const number = typeof value === 'number' ? value : Number(value);
|
|
346
|
+
if (!Number.isFinite(number)) return fallback;
|
|
347
|
+
return Math.max(0, Math.min(MAX_CONTEXT_EVENTS, Math.trunc(number)));
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* JSON-safe copy: bigint becomes a string and cycles become `[circular]`.
|
|
352
|
+
* @param {unknown} value
|
|
353
|
+
* @param {Set<unknown>} [seen]
|
|
354
|
+
* @returns {unknown}
|
|
355
|
+
*/
|
|
356
|
+
export function toJsonSafe(value, seen = new Set()) {
|
|
357
|
+
if (value === null || typeof value !== 'object') {
|
|
358
|
+
return typeof value === 'bigint' ? String(value) : value;
|
|
359
|
+
}
|
|
360
|
+
if (seen.has(value)) return '[circular]';
|
|
361
|
+
seen.add(value);
|
|
362
|
+
if (Array.isArray(value)) return value.map((entry) => toJsonSafe(entry, seen));
|
|
363
|
+
if (value instanceof Map) {
|
|
364
|
+
const out = {};
|
|
365
|
+
for (const [key, entry] of value.entries()) out[String(key)] = toJsonSafe(entry, seen);
|
|
366
|
+
return out;
|
|
367
|
+
}
|
|
368
|
+
if (value instanceof Set) return [...value].map((entry) => toJsonSafe(entry, seen));
|
|
369
|
+
const out = {};
|
|
370
|
+
for (const key of Object.keys(value)) {
|
|
371
|
+
const entry = value[key];
|
|
372
|
+
if (typeof entry === 'function') continue;
|
|
373
|
+
out[key] = toJsonSafe(entry, seen);
|
|
374
|
+
}
|
|
375
|
+
return out;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Read everything one step reference points at.
|
|
380
|
+
*
|
|
381
|
+
* @param {any} sessionQuery `ctx.sessionQuery`
|
|
382
|
+
* @param {string} ref the copied `dsh-step:` reference
|
|
383
|
+
* @param {{ before?: number, after?: number, requests?: boolean }} [options]
|
|
384
|
+
* @param {AbortSignal} [signal]
|
|
385
|
+
* @returns {Promise<object>} the JSON payload the tool renders
|
|
386
|
+
*/
|
|
387
|
+
export async function readStepReference(sessionQuery, ref, options = {}, signal) {
|
|
388
|
+
const { sessionId, stepId } = parseStepReference(ref);
|
|
389
|
+
const normalized = normalizeStepId(stepId);
|
|
390
|
+
const step = parseStepId(normalized);
|
|
391
|
+
if (step === null) {
|
|
392
|
+
throw new StepReferenceError(
|
|
393
|
+
'STEP_REF_INVALID_STEP_ID',
|
|
394
|
+
`"${stepId}" is not a known step id (expected turn.<t>.step.<s>, call.<id>, seq.<n>, or index.<n>)`,
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
if (step.kind === 'index') {
|
|
398
|
+
throw new StepReferenceError('STEP_REF_SYNTHETIC', 'synthetic index rows cannot be resolved');
|
|
399
|
+
}
|
|
400
|
+
if (sessionQuery === null || sessionQuery === undefined || typeof sessionQuery.readSession !== 'function') {
|
|
401
|
+
throw new StepReferenceError('STEP_REF_SESSION_QUERY_UNAVAILABLE', 'this host does not expose ctx.sessionQuery');
|
|
402
|
+
}
|
|
403
|
+
signal?.throwIfAborted?.();
|
|
404
|
+
|
|
405
|
+
let snapshot;
|
|
406
|
+
try {
|
|
407
|
+
snapshot = await sessionQuery.readSession(sessionId);
|
|
408
|
+
} catch (error) {
|
|
409
|
+
const detail = String(error?.message ?? error);
|
|
410
|
+
throw new StepReferenceError(
|
|
411
|
+
'STEP_REF_SESSION_UNAVAILABLE',
|
|
412
|
+
`could not read session "${sessionId}" (${detail})`,
|
|
413
|
+
{ cause: error },
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
signal?.throwIfAborted?.();
|
|
417
|
+
|
|
418
|
+
const events = Array.isArray(snapshot?.events) ? snapshot.events : [];
|
|
419
|
+
if (events.length === 0) {
|
|
420
|
+
throw new StepReferenceError('STEP_REF_EMPTY_SESSION', `session "${sessionId}" has no raw events`);
|
|
421
|
+
}
|
|
422
|
+
const range = resolveStepRange(events, step);
|
|
423
|
+
if (range === null) {
|
|
424
|
+
throw new StepReferenceError(
|
|
425
|
+
'STEP_REF_UNRESOLVED',
|
|
426
|
+
`no event in session "${sessionId}" matches ${stepIdOf(step)}`,
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const before = neighborCount(options.before);
|
|
431
|
+
const after = neighborCount(options.after);
|
|
432
|
+
const start = Math.max(0, range.startIndex - before);
|
|
433
|
+
const end = Math.min(events.length - 1, range.endIndex + after);
|
|
434
|
+
const includeRequests = options.requests === true;
|
|
435
|
+
const selected = [];
|
|
436
|
+
for (let index = start; index <= end; index += 1) {
|
|
437
|
+
const event = events[index];
|
|
438
|
+
if (!includeRequests && REQUEST_EVENT_TYPES.has(event?.type)) continue;
|
|
439
|
+
selected.push(toJsonSafe(event));
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
let title = '';
|
|
443
|
+
if (typeof sessionQuery.readTitle === 'function') {
|
|
444
|
+
try {
|
|
445
|
+
const snapshotTitle = await sessionQuery.readTitle(sessionId);
|
|
446
|
+
if (typeof snapshotTitle?.title === 'string') title = snapshotTitle.title;
|
|
447
|
+
} catch {
|
|
448
|
+
/* A missing title never fails the read. */
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
signal?.throwIfAborted?.();
|
|
452
|
+
|
|
453
|
+
const payload = {
|
|
454
|
+
reference: formatStepReference(String(snapshot?.session?.id ?? sessionId), stepIdOf(step)),
|
|
455
|
+
session: {
|
|
456
|
+
id: String(snapshot?.session?.id ?? sessionId),
|
|
457
|
+
...(typeof snapshot?.session?.cwd === 'string' && snapshot.session.cwd !== '' ? { cwd: snapshot.session.cwd } : {}),
|
|
458
|
+
...(title === '' ? {} : { title }),
|
|
459
|
+
},
|
|
460
|
+
target: { kind: step.kind, id: stepIdOf(step), ...describeStep(step) },
|
|
461
|
+
resolved: range.resolved,
|
|
462
|
+
range: {
|
|
463
|
+
startSeq: events[start].seq,
|
|
464
|
+
endSeq: events[end].seq,
|
|
465
|
+
eventCount: end - start + 1,
|
|
466
|
+
returned: selected.length,
|
|
467
|
+
before,
|
|
468
|
+
after,
|
|
469
|
+
},
|
|
470
|
+
events: selected,
|
|
471
|
+
};
|
|
472
|
+
if (!includeRequests && selected.length !== end - start + 1) {
|
|
473
|
+
payload.note = 'request/header snapshots (the full system prompt and tool schemas) are omitted; pass requests=true to include them';
|
|
474
|
+
}
|
|
475
|
+
return payload;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/** @param {Exclude<ReturnType<typeof parseStepId>, null>} step */
|
|
479
|
+
function describeStep(step) {
|
|
480
|
+
if (step.kind === 'step') return { turn: step.turn, step: step.step };
|
|
481
|
+
if (step.kind === 'call') return { callId: step.callId };
|
|
482
|
+
if (step.kind === 'seq') return { seq: step.seq };
|
|
483
|
+
return { index: step.index };
|
|
484
|
+
}
|
package/lib/step-tool.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model-facing half of step references: one read-only tool that turns a
|
|
3
|
+
* `dsh-step:` reference copied from the Trajectory menu into raw session data.
|
|
4
|
+
*
|
|
5
|
+
* The factory takes the Host's `defineTool` so this module stays importable by
|
|
6
|
+
* the offline tests without resolving a DSH package import.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { readStepReference, STEP_READ_TOOL_NAME } from './step-reference.js';
|
|
10
|
+
|
|
11
|
+
/** Default cooperative deadline for one read. */
|
|
12
|
+
export const STEP_READ_TIMEOUT_MS = 30_000;
|
|
13
|
+
|
|
14
|
+
export const STEP_READ_DESCRIPTION = [
|
|
15
|
+
'Read the complete raw data behind a Power-Up step reference copied from the Trajectory ledger.',
|
|
16
|
+
'The reference looks like dsh-step:<sessionId>/<stepId>; copy one with the Trajectory right-click menu (Copy step reference).',
|
|
17
|
+
'A turn/step reference returns every raw session event of that assistant step (message, tool calls, tool results, attempts);',
|
|
18
|
+
'a call reference returns the tool call and its result; a seq reference returns that single event.',
|
|
19
|
+
'Raw events are returned as JSON. System-prompt/tool-schema request snapshots are omitted by default; pass requests=true to include them.',
|
|
20
|
+
].join(' ');
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {(definition: unknown) => any} defineTool the Host's tool DSL
|
|
24
|
+
* @param {{ getSessionQuery: () => any }} options
|
|
25
|
+
* @returns {any} a ToolDefinition for `ctx.tools.register`
|
|
26
|
+
*/
|
|
27
|
+
export function createStepReadTool(defineTool, options) {
|
|
28
|
+
if (typeof defineTool !== 'function') throw new TypeError('createStepReadTool requires defineTool');
|
|
29
|
+
const getSessionQuery = options?.getSessionQuery;
|
|
30
|
+
if (typeof getSessionQuery !== 'function') throw new TypeError('createStepReadTool requires getSessionQuery');
|
|
31
|
+
|
|
32
|
+
return defineTool({
|
|
33
|
+
name: STEP_READ_TOOL_NAME,
|
|
34
|
+
description: STEP_READ_DESCRIPTION,
|
|
35
|
+
parameters: {
|
|
36
|
+
ref: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
required: true,
|
|
39
|
+
description: 'The dsh-step:<sessionId>/<stepId> reference exactly as copied from the Trajectory menu.',
|
|
40
|
+
},
|
|
41
|
+
before: {
|
|
42
|
+
type: 'integer',
|
|
43
|
+
description: `Extra raw events to include before the step (0-50, default 0).`,
|
|
44
|
+
},
|
|
45
|
+
after: {
|
|
46
|
+
type: 'integer',
|
|
47
|
+
description: `Extra raw events to include after the step (0-50, default 0).`,
|
|
48
|
+
},
|
|
49
|
+
requests: {
|
|
50
|
+
type: 'boolean',
|
|
51
|
+
description: 'Include request/header snapshots (the full system prompt and tool schemas). Default false.',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
output: {
|
|
55
|
+
schema: { type: 'string' },
|
|
56
|
+
render: (_args, value) => [{ type: 'text', text: value }],
|
|
57
|
+
},
|
|
58
|
+
isConcurrencySafe: () => true,
|
|
59
|
+
timeoutMs: STEP_READ_TIMEOUT_MS,
|
|
60
|
+
async execute(args, exec) {
|
|
61
|
+
const sessionQuery = getSessionQuery();
|
|
62
|
+
const payload = await readStepReference(
|
|
63
|
+
sessionQuery,
|
|
64
|
+
args.ref,
|
|
65
|
+
{ before: args.before, after: args.after, requests: args.requests === true },
|
|
66
|
+
exec?.signal,
|
|
67
|
+
);
|
|
68
|
+
return JSON.stringify(payload, null, 2);
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Power-Up",
|
|
4
|
-
"description": "Adds a right-click action menu to the Trajectory ledger: copy a record, copy a Markdown quote, quote it into the composer, open the record inspector, fork the session at that record, export the trajectory snapshot, and copy the session ID. The session header
|
|
4
|
+
"description": "Adds a right-click action menu to the Trajectory ledger: copy a record, copy a Markdown quote, quote it into the composer, open the record inspector, fork the session at that record, copy a step reference (session id + step id) that the read-only powerup_step_read tool resolves back into the raw session data, export the trajectory snapshot, and copy the session ID. The session header background jobs panel gains an optional stop reason when a job is stopped by hand; the reason is appended to the completion notice injected into the session. The Plugins page gains an install control on every third-party installed plugin: read versions from the registry, install the version in the input through the Add plugin path (removing the old copy first), then enable and optionally restart DSH. The install panel also offers a one-click install that installs the input version without the enable and restart questions, enabling and restarting automatically by default; both defaults are configurable on the Power-Up page."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Power-Up",
|
|
4
|
-
"description": "在轨迹页面为记录增加右键操作菜单:复制内容、复制 Markdown 引用、引用到输入框、查看记录详情、从该记录 Fork
|
|
4
|
+
"description": "在轨迹页面为记录增加右键操作菜单:复制内容、复制 Markdown 引用、引用到输入框、查看记录详情、从该记录 Fork 会话、复制「会话 ID + 步骤 ID」的步骤引用(Agent 用只读工具 powerup_step_read 取回该步骤完整数据)、导出轨迹快照、复制会话 ID。在会话顶部的后台任务面板手动停止任务时可以填写停止原因,原因会附加在任务结束后注入会话的提示里。插件页为每个第三方已安装插件增加安装按钮:从安装源读取版本,按输入框中的版本先卸载旧版再按「添加插件」流程安装,完成后可立即启用并选择是否重启 DSH。安装面板还提供「一键安装」:按输入框版本安装并跳过启用与重启的询问,默认自动启用并重启,可在 Power-Up 页面调整默认行为。"
|
|
5
5
|
}
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@restregular/dsh-powerup",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Power-Up — small, opt-in upgrades for DeepSeek Harness. Adds a right-click action menu to the Trajectory ledger, an optional stop reason in the session header's background jobs panel (appended to the injected completion notice), and an install control for third-party plugins from the Plugins page: read versions from the configured registries, install the version in the input through the Add plugin path (removing the old copy first), mark restart-needed installs, hand Power-Up's own install to the background, and optionally restart DSH. One-click install skips the enable and restart questions and can apply those actions automatically with configurable defaults. · 为 DeepSeek Harness 提供小型增强:在轨迹页面右键记录即可复制、引用、查看详情或从该记录 Fork
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "Power-Up — small, opt-in upgrades for DeepSeek Harness. Adds a right-click action menu to the Trajectory ledger, an optional stop reason in the session header's background jobs panel (appended to the injected completion notice), and an install control for third-party plugins from the Plugins page: read versions from the configured registries, install the version in the input through the Add plugin path (removing the old copy first), mark restart-needed installs, hand Power-Up's own install to the background, and optionally restart DSH. One-click install skips the enable and restart questions and can apply those actions automatically with configurable defaults. The ledger menu also copies a step reference (session id + step id) that the read-only powerup_step_read tool resolves back into the raw session data. · 为 DeepSeek Harness 提供小型增强:在轨迹页面右键记录即可复制、引用、查看详情或从该记录 Fork;右键「复制步骤引用」得到「会话 ID + 步骤 ID」,Agent 用只读工具 powerup_step_read 即可取回该步骤的完整原始数据;在会话顶部的后台任务面板手动停止任务时可填写停止原因,原因会附加到任务结束后的会话提示;并在插件页为第三方已安装插件提供安装按钮,从安装源读取版本,按输入框中的版本沿用「添加插件」流程安装(先卸载旧版),支持待重启标记、Power-Up 自身后台安装与可选重启;安装面板提供「一键安装」,按输入框版本安装并跳过启用/重启询问,默认自动启用并重启,可在 Power-Up 页面调整默认行为。",
|
|
5
5
|
"icon": "./icon.svg",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "index.js",
|
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
"cordis.patch.yml",
|
|
20
20
|
"lib/restart.js",
|
|
21
21
|
"lib/restart-helper.cjs",
|
|
22
|
+
"lib/step-reference.js",
|
|
23
|
+
"lib/step-tool.js",
|
|
22
24
|
"locale/*.json",
|
|
23
25
|
"icon.svg",
|
|
24
26
|
"README.md",
|
|
@@ -41,6 +43,18 @@
|
|
|
41
43
|
]
|
|
42
44
|
}
|
|
43
45
|
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@deepseek-ai/cordis": "*",
|
|
48
|
+
"@deepseek-ai/dsh-tools": "*"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"@deepseek-ai/cordis": {
|
|
52
|
+
"optional": true
|
|
53
|
+
},
|
|
54
|
+
"@deepseek-ai/dsh-tools": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
44
58
|
"repository": {
|
|
45
59
|
"type": "git",
|
|
46
60
|
"url": "git+https://github.com/RestRegular/dsh-powerup.git"
|
|
@@ -55,6 +69,7 @@
|
|
|
55
69
|
"deepseek",
|
|
56
70
|
"trajectory",
|
|
57
71
|
"context-menu",
|
|
72
|
+
"step-reference",
|
|
58
73
|
"background-jobs",
|
|
59
74
|
"job-control",
|
|
60
75
|
"power-up"
|
|
@@ -67,7 +82,7 @@
|
|
|
67
82
|
"node": ">=22.13.0"
|
|
68
83
|
},
|
|
69
84
|
"scripts": {
|
|
70
|
-
"test": "node test/smoke.mjs"
|
|
85
|
+
"test": "node test/smoke.mjs && node test/host.mjs"
|
|
71
86
|
},
|
|
72
87
|
"license": "MIT",
|
|
73
88
|
"author": "RestRegular"
|