jg-agent-hq 6.0.0 → 7.0.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +2 -2
  3. package/api/README.md +7 -1
  4. package/dist/cli/cli.js +6 -1
  5. package/dist/contracts/constants.d.ts +4 -0
  6. package/dist/contracts/constants.js +5 -0
  7. package/dist/contracts/index.d.ts +3 -3
  8. package/dist/contracts/index.js +2 -2
  9. package/dist/contracts/types.d.ts +313 -0
  10. package/dist/contracts/types.js +78 -1
  11. package/dist/ipc/client.d.ts +1 -0
  12. package/dist/ipc/client.js +1 -0
  13. package/dist/providers/claude/claude.d.ts +1 -0
  14. package/dist/providers/claude/claude.js +1 -0
  15. package/dist/providers/claude/control/permissions.d.ts +9 -0
  16. package/dist/providers/claude/control/permissions.js +22 -0
  17. package/dist/providers/claude/control/stream.js +18 -1
  18. package/dist/providers/claude/history/history.model.d.ts +17 -0
  19. package/dist/providers/claude/history/history.model.js +100 -3
  20. package/dist/providers/claude/history/types.d.ts +92 -0
  21. package/dist/providers/claude/history/utilities.d.ts +31 -1
  22. package/dist/providers/claude/history/utilities.js +164 -6
  23. package/dist/providers/codex/adapter.js +10 -0
  24. package/dist/providers/codex/codex.js +44 -1
  25. package/dist/providers/codex/transformers.d.ts +25 -1
  26. package/dist/providers/codex/transformers.js +107 -2
  27. package/dist/providers/codex/types.d.ts +16 -1
  28. package/dist/providers/registry/validations.js +12 -0
  29. package/dist/runtime/types.d.ts +1 -0
  30. package/dist/sessions/images.d.ts +11 -0
  31. package/dist/sessions/images.js +44 -0
  32. package/dist/sessions/index.d.ts +2 -1
  33. package/dist/sessions/index.js +4 -2
  34. package/dist/sessions/sessions.d.ts +1 -0
  35. package/dist/sessions/sessions.js +15 -2
  36. package/dist/sessions/types.d.ts +1 -1
  37. package/dist/sessions/utilities.d.ts +57 -1
  38. package/dist/sessions/utilities.js +96 -0
  39. package/dist/store/types.d.ts +33 -0
  40. package/errors/README.md +2 -0
  41. package/package.json +1 -1
