jg-agent-hq 13.4.0 → 13.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 13.4.2
4
+
5
+ - Reconcile completed Claude messages and tool activity by their session-scoped native UUID when autonomous follow-ups have a generated live turn ID but saved history groups them under the preceding input. Completed activity no longer remains live below later answers. Operator inputs retain exact turn/provenance checks, and Codex reconciliation is unchanged.
6
+ - Read bounded recent Claude history at turn completion so autonomous output flushes without waiting for a client history read. Preserve the existing page, retry and live-memory bounds, storage schema and action key.
7
+
8
+ ## 13.4.1
9
+
10
+ - Normalize Codex asynchronous questions with native `options: null` to free-text questions without suggested choices. Preserve the existing public question shape, bounds and malformed-input rejection across live observations, saved history, details and evidence.
11
+
3
12
  ## 13.4.0
4
13
 
5
14
  - Add the optional trusted Node `initializeHostStorage` startup callback for host schema preparation under exclusive ownership, before providers, native rejoin or request admission start. Callback errors retain their identity through startup cleanup; hosts own their SQL transaction and connection.
package/README.md CHANGED
@@ -31,6 +31,8 @@ Work on `development`; reviewed changes reach `main` through a pull request. Aft
31
31
 
32
32
  `pnpm test`, `pnpm check:package`, and `pnpm check` run essential coverage. Their `:full` counterparts retain complete package or package/website checks. Granular and focused commands remain complete by default. Full runs locally only on explicit request; see the [testing policy](https://github.com/jesusgraterol/jg-agent-hq/blob/main/docs/testing.md) for classification and affected-consumer checks.
33
33
 
34
+ CI qualifies the package on both supported Node versions through `pnpm check:package`. Website verification and deployment run separately through Pages after successful main publication; a website failure does not block npm publication.
35
+
34
36
  Testing maintenance can reuse an existing version when only these six aggregate scripts and this marked testing-command block differ. All runtime files, dependencies, exports, installation scripts, other documentation, and file permissions remain protected by the release check. This narrow exception to the general version rule above skips publication; it does not change the installed package.
35
37
 
36
38
  [testing-commands:end]: #
package/api/README.md CHANGED
@@ -258,7 +258,7 @@ File timestamps and records do not prove that a native process is idle or a turn
258
258
 
259
259
  An explicit Codex `agentMessage` with `delivery: 'async'` carries optional `asyncInput` on its normalized history item. The same metadata is available in live items, item details and every evidence fragment. Ordinary messages have no `asyncInput`; text or a `questions` field alone never establishes async semantics.
260
260
 
261
- Available metadata is `{ delivery: 'async', state: 'available', questions }`. Each ordered question has a nonempty `title` and optional ordered string `options`. Question and choice strings retain their exact content, up to 8192 UTF-16 code units each, with at most 32 questions and 32 choices per question. The entire normalized `asyncInput` must fit `MAX_ASYNC_INPUT_BYTES` (32768 serialized UTF-8 bytes, including JSON escaping). Additive native fields are tolerated. Malformed contracts retain ordinary preview text and `{ delivery: 'async', state: 'unavailable', reason: 'invalid' }`; valid shapes over the byte budget use `reason: 'too-large'`. Choices are never shortened to fit a response. Evidence fitting accounts for metadata before selecting its text chunk; live memory accounting includes the complete serialized item, and saved/live reconciliation requires matching async metadata.
261
+ Available metadata is `{ delivery: 'async', state: 'available', questions }`. Each ordered question has a nonempty `title` and optional ordered string `options`. Native `options: null` is normalized to an omitted `options` field for free-text questions. Question and choice strings retain their exact content, up to 8192 UTF-16 code units each, with at most 32 questions and 32 choices per question. The entire normalized `asyncInput` must fit `MAX_ASYNC_INPUT_BYTES` (32768 serialized UTF-8 bytes, including JSON escaping). Additive native fields are tolerated. Malformed contracts retain ordinary preview text and `{ delivery: 'async', state: 'unavailable', reason: 'invalid' }`; valid shapes over the byte budget use `reason: 'too-large'`. Choices are never shortened to fit a response. Evidence fitting accounts for metadata before selecting its text chunk; live memory accounting includes the complete serialized item, and saved/live reconciliation requires matching async metadata.
262
262
 
263
263
  `hq.observeAsyncInputs(listener)` is a trusted in-process Node API, independent of IPC/browser readers. It returns an idempotent unsubscribe function. The listener synchronously enqueues bounded host work; it must not block, return asynchronous work or use observations as authority. An `item` event contains `source: { threadId, provider, nativeId, workspaceRoot }` and the complete normalized `item`. `threadId` names the managed record. Only completed items from controlled sessions with a validated source are emitted; partial updates and external sessions are excluded. Each listener receives its own copy.
264
264
 
@@ -393,7 +393,7 @@ The installed CLI exposes `suggest-thread-name --topic <topic>`. Suggestions nor
393
393
 
394
394
  Control pages default to 32 and cap at 128. Seek cursors are bound to their complete query and ordering. Reads recheck allowed workspaces. Rejected controls retain their known thread association, and native availability failures appear in each affected thread's replay. Lifecycle replay contains metadata, not token or tool output. Each provider has a bounded native lifecycle backlog; overflow stops that source and marks its state uncertain rather than losing events silently. Live items don't count toward it. The runtime recognizes a repeated lifecycle observation within one runtime; startup forgets the observations earlier runtimes recorded. Other providers retain their independent connection and admission state.
395
395
 
396
- Live item presentation is bounded to 128 items per cached thread, 32 windows and 4 MiB of serialized presentation across the runtime, including escaped text and identifiers. This leaves room inside the IPC response limit. Display text uses the same truncation contract as native history. Eviction, an unavailable window or missing chunks sets `hasGap`. Completed items remain `awaiting-flush` after thread closure until a native history page holds the same item, with exactly matching normalized content or, for an item with an outcome, the same final outcome, or the bounded cache evicts them. A message Claude Code saved as a queued command matches the live input its `provenance.nativeInputId` names. The outcome is enough because Codex shortens long command output when it saves it. An item still streaming when its turn ended, such as a message an interrupt or a Codex steer cut, stays `awaiting-flush` until a native history page holds an item of that turn, since the provider may never save it; the history then shows what was saved of it. A client's `items` read is one such page, and when a turn ends the runtime reads that turn's own history too, newest first and at most 8 pages of 128, until none of its finished items remain, so the window doesn't wait on a client that never reads them. Codex's saved state can trail its turn's end, so a turn whose items remain is read once more 2 seconds later; a failed read leaves them to the next history read. A client that shows live items should therefore expect them to leave the window before its own history read holds them. Read persisted history and the live window together after reconnect; a process restart cannot reconstruct unflushed in-memory content.
396
+ 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. Claude output matches its session-scoped native UUID even when an autonomous live turn has a generated ID and saved history groups it under the preceding input; its kind, native type and content/outcome must still match. Operator inputs retain exact turn matching. A message Claude Code saved as a queued command matches the live input its `provenance.nativeInputId` names. The outcome is enough because Codex shortens long command output when it saves it. An item still streaming when its turn ended, such as a message an interrupt or a Codex steer cut, stays `awaiting-flush` until a native history page holds an item of that turn, since the provider may never save it; the history then shows what was saved of it. A client's `items` read is one such page, and when a turn ends the runtime also reads saved history, 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 reads that turn's own history; Claude reads recent session history because an autonomous live turn has no corresponding saved turn ID. 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.
397
397
 
398
398
  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.
399
399
 
@@ -162,7 +162,8 @@ export const createEvents = (context, dispatcher, reconnect) => {
162
162
  /*
163
163
  * A saved item leaves the live window only once a native history page holds it, and a client may
164
164
  * never read the pages that do, so a finished turn's own history is read here, newest first,
165
- * until none of its saved items remain. Codex's saved state can trail its turn's end, so a turn
165
+ * until none of its saved items remain. Claude's native follow-ups have no saved turn ID, so
166
+ * its read spans recent history instead. Codex's saved state can trail its turn's end, so a turn
166
167
  * whose items remain is read once more after the re-check wait. An aborted wait or a failed read
167
168
  * leaves them to the next history read, as before, and never fails the session's events.
168
169
  */
@@ -187,7 +188,7 @@ export const createEvents = (context, dispatcher, reconnect) => {
187
188
  provider,
188
189
  workspaceRoot,
189
190
  nativeId,
190
- turnId,
191
+ ...(provider === 'claude' ? {} : { turnId }),
191
192
  limit: MAX_PAGE_SIZE,
192
193
  cursor,
193
194
  textLimit: MAX_ITEM_TEXT_LENGTH,
@@ -201,7 +202,7 @@ export const createEvents = (context, dispatcher, reconnect) => {
201
202
  live.invalidateProvenance(liveKey);
202
203
  },
203
204
  });
204
- live.reconcile(liveKey, response.result.data);
205
+ live.reconcile(provider, liveKey, response.result.data);
205
206
  if (response.result.nextCursor === null)
206
207
  break;
207
208
  cursor = response.result.nextCursor;
@@ -1,4 +1,4 @@
1
- import type { IHistoryItem } from '../../contracts/index.js';
1
+ import type { IHistoryItem, IProviderId } from '../../contracts/index.js';
2
2
  /**
3
3
  * Keeps a bounded presentation window until matching native history has been flushed. Every
4
4
  * change takes a new revision and is reported.
@@ -52,8 +52,10 @@ export declare class LiveItems {
52
52
  * finished goes once persisted history holds that turn, which then shows what was saved of it.
53
53
  * A message saved under another record than the live input it came from, as Claude Code saves a
54
54
  * message sent while a turn ran, matches that input by the native input it names.
55
+ * Claude output UUIDs identify messages within the session even when a generated live turn
56
+ * differs from history's input-based grouping. Operator input still requires the exact turn.
55
57
  */
56
- reconcile(nativeId: string, persisted: IHistoryItem[]): void;
58
+ reconcile(provider: IProviderId, nativeId: string, persisted: IHistoryItem[]): void;
57
59
  /**
58
60
  * Says whether a turn's window still holds a finished item no native history page has held.
59
61
  * @param nativeId The session's key.
@@ -154,8 +154,10 @@ export class LiveItems {
154
154
  * finished goes once persisted history holds that turn, which then shows what was saved of it.
155
155
  * A message saved under another record than the live input it came from, as Claude Code saves a
156
156
  * message sent while a turn ran, matches that input by the native input it names.
157
+ * Claude output UUIDs identify messages within the session even when a generated live turn
158
+ * differs from history's input-based grouping. Operator input still requires the exact turn.
157
159
  */
158
- reconcile(nativeId, persisted) {
160
+ reconcile(provider, nativeId, persisted) {
159
161
  const thread = this.__threads.get(nativeId);
160
162
  if (!thread)
161
163
  return;
@@ -166,13 +168,19 @@ export class LiveItems {
166
168
  thread.items.delete(key);
167
169
  thread.revision = this.__change();
168
170
  }
171
+ const outputKeys = provider === 'claude'
172
+ ? new Map([...thread.items]
173
+ .filter(([, entry]) => entry.item.kind !== 'user-message')
174
+ .map(([key, entry]) => [entry.item.nativeId, key]))
175
+ : null;
169
176
  for (const item of persisted) {
170
177
  const { nativeInputId } = item.provenance;
171
178
  const liveIds = item.kind === 'user-message' && nativeInputId !== null && nativeInputId !== item.nativeId
172
179
  ? [item.nativeId, nativeInputId]
173
180
  : [item.nativeId];
174
181
  for (const liveId of liveIds) {
175
- const key = JSON.stringify([item.turnId, liveId]);
182
+ const key = (item.kind === 'user-message' ? undefined : outputKeys?.get(liveId)) ??
183
+ JSON.stringify([item.turnId, liveId]);
176
184
  const entry = thread.items.get(key);
177
185
  if (entry?.isComplete &&
178
186
  (liveId === item.nativeId ||
@@ -70,11 +70,15 @@ const TextPartsSchema = z.object({
70
70
  .max(128),
71
71
  });
72
72
  const MessageSchema = z.object({ text: z.string() });
73
+ // Codex serializes absent suggested choices as null; the public contract omits them.
74
+ const NativeAsyncQuestionSchema = AsyncQuestionSchema.extend({
75
+ options: AsyncQuestionSchema.shape.options.nullable(),
76
+ }).transform(({ options, ...question }) => (options == null ? question : { ...question, options }));
73
77
  /** Preserves explicit async delivery even when its structured presentation cannot be trusted. */
74
78
  const toAsyncInput = (item) => {
75
79
  if (item.type !== 'agentMessage' || item.delivery !== 'async')
76
80
  return undefined;
77
- const questions = z.array(AsyncQuestionSchema).min(1).max(32).safeParse(item.questions);
81
+ const questions = z.array(NativeAsyncQuestionSchema).min(1).max(32).safeParse(item.questions);
78
82
  if (!questions.success)
79
83
  return { delivery: 'async', state: 'unavailable', reason: 'invalid' };
80
84
  const input = AsyncInputSchema.safeParse({
@@ -292,7 +292,7 @@ export const createAgentHq = async (options) => {
292
292
  if (command.kind !== 'items' || response.kind !== 'items')
293
293
  return response;
294
294
  // live items reconcile against the persisted text before it is cut
295
- actions.live.reconcile(JSON.stringify([command.provider, command.nativeId]), response.result.data);
295
+ actions.live.reconcile(command.provider, JSON.stringify([command.provider, command.nativeId]), response.result.data);
296
296
  return {
297
297
  ...response,
298
298
  result: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jg-agent-hq",
3
- "version": "13.4.0",
3
+ "version": "13.4.2",
4
4
  "description": "Native Claude Code and Codex session control, history, usage and recoverable local storage for Node.js apps.",
5
5
  "type": "module",
6
6
  "license": "MIT",