jg-agent-hq 13.1.3 → 13.1.4

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 CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 13.1.4
4
+
5
+ - 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.
6
+ - 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.
7
+
3
8
  ## 13.1.3
4
9
 
5
10
  - 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
 
@@ -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. */
@@ -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);
@@ -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>;
@@ -15,6 +15,7 @@ export const HistoryProvenanceSchema = z.object({
15
15
  .regex(/^[a-f0-9]{64}$/)
16
16
  .nullable(),
17
17
  actionId: z.uuid().nullable(),
18
+ browserActionId: z.uuid().optional(),
18
19
  contentBoundary: z.literal('untrusted'),
19
20
  grantsAuthority: z.literal(false),
20
21
  });
@@ -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>;
@@ -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
+ };
@@ -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';
@@ -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 { resetProvenance } from './evidence/index.js';
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, EXISTS(SELECT 1 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 authenticated
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.authenticated === 1 ? 'operator' : 'unknown',
28
- source: row.authenticated === 1 ? 'authenticated-host-action' : 'host-action',
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jg-agent-hq",
3
- "version": "13.1.3",
3
+ "version": "13.1.4",
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",