jg-agent-hq 10.5.3 → 10.6.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 +8 -0
- package/README.md +1 -1
- package/api/README.md +22 -22
- package/dist/providers/claude/adapter.js +2 -9
- package/dist/providers/claude/control/control.d.ts +15 -0
- package/dist/providers/claude/control/control.js +45 -1
- package/dist/providers/claude/control/stream.d.ts +12 -1
- package/dist/providers/claude/control/stream.js +56 -3
- package/dist/providers/claude/control/types.d.ts +8 -0
- package/dist/providers/claude/history/history.model.d.ts +9 -0
- package/dist/providers/claude/history/history.model.js +39 -8
- package/dist/providers/claude/history/types.d.ts +1 -0
- package/dist/providers/claude/history/types.js +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 10.6.0
|
|
4
|
+
|
|
5
|
+
- Steer a Claude session's active turn. Claude reports `steer` as supported and writes the text as a user message into the exact active turn, without interrupting it, and acknowledges the steer when Claude replays the message: at the turn's next tool boundary, where the turn takes it in and ends with one result, or, for text written while the turn's final answer streams, after the turn's result, where it runs as the session's next turn under the message's UUID. Either replay acknowledges the steer against the turn it named. A steer never replayed fails 30 seconds after that turn ends, and one pending when the process stops fails at once. Claude used to reject `steer` as unavailable.
|
|
6
|
+
|
|
7
|
+
## 10.5.4
|
|
8
|
+
|
|
9
|
+
- Keep a Claude response's parallel tool calls in its history when their results finish out of order. Claude Code links each result to its own call, so a result that came back after a later call's result started a side branch, and history left out the later calls and results: they stayed `awaiting-flush` after the session's answer, and an open page's cursor was rejected as changed. Such a result now follows the latest record of its turn. Every Claude history is indexed again once.
|
|
10
|
+
|
|
3
11
|
## 10.5.3
|
|
4
12
|
|
|
5
13
|
- Leave a Claude subagent's stream frames, which name the Agent call that started it, out of a session's live items and turns. History leaves the subagent's sidechain out, so its prompt, tool calls and results stayed `awaiting-flush` after the session's answer, its prompt read as the operator's message, and a background subagent's frames after the session's turn started a turn of Claude's own that never ended, which held the next message as starting. A subagent's tool results still settle the approvals it asked for.
|
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ Use `account --provider <id>` for safe native account metadata, and `mcp-servers
|
|
|
75
75
|
|
|
76
76
|
Use `models --provider <id>` for native model and effort choices, and `configuration --provider <id> --workspace-root <path> [--thread-id <id>]` for known effective settings and paged native agent/profile metadata. Creation and explicit resume accept typed startup settings; messages can select a model and effort for the next turn. Startup instructions, native Claude agents and permission settings require an idle session restart. Capability schemas describe supported selections and change modes. Unknown settings remain explicit, and native configuration files stay with each CLI. See the [configuration contract](api/README.md#native-configuration).
|
|
77
77
|
|
|
78
|
-
Native execution settings, instructions, skills and tool permissions remain with each CLI. Claude uses an owned structured process per controlled session, closes it after 60 idle minutes and reopens it for the next input, and
|
|
78
|
+
Native execution settings, instructions, skills and tool permissions remain with each CLI. Claude uses an owned structured process per controlled session, closes it after 60 idle minutes and reopens it for the next input, and steers its active turn with a structured user message. Close other CLI controllers before confirming adoption, resume or recovery. HQ coordinates sessions sharing one state directory; it cannot lock independently running native CLIs. Integrating browser hosts can use durable host-action admission and operator-scoped reconciliation through the programmatic API; see the [browser host contract](api/README.md#browser-host-integration). The standalone CLI advertises only commands it implements.
|
|
79
79
|
|
|
80
80
|
Approval reads return indexed, cursor-paginated pending, answered and expired metadata after reconnect or restart. Sensitive presentation is available only while the exact native request is live. Native permissions require explicit responses; unknown request kinds or scopes are denied. See [native replies and reconnect reads](api/README.md#thread-control-and-live-input).
|
|
81
81
|
|
package/api/README.md
CHANGED
|
@@ -101,7 +101,7 @@ The current built-in surfaces map to these native entry points:
|
|
|
101
101
|
| Create/adopt/resume | `thread/start`, `thread/read`, `thread/resume` | Structured session creation/resume and idle/session-ID fences |
|
|
102
102
|
| Rename | `thread/name/set` | `rename_session` control request |
|
|
103
103
|
| Message/queue | `turn/start` with explicit native input | Structured user messages with matching acknowledgements |
|
|
104
|
-
| Steer | `turn/steer` for the exact active turn |
|
|
104
|
+
| Steer | `turn/steer` for the exact active turn | A structured user message into the exact active turn, acknowledged by its replay |
|
|
105
105
|
| Interrupt | `turn/interrupt` | `interrupt` control request; completion remains separate |
|
|
106
106
|
| Close/recover | Native background-terminal cleanup/verification and `thread/unsubscribe` | Confirmed process-group shutdown and explicit session release/resume |
|
|
107
107
|
| Runtime restart | Sessions keep running, and the next runtime rejoins them | Turns stop with the runtime; sessions wait inactive for an explicit resume |
|
|
@@ -241,7 +241,7 @@ The existing SQLite worker incrementally records file identity, complete-line of
|
|
|
241
241
|
|
|
242
242
|
Current-chain membership and turn starts are indexed as metadata. Ordinary item and turn continuations seek those indexes; they do not walk the full chain per page. A changed branch rebuilds membership before exposing that revision. Repeated native message identities can replace content while retaining their parent; a changed parent for the same identity is an unsupported format.
|
|
243
243
|
|
|
244
|
-
Selected history reads refresh only that file, retain incomplete tails, and detect truncation or replaced identity. Changed branch/file revisions invalidate item and turn continuations. Only the current parent-linked conversation chain is returned. Text is reread from the native file for the selected page and normalized as plain text. Thinking blocks are left out, and a record holding only thinking is hidden, as are `<task-notification>` records and a subagent's sidechain records. Live items leave a subagent's stream frames out likewise, and those frames start no turn, though a subagent's tool results still settle the approvals it asked for. Compaction summaries, `<local-command-stdout>` output and interruption markers are `notice` items, and a slash command is a `user-message` reading `/name args`. A `!` shell input and its output are `command` items, the output's `callId` being the input's UUID. A tool call shows its native name and input, with the block's ID as `callId`, which is null for a record calling several tools; its result is a `tool` item carrying that ID, `failed` when it has `is_error` and `succeeded` otherwise. An Edit or Write result whose metadata has a `filePath` and a `structuredPatch` is a `file-change` item reading the path and its patch lines, or a created file's content, every line of which counts as added. A result Claude Code saved to a file reads `Output too large (<size>), saved to a file` followed by its preview, without the file's path. A result made of content blocks, such as a screenshot with its caption, reads as its text blocks, each image as `[Image]`. Other non-text content has explicit native block labels. The index stores each entry's presented kind and visibility, so evidence kind filters match `items` and hidden records never shorten a page. An unknown record containing content is returned as an `unsupported` item when its identity and chain are trustworthy; it cannot imply an agent response, idle state or completion. Each selected page reads at most 4 MiB of record bytes beyond its first record and returns at most 4 MiB of serialized item presentation, so a large-text page can contain fewer rows than its requested limit.
|
|
244
|
+
Selected history reads refresh only that file, retain incomplete tails, and detect truncation or replaced identity. Changed branch/file revisions invalidate item and turn continuations. Only the current parent-linked conversation chain is returned. Claude Code links each tool result to its own call, so parallel calls whose results finish out of order would leave the later calls and results on a side branch; such a result follows the latest record of its call's turn instead, keeping every call of the response and all their results on the chain without changing its revision. Text is reread from the native file for the selected page and normalized as plain text. Thinking blocks are left out, and a record holding only thinking is hidden, as are `<task-notification>` records and a subagent's sidechain records. Live items leave a subagent's stream frames out likewise, and those frames start no turn, though a subagent's tool results still settle the approvals it asked for. Compaction summaries, `<local-command-stdout>` output and interruption markers are `notice` items, and a slash command is a `user-message` reading `/name args`. A `!` shell input and its output are `command` items, the output's `callId` being the input's UUID. A tool call shows its native name and input, with the block's ID as `callId`, which is null for a record calling several tools; its result is a `tool` item carrying that ID, `failed` when it has `is_error` and `succeeded` otherwise. An Edit or Write result whose metadata has a `filePath` and a `structuredPatch` is a `file-change` item reading the path and its patch lines, or a created file's content, every line of which counts as added. A result Claude Code saved to a file reads `Output too large (<size>), saved to a file` followed by its preview, without the file's path. A result made of content blocks, such as a screenshot with its caption, reads as its text blocks, each image as `[Image]`. Other non-text content has explicit native block labels. The index stores each entry's presented kind and visibility, so evidence kind filters match `items` and hidden records never shorten a page. An unknown record containing content is returned as an `unsupported` item when its identity and chain are trustworthy; it cannot imply an agent response, idle state or completion. Each selected page reads at most 4 MiB of record bytes beyond its first record and returns at most 4 MiB of serialized item presentation, so a large-text page can contain fewer rows than its requested limit.
|
|
245
245
|
|
|
246
246
|
File timestamps and records do not prove that a native process is idle or a turn completed. Claude file-backed thread and turn states are therefore `unknown`, with no invented completion timestamp. Explicit native custom titles are preserved; a missing title remains null. A turn starts at a message the operator sends, including a slash command; task notifications, compaction summaries, local command output, interruption markers and `!` shell records belong to the turn before them. Grouping follows parent links and is not an authoritative execution boundary. A compaction starts a new chain whose first record names the record before it, so history reads on past the compaction to the start of the conversation.
|
|
247
247
|
|
|
@@ -249,26 +249,26 @@ File timestamps and records do not prove that a native process is idle or a turn
|
|
|
249
249
|
|
|
250
250
|
Send `{ kind: 'action', action: { id, runtimeEpoch, command } }`. Generate one UUID per user intent, take the epoch from `status`, and retain the complete envelope until its receipt can be read. The validated envelope is limited to 32,768 UTF-8 bytes. It is recorded before native writes. Reusing the UUID with the identical envelope returns the saved receipt without dispatch; a changed envelope conflicts. This check also works for an original request read after restart. A new UUID with an expired epoch cannot execute.
|
|
251
251
|
|
|
252
|
-
| Action | Fields and behavior
|
|
253
|
-
| ------------------ |
|
|
254
|
-
| `thread-fork` | Source `threadId`, child `name`. Requires an idle owned source or an inactive managed source. Creates a distinct native session and retains `forkedFromThreadId` and exact native lineage.
|
|
255
|
-
| `thread-archive` | Idle owned `threadId`. Confirms native background cleanup, archives natively and releases control.
|
|
256
|
-
| `thread-unarchive` | Inactive archived `threadId`. Unarchives the exact native session and leaves it inactive.
|
|
257
|
-
| `thread-compact` | Idle owned `threadId`. Records native admission separately from its correlated turn completion. Clears the live presentation and requires a fresh history read.
|
|
258
|
-
| `thread-revert` | Idle owned `threadId`, exact `beforeTurnId`. Removes that native turn and later history; files and historical HQ receipts remain unchanged. Clears the live presentation and requires a fresh history read.
|
|
259
|
-
| `thread-create` | `provider` (a registered provider ID), `workspaceRoot`, `name`. Creates an empty native thread and sets its readable name before reporting acknowledgement.
|
|
260
|
-
| `thread-adopt` | The same fields plus `nativeId`, `operatorConfirmation`. Explicitly records an external thread as managed. Codex accepts it unloaded or idle, between turns of a terminal that still holds it, and resumes it with optional `settings`, which it refuses while another client holds the thread; Claude requires qualified workspace history and the native idle/session-identity checks, and refuses while a terminal runs it.
|
|
261
|
-
| `thread-resume` | `threadId`, `operatorConfirmation`. Resumes an inactive managed thread; HQ does not fetch its complete conversation bodies.
|
|
262
|
-
| `thread-recover` | `threadId`, `operatorConfirmation`, `recovery`. The recovery is `{ kind: 'resume' }` for a known native identity, `{ kind: 'attach', nativeId }` for an inspected identity after uncertain creation, or `{ kind: 'create' }` to explicitly create a fresh empty thread when no native identity was recorded. The latter can leave an empty orphan from the uncertain creation; it never repeats a message.
|
|
263
|
-
| `thread-rename` | `threadId`, `name`. Changes the name only after the matching native acknowledgement.
|
|
264
|
-
| `thread-close` | `threadId`. Requires an idle thread and pauses its queue. Codex cleans and verifies its native terminal list before unsubscribe. Claude closes the owned CLI and proves process-group exit before releasing control.
|
|
265
|
-
| `message` | `threadId`, `input`. Starts a turn only while idle.
|
|
266
|
-
| `steer` | `threadId`, `expectedTurnId`, `text`. Codex uses native `turn/steer`. Claude
|
|
267
|
-
| `queue` | `threadId`, `expectedTurnId`, `input`. Saves an explicit next-turn message or skill invocation, never a permission or question answer.
|
|
268
|
-
| `queue-send` | `queuedActionId`. Explicitly authorizes a still-undelivered queue entry, including a queue paused by restart or interruption.
|
|
269
|
-
| `queue-cancel` | `queuedActionId`. Cancels only an undelivered queue entry and clears its saved body.
|
|
270
|
-
| `interrupt` | `threadId`, `expectedTurnId`. A native request acknowledgement leaves the thread stopping until native completion evidence arrives.
|
|
271
|
-
| `native-reply` | `threadId`, `expectedTurnId`, `approvalId`, `response`. Answers one exact current native request; cannot consume queue text.
|
|
252
|
+
| Action | Fields and behavior |
|
|
253
|
+
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
254
|
+
| `thread-fork` | Source `threadId`, child `name`. Requires an idle owned source or an inactive managed source. Creates a distinct native session and retains `forkedFromThreadId` and exact native lineage. |
|
|
255
|
+
| `thread-archive` | Idle owned `threadId`. Confirms native background cleanup, archives natively and releases control. |
|
|
256
|
+
| `thread-unarchive` | Inactive archived `threadId`. Unarchives the exact native session and leaves it inactive. |
|
|
257
|
+
| `thread-compact` | Idle owned `threadId`. Records native admission separately from its correlated turn completion. Clears the live presentation and requires a fresh history read. |
|
|
258
|
+
| `thread-revert` | Idle owned `threadId`, exact `beforeTurnId`. Removes that native turn and later history; files and historical HQ receipts remain unchanged. Clears the live presentation and requires a fresh history read. |
|
|
259
|
+
| `thread-create` | `provider` (a registered provider ID), `workspaceRoot`, `name`. Creates an empty native thread and sets its readable name before reporting acknowledgement. |
|
|
260
|
+
| `thread-adopt` | The same fields plus `nativeId`, `operatorConfirmation`. Explicitly records an external thread as managed. Codex accepts it unloaded or idle, between turns of a terminal that still holds it, and resumes it with optional `settings`, which it refuses while another client holds the thread; Claude requires qualified workspace history and the native idle/session-identity checks, and refuses while a terminal runs it. |
|
|
261
|
+
| `thread-resume` | `threadId`, `operatorConfirmation`. Resumes an inactive managed thread; HQ does not fetch its complete conversation bodies. |
|
|
262
|
+
| `thread-recover` | `threadId`, `operatorConfirmation`, `recovery`. The recovery is `{ kind: 'resume' }` for a known native identity, `{ kind: 'attach', nativeId }` for an inspected identity after uncertain creation, or `{ kind: 'create' }` to explicitly create a fresh empty thread when no native identity was recorded. The latter can leave an empty orphan from the uncertain creation; it never repeats a message. |
|
|
263
|
+
| `thread-rename` | `threadId`, `name`. Changes the name only after the matching native acknowledgement. |
|
|
264
|
+
| `thread-close` | `threadId`. Requires an idle thread and pauses its queue. Codex cleans and verifies its native terminal list before unsubscribe. Claude closes the owned CLI and proves process-group exit before releasing control. |
|
|
265
|
+
| `message` | `threadId`, `input`. Starts a turn only while idle. |
|
|
266
|
+
| `steer` | `threadId`, `expectedTurnId`, `text`. Codex uses native `turn/steer`. Claude writes the text as a user message into the exact active turn, never interrupting it, and acknowledges it when Claude replays it: at the turn's next tool boundary, where the turn takes it in and ends with one result, or, for text written while the turn's final answer streams, after the turn's result, where it runs as the session's next turn under its own UUID. Either replay acknowledges the steer against the turn it named. A Claude steer never replayed fails 30 seconds after that turn ends, and one pending when the process stops fails at once. Otherwise a finished or changed turn cannot become a new turn. |
|
|
267
|
+
| `queue` | `threadId`, `expectedTurnId`, `input`. Saves an explicit next-turn message or skill invocation, never a permission or question answer. |
|
|
268
|
+
| `queue-send` | `queuedActionId`. Explicitly authorizes a still-undelivered queue entry, including a queue paused by restart or interruption. |
|
|
269
|
+
| `queue-cancel` | `queuedActionId`. Cancels only an undelivered queue entry and clears its saved body. |
|
|
270
|
+
| `interrupt` | `threadId`, `expectedTurnId`. A native request acknowledgement leaves the thread stopping until native completion evidence arrives. |
|
|
271
|
+
| `native-reply` | `threadId`, `expectedTurnId`, `approvalId`, `response`. Answers one exact current native request; cannot consume queue text. |
|
|
272
272
|
|
|
273
273
|
Message and queue input is a closed union: `{ kind: 'text', text }` or `{ kind: 'skill', skillId, arguments }`. Text is nonempty and at most 65,536 characters; skill arguments may be empty and cap at 16,384 characters. The envelope's UTF-8 limit still applies. A selected skill is resolved through the target thread's current native catalog before admission. Unavailable, missing or disabled selections cannot dispatch. Normal text needs no catalog read. Steering retains its `text` field and exact active-turn target.
|
|
274
274
|
|
|
@@ -73,14 +73,7 @@ export const createClaudeProviderFactory = (store, additionalDirectories) => ({
|
|
|
73
73
|
close: SUPPORTED_PROVIDER_OPERATION,
|
|
74
74
|
interrupt: SUPPORTED_PROVIDER_OPERATION,
|
|
75
75
|
recover: SUPPORTED_PROVIDER_OPERATION,
|
|
76
|
-
steer:
|
|
77
|
-
state: 'unsupported',
|
|
78
|
-
changeMode: null,
|
|
79
|
-
reason: {
|
|
80
|
-
code: 'native-control-unsupported',
|
|
81
|
-
message: 'The structured Claude interface does not support steering an active turn.',
|
|
82
|
-
},
|
|
83
|
-
},
|
|
76
|
+
steer: SUPPORTED_PROVIDER_OPERATION,
|
|
84
77
|
history: SUPPORTED_PROVIDER_OPERATION,
|
|
85
78
|
usage: SUPPORTED_PROVIDER_OPERATION,
|
|
86
79
|
models,
|
|
@@ -273,7 +266,7 @@ export const createClaudeProviderFactory = (store, additionalDirectories) => ({
|
|
|
273
266
|
control.validateInput(nativeId, input.settings);
|
|
274
267
|
},
|
|
275
268
|
startTurn: (requestId, nativeId, text, _skill, settings, files, call) => control.startTurn(requestId, nativeId, text, settings, call.signal, files),
|
|
276
|
-
steer:
|
|
269
|
+
steer: (requestId, nativeId, expectedTurnId, text) => control.steer(requestId, nativeId, expectedTurnId, text),
|
|
277
270
|
interrupt: (requestId, nativeId, nativeTurnId) => control.interrupt(requestId, nativeId, nativeTurnId),
|
|
278
271
|
cleanThread: (requestId, nativeId) => control.stopSession(requestId, nativeId),
|
|
279
272
|
releaseThread: (requestId, nativeId) => control.releaseSession(requestId, nativeId),
|
|
@@ -232,6 +232,21 @@ export declare const createClaudeControl: (additionalDirectories?: string[]) =>
|
|
|
232
232
|
startTurn(requestId: string, nativeId: string, text: string, settings?: ITurnSettings, signal?: AbortSignal, files?: IProviderInputFile[]): Promise<{
|
|
233
233
|
id: string;
|
|
234
234
|
}>;
|
|
235
|
+
/**
|
|
236
|
+
* Writes text into the exact active turn, HQ input's or one Claude started, without
|
|
237
|
+
* interrupting it. Claude takes it in at the turn's next tool boundary and replays it there,
|
|
238
|
+
* or, for text written while the turn's final answer streams, replays it after the turn's
|
|
239
|
+
* result and runs it as the session's next turn. Either replay acknowledges the steer against
|
|
240
|
+
* the turn it named; a stopped process, or no replay within 30 seconds of that turn's end,
|
|
241
|
+
* fails it.
|
|
242
|
+
* @returns The turn the steer named, once Claude replayed it.
|
|
243
|
+
* @throws
|
|
244
|
+
* - JG_AGENT_HQ_ACTION_CONFLICT: The HQ action conflicts with its recorded state
|
|
245
|
+
* - JG_AGENT_HQ_CAPABILITY_UNAVAILABLE: The HQ capability is unavailable
|
|
246
|
+
* - JG_AGENT_HQ_CLAUDE_FAILED: The Claude integration failed
|
|
247
|
+
* - JG_AGENT_HQ_TRANSPORT_FAILED: The HQ transport failed
|
|
248
|
+
*/
|
|
249
|
+
steer(_requestId: string, nativeId: string, turnId: string, text: string): Promise<string>;
|
|
235
250
|
/**
|
|
236
251
|
* Requests interruption of the exact active turn, HQ input's or one Claude started; completion
|
|
237
252
|
* arrives separately.
|
|
@@ -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 { receiveClaudeMessage } from './stream.js';
|
|
10
|
+
import { failSteers, getActiveTurn, receiveClaudeMessage } 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;
|
|
@@ -231,6 +231,7 @@ export const createClaudeControl = (additionalDirectories = []) => {
|
|
|
231
231
|
const connection = await createClaudeRpc((reason) => {
|
|
232
232
|
if (reason !== 'unavailable' || session.isClosing || session.parked)
|
|
233
233
|
return;
|
|
234
|
+
failSteers(session);
|
|
234
235
|
if (session.input) {
|
|
235
236
|
clearTimeout(session.input.timer);
|
|
236
237
|
session.input.reject(new Exception('The Claude integration failed', {
|
|
@@ -337,6 +338,7 @@ export const createClaudeControl = (additionalDirectories = []) => {
|
|
|
337
338
|
opening: Promise.resolve(),
|
|
338
339
|
previews: new Map(),
|
|
339
340
|
requests: new Map(),
|
|
341
|
+
steers: new Map(),
|
|
340
342
|
};
|
|
341
343
|
sessions.set(nativeId, session);
|
|
342
344
|
session.opening = start(session, isResume, forkSourceNativeId, signal);
|
|
@@ -622,6 +624,45 @@ export const createClaudeControl = (additionalDirectories = []) => {
|
|
|
622
624
|
});
|
|
623
625
|
}, signal);
|
|
624
626
|
},
|
|
627
|
+
/**
|
|
628
|
+
* Writes text into the exact active turn, HQ input's or one Claude started, without
|
|
629
|
+
* interrupting it. Claude takes it in at the turn's next tool boundary and replays it there,
|
|
630
|
+
* or, for text written while the turn's final answer streams, replays it after the turn's
|
|
631
|
+
* result and runs it as the session's next turn. Either replay acknowledges the steer against
|
|
632
|
+
* the turn it named; a stopped process, or no replay within 30 seconds of that turn's end,
|
|
633
|
+
* fails it.
|
|
634
|
+
* @returns The turn the steer named, once Claude replayed it.
|
|
635
|
+
* @throws
|
|
636
|
+
* - JG_AGENT_HQ_ACTION_CONFLICT: The HQ action conflicts with its recorded state
|
|
637
|
+
* - JG_AGENT_HQ_CAPABILITY_UNAVAILABLE: The HQ capability is unavailable
|
|
638
|
+
* - JG_AGENT_HQ_CLAUDE_FAILED: The Claude integration failed
|
|
639
|
+
* - JG_AGENT_HQ_TRANSPORT_FAILED: The HQ transport failed
|
|
640
|
+
*/
|
|
641
|
+
async steer(_requestId, nativeId, turnId, text) {
|
|
642
|
+
// a parked session is idle, so it has no turn to steer
|
|
643
|
+
return withSession(nativeId, false, (session) => {
|
|
644
|
+
if (getActiveTurn(session)?.id !== turnId)
|
|
645
|
+
conflict();
|
|
646
|
+
if (session.isClosing || !session.connection?.isAvailable)
|
|
647
|
+
unavailable();
|
|
648
|
+
return new Promise((resolve, reject) => {
|
|
649
|
+
const id = randomUUID();
|
|
650
|
+
session.steers.set(id, { id, turnId, resolve, reject });
|
|
651
|
+
void session
|
|
652
|
+
.connection.write({
|
|
653
|
+
type: 'user',
|
|
654
|
+
uuid: id,
|
|
655
|
+
session_id: nativeId,
|
|
656
|
+
message: { role: 'user', content: text },
|
|
657
|
+
parent_tool_use_id: null,
|
|
658
|
+
})
|
|
659
|
+
.catch((error) => {
|
|
660
|
+
session.steers.delete(id);
|
|
661
|
+
reject(error);
|
|
662
|
+
});
|
|
663
|
+
});
|
|
664
|
+
});
|
|
665
|
+
},
|
|
625
666
|
/**
|
|
626
667
|
* Requests interruption of the exact active turn, HQ input's or one Claude started; completion
|
|
627
668
|
* arrives separately.
|
|
@@ -654,6 +695,8 @@ export const createClaudeControl = (additionalDirectories = []) => {
|
|
|
654
695
|
conflict();
|
|
655
696
|
cancelIdleStop(session);
|
|
656
697
|
session.isClosing = true;
|
|
698
|
+
// a stopped process replays nothing more
|
|
699
|
+
failSteers(session);
|
|
657
700
|
// a parked session finishes without a process
|
|
658
701
|
await session.transition?.catch(() => undefined);
|
|
659
702
|
await session.opening.catch((cause) => {
|
|
@@ -689,6 +732,7 @@ export const createClaudeControl = (additionalDirectories = []) => {
|
|
|
689
732
|
const results = await Promise.allSettled([...sessions.values()].map(async (session) => {
|
|
690
733
|
cancelIdleStop(session);
|
|
691
734
|
session.isClosing = true;
|
|
735
|
+
failSteers(session);
|
|
692
736
|
if (session.input) {
|
|
693
737
|
clearTimeout(session.input.timer);
|
|
694
738
|
session.input.reject(new Exception('The Claude integration failed', {
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import type { IClaudeControlEvents, IClaudeSession } from './types.js';
|
|
1
|
+
import type { IClaudeControlEvents, IClaudeSession, IClaudeTurn } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the turn the session's frames belong to: a turn Claude started, or the acknowledged
|
|
4
|
+
* input's. Input still waiting for its replay has no turn yet.
|
|
5
|
+
*/
|
|
6
|
+
export declare const getActiveTurn: (session: IClaudeSession) => IClaudeTurn | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Fails the steers Claude never replayed, as when its process stops, so no steer waits forever.
|
|
9
|
+
* @param session The session.
|
|
10
|
+
* @param turnId The turn whose steers fail, or every pending steer when omitted.
|
|
11
|
+
*/
|
|
12
|
+
export declare const failSteers: (session: IClaudeSession, turnId?: string) => void;
|
|
2
13
|
/**
|
|
3
14
|
* Normalizes native stream evidence without retaining another conversation buffer. A turn frame
|
|
4
15
|
* that arrives while no turn is active, and isn't the waiting input's replay, starts a turn of
|
|
@@ -90,7 +90,7 @@ const unavailable = () => {
|
|
|
90
90
|
* Returns the turn the session's frames belong to: a turn Claude started, or the acknowledged
|
|
91
91
|
* input's. Input still waiting for its replay has no turn yet.
|
|
92
92
|
*/
|
|
93
|
-
const getActiveTurn = (session) => session.nativeTurn ?? (session.input?.isAcknowledged ? session.input : undefined);
|
|
93
|
+
export const getActiveTurn = (session) => session.nativeTurn ?? (session.input?.isAcknowledged ? session.input : undefined);
|
|
94
94
|
/** Acknowledges the single current input before forwarding its ordered turn evidence. */
|
|
95
95
|
const acknowledge = (session, events) => {
|
|
96
96
|
const input = session.input;
|
|
@@ -127,6 +127,53 @@ const startNativeTurn = (session, events) => {
|
|
|
127
127
|
});
|
|
128
128
|
return turn;
|
|
129
129
|
};
|
|
130
|
+
/**
|
|
131
|
+
* Fails the steers Claude never replayed, as when its process stops, so no steer waits forever.
|
|
132
|
+
* @param session The session.
|
|
133
|
+
* @param turnId The turn whose steers fail, or every pending steer when omitted.
|
|
134
|
+
*/
|
|
135
|
+
export const failSteers = (session, turnId) => {
|
|
136
|
+
for (const steer of session.steers.values()) {
|
|
137
|
+
if (turnId !== undefined && steer.turnId !== turnId)
|
|
138
|
+
continue;
|
|
139
|
+
clearTimeout(steer.timer);
|
|
140
|
+
session.steers.delete(steer.id);
|
|
141
|
+
steer.reject(new Exception('The Claude integration failed', {
|
|
142
|
+
code: 'JG_AGENT_HQ_CLAUDE_FAILED',
|
|
143
|
+
data: { kind: 'agent-unavailable' },
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
/*
|
|
148
|
+
* Claude replays a steer written while a turn's final answer streams only after that turn's
|
|
149
|
+
* result, at once; a steer still unreplayed this long after its turn ended fails.
|
|
150
|
+
*/
|
|
151
|
+
const STEER_REPLAY_GRACE_MS = 30_000;
|
|
152
|
+
/** Gives the steers of a turn that just ended their grace period for a replay after its result. */
|
|
153
|
+
const awaitLateSteers = (session, turnId) => {
|
|
154
|
+
for (const steer of session.steers.values())
|
|
155
|
+
if (steer.turnId === turnId && steer.timer === undefined)
|
|
156
|
+
steer.timer = setTimeout(() => failSteers(session, turnId), STEER_REPLAY_GRACE_MS);
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Takes in a steer's replay. During the turn it named, the steer joined it; after that turn's
|
|
160
|
+
* result, the steer runs as the session's next turn, under its own UUID, which its result names.
|
|
161
|
+
* Either way the steer is acknowledged against the turn it named.
|
|
162
|
+
*/
|
|
163
|
+
const acknowledgeSteer = (session, steer, events) => {
|
|
164
|
+
clearTimeout(steer.timer);
|
|
165
|
+
session.steers.delete(steer.id);
|
|
166
|
+
if (!getActiveTurn(session)) {
|
|
167
|
+
session.nativeTurn = { id: steer.id, interruptRequested: false, hasInterruptionMarker: false };
|
|
168
|
+
events?.observe({
|
|
169
|
+
kind: 'turn-started',
|
|
170
|
+
provider: 'claude',
|
|
171
|
+
nativeThreadId: session.id,
|
|
172
|
+
nativeTurnId: steer.id,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
steer.resolve(steer.turnId);
|
|
176
|
+
};
|
|
130
177
|
/** Classifies a result: interrupted only after the marker of an interrupt HQ requested. */
|
|
131
178
|
const toTurnState = (result, turn) => !result.is_error && result.subtype === 'success'
|
|
132
179
|
? 'completed'
|
|
@@ -184,6 +231,9 @@ export const receiveClaudeMessage = (session, raw, events) => {
|
|
|
184
231
|
}
|
|
185
232
|
if (frame.type === 'user' || frame.type === 'assistant') {
|
|
186
233
|
const message = MessageSchema.parse(raw);
|
|
234
|
+
const steer = frame.type === 'user' ? session.steers.get(message.uuid) : undefined;
|
|
235
|
+
if (steer)
|
|
236
|
+
acknowledgeSteer(session, steer, events);
|
|
187
237
|
const isReplay = frame.type === 'user' && session.input !== undefined && message.uuid === session.input.id;
|
|
188
238
|
if (isReplay) {
|
|
189
239
|
// Claude replays input written during its own turn only after that turn's result
|
|
@@ -286,13 +336,15 @@ export const receiveClaudeMessage = (session, raw, events) => {
|
|
|
286
336
|
else if (frame.type === 'result') {
|
|
287
337
|
const result = ResultSchema.parse(raw);
|
|
288
338
|
observeFastMode(session, raw);
|
|
289
|
-
|
|
290
|
-
|
|
339
|
+
// a turn Claude started, or one a steer runs after its turn, has no action to capture its result
|
|
340
|
+
if (result.user_message_uuid === undefined ||
|
|
341
|
+
result.user_message_uuid === session.nativeTurn?.id) {
|
|
291
342
|
const turn = session.nativeTurn;
|
|
292
343
|
if (!turn)
|
|
293
344
|
unavailable();
|
|
294
345
|
session.nativeTurn = undefined;
|
|
295
346
|
endTurn(session, events);
|
|
347
|
+
awaitLateSteers(session, turn.id);
|
|
296
348
|
events?.observe({
|
|
297
349
|
kind: 'turn-completed',
|
|
298
350
|
provider: 'claude',
|
|
@@ -309,6 +361,7 @@ export const receiveClaudeMessage = (session, raw, events) => {
|
|
|
309
361
|
const state = toTurnState(result, input);
|
|
310
362
|
session.input = undefined;
|
|
311
363
|
endTurn(session, events);
|
|
364
|
+
awaitLateSteers(session, input.id);
|
|
312
365
|
const observedUsage = UsageSchema.safeParse(result.usage);
|
|
313
366
|
const usage = observedUsage.success
|
|
314
367
|
? {
|
|
@@ -29,6 +29,13 @@ export type IClaudeNativeTurn = {
|
|
|
29
29
|
interruptRequested: boolean;
|
|
30
30
|
hasInterruptionMarker: boolean;
|
|
31
31
|
};
|
|
32
|
+
export type IClaudeSteer = {
|
|
33
|
+
id: string;
|
|
34
|
+
turnId: string;
|
|
35
|
+
resolve(turnId: string): void;
|
|
36
|
+
reject(error: unknown): void;
|
|
37
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
38
|
+
};
|
|
32
39
|
export type IClaudeTurn = IClaudeInput | IClaudeNativeTurn;
|
|
33
40
|
export type IClaudeFastMode = {
|
|
34
41
|
state: 'on' | 'cooldown' | 'off';
|
|
@@ -47,6 +54,7 @@ export type IClaudeSession = {
|
|
|
47
54
|
skills?: IProviderSkills | null;
|
|
48
55
|
input?: IClaudeInput;
|
|
49
56
|
nativeTurn?: IClaudeNativeTurn;
|
|
57
|
+
steers: Map<string, IClaudeSteer>;
|
|
50
58
|
backgroundTaskCount: number;
|
|
51
59
|
fastMode?: IClaudeFastMode;
|
|
52
60
|
apiMessageId?: string;
|
|
@@ -63,6 +63,15 @@ export declare class ClaudeHistoryModel {
|
|
|
63
63
|
* - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
|
|
64
64
|
*/
|
|
65
65
|
private __record;
|
|
66
|
+
/**
|
|
67
|
+
* Claude Code links a tool result to its own call. When parallel calls finish out of order, an
|
|
68
|
+
* earlier call is no longer the leaf, so its result would start a side branch that the current
|
|
69
|
+
* chain leaves out, with the calls and results written after that call. Such a result follows
|
|
70
|
+
* the leaf of its call's turn instead, which keeps one response's calls and all their results
|
|
71
|
+
* on the chain; the record after them follows the last result written, the leaf by then.
|
|
72
|
+
* @returns The record the result follows in the projection: the leaf, or its own call.
|
|
73
|
+
*/
|
|
74
|
+
private __resultParent;
|
|
66
75
|
private __hasEntry;
|
|
67
76
|
private __unavailable;
|
|
68
77
|
}
|
|
@@ -8,7 +8,7 @@ import { evidencePosition, buildEvidencePage, EVIDENCE_SOURCE_PAGE_SIZE, } from
|
|
|
8
8
|
import { EntryRowSchema, EntrySeekSchema, FileRowSchema, RecordSchema, ApiRequestMetadataSchema, SeekSchema, } from './types.js';
|
|
9
9
|
import { isClaudeAnswer, isClaudeCallFor, isClaudeRecordCwd, isClaudeWorkspaceCwd, openTranscript, projectDirectory, readClaudeParentUuid, toClaudeDetail, toClaudeImageData, toClaudeItem, } from './utilities.js';
|
|
10
10
|
// identifies the path and record interpretation used by persisted projection entries
|
|
11
|
-
const HISTORY_PROJECTION_VERSION =
|
|
11
|
+
const HISTORY_PROJECTION_VERSION = 8;
|
|
12
12
|
// one record, such as a tool result holding images, and an indexing read, which fits the largest
|
|
13
13
|
const MAX_RECORD_BYTES = 8_388_608;
|
|
14
14
|
const MAX_REFRESH_BYTES = 16_777_216;
|
|
@@ -40,7 +40,7 @@ export class ClaudeHistoryModel {
|
|
|
40
40
|
constructor(database) {
|
|
41
41
|
this.__database = database;
|
|
42
42
|
this.__recordStatements = {
|
|
43
|
-
parentTurn: database.prepare(`SELECT turn_id, turn_start_offset, anchor_id FROM hq_claude_entry
|
|
43
|
+
parentTurn: database.prepare(`SELECT turn_id, turn_start_offset, anchor_id, is_current FROM hq_claude_entry
|
|
44
44
|
WHERE workspace_root = ? AND native_id = ? AND uuid = ?`),
|
|
45
45
|
recordedParent: database.prepare('SELECT parent_uuid FROM hq_claude_entry WHERE workspace_root = ? AND native_id = ? AND uuid = ?'),
|
|
46
46
|
upsert: database.prepare(`INSERT INTO hq_claude_entry (workspace_root, native_id, uuid, parent_uuid, turn_id, byte_offset,
|
|
@@ -703,26 +703,40 @@ export class ClaudeHistoryModel {
|
|
|
703
703
|
this.__unavailable();
|
|
704
704
|
const createdAt = Date.parse(record.timestamp);
|
|
705
705
|
const statements = this.__recordStatements;
|
|
706
|
-
const
|
|
707
|
-
const
|
|
706
|
+
const nativeParentUuid = readClaudeParentUuid(record);
|
|
707
|
+
const nativeParent = nativeParentUuid
|
|
708
|
+
? statements.parentTurn.get(root, nativeId, nativeParentUuid)
|
|
709
|
+
: undefined;
|
|
708
710
|
// the CLI's presentation decides what is shown, the kind evidence filters on and where turns start
|
|
709
711
|
const item = record.message !== undefined && !record.isMeta ? toClaudeItem(record, record.uuid) : null;
|
|
710
712
|
const visible = item !== null;
|
|
711
|
-
if (
|
|
713
|
+
if (nativeParentUuid === record.uuid)
|
|
712
714
|
this.__unavailable();
|
|
713
|
-
if (
|
|
715
|
+
if (nativeParentUuid && !nativeParent) {
|
|
714
716
|
if (visible)
|
|
715
717
|
this.__unavailable();
|
|
716
718
|
if (!isOrphanAllowed)
|
|
717
|
-
return
|
|
719
|
+
return nativeParentUuid;
|
|
718
720
|
}
|
|
721
|
+
const previous = statements.recordedParent.get(root, nativeId, record.uuid);
|
|
722
|
+
const isCallResult = item?.nativeType === 'tool-result' &&
|
|
723
|
+
nativeParentUuid !== null &&
|
|
724
|
+
record.sourceToolAssistantUUID === nativeParentUuid;
|
|
725
|
+
// a result indexed again keeps the record it was made to follow
|
|
726
|
+
const parentUuid = isCallResult && typeof previous?.parent_uuid === 'string'
|
|
727
|
+
? previous.parent_uuid
|
|
728
|
+
: isCallResult && !previous
|
|
729
|
+
? this.__resultParent(root, nativeId, row, nativeParentUuid, nativeParent)
|
|
730
|
+
: nativeParentUuid;
|
|
731
|
+
const parent = parentUuid === nativeParentUuid
|
|
732
|
+
? nativeParent
|
|
733
|
+
: statements.parentTurn.get(root, nativeId, parentUuid);
|
|
719
734
|
const textPrompt = item?.kind === 'user-message';
|
|
720
735
|
const turnId = textPrompt
|
|
721
736
|
? record.uuid
|
|
722
737
|
: typeof parent?.turn_id === 'string'
|
|
723
738
|
? parent.turn_id
|
|
724
739
|
: record.uuid;
|
|
725
|
-
const previous = statements.recordedParent.get(root, nativeId, record.uuid);
|
|
726
740
|
if (previous && previous.parent_uuid !== parentUuid)
|
|
727
741
|
this.__unavailable();
|
|
728
742
|
const isAppend = row.leaf_id === null || parent?.anchor_id === row.leaf_id;
|
|
@@ -752,6 +766,23 @@ export class ClaudeHistoryModel {
|
|
|
752
766
|
row.updated_at = Math.max(row.updated_at, createdAt);
|
|
753
767
|
return null;
|
|
754
768
|
}
|
|
769
|
+
/**
|
|
770
|
+
* Claude Code links a tool result to its own call. When parallel calls finish out of order, an
|
|
771
|
+
* earlier call is no longer the leaf, so its result would start a side branch that the current
|
|
772
|
+
* chain leaves out, with the calls and results written after that call. Such a result follows
|
|
773
|
+
* the leaf of its call's turn instead, which keeps one response's calls and all their results
|
|
774
|
+
* on the chain; the record after them follows the last result written, the leaf by then.
|
|
775
|
+
* @returns The record the result follows in the projection: the leaf, or its own call.
|
|
776
|
+
*/
|
|
777
|
+
__resultParent(root, nativeId, row, callUuid, call) {
|
|
778
|
+
if (row.leaf_id === null ||
|
|
779
|
+
call?.is_current !== 1 ||
|
|
780
|
+
call.anchor_id !== callUuid ||
|
|
781
|
+
call.anchor_id === row.leaf_id)
|
|
782
|
+
return callUuid;
|
|
783
|
+
const leaf = this.__recordStatements.parentTurn.get(root, nativeId, row.leaf_id);
|
|
784
|
+
return leaf?.is_current === 1 && leaf.turn_id === call.turn_id ? row.leaf_id : callUuid;
|
|
785
|
+
}
|
|
755
786
|
__hasEntry(root, nativeId, uuid) {
|
|
756
787
|
return this.__recordStatements.hasEntry.get(root, nativeId, uuid) !== undefined;
|
|
757
788
|
}
|
|
@@ -2288,6 +2288,7 @@ export declare const RecordSchema: z.ZodObject<{
|
|
|
2288
2288
|
content: z.ZodUnknown;
|
|
2289
2289
|
}, z.core.$strip>>;
|
|
2290
2290
|
toolUseResult: z.ZodOptional<z.ZodUnknown>;
|
|
2291
|
+
sourceToolAssistantUUID: z.ZodOptional<z.ZodString>;
|
|
2291
2292
|
}, z.core.$strip>;
|
|
2292
2293
|
export type IRecord = z.infer<typeof RecordSchema>;
|
|
2293
2294
|
export declare const FilePatchSchema: z.ZodObject<{
|
|
@@ -56,6 +56,8 @@ export const RecordSchema = z.object({
|
|
|
56
56
|
message: z.object({ role: z.string(), content: z.unknown() }).optional(),
|
|
57
57
|
// the CLI's own result metadata, such as an edit's patch, which live frames call tool_use_result
|
|
58
58
|
toolUseResult: z.unknown().optional(),
|
|
59
|
+
// the call a tool result answers, which Claude Code also writes as the result's parent
|
|
60
|
+
sourceToolAssistantUUID: z.string().optional(),
|
|
59
61
|
});
|
|
60
62
|
// the file Claude Code records on an Edit or Write result; a created file's patch is empty
|
|
61
63
|
export const FilePatchSchema = z.object({
|
package/package.json
CHANGED