-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathindex.ts
More file actions
150 lines (133 loc) · 5.6 KB
/
Copy pathindex.ts
File metadata and controls
150 lines (133 loc) · 5.6 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
import { Command } from "commander"
import { DEFAULT_FLAGS } from "@/types/constants.js"
import { supportedProviders } from "@/types/index.js"
import { VERSION } from "@/lib/utils/version.js"
import { run, logout, status, listCommands, listModes, listModels, listSessions, upgrade } from "@/commands/index.js"
const program = new Command()
program
.name("roo")
.description("Roo Code CLI - starts an interactive session by default, use -p/--print for non-interactive output")
.version(VERSION)
.enablePositionalOptions()
.passThroughOptions()
program
.argument("[prompt]", "Your prompt")
.option("--prompt-file <path>", "Read prompt from a file instead of command line argument")
.option("--create-with-session-id <session-id>", "Create a new task with a specific session ID (must be a UUID)")
.option("--session-id <session-id>", "Resume a specific task by session ID")
.option("-c, --continue", "Resume the most recent task in the current workspace", false)
.option("-w, --workspace <path>", "Workspace directory path (defaults to current working directory)")
.option("-p, --print", "Print response and exit (non-interactive mode)", false)
.option(
"--stdin-prompt-stream",
"Read NDJSON commands from stdin (requires --print and --output-format stream-json)",
false,
)
.option(
"--signal-only-exit",
"Do not exit from normal completion/errors; only terminate on SIGINT/SIGTERM (intended for stdin stream harnesses)",
false,
)
.option("-e, --extension <path>", "Path to the extension bundle directory")
.option("-d, --debug", "Enable debug output (includes detailed debug information)", false)
.option("-a, --require-approval", "Require manual approval for actions", false)
.option("-k, --api-key <key>", "API key for the LLM provider")
.option("--provider <provider>", `API provider (${supportedProviders.join(", ")})`)
.option("-m, --model <model>", "Model to use", DEFAULT_FLAGS.model)
.option("--mode <mode>", "Mode to start in (code, architect, ask, debug, etc.)", DEFAULT_FLAGS.mode)
.option("--terminal-shell <path>", "Absolute path to shell executable for inline terminal commands")
.option(
"-r, --reasoning-effort <effort>",
"Reasoning effort level (unspecified, disabled, none, minimal, low, medium, high, xhigh)",
DEFAULT_FLAGS.reasoningEffort,
)
.option(
"--consecutive-mistake-limit <limit>",
"Consecutive error/repetition limit before guidance prompt (0 disables the limit)",
(value) => Number.parseInt(value, 10),
)
.option("--exit-on-error", "Exit on API request errors instead of retrying", false)
.option("--ephemeral", "Run without persisting state (uses temporary storage)", false)
.option("--oneshot", "Exit upon task completion", false)
.option(
"--output-format <format>",
'Output format (only works with --print): "text" (default), "json" (single result), or "stream-json" (realtime streaming)',
"text",
)
.action(run)
const listCommand = program
.command("list")
.description("List commands, modes, models, or sessions")
.enablePositionalOptions()
.passThroughOptions()
const applyListOptions = (command: Command) =>
command
.option("-w, --workspace <path>", "Workspace directory path (defaults to current working directory)")
.option("-e, --extension <path>", "Path to the extension bundle directory")
.option("-k, --api-key <key>", "API key for the LLM provider")
.option("--format <format>", 'Output format: "json" (default) or "text"', "json")
.option("-d, --debug", "Enable debug output", false)
const runListAction = async (action: () => Promise<void>) => {
try {
await action()
process.exit(0)
} catch (error) {
const message = error instanceof Error ? error.message : String(error)
console.error(`[CLI] Error: ${message}`)
process.exit(1)
}
}
const runUpgradeAction = async (action: () => Promise<void>) => {
try {
await action()
process.exit(0)
} catch (error) {
const message = error instanceof Error ? error.message : String(error)
console.error(`[CLI] Error: ${message}`)
process.exit(1)
}
}
applyListOptions(listCommand.command("commands").description("List available slash commands")).action(
async (options: Parameters<typeof listCommands>[0]) => {
await runListAction(() => listCommands(options))
},
)
applyListOptions(listCommand.command("modes").description("List available modes")).action(
async (options: Parameters<typeof listModes>[0]) => {
await runListAction(() => listModes(options))
},
)
applyListOptions(listCommand.command("models").description("List available models")).action(
async (options: Parameters<typeof listModels>[0]) => {
await runListAction(() => listModels(options))
},
)
applyListOptions(listCommand.command("sessions").description("List task sessions")).action(
async (options: Parameters<typeof listSessions>[0]) => {
await runListAction(() => listSessions(options))
},
)
program
.command("upgrade")
.description("Upgrade Roo Code CLI to the latest version")
.action(async () => {
await runUpgradeAction(() => upgrade())
})
const authCommand = program.command("auth").description("Inspect or remove legacy Roo auth tokens")
authCommand
.command("logout")
.description("Remove a stored legacy Roo auth token")
.option("-v, --verbose", "Enable verbose output", false)
.action(async (options: { verbose: boolean }) => {
const result = await logout({ verbose: options.verbose })
process.exit(result.success ? 0 : 1)
})
authCommand
.command("status")
.description("Show whether a legacy Roo auth token is still stored")
.option("-v, --verbose", "Enable verbose output", false)
.action(async (options: { verbose: boolean }) => {
await status({ verbose: options.verbose })
process.exit(0)
})
program.parse()