jg-agent-hq 10.7.0 → 10.8.0

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,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 10.8.0
4
+
5
+ - Report how many commands a session runs in the background. The `live-items` window carries `backgroundCommands`, the count Claude last reported for a session HQ controls, 0 once its process stopped or when its provider reports none, and a change of it is a new revision, so a client that follows the window sees a command keep running after the turn that started it ended, until Claude resumes the session. Providers report it through a new `background` event.
6
+
3
7
  ## 10.7.0
4
8
 
5
9
  - Accept up to 16,777,216 bytes of files per input, each text file up to 262,144 bytes, up from 2,097,152 and 65,536. `capabilities.inputSchema` reports the new `maxFileBytes` and `maxTextFileBytes`.
package/api/README.md CHANGED
@@ -327,18 +327,18 @@ Trusted runtime construction also accepts `codexExtraSkillRoots?: string[]` and
327
327
 
328
328
  ## Control reads and reconnect
329
329
 
330
- | Command | Fields | Result |
331
- | --------------------- | ------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
332
- | `managed-threads` | `workspaceRoot`, optional `limit`, `cursor` | Creation/UUID seek page of HQ records, including inactive and uncertain states. |
333
- | `managed-thread` | `threadId` | One HQ record or null. |
334
- | `managed-thread-name` | `name` | One HQ record or null, with case-insensitive lookup and the same workspace authorization. |
335
- | `suggest-thread-name` | `topic` | An editable lowercase label, with a currently free suffix when needed. This read does not reserve it. |
336
- | `receipt` | `actionId` | One receipt or null. |
337
- | `action-wait` | `actionId`, `until`, `timeoutMs` | The receipt once it reaches `until`, or as it stands when `timeoutMs` passes, with `isTimedOut`. |
338
- | `actions` | `threadId`, optional `limit`, `cursor` | Creation/UUID seek page of action metadata without queued bodies. |
339
- | `events` | `threadId`, optional `after` (default 0), `limit` | Ascending durable sequence page and `hasMore`; continue after the final sequence. |
340
- | `approvals` | `threadId`, optional `state`, `limit`, `cursor` | Durable approval metadata pages with nullable live presentation. |
341
- | `live-items` | `threadId` | Active/awaiting-flush item window, `hasGap`, `revision` and `unchanged`. Optional `afterRevision` omits bodies for an unchanged window. |
330
+ | Command | Fields | Result |
331
+ | --------------------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
332
+ | `managed-threads` | `workspaceRoot`, optional `limit`, `cursor` | Creation/UUID seek page of HQ records, including inactive and uncertain states. |
333
+ | `managed-thread` | `threadId` | One HQ record or null. |
334
+ | `managed-thread-name` | `name` | One HQ record or null, with case-insensitive lookup and the same workspace authorization. |
335
+ | `suggest-thread-name` | `topic` | An editable lowercase label, with a currently free suffix when needed. This read does not reserve it. |
336
+ | `receipt` | `actionId` | One receipt or null. |
337
+ | `action-wait` | `actionId`, `until`, `timeoutMs` | The receipt once it reaches `until`, or as it stands when `timeoutMs` passes, with `isTimedOut`. |
338
+ | `actions` | `threadId`, optional `limit`, `cursor` | Creation/UUID seek page of action metadata without queued bodies. |
339
+ | `events` | `threadId`, optional `after` (default 0), `limit` | Ascending durable sequence page and `hasMore`; continue after the final sequence. |
340
+ | `approvals` | `threadId`, optional `state`, `limit`, `cursor` | Durable approval metadata pages with nullable live presentation. |
341
+ | `live-items` | `threadId` | Active/awaiting-flush item window, `hasGap`, `revision`, `unchanged` and `backgroundCommands`, the commands the session runs in the background as its provider last reported, which Claude reports and 0 once its process stopped. A change of that count is a new revision. Optional `afterRevision` omits bodies for an unchanged window. |
342
342
 
