claude-yes 1.25.0 → 1.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,111 @@
1
+ import enhancedMs from 'enhanced-ms';
2
+ import yargs from 'yargs';
3
+ import { hideBin } from 'yargs/helpers';
4
+ import { SUPPORTED_CLIS } from '.';
5
+
6
+ /**
7
+ * Parse CLI arguments the same way cli.ts does
8
+ * This is a test helper that mirrors the parsing logic in cli.ts
9
+ */
10
+ export function parseCliArgs(argv: string[]) {
11
+ // Detect cli name from script name (same logic as cli.ts:10-14)
12
+ const cliName = ((e?: string) => {
13
+ if (e === 'cli' || e === 'cli.ts') return undefined;
14
+ return e;
15
+ })(argv[1]?.split('/').pop()?.split('-')[0]);
16
+
17
+ // Parse args with yargs (same logic as cli.ts:16-73)
18
+ const parsedArgv = yargs(hideBin(argv))
19
+ .usage('Usage: $0 [cli] [cli-yes args] [agent-cli args] [--] [prompts...]')
20
+ .example(
21
+ '$0 claude --idle=30s -- solve all todos in my codebase, commit one by one',
22
+ 'Run Claude with a 30 seconds idle timeout, and the prompt is everything after `--`',
23
+ )
24
+ .option('robust', {
25
+ type: 'boolean',
26
+ default: true,
27
+ description:
28
+ 're-spawn Claude with --continue if it crashes, only works for claude yet',
29
+ alias: 'r',
30
+ })
31
+ .option('logFile', {
32
+ type: 'string',
33
+ description: 'Rendered log file to write to.',
34
+ })
35
+ .option('prompt', {
36
+ type: 'string',
37
+ description: 'Prompt to send to Claude (also can be passed after --)',
38
+ alias: 'p',
39
+ })
40
+ .option('verbose', {
41
+ type: 'boolean',
42
+ description: 'Enable verbose logging, will emit ./agent-yes.log',
43
+ default: false,
44
+ })
45
+ .option('exit-on-idle', {
46
+ type: 'string',
47
+ description: 'Exit after a period of inactivity, e.g., "5s" or "1m"',
48
+ deprecated: 'use --idle instead',
49
+ default: '60s',
50
+ alias: 'e',
51
+ })
52
+ .option('idle', {
53
+ type: 'string',
54
+ description: 'Exit after a period of inactivity, e.g., "5s" or "1m"',
55
+ alias: 'i',
56
+ })
57
+ .option('queue', {
58
+ type: 'boolean',
59
+ description:
60
+ 'Queue Agent when spawning multiple agents in the same directory/repo, can be disabled with --no-queue',
61
+ default: true,
62
+ })
63
+ .positional('cli', {
64
+ describe:
65
+ 'The AI CLI to run, e.g., claude, codex, copilot, cursor, gemini',
66
+ type: 'string',
67
+ choices: SUPPORTED_CLIS,
68
+ demandOption: false,
69
+ default: cliName,
70
+ })
71
+ .help()
72
+ .version()
73
+ .parserConfiguration({
74
+ 'unknown-options-as-args': true,
75
+ 'halt-at-non-option': true,
76
+ })
77
+ .parseSync();
78
+
79
+ // Extract cli args and dash prompt (same logic as cli.ts:76-91)
80
+ const optionalIndex = (e: number) => (0 <= e ? e : undefined);
81
+ const rawArgs = argv.slice(2);
82
+ const cliArgIndex = optionalIndex(rawArgs.indexOf(String(parsedArgv._[0])));
83
+ const dashIndex = optionalIndex(rawArgs.indexOf('--'));
84
+
85
+ const cliArgsForSpawn = parsedArgv._[0]
86
+ ? rawArgs.slice(cliArgIndex ?? 0, dashIndex ?? undefined)
87
+ : [];
88
+ const dashPrompt: string | undefined = dashIndex
89
+ ? rawArgs.slice(dashIndex + 1).join(' ')
90
+ : undefined;
91
+
92
+ // Return the config object that would be passed to cliYes (same logic as cli.ts:99-121)
93
+ return {
94
+ cli: (cliName ||
95
+ parsedArgv.cli ||
96
+ parsedArgv._[0]
97
+ ?.toString()
98
+ ?.replace?.(/-yes$/, '')) as (typeof SUPPORTED_CLIS)[number],
99
+ cliArgs: cliArgsForSpawn,
100
+ prompt: [parsedArgv.prompt, dashPrompt].join(' ').trim() || undefined,
101
+ exitOnIdle: Number(
102
+ (parsedArgv.idle || parsedArgv.exitOnIdle)?.replace(/.*/, (e) =>
103
+ String(enhancedMs(e)),
104
+ ) || 0,
105
+ ),
106
+ queue: parsedArgv.queue,
107
+ robust: parsedArgv.robust,
108
+ logFile: parsedArgv.logFile,
109
+ verbose: parsedArgv.verbose,
110
+ };
111
+ }
package/ts/cli.spec.ts DELETED
@@ -1,18 +0,0 @@
1
- import { vi } from 'vitest';
2
-
3
- // Mock cliYes function
4
- const mockCliYes = vi.fn(async ({ prompt }) => {
5
- return { exitCode: 0, logs: 'mocked logs' };
6
- });
7
-
8
- test('CLI args parsing', () => {
9
- const rawArgs = ['claude', '--verbose', '--idle=5m', '--', 'write tests'];
10
- const optionalIndex = (e: number) => (0 <= e ? e : undefined);
11
- const dashIndex = optionalIndex(rawArgs.indexOf('--'));
12
- const dashPrompt = dashIndex
13
- ? rawArgs.slice(dashIndex + 1).join(' ')
14
- : undefined;
15
-
16
- expect(dashPrompt).toBe('write tests');
17
- expect(mockCliYes).toBeDefined();
18
- });