jg-agent-hq 13.1.4 → 13.2.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 (38) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +1 -1
  3. package/api/README.md +28 -22
  4. package/dist/actions/admission/admission.js +4 -4
  5. package/dist/actions/dispatch/dispatch.js +6 -2
  6. package/dist/actions/live/live.d.ts +2 -0
  7. package/dist/actions/live/live.js +22 -10
  8. package/dist/contracts/actions/types.d.ts +22 -0
  9. package/dist/contracts/actions/types.js +7 -2
  10. package/dist/contracts/browser/types.d.ts +22 -0
  11. package/dist/contracts/types.d.ts +22 -0
  12. package/dist/providers/claude/adapter.js +3 -2
  13. package/dist/providers/claude/control/constants.d.ts +1 -0
  14. package/dist/providers/claude/control/constants.js +8 -0
  15. package/dist/providers/claude/control/control.d.ts +1 -1
  16. package/dist/providers/claude/control/control.js +37 -26
  17. package/dist/providers/claude/control/index.d.ts +1 -0
  18. package/dist/providers/claude/control/index.js +2 -0
  19. package/dist/providers/claude/history/history.model.js +10 -5
  20. package/dist/providers/claude/history/types.d.ts +10 -0
  21. package/dist/providers/claude/history/types.js +16 -0
  22. package/dist/providers/claude/history/utilities.d.ts +26 -6
  23. package/dist/providers/claude/history/utilities.js +72 -19
  24. package/dist/providers/codex/adapter.js +5 -4
  25. package/dist/providers/codex/codex.js +16 -12
  26. package/dist/providers/codex/constants.d.ts +1 -0
  27. package/dist/providers/codex/constants.js +7 -0
  28. package/dist/providers/codex/types.d.ts +2 -1
  29. package/dist/providers/registry/registry.js +1 -1
  30. package/dist/providers/types.d.ts +12 -2
  31. package/dist/providers/utilities.d.ts +4 -3
  32. package/dist/providers/utilities.js +4 -3
  33. package/dist/sessions/evidence/origins.d.ts +2 -1
  34. package/dist/sessions/evidence/origins.js +2 -1
  35. package/dist/store/control/reads/reads.model.d.ts +1 -1
  36. package/dist/store/control/reads/reads.model.js +14 -3
  37. package/errors/README.md +2 -0
  38. package/package.json +1 -1
@@ -1,4 +1,6 @@
1
1
  // persistent native controls
2
2
  export { createClaudeControl } from './control.js';
3
+ // qualified attachment types
4
+ export { CLAUDE_STEER_MEDIA_TYPES } from './constants.js';
3
5
  // skills
4
6
  export { toClaudeSkills } from './skills.js';
@@ -8,13 +8,13 @@ import { createRequestCursors, decodeBase64Image, imageUnavailable, } from '../.
8
8
  import { evidencePosition, buildEvidencePage, EVIDENCE_SOURCE_PAGE_SIZE, } from '../../../sessions/evidence/index.js';
9
9
  import { HQ_ERRORS } from '../../../errors/index.js';
10
10
  import { EntrySeekSchema, RecordSchema, ApiRequestMetadataSchema, SeekSchema, } from './types.js';
11
- import { isClaudeAnswer, isClaudeCallFor, isClaudeRecordCwd, isClaudeWorkspaceCwd, openTranscript, projectDirectory, readClaudeParentUuid, readContinuedIn, toClaudeDetail, toClaudeImageData, toClaudeItem, } from './utilities.js';
11
+ import { isClaudeAnswer, isClaudeCallFor, isClaudeRecordCwd, isClaudeWorkspaceCwd, openTranscript, projectDirectory, readClaudeParentUuid, readClaudeQueuedInput, readContinuedIn, toClaudeDetail, toClaudeImageData, toClaudeItem, } from './utilities.js';
12
12
  // an item page continues before its oldest record
13
13
  const itemCursors = createRequestCursors(EntrySeekSchema);
14
14
  // a thread page's continuation: the activity time and session ID of the last transcript listed
15
15
  const THREAD_CURSOR = /^(\d{1,16}):(.+)$/;
16
16
  // identifies the path and record interpretation used by persisted projection entries
17
- const HISTORY_PROJECTION_VERSION = 10;
17
+ const HISTORY_PROJECTION_VERSION = 12;
18
18
  // the transcripts whose continuing session is remembered, oldest dropped first
19
19
  const MAX_CONTINUED_ANSWERS = 1_024;
20
20
  // one record, such as a tool result holding images
