src/vs/platform/agentHost/node/claude/claudePromptQueue.ts
171 LOC · 171 covered · 0 uncovered · 38 ranges · 428 concepts · 22 introducers · 229 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
claudePromptQueue.ts ×10
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type { SDKUserMessage } from '@anthropic-ai/claude-agent-sdk';
import { DeferredPromise } from '../../../../base/common/async.js';
import { Disposable } from '../../../../base/common/lifecycle.js';
import { StopWatch } from '../../../../base/common/stopwatch.js';
import { ILogService } from '../../../log/common/log.js';
/**
* One {@link SDKUserMessage} the queue has handed to (or is about to
* hand to) the SDK. Lifecycle:
* 1. Created by the caller and pushed via {@link ClaudePromptQueue.push}.
* 2. Shifted off the to-yield list and pushed to the yielded list when
* the prompt iterable hands it to the SDK.
* 3. Shifted off the yielded list and {@link deferred} settled when
* the matching SDK `result` message arrives (via
* {@link ClaudePromptQueue.settleHead}).
*/
export interface IPendingSdkMessage {
readonly sdkMessage: SDKUserMessage;
readonly sdkUuid: string;
readonly turnId: string;
readonly stopWatch: StopWatch;
readonly deferred: DeferredPromise<void>;
readonly steeringPendingId?: string;
}
/**
* Owns the prompt queue + the async iterable handed to
* `WarmQuery.query()`. Knows nothing about the SDK Query lifecycle,
* config push, or message dispatch — those live on the pipeline.
*
* Invariants:
* • Pushing wakes the iterable's parked `next()`.
* • The iterable returns `done` when the supplied `getAbortSignal()`
* is aborted; pipeline calls {@link notifyAborted} after flipping
* the controller so the parked `next()` returns immediately.
* • {@link settleHead} pops the head of the yielded list (called by
* the consumer loop on every `result` message).
* • {@link failAll} rejects every pending deferred and clears both
* lists; used by abort and crash fan-out.
* • {@link resetForRebind} re-creates the parked deferred for a fresh
* Query binding (the queue itself survives across rebinds).
*/
export class ClaudePromptQueue extends Disposable {
private _toYield: IPendingSdkMessage[] = [];
private _yielded: IPendingSdkMessage[] = [];
/**
* Entries that have been popped by {@link settleHead} during the
* current turn but whose deferreds haven't been completed yet — we
* batch-complete them when the turn fully drains so an intermediate
* `result` (steering preempt; CONTEXT.md M10) does NOT settle the
* original `sendMessage`'s deferred.
*/
private _popped: IPendingSdkMessage[] = [];
private _pendingPromptDeferred = new DeferredPromise<void>();
readonly iterable: AsyncIterable<SDKUserMessage> = {
[Symbol.asyncIterator]: () => ({
while (true) {
if (this._getAbortSignal().aborted) {
}
this._yielded.push(entry);
this._logService.info(`[Claude:${this._sessionId}] queue yielded sdkUuid=${entry.sdkUuid} turnId=${entry.turnId}${entry.steeringPendingId ? ` steeringPendingId=${entry.steeringPendingId}` : ''}`);
if (entry.steeringPendingId) {
}
}
}
}),
constructor(
private readonly _getAbortSignal: () => AbortSignal,
private readonly _onSteeringYielded: (pendingId: string) => void,
@ILogService private readonly _logService: ILogService,
) {
super();
}
/** True iff no entries are queued or in-flight. */
get isEmpty(): boolean {
}
* Push an entry. Resolves with the entry's deferred (which the
* consumer settles on `result` via {@link settleHead}).
*/
push(entry: IPendingSdkMessage): Promise<void> {
this._pendingPromptDeferred.complete();
return entry.deferred.p;
}
/**
* Most-recent in-flight or queued entry, used by steering to inherit
* its parent's `turnId`. Prefers the in-flight head over the latest
* queued entry (matches CONTEXT.md M10: steering folds into the
* in-progress protocol Turn).
*/
peekParent(): IPendingSdkMessage | undefined {
}
/**
* Pop the head of the yielded list. If the queue is now fully
* drained (no more pending or in-flight entries), batch-complete
* every popped-but-deferred deferred from this turn including the
* one we just popped. Otherwise hold the popped entry's deferred
* until the turn ends — the M10 invariant for steering preempt.
* Called by the consumer on every `result` message.
*/
settleHead(): IPendingSdkMessage | undefined {
if (!completed) {
}
for (const e of this._popped) {
e.deferred.complete();
}
}
}
/** Reject every pending deferred with `err` and clear all lists. */
failAll(err: Error): void {
for (const entry of list) {
entry.deferred.error(err);
}
}
rejectAll(this._toYield);
rejectAll(this._yielded);
rejectAll(this._popped);
this._toYield = [];
this._yielded = [];
this._popped = [];
}
/** Wake any parked `next()` — call after the controller is aborted so the iterable returns `done`. */
notifyAborted(): void {
}
/** Re-create the parked deferred for a fresh Query binding. */
resetForRebind(): void {
}