Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions apps/cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
configureHttpDispatcher,
createStepCode,
createStepCodeProviderInlineExtension,
createStepModelQueueFactory,
createStepProviderConfig,
createStepSessionManagerFactory,
createStepSettingsManager,
Expand All @@ -35,6 +36,7 @@ import {
installProcessStderrDevLogCapture,
isStepConfigCommand,
isStepInteractiveLoginStartup,
isStepProvider,
isStepServicesDisabled,
loginMcpServer,
logoutMcpServer,
Expand Down Expand Up @@ -74,6 +76,7 @@ import {
type StepSettingsManager,
scanUsageOverview,
setStderrDevLogStorageRootDirectory,
stepModelQueueStatusText,
stopThemeWatcher,
syncStepLoginProfileEndpoint,
trackStepTelemetry,
Expand Down Expand Up @@ -270,7 +273,7 @@ const stepMainOptions: MainOptions = {
interactiveModeOptions: {
showChangelog: false,
tuiStyle: "step" as const,
defaultModelForProvider: (providerId) => (providerId === STEP_PROVIDER_ID ? STEP_DEFAULT_MODEL : undefined),
defaultModelForProvider: (providerId) => (isStepProvider(providerId) ? STEP_DEFAULT_MODEL : undefined),
allowedAuthProviders: [STEP_PROVIDER_ID],
stepLogin: (host) =>
runStepLogin({
Expand Down Expand Up @@ -320,6 +323,9 @@ const stepMainOptions: MainOptions = {
},
},
...(modelRequestObserver ? { modelRequestObserver } : {}),
// Every mode (interactive, print/json, rpc and the subagent children it
// starts) runs through here; whether a request waits is the server's decision.
modelFetch: createStepModelQueueFactory(),
systemPromptProduct: {
name: "StepCode",
role: "an interactive terminal coding agent developed by StepFun",
Expand Down Expand Up @@ -741,7 +747,7 @@ try {
STEP_DEFAULT_PROVIDER;
if (
interactiveStartup &&
selectedProvider === STEP_PROVIDER_ID &&
isStepProvider(selectedProvider) &&
!hasExplicitStepCredential &&
!hasConfiguredStepCodeCredential(stepCodeConfig)
) {
Expand Down Expand Up @@ -924,6 +930,7 @@ async function dispatchStepAppMode(prep: Extract<MainPreparation, { kind: "dispa
messages: prep.parsed.messages,
initialMessage: prep.initialMessage,
initialImages: prep.initialImages,
formatModelQueue: stepModelQueueStatusText,
});
stopThemeWatcher();
restoreStdout();
Expand Down
26 changes: 26 additions & 0 deletions apps/cli/src/ui/interactive-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import {
listStepSessions,
loadAllHighlightLanguages,
MissingSessionCwdError,
type ModelQueueState,
messageSkillInvocations,
normalizeChangelogLinks,
onThemeChange,
Expand Down Expand Up @@ -172,6 +173,7 @@ import { FooterComponent, formatTokens } from "./view/chrome/footer.ts";
import {
BranchSummaryStatusIndicator,
IdleStatus,
ModelQueueStatusSlot,
STEP_WORKING_INDICATOR_INTERVAL_MS,
type StatusIndicator,
TurnDoneIndicator,
Expand Down Expand Up @@ -2530,7 +2532,31 @@ export class InteractiveMode {
this.statusContainer.addChild(indicator);
}

/** Created on the first queue report; until then nothing is covered. */
private modelQueueSlot: ModelQueueStatusSlot | undefined;

updateModelQueue(queueId: string, state: ModelQueueState | null): void {
this.modelQueueSlot ??= new ModelQueueStatusSlot({
ui: () => this.ui,
presentation: () => this.presentation,
active: () => this.activeStatusIndicator,
swap: (next) => {
const previous = this.activeStatusIndicator;
this.activeStatusIndicator = next;
this.statusContainer.clear();
if (next) this.statusContainer.addChild(next);
return previous;
},
});
this.modelQueueSlot.update(queueId, state);
}

clearModelQueue(): void {
this.modelQueueSlot?.leave();
}

clearStatusIndicator(kind?: StatusIndicator["kind"]): void {
this.modelQueueSlot?.forget(kind);
if (kind && this.activeStatusIndicator?.kind !== kind) {
return;
}
Expand Down
5 changes: 5 additions & 0 deletions apps/cli/src/ui/runtime/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type {
ExtensionUIDialogOptions,
InteractiveModeOptions,
MarkdownTransformer,
ModelQueueState,
SessionEntry,
} from "@step-harness/coding-agent";
import type { Container, EditorComponent, MarkdownTheme, TUI, TuiAltScreen, TuiMainScreen } from "@step-harness/pi-tui";
Expand Down Expand Up @@ -128,6 +129,10 @@ export interface RuntimeContext {
showWorkingStatusIndicator(): void;
showTurnDoneIndicator(durationSeconds: number): void;
clearStatusIndicator(kind?: StatusIndicator["kind"]): void;
/** Show (or, with `null`, drop) one model request's place in line; see `ModelQueueStatusSlot`. */
updateModelQueue(queueId: string, state: ModelQueueState | null): void;
/** Drop every queue row and restore what they covered. */
clearModelQueue(): void;
showError(errorMessage: string): void;
renderSessionEntries(entries: SessionEntry[], options?: { updateFooter?: boolean; populateHistory?: boolean }): void;
addCompactionCostNotice(notice: {
Expand Down
8 changes: 8 additions & 0 deletions apps/cli/src/ui/runtime/session-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ export async function handleSessionEvent(ctx: RuntimeContext, event: AgentSessio

case "agent_end":
ctx.ui.terminal.setProgress(false);
// A run that ends while a request waits (a stop) leaves no queue row behind.
ctx.clearModelQueue();
ctx.clearStatusIndicator("working");
// Turn-done marker: only for normally-ended turns (aborted/error
// turns already show an error line in the transcript); stays
Expand Down Expand Up @@ -460,6 +462,12 @@ export async function handleSessionEvent(ctx: RuntimeContext, event: AgentSessio
break;
}

case "model_queue": {
ctx.updateModelQueue(event.queueId, event.queue);
ctx.redraw.requestRender();
break;
}

case "auto_retry_start": {
// Set up escape to abort retry
ctx.retryEscapeHandler = ctx.defaultEditor.onEscape;
Expand Down
100 changes: 98 additions & 2 deletions apps/cli/src/ui/view/chrome/status-indicator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { WorkingIndicatorOptions } from "@step-harness/coding-agent";
import { keyText, theme } from "@step-harness/coding-agent";
import { keyText, type ModelQueueState, stepModelQueueStatusText, theme } from "@step-harness/coding-agent";
import { type Component, Loader, type TUI, truncateToWidth, visibleWidth } from "@step-harness/pi-tui";
import type { AssistantMessage, AssistantMessageEvent } from "@step-harness/providers";
import { CountdownTimer } from "../dialogs/countdown-timer.ts";
Expand All @@ -8,7 +8,7 @@ import { estimateTokens, formatElapsedTime, formatTokens } from "./footer.ts";
/** Refresh cadence for the compact Step working indicator. */
export const STEP_WORKING_INDICATOR_INTERVAL_MS = 200;

export type StatusIndicatorKind = "working" | "retry" | "compaction" | "branchSummary";
export type StatusIndicatorKind = "working" | "retry" | "compaction" | "branchSummary" | "queue";

export interface WorkingOutputSnapshot {
elapsedSeconds: number;
Expand Down Expand Up @@ -355,6 +355,102 @@ export class RetryStatusIndicator extends StatusIndicator {
}
}

/**
* Stands in for the working row while the running model request waits in the
* Step Plan queue: the request has not reached the model yet. Shows the place
* in line, never a wait estimate.
*/
export class ModelQueueStatusIndicator extends StatusIndicator {
constructor(ui: TUI, state: ModelQueueState, presentation: "native" | "step" = "native") {
super(
"queue",
ui,
(spinner) => theme.fg("warning", spinner),
(text) => theme.fg("muted", text),
ModelQueueStatusIndicator.label(state),
undefined,
presentation,
);
}

update(state: ModelQueueState): void {
this.setMessage(ModelQueueStatusIndicator.label(state));
}

private static label(state: ModelQueueState): string {
return `${stepModelQueueStatusText(state)} (${keyText("app.interrupt")} to cancel)`;
}
}

/** Where a {@link ModelQueueStatusSlot} shows its row: the host's single status position. */
export interface ModelQueueStatusHost {
ui(): TUI;
presentation(): "native" | "step";
/** The indicator in the status position now. */
active(): StatusIndicator | undefined;
/** Put `next` (or nothing) in the status position and hand back what was there, neither disposed nor stopped. */
swap(next: StatusIndicator | undefined): StatusIndicator | undefined;
}

/**
* The queue row of every model request that waits in line, by queue id. While
* any waits, the row shows the newest one; the indicator it covered (working,
* retry, compaction) is paused, not disposed, and comes back when the last
* request leaves. One request leaving never clears another's place.
*/
export class ModelQueueStatusSlot {
private readonly host: ModelQueueStatusHost;
private readonly waiting = new Map<string, ModelQueueState>();
private indicator: ModelQueueStatusIndicator | undefined;
private covered: StatusIndicator | undefined;

constructor(host: ModelQueueStatusHost) {
this.host = host;
}

update(queueId: string, state: ModelQueueState | null): void {
this.waiting.delete(queueId);
if (state) this.waiting.set(queueId, state);
const newest = [...this.waiting.values()].at(-1);
if (!newest) {
this.leave();
return;
}
if (this.indicator && this.host.active() === this.indicator) {
this.indicator.update(newest);
return;
}
// First report, or another row took the position meanwhile: cover what is there now.
this.indicator = new ModelQueueStatusIndicator(this.host.ui(), newest, this.host.presentation());
const previous = this.host.swap(this.indicator);
this.covered?.dispose();
this.covered = previous;
previous?.stop();
}

/** Every request left the line (or the run ended): restore the covered row. */
leave(): void {
this.waiting.clear();
const indicator = this.indicator;
const covered = this.covered;
this.indicator = undefined;
this.covered = undefined;
if (indicator && this.host.active() === indicator) {
this.host.swap(covered);
covered?.start();
} else covered?.dispose();
indicator?.dispose();
}

/** The host cleared rows of `kind` (all rows when undefined): a covered one of that kind is not restored. */
forget(kind: StatusIndicatorKind | undefined): void {
if (this.covered && (kind === undefined || this.covered.kind === kind)) {
this.covered.dispose();
this.covered = undefined;
}
}
}

export type CompactionStatusReason = "manual" | "threshold" | "overflow";

export class CompactionStatusIndicator extends StatusIndicator {
Expand Down
3 changes: 2 additions & 1 deletion apps/cli/src/ui/view/dialogs/usage-panel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
type AccountUsageState,
type ExtensionCommandContext,
isStepProvider,
stripAnsi,
theme,
type UsagePresentation,
Expand Down Expand Up @@ -237,7 +238,7 @@ export function usagePresentationRows(model: UsagePresentation, width = 100, det
);
if (model.session.invalid || model.session.missing)
rows.push(`Usage coverage: ${model.session.invalid} invalid, ${model.session.missing} missing records`);
if (s.provider !== "step") rows.push(`Step account quota · current model uses ${s.provider}`);
if (!isStepProvider(s.provider)) rows.push(`Step account quota · current model uses ${s.provider}`);
rows.push("", "R refresh account");
}
rows.push("1/2 or ←/→ switch tab · ↑/↓ scroll · Esc close");
Expand Down
2 changes: 2 additions & 0 deletions apps/cli/src/ui/view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export { FooterComponent } from "./chrome/footer.ts";
export {
BranchSummaryStatusIndicator,
CompactionStatusIndicator,
ModelQueueStatusIndicator,
ModelQueueStatusSlot,
RetryStatusIndicator,
StatusIndicator,
TurnDoneIndicator,
Expand Down
Loading