-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathdo.mjs
More file actions
executable file
·47 lines (40 loc) · 1.7 KB
/
Copy pathdo.mjs
File metadata and controls
executable file
·47 lines (40 loc) · 1.7 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
#!/usr/bin/env node
import { ensureUseM } from './src/use-m-bootstrap.lib.mjs';
// Use use-m to dynamically import modules for cross-runtime compatibility
const use = await ensureUseM();
// Use command-stream for consistent $ behavior across runtimes
const { $ } = await use('command-stream');
const { getLinoYargsFactory, hideBin, parseCliArgumentsWithLino } = await import('./src/cli-arguments.lib.mjs');
// Configure command line arguments - prompt as positional argument
const createDoYargsConfig = yargsInstance =>
yargsInstance
.usage('Usage: $0 <prompt>')
.command('$0 <prompt>', 'Send a prompt to Claude', yargs =>
yargs.positional('prompt', {
type: 'string',
description: 'The prompt to send to Claude',
})
)
.demandCommand(1, 'The prompt is required')
.help('h')
.alias('h', 'help');
if (process.argv.includes('--help') || process.argv.includes('-h')) {
const helpYargs = createDoYargsConfig(getLinoYargsFactory()(hideBin(process.argv)));
helpYargs.showHelp();
process.exit(0);
}
const argv = parseCliArgumentsWithLino({
argv: process.argv,
commandName: 'do.mjs',
createYargsConfig: createDoYargsConfig,
positionalAliases: ['prompt'],
});
const prompt = argv.prompt || argv._[0];
const claudePath = process.env.CLAUDE_PATH || '/Users/konard/.claude/local/claude';
try {
const result = await $`${claudePath} -p "${prompt}" --output-format stream-json --verbose --dangerously-skip-permissions --append-system-prompt "Code changes should be tested before finishing the work, preferably with automated tests." --model sonnet | jq`;
console.log(result.text());
} catch (error) {
console.error('Error executing command:', error.message);
process.exit(1);
}