@vibecheckai/cli 3.4.0 → 3.5.1

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.
Files changed (228) hide show
  1. package/bin/registry.js +154 -338
  2. package/bin/runners/context/generators/mcp.js +13 -15
  3. package/bin/runners/context/proof-context.js +1 -248
  4. package/bin/runners/lib/analysis-core.js +180 -198
  5. package/bin/runners/lib/analyzers.js +223 -1669
  6. package/bin/runners/lib/cli-output.js +210 -242
  7. package/bin/runners/lib/detectors-v2.js +785 -547
  8. package/bin/runners/lib/entitlements-v2.js +458 -96
  9. package/bin/runners/lib/error-handler.js +9 -16
  10. package/bin/runners/lib/global-flags.js +0 -37
  11. package/bin/runners/lib/route-truth.js +322 -1167
  12. package/bin/runners/lib/scan-output.js +469 -448
  13. package/bin/runners/lib/ship-output.js +27 -280
  14. package/bin/runners/lib/terminal-ui.js +733 -231
  15. package/bin/runners/lib/truth.js +321 -1004
  16. package/bin/runners/lib/unified-output.js +158 -162
  17. package/bin/runners/lib/upsell.js +204 -104
  18. package/bin/runners/runAllowlist.js +324 -0
  19. package/bin/runners/runAuth.js +95 -324
  20. package/bin/runners/runCheckpoint.js +21 -39
  21. package/bin/runners/runContext.js +24 -136
  22. package/bin/runners/runDoctor.js +67 -115
  23. package/bin/runners/runEvidencePack.js +219 -0
  24. package/bin/runners/runFix.js +5 -6
  25. package/bin/runners/runGuard.js +118 -212
  26. package/bin/runners/runInit.js +2 -14
  27. package/bin/runners/runInstall.js +281 -0
  28. package/bin/runners/runLabs.js +341 -0
  29. package/bin/runners/runMcp.js +52 -130
  30. package/bin/runners/runPolish.js +20 -43
  31. package/bin/runners/runProve.js +3 -13
  32. package/bin/runners/runReality.js +0 -14
  33. package/bin/runners/runReport.js +2 -3
  34. package/bin/runners/runScan.js +44 -511
  35. package/bin/runners/runShip.js +14 -28
  36. package/bin/runners/runValidate.js +2 -19
  37. package/bin/runners/runWatch.js +54 -118
  38. package/bin/vibecheck.js +41 -148
  39. package/mcp-server/ARCHITECTURE.md +339 -0
  40. package/mcp-server/__tests__/cache.test.ts +313 -0
  41. package/mcp-server/__tests__/executor.test.ts +239 -0
  42. package/mcp-server/__tests__/fixtures/exclusion-test/.cache/webpack/cache.pack +1 -0
  43. package/mcp-server/__tests__/fixtures/exclusion-test/.next/server/chunk.js +3 -0
  44. package/mcp-server/__tests__/fixtures/exclusion-test/.turbo/cache.json +3 -0
  45. package/mcp-server/__tests__/fixtures/exclusion-test/.venv/lib/env.py +3 -0
  46. package/mcp-server/__tests__/fixtures/exclusion-test/dist/bundle.js +3 -0
  47. package/mcp-server/__tests__/fixtures/exclusion-test/package.json +5 -0
  48. package/mcp-server/__tests__/fixtures/exclusion-test/src/app.ts +5 -0
  49. package/mcp-server/__tests__/fixtures/exclusion-test/venv/lib/config.py +4 -0
  50. package/mcp-server/__tests__/ids.test.ts +345 -0
  51. package/mcp-server/__tests__/integration/tools.test.ts +410 -0
  52. package/mcp-server/__tests__/registry.test.ts +365 -0
  53. package/mcp-server/__tests__/sandbox.test.ts +323 -0
  54. package/mcp-server/__tests__/schemas.test.ts +372 -0
  55. package/mcp-server/benchmarks/run-benchmarks.ts +304 -0
  56. package/mcp-server/examples/doctor.request.json +14 -0
  57. package/mcp-server/examples/doctor.response.json +53 -0
  58. package/mcp-server/examples/error.response.json +15 -0
  59. package/mcp-server/examples/scan.request.json +14 -0
  60. package/mcp-server/examples/scan.response.json +108 -0
  61. package/mcp-server/handlers/tool-handler.ts +671 -0
  62. package/mcp-server/index-v3.ts +293 -0
  63. package/mcp-server/index.js +1072 -1573
  64. package/mcp-server/index.old.js +4137 -0
  65. package/mcp-server/lib/cache.ts +341 -0
  66. package/mcp-server/lib/errors.ts +346 -0
  67. package/mcp-server/lib/executor.ts +792 -0
  68. package/mcp-server/lib/ids.ts +238 -0
  69. package/mcp-server/lib/logger.ts +368 -0
  70. package/mcp-server/lib/metrics.ts +365 -0
  71. package/mcp-server/lib/sandbox.ts +337 -0
  72. package/mcp-server/lib/validator.ts +229 -0
  73. package/mcp-server/package-lock.json +165 -0
  74. package/mcp-server/package.json +32 -7
  75. package/mcp-server/premium-tools.js +2 -2
  76. package/mcp-server/registry/tools.json +476 -0
  77. package/mcp-server/schemas/error-envelope.schema.json +125 -0
  78. package/mcp-server/schemas/finding.schema.json +167 -0
  79. package/mcp-server/schemas/report-artifact.schema.json +88 -0
  80. package/mcp-server/schemas/run-request.schema.json +75 -0
  81. package/mcp-server/schemas/verdict.schema.json +168 -0
  82. package/mcp-server/tier-auth.d.ts +71 -0
  83. package/mcp-server/tier-auth.js +371 -183
  84. package/mcp-server/truth-context.js +90 -131
  85. package/mcp-server/truth-firewall-tools.js +1000 -1611
  86. package/mcp-server/tsconfig.json +34 -0
  87. package/mcp-server/vibecheck-tools.js +2 -2
  88. package/mcp-server/vitest.config.ts +16 -0
  89. package/package.json +3 -4
  90. package/bin/runners/lib/agent-firewall/ai/false-positive-analyzer.js +0 -474
  91. package/bin/runners/lib/agent-firewall/change-packet/builder.js +0 -488
  92. package/bin/runners/lib/agent-firewall/change-packet/schema.json +0 -228
  93. package/bin/runners/lib/agent-firewall/change-packet/store.js +0 -200
  94. package/bin/runners/lib/agent-firewall/claims/claim-types.js +0 -21
  95. package/bin/runners/lib/agent-firewall/claims/extractor.js +0 -303
  96. package/bin/runners/lib/agent-firewall/claims/patterns.js +0 -24
  97. package/bin/runners/lib/agent-firewall/critic/index.js +0 -151
  98. package/bin/runners/lib/agent-firewall/critic/judge.js +0 -432
  99. package/bin/runners/lib/agent-firewall/critic/prompts.js +0 -305
  100. package/bin/runners/lib/agent-firewall/evidence/auth-evidence.js +0 -88
  101. package/bin/runners/lib/agent-firewall/evidence/contract-evidence.js +0 -75
  102. package/bin/runners/lib/agent-firewall/evidence/env-evidence.js +0 -127
  103. package/bin/runners/lib/agent-firewall/evidence/resolver.js +0 -102
  104. package/bin/runners/lib/agent-firewall/evidence/route-evidence.js +0 -213
  105. package/bin/runners/lib/agent-firewall/evidence/side-effect-evidence.js +0 -145
  106. package/bin/runners/lib/agent-firewall/fs-hook/daemon.js +0 -19
  107. package/bin/runners/lib/agent-firewall/fs-hook/installer.js +0 -87
  108. package/bin/runners/lib/agent-firewall/fs-hook/watcher.js +0 -184
  109. package/bin/runners/lib/agent-firewall/git-hook/pre-commit.js +0 -163
  110. package/bin/runners/lib/agent-firewall/ide-extension/cursor.js +0 -107
  111. package/bin/runners/lib/agent-firewall/ide-extension/vscode.js +0 -68
  112. package/bin/runners/lib/agent-firewall/ide-extension/windsurf.js +0 -66
  113. package/bin/runners/lib/agent-firewall/interceptor/base.js +0 -304
  114. package/bin/runners/lib/agent-firewall/interceptor/cursor.js +0 -35
  115. package/bin/runners/lib/agent-firewall/interceptor/vscode.js +0 -35
  116. package/bin/runners/lib/agent-firewall/interceptor/windsurf.js +0 -34
  117. package/bin/runners/lib/agent-firewall/lawbook/distributor.js +0 -465
  118. package/bin/runners/lib/agent-firewall/lawbook/evaluator.js +0 -604
  119. package/bin/runners/lib/agent-firewall/lawbook/index.js +0 -304
  120. package/bin/runners/lib/agent-firewall/lawbook/registry.js +0 -514
  121. package/bin/runners/lib/agent-firewall/lawbook/schema.js +0 -420
  122. package/bin/runners/lib/agent-firewall/logger.js +0 -141
  123. package/bin/runners/lib/agent-firewall/policy/default-policy.json +0 -90
  124. package/bin/runners/lib/agent-firewall/policy/engine.js +0 -103
  125. package/bin/runners/lib/agent-firewall/policy/loader.js +0 -451
  126. package/bin/runners/lib/agent-firewall/policy/rules/auth-drift.js +0 -50
  127. package/bin/runners/lib/agent-firewall/policy/rules/contract-drift.js +0 -50
  128. package/bin/runners/lib/agent-firewall/policy/rules/fake-success.js +0 -86
  129. package/bin/runners/lib/agent-firewall/policy/rules/ghost-env.js +0 -162
  130. package/bin/runners/lib/agent-firewall/policy/rules/ghost-route.js +0 -189
  131. package/bin/runners/lib/agent-firewall/policy/rules/scope.js +0 -93
  132. package/bin/runners/lib/agent-firewall/policy/rules/unsafe-side-effect.js +0 -57
  133. package/bin/runners/lib/agent-firewall/policy/schema.json +0 -183
  134. package/bin/runners/lib/agent-firewall/policy/verdict.js +0 -54
  135. package/bin/runners/lib/agent-firewall/proposal/extractor.js +0 -394
  136. package/bin/runners/lib/agent-firewall/proposal/index.js +0 -212
  137. package/bin/runners/lib/agent-firewall/proposal/schema.js +0 -251
  138. package/bin/runners/lib/agent-firewall/proposal/validator.js +0 -386
  139. package/bin/runners/lib/agent-firewall/reality/index.js +0 -332
  140. package/bin/runners/lib/agent-firewall/reality/state.js +0 -625
  141. package/bin/runners/lib/agent-firewall/reality/watcher.js +0 -322
  142. package/bin/runners/lib/agent-firewall/risk/index.js +0 -173
  143. package/bin/runners/lib/agent-firewall/risk/scorer.js +0 -328
  144. package/bin/runners/lib/agent-firewall/risk/thresholds.js +0 -321
  145. package/bin/runners/lib/agent-firewall/risk/vectors.js +0 -421
  146. package/bin/runners/lib/agent-firewall/simulator/diff-simulator.js +0 -472
  147. package/bin/runners/lib/agent-firewall/simulator/import-resolver.js +0 -346
  148. package/bin/runners/lib/agent-firewall/simulator/index.js +0 -181
  149. package/bin/runners/lib/agent-firewall/simulator/route-validator.js +0 -380
  150. package/bin/runners/lib/agent-firewall/time-machine/incident-correlator.js +0 -661
  151. package/bin/runners/lib/agent-firewall/time-machine/index.js +0 -267
  152. package/bin/runners/lib/agent-firewall/time-machine/replay-engine.js +0 -436
  153. package/bin/runners/lib/agent-firewall/time-machine/state-reconstructor.js +0 -490
  154. package/bin/runners/lib/agent-firewall/time-machine/timeline-builder.js +0 -530
  155. package/bin/runners/lib/agent-firewall/truthpack/index.js +0 -67
  156. package/bin/runners/lib/agent-firewall/truthpack/loader.js +0 -137
  157. package/bin/runners/lib/agent-firewall/unblock/planner.js +0 -337
  158. package/bin/runners/lib/agent-firewall/utils/ignore-checker.js +0 -118
  159. package/bin/runners/lib/api-client.js +0 -269
  160. package/bin/runners/lib/authority-badge.js +0 -425
  161. package/bin/runners/lib/engines/accessibility-engine.js +0 -190
  162. package/bin/runners/lib/engines/api-consistency-engine.js +0 -162
  163. package/bin/runners/lib/engines/ast-cache.js +0 -99
  164. package/bin/runners/lib/engines/code-quality-engine.js +0 -255
  165. package/bin/runners/lib/engines/console-logs-engine.js +0 -115
  166. package/bin/runners/lib/engines/cross-file-analysis-engine.js +0 -268
  167. package/bin/runners/lib/engines/dead-code-engine.js +0 -198
  168. package/bin/runners/lib/engines/deprecated-api-engine.js +0 -226
  169. package/bin/runners/lib/engines/empty-catch-engine.js +0 -150
  170. package/bin/runners/lib/engines/file-filter.js +0 -131
  171. package/bin/runners/lib/engines/hardcoded-secrets-engine.js +0 -251
  172. package/bin/runners/lib/engines/mock-data-engine.js +0 -272
  173. package/bin/runners/lib/engines/parallel-processor.js +0 -71
  174. package/bin/runners/lib/engines/performance-issues-engine.js +0 -265
  175. package/bin/runners/lib/engines/security-vulnerabilities-engine.js +0 -243
  176. package/bin/runners/lib/engines/todo-fixme-engine.js +0 -115
  177. package/bin/runners/lib/engines/type-aware-engine.js +0 -152
  178. package/bin/runners/lib/engines/unsafe-regex-engine.js +0 -225
  179. package/bin/runners/lib/engines/vibecheck-engines/README.md +0 -53
  180. package/bin/runners/lib/engines/vibecheck-engines/index.js +0 -15
  181. package/bin/runners/lib/engines/vibecheck-engines/lib/ast-cache.js +0 -164
  182. package/bin/runners/lib/engines/vibecheck-engines/lib/code-quality-engine.js +0 -291
  183. package/bin/runners/lib/engines/vibecheck-engines/lib/console-logs-engine.js +0 -83
  184. package/bin/runners/lib/engines/vibecheck-engines/lib/dead-code-engine.js +0 -198
  185. package/bin/runners/lib/engines/vibecheck-engines/lib/deprecated-api-engine.js +0 -275
  186. package/bin/runners/lib/engines/vibecheck-engines/lib/empty-catch-engine.js +0 -167
  187. package/bin/runners/lib/engines/vibecheck-engines/lib/file-filter.js +0 -217
  188. package/bin/runners/lib/engines/vibecheck-engines/lib/hardcoded-secrets-engine.js +0 -139
  189. package/bin/runners/lib/engines/vibecheck-engines/lib/mock-data-engine.js +0 -140
  190. package/bin/runners/lib/engines/vibecheck-engines/lib/parallel-processor.js +0 -164
  191. package/bin/runners/lib/engines/vibecheck-engines/lib/performance-issues-engine.js +0 -234
  192. package/bin/runners/lib/engines/vibecheck-engines/lib/type-aware-engine.js +0 -217
  193. package/bin/runners/lib/engines/vibecheck-engines/lib/unsafe-regex-engine.js +0 -78
  194. package/bin/runners/lib/engines/vibecheck-engines/package.json +0 -13
  195. package/bin/runners/lib/exit-codes.js +0 -275
  196. package/bin/runners/lib/fingerprint.js +0 -377
  197. package/bin/runners/lib/help-formatter.js +0 -413
  198. package/bin/runners/lib/logger.js +0 -38
  199. package/bin/runners/lib/ship-output-enterprise.js +0 -239
  200. package/bin/runners/lib/unified-cli-output.js +0 -604
  201. package/bin/runners/runAgent.d.ts +0 -5
  202. package/bin/runners/runAgent.js +0 -161
  203. package/bin/runners/runApprove.js +0 -1200
  204. package/bin/runners/runClassify.js +0 -859
  205. package/bin/runners/runContext.d.ts +0 -4
  206. package/bin/runners/runFirewall.d.ts +0 -5
  207. package/bin/runners/runFirewall.js +0 -134
  208. package/bin/runners/runFirewallHook.d.ts +0 -5
  209. package/bin/runners/runFirewallHook.js +0 -56
  210. package/bin/runners/runPolish.d.ts +0 -4
  211. package/bin/runners/runProof.zip +0 -0
  212. package/bin/runners/runTruth.d.ts +0 -5
  213. package/bin/runners/runTruth.js +0 -101
  214. package/mcp-server/HARDENING_SUMMARY.md +0 -299
  215. package/mcp-server/agent-firewall-interceptor.js +0 -500
  216. package/mcp-server/authority-tools.js +0 -569
  217. package/mcp-server/conductor/conflict-resolver.js +0 -588
  218. package/mcp-server/conductor/execution-planner.js +0 -544
  219. package/mcp-server/conductor/index.js +0 -377
  220. package/mcp-server/conductor/lock-manager.js +0 -615
  221. package/mcp-server/conductor/request-queue.js +0 -550
  222. package/mcp-server/conductor/session-manager.js +0 -500
  223. package/mcp-server/conductor/tools.js +0 -510
  224. package/mcp-server/lib/api-client.cjs +0 -13
  225. package/mcp-server/lib/logger.cjs +0 -30
  226. package/mcp-server/logger.js +0 -173
  227. package/mcp-server/tools-v3.js +0 -706
  228. package/mcp-server/vibecheck-mcp-server-3.2.0.tgz +0 -0
