MCPcopy Create free account
hub / github.com/SethGammon/Citadel / main

Function main

hooks_src/instructions-loaded.js:45–107  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

43}
44
45function main() {
46 let input = '';
47 process.stdin.setEncoding('utf8');
48 process.stdin.on('data', (chunk) => { input += chunk; });
49 process.stdin.on('end', () => {
50 let event = {};
51 try { event = JSON.parse(input); } catch { /* partial input ok */ }
52
53 const filePath = event.file_path || event.path || null;
54 const sessionId = event.session_id || null;
55
56 health.increment('instructions-loaded', 'count');
57
58 health.logTiming('instructions-loaded', 0, {
59 event: 'instructions-loaded',
60 file: filePath ? path.relative(PROJECT_ROOT, filePath).replace(/\\/g, '/') : null,
61 session_id: sessionId,
62 });
63
64 if (!filePath) {
65 process.exit(0);
66 return;
67 }
68
69 const relativePath = path.relative(PROJECT_ROOT, filePath).replace(/\\/g, '/');
70
71 // Check if the file has changed since we last saw it
72 try {
73 const state = readState();
74 let mtime = null;
75 try {
76 mtime = fs.statSync(filePath).mtimeMs;
77 } catch { /* file may be virtual */ }
78
79 const lastSeen = state[relativePath] || null;
80 const changed = mtime !== null && lastSeen !== null && mtime > lastSeen;
81
82 if (changed) {
83 // Queue a doc-sync review for this file
84 const queuePath = path.join(TELEMETRY_DIR, 'doc-sync-queue.jsonl');
85 if (fs.existsSync(TELEMETRY_DIR)) {
86 const entry = JSON.stringify({
87 event: 'instructions-changed',
88 file: relativePath,
89 timestamp: new Date().toISOString(),
90 status: 'needs-review',
91 prev_mtime: lastSeen,
92 curr_mtime: mtime,
93 });
94 fs.appendFileSync(queuePath, entry + '\n');
95 }
96 }
97
98 // Update last-seen mtime
99 if (mtime !== null) {
100 state[relativePath] = mtime;
101 writeState(state);
102 }

Callers 1

Calls 2

readStateFunction · 0.70
writeStateFunction · 0.70

Tested by

no test coverage detected