dsh-claude-style 0.21.0-dev.61 → 0.21.1-dev.62

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.
@@ -1,65 +1,290 @@
1
+ // packages/contracts/src/image-tokens.ts
2
+ var PATCH = 14;
3
+ var DOWNSAMPLE = 3;
4
+ var CELL = PATCH * DOWNSAMPLE;
5
+ var MAX_TOKENS = 1024;
6
+ var MIN_PIXELS = 544 * 544;
7
+ var ROUNDS = 10;
8
+ var gridTokens = (height, width) => height * (width + 1) + 2;
9
+ var gridCells = (padded) => Math.ceil(Math.floor(padded / PATCH) / DOWNSAMPLE);
10
+ function solvedGrid(height, width) {
11
+ const aspect = height / width;
12
+ const idealWidth = Math.sqrt((MAX_TOKENS - 2) / aspect + 0.25) - 0.5;
13
+ const idealHeight = idealWidth * aspect;
14
+ if (idealWidth < 1 || idealHeight < 1) {
15
+ const cellsWide = idealWidth < 1 ? 1 : MAX_TOKENS - 3;
16
+ const cellsHigh = idealWidth < 1 ? Math.floor((MAX_TOKENS - 2) / 2) : 1;
17
+ const solvedWidth = cellsWide * CELL;
18
+ const solvedHeight = cellsHigh * CELL;
19
+ return { tokens: gridTokens(gridCells(solvedHeight), gridCells(solvedWidth)), width: solvedWidth, height: solvedHeight };
20
+ }
21
+ const scale = Math.min(Math.trunc(idealWidth) * CELL / width, Math.trunc(idealHeight) * CELL / height);
22
+ const bestWidth = Math.trunc(width * scale / PATCH) * PATCH;
23
+ const bestHeight = Math.trunc(height * scale / PATCH) * PATCH;
24
+ return { tokens: gridTokens(gridCells(bestHeight), gridCells(bestWidth)), width: bestWidth, height: bestHeight };
25
+ }
26
+ function resizeOnce(width, height) {
27
+ let scaledWidth = width;
28
+ let scaledHeight = height;
29
+ const pixels = scaledWidth * scaledHeight;
30
+ if (pixels < MIN_PIXELS && pixels > 0) {
31
+ const scale = Math.sqrt(MIN_PIXELS / pixels);
32
+ scaledWidth = Math.trunc(scaledWidth * scale);
33
+ scaledHeight = Math.trunc(scaledHeight * scale);
34
+ }
35
+ const paddedWidth = Math.ceil(scaledWidth / PATCH) * PATCH;
36
+ const paddedHeight = Math.ceil(scaledHeight / PATCH) * PATCH;
37
+ const direct = gridTokens(gridCells(paddedHeight), gridCells(paddedWidth));
38
+ if (direct <= MAX_TOKENS) return { tokens: direct, width: paddedWidth, height: paddedHeight };
39
+ return solvedGrid(scaledHeight, scaledWidth);
40
+ }
41
+ function imageTokens(width, height) {
42
+ let grid = resizeOnce(width, height);
43
+ for (let round = 1; round < ROUNDS; round += 1) {
44
+ const next = resizeOnce(grid.width, grid.height);
45
+ if (next.width === grid.width && next.height === grid.height) return grid.tokens;
46
+ grid = next;
47
+ }
48
+ return grid.tokens;
49
+ }
50
+
51
+ // packages/contracts/src/tokens.ts
52
+ var WORD = [0, 0.496, 0.496, 0.62, 0.62, 0.62, 0.636, 0.636, 0.776, 0.776, 1.593];
53
+ var WORD_TAIL = 0.25;
54
+ var CJK = 0.5235;
55
+ var CJK_MARK = 2.6312;
56
+ var DIGIT_GROUP = 1;
57
+ var NEWLINE = 1.5161;
58
+ var LONE_SPACE = 0.3398;
59
+ var SPACE_RUN = 1.421;
60
+ var PUNCT_RUN = 0.8153;
61
+ var PUNCT_CHAR = 0.1941;
62
+ var NONE = 0;
63
+ var WIDE = 1;
64
+ var WIDE_MARK = 2;
65
+ var LETTER = 3;
66
+ var DIGIT = 4;
67
+ var SPACE = 5;
68
+ var PUNCT = 6;
69
+ var WIDE_MARK_TEST = /[\p{P}\p{S}]/u;
70
+ var WIDE_KINDS = new Uint8Array(65536);
71
+ function classOf(code) {
72
+ if (code >= 11904) {
73
+ if (code >= 65536) return WIDE_MARK_TEST.test(String.fromCodePoint(code)) ? WIDE_MARK : WIDE;
74
+ const known = WIDE_KINDS[code];
75
+ if (known !== 0) return known;
76
+ const kind = WIDE_MARK_TEST.test(String.fromCodePoint(code)) ? WIDE_MARK : WIDE;
77
+ WIDE_KINDS[code] = kind;
78
+ return kind;
79
+ }
80
+ if (code >= 48 && code <= 57) return DIGIT;
81
+ if (code >= 65 && code <= 90 || code >= 97 && code <= 122) return LETTER;
82
+ if (code === 32 || code >= 9 && code <= 13) return SPACE;
83
+ return PUNCT;
84
+ }
85
+ function textTokens(texts) {
86
+ let total = 0;
87
+ let kind = NONE;
88
+ let length = 0;
89
+ let newline = false;
90
+ function close() {
91
+ if (kind === WIDE) total += length * CJK;
92
+ else if (kind === WIDE_MARK) total += length * CJK_MARK;
93
+ else if (kind === LETTER) total += length <= 10 ? WORD[length] : WORD[10] + (length - 10) * WORD_TAIL;
94
+ else if (kind === DIGIT) total += Math.ceil(length / 3) * DIGIT_GROUP;
95
+ else if (kind === SPACE) total += newline ? NEWLINE : length === 1 ? LONE_SPACE : SPACE_RUN;
96
+ else if (kind === PUNCT) total += PUNCT_RUN + length * PUNCT_CHAR;
97
+ kind = NONE;
98
+ length = 0;
99
+ newline = false;
100
+ }
101
+ for (const text of texts) {
102
+ for (let index = 0; index < text.length; index++) {
103
+ let code = text.charCodeAt(index);
104
+ if (code >= 55296 && code <= 56319 && index + 1 < text.length) {
105
+ code = text.codePointAt(index);
106
+ index += 1;
107
+ }
108
+ const next = classOf(code);
109
+ if (next !== kind) {
110
+ close();
111
+ kind = next;
112
+ }
113
+ length += 1;
114
+ if (next === SPACE && (code === 10 || code === 13)) newline = true;
115
+ }
116
+ }
117
+ close();
118
+ return total;
119
+ }
120
+ var BLOCK_OVERHEAD = 4;
121
+ var ROLE_OVERHEAD = 4;
122
+ var structuralTokens = (block) => textTokens([JSON.stringify(block) ?? ""]);
123
+ function sizedOf(block) {
124
+ const attachment = block.attachment;
125
+ if (attachment === null || typeof attachment !== "object") return null;
126
+ const { width, height } = attachment;
127
+ return typeof width === "number" && typeof height === "number" && Number.isFinite(width) && Number.isFinite(height) && width > 0 && height > 0 ? { width, height } : null;
128
+ }
129
+ function blockTokens(block) {
130
+ if (block === null || typeof block !== "object") return BLOCK_OVERHEAD;
131
+ const { type, text, name } = block;
132
+ if (type === "text" || type === "reasoning") {
133
+ return textTokens([typeof text === "string" ? text : ""]) + BLOCK_OVERHEAD;
134
+ }
135
+ if (type === "tool-call") {
136
+ const args = block.arguments;
137
+ return textTokens([typeof name === "string" ? name : "", typeof args === "string" ? args : ""]) + BLOCK_OVERHEAD;
138
+ }
139
+ if (type === "image") {
140
+ const sized = sizedOf(block);
141
+ if (sized !== null) return imageTokens(sized.width, sized.height) + BLOCK_OVERHEAD;
142
+ }
143
+ return structuralTokens(block) + BLOCK_OVERHEAD;
144
+ }
145
+ function messageTokens(message) {
146
+ const content = message?.content;
147
+ if (!Array.isArray(content) || content.length === 0) return 0;
148
+ let tokens = ROLE_OVERHEAD;
149
+ for (const block of content) tokens += blockTokens(block);
150
+ return Math.round(tokens);
151
+ }
152
+ function toolSchemaTokens(tool) {
153
+ return Math.round(structuralTokens(tool) + BLOCK_OVERHEAD);
154
+ }
155
+
1
156
  // packages/host/src/session-panel-context.ts
