(options?: { interval?: string })
| 16 | import { loadConfig } from "../utils/config"; |
| 17 | |
| 18 | export async function watchCommand(options?: { interval?: string }) { |
| 19 | if (!(await isInitialized())) { |
| 20 | console.log(chalk.red("✗ DevContext not initialized. Run `devctx init` first.")); |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | try { |
| 25 | const config = await loadConfig(); |
| 26 | const intervalMinutes = parseInt(options?.interval || String(config.watchInterval), 10); |
| 27 | const intervalMs = intervalMinutes * 60 * 1000; |
| 28 | const root = await getRepoRoot(); |
| 29 | const devctxDir = await getDevCtxDir(); |
| 30 | |
| 31 | let changeCount = 0; |
| 32 | let lastSave = Date.now(); |
| 33 | |
| 34 | console.log(chalk.green("👁 Watch mode started")); |
| 35 | console.log(chalk.gray(` Auto-save every ${intervalMinutes} minutes when changes detected`)); |
| 36 | console.log(chalk.gray(` Watching: ${root}`)); |
| 37 | console.log(chalk.gray(" Press Ctrl+C to stop\n")); |
| 38 | |
| 39 | const watcher = chokidar.watch(root, { |
| 40 | ignored: [ |
| 41 | /(^|[\/\\])\../, // dotfiles |
| 42 | "**/node_modules/**", |
| 43 | "**/dist/**", |
| 44 | "**/build/**", |
| 45 | "**/.devctx/**", |
| 46 | "**/package-lock.json", |
| 47 | ], |
| 48 | persistent: true, |
| 49 | ignoreInitial: true, |
| 50 | }); |
| 51 | |
| 52 | watcher.on("all", (_event: string, _filePath: string) => { |
| 53 | changeCount++; |
| 54 | }); |
| 55 | |
| 56 | // Periodic auto-save |
| 57 | const timer = setInterval(async () => { |
| 58 | if (changeCount === 0) return; |
| 59 | |
| 60 | try { |
| 61 | const [branch, repo, filesChanged, filesStaged, recentCommits, author] = |
| 62 | await Promise.all([ |
| 63 | getCurrentBranch(), |
| 64 | getRepoName(), |
| 65 | getChangedFiles(), |
| 66 | getStagedFiles(), |
| 67 | getRecentCommits(), |
| 68 | getAuthor(), |
| 69 | ]); |
| 70 | |
| 71 | // Try to enrich from editor session data |
| 72 | const chatContext = await extractFromEditorSessions(root); |
| 73 | |
| 74 | const entry: ContextEntry = { |
| 75 | id: uuid(), |
nothing calls this directly
no test coverage detected