Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7b0a304
feat(cli): OpenTUI foundation modules — theme, a11y, clipboard, keys,…
chiga0 Aug 26, 2026
bd028bc
fix(cli): import originals instead of forking slash parser and dialog…
chiga0 Aug 27, 2026
a9ae4ba
fix(cli): address R1 review findings in OpenTUI foundation modules
chiga0 Aug 27, 2026
8e9a6c7
fix(cli): align OpenTUI command host with the memory-file-count rename
chiga0 Aug 28, 2026
81f13f4
feat(cli): OpenTUI migration live-session and input batch
chiga0 Aug 28, 2026
60af4db
fix(cli): address R2 review findings in OpenTUI foundation modules
chiga0 Aug 28, 2026
d09231c
fix(cli): harden kitty probe and screen-reader writer per maintainer …
chiga0 Aug 28, 2026
eb4be25
Merge remote-tracking branch 'fork/feat/tui-foundation-batch' into fe…
chiga0 Aug 28, 2026
e0c4f14
Merge branch 'main' into feat/tui-foundation-batch
chiga0 Aug 28, 2026
39cf0c1
Merge remote-tracking branch 'fork/feat/tui-foundation-batch' into fe…
chiga0 Aug 28, 2026
ff19f4f
fix(cli): address ytahdn independent review findings in OpenTUI found…
chiga0 Aug 28, 2026
ac1278f
Merge remote-tracking branch 'fork/feat/tui-foundation-batch' into fe…
chiga0 Aug 28, 2026
5319d84
Merge remote-tracking branch 'fork/feat/tui-foundation-batch' into fe…
chiga0 Aug 28, 2026
109921e
fix(cli): address R3 review findings in OpenTUI foundation modules
chiga0 Aug 28, 2026
1979cbd
Merge remote-tracking branch 'fork/feat/tui-foundation-batch' into fe…
chiga0 Aug 28, 2026
6e1e4d1
fix(cli): address R4 review findings in OpenTUI foundation modules
chiga0 Aug 28, 2026
46ec0b4
Merge remote-tracking branch 'fork/feat/tui-foundation-batch' into fe…
chiga0 Aug 28, 2026
b46565c
fix(cli): address #10383 R1 findings in foundation modules
chiga0 Aug 29, 2026
5c0e3ef
Merge remote-tracking branch 'fork/feat/tui-foundation-batch' into fe…
chiga0 Aug 29, 2026
ea1c60a
fix(cli): address #10383 R2 Critical findings in slash-dispatch
chiga0 Aug 29, 2026
c25947d
Merge remote-tracking branch 'fork/feat/tui-foundation-batch' into fe…
chiga0 Aug 29, 2026
53d657e
Merge remote-tracking branch 'origin/main' into feat/tui-foundation-b…
chiga0 Aug 30, 2026
65f9220
Merge commit '53d657e137' into feat/tui-live-session-batch
chiga0 Aug 30, 2026
656e996
fix(cli): address #10368 R2 review findings in live-session batch
chiga0 Aug 30, 2026
23655ee
fix(cli): declare cursorOffset on the FakeEditor test interface
chiga0 Aug 30, 2026
efbccbf
Merge remote-tracking branch 'origin/main' into feat/tui-foundation-b…
chiga0 Aug 31, 2026
51647ea
Merge commit 'efbccbf0db' into feat/tui-live-session-batch
chiga0 Aug 31, 2026
69c0e88
Merge remote-tracking branch 'origin/main' into feat/tui-live-session…
chiga0 Aug 31, 2026
00b4893
test(cli): stub listStartingRunIds in the session-switch fake registry
chiga0 Aug 31, 2026
68cf157
Merge remote-tracking branch 'origin/main' into feat/tui-live-session…
chiga0 Aug 31, 2026
b7fe5b9
Merge remote-tracking branch 'origin/main' into feat/tui-live-session…
chiga0 Aug 31, 2026
fd764e8
fix(opentui): address yiliang114 review findings (4 P2 + 1 P3)
chiga0 Aug 31, 2026
859ec33
fix(transcript): address R6 review — thinking latch, cancelled status…
chiga0 Aug 31, 2026
63a7f3c
fix(opentui): address review-pr bot R3 critical findings
chiga0 Aug 31, 2026
1b896e4
fix(opentui): address round-5 review findings R2-5 R3-2 R3-12 R4-1
chiga0 Sep 1, 2026
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
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"qrcode-terminal": "^0.12.0",
"react": "^19.2.4",
"read-package-up": "^11.0.0",
"remend": "^1.3.1",
Comment thread
chiga0 marked this conversation as resolved.
"shell-quote": "^1.9.0",
"simple-git": "^3.36.0",
"string-width": "^7.1.0",
Expand Down
161 changes: 161 additions & 0 deletions packages/cli/src/ui/opentui/client-tool-run.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/**
* @license
* Copyright 2026 Qwen
* SPDX-License-Identifier: Apache-2.0
*/

