Repository navigation
feat(web-shell): run read-only info commands immediately mid-turn #8496
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
Changes from 5 commits
508e2b0
8672498
57eeeda
54e8676
7206e8e
8782aad
548879c
b1a935e
eb6f075
84a7e91
acaa555
f7d04f6
15f3e00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -215,7 +215,10 @@ import { | |
| encodeVisionModelForSetting, | ||
| extractBareModelId, | ||
| } from './utils/modelEncoding'; | ||
| import { appendOrDeferLocalUserMessage } from './utils/localCommandQueue'; | ||
| import { | ||
| appendLocalUserEchoIfIdle, | ||
| appendOrDeferLocalUserMessage, | ||
| } from './utils/localCommandQueue'; | ||
| import { QueuedPromptDisplay } from './components/QueuedPromptDisplay'; | ||
| import { useQueuedPrompts } from './hooks/useQueuedPrompts'; | ||
| import { useNewSessionSuggestion } from './hooks/useNewSessionSuggestion'; | ||
|
|
@@ -5003,6 +5006,21 @@ export function App({ | |
| [store], | ||
| ); | ||
|
|
||
| // Echo a local command when idle, but never block it. Read-only display | ||
| // commands (/stats, /about, /context) render their result as a status | ||
| // block, which does not split the active turn, so they run immediately | ||
| // mid-turn with only the echo skipped (see appendLocalUserEchoIfIdle). | ||
| // Their result dispatch must pass `clearActiveText: false`, otherwise the | ||
| // status block would finalize the in-flight assistant block mid-stream. | ||
| const echoLocalCommandIfIdle = useCallback( | ||
| (text: string): void => { | ||
| appendLocalUserEchoIfIdle(streamingStateRef.current !== 'idle', text, { | ||
| append: (value: string) => store.appendLocalUserMessage(value), | ||
| }); | ||
| }, | ||
| [store], | ||
| ); | ||
|
|
||
| const blockLocalCommandDuringTurn = useCallback((): false => { | ||
| pushToast('error', t('queue.commandBlocked')); | ||
| return false; | ||
|
|
@@ -5865,17 +5883,20 @@ export function App({ | |
| // is revealed even when the click comes while scrolled up. | ||
| const showContextUsage = useCallback( | ||
| (commandText: string, detail: boolean) => { | ||
| // Self-guard so every entry point (keyboard, status-bar button, in-chat | ||
| // "context detail" click) defers mid-turn instead of splitting the turn. | ||
| // Read-only: every entry point (keyboard, status-bar button, in-chat | ||
| // "context detail" click) runs immediately, even mid-turn — only the | ||
| // echo is skipped while streaming so the active turn is not split. | ||
| if (!requireActiveSessionForLocalCommand()) return; | ||
| if (echoOrDeferLocalCommand(commandText)) return; | ||
| echoLocalCommandIfIdle(commandText); | ||
| sessionActions | ||
| .getContextUsage({ detail }) | ||
| .then((result) => { | ||
| store.dispatch([ | ||
| { | ||
| type: 'status', | ||
| text: serializeContextUsageMessage(result), | ||
| // Mid-turn runs must not finalize the streaming block. | ||
| clearActiveText: false, | ||
| }, | ||
| ]); | ||
| resumeChatBottomFollow('smooth'); | ||
|
|
@@ -5885,7 +5906,7 @@ export function App({ | |
| }); | ||
| }, | ||
| [ | ||
| echoOrDeferLocalCommand, | ||
| echoLocalCommandIfIdle, | ||
| store, | ||
| requireActiveSessionForLocalCommand, | ||
| sessionActions, | ||
|
|
@@ -7561,23 +7582,27 @@ export function App({ | |
| if (statsArg === 'model') statsView = 'model'; | ||
| else if (statsArg === 'tools') statsView = 'tools'; | ||
| if (!requireActiveSessionForLocalCommand()) return false; | ||
| if (echoOrDeferLocalCommand(text, images)) return true; | ||
| echoLocalCommandIfIdle(text); | ||
| sessionActions | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| .getStats() | ||
| .then((result) => { | ||
| store.dispatch([ | ||
| { | ||
| type: 'status', | ||
| text: serializeStatsMessage(result, statsView), | ||
| // Mid-turn runs must not finalize the streaming block. | ||
| clearActiveText: false, | ||
| }, | ||
| ]); | ||
| resumeChatBottomFollow('smooth'); | ||
| }) | ||
| .catch(() => {}); | ||
| .catch((error: unknown) => { | ||
| reportError(error, 'Failed to load stats'); | ||
| }); | ||
| return true; | ||
| } | ||
| if (cmd === 'status' || cmd === 'about') { | ||
| if (echoOrDeferLocalCommand(text, images)) return true; | ||
| echoLocalCommandIfIdle(text); | ||
| Promise.all([ | ||
| workspaceActions.loadPreflight().catch(() => null), | ||
|
Comment on lines
+7624
to
7626
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] The Append 中文说明
在 Promise 链末尾追加 — claude-opus-4-6 via Qwen Code /review (v0.21.5) |
||
| workspaceActions.loadProviders().catch(() => null), | ||
|
|
@@ -7635,7 +7660,12 @@ export function App({ | |
| }; | ||
|
|
||
| store.dispatch([ | ||
| { type: 'status', text: serializeStatusMessage(info) }, | ||
| { | ||
| type: 'status', | ||
| text: serializeStatusMessage(info), | ||
| // Mid-turn runs must not finalize the streaming block. | ||
| clearActiveText: false, | ||
| }, | ||
| ]); | ||
| resumeChatBottomFollow('smooth'); | ||
| }); | ||
|
|
@@ -7780,6 +7810,7 @@ export function App({ | |
| store, | ||
| enqueuePrompt, | ||
| echoOrDeferLocalCommand, | ||
| echoLocalCommandIfIdle, | ||
| branchCurrentSession, | ||
| closeMobileDrawer, | ||
| closePanel, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.