-
Notifications
You must be signed in to change notification settings - Fork 938
feat(tui): lazy-create the session on first use with the v2 engine #2458
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 all commits
d375565
79fe2a1
cd52d72
e30180d
2e21d4c
c5e87a1
c7392b6
bccb66a
5562fd7
d2cffe2
0bce21a
0fa8827
1f1d31a
f43d440
0c750fb
6423c5f
d5b03f2
c68b20a
4089a16
07d509f
ec70188
0f752cb
27e712f
fd60d1b
1c8dd7d
fa9dd23
c3e271e
7ad4c0a
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 |
|---|---|---|
|
|
@@ -93,6 +93,13 @@ export async function handlePlanCommand(host: SlashCommandHost, args: string): P | |
| return; | ||
| } | ||
|
|
||
| // The session may already be in the requested mode (e.g. it was created | ||
| // with config.defaultPlanMode applied), and re-entering plan mode throws. | ||
| if (host.state.appState.planMode === enabled) { | ||
| host.showNotice(`Plan mode is already ${enabled ? 'on' : 'off'}`); | ||
| return; | ||
| } | ||
|
|
||
| await applyPlanMode(host, session, enabled); | ||
| } | ||
|
|
||
|
|
@@ -117,10 +124,12 @@ async function applyPlanMode(host: SlashCommandHost, session: Session, enabled: | |
|
|
||
| export async function handleYoloCommand(host: SlashCommandHost, args: string): Promise<void> { | ||
| const session = host.session; | ||
| if (session === undefined) { | ||
| if (session === undefined && !host.engineV2) { | ||
| host.showError(NO_ACTIVE_SESSION_MESSAGE); | ||
| return; | ||
| } | ||
| // v2 session-less: the chosen mode is recorded in appState and passed to the | ||
| // lazy-created session; apply the runtime permission only when one exists. | ||
|
|
||
| const subcmd = args.trim().toLowerCase(); | ||
| const currentMode = host.state.appState.permissionMode; | ||
|
|
@@ -130,7 +139,7 @@ export async function handleYoloCommand(host: SlashCommandHost, args: string): P | |
| host.showNotice('YOLO mode is already on'); | ||
| return; | ||
| } | ||
| await session.setPermission('yolo'); | ||
| await session?.setPermission('yolo'); | ||
|
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.
When a first v2 prompt is already inside lazy Useful? React with 👍 / 👎. 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.
When a first v2 prompt is already inside lazy Useful? React with 👍 / 👎. |
||
| host.setAppState({ permissionMode: 'yolo' }); | ||
| host.showNotice('YOLO mode: ON', 'Tool actions auto-approved; the agent may still ask you questions.'); | ||
| return; | ||
|
|
@@ -141,30 +150,32 @@ export async function handleYoloCommand(host: SlashCommandHost, args: string): P | |
| host.showNotice('YOLO mode is already off'); | ||
| return; | ||
| } | ||
| await session.setPermission('manual'); | ||
| await session?.setPermission('manual'); | ||
| host.setAppState({ permissionMode: 'manual' }); | ||
| host.showNotice('YOLO mode: OFF'); | ||
| return; | ||
| } | ||
|
|
||
| // toggle | ||
| if (currentMode === 'yolo') { | ||
| await session.setPermission('manual'); | ||
| await session?.setPermission('manual'); | ||
| host.setAppState({ permissionMode: 'manual' }); | ||
| host.showNotice('YOLO mode: OFF'); | ||
| } else { | ||
| await session.setPermission('yolo'); | ||
| await session?.setPermission('yolo'); | ||
| host.setAppState({ permissionMode: 'yolo' }); | ||
| host.showNotice('YOLO mode: ON', 'Tool actions auto-approved; the agent may still ask you questions.'); | ||
| } | ||
| } | ||
|
|
||
| export async function handleAutoCommand(host: SlashCommandHost, args: string): Promise<void> { | ||
| const session = host.session; | ||
| if (session === undefined) { | ||
| if (session === undefined && !host.engineV2) { | ||
| host.showError(NO_ACTIVE_SESSION_MESSAGE); | ||
| return; | ||
| } | ||
| // v2 session-less: the chosen mode is recorded in appState and passed to the | ||
| // lazy-created session; apply the runtime permission only when one exists. | ||
|
|
||
| const subcmd = args.trim().toLowerCase(); | ||
| const currentMode = host.state.appState.permissionMode; | ||
|
|
@@ -174,7 +185,7 @@ export async function handleAutoCommand(host: SlashCommandHost, args: string): P | |
| host.showNotice('Auto mode is already on'); | ||
| return; | ||
| } | ||
| await session.setPermission('auto'); | ||
| await session?.setPermission('auto'); | ||
| host.setAppState({ permissionMode: 'auto' }); | ||
| host.showNotice('Auto mode: ON', 'All actions auto-approved; the agent will not ask you questions.'); | ||
| return; | ||
|
|
@@ -185,19 +196,19 @@ export async function handleAutoCommand(host: SlashCommandHost, args: string): P | |
| host.showNotice('Auto mode is already off'); | ||
| return; | ||
| } | ||
| await session.setPermission('manual'); | ||
| await session?.setPermission('manual'); | ||
| host.setAppState({ permissionMode: 'manual' }); | ||
| host.showNotice('Auto mode: OFF'); | ||
| return; | ||
| } | ||
|
|
||
| // toggle | ||
| if (currentMode === 'auto') { | ||
| await session.setPermission('manual'); | ||
| await session?.setPermission('manual'); | ||
| host.setAppState({ permissionMode: 'manual' }); | ||
| host.showNotice('Auto mode: OFF'); | ||
| } else { | ||
| await session.setPermission('auto'); | ||
| await session?.setPermission('auto'); | ||
| host.setAppState({ permissionMode: 'auto' }); | ||
| host.showNotice('Auto mode: ON', 'All actions auto-approved; the agent will not ask you questions.'); | ||
| } | ||
|
|
@@ -463,6 +474,14 @@ async function performModelSwitch( | |
| effort: ThinkingEffort, | ||
| persist: boolean, | ||
| ): Promise<void> { | ||
| let session = host.session; | ||
| if (session === undefined && host.engineV2) { | ||
| // A first prompt may still be inside lazy creation: wait it out so the | ||
| // switch lands on the new session instead of being overwritten by its | ||
| // assembly. | ||
| await host.waitForLazyCreation(); | ||
| session = host.session; | ||
| } | ||
| if (host.state.appState.streamingPhase !== 'idle') { | ||
| host.showError('Cannot switch models while streaming — press Esc or Ctrl-C first.'); | ||
| return; | ||
|
|
@@ -476,7 +495,6 @@ async function performModelSwitch( | |
| let effectiveAlias = alias; | ||
| let effectiveEffort = effort; | ||
|
|
||
| const session = host.session; | ||
| try { | ||
| if (session === undefined && runtimeChanged) { | ||
| await host.authFlow.activateModelAfterLogin(alias, effort); | ||
|
|
@@ -875,7 +893,14 @@ async function applyPermissionChoice(host: SlashCommandHost, mode: PermissionMod | |
| } | ||
|
|
||
| try { | ||
| await host.requireSession().setPermission(mode); | ||
| if (host.session !== undefined) { | ||
| await host.session.setPermission(mode); | ||
| } else if (!host.engineV2) { | ||
| host.showError(NO_ACTIVE_SESSION_MESSAGE); | ||
| return; | ||
| } | ||
| // v2 session-less: the chosen mode is recorded in appState and passed to | ||
| // the lazy-created session. | ||
| } catch (error) { | ||
| const msg = formatErrorMessage(error); | ||
| host.showError(`Failed to set permission mode: ${msg}`); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.