343
343
  `{ kind: 'action-wait', actionId, until, timeoutMs }` waits on one receipt instead of polling `receipt`, and returns `{ receipt, isTimedOut }`. `until: 'native'` returns once the receipt has a `nativeThreadId`, as soon as HQ records a created or forked session's native ID, and `until: 'settled'` once its `delivery` is `acknowledged`, `uncertain`, `failed` or `canceled`, which only late native evidence or an operator's recovery changes. A `native` wait also returns once the receipt settles without a native thread ID, such as after a failed creation, because nothing can then give it one. `timeoutMs`, from 1 to 30,000, bounds the wait; when it passes first, the receipt comes as it stands with `isTimedOut: true`. An unknown action returns a null receipt at once. The receipt's workspace is authorized as for `receipt`. HQ reads the receipt again only after the actions module records a change that can affect it, never on a timer. A wait still running when the runtime starts closing ends at once with RUNTIME_NOT_RUNNING. A wait is admitted work, so `withStorageMaintenance` waits for it to end, and over IPC it holds one of the 32 connections; its 30-second limit fits the 35-second IPC deadline.
344
344
 
@@ -591,6 +591,10 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
591
591
  if (controlled.has(key(provider, nativeId)))
592
592
  live.markGap(key(provider, nativeId));
593
593
  },
594
+ background(provider, nativeId, count) {
595
+ if (controlled.has(key(provider, nativeId)))
596
+ live.setBackgroundCommands(key(provider, nativeId), count);
597
+ },
594
598
  session(provider, nativeId, state) {
595
599
  observingProviders.add(provider);
596
600
  const sessionKey = key(provider, nativeId);
@@ -8,6 +8,8 @@ export declare class LiveItems {
8
8
  open(nativeId: string): void;
9
9
  /** Replaces one native item without persisting token or tool-output bodies. */
10
10
  put(nativeId: string, item: IHistoryItem, isComplete: boolean): void;
11
+ /** Records how many commands a session runs in the background, a change of its window. */
12
+ setBackgroundCommands(nativeId: string, count: number): void;
11
13
  /** Clears a reverted presentation and requires a fresh native history read. */
12
14
  reset(nativeId: string): void;
13
15
  /** Marks missing native stream evidence without discarding the surviving presentation. */
@@ -24,6 +26,7 @@ export declare class LiveItems {
24
26
  state: 'active' | 'awaiting-flush';
25
27
  })[];
26
28
  hasGap: boolean;
29
+ backgroundCommands: number;
27
30
  };
28
31
  /**
29
32
  * Drops completed items once persisted history holds them: with exactly matching normalized
@@ -11,7 +11,12 @@ export class LiveItems {
11
11
  return;
12
12
  if (this.__threads.size >= 32)
13
13
  this.__remove(this.__threads.keys().next().value);
14
- this.__threads.set(nativeId, { items: new Map(), hasGap: false, revision: ++this.__revision });
14
+ this.__threads.set(nativeId, {
15
+ items: new Map(),
16
+ hasGap: false,
17
+ revision: ++this.__revision,
18
+ backgroundCommands: 0,
19
+ });
15
20
  }
16
21
  /** Replaces one native item without persisting token or tool-output bodies. */
17
22
  put(nativeId, item, isComplete) {
@@ -19,7 +24,12 @@ export class LiveItems {
19
24
  if (!thread) {
20
25
  if (this.__threads.size >= 32)
21
26
  this.__remove(this.__threads.keys().next().value);
22
- thread = { items: new Map(), hasGap: true, revision: ++this.__revision };
27
+ thread = {
28
+ items: new Map(),
29
+ hasGap: true,
30
+ revision: ++this.__revision,
31
+ backgroundCommands: 0,
32
+ };
23
33
  this.__threads.set(nativeId, thread);
24
34
  }
25
35
  thread.revision = ++this.__revision;
@@ -39,10 +49,22 @@ export class LiveItems {
39
49
  this.__drop(candidate, candidate.items.keys().next().value);
40
50
  }
41
51
  }
52
+ /** Records how many commands a session runs in the background, a change of its window. */
53
+ setBackgroundCommands(nativeId, count) {
54
+ this.open(nativeId);
55
+ const thread = this.__threads.get(nativeId);
56
+ if (thread.backgroundCommands === count)
57
+ return;
58
+ thread.backgroundCommands = count;
59
+ thread.revision = ++this.__revision;
60
+ }
42
61
  /** Clears a reverted presentation and requires a fresh native history read. */
43
62
  reset(nativeId) {
63
+ // the session's background commands outlive its reverted presentation
64
+ const backgroundCommands = this.__threads.get(nativeId)?.backgroundCommands ?? 0;
44
65
  this.__remove(nativeId);
45
66
  this.open(nativeId);
67
+ this.__threads.get(nativeId).backgroundCommands = backgroundCommands;
46
68
  this.markGap(nativeId);
47
69
  }
48
70
  /** Marks missing native stream evidence without discarding the surviving presentation. */
@@ -101,6 +123,7 @@ export class LiveItems {
101
123
  }))
