-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
166 lines (145 loc) · 5.01 KB
/
Copy pathcli.ts
File metadata and controls
166 lines (145 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env node
import { Command } from "commander";
import { apply } from "./commands/apply.js";
import { clean } from "./commands/clean.js";
import { compare } from "./commands/compare.js";
import { type ConfigAction, config } from "./commands/config.js";
import { list } from "./commands/list.js";
import { run } from "./commands/run.js";
import { stats } from "./commands/stats.js";
import { loadConfig } from "./utils/config.js";
import { resolvePrompt } from "./utils/prompt.js";
const program = new Command();
program
.name("thinktank")
.description(
"Ensemble AI coding — run N parallel agents on the same task, select the best result",
)
.version("0.1.0");
const cfg = loadConfig();
program
.command("run")
.description("Run a task with N parallel AI coding agents")
.argument("[prompt]", "The coding task to perform")
.option("-n, --attempts <number>", "Number of parallel attempts", String(cfg.attempts))
.option("-f, --file <path>", "Read prompt from a file (avoids shell expansion issues)")
.option("-t, --test-cmd <command>", "Test command to verify results (e.g., 'npm test')")
.option(
"--test-timeout <seconds>",
"Timeout for test command in seconds",
String(cfg.testTimeout),
)
.option("--timeout <seconds>", "Timeout per agent in seconds", String(cfg.timeout))
.option("--model <model>", "Claude model to use", cfg.model)
.option("-r, --runner <name>", "AI coding tool to use", cfg.runner)
.option(
"--threshold <number>",
"Convergence clustering similarity threshold (0.0-1.0)",
String(cfg.threshold),
)
.option("--verbose", "Show detailed output from each agent")
.action(async (promptArg: string | undefined, opts) => {
const prompt = resolvePrompt(promptArg, opts.file);
const attempts = parseInt(opts.attempts, 10);
if (Number.isNaN(attempts) || attempts < 1 || attempts > 20) {
console.error("Error: --attempts must be a number between 1 and 20");
process.exit(1);
}
const testTimeout = parseInt(opts.testTimeout, 10);
if (Number.isNaN(testTimeout) || testTimeout < 10 || testTimeout > 600) {
console.error("Error: --test-timeout must be a number between 10 and 600 seconds");
process.exit(1);
}
const timeout = parseInt(opts.timeout, 10);
if (Number.isNaN(timeout) || timeout < 10 || timeout > 600) {
console.error("Error: --timeout must be a number between 10 and 600 seconds");
process.exit(1);
}
const threshold = parseFloat(opts.threshold);
if (Number.isNaN(threshold) || threshold < 0 || threshold > 1) {
console.error("Error: --threshold must be a number between 0.0 and 1.0");
process.exit(1);
}
const knownModels = ["sonnet", "opus", "haiku"];
if (!knownModels.includes(opts.model) && !opts.model.startsWith("claude-")) {
console.warn(
`Warning: unknown model "${opts.model}" — known models: ${knownModels.join(", ")}`,
);
}
await run({
prompt,
attempts,
testCmd: opts.testCmd,
testTimeout,
timeout,
model: opts.model,
threshold,
runner: opts.runner,
verbose: opts.verbose ?? false,
});
});
program
.command("apply")
.description("Apply the recommended (or selected) agent's changes to your repo")
.option("-a, --agent <number>", "Apply a specific agent's changes instead of the recommended one")
.option("-p, --preview", "Show the diff without applying")
.option("-d, --dry-run", "Show what would be applied without making changes")
.action(async (opts) => {
await apply({
agent: opts.agent ? parseInt(opts.agent, 10) : undefined,
preview: opts.preview ?? false,
dryRun: opts.dryRun ?? false,
});
});
program
.command("compare <agentA> <agentB>")
.description("Compare two agents' results side by side")
.action(async (agentA: string, agentB: string) => {
await compare({
agentA: parseInt(agentA, 10),
agentB: parseInt(agentB, 10),
});
});
program
.command("list")
.description("List results from the most recent ensemble run")
.action(async () => {
await list();
});
program
.command("clean")
.description("Remove thinktank worktrees, branches, and optionally run history")
.option("--all", "Also delete .thinktank/ run history")
.action(async (opts) => {
await clean({
all: opts.all ?? false,
});
});
program
.command("stats")
.description("Show aggregate statistics across all thinktank runs")
.action(async () => {
await stats();
});
const configCmd = program
.command("config")
.description("View and update thinktank configuration (.thinktank/config.json)");
configCmd
.command("set <key> <value>")
.description("Set a config value")
.action((key: string, value: string) => {
config("set", key, value);
});
configCmd
.command("get <key>")
.description("Get a config value")
.action((key: string) => {
config("get", key);
});
configCmd
.command("list")
.description("List all config values")
.action(() => {
config("list");
});
program.parse();