157
+ var KIND_ORDER = ["system", "tools", "mcp", "user", "assistant", "tool-result", "memory", "skills", "other"];
2
158
  function createPanelContext() {
3
- return { nodes: /* @__PURE__ */ new Map(), mcpShare: 0 };
159
+ return {
160
+ nodes: /* @__PURE__ */ new Map(),
161
+ sums: { user: 0, assistant: 0, "tool-result": 0, memory: 0, skills: 0, other: 0 },
162
+ system: null,
163
+ tools: 0,
164
+ mcp: 0,
165
+ provider: "",
166
+ model: "",
167
+ reservedOutput: null
168
+ };
169
+ }
170
+ var SKILL_CONTENT = "<skill_content";
171
+ function opensSkill(content) {
172
+ if (!Array.isArray(content)) return false;
173
+ for (const block of content) {
174
+ if (block === null || typeof block !== "object") continue;
175
+ const { type, text } = block;
176
+ if (type !== "text" || typeof text !== "string") continue;
177
+ return text.startsWith(SKILL_CONTENT);
178
+ }
179
+ return false;
180
+ }
181
+ function kindOf(event, message) {
182
+ switch (event.type) {
183
+ case "system/message":
184
+ return "system";
185
+ case "assistant/message":
186
+ return "assistant";
187
+ case "tool/result":
188
+ return opensSkill(message.content) ? "skills" : "tool-result";
189
+ case "developer/message":
190
+ return message.source?.form === "instructions" ? "memory" : "other";
191
+ case "user/message": {
192
+ const source = message.source;
193
+ if (source?.kind === "skill-catalog" || source?.kind === "skill-invocation") return "skills";
194
+ if (source?.form === "instructions") return "memory";
195
+ if (source?.kind !== void 0 && source.kind !== "" && source.kind !== "user") return "other";
196
+ if (source?.form !== void 0) return "other";
197
+ return "user";
198
+ }
199
+ default:
200
+ return null;
201
+ }
4
202
  }
