Elffuss BraidHub

kikocis/continue public

4e263ad457a7 · 3.0 KiBRawPermalink
1import { Command } from "commander";
2
3// Function to add common options to any command
4export function addCommonOptions(command: Command): Command {
5 return command
6 .option(
7 "--config <path>",
8 "Configuration file for the assistant (can be a file path or hub slug)",
9 )
10 .option(
11 "--org <slug>",
12 "Organization slug to use for this session (supported only in headless mode)",
13 )
14 .option("--readonly", "Start in plan mode (read-only tools)")
15 .option("--auto", "Start in auto mode (all tools allowed)")
16 .option("-v, --verbose", "Enable verbose logging")
17 .option(
18 "--rule <rule>",
19 "Add a rule (can be a file path, hub slug, or string content). Can be specified multiple times.",
20 (value: string, previous: string[] | undefined) => {
21 const array = Array.isArray(previous) ? previous : [];
22 array.push(value);
23 return array;
24 },
25 [] as string[],
26 )
27 .option(
28 "--prompt <prompt>",
29 "Add to the initial user message (can be a file path, hub slug, or string content). Can be specified multiple times.",
30 (value: string, previous: string[] | undefined) => {
31 const array = Array.isArray(previous) ? previous : [];
32 array.push(value);
33 return array;
34 },
35 [] as string[],
36 )
37 .option(
38 "--allow <tool>",
39 "Allow specified tool (overrides default policies). Can be specified multiple times.",
40 (value: string, previous: string[] | undefined) => {
41 const array = Array.isArray(previous) ? previous : [];
42 array.push(value);
43 return array;
44 },
45 [] as string[],
46 )
47 .option(
48 "--ask <tool>",
49 "Ask for permission before using specified tool (overrides default policies). Can be specified multiple times.",
50 (value: string, previous: string[] | undefined) => {
51 const array = Array.isArray(previous) ? previous : [];
52 array.push(value);
53 return array;
54 },
55 [] as string[],
56 )
57 .option(
58 "--exclude <tool>",
59 "Exclude specified tool from use (overrides default policies). Can be specified multiple times.",
60 (value: string, previous: string[] | undefined) => {
61 const array = Array.isArray(previous) ? previous : [];
62 array.push(value);
63 return array;
64 },
65 [] as string[],
66 );
67}
68
69// Function to merge parent options into subcommand options
70export function mergeParentOptions(parentCommand: Command, options: any): any {
71 const parentOpts = parentCommand.opts();
72 const mergedOptions = { ...options };
73
74 // List of options to inherit from parent if not present in subcommand
75 const inheritableOptions = [
76 "config",
77 "org",
78 "readonly",
79 "auto",
80 "tools",
81 "verbose",
82 "rule",
83 "prompt",
84 "allow",
85 "ask",
86 "exclude",
87 ];
88
89 for (const optName of inheritableOptions) {
90 if (
91 parentOpts[optName] !== undefined &&
92 mergedOptions[optName] === undefined
93 ) {
94 mergedOptions[optName] = parentOpts[optName];
95 }
96 }
97
98 return mergedOptions;
99}