jg-agent-hq 13.1.1 → 13.1.3
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/events/events.js +1 -1
- package/dist/actions/reattach/reattach.js +16 -0
- package/dist/providers/codex/codex.js +3 -23
- package/dist/providers/codex/constants.d.ts +0 -3
- package/dist/providers/codex/constants.js +0 -5
- package/dist/providers/codex/events.js +8 -15
- package/dist/providers/codex/transformers.d.ts +4 -5
- package/dist/providers/codex/transformers.js +7 -10
- package/dist/providers/codex/types.d.ts +8 -0
- package/dist/providers/codex/types.js +16 -1
- 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.3
|
|
4
|
+
|
|
5
|
+
- 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.
|
|
6
|
+
- 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.
|
|
7
|
+
|
|
8
|
+
## 13.1.2
|
|
9
|
+
|
|
10
|
+
- 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.
|
|
11
|
+
- Remove the extra turn-history requests used only for item timing. Public response shapes, storage schema, action key and native session ownership are unchanged.
|
|
12
|
+
|
|
3
13
|
## 13.1.1
|
|
4
14
|
|
|
5
15
|
- Preserve quarantined Codex controls and their producing runtime epoch during shutdown. Stopping HQ no longer turns unverified native ownership into a managed inactive record or discards its recorded turn, so the next runtime can explicitly recover a still-loaded idle or active session. Queued input stays paused and no input is replayed.
|
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ Intentional failures use `Exception` from `jg-exception`, with the named string
|
|
|
47
47
|
|
|
48
48
|
## Local controller
|
|
49
49
|
|
|
50
|
-
Install the providers you want and sign in through their native CLIs, then start `jg-agent-hq serve --state-root .runtime --workspace-root /path/to/workspace`. Run `jg-agent-hq status --state-root .runtime` in a client. `threads` lists the sessions of several folders and both providers by last activity, with the sessions the runtime created before their first turn, in pages whose cursor resumes each source where it stopped; see [session discovery](api/README.md#session-discovery). `thread`, `items` and `usage` read native information, and each item carries its time as `createdAt
|
|
50
|
+
Install the providers you want and sign in through their native CLIs, then start `jg-agent-hq serve --state-root .runtime --workspace-root /path/to/workspace`. Run `jg-agent-hq status --state-root .runtime` in a client. `threads` lists the sessions of several folders and both providers by last activity, with the sessions the runtime created before their first turn, in pages whose cursor resumes each source where it stopped; see [session discovery](api/README.md#session-discovery). `thread`, `items` and `usage` read native information, and each item carries its time as `createdAt` (Unix milliseconds, null when unavailable); Codex uses recorded item lifecycle times for saved and live items, without substituting a shared turn time; `thread` answers from the runtime's records, its history unavailable, when its provider can't read it. `item-detail` reads what a developer inspects in one item: its command and output, tool call, file diffs and images, and `item-image` returns one of its images. `stop` waits for confirmed runtime shutdown.
|
|
51
51
|
|
|
52
52
|
The Node API exposes `createAgentHq({ stateRoot, allowedRoots })` and `requestAgentHq(stateRoot, command)`, whose results, like the runtime's `request`, are typed by their command's kind, and `getErrorKind(error)`, which reads an error's safe classification. The runtime's `runtimeEpoch` is the epoch actions name. Configuration comes from these trusted operator inputs. Coding-instruction files are not runtime configuration.
|
|
53
53
|
|
package/api/README.md
CHANGED
|
@@ -371,7 +371,7 @@ Control pages default to 32 and cap at 128. Seek cursors are bound to their comp
|
|
|
371
371
|
|
|
372
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.
|
|
373
373
|
|
|
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
|
|
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
|
|
|
376
376
|
Codex leaves `reasoning` items out as it reads them, so a Codex page can hold fewer items than its limit. `contextCompaction` is a `notice` with empty text, because Codex records no summary. `webSearch` and `imageView` are `tool` items reading the query or the image path. A command, file change or tool call takes its `outcome` from its `status`: `completed` succeeded, and `failed` or `declined` failed. `files` counts each change's diff, and an added or deleted file without hunks counts its whole content. A Codex item holds its call and its result together, so its `callId` is null. Claude's rules are under [Claude history](#claude-history).
|
|
377
377
|
|
|
@@ -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.
|
|
@@ -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) {
|
|
@@ -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);
|
|
@@ -5,7 +5,7 @@ import { MAX_PAGE_SIZE, } from '../../contracts/index.js';
|
|
|
5
5
|
import { NativeIdSchema } from '../../contracts/identities/index.js';
|
|
6
6
|
import { decodeBase64Image, imageUnavailable, readImageFile } from '../../sessions/index.js';
|
|
7
7
|
import { HQ_ERRORS } from '../../errors/index.js';
|
|
8
|
-
import { LOADED_THREADS_PAGE_SIZE,
|
|
8
|
+
import { LOADED_THREADS_PAGE_SIZE, NO_ROLLOUT_MESSAGE, SKILL_HINT_READ_CONCURRENCY, } from './constants.js';
|
|
9
9
|
import { createCodexRpc } from './rpc.js';
|
|
10
10
|
import { NativeBucketSchema, NativeSkillsSchema, NativeItemPageSchema, NativeThreadPageSchema, NativeThreadSchema, NativeTurnPageSchema, NativeUsageSchema, NativeTurnSchema, } from './types.js';
|
|
11
11
|
import { toHistoryItem, toImageSources, toItemDetail, toThreadSummary, toTurnSummary, toUsageSnapshot, } from './transformers.js';
|
|
@@ -141,24 +141,6 @@ export const createCodexProvider = async (extraSkillRoots = [], daemonLauncher =
|
|
|
141
141
|
});
|
|
142
142
|
return { data: page.data.map(toTurnSummary), nextCursor: page.nextCursor };
|
|
143
143
|
};
|
|
144
|
-
/*
|
|
145
|
-
* Reads turns newest first until every turn a history page's items belong to is found, so a
|
|
146
|
-
* recent page takes one read; a turn older than the most pages read leaves its items untimed.
|
|
147
|
-
*/
|
|
148
|
-
const readItemTurns = async (nativeId, turnIds) => {
|
|
149
|
-
const turns = new Map();
|
|
150
|
-
let cursor;
|
|
151
|
-
for (let read = 0; read < MAX_TURN_TIME_PAGES && turns.size < turnIds.size; read += 1) {
|
|
152
|
-
const page = await listTurns(nativeId, TURN_TIMES_PAGE_SIZE, cursor);
|
|
153
|
-
for (const turn of page.data)
|
|
154
|
-
if (turnIds.has(turn.nativeId))
|
|
155
|
-
turns.set(turn.nativeId, turn);
|
|
156
|
-
if (!page.nextCursor)
|
|
157
|
-
break;
|
|
158
|
-
cursor = page.nextCursor;
|
|
159
|
-
}
|
|
160
|
-
return turns;
|
|
161
|
-
};
|
|
162
144
|
/**
|
|
163
145
|
* Finds one item of a turn; Codex has no lookup of one item, so the turn's items are read,
|
|
164
146
|
* 128 at a time, until it appears.
|
|
@@ -265,10 +247,9 @@ export const createCodexProvider = async (extraSkillRoots = [], daemonLauncher =
|
|
|
265
247
|
throw HQ_ERRORS.create('codexFailed', {
|
|
266
248
|
data: { kind: 'agent-unavailable' },
|
|
267
249
|
});
|
|
268
|
-
const turns = await readItemTurns(nativeId, new Set(page.data.map((item) => item.turnId)));
|
|
269
250
|
return {
|
|
270
251
|
// reasoning is left out, so a page can hold fewer items than its limit
|
|
271
|
-
data: page.data.flatMap((item) => toHistoryItem(item,
|
|
252
|
+
data: page.data.flatMap((item) => toHistoryItem(item, fullBody) ?? []),
|
|
272
253
|
nextCursor: page.nextCursor,
|
|
273
254
|
};
|
|
274
255
|
},
|
|
@@ -276,8 +257,7 @@ export const createCodexProvider = async (extraSkillRoots = [], daemonLauncher =
|
|
|
276
257
|
const entry = await findItem(nativeId, turnId, nativeItemId);
|
|
277
258
|
if (!entry)
|
|
278
259
|
return null;
|
|
279
|
-
const
|
|
280
|
-
const item = toHistoryItem(entry, turns.get(entry.turnId));
|
|
260
|
+
const item = toHistoryItem(entry);
|
|
281
261
|
return item && { item, ...toItemDetail(entry) };
|
|
282
262
|
},
|
|
283
263
|
async readItemImage(nativeId, turnId, nativeItemId, index) {
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
export declare const LOADED_THREADS_PAGE_SIZE = 128;
|
|
2
2
|
export declare const MAX_LOADED_THREAD_PAGES = 8;
|
|
3
|
-
export declare const TURN_TIMES_PAGE_SIZE = 128;
|
|
4
|
-
export declare const MAX_TURN_TIME_PAGES = 8;
|
|
5
|
-
export declare const RUNNING_TURNS_CAPACITY = 1024;
|
|
6
3
|
export declare const SKILL_HINT_READ_CONCURRENCY = 8;
|
|
7
4
|
export declare const LOST_NOTIFICATIONS: Map<string, "unknown" | "turn-started" | "turn-completed" | "approval-resolved">;
|
|
8
5
|
export declare const KNOWN_NATIVE_STATES: readonly ["notLoaded", "idle", "systemError", "active"];
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
// threads read per page of the daemon's loaded threads, and the most pages one connection reads
|
|
2
2
|
export const LOADED_THREADS_PAGE_SIZE = 128;
|
|
3
3
|
export const MAX_LOADED_THREAD_PAGES = 8;
|
|
4
|
-
// turns read per page when timing a history page's items, and the most pages one page reads
|
|
5
|
-
export const TURN_TIMES_PAGE_SIZE = 128;
|
|
6
|
-
export const MAX_TURN_TIME_PAGES = 8;
|
|
7
|
-
// the most threads whose running turn the live events keep
|
|
8
|
-
export const RUNNING_TURNS_CAPACITY = 1024;
|
|
9
4
|
// the most skill files a catalog read reads at once for their argument hints
|
|
10
5
|
export const SKILL_HINT_READ_CONCURRENCY = 8;
|
|
11
6
|
// the lifecycle notifications whose loss a live re-check of the session makes up for
|
|
@@ -6,10 +6,10 @@ import { HQ_ERRORS } from '../../errors/index.js';
|
|
|
6
6
|
import { toTurnResult } from '../results/index.js';
|
|
7
7
|
import { NativeIdSchema } from '../../contracts/identities/index.js';
|
|
8
8
|
import { parseActionRequest } from '../utilities.js';
|
|
9
|
-
import { LOST_NOTIFICATIONS
|
|
9
|
+
import { LOST_NOTIFICATIONS } from './constants.js';
|
|
10
10
|
import { NativeItemSchema, NativeThreadSchema, NativeThreadStatusSchema, NativeTurnSchema, } from './types.js';
|
|
11
11
|
import { parseNative } from './validations.js';
|
|
12
|
-
import { toHistoryItem, toNativeLineage, toNativeState, toSessionState
|
|
12
|
+
import { toHistoryItem, toNativeLineage, toNativeState, toSessionState } from './transformers.js';
|
|
13
13
|
import { buildCodexReply, parseCodexPrompt, toApprovalPresentation } from './approvals/index.js';
|
|
14
14
|
const TargetSchema = z.object({ threadId: NativeIdSchema, turnId: NativeIdSchema });
|
|
15
15
|
const DeltaSchema = TargetSchema.extend({ itemId: NativeIdSchema, delta: z.string() });
|
|
@@ -29,8 +29,6 @@ export const createCodexEvents = (native, events, observeSession, observeLoaded)
|
|
|
29
29
|
let connectionId = randomUUID();
|
|
30
30
|
const scopedRequestId = (id) => JSON.stringify([connectionId, id]);
|
|
31
31
|
const turns = new Map();
|
|
32
|
-
// each thread's running turn, which times its live items
|
|
33
|
-
const runningTurns = new Map();
|
|
34
32
|
/**
|
|
35
33
|
* Keeps HQ's result capture in step with a turn whose start or end failed validation: a lost
|
|
36
34
|
* start still binds the capture prepared for HQ's input, and a lost end drops its turn's capture,
|
|
@@ -63,11 +61,6 @@ export const createCodexEvents = (native, events, observeSession, observeLoaded)
|
|
|
63
61
|
// a second turn started for HQ's own input breaks the protocol
|
|
64
62
|
if (captured?.turnId && captured.turnId !== turn.id)
|
|
65
63
|
parseNative(z.never(), params);
|
|
66
|
-
const summary = toTurnSummary(turn);
|
|
67
|
-
runningTurns.delete(threadId);
|
|
68
|
-
if (runningTurns.size >= RUNNING_TURNS_CAPACITY)
|
|
69
|
-
runningTurns.delete(runningTurns.keys().next().value);
|
|
70
|
-
runningTurns.set(threadId, summary);
|
|
71
64
|
if (captured)
|
|
72
65
|
captured.turnId = turn.id;
|
|
73
66
|
events.observe({
|
|
@@ -78,8 +71,6 @@ export const createCodexEvents = (native, events, observeSession, observeLoaded)
|
|
|
78
71
|
});
|
|
79
72
|
}
|
|
80
73
|
else if (turn.status !== 'inProgress') {
|
|
81
|
-
if (runningTurns.get(threadId)?.nativeId === turn.id)
|
|
82
|
-
runningTurns.delete(threadId);
|
|
83
74
|
const pending = turns.get(threadId);
|
|
84
75
|
const captured = pending?.turnId === turn.id ? pending : undefined;
|
|
85
76
|
const result = captured
|
|
@@ -108,7 +99,11 @@ export const createCodexEvents = (native, events, observeSession, observeLoaded)
|
|
|
108
99
|
parseNative(z.never(), params);
|
|
109
100
|
}
|
|
110
101
|
else if (method === 'item/started' || method === 'item/completed') {
|
|
111
|
-
const { threadId, turnId, item } = parseNative(TargetSchema.extend({
|
|
102
|
+
const { threadId, turnId, item, startedAtMs, completedAtMs } = parseNative(TargetSchema.extend({
|
|
103
|
+
item: NativeItemSchema.shape.item,
|
|
104
|
+
startedAtMs: NativeItemSchema.shape.startedAtMs,
|
|
105
|
+
completedAtMs: NativeItemSchema.shape.completedAtMs,
|
|
106
|
+
}), params);
|
|
112
107
|
const captured = turns.get(threadId);
|
|
113
108
|
if (captured?.turnId === turnId &&
|
|
114
109
|
method === 'item/completed' &&
|
|
@@ -125,8 +120,7 @@ export const createCodexEvents = (native, events, observeSession, observeLoaded)
|
|
|
125
120
|
captured.text = message.text;
|
|
126
121
|
}
|
|
127
122
|
}
|
|
128
|
-
const
|
|
129
|
-
const presented = toHistoryItem({ turnId, item }, running?.nativeId === turnId ? running : undefined);
|
|
123
|
+
const presented = toHistoryItem({ turnId, item, startedAtMs, completedAtMs });
|
|
130
124
|
if (presented)
|
|
131
125
|
events.item(threadId, presented, method === 'item/completed');
|
|
132
126
|
}
|
|
@@ -307,7 +301,6 @@ export const createCodexEvents = (native, events, observeSession, observeLoaded)
|
|
|
307
301
|
connectionId = randomUUID();
|
|
308
302
|
// a disconnected stream cannot supply a complete result from its partial capture
|
|
309
303
|
turns.clear();
|
|
310
|
-
runningTurns.clear();
|
|
311
304
|
events.unavailable();
|
|
312
305
|
},
|
|
313
306
|
connected: () => observeLoaded(),
|
|
@@ -24,15 +24,14 @@ export declare const toThreadSummary: (thread: INativeThread) => IThreadSummary;
|
|
|
24
24
|
export declare const toTurnSummary: (turn: INativeTurn) => ITurnSummary;
|
|
25
25
|
/**
|
|
26
26
|
* Presents one native item as the CLI shows it, shared by history pages, live items and evidence.
|
|
27
|
-
* Outcome and files come from the full item, before the text is cut.
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* known has no time.
|
|
27
|
+
* Outcome and files come from the full item, before the text is cut. Native lifecycle times are
|
|
28
|
+
* already milliseconds: operator input prefers its start, other items their completion. A
|
|
29
|
+
* missing preferred time uses the other item time; absent item times never use a turn's time.
|
|
31
30
|
* @returns The item, or null for reasoning, which the CLI leaves out of history.
|
|
32
31
|
* @throws
|
|
33
32
|
* - JG_AGENT_HQ_CODEX_FAILED: The Codex integration failed
|
|
34
33
|
*/
|
|
35
|
-
export declare const toHistoryItem: ({ turnId, item
|
|
34
|
+
export declare const toHistoryItem: ({ turnId, item, startedAtMs, completedAtMs }: INativeItem, fullBody?: boolean) => IHistoryItem | null;
|
|
36
35
|
/**
|
|
37
36
|
* Lists the images a native item holds or names, in order: an image view's file, and a user
|
|
38
37
|
* message's attached files and images, an image it holds as a data URL described by its data.
|
|
@@ -112,15 +112,14 @@ const toHistoryFile = (change) => {
|
|
|
112
112
|
};
|
|
113
113
|
/**
|
|
114
114
|
* Presents one native item as the CLI shows it, shared by history pages, live items and evidence.
|
|
115
|
-
* Outcome and files come from the full item, before the text is cut.
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* known has no time.
|
|
115
|
+
* Outcome and files come from the full item, before the text is cut. Native lifecycle times are
|
|
116
|
+
* already milliseconds: operator input prefers its start, other items their completion. A
|
|
117
|
+
* missing preferred time uses the other item time; absent item times never use a turn's time.
|
|
119
118
|
* @returns The item, or null for reasoning, which the CLI leaves out of history.
|
|
120
119
|
* @throws
|
|
121
120
|
* - JG_AGENT_HQ_CODEX_FAILED: The Codex integration failed
|
|
122
121
|
*/
|
|
123
|
-
export const toHistoryItem = ({ turnId, item
|
|
122
|
+
export const toHistoryItem = ({ turnId, item, startedAtMs, completedAtMs }, fullBody = false) => {
|
|
124
123
|
let kind = 'unsupported';
|
|
125
124
|
let text = '';
|
|
126
125
|
// the text part a user message's input sent first, which links it to the action that sent it
|
|
@@ -203,11 +202,9 @@ export const toHistoryItem = ({ turnId, item }, turn, fullBody = false) => {
|
|
|
203
202
|
callId: null,
|
|
204
203
|
outcome,
|
|
205
204
|
files,
|
|
206
|
-
createdAt:
|
|
207
|
-
? null
|
|
208
|
-
: item.
|
|
209
|
-
? turn.startedAt
|
|
210
|
-
: (turn.completedAt ?? turn.startedAt),
|
|
205
|
+
createdAt: item.type === 'userMessage'
|
|
206
|
+
? (startedAtMs ?? item.startedAtMs ?? completedAtMs ?? item.completedAtMs ?? null)
|
|
207
|
+
: (completedAtMs ?? item.completedAtMs ?? startedAtMs ?? item.startedAtMs ?? null),
|
|
211
208
|
});
|
|
212
209
|
};
|
|
213
210
|
// the fields a detail reads beyond what history presents
|
|
@@ -48,9 +48,13 @@ export declare const TurnSummarySchema: z.ZodObject<{
|
|
|
48
48
|
export type ITurnSummary = z.infer<typeof TurnSummarySchema>;
|
|
49
49
|
export declare const NativeItemSchema: z.ZodObject<{
|
|
50
50
|
turnId: z.ZodString;
|
|
51
|
+
startedAtMs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
52
|
+
completedAtMs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
51
53
|
item: z.ZodObject<{
|
|
52
54
|
id: z.ZodString;
|
|
53
55
|
type: z.ZodString;
|
|
56
|
+
startedAtMs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
57
|
+
completedAtMs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
54
58
|
}, z.core.$catchall<z.ZodUnknown>>;
|
|
55
59
|
}, z.core.$strip>;
|
|
56
60
|
export declare const NativeThreadPageSchema: z.ZodObject<{
|
|
@@ -88,9 +92,13 @@ export declare const NativeTurnPageSchema: z.ZodObject<{
|
|
|
88
92
|
export declare const NativeItemPageSchema: z.ZodObject<{
|
|
89
93
|
data: z.ZodArray<z.ZodObject<{
|
|
90
94
|
turnId: z.ZodString;
|
|
95
|
+
startedAtMs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
96
|
+
completedAtMs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
91
97
|
item: z.ZodObject<{
|
|
92
98
|
id: z.ZodString;
|
|
93
99
|
type: z.ZodString;
|
|
100
|
+
startedAtMs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
101
|
+
completedAtMs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
94
102
|
}, z.core.$catchall<z.ZodUnknown>>;
|
|
95
103
|
}, z.core.$strip>>;
|
|
96
104
|
nextCursor: z.ZodNullable<z.ZodString>;
|
|
@@ -32,10 +32,25 @@ export const TurnSummarySchema = z.object({
|
|
|
32
32
|
startedAt: z.number().int().nullable(),
|
|
33
33
|
completedAt: z.number().int().nullable(),
|
|
34
34
|
});
|
|
35
|
+
// recorded native item lifecycle times are milliseconds; older producers may omit them
|
|
36
|
+
const NativeItemTimeSchema = z
|
|
37
|
+
.number()
|
|
38
|
+
.int()
|
|
39
|
+
.safe()
|
|
40
|
+
.nonnegative()
|
|
41
|
+
.max(8_640_000_000_000_000)
|
|
42
|
+
.nullish();
|
|
35
43
|
export const NativeItemSchema = z.object({
|
|
36
44
|
turnId: z.string().min(1).max(4096),
|
|
45
|
+
startedAtMs: NativeItemTimeSchema,
|
|
46
|
+
completedAtMs: NativeItemTimeSchema,
|
|
37
47
|
item: z
|
|
38
|
-
.object({
|
|
48
|
+
.object({
|
|
49
|
+
id: z.string().min(1).max(4096),
|
|
50
|
+
type: z.string().min(1).max(256),
|
|
51
|
+
startedAtMs: NativeItemTimeSchema,
|
|
52
|
+
completedAtMs: NativeItemTimeSchema,
|
|
53
|
+
})
|
|
39
54
|
.catchall(z.unknown()),
|
|
40
55
|
});
|
|
41
56
|
export const NativeThreadPageSchema = z.object({
|
|
@@ -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