-
Notifications
You must be signed in to change notification settings - Fork 3k
feat(cli): OpenTUI migration live-session and input batch #10368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 bd028bc
fix(cli): import originals instead of forking slash parser and dialog…
chiga0 a9ae4ba
fix(cli): address R1 review findings in OpenTUI foundation modules
chiga0 8e9a6c7
fix(cli): align OpenTUI command host with the memory-file-count rename
chiga0 81f13f4
feat(cli): OpenTUI migration live-session and input batch
chiga0 60af4db
fix(cli): address R2 review findings in OpenTUI foundation modules
chiga0 d09231c
fix(cli): harden kitty probe and screen-reader writer per maintainer …
chiga0 eb4be25
Merge remote-tracking branch 'fork/feat/tui-foundation-batch' into fe…
chiga0 e0c4f14
Merge branch 'main' into feat/tui-foundation-batch
chiga0 39cf0c1
Merge remote-tracking branch 'fork/feat/tui-foundation-batch' into fe…
chiga0 ff19f4f
fix(cli): address ytahdn independent review findings in OpenTUI found…
chiga0 ac1278f
Merge remote-tracking branch 'fork/feat/tui-foundation-batch' into fe…
chiga0 5319d84
Merge remote-tracking branch 'fork/feat/tui-foundation-batch' into fe…
chiga0 109921e
fix(cli): address R3 review findings in OpenTUI foundation modules
chiga0 1979cbd
Merge remote-tracking branch 'fork/feat/tui-foundation-batch' into fe…
chiga0 6e1e4d1
fix(cli): address R4 review findings in OpenTUI foundation modules
chiga0 46ec0b4
Merge remote-tracking branch 'fork/feat/tui-foundation-batch' into fe…
chiga0 b46565c
fix(cli): address #10383 R1 findings in foundation modules
chiga0 5c0e3ef
Merge remote-tracking branch 'fork/feat/tui-foundation-batch' into fe…
chiga0 ea1c60a
fix(cli): address #10383 R2 Critical findings in slash-dispatch
chiga0 c25947d
Merge remote-tracking branch 'fork/feat/tui-foundation-batch' into fe…
chiga0 53d657e
Merge remote-tracking branch 'origin/main' into feat/tui-foundation-b…
chiga0 65f9220
Merge commit '53d657e137' into feat/tui-live-session-batch
chiga0 656e996
fix(cli): address #10368 R2 review findings in live-session batch
chiga0 23655ee
fix(cli): declare cursorOffset on the FakeEditor test interface
chiga0 efbccbf
Merge remote-tracking branch 'origin/main' into feat/tui-foundation-b…
chiga0 51647ea
Merge commit 'efbccbf0db' into feat/tui-live-session-batch
chiga0 69c0e88
Merge remote-tracking branch 'origin/main' into feat/tui-live-session…
chiga0 00b4893
test(cli): stub listStartingRunIds in the session-switch fake registry
chiga0 68cf157
Merge remote-tracking branch 'origin/main' into feat/tui-live-session…
chiga0 b7fe5b9
Merge remote-tracking branch 'origin/main' into feat/tui-live-session…
chiga0 fd764e8
fix(opentui): address yiliang114 review findings (4 P2 + 1 P3)
chiga0 859ec33
fix(transcript): address R6 review — thinking latch, cancelled status…
chiga0 63a7f3c
fix(opentui): address review-pr bot R3 critical findings
chiga0 1b896e4
fix(opentui): address round-5 review findings R2-5 R3-2 R3-12 R4-1
chiga0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') { | ||
|
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'); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
|
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; | ||
|
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' | ||
|
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' }; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.