@lukstei/dsh-session-handoff 0.2.2-rc.5.10 → 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/README.md CHANGED
@@ -112,7 +112,7 @@ The client opens the pane. Without the client bundle the session is created but
112
112
  | --- | --- |
113
113
  | Header | session id, `chain` of ancestor ids (when handed off before), cwd, creation time, event and turn counts across the chain |
114
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` |
115
+ | `## Turns` | one `### T<n> [end reason]` block per turn, numbered across the chain, handoff turns skipped. each turn labels `**User:**` and `**Assistant:**`; the last turn quotes every user message and the reply in full (capped at 20,000 chars); the 4 before it quote 1200 head + 400 tail chars; the 30 before them flatten to the ask (500/300) and reply (240 chars); every cut is marked `[N chars omitted]`; older ones collapse to `… N earlier turns omitted` |
116
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
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
118
 
package/dist/index.js CHANGED
@@ -17,6 +17,9 @@ const TOOL_NAME_LIMIT = 80;
17
17
  const RECENT_TURNS = 5;
18
18
  const RECENT_HEAD = 1200;
19
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;
20
23
  const FAILURE_MAX = 20;
21
24
  const ARTIFACT_MAX = 100;
22
25
  const SHORT_ID_LENGTH$1 = 8;
@@ -66,7 +69,7 @@ function renderHandoff(snapshots) {
66
69
  turn: event.data.turn,
67
70
  sessionId,
68
71
  index: 0,
69
- ask: "",
72
+ asks: [],
70
73
  outcome: "",
71
74
  reason: void 0,
72
75
  isHandoff: false
@@ -88,7 +91,7 @@ function renderHandoff(snapshots) {
88
91
  break;
89
92
  }
90
93
  if (goal === "") goal = elide(flatten(text), ASK_HEAD, ASK_TAIL);
91
- if (open !== void 0 && open.ask === "") open.ask = text;
94
+ if (open !== void 0) open.asks.push(text);
92
95
  break;
93
96
  }
94
97
  case "assistant/message": {
@@ -173,11 +176,11 @@ function handoffInstruction(sessionId, file) {
173
176
  "Do not start the work until the user confirms the next action."
174
177
  ].join("\n");
175
178
  }
176
- /** Last RECENT_TURNS turns quoted at length, OLDER_TURNS before them flattened, the rest counted. */
179
+ /** The last turn in full, RECENT_TURNS before it at length, OLDER_TURNS before those flattened, the rest counted. */
177
180
  function turnList(work) {
178
181
  const kept = work.slice(-35);
179
182
  const dropped = work.length - kept.length;
180
- const blocks = kept.map((turn, index) => turnBlock(turn, index >= kept.length - RECENT_TURNS));
183
+ const blocks = kept.map((turn, index) => turnBlock(turn, index === kept.length - 1 ? "last" : index >= kept.length - RECENT_TURNS ? "recent" : "older"));
181
184
  if (dropped > 0) blocks.unshift(`… ${dropped} earlier turns omitted`);
182
185
  return blocks.join("\n\n");
183
186
  }
