@neurcode-ai/cli 0.9.64 → 0.9.66

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 (323) hide show
  1. package/LICENSE +201 -0
  2. package/dist/commands/bootstrap-policy.d.ts +29 -0
  3. package/dist/commands/bootstrap-policy.d.ts.map +1 -0
  4. package/dist/commands/bootstrap-policy.js +334 -0
  5. package/dist/commands/bootstrap-policy.js.map +1 -0
  6. package/dist/commands/brain.d.ts.map +1 -1
  7. package/dist/commands/brain.js +273 -0
  8. package/dist/commands/brain.js.map +1 -1
  9. package/dist/commands/doctor.d.ts.map +1 -1
  10. package/dist/commands/doctor.js +82 -0
  11. package/dist/commands/doctor.js.map +1 -1
  12. package/dist/commands/pilot-report.d.ts +9 -0
  13. package/dist/commands/pilot-report.d.ts.map +1 -0
  14. package/dist/commands/pilot-report.js +176 -0
  15. package/dist/commands/pilot-report.js.map +1 -0
  16. package/dist/commands/quickstart.d.ts +21 -0
  17. package/dist/commands/quickstart.d.ts.map +1 -0
  18. package/dist/commands/quickstart.js +178 -0
  19. package/dist/commands/quickstart.js.map +1 -0
  20. package/dist/commands/remediate-export.d.ts +31 -0
  21. package/dist/commands/remediate-export.d.ts.map +1 -0
  22. package/dist/commands/remediate-export.js +283 -0
  23. package/dist/commands/remediate-export.js.map +1 -0
  24. package/dist/commands/remediate-governance.d.ts +54 -0
  25. package/dist/commands/remediate-governance.d.ts.map +1 -0
  26. package/dist/commands/remediate-governance.js +375 -0
  27. package/dist/commands/remediate-governance.js.map +1 -0
  28. package/dist/commands/remediate.d.ts.map +1 -1
  29. package/dist/commands/remediate.js.map +1 -1
  30. package/dist/commands/replay.d.ts.map +1 -1
  31. package/dist/commands/replay.js +30 -0
  32. package/dist/commands/replay.js.map +1 -1
  33. package/dist/commands/verify.d.ts.map +1 -1
  34. package/dist/commands/verify.js +409 -30
  35. package/dist/commands/verify.js.map +1 -1
  36. package/dist/daemon/server.d.ts.map +1 -1
  37. package/dist/daemon/server.js +1078 -0
  38. package/dist/daemon/server.js.map +1 -1
  39. package/dist/explainability/DeterminismClassifier.d.ts +34 -0
  40. package/dist/explainability/DeterminismClassifier.d.ts.map +1 -0
  41. package/dist/explainability/DeterminismClassifier.js +104 -0
  42. package/dist/explainability/DeterminismClassifier.js.map +1 -0
  43. package/dist/explainability/ViolationFormatter.d.ts +32 -0
  44. package/dist/explainability/ViolationFormatter.d.ts.map +1 -0
  45. package/dist/explainability/ViolationFormatter.js +252 -0
  46. package/dist/explainability/ViolationFormatter.js.map +1 -0
  47. package/dist/explainability/index.d.ts +15 -0
  48. package/dist/explainability/index.d.ts.map +1 -0
  49. package/dist/explainability/index.js +94 -0
  50. package/dist/explainability/index.js.map +1 -0
  51. package/dist/explainability/types.d.ts +37 -0
  52. package/dist/explainability/types.d.ts.map +1 -0
  53. package/dist/explainability/types.js +3 -0
  54. package/dist/explainability/types.js.map +1 -0
  55. package/dist/governance/canonical-invariants.d.ts +88 -0
  56. package/dist/governance/canonical-invariants.d.ts.map +1 -0
  57. package/dist/governance/canonical-invariants.js +197 -0
  58. package/dist/governance/canonical-invariants.js.map +1 -0
  59. package/dist/governance/canonical-ordering.d.ts +76 -0
  60. package/dist/governance/canonical-ordering.d.ts.map +1 -0
  61. package/dist/governance/canonical-ordering.js +189 -0
  62. package/dist/governance/canonical-ordering.js.map +1 -0
  63. package/dist/governance/canonical-pipeline.d.ts +45 -0
  64. package/dist/governance/canonical-pipeline.d.ts.map +1 -0
  65. package/dist/governance/canonical-pipeline.js +616 -0
  66. package/dist/governance/canonical-pipeline.js.map +1 -0
  67. package/dist/governance/diff-line-provenance.d.ts +59 -0
  68. package/dist/governance/diff-line-provenance.d.ts.map +1 -0
  69. package/dist/governance/diff-line-provenance.js +118 -0
  70. package/dist/governance/diff-line-provenance.js.map +1 -0
  71. package/dist/governance/pilot-readiness.d.ts +34 -0
  72. package/dist/governance/pilot-readiness.d.ts.map +1 -0
  73. package/dist/governance/pilot-readiness.js +226 -0
  74. package/dist/governance/pilot-readiness.js.map +1 -0
  75. package/dist/governance/policy-parity-validator.d.ts +62 -0
  76. package/dist/governance/policy-parity-validator.d.ts.map +1 -0
  77. package/dist/governance/policy-parity-validator.js +137 -0
  78. package/dist/governance/policy-parity-validator.js.map +1 -0
  79. package/dist/governance/remediation-boundary.d.ts +55 -0
  80. package/dist/governance/remediation-boundary.d.ts.map +1 -0
  81. package/dist/governance/remediation-boundary.js +120 -0
  82. package/dist/governance/remediation-boundary.js.map +1 -0
  83. package/dist/governance/structural-cache.d.ts +103 -0
  84. package/dist/governance/structural-cache.d.ts.map +1 -0
  85. package/dist/governance/structural-cache.js +240 -0
  86. package/dist/governance/structural-cache.js.map +1 -0
  87. package/dist/governance/structural-on-diff.d.ts +33 -0
  88. package/dist/governance/structural-on-diff.d.ts.map +1 -0
  89. package/dist/governance/structural-on-diff.js +67 -0
  90. package/dist/governance/structural-on-diff.js.map +1 -0
  91. package/dist/governance/structural-policy-merge.d.ts +22 -0
  92. package/dist/governance/structural-policy-merge.d.ts.map +1 -0
  93. package/dist/governance/structural-policy-merge.js +32 -0
  94. package/dist/governance/structural-policy-merge.js.map +1 -0
  95. package/dist/governance/verify-runtime-guard.d.ts +99 -0
  96. package/dist/governance/verify-runtime-guard.d.ts.map +1 -0
  97. package/dist/governance/verify-runtime-guard.js +129 -0
  98. package/dist/governance/verify-runtime-guard.js.map +1 -0
  99. package/dist/index.js +107 -0
  100. package/dist/index.js.map +1 -1
  101. package/dist/integrations/review-compression/index.d.ts +50 -0
  102. package/dist/integrations/review-compression/index.d.ts.map +1 -0
  103. package/dist/integrations/review-compression/index.js +158 -0
  104. package/dist/integrations/review-compression/index.js.map +1 -0
  105. package/dist/intent-engine/domain-taxonomy.d.ts +42 -0
  106. package/dist/intent-engine/domain-taxonomy.d.ts.map +1 -0
  107. package/dist/intent-engine/domain-taxonomy.js +534 -0
  108. package/dist/intent-engine/domain-taxonomy.js.map +1 -0
  109. package/dist/intent-engine/index.d.ts +1 -0
  110. package/dist/intent-engine/index.d.ts.map +1 -1
  111. package/dist/intent-engine/index.js +6 -1
  112. package/dist/intent-engine/index.js.map +1 -1
  113. package/dist/intent-engine/parser.d.ts.map +1 -1
  114. package/dist/intent-engine/parser.js +47 -0
  115. package/dist/intent-engine/parser.js.map +1 -1
  116. package/dist/intent-engine/repo-classifier.d.ts +64 -0
  117. package/dist/intent-engine/repo-classifier.d.ts.map +1 -0
  118. package/dist/intent-engine/repo-classifier.js +178 -0
  119. package/dist/intent-engine/repo-classifier.js.map +1 -0
  120. package/dist/intent-engine/semantic-expander.d.ts +104 -0
  121. package/dist/intent-engine/semantic-expander.d.ts.map +1 -0
  122. package/dist/intent-engine/semantic-expander.js +480 -0
  123. package/dist/intent-engine/semantic-expander.js.map +1 -0
  124. package/dist/patch-engine/patterns.d.ts.map +1 -1
  125. package/dist/patch-engine/patterns.js +8 -4
  126. package/dist/patch-engine/patterns.js.map +1 -1
  127. package/dist/semantic/index.d.ts +14 -0
  128. package/dist/semantic/index.d.ts.map +1 -0
  129. package/dist/semantic/index.js +30 -0
  130. package/dist/semantic/index.js.map +1 -0
  131. package/dist/semantic/tfidf-engine.d.ts +81 -0
  132. package/dist/semantic/tfidf-engine.d.ts.map +1 -0
  133. package/dist/semantic/tfidf-engine.js +278 -0
  134. package/dist/semantic/tfidf-engine.js.map +1 -0
  135. package/dist/semantic/vector-store.d.ts +108 -0
  136. package/dist/semantic/vector-store.d.ts.map +1 -0
  137. package/dist/semantic/vector-store.js +321 -0
  138. package/dist/semantic/vector-store.js.map +1 -0
  139. package/dist/structural-rules/context-severity.d.ts +46 -0
  140. package/dist/structural-rules/context-severity.d.ts.map +1 -0
  141. package/dist/structural-rules/context-severity.js +115 -0
  142. package/dist/structural-rules/context-severity.js.map +1 -0
  143. package/dist/structural-rules/distributed/DS001-saga-rollback-absence.d.ts +11 -0
  144. package/dist/structural-rules/distributed/DS001-saga-rollback-absence.d.ts.map +1 -0
  145. package/dist/structural-rules/distributed/DS001-saga-rollback-absence.js +212 -0
  146. package/dist/structural-rules/distributed/DS001-saga-rollback-absence.js.map +1 -0
  147. package/dist/structural-rules/distributed/DS002-missing-correlation-id.d.ts +11 -0
  148. package/dist/structural-rules/distributed/DS002-missing-correlation-id.d.ts.map +1 -0
  149. package/dist/structural-rules/distributed/DS002-missing-correlation-id.js +213 -0
  150. package/dist/structural-rules/distributed/DS002-missing-correlation-id.js.map +1 -0
  151. package/dist/structural-rules/distributed/index.d.ts +3 -0
  152. package/dist/structural-rules/distributed/index.d.ts.map +1 -0
  153. package/dist/structural-rules/distributed/index.js +8 -0
  154. package/dist/structural-rules/distributed/index.js.map +1 -0
  155. package/dist/structural-rules/engine.d.ts +25 -0
  156. package/dist/structural-rules/engine.d.ts.map +1 -0
  157. package/dist/structural-rules/engine.js +90 -0
  158. package/dist/structural-rules/engine.js.map +1 -0
  159. package/dist/structural-rules/index.d.ts +45 -0
  160. package/dist/structural-rules/index.d.ts.map +1 -0
  161. package/dist/structural-rules/index.js +158 -0
  162. package/dist/structural-rules/index.js.map +1 -0
  163. package/dist/structural-rules/python/PY001-asyncio-task-without-cancel.d.ts +11 -0
  164. package/dist/structural-rules/python/PY001-asyncio-task-without-cancel.d.ts.map +1 -0
  165. package/dist/structural-rules/python/PY001-asyncio-task-without-cancel.js +66 -0
  166. package/dist/structural-rules/python/PY001-asyncio-task-without-cancel.js.map +1 -0
  167. package/dist/structural-rules/python/PY002-unbounded-dict-singleton.d.ts +11 -0
  168. package/dist/structural-rules/python/PY002-unbounded-dict-singleton.d.ts.map +1 -0
  169. package/dist/structural-rules/python/PY002-unbounded-dict-singleton.js +135 -0
  170. package/dist/structural-rules/python/PY002-unbounded-dict-singleton.js.map +1 -0
  171. package/dist/structural-rules/python/PY003-broad-except-clause.d.ts +32 -0
  172. package/dist/structural-rules/python/PY003-broad-except-clause.d.ts.map +1 -0
  173. package/dist/structural-rules/python/PY003-broad-except-clause.js +277 -0
  174. package/dist/structural-rules/python/PY003-broad-except-clause.js.map +1 -0
  175. package/dist/structural-rules/python/PY004-swallowed-async-exception.d.ts +11 -0
  176. package/dist/structural-rules/python/PY004-swallowed-async-exception.d.ts.map +1 -0
  177. package/dist/structural-rules/python/PY004-swallowed-async-exception.js +167 -0
  178. package/dist/structural-rules/python/PY004-swallowed-async-exception.js.map +1 -0
  179. package/dist/structural-rules/python/PY005-fastapi-without-pydantic.d.ts +11 -0
  180. package/dist/structural-rules/python/PY005-fastapi-without-pydantic.d.ts.map +1 -0
  181. package/dist/structural-rules/python/PY005-fastapi-without-pydantic.js +154 -0
  182. package/dist/structural-rules/python/PY005-fastapi-without-pydantic.js.map +1 -0
  183. package/dist/structural-rules/python/PY006-blocking-io-in-async.d.ts +11 -0
  184. package/dist/structural-rules/python/PY006-blocking-io-in-async.d.ts.map +1 -0
  185. package/dist/structural-rules/python/PY006-blocking-io-in-async.js +130 -0
  186. package/dist/structural-rules/python/PY006-blocking-io-in-async.js.map +1 -0
  187. package/dist/structural-rules/python/PY007-sqlalchemy-session-leak.d.ts +11 -0
  188. package/dist/structural-rules/python/PY007-sqlalchemy-session-leak.d.ts.map +1 -0
  189. package/dist/structural-rules/python/PY007-sqlalchemy-session-leak.js +93 -0
  190. package/dist/structural-rules/python/PY007-sqlalchemy-session-leak.js.map +1 -0
  191. package/dist/structural-rules/python/PY008-celery-task-without-retry.d.ts +11 -0
  192. package/dist/structural-rules/python/PY008-celery-task-without-retry.d.ts.map +1 -0
  193. package/dist/structural-rules/python/PY008-celery-task-without-retry.js +154 -0
  194. package/dist/structural-rules/python/PY008-celery-task-without-retry.js.map +1 -0
  195. package/dist/structural-rules/python/PY009-unsafe-pickle-deserialization.d.ts +11 -0
  196. package/dist/structural-rules/python/PY009-unsafe-pickle-deserialization.d.ts.map +1 -0
  197. package/dist/structural-rules/python/PY009-unsafe-pickle-deserialization.js +133 -0
  198. package/dist/structural-rules/python/PY009-unsafe-pickle-deserialization.js.map +1 -0
  199. package/dist/structural-rules/python/PY010-leaked-aiohttp-session.d.ts +11 -0
  200. package/dist/structural-rules/python/PY010-leaked-aiohttp-session.d.ts.map +1 -0
  201. package/dist/structural-rules/python/PY010-leaked-aiohttp-session.js +80 -0
  202. package/dist/structural-rules/python/PY010-leaked-aiohttp-session.js.map +1 -0
  203. package/dist/structural-rules/python/PY011-thread-lifecycle.d.ts +11 -0
  204. package/dist/structural-rules/python/PY011-thread-lifecycle.d.ts.map +1 -0
  205. package/dist/structural-rules/python/PY011-thread-lifecycle.js +97 -0
  206. package/dist/structural-rules/python/PY011-thread-lifecycle.js.map +1 -0
  207. package/dist/structural-rules/python/PY012-asyncio-run-misuse.d.ts +11 -0
  208. package/dist/structural-rules/python/PY012-asyncio-run-misuse.d.ts.map +1 -0
  209. package/dist/structural-rules/python/PY012-asyncio-run-misuse.js +83 -0
  210. package/dist/structural-rules/python/PY012-asyncio-run-misuse.js.map +1 -0
  211. package/dist/structural-rules/python/PY013-mutable-default-arg.d.ts +11 -0
  212. package/dist/structural-rules/python/PY013-mutable-default-arg.d.ts.map +1 -0
  213. package/dist/structural-rules/python/PY013-mutable-default-arg.js +73 -0
  214. package/dist/structural-rules/python/PY013-mutable-default-arg.js.map +1 -0
  215. package/dist/structural-rules/python/PY014-fixed-sleep-retry.d.ts +11 -0
  216. package/dist/structural-rules/python/PY014-fixed-sleep-retry.d.ts.map +1 -0
  217. package/dist/structural-rules/python/PY014-fixed-sleep-retry.js +115 -0
  218. package/dist/structural-rules/python/PY014-fixed-sleep-retry.js.map +1 -0
  219. package/dist/structural-rules/rules/SR001-swallowed-async-rejection.d.ts +11 -0
  220. package/dist/structural-rules/rules/SR001-swallowed-async-rejection.d.ts.map +1 -0
  221. package/dist/structural-rules/rules/SR001-swallowed-async-rejection.js +145 -0
  222. package/dist/structural-rules/rules/SR001-swallowed-async-rejection.js.map +1 -0
  223. package/dist/structural-rules/rules/SR002-unbounded-collection.d.ts +11 -0
  224. package/dist/structural-rules/rules/SR002-unbounded-collection.d.ts.map +1 -0
  225. package/dist/structural-rules/rules/SR002-unbounded-collection.js +196 -0
  226. package/dist/structural-rules/rules/SR002-unbounded-collection.js.map +1 -0
  227. package/dist/structural-rules/rules/SR003-timer-without-cleanup.d.ts +11 -0
  228. package/dist/structural-rules/rules/SR003-timer-without-cleanup.d.ts.map +1 -0
  229. package/dist/structural-rules/rules/SR003-timer-without-cleanup.js +148 -0
  230. package/dist/structural-rules/rules/SR003-timer-without-cleanup.js.map +1 -0
  231. package/dist/structural-rules/rules/SR004-request-boundary-no-validation.d.ts +11 -0
  232. package/dist/structural-rules/rules/SR004-request-boundary-no-validation.d.ts.map +1 -0
  233. package/dist/structural-rules/rules/SR004-request-boundary-no-validation.js +162 -0
  234. package/dist/structural-rules/rules/SR004-request-boundary-no-validation.js.map +1 -0
  235. package/dist/structural-rules/rules/SR005-halfopen-probe-gate.d.ts +11 -0
  236. package/dist/structural-rules/rules/SR005-halfopen-probe-gate.d.ts.map +1 -0
  237. package/dist/structural-rules/rules/SR005-halfopen-probe-gate.js +150 -0
  238. package/dist/structural-rules/rules/SR005-halfopen-probe-gate.js.map +1 -0
  239. package/dist/structural-rules/rules/SR006-fanout-error-sanitization.d.ts +11 -0
  240. package/dist/structural-rules/rules/SR006-fanout-error-sanitization.d.ts.map +1 -0
  241. package/dist/structural-rules/rules/SR006-fanout-error-sanitization.js +161 -0
  242. package/dist/structural-rules/rules/SR006-fanout-error-sanitization.js.map +1 -0
  243. package/dist/structural-rules/rules/SR007-cross-request-error.d.ts +11 -0
  244. package/dist/structural-rules/rules/SR007-cross-request-error.d.ts.map +1 -0
  245. package/dist/structural-rules/rules/SR007-cross-request-error.js +175 -0
  246. package/dist/structural-rules/rules/SR007-cross-request-error.js.map +1 -0
  247. package/dist/structural-rules/rules/SR008-background-task-orphan.d.ts +11 -0
  248. package/dist/structural-rules/rules/SR008-background-task-orphan.d.ts.map +1 -0
  249. package/dist/structural-rules/rules/SR008-background-task-orphan.js +176 -0
  250. package/dist/structural-rules/rules/SR008-background-task-orphan.js.map +1 -0
  251. package/dist/structural-rules/rules/SR009-missing-retry-backoff.d.ts +11 -0
  252. package/dist/structural-rules/rules/SR009-missing-retry-backoff.d.ts.map +1 -0
  253. package/dist/structural-rules/rules/SR009-missing-retry-backoff.js +168 -0
  254. package/dist/structural-rules/rules/SR009-missing-retry-backoff.js.map +1 -0
  255. package/dist/structural-rules/rules/SR010-retry-storm.d.ts +11 -0
  256. package/dist/structural-rules/rules/SR010-retry-storm.d.ts.map +1 -0
  257. package/dist/structural-rules/rules/SR010-retry-storm.js +181 -0
  258. package/dist/structural-rules/rules/SR010-retry-storm.js.map +1 -0
  259. package/dist/structural-rules/rules/SR011-event-listener-leak.d.ts +11 -0
  260. package/dist/structural-rules/rules/SR011-event-listener-leak.d.ts.map +1 -0
  261. package/dist/structural-rules/rules/SR011-event-listener-leak.js +208 -0
  262. package/dist/structural-rules/rules/SR011-event-listener-leak.js.map +1 -0
  263. package/dist/structural-rules/rules/SR012-promise-race-leak.d.ts +11 -0
  264. package/dist/structural-rules/rules/SR012-promise-race-leak.d.ts.map +1 -0
  265. package/dist/structural-rules/rules/SR012-promise-race-leak.js +191 -0
  266. package/dist/structural-rules/rules/SR012-promise-race-leak.js.map +1 -0
  267. package/dist/structural-rules/rules/SR013-missing-idempotency-key.d.ts +11 -0
  268. package/dist/structural-rules/rules/SR013-missing-idempotency-key.d.ts.map +1 -0
  269. package/dist/structural-rules/rules/SR013-missing-idempotency-key.js +219 -0
  270. package/dist/structural-rules/rules/SR013-missing-idempotency-key.js.map +1 -0
  271. package/dist/structural-rules/rules/SR014-mutable-closure-async.d.ts +11 -0
  272. package/dist/structural-rules/rules/SR014-mutable-closure-async.d.ts.map +1 -0
  273. package/dist/structural-rules/rules/SR014-mutable-closure-async.js +208 -0
  274. package/dist/structural-rules/rules/SR014-mutable-closure-async.js.map +1 -0
  275. package/dist/structural-rules/rules/SR015-dangling-abort-controller.d.ts +11 -0
  276. package/dist/structural-rules/rules/SR015-dangling-abort-controller.d.ts.map +1 -0
  277. package/dist/structural-rules/rules/SR015-dangling-abort-controller.js +190 -0
  278. package/dist/structural-rules/rules/SR015-dangling-abort-controller.js.map +1 -0
  279. package/dist/structural-rules/rules/SR016-unsafe-json-parse.d.ts +11 -0
  280. package/dist/structural-rules/rules/SR016-unsafe-json-parse.d.ts.map +1 -0
  281. package/dist/structural-rules/rules/SR016-unsafe-json-parse.js +187 -0
  282. package/dist/structural-rules/rules/SR016-unsafe-json-parse.js.map +1 -0
  283. package/dist/structural-rules/suppressions.d.ts +43 -0
  284. package/dist/structural-rules/suppressions.d.ts.map +1 -0
  285. package/dist/structural-rules/suppressions.js +115 -0
  286. package/dist/structural-rules/suppressions.js.map +1 -0
  287. package/dist/structural-rules/types.d.ts +55 -0
  288. package/dist/structural-rules/types.d.ts.map +1 -0
  289. package/dist/structural-rules/types.js +3 -0
  290. package/dist/structural-rules/types.js.map +1 -0
  291. package/dist/utils/brain-cache.d.ts +100 -0
  292. package/dist/utils/brain-cache.d.ts.map +1 -0
  293. package/dist/utils/brain-cache.js +346 -0
  294. package/dist/utils/brain-cache.js.map +1 -0
  295. package/dist/utils/governance-provenance.d.ts +95 -0
  296. package/dist/utils/governance-provenance.d.ts.map +1 -0
  297. package/dist/utils/governance-provenance.js +187 -0
  298. package/dist/utils/governance-provenance.js.map +1 -0
  299. package/dist/utils/pilot-metrics.d.ts +46 -0
  300. package/dist/utils/pilot-metrics.d.ts.map +1 -0
  301. package/dist/utils/pilot-metrics.js +240 -0
  302. package/dist/utils/pilot-metrics.js.map +1 -0
  303. package/dist/utils/replay-runtime.d.ts +34 -0
  304. package/dist/utils/replay-runtime.d.ts.map +1 -1
  305. package/dist/utils/replay-runtime.js +207 -0
  306. package/dist/utils/replay-runtime.js.map +1 -1
  307. package/dist/utils/verify-runtime-stability.d.ts +142 -0
  308. package/dist/utils/verify-runtime-stability.d.ts.map +1 -0
  309. package/dist/utils/verify-runtime-stability.js +230 -0
  310. package/dist/utils/verify-runtime-stability.js.map +1 -0
  311. package/dist/workspace/cross-repo-graph.d.ts +111 -0
  312. package/dist/workspace/cross-repo-graph.d.ts.map +1 -0
  313. package/dist/workspace/cross-repo-graph.js +450 -0
  314. package/dist/workspace/cross-repo-graph.js.map +1 -0
  315. package/dist/workspace/federated-context.d.ts +144 -0
  316. package/dist/workspace/federated-context.d.ts.map +1 -0
  317. package/dist/workspace/federated-context.js +347 -0
  318. package/dist/workspace/federated-context.js.map +1 -0
  319. package/dist/workspace/index.d.ts +38 -0
  320. package/dist/workspace/index.d.ts.map +1 -0
  321. package/dist/workspace/index.js +48 -0
  322. package/dist/workspace/index.js.map +1 -0
  323. package/package.json +9 -9
