@sumicom/quicksave 0.5.2 → 0.6.0
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/ai/asyncQueue.d.ts +16 -0
- package/dist/ai/asyncQueue.d.ts.map +1 -0
- package/dist/ai/asyncQueue.js +39 -0
- package/dist/ai/asyncQueue.js.map +1 -0
- package/dist/ai/asyncQueue.test.d.ts +2 -0
- package/dist/ai/asyncQueue.test.d.ts.map +1 -0
- package/dist/ai/asyncQueue.test.js +56 -0
- package/dist/ai/asyncQueue.test.js.map +1 -0
- package/dist/ai/cardBuilder.d.ts +64 -0
- package/dist/ai/cardBuilder.d.ts.map +1 -0
- package/dist/ai/cardBuilder.js +503 -0
- package/dist/ai/cardBuilder.js.map +1 -0
- package/dist/ai/claudeCodeService.d.ts +47 -36
- package/dist/ai/claudeCodeService.d.ts.map +1 -1
- package/dist/ai/claudeCodeService.js +472 -367
- package/dist/ai/claudeCodeService.js.map +1 -1
- package/dist/connection/connection.d.ts +24 -6
- package/dist/connection/connection.d.ts.map +1 -1
- package/dist/connection/connection.js +85 -13
- package/dist/connection/connection.js.map +1 -1
- package/dist/connection/pubsub.d.ts +41 -0
- package/dist/connection/pubsub.d.ts.map +1 -0
- package/dist/connection/pubsub.js +101 -0
- package/dist/connection/pubsub.js.map +1 -0
- package/dist/connection/pubsub.test.d.ts +2 -0
- package/dist/connection/pubsub.test.d.ts.map +1 -0
- package/dist/connection/pubsub.test.js +96 -0
- package/dist/connection/pubsub.test.js.map +1 -0
- package/dist/handlers/messageHandler.d.ts +17 -2
- package/dist/handlers/messageHandler.d.ts.map +1 -1
- package/dist/handlers/messageHandler.js +171 -18
- package/dist/handlers/messageHandler.js.map +1 -1
- package/dist/handlers/messageHandler.test.js +1 -1
- package/dist/index.js +191 -3
- package/dist/index.js.map +1 -1
- package/dist/service/ipc.test.js +6 -6
- package/dist/service/ipcClient.js +1 -1
- package/dist/service/run.d.ts.map +1 -1
- package/dist/service/run.js +114 -12
- package/dist/service/run.js.map +1 -1
- package/dist/service/singleton.test.js +1 -1
- package/dist/service/types.d.ts +29 -0
- package/dist/service/types.d.ts.map +1 -1
- package/dist/service/types.js +11 -0
- package/dist/service/types.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
import { getSessionMessages, listSubagents, } from '@anthropic-ai/claude-agent-sdk';
|
|
2
|
+
import { readFile } from 'fs/promises';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
const TOOL_RESULT_TRUNCATE_LENGTH = 500;
|
|
5
|
+
/** Extract readable text from tool_result content (string or array of blocks). */
|
|
6
|
+
function extractToolResultText(content) {
|
|
7
|
+
if (typeof content === 'string')
|
|
8
|
+
return content;
|
|
9
|
+
if (Array.isArray(content)) {
|
|
10
|
+
return content
|
|
11
|
+
.filter((b) => b.type === 'text')
|
|
12
|
+
.map((b) => b.text || '')
|
|
13
|
+
.join('\n');
|
|
14
|
+
}
|
|
15
|
+
return JSON.stringify(content);
|
|
16
|
+
}
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// StreamCardBuilder — streaming session, emits CardEvents
|
|
19
|
+
// ============================================================================
|
|
20
|
+
export class StreamCardBuilder {
|
|
21
|
+
sessionId;
|
|
22
|
+
streamId;
|
|
23
|
+
seq = 0;
|
|
24
|
+
cards = new Map();
|
|
25
|
+
/** tool_use_id → CardId, for pairing tool_result to ToolCallCard */
|
|
26
|
+
toolUseIdToCardId = new Map();
|
|
27
|
+
/** agentId (task_id) → CardId, for matching subagent updates */
|
|
28
|
+
agentIdToCardId = new Map();
|
|
29
|
+
/** Cards created for subagent permissions — removed after resolution. */
|
|
30
|
+
ephemeralCards = new Set();
|
|
31
|
+
/** Current streaming assistant_text card (for append_text events) */
|
|
32
|
+
currentTextCardId = null;
|
|
33
|
+
constructor(sessionId, streamId) {
|
|
34
|
+
this.sessionId = sessionId;
|
|
35
|
+
this.streamId = streamId;
|
|
36
|
+
}
|
|
37
|
+
updateSessionId(sessionId) {
|
|
38
|
+
this.sessionId = sessionId;
|
|
39
|
+
}
|
|
40
|
+
/** Start a new turn: update streamId and reset per-turn state, keep accumulated cards. */
|
|
41
|
+
startNewTurn(streamId) {
|
|
42
|
+
this.streamId = streamId;
|
|
43
|
+
this.currentTextCardId = null;
|
|
44
|
+
}
|
|
45
|
+
nextId() {
|
|
46
|
+
return `${this.sessionId}:${this.streamId}:${++this.seq}`;
|
|
47
|
+
}
|
|
48
|
+
addEvent(card, afterCardId) {
|
|
49
|
+
this.cards.set(card.id, card);
|
|
50
|
+
return { type: 'add', streamId: this.streamId, sessionId: this.sessionId, card, afterCardId };
|
|
51
|
+
}
|
|
52
|
+
updateEvent(cardId, patch) {
|
|
53
|
+
const existing = this.cards.get(cardId);
|
|
54
|
+
if (existing) {
|
|
55
|
+
Object.assign(existing, patch);
|
|
56
|
+
}
|
|
57
|
+
return { type: 'update', streamId: this.streamId, sessionId: this.sessionId, cardId, patch };
|
|
58
|
+
}
|
|
59
|
+
appendTextEvent(cardId, text) {
|
|
60
|
+
const existing = this.cards.get(cardId);
|
|
61
|
+
if (existing && 'text' in existing) {
|
|
62
|
+
existing.text += text;
|
|
63
|
+
}
|
|
64
|
+
return { type: 'append_text', streamId: this.streamId, sessionId: this.sessionId, cardId, text };
|
|
65
|
+
}
|
|
66
|
+
removeEvent(cardId) {
|
|
67
|
+
this.cards.delete(cardId);
|
|
68
|
+
return { type: 'remove', streamId: this.streamId, sessionId: this.sessionId, cardId };
|
|
69
|
+
}
|
|
70
|
+
// ── Public: produce CardEvents from SDK data ────────────────────────────
|
|
71
|
+
userMessage(text) {
|
|
72
|
+
this.currentTextCardId = null;
|
|
73
|
+
const card = { type: 'user', id: this.nextId(), timestamp: Date.now(), text };
|
|
74
|
+
return this.addEvent(card);
|
|
75
|
+
}
|
|
76
|
+
thinkingBlock(text) {
|
|
77
|
+
this.currentTextCardId = null;
|
|
78
|
+
const card = { type: 'thinking', id: this.nextId(), timestamp: Date.now(), text };
|
|
79
|
+
return this.addEvent(card);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Append text to current assistant_text card, or create a new one.
|
|
83
|
+
* Returns append_text event (hot path) or add event (new card).
|
|
84
|
+
*/
|
|
85
|
+
assistantText(text) {
|
|
86
|
+
if (this.currentTextCardId) {
|
|
87
|
+
return this.appendTextEvent(this.currentTextCardId, text);
|
|
88
|
+
}
|
|
89
|
+
const id = this.nextId();
|
|
90
|
+
const card = { type: 'assistant_text', id, timestamp: Date.now(), text, streaming: true };
|
|
91
|
+
this.currentTextCardId = id;
|
|
92
|
+
return this.addEvent(card);
|
|
93
|
+
}
|
|
94
|
+
/** Mark the current assistant_text card as done streaming. */
|
|
95
|
+
finalizeAssistantText() {
|
|
96
|
+
if (!this.currentTextCardId)
|
|
97
|
+
return null;
|
|
98
|
+
const id = this.currentTextCardId;
|
|
99
|
+
this.currentTextCardId = null;
|
|
100
|
+
return this.updateEvent(id, { streaming: false });
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Handle tool_use block from SDK stream.
|
|
104
|
+
* If the card was already pre-created via `toolCallFromPermission()`, confirm it.
|
|
105
|
+
* Otherwise create a new ToolCallCard.
|
|
106
|
+
*/
|
|
107
|
+
toolUse(toolName, toolInput, toolUseId) {
|
|
108
|
+
this.currentTextCardId = null;
|
|
109
|
+
// Check if card was pre-created from canUseTool
|
|
110
|
+
const existingCardId = this.toolUseIdToCardId.get(toolUseId);
|
|
111
|
+
if (existingCardId) {
|
|
112
|
+
// Confirm with real data (input may differ if updatedInput was returned)
|
|
113
|
+
return this.updateEvent(existingCardId, { toolInput });
|
|
114
|
+
}
|
|
115
|
+
const id = this.nextId();
|
|
116
|
+
const card = {
|
|
117
|
+
type: 'tool_call', id, timestamp: Date.now(),
|
|
118
|
+
toolName, toolInput, toolUseId,
|
|
119
|
+
};
|
|
120
|
+
this.toolUseIdToCardId.set(toolUseId, id);
|
|
121
|
+
return this.addEvent(card);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Pre-create a ToolCallCard from canUseTool (fires before tool_use stream event).
|
|
125
|
+
* This eliminates the synthetic message hack.
|
|
126
|
+
*/
|
|
127
|
+
toolCallFromPermission(toolName, toolInput, toolUseId, pendingInput,
|
|
128
|
+
/** Ephemeral cards are removed after permission is resolved (subagent permissions). */
|
|
129
|
+
ephemeral = false) {
|
|
130
|
+
this.currentTextCardId = null;
|
|
131
|
+
// If the card was already created by the assistant message's tool_use block
|
|
132
|
+
// (which arrives in the stream BEFORE canUseTool fires), update it with pendingInput.
|
|
133
|
+
const existingCardId = this.toolUseIdToCardId.get(toolUseId);
|
|
134
|
+
if (existingCardId) {
|
|
135
|
+
if (ephemeral)
|
|
136
|
+
this.ephemeralCards.add(existingCardId);
|
|
137
|
+
return this.updateEvent(existingCardId, { pendingInput });
|
|
138
|
+
}
|
|
139
|
+
const id = this.nextId();
|
|
140
|
+
const card = {
|
|
141
|
+
type: 'tool_call', id, timestamp: Date.now(),
|
|
142
|
+
toolName, toolInput, toolUseId, pendingInput,
|
|
143
|
+
};
|
|
144
|
+
this.toolUseIdToCardId.set(toolUseId, id);
|
|
145
|
+
if (ephemeral)
|
|
146
|
+
this.ephemeralCards.add(id);
|
|
147
|
+
return this.addEvent(card);
|
|
148
|
+
}
|
|
149
|
+
/** Attach a pending input to a subagent card (subagent permission). */
|
|
150
|
+
attachPendingToSubagent(agentId, pendingInput) {
|
|
151
|
+
const cardId = this.agentIdToCardId.get(agentId);
|
|
152
|
+
if (!cardId)
|
|
153
|
+
return null;
|
|
154
|
+
return this.updateEvent(cardId, { pendingInput });
|
|
155
|
+
}
|
|
156
|
+
/** Clear pending input from a card. Ephemeral cards are removed entirely. */
|
|
157
|
+
clearPendingInput(requestId) {
|
|
158
|
+
for (const [, card] of this.cards) {
|
|
159
|
+
if (card.pendingInput?.requestId === requestId) {
|
|
160
|
+
if (this.ephemeralCards.has(card.id)) {
|
|
161
|
+
this.ephemeralCards.delete(card.id);
|
|
162
|
+
return this.removeEvent(card.id);
|
|
163
|
+
}
|
|
164
|
+
return this.updateEvent(card.id, { pendingInput: undefined });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
/** Find the card ID for a given requestId. */
|
|
170
|
+
findCardByRequestId(requestId) {
|
|
171
|
+
for (const [, card] of this.cards) {
|
|
172
|
+
if (card.pendingInput?.requestId === requestId)
|
|
173
|
+
return card.id;
|
|
174
|
+
}
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
/** Check if a tool card already exists for the given tool_use_id. */
|
|
178
|
+
hasToolCard(toolUseId) {
|
|
179
|
+
return this.toolUseIdToCardId.has(toolUseId);
|
|
180
|
+
}
|
|
181
|
+
/** Return all live cards (insertion order). Cards carry pendingInput if set. */
|
|
182
|
+
getCards() {
|
|
183
|
+
return Array.from(this.cards.values());
|
|
184
|
+
}
|
|
185
|
+
toolResult(toolUseId, content, isError) {
|
|
186
|
+
const cardId = this.toolUseIdToCardId.get(toolUseId);
|
|
187
|
+
if (!cardId)
|
|
188
|
+
return null;
|
|
189
|
+
const truncated = content.length > TOOL_RESULT_TRUNCATE_LENGTH;
|
|
190
|
+
const resultContent = truncated
|
|
191
|
+
? content.slice(0, TOOL_RESULT_TRUNCATE_LENGTH) + ' [truncated]'
|
|
192
|
+
: content;
|
|
193
|
+
return this.updateEvent(cardId, {
|
|
194
|
+
result: { content: resultContent, isError, truncated },
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
subagentStart(description, agentId, toolUseId) {
|
|
198
|
+
this.currentTextCardId = null;
|
|
199
|
+
const id = this.nextId();
|
|
200
|
+
const card = {
|
|
201
|
+
type: 'subagent', id, timestamp: Date.now(),
|
|
202
|
+
description,
|
|
203
|
+
toolUseId: toolUseId ?? agentId,
|
|
204
|
+
agentId,
|
|
205
|
+
status: 'running',
|
|
206
|
+
toolUseCount: 0,
|
|
207
|
+
};
|
|
208
|
+
this.agentIdToCardId.set(agentId, id);
|
|
209
|
+
// Position after the parent ToolCallCard if we have the toolUseId
|
|
210
|
+
const afterCardId = toolUseId ? this.toolUseIdToCardId.get(toolUseId) : undefined;
|
|
211
|
+
return this.addEvent(card, afterCardId);
|
|
212
|
+
}
|
|
213
|
+
subagentProgress(agentId, toolUseId, toolUseCount, lastToolName) {
|
|
214
|
+
const cardId = this.agentIdToCardId.get(agentId)
|
|
215
|
+
?? (toolUseId ? this.agentIdToCardId.get(toolUseId) : undefined);
|
|
216
|
+
if (!cardId)
|
|
217
|
+
return null;
|
|
218
|
+
const patch = {};
|
|
219
|
+
if (toolUseCount !== undefined)
|
|
220
|
+
patch.toolUseCount = toolUseCount;
|
|
221
|
+
if (lastToolName !== undefined)
|
|
222
|
+
patch.lastToolName = lastToolName;
|
|
223
|
+
return this.updateEvent(cardId, patch);
|
|
224
|
+
}
|
|
225
|
+
subagentEnd(agentId, toolUseId, status, summary) {
|
|
226
|
+
const cardId = this.agentIdToCardId.get(agentId)
|
|
227
|
+
?? (toolUseId ? this.agentIdToCardId.get(toolUseId) : undefined);
|
|
228
|
+
if (!cardId)
|
|
229
|
+
return null;
|
|
230
|
+
return this.updateEvent(cardId, { status, summary });
|
|
231
|
+
}
|
|
232
|
+
systemMessage(text, subtype) {
|
|
233
|
+
const card = { type: 'system', id: this.nextId(), timestamp: Date.now(), text, subtype };
|
|
234
|
+
return this.addEvent(card);
|
|
235
|
+
}
|
|
236
|
+
errorMessage(text) {
|
|
237
|
+
return this.systemMessage(`Error: ${text}`, 'error');
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// ============================================================================
|
|
241
|
+
// buildCardsFromHistory — convert JSONL history into Card[]
|
|
242
|
+
// ============================================================================
|
|
243
|
+
export async function buildCardsFromHistory(sessionId, cwd, offset = 0, limit = 50) {
|
|
244
|
+
const allMessages = (await getSessionMessages(sessionId, { dir: cwd, includeSystemMessages: true }))
|
|
245
|
+
.filter((m) => !m.isSidechain);
|
|
246
|
+
const total = allMessages.length;
|
|
247
|
+
const tailStart = Math.max(0, total - offset - limit);
|
|
248
|
+
const tailEnd = Math.max(0, total - offset);
|
|
249
|
+
const sliced = allMessages.slice(tailStart, tailEnd);
|
|
250
|
+
// ── Pass 1: Build indexes from ALL messages ────────────────────────────
|
|
251
|
+
// toolUseId → toolName (for tool_result lookup across pages)
|
|
252
|
+
const agentToolUseIds = new Set();
|
|
253
|
+
// toolUseId → tool_result data (for pairing)
|
|
254
|
+
const toolResults = new Map();
|
|
255
|
+
for (const msg of allMessages) {
|
|
256
|
+
const rawMsg = msg.message;
|
|
257
|
+
if (!Array.isArray(rawMsg?.content))
|
|
258
|
+
continue;
|
|
259
|
+
for (const block of rawMsg.content) {
|
|
260
|
+
if (block.type === 'tool_use' && block.name === 'Agent' && block.id) {
|
|
261
|
+
agentToolUseIds.add(block.id);
|
|
262
|
+
}
|
|
263
|
+
if (block.type === 'tool_result' && block.tool_use_id) {
|
|
264
|
+
const text = extractToolResultText(block.content);
|
|
265
|
+
toolResults.set(block.tool_use_id, { content: text, isError: !!block.is_error });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// ── Get real agentIds from SDK listSubagents ───────────────────────────
|
|
270
|
+
// System messages (task_started) are NOT reliably present in the JSONL.
|
|
271
|
+
// Instead, read subagent meta.json files and match by description to the
|
|
272
|
+
// Agent tool_use input.description.
|
|
273
|
+
// Build description → toolUseId map from Agent tool_use blocks
|
|
274
|
+
const descToToolUseId = new Map();
|
|
275
|
+
for (const msg of allMessages) {
|
|
276
|
+
const rawMsg = msg.message;
|
|
277
|
+
if (!Array.isArray(rawMsg?.content))
|
|
278
|
+
continue;
|
|
279
|
+
for (const block of rawMsg.content) {
|
|
280
|
+
if (block.type === 'tool_use' && block.name === 'Agent' && block.id) {
|
|
281
|
+
const desc = block.input?.description ?? '';
|
|
282
|
+
if (desc)
|
|
283
|
+
descToToolUseId.set(desc, block.id);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
const toolUseIdToAgentId = new Map();
|
|
288
|
+
try {
|
|
289
|
+
const agentIds = await listSubagents(sessionId, { dir: cwd });
|
|
290
|
+
// Read each subagent's meta.json to get description, then match to toolUseId
|
|
291
|
+
// SDK stores subagent meta at ~/.claude/projects/<cwd-hash>/<sessionId>/subagents/<agentId>.meta.json
|
|
292
|
+
const cwdHash = cwd.replace(/\//g, '-').replace(/^-/, '');
|
|
293
|
+
const subagentsDir = join(process.env.HOME ?? '', '.claude', 'projects', cwdHash, sessionId, 'subagents');
|
|
294
|
+
for (const agentId of agentIds) {
|
|
295
|
+
try {
|
|
296
|
+
const possiblePaths = [
|
|
297
|
+
join(subagentsDir, `${agentId}.meta.json`),
|
|
298
|
+
];
|
|
299
|
+
let meta = null;
|
|
300
|
+
for (const p of possiblePaths) {
|
|
301
|
+
try {
|
|
302
|
+
meta = JSON.parse(await readFile(p, 'utf-8'));
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
catch { /* try next */ }
|
|
306
|
+
}
|
|
307
|
+
if (meta?.description && descToToolUseId.has(meta.description)) {
|
|
308
|
+
toolUseIdToAgentId.set(descToToolUseId.get(meta.description), agentId);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
catch { /* skip this agent */ }
|
|
312
|
+
}
|
|
313
|
+
// Fallback for any unmatched Agent tool_use IDs
|
|
314
|
+
for (const toolUseId of agentToolUseIds) {
|
|
315
|
+
if (!toolUseIdToAgentId.has(toolUseId)) {
|
|
316
|
+
toolUseIdToAgentId.set(toolUseId, toolUseId);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
catch {
|
|
321
|
+
// No subagents or SDK error — fallback: agentId = toolUseId
|
|
322
|
+
for (const toolUseId of agentToolUseIds) {
|
|
323
|
+
toolUseIdToAgentId.set(toolUseId, toolUseId);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
// ── Pass 2: Build Cards from sliced messages ───────────────────────────
|
|
327
|
+
let seq = tailStart;
|
|
328
|
+
const nextId = () => `${sessionId}:h:${++seq}`;
|
|
329
|
+
const cards = [];
|
|
330
|
+
for (const msg of sliced) {
|
|
331
|
+
// ── System messages ──
|
|
332
|
+
if (msg.type === 'system') {
|
|
333
|
+
const subtype = msg.subtype;
|
|
334
|
+
// Skip subagent lifecycle events (handled via subagentCards below)
|
|
335
|
+
if (subtype === 'task_started' || subtype === 'task_progress' || subtype === 'task_notification')
|
|
336
|
+
continue;
|
|
337
|
+
// Skip init and status messages (not useful in history)
|
|
338
|
+
if (subtype === 'init' || subtype === 'status' || subtype === 'session_state_changed')
|
|
339
|
+
continue;
|
|
340
|
+
if (subtype === 'compact_boundary') {
|
|
341
|
+
cards.push({ type: 'system', id: nextId(), timestamp: Date.now(), text: 'Context compacted', subtype: 'compacted' });
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
// Unknown system subtype — show as info
|
|
345
|
+
cards.push({ type: 'system', id: nextId(), timestamp: Date.now(), text: subtype ?? 'System event', subtype: 'info' });
|
|
346
|
+
}
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
const rawMessage = msg.message;
|
|
350
|
+
if (!rawMessage?.content) {
|
|
351
|
+
// Empty message — skip
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
// ── User messages ──
|
|
355
|
+
if (msg.type === 'user') {
|
|
356
|
+
if (typeof rawMessage.content === 'string') {
|
|
357
|
+
cards.push({ type: 'user', id: nextId(), timestamp: Date.now(), text: rawMessage.content });
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
if (Array.isArray(rawMessage.content)) {
|
|
361
|
+
for (const block of rawMessage.content) {
|
|
362
|
+
if (block.type === 'text') {
|
|
363
|
+
cards.push({ type: 'user', id: nextId(), timestamp: Date.now(), text: block.text });
|
|
364
|
+
}
|
|
365
|
+
// tool_result blocks are paired into ToolCallCard.result (handled below)
|
|
366
|
+
// Skip them here — they don't need separate cards
|
|
367
|
+
}
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
// ── Assistant messages ──
|
|
373
|
+
if (msg.type === 'assistant') {
|
|
374
|
+
const blocks = rawMessage.content;
|
|
375
|
+
if (!Array.isArray(blocks))
|
|
376
|
+
continue;
|
|
377
|
+
for (const block of blocks) {
|
|
378
|
+
switch (block.type) {
|
|
379
|
+
case 'text':
|
|
380
|
+
if (block.text) {
|
|
381
|
+
cards.push({ type: 'assistant_text', id: nextId(), timestamp: Date.now(), text: block.text });
|
|
382
|
+
}
|
|
383
|
+
break;
|
|
384
|
+
case 'thinking':
|
|
385
|
+
if (block.thinking) {
|
|
386
|
+
cards.push({ type: 'thinking', id: nextId(), timestamp: Date.now(), text: block.thinking });
|
|
387
|
+
}
|
|
388
|
+
break;
|
|
389
|
+
case 'redacted_thinking':
|
|
390
|
+
cards.push({ type: 'thinking', id: nextId(), timestamp: Date.now(), text: '[Redacted thinking]' });
|
|
391
|
+
break;
|
|
392
|
+
case 'tool_use': {
|
|
393
|
+
if (agentToolUseIds.has(block.id)) {
|
|
394
|
+
// Agent tool_use → create a ToolCallCard as anchor, then SubagentCard
|
|
395
|
+
const agentId = toolUseIdToAgentId.get(block.id) ?? block.id;
|
|
396
|
+
const result = toolResults.get(block.id);
|
|
397
|
+
const description = block.input?.description ?? '';
|
|
398
|
+
const summary = result ? result.content.slice(0, 200) : undefined;
|
|
399
|
+
// Insert SubagentCard
|
|
400
|
+
const subagentCard = {
|
|
401
|
+
type: 'subagent',
|
|
402
|
+
id: nextId(),
|
|
403
|
+
timestamp: Date.now(),
|
|
404
|
+
description,
|
|
405
|
+
toolUseId: block.id,
|
|
406
|
+
agentId,
|
|
407
|
+
status: result ? 'completed' : 'running',
|
|
408
|
+
summary,
|
|
409
|
+
toolUseCount: 0,
|
|
410
|
+
};
|
|
411
|
+
cards.push(subagentCard);
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
// Normal tool call
|
|
415
|
+
const toolInput = typeof block.input === 'object' && block.input !== null
|
|
416
|
+
? block.input
|
|
417
|
+
: {};
|
|
418
|
+
const result = toolResults.get(block.id);
|
|
419
|
+
let pairedResult;
|
|
420
|
+
if (result) {
|
|
421
|
+
const truncated = result.content.length > TOOL_RESULT_TRUNCATE_LENGTH;
|
|
422
|
+
pairedResult = {
|
|
423
|
+
content: truncated
|
|
424
|
+
? result.content.slice(0, TOOL_RESULT_TRUNCATE_LENGTH) + ' [truncated]'
|
|
425
|
+
: result.content,
|
|
426
|
+
isError: result.isError,
|
|
427
|
+
truncated,
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
cards.push({
|
|
431
|
+
type: 'tool_call',
|
|
432
|
+
id: nextId(),
|
|
433
|
+
timestamp: Date.now(),
|
|
434
|
+
toolName: block.name,
|
|
435
|
+
toolInput,
|
|
436
|
+
toolUseId: block.id,
|
|
437
|
+
result: pairedResult,
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
break;
|
|
441
|
+
}
|
|
442
|
+
// Server tool blocks — show as generic tool calls
|
|
443
|
+
case 'server_tool_use':
|
|
444
|
+
case 'mcp_tool_use': {
|
|
445
|
+
const toolInput = typeof block.input === 'object' && block.input !== null
|
|
446
|
+
? block.input
|
|
447
|
+
: {};
|
|
448
|
+
cards.push({
|
|
449
|
+
type: 'tool_call',
|
|
450
|
+
id: nextId(),
|
|
451
|
+
timestamp: Date.now(),
|
|
452
|
+
toolName: block.name ?? block.type,
|
|
453
|
+
toolInput,
|
|
454
|
+
toolUseId: block.id ?? nextId(),
|
|
455
|
+
});
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
// Server/MCP tool results — show as system info
|
|
459
|
+
case 'web_search_tool_result':
|
|
460
|
+
case 'web_fetch_tool_result':
|
|
461
|
+
case 'mcp_tool_result':
|
|
462
|
+
case 'code_execution_tool_result':
|
|
463
|
+
case 'bash_code_execution_tool_result':
|
|
464
|
+
case 'text_editor_code_execution_tool_result':
|
|
465
|
+
case 'tool_search_tool_result': {
|
|
466
|
+
const resultText = extractToolResultText(block.content ?? block.text ?? '');
|
|
467
|
+
const parentToolUseId = block.tool_use_id;
|
|
468
|
+
// Try to pair with a previously emitted tool_call card
|
|
469
|
+
if (parentToolUseId) {
|
|
470
|
+
const parentCard = cards.find((c) => c.type === 'tool_call' && c.toolUseId === parentToolUseId);
|
|
471
|
+
if (parentCard && !parentCard.result) {
|
|
472
|
+
const truncated = resultText.length > TOOL_RESULT_TRUNCATE_LENGTH;
|
|
473
|
+
parentCard.result = {
|
|
474
|
+
content: truncated ? resultText.slice(0, TOOL_RESULT_TRUNCATE_LENGTH) + ' [truncated]' : resultText,
|
|
475
|
+
isError: !!block.is_error,
|
|
476
|
+
truncated,
|
|
477
|
+
};
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
// Fallback: show as system info
|
|
482
|
+
if (resultText) {
|
|
483
|
+
cards.push({ type: 'system', id: nextId(), timestamp: Date.now(), text: `${block.type}: ${resultText.slice(0, 200)}`, subtype: 'info' });
|
|
484
|
+
}
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
case 'container_upload':
|
|
488
|
+
cards.push({ type: 'system', id: nextId(), timestamp: Date.now(), text: 'Container upload', subtype: 'info' });
|
|
489
|
+
break;
|
|
490
|
+
// Unknown block types — skip silently
|
|
491
|
+
default:
|
|
492
|
+
break;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
return {
|
|
498
|
+
cards,
|
|
499
|
+
total,
|
|
500
|
+
hasMore: tailStart > 0,
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
//# sourceMappingURL=cardBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cardBuilder.js","sourceRoot":"","sources":["../../src/ai/cardBuilder.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,kBAAkB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
|
4
|
-
sessionId: string;
|
|
5
|
-
streamId: string;
|
|
6
|
-
eventType: ClaudeStreamEventType;
|
|
7
|
-
content: string;
|
|
8
|
-
toolName?: string;
|
|
9
|
-
toolInput?: string;
|
|
10
|
-
toolUseId?: string;
|
|
11
|
-
toolResultForId?: string;
|
|
12
|
-
isPartial?: boolean;
|
|
13
|
-
}
|
|
14
|
-
export interface StreamEndResult {
|
|
15
|
-
sessionId: string;
|
|
16
|
-
streamId: string;
|
|
17
|
-
success: boolean;
|
|
18
|
-
error?: string;
|
|
19
|
-
totalCostUsd?: number;
|
|
20
|
-
tokenUsage?: {
|
|
21
|
-
input: number;
|
|
22
|
-
output: number;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
2
|
+
import type { ClaudeSessionSummary, ClaudeUserInputRequestPayload, ClaudeUserInputResponsePayload, ClaudePreferences, ConfigValue, CardHistoryResponse } from '@sumicom/quicksave-shared';
|
|
3
|
+
import { StreamCardBuilder } from './cardBuilder.js';
|
|
25
4
|
/**
|
|
26
5
|
* Events emitted by ClaudeCodeService:
|
|
27
|
-
* '
|
|
28
|
-
* 'stream
|
|
29
|
-
* 'user-input-request'
|
|
6
|
+
* 'card-event' (event: CardEvent)
|
|
7
|
+
* 'card-stream-end' (result: CardStreamEnd)
|
|
8
|
+
* 'user-input-request' (request: ClaudeUserInputRequestPayload)
|
|
9
|
+
* 'user-input-resolved' ({ requestId, sessionId })
|
|
10
|
+
* 'session-updated' ({ sessionId, isActive, isStreaming, hasPendingInput, permissionMode })
|
|
11
|
+
* 'preferences-updated' (prefs: ClaudePreferences)
|
|
12
|
+
* 'session-config-updated' ({ sessionId, config: Record<string, ConfigValue> })
|
|
30
13
|
*/
|
|
31
14
|
type PermissionLevel = 'bypassPermissions' | 'acceptEdits' | 'default' | 'plan';
|
|
32
15
|
export declare class ClaudeCodeService extends EventEmitter {
|
|
33
16
|
private sessions;
|
|
34
17
|
private sessionPermissions;
|
|
18
|
+
private sessionConfigs;
|
|
35
19
|
private pendingInputRequests;
|
|
36
20
|
private requestCounter;
|
|
37
21
|
private preferences;
|
|
38
22
|
constructor();
|
|
39
23
|
/**
|
|
40
|
-
* Initialize preferences from the most recently used session
|
|
41
|
-
*
|
|
24
|
+
* Initialize preferences from the most recently used session.
|
|
25
|
+
* Uses SDK listSessions + getSessionMessages to read the last assistant message's model field.
|
|
42
26
|
*/
|
|
43
27
|
initPreferences(): Promise<void>;
|
|
44
28
|
getPreferences(): ClaudePreferences;
|
|
@@ -47,19 +31,21 @@ export declare class ClaudeCodeService extends EventEmitter {
|
|
|
47
31
|
* Emits 'preferences-updated' if any value actually changed.
|
|
48
32
|
*/
|
|
49
33
|
setPreferences(prefs: Partial<ClaudePreferences>): ClaudePreferences;
|
|
34
|
+
getSessionConfig(sessionId: string): Record<string, ConfigValue>;
|
|
35
|
+
/**
|
|
36
|
+
* Set a single key on a session's config. Applies known keys immediately:
|
|
37
|
+
* model / reasoningEffort → updates global preferences (takes effect next turn)
|
|
38
|
+
* permissionMode → calls setPermissionLevel (immediate)
|
|
39
|
+
*/
|
|
40
|
+
setSessionConfig(sessionId: string, key: string, value: ConfigValue): Record<string, ConfigValue>;
|
|
50
41
|
/** Build and emit a session-updated event with current state. */
|
|
51
42
|
private emitSessionUpdate;
|
|
52
43
|
listAvailableSessions(cwd: string): Promise<ClaudeSessionSummary[]>;
|
|
53
44
|
/**
|
|
54
|
-
* Check if a session's last message
|
|
55
|
-
*
|
|
45
|
+
* Check if a session's last message is an unanswered tool_use.
|
|
46
|
+
* Uses SDK getSessionMessages + listSubagents/getSubagentMessages.
|
|
56
47
|
*/
|
|
57
48
|
private detectPendingFromJSONL;
|
|
58
|
-
getMessages(sessionId: string, cwd: string, offset?: number, limit?: number): Promise<{
|
|
59
|
-
messages: ClaudeHistoryMessage[];
|
|
60
|
-
total: number;
|
|
61
|
-
hasMore: boolean;
|
|
62
|
-
}>;
|
|
63
49
|
/**
|
|
64
50
|
* Create a V2 session with the given cwd.
|
|
65
51
|
* V2 SDKSessionOptions doesn't expose `cwd`, so we temporarily change
|
|
@@ -75,6 +61,23 @@ export declare class ClaudeCodeService extends EventEmitter {
|
|
|
75
61
|
* Get all pending user input requests (for re-sending to a reconnected client).
|
|
76
62
|
*/
|
|
77
63
|
getPendingInputRequests(): ClaudeUserInputRequestPayload[];
|
|
64
|
+
/** Debug snapshot of pending inputs and active sessions. */
|
|
65
|
+
getDebugState(): {
|
|
66
|
+
pendingInputs: Array<{
|
|
67
|
+
requestId: string;
|
|
68
|
+
sessionId: string;
|
|
69
|
+
toolName?: string;
|
|
70
|
+
agentId?: string;
|
|
71
|
+
inputType: string;
|
|
72
|
+
}>;
|
|
73
|
+
activeSessions: Array<{
|
|
74
|
+
sessionId: string;
|
|
75
|
+
cwd: string;
|
|
76
|
+
isStreaming: boolean;
|
|
77
|
+
hasPendingInput: boolean;
|
|
78
|
+
permissionMode: string;
|
|
79
|
+
}>;
|
|
80
|
+
};
|
|
78
81
|
startSession(opts: {
|
|
79
82
|
prompt: string;
|
|
80
83
|
cwd: string;
|
|
@@ -105,7 +108,15 @@ export declare class ClaudeCodeService extends EventEmitter {
|
|
|
105
108
|
isOpen(sessionId: string): boolean;
|
|
106
109
|
getActiveSessionCount(): number;
|
|
107
110
|
cleanup(): void;
|
|
108
|
-
|
|
111
|
+
/** Get the CardBuilder for a session (if streaming). Used by canUseTool. */
|
|
112
|
+
getCardBuilder(sessionId: string): StreamCardBuilder | null;
|
|
113
|
+
/** Get card-based history for a session. */
|
|
114
|
+
getCards(sessionId: string, cwd: string, offset?: number, limit?: number): Promise<CardHistoryResponse>;
|
|
115
|
+
/**
|
|
116
|
+
* Turn loop: dequeue prompt → send() → consume stream → on result, check queue → repeat.
|
|
117
|
+
* The first entry may have an empty prompt (already sent by startSession/resumeSession).
|
|
118
|
+
*/
|
|
119
|
+
private processTurnLoop;
|
|
109
120
|
}
|
|
110
121
|
export {};
|
|
111
122
|
//# sourceMappingURL=claudeCodeService.d.ts.map
|