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
5 changes: 5 additions & 0 deletions .changeset/persist-cycled-effort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pythoughts/pythinker-code": patch
---

Keep the thinking effort chosen with Ctrl-T/Shift-Tab as the default across restarts.
17 changes: 2 additions & 15 deletions apps/pythinker-code/src/tui/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { ThemeSelectorComponent } from '../components/dialogs/theme-selector';
import { UpdatePreferenceSelectorComponent } from '../components/dialogs/update-preference-selector';
import { saveTuiConfig } from '../config';
import { generateKeybindingsTemplate } from '../keybindings';
import { persistDefaultModelSelection } from '../utils/persist-effort';
import type { ThemeName } from '#/tui/theme';
import { currentTheme, isBuiltInTheme, lightColors, loadCustomThemeMerged } from '#/tui/theme';
import {
Expand Down Expand Up @@ -769,21 +770,7 @@ async function performModelSwitch(host: SlashCommandHost, alias: string, effort:
}

async function persistModelSelection(host: SlashCommandHost, alias: string, effort: string): Promise<boolean> {
const defaultThinking = effort !== 'off';
const config = await host.harness.getConfig({ reload: true });
if (
config.defaultModel === alias &&
config.defaultThinking === defaultThinking &&
config.thinking?.effort === effort
) {
return false;
}
await host.harness.setConfig({
defaultModel: alias,
defaultThinking,
thinking: { effort },
});
return true;
return persistDefaultModelSelection(host.harness, alias, effort);
}

// ---------------------------------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions apps/pythinker-code/src/tui/controllers/editor-keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Editor, parseKey } from '@earendil-works/pi-tui';
import {
coerceEffortForModel,
effortLevelsForModel,
type PythinkerHarness,
type Session,
} from '@pythoughts/pythinker-code-sdk';

Expand All @@ -28,6 +29,7 @@ import {
type ParsedKeybinding,
} from '#/tui/keybindings';
import { isPrintableChar, printableChar } from '#/tui/utils/printable-key';
import { persistDefaultModelSelection } from '#/tui/utils/persist-effort';

function effectiveContextBindings(
bindings: readonly ParsedKeybinding[],
Expand All @@ -45,6 +47,7 @@ function effectiveContextBindings(
export interface EditorKeyboardHost {
state: TUIState;
session: Session | undefined;
readonly harness: PythinkerHarness;
cancelInFlight: (() => void) | undefined;

handleUserInput(text: string): void;
Expand Down Expand Up @@ -323,6 +326,13 @@ export class EditorKeyboardController {
host.track('thinking_toggle', { enabled: next !== 'off', effort: next });
// No transcript notice: the footer already shows the new level live, and
// rapid cycling would stack a line per keypress in the chat history.
try {
await persistDefaultModelSelection(host.harness, alias, next);
} catch (error) {
host.showError(
`Thinking effort set to ${next}, but failed to save default: ${formatErrorMessage(error)}`,
);
}
}

private cancelCurrentCompaction(): void {
Expand Down
27 changes: 27 additions & 0 deletions apps/pythinker-code/src/tui/utils/persist-effort.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { PythinkerHarness } from '@pythoughts/pythinker-code-sdk';

/**
* Save the model + thinking-effort pair as the startup default.
* Returns false when the config already holds the same selection.
*/
export async function persistDefaultModelSelection(
harness: PythinkerHarness,
alias: string,
effort: string,
): Promise<boolean> {
const defaultThinking = effort !== 'off';
const config = await harness.getConfig({ reload: true });
if (
config.defaultModel === alias &&
config.defaultThinking === defaultThinking &&
config.thinking?.effort === effort
) {
return false;
}
await harness.setConfig({
defaultModel: alias,
defaultThinking,
thinking: { effort },
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return true;
}
61 changes: 61 additions & 0 deletions apps/pythinker-code/test/tui/controllers/editor-keyboard.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { describe, expect, it, vi } from 'vitest';

import {
EditorKeyboardController,
type EditorKeyboardHost,
} from '#/tui/controllers/editor-keyboard';
import type { ImageAttachmentStore } from '#/tui/utils/image-attachment-store';

function makeHost() {
const editor: Record<string, unknown> = {};
const setConfig = vi.fn(() => Promise.resolve());
const getConfig = vi.fn(() =>
Promise.resolve({ defaultModel: undefined, defaultThinking: undefined, thinking: undefined }),
);
const host = {
state: {
editor,
ui: { addInputListener: vi.fn(() => () => {}), requestRender: vi.fn() },
appState: {
model: 'test/model',
thinkingLevel: 'low',
availableModels: {
'test/model': {
capabilities: ['thinking'],
supportEfforts: ['low', 'medium', 'high', 'max'],
},
},
},
},
session: { setThinking: vi.fn(() => Promise.resolve()) },
harness: { getConfig, setConfig },
cancelInFlight: undefined,
setAppState: vi.fn(),
track: vi.fn(),
showError: vi.fn(),
showNotice: vi.fn(),
dispatchFooter: vi.fn(),
updateEditorBorderHighlight: vi.fn(),
updateQueueDisplay: vi.fn(),
} as unknown as EditorKeyboardHost;
return { host, editor, setConfig, getConfig };
}

describe('EditorKeyboardController thinking-effort cycling', () => {
it('persists the cycled effort as the startup default', async () => {
const { host, editor, setConfig } = makeHost();
const controller = new EditorKeyboardController(host, {} as unknown as ImageAttachmentStore);
controller.install();

const onCycleEffort = editor['onCycleEffort'] as () => void;
expect(typeof onCycleEffort).toBe('function');
onCycleEffort();
await vi.waitFor(() => {
expect(setConfig).toHaveBeenCalledWith({
defaultModel: 'test/model',
defaultThinking: true,
thinking: { effort: 'medium' },
});
});
});
});
Loading