jg-agent-hq 13.1.3 → 13.1.5
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/CHANGELOG.md +10 -0
- package/README.md +1 -1
- package/api/README.md +4 -4
- package/dist/actions/dispatch/dispatch.js +2 -0
- package/dist/actions/live/live.d.ts +4 -0
- package/dist/actions/live/live.js +25 -10
- package/dist/actions/reads.js +2 -1
- package/dist/contracts/browser/types.d.ts +1 -0
- package/dist/contracts/evidence/types.d.ts +3 -0
- package/dist/contracts/evidence/types.js +1 -0
- package/dist/contracts/types.d.ts +11 -0
- package/dist/providers/claude/history/history.model.js +10 -5
- package/dist/providers/claude/history/types.d.ts +7 -0
- package/dist/providers/claude/history/types.js +13 -0
- package/dist/providers/claude/history/utilities.d.ts +20 -6
- package/dist/providers/claude/history/utilities.js +38 -11
- package/dist/sessions/evidence/index.d.ts +1 -0
- package/dist/sessions/evidence/index.js +2 -0
- package/dist/sessions/evidence/origins.d.ts +17 -0
- package/dist/sessions/evidence/origins.js +36 -0
- package/dist/sessions/index.d.ts +1 -0
- package/dist/sessions/index.js +2 -0
- package/dist/sessions/sessions.js +3 -27
- package/dist/store/control/reads/reads.model.js +4 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 13.1.5
|
|
4
|
+
|
|
5
|
+
- Show a message Claude Code takes into a running turn, such as a steer at a tool boundary, in that turn's saved history. Claude Code saves it as a `queued_command` attachment rather than a user record, so it was missing from history and its live row never flushed. It reads as a `user-message` whose `provenance.nativeInputId` is the input the attachment names; background task notifications stay hidden. The reader's projection revision changes, so existing transcripts are indexed again on their next read.
|
|
6
|
+
- Flush a live input once history holds the queued record that names it, matching its turn, kind and text.
|
|
7
|
+
|
|
8
|
+
## 13.1.4
|
|
9
|
+
|
|
10
|
+
- Correlate live user inputs against the same acknowledged native identity, turn and content fingerprint as saved history. Verified browser inputs also expose their original optional `browserActionId`, allowing an optimistic row to reconcile before the HTTP receipt arrives.
|
|
11
|
+
- Publish a fresh live-window revision when late native acknowledgement changes its provenance, without waiting for another output token or reading native history. Storage, action admission and historical provenance's lack of execution authority are unchanged.
|
|
12
|
+
|
|
3
13
|
## 13.1.3
|
|
4
14
|
|
|
5
15
|
- Keep native execution status visible for sessions with uncertain control ownership, including CLI sessions already running at startup and status changes after connection loss. Session reads, discovery and active lists retain the managed identity and uncertain ownership without joining the session, replaying input or releasing queued work.
|
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ Trusted Node hosts can open the database described by `hq.storage` with `openHos
|
|
|
59
59
|
|
|
60
60
|
`hq.createSnapshot(destination)` captures local state through SQLite's backup API while agents keep working, including host tables and action.key, under the state root's `snapshot` lock; the host keeps its own connections from writing host tables until it resolves. It leaves out the index of Claude transcripts, which a restored runtime rebuilds from the transcripts on its first Claude history read, as a fresh one does. `restoreHqSnapshot({ snapshotDirectory, destination })` verifies the complete snapshot and stages it into a new private recovery workspace. `packHqSnapshot(snapshotDirectory, archivePath, key)` encrypts a snapshot into one AES-256-GCM file for off-machine copies, and `unpackHqSnapshot(archivePath, destination, key)` verifies and writes it back as a snapshot directory. Snapshots from another schema are refused by the package version that wrote them. Restored native ownership needs reconciliation and allowed roots must be selected explicitly. Hosts own the key and remote backups; a failed disk can lose changes since the last successful off-machine backup. See [snapshot and restore](api/README.md#snapshot-and-restore) and [recovery](docs/recovery.md).
|
|
61
61
|
|
|
62
|
-
Sessions started in a terminal show up too. Codex sessions on the shared daemon and Claude sessions from `claude agents --json` report a live state (`running`, `waiting`, `idle`, `closed`, `failed` or `unknown`) with external ownership. jg-agent-hq builds on what each CLI offers and never stops, wakes or drives a session a terminal runs: it adopts a Codex session the terminal holds between turns, through the shared daemon, and a Claude session only once no terminal runs it, while a Claude session's `terminal` field names the terminal that does. Every state change of a managed or observed session is recorded in order, with the session's folder; read them with `{ kind: 'session-states', afterSequence }` or `session-states`, and add `waitMs` to wait up to 30 seconds for the next one. `live-items` waits the same way for a window's next change, and cuts its text to `textLimit`; both long-polls are woken by the runtime's own changes, never a timer. `active-sessions` lists every running and waiting session with its workspace, and `observation-pace` polls Claude every 5 seconds instead of 30 while a client follows sessions live. See [session states](api/README.md#session-states).
|
|
62
|
+
Sessions started in a terminal show up too. Codex sessions on the shared daemon and Claude sessions from `claude agents --json` report a live state (`running`, `waiting`, `idle`, `closed`, `failed` or `unknown`) with external ownership. jg-agent-hq builds on what each CLI offers and never stops, wakes or drives a session a terminal runs: it adopts a Codex session the terminal holds between turns, through the shared daemon, and a Claude session only once no terminal runs it, while a Claude session's `terminal` field names the terminal that does. Every state change of a managed or observed session is recorded in order, with the session's folder; read them with `{ kind: 'session-states', afterSequence }` or `session-states`, and add `waitMs` to wait up to 30 seconds for the next one. `live-items` waits the same way for a window's next change, and cuts its text to `textLimit`; both long-polls are woken by the runtime's own changes, never a timer. `active-sessions` lists every running and waiting session with its workspace, and `observation-pace` polls Claude every 5 seconds instead of 30 while a client follows sessions live. See [session states](api/README.md#session-states). Verified inputs in saved history and live windows link to their acknowledged native action; authenticated browser inputs also carry their original optional `browserActionId`. Late acknowledgement refreshes the live revision, allowing pending UI to reconcile without another output token.
|
|
63
63
|
|
|
64
64
|
The providers are `codex` and `claude`. Capabilities report current operation support, provider/session scope and unavailable reasons. Native version labels are diagnostic metadata and never determine admission. Unknown essential control data fails explicitly. `jg-agent-hq/contracts` contains browser-safe schemas and types; importing it does not import the host runtime.
|
|
65
65
|
|
package/api/README.md
CHANGED
|
@@ -196,7 +196,7 @@ Threads expose native state, the live session `state` described under [session s
|
|
|
196
196
|
|
|
197
197
|
Text chunks contain at most 32,768 UTF-8 bytes and shrink when escaping or metadata consumes the response budget. Cursors bind all query fields and the content of a partially consumed native page. Changed content, changed query scope or a changed Claude chain revision uses CURSOR_INVALID; start a fresh read rather than joining different evidence. New native pages use the provider's continuation, not an immutable transcript snapshot. Newly arriving or removed history may therefore require a fresh evidence read. Authorization is rechecked on every request before content access, and no alternate raw-file path bypasses a denial.
|
|
198
198
|
|
|
199
|
-
`HistoryItemSchema` and evidence fragments expose `provenance: { origin, source, nativeInputId, nativeInputSha256, actionId, contentBoundary: 'untrusted', grantsAuthority: false }`. Origins are operator, agent, tool, system or unknown. Native assistant/tool kinds establish only their observed category. A native user role, quoted operator text or an imported message cannot establish an operator. The runtime correlates a submitted input only when its exact native message/client identity, thread/turn and `nativeInputSha256` match the acknowledged action ledger. A provider's user message carries `nativeInputSha256`, the SHA-256 of the text its native input sent: a Codex message's first text part, or a Claude record's string content or first text block, with a slash command or skill, which Claude records as command markup, read back as the `/name args` it sent. It is hashed before the parts the same input added after the text, such as a skill or attached files, and before a page cuts the text, so those messages correlate too. Programmatic host submissions have source `host-action` and unknown actor. An authenticated browser submission additionally requires the same selected thread and text fingerprint, yielding `authenticated-host-action` and operator provenance. An explicit skill's fingerprint is its prepared invocation, the `$name args` or `/name args` the session received, which the browser submission takes once its action is admitted. A message without a native input identity, or whose sent text differs from the action's, stays unknown. Provenance remains historical evidence and grants no current approval, execution authority or tool permission; quotations remain inside its untrusted content boundary.
|
|
199
|
+
`HistoryItemSchema` and evidence fragments expose `provenance: { origin, source, nativeInputId, nativeInputSha256, actionId, contentBoundary: 'untrusted', grantsAuthority: false }`. Origins are operator, agent, tool, system or unknown. Native assistant/tool kinds establish only their observed category. A native user role, quoted operator text or an imported message cannot establish an operator. The runtime correlates a submitted input only when its exact native message/client identity, thread/turn and `nativeInputSha256` match the acknowledged action ledger. A provider's user message carries `nativeInputSha256`, the SHA-256 of the text its native input sent: a Codex message's first text part, or a Claude record's string content or first text block, with a slash command or skill, which Claude records as command markup, read back as the `/name args` it sent. It is hashed before the parts the same input added after the text, such as a skill or attached files, and before a page cuts the text, so those messages correlate too. Programmatic host submissions have source `host-action` and unknown actor. An authenticated browser submission additionally requires the same selected thread and text fingerprint, yielding `authenticated-host-action` and operator provenance. An explicit skill's fingerprint is its prepared invocation, the `$name args` or `/name args` the session received, which the browser submission takes once its action is admitted. A message without a native input identity, or whose sent text differs from the action's, stays unknown. Saved history and live windows apply the same ledger verification. A verified authenticated browser input additionally carries optional `browserActionId`, the original browser intent UUID, so clients can reconcile a local pending row before its POST response arrives. Unverified inputs never carry this field. A native acknowledgement that changes retained live provenance advances the window revision and wakes conditional live reads. Provenance remains historical evidence and grants no current approval, execution authority or tool permission; quotations remain inside its untrusted content boundary.
|
|
200
200
|
|
|
201
201
|
Codex uses its native descending item API with unloaded thread metadata. It never reads Codex transcript files. Claude uses indexed current-chain byte locations, exact UUID lookups and separate bounded seeks per selected kind. Its cold index uses 8 MiB batches and a 30-second operation budget; selected evidence reads parse at most 4 MiB of records beyond the first. Continuation revalidates and rereads one bounded native page to detect content changes rather than caching transcript bodies. Work and memory per read are bounded independently of history growth; reconstructing a large body may reread that source page. No conversation-body cache is maintained.
|
|
202
202
|
|
|
@@ -242,9 +242,9 @@ The existing SQLite worker incrementally records file identity, complete-line of
|
|
|
242
242
|
|
|
243
243
|
Current-chain membership and turn starts are indexed as metadata. Item continuations seek those indexes; they do not walk the full chain per page. A changed branch rebuilds membership before exposing that revision. Repeated native message identities can replace content while retaining their parent; a changed parent for the same identity is an unsupported format.
|
|
244
244
|
|
|
245
|
-
Selected history reads refresh only that file, retain incomplete tails, and detect truncation or replaced identity. Changed branch/file revisions invalidate item continuations. Only the current parent-linked conversation chain is returned. A compaction's boundary has no parent and names the record before it, which the chain follows back to the start of the conversation; when the transcript holds no such record before the boundary, as in a chat Claude Code moved into a new session, whose boundary names the old session's record, the chain starts at the boundary. Claude Code links each tool result to its own call, so parallel calls whose results finish out of order would leave the later calls and results on a side branch; such a result follows the latest record of its call's turn instead, keeping every call of the response and all their results on the chain without changing its revision. Text is reread from the native file for the selected page and normalized as plain text. Thinking blocks are left out, and a record holding only thinking is hidden, as are `<task-notification>` records and a subagent's sidechain records. Live items leave a subagent's stream frames out likewise, and those frames start no turn, though a subagent's tool results still settle the approvals it asked for. Compaction summaries, `<local-command-stdout>` output and interruption markers are `notice` items, and a slash command is a `user-message` reading `/name args`. A `!` shell input and its output are `command` items, the output's `callId` being the input's UUID. A tool call shows its native name and input, with the block's ID as `callId`, which is null for a record calling several tools; its result is a `tool` item carrying that ID, `failed` when it has `is_error` and `succeeded` otherwise. An Edit or Write result whose metadata has a `filePath` and a `structuredPatch` is a `file-change` item reading the path and its patch lines, or a created file's content, every line of which counts as added. A result Claude Code saved to a file reads `Output too large (<size>), saved to a file` followed by its preview, without the file's path. A result made of content blocks, such as a screenshot with its caption, reads as its text blocks, each image as `[Image]`. Other non-text content has explicit native block labels. The index stores each entry's presented kind and visibility, so evidence kind filters match `items` and hidden records never shorten a page. An unknown record containing content is returned as an `unsupported` item when its identity and chain are trustworthy; it cannot imply an agent response, idle state or completion. Each selected page reads at most 4 MiB of record bytes beyond its first record and returns at most 4 MiB of serialized item presentation, so a large-text page can contain fewer rows than its requested limit.
|
|
245
|
+
Selected history reads refresh only that file, retain incomplete tails, and detect truncation or replaced identity. Changed branch/file revisions invalidate item continuations. Only the current parent-linked conversation chain is returned. A compaction's boundary has no parent and names the record before it, which the chain follows back to the start of the conversation; when the transcript holds no such record before the boundary, as in a chat Claude Code moved into a new session, whose boundary names the old session's record, the chain starts at the boundary. Claude Code links each tool result to its own call, so parallel calls whose results finish out of order would leave the later calls and results on a side branch; such a result follows the latest record of its call's turn instead, keeping every call of the response and all their results on the chain without changing its revision. Text is reread from the native file for the selected page and normalized as plain text. Thinking blocks are left out, and a record holding only thinking is hidden, as are `<task-notification>` records and a subagent's sidechain records. A message Claude Code takes into a running turn, such as a steer it takes in at a tool boundary, is saved as a `queued_command` attachment instead of a user record; it is a `user-message` of that turn whose `provenance.nativeInputId` is the native input the attachment names, and other queued commands, such as background task notifications, stay hidden. Live items leave a subagent's stream frames out likewise, and those frames start no turn, though a subagent's tool results still settle the approvals it asked for. Compaction summaries, `<local-command-stdout>` output and interruption markers are `notice` items, and a slash command is a `user-message` reading `/name args`. A `!` shell input and its output are `command` items, the output's `callId` being the input's UUID. A tool call shows its native name and input, with the block's ID as `callId`, which is null for a record calling several tools; its result is a `tool` item carrying that ID, `failed` when it has `is_error` and `succeeded` otherwise. An Edit or Write result whose metadata has a `filePath` and a `structuredPatch` is a `file-change` item reading the path and its patch lines, or a created file's content, every line of which counts as added. A result Claude Code saved to a file reads `Output too large (<size>), saved to a file` followed by its preview, without the file's path. A result made of content blocks, such as a screenshot with its caption, reads as its text blocks, each image as `[Image]`. Other non-text content has explicit native block labels. The index stores each entry's presented kind and visibility, so evidence kind filters match `items` and hidden records never shorten a page. An unknown record containing content is returned as an `unsupported` item when its identity and chain are trustworthy; it cannot imply an agent response, idle state or completion. Each selected page reads at most 4 MiB of record bytes beyond its first record and returns at most 4 MiB of serialized item presentation, so a large-text page can contain fewer rows than its requested limit.
|
|
246
246
|
|
|
247
|
-
File timestamps and records do not prove that a native process is idle or a turn completed. Claude file-backed thread and turn states are therefore `unknown`, with no invented completion timestamp. Explicit native custom titles are preserved; a missing title remains null. A turn starts at a message the operator sends, including a slash command; task notifications, compaction summaries, local command output, interruption markers and `!` shell records belong to the turn before them. Grouping follows parent links and is not an authoritative execution boundary. A compaction starts a new chain whose first record names the record before it, so history reads on past the compaction to the start of the conversation.
|
|
247
|
+
File timestamps and records do not prove that a native process is idle or a turn completed. Claude file-backed thread and turn states are therefore `unknown`, with no invented completion timestamp. Explicit native custom titles are preserved; a missing title remains null. A turn starts at a message the operator sends, including a slash command, except a message taken into a running turn, which belongs to it; task notifications, compaction summaries, local command output, interruption markers and `!` shell records belong to the turn before them. Grouping follows parent links and is not an authoritative execution boundary. A compaction starts a new chain whose first record names the record before it, so history reads on past the compaction to the start of the conversation.
|
|
248
248
|
|
|
249
249
|
## Thread control and live input
|
|
250
250
|
|
|
@@ -369,7 +369,7 @@ The installed CLI exposes `suggest-thread-name --topic <topic>`. Suggestions nor
|
|
|
369
369
|
|
|
370
370
|
Control pages default to 32 and cap at 128. Seek cursors are bound to their complete query and ordering. Reads recheck allowed workspaces. Rejected controls retain their known thread association, and native availability failures appear in each affected thread's replay. Lifecycle replay contains metadata, not token or tool output. Each provider has a bounded native lifecycle backlog; overflow stops that source and marks its state uncertain rather than losing events silently. Live items don't count toward it. The runtime recognizes a repeated lifecycle observation within one runtime; startup forgets the observations earlier runtimes recorded. Other providers retain their independent connection and admission state.
|
|
371
371
|
|
|
372
|
-
Live item presentation is bounded to 128 items per cached thread, 32 windows and 4 MiB of serialized presentation across the runtime, including escaped text and identifiers. This leaves room inside the IPC response limit. Display text uses the same truncation contract as native history. Eviction, an unavailable window or missing chunks sets `hasGap`. Completed items remain `awaiting-flush` after thread closure until a native history page holds the same item, with exactly matching normalized content or, for an item with an outcome, the same final outcome, or the bounded cache evicts them. The outcome is enough because Codex shortens long command output when it saves it. An item still streaming when its turn ended, such as a message an interrupt or a Codex steer cut, stays `awaiting-flush` until a native history page holds an item of that turn, since the provider may never save it; the history then shows what was saved of it. A client's `items` read is one such page, and when a turn ends the runtime reads that turn's own history too, newest first and at most 8 pages of 128, until none of its finished items remain, so the window doesn't wait on a client that never reads them. Codex's saved state can trail its turn's end, so a turn whose items remain is read once more 2 seconds later; a failed read leaves them to the next history read. A client that shows live items should therefore expect them to leave the window before its own history read holds them. Read persisted history and the live window together after reconnect; a process restart cannot reconstruct unflushed in-memory content.
|
|
372
|
+
Live item presentation is bounded to 128 items per cached thread, 32 windows and 4 MiB of serialized presentation across the runtime, including escaped text and identifiers. This leaves room inside the IPC response limit. Display text uses the same truncation contract as native history. Eviction, an unavailable window or missing chunks sets `hasGap`. Completed items remain `awaiting-flush` after thread closure until a native history page holds the same item, with exactly matching normalized content or, for an item with an outcome, the same final outcome, or the bounded cache evicts them. A message Claude Code saved as a queued command matches the live input its `provenance.nativeInputId` names. The outcome is enough because Codex shortens long command output when it saves it. An item still streaming when its turn ended, such as a message an interrupt or a Codex steer cut, stays `awaiting-flush` until a native history page holds an item of that turn, since the provider may never save it; the history then shows what was saved of it. A client's `items` read is one such page, and when a turn ends the runtime reads that turn's own history too, newest first and at most 8 pages of 128, until none of its finished items remain, so the window doesn't wait on a client that never reads them. Codex's saved state can trail its turn's end, so a turn whose items remain is read once more 2 seconds later; a failed read leaves them to the next history read. A client that shows live items should therefore expect them to leave the window before its own history read holds them. Read persisted history and the live window together after reconnect; a process restart cannot reconstruct unflushed in-memory content.
|
|
373
373
|
|
|
374
374
|
Items expose only normalized presentation fields, and one mapping per provider presents `items`, live items and `session-evidence` alike, as the provider's CLI shows them. Kinds are `user-message`, `agent-message`, `command`, `tool`, `file-change`, `notice` and `unsupported`. `callId` pairs a tool call with its result, or is null. `outcome` is `succeeded`, `failed`, or null when unknown or still running. `files` lists each file a file change touched, at most 128, with its added and removed lines, and is empty on other items. `outcome` and `files` come from the full native record, so `textLimit` never changes them. Unknown native kinds report `unsupported` without copying arbitrary payloads. Display text is bounded to 65,536 UTF-16 code units without splitting a surrogate pair; `isTruncated` reports omissions. An unsupported or oversized native transport frame fails explicitly. `createdAt` is the item's time in Unix milliseconds, or null when the provider records none. A Claude item takes its record's `timestamp`, and a live one the time its frame arrived. A Codex item takes its own native lifecycle timestamps, already in milliseconds: operator input prefers `startedAtMs`, and other items prefer `completedAtMs`, using the other item timestamp when the preferred one is missing. History entries and live notifications use the same mapping, with entry/notification metadata preferred over the matching embedded item field. Missing item timestamps remain null; turn times and observation times are never substituted. History pages and item details need no additional turn reads for timing.
|
|
375
375
|
|
|
@@ -66,6 +66,8 @@ export const createDispatch = (context) => {
|
|
|
66
66
|
if (!receipt?.threadId)
|
|
67
67
|
return receipt;
|
|
68
68
|
const thread = await store.call('reads', 'getThread', receipt.threadId);
|
|
69
|
+
if (thread?.nativeId && (outcome.kind === 'turn-accepted' || outcome.kind === 'steer-accepted'))
|
|
70
|
+
context.live.invalidateProvenance(context.key(thread.provider, thread.nativeId));
|
|
69
71
|
if (thread?.nativeId && outcome.kind === 'closed') {
|
|
70
72
|
controlled.delete(context.key(thread.provider, thread.nativeId));
|
|
71
73
|
watched.delete(context.key(thread.provider, thread.nativeId));
|
|
@@ -29,6 +29,8 @@ export declare class LiveItems {
|
|
|
29
29
|
backgroundKeys(): string[];
|
|
30
30
|
/** Marks missing native stream evidence without discarding the surviving presentation. */
|
|
31
31
|
markGap(nativeId: string): void;
|
|
32
|
+
/** Publishes a new revision when ledger evidence can change retained items' provenance. */
|
|
33
|
+
invalidateProvenance(nativeId: string): void;
|
|
32
34
|
/** Replaces an ephemeral stream identity when the native persisted identity arrives. */
|
|
33
35
|
replace(nativeId: string, turnId: string, itemId: string): void;
|
|
34
36
|
/** Appends bounded text; a truncated prefix is never presented as the complete item. */
|
|
@@ -48,6 +50,8 @@ export declare class LiveItems {
|
|
|
48
50
|
* content, or, for an item with an outcome, the same final outcome, since a provider can shorten
|
|
49
51
|
* long output when it saves it, as Codex does. An item its turn ended before the provider
|
|
50
52
|
* finished goes once persisted history holds that turn, which then shows what was saved of it.
|
|
53
|
+
* A message saved under another record than the live input it came from, as Claude Code saves a
|
|
54
|
+
* message sent while a turn ran, matches that input by the native input it names.
|
|
51
55
|
*/
|
|
52
56
|
reconcile(nativeId: string, persisted: IHistoryItem[]): void;
|
|
53
57
|
/**
|
|
@@ -89,6 +89,13 @@ export class LiveItems {
|
|
|
89
89
|
thread.revision = this.__change();
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
+
/** Publishes a new revision when ledger evidence can change retained items' provenance. */
|
|
93
|
+
invalidateProvenance(nativeId) {
|
|
94
|
+
const thread = this.__threads.get(nativeId);
|
|
95
|
+
if (thread &&
|
|
96
|
+
[...thread.items.values()].some(({ item }) => item.kind === 'user-message' && item.provenance.nativeInputId !== null))
|
|
97
|
+
thread.revision = this.__change();
|
|
98
|
+
}
|
|
92
99
|
/** Replaces an ephemeral stream identity when the native persisted identity arrives. */
|
|
93
100
|
replace(nativeId, turnId, itemId) {
|
|
94
101
|
const thread = this.__threads.get(nativeId);
|
|
@@ -145,6 +152,8 @@ export class LiveItems {
|
|
|
145
152
|
* content, or, for an item with an outcome, the same final outcome, since a provider can shorten
|
|
146
153
|
* long output when it saves it, as Codex does. An item its turn ended before the provider
|
|
147
154
|
* finished goes once persisted history holds that turn, which then shows what was saved of it.
|
|
155
|
+
* A message saved under another record than the live input it came from, as Claude Code saves a
|
|
156
|
+
* message sent while a turn ran, matches that input by the native input it names.
|
|
148
157
|
*/
|
|
149
158
|
reconcile(nativeId, persisted) {
|
|
150
159
|
const thread = this.__threads.get(nativeId);
|
|
@@ -158,16 +167,22 @@ export class LiveItems {
|
|
|
158
167
|
thread.revision = this.__change();
|
|
159
168
|
}
|
|
160
169
|
for (const item of persisted) {
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
170
|
+
const { nativeInputId } = item.provenance;
|
|
171
|
+
const liveIds = item.kind === 'user-message' && nativeInputId !== null && nativeInputId !== item.nativeId
|
|
172
|
+
? [item.nativeId, nativeInputId]
|
|
173
|
+
: [item.nativeId];
|
|
174
|
+
for (const liveId of liveIds) {
|
|
175
|
+
const key = JSON.stringify([item.turnId, liveId]);
|
|
176
|
+
const entry = thread.items.get(key);
|
|
177
|
+
if (entry?.isComplete &&
|
|
178
|
+
entry.item.nativeType === item.nativeType &&
|
|
179
|
+
entry.item.kind === item.kind &&
|
|
180
|
+
((entry.item.text === item.text && entry.item.isTruncated === item.isTruncated) ||
|
|
181
|
+
(item.outcome !== null && entry.item.outcome === item.outcome))) {
|
|
182
|
+
this.__bytes -= entry.bytes;
|
|
183
|
+
thread.items.delete(key);
|
|
184
|
+
thread.revision = this.__change();
|
|
185
|
+
}
|
|
171
186
|
}
|
|
172
187
|
}
|
|
173
188
|
}
|
package/dist/actions/reads.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { resolveWorkspaceTarget } from '../runtime/state/index.js';
|
|
3
|
-
import { createRequestCursors, limitItemText } from '../sessions/index.js';
|
|
3
|
+
import { correlateEvidenceOrigins, createRequestCursors, limitItemText, } from '../sessions/index.js';
|
|
4
4
|
import { HQ_ERRORS } from '../errors/index.js';
|
|
5
5
|
// a control page continues after its final row's complete ordering tuple
|
|
6
6
|
const positions = createRequestCursors(z.strictObject({ createdAt: z.number().int(), id: z.uuid() }));
|
|
@@ -111,6 +111,7 @@ export const readControl = async (command, store, actions, roots) => {
|
|
|
111
111
|
let items = await read();
|
|
112
112
|
if (items.unchanged && command.waitMs !== undefined)
|
|
113
113
|
({ value: items } = await actions.polls.wait(read, (current) => !current.unchanged, (topic) => topic.kind === 'live', command.waitMs));
|
|
114
|
+
await correlateEvidenceOrigins(items.data, thread.provider, thread.nativeId, store);
|
|
114
115
|
return {
|
|
115
116
|
kind: 'live-items',
|
|
116
117
|
result: { ...items, data: limitItemText(items.data, command.textLimit) },
|
|
@@ -775,6 +775,7 @@ export declare const BrowserThreadDetailSchema: z.ZodObject<{
|
|
|
775
775
|
nativeInputId: z.ZodNullable<z.ZodString>;
|
|
776
776
|
nativeInputSha256: z.ZodNullable<z.ZodString>;
|
|
777
777
|
actionId: z.ZodNullable<z.ZodUUID>;
|
|
778
|
+
browserActionId: z.ZodOptional<z.ZodUUID>;
|
|
778
779
|
contentBoundary: z.ZodLiteral<"untrusted">;
|
|
779
780
|
grantsAuthority: z.ZodLiteral<false>;
|
|
780
781
|
}, z.core.$strip>;
|
|
@@ -16,6 +16,7 @@ export declare const HistoryProvenanceSchema: z.ZodObject<{
|
|
|
16
16
|
nativeInputId: z.ZodNullable<z.ZodString>;
|
|
17
17
|
nativeInputSha256: z.ZodNullable<z.ZodString>;
|
|
18
18
|
actionId: z.ZodNullable<z.ZodUUID>;
|
|
19
|
+
browserActionId: z.ZodOptional<z.ZodUUID>;
|
|
19
20
|
contentBoundary: z.ZodLiteral<"untrusted">;
|
|
20
21
|
grantsAuthority: z.ZodLiteral<false>;
|
|
21
22
|
}, z.core.$strip>;
|
|
@@ -90,6 +91,7 @@ export declare const EvidenceItemSchema: z.ZodObject<{
|
|
|
90
91
|
nativeInputId: z.ZodNullable<z.ZodString>;
|
|
91
92
|
nativeInputSha256: z.ZodNullable<z.ZodString>;
|
|
92
93
|
actionId: z.ZodNullable<z.ZodUUID>;
|
|
94
|
+
browserActionId: z.ZodOptional<z.ZodUUID>;
|
|
93
95
|
contentBoundary: z.ZodLiteral<"untrusted">;
|
|
94
96
|
grantsAuthority: z.ZodLiteral<false>;
|
|
95
97
|
}, z.core.$strip>;
|
|
@@ -143,6 +145,7 @@ export declare const EvidencePageSchema: z.ZodObject<{
|
|
|
143
145
|
nativeInputId: z.ZodNullable<z.ZodString>;
|
|
144
146
|
nativeInputSha256: z.ZodNullable<z.ZodString>;
|
|
145
147
|
actionId: z.ZodNullable<z.ZodUUID>;
|
|
148
|
+
browserActionId: z.ZodOptional<z.ZodUUID>;
|
|
146
149
|
contentBoundary: z.ZodLiteral<"untrusted">;
|
|
147
150
|
grantsAuthority: z.ZodLiteral<false>;
|
|
148
151
|
}, z.core.$strip>;
|
|
@@ -638,6 +638,7 @@ export declare const HistoryItemSchema: z.ZodObject<{
|
|
|
638
638
|
nativeInputId: z.ZodNullable<z.ZodString>;
|
|
639
639
|
nativeInputSha256: z.ZodNullable<z.ZodString>;
|
|
640
640
|
actionId: z.ZodNullable<z.ZodUUID>;
|
|
641
|
+
browserActionId: z.ZodOptional<z.ZodUUID>;
|
|
641
642
|
contentBoundary: z.ZodLiteral<"untrusted">;
|
|
642
643
|
grantsAuthority: z.ZodLiteral<false>;
|
|
643
644
|
}, z.core.$strip>;
|
|
@@ -694,6 +695,7 @@ export declare const ItemDetailSchema: z.ZodObject<{
|
|
|
694
695
|
nativeInputId: z.ZodNullable<z.ZodString>;
|
|
695
696
|
nativeInputSha256: z.ZodNullable<z.ZodString>;
|
|
696
697
|
actionId: z.ZodNullable<z.ZodUUID>;
|
|
698
|
+
browserActionId: z.ZodOptional<z.ZodUUID>;
|
|
697
699
|
contentBoundary: z.ZodLiteral<"untrusted">;
|
|
698
700
|
grantsAuthority: z.ZodLiteral<false>;
|
|
699
701
|
}, z.core.$strip>;
|
|
@@ -786,6 +788,7 @@ export declare const LiveItemsSchema: z.ZodObject<{
|
|
|
786
788
|
nativeInputId: z.ZodNullable<z.ZodString>;
|
|
787
789
|
nativeInputSha256: z.ZodNullable<z.ZodString>;
|
|
788
790
|
actionId: z.ZodNullable<z.ZodUUID>;
|
|
791
|
+
browserActionId: z.ZodOptional<z.ZodUUID>;
|
|
789
792
|
contentBoundary: z.ZodLiteral<"untrusted">;
|
|
790
793
|
grantsAuthority: z.ZodLiteral<false>;
|
|
791
794
|
}, z.core.$strip>;
|
|
@@ -971,6 +974,7 @@ export declare const HqResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
971
974
|
nativeInputId: z.ZodNullable<z.ZodString>;
|
|
972
975
|
nativeInputSha256: z.ZodNullable<z.ZodString>;
|
|
973
976
|
actionId: z.ZodNullable<z.ZodUUID>;
|
|
977
|
+
browserActionId: z.ZodOptional<z.ZodUUID>;
|
|
974
978
|
contentBoundary: z.ZodLiteral<"untrusted">;
|
|
975
979
|
grantsAuthority: z.ZodLiteral<false>;
|
|
976
980
|
}, z.core.$strip>;
|
|
@@ -1492,6 +1496,7 @@ export declare const HqResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
1492
1496
|
nativeInputId: z.ZodNullable<z.ZodString>;
|
|
1493
1497
|
nativeInputSha256: z.ZodNullable<z.ZodString>;
|
|
1494
1498
|
actionId: z.ZodNullable<z.ZodUUID>;
|
|
1499
|
+
browserActionId: z.ZodOptional<z.ZodUUID>;
|
|
1495
1500
|
contentBoundary: z.ZodLiteral<"untrusted">;
|
|
1496
1501
|
grantsAuthority: z.ZodLiteral<false>;
|
|
1497
1502
|
}, z.core.$strip>;
|
|
@@ -1543,6 +1548,7 @@ export declare const HqResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
1543
1548
|
nativeInputId: z.ZodNullable<z.ZodString>;
|
|
1544
1549
|
nativeInputSha256: z.ZodNullable<z.ZodString>;
|
|
1545
1550
|
actionId: z.ZodNullable<z.ZodUUID>;
|
|
1551
|
+
browserActionId: z.ZodOptional<z.ZodUUID>;
|
|
1546
1552
|
contentBoundary: z.ZodLiteral<"untrusted">;
|
|
1547
1553
|
grantsAuthority: z.ZodLiteral<false>;
|
|
1548
1554
|
}, z.core.$strip>;
|
|
@@ -2307,6 +2313,7 @@ export declare const HqResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
2307
2313
|
nativeInputId: z.ZodNullable<z.ZodString>;
|
|
2308
2314
|
nativeInputSha256: z.ZodNullable<z.ZodString>;
|
|
2309
2315
|
actionId: z.ZodNullable<z.ZodUUID>;
|
|
2316
|
+
browserActionId: z.ZodOptional<z.ZodUUID>;
|
|
2310
2317
|
contentBoundary: z.ZodLiteral<"untrusted">;
|
|
2311
2318
|
grantsAuthority: z.ZodLiteral<false>;
|
|
2312
2319
|
}, z.core.$strip>;
|
|
@@ -2964,6 +2971,7 @@ export declare const IpcResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
2964
2971
|
nativeInputId: z.ZodNullable<z.ZodString>;
|
|
2965
2972
|
nativeInputSha256: z.ZodNullable<z.ZodString>;
|
|
2966
2973
|
actionId: z.ZodNullable<z.ZodUUID>;
|
|
2974
|
+
browserActionId: z.ZodOptional<z.ZodUUID>;
|
|
2967
2975
|
contentBoundary: z.ZodLiteral<"untrusted">;
|
|
2968
2976
|
grantsAuthority: z.ZodLiteral<false>;
|
|
2969
2977
|
}, z.core.$strip>;
|
|
@@ -3485,6 +3493,7 @@ export declare const IpcResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
3485
3493
|
nativeInputId: z.ZodNullable<z.ZodString>;
|
|
3486
3494
|
nativeInputSha256: z.ZodNullable<z.ZodString>;
|
|
3487
3495
|
actionId: z.ZodNullable<z.ZodUUID>;
|
|
3496
|
+
browserActionId: z.ZodOptional<z.ZodUUID>;
|
|
3488
3497
|
contentBoundary: z.ZodLiteral<"untrusted">;
|
|
3489
3498
|
grantsAuthority: z.ZodLiteral<false>;
|
|
3490
3499
|
}, z.core.$strip>;
|
|
@@ -3536,6 +3545,7 @@ export declare const IpcResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
3536
3545
|
nativeInputId: z.ZodNullable<z.ZodString>;
|
|
3537
3546
|
nativeInputSha256: z.ZodNullable<z.ZodString>;
|
|
3538
3547
|
actionId: z.ZodNullable<z.ZodUUID>;
|
|
3548
|
+
browserActionId: z.ZodOptional<z.ZodUUID>;
|
|
3539
3549
|
contentBoundary: z.ZodLiteral<"untrusted">;
|
|
3540
3550
|
grantsAuthority: z.ZodLiteral<false>;
|
|
3541
3551
|
}, z.core.$strip>;
|
|
@@ -4300,6 +4310,7 @@ export declare const IpcResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
4300
4310
|
nativeInputId: z.ZodNullable<z.ZodString>;
|
|
4301
4311
|
nativeInputSha256: z.ZodNullable<z.ZodString>;
|
|
4302
4312
|
actionId: z.ZodNullable<z.ZodUUID>;
|
|
4313
|
+
browserActionId: z.ZodOptional<z.ZodUUID>;
|
|
4303
4314
|
contentBoundary: z.ZodLiteral<"untrusted">;
|
|
4304
4315
|
grantsAuthority: z.ZodLiteral<false>;
|
|
4305
4316
|
}, z.core.$strip>;
|
|
@@ -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 =
|
|
17
|
+
const HISTORY_PROJECTION_VERSION = 11;
|
|
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
|
|
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
|
-
|
|
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,15 @@ 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.ZodArray<z.ZodUnknown>]>;
|
|
67
|
+
source_uuid: z.ZodOptional<z.ZodString>;
|
|
68
|
+
}, z.core.$strip>;
|
|
62
69
|
export declare const FilePatchSchema: z.ZodObject<{
|
|
63
70
|
filePath: z.ZodString;
|
|
64
71
|
type: z.ZodOptional<z.ZodString>;
|
|
@@ -27,6 +27,19 @@ 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([z.string(), z.array(z.unknown())]),
|
|
42
|
+
source_uuid: z.string().min(1).max(4096).optional(),
|
|
30
43
|
});
|
|
31
44
|
// the file Claude Code records on an Edit or Write result; a created file's patch is empty
|
|
32
45
|
export const FilePatchSchema = z.object({
|
|
@@ -60,17 +60,30 @@ 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
|
+
*/
|
|
70
|
+
export declare const readClaudeQueuedInput: (record: IRecord) => {
|
|
71
|
+
content: string | unknown[];
|
|
72
|
+
inputId: string | null;
|
|
73
|
+
} | null;
|
|
63
74
|
/**
|
|
64
75
|
* Presents one native record as the CLI shows it, shared by history pages, live items and
|
|
65
76
|
* evidence. Outcome and files come from the full record, before the text is cut, and its time
|
|
66
|
-
* from the record's `timestamp`.
|
|
77
|
+
* from the record's `timestamp`. A message queued while a turn ran shows as the user message it
|
|
78
|
+
* is, whose native input is the one Claude Code names.
|
|
67
79
|
* @returns The item, or null for a record the CLI leaves out, such as thinking or a task notification.
|
|
68
80
|
* @throws
|
|
69
81
|
* - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
|
|
70
82
|
*/
|
|
71
|
-
export declare const toClaudeItem: (
|
|
83
|
+
export declare const toClaudeItem: (native: IRecord, turnId: string, fullBody?: boolean) => IHistoryItem | null;
|
|
72
84
|
/**
|
|
73
|
-
* Lists the images a record holds, in its message and in its tool
|
|
85
|
+
* Lists the images a record holds, in its message, a queued message included, and in its tool
|
|
86
|
+
* results' content, in order.
|
|
74
87
|
* @param record The record.
|
|
75
88
|
* @returns At most 64 images, each its base64 data, or null for one that has no base64 source.
|
|
76
89
|
*/
|
|
@@ -93,9 +106,10 @@ export declare const isClaudeCallFor: (candidate: IRecord, item: IHistoryItem) =
|
|
|
93
106
|
/**
|
|
94
107
|
* Reads what a developer inspects in one record beyond its display text: a Bash command or `!`
|
|
95
108
|
* 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
|
-
*
|
|
109
|
+
* holds. A result takes its command or tool name from the call it answers, and a queued message
|
|
110
|
+
* reads as the user message it is.
|
|
111
|
+
* @param native The item's record.
|
|
98
112
|
* @param call The call it answers, or null when it answers none or the call isn't found.
|
|
99
113
|
* @returns The detail's parts; the item itself comes from `toClaudeItem`.
|
|
100
114
|
*/
|
|
101
|
-
export declare const toClaudeDetail: (
|
|
115
|
+
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
|
/**
|
|
@@ -405,19 +405,43 @@ const toPresentation = (record) => {
|
|
|
405
405
|
callId: calls.length === 1 ? (calls[0].id ?? null) : null,
|
|
406
406
|
};
|
|
407
407
|
};
|
|
408
|
+
/**
|
|
409
|
+
* Reads the message a queued command attachment holds: input Claude Code took into a running turn,
|
|
410
|
+
* which it records as an attachment rather than a user record.
|
|
411
|
+
* @param record The record.
|
|
412
|
+
* @returns The message as a user record's content and the native input it came from, or null for
|
|
413
|
+
* any other record, such as a background task notification.
|
|
414
|
+
*/
|
|
415
|
+
export const readClaudeQueuedInput = (record) => {
|
|
416
|
+
if (record.type !== 'attachment')
|
|
417
|
+
return null;
|
|
418
|
+
const queued = QueuedPromptSchema.safeParse(record.attachment);
|
|
419
|
+
return queued.success
|
|
420
|
+
? { content: queued.data.prompt, inputId: queued.data.source_uuid ?? null }
|
|
421
|
+
: null;
|
|
422
|
+
};
|
|
423
|
+
// presents a queued command's message as the user record it stands for, and any other record as is
|
|
424
|
+
const toMessageRecord = (record) => {
|
|
425
|
+
const queued = readClaudeQueuedInput(record);
|
|
426
|
+
return queued
|
|
427
|
+
? { ...record, type: 'user', message: { role: 'user', content: queued.content } }
|
|
428
|
+
: record;
|
|
429
|
+
};
|
|
408
430
|
/**
|
|
409
431
|
* Presents one native record as the CLI shows it, shared by history pages, live items and
|
|
410
432
|
* evidence. Outcome and files come from the full record, before the text is cut, and its time
|
|
411
|
-
* from the record's `timestamp`.
|
|
433
|
+
* from the record's `timestamp`. A message queued while a turn ran shows as the user message it
|
|
434
|
+
* is, whose native input is the one Claude Code names.
|
|
412
435
|
* @returns The item, or null for a record the CLI leaves out, such as thinking or a task notification.
|
|
413
436
|
* @throws
|
|
414
437
|
* - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
|
|
415
438
|
*/
|
|
416
|
-
export const toClaudeItem = (
|
|
417
|
-
if (!
|
|
439
|
+
export const toClaudeItem = (native, turnId, fullBody = false) => {
|
|
440
|
+
if (!native.uuid)
|
|
418
441
|
throw HQ_ERRORS.create('claudeHistoryUnavailable', {
|
|
419
442
|
data: { kind: 'agent-unavailable' },
|
|
420
443
|
});
|
|
444
|
+
const record = toMessageRecord(native);
|
|
421
445
|
const presentation = toPresentation(record);
|
|
422
446
|
if (!presentation)
|
|
423
447
|
return null;
|
|
@@ -428,10 +452,10 @@ export const toClaudeItem = (record, turnId, fullBody = false) => {
|
|
|
428
452
|
const createdAt = Date.parse(record.timestamp ?? '');
|
|
429
453
|
return {
|
|
430
454
|
...presentation,
|
|
431
|
-
nativeId:
|
|
455
|
+
nativeId: native.uuid,
|
|
432
456
|
turnId,
|
|
433
457
|
provenance: presentation.kind === 'user-message'
|
|
434
|
-
? nativeProvenance(presentation.kind,
|
|
458
|
+
? nativeProvenance(presentation.kind, readClaudeQueuedInput(native)?.inputId ?? native.uuid, readInputText(record))
|
|
435
459
|
: nativeProvenance(presentation.kind),
|
|
436
460
|
text: text.slice(0, end),
|
|
437
461
|
isTruncated: end < text.length,
|
|
@@ -495,11 +519,12 @@ const toResultBody = (block) => Array.isArray(block.content)
|
|
|
495
519
|
// a Bash call's command
|
|
496
520
|
const toShellCommand = (input) => z.object({ command: z.string() }).safeParse(input).data?.command ?? null;
|
|
497
521
|
/**
|
|
498
|
-
* Lists the images a record holds, in its message and in its tool
|
|
522
|
+
* Lists the images a record holds, in its message, a queued message included, and in its tool
|
|
523
|
+
* results' content, in order.
|
|
499
524
|
* @param record The record.
|
|
500
525
|
* @returns At most 64 images, each its base64 data, or null for one that has no base64 source.
|
|
501
526
|
*/
|
|
502
|
-
export const toClaudeImageData = (record) => toBlocks(record)
|
|
527
|
+
export const toClaudeImageData = (record) => toBlocks(toMessageRecord(record))
|
|
503
528
|
.flatMap((block) => block.type === 'tool_result' && Array.isArray(block.content)
|
|
504
529
|
? block.content.flatMap((part) => BlockSchema.safeParse(part).data ?? [])
|
|
505
530
|
: [block])
|
|
@@ -532,12 +557,14 @@ export const isClaudeCallFor = (candidate, item) => item.nativeType === 'tool-re
|
|
|
532
557
|
/**
|
|
533
558
|
* Reads what a developer inspects in one record beyond its display text: a Bash command or `!`
|
|
534
559
|
* 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
|
-
*
|
|
560
|
+
* holds. A result takes its command or tool name from the call it answers, and a queued message
|
|
561
|
+
* reads as the user message it is.
|
|
562
|
+
* @param native The item's record.
|
|
537
563
|
* @param call The call it answers, or null when it answers none or the call isn't found.
|
|
538
564
|
* @returns The detail's parts; the item itself comes from `toClaudeItem`.
|
|
539
565
|
*/
|
|
540
|
-
export const toClaudeDetail = (
|
|
566
|
+
export const toClaudeDetail = (native, call) => {
|
|
567
|
+
const record = toMessageRecord(native);
|
|
541
568
|
const detail = {
|
|
542
569
|
command: null,
|
|
543
570
|
tool: null,
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { buildEvidencePage, evidencePosition, evidenceHash, nativeProvenance, resetProvenance, EVIDENCE_RESPONSE_BYTES, EVIDENCE_SOURCE_PAGE_SIZE, } from './utilities.js';
|
|
2
2
|
export type { IEvidenceOriginsRequest } from './types.js';
|
|
3
|
+
export { correlateEvidenceOrigins } from './origins.js';
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
// bounded native evidence selection
|
|
2
2
|
export { buildEvidencePage, evidencePosition, evidenceHash, nativeProvenance, resetProvenance, EVIDENCE_RESPONSE_BYTES, EVIDENCE_SOURCE_PAGE_SIZE, } from './utilities.js';
|
|
3
|
+
// verified history and live input origins
|
|
4
|
+
export { correlateEvidenceOrigins } from './origins.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IEvidenceItem, IHistoryItem, IProviderId } from '../../contracts/index.js';
|
|
2
|
+
import type { IStore } from '../../store/index.js';
|
|
3
|
+
type IProvenanceItem = Pick<IHistoryItem, 'kind' | 'provenance'> & (Pick<IHistoryItem, 'turnId'> | Pick<IEvidenceItem, 'reference'>);
|
|
4
|
+
/**
|
|
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.
|
|
7
|
+
* @param items Fresh presentation rows, including full-input fingerprints before preview cuts.
|
|
8
|
+
* @param provider The provider whose native session supplied the rows.
|
|
9
|
+
* @param nativeId The selected native session.
|
|
10
|
+
* @param store The authoritative action ledger.
|
|
11
|
+
* @mutates Replaces provenance on the supplied presentation rows.
|
|
12
|
+
* @returns Completion after the eligible user inputs have been correlated.
|
|
13
|
+
* @throws
|
|
14
|
+
* - JG_AGENT_HQ_STORE_FAILED: The HQ store failed
|
|
15
|
+
*/
|
|
16
|
+
export declare const correlateEvidenceOrigins: (items: IProvenanceItem[], provider: IProviderId, nativeId: string, store: IStore) => Promise<void>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { parseActionRequest } from '../../providers/index.js';
|
|
2
|
+
import { resetProvenance } from './utilities.js';
|
|
3
|
+
/**
|
|
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.
|
|
6
|
+
* @param items Fresh presentation rows, including full-input fingerprints before preview cuts.
|
|
7
|
+
* @param provider The provider whose native session supplied the rows.
|
|
8
|
+
* @param nativeId The selected native session.
|
|
9
|
+
* @param store The authoritative action ledger.
|
|
10
|
+
* @mutates Replaces provenance on the supplied presentation rows.
|
|
11
|
+
* @returns Completion after the eligible user inputs have been correlated.
|
|
12
|
+
* @throws
|
|
13
|
+
* - JG_AGENT_HQ_STORE_FAILED: The HQ store failed
|
|
14
|
+
*/
|
|
15
|
+
export const correlateEvidenceOrigins = async (items, provider, nativeId, store) => {
|
|
16
|
+
for (const item of items)
|
|
17
|
+
item.provenance = resetProvenance(item.kind, item.provenance);
|
|
18
|
+
const inputs = items.filter(({ kind, provenance }) => kind === 'user-message' &&
|
|
19
|
+
provenance.nativeInputId !== null &&
|
|
20
|
+
provenance.nativeInputSha256 !== null);
|
|
21
|
+
if (inputs.length === 0)
|
|
22
|
+
return;
|
|
23
|
+
const origins = await store.call('reads', 'getEvidenceOrigins', {
|
|
24
|
+
provider,
|
|
25
|
+
nativeId,
|
|
26
|
+
items: inputs.map(({ provenance, ...item }) => ({
|
|
27
|
+
nativeInputId: provenance.nativeInputId,
|
|
28
|
+
request: parseActionRequest(provenance.nativeInputId),
|
|
29
|
+
turnId: 'reference' in item ? item.reference.turnId : item.turnId,
|
|
30
|
+
sha256: provenance.nativeInputSha256,
|
|
31
|
+
})),
|
|
32
|
+
});
|
|
33
|
+
for (const [index, origin] of origins.entries())
|
|
34
|
+
if (origin)
|
|
35
|
+
inputs[index].provenance = origin;
|
|
36
|
+
};
|
package/dist/sessions/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export { readImageFile } from './images.js';
|
|
|
3
3
|
export type { IClaudeSessions } from './types.js';
|
|
4
4
|
export { readActiveSessions, readNativeHistory } from './sessions.js';
|
|
5
5
|
export type { IHistoryRequest } from './types.js';
|
|
6
|
+
export { correlateEvidenceOrigins } from './evidence/index.js';
|
|
6
7
|
export { readThreads } from './discovery/index.js';
|
package/dist/sessions/index.js
CHANGED
|
@@ -3,5 +3,7 @@ export { createRequestCursors, decodeHistoryCursor, encodeHistoryCursor, limitIt
|
|
|
3
3
|
// image files an item names
|
|
4
4
|
export { readImageFile } from './images.js';
|
|
5
5
|
export { readActiveSessions, readNativeHistory } from './sessions.js';
|
|
6
|
+
// verified input origins
|
|
7
|
+
export { correlateEvidenceOrigins } from './evidence/index.js';
|
|
6
8
|
// discovery across folders and providers
|
|
7
9
|
export { readThreads } from './discovery/index.js';
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { MAX_PAGE_SIZE, } from '../contracts/index.js';
|
|
2
|
-
import { parseActionRequest } from '../providers/index.js';
|
|
3
2
|
import { resolveWorkspaceTarget } from '../runtime/state/index.js';
|
|
4
3
|
import { getErrorKind, HQ_ERRORS } from '../errors/index.js';
|
|
5
4
|
import { imageUnavailable } from './utilities.js';
|
|
6
5
|
import { joinRecords, toManagedSummaries, withListing } from './summaries.js';
|
|
7
|
-
import {
|
|
6
|
+
import { correlateEvidenceOrigins } from './evidence/index.js';
|
|
8
7
|
/**
|
|
9
8
|
* Authorizes native history before loading content. A `thread` read whose history its provider
|
|
10
9
|
* can't read answers from HQ's records of the session, with its history unavailable, and fails
|
|
@@ -71,31 +70,8 @@ export const readNativeHistory = async (command, registry, projection, allowedRo
|
|
|
71
70
|
: response.kind === 'item-detail' && response.result
|
|
72
71
|
? [response.result.item]
|
|
73
72
|
: [];
|
|
74
|
-
if (items.length && 'nativeId' in command)
|
|
75
|
-
|
|
76
|
-
* Provider assertions alone never establish an operator or an HQ action link. A user message
|
|
77
|
-
* links to the action whose input it holds by its native input and the hash of the text that
|
|
78
|
-
* input sent, so attachments and a cut text don't hide it.
|
|
79
|
-
*/
|
|
80
|
-
for (const item of items)
|
|
81
|
-
item.provenance = resetProvenance(item.kind, item.provenance);
|
|
82
|
-
const origins = await projection.call('reads', 'getEvidenceOrigins', {
|
|
83
|
-
provider: command.provider,
|
|
84
|
-
nativeId: command.nativeId,
|
|
85
|
-
items: items.map(({ kind, provenance, ...item }) => {
|
|
86
|
-
const nativeInputId = kind === 'user-message' ? provenance.nativeInputId : null;
|
|
87
|
-
return {
|
|
88
|
-
nativeInputId,
|
|
89
|
-
request: nativeInputId === null ? null : parseActionRequest(nativeInputId),
|
|
90
|
-
turnId: 'reference' in item ? item.reference.turnId : item.turnId,
|
|
91
|
-
sha256: provenance.nativeInputSha256,
|
|
92
|
-
};
|
|
93
|
-
}),
|
|
94
|
-
});
|
|
95
|
-
for (const [index, origin] of origins.entries())
|
|
96
|
-
if (origin && items[index])
|
|
97
|
-
items[index].provenance = origin;
|
|
98
|
-
}
|
|
73
|
+
if (items.length && 'nativeId' in command)
|
|
74
|
+
await correlateEvidenceOrigins(items, command.provider, command.nativeId, projection);
|
|
99
75
|
if (response.kind === 'session-evidence' && Buffer.byteLength(JSON.stringify(response)) > 65_280)
|
|
100
76
|
throw HQ_ERRORS.create('providerFailed', { data: { kind: 'agent-unavailable' } });
|
|
101
77
|
return response;
|
|
@@ -15,7 +15,7 @@ export class ControlReads extends ControlModel {
|
|
|
15
15
|
return command.items.map((item) => {
|
|
16
16
|
if (item.nativeInputId === null || item.sha256 === null)
|
|
17
17
|
return null;
|
|
18
|
-
const rows = this._statements.all(`SELECT a.id,
|
|
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
19
|
FROM agent_hq_action a JOIN agent_hq_thread t ON t.id = a.thread_id
|
|
20
20
|
WHERE t.provider = ? AND t.native_id = ? AND a.native_turn_id = ? AND a.input_sha256 = ?
|
|
21
21
|
AND a.delivery = 'acknowledged' AND ((a.id = ? AND a.phase = ?) OR a.native_turn_id = ?)
|
|
@@ -24,9 +24,10 @@ export class ControlReads extends ControlModel {
|
|
|
24
24
|
return null;
|
|
25
25
|
const row = rows[0];
|
|
26
26
|
return {
|
|
27
|
-
origin: row.
|
|
28
|
-
source: row.
|
|
27
|
+
origin: row.browser_action_id !== null ? 'operator' : 'unknown',
|
|
28
|
+
source: row.browser_action_id !== null ? 'authenticated-host-action' : 'host-action',
|
|
29
29
|
actionId: row.id,
|
|
30
|
+
...(row.browser_action_id === null ? {} : { browserActionId: row.browser_action_id }),
|
|
30
31
|
nativeInputId: item.nativeInputId,
|
|
31
32
|
nativeInputSha256: item.sha256,
|
|
32
33
|
contentBoundary: 'untrusted',
|
package/package.json
CHANGED