MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / offerWatchFallback

Function offerWatchFallback

src/installer/index.ts:660–720  ·  view source on GitHub ↗
(
  clack: typeof import('@clack/prompts'),
  projectPath: string,
  opts: { yes?: boolean } = {},
)

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.85

Calls 6

watchDisabledReasonFunction · 0.90
isGitRepoFunction · 0.90
isSyncHookInstalledFunction · 0.90
installGitSyncHookFunction · 0.90
warnMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected