jg-agent-hq 13.5.3 → 13.5.5
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 +11 -0
- package/README.md +2 -0
- package/api/README.md +16 -16
- package/dist/providers/claude/control/control.d.ts +2 -2
- package/dist/providers/claude/control/control.js +3 -2
- package/dist/providers/claude/control/diagnostics.d.ts +3 -0
- package/dist/providers/claude/control/diagnostics.js +35 -0
- package/dist/providers/claude/control/stream.js +66 -19
- package/dist/providers/claude/control/types.d.ts +2 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 13.5.5
|
|
4
|
+
|
|
5
|
+
- Preserve queued Claude steers across intervening native turns. Unconfirmed delivery expires only after 30 continuous idle seconds; saved-history confirmations retain their identity until live replay or controller teardown.
|
|
6
|
+
- Report rejected Claude results with bounded UUID-only correlation metadata and a rejection reason, without prompts, native output, file paths or credentials.
|
|
7
|
+
- Preserve exact replay/result validation, action receipts, native history, storage schema and paused queues without resending input.
|
|
8
|
+
|
|
9
|
+
## 13.5.4
|
|
10
|
+
|
|
11
|
+
- Keep Claude control when a steering message is replayed before the preceding turn's result but its own answer completes afterward. Match that completion only to an exact live replay observed by the same controller, retaining bounded correlation metadata and rejecting unknown or consumed identities.
|
|
12
|
+
- Retire replay metadata on new explicit input, controller replacement and shutdown. Preserve existing action receipts, paused queues, storage schema and native history without sending input again.
|
|
13
|
+
|
|
3
14
|
## 13.5.3
|
|
4
15
|
|
|
5
16
|
- Keep controller creation, adoption, resume and recovery in the existing preparation state until native readiness. Opening a session without input no longer reports a turn starting or completing, preventing false completion notifications. Genuine input and autonomous native turns retain their lifecycle events.
|
package/README.md
CHANGED
|
@@ -71,6 +71,8 @@ Explicit actions create, name, adopt, resume, close and delete threads; send idl
|
|
|
71
71
|
|
|
72
72
|
Claude can save a steer as a queued-command attachment without echoing a live user message. Reading that saved input through history, details or evidence confirms a submitted or uncertain delivery when its exact action, session, workspace, turn and original-text fingerprint match. The existing turn-completion history flush performs the same check. This also resolves receipts from an earlier runtime without restoring control or resending input.
|
|
73
73
|
|
|
74
|
+
A steering replay can arrive before the preceding turn's result even when Claude answers it in a following turn. That following completion can name the exact replayed input instead of HQ's generated live turn ID. The controller retains a bounded set of these observed identities within its process generation, consumes a matching completion once and retires them on a new explicit input or controller replacement. Unknown results remain unavailable. This changes no receipt ownership, storage schema or queue delivery and never resends input. Pending steers survive intervening native turns: only unconfirmed input expires after 30 continuous idle seconds, and saved confirmations retain their identity until live replay or controller teardown. Rejected results emit a bounded stderr diagnostic with validated UUIDs and a reason, never message bodies or paths.
|
|
75
|
+
|
|
74
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).
|
|
75
77
|
|
|
76
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. The runtime 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.
|
package/api/README.md
CHANGED
|
@@ -274,22 +274,22 @@ Hosts retain their own resolution metadata and recover missed questions through
|
|
|
274
274
|
|
|
275
275
|
Send `{ kind: 'action', action: { id, runtimeEpoch, command } }`. Generate one UUID per user intent, take the epoch from `status` or the runtime's `runtimeEpoch`, and retain the complete envelope until its receipt can be read. The validated envelope is limited to `MAX_ACTION_BYTES`, 32,768 UTF-8 bytes of its JSON, which `jg-agent-hq/contracts` exports. 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.
|
|
276
276
|
|
|
277
|
-
| Action | Fields and behavior
|
|
278
|
-
| ---------------- |
|
|
279
|
-
| `thread-create` | `provider` (a registered provider ID), `workspaceRoot`, `name`, optional `input`. Creates an empty native thread and sets its readable name before reporting acknowledgement. With `input`, the same action then sends it as the session's first message, see [first input](#first-input).
|
|
280
|
-
| `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.
|
|
281
|
-
| `thread-resume` | `threadId`, `operatorConfirmation`. Resumes an inactive managed thread; the runtime does not fetch its complete conversation bodies.
|
|
282
|
-
| `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.
|
|
283
|
-
| `thread-rename` | `threadId`, `name`. Changes the name only after the matching native acknowledgement.
|
|
284
|
-
| `thread-close` | `threadId`, optional `interrupt`. 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. With `interrupt: true`, a thread whose turn runs is interrupted first, by the same action: its `phase` is `interrupt` until the turn ends, then `clean` and `close`; an idle thread closes as without it. For a verified current-runtime quarantined Claude controller, explicit interrupting close instead starts at clean/close, without guessing a turn; unknown work may still be running.
|
|
285
|
-
| `thread-delete` | `provider`, `workspaceRoot`, `nativeId`. Deletes a session no process runs from its provider's storage, with the runtime's records of it, and runs within its request; see [thread deletion](#thread-deletion).
|
|
286
|
-
| `message` | `threadId`, `input`. Starts a turn only while idle.
|
|
287
|
-
| `steer` | `threadId`, `expectedTurnId`, `text`, optional top-level `files` (`InputFileSchema[]`). Codex uses native `turn/steer`. Claude writes text and qualified files 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.
|
|
288
|
-
| `queue` | `threadId`, `expectedTurnId`, `input`. Saves an explicit next-turn message or skill invocation, never a permission or question answer.
|
|
289
|
-
| `queue-send` | `queuedActionId`. Explicitly authorizes a still-undelivered queue entry, including a queue paused by restart or interruption.
|
|
290
|
-
| `queue-cancel` | `queuedActionId`. Cancels only an undelivered queue entry and clears its saved body.
|
|
291
|
-
| `interrupt` | `threadId`, `expectedTurnId`. A native request acknowledgement leaves the thread stopping until native completion evidence arrives.
|
|
292
|
-
| `native-reply` | `threadId`, `expectedTurnId`, `approvalId`, `response`. Answers one exact current native request; cannot consume queue text.
|
|
277
|
+
| Action | Fields and behavior |
|
|
278
|
+
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
279
|
+
| `thread-create` | `provider` (a registered provider ID), `workspaceRoot`, `name`, optional `input`. Creates an empty native thread and sets its readable name before reporting acknowledgement. With `input`, the same action then sends it as the session's first message, see [first input](#first-input). |
|
|
280
|
+
| `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. |
|
|
281
|
+
| `thread-resume` | `threadId`, `operatorConfirmation`. Resumes an inactive managed thread; the runtime does not fetch its complete conversation bodies. |
|
|
282
|
+
| `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. |
|
|
283
|
+
| `thread-rename` | `threadId`, `name`. Changes the name only after the matching native acknowledgement. |
|
|
284
|
+
| `thread-close` | `threadId`, optional `interrupt`. 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. With `interrupt: true`, a thread whose turn runs is interrupted first, by the same action: its `phase` is `interrupt` until the turn ends, then `clean` and `close`; an idle thread closes as without it. For a verified current-runtime quarantined Claude controller, explicit interrupting close instead starts at clean/close, without guessing a turn; unknown work may still be running. |
|
|
285
|
+
| `thread-delete` | `provider`, `workspaceRoot`, `nativeId`. Deletes a session no process runs from its provider's storage, with the runtime's records of it, and runs within its request; see [thread deletion](#thread-deletion). |
|
|
286
|
+
| `message` | `threadId`, `input`. Starts a turn only while idle. |
|
|
287
|
+
| `steer` | `threadId`, `expectedTurnId`, `text`, optional top-level `files` (`InputFileSchema[]`). Codex uses native `turn/steer`. Claude writes text and qualified files 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. Unconfirmed Claude input expires after 30 continuous idle seconds; any new turn cancels that deadline and a later idle window rearms it for all waiting steers. Saved-history-confirmed steers retain their correlation identity until live replay or controller teardown. Unconfirmed input pending when the process stops fails at once. Otherwise a finished or changed turn cannot become a new turn. Unlisted media types reject the complete input before native writing. No skills or settings are accepted. |
|
|
288
|
+
| `queue` | `threadId`, `expectedTurnId`, `input`. Saves an explicit next-turn message or skill invocation, never a permission or question answer. |
|
|
289
|
+
| `queue-send` | `queuedActionId`. Explicitly authorizes a still-undelivered queue entry, including a queue paused by restart or interruption. |
|
|
290
|
+
| `queue-cancel` | `queuedActionId`. Cancels only an undelivered queue entry and clears its saved body. |
|
|
291
|
+
| `interrupt` | `threadId`, `expectedTurnId`. A native request acknowledgement leaves the thread stopping until native completion evidence arrives. |
|
|
292
|
+
| `native-reply` | `threadId`, `expectedTurnId`, `approvalId`, `response`. Answers one exact current native request; cannot consume queue text. |
|
|
293
293
|
|
|
294
294
|
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, adding only optional top-level `files`. Text-only steers remain unchanged; skills and turn settings cannot be steered.
|
|
295
295
|
|
|
@@ -141,8 +141,8 @@ export declare const createClaudeControl: (additionalDirectories?: string[]) =>
|
|
|
141
141
|
* interrupting it. Claude takes it in at the turn's next tool boundary and replays it there,
|
|
142
142
|
* or, for text written while the turn's final answer streams, replays it after the turn's
|
|
143
143
|
* result and runs it as the session's next turn. Either replay acknowledges the steer against
|
|
144
|
-
* the turn it named
|
|
145
|
-
*
|
|
144
|
+
* the turn it named. Unconfirmed input fails after 30 continuous idle seconds or process
|
|
145
|
+
* shutdown. Saved confirmations retain their identity for a later live replay.
|
|
146
146
|
* @returns The turn the steer named, once Claude replayed it.
|
|
147
147
|
* @throws
|
|
148
148
|
* - JG_AGENT_HQ_ACTION_CONFLICT: The HQ action conflicts with its recorded state
|
|
@@ -206,6 +206,7 @@ export const createClaudeControl = (additionalDirectories = []) => {
|
|
|
206
206
|
conflict();
|
|
207
207
|
session.parked = undefined;
|
|
208
208
|
session.scope = randomUUID();
|
|
209
|
+
session.replayedSteers?.clear();
|
|
209
210
|
const scope = session.scope;
|
|
210
211
|
session.opening = start(session, session.hasInput, signal);
|
|
211
212
|
try {
|
|
@@ -609,8 +610,8 @@ export const createClaudeControl = (additionalDirectories = []) => {
|
|
|
609
610
|
* interrupting it. Claude takes it in at the turn's next tool boundary and replays it there,
|
|
610
611
|
* or, for text written while the turn's final answer streams, replays it after the turn's
|
|
611
612
|
* result and runs it as the session's next turn. Either replay acknowledges the steer against
|
|
612
|
-
* the turn it named
|
|
613
|
-
*
|
|
613
|
+
* the turn it named. Unconfirmed input fails after 30 continuous idle seconds or process
|
|
614
|
+
* shutdown. Saved confirmations retain their identity for a later live replay.
|
|
614
615
|
* @returns The turn the steer named, once Claude replayed it.
|
|
615
616
|
* @throws
|
|
616
617
|
* - JG_AGENT_HQ_ACTION_CONFLICT: The HQ action conflicts with its recorded state
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { IClaudeSession } from './types.js';
|
|
2
|
+
/** Reports one rejected result without exposing prompts, output, paths or parser payloads. */
|
|
3
|
+
export declare const reportRejectedClaudeResult: (session: IClaudeSession, result: unknown, reason: "invalid-result" | "no-active-turn" | "input-mismatch") => void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// failure output is bounded and contains only validated identities, never native bodies
|
|
3
|
+
const MAX_DIAGNOSTIC_IDS = 64;
|
|
4
|
+
const ResultIdentitySchema = z.object({ user_message_uuid: z.uuid().optional() });
|
|
5
|
+
const uuidOrNull = (candidate) => {
|
|
6
|
+
const parsed = z.uuid().safeParse(candidate);
|
|
7
|
+
return parsed.success ? parsed.data : null;
|
|
8
|
+
};
|
|
9
|
+
const collectIds = (identities) => {
|
|
10
|
+
const selected = [];
|
|
11
|
+
let inspected = 0;
|
|
12
|
+
for (const identity of identities) {
|
|
13
|
+
inspected += 1;
|
|
14
|
+
const uuid = uuidOrNull(identity);
|
|
15
|
+
if (uuid !== null)
|
|
16
|
+
selected.push(uuid);
|
|
17
|
+
if (inspected === MAX_DIAGNOSTIC_IDS)
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
return selected;
|
|
21
|
+
};
|
|
22
|
+
/** Reports one rejected result without exposing prompts, output, paths or parser payloads. */
|
|
23
|
+
export const reportRejectedClaudeResult = (session, result, reason) => {
|
|
24
|
+
const identity = ResultIdentitySchema.safeParse(result);
|
|
25
|
+
console.error('[jg-agent-hq] Claude result rejected', JSON.stringify({
|
|
26
|
+
reason,
|
|
27
|
+
sessionId: uuidOrNull(session.id),
|
|
28
|
+
userMessageUuid: identity.success ? (identity.data.user_message_uuid ?? null) : null,
|
|
29
|
+
inputId: uuidOrNull(session.input?.id),
|
|
30
|
+
nativeTurnId: uuidOrNull(session.nativeTurn?.id),
|
|
31
|
+
pendingSteerCount: session.steers.size,
|
|
32
|
+
pendingSteerIds: collectIds(session.steers.keys()),
|
|
33
|
+
replayedSteerIds: collectIds(session.replayedSteers ?? []),
|
|
34
|
+
}));
|
|
35
|
+
};
|
|
@@ -6,6 +6,7 @@ import { toTurnResult } from '../../results/index.js';
|
|
|
6
6
|
import { parseActionRequest } from '../../utilities.js';
|
|
7
7
|
import { HQ_ERRORS } from '../../../errors/index.js';
|
|
8
8
|
import { createClaudePrompt } from './permissions.js';
|
|
9
|
+
import { reportRejectedClaudeResult } from './diagnostics.js';
|
|
9
10
|
const FrameSchema = z.object({
|
|
10
11
|
type: z.string(),
|
|
11
12
|
session_id: z.string().optional(),
|
|
@@ -109,12 +110,19 @@ const unavailable = () => {
|
|
|
109
110
|
* input's. Input still waiting for its replay has no turn yet.
|
|
110
111
|
*/
|
|
111
112
|
export const getActiveTurn = (session) => session.nativeTurn ?? (session.input?.isAcknowledged ? session.input : undefined);
|
|
113
|
+
/** Cancels the idle-only replay deadline before a new native turn begins. */
|
|
114
|
+
const pauseSteerExpiry = (session) => {
|
|
115
|
+
clearTimeout(session.steerReplayTimer);
|
|
116
|
+
delete session.steerReplayTimer;
|
|
117
|
+
};
|
|
112
118
|
/** Acknowledges the single current input before forwarding its ordered turn evidence. */
|
|
113
119
|
const acknowledge = (session, events) => {
|
|
114
120
|
const input = session.input;
|
|
115
121
|
if (!input || input.isAcknowledged)
|
|
116
122
|
return;
|
|
117
123
|
input.isAcknowledged = true;
|
|
124
|
+
pauseSteerExpiry(session);
|
|
125
|
+
session.replayedSteers?.clear();
|
|
118
126
|
clearTimeout(input.timer);
|
|
119
127
|
input.resolve({ id: input.id });
|
|
120
128
|
const request = parseActionRequest(input.requestId);
|
|
@@ -134,6 +142,7 @@ const acknowledge = (session, events) => {
|
|
|
134
142
|
const startNativeTurn = (session, events) => {
|
|
135
143
|
const turn = { id: randomUUID(), interruptRequested: false, hasInterruptionMarker: false };
|
|
136
144
|
session.nativeTurn = turn;
|
|
145
|
+
pauseSteerExpiry(session);
|
|
137
146
|
events?.observe({
|
|
138
147
|
kind: 'turn-started',
|
|
139
148
|
provider: 'claude',
|
|
@@ -162,35 +171,61 @@ export const setBackgroundCommands = (session, count, events) => {
|
|
|
162
171
|
* @param failure The shared control failure, when its diagnostic cause is available.
|
|
163
172
|
*/
|
|
164
173
|
export const failSteers = (session, turnId, failure = HQ_ERRORS.create('claudeFailed', { data: { kind: 'agent-unavailable' } })) => {
|
|
174
|
+
if (turnId === undefined) {
|
|
175
|
+
pauseSteerExpiry(session);
|
|
176
|
+
session.replayedSteers?.clear();
|
|
177
|
+
}
|
|
165
178
|
for (const steer of session.steers.values()) {
|
|
166
179
|
if (turnId !== undefined && steer.turnId !== turnId)
|
|
167
180
|
continue;
|
|
168
|
-
clearTimeout(steer.timer);
|
|
169
181
|
session.steers.delete(steer.id);
|
|
170
182
|
if (!steer.isAcknowledged)
|
|
171
183
|
steer.reject(failure);
|
|
172
184
|
}
|
|
173
185
|
};
|
|
174
|
-
|
|
175
|
-
* Claude replays a steer written while a turn's final answer streams only after that turn's
|
|
176
|
-
* result, at once; a steer still unreplayed this long after its turn ended fails.
|
|
177
|
-
*/
|
|
186
|
+
// an unconfirmed steer expires only after a continuous idle window
|
|
178
187
|
const STEER_REPLAY_GRACE_MS = 30_000;
|
|
179
|
-
|
|
180
|
-
const
|
|
188
|
+
// match the bounded late-control identity window; eviction never accepts an unknown result
|
|
189
|
+
const MAX_REPLAYED_STEERS = 64;
|
|
190
|
+
/** Retains saved confirmations and never expires an input while another turn is running. */
|
|
191
|
+
const expireIdleSteers = (session) => {
|
|
192
|
+
delete session.steerReplayTimer;
|
|
193
|
+
if (getActiveTurn(session) || session.isClosing || session.isQuarantined)
|
|
194
|
+
return;
|
|
195
|
+
for (const [id, steer] of session.steers) {
|
|
196
|
+
if (steer.isAcknowledged)
|
|
197
|
+
continue;
|
|
198
|
+
session.steers.delete(id);
|
|
199
|
+
steer.reject(HQ_ERRORS.create('claudeFailed', { data: { kind: 'agent-unavailable' } }));
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
/** Arms one idle deadline for every unconfirmed input, including steers of earlier turns. */
|
|
203
|
+
const awaitLateSteers = (session) => {
|
|
204
|
+
pauseSteerExpiry(session);
|
|
205
|
+
if (getActiveTurn(session) || session.isClosing || session.isQuarantined)
|
|
206
|
+
return;
|
|
181
207
|
for (const steer of session.steers.values())
|
|
182
|
-
if (steer.
|
|
183
|
-
|
|
208
|
+
if (!steer.isAcknowledged) {
|
|
209
|
+
session.steerReplayTimer = setTimeout(() => expireIdleSteers(session), STEER_REPLAY_GRACE_MS);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
184
212
|
};
|
|
185
213
|
/**
|
|
186
|
-
* Takes in a steer's replay
|
|
187
|
-
*
|
|
188
|
-
*
|
|
214
|
+
* Takes in a steer's replay, which can precede the old result even when its answer runs next.
|
|
215
|
+
* With no active turn, the replay starts that following turn under its own UUID; otherwise keep
|
|
216
|
+
* its identity for a later native completion. Acknowledge delivery against the turn it named.
|
|
189
217
|
*/
|
|
190
218
|
const acknowledgeSteer = (session, steer, events) => {
|
|
191
|
-
clearTimeout(steer.timer);
|
|
192
219
|
session.steers.delete(steer.id);
|
|
220
|
+
const replayed = (session.replayedSteers ??= new Set());
|
|
221
|
+
replayed.add(steer.id);
|
|
222
|
+
if (replayed.size > MAX_REPLAYED_STEERS) {
|
|
223
|
+
const oldest = replayed.values().next().value;
|
|
224
|
+
if (oldest !== undefined)
|
|
225
|
+
replayed.delete(oldest);
|
|
226
|
+
}
|
|
193
227
|
if (!getActiveTurn(session)) {
|
|
228
|
+
pauseSteerExpiry(session);
|
|
194
229
|
session.nativeTurn = { id: steer.id, interruptRequested: false, hasInterruptionMarker: false };
|
|
195
230
|
events?.observe({
|
|
196
231
|
kind: 'turn-started',
|
|
@@ -360,17 +395,27 @@ export const receiveClaudeMessage = (session, raw, events) => {
|
|
|
360
395
|
}
|
|
361
396
|
}
|
|
362
397
|
else if (frame.type === 'result') {
|
|
363
|
-
const
|
|
398
|
+
const parsedResult = ResultSchema.safeParse(raw);
|
|
399
|
+
if (!parsedResult.success) {
|
|
400
|
+
reportRejectedClaudeResult(session, raw, 'invalid-result');
|
|
401
|
+
throw parsedResult.error;
|
|
402
|
+
}
|
|
403
|
+
const result = parsedResult.data;
|
|
364
404
|
observeFastMode(session, raw);
|
|
365
405
|
// a turn Claude started, or one a steer runs after its turn, has no action to capture its result
|
|
366
406
|
if (result.user_message_uuid === undefined ||
|
|
367
|
-
result.user_message_uuid === session.nativeTurn?.id
|
|
407
|
+
result.user_message_uuid === session.nativeTurn?.id ||
|
|
408
|
+
(session.nativeTurn !== undefined && session.replayedSteers?.has(result.user_message_uuid))) {
|
|
368
409
|
const turn = session.nativeTurn;
|
|
369
|
-
if (!turn)
|
|
410
|
+
if (!turn) {
|
|
411
|
+
reportRejectedClaudeResult(session, result, 'no-active-turn');
|
|
370
412
|
unavailable();
|
|
413
|
+
}
|
|
414
|
+
if (result.user_message_uuid !== undefined)
|
|
415
|
+
session.replayedSteers?.delete(result.user_message_uuid);
|
|
371
416
|
session.nativeTurn = undefined;
|
|
372
417
|
endTurn(session, events);
|
|
373
|
-
awaitLateSteers(session
|
|
418
|
+
awaitLateSteers(session);
|
|
374
419
|
events?.observe({
|
|
375
420
|
kind: 'turn-completed',
|
|
376
421
|
provider: 'claude',
|
|
@@ -381,13 +426,15 @@ export const receiveClaudeMessage = (session, raw, events) => {
|
|
|
381
426
|
return;
|
|
382
427
|
}
|
|
383
428
|
const input = session.input;
|
|
384
|
-
if (!input || input.id !== result.user_message_uuid || session.nativeTurn)
|
|
429
|
+
if (!input || input.id !== result.user_message_uuid || session.nativeTurn) {
|
|
430
|
+
reportRejectedClaudeResult(session, result, 'input-mismatch');
|
|
385
431
|
unavailable();
|
|
432
|
+
}
|
|
386
433
|
acknowledge(session, events);
|
|
387
434
|
const state = toTurnState(result, input);
|
|
388
435
|
session.input = undefined;
|
|
389
436
|
endTurn(session, events);
|
|
390
|
-
awaitLateSteers(session
|
|
437
|
+
awaitLateSteers(session);
|
|
391
438
|
const observedUsage = UsageSchema.safeParse(result.usage);
|
|
392
439
|
const usage = observedUsage.success
|
|
393
440
|
? {
|
|
@@ -27,7 +27,6 @@ export type IClaudeSteer = {
|
|
|
27
27
|
isAcknowledged: boolean;
|
|
28
28
|
resolve(turnId: string): void;
|
|
29
29
|
reject(error: unknown): void;
|
|
30
|
-
timer?: ReturnType<typeof setTimeout>;
|
|
31
30
|
};
|
|
32
31
|
export type IClaudeSavedInput = Pick<IHistoryItem, 'kind' | 'provenance'> & (Pick<IHistoryItem, 'turnId'> | Pick<IEvidenceItem, 'reference'>);
|
|
33
32
|
export type IClaudeTurn = IClaudeInput | IClaudeNativeTurn;
|
|
@@ -54,6 +53,8 @@ export type IClaudeSession = {
|
|
|
54
53
|
input?: IClaudeInput;
|
|
55
54
|
nativeTurn?: IClaudeNativeTurn;
|
|
56
55
|
steers: Map<string, IClaudeSteer>;
|
|
56
|
+
steerReplayTimer?: ReturnType<typeof setTimeout>;
|
|
57
|
+
replayedSteers?: Set<string>;
|
|
57
58
|
backgroundTaskCount: number;
|
|
58
59
|
fastMode?: IClaudeFastMode;
|
|
59
60
|
apiMessageId?: string;
|
package/package.json
CHANGED