Open History to see the last commit
1/** Placeholder swapped for the schema JSON after the runner reads the files. */
2export const CLAUDE_JSON_SCHEMA_PLACEHOLDER = '__TANSTACK_SCHEMA__'
3
4/**
5 * Written into the sandbox and run with `node`.
6 *
7 * The shell only sees two filenames. The runner reads the argv array and the
8 * schema JSON from those files, then spawn()s claude so `--json-schema` is a
9 * real argv value (the CLI rejects a file path).
10 *
11 * On Windows, `claude` is often a `.cmd` shim. `spawn(cmd, args)` without a
12 * shell cannot find that shim, so we go through `sh` with `"$0"` / `"$@"`
13 * (git-bash is already on PATH in the local-process sandbox).
14 */
15export const CLAUDE_RUNNER_SOURCE = `import { spawn } from 'node:child_process'
16import { readFileSync } from 'node:fs'
17
18const argvFile = process.argv[2]
19if (!argvFile) {
20 console.error('tanstack-claude-run: missing argv file')
21 process.exit(1)
22}
23
24const argv = JSON.parse(readFileSync(argvFile, 'utf8'))
25if (!Array.isArray(argv)) {
26 console.error('tanstack-claude-run: argv file must be a JSON array')
27 process.exit(1)
28}
29
30const schemaFile = process.argv[3]
31if (schemaFile) {
32 const schema = readFileSync(schemaFile, 'utf8')
33 for (let i = 0; i < argv.length; i++) {
34 if (argv[i] === ${JSON.stringify(CLAUDE_JSON_SCHEMA_PLACEHOLDER)}) argv[i] = schema
35 }
36}
37
38const [cmd, ...args] = argv
39if (typeof cmd !== 'string' || cmd === '') {
40 console.error('tanstack-claude-run: missing command')
41 process.exit(1)
42}
43
44const opts = {
45 stdio: ['pipe', 'pipe', 'pipe'],
46 env: process.env,
47 windowsHide: true,
48}
49
50const child =
51 process.platform === 'win32'
52 ? spawn('sh', ['-c', 'exec "$0" "$@"', cmd, ...args], opts)
53 : spawn(cmd, args, opts)
54
55process.stdin.pipe(child.stdin)
56child.stdout.pipe(process.stdout)
57child.stderr.pipe(process.stderr)
58child.on('error', (error) => {
59 console.error(error)
60 process.exit(1)
61})
62child.on('exit', (code, signal) => {
63 if (signal) process.exit(1)
64 process.exit(code ?? 1)
65})
66`