@lukstei/dsh-session-handoff 0.2.2-rc.5.8 → 0.2.2-rc.5.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 +16 -14
- package/dist/client.js +28 -4
- package/dist/index.js +56 -36
- package/package.json +9 -3
- package/src/client/index.ts +47 -4
- package/src/index.ts +67 -72
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Summary
|
|
4
4
|
|
|
5
|
-
Adds a `/handoff` command that turns a session log into a short resume brief.
|
|
5
|
+
Adds a `/handoff` command that turns a session log into a short resume brief. `/handoff` starts a new session beside the current one with the brief loaded, on the same model or on a model picked from a list.
|
|
6
6
|
|
|
7
7
|
## Table of Contents
|
|
8
8
|
|
|
@@ -40,25 +40,27 @@ Mount through the bundle patch ([`cordis.patch.yml`](cordis.patch.yml)) and add
|
|
|
40
40
|
|
|
41
41
|
Then `pnpm install` in the profile directory and restart the harness. No config fields.
|
|
42
42
|
|
|
43
|
-
Required Host services (`inject`): `commands`, `sessionQuery`, `workingDirectory`, `sessionController`, `sessionTitle`, `workspaceRegistry`. Workspace dependency: [`@lukstei/dsh-scratch-dir`](../dsh-scratch-dir/README.md) (`scratchDirectory()`).
|
|
43
|
+
Required Host services (`inject`): `commands`, `llm`, `sessionQuery`, `workingDirectory`, `sessionController`, `sessionTitle`, `workspaceRegistry`. Workspace dependency: [`@lukstei/dsh-scratch-dir`](../dsh-scratch-dir/README.md) (`scratchDirectory()`).
|
|
44
44
|
|
|
45
45
|
The client half needs `@deepseek-ai/dsh-api-session-controller` and [`@lukstei/dsh-client-split-view`](../dsh-client-split-view/README.md). Build it with `pnpm build` (emits `dist/client.js`); rebuild and restart after changing `src/client/`. The client bundle is marked `immediately` because no route lazily pulls it in; without stage-one prefetch its watcher would never register.
|
|
46
46
|
|
|
47
47
|
```text
|
|
48
48
|
/handoff
|
|
49
|
-
/handoff
|
|
50
|
-
/handoff 06542298-c989-417d-9ed4-fa5877768140
|
|
49
|
+
/handoff google/gemini-4
|
|
51
50
|
```
|
|
52
51
|
|
|
52
|
+
Typed in the composer, a bare `/handoff` opens the same provider-grouped model list as `/model`, with the current model highlighted; picking a row starts the new session on that model with the brief loaded. The argued form (`<provider>/<model>`, split at the first slash) skips the list. The Host checks the route against the registered LLM providers and the provider's own model resolution, so a typo returns an error before any session is created. Because it creates a new session, it also works across native and ACP models, where an in-place model switch is blocked. Reasoning effort is the model's default. The handoff ring sends the bare line straight to the Host, which keeps the source's model and skips the list. The client half also needs `@deepseek-ai/dsh-client-ui-commands` and `@deepseek-ai/dsh-client-ui-model-selection`.
|
|
53
|
+
|
|
53
54
|
### Plugin dependencies
|
|
54
55
|
|
|
55
56
|
Server-side and client-side entries.
|
|
56
57
|
|
|
57
|
-
**Server-side** (`inject`: `commands`, `sessionQuery`, `workingDirectory`, `sessionController`, `sessionTitle`, `workspaceRegistry`):
|
|
58
|
+
**Server-side** (`inject`: `commands`, `llm`, `sessionQuery`, `workingDirectory`, `sessionController`, `sessionTitle`, `workspaceRegistry`):
|
|
58
59
|
|
|
59
60
|
| Plugin / service | Required? | Provided by | Effect without it |
|
|
60
61
|
|---|---|---|---|
|
|
61
62
|
| `commands` | Required | @deepseek-ai/dsh-commands | Plugin stays pending; never applies. No `/handoff`. |
|
|
63
|
+
| `llm` | Required | @deepseek-ai/dsh-llm | Plugin stays pending; never applies. |
|
|
62
64
|
| `sessionQuery` | Required | @deepseek-ai/dsh-session-query | Plugin stays pending; never applies. |
|
|
63
65
|
| `workingDirectory` | Required | @deepseek-ai/dsh-working-directory | Plugin stays pending; never applies. |
|
|
64
66
|
| `sessionController` | Required | @deepseek-ai/dsh-api-session-controller | Plugin stays pending; never applies. |
|
|
@@ -84,18 +86,18 @@ Used by: nothing.
|
|
|
84
86
|
|
|
85
87
|
### Modes
|
|
86
88
|
|
|
87
|
-
| Input |
|
|
88
|
-
|
|
89
|
-
| `/handoff`
|
|
90
|
-
| `/handoff <
|
|
89
|
+
| Input | Model of the new session |
|
|
90
|
+
|---|---|
|
|
91
|
+
| `/handoff` (Host, e.g. from the ring) | the source's own |
|
|
92
|
+
| `/handoff <provider>/<model>` | that model, validated first |
|
|
91
93
|
|
|
92
|
-
|
|
94
|
+
Any other argument is an error naming the expected form. A session with no turns returns an error. All I/O failures return `{ kind: "error" }`.
|
|
93
95
|
|
|
94
|
-
###
|
|
96
|
+
### Launch
|
|
95
97
|
|
|
96
98
|
1. Renders this session's brief.
|
|
97
99
|
2. Creates a session via `sessionController.create()` in the current workspace (falls back to `cwd` when the session has no workspace), same `agentPreset`.
|
|
98
|
-
3.
|
|
100
|
+
3. Selects the requested model on the new agent, or replays the source's own selection.
|
|
99
101
|
4. Titles it with the full source title (or `Handoff <first 8 id chars>` when untitled) and renames the source to `<title> (Resumed)` unless it already ends with that. A user title pins it against auto-generated titles. Adds a Kanban link `Resumed from <source id>` (`dsh://sessions/<id>`, opens the source session) to record the origin.
|
|
100
102
|
5. Runs `/kanban {"action":"init","createdAt":…}` against the new agent so it appears on the Kanban board. No `prompt` is sent, since that would seed the composer draft with the follow-up text.
|
|
101
103
|
6. Copies the source session's kanban links by replaying its `add-link` commands against the new agent.
|
|
@@ -128,14 +130,14 @@ Empty sections render `none`. Output is deterministic for a given log. `request/
|
|
|
128
130
|
|
|
129
131
|
Files:
|
|
130
132
|
|
|
131
|
-
- [`src/index.ts`](src/index.ts): command registration,
|
|
133
|
+
- [`src/index.ts`](src/index.ts): command registration, model validation, `deliver` (write brief + queue follow-up), `createBeside` (launch).
|
|
132
134
|
- [`src/handoff.ts`](src/handoff.ts): `renderHandoff` and `handoffInstruction`, pure.
|
|
133
135
|
- [`src/launch.ts`](src/launch.ts): `LAUNCH_PREFIX`, `formatLaunchResult`, `launchedSessionId`.
|
|
134
136
|
- [`src/client/index.ts`](src/client/index.ts): client watcher. Tests sit beside each file.
|
|
135
137
|
|
|
136
138
|
Details:
|
|
137
139
|
|
|
138
|
-
- The command declares `input: { hint: "[
|
|
140
|
+
- The command declares `input: { hint: "[provider/model]" }`. Without a declared input the client sends the raw line to the model as a prompt and the handler never runs.
|
|
139
141
|
- A slash command has no structured return channel to the client, so the Host encodes the new id in the command result text, which is persisted in the `command/done` event. The client subscribes to every open session's event source and calls `ctx.splitView.replaceSession()` when it sees a successful `command/done` starting with `Handoff launched: `, replacing the pane in-place atomically. It then sends `/kanban {"action":"done"}` to the source session, as the Kanban Done button does. A source never initialised in Kanban ignores the done action.
|
|
140
142
|
- The pane is added through the split store, not `uiWorkspace.openSession()`. The split view patches that method into a read-only overlay without its own composer, so prompts would keep landing in the pane underneath.
|
|
141
143
|
- The client reacts only to `append` changes. A `replace` replays the whole window on first open and after reconnect gaps and would reopen panes the user closed; the split view restores its panes from local storage.
|
package/dist/client.js
CHANGED
|
@@ -131,7 +131,9 @@ window.__ModuleLoader__.load({
|
|
|
131
131
|
const inject = [
|
|
132
132
|
"sessions",
|
|
133
133
|
"splitView",
|
|
134
|
-
"slots"
|
|
134
|
+
"slots",
|
|
135
|
+
"commandUi",
|
|
136
|
+
"modelDirectories"
|
|
135
137
|
];
|
|
136
138
|
/**
|
|
137
139
|
* Open every session the Host reports as launched as a pane of its own. A slash
|
|
@@ -155,12 +157,34 @@ window.__ModuleLoader__.load({
|
|
|
155
157
|
})}`);
|
|
156
158
|
});
|
|
157
159
|
};
|
|
158
|
-
const
|
|
160
|
+
const run = async (id, line) => {
|
|
159
161
|
await sessions.using(id, { source: "splitView" }, async (reference) => {
|
|
160
|
-
const result = await reference.binding.session.command(
|
|
161
|
-
if (!result.ok) console.warn(
|
|
162
|
+
const result = await reference.binding.session.command(line);
|
|
163
|
+
if (!result.ok) console.warn(`session-handoff: ${line} failed`, result);
|
|
162
164
|
});
|
|
163
165
|
};
|
|
166
|
+
const handoff = (id) => run(id, "/handoff");
|
|
167
|
+
ctx.effect(() => ctx.commandUi.decorate({
|
|
168
|
+
name: "handoff",
|
|
169
|
+
available: () => true,
|
|
170
|
+
ui: {
|
|
171
|
+
kind: "popupSelect",
|
|
172
|
+
searchMode: "fuzzy-label",
|
|
173
|
+
options: async (session) => {
|
|
174
|
+
const state = await ctx.modelDirectories.directoryFor(session.sessionId).load();
|
|
175
|
+
return state.groups.flatMap((group) => group.models.map((model) => ({
|
|
176
|
+
id: `${group.id}/${model.id}`,
|
|
177
|
+
label: model.name,
|
|
178
|
+
group: {
|
|
179
|
+
name: group.id,
|
|
180
|
+
label: group.name
|
|
181
|
+
},
|
|
182
|
+
...state.current !== null && state.current.provider === group.id && state.current.model === model.id ? { active: true } : {}
|
|
183
|
+
})));
|
|
184
|
+
},
|
|
185
|
+
onSelect: (option, session) => run(session.sessionId, `/handoff ${option.id}`)
|
|
186
|
+
}
|
|
187
|
+
}), "session-handoff: /handoff picker");
|
|
164
188
|
const watch = (id) => {
|
|
165
189
|
const binding = sessions.binding(id);
|
|
166
190
|
if (binding === void 0) return;
|
package/dist/index.js
CHANGED
|
@@ -260,63 +260,82 @@ const inject = [
|
|
|
260
260
|
"workingDirectory",
|
|
261
261
|
"sessionController",
|
|
262
262
|
"sessionTitle",
|
|
263
|
-
"workspaceRegistry"
|
|
263
|
+
"workspaceRegistry",
|
|
264
|
+
"llm"
|
|
264
265
|
];
|
|
265
266
|
const HANDOFF_FILE = "HANDOFF.md";
|
|
266
|
-
const RECENT_LIMIT = 5;
|
|
267
267
|
const SHORT_ID_LENGTH = 8;
|
|
268
268
|
const RESUMED_SUFFIX = " (Resumed)";
|
|
269
269
|
function apply(ctx) {
|
|
270
270
|
ctx.commands.register({
|
|
271
271
|
name: "handoff",
|
|
272
|
-
description: "Hand this session off to a new one
|
|
273
|
-
input: { hint: "[
|
|
272
|
+
description: "Hand this session off to a new one (bare: pick the model from a list)",
|
|
273
|
+
input: { hint: "[provider/model]" },
|
|
274
274
|
handler: (invocation) => handoff(ctx, invocation)
|
|
275
275
|
});
|
|
276
276
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
277
|
+
/**
|
|
278
|
+
* Split `provider/model` at the first slash: provider ids have none, model ids may.
|
|
279
|
+
* @internal exported for the unit test only.
|
|
280
|
+
*/
|
|
281
|
+
function parseModelArg(raw) {
|
|
282
|
+
const text = raw.trim();
|
|
283
|
+
const slash = text.indexOf("/");
|
|
284
|
+
if (slash <= 0 || slash === text.length - 1) return void 0;
|
|
285
|
+
return {
|
|
286
|
+
provider: text.slice(0, slash),
|
|
287
|
+
model: text.slice(slash + 1)
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Check the route against the registered providers and the provider's own model
|
|
292
|
+
* resolution, the same check subagent routes get, so a typo fails here and not
|
|
293
|
+
* on the new session's first turn.
|
|
294
|
+
* @returns an error text, or `undefined` when the route resolves.
|
|
295
|
+
*/
|
|
296
|
+
async function modelError(ctx, model, signal) {
|
|
297
|
+
try {
|
|
298
|
+
const providers = ctx.llm.listProviders();
|
|
299
|
+
if (!providers.some((provider) => provider.id === model.provider)) {
|
|
300
|
+
const available = providers.map((provider) => provider.id).join(", ");
|
|
301
|
+
return `LLM provider '${model.provider}' is not registered; available providers: ${available || "(none)"}`;
|
|
302
|
+
}
|
|
303
|
+
await ctx.llm.resolveCallConfig({
|
|
304
|
+
provider: model.provider,
|
|
305
|
+
model: model.model
|
|
306
|
+
}, signal);
|
|
307
|
+
return;
|
|
308
|
+
} catch (error) {
|
|
309
|
+
return error instanceof Error ? error.message : String(error);
|
|
310
|
+
}
|
|
281
311
|
}
|
|
282
312
|
async function handoff(ctx, invocation) {
|
|
283
313
|
const raw = invocation.rawInput.trim();
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
else {
|
|
289
|
-
const sessions = await ctx.sessionQuery.listSessions(invocation.signal);
|
|
290
|
-
const matches = resolveHandoffTarget(sessions, raw);
|
|
291
|
-
if (matches.length === 0) return {
|
|
314
|
+
let model;
|
|
315
|
+
if (raw !== "") {
|
|
316
|
+
model = parseModelArg(raw);
|
|
317
|
+
if (model === void 0) return {
|
|
292
318
|
kind: "error",
|
|
293
|
-
text: `
|
|
319
|
+
text: `Expected "<provider>/<model>", got "${raw}"; run bare /handoff to pick one.`
|
|
294
320
|
};
|
|
295
|
-
|
|
321
|
+
const invalid = await modelError(ctx, model, invocation.signal);
|
|
322
|
+
if (invalid !== void 0) return {
|
|
296
323
|
kind: "error",
|
|
297
|
-
text:
|
|
298
|
-
};
|
|
299
|
-
targetId = matches[0].header.id;
|
|
300
|
-
if (targetId === agent.session.id) return {
|
|
301
|
-
kind: "error",
|
|
302
|
-
text: "That is this session; there is nothing to hand off."
|
|
324
|
+
text: invalid
|
|
303
325
|
};
|
|
304
326
|
}
|
|
327
|
+
const agent = invocation.agent;
|
|
328
|
+
const targetId = agent.session.id;
|
|
305
329
|
try {
|
|
306
330
|
const snapshot = await ctx.sessionQuery.readSession(targetId);
|
|
307
331
|
const rendered = renderHandoff(await readChain(ctx, snapshot, invocation.signal));
|
|
308
332
|
if (rendered.turns === 0) return {
|
|
309
333
|
kind: "error",
|
|
310
|
-
text:
|
|
311
|
-
};
|
|
312
|
-
if (launch) return {
|
|
313
|
-
kind: "success",
|
|
314
|
-
text: formatLaunchResult((await createBeside(ctx, agent, targetId, rendered.markdown, snapshot, invocation.signal)).sessionId)
|
|
334
|
+
text: "This session has no turns to hand off."
|
|
315
335
|
};
|
|
316
|
-
const file = await deliver(ctx, agent, targetId, rendered.markdown);
|
|
317
336
|
return {
|
|
318
337
|
kind: "success",
|
|
319
|
-
text:
|
|
338
|
+
text: formatLaunchResult((await createBeside(ctx, agent, targetId, rendered.markdown, snapshot, invocation.signal, model)).sessionId)
|
|
320
339
|
};
|
|
321
340
|
} catch (error) {
|
|
322
341
|
return {
|
|
@@ -387,8 +406,8 @@ function shortId(id) {
|
|
|
387
406
|
return id.slice(0, SHORT_ID_LENGTH);
|
|
388
407
|
}
|
|
389
408
|
/**
|
|
390
|
-
* Create the resumed session beside this one: same workspace, same preset,
|
|
391
|
-
* model, the brief in its own scratch directory, and one follow-up turn that
|
|
409
|
+
* Create the resumed session beside this one: same workspace, same preset, the
|
|
410
|
+
* source's model or the given one, the brief in its own scratch directory, and one follow-up turn that
|
|
392
411
|
* tells it to read that brief.
|
|
393
412
|
* @param ctx - Host context.
|
|
394
413
|
* @param source - Session the command runs in.
|
|
@@ -396,10 +415,11 @@ function shortId(id) {
|
|
|
396
415
|
* @param markdown - Rendered brief.
|
|
397
416
|
* @param snapshot - Source session log, the origin of the kanban links to copy.
|
|
398
417
|
* @param signal - Cancellation signal of the invoking command.
|
|
418
|
+
* @param model - Model the new session starts on; the source's own when absent.
|
|
399
419
|
* @returns the created session identity.
|
|
400
420
|
*/
|
|
401
|
-
async function createBeside(ctx, source, targetId, markdown, snapshot, signal) {
|
|
402
|
-
const selection = source.model.current();
|
|
421
|
+
async function createBeside(ctx, source, targetId, markdown, snapshot, signal, model) {
|
|
422
|
+
const selection = model === void 0 ? source.model.current() : model;
|
|
403
423
|
const agentPreset = source.session.header.agentPreset;
|
|
404
424
|
const workspace = workspaceOf(ctx, source.session.id);
|
|
405
425
|
const created = await ctx.sessionController.create(workspace === void 0 ? {
|
|
@@ -431,4 +451,4 @@ async function createBeside(ctx, source, targetId, markdown, snapshot, signal) {
|
|
|
431
451
|
await deliver(ctx, agent, targetId, markdown);
|
|
432
452
|
return created;
|
|
433
453
|
}
|
|
434
|
-
export { apply, inject, name,
|
|
454
|
+
export { apply, inject, name, parseModelArg };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lukstei/dsh-session-handoff",
|
|
3
|
-
"version": "0.2.2-rc.5.
|
|
3
|
+
"version": "0.2.2-rc.5.9",
|
|
4
4
|
"description": "Session handoff brief command for DSH",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -36,19 +36,23 @@
|
|
|
36
36
|
"inject": [
|
|
37
37
|
"@deepseek-ai/dsh-api-session-controller",
|
|
38
38
|
"@lukstei/dsh-client-split-view",
|
|
39
|
+
"@deepseek-ai/dsh-client-ui-commands",
|
|
39
40
|
"@deepseek-ai/dsh-client-ui-conversation",
|
|
41
|
+
"@deepseek-ai/dsh-client-ui-model-selection",
|
|
40
42
|
"@deepseek-ai/dsh-client-ui-renderer"
|
|
41
43
|
]
|
|
42
44
|
}
|
|
43
45
|
},
|
|
44
46
|
"dependencies": {
|
|
45
|
-
"@lukstei/dsh-scratch-dir": "0.2.2-rc.5.
|
|
47
|
+
"@lukstei/dsh-scratch-dir": "0.2.2-rc.5.9"
|
|
46
48
|
},
|
|
47
49
|
"peerDependencies": {
|
|
48
50
|
"@deepseek-ai/cordis": "*",
|
|
49
51
|
"@deepseek-ai/dsh-agent": "*",
|
|
50
52
|
"@deepseek-ai/dsh-api-session-controller": "*",
|
|
53
|
+
"@deepseek-ai/dsh-client-ui-commands": "*",
|
|
51
54
|
"@deepseek-ai/dsh-client-ui-conversation": "*",
|
|
55
|
+
"@deepseek-ai/dsh-client-ui-model-selection": "*",
|
|
52
56
|
"@deepseek-ai/dsh-client-ui-primitives": "*",
|
|
53
57
|
"@deepseek-ai/dsh-client-ui-renderer": "*",
|
|
54
58
|
"@deepseek-ai/dsh-client-ui-session": "*",
|
|
@@ -68,7 +72,9 @@
|
|
|
68
72
|
"@deepseek-ai/cordis": "4.1.0",
|
|
69
73
|
"@deepseek-ai/dsh-agent": "0.2.2-rc.5",
|
|
70
74
|
"@deepseek-ai/dsh-api-session-controller": "0.2.2-rc.5",
|
|
75
|
+
"@deepseek-ai/dsh-client-ui-commands": "0.2.2-rc.5",
|
|
71
76
|
"@deepseek-ai/dsh-client-ui-conversation": "0.2.2-rc.5",
|
|
77
|
+
"@deepseek-ai/dsh-client-ui-model-selection": "0.2.2-rc.5",
|
|
72
78
|
"@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.5",
|
|
73
79
|
"@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.5",
|
|
74
80
|
"@deepseek-ai/dsh-client-ui-session": "0.2.2-rc.5",
|
|
@@ -81,7 +87,7 @@
|
|
|
81
87
|
"@deepseek-ai/dsh-token-meter": "0.2.2-rc.5",
|
|
82
88
|
"@deepseek-ai/dsh-working-directory": "0.2.2-rc.5",
|
|
83
89
|
"@deepseek-ai/dsh-workspace": "0.2.2-rc.5",
|
|
84
|
-
"@lukstei/dsh-client-split-view": "0.2.2-rc.5.
|
|
90
|
+
"@lukstei/dsh-client-split-view": "0.2.2-rc.5.9",
|
|
85
91
|
"@types/node": "^26.0.0",
|
|
86
92
|
"@types/react": "^19.3.0",
|
|
87
93
|
"@zaimokuza/dsh-acp-adapter": "0.2.2-rc.5.2",
|
package/src/client/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Context } from "@deepseek-ai/cordis";
|
|
2
2
|
import type { ISessions } from "@deepseek-ai/dsh-api-session-controller/client";
|
|
3
|
+
import type {} from "@deepseek-ai/dsh-client-ui-commands/client";
|
|
3
4
|
import type {} from "@deepseek-ai/dsh-client-ui-conversation/client";
|
|
5
|
+
import type {} from "@deepseek-ai/dsh-client-ui-model-selection/client";
|
|
4
6
|
import type {} from "@deepseek-ai/dsh-client-ui-renderer/client";
|
|
5
7
|
import type { SessionId } from "@deepseek-ai/dsh-session/types";
|
|
6
8
|
import type {} from "@lukstei/dsh-client-split-view/client-contract";
|
|
@@ -9,7 +11,13 @@ import { launchedSessionId } from "../launch.ts";
|
|
|
9
11
|
import { type AcpUsageReader, setAcpUsageReader } from "./acp-usage.ts";
|
|
10
12
|
import { HandoffRing } from "./ring.ts";
|
|
11
13
|
|
|
12
|
-
export const inject = [
|
|
14
|
+
export const inject = [
|
|
15
|
+
"sessions",
|
|
16
|
+
"splitView",
|
|
17
|
+
"slots",
|
|
18
|
+
"commandUi",
|
|
19
|
+
"modelDirectories",
|
|
20
|
+
];
|
|
13
21
|
|
|
14
22
|
/**
|
|
15
23
|
* Open every session the Host reports as launched as a pane of its own. A slash
|
|
@@ -38,14 +46,49 @@ export function apply(ctx: Context): void {
|
|
|
38
46
|
};
|
|
39
47
|
|
|
40
48
|
// Same command the user would type; sent directly so the composer draft stays untouched.
|
|
41
|
-
const
|
|
49
|
+
const run = async (id: SessionId, line: string): Promise<void> => {
|
|
42
50
|
await sessions.using(id, { source: "splitView" }, async (reference) => {
|
|
43
|
-
const result = await reference.binding.session.command(
|
|
51
|
+
const result = await reference.binding.session.command(line);
|
|
44
52
|
if (!result.ok) {
|
|
45
|
-
console.warn(
|
|
53
|
+
console.warn(`session-handoff: ${line} failed`, result);
|
|
46
54
|
}
|
|
47
55
|
});
|
|
48
56
|
};
|
|
57
|
+
const handoff = (id: SessionId): Promise<void> => run(id, "/handoff");
|
|
58
|
+
|
|
59
|
+
// A bare composer `/handoff` opens the same model list as `/model`; the pick is
|
|
60
|
+
// submitted back as the argued line the Host command parses (the ring sends the bare line straight to the Host, which keeps the source model).
|
|
61
|
+
ctx.effect(
|
|
62
|
+
() =>
|
|
63
|
+
ctx.commandUi.decorate({
|
|
64
|
+
name: "handoff",
|
|
65
|
+
available: () => true,
|
|
66
|
+
ui: {
|
|
67
|
+
kind: "popupSelect",
|
|
68
|
+
searchMode: "fuzzy-label",
|
|
69
|
+
options: async (session) => {
|
|
70
|
+
const state = await ctx.modelDirectories
|
|
71
|
+
.directoryFor(session.sessionId)
|
|
72
|
+
.load();
|
|
73
|
+
return state.groups.flatMap((group) =>
|
|
74
|
+
group.models.map((model) => ({
|
|
75
|
+
id: `${group.id}/${model.id}`,
|
|
76
|
+
label: model.name,
|
|
77
|
+
group: { name: group.id, label: group.name },
|
|
78
|
+
...(state.current !== null &&
|
|
79
|
+
state.current.provider === group.id &&
|
|
80
|
+
state.current.model === model.id
|
|
81
|
+
? { active: true }
|
|
82
|
+
: {}),
|
|
83
|
+
})),
|
|
84
|
+
);
|
|
85
|
+
},
|
|
86
|
+
onSelect: (option, session) =>
|
|
87
|
+
run(session.sessionId, `/handoff ${option.id}`),
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
90
|
+
"session-handoff: /handoff picker",
|
|
91
|
+
);
|
|
49
92
|
|
|
50
93
|
const watch = (id: SessionId): void => {
|
|
51
94
|
const binding = sessions.binding(id);
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import type { Context } from "@deepseek-ai/cordis";
|
|
4
|
-
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
4
|
+
import type { Agent, ModelSelection } from "@deepseek-ai/dsh-agent";
|
|
5
5
|
import type { SessionCreateValue } from "@deepseek-ai/dsh-api-session-controller";
|
|
6
6
|
import type {
|
|
7
7
|
CommandInvocation,
|
|
@@ -10,10 +10,7 @@ import type {
|
|
|
10
10
|
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
11
11
|
import type {} from "@deepseek-ai/dsh-session";
|
|
12
12
|
import type { SessionId } from "@deepseek-ai/dsh-session/types";
|
|
13
|
-
import type {
|
|
14
|
-
SessionLogSnapshot,
|
|
15
|
-
SessionRecord,
|
|
16
|
-
} from "@deepseek-ai/dsh-session-query";
|
|
13
|
+
import type { SessionLogSnapshot } from "@deepseek-ai/dsh-session-query";
|
|
17
14
|
import type {} from "@deepseek-ai/dsh-session-title";
|
|
18
15
|
import type {} from "@deepseek-ai/dsh-working-directory";
|
|
19
16
|
import type { Workspace } from "@deepseek-ai/dsh-workspace";
|
|
@@ -33,10 +30,10 @@ export const inject = [
|
|
|
33
30
|
"sessionController",
|
|
34
31
|
"sessionTitle",
|
|
35
32
|
"workspaceRegistry",
|
|
33
|
+
"llm",
|
|
36
34
|
];
|
|
37
35
|
|
|
38
36
|
const HANDOFF_FILE = "HANDOFF.md";
|
|
39
|
-
const RECENT_LIMIT = 5;
|
|
40
37
|
const SHORT_ID_LENGTH = 8;
|
|
41
38
|
const RESUMED_SUFFIX = " (Resumed)";
|
|
42
39
|
|
|
@@ -44,26 +41,51 @@ export function apply(ctx: Context): void {
|
|
|
44
41
|
ctx.commands.register({
|
|
45
42
|
name: "handoff",
|
|
46
43
|
description:
|
|
47
|
-
"Hand this session off to a new one
|
|
44
|
+
"Hand this session off to a new one (bare: pick the model from a list)",
|
|
48
45
|
// edge case: without a declared input the client sends the raw line to the
|
|
49
46
|
// model as a prompt and this handler never runs.
|
|
50
|
-
input: { hint: "[
|
|
47
|
+
input: { hint: "[provider/model]" },
|
|
51
48
|
handler: (invocation: CommandInvocation): Promise<CommandResult> =>
|
|
52
49
|
handoff(ctx, invocation),
|
|
53
50
|
});
|
|
54
51
|
}
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
);
|
|
63
|
-
if (
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Split `provider/model` at the first slash: provider ids have none, model ids may.
|
|
55
|
+
* @internal exported for the unit test only.
|
|
56
|
+
*/
|
|
57
|
+
export function parseModelArg(raw: string): ModelSelection | undefined {
|
|
58
|
+
const text = raw.trim();
|
|
59
|
+
const slash = text.indexOf("/");
|
|
60
|
+
if (slash <= 0 || slash === text.length - 1) return undefined;
|
|
61
|
+
return { provider: text.slice(0, slash), model: text.slice(slash + 1) };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Check the route against the registered providers and the provider's own model
|
|
66
|
+
* resolution, the same check subagent routes get, so a typo fails here and not
|
|
67
|
+
* on the new session's first turn.
|
|
68
|
+
* @returns an error text, or `undefined` when the route resolves.
|
|
69
|
+
*/
|
|
70
|
+
async function modelError(
|
|
71
|
+
ctx: Context,
|
|
72
|
+
model: ModelSelection,
|
|
73
|
+
signal: AbortSignal,
|
|
74
|
+
): Promise<string | undefined> {
|
|
75
|
+
try {
|
|
76
|
+
const providers = ctx.llm.listProviders();
|
|
77
|
+
if (!providers.some((provider) => provider.id === model.provider)) {
|
|
78
|
+
const available = providers.map((provider) => provider.id).join(", ");
|
|
79
|
+
return `LLM provider '${model.provider}' is not registered; available providers: ${available || "(none)"}`;
|
|
80
|
+
}
|
|
81
|
+
await ctx.llm.resolveCallConfig(
|
|
82
|
+
{ provider: model.provider, model: model.model },
|
|
83
|
+
signal,
|
|
84
|
+
);
|
|
85
|
+
return undefined;
|
|
86
|
+
} catch (error: unknown) {
|
|
87
|
+
return error instanceof Error ? error.message : String(error);
|
|
88
|
+
}
|
|
67
89
|
}
|
|
68
90
|
|
|
69
91
|
async function handoff(
|
|
@@ -71,41 +93,21 @@ async function handoff(
|
|
|
71
93
|
invocation: CommandInvocation,
|
|
72
94
|
): Promise<CommandResult> {
|
|
73
95
|
const raw = invocation.rawInput.trim();
|
|
74
|
-
// edge case: no
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
let targetId: SessionId;
|
|
80
|
-
if (launch) {
|
|
81
|
-
targetId = agent.session.id;
|
|
82
|
-
} else {
|
|
83
|
-
const sessions = await ctx.sessionQuery.listSessions(invocation.signal);
|
|
84
|
-
const matches = resolveHandoffTarget(sessions, raw);
|
|
85
|
-
if (matches.length === 0) {
|
|
86
|
-
const recent = sessions
|
|
87
|
-
.slice(0, RECENT_LIMIT)
|
|
88
|
-
.map((session) => `- ${String(session.header.id)}`)
|
|
89
|
-
.join("\n");
|
|
90
|
-
return {
|
|
91
|
-
kind: "error",
|
|
92
|
-
text: `No session matches "${raw}". Most recent sessions:\n${recent}`,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
if (matches.length > 1) {
|
|
96
|
-
const candidates = matches
|
|
97
|
-
.map((session) => `- ${String(session.header.id)}`)
|
|
98
|
-
.join("\n");
|
|
99
|
-
return { kind: "error", text: `"${raw}" is ambiguous:\n${candidates}` };
|
|
100
|
-
}
|
|
101
|
-
targetId = matches[0].header.id;
|
|
102
|
-
if (targetId === agent.session.id) {
|
|
96
|
+
// edge case: no argument keeps the source's own model, the ring's path.
|
|
97
|
+
let model: ModelSelection | undefined;
|
|
98
|
+
if (raw !== "") {
|
|
99
|
+
model = parseModelArg(raw);
|
|
100
|
+
if (model === undefined) {
|
|
103
101
|
return {
|
|
104
102
|
kind: "error",
|
|
105
|
-
text: "
|
|
103
|
+
text: `Expected "<provider>/<model>", got "${raw}"; run bare /handoff to pick one.`,
|
|
106
104
|
};
|
|
107
105
|
}
|
|
106
|
+
const invalid = await modelError(ctx, model, invocation.signal);
|
|
107
|
+
if (invalid !== undefined) return { kind: "error", text: invalid };
|
|
108
108
|
}
|
|
109
|
+
const agent = invocation.agent;
|
|
110
|
+
const targetId = agent.session.id;
|
|
109
111
|
|
|
110
112
|
try {
|
|
111
113
|
const snapshot = await ctx.sessionQuery.readSession(targetId);
|
|
@@ -115,30 +117,21 @@ async function handoff(
|
|
|
115
117
|
if (rendered.turns === 0) {
|
|
116
118
|
return {
|
|
117
119
|
kind: "error",
|
|
118
|
-
text:
|
|
119
|
-
? "This session has no turns to hand off."
|
|
120
|
-
: `Session ${shortId(targetId)} has no turns to hand off.`,
|
|
120
|
+
text: "This session has no turns to hand off.",
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return {
|
|
133
|
-
kind: "success",
|
|
134
|
-
text: formatLaunchResult(created.sessionId),
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const file = await deliver(ctx, agent, targetId, rendered.markdown);
|
|
123
|
+
const created = await createBeside(
|
|
124
|
+
ctx,
|
|
125
|
+
agent,
|
|
126
|
+
targetId,
|
|
127
|
+
rendered.markdown,
|
|
128
|
+
snapshot,
|
|
129
|
+
invocation.signal,
|
|
130
|
+
model,
|
|
131
|
+
);
|
|
139
132
|
return {
|
|
140
133
|
kind: "success",
|
|
141
|
-
text:
|
|
134
|
+
text: formatLaunchResult(created.sessionId),
|
|
142
135
|
};
|
|
143
136
|
} catch (error: unknown) {
|
|
144
137
|
return {
|
|
@@ -255,8 +248,8 @@ function shortId(id: string): string {
|
|
|
255
248
|
}
|
|
256
249
|
|
|
257
250
|
/**
|
|
258
|
-
* Create the resumed session beside this one: same workspace, same preset,
|
|
259
|
-
* model, the brief in its own scratch directory, and one follow-up turn that
|
|
251
|
+
* Create the resumed session beside this one: same workspace, same preset, the
|
|
252
|
+
* source's model or the given one, the brief in its own scratch directory, and one follow-up turn that
|
|
260
253
|
* tells it to read that brief.
|
|
261
254
|
* @param ctx - Host context.
|
|
262
255
|
* @param source - Session the command runs in.
|
|
@@ -264,6 +257,7 @@ function shortId(id: string): string {
|
|
|
264
257
|
* @param markdown - Rendered brief.
|
|
265
258
|
* @param snapshot - Source session log, the origin of the kanban links to copy.
|
|
266
259
|
* @param signal - Cancellation signal of the invoking command.
|
|
260
|
+
* @param model - Model the new session starts on; the source's own when absent.
|
|
267
261
|
* @returns the created session identity.
|
|
268
262
|
*/
|
|
269
263
|
async function createBeside(
|
|
@@ -273,8 +267,9 @@ async function createBeside(
|
|
|
273
267
|
markdown: string,
|
|
274
268
|
snapshot: SessionLogSnapshot,
|
|
275
269
|
signal: AbortSignal,
|
|
270
|
+
model: ModelSelection | undefined,
|
|
276
271
|
): Promise<SessionCreateValue> {
|
|
277
|
-
const selection = source.model.current();
|
|
272
|
+
const selection = model === undefined ? source.model.current() : model;
|
|
278
273
|
const agentPreset = source.session.header.agentPreset;
|
|
279
274
|
// edge case: a session created by cwd alone is attached to no workspace, so it
|
|
280
275
|
// would stay out of the sidebar tree until the next Host start.
|