mirror of
https://github.com/bendtherules/opencode-multi-model.git
synced 2026-08-18 13:42:21 +00:00
build: add biome formatter and linter
This commit is contained in:
+67
-14
@@ -136,7 +136,10 @@ export function createWindowPlans(models: string[]): WindowLaunchPlan[] {
|
||||
}
|
||||
|
||||
const suffix = `-${nextCount}`;
|
||||
const trimmedBase = baseName.slice(0, Math.max(1, WINDOW_NAME_LIMIT - suffix.length));
|
||||
const trimmedBase = baseName.slice(
|
||||
0,
|
||||
Math.max(1, WINDOW_NAME_LIMIT - suffix.length),
|
||||
);
|
||||
|
||||
return {
|
||||
model,
|
||||
@@ -194,7 +197,10 @@ export function levenshtein(left: string, right: string): number {
|
||||
* // ["openai/gpt-5.4", "openai/gpt-5.4-pro"]
|
||||
* ```
|
||||
*/
|
||||
export function suggestModels(requested: string, allowlist: string[]): string[] {
|
||||
export function suggestModels(
|
||||
requested: string,
|
||||
allowlist: string[],
|
||||
): string[] {
|
||||
const normalizedRequested = requested.toLowerCase();
|
||||
|
||||
return allowlist
|
||||
@@ -212,7 +218,11 @@ export function suggestModels(requested: string, allowlist: string[]): string[]
|
||||
score: distance + containsBoost,
|
||||
};
|
||||
})
|
||||
.sort((left, right) => left.score - right.score || left.candidate.localeCompare(right.candidate))
|
||||
.sort(
|
||||
(left, right) =>
|
||||
left.score - right.score ||
|
||||
left.candidate.localeCompare(right.candidate),
|
||||
)
|
||||
.slice(0, MAX_SUGGESTIONS)
|
||||
.map(({ candidate }) => candidate);
|
||||
}
|
||||
@@ -229,7 +239,10 @@ export function suggestModels(requested: string, allowlist: string[]): string[]
|
||||
* const message = formatInvalidModelError(["openai/gpt5.4"], ["openai/gpt-5.4"]);
|
||||
* ```
|
||||
*/
|
||||
export function formatInvalidModelError(invalidModels: string[], allowlist: string[]): string {
|
||||
export function formatInvalidModelError(
|
||||
invalidModels: string[],
|
||||
allowlist: string[],
|
||||
): string {
|
||||
const firstInvalidModel = invalidModels[0]!;
|
||||
const suggestions = suggestModels(firstInvalidModel, allowlist);
|
||||
const suggestionText =
|
||||
@@ -264,7 +277,14 @@ export async function launchModelInWindow(
|
||||
): Promise<CommandResult> {
|
||||
const launchCommand = `${binaryName} --model ${shellQuote(plan.model)}`;
|
||||
|
||||
return runCommand(["tmux", "send-keys", "-t", `${sessionName}:${plan.windowName}`, launchCommand, "C-m"]);
|
||||
return runCommand([
|
||||
"tmux",
|
||||
"send-keys",
|
||||
"-t",
|
||||
`${sessionName}:${plan.windowName}`,
|
||||
launchCommand,
|
||||
"C-m",
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,7 +300,10 @@ export async function launchModelInWindow(
|
||||
* ```
|
||||
*/
|
||||
export function sanitizeName(name: string): string {
|
||||
return name.replace(/[^a-zA-Z0-9_-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
||||
return name
|
||||
.replace(/[^a-zA-Z0-9_-]/g, "-")
|
||||
.replace(/-+/g, "-")
|
||||
.replace(/^-|-$/g, "");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -297,7 +320,14 @@ export function sanitizeName(name: string): string {
|
||||
*/
|
||||
export function getSessionPath(sessionName: string): string {
|
||||
const homedir = os.homedir();
|
||||
return path.join(homedir, ".local", "share", "opencode", "multi-model", sessionName);
|
||||
return path.join(
|
||||
homedir,
|
||||
".local",
|
||||
"share",
|
||||
"opencode",
|
||||
"multi-model",
|
||||
sessionName,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -313,7 +343,10 @@ export function getSessionPath(sessionName: string): string {
|
||||
* // "/home/user/.local/share/opencode/multi-model/my-session/gpt-5-2"
|
||||
* ```
|
||||
*/
|
||||
export function getWorktreePath(safeSession: string, windowName: string): string {
|
||||
export function getWorktreePath(
|
||||
safeSession: string,
|
||||
windowName: string,
|
||||
): string {
|
||||
return path.join(getSessionPath(safeSession), windowName);
|
||||
}
|
||||
|
||||
@@ -328,8 +361,15 @@ export function getWorktreePath(safeSession: string, windowName: string): string
|
||||
* const worktrees = await getWorktreesForSession("my-session");
|
||||
* ```
|
||||
*/
|
||||
export async function getWorktreesForSession(sessionName: string): Promise<WorktreeInfo[]> {
|
||||
const { stdout } = await runCommand(["git", "worktree", "list", "--porcelain"]);
|
||||
export async function getWorktreesForSession(
|
||||
sessionName: string,
|
||||
): Promise<WorktreeInfo[]> {
|
||||
const { stdout } = await runCommand([
|
||||
"git",
|
||||
"worktree",
|
||||
"list",
|
||||
"--porcelain",
|
||||
]);
|
||||
const worktrees: WorktreeInfo[] = [];
|
||||
|
||||
const sessionPath = getSessionPath(sanitizeName(sessionName));
|
||||
@@ -371,13 +411,26 @@ export async function getWorktreesForSession(sessionName: string): Promise<Workt
|
||||
* if (errors.length > 0) console.error(errors);
|
||||
* ```
|
||||
*/
|
||||
export async function undoWorktree(worktreePath: string, branchName: string): Promise<string[]> {
|
||||
export async function undoWorktree(
|
||||
worktreePath: string,
|
||||
branchName: string,
|
||||
): Promise<string[]> {
|
||||
const errors: string[] = [];
|
||||
const removeRes = await runCommand(["git", "worktree", "remove", "-f", worktreePath]);
|
||||
if (!removeRes.ok) errors.push(`Failed to remove worktree ${worktreePath}: ${removeRes.stderr}`);
|
||||
const removeRes = await runCommand([
|
||||
"git",
|
||||
"worktree",
|
||||
"remove",
|
||||
"-f",
|
||||
worktreePath,
|
||||
]);
|
||||
if (!removeRes.ok)
|
||||
errors.push(
|
||||
`Failed to remove worktree ${worktreePath}: ${removeRes.stderr}`,
|
||||
);
|
||||
|
||||
const branchRes = await runCommand(["git", "branch", "-D", branchName]);
|
||||
if (!branchRes.ok) errors.push(`Failed to delete branch ${branchName}: ${branchRes.stderr}`);
|
||||
if (!branchRes.ok)
|
||||
errors.push(`Failed to delete branch ${branchName}: ${branchRes.stderr}`);
|
||||
return errors;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user