@lukstei/dsh-session-handoff 0.0.0-stage → 0.2.2-rc.5.11

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/dist/index.js ADDED
@@ -0,0 +1,463 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { createUserMessage } from "@deepseek-ai/dsh-llm";
4
+ import { scratchDirectory } from "@lukstei/dsh-scratch-dir";
5
+ // src/handoff.ts
6
+ /**
7
+ * Bounds on quoted text. The Goal and older turns quote a head and a tail of the user's
8
+ * ask; the last RECENT_TURNS use a larger budget so the receiving agent still reads the
9
+ * actual words.
10
+ */
11
+ const ASK_HEAD = 500;
12
+ const ASK_TAIL = 300;
13
+ const OUTCOME_LIMIT = 240;
14
+ const FAILURE_LIMIT = 200;
15
+ const PATH_LIMIT = 300;
16
+ const TOOL_NAME_LIMIT = 80;
17
+ const RECENT_TURNS = 5;
18
+ const RECENT_HEAD = 1200;
19
+ const RECENT_TAIL = 400;
20
+ /** The last turn is quoted in full up to this cap, split head/tail like the others. */
21
+ const LAST_HEAD = 15e3;
22
+ const LAST_TAIL = 5e3;
23
+ const FAILURE_MAX = 20;
24
+ const ARTIFACT_MAX = 100;
25
+ const SHORT_ID_LENGTH$1 = 8;
26
+ /** Tool argument keys that carry a durable file path. */
27
+ const PATH_KEYS = [
28
+ "path",
29
+ "file_path",
30
+ "filePath",
31
+ "notebook_path"
32
+ ];
33
+ /** The first line of every handoff follow-up; names the parent session and its brief. */
34
+ const INSTRUCTION_LINE = /^The handoff brief for session (\S+) is at (.+)\.$/;
35
+ /**
36
+ * Id of the session whose brief this session was started from, read from the
37
+ * handoff follow-up it received.
38
+ */
39
+ function parentSessionId(snapshot) {
40
+ for (const event of snapshot.events) {
41
+ if (event.type !== "user/message" || event.data.source.kind !== "user") continue;
42
+ const text = blockText(event.data.content);
43
+ if (text === "") continue;
44
+ const match = INSTRUCTION_LINE.exec(text.split("\n", 1)[0]);
45
+ return match === null ? void 0 : match[1];
46
+ }
47
+ }
48
+ /**
49
+ * Renders one brief for a handoff chain.
50
+ * @param snapshots - Session logs, oldest ancestor first, the handed-off session last.
51
+ */
52
+ function renderHandoff(snapshots) {
53
+ const turns = [];
54
+ const failures = [];
55
+ const artifacts = /* @__PURE__ */ new Map();
56
+ const briefFiles = /* @__PURE__ */ new Set();
57
+ let goal = "";
58
+ let eventCount = 0;
59
+ for (const snapshot of snapshots) {
60
+ const sessionId = String(snapshot.session.id);
61
+ const byId = /* @__PURE__ */ new Map();
62
+ const callNames = /* @__PURE__ */ new Map();
63
+ let open;
64
+ let sawUserMessage = false;
65
+ eventCount += snapshot.events.length;
66
+ for (const event of snapshot.events) switch (event.type) {
67
+ case "turn/start": {
68
+ const opened = {
69
+ turn: event.data.turn,
70
+ sessionId,
71
+ index: 0,
72
+ asks: [],
73
+ outcome: "",
74
+ reason: void 0,
75
+ isHandoff: false
76
+ };
77
+ turns.push(opened);
78
+ byId.set(event.data.turn, opened);
79
+ open = opened;
80
+ break;
81
+ }
82
+ case "user/message": {
83
+ if (event.data.source.kind !== "user") break;
84
+ const text = blockText(event.data.content);
85
+ if (text === "") break;
86
+ const instruction = sawUserMessage ? null : INSTRUCTION_LINE.exec(text.split("\n", 1)[0]);
87
+ sawUserMessage = true;
88
+ if (instruction !== null) {
89
+ briefFiles.add(instruction[2]);
90
+ if (open !== void 0) open.isHandoff = true;
91
+ break;
92
+ }
93
+ if (goal === "") goal = elide(flatten(text), ASK_HEAD, ASK_TAIL);
94
+ if (open !== void 0) open.asks.push(text);
95
+ break;
96
+ }
97
+ case "assistant/message": {
98
+ const arc = byId.get(event.data.turn);
99
+ if (arc === void 0) break;
100
+ arc.outcome = blockText(event.data.message.content);
101
+ break;
102
+ }
103
+ case "turn/end": {
104
+ const arc = byId.get(event.data.turn);
105
+ if (arc === void 0) break;
106
+ arc.reason = event.data.reason;
107
+ break;
108
+ }
109
+ case "tool/call": {
110
+ const arc = byId.get(event.data.turn);
111
+ callNames.set(event.data.callId, event.data.name);
112
+ if (arc === void 0 || arc.isHandoff) break;
113
+ collectArtifacts(event.data.arguments, artifacts, briefFiles);
114
+ break;
115
+ }
116
+ case "tool/result": {
117
+ const arc = byId.get(event.data.turn);
118
+ if (event.data.message.isError !== true || arc === void 0) break;
119
+ if (arc.isHandoff) break;
120
+ const callId = event.data.message.toolCallId;
121
+ const name = callNames.get(callId);
122
+ failures.push({
123
+ arc,
124
+ text: `tool \`${clip(name === void 0 ? callId : name, TOOL_NAME_LIMIT)}\`: ${clip(errorReason(event.data.error), FAILURE_LIMIT)}`
125
+ });
126
+ break;
127
+ }
128
+ }
129
+ }
130
+ const work = turns.filter((turn) => !turn.isHandoff);
131
+ work.forEach((turn, index) => {
132
+ turn.index = index + 1;
133
+ });
134
+ const current = snapshots[snapshots.length - 1];
135
+ const id = String(current.session.id);
136
+ const cwd = current.session.cwd;
137
+ return {
138
+ markdown: `${[
139
+ `# Handoff — ${id}`,
140
+ "",
141
+ `- session: \`${id}\``,
142
+ ...snapshots.length > 1 ? [`- chain: ${snapshots.map((snapshot) => `\`${shortId$1(String(snapshot.session.id))}\``).join(" → ")}`] : [],
143
+ `- cwd: \`${cwd === void 0 ? "unknown" : cwd}\``,
144
+ `- created: ${new Date(current.session.createdAt).toISOString()}`,
145
+ `- events: ${eventCount}`,
146
+ `- turns: ${work.length}`,
147
+ "",
148
+ "## Goal",
149
+ "",
150
+ goal === "" ? "none" : goal,
151
+ "",
152
+ "## Turns",
153
+ "",
154
+ work.length === 0 ? "none" : turnList(work),
155
+ "",
156
+ "## Failures",
157
+ "",
158
+ failures.length === 0 ? "none" : bounded(failures.map(({ arc, text }) => `- **T${arc.index}**${arc.sessionId === id ? "" : ` (${shortId$1(arc.sessionId)})`} ${text}`), FAILURE_MAX, "older failures"),
159
+ "",
160
+ "## Artifacts",
161
+ "",
162
+ artifacts.size === 0 ? "none" : bounded([...artifacts.keys()].map((file) => `- \`${file}\``), ARTIFACT_MAX, "older paths")
163
+ ].join("\n")}\n`,
164
+ turns: work.length
165
+ };
166
+ }
167
+ function handoffInstruction(sessionId, file) {
168
+ return [
169
+ `The handoff brief for session ${sessionId} is at ${file}.`,
170
+ "",
171
+ "Read that file now, then reply with three lines and stop:",
172
+ "Goal: <one line>",
173
+ "State: <one line>",
174
+ "Next: <one line>",
175
+ "",
176
+ "Do not start the work until the user confirms the next action."
177
+ ].join("\n");
178
+ }
179
+ /** The last turn in full, RECENT_TURNS before it at length, OLDER_TURNS before those flattened, the rest counted. */
180
+ function turnList(work) {
181
+ const kept = work.slice(-35);
182
+ const dropped = work.length - kept.length;
183
+ const blocks = kept.map((turn, index) => turnBlock(turn, index === kept.length - 1 ? "last" : index >= kept.length - RECENT_TURNS ? "recent" : "older"));
184
+ if (dropped > 0) blocks.unshift(`… ${dropped} earlier turns omitted`);
185
+ return blocks.join("\n\n");
186
+ }
187
+ /** Keeps the newest `max` lines, naming how many older ones were dropped. */
188
+ function bounded(lines, max, noun) {
189
+ const dropped = lines.length - max;
190
+ if (dropped <= 0) return lines.join("\n");
191
+ return [`- … ${dropped} ${noun} omitted`, ...lines.slice(-max)].join("\n");
192
+ }
193
+ function shortId$1(id) {
194
+ return id.slice(0, SHORT_ID_LENGTH$1);
195
+ }
196
+ /**
197
+ * The last turn quotes every user message and the reply in full, recent turns quote the first
198
+ * ask and the reply at length, older turns are flattened and short. Roles are labelled so an
199
+ * unanswered ask is never mistaken for a reply.
200
+ */
201
+ function turnBlock(turn, tier) {
202
+ const kind = turn.reason === void 0 ? "unfinished" : turn.reason.kind;
203
+ const quote = (text) => tier === "last" ? elide(text, LAST_HEAD, LAST_TAIL) : elide(text, RECENT_HEAD, RECENT_TAIL);
204
+ const user = (tier === "last" ? turn.asks : turn.asks.slice(0, 1)).map((ask) => tier === "older" ? `**User:** ${elide(flatten(ask), ASK_HEAD, ASK_TAIL)}` : `**User:**\n\n${quote(ask)}`);
205
+ const reply = turn.outcome.trim() === "" ? "**Assistant:** (no reply)" : tier === "older" ? `**Assistant:** ${clip(turn.outcome, OUTCOME_LIMIT)}` : `**Assistant:**\n\n${quote(turn.outcome)}`;
206
+ return `### T${turn.index} [${kind}]\n\n${[...user, reply].join("\n\n")}`;
207
+ }
208
+ function blockText(blocks) {
209
+ const parts = [];
210
+ for (const block of blocks) if (block.type === "text") parts.push(block.text);
211
+ return parts.join("\n");
212
+ }
213
+ /** Collapses whitespace so a quote fits on one line, then cuts it. */
214
+ function clip(value, limit) {
215
+ const flat = flatten(value);
216
+ if (flat.length <= limit) return flat;
217
+ return `${flat.slice(0, limit)} … [${flat.length - limit} chars omitted]`;
218
+ }
219
+ function flatten(value) {
220
+ return value.replace(/\s+/g, " ").trim();
221
+ }
222
+ /**
223
+ * Keeps `head` chars from the start and `tail` chars from the end, naming how much was
224
+ * dropped. Raw text is preserved so the Tail keeps the shape of code blocks and tables.
225
+ */
226
+ function elide(value, head, tail) {
227
+ const trimmed = value.trim();
228
+ if (trimmed.length <= head + tail) return trimmed;
229
+ const omitted = trimmed.length - head - tail;
230
+ return `${trimmed.slice(0, head)} … [${omitted} chars omitted] … ${trimmed.slice(-tail)}`;
231
+ }
232
+ function errorReason(error) {
233
+ if (error === void 0) return "failed";
234
+ if (error.reason === void 0) return error.code;
235
+ return error.reason;
236
+ }
237
+ function collectArtifacts(args, into, briefFiles) {
238
+ let parsed;
239
+ try {
240
+ parsed = JSON.parse(args);
241
+ } catch {
242
+ return;
243
+ }
244
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return;
245
+ const record = parsed;
246
+ for (const key of PATH_KEYS) {
247
+ const value = record[key];
248
+ if (typeof value !== "string" || value === "" || briefFiles.has(value)) continue;
249
+ const path = clip(value, PATH_LIMIT);
250
+ into.delete(path);
251
+ into.set(path, true);
252
+ }
253
+ }
254
+ // src/launch.ts
255
+ /**
256
+ * First line of the launch result. A slash command has no structured return
257
+ * channel, so the Host encodes the new Session id here and the client reads it
258
+ * back out of the durable `command/done` record.
259
+ */
260
+ const LAUNCH_PREFIX = "Handoff launched: ";
261
+ function formatLaunchResult(sessionId) {
262
+ return `${LAUNCH_PREFIX}${String(sessionId)}`;
263
+ }
264
+ // src/index.ts
265
+ const name = "session-handoff";
266
+ const inject = [
267
+ "commands",
268
+ "sessionQuery",
269
+ "workingDirectory",
270
+ "sessionController",
271
+ "sessionTitle",
272
+ "workspaceRegistry",
273
+ "llm"
274
+ ];
275
+ const HANDOFF_FILE = "HANDOFF.md";
276
+ const SHORT_ID_LENGTH = 8;
277
+ const RESUMED_SUFFIX = " (Resumed)";
278
+ function apply(ctx) {
279
+ ctx.commands.register({
280
+ name: "handoff",
281
+ description: "Hand this session off to a new one (bare: pick the model from a list)",
282
+ input: { hint: "[provider/model]" },
283
+ handler: (invocation) => handoff(ctx, invocation)
284
+ });
285
+ }
286
+ /**
287
+ * Split `provider/model` at the first slash: provider ids have none, model ids may.
288
+ * @internal exported for the unit test only.
289
+ */
290
+ function parseModelArg(raw) {
291
+ const text = raw.trim();
292
+ const slash = text.indexOf("/");
293
+ if (slash <= 0 || slash === text.length - 1) return void 0;
294
+ return {
295
+ provider: text.slice(0, slash),
296
+ model: text.slice(slash + 1)
297
+ };
298
+ }
299
+ /**
300
+ * Check the route against the registered providers and the provider's own model
301
+ * resolution, the same check subagent routes get, so a typo fails here and not
302
+ * on the new session's first turn.
303
+ * @returns an error text, or `undefined` when the route resolves.
304
+ */
305
+ async function modelError(ctx, model, signal) {
306
+ try {
307
+ const providers = ctx.llm.listProviders();
308
+ if (!providers.some((provider) => provider.id === model.provider)) {
309
+ const available = providers.map((provider) => provider.id).join(", ");
310
+ return `LLM provider '${model.provider}' is not registered; available providers: ${available || "(none)"}`;
311
+ }
312
+ await ctx.llm.resolveCallConfig({
313
+ provider: model.provider,
314
+ model: model.model
315
+ }, signal);
316
+ return;
317
+ } catch (error) {
318
+ return error instanceof Error ? error.message : String(error);
319
+ }
320
+ }
321
+ async function handoff(ctx, invocation) {
322
+ const raw = invocation.rawInput.trim();
323
+ let model;
324
+ if (raw !== "") {
325
+ model = parseModelArg(raw);
326
+ if (model === void 0) return {
327
+ kind: "error",
328
+ text: `Expected "<provider>/<model>", got "${raw}"; run bare /handoff to pick one.`
329
+ };
330
+ const invalid = await modelError(ctx, model, invocation.signal);
331
+ if (invalid !== void 0) return {
332
+ kind: "error",
333
+ text: invalid
334
+ };
335
+ }
336
+ const agent = invocation.agent;
337
+ const targetId = agent.session.id;
338
+ try {
339
+ const snapshot = await ctx.sessionQuery.readSession(targetId);
340
+ const rendered = renderHandoff(await readChain(ctx, snapshot, invocation.signal));
341
+ if (rendered.turns === 0) return {
342
+ kind: "error",
343
+ text: "This session has no turns to hand off."
344
+ };
345
+ return {
346
+ kind: "success",
347
+ text: formatLaunchResult((await createBeside(ctx, agent, targetId, rendered.markdown, snapshot, invocation.signal, model)).sessionId)
348
+ };
349
+ } catch (error) {
350
+ return {
351
+ kind: "error",
352
+ text: `Handoff failed: ${error instanceof Error ? error.message : String(error)}`
353
+ };
354
+ }
355
+ }
356
+ /**
357
+ * The handed-off session preceded by every ancestor it was itself handed off from,
358
+ * oldest first, so the brief keeps what earlier briefs summarized.
359
+ */
360
+ async function readChain(ctx, snapshot, signal) {
361
+ const chain = [snapshot];
362
+ const seen = /* @__PURE__ */ new Set([String(snapshot.session.id)]);
363
+ let parent = parentSessionId(snapshot);
364
+ if (parent === void 0) return chain;
365
+ const known = new Set((await ctx.sessionQuery.listSessions(signal)).map((session) => String(session.header.id)));
366
+ while (parent !== void 0 && !seen.has(parent) && known.has(parent)) {
367
+ seen.add(parent);
368
+ const ancestor = await ctx.sessionQuery.readSession(parent);
369
+ chain.unshift(ancestor);
370
+ parent = parentSessionId(ancestor);
371
+ }
372
+ return chain;
373
+ }
374
+ /**
375
+ * Write the brief into the agent's own scratch directory and queue the follow-up
376
+ * turn that tells it to read that file.
377
+ * @param ctx - Host context.
378
+ * @param agent - Agent that receives the brief and the follow-up.
379
+ * @param targetId - Durable id of the handed-off session.
380
+ * @param markdown - Rendered brief.
381
+ * @returns absolute path of the written brief.
382
+ */
383
+ async function deliver(ctx, agent, targetId, markdown) {
384
+ const dir = scratchDirectory(ctx.workingDirectory.get(agent.session), String(agent.session.id));
385
+ if (dir === void 0) throw new Error(`Unsafe session id "${String(agent.session.id)}"; no handoff written.`);
386
+ await mkdir(dir, { recursive: true });
387
+ const file = path.join(dir, HANDOFF_FILE);
388
+ await writeFile(file, markdown, "utf8");
389
+ agent.followup(createUserMessage({
390
+ content: [{
391
+ type: "text",
392
+ text: handoffInstruction(targetId, file)
393
+ }],
394
+ source: { kind: "user" }
395
+ }));
396
+ return file;
397
+ }
398
+ function workspaceOf(ctx, sessionId) {
399
+ for (const workspace of ctx.workspaceRegistry.list()) if (workspace.sessionIds.includes(sessionId)) return workspace;
400
+ }
401
+ function kanbanLinkArgs(snapshot) {
402
+ const all = [];
403
+ for (const event of snapshot.events) {
404
+ if (event.type !== "command/run" || event.data.name !== "kanban") continue;
405
+ const args = event.data.args;
406
+ if (args === void 0) continue;
407
+ try {
408
+ const parsed = JSON.parse(args);
409
+ if (typeof parsed === "object" && parsed !== null && "action" in parsed && parsed.action === "add-link") all.push(args);
410
+ } catch {}
411
+ }
412
+ return all;
413
+ }
414
+ function shortId(id) {
415
+ return id.slice(0, SHORT_ID_LENGTH);
416
+ }
417
+ /**
418
+ * Create the resumed session beside this one: same workspace, same preset, the
419
+ * source's model or the given one, the brief in its own scratch directory, and one follow-up turn that
420
+ * tells it to read that brief.
421
+ * @param ctx - Host context.
422
+ * @param source - Session the command runs in.
423
+ * @param targetId - Durable id of the handed-off session.
424
+ * @param markdown - Rendered brief.
425
+ * @param snapshot - Source session log, the origin of the kanban links to copy.
426
+ * @param signal - Cancellation signal of the invoking command.
427
+ * @param model - Model the new session starts on; the source's own when absent.
428
+ * @returns the created session identity.
429
+ */
430
+ async function createBeside(ctx, source, targetId, markdown, snapshot, signal, model) {
431
+ const selection = model === void 0 ? source.model.current() : model;
432
+ const agentPreset = source.session.header.agentPreset;
433
+ const workspace = workspaceOf(ctx, source.session.id);
434
+ const created = await ctx.sessionController.create(workspace === void 0 ? {
435
+ cwd: ctx.workingDirectory.get(source.session),
436
+ agentPreset
437
+ } : {
438
+ workspaceId: workspace.id,
439
+ agentPreset
440
+ });
441
+ const resolved = await ctx.sessionController.resolveAgent(created.sessionId);
442
+ if ("error" in resolved) throw new Error(resolved.error.message);
443
+ const agent = resolved.agent;
444
+ if (selection !== void 0) agent.model.select(selection);
445
+ const sourceTitle = ctx.sessionTitle.get(source.session);
446
+ ctx.sessionTitle.rename(agent.session, sourceTitle === void 0 ? `Handoff ${shortId(targetId)}` : sourceTitle.title);
447
+ if (sourceTitle !== void 0 && !sourceTitle.title.endsWith(RESUMED_SUFFIX)) ctx.sessionTitle.rename(source.session, `${sourceTitle.title}${RESUMED_SUFFIX}`);
448
+ await ctx.commands.execute(agent, `/kanban ${JSON.stringify({
449
+ action: "init",
450
+ createdAt: Date.now()
451
+ })}`, [], signal);
452
+ for (const args of kanbanLinkArgs(snapshot)) await ctx.commands.execute(agent, `/kanban ${args}`, [], signal);
453
+ const sourceLink = {
454
+ action: "add-link",
455
+ label: `Resumed from ${targetId}`,
456
+ url: `dsh://sessions/${targetId}`,
457
+ priority: 0
458
+ };
459
+ await ctx.commands.execute(agent, `/kanban ${JSON.stringify(sourceLink)}`, [], signal);
460
+ await deliver(ctx, agent, targetId, markdown);
461
+ return created;
462
+ }
463
+ export { apply, inject, name, parseModelArg };
package/package.json CHANGED
@@ -1,6 +1,120 @@
1
1
  {
2
2
  "name": "@lukstei/dsh-session-handoff",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.2-rc.5.11",
4
+ "description": "Session handoff brief command for DSH",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./src/index.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./src/index.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./client": "./dist/client.js",
14
+ "./package.json": "./package.json"
15
+ },
16
+ "files": [
17
+ "src",
18
+ "dist",
19
+ "README.md",
20
+ "cordis.patch.yml",
21
+ "!src/**/*.spec.*",
22
+ "!src/**/*.test.*",
23
+ "!src/**/*.stories.*",
24
+ "!src/**/stories",
25
+ "!src/**/*.e2e.*",
26
+ "!src/**/__snapshots__",
27
+ "!src/**/fixtures"
28
+ ],
29
+ "dsh": {
30
+ "bundle": {
31
+ "patch": "./cordis.patch.yml"
32
+ },
33
+ "client": {
34
+ "platform": "web",
35
+ "immediately": true,
36
+ "inject": [
37
+ "@deepseek-ai/dsh-api-session-controller",
38
+ "@lukstei/dsh-client-split-view",
39
+ "@deepseek-ai/dsh-client-ui-commands",
40
+ "@deepseek-ai/dsh-client-ui-conversation",
41
+ "@deepseek-ai/dsh-client-ui-model-selection",
42
+ "@deepseek-ai/dsh-client-ui-renderer"
43
+ ]
44
+ }
45
+ },
46
+ "dependencies": {
47
+ "@lukstei/dsh-scratch-dir": "0.2.2-rc.5.11"
48
+ },
49
+ "peerDependencies": {
50
+ "@deepseek-ai/cordis": "*",
51
+ "@deepseek-ai/dsh-agent": "*",
52
+ "@deepseek-ai/dsh-api-session-controller": "*",
53
+ "@deepseek-ai/dsh-client-ui-commands": "*",
54
+ "@deepseek-ai/dsh-client-ui-conversation": "*",
55
+ "@deepseek-ai/dsh-client-ui-model-selection": "*",
56
+ "@deepseek-ai/dsh-client-ui-primitives": "*",
57
+ "@deepseek-ai/dsh-client-ui-renderer": "*",
58
+ "@deepseek-ai/dsh-client-ui-session": "*",
59
+ "@deepseek-ai/dsh-client-ui-slots": "*",
60
+ "@deepseek-ai/dsh-commands": "*",
61
+ "@deepseek-ai/dsh-llm": "*",
62
+ "@deepseek-ai/dsh-session": "*",
63
+ "@deepseek-ai/dsh-session-query": "*",
64
+ "@deepseek-ai/dsh-session-title": "*",
65
+ "@deepseek-ai/dsh-token-meter": "*",
66
+ "@deepseek-ai/dsh-working-directory": "*",
67
+ "@deepseek-ai/dsh-workspace": "*",
68
+ "@zaimokuza/dsh-acp-adapter": "*",
69
+ "react": "*"
70
+ },
71
+ "devDependencies": {
72
+ "@deepseek-ai/cordis": "4.1.0",
73
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.5",
74
+ "@deepseek-ai/dsh-api-session-controller": "0.2.2-rc.5",
75
+ "@deepseek-ai/dsh-client-ui-commands": "0.2.2-rc.5",
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",
78
+ "@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.5",
79
+ "@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.5",
80
+ "@deepseek-ai/dsh-client-ui-session": "0.2.2-rc.5",
81
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.5",
82
+ "@deepseek-ai/dsh-commands": "0.2.2-rc.5",
83
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.5",
84
+ "@deepseek-ai/dsh-session": "0.2.2-rc.5",
85
+ "@deepseek-ai/dsh-session-query": "0.2.2-rc.5",
86
+ "@deepseek-ai/dsh-session-title": "0.2.2-rc.5",
87
+ "@deepseek-ai/dsh-token-meter": "0.2.2-rc.5",
88
+ "@deepseek-ai/dsh-working-directory": "0.2.2-rc.5",
89
+ "@deepseek-ai/dsh-workspace": "0.2.2-rc.5",
90
+ "@lukstei/dsh-client-split-view": "0.2.2-rc.5.11",
91
+ "@types/node": "^26.0.0",
92
+ "@types/react": "^19.3.0",
93
+ "@zaimokuza/dsh-acp-adapter": "0.2.2-rc.5.2",
94
+ "react": "^19.3.1",
95
+ "tsdown": "^0.23.0",
96
+ "typescript": "^7.0.2"
97
+ },
98
+ "peerDependenciesMeta": {
99
+ "@zaimokuza/dsh-acp-adapter": {
100
+ "optional": true
101
+ }
102
+ },
103
+ "license": "MIT",
104
+ "repository": {
105
+ "type": "git",
106
+ "url": "git+https://github.com/lukstei/dsh-plugins.git",
107
+ "directory": "packages/dsh-session-handoff"
108
+ },
109
+ "publishConfig": {
110
+ "access": "public"
111
+ },
112
+ "scripts": {
113
+ "build": "tsdown --config tsdown.config.ts --logLevel error",
114
+ "dev": "tsdown --config tsdown.config.ts --watch",
115
+ "check": "biome check --reporter=concise .",
116
+ "typecheck": "tsc --noEmit",
117
+ "test": "node --experimental-test-module-mocks --test --test-reporter=dot",
118
+ "verify": "pnpm --silent run check && pnpm --silent run build && pnpm --silent run typecheck && pnpm --silent run test"
119
+ }
6
120
  }
@@ -0,0 +1,31 @@
1
+ /** Context occupancy an ACP agent reported, as the adapter exposes it. */
2
+ export interface AcpUsage {
3
+ readonly used: number;
4
+ readonly size: number;
5
+ }
6
+
7
+ export type AcpUsageReader = (
8
+ sessionId: string,
9
+ ) => Promise<AcpUsage | undefined>;
10
+
11
+ // smell: module-level seat; the optional ACP scope in `index.ts` fills it, so the ring needs no
12
+ // hard dependency on the adapter.
13
+ let reader: AcpUsageReader | undefined;
14
+ const listeners = new Set<() => void>();
15
+
16
+ export function setAcpUsageReader(next: AcpUsageReader | undefined): void {
17
+ reader = next;
18
+ for (const listener of listeners) listener();
19
+ }
20
+
21
+ /** `useSyncExternalStore` seat, so a ring mounted before the adapter re-reads once it arrives. */
22
+ export function subscribeAcpUsageReader(listener: () => void): () => void {
23
+ listeners.add(listener);
24
+ return () => {
25
+ listeners.delete(listener);
26
+ };
27
+ }
28
+
29
+ export function currentAcpUsageReader(): AcpUsageReader | undefined {
30
+ return reader;
31
+ }