@lukstei/dsh-session-handoff 0.2.2-rc.5.7 → 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 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. Bare `/handoff` starts a new session beside the current one with the brief loaded; `/handoff <session-id>` writes another session's brief into the current session.
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 06542298
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. |
@@ -76,7 +78,7 @@ Server-side and client-side entries.
76
78
 
77
79
  ### Handoff ring
78
80
 
79
- A small ring beside the send button marks a session worth handing off: yellow at 70k prompt tokens, red at 100k. After 5 idle minutes the prompt cache is cold and the bars drop to 40k and 70k. Both bars are also capped at 60% and 80% of the model's context window. For ACP agent sessions, which never report usage to DSH, it reads the agent's context usage from `@zaimokuza/dsh-acp-adapter` once per finished turn. The adapter is an optional peer dependency: without it the ring only covers regular DSH sessions. Display only; run `/handoff` yourself. Thresholds live in `src/client/level.ts`.
81
+ A small gauge button beside the send button marks a session worth handing off: yellow at 100k prompt tokens, red at 150k. After 5 idle minutes the prompt cache is cold and the bars drop to 70k and 100k. Both bars are also capped at 60% and 80% of the model's context window. For ACP agent sessions, which never report usage to DSH, it reads the agent's context usage from `@zaimokuza/dsh-acp-adapter` once per finished turn. The adapter is an optional peer dependency: without it the ring only covers regular DSH sessions. Clicking the button runs `/handoff` directly; it is disabled while a turn is running or a handoff is in flight. Thresholds live in `src/client/level.ts`.
80
82
 
81
83
  Code import (no mount): [`@lukstei/dsh-scratch-dir`](../dsh-scratch-dir/README.md) (`scratchDirectory`).
82
84
 
@@ -84,18 +86,18 @@ Used by: nothing.
84
86
 
85
87
  ### Modes
86
88
 
87
- | Input | Brief describes | Brief lands in | Then |
88
- |---|---|---|---|
89
- | `/handoff` | this session | scratch directory of a newly created session | New session opens as a split pane; the source is marked done in Kanban and its pane is closed. |
90
- | `/handoff <id-or-prefix>` | that session | `<cwd>/.agents/scratch/<current-session-id>/HANDOFF.md` | Current agent is told to read it. |
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
- Id resolution: exact id first, then unique prefix over `sessionQuery.listSessions()`. Unknown ids return an error listing the 5 most recent sessions; ambiguous prefixes list candidates. Passing the current session's id is an error. Any non-id text, including `launch`, is treated as an id. A session with no turns returns an error. All I/O failures return `{ kind: "error" }`.
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
- ### Bare `/handoff` launch
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. Replays the current model selection onto the new agent.
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.
@@ -108,11 +110,13 @@ The client opens the pane. Without the client bundle the session is created but
108
110
 
109
111
  | Section | Contents |
110
112
  | --- | --- |
111
- | Header | session id, cwd, creation time, event and turn counts |
112
- | `## Goal` | first user prompt, head 500 + tail 300 chars |
113
- | `## Turns` | one `### T<n> [end reason]` block per turn: ask and final reply. Last 5 turns quote each 1200 head + 400 tail chars; older turns flatten to the ask (500/300) and reply (240 chars) |
114
- | `## Failures` | every `tool/result` with `isError`: turn, tool name, reason (200 chars) |
115
- | `## Artifacts` | deduped paths from tool call arguments (`path`, `file_path`, `filePath`, `notebook_path`), max 12 |
113
+ | Header | session id, `chain` of ancestor ids (when handed off before), cwd, creation time, event and turn counts across the chain |
114
+ | `## Goal` | first real user prompt of the oldest ancestor, head 500 + tail 300 chars |
115
+ | `## Turns` | one `### T<n> [end reason]` block per turn, numbered across the chain, handoff turns skipped. Last 5 turns quote each 1200 head + 400 tail chars; the 30 before them flatten to the ask (500/300) and reply (240 chars); older ones collapse to `… N earlier turns omitted` |
116
+ | `## Failures` | newest 20 `tool/result` errors: turn, session id when from an ancestor, tool name, reason (200 chars), plus `… N older failures omitted` |
117
+ | `## Artifacts` | deduped paths from tool call arguments (`path`, `file_path`, `filePath`, `notebook_path`) across the chain, newest 100, plus `… N older paths omitted`; the brief files themselves are excluded |
118
+
119
+ Every section is bounded by entry count and per-line length (paths 300 chars, tool names 80), so a brief stays near 50k characters however many times a session is handed off.
116
120
 
117
121
  Empty sections render `none`. Output is deterministic for a given log. `request/header`, `agent/inbox/spliced` and reasoning blocks are excluded.
118
122
 
