jg-agent-hq 13.1.2 → 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 +10 -0
- package/README.md +1 -1
- package/api/README.md +3 -1
- package/dist/actions/dispatch/dispatch.js +2 -0
- package/dist/actions/events/events.js +1 -1
- package/dist/actions/live/live.d.ts +2 -0
- package/dist/actions/live/live.js +7 -0
- package/dist/actions/reads.js +2 -1
- package/dist/actions/reattach/reattach.js +16 -0
- 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/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/dist/store/sessions/constants.d.ts +1 -1
- package/dist/store/sessions/constants.js +14 -5
- package/dist/store/sessions/sessions.model.js +6 -6
- package/docs/recovery.md +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
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
|
+
|
|
8
|
+
## 13.1.3
|
|
9
|
+
|
|
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.
|
|
11
|
+
- Reread native status after a newer CLI turn prevents automatic reattachment, preserving the initial observation across the startup quarantine race. Keep the existing storage schema, action key and public request contracts unchanged.
|
|
12
|
+
|
|
3
13
|
## 13.1.2
|
|
4
14
|
|
|
5
15
|
- Preserve native Codex item lifecycle timestamps in history, item details, evidence and live notifications. Operator messages use their own start time and replies their own completion time, retaining millisecond precision. Missing item times remain unknown instead of borrowing a turn time.
|
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
|
|
|
@@ -379,6 +379,8 @@ Codex leaves `reasoning` items out as it reads them, so a Codex page can hold fe
|
|
|
379
379
|
|
|
380
380
|
Every session has a live state: `running`, `waiting` (on the operator), `idle`, `closed`, `failed` or `unknown`. A managed session reports it from its managed record. A session another client drives is observed and listed with `ownership: 'external'`; the runtime sends it no input until `thread-adopt` records it as managed, and never stops, wakes or drives a session a terminal runs. A managed session the runtime closed is observed again, so a terminal that continues it shows its state.
|
|
381
381
|
|
|
382
|
+
A retained session with uncertain ownership also takes its live state from native observation, including loaded Codex sessions found at startup and later status changes. Thread reads, discovery and active-session summaries retain its managed ID and `ownership: 'uncertain'`. Observation never changes its control record, settles uncertain input, advances queued input or restores execution authority. Without a native observation its state remains unknown; explicit recovery is still required to regain control.
|
|
383
|
+
|
|
382
384
|
A Claude session's summary carries `terminal`: `{ kind: 'interactive' }`, or `{ kind: 'background', attachId }` with the short ID `claude attach` takes, while the latest `claude agents --json` run lists it with a `pid`, and null otherwise; Codex summaries always carry null. While it is set, `thread-adopt` and `thread-resume` of the session, and input to it, are refused with JG_AGENT_HQ_ACTION_CONFLICT, so a session the runtime runs that a terminal resumed takes nothing from the runtime until the terminal closes it. An approval request of a Codex turn reaches every client the daemon serves; when another answers first, the runtime's prompt expires.
|
|
383
385
|
|
|
384
386
|
Every summary carries `backgroundCommands`, the background tasks the session runs, after which Claude resumes it on its own: commands it runs or moved to the background, and agents it launched there. A session the runtime runs reports the count Claude last reported in `system/background_tasks_changed`, the same count its `live-items` window carries. A Claude session a terminal runs reports the tasks its transcript records since its listed process's `startedAt`, as the active-session poll below counts them. Codex sessions, and Claude sessions no run lists, report 0.
|
|
@@ -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));
|
|
@@ -324,8 +324,8 @@ export const createEvents = (context, dispatcher, reconnect) => {
|
|
|
324
324
|
turnId: null,
|
|
325
325
|
});
|
|
326
326
|
}
|
|
327
|
-
return;
|
|
328
327
|
}
|
|
328
|
+
// the store suppresses controlled observations and retains status for uncertain controls
|
|
329
329
|
enqueue(provider, () => store.call('sessions', 'observe', provider, [{ nativeId, state: sessionState, thread }], false));
|
|
330
330
|
},
|
|
331
331
|
delta(provider, nativeId, turnId, itemId, text) {
|
|
@@ -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);
|
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) },
|
|
@@ -37,6 +37,22 @@ export const createReattach = (context, dispatcher, events) => {
|
|
|
37
37
|
},
|
|
38
38
|
});
|
|
39
39
|
waits.notifyThread(thread.id);
|
|
40
|
+
if (bound?.thread?.ownership === 'uncertain') {
|
|
41
|
+
// the initial loaded-thread observation may have preceded quarantine
|
|
42
|
+
const { thread: observed } = await control.inspectThread(nativeId, thread.workspaceRoot);
|
|
43
|
+
await store.call('sessions', 'observe', thread.provider, [
|
|
44
|
+
{
|
|
45
|
+
nativeId,
|
|
46
|
+
state: observed.state,
|
|
47
|
+
thread: {
|
|
48
|
+
workspaceRoot: observed.workspaceRoot,
|
|
49
|
+
name: observed.name,
|
|
50
|
+
createdAt: observed.createdAt,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
], false);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
40
56
|
if (bound?.thread?.ownership !== 'managed' || bound.thread.runtimeEpoch !== epoch)
|
|
41
57
|
return;
|
|
42
58
|
own(thread.provider, nativeId);
|
|
@@ -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>;
|
|
@@ -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',
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const RETENTION_MS = 604800000;
|
|
2
|
-
export declare const ACTIVE_SESSIONS = "WITH included(provider, native_id) AS (\n SELECT json_extract(value, '$[0]'), json_extract(value, '$[1]') FROM json_each(?)\n)\nSELECT provider, native_id, state, changed_at, thread, observed_thread, history FROM (\n SELECT agent_hq_thread.provider, agent_hq_thread.native_id,\n EXISTS (SELECT 1 FROM included WHERE included.provider = agent_hq_thread.provider AND included.native_id = agent_hq_thread.native_id) AS is_included,\n coalesce(map.session_state, (SELECT state FROM agent_hq_session_transition WHERE thread_id = agent_hq_thread.id ORDER BY sequence DESC LIMIT 1), 'unknown') AS state,\n coalesce((SELECT recorded_at FROM agent_hq_session_transition WHERE thread_id = agent_hq_thread.id ORDER BY sequence DESC LIMIT 1), agent_hq_thread.updated_at) AS changed_at,\n json_object('id', agent_hq_thread.id, 'ownership', agent_hq_thread.ownership, 'name', agent_hq_thread.name,\n 'workspaceRoot', agent_hq_thread.workspace_root, 'nativeLineage', json(agent_hq_thread.native_lineage),\n 'createdAt', agent_hq_thread.created_at, 'updatedAt', agent_hq_thread.updated_at) AS thread,\n NULL AS observed_thread, NULL AS history\n FROM agent_hq_thread INNER JOIN agent_hq_session_state_map AS map ON map.thread_state = agent_hq_thread.state\n WHERE agent_hq_thread.runtime_epoch IS NOT NULL AND agent_hq_thread.native_id IS NOT NULL AND (map.session_state IS NULL OR map.session_state IN ('running', 'waiting')\n OR EXISTS (SELECT 1 FROM included WHERE included.provider = agent_hq_thread.provider AND included.native_id = agent_hq_thread.native_id))\n UNION ALL\n SELECT observed.provider, observed.native_id,\n EXISTS (SELECT 1 FROM included WHERE included.provider = observed.provider AND included.native_id = observed.native_id),\n observed.state, observed.observed_at,
|
|
2
|
+
export declare const ACTIVE_SESSIONS = "WITH included(provider, native_id) AS (\n SELECT json_extract(value, '$[0]'), json_extract(value, '$[1]') FROM json_each(?)\n)\nSELECT provider, native_id, state, changed_at, thread, observed_thread, history FROM (\n SELECT agent_hq_thread.provider, agent_hq_thread.native_id,\n EXISTS (SELECT 1 FROM included WHERE included.provider = agent_hq_thread.provider AND included.native_id = agent_hq_thread.native_id) AS is_included,\n coalesce(map.session_state, (SELECT state FROM agent_hq_session_transition WHERE thread_id = agent_hq_thread.id ORDER BY sequence DESC LIMIT 1), 'unknown') AS state,\n coalesce((SELECT recorded_at FROM agent_hq_session_transition WHERE thread_id = agent_hq_thread.id ORDER BY sequence DESC LIMIT 1), agent_hq_thread.updated_at) AS changed_at,\n json_object('id', agent_hq_thread.id, 'ownership', agent_hq_thread.ownership, 'name', agent_hq_thread.name,\n 'workspaceRoot', agent_hq_thread.workspace_root, 'nativeLineage', json(agent_hq_thread.native_lineage),\n 'createdAt', agent_hq_thread.created_at, 'updatedAt', agent_hq_thread.updated_at) AS thread,\n NULL AS observed_thread, NULL AS history\n FROM agent_hq_thread INNER JOIN agent_hq_session_state_map AS map ON map.thread_state = agent_hq_thread.state\n WHERE agent_hq_thread.ownership = 'managed' AND agent_hq_thread.runtime_epoch IS NOT NULL AND agent_hq_thread.native_id IS NOT NULL AND (map.session_state IS NULL OR map.session_state IN ('running', 'waiting')\n OR EXISTS (SELECT 1 FROM included WHERE included.provider = agent_hq_thread.provider AND included.native_id = agent_hq_thread.native_id))\n UNION ALL\n SELECT observed.provider, observed.native_id,\n EXISTS (SELECT 1 FROM included WHERE included.provider = observed.provider AND included.native_id = observed.native_id),\n observed.state, observed.observed_at,\n CASE WHEN retained.id IS NOT NULL THEN json_object('id', retained.id, 'ownership', retained.ownership,\n 'name', retained.name, 'workspaceRoot', retained.workspace_root, 'nativeLineage', json(retained.native_lineage),\n 'createdAt', retained.created_at, 'updatedAt', retained.updated_at) END,\n CASE WHEN observed.provider = 'codex' AND observed.workspace_root IS NOT NULL THEN json_object('workspaceRoot', observed.workspace_root,\n 'name', observed.name, 'createdAt', observed.created_at) END,\n CASE WHEN observed.provider = 'claude' THEN (\n SELECT json_object('name', name, 'createdAt', created_at, 'updatedAt', updated_at,\n 'isSupported', json(CASE WHEN supported = 1 THEN 'true' ELSE 'false' END))\n FROM agent_hq_claude_file WHERE native_id = observed.native_id AND workspace_state = 'matching'\n ORDER BY updated_at DESC LIMIT 1\n ) END\n FROM agent_hq_observed_session AS observed\n LEFT JOIN agent_hq_thread AS retained ON retained.provider = observed.provider\n AND retained.native_id = observed.native_id AND retained.ownership = 'uncertain'\n WHERE (observed.state IN ('running', 'waiting')\n OR EXISTS (SELECT 1 FROM included WHERE included.provider = observed.provider AND included.native_id = observed.native_id))\n AND NOT EXISTS (SELECT 1 FROM agent_hq_thread AS controlled WHERE controlled.provider = observed.provider\n AND controlled.native_id = observed.native_id AND controlled.ownership = 'managed' AND controlled.state != 'inactive')\n) WHERE state IN ('running', 'waiting') OR (is_included AND state = 'idle')\nORDER BY changed_at DESC, native_id DESC LIMIT ?";
|
|
@@ -5,7 +5,8 @@ export const RETENTION_MS = 604_800_000;
|
|
|
5
5
|
* sessions, which run background commands. A managed thread is active only while a runtime binds
|
|
6
6
|
* it, which its runtime epoch index finds; a stopping one reports the state it stops, from its
|
|
7
7
|
* last transition. An observed Codex session carries its latest confirmed metadata, and an
|
|
8
|
-
* observed Claude session joins its indexed transcript, if any, by session ID.
|
|
8
|
+
* observed Claude session joins its indexed transcript, if any, by session ID. An uncertain
|
|
9
|
+
* control retains its identity while taking its live state from observation. The included
|
|
9
10
|
* sessions are one JSON array of [provider, native ID] pairs.
|
|
10
11
|
*/
|
|
11
12
|
export const ACTIVE_SESSIONS = `WITH included(provider, native_id) AS (
|
|
@@ -21,12 +22,15 @@ SELECT provider, native_id, state, changed_at, thread, observed_thread, history
|
|
|
21
22
|
'createdAt', agent_hq_thread.created_at, 'updatedAt', agent_hq_thread.updated_at) AS thread,
|
|
22
23
|
NULL AS observed_thread, NULL AS history
|
|
23
24
|
FROM agent_hq_thread INNER JOIN agent_hq_session_state_map AS map ON map.thread_state = agent_hq_thread.state
|
|
24
|
-
WHERE agent_hq_thread.runtime_epoch IS NOT NULL AND agent_hq_thread.native_id IS NOT NULL AND (map.session_state IS NULL OR map.session_state IN ('running', 'waiting')
|
|
25
|
+
WHERE agent_hq_thread.ownership = 'managed' AND agent_hq_thread.runtime_epoch IS NOT NULL AND agent_hq_thread.native_id IS NOT NULL AND (map.session_state IS NULL OR map.session_state IN ('running', 'waiting')
|
|
25
26
|
OR EXISTS (SELECT 1 FROM included WHERE included.provider = agent_hq_thread.provider AND included.native_id = agent_hq_thread.native_id))
|
|
26
27
|
UNION ALL
|
|
27
28
|
SELECT observed.provider, observed.native_id,
|
|
28
29
|
EXISTS (SELECT 1 FROM included WHERE included.provider = observed.provider AND included.native_id = observed.native_id),
|
|
29
|
-
observed.state, observed.observed_at,
|
|
30
|
+
observed.state, observed.observed_at,
|
|
31
|
+
CASE WHEN retained.id IS NOT NULL THEN json_object('id', retained.id, 'ownership', retained.ownership,
|
|
32
|
+
'name', retained.name, 'workspaceRoot', retained.workspace_root, 'nativeLineage', json(retained.native_lineage),
|
|
33
|
+
'createdAt', retained.created_at, 'updatedAt', retained.updated_at) END,
|
|
30
34
|
CASE WHEN observed.provider = 'codex' AND observed.workspace_root IS NOT NULL THEN json_object('workspaceRoot', observed.workspace_root,
|
|
31
35
|
'name', observed.name, 'createdAt', observed.created_at) END,
|
|
32
36
|
CASE WHEN observed.provider = 'claude' THEN (
|
|
@@ -35,7 +39,12 @@ SELECT provider, native_id, state, changed_at, thread, observed_thread, history
|
|
|
35
39
|
FROM agent_hq_claude_file WHERE native_id = observed.native_id AND workspace_state = 'matching'
|
|
36
40
|
ORDER BY updated_at DESC LIMIT 1
|
|
37
41
|
) END
|
|
38
|
-
FROM agent_hq_observed_session AS observed
|
|
39
|
-
|
|
42
|
+
FROM agent_hq_observed_session AS observed
|
|
43
|
+
LEFT JOIN agent_hq_thread AS retained ON retained.provider = observed.provider
|
|
44
|
+
AND retained.native_id = observed.native_id AND retained.ownership = 'uncertain'
|
|
45
|
+
WHERE (observed.state IN ('running', 'waiting')
|
|
46
|
+
OR EXISTS (SELECT 1 FROM included WHERE included.provider = observed.provider AND included.native_id = observed.native_id))
|
|
47
|
+
AND NOT EXISTS (SELECT 1 FROM agent_hq_thread AS controlled WHERE controlled.provider = observed.provider
|
|
48
|
+
AND controlled.native_id = observed.native_id AND controlled.ownership = 'managed' AND controlled.state != 'inactive')
|
|
40
49
|
) WHERE state IN ('running', 'waiting') OR (is_included AND state = 'idle')
|
|
41
50
|
ORDER BY changed_at DESC, native_id DESC LIMIT ?`;
|
|
@@ -19,10 +19,10 @@ export class SessionsModel {
|
|
|
19
19
|
try {
|
|
20
20
|
for (const session of sessions) {
|
|
21
21
|
/*
|
|
22
|
-
* A session HQ
|
|
23
|
-
* observed
|
|
22
|
+
* A session HQ controls keeps its transitions on its managed record. Closed and uncertain
|
|
23
|
+
* controls can still be observed without granting control or changing their ledger.
|
|
24
24
|
*/
|
|
25
|
-
if (this.__statements.get("SELECT 1 FROM agent_hq_thread WHERE provider = ? AND native_id = ? AND state != 'inactive'", provider, session.nativeId)) {
|
|
25
|
+
if (this.__statements.get("SELECT 1 FROM agent_hq_thread WHERE provider = ? AND native_id = ? AND ownership = 'managed' AND state != 'inactive'", provider, session.nativeId)) {
|
|
26
26
|
this.__statements.run('DELETE FROM agent_hq_observed_session WHERE provider = ? AND native_id = ?', provider, session.nativeId);
|
|
27
27
|
continue;
|
|
28
28
|
}
|
|
@@ -67,10 +67,10 @@ export class SessionsModel {
|
|
|
67
67
|
/** Reads the live states of selected native sessions, managed or observed. */
|
|
68
68
|
states(provider, nativeIds) {
|
|
69
69
|
return nativeIds.flatMap((nativeId) => {
|
|
70
|
-
const record = this.__statements.get("SELECT coalesce(agent_hq_session_state_map.session_state, (SELECT state FROM agent_hq_session_transition WHERE thread_id = agent_hq_thread.id ORDER BY sequence DESC LIMIT 1), 'unknown') AS state, agent_hq_thread.state = 'inactive' AS
|
|
70
|
+
const record = this.__statements.get("SELECT coalesce(agent_hq_session_state_map.session_state, (SELECT state FROM agent_hq_session_transition WHERE thread_id = agent_hq_thread.id ORDER BY sequence DESC LIMIT 1), 'unknown') AS state, (agent_hq_thread.state = 'inactive' OR agent_hq_thread.ownership = 'uncertain') AS uses_observation FROM agent_hq_thread INNER JOIN agent_hq_session_state_map ON agent_hq_session_state_map.thread_state = agent_hq_thread.state WHERE agent_hq_thread.provider = ? AND agent_hq_thread.native_id = ?", provider, nativeId);
|
|
71
71
|
const observed = () => this.__statements.get('SELECT state FROM agent_hq_observed_session WHERE provider = ? AND native_id = ?', provider, nativeId);
|
|
72
|
-
//
|
|
73
|
-
const row = record?.
|
|
72
|
+
// native status remains readable even when HQ no longer controls the session
|
|
73
|
+
const row = record?.uses_observation ? (observed() ?? record) : (record ?? observed());
|
|
74
74
|
return row ? [{ nativeId, state: row.state }] : [];
|
|
75
75
|
});
|
|
76
76
|
}
|
package/docs/recovery.md
CHANGED
|
@@ -32,6 +32,8 @@ The expanded name contract is still a breaking change for older consumers: 12.x
|
|
|
32
32
|
|
|
33
33
|
## Codex connection recovery
|
|
34
34
|
|
|
35
|
+
A quarantined session can still be monitored while a CLI runs it. Native observations update its live state without recovering ownership; the summary keeps uncertain ownership and its existing managed identity. Monitoring sends no input and leaves the control ledger and earlier queued entries unchanged.
|
|
36
|
+
|
|
35
37
|
A shared Codex daemon restart can interrupt every managed Codex session's live connection while HQ stays running. The runtime rechecks only its previously controlled sessions with no action in flight and rejoins matching native turns without changing settings or repeating input. Confirmed completions advance their waiting queues; unacknowledged actions and changed turns remain uncertain. Native command handles may have been lost, so rejoining establishes session control rather than successful command execution. See [runtime lifecycle](../api/README.md#runtime-lifecycle).
|
|
36
38
|
|
|
37
39
|
For a session left uncertain, stop its producing HQ runtime and inspect the native identity and competing controllers before explicit recovery in the next runtime. `thread-recover` with `recovery: { kind: 'resume' }` can rejoin its already known Codex identity even when the daemon still holds it idle or active. The verified current turn is bound before joining and checked again afterward; no settings or input are sent. Reissued approvals can then be answered explicitly. Earlier queued entries stay paused, uncertain input receipts stay unresolved, and unknown state or a turn changing during the join leaves control uncertain. Never use attach/create to replace a known native identity or replay work to recover control.
|
package/package.json
CHANGED