MCPcopy Create free account
hub / github.com/IAmUnbounded/devctx / watchCommand

Function watchCommand

devctx/src/commands/watch.ts:18–119  ·  view source on GitHub ↗
(options?: { interval?: string })

Source from the content-addressed store, hash-verified

16import { loadConfig } from "../utils/config";
17
18export 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(),

Callers

nothing calls this directly

Calls 12

isInitializedFunction · 0.90
loadConfigFunction · 0.90
getRepoRootFunction · 0.90
getDevCtxDirFunction · 0.90
getCurrentBranchFunction · 0.90
getRepoNameFunction · 0.90
getChangedFilesFunction · 0.90
getStagedFilesFunction · 0.90
getRecentCommitsFunction · 0.90
getAuthorFunction · 0.90
saveContextFunction · 0.90

Tested by

no test coverage detected