@@ -190,11 +193,17 @@ function bounded(lines, max, noun) {
190
193
  function shortId$1(id) {
191
194
  return id.slice(0, SHORT_ID_LENGTH$1);
192
195
  }
193
- /** Recent turns quote the ask and reply at length; older turns are flattened and short. */
194
- function turnBlock(turn, recent) {
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) {
195
202
  const kind = turn.reason === void 0 ? "unfinished" : turn.reason.kind;
196
- const body = (recent ? [elide(turn.ask, RECENT_HEAD, RECENT_TAIL), elide(turn.outcome, RECENT_HEAD, RECENT_TAIL)] : [elide(flatten(turn.ask), ASK_HEAD, ASK_TAIL), clip(turn.outcome, OUTCOME_LIMIT)]).filter((part) => part !== "").join("\n\n");
197
- return `### T${turn.index} [${kind}]\n\n${body === "" ? "(no content)" : body}`;
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")}`;
198
207
  }
199
208
  function blockText(blocks) {
200
209
  const parts = [];
@@ -205,7 +214,7 @@ function blockText(blocks) {
205
214
  function clip(value, limit) {
206
215
  const flat = flatten(value);
207
216
  if (flat.length <= limit) return flat;
208
- return `${flat.slice(0, limit - 1)}…`;
217
+ return `${flat.slice(0, limit)} … [${flat.length - limit} chars omitted]`;
209
218
  }
210
219
  function flatten(value) {
211
220
  return value.replace(/\s+/g, " ").trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lukstei/dsh-session-handoff",
3
- "version": "0.2.2-rc.5.10",
3
+ "version": "0.2.2-rc.5.11",
4
4
  "description": "Session handoff brief command for DSH",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -44,7 +44,7 @@
44
44
  }
45
45
  },
46
46
  "dependencies": {
47
- "@lukstei/dsh-scratch-dir": "0.2.2-rc.5.10"
47
+ "@lukstei/dsh-scratch-dir": "0.2.2-rc.5.11"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@deepseek-ai/cordis": "*",
@@ -87,7 +87,7 @@
87
87
  "@deepseek-ai/dsh-token-meter": "0.2.2-rc.5",
88
88
  "@deepseek-ai/dsh-working-directory": "0.2.2-rc.5",
89
89
  "@deepseek-ai/dsh-workspace": "0.2.2-rc.5",
90
- "@lukstei/dsh-client-split-view": "0.2.2-rc.5.10",
90
+ "@lukstei/dsh-client-split-view": "0.2.2-rc.5.11",
91
91
  "@types/node": "^26.0.0",
92
92
  "@types/react": "^19.3.0",
93
93
  "@zaimokuza/dsh-acp-adapter": "0.2.2-rc.5.2",
package/src/handoff.ts CHANGED
@@ -16,6 +16,9 @@ const TOOL_NAME_LIMIT = 80;
16
16
  const RECENT_TURNS = 5;
17
17
  const RECENT_HEAD = 1200;
18
18
  const RECENT_TAIL = 400;
19
+ /** The last turn is quoted in full up to this cap, split head/tail like the others. */
20
+ const LAST_HEAD = 15000;
21
+ const LAST_TAIL = 5000;
19
22
  /**
20
23
  * Bounds that keep a brief small however long the handoff chain is: each section
21
24
  * keeps only its newest entries and names how many it dropped.
@@ -41,7 +44,8 @@ interface TurnArc {
41
44
  readonly sessionId: string;
42
45
  /** Running number across the whole chain; assigned after collection. */
43
46
  index: number;
44
- ask: string;
47
+ /** Every user message of the turn, in order. */
48
+ asks: string[];
45
49
  outcome: string;
46
50
  reason: TurnEndReason | undefined;
47
51
  /** The turn only read a parent brief; it carries no work of its own. */
@@ -102,7 +106,7 @@ export function renderHandoff(
102
106
  turn: event.data.turn,
103
107
  sessionId,
104
108
  index: 0,
105
- ask: "",
109
+ asks: [],
106
110
  outcome: "",
107
111
  reason: undefined,
108
112
  isHandoff: false,
@@ -128,7 +132,7 @@ export function renderHandoff(
128
132
  break;
129
133
  }
130
134
  if (goal === "") goal = elide(flatten(text), ASK_HEAD, ASK_TAIL);
131
- if (open !== undefined && open.ask === "") open.ask = text;
135
+ if (open !== undefined) open.asks.push(text);
132
136
  break;
133
137
  }
134
138
  case "assistant/message": {
@@ -239,12 +243,19 @@ export function handoffInstruction(sessionId: string, file: string): string {
239
243
  ].join("\n");
240
244
  }
241
245
 
242
- /** Last RECENT_TURNS turns quoted at length, OLDER_TURNS before them flattened, the rest counted. */
246
+ /** The last turn in full, RECENT_TURNS before it at length, OLDER_TURNS before those flattened, the rest counted. */
243
247
  function turnList(work: readonly TurnArc[]): string {
244
248
  const kept = work.slice(-(RECENT_TURNS + OLDER_TURNS));
245
249
  const dropped = work.length - kept.length;
246
250
  const blocks = kept.map((turn, index) =>
247
- turnBlock(turn, index >= kept.length - RECENT_TURNS),
251
+ turnBlock(
252
+ turn,
253
+ index === kept.length - 1
254
+ ? "last"
255
+ : index >= kept.length - RECENT_TURNS
256
+ ? "recent"
257
+ : "older",
258
+ ),
248
259
  );
249
260
  if (dropped > 0) blocks.unshift(`… ${dropped} earlier turns omitted`);
250
261
  return blocks.join("\n\n");
@@ -261,23 +272,30 @@ function shortId(id: string): string {
261
272
  return id.slice(0, SHORT_ID_LENGTH);
262
273
  }
263
274
 
264
- /** Recent turns quote the ask and reply at length; older turns are flattened and short. */
265
- function turnBlock(turn: TurnArc, recent: boolean): string {
275
+ /**
276
+ * The last turn quotes every user message and the reply in full, recent turns quote the first
277
+ * ask and the reply at length, older turns are flattened and short. Roles are labelled so an
278
+ * unanswered ask is never mistaken for a reply.
279
+ */
280
+ function turnBlock(turn: TurnArc, tier: "last" | "recent" | "older"): string {
266
281
  const kind = turn.reason === undefined ? "unfinished" : turn.reason.kind;
267
- const body = (
268
- recent
269
- ? [
270
- elide(turn.ask, RECENT_HEAD, RECENT_TAIL),
271
- elide(turn.outcome, RECENT_HEAD, RECENT_TAIL),
272
- ]
273
- : [
274
- elide(flatten(turn.ask), ASK_HEAD, ASK_TAIL),
275
- clip(turn.outcome, OUTCOME_LIMIT),
276
- ]
277
- )
278
- .filter((part) => part !== "")
279
- .join("\n\n");
280
- return `### T${turn.index} [${kind}]\n\n${body === "" ? "(no content)" : body}`;
282
+ const quote = (text: string): string =>
283
+ tier === "last"
284
+ ? elide(text, LAST_HEAD, LAST_TAIL)
285
+ : elide(text, RECENT_HEAD, RECENT_TAIL);
286
+ const asks = tier === "last" ? turn.asks : turn.asks.slice(0, 1);
287
+ const user = asks.map((ask) =>
288
+ tier === "older"
289
+ ? `**User:** ${elide(flatten(ask), ASK_HEAD, ASK_TAIL)}`
290
+ : `**User:**\n\n${quote(ask)}`,
291
+ );
292
+ const reply =
293
+ turn.outcome.trim() === ""
294
+ ? "**Assistant:** (no reply)"
295
+ : tier === "older"
296
+ ? `**Assistant:** ${clip(turn.outcome, OUTCOME_LIMIT)}`
297
+ : `**Assistant:**\n\n${quote(turn.outcome)}`;
298
+ return `### T${turn.index} [${kind}]\n\n${[...user, reply].join("\n\n")}`;
281
299
  }
282
300
 
283
301
  function blockText(blocks: readonly ContentBlock[]): string {
@@ -292,7 +310,7 @@ function blockText(blocks: readonly ContentBlock[]): string {
292
310
  function clip(value: string, limit: number): string {
293
311
  const flat = flatten(value);
294
312
  if (flat.length <= limit) return flat;
295
- return `${flat.slice(0, limit - 1)}…`;
313
+ return `${flat.slice(0, limit)} … [${flat.length - limit} chars omitted]`;
296
314
  }
297
315
 
298
316
  function flatten(value: string): string {