@thegitai/cli 1.0.0-preview.53 → 1.0.0-preview.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -0
- package/dist/bin/ai.js +5 -0
- package/dist/src/api/chat.js +4 -0
- package/dist/src/help-text.js +16 -1
- package/dist/src/mcp-client.js +335 -0
- package/dist/src/mcp-command.js +176 -0
- package/dist/src/mcp-config.js +123 -0
- package/dist/src/mcp-sdk.js +3 -0
- package/dist/src/mcp-types.js +26 -0
- package/dist/src/permissions.js +16 -3
- package/dist/src/project-key.js +11 -0
- package/dist/src/project-model-preferences.js +74 -0
- package/dist/src/reasoning-effort.js +27 -0
- package/dist/src/session-store.js +2 -10
- package/dist/src/session.js +2 -1
- package/dist/src/tool-executor.js +10 -3
- package/dist/src/ui/repl.js +45 -16
- package/dist/src/ui/slash-commands.js +2 -1
- package/dist/src/ui/tui/build-frame.js +85 -34
- package/dist/src/ui/tui/model-label.js +13 -0
- package/dist/src/ui/tui/shell-input.js +19 -0
- package/dist/vendor/mcp/LICENSES.txt +414 -0
- package/dist/vendor/mcp/client.cjs +82 -0
- package/package.json +6 -6
package/dist/src/ui/repl.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { sessionMcp } from '../mcp-client.js';
|
|
2
|
+
import { projectModelEffort, readProjectModelEfforts, saveProjectModelEffort } from '../project-model-preferences.js';
|
|
3
|
+
import { REASONING_EFFORT_LABELS } from '../reasoning-effort.js';
|
|
1
4
|
import { basename } from 'node:path';
|
|
2
5
|
import { createRatatuiBridge } from './tui/bridge.js';
|
|
3
6
|
import { bucketActionLabel, } from '../permissions.js';
|
|
@@ -705,7 +708,7 @@ function buildFileChangeEntry(event) {
|
|
|
705
708
|
title: `Edited ${filePath}${summary}`,
|
|
706
709
|
};
|
|
707
710
|
}
|
|
708
|
-
export function buildWorkingToolEntry(event) {
|
|
711
|
+
export function buildWorkingToolEntry(event, label = event.call.name) {
|
|
709
712
|
const { call, result } = event;
|
|
710
713
|
const failed = result?.ok !== true && result?.skipped !== true;
|
|
711
714
|
const kind = result?.ok === true ? 'tool' : 'system';
|
|
@@ -754,7 +757,7 @@ export function buildWorkingToolEntry(event) {
|
|
|
754
757
|
}
|
|
755
758
|
const args = formatToolArgs(call, result);
|
|
756
759
|
return {
|
|
757
|
-
body: `${
|
|
760
|
+
body: `${label}${args ? ` ${args}` : ''}${state(` -> ${formatToolResultState(result)}`)}${error}`,
|
|
758
761
|
kind,
|
|
759
762
|
title: 'Tool',
|
|
760
763
|
};
|
|
@@ -1039,7 +1042,7 @@ function shallowArrayEqual(a, b) {
|
|
|
1039
1042
|
}
|
|
1040
1043
|
return true;
|
|
1041
1044
|
}
|
|
1042
|
-
function createInitialShellState(session, serverModels, debugUi) {
|
|
1045
|
+
function createInitialShellState(session, serverModels, debugUi, serverUrl) {
|
|
1043
1046
|
return {
|
|
1044
1047
|
activeTurnInput: '',
|
|
1045
1048
|
activeTurnInputPreformatted: false,
|
|
@@ -1059,6 +1062,7 @@ function createInitialShellState(session, serverModels, debugUi) {
|
|
|
1059
1062
|
commandLog: [],
|
|
1060
1063
|
contextStatus: 'Idle',
|
|
1061
1064
|
currentModelId: session.modelId,
|
|
1065
|
+
reasoningEffort: projectModelEffort(readProjectModelEfforts(session.rootDir, serverUrl, session.env), session.modelId),
|
|
1062
1066
|
cursor: 0,
|
|
1063
1067
|
exiting: false,
|
|
1064
1068
|
input: '',
|
|
@@ -1407,7 +1411,7 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
1407
1411
|
setScratchSession(session.sessionId);
|
|
1408
1412
|
setImageStoreSession(session.sessionId);
|
|
1409
1413
|
setTodoSession(session.sessionId);
|
|
1410
|
-
const store = createShellStore(createInitialShellState(session, serverModels, debugUi));
|
|
1414
|
+
const store = createShellStore(createInitialShellState(session, serverModels, debugUi, authConfig.serverUrl));
|
|
1411
1415
|
store.replaceTranscript(createSessionTranscript(session));
|
|
1412
1416
|
let currentServerModels = serverModels;
|
|
1413
1417
|
let sessionAutoYes = session.autoYes;
|
|
@@ -1772,6 +1776,7 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
1772
1776
|
autoYes: sessionAutoYes,
|
|
1773
1777
|
commandCursor: 0,
|
|
1774
1778
|
currentModelId: session.modelId,
|
|
1779
|
+
reasoningEffort: projectModelEffort(readProjectModelEfforts(session.rootDir, authConfig.serverUrl, session.env), session.modelId),
|
|
1775
1780
|
sessionId: session.sessionId,
|
|
1776
1781
|
modelPickerIndex: current.modelPickerOpen
|
|
1777
1782
|
? getDefaultModelPickerIndex(session.modelId, current.serverModels)
|
|
@@ -2073,15 +2078,19 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
2073
2078
|
input: '',
|
|
2074
2079
|
modelPickerIndex: getDefaultModelPickerIndex(current.currentModelId, fresh.models),
|
|
2075
2080
|
modelPickerOpen: true,
|
|
2081
|
+
modelPickerEfforts: readProjectModelEfforts(session.rootDir, authConfig.serverUrl, session.env),
|
|
2076
2082
|
status: 'Select a model',
|
|
2077
2083
|
}));
|
|
2078
2084
|
};
|
|
2079
|
-
const switchToModel = async (modelId) => {
|
|
2085
|
+
const switchToModel = async (modelId, effort) => {
|
|
2080
2086
|
const requested = Number(modelId);
|
|
2081
2087
|
const fresh = currentServerModels.models.some((model) => model.id === requested)
|
|
2082
2088
|
? currentServerModels
|
|
2083
2089
|
: await refreshServerModels();
|
|
2084
2090
|
const selected = models.validateServerModel(modelId, fresh);
|
|
2091
|
+
if (effort !== undefined) {
|
|
2092
|
+
saveProjectModelEffort(session.rootDir, selected, effort, authConfig.serverUrl, session.env);
|
|
2093
|
+
}
|
|
2085
2094
|
session.modelId = selected;
|
|
2086
2095
|
models.updateSelectedModelCache({
|
|
2087
2096
|
config: authConfig,
|
|
@@ -2092,7 +2101,7 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
2092
2101
|
return;
|
|
2093
2102
|
syncShellStateFromSession();
|
|
2094
2103
|
appendStaticEntry({
|
|
2095
|
-
body:
|
|
2104
|
+
body: `${formatModelLabel(selected, fresh.models)} · ${REASONING_EFFORT_LABELS[store.getState().reasoningEffort]} effort${effort === undefined ? '' : '\nSaved for this model in this project.'}`,
|
|
2096
2105
|
kind: 'system',
|
|
2097
2106
|
title: 'Model',
|
|
2098
2107
|
});
|
|
@@ -2226,16 +2235,8 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
2226
2235
|
});
|
|
2227
2236
|
return;
|
|
2228
2237
|
}
|
|
2229
|
-
if (selected.id === current.currentModelId) {
|
|
2230
|
-
appendStaticEntry({
|
|
2231
|
-
body: `Already using ${formatModelLabel(selected.id, current.serverModels)}.`,
|
|
2232
|
-
kind: 'system',
|
|
2233
|
-
title: 'Model',
|
|
2234
|
-
});
|
|
2235
|
-
return;
|
|
2236
|
-
}
|
|
2237
2238
|
try {
|
|
2238
|
-
await switchToModel(selected.id);
|
|
2239
|
+
await switchToModel(selected.id, projectModelEffort(current.modelPickerEfforts ?? {}, selected.id));
|
|
2239
2240
|
}
|
|
2240
2241
|
catch (error) {
|
|
2241
2242
|
if (exitForAuthenticationError(error))
|
|
@@ -2592,6 +2593,27 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
2592
2593
|
requestExit();
|
|
2593
2594
|
return;
|
|
2594
2595
|
}
|
|
2596
|
+
if (input === '/mcp') {
|
|
2597
|
+
const connections = sessionMcp(session);
|
|
2598
|
+
const controller = new AbortController();
|
|
2599
|
+
activeTurnAbort = controller;
|
|
2600
|
+
store.update((current) => ({ ...current, busy: true, status: 'Checking MCP servers...', activeTurnInput: '/mcp' }));
|
|
2601
|
+
try {
|
|
2602
|
+
await connections.discover(controller.signal, { force: true });
|
|
2603
|
+
appendStaticEntry({ body: connections.status(), kind: 'system', title: 'MCP servers' });
|
|
2604
|
+
}
|
|
2605
|
+
catch (error) {
|
|
2606
|
+
appendStaticEntry({ body: controller.signal.aborted ? 'MCP discovery cancelled.' : String(error.message), kind: 'system', title: 'MCP servers' });
|
|
2607
|
+
}
|
|
2608
|
+
finally {
|
|
2609
|
+
if (activeTurnAbort === controller)
|
|
2610
|
+
activeTurnAbort = null;
|
|
2611
|
+
store.update((current) => ({ ...current, busy: false, activeTurnInput: '', status: '' }));
|
|
2612
|
+
await remountTui();
|
|
2613
|
+
}
|
|
2614
|
+
await flushQueuedMessage();
|
|
2615
|
+
return;
|
|
2616
|
+
}
|
|
2595
2617
|
if (input === '/help') {
|
|
2596
2618
|
appendStaticEntry({
|
|
2597
2619
|
body: formatInteractiveHelpText(),
|
|
@@ -3071,7 +3093,7 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
3071
3093
|
appendTurnAwareEntry(entry);
|
|
3072
3094
|
return;
|
|
3073
3095
|
}
|
|
3074
|
-
store.appendWorkingTool(buildWorkingToolEntry(event));
|
|
3096
|
+
store.appendWorkingTool(buildWorkingToolEntry(event, session.mcp?.label(event.call.name)));
|
|
3075
3097
|
};
|
|
3076
3098
|
const syncBackgroundJobsState = () => {
|
|
3077
3099
|
const expandedId = store.getState().jobsPickerExpandedId;
|
|
@@ -3161,6 +3183,13 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
3161
3183
|
title: 'Approvals',
|
|
3162
3184
|
});
|
|
3163
3185
|
}
|
|
3186
|
+
else if (decision.kind === 'always-mcp-tool') {
|
|
3187
|
+
appendTurnAwareEntry({
|
|
3188
|
+
body: `Allowed for the rest of this session: ${request.mcpLabel ?? request.title}.`,
|
|
3189
|
+
kind: 'system',
|
|
3190
|
+
title: 'Approvals',
|
|
3191
|
+
});
|
|
3192
|
+
}
|
|
3164
3193
|
else if (decision.kind === 'always-origin') {
|
|
3165
3194
|
appendTurnAwareEntry({
|
|
3166
3195
|
body: `Allowed for the rest of this session: browser actions on ${decision.origin}.`,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const SLASH_COMMANDS = [
|
|
2
|
-
{ command: '/model', description: '
|
|
2
|
+
{ command: '/model', description: 'Choose a model and project reasoning effort' },
|
|
3
3
|
{ command: '/help', description: 'Show available chat commands' },
|
|
4
4
|
{ command: '/usage', description: 'Show account usage percentage and reset times' },
|
|
5
5
|
{
|
|
@@ -7,6 +7,7 @@ export const SLASH_COMMANDS = [
|
|
|
7
7
|
description: 'Open the session picker to resume a previous session',
|
|
8
8
|
},
|
|
9
9
|
{ command: '/new', description: 'start a new conversation; this session remains saved' },
|
|
10
|
+
{ command: '/mcp', description: 'Check MCP connections and available tools' },
|
|
10
11
|
{ command: '/jobs', description: 'Background jobs: pick to view output or kill' },
|
|
11
12
|
{
|
|
12
13
|
command: '/notify',
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { fitModelLabel } from './model-label.js';
|
|
2
|
+
import { projectModelEffort } from '../../project-model-preferences.js';
|
|
3
|
+
import { REASONING_EFFORTS, REASONING_EFFORT_LABELS, REASONING_EFFORT_DESCRIPTIONS } from '../../reasoning-effort.js';
|
|
1
4
|
import { agentModeColor, agentModeLabelTiers, agentModeShortLabel, } from '../../agent-mode.js';
|
|
2
5
|
import { singleLinePreview, truncate } from '../../utils.js';
|
|
3
6
|
import { formatClientTokenUsage } from '../repl.js';
|
|
@@ -523,7 +526,7 @@ function composerFooterLines(state, contentWidth) {
|
|
|
523
526
|
return lines;
|
|
524
527
|
}
|
|
525
528
|
const tokenUsageText = state.tokenUsage || formatClientTokenUsage(null);
|
|
526
|
-
lines.push(
|
|
529
|
+
lines.push(...composerFooterModeLines(state, contentWidth, formatModelLabel(state.currentModelId, state.serverModels), tokenUsageText
|
|
527
530
|
? displayWidth(tokenUsageText) + FOOTER_USAGE_SEPARATOR.length
|
|
528
531
|
: 0, tokenUsageText
|
|
529
532
|
? [
|
|
@@ -533,22 +536,48 @@ function composerFooterLines(state, contentWidth) {
|
|
|
533
536
|
: []));
|
|
534
537
|
return lines;
|
|
535
538
|
}
|
|
536
|
-
function
|
|
537
|
-
const
|
|
539
|
+
function composerFooterModeLines(state, contentWidth, modelLabel, usageWidth, usageSpans) {
|
|
540
|
+
const effort = REASONING_EFFORT_LABELS[state.reasoningEffort ?? 'default'];
|
|
541
|
+
const effortText = ` · ${effort} effort`;
|
|
542
|
+
const modeLabels = agentModeLabelTiers(state.agentMode).map((label) => `Mode: ${label}`);
|
|
543
|
+
const modeWidth = displayWidth(modeLabels[0]);
|
|
544
|
+
const separateUsage = usageWidth > 0 && modeWidth + usageWidth > contentWidth;
|
|
545
|
+
const tailWidth = separateUsage ? 0 : usageWidth;
|
|
546
|
+
const canCancel = state.busy && !state.queuedMessage && !state.userInputPrompt;
|
|
547
|
+
const feedbackHints = [canCancel ? FOOTER_CANCEL_HINT : '', footerNotificationHint(state.transientStatus)].filter(Boolean);
|
|
548
|
+
const feedback = feedbackHints.join(' · ');
|
|
549
|
+
const feedbackWidth = feedback ? displayWidth(feedback) + FOOTER_HINT_MIN_GAP : 0;
|
|
550
|
+
const combined = displayWidth(modelLabel + effortText) + FOOTER_MODEL_SEPARATOR.length + modeWidth + tailWidth + feedbackWidth <= contentWidth;
|
|
551
|
+
const modelText = combined ? modelLabel : fitModelLabel(modelLabel, contentWidth - displayWidth(effortText));
|
|
552
|
+
const modelSpans = [
|
|
553
|
+
span(modelText, { color: 'cyan' }),
|
|
554
|
+
span(effortText, { bold: true }),
|
|
555
|
+
];
|
|
538
556
|
const row = fitComposerFooterRow({
|
|
539
|
-
modeLabels
|
|
540
|
-
modeLabelFallback: agentModeShortLabel(state.agentMode)
|
|
557
|
+
modeLabels,
|
|
558
|
+
modeLabelFallback: `Mode: ${agentModeShortLabel(state.agentMode)}`,
|
|
541
559
|
cycleHint: state.busy ? '' : FOOTER_CYCLE_HINT,
|
|
542
560
|
rightHints: composerFooterRightHints(state),
|
|
543
|
-
leadWidth: displayWidth(
|
|
544
|
-
tailWidth
|
|
561
|
+
leadWidth: combined ? displayWidth(modelLabel + effortText) + FOOTER_MODEL_SEPARATOR.length : 0,
|
|
562
|
+
tailWidth,
|
|
545
563
|
contentWidth,
|
|
546
564
|
});
|
|
565
|
+
const remainingHints = feedbackHints.filter((hint) => !row.rightHint.includes(hint));
|
|
566
|
+
const remainingFeedback = remainingHints.join(' · ');
|
|
567
|
+
const feedbackLines = !remainingFeedback ? []
|
|
568
|
+
: displayWidth(remainingFeedback) <= contentWidth ? [remainingFeedback]
|
|
569
|
+
: remainingHints.flatMap((hint) => wrapText(hint, contentWidth));
|
|
547
570
|
const footerMuted = mutedStyle();
|
|
548
|
-
|
|
571
|
+
const modeLine = line(...(combined ? [...modelSpans, span(FOOTER_MODEL_SEPARATOR, footerMuted)] : []), span(row.modeLabel, {
|
|
549
572
|
color: agentModeColor(state.agentMode),
|
|
550
573
|
bold: state.agentMode === 'auto-accept',
|
|
551
|
-
}), ...(row.cycleHint ? [span(row.cycleHint, footerMuted)] : []), ...(row.gap ? [span(' '.repeat(row.gap), footerMuted)] : []), ...(row.rightHint ? [span(row.rightHint, footerMuted)] : []), ...usageSpans);
|
|
574
|
+
}), ...(row.cycleHint ? [span(row.cycleHint, footerMuted)] : []), ...(row.gap ? [span(' '.repeat(row.gap), footerMuted)] : []), ...(row.rightHint ? [span(row.rightHint, footerMuted)] : []), ...(separateUsage ? [] : usageSpans));
|
|
575
|
+
return [
|
|
576
|
+
...(combined ? [] : [line(...modelSpans)]),
|
|
577
|
+
modeLine,
|
|
578
|
+
...feedbackLines.map((text) => plainLine(text, footerMuted)),
|
|
579
|
+
...(separateUsage ? wrapText(usageSpans.slice(1).map((part) => part.text).join(''), contentWidth).map((text) => plainLine(text, { color: 'cyan' })) : []),
|
|
580
|
+
];
|
|
552
581
|
}
|
|
553
582
|
const FOOTER_USAGE_SEPARATOR = ' ';
|
|
554
583
|
const FOOTER_MODEL_SEPARATOR = ' ';
|
|
@@ -807,7 +836,7 @@ function buildOverlayPanel(rows, width, color, height = Number.POSITIVE_INFINITY
|
|
|
807
836
|
];
|
|
808
837
|
}
|
|
809
838
|
function padSpansToInnerWidth(spans, innerWidth, fill) {
|
|
810
|
-
const used = spans.reduce((total, part) => total +
|
|
839
|
+
const used = spans.reduce((total, part) => total + displayWidth(part.text), 0);
|
|
811
840
|
const pad = Math.max(0, innerWidth - used);
|
|
812
841
|
if (pad === 0)
|
|
813
842
|
return spans;
|
|
@@ -817,7 +846,8 @@ function modelPickerPanelSideLine(content, innerWidth) {
|
|
|
817
846
|
return overlayPanelLine(content, innerWidth, MODEL_PICKER_BORDER_COLOR);
|
|
818
847
|
}
|
|
819
848
|
const MODEL_PICKER_COST_WIDTH = 6;
|
|
820
|
-
const
|
|
849
|
+
const MODEL_PICKER_MODEL_MIN_WIDTH = 42;
|
|
850
|
+
const MODEL_PICKER_MODEL_MAX_WIDTH = 54;
|
|
821
851
|
const MODEL_PICKER_SEPARATOR = ' │ ';
|
|
822
852
|
const MODEL_PICKER_WIDE_MIN_WIDTH = 78;
|
|
823
853
|
function modelPickerTopBorder(panelWidth) {
|
|
@@ -842,24 +872,29 @@ function modelPickerCostText(rating) {
|
|
|
842
872
|
const steps = Math.max(1, Math.min(3, Math.round(rating)));
|
|
843
873
|
return '$'.repeat(steps);
|
|
844
874
|
}
|
|
875
|
+
function modelPickerModelWidth(innerWidth) {
|
|
876
|
+
return Math.min(MODEL_PICKER_MODEL_MAX_WIDTH, Math.max(MODEL_PICKER_MODEL_MIN_WIDTH, innerWidth - MODEL_PICKER_COST_WIDTH - MODEL_PICKER_SEPARATOR.length * 2 - 18));
|
|
877
|
+
}
|
|
845
878
|
function modelPickerNotesWidth(innerWidth) {
|
|
846
879
|
return Math.max(18, innerWidth -
|
|
847
|
-
|
|
880
|
+
modelPickerModelWidth(innerWidth) -
|
|
848
881
|
MODEL_PICKER_COST_WIDTH -
|
|
849
882
|
MODEL_PICKER_SEPARATOR.length * 2);
|
|
850
883
|
}
|
|
851
|
-
function modelPickerModelSpans(option, selected, width, showCurrentTag, labelStyle, selectedStyle) {
|
|
884
|
+
function modelPickerModelSpans(option, selected, effort, width, showCurrentTag, labelStyle, selectedStyle) {
|
|
852
885
|
const tag = option.current && showCurrentTag ? ' (current)' : '';
|
|
853
|
-
const
|
|
854
|
-
const
|
|
855
|
-
const
|
|
886
|
+
const effortText = ` · ${REASONING_EFFORT_LABELS[effort]}`;
|
|
887
|
+
const nameWidth = Math.max(1, width - displayWidth(tag + effortText) - 2);
|
|
888
|
+
const label = `${selected ? '▶ ' : ' '}${fitModelLabel(option.label, nameWidth)}`;
|
|
889
|
+
const used = displayWidth(label + effortText + tag);
|
|
856
890
|
return [
|
|
857
891
|
span(label, { ...labelStyle, ...selectedStyle }),
|
|
892
|
+
span(effortText, { color: mutedColor(), bold: selected, ...selectedStyle }),
|
|
858
893
|
span(tag, { color: 'gray', ...selectedStyle }),
|
|
859
894
|
span(' '.repeat(Math.max(0, width - used)), selectedStyle),
|
|
860
895
|
];
|
|
861
896
|
}
|
|
862
|
-
function modelPickerItemLines(option, selected, innerWidth) {
|
|
897
|
+
function modelPickerItemLines(option, selected, effort, innerWidth) {
|
|
863
898
|
const selectedStyle = selected ? { bgColor: MODEL_PICKER_HIGHLIGHT_BG } : {};
|
|
864
899
|
const labelStyle = option.disabled
|
|
865
900
|
? { color: 'gray' }
|
|
@@ -868,18 +903,19 @@ function modelPickerItemLines(option, selected, innerWidth) {
|
|
|
868
903
|
: {};
|
|
869
904
|
const cost = modelPickerCostText(option.costRating);
|
|
870
905
|
if (innerWidth < MODEL_PICKER_WIDE_MIN_WIDTH) {
|
|
871
|
-
const
|
|
906
|
+
const costWidth = 3;
|
|
907
|
+
const modelWidth = Math.max(12, innerWidth - costWidth - 2);
|
|
872
908
|
const row = [
|
|
873
|
-
...modelPickerModelSpans(option, selected, modelWidth, false, labelStyle, selectedStyle),
|
|
909
|
+
...modelPickerModelSpans(option, selected, effort, modelWidth, false, labelStyle, selectedStyle),
|
|
874
910
|
span(' ', selectedStyle),
|
|
875
|
-
modelPickerCell(cost,
|
|
911
|
+
modelPickerCell(cost, costWidth, selectedStyle),
|
|
876
912
|
];
|
|
877
913
|
return [
|
|
878
914
|
modelPickerPanelSideLine(line(...padSpansToInnerWidth(row, innerWidth, selectedStyle)), innerWidth),
|
|
879
915
|
];
|
|
880
916
|
}
|
|
881
917
|
const row = [
|
|
882
|
-
...modelPickerModelSpans(option, selected,
|
|
918
|
+
...modelPickerModelSpans(option, selected, effort, modelPickerModelWidth(innerWidth), true, labelStyle, selectedStyle),
|
|
883
919
|
span(MODEL_PICKER_SEPARATOR, { color: 'gray', ...selectedStyle }),
|
|
884
920
|
modelPickerCell(cost, MODEL_PICKER_COST_WIDTH, selectedStyle),
|
|
885
921
|
span(MODEL_PICKER_SEPARATOR, { color: 'gray', ...selectedStyle }),
|
|
@@ -895,15 +931,20 @@ function modelPickerItemLines(option, selected, innerWidth) {
|
|
|
895
931
|
function modelPickerHeaderLine(innerWidth) {
|
|
896
932
|
const heading = { color: MODEL_PICKER_ACCENT_COLOR, bold: true };
|
|
897
933
|
if (innerWidth < MODEL_PICKER_WIDE_MIN_WIDTH) {
|
|
898
|
-
return line(modelPickerCell('Model', Math.max(1, innerWidth), heading));
|
|
934
|
+
return line(modelPickerCell('Model · effort', Math.max(1, innerWidth), heading));
|
|
899
935
|
}
|
|
900
|
-
return line(modelPickerCell('Model',
|
|
936
|
+
return line(modelPickerCell('Model · effort', modelPickerModelWidth(innerWidth), heading), span(MODEL_PICKER_SEPARATOR, { color: 'gray' }), modelPickerCell('Cost', MODEL_PICKER_COST_WIDTH, heading), span(MODEL_PICKER_SEPARATOR, { color: 'gray' }), modelPickerCell('Notes', modelPickerNotesWidth(innerWidth), heading));
|
|
901
937
|
}
|
|
902
|
-
function buildModelPickerPanel(options, selectedIndex, width, availableHeight) {
|
|
938
|
+
function buildModelPickerPanel(options, selectedIndex, width, availableHeight, efforts = {}) {
|
|
903
939
|
const panelWidth = Math.max(28, Math.min(width, MODEL_PICKER_PANEL_MAX_WIDTH));
|
|
904
940
|
const innerWidth = Math.max(1, panelWidth - 4);
|
|
905
|
-
const
|
|
906
|
-
const
|
|
941
|
+
const showEffortDetails = options.length + 10 <= availableHeight;
|
|
942
|
+
const fixedLineCount = showEffortDetails ? 10 : 7;
|
|
943
|
+
const visibleCount = Math.min(options.length, Math.max(1, availableHeight - fixedLineCount));
|
|
944
|
+
const firstVisible = Math.max(0, Math.min(selectedIndex - visibleCount + 1, options.length - visibleCount));
|
|
945
|
+
const visibleOptions = options.slice(firstVisible, firstVisible + visibleCount);
|
|
946
|
+
const compactBodyLineCount = visibleOptions.length + fixedLineCount;
|
|
947
|
+
const spacerLineCount = Math.max(0, visibleOptions.length - 1);
|
|
907
948
|
const useRowSpacing = compactBodyLineCount + spacerLineCount <= availableHeight;
|
|
908
949
|
const bodyLineCount = compactBodyLineCount + (useRowSpacing ? spacerLineCount : 0);
|
|
909
950
|
const marginLineCount = Math.max(0, Math.min(MODEL_PICKER_PANEL_MARGIN_LINES, Math.floor((availableHeight - bodyLineCount) / 2)));
|
|
@@ -913,16 +954,26 @@ function buildModelPickerPanel(options, selectedIndex, width, availableHeight) {
|
|
|
913
954
|
modelPickerPanelSideLine(modelPickerHeaderLine(innerWidth), innerWidth),
|
|
914
955
|
modelPickerDivider(panelWidth),
|
|
915
956
|
];
|
|
916
|
-
|
|
917
|
-
body.push(...modelPickerItemLines(option, index === selectedIndex, innerWidth));
|
|
918
|
-
if (useRowSpacing && index <
|
|
957
|
+
visibleOptions.forEach((option, index) => {
|
|
958
|
+
body.push(...modelPickerItemLines(option, firstVisible + index === selectedIndex, projectModelEffort(efforts, option.publicId), innerWidth));
|
|
959
|
+
if (useRowSpacing && index < visibleOptions.length - 1) {
|
|
919
960
|
body.push(modelPickerPanelSideLine(plainLine(''), innerWidth));
|
|
920
961
|
}
|
|
921
962
|
});
|
|
922
|
-
const
|
|
923
|
-
const
|
|
963
|
+
const selectedEffort = projectModelEffort(efforts, options[selectedIndex]?.publicId ?? 0);
|
|
964
|
+
const effortChoices = REASONING_EFFORTS.map((effort) => effort === selectedEffort ? `[${REASONING_EFFORT_LABELS[effort]}]` : REASONING_EFFORT_LABELS[effort]).join(' ');
|
|
965
|
+
const fullEffort = `Reasoning effort: ${effortChoices}`;
|
|
966
|
+
const effortText = [...fullEffort].length <= innerWidth
|
|
967
|
+
? fullEffort
|
|
968
|
+
: `Effort: ${REASONING_EFFORT_LABELS[selectedEffort]} ←/→`;
|
|
969
|
+
const fullHint = '↑/↓ model • ←/→ effort • Enter select/save • Esc cancel';
|
|
970
|
+
const compactHint = '↑↓ · ←→ · Enter · Esc';
|
|
924
971
|
const hint = [...fullHint].length <= innerWidth ? fullHint : compactHint;
|
|
925
|
-
body.push(modelPickerDivider(panelWidth), modelPickerPanelSideLine(plainLine(fitLine(
|
|
972
|
+
body.push(modelPickerDivider(panelWidth), modelPickerPanelSideLine(plainLine(fitLine(effortText, innerWidth), { color: 'cyan', bold: true }), innerWidth), ...(showEffortDetails ? [
|
|
973
|
+
modelPickerPanelSideLine(plainLine(''), innerWidth),
|
|
974
|
+
modelPickerPanelSideLine(plainLine(fitLine(REASONING_EFFORT_DESCRIPTIONS[selectedEffort], innerWidth), { color: 'gray' }), innerWidth),
|
|
975
|
+
modelPickerPanelSideLine(plainLine(''), innerWidth),
|
|
976
|
+
] : []), modelPickerPanelSideLine(plainLine(fitLine(hint, innerWidth), { color: 'gray' }), innerWidth), plainLine(`╰${'─'.repeat(panelWidth - 2)}╯`, { color: MODEL_PICKER_BORDER_COLOR }));
|
|
926
977
|
return [...margin, ...body, ...margin];
|
|
927
978
|
}
|
|
928
979
|
const SHORTCUTS_PANEL_MAX_WIDTH = 96;
|
|
@@ -1243,7 +1294,7 @@ function buildOverlayLines(state, width, height, nowMs) {
|
|
|
1243
1294
|
}
|
|
1244
1295
|
if (state.modelPickerOpen) {
|
|
1245
1296
|
const options = buildModelPickerOptions(state.currentModelId, state.serverModels);
|
|
1246
|
-
lines.push(...buildModelPickerPanel(options, state.modelPickerIndex, width, height));
|
|
1297
|
+
lines.push(...buildModelPickerPanel(options, state.modelPickerIndex, width, height, state.modelPickerEfforts));
|
|
1247
1298
|
}
|
|
1248
1299
|
if (state.jobsPickerOpen) {
|
|
1249
1300
|
lines.push(...buildJobsPickerLines(state, width, height, nowMs));
|
|
@@ -1390,7 +1441,7 @@ export function buildTuiFrame(state, cols, rows, spinnerFrame, elapsedSeconds, n
|
|
|
1390
1441
|
}
|
|
1391
1442
|
const overlayHeight = state.userInputPrompt
|
|
1392
1443
|
? Math.max(0, rows - countSectionLines(sections))
|
|
1393
|
-
: state.jobsPickerOpen || state.shortcutsOpen
|
|
1444
|
+
: state.jobsPickerOpen || state.shortcutsOpen || state.modelPickerOpen
|
|
1394
1445
|
? Math.max(Math.min(rows, JOBS_PICKER_MIN_ROWS), rows - countSectionLines(sections))
|
|
1395
1446
|
: rows;
|
|
1396
1447
|
const overlayLines = buildOverlayLines(state, contentWidth, overlayHeight, nowMs);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { displayWidth, sliceToWidth } from './text.js';
|
|
2
|
+
export function fitModelLabel(label, width) {
|
|
3
|
+
if (width <= 0)
|
|
4
|
+
return '';
|
|
5
|
+
if (displayWidth(label) <= width)
|
|
6
|
+
return label;
|
|
7
|
+
const name = label.replace(/\s+\([^()]+\)$/, '');
|
|
8
|
+
if (displayWidth(name) <= width)
|
|
9
|
+
return name;
|
|
10
|
+
if (width === 1)
|
|
11
|
+
return '…';
|
|
12
|
+
return `${sliceToWidth(name, width - 1)}…`;
|
|
13
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { projectModelEffort } from '../../project-model-preferences.js';
|
|
2
|
+
import { cycleReasoningEffort } from '../../reasoning-effort.js';
|
|
1
3
|
import { shortcutsPanelAvailable } from './shortcuts.js';
|
|
2
4
|
import { moveComposerCursorVertically } from './composer-layout.js';
|
|
3
5
|
import { readClipboardImage, readClipboardText } from '../../core/clipboard.js';
|
|
@@ -370,6 +372,23 @@ export function handleShellKeyEvent(store, handlers, event) {
|
|
|
370
372
|
});
|
|
371
373
|
return;
|
|
372
374
|
}
|
|
375
|
+
if (key.leftArrow || key.rightArrow) {
|
|
376
|
+
store.update((current) => {
|
|
377
|
+
const options = buildModelPickerOptions(Number(current.currentModelId ?? 0), current.serverModels ?? []);
|
|
378
|
+
const model = options[current.modelPickerIndex];
|
|
379
|
+
if (!model)
|
|
380
|
+
return current;
|
|
381
|
+
const efforts = current.modelPickerEfforts ?? {};
|
|
382
|
+
return {
|
|
383
|
+
...current,
|
|
384
|
+
modelPickerEfforts: {
|
|
385
|
+
...efforts,
|
|
386
|
+
[String(model.publicId)]: cycleReasoningEffort(projectModelEffort(efforts, model.publicId), key.leftArrow ? -1 : 1),
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
});
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
373
392
|
if (key.returnKey) {
|
|
374
393
|
void handlers.onSelectModel();
|
|
375
394
|
}
|