/**
* Client-initiated tool scheduling tests (/restore, /setup-github parity):
* the one-shot CoreToolScheduler runs with isClientInitiated requests, its
* completion feeds tool-result/tool-end events, and the result never becomes
* a model follow-up (the generator ends with `done`).
*/

import { describe, it, expect, vi, afterEach } from 'vitest';
import type { Config } from '@qwen-code/qwen-code-core';
import type { OpenTuiStreamEvent } from './event-adapter.js';

interface ScheduledCall {
request: { callId: string; name: string; args?: unknown };
status: string;
response?: { resultDisplay?: unknown };
}

let schedulerBehavior: (
options: {
onToolCallsUpdate?: (calls: unknown[]) => void;
onAllToolCallsComplete?: (calls: ScheduledCall[]) => Promise<void>;
},
requests: Array<{ callId: string; name: string; args?: unknown }>,
) => Promise<void>;

vi.mock('@qwen-code/qwen-code-core', async (importOriginal) => {
const actual =
await importOriginal<typeof import('@qwen-code/qwen-code-core')>();
return {
...actual,
CoreToolScheduler: class {
constructor(
private readonly options: {
onToolCallsUpdate?: (calls: unknown[]) => void;
onAllToolCallsComplete?: (calls: ScheduledCall[]) => Promise<void>;
},
) {}
async schedule(
request:
| { callId: string; name: string; args?: unknown }
| Array<{ callId: string; name: string; args?: unknown }>,
): Promise<void> {
const requests = Array.isArray(request) ? request : [request];
await schedulerBehavior(this.options, requests);
}
},
};
});

import { clientToolEvents } from './client-tool-run.js';

async function collect(
generator: AsyncGenerator<OpenTuiStreamEvent>,
): Promise<OpenTuiStreamEvent[]> {
const events: OpenTuiStreamEvent[] = [];
for await (const event of generator) events.push(event);
return events;
}

describe('clientToolEvents', () => {
afterEach(() => {
vi.restoreAllMocks();
});

const config = {} as Config;

it('schedules a client-initiated call and streams its result', async () => {
schedulerBehavior = async (options, requests) => {
await options.onAllToolCallsComplete?.(
requests.map((request) => ({
request,
status: 'success',
response: { resultDisplay: 'restored 3 files' },
})),
);
};
const events = await collect(
clientToolEvents(config, 'restore_files', { checkpoint: 'c1' }),
);
const types = events.map((event) => event.type);
expect(types).toEqual([
'tool-start',
'tool-args',
'tool-result',
'tool-end',
'done',
]);
const start = events[0];
if (start?.type === 'tool-start') {
Comment thread
chiga0 marked this conversation as resolved.
expect(start.tool).toBe('restore_files');
}
const result = events[2];
if (result?.type === 'tool-result') {
expect(result.display).toBe('restored 3 files');
}
const end = events[3];
if (end?.type === 'tool-end') {
expect(end.success).toBe(true);
}
});

it('marks failed executions as unsuccessful tool-end events', async () => {
schedulerBehavior = async (options, requests) => {
await options.onAllToolCallsComplete?.(
requests.map((request) => ({
request,
status: 'error',
response: { resultDisplay: 'boom' },
})),
);
};
const events = await collect(
clientToolEvents(config, 'run_shell_command', { command: 'false' }),
);
const end = events.find((event) => event.type === 'tool-end');
if (end?.type === 'tool-end') {
expect(end.success).toBe(false);
expect(end.summary).toBe('error');
} else {
throw new Error('expected a tool-end event');
}
});

it('surfaces awaiting_approval calls through onWaitingCall', async () => {
const onConfirm = vi.fn();
schedulerBehavior = async (options, requests) => {
options.onToolCallsUpdate?.([
{
status: 'awaiting_approval',
request: requests[0],
confirmationDetails: { type: 'exec', onConfirm },
},
]);
await options.onAllToolCallsComplete?.(
requests.map((request) => ({ request, status: 'success' })),
);
};
const waiting: Array<{ name: string }> = [];
const events = await collect(
clientToolEvents(
config,
'run_shell_command',
{ command: 'gh auth status' },
undefined,
{
onWaitingCall: (call) => {
waiting.push({ name: call.name });
},
},
),
);
expect(waiting).toEqual([{ name: 'run_shell_command' }]);
expect(events.map((event) => event.type)).toContain('done');
});
});
138 changes: 138 additions & 0 deletions packages/cli/src/ui/opentui/client-tool-run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/**
* @license
* Copyright 2026 Qwen
* SPDX-License-Identifier: Apache-2.0
*/

