Compare commits

..
7 Commits
Author SHA1 Message Date
bendtherules bc1efdbd63 chore(release): 0.2.2 2026-03-23 19:22:06 +05:30
bendtherules 77e5470d04 fix: lint fix 2026-03-23 19:17:27 +05:30
bendtherules ac31d69e3a feat: add abortSignal to all commands
- Extend `listArchiveTags`, `getAvailableRemotes`, `deleteLocalTag`, `deleteRemoteTag`, and `cleanupMultiModel` to accept `mode` and `abortSignal` for better control and cancellation.
- Update internal calls to pass the new parameters throughout the cleanup workflow.
- Add detailed JSDoc comments for the new arguments.
- Modify `closeMultiModel` to destructure `mode` and `abortSignal` from options and forward them to `runCommand` calls, including spinner messages for session checks, killing sessions, and worktree removal.
2026-03-23 19:16:12 +05:30
bendtherules 651c2ae9a9 chore: add missing trailing newline to .opencode/package.json 2026-03-23 19:01:34 +05:30
bendtherules 0a509d2bc3 style: lint fix 2026-03-23 19:01:26 +05:30
bendtherules d8a2e11d29 style: remove extraneous blank line after assigning models from settings.lastModels 2026-03-23 19:00:04 +05:30
bendtherules 2cc01f5faa refactor(core): rename MultiModelOptions and MultiModelResult to OpenSessionOptions and OpenSessionResult 2026-03-23 18:59:44 +05:30
9 changed files with 128 additions and 60 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "opencode-multi-model",
"version": "0.2.1",
"version": "0.2.2",
"description": "Launch multiple AI models in tmux sessions - OpenCode Plugin, CLI, and Project Tool",
"type": "module",
"main": "./dist/index.js",
+5 -3
View File
@@ -1,11 +1,11 @@
#!/usr/bin/env bun
import chalk from "chalk";
import { Command } from "commander";
import pkg from "../package.json";
import { cleanupMultiModel } from "./core/cleanup";
import { closeMultiModel } from "./core/close";
import { openMultiModel } from "./core/open";
import { getBinaryName, loadSettings, promptUser } from "./core/utils";
import chalk from "chalk";
const program = new Command();
@@ -46,9 +46,11 @@ program
const answer = await promptUser(
`Continue with last used models?\n${modelList}\n(Y/n): `,
);
if (answer.toLowerCase() === "y" || answer.toLowerCase() === "yes") {
if (
answer.toLowerCase() === "y" ||
answer.toLowerCase() === "yes"
) {
models = settings.lastModels;
}
} else {
models = settings.lastModels;
+34 -9
View File
@@ -5,16 +5,32 @@ import { promptUser, runCommand } from "./utils";
/**
* Lists all archive tags matching the pattern archive/*.
*/
export async function listArchiveTags(): Promise<string[]> {
const { stdout } = await runCommand(["git", "tag", "-l", "archive/*"]);
export async function listArchiveTags(
mode?: "cli" | "tool",
abortSignal?: AbortSignal,
): Promise<string[]> {
const { stdout } = await runCommand(["git", "tag", "-l", "archive/*"], {
mode,
abortSignal,
});
return stdout.split("\n").filter(Boolean);
}
/**
* Gets the list of available git remotes.
*/
export async function getAvailableRemotes(): Promise<string[]> {
const { stdout } = await runCommand(["git", "remote"]);
/**
* Retrieves the list of git remotes.
* Accepts optional mode and abort signal for cancellation support.
*/
export async function getAvailableRemotes(
mode?: "cli" | "tool",
abortSignal?: AbortSignal,
): Promise<string[]> {
const { stdout } = await runCommand(["git", "remote"], {
mode,
abortSignal,
});
return stdout.split("\n").filter(Boolean);
}
@@ -24,10 +40,12 @@ export async function getAvailableRemotes(): Promise<string[]> {
async function deleteLocalTag(
tagName: string,
mode?: "cli" | "tool",
abortSignal?: AbortSignal,
): Promise<boolean> {
const result = await runCommand(["git", "tag", "-d", tagName], {
mode,
spinnerMsg: `Deleting local tag ${tagName}...`,
abortSignal,
});
return result.ok;
}
@@ -39,12 +57,14 @@ async function deleteRemoteTag(
tagName: string,
remoteName: string,
mode?: "cli" | "tool",
abortSignal?: AbortSignal,
): Promise<{ ok: boolean; error: string }> {
const result = await runCommand(
["git", "push", remoteName, "--delete", tagName],
{
mode,
spinnerMsg: `Deleting remote tag ${tagName} from ${remoteName}...`,
abortSignal,
},
);
return {
@@ -65,11 +85,11 @@ async function deleteRemoteTag(
export async function cleanupMultiModel(
options: CleanupOptions,
): Promise<CleanupResult> {
const { force = false, remote, mode } = options;
const { force = false, remote, mode, abortSignal } = options;
// Get available remotes and archive tags first
const availableRemotes = await getAvailableRemotes();
const archiveTags = await listArchiveTags();
const availableRemotes = await getAvailableRemotes(mode, abortSignal);
const archiveTags = await listArchiveTags(mode, abortSignal);
// Determine whether to push to remote and which remote to use:
// - remote === false: --no-remote flag, local-only mode
@@ -155,7 +175,7 @@ export async function cleanupMultiModel(
// Delete local tags
for (const tag of archiveTags) {
const deleted = await deleteLocalTag(tag, mode);
const deleted = await deleteLocalTag(tag, mode, abortSignal);
if (deleted) {
localTagNames.push(tag);
}
@@ -164,7 +184,12 @@ export async function cleanupMultiModel(
// Delete from remote (if remote is specified and exists)
if (shouldPushToRemote && remoteToDeleteFrom) {
for (const tag of localTagNames) {
const result = await deleteRemoteTag(tag, remoteToDeleteFrom, mode);
const result = await deleteRemoteTag(
tag,
remoteToDeleteFrom,
mode,
abortSignal,
);
if (result.ok) {
remoteTagNames.push(tag);
} else {
+21 -9
View File
@@ -36,21 +36,27 @@ export async function closeMultiModel(
const instructionsArr: string[] = [];
const branchesDeleted: string[] = [];
const tagsCreated: string[] = [];
const mode = options.mode;
const { mode, abortSignal } = options;
const safeSessionName = sanitizeName(options.sessionName);
try {
// Check if session exists
const { ok: sessionExists } = await runCommand([
"tmux",
"has-session",
"-t",
options.sessionName,
]);
const { ok: sessionExists } = await runCommand(
["tmux", "has-session", "-t", options.sessionName],
{
mode,
spinnerMsg: `Checking if session '${options.sessionName}' exists...`,
abortSignal,
},
);
// Kill tmux session if it exists
if (sessionExists) {
await runCommand(["tmux", "kill-session", "-t", options.sessionName]);
await runCommand(["tmux", "kill-session", "-t", options.sessionName], {
mode,
spinnerMsg: `Killing session '${options.sessionName}'...`,
abortSignal,
});
instructionsArr.push(
chalk.green(`Closed session '${options.sessionName}'`),
);
@@ -96,6 +102,7 @@ export async function closeMultiModel(
await runCommand(["git", "worktree", "remove", "-f", worktree.path], {
mode,
spinnerMsg: `Removing worktree ${worktree.path}...`,
abortSignal,
});
worktreesRemoved.push(worktree.path);
@@ -121,6 +128,7 @@ export async function closeMultiModel(
await runCommand(["git", "branch", "-D", worktree.branch], {
mode,
spinnerMsg: `Deleting branch ${worktree.branch}...`,
abortSignal,
});
branchesDeleted.push(worktree.branch);
} catch (err) {
@@ -133,7 +141,11 @@ export async function closeMultiModel(
// Also remove the base directory
const worktreeBase = getSessionPath(safeSessionName);
try {
await runCommand(["rm", "-rf", worktreeBase]);
await runCommand(["rm", "-rf", worktreeBase], {
mode,
spinnerMsg: `Removing worktree base directory: ${worktreeBase}...`,
abortSignal,
});
} catch {
// Ignore errors
}
+54 -27
View File
@@ -1,6 +1,6 @@
import * as fs from "node:fs";
import chalk from "chalk";
import type { MultiModelOptions, MultiModelResult } from "../types";
import type { OpenSessionOptions, OpenSessionResult } from "../types";
import {
createWindowPlans,
findDuplicates,
@@ -36,13 +36,13 @@ import {
* ```
*/
export async function openMultiModel(
options: MultiModelOptions,
): Promise<MultiModelResult> {
options: OpenSessionOptions,
): Promise<OpenSessionResult> {
const sessionName = options.sessionName.trim();
const safeSessionName = sanitizeName(sessionName);
const models = normalizeModels(options.models);
const binaryName = options.binaryName || "opencode";
const mode = options.mode;
const { mode, abortSignal } = options;
if (!sessionName) {
return {
@@ -69,11 +69,14 @@ export async function openMultiModel(
};
}
const gitRepoCheck = await runCommand([
"git",
"rev-parse",
"--is-inside-work-tree",
]);
const gitRepoCheck = await runCommand(
["git", "rev-parse", "--is-inside-work-tree"],
{
mode,
spinnerMsg: "Checking if inside git repository...",
abortSignal,
},
);
if (!gitRepoCheck.ok) {
return {
success: false,
@@ -82,7 +85,11 @@ export async function openMultiModel(
};
}
const tmuxExists = await runCommand(["command", "-v", "tmux"]);
const tmuxExists = await runCommand(["command", "-v", "tmux"], {
mode,
spinnerMsg: "Checking if tmux is installed...",
abortSignal,
});
if (!tmuxExists.ok) {
return {
success: false,
@@ -91,7 +98,11 @@ export async function openMultiModel(
};
}
const binaryExists = await runCommand(["command", "-v", binaryName]);
const binaryExists = await runCommand(["command", "-v", binaryName], {
mode,
spinnerMsg: `Checking if ${binaryName} is installed...`,
abortSignal,
});
if (!binaryExists.ok) {
return {
success: false,
@@ -103,6 +114,7 @@ export async function openMultiModel(
const modelListResult = await runCommand([binaryName, "models"], {
mode,
spinnerMsg: `Fetching available models using \`${binaryName} models\`...`,
abortSignal,
});
if (!modelListResult.ok) {
return {
@@ -126,12 +138,14 @@ export async function openMultiModel(
};
}
const sessionExists = await runCommand([
"tmux",
"has-session",
"-t",
sessionName,
]);
const sessionExists = await runCommand(
["tmux", "has-session", "-t", sessionName],
{
mode,
spinnerMsg: `Checking if tmux session '${sessionName}' already exists...`,
abortSignal,
},
);
if (sessionExists.ok) {
return {
success: false,
@@ -166,13 +180,14 @@ export async function openMultiModel(
}
}
const branchExists = await runCommand([
"git",
"show-ref",
"--verify",
"--quiet",
`refs/heads/${branchName}`,
]);
const branchExists = await runCommand(
["git", "show-ref", "--verify", "--quiet", `refs/heads/${branchName}`],
{
mode,
spinnerMsg: `Checking if branch '${branchName}' already exists...`,
abortSignal,
},
);
if (branchExists.ok) {
if (!isFirst) {
failedModels.push(
@@ -190,7 +205,11 @@ export async function openMultiModel(
const worktreeResult = await runCommand(
["git", "worktree", "add", "-b", branchName, worktreePath],
{ mode, spinnerMsg: `Creating worktree for ${plan.model}...` },
{
mode,
spinnerMsg: `Creating worktree for ${plan.model}...`,
abortSignal,
},
);
if (!worktreeResult.ok) {
if (!isFirst) {
@@ -220,7 +239,11 @@ export async function openMultiModel(
"-c",
worktreePath,
],
{ mode, spinnerMsg: `Starting tmux session '${sessionName}'...` },
{
mode,
spinnerMsg: `Starting tmux session '${sessionName}'...`,
abortSignal,
},
);
if (!sessionCreateResult.ok) {
@@ -244,7 +267,11 @@ export async function openMultiModel(
"-c",
worktreePath,
],
{ mode, spinnerMsg: `Creating tmux window '${plan.windowName}'...` },
{
mode,
spinnerMsg: `Creating tmux window '${plan.windowName}'...`,
abortSignal,
},
);
if (!windowCreateResult.ok) {
+1
View File
@@ -51,6 +51,7 @@ export async function runCommand(
spinner = sharedSpinner;
}
options?.abortSignal?.throwIfAborted();
const result = await Bun.$`${parts}`.quiet().nothrow();
if (spinner) {
+1 -8
View File
@@ -32,14 +32,7 @@ Arguments:
models: args.models,
binaryName,
mode: "tool",
});
context.metadata({
title: `multi-model ${args.sessionName}`,
metadata: {
safeSessionName: result.sessionName,
modelCount: args.models.length,
},
abortSignal: context.abort,
});
if (!result.success) {
+10 -2
View File
@@ -8,7 +8,7 @@ export interface MultiModelSettings {
/**
* Options for launching a multi-model tmux session.
*/
export interface MultiModelOptions {
export interface OpenSessionOptions {
/** Name for the tmux session. */
sessionName: string;
/** List of model ids to launch. */
@@ -19,12 +19,14 @@ export interface MultiModelOptions {
mode: "cli" | "tool";
/** Save models to settings file on successful launch (CLI only). */
saveToSettings?: boolean;
/** Signal to abort the operation. */
abortSignal?: AbortSignal;
}
/**
* Result returned after attempting to launch a multi-model session.
*/
export interface MultiModelResult {
export interface OpenSessionResult {
/** Whether the launch succeeded. */
success: boolean;
/** The session name used. */
@@ -51,6 +53,8 @@ export interface CloseSessionOptions {
force?: boolean;
/** Caller context: 'cli' shows shell commands, 'tool' shows tool instructions. */
mode: "cli" | "tool";
/** Signal to abort the operation. */
abortSignal?: AbortSignal;
}
/**
@@ -100,6 +104,8 @@ export interface CleanupOptions {
remote?: string | false;
/** Caller context: 'cli' shows shell commands, 'tool' shows tool instructions. */
mode: "cli" | "tool";
/** Optional abort signal to cancel the operation. */
abortSignal?: AbortSignal;
}
/**
@@ -146,6 +152,8 @@ export interface RunCommandOptions {
mode?: "cli" | "tool";
/** Message to display in the spinner while the command runs. */
spinnerMsg?: string;
/** Signal to abort the operation. Check it before running the command. */
abortSignal?: AbortSignal;
}
/**