5
- function foldPanelContext(state, events, meter) {
203
+ function retire(state, startSeq, endSeq) {
204
+ for (const [seq, node] of state.nodes) {
205
+ if (seq < startSeq || seq > endSeq) continue;
206
+ if (node.kind !== "system") state.sums[node.kind] -= node.tokens;
207
+ state.nodes.delete(seq);
208
+ }
209
+ const system = state.system;
210
+ if (system !== null && system.seq >= startSeq && system.seq <= endSeq) state.system = null;
211
+ }
212
+ function priceTools(state, tools) {
213
+ let plain = 0;
214
+ let mcp = 0;
215
+ for (const tool of tools) {
216
+ const tokens = toolSchemaTokens(tool);
217
+ const name = tool?.name;
218
+ if (typeof name === "string" && name.startsWith("mcp__")) mcp += tokens;
219
+ else plain += tokens;
220
+ }
221
+ state.tools = plain;
222
+ state.mcp = mcp;
223
+ }
224
+ function foldPanelContext(state, events) {
6
225
  for (const event of events) {
226
+ const operation = event.surfaceOp;
227
+ if (operation !== void 0 && operation !== "append") retire(state, operation.startSeq, operation.endSeq);
228
+ const data = event.data;
7
229
  if (event.type === "request/header") {
8
- const tools = event.data?.header?.tools ?? [];
9
- let total = 0;
10
- let mcp = 0;
11
- for (const tool of tools) {
12
- const weight = JSON.stringify(tool).length;
13
- total += weight;
14
- if (tool.name.startsWith("mcp__")) mcp += weight;
15
- }
16
- state.mcpShare = total === 0 ? 0 : mcp / total;
230
+ const tools = data?.header?.tools;
231
+ priceTools(state, Array.isArray(tools) ? tools : []);
232
+ const config = data?.header?.config;
233
+ if (typeof config?.provider === "string") state.provider = config.provider;
234
+ if (typeof config?.model === "string") state.model = config.model;
235
+ state.reservedOutput = typeof config?.maxTokens === "number" && Number.isFinite(config.maxTokens) && config.maxTokens > 0 ? config.maxTokens : null;
236
+ continue;
17
237
  }
18
- const operation = event.surfaceOp;
19
- if (operation !== void 0 && operation !== "append") {
20
- for (const seq of state.nodes.keys()) {
21
- if (seq >= operation.startSeq && seq <= operation.endSeq) state.nodes.delete(seq);
238
+ if (data === void 0 || event.seq === void 0) continue;
239
+ const message = data.message ?? data;
240
+ const kind = kindOf(event, message);
241
+ if (kind === null) continue;
242
+ const tokens = messageTokens(message);
243
+ if (kind === "system") {
244
+ const previous = state.system;
245
+ if (previous !== null && previous.seq !== event.seq) {
246
+ const kept = state.nodes.get(previous.seq);
247
+ if (kept !== void 0) {
248
+ kept.kind = "other";
249
+ state.sums.other += kept.tokens;
250
+ }
22
251
  }
252
+ state.system = { seq: event.seq, tokens };
253
+ state.nodes.set(event.seq, { kind: "system", tokens });
254
+ continue;
23
255
  }
24
- const message = event.data;
25
- if (event.type !== "user/message" || message === void 0 || event.seq === void 0) continue;
26
- const source = message.source;
27
- let kind;
28
- if (source?.kind === "skill-catalog" || source?.kind === "skill-invocation") kind = "skills";
29
- else if (source?.form === "instructions") kind = "memory";
30
- else if (source?.kind === "runtime-context") kind = "other";
31
- else continue;
32
- if (meter === null || meter === void 0) continue;
33
- state.nodes.set(event.seq, { kind, tokens: meter.estimateMessage(message) });
256
+ const existing = state.nodes.get(event.seq);
257
+ if (existing !== void 0) retire(state, event.seq, event.seq);
258
+ state.nodes.set(event.seq, { kind, tokens });
259
+ state.sums[kind] += tokens;
34
260
  }
35
261
  }
36
- function panelContextOf(projections, state) {
262
+ function panelContextOf(projections, state, thresholdTokens = null) {
37
263
  const pressure = projections.contextPressure;
38
264
  const used = pressure?.projectedTokens ?? pressure?.pressureTokens;
39
265
  const window = pressure?.contextWindow;
40
266
  if (used === void 0 || window === void 0 || window <= 0) return null;
41
- const breakdown = projections.contextBreakdown;
42
- const system = breakdown?.systemTokens ?? 0;
43
- const tools = breakdown?.toolsTokens ?? 0;
44
- const messages = breakdown?.messageTokens ?? 0;
45
- const attributed = /* @__PURE__ */ new Map();
46
- for (const node of state.nodes.values()) attributed.set(node.kind, (attributed.get(node.kind) ?? 0) + node.tokens);
47
- const injected = [...attributed.values()].reduce((sum, tokens) => sum + tokens, 0);
48
- const scale = injected > messages ? messages / injected : 1;
49
- const mcp = tools * state.mcpShare;
267
+ const counts = {
268
+ system: state.system?.tokens ?? 0,
269
+ tools: state.tools,
270
+ mcp: state.mcp,
271
+ user: state.sums.user,
272
+ assistant: state.sums.assistant,
273
+ "tool-result": state.sums["tool-result"],
274
+ memory: state.sums.memory,
275
+ skills: state.sums.skills,
276
+ other: state.sums.other
277
+ };
278
+ const parts = [];
279
+ for (const kind of KIND_ORDER) {
280
+ const tokens = Math.max(0, Math.round(counts[kind]));
281
+ if (tokens > 0) parts.push({ kind, tokens });
282
+ }
50
283
  return {
51
284
  used,
52
285
  window,
53
- system,
54
- tools,
55
- messages,
56
- parts: [
57
- { kind: "messages", tokens: Math.max(0, messages - injected) },
58
- { kind: "tools", tokens: tools - mcp },
59
- { kind: "mcp", tokens: mcp },
60
- { kind: "system", tokens: system },
61
- ...[...attributed].map(([kind, tokens]) => ({ kind, tokens: tokens * scale }))
62
- ]
286
+ parts,
287
+ ...thresholdTokens !== null && thresholdTokens > 0 ? { compaction: { thresholdTokens } } : {}
63
288
  };
64
289
  }
65
290
  export {
@@ -1,5 +1,15 @@
1
1
  // packages/host/src/session-panel-log.ts
2
+ import { createHash } from "node:crypto";
3
+ import { isPanelProcess, panelInvocation } from "./session-panel-call.js";
2
4
  var JOB_OUTPUT_MAX = 8e3;
5
+ function linkJobCall(state, callId, jobId) {
6
+ let ids = state.jobCalls.get(callId);
7
+ if (ids === void 0) {
8
+ ids = /* @__PURE__ */ new Set();
9
+ state.jobCalls.set(callId, ids);
10
+ }
11
+ ids.add(jobId);
12
+ }
3
13
  function text(value) {
4
14
  return typeof value === "string" && value !== "" ? value : null;
5
15
  }
@@ -15,33 +25,72 @@ function messageText(content) {
15
25
  return out;
16
26
  }
17
27
  function rememberJobOutput(state, jobId, text2) {
18
- if (text2 === "" || state.jobOutputs.has(jobId)) return;
28
+ if (text2 === "") return;
19
29
  const capped = text2.length > JOB_OUTPUT_MAX ? text2.slice(text2.length - JOB_OUTPUT_MAX) : text2;
20
- state.jobOutputs.set(jobId, { text: capped, lossy: false, status: state.jobs.get(jobId)?.status ?? "" });
30
+ state.jobOutputs.set(jobId, { text: capped, lossy: text2.length > JOB_OUTPUT_MAX, status: state.jobs.get(jobId)?.status ?? "" });
21
31
  }
22
32
  function foldJobs(state, events) {
23
33
  for (const event of events) {
24
34
  const data = event.data;
25
35
  if (data === void 0) continue;
36
+ if (event.type === "tool/call") {
37
+ const callId = text(data.callId);
38
+ if (callId === null) continue;
39
+ const invocation = panelInvocation(data.name, data.arguments);
40
+ state.jobInvocations.set(callId, invocation);
41
+ if (!invocation.process) continue;
42
+ const id = `call-${createHash("sha256").update(callId).digest("hex").slice(0, 24)}`;
43
+ linkJobCall(state, callId, id);
44
+ state.jobOrigins.set(id, callId);
45
+ state.jobs.set(id, {
46
+ id,
47
+ label: invocation.label,
48
+ category: "process",
49
+ execution: invocation.background ? "background" : "foreground",
50
+ controllable: false,
51
+ status: "running",
52
+ startedAt: event.time ?? 0
53
+ });
54
+ continue;
55
+ }
26
56
  if (event.type === "job/registered" || event.type === "job/settled") {
27
57
  const id = text(data.jobId);
28
58
  if (id === null) continue;
29
59
  if (event.type === "job/registered") {
60
+ const callId = text(data.toolCall?.callId);
61
+ const rootId = text(data.toolCall?.rootCallId) ?? callId;
62
+ const invocation = (callId === null ? void 0 : state.jobInvocations.get(callId)) ?? (rootId === null ? void 0 : state.jobInvocations.get(rootId));
63
+ const temporary = callId === null ? void 0 : [...state.jobCalls.get(callId) ?? []].find((candidate) => state.jobs.get(candidate)?.controllable === false);
64
+ const called = temporary === void 0 ? void 0 : state.jobs.get(temporary);
65
+ if (called?.controllable === false) {
66
+ state.jobs.delete(called.id);
67
+ state.jobOrigins.delete(called.id);
68
+ state.jobCalls.get(callId).delete(called.id);
69
+ }
30
70
  const known2 = state.jobs.get(id);
31
71
  state.jobs.set(id, {
32
72
  id,
33
- label: known2?.label ?? text(data.label) ?? "",
73
+ label: called?.label || known2?.label || text(data.label) || "",
74
+ category: isPanelProcess(id, data.kind, invocation) ? "process" : "task",
75
+ execution: invocation?.background === true ? "background" : invocation?.process === true ? "foreground" : "unknown",
76
+ controllable: true,
34
77
  status: "running",
35
78
  startedAt: number(data.startedAt) ?? known2?.startedAt ?? 0
36
79
  });
37
- const callId = text(data.toolCall?.callId);
38
- if (callId !== null) state.jobCalls.set(callId, id);
80
+ if (callId !== null) {
81
+ linkJobCall(state, callId, id);
82
+ state.jobOrigins.set(id, callId);
83
+ }
84
+ if (rootId !== null) linkJobCall(state, rootId, id);
39
85
  continue;
40
86
  }
41
87
  const known = state.jobs.get(id);
42
88
  state.jobs.set(id, {
43
89
  id,
44
90
  label: known?.label ?? text(data.label) ?? "",
91
+ category: known?.category ?? (isPanelProcess(id, data.kind) ? "process" : "task"),
92
+ execution: known?.execution ?? "unknown",
93
+ controllable: true,
45
94
  status: text(data.status) ?? "completed",
46
95
  startedAt: number(data.startedAt) ?? known?.startedAt ?? 0,
47
96
  finishedAt: number(data.finishedAt) ?? void 0,
@@ -51,17 +100,32 @@ function foldJobs(state, events) {
51
100
  }
52
101
  if (event.type === "tool/result") {
53
102
  const callId = text(data.message?.source?.callId);
54
- const jobId = callId === null ? void 0 : state.jobCalls.get(callId);
55
- if (jobId === void 0) continue;
56
- const known = state.jobs.get(jobId);
57
- if (known === void 0 || known.status === "running" || known.status === "stopping") continue;
58
- rememberJobOutput(state, jobId, messageText(data.message?.content));
103
+ if (callId === null) continue;
104
+ const output = messageText(data.message?.content);
105
+ for (const jobId of state.jobCalls.get(callId) ?? []) {
106
+ const known = state.jobs.get(jobId);
107
+ const handedOut = output.includes(`started background job ${jobId}`) || output.includes(`moved to background job ${jobId}]`);
108
+ const live = known.status === "running" || known.status === "stopping";
109
+ const execution = known.execution === "background" || handedOut || known.controllable && live && data.message?.isError !== true ? "background" : known.execution;
110
+ const settled = !known.controllable;
111
+ state.jobs.set(jobId, {
112
+ ...known,
113
+ execution,
114
+ ...settled ? { status: data.message?.isError === true ? "failed" : "completed", finishedAt: event.time ?? known.startedAt } : {}
115
+ });
116
+ if ((settled || !live) && state.jobOrigins.get(jobId) === callId) rememberJobOutput(state, jobId, output);
117
+ }
59
118
  continue;
60
119
  }
61
120
  if (event.type === "user/message") {
62
- const notice = messageText(data.message?.content);
121
+ const message = data.message ?? data;
122
+ if (message.source?.kind !== "job") continue;
123
+ const notice = messageText(message.content);
63
124
  const match = notice.match(/background job ([A-Za-z0-9_-]+)/);
64
125
  if (match === null) continue;
126
+ const known = state.jobs.get(match[1]);
127
+ if (known === void 0) continue;
128
+ state.jobs.set(known.id, { ...known, execution: "background" });
65
129
  const at = notice.indexOf("Output:");
66
130
  const output = at === -1 ? "" : notice.slice(at + "Output:".length).replace(/^\s*/, "");
67
131
  if (output !== "") rememberJobOutput(state, match[1], output);
@@ -1,23 +1,14 @@
1
1
  // packages/host/src/session-panel-round.ts
2
+ import { panelArguments } from "./session-panel-call.js";
2
3
  var IMAGE_EXT = /\.(?:png|jpe?g|webp|gif|svg|avif|bmp)$/i;
3
4
  var DOCUMENT_EXT = /\.(?:md|markdown|txt|pdf|docx?|xlsx?|pptx?|csv|json|jsonl|yaml|yml|html?)$/i;
4
5
  var WRITE_TOOLS = /* @__PURE__ */ new Set(["write", "edit", "str_replace_editor"]);
5
6
  function createPanelRound() {
6
- return { round: 0, since: 0, outputs: [], calls: /* @__PURE__ */ new Map(), jobs: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() };
7
+ return { round: 0, since: 0, outputs: [], calls: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() };
7
8
  }
8
9
  function text(value) {
9
10
  return typeof value === "string" && value !== "" ? value : null;
10
11
  }
11
- function argumentsOf(value) {
12
- if (typeof value !== "string" || value === "") return null;
13
- let parsed;
14
- try {
15
- parsed = JSON.parse(value);
16
- } catch {
17
- return null;
18
- }
19
- return typeof parsed === "object" && parsed !== null ? parsed : null;
20
- }
21
12
  function outputOf(path, origin, directory) {
22
13
  const normalized = path.replaceAll("\\", "/");
23
14
  const base = directory?.replaceAll("\\", "/");
@@ -47,20 +38,12 @@ function foldPanelRound(state, events, directory) {
47
38
  if (event.type === "tool/call") {
48
39
  const id = text(data.callId);
49
40
  if (id === null) continue;
50
- const args = argumentsOf(data.arguments);
41
+ const args = panelArguments(data.arguments);
51
42
  const written = WRITE_TOOLS.has(String(data.name)) && args !== null ? text(args.path) ?? text(args.file_path) ?? text(args.target_file) ?? text(args.filePath) : null;
52
43
  const child = data.name === "send_message" && args !== null ? text(args.agent_id) : null;
53
44
  state.calls.set(id, { round: state.round, written, child });
54
45
  continue;
55
46
  }
56
- if (event.type === "job/registered") {
57
- const id = text(data.jobId);
58
- const call = text(data.toolCall?.callId);
59
- const root = text(data.toolCall?.rootCallId);
60
- const round = (call === null ? void 0 : state.calls.get(call)?.round) ?? (root === null ? void 0 : state.calls.get(root)?.round) ?? state.round;
61
- if (id !== null) state.jobs.set(id, round);
62
- continue;
63
- }
64
47
  if (event.type === "subagent/catalog") {
65
48
  const id = text(data.childId);
66
49
  if (id !== null) state.children.set(id, state.round);
@@ -89,12 +72,8 @@ function belongsToPanelRound(state, kind, id, createdAt) {
89
72
  const round = state[kind].get(id);
90
73
  return round === void 0 ? state.round === 0 || state.since > 0 && createdAt >= state.since : round === state.round;
91
74
  }
92
- function panelRoundJobs(state, jobs) {
93
- return jobs.filter((job) => job.status === "running" || job.status === "stopping" || belongsToPanelRound(state, "jobs", job.id, job.startedAt));
94
- }
95
75
  export {
96
76
  belongsToPanelRound,
97
77
  createPanelRound,
98
- foldPanelRound,
99
- panelRoundJobs
78
+ foldPanelRound
100
79
  };
@@ -2,7 +2,9 @@
2
2
  import { panelEnvironment } from "./checkout.js";
3
3
  import { JOB_OUTPUT_MAX, foldJobs } from "./session-panel-log.js";
4
4
  import { createPanelContext, foldPanelContext, panelContextOf } from "./session-panel-context.js";
5
- import { belongsToPanelRound, createPanelRound, foldPanelRound, panelRoundJobs } from "./session-panel-round.js";
5
+ import { compactionThresholdOf } from "./session-compact.js";
6
+ import { belongsToPanelRound, createPanelRound, foldPanelRound } from "./session-panel-round.js";
7
+ import { isPanelProcess } from "./session-panel-call.js";
6
8
  var KEPT_SESSIONS = 32;
7
9
  var ANSWER_TTL_MS = 1200;
8
10
  var CHILD_FACTS_TTL_MS = 8e3;
@@ -121,7 +123,7 @@ function createSessionPanel(ctx, cost) {
121
123
  const events = observation.events ?? [];
122
124
  if (entry.cursor === -1 || events.length > 0) {
123
125
  const incoming = arrivals(events, entry.cursor);
124
- foldPanelContext(entry.context, incoming, ctx.get("tokenMeter"));
126
+ foldPanelContext(entry.context, incoming);
125
127
  foldPanelRound(entry.round, incoming, resolvedDirectory);
126
128
  foldJobs(entry, incoming);
127
129
  const last = incoming[incoming.length - 1];
@@ -142,9 +144,10 @@ function createSessionPanel(ctx, cost) {
142
144
  }
143
145
  changes.reverse();
144
146
  const background = await backgroundOf(entry, projections, jobs, agents, sessionId);
147
+ const thresholdTokens = compactionThresholdOf(ctx, agents, sessionId, entry.context, projections.contextPressure?.contextWindow);
145
148
  const value = {
146
149
  environment,
147
- context: panelContextOf(projections, entry.context),
150
+ context: panelContextOf(projections, entry.context, thresholdTokens),
148
151
  // Newest first: the row a reader just caused stands at the top of the list.
149
152
  outputs: [...entry.round.outputs].reverse(),
150
153
  changes,
@@ -194,9 +197,13 @@ function createSessionPanel(ctx, cost) {
194
197
  const id = String(job.id ?? "");
195
198
  if (id === "") continue;
196
199
  live.add(id);
200
+ const known = entry.jobs.get(id);
197
201
  entry.jobs.set(id, {
198
202
  id,
199
- label: text(job.label) ?? "",
203
+ label: known?.label || text(job.label) || "",
204
+ category: known?.category ?? (isPanelProcess(id, job.kind) ? "process" : "task"),
205
+ execution: known?.execution ?? "unknown",
206
+ controllable: true,
200
207
  status: text(job.status) ?? "running",
201
208
  startedAt: number(job.startedAt) ?? 0,
202
209
  finishedAt: number(job.finishedAt) ?? void 0,
@@ -210,7 +217,7 @@ function createSessionPanel(ctx, cost) {
210
217
  const read = jobOutput(sessionId, job.id);
211
218
  if (read !== null && read.text !== "") entry.jobOutputs.set(job.id, read);
212
219
  }
213
- const jobRows = panelRoundJobs(entry.round, [...entry.jobs.values()]).sort((left, right) => {
220
+ const jobRows = [...entry.jobs.values()].sort((left, right) => {
214
221
  const leftRunning = left.status === "running" || left.status === "stopping" ? 0 : 1;
215
222
  const rightRunning = right.status === "running" || right.status === "stopping" ? 0 : 1;
216
223
  return leftRunning - rightRunning || right.startedAt - left.startedAt;
@@ -290,6 +297,8 @@ function createSessionPanel(ctx, cost) {
290
297
  jobs: /* @__PURE__ */ new Map(),
291
298
  jobOutputs: /* @__PURE__ */ new Map(),
292
299
  jobCalls: /* @__PURE__ */ new Map(),
300
+ jobInvocations: /* @__PURE__ */ new Map(),
301
+ jobOrigins: /* @__PURE__ */ new Map(),
293
302
  updates: /* @__PURE__ */ new Map(),
294
303
  watches: /* @__PURE__ */ new Map(),
295
304
  loading: null,
@@ -4,6 +4,12 @@ var PACKAGE_NAME = "dsh-claude-style";
4
4
  // packages/contracts/src/services.ts
5
5
  var OFFICIAL_MODEL_GROUP = "deepseek-official";
6
6
 
7
+ // packages/contracts/src/palette-schemes.ts
8
+ var PALETTE_SCHEME_LIMIT = 16;
9
+ var PALETTE_SCHEME_ENTRY_MAX = 400;
10
+ var PALETTE_SCHEME_ID_MAX = 24;
11
+ var PALETTE_SCHEME_FOLLOW = "brand";
12
+
7
13
  // packages/contracts/src/prices.ts
8
14
  var CURRENCY_CNY = "CNY";
9
15
  var CURRENCY_USD = "USD";
@@ -31,9 +37,8 @@ var BRAND_CLAUDE = "claude";
31
37
  var BRAND_DEEPSEEK = "deepseek";
32
38
  var BRAND_DEEPSEEK_LEGACY = "off";
33
39
  var BRANDS = [BRAND_CLAUDE, BRAND_DEEPSEEK];
34
- var PALETTE_COLORING_BRAND = "brand";
35
- var PALETTE_COLORING_CUSTOM = "custom";
36
- var PALETTE_COLORINGS = [PALETTE_COLORING_BRAND, ...BRANDS, PALETTE_COLORING_CUSTOM];
40
+ var BRAND_DEFAULT_PRESETS = { [BRAND_CLAUDE]: "claude", [BRAND_DEEPSEEK]: "deepseek" };
41
+ var PALETTE_COLORING_BRAND = PALETTE_SCHEME_FOLLOW;
37
42
  var INLINE_CODE_COLOR_PALETTE = "palette";
38
43
  var INLINE_CODE_COLOR_CLASSIC = "classic";
39
44
  var INLINE_CODE_COLORS = [INLINE_CODE_COLOR_PALETTE, INLINE_CODE_COLOR_CLASSIC];
@@ -156,13 +161,16 @@ var PREFS = {
156
161
  /** Whether the sidebar draws its brand area; off collapses that area and leaves the sidebar toggle in place. */
157
162
  sidebarBrand: { type: "boolean", default: true },
158
163
  brandAccent: { type: "color", default: "" },
159
- /** One brand's card, `brand` to follow the theme style, or the reader's four. */
160
- paletteColors: { type: "choice", values: PALETTE_COLORINGS, default: PALETTE_COLORING_BRAND },
161
- /** The reader's four colours, empty until picked; each falls back to the card's own. */
164
+ /** The selected scheme's id, or `brand` to follow the theme style; an id no scheme carries reads as `brand`. */
165
+ paletteColors: { type: "text", default: PALETTE_COLORING_BRAND, max: PALETTE_SCHEME_ID_MAX },
166
+ /** The schemes' records (palette-schemes.ts): the reader's own and the presets' overrides. */
167
+ paletteSchemes: { type: "list", default: [], max: PALETTE_SCHEME_LIMIT, entryMax: PALETTE_SCHEME_ENTRY_MAX, drop: [] },
168
+ /** The earlier single custom card's four colours; read once into the scheme `custom` and then left empty. */
162
169
  customAccent: { type: "color", default: "" },
163
170
  customCanvasLight: { type: "color", default: "" },
164
171
  customCanvasDark: { type: "color", default: "" },
165
172
  customCode: { type: "color", default: "" },
173
+ /** Read once and left at the default: the choice now lives in the Claude preset's override record. */
166
174
  inlineCodeColor: { type: "choice", values: INLINE_CODE_COLORS, default: INLINE_CODE_COLOR_PALETTE },
167
175
  motion: { type: "choice", values: MOTION_MODES, default: MOTION_SYSTEM },
168
176
  statusMotion: { type: "choice", values: STATUS_MOTIONS, default: STATUS_MOTION_SWEEP },
@@ -213,6 +221,13 @@ var PREFS = {
213
221
  /** Whether the percentage stands beside that face. */
214
222
  contextNumbers: { type: "boolean", default: true },
215
223
  statsFooterAlign: { type: "choice", values: STATS_FOOTER_ALIGNS, default: "center" },
224
+ /** Compact-footer figures; speed and TTFT join the existing figures only when asked for. */
225
+ statsFooterSpeed: { type: "boolean", default: false },
226
+ statsFooterTtft: { type: "boolean", default: false },
227
+ statsFooterCache: { type: "boolean", default: true },
228
+ statsFooterCost: { type: "boolean", default: true },
229
+ statsFooterTotal: { type: "boolean", default: true },
230
+ statsFooterContext: { type: "boolean", default: true },
216
231
  /** Which official price table the session's cost follows, or off for no figure at all. */
217
232
  billingCurrency: { type: "choice", values: BILLING_CHOICES, default: CURRENCY_CNY },
218
233
  /** Custom `model|input|cacheRead|output` rows per million tokens; blank buckets inherit official rates. */
@@ -243,7 +258,7 @@ var PREFS = {
243
258
  chatAnimations: { type: "boolean", default: true, legacy: { [CHAT_ANIMATIONS_OFF]: false, enhanced: true, redraw: true } },
244
259
  chatWait: { type: "boolean", default: true },
245
260
  chatSend: { type: "boolean", default: true },
246
- chatReveal: { type: "choice", values: CHAT_REVEAL_MODES, default: CHAT_REVEAL_OFF },
261
+ chatReveal: { type: "choice", values: CHAT_REVEAL_MODES, default: CHAT_REVEAL_ON },
247
262
  reasoningDisplay: { type: "choice", values: REASONING_DISPLAYS, default: REASONING_DISPLAY_STEPPED },
248
263
  /** Moves the reading position when an answer starts; default off because this is unsolicited movement. */
249
264
  answerAnchor: { type: "boolean", default: false },