deepflow 0.1.105 → 0.1.107

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,6 +18,7 @@
18
18
  const fs = require('fs');
19
19
  const path = require('path');
20
20
  const os = require('os');
21
+ const { readStdinIfMain } = require('./lib/hook-stdin');
21
22
 
22
23
  /**
23
24
  * Locate the explore-protocol.md template.
@@ -34,50 +35,40 @@ function findProtocol(cwd) {
34
35
  return null;
35
36
  }
36
37
 
37
- let raw = '';
38
- process.stdin.setEncoding('utf8');
39
- process.stdin.on('data', chunk => raw += chunk);
40
- process.stdin.on('end', () => {
41
- try {
42
- const payload = JSON.parse(raw);
43
- const { tool_name, tool_input, cwd } = payload;
38
+ readStdinIfMain(module, (payload) => {
39
+ const { tool_name, tool_input, cwd } = payload;
44
40
 
45
- // Only intercept Agent calls with subagent_type "Explore"
46
- if (tool_name !== 'Agent') {
47
- process.exit(0);
48
- }
49
- const subagentType = (tool_input.subagent_type || '').toLowerCase();
50
- if (subagentType !== 'explore') {
51
- process.exit(0);
52
- }
41
+ // Only intercept Agent calls with subagent_type "Explore"
42
+ if (tool_name !== 'Agent') {
43
+ return;
44
+ }
45
+ const subagentType = (tool_input.subagent_type || '').toLowerCase();
46
+ if (subagentType !== 'explore') {
47
+ return;
48
+ }
53
49
 
54
- const protocolPath = findProtocol(cwd || process.cwd());
55
- if (!protocolPath) {
56
- // No template found — allow without modification
57
- process.exit(0);
58
- }
50
+ const protocolPath = findProtocol(cwd || process.cwd());
51
+ if (!protocolPath) {
52
+ // No template found — allow without modification
53
+ return;
54
+ }
59
55
 
60
- const protocol = fs.readFileSync(protocolPath, 'utf8').trim();
61
- const originalPrompt = tool_input.prompt || '';
56
+ const protocol = fs.readFileSync(protocolPath, 'utf8').trim();
57
+ const originalPrompt = tool_input.prompt || '';
62
58
 
63
- // Append protocol as a system-level suffix the agent must follow
64
- const updatedPrompt = `${originalPrompt}\n\n---\n## Search Protocol (auto-injected — MUST follow)\n\n${protocol}`;
59
+ // Append protocol as a system-level suffix the agent must follow
60
+ const updatedPrompt = `${originalPrompt}\n\n---\n## Search Protocol (auto-injected — MUST follow)\n\n${protocol}`;
65
61
 
66
- const result = {
67
- hookSpecificOutput: {
68
- hookEventName: 'PreToolUse',
69
- permissionDecision: 'allow',
70
- updatedInput: {
71
- ...tool_input,
72
- prompt: updatedPrompt,
73
- },
62
+ const result = {
63
+ hookSpecificOutput: {
64
+ hookEventName: 'PreToolUse',
65
+ permissionDecision: 'allow',
66
+ updatedInput: {
67
+ ...tool_input,
68
+ prompt: updatedPrompt,
74
69
  },
75
- };
70
+ },
71
+ };
76
72
 
77
- process.stdout.write(JSON.stringify(result));
78
- process.exit(0);
79
- } catch {
80
- // Never break Claude Code
81
- process.exit(0);
82
- }
73
+ process.stdout.write(JSON.stringify(result));
83
74
  });
@@ -18,6 +18,7 @@ const fs = require('fs');
18
18
  const path = require('path');
19
19
  const { execFileSync } = require('child_process');
20
20
  const { extractSection } = require('./df-spec-lint');
21
+ const { readStdinIfMain } = require('./lib/hook-stdin');
21
22
 
22
23
  // ── LSP availability check (REQ-5, AC-11) ────────────────────────────────────
23
24
 
@@ -141,6 +142,7 @@ const TAGS = {
141
142
  STUB: 'STUB', // Incomplete stub left in production code
142
143
  PHANTOM: 'PHANTOM', // Reference to non-existent symbol/file/function
143
144
  SCOPE_GAP: 'SCOPE_GAP', // Implementation goes beyond or falls short of spec scope
145
+ CONFIG_GUARD: 'CONFIG_GUARD', // config.yaml/yml modified inside a worktree path
144
146
  };
145
147
 
146
148
  // ── Diff parsing ──────────────────────────────────────────────────────────────
@@ -947,6 +949,43 @@ function formatOutput(results) {
947
949
 
948
950
  // ── Core API ──────────────────────────────────────────────────────────────────
949
951
 
952
+ /**
953
+ * REQ-3: Guard against creation or modification of .deepflow/config.yaml (or config.yml)
954
+ * inside worktree paths. Agents must never alter project-level config from a worktree.
955
+ *
956
+ * Matches `+++ b/` diff header lines whose path contains `.deepflow/config.yaml` or
957
+ * `.deepflow/config.yml`, regardless of worktree depth.
958
+ *
959
+ * Always HARD severity — no advisory variant. Tag: [CONFIG_GUARD]
960
+ *
961
+ * @param {Array} files - Parsed diff files
962
+ * @param {string} specContent - Raw spec markdown (unused, kept for uniform signature)
963
+ * @param {string} taskType - Task type (unused, check always runs)
964
+ * @returns {Array<{ file: string, line: number, tag: string, description: string }>}
965
+ */
966
+ function checkConfigYamlGuard(files, specContent, taskType) { // eslint-disable-line no-unused-vars
967
+ const violations = [];
968
+
969
+ // Pattern matches .deepflow/config.yaml or .deepflow/config.yml anywhere in the path,
970
+ // which covers worktree sub-paths like .claude/worktrees/agent-xyz/.deepflow/config.yaml
971
+ const CONFIG_PATTERN = /\.deepflow\/config\.ya?ml$/;
972
+
973
+ for (const f of files) {
974
+ if (CONFIG_PATTERN.test(f.file)) {
975
+ violations.push({
976
+ file: f.file,
977
+ line: 1,
978
+ tag: TAGS.CONFIG_GUARD,
979
+ description:
980
+ `[CONFIG_GUARD] Modification of "${f.file}" detected inside a worktree. ` +
981
+ 'Agents must not create or modify .deepflow/config.yaml from within a worktree.',
982
+ });
983
+ }
984
+ }
985
+
986
+ return violations;
987
+ }
988
+
950
989
  /**
951
990
  * Check implementation diffs against spec invariants.
952
991
  *
@@ -1011,6 +1050,10 @@ function checkInvariants(diff, specContent, opts = {}) {
1011
1050
  const reqOnlyInTestsViolations = checkReqOnlyInTests(files, specContent, taskType);
1012
1051
  hard.push(...reqOnlyInTestsViolations);
1013
1052
 
1053
+ // REQ-3: config.yaml guard — always hard, no advisory variant
1054
+ const configGuardViolations = checkConfigYamlGuard(files, specContent, taskType);
1055
+ hard.push(...configGuardViolations);
1056
+
1014
1057
  // ── Auto-mode escalation (REQ-9) ─────────────────────────────────────────
1015
1058
  // In auto mode (non-interactive CI/hook runs), all advisory items are promoted
1016
1059
  // to hard failures so the pipeline blocks on any violation.
@@ -1080,78 +1123,63 @@ function isGitCommitBash(toolName, toolInput) {
1080
1123
  return /git\s+commit\b/.test(cmd);
1081
1124
  }
1082
1125
 
1083
- // Run hook mode when stdin is not a TTY (i.e., piped payload from Claude Code)
1084
- if (!process.stdin.isTTY) {
1085
- let raw = '';
1086
- process.stdin.setEncoding('utf8');
1087
- process.stdin.on('data', (chunk) => { raw += chunk; });
1088
- process.stdin.on('end', () => {
1089
- let data;
1090
- try {
1091
- data = JSON.parse(raw);
1092
- } catch (_) {
1093
- // Not valid JSON — not a hook payload, exit silently
1094
- process.exit(0);
1095
- }
1126
+ // Run hook mode when called as main module (stdin payload from Claude Code).
1127
+ // readStdinIfMain guards against hanging when required by tests.
1128
+ readStdinIfMain(module, (data) => {
1129
+ // CLI --invariants mode is handled separately below; if we're here,
1130
+ // we got a JSON payload on stdin (PostToolUse hook invocation).
1131
+ if (process.argv.includes('--invariants')) return;
1096
1132
 
1097
- try {
1098
- const toolName = data.tool_name || '';
1099
- const toolInput = data.tool_input || {};
1133
+ const toolName = data.tool_name || '';
1134
+ const toolInput = data.tool_input || {};
1100
1135
 
1101
- // Only run after a git commit bash call
1102
- if (!isGitCommitBash(toolName, toolInput)) {
1103
- process.exit(0);
1104
- }
1136
+ // Only run after a git commit bash call
1137
+ if (!isGitCommitBash(toolName, toolInput)) {
1138
+ process.exit(0);
1139
+ }
1105
1140
 
1106
- const cwd = data.cwd || process.cwd();
1141
+ const cwd = data.cwd || process.cwd();
1107
1142
 
1108
- const diff = extractDiffFromLastCommit(cwd);
1109
- if (!diff) {
1110
- // No diff available (e.g. initial commit) — pass through
1111
- process.exit(0);
1112
- }
1143
+ const diff = extractDiffFromLastCommit(cwd);
1144
+ if (!diff) {
1145
+ // No diff available (e.g. initial commit) — pass through
1146
+ process.exit(0);
1147
+ }
1113
1148
 
1114
- const specContent = loadActiveSpec(cwd);
1115
- if (!specContent) {
1116
- // No active spec found — not a deepflow project or no spec in progress
1117
- process.exit(0);
1118
- }
1149
+ const specContent = loadActiveSpec(cwd);
1150
+ if (!specContent) {
1151
+ // No active spec found — not a deepflow project or no spec in progress
1152
+ process.exit(0);
1153
+ }
1119
1154
 
1120
- const results = checkInvariants(diff, specContent, { mode: 'auto', taskType: 'implementation', projectRoot: cwd });
1155
+ const results = checkInvariants(diff, specContent, { mode: 'auto', taskType: 'implementation', projectRoot: cwd });
1121
1156
 
1122
- if (results.hard.length > 0) {
1123
- console.error('[df-invariant-check] Hard invariant failures detected:');
1124
- const outputLines = formatOutput(results);
1125
- for (const line of outputLines) {
1126
- if (results.hard.some((v) => formatViolation(v) === line)) {
1127
- console.error(` ${line}`);
1128
- }
1129
- }
1130
- process.exit(1);
1131
- }
1132
-
1133
- if (results.advisory.length > 0) {
1134
- console.warn('[df-invariant-check] Advisory warnings:');
1135
- for (const v of results.advisory) {
1136
- console.warn(` ${formatViolation(v)}`);
1137
- }
1157
+ if (results.hard.length > 0) {
1158
+ console.error('[df-invariant-check] Hard invariant failures detected:');
1159
+ const outputLines = formatOutput(results);
1160
+ for (const line of outputLines) {
1161
+ if (results.hard.some((v) => formatViolation(v) === line)) {
1162
+ console.error(` ${line}`);
1138
1163
  }
1164
+ }
1165
+ process.exit(1);
1166
+ }
1139
1167
 
1140
- process.exit(0);
1141
- } catch (_err) {
1142
- // Unexpected error fail open so we never break non-deepflow projects
1143
- process.exit(0);
1168
+ if (results.advisory.length > 0) {
1169
+ console.warn('[df-invariant-check] Advisory warnings:');
1170
+ for (const v of results.advisory) {
1171
+ console.warn(` ${formatViolation(v)}`);
1144
1172
  }
1145
- });
1146
- } else {
1173
+ }
1174
+ });
1147
1175
 
1148
1176
  // ── CLI entry point (REQ-6) ───────────────────────────────────────────────────
1149
- if (require.main === module) {
1177
+ if (require.main === module && process.argv.includes('--invariants')) {
1150
1178
  const args = process.argv.slice(2);
1151
1179
 
1152
1180
  // Parse --invariants <spec-path> <diff-file>
1153
1181
  const invariantsIdx = args.indexOf('--invariants');
1154
- if (invariantsIdx === -1 || args.length < invariantsIdx + 3) {
1182
+ if (args.length < invariantsIdx + 3) {
1155
1183
  console.error('Usage: df-invariant-check.js --invariants <spec-file.md> <diff-file>');
1156
1184
  console.error('');
1157
1185
  console.error('Options:');
@@ -1216,8 +1244,6 @@ if (require.main === module) {
1216
1244
  process.exit(results.hard.length > 0 ? 1 : 0);
1217
1245
  }
1218
1246
 
1219
- } // end else (TTY / CLI mode)
1220
-
1221
1247
  module.exports = {
1222
1248
  checkInvariants,
1223
1249
  checkLspAvailability,
@@ -1231,4 +1257,5 @@ module.exports = {
1231
1257
  checkReqOnlyInTests,
1232
1258
  checkPhantoms,
1233
1259
  checkScopeGaps,
1260
+ checkConfigYamlGuard,
1234
1261
  };
@@ -15,7 +15,7 @@ const assert = require('node:assert/strict');
15
15
  const fs = require('node:fs');
16
16
  const path = require('node:path');
17
17
 
18
- const { isBinaryAvailable } = require('./df-invariant-check');
18
+ const { isBinaryAvailable, checkConfigYamlGuard } = require('./df-invariant-check');
19
19
 
20
20
  const HOOK_SOURCE = fs.readFileSync(
21
21
  path.resolve(__dirname, 'df-invariant-check.js'),
@@ -139,3 +139,177 @@ describe('extractDiffFromLastCommit implementation', () => {
139
139
  );
140
140
  });
141
141
  });
142
+
143
+ // ---------------------------------------------------------------------------
144
+ // 4. checkConfigYamlGuard — config.yaml/yml modification detection
145
+ // ---------------------------------------------------------------------------
146
+
147
+ describe('checkConfigYamlGuard', () => {
148
+ // Helper: build a minimal parsed-file object matching the shape used by check functions
149
+ function makeFiles(...paths) {
150
+ return paths.map((p) => ({ file: p, chunks: [] }));
151
+ }
152
+
153
+ test('detects .deepflow/config.yaml modification as HARD violation', () => {
154
+ const files = makeFiles('.deepflow/config.yaml');
155
+ const violations = checkConfigYamlGuard(files, '', 'implementation');
156
+
157
+ assert.equal(violations.length, 1);
158
+ assert.equal(violations[0].tag, 'CONFIG_GUARD');
159
+ assert.equal(violations[0].file, '.deepflow/config.yaml');
160
+ assert.equal(violations[0].line, 1);
161
+ assert.ok(violations[0].description.includes('[CONFIG_GUARD]'));
162
+ });
163
+
164
+ test('detects .deepflow/config.yml variant as HARD violation', () => {
165
+ const files = makeFiles('.deepflow/config.yml');
166
+ const violations = checkConfigYamlGuard(files, '', 'implementation');
167
+
168
+ assert.equal(violations.length, 1);
169
+ assert.equal(violations[0].tag, 'CONFIG_GUARD');
170
+ assert.equal(violations[0].file, '.deepflow/config.yml');
171
+ });
172
+
173
+ test('detects config.yaml inside a worktree sub-path', () => {
174
+ const worktreePath = '.claude/worktrees/agent-abc123/.deepflow/config.yaml';
175
+ const files = makeFiles(worktreePath);
176
+ const violations = checkConfigYamlGuard(files, '', 'implementation');
177
+
178
+ assert.equal(violations.length, 1);
179
+ assert.equal(violations[0].tag, 'CONFIG_GUARD');
180
+ assert.equal(violations[0].file, worktreePath);
181
+ });
182
+
183
+ test('detects config.yml inside a deeply nested worktree path', () => {
184
+ const deepPath = 'some/deep/path/.deepflow/config.yml';
185
+ const files = makeFiles(deepPath);
186
+ const violations = checkConfigYamlGuard(files, '', 'implementation');
187
+
188
+ assert.equal(violations.length, 1);
189
+ assert.equal(violations[0].tag, 'CONFIG_GUARD');
190
+ });
191
+
192
+ test('returns no violations for non-config files', () => {
193
+ const files = makeFiles(
194
+ 'src/index.js',
195
+ 'hooks/df-invariant-check.js',
196
+ 'package.json',
197
+ '.deepflow/decisions.md'
198
+ );
199
+ const violations = checkConfigYamlGuard(files, '', 'implementation');
200
+
201
+ assert.equal(violations.length, 0);
202
+ });
203
+
204
+ test('ignores files that partially match but are not config.yaml/yml', () => {
205
+ const files = makeFiles(
206
+ '.deepflow/config.yaml.bak',
207
+ '.deepflow/config.yamls',
208
+ '.deepflow/my-config.yaml',
209
+ 'config.yaml' // not under .deepflow/
210
+ );
211
+ const violations = checkConfigYamlGuard(files, '', 'implementation');
212
+
213
+ assert.equal(violations.length, 0);
214
+ });
215
+
216
+ test('returns one violation per matching file when multiple configs present', () => {
217
+ const files = makeFiles(
218
+ '.deepflow/config.yaml',
219
+ '.claude/worktrees/agent-xyz/.deepflow/config.yml'
220
+ );
221
+ const violations = checkConfigYamlGuard(files, '', 'implementation');
222
+
223
+ assert.equal(violations.length, 2);
224
+ assert.equal(violations[0].tag, 'CONFIG_GUARD');
225
+ assert.equal(violations[1].tag, 'CONFIG_GUARD');
226
+ });
227
+
228
+ test('returns empty array when files list is empty', () => {
229
+ const violations = checkConfigYamlGuard([], '', 'implementation');
230
+ assert.equal(violations.length, 0);
231
+ });
232
+
233
+ test('works regardless of specContent and taskType arguments', () => {
234
+ const files = makeFiles('.deepflow/config.yaml');
235
+
236
+ // Different specContent and taskType should not affect the result
237
+ const v1 = checkConfigYamlGuard(files, 'some spec content', 'spike');
238
+ const v2 = checkConfigYamlGuard(files, '', 'bootstrap');
239
+
240
+ assert.equal(v1.length, 1);
241
+ assert.equal(v2.length, 1);
242
+ });
243
+
244
+ test('violation description mentions the offending file path', () => {
245
+ const targetPath = '.claude/worktrees/agent-foo/.deepflow/config.yaml';
246
+ const files = makeFiles(targetPath);
247
+ const violations = checkConfigYamlGuard(files, '', 'implementation');
248
+
249
+ assert.ok(
250
+ violations[0].description.includes(targetPath),
251
+ 'description should include the exact file path'
252
+ );
253
+ });
254
+ });
255
+
256
+ // ---------------------------------------------------------------------------
257
+ // 5. T3 — stdin hang fix: readStdinIfMain guard and no raw stdin listeners
258
+ // ---------------------------------------------------------------------------
259
+
260
+ describe('stdin hang fix (T3)', () => {
261
+ test('source does not contain process.stdin.on calls', () => {
262
+ // The old code used process.stdin.on('data') directly, which caused hangs
263
+ // when the file was required by tests. readStdinIfMain replaces this.
264
+ const lines = HOOK_SOURCE.split('\n');
265
+ const offendingLines = lines.filter((line) => {
266
+ if (line.trimStart().startsWith('//') || line.trimStart().startsWith('*')) return false;
267
+ return /process\.stdin\.on\b/.test(line);
268
+ });
269
+ assert.equal(
270
+ offendingLines.length,
271
+ 0,
272
+ `Found process.stdin.on in source: ${offendingLines.map((l) => l.trim()).join('; ')}`
273
+ );
274
+ });
275
+
276
+ test('source calls readStdinIfMain', () => {
277
+ // readStdinIfMain(module, callback) should be the entry point for stdin reading
278
+ assert.ok(
279
+ /readStdinIfMain\s*\(\s*module\b/.test(HOOK_SOURCE),
280
+ 'source should call readStdinIfMain(module, ...) to guard stdin reading'
281
+ );
282
+ });
283
+
284
+ test('source imports readStdinIfMain from hook-stdin', () => {
285
+ assert.ok(
286
+ /require\(['"]\.\/lib\/hook-stdin['"]\)/.test(HOOK_SOURCE),
287
+ 'source should require ./lib/hook-stdin'
288
+ );
289
+ assert.ok(
290
+ /readStdinIfMain/.test(HOOK_SOURCE),
291
+ 'readStdinIfMain should be destructured from the import'
292
+ );
293
+ });
294
+
295
+ test('--invariants CLI entry point is preserved', () => {
296
+ // The CLI path must still exist: require.main === module && --invariants
297
+ assert.ok(
298
+ /require\.main\s*===\s*module/.test(HOOK_SOURCE),
299
+ 'source should have require.main === module guard for CLI mode'
300
+ );
301
+ assert.ok(
302
+ /--invariants/.test(HOOK_SOURCE),
303
+ 'source should reference --invariants flag'
304
+ );
305
+ });
306
+
307
+ test('requiring the module does not hang (exits immediately)', () => {
308
+ // AC-5: node -e "require('./hooks/df-invariant-check.js')" should exit fast.
309
+ // We already required it at the top of this file without hanging,
310
+ // so reaching this test at all proves require() does not block.
311
+ // Additionally, verify the exported API is still accessible.
312
+ assert.equal(typeof isBinaryAvailable, 'function');
313
+ assert.equal(typeof checkConfigYamlGuard, 'function');
314
+ });
315
+ });
@@ -19,6 +19,7 @@
19
19
 
20
20
  const fs = require('fs');
21
21
  const path = require('path');
22
+ const { readStdinIfMain } = require('./lib/hook-stdin');
22
23
 
23
24
  function loadSnapshotPaths(cwd) {
24
25
  try {
@@ -55,52 +56,43 @@ function isSnapshotFile(filePath, snapshotPaths, cwd) {
55
56
  return false;
56
57
  }
57
58
 
58
- let raw = '';
59
- process.stdin.setEncoding('utf8');
60
- process.stdin.on('data', chunk => { raw += chunk; });
61
- process.stdin.on('end', () => {
62
- try {
63
- const data = JSON.parse(raw);
64
- const toolName = data.tool_name || '';
65
-
66
- // Only guard Write and Edit
67
- if (toolName !== 'Write' && toolName !== 'Edit') {
68
- process.exit(0);
69
- }
59
+ readStdinIfMain(module, (data) => {
60
+ const toolName = data.tool_name || '';
70
61
 
71
- const filePath = (data.tool_input && data.tool_input.file_path) || '';
72
- const cwd = data.cwd || process.cwd();
62
+ // Only guard Write and Edit
63
+ if (toolName !== 'Write' && toolName !== 'Edit') {
64
+ return;
65
+ }
73
66
 
74
- if (!filePath) {
75
- process.exit(0);
76
- }
67
+ const filePath = (data.tool_input && data.tool_input.file_path) || '';
68
+ const cwd = data.cwd || process.cwd();
77
69
 
78
- const snapshotPaths = loadSnapshotPaths(cwd);
70
+ if (!filePath) {
71
+ return;
72
+ }
79
73
 
80
- // No snapshot file present — not a deepflow project or ratchet not initialized
81
- if (snapshotPaths === null) {
82
- process.exit(0);
83
- }
74
+ const snapshotPaths = loadSnapshotPaths(cwd);
84
75
 
85
- // Empty snapshot — nothing to protect
86
- if (snapshotPaths.length === 0) {
87
- process.exit(0);
88
- }
76
+ // No snapshot file present not a deepflow project or ratchet not initialized
77
+ if (snapshotPaths === null) {
78
+ return;
79
+ }
89
80
 
90
- if (!isSnapshotFile(filePath, snapshotPaths, cwd)) {
91
- process.exit(0);
92
- }
81
+ // Empty snapshot nothing to protect
82
+ if (snapshotPaths.length === 0) {
83
+ return;
84
+ }
93
85
 
94
- // File is in the snapshot — block the write
95
- console.error(
96
- `[df-snapshot-guard] Blocked ${toolName} to "${filePath}" — this file is listed in ` +
97
- `.deepflow/auto-snapshot.txt (ratchet baseline). ` +
98
- `Pre-existing test files must not be modified by agents. ` +
99
- `If you need to update this file, do so manually outside the autonomous loop.`
100
- );
101
- process.exit(1);
102
- } catch (_e) {
103
- // Parse or unexpected error — fail open so we never break non-deepflow projects
104
- process.exit(0);
86
+ if (!isSnapshotFile(filePath, snapshotPaths, cwd)) {
87
+ return;
105
88
  }
89
+
90
+ // File is in the snapshot — block the write
91
+ console.error(
92
+ `[df-snapshot-guard] Blocked ${toolName} to "${filePath}" — this file is listed in ` +
93
+ `.deepflow/auto-snapshot.txt (ratchet baseline). ` +
94
+ `Pre-existing test files must not be modified by agents. ` +
95
+ `If you need to update this file, do so manually outside the autonomous loop.`
96
+ );
97
+ process.exit(1);
106
98
  });
@@ -8,6 +8,7 @@
8
8
  const fs = require('fs');
9
9
  const path = require('path');
10
10
  const os = require('os');
11
+ const { readStdinIfMain } = require('./lib/hook-stdin');
11
12
 
12
13
  // ANSI colors
13
14
  const colors = {
@@ -21,18 +22,8 @@ const colors = {
21
22
  cyan: '\x1b[36m'
22
23
  };
23
24
 
24
- // Read JSON from stdin
25
- let input = '';
26
- process.stdin.setEncoding('utf8');
27
- process.stdin.on('data', chunk => input += chunk);
28
- process.stdin.on('end', () => {
29
- try {
30
- const data = JSON.parse(input);
31
- console.log(buildStatusLine(data));
32
- } catch (e) {
33
- // Fail silently to avoid breaking statusline
34
- console.log('');
35
- }
25
+ readStdinIfMain(module, (data) => {
26
+ console.log(buildStatusLine(data));
36
27
  });
37
28
 
38
29
  function buildStatusLine(data) {