(loc: Location)
| 427 | * only calls this when the user accepts the prompt (default-yes). |
| 428 | */ |
| 429 | export function writePromptHookEntry(loc: Location): WriteResult['files'][number] { |
| 430 | const file = settingsJsonPath(loc); |
| 431 | const created = !fs.existsSync(file); |
| 432 | const settings = readJsonFile(file); |
| 433 | |
| 434 | if (!settings.hooks || typeof settings.hooks !== 'object' || Array.isArray(settings.hooks)) { |
| 435 | settings.hooks = {}; |
| 436 | } |
| 437 | if (!Array.isArray(settings.hooks.UserPromptSubmit)) settings.hooks.UserPromptSubmit = []; |
| 438 | |
| 439 | // Self-heal (#1466): a pre-fix install on Windows wrote the bare |
| 440 | // `codegraph prompt-hook`, which Git Bash resolves to nothing; a |
| 441 | // settings.json carried across platforms can hold the other spelling too. |
| 442 | // Rewrite an installer-written command to this platform's form in place. |
| 443 | // Only the exact installer spellings migrate — an `npx …` or hand-edited |
| 444 | // variant is the user's own and stays untouched. |
| 445 | let migrated = false; |
| 446 | for (const group of settings.hooks.UserPromptSubmit) { |
| 447 | if (!group || !Array.isArray(group.hooks)) continue; |
| 448 | for (const h of group.hooks) { |
| 449 | if (h && PROMPT_HOOK_FORMS.includes(h.command) && h.command !== PROMPT_HOOK_COMMAND) { |
| 450 | h.command = PROMPT_HOOK_COMMAND; |
| 451 | migrated = true; |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | const already = settings.hooks.UserPromptSubmit.some( |
| 457 | (g: any) => g && Array.isArray(g.hooks) && g.hooks.some((h: any) => isPromptHookCommand(h?.command)), |
| 458 | ); |
| 459 | if (already) { |
| 460 | if (!migrated) return { path: file, action: 'unchanged' }; |
| 461 | writeJsonFile(file, settings); |
| 462 | return { path: file, action: 'updated' }; |
| 463 | } |
| 464 | |
| 465 | settings.hooks.UserPromptSubmit.push({ |
| 466 | hooks: [{ type: 'command', command: PROMPT_HOOK_COMMAND }], |
| 467 | }); |
| 468 | writeJsonFile(file, settings); |
| 469 | return { path: file, action: created ? 'created' : 'updated' }; |
| 470 | } |
| 471 | |
| 472 | /** |
| 473 | * Strip the marker-delimited CodeGraph block from CLAUDE.md if a prior |
no test coverage detected