@@ -5,7 +5,7 @@ import { EvidenceRequestSchema, SessionDiscoveryRequestSchema, EvidencePageSchem
5
5
  import { AccountRequestSchema, AccountObservationSchema, LoginRequestSchema, LoginObservationSchema, } from './accounts/index.js';
6
6
  import { McpRequestSchema, McpServerPageSchema, McpToolPageSchema, McpResourcePageSchema, } from './extensions/index.js';
7
7
  import { MAX_PROVIDERS, ProviderCapabilitiesSchema, ProviderIdSchema, ProviderStatusSchema, } from './providers/index.js';
8
- import { DEFAULT_PAGE_SIZE, MAX_ITEM_TEXT_LENGTH, MAX_PAGE_SIZE, PUBLIC_ERROR_MESSAGES, } from './constants.js';
8
+ import { DEFAULT_PAGE_SIZE, MAX_ITEM_IMAGE_BYTES, MAX_ITEM_IMAGES, MAX_ITEM_TEXT_LENGTH, MAX_PAGE_SIZE, PUBLIC_ERROR_MESSAGES, } from './constants.js';
9
9
  import { SkillIdSchema, SkillPageSchema, SkillPreviewSchema } from './skills/index.js';
10
10
  import { NativeIdSchema, CursorSchema, NativeLineageSchema } from './identities/index.js';
11
11
  import { ProviderModelPageSchema, ProviderModelsRequestSchema } from './models/index.js';
@@ -62,6 +62,25 @@ export const HqRequestSchema = z.discriminatedUnion('kind', [
62
62
  })
63
63
  .refine((command) => command.nativeItemId === undefined ||
64
64
  (command.turnId !== undefined && command.cursor === undefined), { message: 'One item is read within its turn, without a cursor', path: ['nativeItemId'] }),
65
+ // one item's detail, by its native ID within its turn
66
+ z.strictObject({
67
+ kind: z.literal('item-detail'),
68
+ ...TargetFields,
69
+ turnId: NativeIdSchema,
70
+ nativeItemId: NativeIdSchema,
71
+ }),
72
+ // one image of an item, by its index in the item's detail
73
+ z.strictObject({
74
+ kind: z.literal('item-image'),
75
+ ...TargetFields,
76
+ turnId: NativeIdSchema,
77
+ nativeItemId: NativeIdSchema,
78
+ index: z
79
+ .number()
80
+ .int()
81
+ .min(0)
82
+ .max(MAX_ITEM_IMAGES - 1),
83
+ }),
65
84
  z.strictObject({ kind: z.literal('usage'), provider: TargetFields.provider }),
66
85
  z.strictObject({
67
86
  kind: z.literal('skills'),
@@ -190,6 +209,61 @@ export const HistoryItemSchema = z.object({
190
209
  files: z.array(HistoryFileSchema).max(MAX_PAGE_SIZE),
191
210
  createdAt: z.number().int().nullable(),
192
211
  });
212
+ // the image formats HQ recognizes by their first bytes
213
+ export const ItemImageMediaTypeSchema = z.enum([
214
+ 'image/png',
215
+ 'image/jpeg',
216
+ 'image/gif',
217
+ 'image/webp',
218
+ ]);
219
+ /*
220
+ * What a developer inspects in one item, beyond its display text. Each part is null, or empty,
221
+ * when the item has none, and a field the provider doesn't record is null. Output and results
222
+ * keep their last 65,536 UTF-16 code units, with the start-cut flag set when they lost their
223
+ * start. `images` lists every image the item holds or names, in order, by its index, with its
224
+ * format and size when the item holds the image itself.
225
+ */
226
+ export const ItemDetailSchema = z.object({
227
+ item: HistoryItemSchema,
228
+ command: z
229
+ .object({
230
+ command: z.string().nullable(),
231
+ output: z.string().max(MAX_ITEM_TEXT_LENGTH).nullable(),
232
+ isOutputStartCut: z.boolean(),
233
+ exitCode: z.number().int().nullable(),
234
+ durationMs: z.number().int().nonnegative().nullable(),
235
+ })
236
+ .nullable(),
237
+ tool: z
238
+ .object({
239
+ server: z.string().nullable(),
240
+ name: z.string().nullable(),
241
+ input: z.string().nullable(),
242
+ result: z.string().max(MAX_ITEM_TEXT_LENGTH).nullable(),
243
+ isResultStartCut: z.boolean(),
244
+ })
245
+ .nullable(),
246
+ files: z.array(HistoryFileSchema.extend({ diff: z.string() })).max(MAX_PAGE_SIZE),
247
+ images: z
248
+ .array(z.object({
249
+ index: z
250
+ .number()
251
+ .int()
252
+ .min(0)
253
+ .max(MAX_ITEM_IMAGES - 1),
254
+ mediaType: ItemImageMediaTypeSchema.nullable(),
255
+ byteCount: z.number().int().nonnegative().nullable(),
256
+ }))
257
+ .max(MAX_ITEM_IMAGES),
258
+ });
259
+ // an image's bytes in base64, recognized by its first bytes and at most 4 MiB
260
+ export const ItemImageSchema = z.object({
261
+ mediaType: ItemImageMediaTypeSchema,
262
+ data: z
263
+ .string()
264
+ .max(Math.ceil(MAX_ITEM_IMAGE_BYTES / 3) * 4)
265
+ .regex(/^[A-Za-z0-9+/]*={0,2}$/),
266
+ });
193
267
  export const LiveItemsSchema = z.object({
194
268
  revision: z.number().int().nonnegative(),
195
269
  unchanged: z.boolean(),
@@ -300,6 +374,9 @@ export const HqResponseSchema = z.discriminatedUnion('kind', [
300
374
  history: z.literal('persisted'),
301
375
  }),
302
376
  }),
377
+ // null for an unknown or hidden item, or one in another turn
378
+ z.object({ kind: z.literal('item-detail'), result: ItemDetailSchema.nullable() }),
379
+ z.object({ kind: z.literal('item-image'), result: ItemImageSchema }),
303
380
  z.object({ kind: z.literal('usage'), result: UsageSnapshotSchema }),
304
381
  z.object({ kind: z.literal('skills'), result: SkillPageSchema }),
305
382
  z.object({ kind: z.literal('skill-preview'), result: SkillPreviewSchema }),
@@ -16,5 +16,6 @@ import { type IHqRequestInput, type IHqResponse } from '../contracts/index.js';
16
16
  * - JG_AGENT_HQ_CLIENT_STATE_CONFLICT: State changed. Refresh before continuing.
17
17
  * - JG_AGENT_HQ_CLIENT_AGENT_UNAVAILABLE: Coding agent is unavailable.
18
18
  * - JG_AGENT_HQ_CLIENT_OPERATION_FAILED: Operation could not be completed.
19
+ * - JG_AGENT_HQ_CLIENT_IMAGE_UNAVAILABLE: Image is unavailable.
19
20
  */
20
21
  export declare const requestAgentHq: (stateRoot: string, command: IHqRequestInput, signal?: AbortSignal) => Promise<IHqResponse>;
@@ -25,6 +25,7 @@ import { createLineDecoder } from './framing.js';
25
25
  * - JG_AGENT_HQ_CLIENT_STATE_CONFLICT: State changed. Refresh before continuing.
26
26
  * - JG_AGENT_HQ_CLIENT_AGENT_UNAVAILABLE: Coding agent is unavailable.
27
27
  * - JG_AGENT_HQ_CLIENT_OPERATION_FAILED: Operation could not be completed.
28
+ * - JG_AGENT_HQ_CLIENT_IMAGE_UNAVAILABLE: Image is unavailable.
28
29
  */
29
30
  export const requestAgentHq = async (stateRoot, command, signal) => {
30
31
  const input = HqRequestSchema.safeParse(command);
@@ -94,6 +94,7 @@ export declare const createClaudeProvider: (store: IStore) => {
94
94
  * @throws
95
95
  * - JG_AGENT_HQ_CLAUDE_FAILED: The Claude integration failed
96
96
  * - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
97
+ * - JG_AGENT_HQ_IMAGE_UNAVAILABLE: The HQ image is unavailable
97
98
  * - JG_AGENT_HQ_STORE_FAILED: The HQ store failed
98
99
  * - JG_AGENT_HQ_CURSOR_INVALID: The HQ cursor does not match this request
99
100
  * - JG_AGENT_HQ_PROVIDER_FAILED: The HQ provider integration failed
@@ -203,6 +203,7 @@ export const createClaudeProvider = (store) => {
203
203
  * @throws
204
204
  * - JG_AGENT_HQ_CLAUDE_FAILED: The Claude integration failed
205
205
  * - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
206
+ * - JG_AGENT_HQ_IMAGE_UNAVAILABLE: The HQ image is unavailable
206
207
  * - JG_AGENT_HQ_STORE_FAILED: The HQ store failed
207
208
  * - JG_AGENT_HQ_CURSOR_INVALID: The HQ cursor does not match this request
208
209
  * - JG_AGENT_HQ_PROVIDER_FAILED: The HQ provider integration failed
@@ -1,4 +1,13 @@
1
1
  import type { INativePrompt } from '../../types.js';
2
+ /**
3
+ * Reads a tool request for one of HQ's own agent tools, which the session's agent bridge serves.
4
+ * A tool name holds no `__`, so a server whose name only starts with the bridge's, such as
5
+ * `<bridge>__other`, never passes for it.
6
+ * @param raw The native control request.
7
+ * @param serverName The name the session's agent bridge has in its MCP configuration.
8
+ * @returns The request's tool input, or null for any other request.
9
+ */
10
+ export declare const readOwnToolInput: (raw: unknown, serverName: string) => Record<string, unknown> | null;
2
11
  /**
3
12
  * Binds a native tool request to one turn without accepting arbitrary tool-input edits.
4
13
  * @returns The scoped prompt and tool identity, or null for an unsupported request.
@@ -49,6 +49,12 @@ const RequestSchema = z.strictObject({
49
49
  description: z.string().max(8192).optional(),
50
50
  requires_user_interaction: z.boolean().optional(),
51
51
  });
52
+ // the fields that identify a tool request, whatever else the CLI sends with it
53
+ const ToolRequestSchema = z.object({
54
+ subtype: z.literal('can_use_tool'),
55
+ tool_name: z.string(),
56
+ input: z.record(z.string(), z.unknown()),
57
+ });
52
58
  const ElicitationRequestSchema = z.strictObject({
53
59
  subtype: z.literal('elicitation'),
54
60
  mcp_server_name: z.string().min(1).max(256),
@@ -62,6 +68,22 @@ const ElicitationRequestSchema = z.strictObject({
62
68
  display_name: z.string().max(4096).optional(),
63
69
  description: z.string().max(8192).optional(),
64
70
  });
71
+ /**
72
+ * Reads a tool request for one of HQ's own agent tools, which the session's agent bridge serves.
73
+ * A tool name holds no `__`, so a server whose name only starts with the bridge's, such as
74
+ * `<bridge>__other`, never passes for it.
75
+ * @param raw The native control request.
76
+ * @param serverName The name the session's agent bridge has in its MCP configuration.
77
+ * @returns The request's tool input, or null for any other request.
78
+ */
79
+ export const readOwnToolInput = (raw, serverName) => {
80
+ const request = ToolRequestSchema.safeParse(raw);
81
+ const prefix = `mcp__${serverName}__`;
82
+ if (!request.success || !request.data.tool_name.startsWith(prefix))
83
+ return null;
84
+ const tool = request.data.tool_name.slice(prefix.length);
85
+ return tool.length > 0 && !tool.includes('__') ? request.data.input : null;
86
+ };
65
87
  /**
66
88
  * Binds a native tool request to one turn without accepting arbitrary tool-input edits.
67
89
  * @returns The scoped prompt and tool identity, or null for an unsupported request.
@@ -4,7 +4,7 @@ import { RecordSchema, toClaudeItem } from '../history/index.js';
4
4
  import { MAX_RESULT_BYTES } from '../../../contracts/index.js';
5
5
  import { toTurnResult } from '../../results/index.js';
6
6
  import { DispatchResponseSchema } from '../../../contracts/collaboration/index.js';
7
- import { createClaudePrompt } from './permissions.js';
7
+ import { createClaudePrompt, readOwnToolInput } from './permissions.js';
8
8
  const FrameSchema = z.object({ type: z.string(), session_id: z.string().optional() });
9
9
  const MessageSchema = z.object({
10
10
  uuid: z.string().min(1).max(4096),
@@ -260,6 +260,23 @@ export const receiveClaudeMessage = (session, raw, events) => {
260
260
  const request = RequestSchema.parse(raw);
261
261
  if (!input || !session.connection)
262
262
  unavailable();
263
+ // HQ's own agent tools run without asking: the bridge already scopes them to this session
264
+ const ownInput = session.agentBridge
265
+ ? readOwnToolInput(request.request, session.agentBridge.serverName)
266
+ : null;
267
+ if (ownInput) {
268
+ void session.connection
269
+ .write({
270
+ type: 'control_response',
271
+ response: {
272
+ subtype: 'success',
273
+ request_id: request.request_id,
274
+ response: { behavior: 'allow', updatedInput: ownInput },
275
+ },
276
+ })
277
+ .catch(() => events?.unavailable(session.id));
278
+ return;
279
+ }
263
280
  const parsed = createClaudePrompt(request.request, session.id, input.id, session.scope, request.request_id, async (message) => {
264
281
  const pending = session.requests.get(request.request_id);
265
282
  if (session.input !== input || !pending || pending.isWritten)
@@ -14,6 +14,7 @@ export declare class ClaudeHistoryModel {
14
14
  * @returns A validated result or a private marker requesting another bounded indexing batch.
15
15
  * @throws
16
16
  * - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
17
+ * - JG_AGENT_HQ_IMAGE_UNAVAILABLE: The HQ image is unavailable
17
18
  * - JG_AGENT_HQ_CURSOR_INVALID: The HQ cursor does not match this request
18
19
  * - JG_AGENT_HQ_PROVIDER_FAILED: The HQ provider integration failed
19
20
  */
@@ -21,6 +22,22 @@ export declare class ClaudeHistoryModel {
21
22
  /** Releases incomplete discovery iterators before the worker closes SQLite. */
22
23
  close(): void;
23
24
  private __read;
25
+ /**
26
+ * Reads one visible item of a turn with its detail. A tool result, or a `!` shell output, is
27
+ * paired with the call it answers among its nearest ancestors in the turn.
28
+ * @returns The detail, or null when the turn holds no such visible item.
29
+ */
30
+ private __itemDetail;
31
+ /**
32
+ * Reads one image a visible item of a turn holds in its record.
33
+ * @returns The image.
34
+ * @throws
35
+ * - JG_AGENT_HQ_IMAGE_UNAVAILABLE: The HQ image is unavailable
36
+ * - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
37
+ */
38
+ private __itemImage;
39
+ private __entry;
40
+ private __readEntry;
24
41
  private __summary;
25
42
  private __evidence;
26
43
  private __parseCursor;
@@ -3,10 +3,10 @@ import { closeSync, fstatSync, opendirSync, readSync } from 'node:fs';
3
3
  import { Exception, extractMessage, hasErrorCode, isException } from 'jg-exception';
4
4
  import { z } from 'zod';
5
5
  import { HqResponseSchema, } from '../../../contracts/index.js';
6
- import { decodeHistoryCursor, encodeHistoryCursor, } from '../../../sessions/index.js';
6
+ import { decodeBase64Image, decodeHistoryCursor, encodeHistoryCursor, imageUnavailable, } from '../../../sessions/index.js';
7
7
  import { evidencePosition, buildEvidencePage, EVIDENCE_SOURCE_PAGE_SIZE, } from '../../../sessions/evidence/index.js';
8
8
  import { EntryRowSchema, EntrySeekSchema, FileRowSchema, RecordSchema, ApiRequestMetadataSchema, SeekSchema, } from './types.js';
9
- import { isClaudeWorkspaceCwd, openTranscript, projectDirectory, toClaudeItem, } from './utilities.js';
9
+ import { isClaudeAnswer, isClaudeCallFor, isClaudeWorkspaceCwd, openTranscript, projectDirectory, toClaudeDetail, toClaudeImageData, toClaudeItem, } from './utilities.js';
10
10
  // identifies the path and record interpretation used by persisted projection entries
11
11
  const HISTORY_PROJECTION_VERSION = 5;
12
12
  // one record, such as a tool result holding images, and an indexing read, which fits the largest
@@ -16,6 +16,8 @@ const MAX_REFRESH_BYTES = 16_777_216;
16
16
  const MAX_PAGE_BYTES = 4_194_304;
17
17
  // hidden records awaiting a parent later in the file; Claude Code writes them a few lines early
18
18
  const MAX_HELD_BACK_RECORDS = 64;
19
+ // the ancestors a result's call is looked for in, enough for 16 parallel calls and their results
20
+ const MAX_CALL_DISTANCE = 32;
19
21
  const CHAIN = `WITH RECURSIVE current_chain AS (
20
22
  SELECT workspace_root, native_id, uuid, parent_uuid, turn_id, byte_offset, byte_length, created_at, is_visible
21
23
  FROM hq_claude_entry WHERE workspace_root = ? AND native_id = ? AND uuid = ?
@@ -40,6 +42,7 @@ export class ClaudeHistoryModel {
40
42
  * @returns A validated result or a private marker requesting another bounded indexing batch.
41
43
  * @throws
42
44
  * - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
45
+ * - JG_AGENT_HQ_IMAGE_UNAVAILABLE: The HQ image is unavailable
43
46
  * - JG_AGENT_HQ_CURSOR_INVALID: The HQ cursor does not match this request
44
47
  * - JG_AGENT_HQ_PROVIDER_FAILED: The HQ provider integration failed
45
48
  */
@@ -48,6 +51,8 @@ export class ClaudeHistoryModel {
48
51
  command.kind !== 'thread' &&
49
52
  command.kind !== 'turns' &&
50
53
  command.kind !== 'items' &&
54
+ command.kind !== 'item-detail' &&
55
+ command.kind !== 'item-image' &&
51
56
  command.kind !== 'session-evidence') ||
52
57
  command.provider !== 'claude')
53
58
  throw new Exception('The Claude history is unavailable', {
@@ -77,7 +82,9 @@ export class ClaudeHistoryModel {
77
82
  }
78
83
  __read(command) {
79
84
  const root = command.workspaceRoot;
80
- const { cursor, ...filters } = command.kind === 'thread' ? { ...command, cursor: undefined } : command;
85
+ const { cursor, ...filters } = command.kind === 'thread' || command.kind === 'item-detail' || command.kind === 'item-image'
86
+ ? { ...command, cursor: undefined }
87
+ : command;
81
88
  const continuation = command.kind === 'session-evidence' ? undefined : decodeHistoryCursor(cursor, filters);
82
89
  if (command.kind === 'session-evidence')
83
90
  evidencePosition(command);
@@ -127,6 +134,16 @@ export class ClaudeHistoryModel {
127
134
  return { kind: 'thread', result: this.__summary(row) };
128
135
  if (command.kind === 'session-evidence')
129
136
  return { kind: 'session-evidence', result: this.__evidence(command, row, directory) };
137
+ if (command.kind === 'item-detail')
138
+ return HqResponseSchema.parse({
139
+ kind: 'item-detail',
140
+ result: this.__itemDetail(command, row, directory),
141
+ });
142
+ if (command.kind === 'item-image')
143
+ return HqResponseSchema.parse({
144
+ kind: 'item-image',
145
+ result: this.__itemImage(command, row, directory),
146
+ });
130
147
  const seek = continuation ? this.__parseCursor(EntrySeekSchema, continuation) : undefined;
131
148
  if (seek && seek.revision !== row.revision)
132
149
  throw new Exception('The HQ cursor does not match this request', {
@@ -221,6 +238,86 @@ export class ClaudeHistoryModel {
221
238
  closeSync(fd);
222
239
  }
223
240
  }
241
+ /**
242
+ * Reads one visible item of a turn with its detail. A tool result, or a `!` shell output, is
243
+ * paired with the call it answers among its nearest ancestors in the turn.
244
+ * @returns The detail, or null when the turn holds no such visible item.
245
+ */
246
+ __itemDetail(command, row, directory) {
247
+ const root = command.workspaceRoot;
248
+ const entry = this.__entry(root, command.nativeId, command.nativeItemId);
249
+ if (!entry || entry.is_visible !== 1 || entry.turn_id !== command.turnId)
250
+ return null;
251
+ const fd = openTranscript(directory, command.nativeId);
252
+ try {
253
+ if (this.__identity(fd) !== row.identity || fstatSync(fd).size < row.file_size)
254
+ this.__unavailable();
255
+ const record = this.__readEntry(fd, entry, root);
256
+ const item = toClaudeItem(record, entry.turn_id) ?? this.__unavailable();
257
+ let call = null;
258
+ if (isClaudeAnswer(record, item)) {
259
+ let parent = entry.parent_uuid;
260
+ let budget = MAX_REFRESH_BYTES;
261
+ for (let step = 0; parent !== null && step < MAX_CALL_DISTANCE; step += 1) {
262
+ const ancestor = this.__entry(root, command.nativeId, parent);
263
+ if (!ancestor || ancestor.turn_id !== entry.turn_id || ancestor.byte_length > budget)
264
+ break;
265
+ budget -= ancestor.byte_length;
266
+ const candidate = this.__readEntry(fd, ancestor, root);
267
+ if (isClaudeCallFor(candidate, item)) {
268
+ call = candidate;
269
+ break;
270
+ }
271
+ parent = ancestor.parent_uuid;
272
+ }
273
+ }
274
+ return { item, ...toClaudeDetail(record, call) };
275
+ }
276
+ finally {
277
+ closeSync(fd);
278
+ }
279
+ }
280
+ /**
281
+ * Reads one image a visible item of a turn holds in its record.
282
+ * @returns The image.
283
+ * @throws
284
+ * - JG_AGENT_HQ_IMAGE_UNAVAILABLE: The HQ image is unavailable
285
+ * - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
286
+ */
287
+ __itemImage(command, row, directory) {
288
+ const root = command.workspaceRoot;
289
+ const entry = this.__entry(root, command.nativeId, command.nativeItemId);
290
+ if (!entry || entry.is_visible !== 1 || entry.turn_id !== command.turnId)
291
+ return imageUnavailable();
292
+ const fd = openTranscript(directory, command.nativeId);
293
+ try {
294
+ if (this.__identity(fd) !== row.identity || fstatSync(fd).size < row.file_size)
295
+ this.__unavailable();
296
+ const data = toClaudeImageData(this.__readEntry(fd, entry, root))[command.index];
297
+ return data ? decodeBase64Image(data) : imageUnavailable();
298
+ }
299
+ finally {
300
+ closeSync(fd);
301
+ }
302
+ }
303
+ // one current entry of a session's index, visible or not
304
+ __entry(root, nativeId, uuid) {
305
+ const entry = this.__database
306
+ .prepare(`SELECT uuid, parent_uuid, turn_id, byte_offset, byte_length, created_at, is_visible FROM hq_claude_entry
307
+ WHERE workspace_root = ? AND native_id = ? AND uuid = ? AND is_current = 1`)
308
+ .get(root, nativeId, uuid);
309
+ return entry === undefined ? null : EntryRowSchema.parse(entry);
310
+ }
311
+ // reads an entry's record, which must still be the one the index found there
312
+ __readEntry(fd, entry, root) {
313
+ const bytes = Buffer.alloc(entry.byte_length);
314
+ if (readSync(fd, bytes, 0, bytes.length, entry.byte_offset) !== bytes.length)
315
+ this.__unavailable();
316
+ const record = RecordSchema.parse(JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes)));
317
+ if (record.uuid !== entry.uuid || !isClaudeWorkspaceCwd(record.cwd, root))
318
+ this.__unavailable();
319
+ return record;
320
+ }
224
321
  __summary(row) {
225
322
  return {
226
323
  provider: 'claude',
@@ -3972,6 +3972,98 @@ export declare const ClaudeHistoryReadSchema: z.ZodUnion<readonly [z.ZodDiscrimi
3972
3972
  createdAt: z.ZodNullable<z.ZodNumber>;
3973
3973
  }, z.core.$strip>>;
3974
3974
  }, z.core.$strip>;
3975
+ }, z.core.$strip>, z.ZodObject<{
3976
+ kind: z.ZodLiteral<"item-detail">;
3977
+ result: z.ZodNullable<z.ZodObject<{
3978
+ item: z.ZodObject<{
3979
+ nativeId: z.ZodString;
3980
+ turnId: z.ZodString;
3981
+ nativeType: z.ZodString;
3982
+ kind: z.ZodEnum<{
3983
+ command: "command";
3984
+ unsupported: "unsupported";
3985
+ "user-message": "user-message";
3986
+ tool: "tool";
3987
+ "agent-message": "agent-message";
3988
+ "file-change": "file-change";
3989
+ notice: "notice";
3990
+ }>;
3991
+ provenance: z.ZodObject<{
3992
+ origin: z.ZodEnum<{
3993
+ unknown: "unknown";
3994
+ operator: "operator";
3995
+ agent: "agent";
3996
+ tool: "tool";
3997
+ system: "system";
3998
+ }>;
3999
+ source: z.ZodEnum<{
4000
+ unknown: "unknown";
4001
+ "native-kind": "native-kind";
4002
+ "host-action": "host-action";
4003
+ "authenticated-host-action": "authenticated-host-action";
4004
+ "agent-input": "agent-input";
4005
+ }>;
4006
+ nativeInputId: z.ZodNullable<z.ZodString>;
4007
+ actionId: z.ZodNullable<z.ZodUUID>;
4008
+ contentBoundary: z.ZodLiteral<"untrusted">;
4009
+ grantsAuthority: z.ZodLiteral<false>;
4010
+ }, z.core.$strip>;
4011
+ text: z.ZodString;
4012
+ isTruncated: z.ZodBoolean;
4013
+ callId: z.ZodNullable<z.ZodString>;
4014
+ outcome: z.ZodNullable<z.ZodEnum<{
4015
+ failed: "failed";
4016
+ succeeded: "succeeded";
4017
+ }>>;
4018
+ files: z.ZodArray<z.ZodObject<{
4019
+ path: z.ZodString;
4020
+ added: z.ZodNumber;
4021
+ removed: z.ZodNumber;
4022
+ }, z.core.$strip>>;
4023
+ createdAt: z.ZodNullable<z.ZodNumber>;
4024
+ }, z.core.$strip>;
4025
+ command: z.ZodNullable<z.ZodObject<{
4026
+ command: z.ZodNullable<z.ZodString>;
4027
+ output: z.ZodNullable<z.ZodString>;
4028
+ isOutputStartCut: z.ZodBoolean;
4029
+ exitCode: z.ZodNullable<z.ZodNumber>;
4030
+ durationMs: z.ZodNullable<z.ZodNumber>;
4031
+ }, z.core.$strip>>;
4032
+ tool: z.ZodNullable<z.ZodObject<{
4033
+ server: z.ZodNullable<z.ZodString>;
4034
+ name: z.ZodNullable<z.ZodString>;
4035
+ input: z.ZodNullable<z.ZodString>;
4036
+ result: z.ZodNullable<z.ZodString>;
4037
+ isResultStartCut: z.ZodBoolean;
4038
+ }, z.core.$strip>>;
4039
+ files: z.ZodArray<z.ZodObject<{
4040
+ path: z.ZodString;
4041
+ added: z.ZodNumber;
4042
+ removed: z.ZodNumber;
4043
+ diff: z.ZodString;
4044
+ }, z.core.$strip>>;
4045
+ images: z.ZodArray<z.ZodObject<{
4046
+ index: z.ZodNumber;
4047
+ mediaType: z.ZodNullable<z.ZodEnum<{
4048
+ "image/png": "image/png";
4049
+ "image/jpeg": "image/jpeg";
4050
+ "image/webp": "image/webp";
4051
+ "image/gif": "image/gif";
4052
+ }>>;
4053
+ byteCount: z.ZodNullable<z.ZodNumber>;
4054
+ }, z.core.$strip>>;
4055
+ }, z.core.$strip>>;
4056
+ }, z.core.$strip>, z.ZodObject<{
4057
+ kind: z.ZodLiteral<"item-image">;
4058
+ result: z.ZodObject<{
4059
+ mediaType: z.ZodEnum<{
4060
+ "image/png": "image/png";
4061
+ "image/jpeg": "image/jpeg";
4062
+ "image/webp": "image/webp";
4063
+ "image/gif": "image/gif";
4064
+ }>;
4065
+ data: z.ZodString;
4066
+ }, z.core.$strip>;
3975
4067
  }, z.core.$strip>, z.ZodObject<{
3976
4068
  kind: z.ZodLiteral<"usage">;
3977
4069
  result: z.ZodObject<{
@@ -1,4 +1,4 @@
1
- import { type IHistoryItem } from '../../../contracts/index.js';
1
+ import { type IHistoryItem, type IItemDetail } from '../../../contracts/index.js';
2
2
  import { type IRecord } from './types.js';
3
3
  /**
4
4
  * Resolves only the verified native project layout, without following directory links.
@@ -28,3 +28,33 @@ export declare const openTranscript: (directory: string, nativeId: string) => nu
28
28
  * - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
29
29
  */
30
30
  export declare const toClaudeItem: (record: IRecord, turnId: string, fullBody?: boolean) => IHistoryItem | null;
31
+ /**
32
+ * Lists the images a record holds, in its message and in its tool results' content, in order.
33
+ * @param record The record.
34
+ * @returns At most 64 images, each its base64 data, or null for one that has no base64 source.
35
+ */
36
+ export declare const toClaudeImageData: (record: IRecord) => (string | null)[];
37
+ /**
38
+ * Tells whether an item answers an earlier record of its turn: a tool result its call, or a `!`
39
+ * shell output the input it follows.
40
+ * @param record The item's record.
41
+ * @param item The item, as history presents it.
42
+ * @returns Whether the item has a call to pair it with.
43
+ */
44
+ export declare const isClaudeAnswer: (record: IRecord, item: IHistoryItem) => boolean;
45
+ /**
46
+ * Tells whether a record is the call an answering item follows.
47
+ * @param candidate The record, one of the item's ancestors.
48
+ * @param item The answering item.
49
+ * @returns Whether the record holds the item's tool call, or is the shell input it follows.
50
+ */
51
+ export declare const isClaudeCallFor: (candidate: IRecord, item: IHistoryItem) => boolean;
52
+ /**
53
+ * Reads what a developer inspects in one record beyond its display text: a Bash command or `!`
54
+ * shell input with its output, a tool call or result, an Edit or Write patch, and the images it
55
+ * holds. A result takes its command or tool name from the call it answers.
56
+ * @param record The item's record.
57
+ * @param call The call it answers, or null when it answers none or the call isn't found.
58
+ * @returns The detail's parts; the item itself comes from `toClaudeItem`.
59
+ */
60
+ export declare const toClaudeDetail: (record: IRecord, call: IRecord | null) => Omit<IItemDetail, "item">;