mirror of
https://github.com/bendtherules/opencode-multi-model.git
synced 2026-08-18 13:42:21 +00:00
plan: fix inconsistencies in npm package plan
This commit is contained in:
@@ -226,16 +226,17 @@ export function getBinaryName(context?: { config?: { multiModelBinary?: string }
|
||||
|
||||
```typescript
|
||||
// src/core/launch.ts
|
||||
import type { MultiModelOptions, MultiModelResult } from "../types.js";
|
||||
import type { MultiModelOptions, MultiModelResult } from "../types";
|
||||
import {
|
||||
runCommand, shellQuote, normalizeModels, findDuplicates,
|
||||
createWindowPlans, suggestModels, formatInvalidModelError,
|
||||
sanitizeName, getWorktreePath, undoWorktree, getBinaryName
|
||||
} from "./utils.js";
|
||||
} from "./utils";
|
||||
|
||||
export async function launchMultiModel(options: MultiModelOptions): Promise<MultiModelResult> {
|
||||
// Core implementation from current multi-model.ts
|
||||
// All the validation, tmux setup, worktree creation, etc.
|
||||
const safeSessionName = sanitizeName(options.sessionName);
|
||||
|
||||
// Returns result with instructions for connecting and cleanup
|
||||
return {
|
||||
@@ -267,8 +268,8 @@ Or manually:
|
||||
|
||||
```typescript
|
||||
// src/core/close.ts
|
||||
import type { CloseSessionOptions, CloseSessionResult } from "../types.ts";
|
||||
import { runCommand, getWorktreePath, getWorktreesForSession, sanitizeName } from "./utils.ts";
|
||||
import type { CloseSessionOptions, CloseSessionResult } from "../types";
|
||||
import { runCommand, getWorktreePath, getWorktreesForSession, sanitizeName } from "./utils";
|
||||
import * as readline from "readline";
|
||||
|
||||
async function promptUser(question: string): Promise<string> {
|
||||
@@ -320,7 +321,7 @@ export async function closeMultiModel(options: CloseSessionOptions): Promise<Clo
|
||||
let cleanupPerformed = false;
|
||||
|
||||
// Cleanup worktrees and optionally branches
|
||||
if (options.cleanup) {
|
||||
if (options.cleanupWorktrees) {
|
||||
for (const worktree of worktrees) {
|
||||
try {
|
||||
// Remove worktree
|
||||
@@ -368,10 +369,10 @@ export async function closeMultiModel(options: CloseSessionOptions): Promise<Clo
|
||||
|
||||
```typescript
|
||||
// src/core/index.ts
|
||||
export { launchMultiModel } from "./launch.ts";
|
||||
export { closeMultiModel } from "./close.ts";
|
||||
export * from "./utils.ts";
|
||||
export * from "../types.ts";
|
||||
export { launchMultiModel } from "./launch";
|
||||
export { closeMultiModel } from "./close";
|
||||
export * from "./utils";
|
||||
export * from "../types";
|
||||
```
|
||||
|
||||
### 7. Create Open Tool Definition
|
||||
@@ -379,8 +380,8 @@ export * from "../types.ts";
|
||||
```typescript
|
||||
// src/tools/open.ts
|
||||
import { tool, type ToolContext } from "@opencode-ai/plugin";
|
||||
import { launchMultiModel } from "../core/launch.ts";
|
||||
import { getBinaryName } from "../core/utils.ts";
|
||||
import { launchMultiModel } from "../core/launch";
|
||||
import { getBinaryName } from "../core/utils";
|
||||
|
||||
export const openTool = tool({
|
||||
name: "multi-model-open",
|
||||
@@ -410,7 +411,7 @@ export const openTool = tool({
|
||||
}
|
||||
});
|
||||
|
||||
export default openTool;
|
||||
|
||||
```
|
||||
|
||||
### 8. Create Close Tool Definition
|
||||
@@ -418,14 +419,14 @@ export default openTool;
|
||||
```typescript
|
||||
// src/tools/close.ts
|
||||
import { tool, type ToolContext } from "@opencode-ai/plugin";
|
||||
import { closeMultiModel } from "../core/close.ts";
|
||||
import { closeMultiModel } from "../core/close";
|
||||
|
||||
export const closeTool = tool({
|
||||
name: "multi-model-close",
|
||||
description: "Close a multi-model tmux session and optionally cleanup worktrees and branches",
|
||||
args: {
|
||||
sessionName: tool.schema.string().min(1).describe("tmux session name to close"),
|
||||
cleanupWorktrees: tool.schema.boolean().optional().describe("whether to remove worktrees and delete branches (default: true)"),(default: true)"),
|
||||
cleanupWorktrees: tool.schema.boolean().default(true).describe("whether to remove worktrees and delete branches (default: true)"),
|
||||
},
|
||||
async execute(args, context: ToolContext) {
|
||||
// In plugin mode, we skip confirmation (force=true) since there's no interactive terminal
|
||||
@@ -450,7 +451,7 @@ export const closeTool = tool({
|
||||
}
|
||||
});
|
||||
|
||||
export default closeTool;
|
||||
|
||||
```
|
||||
|
||||
### 9. Create Plugin Entry Point
|
||||
@@ -458,8 +459,8 @@ export default closeTool;
|
||||
```typescript
|
||||
// src/index.ts
|
||||
import type { Plugin } from "@opencode-ai/plugin";
|
||||
import { openTool } from "./tools/open.ts";
|
||||
import { closeTool } from "./tools/close.ts";
|
||||
import { openTool } from "./tools/open";
|
||||
import { closeTool } from "./tools/close";
|
||||
|
||||
export const OpenCodeMultiModelPlugin: Plugin = async (ctx) => {
|
||||
return {
|
||||
@@ -470,9 +471,8 @@ export const OpenCodeMultiModelPlugin: Plugin = async (ctx) => {
|
||||
};
|
||||
};
|
||||
|
||||
export default OpenCodeMultiModelPlugin;
|
||||
export { openTool, closeTool };
|
||||
export * from "./core/index.ts";
|
||||
export * from "./core/index";
|
||||
```
|
||||
|
||||
### 10. Create CLI Entry Point (with env support)
|
||||
@@ -481,9 +481,9 @@ export * from "./core/index.ts";
|
||||
// src/cli.ts
|
||||
#!/usr/bin/env node
|
||||
import { Command } from "commander";
|
||||
import { launchMultiModel } from "./core/launch.js";
|
||||
import { closeMultiModel } from "./core/close.js";
|
||||
import { getBinaryName } from "./core/utils.js";
|
||||
import { launchMultiModel } from "./core/launch";
|
||||
import { closeMultiModel } from "./core/close";
|
||||
import { getBinaryName } from "./core/utils";
|
||||
|
||||
const program = new Command();
|
||||
|
||||
@@ -527,16 +527,14 @@ program
|
||||
.command("close")
|
||||
.description("Close a multi-model tmux session")
|
||||
.argument("<session-name>", "Name of the tmux session to close")
|
||||
.option("-c, --cleanup", "Remove worktrees and delete branches", false)
|
||||
.option("-c, --cleanup-worktrees", "Remove worktrees and delete branches", true)
|
||||
.option("-f, --force", "Skip confirmation prompts", false)
|
||||
.option("-k, --keep-branches", "Keep git branches (only remove worktrees)", false)
|
||||
.action(async (sessionName, options) => {
|
||||
try {
|
||||
const result = await closeMultiModel({
|
||||
sessionName,
|
||||
cleanup: options.cleanup,
|
||||
cleanupWorktrees: options.cleanupWorktrees,
|
||||
force: options.force,
|
||||
keepBranches: options.keepBranches
|
||||
});
|
||||
|
||||
if (result.success) {
|
||||
@@ -557,35 +555,6 @@ program
|
||||
}
|
||||
});
|
||||
|
||||
// Default to open command for backwards compatibility
|
||||
program
|
||||
.argument("[session-name]", "Name for the tmux session (deprecated, use 'open' command)")
|
||||
.option("-m, --models <models...>", "Model IDs to launch", [])
|
||||
.option("-b, --binary <binary>", "Binary to use")
|
||||
.action(async (sessionName, options) => {
|
||||
if (!sessionName) {
|
||||
program.help();
|
||||
return;
|
||||
}
|
||||
|
||||
console.warn("Warning: Direct session name is deprecated. Use 'opencode-multi-model open <session-name>' instead.");
|
||||
|
||||
const binaryName = options.binary || getBinaryName();
|
||||
|
||||
const result = await launchMultiModel({
|
||||
sessionName,
|
||||
models: options.models,
|
||||
binaryName
|
||||
});
|
||||
|
||||
if (result.success) {
|
||||
console.log(result.instructions);
|
||||
} else {
|
||||
console.error(`✗ Failed: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
program.parse();
|
||||
```
|
||||
|
||||
@@ -595,10 +564,10 @@ program.parse();
|
||||
// .opencode/tools/multi-model.ts
|
||||
// Re-export both open and close tools for project-level use
|
||||
|
||||
import { openTool, closeTool } from "../../src/tools/open.js";
|
||||
import { openTool } from "../../src/tools/open";
|
||||
import { closeTool } from "../../src/tools/close";
|
||||
|
||||
export { openTool, closeTool };
|
||||
export default openTool; // Default to open for backwards compatibility
|
||||
```
|
||||
|
||||
### 12. Add Build Configuration
|
||||
@@ -636,7 +605,7 @@ export default openTool; // Default to open for backwards compatibility
|
||||
|
||||
**Tests**: Copy `.opencode/multi-model.test.ts` to `tests/multi-model.test.ts` and update imports:
|
||||
- Change `import multiModelTool, { __testing_helpers } from "./tools/multi-model"`
|
||||
- To `import { launchMultiModel, closeMultiModel, runCommand, ... } from "../src/core"`
|
||||
- To `import { launchMultiModel, closeMultiModel } from "../src/core"` and `import { runCommand, ... } from "../src/core/utils"`
|
||||
|
||||
The existing tests should work with minimal changes since the core logic remains the same.
|
||||
|
||||
@@ -679,7 +648,6 @@ opencode-multi-model open my-session -m openai/gpt-4o
|
||||
// .opencode/tools/multi-model.ts
|
||||
import { openTool, closeTool } from "@username/opencode-multi-model"
|
||||
export { openTool, closeTool }
|
||||
export default openTool
|
||||
```
|
||||
|
||||
## Usage
|
||||
@@ -695,7 +663,7 @@ sessionName: my-session, models: ["openai/gpt-4o", "anthropic/claude-3-5-sonnet"
|
||||
**Close a session:**
|
||||
```
|
||||
Use multi-model-close tool:
|
||||
sessionName: my-session, cleanup: true
|
||||
sessionName: my-session, cleanupWorktrees: true
|
||||
```
|
||||
|
||||
### CLI Usage
|
||||
@@ -719,7 +687,7 @@ opencode-multi-model open my-session -m openai/gpt-4o
|
||||
opencode-multi-model close my-session
|
||||
|
||||
# Close and cleanup worktrees
|
||||
opencode-multi-model close my-session --cleanup
|
||||
opencode-multi-model close my-session --cleanup-worktrees
|
||||
```
|
||||
|
||||
**Help:**
|
||||
@@ -767,13 +735,12 @@ For local development and testing without publishing:
|
||||
|
||||
```typescript
|
||||
// .opencode/tools/multi-model.ts
|
||||
import { openTool, closeTool } from "../../src/tools/open.js"
|
||||
import { openTool } from "../../src/tools/open"
|
||||
import { closeTool } from "../../src/tools/close"
|
||||
export { openTool, closeTool }
|
||||
export default openTool
|
||||
```
|
||||
|
||||
This allows testing the tool without publishing to npm.
|
||||
```
|
||||
|
||||
## Files to Create/Modify
|
||||
|
||||
@@ -846,7 +813,7 @@ npm install -g @username/opencode-multi-model
|
||||
opencode-multi-model open compare-session -m openai/gpt-4o anthropic/claude-3-opus google/gemini-pro
|
||||
|
||||
# Close session with cleanup
|
||||
opencode-multi-model close compare-session --cleanup
|
||||
opencode-multi-model close compare-session --cleanup-worktrees
|
||||
```
|
||||
|
||||
### Developer - Project Tool
|
||||
@@ -854,9 +821,9 @@ opencode-multi-model close compare-session --cleanup
|
||||
```typescript
|
||||
// .opencode/tools/multi-model.ts
|
||||
// For testing local changes before publishing
|
||||
import { openTool, closeTool } from "../../src/tools/open.js"
|
||||
import { openTool } from "../../src/tools/open"
|
||||
import { closeTool } from "../../src/tools/close"
|
||||
export { openTool, closeTool }
|
||||
export default openTool
|
||||
```
|
||||
|
||||
This allows testing the tool without publishing to npm.
|
||||
|
||||
Reference in New Issue
Block a user