(
clack: typeof import('@clack/prompts'),
projectPath: string,
opts: { yes?: boolean } = {},
)
| 679 | * call unconditionally after init. |
| 680 | */ |
| 681 | export async function offerWatchFallback( |
| 682 | clack: typeof import('@clack/prompts'), |
| 683 | projectPath: string, |
| 684 | opts: { yes?: boolean } = {}, |
| 685 | ): Promise<void> { |
| 686 | const reason = watchDisabledReason(projectPath); |
| 687 | if (!reason) return; // Watcher runs normally — nothing to set up. |
| 688 | |
| 689 | clack.log.warn(`Live file watching is disabled here — ${reason}.`); |
| 690 | clack.log.info('Until you re-sync, the CodeGraph index stays frozen — it will not pick up edits on its own.'); |
| 691 | |
| 692 | // No git repo → the commit-hook path doesn't apply; point at manual sync. |
| 693 | if (!isGitRepo(projectPath)) { |
| 694 | clack.log.info('Run `codegraph sync` after changing files to refresh the index.'); |
| 695 | return; |
| 696 | } |
| 697 | |
| 698 | // Already wired up on a previous run — confirm and move on without nagging. |
| 699 | if (isSyncHookInstalled(projectPath)) { |
| 700 | clack.log.info('Git sync hooks are already installed — the index refreshes after commit / pull / checkout.'); |
| 701 | return; |
| 702 | } |
| 703 | |
| 704 | let choice: 'hook' | 'manual'; |
| 705 | if (opts.yes) { |
| 706 | choice = 'hook'; |
| 707 | } else { |
| 708 | const sel = await clack.select({ |
| 709 | message: 'How should CodeGraph keep its index fresh?', |
| 710 | options: [ |
| 711 | { value: 'hook' as const, label: 'Sync on git commit / pull / checkout', hint: 'installs git hooks (recommended)' }, |
| 712 | { value: 'manual' as const, label: 'I\'ll run `codegraph sync` myself', hint: 'fully manual' }, |
| 713 | ], |
| 714 | initialValue: 'hook' as const, |
| 715 | }); |
| 716 | if (clack.isCancel(sel)) { |
| 717 | clack.log.info('Skipped — run `codegraph sync` after changes to refresh the index.'); |
| 718 | return; |
| 719 | } |
| 720 | choice = sel; |
| 721 | } |
| 722 | |
| 723 | if (choice === 'manual') { |
| 724 | clack.log.info('Run `codegraph sync` after changing files to refresh the index.'); |
| 725 | return; |
| 726 | } |
| 727 | |
| 728 | const result = installGitSyncHook(projectPath); |
| 729 | if (result.installed.length > 0) { |
| 730 | clack.log.success( |
| 731 | `Installed git ${result.installed.join(', ')} hook${result.installed.length > 1 ? 's' : ''} — ` + |
| 732 | 'the index refreshes in the background after each.', |
| 733 | ); |
| 734 | clack.log.info('Run `codegraph sync` anytime to refresh immediately.'); |
| 735 | } else { |
| 736 | clack.log.warn( |
| 737 | `Could not install git hooks${result.skipped ? ` (${result.skipped})` : ''}. ` + |
| 738 | 'Run `codegraph sync` after changes instead.', |
no test coverage detected