mirror of
https://github.com/bendtherules/opencode-multi-model.git
synced 2026-08-18 13:42:21 +00:00
build: remember last models
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import * as fs from "node:fs";
|
||||
import * as os from "node:os";
|
||||
import * as path from "node:path";
|
||||
import * as readline from "node:readline";
|
||||
import ora, { type Ora } from "ora";
|
||||
import type {
|
||||
CommandResult,
|
||||
MultiModelSettings,
|
||||
RunCommandOptions,
|
||||
WindowLaunchPlan,
|
||||
WorktreeInfo,
|
||||
@@ -489,3 +492,49 @@ export async function undoWorktree(
|
||||
export function getBinaryName(): string {
|
||||
return process.env.OPENCODE_MULTI_MODEL_BINARY || "opencode";
|
||||
}
|
||||
|
||||
export function getSettingsPath(): string {
|
||||
const homedir = os.homedir();
|
||||
return path.join(homedir, ".config", "opencode-multi-model", "settings.json");
|
||||
}
|
||||
|
||||
export async function loadSettings(): Promise<MultiModelSettings> {
|
||||
const settingsPath = getSettingsPath();
|
||||
try {
|
||||
const content = await fs.promises.readFile(settingsPath, "utf-8");
|
||||
const parsed = JSON.parse(content) as MultiModelSettings;
|
||||
if (!Array.isArray(parsed.lastModels)) {
|
||||
return { lastModels: [] };
|
||||
}
|
||||
return parsed;
|
||||
} catch {
|
||||
return { lastModels: [] };
|
||||
}
|
||||
}
|
||||
|
||||
export async function saveSettings(
|
||||
settings: MultiModelSettings,
|
||||
): Promise<void> {
|
||||
const settingsPath = getSettingsPath();
|
||||
const dir = path.dirname(settingsPath);
|
||||
await fs.promises.mkdir(dir, { recursive: true });
|
||||
await fs.promises.writeFile(
|
||||
settingsPath,
|
||||
JSON.stringify(settings, null, 2),
|
||||
"utf-8",
|
||||
);
|
||||
}
|
||||
|
||||
export async function promptUser(question: string): Promise<string> {
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
});
|
||||
|
||||
return new Promise((resolve) => {
|
||||
rl.question(question, (answer) => {
|
||||
rl.close();
|
||||
resolve(answer);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user