@@ -0,0 +1,240 @@
1
+ "use strict";
2
+ /**
3
+ * Structural Analysis Cache (Phase 5 — Performance Stability)
4
+ *
5
+ * Persists rule-engine results to disk so that unchanged files are not
6
+ * re-analyzed on every `verify` run. Provides consistent CI performance
7
+ * independent of repo size.
8
+ *
9
+ * Cache design:
10
+ * Key: file path (relative to project root)
11
+ * Value: { contentHash, rulesVersion, violations, analysisMs, cachedAt }
12
+ *
13
+ * Invalidation triggers:
14
+ * 1. File content changes (SHA-256 of file content)
15
+ * 2. Rules version changes (SHA-256 of all rule IDs + policyRefs)
16
+ *
17
+ * Storage: .neurcode/structural-cache.json
18
+ * Write strategy: atomic (write to .tmp, then rename) to prevent corruption
19
+ * on process kill mid-write.
20
+ *
21
+ * This module is fully synchronous to stay compatible with the existing
22
+ * structural-on-diff.ts read path.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.StructuralCache = void 0;
26
+ exports.computeRulesVersion = computeRulesVersion;
27
+ exports.computeImplementationHash = computeImplementationHash;
28
+ const crypto_1 = require("crypto");
29
+ const fs_1 = require("fs");
30
+ const path_1 = require("path");
31
+ // ── Constants ─────────────────────────────────────────────────────────────────
32
+ const CACHE_FILE = 'structural-cache.json';
33
+ const NEURCODE_DIR = '.neurcode';
34
+ const CACHE_VERSION = 1;
35
+ // ── Helpers ───────────────────────────────────────────────────────────────────
36
+ function sha256(input) {
37
+ return (0, crypto_1.createHash)('sha256').update(input, 'utf-8').digest('hex');
38
+ }
39
+ function atomicWrite(filePath, content) {
40
+ const tmp = `${filePath}.tmp`;
41
+ const dir = (0, path_1.dirname)(filePath);
42
+ if (!(0, fs_1.existsSync)(dir)) {
43
+ (0, fs_1.mkdirSync)(dir, { recursive: true });
44
+ }
45
+ (0, fs_1.writeFileSync)(tmp, content, 'utf-8');
46
+ (0, fs_1.renameSync)(tmp, filePath);
47
+ }
48
+ // ── StructuralCache class ─────────────────────────────────────────────────────
49
+ class StructuralCache {
50
+ cacheFilePath;
51
+ store;
52
+ dirty = false;
53
+ constructor(projectRoot) {
54
+ this.cacheFilePath = (0, path_1.join)(projectRoot, NEURCODE_DIR, CACHE_FILE);
55
+ this.store = this.load();
56
+ }
57
+ // ── Load ────────────────────────────────────────────────────────────────────
58
+ load() {
59
+ if (!(0, fs_1.existsSync)(this.cacheFilePath)) {
60
+ return { version: CACHE_VERSION, entries: {} };
61
+ }
62
+ try {
63
+ const raw = (0, fs_1.readFileSync)(this.cacheFilePath, 'utf-8');
64
+ const parsed = JSON.parse(raw);
65
+ if (typeof parsed === 'object' &&
66
+ parsed !== null &&
67
+ parsed.version === CACHE_VERSION &&
68
+ typeof parsed.entries === 'object') {
69
+ return parsed;
70
+ }
71
+ }
72
+ catch {
73
+ // Corrupt cache — start fresh
74
+ }
75
+ return { version: CACHE_VERSION, entries: {} };
76
+ }
77
+ // ── Public API ──────────────────────────────────────────────────────────────
78
+ /**
79
+ * Check if a valid cache entry exists for the given file.
80
+ *
81
+ * @param filePath Relative file path (cache key)
82
+ * @param content Current file content
83
+ * @param rulesVersion Current rules fingerprint
84
+ */
85
+ get(filePath, content, rulesVersion) {
86
+ const entry = this.store.entries[filePath];
87
+ if (!entry)
88
+ return null;
89
+ const contentHash = sha256(content);
90
+ if (entry.contentHash !== contentHash)
91
+ return null;
92
+ if (entry.rulesVersion !== rulesVersion)
93
+ return null;
94
+ return entry.violations;
95
+ }
96
+ /**
97
+ * Store analysis results for a file.
98
+ */
99
+ set(filePath, content, rulesVersion, violations, analysisMs) {
100
+ const contentHash = sha256(content);
101
+ this.store.entries[filePath] = {
102
+ contentHash,
103
+ rulesVersion,
104
+ violations,
105
+ analysisMs,
106
+ cachedAt: new Date().toISOString(),
107
+ };
108
+ this.dirty = true;
109
+ }
110
+ /**
111
+ * Invalidate a specific file entry (e.g. on explicit cache bust).
112
+ */
113
+ invalidate(filePath) {
114
+ if (this.store.entries[filePath]) {
115
+ delete this.store.entries[filePath];
116
+ this.dirty = true;
117
+ }
118
+ }
119
+ /**
120
+ * Flush dirty cache to disk (atomic write).
121
+ * Safe to call even if nothing changed (no-op).
122
+ */
123
+ flush() {
124
+ if (!this.dirty)
125
+ return;
126
+ try {
127
+ atomicWrite(this.cacheFilePath, JSON.stringify(this.store, null, 2));
128
+ this.dirty = false;
129
+ }
130
+ catch {
131
+ // Non-fatal — cache write failure degrades to uncached analysis
132
+ }
133
+ }
134
+ /**
135
+ * Return cache diagnostics for the `neurcode cache diagnostics` command.
136
+ */
137
+ diagnostics() {
138
+ const entries = Object.values(this.store.entries);
139
+ const totalViolations = entries.reduce((s, e) => s + e.violations.length, 0);
140
+ const totalMs = entries.reduce((s, e) => s + e.analysisMs, 0);
141
+ const dates = entries.map(e => e.cachedAt).sort();
142
+ const staleRiskCount = entries.filter(e => e.staleRisk === true || e.implementationHashAvailable === false).length;
143
+ const withImplHash = entries.filter(e => e.implementationHashAvailable === true).length;
144
+ return {
145
+ cacheFilePath: this.cacheFilePath,
146
+ entryCount: entries.length,
147
+ totalCachedViolations: totalViolations,
148
+ averageAnalysisMs: entries.length > 0 ? Math.round(totalMs / entries.length) : 0,
149
+ oldestEntry: dates[0] ?? null,
150
+ newestEntry: dates[dates.length - 1] ?? null,
151
+ staleRiskEntryCount: staleRiskCount,
152
+ implementationHashCoveragePct: entries.length > 0
153
+ ? Math.round((withImplHash / entries.length) * 100)
154
+ : 100,
155
+ };
156
+ }
157
+ }
158
+ exports.StructuralCache = StructuralCache;
159
+ // ── Rules version fingerprint ─────────────────────────────────────────────────
160
+ /**
161
+ * Compute a stable two-tier fingerprint of the currently active rule set.
162
+ *
163
+ * Tier 1 (always): ruleId:policyRef — invalidates on rule additions/removals/policyRef changes
164
+ * Tier 2 (when available): implementation hash — invalidates when rule logic changes
165
+ * without a policyRef change (e.g. PY003 logic rewrite keeping policyRef='P017')
166
+ *
167
+ * The combined fingerprint is:
168
+ * sha256(tier1 + '\n\x1e\n' + tier2).slice(0,16)
169
+ *
170
+ * If Tier 2 is unavailable (distDir not found), the fingerprint uses Tier 1 only
171
+ * and the caller should set implementationHashAvailable=false in the cache entry.
172
+ *
173
+ * @param rules Array of { id, policyRef } from the registered rule engine
174
+ * @param distDir Optional path to the CLI dist/governance/ directory for Tier 2
175
+ */
176
+ function computeRulesVersion(rules, distDir) {
177
+ // Tier 1: ruleId:policyRef fingerprint
178
+ const tier1 = rules
179
+ .map(r => `${r.id}:${r.policyRef}`)
180
+ .sort()
181
+ .join('\n');
182
+ const tier1Hash = sha256(tier1);
183
+ // Tier 2: compiled implementation hash
184
+ const implHash = distDir ? computeImplementationHash(rules, distDir) : null;
185
+ const combined = implHash
186
+ ? sha256(`${tier1Hash}\n\x1e\n${implHash}`).slice(0, 16)
187
+ : tier1Hash.slice(0, 16);
188
+ return {
189
+ rulesVersion: combined,
190
+ implementationHash: implHash,
191
+ implementationHashAvailable: implHash !== null,
192
+ };
193
+ }
194
+ /**
195
+ * Compute a hash of the compiled rule implementation files.
196
+ *
197
+ * Reads compiled .js files for each rule under distDir/structural-rules and
198
+ * hashes the concatenated content. Changes when rule logic changes, even
199
+ * if ruleId and policyRef are unchanged (two-tier fingerprinting).
200
+ *
201
+ * Falls back gracefully when files are unreadable. Returns null if distDir
202
+ * does not exist or no rule implementation files are found.
203
+ */
204
+ function computeImplementationHash(rules, distDir) {
205
+ if (!(0, fs_1.existsSync)(distDir))
206
+ return null;
207
+ const hasher = (0, crypto_1.createHash)('sha256');
208
+ let filesHashed = 0;
209
+ // Sort rules for deterministic hash order
210
+ const sortedRules = [...rules].sort((a, b) => a.id.localeCompare(b.id));
211
+ for (const rule of sortedRules) {
212
+ const ruleIdLower = rule.id.toLowerCase();
213
+ const rulesBase = (0, path_1.join)(distDir, 'structural-rules');
214
+ // Check direct rule file
215
+ const targetFile = `${ruleIdLower}.js`;
216
+ let found = false;
217
+ if ((0, fs_1.existsSync)(rulesBase)) {
218
+ try {
219
+ const files = (0, fs_1.readdirSync)(rulesBase);
220
+ const match = files.find(f => f.toLowerCase() === targetFile);
221
+ if (match) {
222
+ hasher.update(`${rule.id}:`);
223
+ hasher.update((0, fs_1.readFileSync)((0, path_1.join)(rulesBase, match)));
224
+ filesHashed++;
225
+ found = true;
226
+ }
227
+ }
228
+ catch {
229
+ // Skip unreadable directory
230
+ }
231
+ }
232
+ if (!found) {
233
+ hasher.update(`${rule.id}:MISSING`);
234
+ }
235
+ }
236
+ if (filesHashed === 0)
237
+ return null;
238
+ return hasher.digest('hex').slice(0, 32);
239
+ }
240
+ //# sourceMappingURL=structural-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structural-cache.js","sourceRoot":"","sources":["../../src/governance/structural-cache.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AA+NH,kDAuBC;AAYD,8DA0CC;AA1SD,mCAAoC;AACpC,2BAAiG;AACjG,+BAAqC;AAwCrC,iFAAiF;AAEjF,MAAM,UAAU,GAAO,uBAAuB,CAAC;AAC/C,MAAM,YAAY,GAAK,WAAW,CAAC;AACnC,MAAM,aAAa,GAAI,CAAU,CAAC;AAElC,iFAAiF;AAEjF,SAAS,MAAM,CAAC,KAAa;IAC3B,OAAO,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACnE,CAAC;AA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G,CAAC,CAAC;oBAC7B,MAAM,CAAC,MAAM,CAAC,IAAA,iBAAY,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;oBACpD,WAAW,EAAE,CAAC;oBACd,KAAK,GAAG,IAAI,CAAC;gBACf,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,4BAA4B;YAC9B,CAAC;QACH,CAAC;QAED,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAED,IAAI,WAAW,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACnC,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { type StructuralViolation } from '../structural-rules';
2
+ import type { DiffFile } from '@neurcode-ai/diff-parser';
3
+ export interface StructuralOnDiffResult {
4
+ violations: StructuralViolation[];
5
+ rulesApplied: string[];
6
+ suppressedCount: number;
7
+ /** Phase 2: violations on modified lines (new violations) */
8
+ newViolationCount: number;
9
+ /** Phase 2: violations on unmodified historical lines (demoted to ADVISORY) */
10
+ legacyDebtCount: number;
11
+ /** Whether diff-scoped enforcement was active */
12
+ diffScopedEnforcement: boolean;
13
+ }
14
+ /**
15
+ * Run the default structural rule set on files touched by the diff.
16
+ *
17
+ * Phase 2 — Diff-Scoped Enforcement:
18
+ * When diffFiles carries hunk line ranges, violations are classified as:
19
+ * - introducedOnModifiedLine: true → BLOCKING eligible (new code)
20
+ * - introducedOnModifiedLine: false → ADVISORY only (legacy debt)
21
+ *
22
+ * Pass strictFullFile=true to restore the original whole-file behaviour
23
+ * (equivalent to the --strict-full-file CLI flag).
24
+ *
25
+ * No I/O beyond reading the file contents. The modified-line index is built
26
+ * entirely from the already-parsed diffFiles structure.
27
+ */
28
+ export declare function runStructuralOnDiffFiles(projectRoot: string, diffFiles: Array<{
29
+ path: string;
30
+ } | DiffFile>, options?: {
31
+ strictFullFile?: boolean;
32
+ }): StructuralOnDiffResult;
33
+ //# sourceMappingURL=structural-on-diff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structural-on-diff.d.ts","sourceRoot":"","sources":["../../src/governance/structural-on-diff.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqC,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAClG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAGzD,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,mBAAmB,EAAE,CAAC;IAClC,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,6DAA6D;IAC7D,iBAAiB,EAAE,MAAM,CAAC;IAC1B,+EAA+E;IAC/E,eAAe,EAAE,MAAM,CAAC;IACxB,iDAAiD;IACjD,qBAAqB,EAAE,OAAO,CAAC;CAChC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,wBAAwB,CACtC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,QAAQ,CAAC,EAC7C,OAAO,GAAE;IACP,cAAc,CAAC,EAAE,OAAO,CAAC;CACrB,GACL,sBAAsB,CAkDxB"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runStructuralOnDiffFiles = runStructuralOnDiffFiles;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ const structural_rules_1 = require("../structural-rules");
7
+ const diff_line_provenance_1 = require("./diff-line-provenance");
8
+ /**
9
+ * Run the default structural rule set on files touched by the diff.
10
+ *
11
+ * Phase 2 — Diff-Scoped Enforcement:
12
+ * When diffFiles carries hunk line ranges, violations are classified as:
13
+ * - introducedOnModifiedLine: true → BLOCKING eligible (new code)
14
+ * - introducedOnModifiedLine: false → ADVISORY only (legacy debt)
15
+ *
16
+ * Pass strictFullFile=true to restore the original whole-file behaviour
17
+ * (equivalent to the --strict-full-file CLI flag).
18
+ *
19
+ * No I/O beyond reading the file contents. The modified-line index is built
20
+ * entirely from the already-parsed diffFiles structure.
21
+ */
22
+ function runStructuralOnDiffFiles(projectRoot, diffFiles, options = {}) {
23
+ const strictMode = options.strictFullFile ?? false;
24
+ // Build the modified-line index from hunk data (Phase 2).
25
+ // If the diff objects don't carry hunk info (legacy callers), the index
26
+ // will be empty and all violations will be treated as new (safe default).
27
+ const modifiedLineIndex = (0, diff_line_provenance_1.buildModifiedLineIndex)(diffFiles);
28
+ const hasDiffLineData = modifiedLineIndex.size > 0;
29
+ const engine = (0, structural_rules_1.createDefaultStructuralRuleEngine)();
30
+ const filesToAnalyze = [];
31
+ for (const df of diffFiles) {
32
+ const absPath = (0, path_1.join)(projectRoot, df.path);
33
+ if (!(0, fs_1.existsSync)(absPath))
34
+ continue;
35
+ try {
36
+ const sourceText = (0, fs_1.readFileSync)(absPath, 'utf-8');
37
+ filesToAnalyze.push({ filePath: df.path, sourceText });
38
+ }
39
+ catch {
40
+ // skip unreadable
41
+ }
42
+ }
43
+ if (filesToAnalyze.length === 0) {
44
+ return {
45
+ violations: [],
46
+ rulesApplied: [],
47
+ suppressedCount: 0,
48
+ newViolationCount: 0,
49
+ legacyDebtCount: 0,
50
+ diffScopedEnforcement: false,
51
+ };
52
+ }
53
+ const result = engine.analyze(filesToAnalyze);
54
+ // Apply diff-scoped provenance classification (Phase 2)
55
+ const { violations, legacyDebtCount, newViolationCount } = hasDiffLineData && !strictMode
56
+ ? (0, diff_line_provenance_1.applyDiffScopedProvenance)(result.violations, modifiedLineIndex, false)
57
+ : { violations: result.violations, legacyDebtCount: 0, newViolationCount: result.violations.length };
58
+ return {
59
+ violations,
60
+ rulesApplied: result.rulesApplied,
61
+ suppressedCount: result.suppressedCount,
62
+ newViolationCount,
63
+ legacyDebtCount,
64
+ diffScopedEnforcement: hasDiffLineData && !strictMode,
65
+ };
66
+ }
67
+ //# sourceMappingURL=structural-on-diff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structural-on-diff.js","sourceRoot":"","sources":["../../src/governance/structural-on-diff.ts"],"names":[],"mappings":";;AAgCA,4DAwDC;AAxFD,2BAA8C;AAC9C,+BAA4B;AAC5B,0DAAkG;AAElG,iEAA2F;AAc3F;;;;;;;;;;;;;GAaG;AACH,SAAgB,wBAAwB,CACtC,WAAmB,EACnB,SAA6C,EAC7C,UAEI,EAAE;IAEN,MAAM,UAAU,GAAG,OAAO,CAAC,cAAc,IAAI,KAAK,CAAC;IAEnD,0DAA0D;IAC1D,wEAAwE;IACxE,0EAA0E;IAC1E,MAAM,iBAAiB,GAAG,IAAA,6CAAsB,EAAC,SAAuB,CAAC,CAAC;IAC1E,MAAM,eAAe,GAAG,iBAAiB,CAAC,IAAI,GAAG,CAAC,CAAC;IAEnD,MAAM,MAAM,GAAG,IAAA,oDAAiC,GAAE,CAAC;IACnD,MAAM,cAAc,GAAoD,EAAE,CAAC;IAE3E,KAAK,MAAM,EAAE,IAAI,SAAS,EAAE,CAAC;QAC3B,MAAM,OAAO,GAAG,IAAA,WAAI,EAAC,WAAW,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAA,eAAU,EAAC,OAAO,CAAC;YAAE,SAAS;QACnC,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,IAAA,iBAAY,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAClD,cAAc,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;QACzD,CAAC;QAAC,MAAM,CAAC;YACP,kBAAkB;QACpB,CAAC;IACH,CAAC;IAED,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO;YACL,UAAU,EAAE,EAAE;YACd,YAAY,EAAE,EAAE;YAChB,eAAe,EAAE,CAAC;YAClB,iBAAiB,EAAE,CAAC;YACpB,eAAe,EAAE,CAAC;YAClB,qBAAqB,EAAE,KAAK;SAC7B,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAE9C,wDAAwD;IACxD,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,iBAAiB,EAAE,GACtD,eAAe,IAAI,CAAC,UAAU;QAC5B,CAAC,CAAC,IAAA,gDAAyB,EAAC,MAAM,CAAC,UAAU,EAAE,iBAAiB,EAAE,KAAK,CAAC;QACxE,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,eAAe,EAAE,CAAC,EAAE,iBAAiB,EAAE,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;IAEzG,OAAO;QACL,UAAU;QACV,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,eAAe,EAAE,MAAM,CAAC,eAAe;QACvC,iBAAiB;QACjB,eAAe;QACf,qBAAqB,EAAE,eAAe,IAAI,CAAC,UAAU;KACtD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { StructuralViolation } from '../structural-rules';
2
+ export type PolicyViolationRow = {
3
+ rule: string;
4
+ file: string;
5
+ severity: string;
6
+ message?: string;
7
+ line?: number;
8
+ /** Phase 4: language of the original finding — required for remediation boundary checks. */
9
+ language?: string;
10
+ };
11
+ /**
12
+ * Append structural violations to policy-engine rows so verdicts and JSON violations stay aligned.
13
+ * Dedupes identical structural rule + file + line.
14
+ *
15
+ * @deprecated The canonical pipeline (`buildGovernanceVerificationEnvelope`) is the single
16
+ * aggregation point. Prefer passing `structuralViolations` directly rather than merging here.
17
+ * Structural rows merged here are stripped by `stripStructuralPolicyRows()` in the pipeline
18
+ * to prevent duplicate GovernanceFinding objects. This function is kept for backward compat
19
+ * with existing callers that rely on the combined `violations` array for non-canonical output.
20
+ */
21
+ export declare function mergeStructuralIntoPolicyViolations(policyViolations: PolicyViolationRow[], structuralViolations: StructuralViolation[]): void;
22
+ //# sourceMappingURL=structural-policy-merge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structural-policy-merge.d.ts","sourceRoot":"","sources":["../../src/governance/structural-policy-merge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE/D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4FAA4F;IAC5F,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,mCAAmC,CACjD,gBAAgB,EAAE,kBAAkB,EAAE,EACtC,oBAAoB,EAAE,mBAAmB,EAAE,GAC1C,IAAI,CAkBN"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeStructuralIntoPolicyViolations = mergeStructuralIntoPolicyViolations;
4
+ /**
5
+ * Append structural violations to policy-engine rows so verdicts and JSON violations stay aligned.
6
+ * Dedupes identical structural rule + file + line.
7
+ *
8
+ * @deprecated The canonical pipeline (`buildGovernanceVerificationEnvelope`) is the single
9
+ * aggregation point. Prefer passing `structuralViolations` directly rather than merging here.
10
+ * Structural rows merged here are stripped by `stripStructuralPolicyRows()` in the pipeline
11
+ * to prevent duplicate GovernanceFinding objects. This function is kept for backward compat
12
+ * with existing callers that rely on the combined `violations` array for non-canonical output.
13
+ */
14
+ function mergeStructuralIntoPolicyViolations(policyViolations, structuralViolations) {
15
+ const seen = new Set(policyViolations.map((v) => `${v.rule}|${v.file}|${v.line ?? 0}`));
16
+ for (const sv of structuralViolations) {
17
+ const rule = `structural:${sv.ruleId}`;
18
+ const key = `${rule}|${sv.filePath}|${sv.line}`;
19
+ if (seen.has(key))
20
+ continue;
21
+ seen.add(key);
22
+ policyViolations.push({
23
+ file: sv.filePath,
24
+ rule,
25
+ severity: sv.severity === 'BLOCKING' ? 'block' : 'warn',
26
+ message: `[${sv.ruleId}] ${sv.ruleName}: ${sv.operationalRisk}`,
27
+ line: sv.line,
28
+ language: sv.language,
29
+ });
30
+ }
31
+ }
32
+ //# sourceMappingURL=structural-policy-merge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structural-policy-merge.js","sourceRoot":"","sources":["../../src/governance/structural-policy-merge.ts"],"names":[],"mappings":";;AAsBA,kFAqBC;AA/BD;;;;;;;;;GASG;AACH,SAAgB,mCAAmC,CACjD,gBAAsC,EACtC,oBAA2C;IAE3C,MAAM,IAAI,GAAG,IAAI,GAAG,CAClB,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,EAAE,CAAC,CAClE,CAAC;IACF,KAAK,MAAM,EAAE,IAAI,oBAAoB,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,cAAc,EAAE,CAAC,MAAM,EAAE,CAAC;QACvC,MAAM,GAAG,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,QAAQ,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;QAChD,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,SAAS;QAC5B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACd,gBAAgB,CAAC,IAAI,CAAC;YACpB,IAAI,EAAE,EAAE,CAAC,QAAQ;YACjB,IAAI;YACJ,QAAQ,EAAE,EAAE,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;YACvD,OAAO,EAAE,IAAI,EAAE,CAAC,MAAM,KAAK,EAAE,CAAC,QAAQ,KAAK,EAAE,CAAC,eAAe,EAAE;YAC/D,IAAI,EAAE,EAAE,CAAC,IAAI;YACb,QAAQ,EAAE,EAAE,CAAC,QAAQ;SACtB,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Verify Runtime Guard (Phase 5 — CI Stability Hardening)
3
+ *
4
+ * Provides:
5
+ * 1. withVerifyTimeout() — wraps any verify sub-step with a wall-clock timeout.
6
+ * On timeout: returns a degraded result instead of hanging indefinitely.
7
+ * This ensures CI jobs always terminate, even when a rule engine or
8
+ * brain indexer stalls on an unexpectedly large file.
9
+ *
10
+ * 2. buildCIHealthSummary() — produces a structured CI health summary with:
11
+ * - cache warm/cold indicator
12
+ * - per-subsystem latency breakdown
13
+ * - degraded subsystem list
14
+ * Used for CI visibility when --ci flag is set.
15
+ *
16
+ * Key design invariant:
17
+ * withVerifyTimeout NEVER throws. It returns a typed DegradedResult.
18
+ * Callers must check result.degraded before using result.value.
19
+ */
20
+ export interface DegradedResult<T> {
21
+ degraded: false;
22
+ value: T;
23
+ durationMs: number;
24
+ }
25
+ export interface TimeoutResult {
26
+ degraded: true;
27
+ reason: 'timeout';
28
+ timeoutMs: number;
29
+ durationMs: number;
30
+ }
31
+ export interface ErrorResult {
32
+ degraded: true;
33
+ reason: 'error';
34
+ error: string;
35
+ durationMs: number;
36
+ }
37
+ export type SubstepResult<T> = DegradedResult<T> | TimeoutResult | ErrorResult;
38
+ export interface CISubsystemTiming {
39
+ name: string;
40
+ durationMs: number;
41
+ status: 'ok' | 'degraded' | 'timeout' | 'error' | 'skipped';
42
+ }
43
+ export interface CIHealthSummary {
44
+ /** Was the structural cache warm (hits > 0) or cold? */
45
+ cacheStatus: 'warm' | 'cold' | 'disabled';
46
+ /** Total wall-clock time across all subsystems */
47
+ totalDurationMs: number;
48
+ /** Per-subsystem timing breakdown */
49
+ subsystems: CISubsystemTiming[];
50
+ /** Names of subsystems that ran in degraded mode */
51
+ degradedSubsystems: string[];
52
+ /** Whether all subsystems completed successfully */
53
+ allSubsystemsHealthy: boolean;
54
+ /** ISO timestamp */
55
+ generatedAt: string;
56
+ }
57
+ /**
58
+ * Run an async function with a wall-clock timeout.
59
+ *
60
+ * On success: returns { degraded: false, value: T, durationMs }
61
+ * On timeout: returns { degraded: true, reason: 'timeout', timeoutMs, durationMs }
62
+ * On error: returns { degraded: true, reason: 'error', error: string, durationMs }
63
+ *
64
+ * NEVER throws. All error/timeout paths are handled internally.
65
+ *
66
+ * @param fn The async function to execute
67
+ * @param timeoutMs Wall-clock timeout in milliseconds
68
+ */
69
+ export declare function withVerifyTimeout<T>(fn: () => Promise<T>, timeoutMs: number): Promise<SubstepResult<T>>;
70
+ /**
71
+ * Synchronous version of withVerifyTimeout for use with non-async functions.
72
+ *
73
+ * Since true synchronous timeout is impossible in Node.js without worker threads,
74
+ * this wraps the synchronous function as a Promise and applies the async timeout.
75
+ * If the sync function blocks the event loop longer than timeoutMs, the timeout
76
+ * will fire only after it completes — this is a best-effort guard for functions
77
+ * that are expected to complete quickly but may unexpectedly stall.
78
+ */
79
+ export declare function withVerifyTimeoutSync<T>(fn: () => T, timeoutMs: number): Promise<SubstepResult<T>>;
80
+ export interface CIHealthInput {
81
+ subsystems: CISubsystemTiming[];
82
+ cacheHits: number;
83
+ cacheEnabled: boolean;
84
+ }
85
+ /**
86
+ * Build a structured CI health summary from subsystem timing data.
87
+ *
88
+ * @param input Subsystem timings collected during verify execution
89
+ */
90
+ export declare function buildCIHealthSummary(input: CIHealthInput): CIHealthSummary;
91
+ /** Default timeout for the structural rule engine per verify run (30s) */
92
+ export declare const STRUCTURAL_ENGINE_TIMEOUT_MS = 30000;
93
+ /** Default timeout for the brain context indexer (20s) */
94
+ export declare const BRAIN_INDEXER_TIMEOUT_MS = 20000;
95
+ /** Default timeout for intent engine operations (25s) */
96
+ export declare const INTENT_ENGINE_TIMEOUT_MS = 25000;
97
+ /** Maximum total verify wall-clock time before CI is considered hung (5min) */
98
+ export declare const VERIFY_TOTAL_TIMEOUT_MS = 300000;
99
+ //# sourceMappingURL=verify-runtime-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify-runtime-guard.d.ts","sourceRoot":"","sources":["../../src/governance/verify-runtime-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,QAAQ,EAAE,KAAK,CAAC;IAChB,KAAK,EAAE,CAAC,CAAC;IACT,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,IAAI,CAAC;IACf,MAAM,EAAE,SAAS,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,IAAI,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG,aAAa,GAAG,WAAW,CAAC;AAE/E,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,IAAI,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;CAC7D;AAED,MAAM,WAAW,eAAe;IAC9B,wDAAwD;IACxD,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;IAC1C,kDAAkD;IAClD,eAAe,EAAE,MAAM,CAAC;IACxB,qCAAqC;IACrC,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,oDAAoD;IACpD,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,oDAAoD;IACpD,oBAAoB,EAAE,OAAO,CAAC;IAC9B,oBAAoB;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAID;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,EACvC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CA4C3B;AAED;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CAAC,CAAC,EAC3C,EAAE,EAAE,MAAM,CAAC,EACX,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAE3B;AAID,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,GAAG,eAAe,CAwB1E;AAID,0EAA0E;AAC1E,eAAO,MAAM,4BAA4B,QAAS,CAAC;AAEnD,0DAA0D;AAC1D,eAAO,MAAM,wBAAwB,QAAS,CAAC;AAE/C,yDAAyD;AACzD,eAAO,MAAM,wBAAwB,QAAS,CAAC;AAE/C,+EAA+E;AAC/E,eAAO,MAAM,uBAAuB,SAAU,CAAC"}
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ /**
3
+ * Verify Runtime Guard (Phase 5 — CI Stability Hardening)
4
+ *
5
+ * Provides:
6
+ * 1. withVerifyTimeout() — wraps any verify sub-step with a wall-clock timeout.
7
+ * On timeout: returns a degraded result instead of hanging indefinitely.
8
+ * This ensures CI jobs always terminate, even when a rule engine or
9
+ * brain indexer stalls on an unexpectedly large file.
10
+ *
11
+ * 2. buildCIHealthSummary() — produces a structured CI health summary with:
12
+ * - cache warm/cold indicator
13
+ * - per-subsystem latency breakdown
14
+ * - degraded subsystem list
15
+ * Used for CI visibility when --ci flag is set.
16
+ *
17
+ * Key design invariant:
18
+ * withVerifyTimeout NEVER throws. It returns a typed DegradedResult.
19
+ * Callers must check result.degraded before using result.value.
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.VERIFY_TOTAL_TIMEOUT_MS = exports.INTENT_ENGINE_TIMEOUT_MS = exports.BRAIN_INDEXER_TIMEOUT_MS = exports.STRUCTURAL_ENGINE_TIMEOUT_MS = void 0;
23
+ exports.withVerifyTimeout = withVerifyTimeout;
24
+ exports.withVerifyTimeoutSync = withVerifyTimeoutSync;
25
+ exports.buildCIHealthSummary = buildCIHealthSummary;
26
+ // ── withVerifyTimeout ─────────────────────────────────────────────────────────
27
+ /**
28
+ * Run an async function with a wall-clock timeout.
29
+ *
30
+ * On success: returns { degraded: false, value: T, durationMs }
31
+ * On timeout: returns { degraded: true, reason: 'timeout', timeoutMs, durationMs }
32
+ * On error: returns { degraded: true, reason: 'error', error: string, durationMs }
33
+ *
34
+ * NEVER throws. All error/timeout paths are handled internally.
35
+ *
36
+ * @param fn The async function to execute
37
+ * @param timeoutMs Wall-clock timeout in milliseconds
38
+ */
39
+ async function withVerifyTimeout(fn, timeoutMs) {
40
+ const startMs = Date.now();
41
+ return new Promise((resolve) => {
42
+ let settled = false;
43
+ const timer = setTimeout(() => {
44
+ if (!settled) {
45
+ settled = true;
46
+ resolve({
47
+ degraded: true,
48
+ reason: 'timeout',
49
+ timeoutMs,
50
+ durationMs: Date.now() - startMs,
51
+ });
52
+ }
53
+ }, timeoutMs);
54
+ fn().then((value) => {
55
+ if (!settled) {
56
+ settled = true;
57
+ clearTimeout(timer);
58
+ resolve({
59
+ degraded: false,
60
+ value,
61
+ durationMs: Date.now() - startMs,
62
+ });
63
+ }
64
+ }, (err) => {
65
+ if (!settled) {
66
+ settled = true;
67
+ clearTimeout(timer);
68
+ resolve({
69
+ degraded: true,
70
+ reason: 'error',
71
+ error: err instanceof Error ? err.message : String(err),
72
+ durationMs: Date.now() - startMs,
73
+ });
74
+ }
75
+ });
76
+ });
77
+ }
78
+ /**
79
+ * Synchronous version of withVerifyTimeout for use with non-async functions.
80
+ *
81
+ * Since true synchronous timeout is impossible in Node.js without worker threads,
82
+ * this wraps the synchronous function as a Promise and applies the async timeout.
83
+ * If the sync function blocks the event loop longer than timeoutMs, the timeout
84
+ * will fire only after it completes — this is a best-effort guard for functions
85
+ * that are expected to complete quickly but may unexpectedly stall.
86
+ */
87
+ async function withVerifyTimeoutSync(fn, timeoutMs) {
88
+ return withVerifyTimeout(() => Promise.resolve(fn()), timeoutMs);
89
+ }
90
+ /**
91
+ * Build a structured CI health summary from subsystem timing data.
92
+ *
93
+ * @param input Subsystem timings collected during verify execution
94
+ */
95
+ function buildCIHealthSummary(input) {
96
+ const totalDurationMs = input.subsystems.reduce((s, sub) => s + sub.durationMs, 0);
97
+ const degradedSubsystems = input.subsystems
98
+ .filter(s => s.status === 'degraded' || s.status === 'timeout' || s.status === 'error')
99
+ .map(s => s.name);
100
+ const allSubsystemsHealthy = degradedSubsystems.length === 0;
101
+ let cacheStatus;
102
+ if (!input.cacheEnabled) {
103
+ cacheStatus = 'disabled';
104
+ }
105
+ else if (input.cacheHits > 0) {
106
+ cacheStatus = 'warm';
107
+ }
108
+ else {
109
+ cacheStatus = 'cold';
110
+ }
111
+ return {
112
+ cacheStatus,
113
+ totalDurationMs,
114
+ subsystems: input.subsystems,
115
+ degradedSubsystems,
116
+ allSubsystemsHealthy,
117
+ generatedAt: new Date().toISOString(),
118
+ };
119
+ }
120
+ // ── Default timeout constants ─────────────────────────────────────────────────
121
+ /** Default timeout for the structural rule engine per verify run (30s) */
122
+ exports.STRUCTURAL_ENGINE_TIMEOUT_MS = 30_000;
123
+ /** Default timeout for the brain context indexer (20s) */
124
+ exports.BRAIN_INDEXER_TIMEOUT_MS = 20_000;
125
+ /** Default timeout for intent engine operations (25s) */
126
+ exports.INTENT_ENGINE_TIMEOUT_MS = 25_000;
127
+ /** Maximum total verify wall-clock time before CI is considered hung (5min) */
128
+ exports.VERIFY_TOTAL_TIMEOUT_MS = 300_000;
129
+ //# sourceMappingURL=verify-runtime-guard.js.map