102
124
  : [],
103
125
  hasGap: thread?.hasGap ?? true,
126
+ backgroundCommands: thread?.backgroundCommands ?? 0,
104
127
  };
105
128
  }
106
129
  /**
@@ -143,6 +143,12 @@ export const readControl = async (command, store, actions, roots) => {
143
143
  kind: 'live-items',
144
144
  result: thread.nativeId
145
145
  ? actions.live.read(JSON.stringify([thread.provider, thread.nativeId]), command.afterRevision)
146
- : { data: [], hasGap: false, revision: 0, unchanged: command.afterRevision === 0 },
146
+ : {
147
+ data: [],
148
+ hasGap: false,
149
+ revision: 0,
150
+ unchanged: command.afterRevision === 0,
151
+ backgroundCommands: 0,
152
+ },
147
153
  };
148
154
  };
@@ -814,6 +814,7 @@ export declare const BrowserThreadDetailSchema: z.ZodObject<{
814
814
  }>;
815
815
  }, z.core.$strip>>;
816
816
  hasGap: z.ZodBoolean;
817
+ backgroundCommands: z.ZodNumber;
817
818
  }, z.core.$strip>;
818
819
  actions: z.ZodObject<{
819
820
  data: z.ZodArray<z.ZodObject<{
@@ -825,6 +825,7 @@ export declare const LiveItemsSchema: z.ZodObject<{
825
825
  }>;
826
826
  }, z.core.$strip>>;
827
827
  hasGap: z.ZodBoolean;
828
+ backgroundCommands: z.ZodNumber;
828
829
  }, z.core.$strip>;
829
830
  export declare const UsageCreditsSchema: z.ZodObject<{
830
831
  bucket: z.ZodString;
@@ -2992,6 +2993,7 @@ export declare const HqResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
2992
2993
  }>;
2993
2994
  }, z.core.$strip>>;
2994
2995
  hasGap: z.ZodBoolean;
2996
+ backgroundCommands: z.ZodNumber;
2995
2997
  }, z.core.$strip>;
2996
2998
  }, z.core.$strip>, z.ZodObject<{
2997
2999
  kind: z.ZodLiteral<"session-states">;
@@ -5702,6 +5704,7 @@ export declare const IpcResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
5702
5704
  }>;
5703
5705
  }, z.core.$strip>>;
5704
5706
  hasGap: z.ZodBoolean;
5707
+ backgroundCommands: z.ZodNumber;
5705
5708
  }, z.core.$strip>;
5706
5709
  }, z.core.$strip>, z.ZodObject<{
5707
5710
  kind: z.ZodLiteral<"session-states">;
@@ -272,6 +272,8 @@ export const LiveItemsSchema = z.object({
272
272
  unchanged: z.boolean(),
273
273
  data: z.array(HistoryItemSchema.extend({ state: z.enum(['active', 'awaiting-flush']) })).max(128),
274
274
  hasGap: z.boolean(),
275
+ // the commands the session runs in the background, as its provider last reported, 0 for none
276
+ backgroundCommands: z.number().int().nonnegative(),
275
277
  });
276
278
  // exact native credit observations; balances have no assumed currency or arithmetic semantics
277
279
  export const UsageCreditsSchema = z.object({
@@ -7,7 +7,7 @@ import { toClaudeConfiguration } from '../configuration/index.js';
7
7
  import { createClaudeExtensions } from '../extensions/index.js';
8
8
  import { createClaudeRpc } from '../rpc.js';
9
9
  import { ClaudeInitializeSchema } from '../types.js';
10
- import { failSteers, getActiveTurn, receiveClaudeMessage } from './stream.js';
10
+ import { failSteers, getActiveTurn, receiveClaudeMessage, setBackgroundCommands, } from './stream.js';
11
11
  import { toClaudeSkills } from './skills.js';
12
12
  // a session idle this long since its last turn ended gives up its process until it is needed
13
13
  const IDLE_STOP_SECONDS = 3_600;
@@ -227,11 +227,13 @@ export const createClaudeControl = (additionalDirectories = []) => {
227
227
  session.isResumed = isResume || forkSourceNativeId !== undefined;
228
228
  // a new process has no turn of its own and no background commands yet
229
229
  session.nativeTurn = undefined;
230
- session.backgroundTaskCount = 0;
230
+ setBackgroundCommands(session, 0, events);
231
231
  const connection = await createClaudeRpc((reason) => {
232
232
  if (reason !== 'unavailable' || session.isClosing || session.parked)
233
233
  return;
234
234
  failSteers(session);
235
+ // the commands stopped with the process
236
+ setBackgroundCommands(session, 0, events);
235
237
  if (session.input) {
236
238
  clearTimeout(session.input.timer);
237
239
  session.input.reject(new Exception('The Claude integration failed', {
@@ -695,8 +697,9 @@ export const createClaudeControl = (additionalDirectories = []) => {
695
697
  conflict();
696
698
  cancelIdleStop(session);
697
699
  session.isClosing = true;
698
- // a stopped process replays nothing more
700
+ // a stopped process replays nothing more, and its background commands stop with it
699
701
  failSteers(session);
702
+ setBackgroundCommands(session, 0, events);
700
703
  // a parked session finishes without a process
701
704
  await session.transition?.catch(() => undefined);
702
705
  await session.opening.catch((cause) => {
@@ -4,6 +4,14 @@ import type { IClaudeControlEvents, IClaudeSession, IClaudeTurn } from './types.
4
4
  * input's. Input still waiting for its replay has no turn yet.
5
5
  */