@@ -126,14 +130,14 @@ Empty sections render `none`. Output is deterministic for a given log. `request/
126
130
 
127
131
  Files:
128
132
 
129
- - [`src/index.ts`](src/index.ts): command registration, target resolution, `deliver` (write brief + queue follow-up), `createBeside` (launch).
133
+ - [`src/index.ts`](src/index.ts): command registration, model validation, `deliver` (write brief + queue follow-up), `createBeside` (launch).
130
134
  - [`src/handoff.ts`](src/handoff.ts): `renderHandoff` and `handoffInstruction`, pure.
131
135
  - [`src/launch.ts`](src/launch.ts): `LAUNCH_PREFIX`, `formatLaunchResult`, `launchedSessionId`.
132
136
  - [`src/client/index.ts`](src/client/index.ts): client watcher. Tests sit beside each file.
133
137
 
134
138
  Details:
135
139
 
136
- - The command declares `input: { hint: "[session-id]" }`. Without a declared input the client sends the raw line to the model as a prompt and the handler never runs.
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.
137
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.
138
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.
139
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.
@@ -141,6 +145,7 @@ Details:
141
145
  - A session created by `cwd` alone is attached to no workspace and stays out of the sidebar tree until the next Host start, so the workspace id is used when available.
142
146
  - Turn attribution: `user/message` carries no turn number, so it is attributed to the most recently opened turn.
143
147
  - Artifact extraction parses tool arguments as JSON; non-JSON payloads are ignored.
148
+ - Handoff chain: a handed-off session starts with the follow-up "The handoff brief for session <id> is at <file>." `readChain` follows that id back through `sessionQuery.readSession` (cycle-guarded; a deleted parent ends the walk) and `renderHandoff` merges the logs oldest first. The follow-up turn and the read of its brief file add no Goal, Turn or Artifact.
144
149
  - The scratch path comes from `scratchDirectory()`; an unsafe id throws and the command returns an error.
145
150
 
146
151
  Trust boundary: the session id argument and session log contents are untrusted text; output is markdown written under the scratch directory only.
package/dist/client.js CHANGED
@@ -65,6 +65,7 @@ window.__ModuleLoader__.load({
65
65
  const running = useSession((session) => session.running);
66
66
  const [acp, setAcp] = (0, react.useState)(void 0);
67
67
  const [cold, setCold] = (0, react.useState)(false);
68
+ const [pendingSession, setPendingSession] = (0, react.useState)(void 0);
68
69
  const readUsage = (0, react.useSyncExternalStore)(subscribeAcpUsageReader, currentAcpUsageReader);
69
70
  (0, react.useEffect)(() => {
70
71
  if (running || readUsage === void 0) return;
@@ -90,14 +91,31 @@ window.__ModuleLoader__.load({
90
91
  }, [tokens, running]);
91
92
  const level = handoffLevel(tokens, window, cold);
92
93
  if (level === "none" || tokens === void 0) return null;
93
- const label = `Context ${Math.round(tokens / 1e3)}k tokens: ${cold ? "cache is cold, a fresh session is cheaper now" : "consider a fresh session"}. Click to hand off (/handoff)`;
94
+ const k = Math.round(tokens / 1e3);
95
+ const pending = pendingSession === sessionId;
96
+ const isDisabled = running || pending;
97
+ const startHandoff = async () => {
98
+ if (isDisabled) return;
99
+ setPendingSession(sessionId);
100
+ try {
101
+ await onHandoff(sessionId);
102
+ } catch (error) {
103
+ console.error("session-handoff: handoff failed", error);
104
+ } finally {
105
+ setPendingSession((current) => current === sessionId ? void 0 : current);
106
+ }
107
+ };
108
+ const label = `Context ${k}k tokens: ${cold ? "cache is cold, a fresh session is cheaper now" : "consider a fresh session"}. ${pending ? "Handing off…" : running ? "Wait for the current turn to finish to hand off (/handoff)" : "Click to hand off (/handoff)"}`;
94
109
  return (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives.Tooltip, {
95
110
  label,
96
111
  side: "top",
97
112
  portal: true,
113
+ disabled: isDisabled,
98
114
  children: (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives.Button, {
99
115
  variant: "ghost",
100
116
  size: "sm",
117
+ disabled: isDisabled,
118
+ title: isDisabled ? label : void 0,
101
119
  "aria-label": label,
102
120
  style: {
103
121
  color: COLOR[level],
@@ -105,7 +123,7 @@ window.__ModuleLoader__.load({
105
123
  width: 28
106
124
  },
107
125
  icon: (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives.IconGaugeOutlineMedium, { size: 16 }),
108
- onClick: () => void onHandoff(sessionId)
126
+ onClick: () => void startHandoff()
109
127
  })
110
128
  });
111
129
  }
@@ -113,7 +131,9 @@ window.__ModuleLoader__.load({
113
131
  const inject = [
114
132
  "sessions",
115
133
  "splitView",
116
- "slots"
134
+ "slots",
135
+ "commandUi",
136
+ "modelDirectories"
117
137
  ];
118
138
  /**
119
139
  * Open every session the Host reports as launched as a pane of its own. A slash
@@ -137,11 +157,34 @@ window.__ModuleLoader__.load({
137
157
  })}`);
138
158
  });
139
159
  };
140
- const handoff = async (id) => {
160
+ const run = async (id, line) => {
141
161
  await sessions.using(id, { source: "splitView" }, async (reference) => {
142
- await reference.binding.session.command("/handoff");
162
+ const result = await reference.binding.session.command(line);
163
+ if (!result.ok) console.warn(`session-handoff: ${line} failed`, result);
143
164
  });
144
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");
145
188
  const watch = (id) => {
146
189
  const binding = sessions.binding(id);
147
190
  if (binding === void 0) return;