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

Function offerWatchFallback

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

Source from the content-addressed store, hash-verified

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

Callers 1

runInitFunction · 0.85

Calls 7

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

Tested by

no test coverage detected