-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcli.ts
More file actions
422 lines (391 loc) · 17.1 KB
/
cli.ts
File metadata and controls
422 lines (391 loc) · 17.1 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
#!/usr/bin/env node
import chalk from 'chalk';
import { Command } from 'commander';
import { authCommand } from './commands/auth.js';
import { autoCommand } from './commands/auto.js';
import { checkCommand } from './commands/check.js';
import { configCommand } from './commands/config.js';
import { figmaCommand } from './commands/figma.js';
import { fixCommand } from './commands/fix.js';
import { initCommand } from './commands/init.js';
import { integrationsCommand } from './commands/integrations.js';
import { linearCommand } from './commands/linear.js';
import { pauseCommand } from './commands/pause.js';
import { planCommand } from './commands/plan.js';
import { resumeCommand } from './commands/resume.js';
import { runCommand } from './commands/run.js';
import { setupCommand } from './commands/setup.js';
import { skillCommand } from './commands/skill.js';
import { sourceCommand } from './commands/source.js';
import { taskCommand } from './commands/task.js';
import { templateCommand } from './commands/template.js';
import { startMcpServer } from './mcp/server.js';
import { formatPresetsHelp, getPresetNames } from './presets/index.js';
import { drawBox, getTerminalWidth } from './ui/box.js';
import { getPackageVersion } from './utils/version.js';
import { runIdeaMode, runWizard } from './wizard/index.js';
const VERSION = getPackageVersion();
const program = new Command();
function stripAnsi(text: string): string {
// biome-ignore lint/suspicious/noControlCharactersInRegex: ANSI escape sequence detection requires control characters
return text.replace(/\u001b\[[0-9;]*m/g, '');
}
const bannerLines = [
` ${chalk.bold.white('ralph-starter')} ${chalk.gray(`v${VERSION}`)}`,
` ${chalk.dim('Ralph Wiggum made easy.')}`,
` ${chalk.dim('One command to run autonomous AI coding loops.')}`,
];
const maxLineLen = Math.max(...bannerLines.map((line) => stripAnsi(line).length));
const bannerWidth = Math.min(getTerminalWidth() - 4, Math.max(40, maxLineLen + 2));
const banner = `\n${drawBox(bannerLines, { color: chalk.cyan, width: bannerWidth })}\n`;
program
.name('ralph-starter')
.description('Ralph Wiggum made easy. Run autonomous AI coding loops with one command.')
.version(VERSION)
.addHelpText('beforeAll', banner);
// ralph-starter run [task] - Main command to run a loop
program
.command('run [task]')
.description('Run an autonomous AI coding loop')
.option('--auto', 'Run in fully automated mode (skip permissions)', true)
.option('--no-auto', 'Require manual permission approval')
.option('--commit', 'Auto-commit after each successful task')
.option('--push', 'Push commits to remote')
.option('--pr', 'Create a pull request when done')
.option('--validate', 'Run tests/lint/build after each iteration (backpressure)')
.option('--docker', 'Run in Docker sandbox (coming soon)')
.option('--prd <file>', 'Read tasks from a PRD markdown file')
.option('--max-iterations <n>', 'Maximum loop iterations (auto-calculated if not specified)')
.option('--agent <name>', 'Specify agent (claude-code, cursor, codex, opencode, openclaw)')
.option('--model <name>', 'Model to use (e.g., claude-sonnet-4-5-20250929, claude-opus-4-6)')
.option('--from <source>', 'Fetch spec from source (file, url, github, todoist, linear, notion)')
.option('--project <name>', 'Project/repo name for --from integrations')
.option('--label <name>', 'Label filter for --from integrations')
.option('--status <status>', 'Status filter for --from integrations')
.option('--limit <n>', 'Max items to fetch for --from integrations', '20')
.option('--issue <n>', 'Specific issue number to fetch (for github)')
.option('--output-dir <path>', 'Directory to run the task in (skips location prompt)')
// New options
.option(
'--preset <name>',
`Use a workflow preset (${getPresetNames().slice(0, 5).join(', ')}...)`
)
.option('--completion-promise <string>', 'Custom completion promise string to detect task done')
.option('--require-exit-signal', 'Require explicit EXIT_SIGNAL: true for completion')
.option('--rate-limit <n>', 'Max API calls per hour (default: unlimited)')
.option('--track-progress', 'Write progress to activity.md (default: true)')
.option('--no-track-progress', 'Disable progress tracking')
.option('--track-cost', 'Track token usage and estimated cost (default: true)')
.option('--no-track-cost', 'Disable cost tracking')
.option('--circuit-breaker-failures <n>', 'Max consecutive failures before stopping (default: 3)')
.option('--circuit-breaker-errors <n>', 'Max same error occurrences before stopping (default: 5)')
.option(
'--validation-warmup <n>',
'Skip validation until N tasks are completed (auto-detected for greenfield builds)'
)
.option(
'--context-budget <n>',
'Max input tokens per iteration for smart context trimming (0 = unlimited)'
)
.option('--max-cost <amount>', 'Maximum cost in USD before stopping (0 = unlimited)', parseFloat)
.option('--plan <name>', 'API plan for budget tracking (max, pro, team, api)')
// Figma integration options
.option('--figma-mode <mode>', 'Figma mode: spec, tokens, components, assets, content')
.option(
'--figma-framework <framework>',
'Component framework: react, vue, svelte, astro, nextjs, nuxt, html'
)
.option('--figma-format <format>', 'Token format: css, scss, json, tailwind')
.option('--figma-nodes <ids>', 'Specific Figma node IDs (comma-separated)')
.option('--figma-scale <n>', 'Image export scale (default: 1)')
.option('--figma-target <path>', 'Target directory for content mode')
.option('--figma-preview', 'Show content changes without applying (content mode)')
.option('--figma-mapping <file>', 'Custom content mapping file (content mode)')
.option(
'--design-image <path>',
'Design reference image (screenshot of the target design for pixel-perfect matching)'
)
.option(
'--no-visual-check',
'Disable visual comparison validation (auto-enabled when Figma screenshots exist)'
)
.action(runCommand);
// ralph-starter fix - Fix build errors and code quality issues
program
.command('fix [task]')
.description('Fix build errors and code quality issues (optional: describe what to fix)')
.option('--scan', 'Force full project scan (build + lint + typecheck + tests)')
.option('--agent <agent>', 'Agent to use (default: auto-detect)')
.option('--commit', 'Auto-commit the fix')
.option('--max-iterations <n>', 'Max fix iterations (default: 3)')
.option('--output-dir <dir>', 'Project directory (default: cwd)')
.option('--design', 'Visual-first design fix: screenshot, analyze, plan, and fix design issues')
.option(
'--design-image <path>',
'Design reference image to match (screenshot of the target design)'
)
.action(fixCommand);
// ralph-starter figma - Figma design to code wizard
program
.command('figma')
.description('Convert Figma designs to code with an interactive wizard')
.option('--figma-mode <mode>', 'Figma mode: spec, tokens, components, assets, content')
.option(
'--figma-framework <framework>',
'Component framework: react, vue, svelte, astro, nextjs, nuxt, html'
)
.option('--commit', 'Auto-commit changes')
.option('--validate', 'Run validation after each iteration', true)
.option('--no-validate', 'Skip validation')
.option('--max-iterations <n>', 'Maximum loop iterations')
.option('--agent <name>', 'Specify agent to use')
.action(async (options) => {
await figmaCommand({
mode: options.figmaMode,
framework: options.figmaFramework,
commit: options.commit,
validate: options.validate,
maxIterations: options.maxIterations ? parseInt(options.maxIterations, 10) : undefined,
agent: options.agent,
});
});
// ralph-starter linear - Linear issues wizard
program
.command('linear')
.description('Build from Linear issues with an interactive wizard')
.option('--commit', 'Auto-commit after tasks')
.option('--push', 'Push to remote')
.option('--pr', 'Create PR when done')
.option('--validate', 'Run validation', true)
.option('--no-validate', 'Skip validation')
.option('--max-iterations <n>', 'Max loop iterations')
.option('--agent <name>', 'Agent to use')
.action(async (options) => {
await linearCommand({
commit: options.commit,
push: options.push,
pr: options.pr,
validate: options.validate,
maxIterations: options.maxIterations ? parseInt(options.maxIterations, 10) : undefined,
agent: options.agent,
});
});
// ralph-starter init - Initialize Ralph in a project
program
.command('init')
.description('Initialize Ralph Wiggum in an existing project')
.option('-n, --name <name>', 'Project name')
.action(initCommand);
// ralph-starter skill - Manage agent skills
program
.command('skill <action> [name]')
.description('Manage agent skills (add, list, search, browse)')
.option('-g, --global', 'Install skill globally')
.action(skillCommand);
// ralph-starter plan - Create implementation plan from specs
program
.command('plan')
.description('Analyze specs and create implementation plan (Ralph Playbook planning mode)')
.option('--auto', 'Run in automated mode (skip permissions)', true)
.option('--no-auto', 'Require manual permission approval')
.action(planCommand);
// ralph-starter setup - Interactive setup wizard
program
.command('setup')
.description('Interactive setup wizard to configure LLM and agents')
.option('--force', 'Force re-run setup even if already configured')
.action(setupCommand);
// ralph-starter check - Check configuration and test connection
program
.command('check')
.description('Check configuration and test LLM connection')
.option('--verbose', 'Show detailed output')
.action(checkCommand);
// ralph-starter wizard - Interactive wizard (explicit command)
program
.command('wizard')
.description('Launch the interactive wizard to build a new project')
.action(async () => {
await runWizard();
});
// ralph-starter ideas - Brainstorm project ideas
program
.command('ideas')
.description("Brainstorm project ideas when you don't know what to build")
.action(async () => {
const idea = await runIdeaMode();
if (idea) {
console.log();
console.log(' Selected idea:', idea);
console.log();
console.log(' To build this project, run:');
console.log(' ralph-starter wizard');
console.log();
}
});
// ralph-starter config - Manage source configuration
program
.command('config [action] [args...]')
.description('Manage source configuration (list, get, set, delete)')
.action(async (action: string | undefined, args: string[]) => {
if (!action) {
// Show help when no action provided
await configCommand('help', []);
return;
}
await configCommand(action, args);
});
// ralph-starter auth - Browser-based OAuth authentication
program
.command('auth [service]')
.description('Browser-based OAuth authentication for integrations')
.option('--list', 'Show authentication status for all services')
.option('--logout <service>', 'Remove credentials for a service')
.action(async (service: string | undefined, options: { list?: boolean; logout?: string }) => {
await authCommand(service, options);
});
// ralph-starter source - Manage input sources
program
.command('source [action] [args...]')
.description('Manage input sources (list, help, test, preview)')
.option('--project <name>', 'Project/repo name for integrations')
.option('--label <name>', 'Label filter')
.option('--status <status>', 'Status filter')
.option('--limit <n>', 'Max items to fetch', '10')
.option('--issue <n>', 'Specific issue number to fetch (for github)')
.action(async (action: string | undefined, args: string[], options) => {
if (!action) {
// Show help when no action provided
await sourceCommand('help', []);
return;
}
await sourceCommand(action, args, options);
});
// ralph-starter integrations - Manage integrations (unified architecture)
program
.command('integrations [action] [args...]')
.description('Manage integrations (list, help, test, fetch)')
.option('--project <name>', 'Project/repo name')
.option('--label <name>', 'Label filter')
.option('--status <status>', 'Status filter')
.option('--limit <n>', 'Max items to fetch', '10')
.action(async (action: string | undefined, args: string[], options) => {
if (!action) {
// Default to list when no action provided
await integrationsCommand('list', [], options);
return;
}
await integrationsCommand(action, args, options);
});
// ralph-starter mcp - Start as MCP server
program
.command('mcp')
.description('Start as an MCP (Model Context Protocol) server for Claude Desktop/Code')
.action(async () => {
await startMcpServer();
});
// ralph-starter auto - Autonomous batch task processing
program
.command('auto')
.description('Run in autonomous mode, processing multiple tasks from GitHub/Linear')
.requiredOption('--source <source>', 'Source to fetch tasks from (github, linear)')
.option('--project <name>', 'Project identifier (owner/repo for GitHub)')
.option('--label <name>', 'Filter tasks by label (e.g., "auto-ready")')
.option('--limit <n>', 'Maximum tasks to process (default: 10)', '10')
.option('--dry-run', 'Preview mode - show tasks without executing')
.option('--skip-pr', 'Skip PR creation (commit only)')
.option('--agent <name>', 'Specify agent to use')
.option('--validate', 'Run validation after each task', true)
.option('--no-validate', 'Skip validation')
.option('--max-iterations <n>', 'Max iterations per task (default: 15)')
.option('--batch', 'Use Anthropic Batch API for 50% cost reduction (no tool use)')
.option('--model <name>', 'Model to use in batch mode')
.action(async (options) => {
await autoCommand({
source: options.source,
project: options.project,
label: options.label,
limit: parseInt(options.limit, 10),
dryRun: options.dryRun,
skipPr: options.skipPr,
agent: options.agent,
validate: options.validate,
maxIterations: options.maxIterations ? parseInt(options.maxIterations, 10) : undefined,
batch: options.batch,
model: options.model,
});
});
// ralph-starter task - Manage tasks across GitHub and Linear
program
.command('task [action] [args...]')
.description('Manage tasks across GitHub and Linear (list, create, update, close, comment)')
.option('--source <source>', 'Source: github, linear, or all (default: all)')
.option('--project <name>', 'Project filter (owner/repo for GitHub, team name for Linear)')
.option('--label <name>', 'Filter by label')
.option('--status <status>', 'Filter by status or set status on update')
.option('--limit <n>', 'Max tasks to fetch (default: 50)', '50')
.option('--title <title>', 'Task title (for create)')
.option('--body <body>', 'Task description (for create)')
.option('--priority <p>', 'Priority: P0, P1, P2, P3')
.option('--comment <text>', 'Comment text (for close/update)')
.option('--assignee <name>', 'Assign to team member (GitHub username or Linear display name)')
.action(async (action: string | undefined, args: string[], options) => {
await taskCommand(action, args, options);
});
// ralph-starter pause - Pause a running session
program
.command('pause')
.description('Pause a running session for later resumption')
.option('--reason <text>', 'Reason for pausing the session')
.action(async (options) => {
await pauseCommand({
reason: options.reason,
});
});
// ralph-starter resume - Resume a paused session
program
.command('resume')
.description('Resume a paused session from where it left off')
.option('--force', 'Force resume even if session is not paused')
.action(async (options) => {
await resumeCommand({
force: options.force,
});
});
// ralph-starter presets - List available workflow presets
program
.command('presets')
.description('List available workflow presets')
.action(() => {
console.log();
console.log(formatPresetsHelp());
console.log('Use with: ralph-starter run --preset <name> [task]');
console.log();
});
// ralph-starter template - Browse and use project templates
program
.command('template [action] [args...]')
.description('Browse and use project templates from ralph-templates')
.option(
'--category <name>',
'Filter by category (web-dev, blockchain, devops, mobile, tools, seo)'
)
.option('--refresh', 'Force refresh the cache')
.option('--auto', 'Skip confirmation prompts')
.option('--output-dir <path>', 'Directory to create the project in')
.option('--commit', 'Auto-commit after each successful task')
.option('--push', 'Push commits to remote')
.option('--pr', 'Create a pull request when done')
.option('--validate', 'Run tests/lint/build after each iteration')
.option('--max-iterations <n>', 'Maximum loop iterations')
.option('--agent <name>', 'Specify agent (claude-code, cursor, codex, opencode, openclaw)')
.action(async (action: string | undefined, args: string[], options) => {
await templateCommand(action, args, options);
});
// Default action - launch interactive wizard
program.action(async () => {
// If user passes --help, commander handles it
// Otherwise, launch the wizard
await runWizard();
});
program.parse();