Elffuss BraidHub

kikocis/continue public

88b8936f200c · 2.6 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 "--allow <tool>",
29 "Allow specified tool (overrides default policies). 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 "--ask <tool>",
39 "Ask for permission before using 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 "--exclude <tool>",
49 "Exclude specified tool from use (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}
58
59// Function to merge parent options into subcommand options
60export function mergeParentOptions(parentCommand: Command, options: any): any {
61 const parentOpts = parentCommand.opts();
62 const mergedOptions = { ...options };
63
64 // List of options to inherit from parent if not present in subcommand
65 const inheritableOptions = [
66 "config",
67 "org",
68 "readonly",
69 "auto",
70 "tools",
71 "verbose",
72 "rule",
73 "allow",
74 "ask",
75 "exclude",
76 ];
77
78 for (const optName of inheritableOptions) {
79 if (
80 parentOpts[optName] !== undefined &&
81 mergedOptions[optName] === undefined
82 ) {
83 mergedOptions[optName] = parentOpts[optName];
84 }
85 }
86
87 return mergedOptions;
88}