@@ -1,213 +0,0 @@
1
- /**
2
- * Route Evidence Resolver
3
- *
4
- * Resolves route claims against truthpack.routes.json
5
- * Checks for ghost routes (UI references route not registered).
6
- */
7
-
8
- "use strict";
9
-
10
- const { getRoutes } = require("../truthpack");
11
- const { canonicalizePath } = require("../../route-truth");
12
- const { shouldIgnore } = require("../utils/ignore-checker");
13
-
14
- /**
15
- * Resolve route claim evidence
16
- * @param {string} projectRoot - Project root directory
17
- * @param {object} claim - Route claim
18
- * @returns {object} Evidence result
19
- */
20
- function resolve(projectRoot, claim) {
21
- // Skip checking routes from ignored files (test files, fixtures, etc.)
22
- if (claim.pointer && shouldIgnore(projectRoot, claim.pointer.split(":")[0])) {
23
- return {
24
- result: "PROVEN",
25
- sources: [{
26
- type: "ignored",
27
- pointer: claim.pointer,
28
- confidence: 1.0
29
- }],
30
- reason: `Route from ignored file (test/fixture)`
31
- };
32
- }
33
-
34
- // Normalize route path from claim
35
- const routePath = canonicalizePath(claim.value);
36
-
37
- // Skip external API calls (routes that don't start with /api/ in Next.js context)
38
- // Routes like /content/blog, /content/faq are external backend API calls, not Next.js routes
39
- // Only validate Next.js API routes (those in apps/web-ui/src/app/api/)
40
- if (!routePath.startsWith('/api/')) {
41
- return {
42
- result: "PROVEN",
43
- sources: [{
44
- type: "external_api",
45
- pointer: claim.pointer,
46
- confidence: 1.0
47
- }],
48
- reason: `Route ${routePath} is an external API call, not a Next.js route`
49
- };
50
- }
51
-
52
- // Skip wildcard patterns from template literals (they're approximations)
53
- // These are detected from fetch(`${url}/api/...`) and are not exact routes
54
- if (routePath.includes('*') || routePath === '/api/*') {
55
- return {
56
- result: "PROVEN",
57
- sources: [{
58
- type: "pattern",
59
- pointer: claim.pointer,
60
- confidence: 0.8
61
- }],
62
- reason: `Route pattern ${routePath} is a template literal approximation, not an exact route`
63
- };
64
- }
65
-
66
- // Skip backend API routes (routes from template literals using apiUrl)
67
- // These are calls to the backend API server, not Next.js API routes
68
- if (claim.isBackendApi || (claim.reason && claim.reason.includes('backend API'))) {
69
- return {
70
- result: "PROVEN",
71
- sources: [{
72
- type: "backend_api",
73
- pointer: claim.pointer,
74
- confidence: 0.9
75
- }],
76
- reason: `Route ${routePath} is a backend API call (using apiUrl variable), not a Next.js route`
77
- };
78
- }
79
-
80
- // Skip routes that are clearly backend API routes (v1, v2, etc. are typically backend)
81
- // Next.js API routes are usually simpler like /api/checkout, /api/health
82
- if (routePath.match(/^\/api\/v\d+\//)) {
83
- return {
84
- result: "PROVEN",
85
- sources: [{
86
- type: "backend_api",
87
- pointer: claim.pointer,
88
- confidence: 0.85
89
- }],
90
- reason: `Route ${routePath} appears to be a backend API route (versioned), not a Next.js route`
91
- };
92
- }
93
-
94
- const routes = getRoutes(projectRoot);
95
-
96
- // Check if route exists in truthpack
97
- if (routes && routes.length > 0) {
98
- // First, check for exact match
99
- const exactMatch = routes.find(route => {
100
- const routePathNormalized = canonicalizePath(route.path || route);
101
- return routePathNormalized === routePath;
102
- });
103
-
104
- if (exactMatch) {
105
- return {
106
- result: "PROVEN",
107
- sources: [{
108
- type: "truthpack.routes",
109
- pointer: claim.pointer,
110
- confidence: 0.9
111
- }],
112
- reason: `Route ${routePath} found in truthpack (exact match)`
113
- };
114
- }
115
-
116
- // Then check parameterized routes - but be conservative
117
- // Only match if it looks like a parameter value (numeric/UUID-like)
118
- const paramMatch = routes.find(route => {
119
- const routePathNormalized = canonicalizePath(route.path || route);
120
-
121
- if (!isParameterizedPath(routePathNormalized)) return false;
122
-
123
- const routeParts = routePathNormalized.split("/").filter(Boolean);
124
- const claimParts = routePath.split("/").filter(Boolean);
125
-
126
- if (routeParts.length !== claimParts.length) return false;
127
-
128
- // Check if all non-parameter segments match exactly
129
- for (let i = 0; i < routeParts.length; i++) {
130
- const rSeg = routeParts[i];
131
- const cSeg = claimParts[i];
132
-
133
- // If it's a parameter, check if the concrete value looks like a parameter
134
- if (rSeg.startsWith(":")) {
135
- // Only match if it looks like an ID (numeric or UUID-like)
136
- // Don't match literal words like "create", "update", etc.
137
- const looksLikeId = /^\d+$/.test(cSeg) || /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(cSeg);
138
- if (!looksLikeId) return false;
139
- } else if (rSeg !== cSeg) {
140
- return false;
141
- }
142
- }
143
-
144
- return true;
145
- });
146
-
147
- if (paramMatch) {
148
- return {
149
- result: "PROVEN",
150
- sources: [{
151
- type: "truthpack.routes",
152
- pointer: claim.pointer,
153
- confidence: 0.7
154
- }],
155
- reason: `Route ${routePath} matches parameterized route in truthpack`
156
- };
157
- }
158
-
159
- // No match found - ghost route
160
- return {
161
- result: "UNPROVEN",
162
- sources: [],
163
- reason: `Route ${routePath} not found in truthpack (ghost route)`
164
- };
165
- } else {
166
- // No routes in truthpack - cannot prove
167
- return {
168
- result: "UNPROVEN",
169
- sources: [],
170
- reason: "No routes found in truthpack"
171
- };
172
- }
173
- }
174
-
175
- function isParameterizedPath(p) {
176
- const s = String(p || "").trim();
177
- return s.includes(":") || s.includes("*");
178
- }
179
-
180
- function matchPath(pattern, concrete) {
181
- const pat = String(pattern || "").trim();
182
- const con = String(concrete || "").trim();
183
-
184
- if (pat === con) return true;
185
-
186
- // Simple parameterized matching - only match if segments align
187
- const patParts = pat.split("/").filter(Boolean);
188
- const conParts = con.split("/").filter(Boolean);
189
-
190
- if (patParts.length !== conParts.length) return false;
191
-
192
- for (let i = 0; i < patParts.length; i++) {
193
- const pSeg = patParts[i];
194
- const cSeg = conParts[i];
195
-
196
- // Parameter placeholder (:id, :slug) matches any segment
197
- if (pSeg.startsWith(":")) {
198
- continue;
199
- }
200
- // Wildcard (*slug) matches remainder
201
- if (pSeg.startsWith("*")) {
202
- return true;
203
- }
204
- // Exact match required for literal segments
205
- if (pSeg !== cSeg) return false;
206
- }
207
-
208
- return true;
209
- }
210
-
211
- module.exports = {
212
- resolve
213
- };
@@ -1,145 +0,0 @@
1
- /**
2
- * Side Effect Evidence Resolver
3
- *
4
- * Detects unverified side effects (DB writes, email, payments).
5
- * Checks for test coverage or reality proof.
6
- */
7
-
8
- "use strict";
9
-
10
- const fs = require("fs");
11
- const path = require("path");
12
-
13
- /**
14
- * Resolve side effect claim evidence
15
- * @param {string} projectRoot - Project root directory
16
- * @param {object} claim - Side effect claim
17
- * @returns {object} Evidence result
18
- */
19
- function resolve(projectRoot, claim) {
20
- const claimFile = claim.file || "";
21
- const claimValue = claim.value.toLowerCase();
22
-
23
- // Detect side effect types
24
- const hasDbWrite = /\b(create|update|delete|insert|save|write)\b/i.test(claimValue) ||
25
- /\b(prisma|sequelize|mongoose|db\.|database\.)\b/i.test(claimValue);
26
-
27
- const hasEmail = /\b(email|sendMail|nodemailer|sendgrid|mailgun)\b/i.test(claimValue);
28
-
29
- const hasPayment = /\b(stripe|payment|charge|checkout|billing)\b/i.test(claimValue);
30
-
31
- if (!hasDbWrite && !hasEmail && !hasPayment) {
32
- // Not a side effect
33
- return {
34
- result: "PROVEN",
35
- sources: [],
36
- reason: "No side effect detected"
37
- };
38
- }
39
-
40
- // Check for test coverage
41
- const testFile = findTestFile(projectRoot, claimFile);
42
- if (testFile && fs.existsSync(testFile)) {
43
- const testContent = fs.readFileSync(testFile, "utf8");
44
- // Check if test covers the side effect
45
- if (testContent.includes(claimValue.slice(0, 20)) ||
46
- testContent.includes("mock") ||
47
- testContent.includes("test")) {
48
- return {
49
- result: "PROVEN",
50
- sources: [{
51
- type: "repo.search",
52
- pointer: testFile,
53
- confidence: 0.7
54
- }],
55
- reason: "Test file found for side effect"
56
- };
57
- }
58
- }
59
-
60
- // Check for reality proof (reality report)
61
- const realityReport = findRealityReport(projectRoot, claimFile);
62
- if (realityReport) {
63
- return {
64
- result: "PROVEN",
65
- sources: [{
66
- type: "repo.search",
67
- pointer: realityReport,
68
- confidence: 0.8
69
- }],
70
- reason: "Reality proof found for side effect"
71
- };
72
- }
73
-
74
- // Side effect detected but no verification found
75
- return {
76
- result: "UNPROVEN",
77
- sources: [],
78
- reason: `Side effect detected (${hasDbWrite ? 'DB' : ''}${hasEmail ? 'Email' : ''}${hasPayment ? 'Payment' : ''}) but no test coverage or reality proof found`
79
- };
80
- }
81
-
82
- /**
83
- * Find test file for a source file
84
- * @param {string} projectRoot - Project root directory
85
- * @param {string} sourceFile - Source file path
86
- * @returns {string|null} Test file path or null
87
- */
88
- function findTestFile(projectRoot, sourceFile) {
89
- if (!sourceFile) return null;
90
-
91
- // Try common test file patterns
92
- const baseName = path.basename(sourceFile, path.extname(sourceFile));
93
- const dir = path.dirname(sourceFile);
94
-
95
- const patterns = [
96
- `${dir}/${baseName}.test.ts`,
97
- `${dir}/${baseName}.test.tsx`,
98
- `${dir}/${baseName}.test.js`,
99
- `${dir}/__tests__/${baseName}.test.ts`,
100
- `${dir}/__tests__/${baseName}.test.tsx`,
101
- `${dir.replace(/\/src\//, '/tests/')}/${baseName}.test.ts`
102
- ];
103
-
104
- for (const pattern of patterns) {
105
- const testPath = path.join(projectRoot, pattern);
106
- if (fs.existsSync(testPath)) {
107
- return pattern;
108
- }
109
- }
110
-
111
- return null;
112
- }
113
-
114
- /**
115
- * Find reality report for a file
116
- * @param {string} projectRoot - Project root directory
117
- * @param {string} sourceFile - Source file path
118
- * @returns {string|null} Reality report path or null
119
- */
120
- function findRealityReport(projectRoot, sourceFile) {
121
- const realityDir = path.join(projectRoot, ".vibecheck", "reality");
122
-
123
- if (!fs.existsSync(realityDir)) {
124
- return null;
125
- }
126
-
127
- // Look for recent reality reports
128
- const reports = fs.readdirSync(realityDir)
129
- .filter(file => file.endsWith('.json'))
130
- .map(file => path.join(realityDir, file))
131
- .filter(file => {
132
- try {
133
- const report = JSON.parse(fs.readFileSync(file, "utf8"));
134
- return report.files && report.files.includes(sourceFile);
135
- } catch {
136
- return false;
137
- }
138
- });
139
-
140
- return reports.length > 0 ? reports[0] : null;
141
- }
142
-
143
- module.exports = {
144
- resolve
145
- };
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * File System Hook Daemon
4
- *
5
- * Runs as a background process to intercept file writes.
6
- * Start with: node bin/runners/lib/agent-firewall/fs-hook/daemon.js
7
- */
8
-
9
- const path = require("path");
10
- const { startFileSystemHook } = require("./installer");
11
-
12
- const projectRoot = process.cwd();
13
-
14
- console.log("🛡️ Starting Agent Firewall File System Hook...\n");
15
- console.log(` Project: ${projectRoot}\n`);
16
-
17
- startFileSystemHook(projectRoot);
18
-
19
- console.log("✅ File System Hook running (press Ctrl+C to stop)\n");
@@ -1,87 +0,0 @@
1
- /**
2
- * File System Hook Installer
3
- *
4
- * Installs and manages the file system hook daemon.
5
- */
6
-
7
- "use strict";
8
-
9
- const fs = require("fs");
10
- const path = require("path");
11
- const { FileSystemHook } = require("./watcher");
12
-
13
- let globalHook = null;
14
-
15
- /**
16
- * Install file system hook
17
- * @param {string} projectRoot - Project root directory
18
- * @returns {object} Installation result
19
- */
20
- function installFileSystemHook(projectRoot) {
21
- const hookScript = path.join(__dirname, "daemon.js");
22
- const packageJson = path.join(projectRoot, "package.json");
23
-
24
- // Add script to package.json
25
- if (fs.existsSync(packageJson)) {
26
- const pkg = JSON.parse(fs.readFileSync(packageJson, "utf8"));
27
- if (!pkg.scripts) {
28
- pkg.scripts = {};
29
- }
30
- pkg.scripts["firewall:fs-hook"] = `node ${path.relative(projectRoot, hookScript)}`;
31
- fs.writeFileSync(packageJson, JSON.stringify(pkg, null, 2));
32
- }
33
-
34
- // Create marker file
35
- const markerFile = path.join(projectRoot, ".vibecheck", "fs-hook-enabled");
36
- fs.writeFileSync(markerFile, JSON.stringify({
37
- enabled: true,
38
- installedAt: new Date().toISOString()
39
- }, null, 2));
40
-
41
- return {
42
- success: true,
43
- message: "File system hook installed. Run 'npm run firewall:fs-hook' to start."
44
- };
45
- }
46
-
47
- /**
48
- * Start file system hook daemon
49
- * @param {string} projectRoot - Project root directory
50
- */
51
- function startFileSystemHook(projectRoot) {
52
- if (globalHook) {
53
- console.log("⚠️ File system hook already running");
54
- return;
55
- }
56
-
57
- globalHook = new FileSystemHook(projectRoot);
58
- globalHook.start().catch(console.error);
59
-
60
- // Keep process alive
61
- process.on("SIGINT", () => {
62
- if (globalHook) {
63
- globalHook.stop();
64
- }
65
- process.exit(0);
66
- });
67
-
68
- // Keep alive
69
- setInterval(() => {}, 1000);
70
- }
71
-
72
- /**
73
- * Stop file system hook
74
- */
75
- function stopFileSystemHook() {
76
- if (globalHook) {
77
- globalHook.stop();
78
- globalHook = null;
79
- }
80
- }
81
-
82
- module.exports = {
83
- installFileSystemHook,
84
- startFileSystemHook,
85
- stopFileSystemHook,
86
- FileSystemHook
87
- };
@@ -1,184 +0,0 @@
1
- /**
2
- * File System Hook - Intercepts ALL file writes at OS level
3
- *
4
- * Uses chokidar to watch for file changes and intercepts them
5
- * before they're written to disk.
6
- */
7
-
8
- "use strict";
9
-
10
- const chokidar = require("chokidar");
11
- const fs = require("fs");
12
- const path = require("path");
13
- const { interceptFileWrite } = require("../interceptor/base");
14
- const { loadPolicy } = require("../policy/loader");
15
-
16
- class FileSystemHook {
17
- constructor(projectRoot) {
18
- this.projectRoot = projectRoot;
19
- this.watcher = null;
20
- this.pendingWrites = new Map(); // Track writes in progress
21
- this.isEnabled = false;
22
- }
23
-
24
- /**
25
- * Start watching for file writes
26
- */
27
- async start() {
28
- if (this.watcher) {
29
- return; // Already watching
30
- }
31
-
32
- const policy = loadPolicy(this.projectRoot);
33
- if (policy.mode !== "enforce") {
34
- console.log("⚠️ File system hook only active in enforce mode");
35
- return;
36
- }
37
-
38
- this.isEnabled = true;
39
-
40
- // Watch for file changes
41
- this.watcher = chokidar.watch([
42
- "**/*.ts",
43
- "**/*.tsx",
44
- "**/*.js",
45
- "**/*.jsx",
46
- "**/*.py",
47
- "**/*.go",
48
- "**/*.rs"
49
- ], {
50
- cwd: this.projectRoot,
51
- ignored: [
52
- "**/node_modules/**",
53
- "**/dist/**",
54
- "**/.next/**",
55
- "**/.vibecheck/**",
56
- "**/.git/**",
57
- "**/build/**"
58
- ],
59
- persistent: true,
60
- ignoreInitial: true,
61
- awaitWriteFinish: {
62
- stabilityThreshold: 100,
63
- pollInterval: 50
64
- }
65
- });
66
-
67
- // Intercept file writes
68
- this.watcher.on("add", (filePath) => this.handleFileWrite(filePath, "create"));
69
- this.watcher.on("change", (filePath) => this.handleFileWrite(filePath, "modify"));
70
-
71
- console.log("🛡️ File System Hook ACTIVE - intercepting all file writes");
72
- }
73
-
74
- /**
75
- * Handle file write event
76
- */
77
- async handleFileWrite(filePath, operation) {
78
- // Skip if we're already processing this file
79
- if (this.pendingWrites.has(filePath)) {
80
- return;
81
- }
82
-
83
- this.pendingWrites.set(filePath, true);
84
-
85
- try {
86
- // Read the new content
87
- const fileAbs = path.join(this.projectRoot, filePath);
88
- if (!fs.existsSync(fileAbs)) {
89
- this.pendingWrites.delete(filePath);
90
- return;
91
- }
92
-
93
- const newContent = fs.readFileSync(fileAbs, "utf8");
94
-
95
- // Try to get old content from git or backup
96
- let oldContent = null;
97
- try {
98
- // Check if file existed before (for modifications)
99
- if (operation === "modify") {
100
- // Try to read from git index
101
- const { execSync } = require("child_process");
102
- try {
103
- oldContent = execSync(
104
- `git show :${filePath}`,
105
- { cwd: this.projectRoot, encoding: "utf8", stdio: "pipe" }
106
- );
107
- } catch {
108
- // File not in git, that's okay
109
- }
110
- }
111
- } catch {
112
- // Couldn't get old content, that's okay
113
- }
114
-
115
- // Intercept the write
116
- const result = await interceptFileWrite({
117
- projectRoot: this.projectRoot,
118
- agentId: "filesystem-hook",
119
- intent: `File ${operation} via filesystem`,
120
- filePath: filePath,
121
- content: newContent,
122
- oldContent: oldContent
123
- });
124
-
125
- const policy = loadPolicy(this.projectRoot);
126
-
127
- // If blocked and in enforce mode, revert the file
128
- if (!result.allowed && policy.mode === "enforce") {
129
- console.error(`\n❌ BLOCKED: ${filePath}`);
130
- console.error(` ${result.message}`);
131
-
132
- if (result.violations) {
133
- result.violations.forEach(v => {
134
- console.error(` - ${v.rule}: ${v.message}`);
135
- });
136
- }
137
-
138
- // Revert the file
139
- if (oldContent !== null) {
140
- fs.writeFileSync(fileAbs, oldContent, "utf8");
141
- console.error(` ✅ File reverted to previous version\n`);
142
- } else {
143
- // Delete the file if it was newly created
144
- fs.unlinkSync(fileAbs);
145
- console.error(` ✅ File deleted (was newly created)\n`);
146
- }
147
-
148
- // Show unblock plan
149
- if (result.unblockPlan && result.unblockPlan.steps.length > 0) {
150
- console.error(" To fix:");
151
- result.unblockPlan.steps.forEach((step, i) => {
152
- console.error(` ${i + 1}. ${step.action}: ${step.description}`);
153
- });
154
- console.error("");
155
- }
156
- } else if (result.allowed || policy.mode === "observe") {
157
- // Log in observe mode
158
- if (policy.mode === "observe" && result.violations && result.violations.length > 0) {
159
- console.log(`📊 OBSERVE: ${filePath} - violations logged (not blocked)`);
160
- }
161
- }
162
- } catch (error) {
163
- console.error(`Error intercepting file write: ${error.message}`);
164
- } finally {
165
- this.pendingWrites.delete(filePath);
166
- }
167
- }
168
-
169
- /**
170
- * Stop watching
171
- */
172
- stop() {
173
- if (this.watcher) {
174
- this.watcher.close();
175
- this.watcher = null;
176
- this.isEnabled = false;
177
- console.log("🛡️ File System Hook stopped");
178
- }
179
- }
180
- }
181
-
182
- module.exports = {
183
- FileSystemHook
184
- };