(binary, { home, repoPath, project, mode = 'full' })
| 70 | * und genau das haelt der Beweislauf hier fest. |
| 71 | */ |
| 72 | export async function indexRepository(binary, { home, repoPath, project, mode = 'full' }) { |
| 73 | const started = Date.now(); |
| 74 | const payload = JSON.stringify({ repo_path: repoPath, name: project, mode }); |
| 75 | const result = await new Promise((resolve, reject) => { |
| 76 | const child = spawn(binary, ['cli', 'index_repository'], { |
| 77 | env: { ...process.env, HOME: home }, |
| 78 | stdio: ['pipe', 'pipe', 'pipe'], |
| 79 | }); |
| 80 | let out = ''; |
| 81 | let err = ''; |
| 82 | child.stdout.on('data', (d) => { out += d.toString(); }); |
| 83 | child.stderr.on('data', (d) => { err += d.toString(); }); |
| 84 | child.on('error', reject); |
| 85 | child.on('close', (code) => resolve({ code, out, err })); |
| 86 | child.stdin.end(payload + '\n'); |
| 87 | }); |
| 88 | |
| 89 | const line = result.out.split('\n').map((l) => l.trim()).filter(Boolean).pop(); |
| 90 | if (!line) { |
| 91 | throw new Error( |
| 92 | `index_repository lieferte keine Ausgabe (exit ${result.code}): ${result.err.trim()}`, |
| 93 | ); |
| 94 | } |
| 95 | let parsed; |
| 96 | try { |
| 97 | parsed = JSON.parse(line); |
| 98 | } catch { |
| 99 | throw new Error(`index_repository lieferte kein JSON: ${line.slice(0, 400)}`); |
| 100 | } |
| 101 | if (parsed.status !== 'indexed' && parsed.nodes === undefined) { |
| 102 | throw new Error(`index_repository status=${parsed.status}: ${line.slice(0, 400)}`); |
| 103 | } |
| 104 | return { ...parsed, durationMs: Date.now() - started, stderr: result.err.trim() }; |
| 105 | } |
| 106 | |
| 107 | const INITIALIZE = JSON.stringify({ |
| 108 | jsonrpc: '2.0', |
nothing calls this directly
no outgoing calls
no test coverage detected