6
6
  export declare const getActiveTurn: (session: IClaudeSession) => IClaudeTurn | undefined;
7
+ /**
8
+ * Records how many commands the session runs in the background and reports a change, which HQ
9
+ * shows while no turn runs, since Claude resumes the session itself once one finishes.
10
+ * @param session The session.
11
+ * @param count The commands Claude now reports, 0 once its process stopped with them.
12
+ * @param events Where the change goes.
13
+ */
14
+ export declare const setBackgroundCommands: (session: IClaudeSession, count: number, events: IClaudeControlEvents | undefined) => void;
7
15
  /**
8
16
  * Fails the steers Claude never replayed, as when its process stops, so no steer waits forever.
9
17
  * @param session The session.
@@ -127,6 +127,19 @@ const startNativeTurn = (session, events) => {
127
127
  });
128
128
  return turn;
129
129
  };
130
+ /**
131
+ * Records how many commands the session runs in the background and reports a change, which HQ
132
+ * shows while no turn runs, since Claude resumes the session itself once one finishes.
133
+ * @param session The session.
134
+ * @param count The commands Claude now reports, 0 once its process stopped with them.
135
+ * @param events Where the change goes.
136
+ */
137
+ export const setBackgroundCommands = (session, count, events) => {
138
+ if (session.backgroundTaskCount === count)
139
+ return;
140
+ session.backgroundTaskCount = count;
141
+ events?.background(session.id, count);
142
+ };
130
143
  /**
131
144
  * Fails the steers Claude never replayed, as when its process stops, so no steer waits forever.
132
145
  * @param session The session.
@@ -445,7 +458,7 @@ export const receiveClaudeMessage = (session, raw, events) => {
445
458
  // a list in an unexpected shape leaves the count as it was, as parking only waits on it
446
459
  const background = BackgroundTasksSchema.safeParse(raw);
447
460
  if (background.success)
448
- session.backgroundTaskCount = background.data.tasks.length;
461
+ setBackgroundCommands(session, background.data.tasks.length, events);
449
462
  observeFastMode(session, raw);
450
463
  }
451
464
  };
@@ -5,6 +5,7 @@ export type IClaudeControlEvents = {
5
5
  observe(observation: INativeObservation): void;
6
6
  item(nativeId: string, item: IHistoryItem, isComplete: boolean, replacedIds?: string[]): void;
7
7
  gap(nativeId: string): void;
8
+ background(nativeId: string, count: number): void;
8
9
  delta(nativeId: string, turnId: string, itemId: string, text: string): void;
9
10
  prompt(prompt: INativePrompt): void;
10
11
  outcome(outcome: IAgentProviderOutcome): void;
@@ -2051,6 +2051,7 @@ export declare const ClaudeHistoryReadSchema: z.ZodUnion<readonly [z.ZodDiscrimi
2051
2051
  }>;
2052
2052
  }, z.core.$strip>>;
2053
2053
  hasGap: z.ZodBoolean;
2054
+ backgroundCommands: z.ZodNumber;
2054
2055
  }, z.core.$strip>;
2055
2056
  }, z.core.$strip>, z.ZodObject<{
2056
2057
  kind: z.ZodLiteral<"session-states">;
@@ -0,0 +1 @@
1
+ export declare const MAX_BACKGROUND_COMMANDS = 1024;
@@ -0,0 +1,2 @@
1
+ // the most background commands a provider may report for one session
2
+ export const MAX_BACKGROUND_COMMANDS = 1024;
@@ -8,6 +8,7 @@ import { resetProvenance } from '../../sessions/evidence/index.js';
8
8
  import { ApprovalRecordSchema } from '../../store/control/index.js';
9
9
  import { ProviderMcpServerPageSchema, ProviderMcpToolsSchema, ProviderMcpResourcesSchema, } from '../extensions/index.js';
10
10
  import { ProviderInspectionSchema, ProviderReattachmentSchema, ProviderThreadSchema, ProviderSkillsSchema, ResyncLossSchema, } from '../index.js';
11
+ import { MAX_BACKGROUND_COMMANDS } from './constants.js';
11
12
  import { capabilityUnavailable, normalizeProviderError } from './utilities.js';
12
13
  import { parseProviderObservation, parseProviderOutcome, rejectProviderResponse, validateProviderHistory, } from './validations.js';
13
14
  const CleanupSchema = z.object({ cleanupUnconfirmed: z.literal(true) });
@@ -149,6 +150,7 @@ export const createProviderRegistry = (registrations, allowedRoots, runtimeEpoch
149
150
  : z.array(NativeIdSchema).max(128).parse(replacedIds));
150
151
  }),
151
152
  gap: (nativeId) => deliver(() => handlers?.gap(provider, NativeIdSchema.parse(nativeId))),
153
+ background: (nativeId, count) => deliver(() => handlers?.background(provider, NativeIdSchema.parse(nativeId), z.number().int().nonnegative().max(MAX_BACKGROUND_COMMANDS).parse(count))),
152
154
  session: (nativeId, state) => deliver(() => handlers?.session(provider, NativeIdSchema.parse(nativeId), SessionStateSchema.parse(state))),
153
155
  delta: (nativeId, turnId, itemId, text) => deliver(() => {
154
156
  handlers?.delta(provider, NativeIdSchema.parse(nativeId), NativeIdSchema.parse(turnId), NativeIdSchema.parse(itemId), z.string().max(MAX_FRAME_BYTES).parse(text));
@@ -114,6 +114,7 @@ export type IAgentProviderEvents = {
114
114
  observe(observation: INativeObservation): void;
115
115
  item(nativeId: string, item: IHistoryItem, isComplete: boolean, replacedIds?: string[]): void;
116
116
  gap(nativeId: string): void;
117
+ background(nativeId: string, count: number): void;
117
118
  delta(nativeId: string, turnId: string, itemId: string, text: string): void;
118
119
  prompt(prompt: INativePrompt): void;
119
120
  unpresentable(nativeId: string, reject: () => Promise<void>): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jg-agent-hq",
3
- "version": "10.7.0",
3
+ "version": "10.8.0",
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",