@@ -779,13 +779,18 @@ export class ClaudeHistoryModel {
779
779
  const nativeParent = nativeParentUuid
780
780
  ? this.__statements.get(PARENT_TURN, root, nativeId, nativeParentUuid)
781
781
  : undefined;
782
+ // a message sent while a turn ran is an attachment that shows, though it starts no turn
783
+ const isQueuedInput = readClaudeQueuedInput(record) !== null;
782
784
  // the CLI's presentation decides what is shown, the kind evidence filters on and where turns start
783
- const item = record.message !== undefined && !record.isMeta ? toClaudeItem(record, record.uuid) : null;
785
+ const item = (record.message !== undefined || isQueuedInput) && !record.isMeta
786
+ ? toClaudeItem(record, record.uuid)
787
+ : null;
784
788
  const visible = item !== null;
785
789
  if (nativeParentUuid === record.uuid)
786
790
  this.__unavailable();
787
791
  if (nativeParentUuid && !nativeParent) {
788
- if (visible)
792
+ // an attachment may come a few lines before its parent, so a queued message waits like one
793
+ if (visible && !isQueuedInput)
789
794
  this.__unavailable();
790
795
  /*
791
796
  * A compaction's boundary has no parent and names the record before it, which is indexed
@@ -809,7 +814,7 @@ export class ClaudeHistoryModel {
809
814
  const parent = parentUuid === nativeParentUuid
810
815
  ? nativeParent
811
816
  : this.__statements.get(PARENT_TURN, root, nativeId, parentUuid);
812
- const textPrompt = item?.kind === 'user-message';
817
+ const textPrompt = item?.kind === 'user-message' && !isQueuedInput;
813
818
  const turnId = textPrompt
814
819
  ? record.uuid
815
820
  : typeof parent?.turn_id === 'string'
@@ -57,8 +57,18 @@ export declare const RecordSchema: z.ZodObject<{
57
57
  }, z.core.$strip>>;
58
58
  toolUseResult: z.ZodOptional<z.ZodUnknown>;
59
59
  sourceToolAssistantUUID: z.ZodOptional<z.ZodString>;
60
+ attachment: z.ZodOptional<z.ZodUnknown>;
60
61
  }, z.core.$strip>;
61
62
  export type IRecord = z.infer<typeof RecordSchema>;
63
+ export declare const QueuedPromptSchema: z.ZodObject<{
64
+ type: z.ZodLiteral<"queued_command">;
65
+ commandMode: z.ZodLiteral<"prompt">;
66
+ prompt: z.ZodUnion<readonly [z.ZodString, z.ZodTuple<[z.ZodObject<{
67
+ type: z.ZodLiteral<"text">;
68
+ text: z.ZodString;
69
+ }, z.core.$strip>], z.ZodUnknown>]>;
70
+ source_uuid: z.ZodUUID;
71
+ }, z.core.$strip>;
62
72
  export declare const FilePatchSchema: z.ZodObject<{
63
73
  filePath: z.ZodString;
64
74
  type: z.ZodOptional<z.ZodString>;
@@ -27,6 +27,22 @@ export const RecordSchema = z.object({
27
27
  toolUseResult: z.unknown().optional(),
28
28
  // the call a tool result answers, which Claude Code also writes as the result's parent
29
29
  sourceToolAssistantUUID: z.string().optional(),
30
+ // what an attachment record carries, such as a message queued while a turn ran
31
+ attachment: z.unknown().optional(),
32
+ });
33
+ /*
34
+ * A message sent while a turn ran, which Claude Code takes into that turn and records as a queued
35
+ * command attachment instead of a user record; `source_uuid` names the native input it came from.
36
+ * Other queued commands, such as background task notifications, aren't messages.
37
+ */
38
+ export const QueuedPromptSchema = z.object({
39
+ type: z.literal('queued_command'),
40
+ commandMode: z.literal('prompt'),
41
+ prompt: z.union([
42
+ z.string().min(1),
43
+ z.tuple([z.object({ type: z.literal('text'), text: z.string().min(1) })]).rest(z.unknown()),
44
+ ]),
45
+ source_uuid: z.uuid(),
30
46
  });
31
47
  // the file Claude Code records on an Edit or Write result; a created file's patch is empty
32
48
  export const FilePatchSchema = z.object({
@@ -60,19 +60,36 @@ export declare const deleteTranscript: (workspaceRoot: string, nativeId: string)
60
60
  * @returns The continuing session's ID, or null, including when a transcript can't be read.
61
61
  */
62
62
  export declare const readContinuedIn: (directory: string, nativeId: string) => string | null;
63
+ /**
64
+ * Reads the message a queued command attachment holds: input Claude Code took into a running turn,
65
+ * which it records as an attachment rather than a user record.
66
+ * @param record The record.
67
+ * @returns The message as a user record's content and the native input it came from, or null for
68
+ * any other record, such as a background task notification.
69
+ * @throws
70
+ * - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
71
+ */
72
+ export declare const readClaudeQueuedInput: (record: IRecord) => {
73
+ content: string | unknown[];
74
+ inputId: string | null;
75
+ } | null;
63
76
  /**
64
77
  * Presents one native record as the CLI shows it, shared by history pages, live items and
65
78
  * evidence. Outcome and files come from the full record, before the text is cut, and its time
66
- * from the record's `timestamp`.
79
+ * from the record's `timestamp`. A message queued while a turn ran shows as the user message it
80
+ * is, whose native input is the one Claude Code names.
67
81
  * @returns The item, or null for a record the CLI leaves out, such as thinking or a task notification.
68
82
  * @throws
69
83
  * - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
70
84
  */
71
- export declare const toClaudeItem: (record: IRecord, turnId: string, fullBody?: boolean) => IHistoryItem | null;
85
+ export declare const toClaudeItem: (native: IRecord, turnId: string, fullBody?: boolean) => IHistoryItem | null;
72
86
  /**
73
- * Lists the images a record holds, in its message and in its tool results' content, in order.
87
+ * Lists the images a record holds, in its message, a queued message included, and in its tool
88
+ * results' content, in order.
74
89
  * @param record The record.
75
90
  * @returns At most 64 images, each its base64 data, or null for one that has no base64 source.
91
+ * @throws
92
+ * - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
76
93
  */
77
94
  export declare const toClaudeImageData: (record: IRecord) => (string | null)[];
78
95
  /**
@@ -93,9 +110,12 @@ export declare const isClaudeCallFor: (candidate: IRecord, item: IHistoryItem) =
93
110
  /**
94
111
  * Reads what a developer inspects in one record beyond its display text: a Bash command or `!`
95
112
  * shell input with its output, a tool call or result, an Edit or Write patch, and the images it
96
- * holds. A result takes its command or tool name from the call it answers.
97
- * @param record The item's record.
113
+ * holds. A result takes its command or tool name from the call it answers, and a queued message
114
+ * reads as the user message it is.
115
+ * @param native The item's record.
98
116
  * @param call The call it answers, or null when it answers none or the call isn't found.
99
117
  * @returns The detail's parts; the item itself comes from `toClaudeItem`.
118
+ * @throws
119
+ * - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
100
120
  */
101
- export declare const toClaudeDetail: (record: IRecord, call: IRecord | null) => Omit<IItemDetail, "item">;
121
+ export declare const toClaudeDetail: (native: IRecord, call: IRecord | null) => Omit<IItemDetail, "item">;
@@ -9,7 +9,7 @@ import { MAX_ITEM_IMAGES, MAX_ITEM_TEXT_LENGTH, } from '../../../contracts/index
9
9
  import { countLines, describeBase64Image, keepTextEnd, toWholeFileDiff, } from '../../../sessions/index.js';
10
10
  import { nativeProvenance } from '../../../sessions/evidence/index.js';
11
11
  import { HQ_ERRORS } from '../../../errors/index.js';
12
- import { FilePatchSchema } from './types.js';
12
+ import { FilePatchSchema, QueuedPromptSchema } from './types.js';
13
13
  const EXCLUDED = new Set(['_archive', '_archives', '_backup', '_backups']);
14
14
  const hasExcludedSegment = (path) => path.split(sep).some((part) => EXCLUDED.has(part));
15
15
  /**
@@ -339,15 +339,16 @@ const toUserPresentation = (record, text) => {
339
339
  /*
340
340
  * The text a user record's input sent: its whole content, or its first block when that is text,
341
341
  * with a slash command or skill as the `/name args` that was sent, not the markup Claude records.
342
+ * Queued prompt text is already the original input and is never stripped as command markup.
342
343
  */
343
- const readInputText = (record) => {
344
+ const readInputText = (record, isQueuedInput = false) => {
344
345
  const content = record.message?.content;
345
346
  const first = Array.isArray(content) ? BlockSchema.safeParse(content[0]).data : undefined;
346
347
  const text = typeof content === 'string' ? content : first?.type === 'text' ? (first.text ?? null) : null;
347
- return text === null ? null : (readCommandText(text) ?? text);
348
+ return text === null || isQueuedInput ? text : (readCommandText(text) ?? text);
348
349
  };
349
350
  /** Presents a native record as the CLI shows it, or null for one it leaves out. */
350
- const toPresentation = (record) => {
351
+ const toPresentation = (record, isQueuedInput = false) => {
351
352
  const base = { nativeType: record.type, callId: null, outcome: null, files: [] };
352
353
  if (record.type !== 'user' && record.type !== 'assistant')
353
354
  return { ...base, kind: 'unsupported', text: UNSUPPORTED };
@@ -371,9 +372,11 @@ const toPresentation = (record) => {
371
372
  if (record.isCompactSummary)
372
373
  return { ...base, kind: 'notice', text: text ?? UNSUPPORTED };
373
374
  if (text !== undefined)
374
- return record.type === 'user'
375
- ? toUserPresentation(record, text)
376
- : { ...base, kind: 'agent-message', text };
375
+ return isQueuedInput
376
+ ? { ...base, kind: 'user-message', text }
377
+ : record.type === 'user'
378
+ ? toUserPresentation(record, text)
379
+ : { ...base, kind: 'agent-message', text };
377
380
  if (blocks.every((block) => block?.type === 'tool_result')) {
378
381
  const patch = FilePatchSchema.safeParse(record.toolUseResult);
379
382
  return {
@@ -386,7 +389,9 @@ const toPresentation = (record) => {
386
389
  outcome: blocks.some((block) => block.is_error) ? 'failed' : 'succeeded',
387
390
  };
388
391
  }
389
- const calls = blocks.filter((block) => block?.type === 'tool_use' && block.name);
392
+ const calls = isQueuedInput
393
+ ? []
394
+ : blocks.filter((block) => block?.type === 'tool_use' && block.name);
390
395
  return {
391
396
  ...base,
392
397
  kind: calls.length > 0 ? 'tool' : message,
@@ -405,20 +410,59 @@ const toPresentation = (record) => {
405
410
  callId: calls.length === 1 ? (calls[0].id ?? null) : null,
406
411
  };
407
412
  };
413
+ /**
414
+ * Reads the message a queued command attachment holds: input Claude Code took into a running turn,
415
+ * which it records as an attachment rather than a user record.
416
+ * @param record The record.
417
+ * @returns The message as a user record's content and the native input it came from, or null for
418
+ * any other record, such as a background task notification.
419
+ * @throws
420
+ * - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
421
+ */
422
+ export const readClaudeQueuedInput = (record) => {
423
+ if (record.type !== 'attachment' || record.isMeta)
424
+ return null;
425
+ const header = z
426
+ .object({ type: z.string(), commandMode: z.unknown().optional() })
427
+ .safeParse(record.attachment);
428
+ if (!header.success || header.data.type !== 'queued_command')
429
+ return null;
430
+ if (typeof header.data.commandMode === 'string' && header.data.commandMode !== 'prompt')
431
+ return null;
432
+ const queued = QueuedPromptSchema.safeParse(record.attachment);
433
+ if (!queued.success || !z.uuid().safeParse(record.uuid).success)
434
+ throw HQ_ERRORS.create('claudeHistoryUnavailable', { data: { kind: 'agent-unavailable' } });
435
+ return { content: queued.data.prompt, inputId: queued.data.source_uuid };
436
+ };
437
+ /**
438
+ * Presents a queued prompt as its user record while retaining the graph identity.
439
+ * @returns The normalized message record, or the original non-prompt record.
440
+ * @throws
441
+ * - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
442
+ */
443
+ const toMessageRecord = (record) => {
444
+ const queued = readClaudeQueuedInput(record);
445
+ return queued
446
+ ? { ...record, type: 'user', message: { role: 'user', content: queued.content } }
447
+ : record;
448
+ };
408
449
  /**
409
450
  * Presents one native record as the CLI shows it, shared by history pages, live items and
410
451
  * evidence. Outcome and files come from the full record, before the text is cut, and its time
411
- * from the record's `timestamp`.
452
+ * from the record's `timestamp`. A message queued while a turn ran shows as the user message it
453
+ * is, whose native input is the one Claude Code names.
412
454
  * @returns The item, or null for a record the CLI leaves out, such as thinking or a task notification.
413
455
  * @throws
414
456
  * - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
415
457
  */
416
- export const toClaudeItem = (record, turnId, fullBody = false) => {
417
- if (!record.uuid)
458
+ export const toClaudeItem = (native, turnId, fullBody = false) => {
459
+ if (!native.uuid)
418
460
  throw HQ_ERRORS.create('claudeHistoryUnavailable', {
419
461
  data: { kind: 'agent-unavailable' },
420
462
  });
421
- const presentation = toPresentation(record);
463
+ const queued = readClaudeQueuedInput(native);
464
+ const record = toMessageRecord(native);
465
+ const presentation = toPresentation(record, queued !== null);
422
466
  if (!presentation)
423
467
  return null;
424
468
  const { text } = presentation;
@@ -428,10 +472,10 @@ export const toClaudeItem = (record, turnId, fullBody = false) => {
428
472
  const createdAt = Date.parse(record.timestamp ?? '');
429
473
  return {
430
474
  ...presentation,
431
- nativeId: record.uuid,
475
+ nativeId: native.uuid,
432
476
  turnId,
433
477
  provenance: presentation.kind === 'user-message'
434
- ? nativeProvenance(presentation.kind, record.uuid, readInputText(record))
478
+ ? nativeProvenance(presentation.kind, queued?.inputId ?? native.uuid, readInputText(record, queued !== null))
435
479
  : nativeProvenance(presentation.kind),
436
480
  text: text.slice(0, end),
437
481
  isTruncated: end < text.length,
@@ -495,11 +539,14 @@ const toResultBody = (block) => Array.isArray(block.content)
495
539
  // a Bash call's command
496
540
  const toShellCommand = (input) => z.object({ command: z.string() }).safeParse(input).data?.command ?? null;
497
541
  /**
498
- * Lists the images a record holds, in its message and in its tool results' content, in order.
542
+ * Lists the images a record holds, in its message, a queued message included, and in its tool
543
+ * results' content, in order.
499
544
  * @param record The record.
500
545
  * @returns At most 64 images, each its base64 data, or null for one that has no base64 source.
546
+ * @throws
547
+ * - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
501
548
  */
502
- export const toClaudeImageData = (record) => toBlocks(record)
549
+ export const toClaudeImageData = (record) => toBlocks(toMessageRecord(record))
503
550
  .flatMap((block) => block.type === 'tool_result' && Array.isArray(block.content)
504
551
  ? block.content.flatMap((part) => BlockSchema.safeParse(part).data ?? [])
505
552
  : [block])
@@ -532,18 +579,24 @@ export const isClaudeCallFor = (candidate, item) => item.nativeType === 'tool-re
532
579
  /**
533
580
  * Reads what a developer inspects in one record beyond its display text: a Bash command or `!`
534
581
  * shell input with its output, a tool call or result, an Edit or Write patch, and the images it
535
- * holds. A result takes its command or tool name from the call it answers.
536
- * @param record The item's record.
582
+ * holds. A result takes its command or tool name from the call it answers, and a queued message
583
+ * reads as the user message it is.
584
+ * @param native The item's record.
537
585
  * @param call The call it answers, or null when it answers none or the call isn't found.
538
586
  * @returns The detail's parts; the item itself comes from `toClaudeItem`.
587
+ * @throws
588
+ * - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
539
589
  */
540
- export const toClaudeDetail = (record, call) => {
590
+ export const toClaudeDetail = (native, call) => {
591
+ const record = toMessageRecord(native);
541
592
  const detail = {
542
593
  command: null,
543
594
  tool: null,
544
595
  files: [],
545
596
  images: toImages(record),
546
597
  };
598
+ if (native.type === 'attachment' && readClaudeQueuedInput(native) !== null)
599
+ return detail;
547
600
  const text = toText(record);
548
601
  if (record.type === 'user' && text !== undefined) {
549
602
  const input = SHELL_INPUT.exec(text);
@@ -8,7 +8,7 @@ import { buildProviderCapabilities, MODEL_CATALOG_UNAVAILABLE, SUPPORTED_PROVIDE
8
8
  import { capabilityUnavailable } from '../registry/index.js';
9
9
  import { HQ_ERRORS } from '../../errors/index.js';
10
10
  import { createCodexProvider } from './codex.js';
11
- import { MAX_LOADED_THREAD_PAGES } from './constants.js';
11
+ import { CODEX_SUPPORTED_MEDIA_TYPES, MAX_LOADED_THREAD_PAGES } from './constants.js';
12
12
  import { createCodexEvents, toProviderThread } from './events.js';
13
13
  /**
14
14
  * Describes current Codex controls and lazily owns a connection to the shared app-server daemon.
@@ -187,7 +187,8 @@ export const createCodexProviderFactory = (extraSkillRoots, daemonLauncher) => (
187
187
  return buildProviderCapabilities({
188
188
  provider: 'codex',
189
189
  operations: { models },
190
- supportedMediaTypes: ['image/png', 'image/jpeg', 'image/webp', 'text/plain'],
190
+ supportedMediaTypes: CODEX_SUPPORTED_MEDIA_TYPES,
191
+ steerMediaTypes: CODEX_SUPPORTED_MEDIA_TYPES,
191
192
  configurationSchema: {
192
193
  session: z
193
194
  .json()
@@ -253,11 +254,11 @@ export const createCodexProviderFactory = (extraSkillRoots, daemonLauncher) => (
253
254
  resumeThread: async (requestId, nativeId, _workspaceRoot, _name, settings, call) => toProviderThread(await native.resumeThread(requestId, nativeId, settings, call.signal)),
254
255
  nameThread: (requestId, nativeId, name) => native.nameThread(requestId, nativeId, name),
255
256
  async validateInput(_nativeId, input) {
256
- if (input.files.some((file) => file.mediaType === 'application/pdf' || file.mediaType === 'image/gif'))
257
+ if (input.files.some((file) => !CODEX_SUPPORTED_MEDIA_TYPES.includes(file.mediaType)))
257
258
  capabilityUnavailable();
258
259
  },
259
260
  startTurn: (requestId, nativeId, text, skill, settings, files) => native.startTurn(requestId, nativeId, text, skill, settings, files),
260
- steer: (requestId, nativeId, expectedTurnId, text) => native.steer(requestId, nativeId, expectedTurnId, text),
261
+ steer: (requestId, nativeId, expectedTurnId, text, files) => native.steer(requestId, nativeId, expectedTurnId, text, files),
261
262
  interrupt: (requestId, nativeId, nativeTurnId) => native.interrupt(requestId, nativeId, nativeTurnId),
262
263
  cleanThread: (requestId, nativeId) => native.cleanTerminals(requestId, nativeId),
263
264
  async releaseThread(requestId, nativeId) {
@@ -5,7 +5,7 @@ import { MAX_PAGE_SIZE, } from '../../contracts/index.js';
5
5
  import { NativeIdSchema } from '../../contracts/identities/index.js';
6
6
  import { decodeBase64Image, imageUnavailable, readImageFile } from '../../sessions/index.js';
7
7
  import { HQ_ERRORS } from '../../errors/index.js';
8
- import { LOADED_THREADS_PAGE_SIZE, NO_ROLLOUT_MESSAGE, SKILL_HINT_READ_CONCURRENCY, } from './constants.js';
8
+ import { CODEX_SUPPORTED_MEDIA_TYPES, LOADED_THREADS_PAGE_SIZE, NO_ROLLOUT_MESSAGE, SKILL_HINT_READ_CONCURRENCY, } from './constants.js';
9
9
  import { createCodexRpc } from './rpc.js';
10
10
  import { NativeBucketSchema, NativeSkillsSchema, NativeItemPageSchema, NativeThreadPageSchema, NativeThreadSchema, NativeTurnPageSchema, NativeUsageSchema, NativeTurnSchema, } from './types.js';
11
11
  import { toHistoryItem, toImageSources, toItemDetail, toThreadSummary, toTurnSummary, toUsageSnapshot, } from './transformers.js';
@@ -13,6 +13,16 @@ import { parseNative } from './validations.js';
13
13
  import { toCodexModels } from './models/index.js';
14
14
  import { HOST_SKILL_SCOPE, readSkillHint, readSkillRoots, toCapabilityRoots, } from './skill-roots/index.js';
15
15
  import { toCodexConfiguration, toCodexServiceTier, toCodexSessionSettings, readCodexConfigurationObservation, } from './configuration/index.js';
16
+ /** Builds the same checked file items for turn start and Steer. */
17
+ const toFileItems = (files) => files.map((file) => file.mediaType === 'text/plain'
18
+ ? {
19
+ type: 'text',
20
+ text: `File ${file.path} (SHA-256 ${file.sha256}):\n${new TextDecoder('utf-8', { fatal: true }).decode(file.content)}`,
21
+ }
22
+ : {
23
+ type: 'image',
24
+ url: `data:${file.mediaType};base64,${Buffer.from(file.content).toString('base64')}`,
25
+ });
16
26
  /**
17
27
  * Connects native history, usage observations and explicitly admitted runtime controls.
18
28
  * @returns The owned adapter. Its caller must close it on shutdown.
@@ -377,24 +387,18 @@ export const createCodexProvider = async (extraSkillRoots = [], daemonLauncher =
377
387
  input: [
378
388
  { type: 'text', text },
379
389
  ...(skill ? [{ type: 'skill', name: skill.name, path: skill.path }] : []),
380
- ...files.map((file) => file.mediaType === 'text/plain'
381
- ? {
382
- type: 'text',
383
- text: `File ${file.path} (SHA-256 ${file.sha256}):\n${new TextDecoder('utf-8', { fatal: true }).decode(file.content)}`,
384
- }
385
- : {
386
- type: 'image',
387
- url: `data:${file.mediaType};base64,${Buffer.from(file.content).toString('base64')}`,
388
- }),
390
+ ...toFileItems(files),
389
391
  ],
390
392
  }, requestId)).turn;
391
393
  },
392
- async steer(requestId, nativeId, expectedTurnId, text) {
394
+ async steer(requestId, nativeId, expectedTurnId, text, files = []) {
395
+ if (files.some((file) => !CODEX_SUPPORTED_MEDIA_TYPES.includes(file.mediaType)))
396
+ throw HQ_ERRORS.create('capabilityUnavailable', { data: { kind: 'agent-unavailable' } });
393
397
  const result = parseNative(z.object({ turnId: z.literal(expectedTurnId) }), await connection.request('turn/steer', {
394
398
  threadId: nativeId,
395
399
  expectedTurnId,
396
400
  clientUserMessageId: requestId,
397
- input: [{ type: 'text', text }],
401
+ input: [{ type: 'text', text }, ...toFileItems(files)],
398
402
  }, requestId));
399
403
  return result.turnId;
400
404
  },
@@ -1,3 +1,4 @@
1
+ export declare const CODEX_SUPPORTED_MEDIA_TYPES: readonly string[];
1
2
  export declare const LOADED_THREADS_PAGE_SIZE = 128;
2
3
  export declare const MAX_LOADED_THREAD_PAGES = 8;
3
4
  export declare const SKILL_HINT_READ_CONCURRENCY = 8;
@@ -1,3 +1,10 @@
1
+ // file types accepted by both Codex turn start and Steer
2
+ export const CODEX_SUPPORTED_MEDIA_TYPES = [
3
+ 'image/png',
4
+ 'image/jpeg',
5
+ 'image/webp',
6
+ 'text/plain',
7
+ ];
1
8
  // threads read per page of the daemon's loaded threads, and the most pages one connection reads
2
9
  export const LOADED_THREADS_PAGE_SIZE = 128;
3
10
  export const MAX_LOADED_THREAD_PAGES = 8;
@@ -280,9 +280,10 @@ export type ICodexProvider = {
280
280
  * Steers only the required active native turn and verifies its response identity.
281
281
  * @returns The acknowledged native turn identity.
282
282
  * @throws
283
+ * - JG_AGENT_HQ_CAPABILITY_UNAVAILABLE: The HQ capability is unavailable
283
284
  * - JG_AGENT_HQ_CODEX_FAILED: The Codex integration failed
284
285
  */
285
- steer(requestId: string, nativeId: string, expectedTurnId: string, text: string): Promise<string>;
286
+ steer(requestId: string, nativeId: string, expectedTurnId: string, text: string, files?: IProviderInputFile[]): Promise<string>;
286
287
  /**
287
288
  * Requests interruption; its acknowledgement does not prove completion.
288
289
  * @returns A promise resolved after native interruption-request acknowledgement.
@@ -242,7 +242,7 @@ export const createProviderRegistry = (factories, allowedRoots, runtimeEpoch) =>
242
242
  nameThread: (requestId, nativeId, name) => invokeControl((call) => adapter.nameThread(requestId, nativeId, name, call)),
243
243
  validateInput: (nativeId, input) => invoke((call) => adapter.validateInput(nativeId, input, call)),
244
244
  startTurn: (requestId, nativeId, text, skill, settings, files) => invokeControl((call) => adapter.startTurn(requestId, nativeId, text, skill, settings, files, call)),
245
- steer: (requestId, nativeId, expectedTurnId, text) => invokeControl((call) => adapter.steer(requestId, nativeId, expectedTurnId, text, call)),
245
+ steer: (requestId, nativeId, expectedTurnId, text, files) => invokeControl((call) => adapter.steer(requestId, nativeId, expectedTurnId, text, files, call)),
246
246
  interrupt: (requestId, nativeId, nativeTurnId) => invokeControl((call) => adapter.interrupt(requestId, nativeId, nativeTurnId, call)),
247
247
  cleanThread: (requestId, nativeId) => invokeControl((call) => adapter.cleanThread(requestId, nativeId, call)),
248
248
  releaseThread: (requestId, nativeId) => invokeControl((call) => adapter.releaseThread(requestId, nativeId, call)),
@@ -219,8 +219,18 @@ export type IAgentProvider = {
219
219
  startTurn(requestId: string, nativeId: string, text: string, skill: INativeSkillInput | null, settings: ITurnSettings, files: IProviderInputFile[], call: IProviderCall): Promise<{
220
220
  id: string;
221
221
  }>;
222
- /** @returns The acknowledged active turn identity, without creating a new turn. */
223
- steer(requestId: string, nativeId: string, expectedTurnId: string, text: string, call: IProviderCall): Promise<string>;
222
+ /**
223
+ * Sends text and qualified attachments to the exact active turn.
224
+ * @returns The acknowledged active turn identity, without creating a new turn.
225
+ * @throws
226
+ * - JG_AGENT_HQ_ACTION_CONFLICT: The HQ action conflicts with its recorded state
227
+ * - JG_AGENT_HQ_CAPABILITY_UNAVAILABLE: The HQ capability is unavailable
228
+ * - JG_AGENT_HQ_PROVIDER_FAILED: The HQ provider integration failed
229
+ * - JG_AGENT_HQ_CODEX_FAILED: The Codex integration failed
230
+ * - JG_AGENT_HQ_CLAUDE_FAILED: The Claude integration failed
231
+ * - JG_AGENT_HQ_TRANSPORT_FAILED: The HQ transport failed
232
+ */
233
+ steer(requestId: string, nativeId: string, expectedTurnId: string, text: string, files: IProviderInputFile[], call: IProviderCall): Promise<string>;
224
234
  /** @returns Acknowledgement of the interruption request, without implying completion. */
225
235
  interrupt(requestId: string, nativeId: string, nativeTurnId: string, call: IProviderCall): Promise<void>;
226
236
  /** @returns Native cleanup acknowledgement for the selected owned session. */
@@ -20,12 +20,13 @@ export declare const parseActionRequest: (requestId: string) => {
20
20
  * Builds a provider's capabilities from its operation support and the input limits both providers
21
21
  * share.
22
22
  * @param overrides The provider, the operations its native CLI reports now, the media types it
23
- * accepts, and its configuration schema.
23
+ * accepts at turn start and during steering, and its configuration schema.
24
24
  * @returns The provider's capability set.
25
25
  */
26
- export declare const buildProviderCapabilities: ({ provider, operations, supportedMediaTypes, configurationSchema, }: {
26
+ export declare const buildProviderCapabilities: ({ provider, operations, supportedMediaTypes, steerMediaTypes, configurationSchema, }: {
27
27
  provider: IProviderId;
28
28
  operations: Partial<IProviderCapabilitySet["operations"]>;
29
- supportedMediaTypes: string[];
29
+ supportedMediaTypes: readonly string[];
30
+ steerMediaTypes: readonly string[];
30
31
  configurationSchema: IProviderCapabilitySet["configurationSchema"];
31
32
  }) => IProviderCapabilitySet;
@@ -23,14 +23,15 @@ export const parseActionRequest = (requestId) => {
23
23
  * Builds a provider's capabilities from its operation support and the input limits both providers
24
24
  * share.
25
25
  * @param overrides The provider, the operations its native CLI reports now, the media types it
26
- * accepts, and its configuration schema.
26
+ * accepts at turn start and during steering, and its configuration schema.
27
27
  * @returns The provider's capability set.
28
28
  */
29
- export const buildProviderCapabilities = ({ provider, operations, supportedMediaTypes, configurationSchema, }) => ({
29
+ export const buildProviderCapabilities = ({ provider, operations, supportedMediaTypes, steerMediaTypes, configurationSchema, }) => ({
30
30
  operations: { ...PROVIDER_OPERATIONS[provider], ...operations },
31
31
  inputSchema: {
32
32
  ...PROVIDER_INPUT_SCHEMA,
33
- supportedMediaTypes,
33
+ supportedMediaTypes: [...supportedMediaTypes],
34
+ steerMediaTypes: [...steerMediaTypes],
34
35
  maxFiles: MAX_INPUT_FILES,
35
36
  maxFileBytes: MAX_INPUT_FILE_BYTES,
36
37
  maxTextFileBytes: MAX_TEXT_FILE_BYTES,
@@ -3,7 +3,8 @@ import type { IStore } from '../../store/index.js';
3
3
  type IProvenanceItem = Pick<IHistoryItem, 'kind' | 'provenance'> & (Pick<IHistoryItem, 'turnId'> | Pick<IEvidenceItem, 'reference'>);
4
4
  /**
5
5
  * Replaces provider assertions with provenance verified against acknowledged native inputs.
6
- * Only input identities and hashes cross the worker boundary; message bodies stay in their owner.
6
+ * Only input identities and hashes cross the worker boundary; Claude queued prompts use their
7
+ * source UUID, independently of the transcript's graph UUID. Bodies stay in their owner.
7
8
  * @param items Fresh presentation rows, including full-input fingerprints before preview cuts.
8
9
  * @param provider The provider whose native session supplied the rows.
9
10
  * @param nativeId The selected native session.
@@ -2,7 +2,8 @@ import { parseActionRequest } from '../../providers/index.js';
2
2
  import { resetProvenance } from './utilities.js';
3
3
  /**
4
4
  * Replaces provider assertions with provenance verified against acknowledged native inputs.
5
- * Only input identities and hashes cross the worker boundary; message bodies stay in their owner.
5
+ * Only input identities and hashes cross the worker boundary; Claude queued prompts use their
6
+ * source UUID, independently of the transcript's graph UUID. Bodies stay in their owner.
6
7
  * @param items Fresh presentation rows, including full-input fingerprints before preview cuts.
7
8
  * @param provider The provider whose native session supplied the rows.
8
9
  * @param nativeId The selected native session.
@@ -8,7 +8,7 @@ export declare class ControlReads extends ControlModel {
8
8
  getAction(id: string): IActionReceipt | null;
9
9
  /**
10
10
  * Resolves exact native input identities and content hashes; native roles grant no identity.
11
- * An input matches the action and phase its native ID names, or the turn it started.
11
+ * Claude steers name their action UUID while retaining the original target turn.
12
12
  */
13
13
  getEvidenceOrigins(command: IEvidenceOriginsRequest): (IHistoryProvenance | null)[];
14
14
  /** Returns one control record by immutable identity. */
@@ -9,17 +9,28 @@ export class ControlReads extends ControlModel {
9
9
  }
10
10
  /**
11
11
  * Resolves exact native input identities and content hashes; native roles grant no identity.
12
- * An input matches the action and phase its native ID names, or the turn it started.
12
+ * Claude steers name their action UUID while retaining the original target turn.
13
13
  */
14
14
  getEvidenceOrigins(command) {
15
+ const selection = `SELECT a.id, (SELECT b.id FROM agent_hq_browser_action b WHERE b.native_action_id = a.id AND b.native_thread_id = a.thread_id AND b.native_input_sha256 = a.input_sha256) AS browser_action_id
16
+ FROM agent_hq_action a JOIN agent_hq_thread t ON t.id = a.thread_id`;
15
17
  return command.items.map((item) => {
16
18
  if (item.nativeInputId === null || item.sha256 === null)
17
19
  return null;
18
- const rows = this._statements.all(`SELECT a.id, (SELECT b.id FROM agent_hq_browser_action b WHERE b.native_action_id = a.id AND b.native_thread_id = a.thread_id AND b.native_input_sha256 = a.input_sha256) AS browser_action_id
19
- FROM agent_hq_action a JOIN agent_hq_thread t ON t.id = a.thread_id
20
+ const rows = this._statements.all(`${selection}
20
21
  WHERE t.provider = ? AND t.native_id = ? AND a.native_turn_id = ? AND a.input_sha256 = ?
21
22
  AND a.delivery = 'acknowledged' AND ((a.id = ? AND a.phase = ?) OR a.native_turn_id = ?)
22
23
  ORDER BY a.id LIMIT 2`, command.provider, command.nativeId, item.turnId, item.sha256, item.request?.actionId ?? null, item.request?.phase ?? null, item.nativeInputId);
24
+ if (command.provider === 'claude') {
25
+ const steer = this._statements.get(`${selection}
26
+ WHERE a.id = ? AND t.provider = 'claude' AND t.native_id = ?
27
+ AND a.kind = 'steer' AND a.phase = 'steer' AND a.delivery = 'acknowledged'
28
+ AND a.native_turn_id IS NOT NULL AND a.native_turn_id = a.expected_turn_id
29
+ AND a.input_sha256 = ? AND (a.native_turn_id = ? OR a.id = ?)
30
+ LIMIT 1`, item.nativeInputId, command.nativeId, item.sha256, item.turnId, item.turnId);
31
+ if (steer && !rows.some((row) => row.id === steer.id))
32
+ rows.push(steer);
33
+ }
23
34
  if (rows.length !== 1)
24
35
  return null;
25
36
  const row = rows[0];
package/errors/README.md CHANGED
@@ -55,6 +55,8 @@ An `action-wait` reuses TARGET_FORBIDDEN as `receipt` does, and RUNTIME_NOT_RUNN
55
55
 
56
56
  Input-file admission reuses REQUEST_INVALID for invalid media, malformed UTF-8 and byte/count limits, and TARGET_FORBIDDEN for root or symlink escapes. A changed or missing content-bound file uses ACTION_CONFLICT before native submission; no input is replayed. Unsupported provider media or live output-schema changes use CAPABILITY_UNAVAILABLE. Schema mismatch, missing final output and result overflow are explicit receipt-result classifications rather than new exception codes. Native rejection and transport uncertainty retain the existing provider/action contracts.
57
57
 
58
+ Steer files use the same admission, content-binding and pre-send checks. Types outside the provider's `inputSchema.steerMediaTypes`, including Claude PDFs, use CAPABILITY_UNAVAILABLE before any native write, rejecting the complete input. An invalid internal Claude `<action UUID>:steer` request identity uses ACTION_CONFLICT before writing. A recognized malformed visible Claude queued prompt, including an unverifiable graph/source UUID or original first text block, uses CLAUDE_HISTORY_UNAVAILABLE; unsupported non-prompt attachment kinds remain hidden.
59
+
58
60
  Native form replies reuse REQUEST_INVALID for content outside the exact requested schema or response kind. Stale, expired, cross-thread or already answered request identities use ACTION_CONFLICT. Native writes without matching consumption evidence remain submitted or uncertain; expiry never proves a response was rejected. Unsupported native request variants are denied on their own native channel without granting permission.
59
61
 
60
62
  ## Public error messages
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jg-agent-hq",
3
- "version": "13.1.4",
3
+ "version": "13.2.0",
4
4
  "description": "Native Claude Code and Codex session control, history, usage and recoverable local storage for Node.js apps.",
5
5
  "type": "module",
6
6
  "license": "MIT",