@gajae-code/coding-agent 0.3.1 → 0.3.2
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/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/dist/types/cli/args.d.ts +2 -0
- package/dist/types/commands/launch.d.ts +6 -0
- package/dist/types/config/model-profile-activation.d.ts +30 -0
- package/dist/types/config/model-profiles.d.ts +19 -0
- package/dist/types/config/model-registry.d.ts +8 -0
- package/dist/types/config/model-resolver.d.ts +1 -1
- package/dist/types/config/models-config-schema.d.ts +47 -0
- package/dist/types/config/settings-schema.d.ts +10 -0
- package/dist/types/gjc-runtime/ultragoal-runtime.d.ts +2 -1
- package/dist/types/main.d.ts +10 -1
- package/dist/types/modes/components/custom-provider-wizard.d.ts +10 -0
- package/dist/types/modes/components/model-selector.d.ts +6 -1
- package/dist/types/modes/components/provider-onboarding-selector.d.ts +1 -1
- package/dist/types/modes/controllers/selector-controller.d.ts +1 -0
- package/dist/types/modes/types.d.ts +1 -0
- package/dist/types/sdk.d.ts +1 -1
- package/dist/types/task/executor.d.ts +1 -0
- package/dist/types/tools/hindsight-recall.d.ts +0 -2
- package/dist/types/tools/hindsight-reflect.d.ts +0 -2
- package/dist/types/tools/hindsight-retain.d.ts +0 -2
- package/dist/types/tools/index.d.ts +4 -4
- package/package.json +7 -7
- package/src/cli/args.ts +10 -0
- package/src/commands/launch.ts +8 -0
- package/src/config/model-profile-activation.ts +157 -0
- package/src/config/model-profiles.ts +155 -0
- package/src/config/model-registry.ts +19 -0
- package/src/config/model-resolver.ts +3 -2
- package/src/config/models-config-schema.ts +36 -0
- package/src/config/settings-schema.ts +10 -0
- package/src/defaults/gjc/skills/ultragoal/SKILL.md +11 -1
- package/src/defaults/gjc/skills/ultragoal/ai-slop-cleaner.md +61 -0
- package/src/defaults/gjc-defaults.ts +7 -0
- package/src/gjc-runtime/ultragoal-runtime.ts +119 -14
- package/src/internal-urls/docs-index.generated.ts +6 -9
- package/src/main.ts +67 -1
- package/src/modes/components/custom-provider-wizard.ts +318 -0
- package/src/modes/components/model-selector.ts +108 -18
- package/src/modes/components/provider-onboarding-selector.ts +6 -1
- package/src/modes/controllers/selector-controller.ts +57 -1
- package/src/modes/types.ts +1 -0
- package/src/prompts/memories/consolidation.md +1 -1
- package/src/prompts/memories/read-path.md +6 -7
- package/src/prompts/memories/unavailable.md +2 -2
- package/src/prompts/tools/bash.md +1 -1
- package/src/prompts/tools/irc.md +1 -1
- package/src/prompts/tools/read.md +2 -2
- package/src/prompts/tools/recall.md +1 -0
- package/src/prompts/tools/reflect.md +1 -0
- package/src/prompts/tools/retain.md +1 -0
- package/src/sdk.ts +1 -1
- package/src/slash-commands/builtin-registry.ts +1 -1
- package/src/task/executor.ts +2 -0
- package/src/task/index.ts +2 -0
- package/src/tools/hindsight-recall.ts +0 -2
- package/src/tools/hindsight-reflect.ts +0 -2
- package/src/tools/hindsight-retain.ts +0 -2
- package/src/tools/index.ts +4 -18
- package/src/tools/read.ts +3 -3
package/src/main.ts
CHANGED
|
@@ -26,6 +26,7 @@ import { buildInitialMessage } from "./cli/initial-message";
|
|
|
26
26
|
import { runListModelsCommand } from "./cli/list-models";
|
|
27
27
|
import { selectSession } from "./cli/session-picker";
|
|
28
28
|
import { findConfigFile } from "./config";
|
|
29
|
+
import { activateModelProfile } from "./config/model-profile-activation";
|
|
29
30
|
import { ModelRegistry, ModelsConfigFile } from "./config/model-registry";
|
|
30
31
|
import { resolveCliModel, resolveModelRoleValue, resolveModelScope, type ScopedModel } from "./config/model-resolver";
|
|
31
32
|
import { getDefault, type SettingPath, Settings, settings } from "./config/settings";
|
|
@@ -194,11 +195,59 @@ export interface AcpSessionFactoryOptions {
|
|
|
194
195
|
sessionDir?: string;
|
|
195
196
|
authStorage: AuthStorage;
|
|
196
197
|
modelRegistry: ModelRegistry;
|
|
197
|
-
parsedArgs: Pick<Args, "apiKey">;
|
|
198
|
+
parsedArgs: Pick<Args, "apiKey" | "default" | "model" | "mpreset" | "thinking">;
|
|
198
199
|
rawArgs: string[];
|
|
199
200
|
createSession: (options: CreateAgentSessionOptions) => Promise<CreateAgentSessionResult>;
|
|
200
201
|
}
|
|
201
202
|
|
|
203
|
+
export async function applyStartupModelProfiles(args: {
|
|
204
|
+
session: AgentSession;
|
|
205
|
+
settings: Settings;
|
|
206
|
+
modelRegistry: ModelRegistry;
|
|
207
|
+
parsedArgs: Pick<Args, "default" | "model" | "mpreset" | "thinking">;
|
|
208
|
+
startupModel?: CreateAgentSessionOptions["model"];
|
|
209
|
+
startupThinkingLevel?: CreateAgentSessionOptions["thinkingLevel"];
|
|
210
|
+
}): Promise<void> {
|
|
211
|
+
const applyProfile = async (profileName: string, persistDefault: boolean): Promise<void> => {
|
|
212
|
+
await activateModelProfile(
|
|
213
|
+
{ session: args.session, modelRegistry: args.modelRegistry, settings: args.settings, profileName },
|
|
214
|
+
{ persistDefault },
|
|
215
|
+
);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// Capture the explicitly-selected startup model BEFORE profile activation can
|
|
219
|
+
// override it. startupModel covers the eager path; session.model covers the
|
|
220
|
+
// deferred `--model <pattern>` path resolved inside createAgentSession.
|
|
221
|
+
const explicitModel = args.parsedArgs.model ? (args.startupModel ?? args.session.model) : undefined;
|
|
222
|
+
|
|
223
|
+
const defaultProfile = args.settings.get("modelProfile.default");
|
|
224
|
+
if (defaultProfile) {
|
|
225
|
+
await applyProfile(defaultProfile, false);
|
|
226
|
+
}
|
|
227
|
+
if (args.parsedArgs.mpreset) {
|
|
228
|
+
await applyProfile(args.parsedArgs.mpreset, args.parsedArgs.default === true);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Explicit CLI --model/--thinking must win over any activated profile.
|
|
232
|
+
if (explicitModel) {
|
|
233
|
+
await args.session.setModelTemporary(explicitModel, args.startupThinkingLevel ?? args.parsedArgs.thinking);
|
|
234
|
+
} else if (args.parsedArgs.thinking && args.session.model) {
|
|
235
|
+
await args.session.setModelTemporary(args.session.model, args.parsedArgs.thinking);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export async function applyStartupModelProfilesOrExit(
|
|
240
|
+
args: Parameters<typeof applyStartupModelProfiles>[0],
|
|
241
|
+
): Promise<void> {
|
|
242
|
+
try {
|
|
243
|
+
await applyStartupModelProfiles(args);
|
|
244
|
+
} catch (error) {
|
|
245
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
246
|
+
process.stderr.write(`${chalk.red(`Error: ${message}`)}\n`);
|
|
247
|
+
process.exit(1);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
202
251
|
/**
|
|
203
252
|
* Build the per-`session/new` factory used by ACP mode.
|
|
204
253
|
*
|
|
@@ -225,6 +274,14 @@ export function createAcpSessionFactory(args: AcpSessionFactoryOptions): AcpSess
|
|
|
225
274
|
hasUI: false,
|
|
226
275
|
enableMCP: false,
|
|
227
276
|
});
|
|
277
|
+
await applyStartupModelProfilesOrExit({
|
|
278
|
+
session: nextSession,
|
|
279
|
+
settings: nextSettings,
|
|
280
|
+
modelRegistry: args.modelRegistry,
|
|
281
|
+
parsedArgs: args.parsedArgs,
|
|
282
|
+
startupModel: args.baseOptions.model,
|
|
283
|
+
startupThinkingLevel: args.baseOptions.thinkingLevel,
|
|
284
|
+
});
|
|
228
285
|
if (args.parsedArgs.apiKey && !args.baseOptions.model && nextSession.model) {
|
|
229
286
|
args.authStorage.setRuntimeApiKey(nextSession.model.provider, args.parsedArgs.apiKey);
|
|
230
287
|
}
|
|
@@ -878,6 +935,15 @@ export async function runRootCommand(
|
|
|
878
935
|
authStorage.setRuntimeApiKey(session.model.provider, parsedArgs.apiKey);
|
|
879
936
|
}
|
|
880
937
|
|
|
938
|
+
await applyStartupModelProfilesOrExit({
|
|
939
|
+
session,
|
|
940
|
+
settings: settingsInstance,
|
|
941
|
+
modelRegistry,
|
|
942
|
+
parsedArgs,
|
|
943
|
+
startupModel: sessionOptions.model,
|
|
944
|
+
startupThinkingLevel: sessionOptions.thinkingLevel,
|
|
945
|
+
});
|
|
946
|
+
|
|
881
947
|
if (modelFallbackMessage) {
|
|
882
948
|
notifs.push({ kind: "warn", message: modelFallbackMessage });
|
|
883
949
|
}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { Container, Input, matchesKey, Spacer, Text, TruncatedText } from "@gajae-code/tui";
|
|
2
|
+
import type { ProviderCompatibility, ProviderSetupInput } from "../../setup/provider-onboarding";
|
|
3
|
+
import { theme } from "../theme/theme";
|
|
4
|
+
import { matchesAppInterrupt } from "../utils/keybinding-matchers";
|
|
5
|
+
import { DynamicBorder } from "./dynamic-border";
|
|
6
|
+
|
|
7
|
+
export type CustomProviderCredentialSource = "env" | "literal";
|
|
8
|
+
|
|
9
|
+
type WizardStep =
|
|
10
|
+
| "compatibility"
|
|
11
|
+
| "provider-id"
|
|
12
|
+
| "base-url"
|
|
13
|
+
| "credential-source"
|
|
14
|
+
| "credential"
|
|
15
|
+
| "models"
|
|
16
|
+
| "confirm"
|
|
17
|
+
| "force-confirm";
|
|
18
|
+
|
|
19
|
+
interface WizardState {
|
|
20
|
+
compatibility: ProviderCompatibility;
|
|
21
|
+
providerId: string;
|
|
22
|
+
baseUrl: string;
|
|
23
|
+
credentialSource: CustomProviderCredentialSource;
|
|
24
|
+
credential: string;
|
|
25
|
+
models: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type CustomProviderWizardSubmit = ProviderSetupInput;
|
|
29
|
+
|
|
30
|
+
export class CustomProviderWizardComponent extends Container {
|
|
31
|
+
#contentContainer: Container;
|
|
32
|
+
#input: Input | null = null;
|
|
33
|
+
#step: WizardStep = "compatibility";
|
|
34
|
+
#selectedIndex = 0;
|
|
35
|
+
#lastSubmitError: string | null = null;
|
|
36
|
+
#state: WizardState = {
|
|
37
|
+
compatibility: "openai",
|
|
38
|
+
providerId: "",
|
|
39
|
+
baseUrl: "",
|
|
40
|
+
credentialSource: "env",
|
|
41
|
+
credential: "",
|
|
42
|
+
models: "",
|
|
43
|
+
};
|
|
44
|
+
#onSubmit: (input: CustomProviderWizardSubmit) => void;
|
|
45
|
+
#onCancel: () => void;
|
|
46
|
+
#onRender: () => void;
|
|
47
|
+
|
|
48
|
+
constructor(
|
|
49
|
+
onSubmit: (input: CustomProviderWizardSubmit) => void,
|
|
50
|
+
onCancel: () => void,
|
|
51
|
+
onRender: () => void = () => {},
|
|
52
|
+
) {
|
|
53
|
+
super();
|
|
54
|
+
this.#onSubmit = onSubmit;
|
|
55
|
+
this.#onCancel = onCancel;
|
|
56
|
+
this.#onRender = onRender;
|
|
57
|
+
|
|
58
|
+
this.addChild(new DynamicBorder());
|
|
59
|
+
this.addChild(new Spacer(1));
|
|
60
|
+
this.addChild(new TruncatedText(theme.bold("Add custom provider")));
|
|
61
|
+
this.addChild(
|
|
62
|
+
new TruncatedText(theme.fg("muted", " Configure an OpenAI- or Anthropic-compatible API provider."), 0, 0),
|
|
63
|
+
);
|
|
64
|
+
this.addChild(new Spacer(1));
|
|
65
|
+
this.#contentContainer = new Container();
|
|
66
|
+
this.addChild(this.#contentContainer);
|
|
67
|
+
this.addChild(new Spacer(1));
|
|
68
|
+
this.addChild(new DynamicBorder());
|
|
69
|
+
this.#renderStep();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
setSubmitError(error: string): void {
|
|
73
|
+
this.#lastSubmitError = error;
|
|
74
|
+
if (error.includes("already exists")) {
|
|
75
|
+
this.#step = "force-confirm";
|
|
76
|
+
this.#selectedIndex = 1;
|
|
77
|
+
}
|
|
78
|
+
this.#renderStep();
|
|
79
|
+
this.#onRender();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
handleInput(keyData: string): void {
|
|
83
|
+
if (matchesAppInterrupt(keyData)) {
|
|
84
|
+
if (this.#step === "compatibility") {
|
|
85
|
+
this.#onCancel();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
this.#goBack();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (this.#input) {
|
|
93
|
+
if (matchesKey(keyData, "enter") || matchesKey(keyData, "return") || keyData === "\n") {
|
|
94
|
+
this.#saveInputAndProceed();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this.#input.handleInput(keyData);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (matchesKey(keyData, "up")) {
|
|
102
|
+
this.#moveSelection(-1);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (matchesKey(keyData, "down")) {
|
|
106
|
+
this.#moveSelection(1);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (matchesKey(keyData, "enter") || matchesKey(keyData, "return") || keyData === "\n") {
|
|
110
|
+
this.#selectCurrentOption();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
#renderStep(): void {
|
|
115
|
+
this.#contentContainer.clear();
|
|
116
|
+
this.#input = null;
|
|
117
|
+
switch (this.#step) {
|
|
118
|
+
case "compatibility":
|
|
119
|
+
this.#renderCompatibilityStep();
|
|
120
|
+
break;
|
|
121
|
+
case "provider-id":
|
|
122
|
+
this.#renderInputStep(
|
|
123
|
+
"Step 2: Provider id",
|
|
124
|
+
"Enter a provider id:",
|
|
125
|
+
this.#state.providerId,
|
|
126
|
+
"e.g. my-openai-proxy",
|
|
127
|
+
);
|
|
128
|
+
break;
|
|
129
|
+
case "base-url":
|
|
130
|
+
this.#renderInputStep(
|
|
131
|
+
"Step 3: Base URL",
|
|
132
|
+
"Enter the API base URL:",
|
|
133
|
+
this.#state.baseUrl,
|
|
134
|
+
"e.g. https://api.example.com/v1",
|
|
135
|
+
);
|
|
136
|
+
break;
|
|
137
|
+
case "credential-source":
|
|
138
|
+
this.#renderCredentialSourceStep();
|
|
139
|
+
break;
|
|
140
|
+
case "credential":
|
|
141
|
+
this.#renderInputStep(
|
|
142
|
+
"Step 5: Credential",
|
|
143
|
+
this.#state.credentialSource === "env"
|
|
144
|
+
? "Enter the API key environment variable name:"
|
|
145
|
+
: "Paste the API key:",
|
|
146
|
+
this.#state.credential,
|
|
147
|
+
this.#state.credentialSource === "env"
|
|
148
|
+
? "e.g. OPENAI_API_KEY"
|
|
149
|
+
: "The key will be stored in models.yml and redacted in output.",
|
|
150
|
+
);
|
|
151
|
+
break;
|
|
152
|
+
case "models":
|
|
153
|
+
this.#renderInputStep(
|
|
154
|
+
"Step 6: Model id(s)",
|
|
155
|
+
"Enter model ids, comma-separated:",
|
|
156
|
+
this.#state.models,
|
|
157
|
+
"e.g. gpt-5, claude-sonnet-4-5",
|
|
158
|
+
);
|
|
159
|
+
break;
|
|
160
|
+
case "confirm":
|
|
161
|
+
this.#renderConfirmStep(false);
|
|
162
|
+
break;
|
|
163
|
+
case "force-confirm":
|
|
164
|
+
this.#renderConfirmStep(true);
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
#renderCompatibilityStep(): void {
|
|
170
|
+
this.#contentContainer.addChild(new Text(theme.fg("accent", "Step 1: Compatibility")));
|
|
171
|
+
this.#contentContainer.addChild(new Spacer(1));
|
|
172
|
+
const options: Array<{ value: ProviderCompatibility; label: string }> = [
|
|
173
|
+
{ value: "openai", label: "OpenAI-compatible" },
|
|
174
|
+
{ value: "anthropic", label: "Anthropic-compatible" },
|
|
175
|
+
];
|
|
176
|
+
for (let i = 0; i < options.length; i++) this.#addOption(i, options[i]?.label ?? "");
|
|
177
|
+
this.#addHelp("[↑↓ to navigate, Enter to select, Esc to cancel]");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
#renderCredentialSourceStep(): void {
|
|
181
|
+
this.#contentContainer.addChild(new Text(theme.fg("accent", "Step 4: Credential source")));
|
|
182
|
+
this.#contentContainer.addChild(new Spacer(1));
|
|
183
|
+
this.#addOption(0, "Environment variable");
|
|
184
|
+
this.#addOption(1, "Paste API key");
|
|
185
|
+
this.#addHelp("[↑↓ to navigate, Enter to select, Esc to go back]");
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
#renderInputStep(title: string, prompt: string, value: string, hint: string): void {
|
|
189
|
+
this.#contentContainer.addChild(new Text(theme.fg("accent", title)));
|
|
190
|
+
this.#contentContainer.addChild(new Spacer(1));
|
|
191
|
+
this.#contentContainer.addChild(new Text(prompt, 0, 0));
|
|
192
|
+
this.#contentContainer.addChild(new Spacer(1));
|
|
193
|
+
this.#input = new Input();
|
|
194
|
+
this.#input.setValue(value);
|
|
195
|
+
this.#contentContainer.addChild(this.#input);
|
|
196
|
+
this.#contentContainer.addChild(new Spacer(1));
|
|
197
|
+
this.#addHelp(hint);
|
|
198
|
+
this.#addHelp("[Enter to continue, Esc to go back]");
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
#renderConfirmStep(force: boolean): void {
|
|
202
|
+
this.#contentContainer.addChild(
|
|
203
|
+
new Text(theme.fg("accent", force ? "Provider exists — replace it?" : "Confirm custom provider")),
|
|
204
|
+
);
|
|
205
|
+
this.#contentContainer.addChild(new Spacer(1));
|
|
206
|
+
if (this.#lastSubmitError) {
|
|
207
|
+
this.#contentContainer.addChild(new Text(theme.fg(force ? "warning" : "error", this.#lastSubmitError), 0, 0));
|
|
208
|
+
this.#contentContainer.addChild(new Spacer(1));
|
|
209
|
+
}
|
|
210
|
+
this.#contentContainer.addChild(new Text(`Compatibility: ${this.#state.compatibility}`, 0, 0));
|
|
211
|
+
this.#contentContainer.addChild(new Text(`Provider: ${this.#state.providerId}`, 0, 0));
|
|
212
|
+
this.#contentContainer.addChild(new Text(`Base URL: ${this.#state.baseUrl}`, 0, 0));
|
|
213
|
+
this.#contentContainer.addChild(
|
|
214
|
+
new Text(
|
|
215
|
+
`Credential: ${this.#state.credentialSource === "env" ? this.#state.credential : "pasted API key"}`,
|
|
216
|
+
0,
|
|
217
|
+
0,
|
|
218
|
+
),
|
|
219
|
+
);
|
|
220
|
+
this.#contentContainer.addChild(new Text(`Models: ${this.#state.models}`, 0, 0));
|
|
221
|
+
this.#contentContainer.addChild(new Spacer(1));
|
|
222
|
+
this.#addOption(0, force ? "Replace existing provider" : "Add provider");
|
|
223
|
+
this.#addOption(1, "Go back");
|
|
224
|
+
this.#addHelp("[↑↓ to navigate, Enter to select, Esc to go back]");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
#addOption(index: number, label: string): void {
|
|
228
|
+
const selected = index === this.#selectedIndex;
|
|
229
|
+
const prefix = selected ? theme.fg("accent", `${theme.nav.cursor} `) : " ";
|
|
230
|
+
this.#contentContainer.addChild(new Text(`${prefix}${selected ? theme.fg("accent", label) : label}`, 0, 0));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
#addHelp(text: string): void {
|
|
234
|
+
this.#contentContainer.addChild(new Text(theme.fg("muted", text), 0, 0));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
#saveInputAndProceed(): void {
|
|
238
|
+
const value = this.#input?.getValue().trim() ?? "";
|
|
239
|
+
if (!value) return;
|
|
240
|
+
if (this.#step === "provider-id") {
|
|
241
|
+
this.#state.providerId = value;
|
|
242
|
+
this.#step = "base-url";
|
|
243
|
+
} else if (this.#step === "base-url") {
|
|
244
|
+
this.#state.baseUrl = value;
|
|
245
|
+
this.#step = "credential-source";
|
|
246
|
+
this.#selectedIndex = 0;
|
|
247
|
+
} else if (this.#step === "credential") {
|
|
248
|
+
this.#state.credential = value;
|
|
249
|
+
this.#step = "models";
|
|
250
|
+
} else if (this.#step === "models") {
|
|
251
|
+
this.#state.models = value;
|
|
252
|
+
this.#step = "confirm";
|
|
253
|
+
this.#selectedIndex = 0;
|
|
254
|
+
this.#lastSubmitError = null;
|
|
255
|
+
}
|
|
256
|
+
this.#renderStep();
|
|
257
|
+
this.#onRender();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
#selectCurrentOption(): void {
|
|
261
|
+
if (this.#step === "compatibility") {
|
|
262
|
+
this.#state.compatibility = this.#selectedIndex === 0 ? "openai" : "anthropic";
|
|
263
|
+
this.#step = "provider-id";
|
|
264
|
+
} else if (this.#step === "credential-source") {
|
|
265
|
+
this.#state.credentialSource = this.#selectedIndex === 0 ? "env" : "literal";
|
|
266
|
+
this.#state.credential = "";
|
|
267
|
+
this.#step = "credential";
|
|
268
|
+
} else if (this.#step === "confirm" || this.#step === "force-confirm") {
|
|
269
|
+
if (this.#selectedIndex === 0) {
|
|
270
|
+
this.#onSubmit(this.#buildInput(this.#step === "force-confirm"));
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
this.#step = "models";
|
|
274
|
+
}
|
|
275
|
+
this.#renderStep();
|
|
276
|
+
this.#onRender();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
#buildInput(force: boolean): CustomProviderWizardSubmit {
|
|
280
|
+
return {
|
|
281
|
+
compatibility: this.#state.compatibility,
|
|
282
|
+
providerId: this.#state.providerId,
|
|
283
|
+
baseUrl: this.#state.baseUrl,
|
|
284
|
+
apiKeyEnv: this.#state.credentialSource === "env" ? this.#state.credential : undefined,
|
|
285
|
+
apiKey: this.#state.credentialSource === "literal" ? this.#state.credential : undefined,
|
|
286
|
+
models: this.#state.models
|
|
287
|
+
.split(",")
|
|
288
|
+
.map(model => model.trim())
|
|
289
|
+
.filter(Boolean),
|
|
290
|
+
force,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
#moveSelection(delta: number): void {
|
|
295
|
+
const maxIndex =
|
|
296
|
+
this.#step === "confirm" ||
|
|
297
|
+
this.#step === "force-confirm" ||
|
|
298
|
+
this.#step === "compatibility" ||
|
|
299
|
+
this.#step === "credential-source"
|
|
300
|
+
? 1
|
|
301
|
+
: 0;
|
|
302
|
+
this.#selectedIndex = (this.#selectedIndex + delta + maxIndex + 1) % (maxIndex + 1);
|
|
303
|
+
this.#renderStep();
|
|
304
|
+
this.#onRender();
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
#goBack(): void {
|
|
308
|
+
if (this.#step === "provider-id") this.#step = "compatibility";
|
|
309
|
+
else if (this.#step === "base-url") this.#step = "provider-id";
|
|
310
|
+
else if (this.#step === "credential-source") this.#step = "base-url";
|
|
311
|
+
else if (this.#step === "credential") this.#step = "credential-source";
|
|
312
|
+
else if (this.#step === "models") this.#step = "credential";
|
|
313
|
+
else if (this.#step === "confirm" || this.#step === "force-confirm") this.#step = "models";
|
|
314
|
+
this.#selectedIndex = 0;
|
|
315
|
+
this.#renderStep();
|
|
316
|
+
this.#onRender();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
Text,
|
|
13
13
|
type TUI,
|
|
14
14
|
} from "@gajae-code/tui";
|
|
15
|
+
import type { ModelProfileDefinition } from "../../config/model-profiles";
|
|
15
16
|
import type { GjcModelAssignmentTargetId, ModelRegistry } from "../../config/model-registry";
|
|
16
17
|
import { GJC_MODEL_ASSIGNMENT_TARGET_IDS, GJC_MODEL_ASSIGNMENT_TARGETS } from "../../config/model-registry";
|
|
17
18
|
import {
|
|
@@ -74,6 +75,12 @@ interface CanonicalModelItem {
|
|
|
74
75
|
explicitThinkingLevel?: boolean;
|
|
75
76
|
}
|
|
76
77
|
|
|
78
|
+
interface ProfileItem {
|
|
79
|
+
kind: "profile";
|
|
80
|
+
name: string;
|
|
81
|
+
profile: ModelProfileDefinition;
|
|
82
|
+
}
|
|
83
|
+
|
|
77
84
|
type ScopedModelItem = ScopedModelSelection;
|
|
78
85
|
|
|
79
86
|
interface RoleAssignment {
|
|
@@ -102,6 +109,11 @@ export type ModelSelectorSelection =
|
|
|
102
109
|
selector: string;
|
|
103
110
|
preset: ModelAssignmentPreset;
|
|
104
111
|
assignments: Record<GjcModelAssignmentTargetId, ThinkingLevel>;
|
|
112
|
+
}
|
|
113
|
+
| {
|
|
114
|
+
kind: "profile";
|
|
115
|
+
profileName: string;
|
|
116
|
+
setDefault: boolean;
|
|
105
117
|
};
|
|
106
118
|
|
|
107
119
|
interface PendingThinkingChoice {
|
|
@@ -110,7 +122,7 @@ interface PendingThinkingChoice {
|
|
|
110
122
|
levels: ThinkingLevel[];
|
|
111
123
|
}
|
|
112
124
|
|
|
113
|
-
type RoleSelectCallback = (selection: ModelSelectorSelection) => void
|
|
125
|
+
type RoleSelectCallback = (selection: ModelSelectorSelection) => void | Promise<void>;
|
|
114
126
|
type CancelCallback = () => void;
|
|
115
127
|
|
|
116
128
|
interface ProviderTabState {
|
|
@@ -161,6 +173,7 @@ export class ModelSelectorComponent extends Container {
|
|
|
161
173
|
#filteredModels: ModelItem[] = [];
|
|
162
174
|
#canonicalModels: CanonicalModelItem[] = [];
|
|
163
175
|
#filteredCanonicalModels: CanonicalModelItem[] = [];
|
|
176
|
+
#profileItems: ProfileItem[] = [];
|
|
164
177
|
#selectedIndex: number = 0;
|
|
165
178
|
#roles = {} as Record<string, RoleAssignment | undefined>;
|
|
166
179
|
#settings = null as unknown as Settings;
|
|
@@ -228,7 +241,11 @@ export class ModelSelectorComponent extends Container {
|
|
|
228
241
|
this.#searchInput.onSubmit = () => {
|
|
229
242
|
const selectedItem = this.#getSelectedItem();
|
|
230
243
|
if (selectedItem) {
|
|
231
|
-
|
|
244
|
+
if (selectedItem.kind === "profile") {
|
|
245
|
+
this.#beginProfileActionMenu(selectedItem);
|
|
246
|
+
} else {
|
|
247
|
+
this.#beginActionMenuOrSelect(selectedItem);
|
|
248
|
+
}
|
|
232
249
|
}
|
|
233
250
|
};
|
|
234
251
|
this.addChild(this.#searchInput);
|
|
@@ -465,11 +482,18 @@ export class ModelSelectorComponent extends Container {
|
|
|
465
482
|
|
|
466
483
|
this.#sortModels(models);
|
|
467
484
|
this.#sortCanonicalModels(canonicalModels);
|
|
485
|
+
const profiles = this.#modelRegistry.getModelProfiles?.() ?? new Map();
|
|
486
|
+
const profileItems = this.#temporaryOnly
|
|
487
|
+
? []
|
|
488
|
+
: [...profiles.values()]
|
|
489
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
490
|
+
.map(profile => ({ kind: "profile" as const, name: profile.name, profile }));
|
|
468
491
|
|
|
469
492
|
this.#allModels = models;
|
|
470
493
|
this.#filteredModels = models;
|
|
471
494
|
this.#canonicalModels = canonicalModels;
|
|
472
495
|
this.#filteredCanonicalModels = canonicalModels;
|
|
496
|
+
this.#profileItems = profileItems;
|
|
473
497
|
this.#selectedIndex = Math.min(this.#selectedIndex, Math.max(0, models.length - 1));
|
|
474
498
|
}
|
|
475
499
|
|
|
@@ -664,20 +688,40 @@ export class ModelSelectorComponent extends Container {
|
|
|
664
688
|
}
|
|
665
689
|
}
|
|
666
690
|
|
|
691
|
+
#getVisibleProfiles(): ProfileItem[] {
|
|
692
|
+
return !this.#temporaryOnly && !this.#isCanonicalTab() && this.#getActiveTabId() === ALL_TAB
|
|
693
|
+
? this.#profileItems
|
|
694
|
+
: [];
|
|
695
|
+
}
|
|
696
|
+
|
|
667
697
|
#updateList(): void {
|
|
668
698
|
this.#listContainer.clear();
|
|
669
699
|
const isCanonicalTab = this.#isCanonicalTab();
|
|
700
|
+
const visibleProfiles = this.#getVisibleProfiles();
|
|
701
|
+
const modelSelectedIndex = Math.max(0, this.#selectedIndex - visibleProfiles.length);
|
|
670
702
|
const visibleItems = isCanonicalTab ? this.#filteredCanonicalModels : this.#filteredModels;
|
|
671
703
|
|
|
672
704
|
const maxVisible = 10;
|
|
673
705
|
const startIndex = Math.max(
|
|
674
706
|
0,
|
|
675
|
-
Math.min(
|
|
707
|
+
Math.min(modelSelectedIndex - Math.floor(maxVisible / 2), visibleItems.length - maxVisible),
|
|
676
708
|
);
|
|
677
709
|
const endIndex = Math.min(startIndex + maxVisible, visibleItems.length);
|
|
678
710
|
|
|
679
711
|
const showProvider = this.#getActiveTabId() === ALL_TAB;
|
|
680
712
|
|
|
713
|
+
if (visibleProfiles.length > 0) {
|
|
714
|
+
this.#listContainer.addChild(new Text(theme.fg("muted", "Profiles"), 0, 0));
|
|
715
|
+
for (let i = 0; i < visibleProfiles.length; i++) {
|
|
716
|
+
const profile = visibleProfiles[i];
|
|
717
|
+
if (!profile) continue;
|
|
718
|
+
const isSelected = i === this.#selectedIndex;
|
|
719
|
+
const prefix = isSelected ? theme.fg("accent", `${theme.nav.cursor} `) : " ";
|
|
720
|
+
const label = isSelected ? theme.fg("accent", profile.name) : profile.name;
|
|
721
|
+
this.#listContainer.addChild(new Text(`${prefix}${label}`, 0, 0));
|
|
722
|
+
}
|
|
723
|
+
this.#listContainer.addChild(new Spacer(1));
|
|
724
|
+
}
|
|
681
725
|
// Show visible slice of filtered models
|
|
682
726
|
for (let i = startIndex; i < endIndex; i++) {
|
|
683
727
|
const item = visibleItems[i];
|
|
@@ -685,7 +729,7 @@ export class ModelSelectorComponent extends Container {
|
|
|
685
729
|
const canonicalItem = isCanonicalTab ? (item as CanonicalModelItem) : undefined;
|
|
686
730
|
const providerItem = isCanonicalTab ? undefined : (item as ModelItem);
|
|
687
731
|
|
|
688
|
-
const isSelected = i === this.#selectedIndex;
|
|
732
|
+
const isSelected = i + visibleProfiles.length === this.#selectedIndex;
|
|
689
733
|
|
|
690
734
|
// Build role badges (inverted: color as background, black text)
|
|
691
735
|
const roleBadgeTokens: string[] = [];
|
|
@@ -742,7 +786,7 @@ export class ModelSelectorComponent extends Container {
|
|
|
742
786
|
for (const line of errorLines) {
|
|
743
787
|
this.#listContainer.addChild(new Text(theme.fg("error", line), 0, 0));
|
|
744
788
|
}
|
|
745
|
-
} else if (visibleItems.length === 0) {
|
|
789
|
+
} else if (visibleItems.length === 0 && visibleProfiles.length === 0) {
|
|
746
790
|
const statusMessage = this.#getProviderEmptyStateMessage();
|
|
747
791
|
this.#listContainer.addChild(
|
|
748
792
|
new Text(
|
|
@@ -751,8 +795,13 @@ export class ModelSelectorComponent extends Container {
|
|
|
751
795
|
0,
|
|
752
796
|
),
|
|
753
797
|
);
|
|
798
|
+
} else if (this.#selectedIndex < visibleProfiles.length) {
|
|
799
|
+
const selectedProfile = visibleProfiles[this.#selectedIndex];
|
|
800
|
+
if (selectedProfile && this.#pendingActionItem) {
|
|
801
|
+
this.#renderProfileActionMenu(selectedProfile);
|
|
802
|
+
}
|
|
754
803
|
} else {
|
|
755
|
-
const selected = visibleItems[
|
|
804
|
+
const selected = visibleItems[modelSelectedIndex];
|
|
756
805
|
if (!selected) {
|
|
757
806
|
return;
|
|
758
807
|
}
|
|
@@ -806,6 +855,20 @@ export class ModelSelectorComponent extends Container {
|
|
|
806
855
|
}
|
|
807
856
|
}
|
|
808
857
|
|
|
858
|
+
#renderProfileActionMenu(profile: ProfileItem): void {
|
|
859
|
+
this.#listContainer.addChild(new Spacer(1));
|
|
860
|
+
this.#listContainer.addChild(new Text(theme.fg("muted", ` Action for profile: ${profile.name}`), 0, 0));
|
|
861
|
+
this.#listContainer.addChild(new Spacer(1));
|
|
862
|
+
const labels = ["Apply for this session", "Set as default"];
|
|
863
|
+
for (let i = 0; i < labels.length; i++) {
|
|
864
|
+
const label = labels[i] ?? "";
|
|
865
|
+
const prefix = i === this.#selectedActionIndex ? theme.fg("accent", `${theme.nav.cursor} `) : " ";
|
|
866
|
+
this.#listContainer.addChild(
|
|
867
|
+
new Text(`${prefix}${i === this.#selectedActionIndex ? theme.fg("accent", label) : label}`, 0, 0),
|
|
868
|
+
);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
|
|
809
872
|
#getCurrentRoleThinkingLevel(role: string): ThinkingLevel {
|
|
810
873
|
return this.#roles[role]?.thinkingLevel ?? ThinkingLevel.Inherit;
|
|
811
874
|
}
|
|
@@ -813,10 +876,11 @@ export class ModelSelectorComponent extends Container {
|
|
|
813
876
|
return GJC_MODEL_ASSIGNMENT_TARGET_IDS.length + (supportsOpenAICodexPreset(model) ? 1 : 0);
|
|
814
877
|
}
|
|
815
878
|
|
|
816
|
-
#getSelectedItem(): ModelItem | CanonicalModelItem | undefined {
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
879
|
+
#getSelectedItem(): ModelItem | CanonicalModelItem | ProfileItem | undefined {
|
|
880
|
+
const visibleProfiles = this.#getVisibleProfiles();
|
|
881
|
+
if (this.#selectedIndex < visibleProfiles.length) return visibleProfiles[this.#selectedIndex];
|
|
882
|
+
const modelIndex = this.#selectedIndex - visibleProfiles.length;
|
|
883
|
+
return this.#isCanonicalTab() ? this.#filteredCanonicalModels[modelIndex] : this.#filteredModels[modelIndex];
|
|
820
884
|
}
|
|
821
885
|
|
|
822
886
|
handleInput(keyData: string): void {
|
|
@@ -836,7 +900,9 @@ export class ModelSelectorComponent extends Container {
|
|
|
836
900
|
|
|
837
901
|
// Up arrow - navigate list (wrap to bottom when at top)
|
|
838
902
|
if (matchesKey(keyData, "up")) {
|
|
839
|
-
const itemCount =
|
|
903
|
+
const itemCount =
|
|
904
|
+
this.#getVisibleProfiles().length +
|
|
905
|
+
(this.#isCanonicalTab() ? this.#filteredCanonicalModels.length : this.#filteredModels.length);
|
|
840
906
|
if (itemCount === 0) return;
|
|
841
907
|
this.#selectedIndex = this.#selectedIndex === 0 ? itemCount - 1 : this.#selectedIndex - 1;
|
|
842
908
|
this.#updateList();
|
|
@@ -845,7 +911,9 @@ export class ModelSelectorComponent extends Container {
|
|
|
845
911
|
|
|
846
912
|
// Down arrow - navigate list (wrap to top when at bottom)
|
|
847
913
|
if (matchesKey(keyData, "down")) {
|
|
848
|
-
const itemCount =
|
|
914
|
+
const itemCount =
|
|
915
|
+
this.#getVisibleProfiles().length +
|
|
916
|
+
(this.#isCanonicalTab() ? this.#filteredCanonicalModels.length : this.#filteredModels.length);
|
|
849
917
|
if (itemCount === 0) return;
|
|
850
918
|
this.#selectedIndex = this.#selectedIndex === itemCount - 1 ? 0 : this.#selectedIndex + 1;
|
|
851
919
|
this.#updateList();
|
|
@@ -857,7 +925,11 @@ export class ModelSelectorComponent extends Container {
|
|
|
857
925
|
if (matchesKey(keyData, "enter") || matchesKey(keyData, "return") || keyData === "\n") {
|
|
858
926
|
const selectedItem = this.#getSelectedItem();
|
|
859
927
|
if (selectedItem) {
|
|
860
|
-
|
|
928
|
+
if (selectedItem.kind === "profile") {
|
|
929
|
+
this.#beginProfileActionMenu(selectedItem);
|
|
930
|
+
} else {
|
|
931
|
+
this.#beginActionMenuOrSelect(selectedItem);
|
|
932
|
+
}
|
|
861
933
|
}
|
|
862
934
|
return;
|
|
863
935
|
}
|
|
@@ -872,6 +944,12 @@ export class ModelSelectorComponent extends Container {
|
|
|
872
944
|
this.#searchInput.handleInput(keyData);
|
|
873
945
|
this.#filterModels(this.#searchInput.getValue());
|
|
874
946
|
}
|
|
947
|
+
#beginProfileActionMenu(profile: ProfileItem): void {
|
|
948
|
+
this.#pendingActionItem = profile as unknown as ModelItem;
|
|
949
|
+
this.#selectedActionIndex = 0;
|
|
950
|
+
this.#updateList();
|
|
951
|
+
}
|
|
952
|
+
|
|
875
953
|
#beginActionMenuOrSelect(item: ModelItem | CanonicalModelItem): void {
|
|
876
954
|
if (this.#temporaryOnly) {
|
|
877
955
|
this.#handleSelect(item, null);
|
|
@@ -885,7 +963,7 @@ export class ModelSelectorComponent extends Container {
|
|
|
885
963
|
#handleActionMenuInput(keyData: string): void {
|
|
886
964
|
const item = this.#pendingActionItem;
|
|
887
965
|
if (!item) return;
|
|
888
|
-
const actionCount = this.#getActionCount(item.model);
|
|
966
|
+
const actionCount = (item as unknown as ProfileItem).kind === "profile" ? 2 : this.#getActionCount(item.model);
|
|
889
967
|
if (matchesKey(keyData, "up")) {
|
|
890
968
|
this.#selectedActionIndex = this.#selectedActionIndex === 0 ? actionCount - 1 : this.#selectedActionIndex - 1;
|
|
891
969
|
this.#updateList();
|
|
@@ -898,11 +976,20 @@ export class ModelSelectorComponent extends Container {
|
|
|
898
976
|
}
|
|
899
977
|
if (matchesKey(keyData, "enter") || matchesKey(keyData, "return") || keyData === "\n") {
|
|
900
978
|
this.#pendingActionItem = undefined;
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
this.#
|
|
979
|
+
if ((item as unknown as ProfileItem).kind === "profile") {
|
|
980
|
+
const profile = item as unknown as ProfileItem;
|
|
981
|
+
this.#onSelectCallback({
|
|
982
|
+
kind: "profile",
|
|
983
|
+
profileName: profile.name,
|
|
984
|
+
setDefault: this.#selectedActionIndex === 1,
|
|
985
|
+
});
|
|
904
986
|
} else {
|
|
905
|
-
this.#
|
|
987
|
+
const role = GJC_MODEL_ASSIGNMENT_TARGET_IDS[this.#selectedActionIndex];
|
|
988
|
+
if (role) {
|
|
989
|
+
this.#handleSelect(item, role);
|
|
990
|
+
} else {
|
|
991
|
+
this.#handlePresetSelect(item, OPENAI_CODE_PROFILE_PRESET);
|
|
992
|
+
}
|
|
906
993
|
}
|
|
907
994
|
return;
|
|
908
995
|
}
|
|
@@ -1004,6 +1091,9 @@ export class ModelSelectorComponent extends Container {
|
|
|
1004
1091
|
getSearchInput(): Input {
|
|
1005
1092
|
return this.#searchInput;
|
|
1006
1093
|
}
|
|
1094
|
+
async __testSelectProfile(profileName: string, setDefault: boolean): Promise<void> {
|
|
1095
|
+
await this.#onSelectCallback({ kind: "profile", profileName, setDefault });
|
|
1096
|
+
}
|
|
1007
1097
|
}
|
|
1008
1098
|
|
|
1009
1099
|
function requiresExplicitThinkingChoice(model: Model): boolean {
|