/**
* Client-initiated tool scheduling for the OpenTUI backend (audit 01 G-6b).
*
* Ink commands that return `{ type: 'tool' }` (/restore, /setup-github) are
* scheduled through `useGeminiStream`'s `schedule_tool` branch: a
* `ToolCallRequestInfo` with `isClientInitiated: true` goes to the
* `CoreToolScheduler`, and the completed calls are NOT fed back to the model
* (useGeminiStream only submits functionResponses for provider-initiated
* calls). This module reproduces that one-shot schedule as a neutral event
* stream the backend folds into its transcript, using the same scheduler
* callbacks the live turn uses (approval requests included).
*/

import {
CoreToolScheduler,
type Config,
type ToolCallConfirmationDetails,
type ToolCallRequestInfo,
} from '@qwen-code/qwen-code-core';
import {
extractFileDiff,
renderResultDisplay,
type OpenTuiStreamEvent,
} from './event-adapter.js';

interface LooseCompletedCall {
Comment thread
chiga0 marked this conversation as resolved.
request: { callId: string; name?: string; args?: unknown };
status: string;
response?: {
responseParts?: unknown[];
resultDisplay?: unknown;
error?: unknown;
};
}

export interface ClientToolRunOptions {
/**
* Scheduler-level confirmation requests (DEFAULT mode edit/exec approval).
* The backend renders the dialog and resolves the call through
* `confirmationDetails.onConfirm`; without it the call never settles.
*/
onWaitingCall?: (call: {
callId: string;
name: string;
confirmationDetails: ToolCallConfirmationDetails;
}) => void;
}

/**
* Runs one client-initiated tool call through the real CoreToolScheduler and
* yields neutral events (tool-start → args/output/result → tool-end, ending
* with `done`). Esc aborts through the signal.
*/
export async function* clientToolEvents(
config: Config,
toolName: string,
toolArgs: Record<string, unknown>,
signal?: AbortSignal,
options?: ClientToolRunOptions,
): AsyncGenerator<OpenTuiStreamEvent> {
const abort = signal ?? new AbortController().signal;
const callId = `${toolName}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
const request: ToolCallRequestInfo = {
callId,
name: toolName,
args: toolArgs,
isClientInitiated: true,
prompt_id: `opentui-cmd-${Date.now()}`,
};

yield { type: 'tool-start', id: callId, tool: toolName, title: toolName };
const formattedArgs = JSON.stringify(toolArgs ?? {});
if (formattedArgs !== '{}') {
yield { type: 'tool-args', id: callId, args: formattedArgs };
}

let waitingSeen = false;
const completed = await new Promise<LooseCompletedCall[]>((resolve) => {
const scheduler = new CoreToolScheduler({
config,
getPreferredEditor: () => undefined,
onEditorClose: () => {},
// No outputUpdateHandler: like the live turn, the completion path
// emits the full result; execution-time chunks are not streamed.
onToolCallsUpdate: (calls) => {
if (!options?.onWaitingCall) return;
for (const call of calls) {
if (call.status !== 'awaiting_approval') continue;
if (waitingSeen) continue;
Comment thread
chiga0 marked this conversation as resolved.
waitingSeen = true;
options.onWaitingCall({
callId: call.request.callId,
name: call.request.name,
confirmationDetails: call.confirmationDetails,
});
}
},
onAllToolCallsComplete: async (calls) => {
resolve(calls as unknown as LooseCompletedCall[]);
},
});
void scheduler.schedule([request], abort);
});

for (const call of completed) {
// FileDiff results ride as structured payloads so the tool card renders
// colored diff lines (ink DiffResultRenderer parity).
const diff = extractFileDiff(call.response?.resultDisplay);
if (diff) {
yield { type: 'tool-result', id: call.request.callId, display: '', diff };
} else {
const display = renderResultDisplay(call.response?.resultDisplay);
if (display) {
yield { type: 'tool-result', id: call.request.callId, display };
}
}
const failed = call.status === 'error' || call.status === 'cancelled';
yield {
type: 'tool-end',
id: call.request.callId,
success: !failed,
summary: failed
? call.status === 'cancelled'
? 'cancelled'
Comment thread
chiga0 marked this conversation as resolved.
: 'error'
: 'ok',
};
}
// Client-initiated tools never feed the model back (ink parity: only
// provider-initiated calls become functionResponses).
yield { type: 'done' };
}
Loading
Loading