@pavanyn/docugen 1.1.1 → 1.3.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 (515) hide show
  1. package/LICENSE +20 -4
  2. package/README.md +12 -6
  3. package/dist/agents/cli-backend.d.ts.map +1 -1
  4. package/dist/agents/cli-backend.js +10 -1
  5. package/dist/agents/cli-backend.js.map +1 -1
  6. package/dist/changes/schema.d.ts +21 -60
  7. package/dist/changes/schema.d.ts.map +1 -1
  8. package/dist/cli.d.ts.map +1 -1
  9. package/dist/cli.js +45 -0
  10. package/dist/cli.js.map +1 -1
  11. package/dist/commands/answer.js +2 -2
  12. package/dist/commands/answer.js.map +1 -1
  13. package/dist/commands/ask.d.ts.map +1 -1
  14. package/dist/commands/ask.js +5 -3
  15. package/dist/commands/ask.js.map +1 -1
  16. package/dist/commands/audit-docs.d.ts +39 -0
  17. package/dist/commands/audit-docs.d.ts.map +1 -0
  18. package/dist/commands/audit-docs.js +192 -0
  19. package/dist/commands/audit-docs.js.map +1 -0
  20. package/dist/commands/bootstrap.d.ts.map +1 -1
  21. package/dist/commands/bootstrap.js +3 -37
  22. package/dist/commands/bootstrap.js.map +1 -1
  23. package/dist/commands/document.d.ts +30 -0
  24. package/dist/commands/document.d.ts.map +1 -0
  25. package/dist/commands/document.js +177 -0
  26. package/dist/commands/document.js.map +1 -0
  27. package/dist/commands/inference-policy.d.ts +11 -0
  28. package/dist/commands/inference-policy.d.ts.map +1 -0
  29. package/dist/commands/inference-policy.js +47 -0
  30. package/dist/commands/inference-policy.js.map +1 -0
  31. package/dist/commands/triage.js +2 -2
  32. package/dist/commands/triage.js.map +1 -1
  33. package/dist/config/paths.d.ts +4 -0
  34. package/dist/config/paths.d.ts.map +1 -1
  35. package/dist/config/paths.js +4 -0
  36. package/dist/config/paths.js.map +1 -1
  37. package/dist/config/schema.d.ts +60 -304
  38. package/dist/config/schema.d.ts.map +1 -1
  39. package/dist/config/schema.js +31 -9
  40. package/dist/config/schema.js.map +1 -1
  41. package/dist/detect/inventory-infra.d.ts +51 -0
  42. package/dist/detect/inventory-infra.d.ts.map +1 -0
  43. package/dist/detect/inventory-infra.js +247 -0
  44. package/dist/detect/inventory-infra.js.map +1 -0
  45. package/dist/detect/inventory-manifests.d.ts +60 -0
  46. package/dist/detect/inventory-manifests.d.ts.map +1 -0
  47. package/dist/detect/inventory-manifests.js +791 -0
  48. package/dist/detect/inventory-manifests.js.map +1 -0
  49. package/dist/detect/inventory.d.ts +110 -0
  50. package/dist/detect/inventory.d.ts.map +1 -0
  51. package/dist/detect/inventory.js +494 -0
  52. package/dist/detect/inventory.js.map +1 -0
  53. package/dist/detect/signatures.d.ts +9 -0
  54. package/dist/detect/signatures.d.ts.map +1 -1
  55. package/dist/detect/signatures.js +271 -32
  56. package/dist/detect/signatures.js.map +1 -1
  57. package/dist/detect/stack.d.ts +10 -0
  58. package/dist/detect/stack.d.ts.map +1 -1
  59. package/dist/detect/stack.js +88 -16
  60. package/dist/detect/stack.js.map +1 -1
  61. package/dist/extract/config/index.d.ts.map +1 -1
  62. package/dist/extract/config/index.js +6 -3
  63. package/dist/extract/config/index.js.map +1 -1
  64. package/dist/extract/csharp-constants.d.ts +25 -0
  65. package/dist/extract/csharp-constants.d.ts.map +1 -0
  66. package/dist/extract/csharp-constants.js +181 -0
  67. package/dist/extract/csharp-constants.js.map +1 -0
  68. package/dist/extract/csharp-source.d.ts +100 -0
  69. package/dist/extract/csharp-source.d.ts.map +1 -0
  70. package/dist/extract/csharp-source.js +514 -0
  71. package/dist/extract/csharp-source.js.map +1 -0
  72. package/dist/extract/endpoints/aspnet-chains.d.ts +50 -0
  73. package/dist/extract/endpoints/aspnet-chains.d.ts.map +1 -0
  74. package/dist/extract/endpoints/aspnet-chains.js +263 -0
  75. package/dist/extract/endpoints/aspnet-chains.js.map +1 -0
  76. package/dist/extract/endpoints/aspnet-controllers.d.ts +26 -0
  77. package/dist/extract/endpoints/aspnet-controllers.d.ts.map +1 -0
  78. package/dist/extract/endpoints/aspnet-controllers.js +367 -0
  79. package/dist/extract/endpoints/aspnet-controllers.js.map +1 -0
  80. package/dist/extract/endpoints/aspnet-minimal.d.ts +21 -0
  81. package/dist/extract/endpoints/aspnet-minimal.d.ts.map +1 -0
  82. package/dist/extract/endpoints/aspnet-minimal.js +608 -0
  83. package/dist/extract/endpoints/aspnet-minimal.js.map +1 -0
  84. package/dist/extract/endpoints/aspnet-routes.d.ts +45 -0
  85. package/dist/extract/endpoints/aspnet-routes.d.ts.map +1 -0
  86. package/dist/extract/endpoints/aspnet-routes.js +63 -0
  87. package/dist/extract/endpoints/aspnet-routes.js.map +1 -0
  88. package/dist/extract/endpoints/aspnet.d.ts +26 -0
  89. package/dist/extract/endpoints/aspnet.d.ts.map +1 -0
  90. package/dist/extract/endpoints/aspnet.js +54 -0
  91. package/dist/extract/endpoints/aspnet.js.map +1 -0
  92. package/dist/extract/endpoints/django.d.ts.map +1 -1
  93. package/dist/extract/endpoints/django.js +107 -4
  94. package/dist/extract/endpoints/django.js.map +1 -1
  95. package/dist/extract/endpoints/drf.d.ts +97 -0
  96. package/dist/extract/endpoints/drf.d.ts.map +1 -0
  97. package/dist/extract/endpoints/drf.js +501 -0
  98. package/dist/extract/endpoints/drf.js.map +1 -0
  99. package/dist/extract/endpoints/fastapi.d.ts.map +1 -1
  100. package/dist/extract/endpoints/fastapi.js +2 -1
  101. package/dist/extract/endpoints/fastapi.js.map +1 -1
  102. package/dist/extract/endpoints/fastify.d.ts +7 -0
  103. package/dist/extract/endpoints/fastify.d.ts.map +1 -0
  104. package/dist/extract/endpoints/fastify.js +438 -0
  105. package/dist/extract/endpoints/fastify.js.map +1 -0
  106. package/dist/extract/endpoints/flask.d.ts +77 -0
  107. package/dist/extract/endpoints/flask.d.ts.map +1 -0
  108. package/dist/extract/endpoints/flask.js +571 -0
  109. package/dist/extract/endpoints/flask.js.map +1 -0
  110. package/dist/extract/endpoints/go-http.d.ts +43 -0
  111. package/dist/extract/endpoints/go-http.d.ts.map +1 -0
  112. package/dist/extract/endpoints/go-http.js +148 -0
  113. package/dist/extract/endpoints/go-http.js.map +1 -0
  114. package/dist/extract/endpoints/go-routes.d.ts +54 -0
  115. package/dist/extract/endpoints/go-routes.d.ts.map +1 -0
  116. package/dist/extract/endpoints/go-routes.js +726 -0
  117. package/dist/extract/endpoints/go-routes.js.map +1 -0
  118. package/dist/extract/endpoints/hono.d.ts +7 -0
  119. package/dist/extract/endpoints/hono.d.ts.map +1 -0
  120. package/dist/extract/endpoints/hono.js +278 -0
  121. package/dist/extract/endpoints/hono.js.map +1 -0
  122. package/dist/extract/endpoints/index.d.ts.map +1 -1
  123. package/dist/extract/endpoints/index.js +57 -3
  124. package/dist/extract/endpoints/index.js.map +1 -1
  125. package/dist/extract/endpoints/js-router-ast.d.ts +42 -0
  126. package/dist/extract/endpoints/js-router-ast.d.ts.map +1 -0
  127. package/dist/extract/endpoints/js-router-ast.js +183 -0
  128. package/dist/extract/endpoints/js-router-ast.js.map +1 -0
  129. package/dist/extract/endpoints/js-routers.d.ts +190 -0
  130. package/dist/extract/endpoints/js-routers.d.ts.map +1 -0
  131. package/dist/extract/endpoints/js-routers.js +740 -0
  132. package/dist/extract/endpoints/js-routers.js.map +1 -0
  133. package/dist/extract/endpoints/koa.d.ts +7 -0
  134. package/dist/extract/endpoints/koa.d.ts.map +1 -0
  135. package/dist/extract/endpoints/koa.js +239 -0
  136. package/dist/extract/endpoints/koa.js.map +1 -0
  137. package/dist/extract/endpoints/laravel-routes.d.ts +57 -0
  138. package/dist/extract/endpoints/laravel-routes.d.ts.map +1 -0
  139. package/dist/extract/endpoints/laravel-routes.js +483 -0
  140. package/dist/extract/endpoints/laravel-routes.js.map +1 -0
  141. package/dist/extract/endpoints/laravel.d.ts +23 -0
  142. package/dist/extract/endpoints/laravel.d.ts.map +1 -0
  143. package/dist/extract/endpoints/laravel.js +518 -0
  144. package/dist/extract/endpoints/laravel.js.map +1 -0
  145. package/dist/extract/endpoints/nest-middleware.d.ts +43 -0
  146. package/dist/extract/endpoints/nest-middleware.d.ts.map +1 -0
  147. package/dist/extract/endpoints/nest-middleware.js +134 -0
  148. package/dist/extract/endpoints/nest-middleware.js.map +1 -0
  149. package/dist/extract/endpoints/nest.d.ts +1 -0
  150. package/dist/extract/endpoints/nest.d.ts.map +1 -1
  151. package/dist/extract/endpoints/nest.js +36 -2
  152. package/dist/extract/endpoints/nest.js.map +1 -1
  153. package/dist/extract/endpoints/python.d.ts.map +1 -1
  154. package/dist/extract/endpoints/python.js +44 -1
  155. package/dist/extract/endpoints/python.js.map +1 -1
  156. package/dist/extract/endpoints/rails-routes.d.ts +40 -0
  157. package/dist/extract/endpoints/rails-routes.d.ts.map +1 -0
  158. package/dist/extract/endpoints/rails-routes.js +588 -0
  159. package/dist/extract/endpoints/rails-routes.js.map +1 -0
  160. package/dist/extract/endpoints/rails.d.ts +23 -0
  161. package/dist/extract/endpoints/rails.d.ts.map +1 -0
  162. package/dist/extract/endpoints/rails.js +236 -0
  163. package/dist/extract/endpoints/rails.js.map +1 -0
  164. package/dist/extract/endpoints/spring-constants.d.ts +55 -0
  165. package/dist/extract/endpoints/spring-constants.d.ts.map +1 -0
  166. package/dist/extract/endpoints/spring-constants.js +174 -0
  167. package/dist/extract/endpoints/spring-constants.js.map +1 -0
  168. package/dist/extract/endpoints/spring.d.ts +35 -0
  169. package/dist/extract/endpoints/spring.d.ts.map +1 -0
  170. package/dist/extract/endpoints/spring.js +446 -0
  171. package/dist/extract/endpoints/spring.js.map +1 -0
  172. package/dist/extract/go-source.d.ts +119 -0
  173. package/dist/extract/go-source.d.ts.map +1 -0
  174. package/dist/extract/go-source.js +404 -0
  175. package/dist/extract/go-source.js.map +1 -0
  176. package/dist/extract/inflect.d.ts +15 -0
  177. package/dist/extract/inflect.d.ts.map +1 -0
  178. package/dist/extract/inflect.js +103 -0
  179. package/dist/extract/inflect.js.map +1 -0
  180. package/dist/extract/java-source.d.ts +84 -0
  181. package/dist/extract/java-source.d.ts.map +1 -0
  182. package/dist/extract/java-source.js +402 -0
  183. package/dist/extract/java-source.js.map +1 -0
  184. package/dist/extract/jobs/dotnet-jobs.d.ts +27 -0
  185. package/dist/extract/jobs/dotnet-jobs.d.ts.map +1 -0
  186. package/dist/extract/jobs/dotnet-jobs.js +205 -0
  187. package/dist/extract/jobs/dotnet-jobs.js.map +1 -0
  188. package/dist/extract/jobs/index.d.ts.map +1 -1
  189. package/dist/extract/jobs/index.js +23 -1
  190. package/dist/extract/jobs/index.js.map +1 -1
  191. package/dist/extract/jobs/laravel-jobs.d.ts +35 -0
  192. package/dist/extract/jobs/laravel-jobs.d.ts.map +1 -0
  193. package/dist/extract/jobs/laravel-jobs.js +223 -0
  194. package/dist/extract/jobs/laravel-jobs.js.map +1 -0
  195. package/dist/extract/jobs/python-call-args.d.ts +66 -0
  196. package/dist/extract/jobs/python-call-args.d.ts.map +1 -0
  197. package/dist/extract/jobs/python-call-args.js +196 -0
  198. package/dist/extract/jobs/python-call-args.js.map +1 -0
  199. package/dist/extract/jobs/python-jobs.d.ts +18 -0
  200. package/dist/extract/jobs/python-jobs.d.ts.map +1 -0
  201. package/dist/extract/jobs/python-jobs.js +259 -0
  202. package/dist/extract/jobs/python-jobs.js.map +1 -0
  203. package/dist/extract/jobs/python-queue-jobs.d.ts +15 -0
  204. package/dist/extract/jobs/python-queue-jobs.d.ts.map +1 -0
  205. package/dist/extract/jobs/python-queue-jobs.js +251 -0
  206. package/dist/extract/jobs/python-queue-jobs.js.map +1 -0
  207. package/dist/extract/jobs/rails-jobs.d.ts +36 -0
  208. package/dist/extract/jobs/rails-jobs.d.ts.map +1 -0
  209. package/dist/extract/jobs/rails-jobs.js +309 -0
  210. package/dist/extract/jobs/rails-jobs.js.map +1 -0
  211. package/dist/extract/jobs/spring-jobs.d.ts +23 -0
  212. package/dist/extract/jobs/spring-jobs.d.ts.map +1 -0
  213. package/dist/extract/jobs/spring-jobs.js +302 -0
  214. package/dist/extract/jobs/spring-jobs.js.map +1 -0
  215. package/dist/extract/php-source.d.ts +71 -0
  216. package/dist/extract/php-source.d.ts.map +1 -0
  217. package/dist/extract/php-source.js +297 -0
  218. package/dist/extract/php-source.js.map +1 -0
  219. package/dist/extract/ruby-source.d.ts +62 -0
  220. package/dist/extract/ruby-source.d.ts.map +1 -0
  221. package/dist/extract/ruby-source.js +353 -0
  222. package/dist/extract/ruby-source.js.map +1 -0
  223. package/dist/extract/schema/decorated-orm.d.ts.map +1 -1
  224. package/dist/extract/schema/decorated-orm.js +3 -1
  225. package/dist/extract/schema/decorated-orm.js.map +1 -1
  226. package/dist/extract/schema/drizzle-scan.d.ts +97 -0
  227. package/dist/extract/schema/drizzle-scan.d.ts.map +1 -0
  228. package/dist/extract/schema/drizzle-scan.js +567 -0
  229. package/dist/extract/schema/drizzle-scan.js.map +1 -0
  230. package/dist/extract/schema/drizzle.d.ts +27 -0
  231. package/dist/extract/schema/drizzle.d.ts.map +1 -0
  232. package/dist/extract/schema/drizzle.js +452 -0
  233. package/dist/extract/schema/drizzle.js.map +1 -0
  234. package/dist/extract/schema/efcore-fluent.d.ts +47 -0
  235. package/dist/extract/schema/efcore-fluent.d.ts.map +1 -0
  236. package/dist/extract/schema/efcore-fluent.js +118 -0
  237. package/dist/extract/schema/efcore-fluent.js.map +1 -0
  238. package/dist/extract/schema/efcore-scan.d.ts +60 -0
  239. package/dist/extract/schema/efcore-scan.d.ts.map +1 -0
  240. package/dist/extract/schema/efcore-scan.js +189 -0
  241. package/dist/extract/schema/efcore-scan.js.map +1 -0
  242. package/dist/extract/schema/efcore.d.ts +18 -0
  243. package/dist/extract/schema/efcore.d.ts.map +1 -0
  244. package/dist/extract/schema/efcore.js +628 -0
  245. package/dist/extract/schema/efcore.js.map +1 -0
  246. package/dist/extract/schema/gorm.d.ts +49 -0
  247. package/dist/extract/schema/gorm.d.ts.map +1 -0
  248. package/dist/extract/schema/gorm.js +475 -0
  249. package/dist/extract/schema/gorm.js.map +1 -0
  250. package/dist/extract/schema/index.d.ts.map +1 -1
  251. package/dist/extract/schema/index.js +30 -3
  252. package/dist/extract/schema/index.js.map +1 -1
  253. package/dist/extract/schema/jpa-scan.d.ts +60 -0
  254. package/dist/extract/schema/jpa-scan.d.ts.map +1 -0
  255. package/dist/extract/schema/jpa-scan.js +318 -0
  256. package/dist/extract/schema/jpa-scan.js.map +1 -0
  257. package/dist/extract/schema/jpa.d.ts +29 -0
  258. package/dist/extract/schema/jpa.d.ts.map +1 -0
  259. package/dist/extract/schema/jpa.js +288 -0
  260. package/dist/extract/schema/jpa.js.map +1 -0
  261. package/dist/extract/schema/js-schema-sources.d.ts +47 -0
  262. package/dist/extract/schema/js-schema-sources.d.ts.map +1 -0
  263. package/dist/extract/schema/js-schema-sources.js +111 -0
  264. package/dist/extract/schema/js-schema-sources.js.map +1 -0
  265. package/dist/extract/schema/knex-table.d.ts +52 -0
  266. package/dist/extract/schema/knex-table.d.ts.map +1 -0
  267. package/dist/extract/schema/knex-table.js +348 -0
  268. package/dist/extract/schema/knex-table.js.map +1 -0
  269. package/dist/extract/schema/knex.d.ts +43 -0
  270. package/dist/extract/schema/knex.d.ts.map +1 -0
  271. package/dist/extract/schema/knex.js +470 -0
  272. package/dist/extract/schema/knex.js.map +1 -0
  273. package/dist/extract/schema/laravel-blueprint.d.ts +22 -0
  274. package/dist/extract/schema/laravel-blueprint.d.ts.map +1 -0
  275. package/dist/extract/schema/laravel-blueprint.js +337 -0
  276. package/dist/extract/schema/laravel-blueprint.js.map +1 -0
  277. package/dist/extract/schema/laravel-migrations.d.ts +22 -0
  278. package/dist/extract/schema/laravel-migrations.d.ts.map +1 -0
  279. package/dist/extract/schema/laravel-migrations.js +241 -0
  280. package/dist/extract/schema/laravel-migrations.js.map +1 -0
  281. package/dist/extract/schema/mikro-orm.d.ts +53 -0
  282. package/dist/extract/schema/mikro-orm.d.ts.map +1 -0
  283. package/dist/extract/schema/mikro-orm.js +370 -0
  284. package/dist/extract/schema/mikro-orm.js.map +1 -0
  285. package/dist/extract/schema/mongoose.d.ts.map +1 -1
  286. package/dist/extract/schema/mongoose.js +3 -1
  287. package/dist/extract/schema/mongoose.js.map +1 -1
  288. package/dist/extract/schema/python-model-scan.d.ts +66 -0
  289. package/dist/extract/schema/python-model-scan.d.ts.map +1 -0
  290. package/dist/extract/schema/python-model-scan.js +392 -0
  291. package/dist/extract/schema/python-model-scan.js.map +1 -0
  292. package/dist/extract/schema/python-models.d.ts +15 -7
  293. package/dist/extract/schema/python-models.d.ts.map +1 -1
  294. package/dist/extract/schema/python-models.js +274 -213
  295. package/dist/extract/schema/python-models.js.map +1 -1
  296. package/dist/extract/schema/rails-schema.d.ts +22 -0
  297. package/dist/extract/schema/rails-schema.d.ts.map +1 -0
  298. package/dist/extract/schema/rails-schema.js +259 -0
  299. package/dist/extract/schema/rails-schema.js.map +1 -0
  300. package/dist/extract/schema/reconcile.d.ts +27 -0
  301. package/dist/extract/schema/reconcile.d.ts.map +1 -0
  302. package/dist/extract/schema/reconcile.js +69 -0
  303. package/dist/extract/schema/reconcile.js.map +1 -0
  304. package/dist/extract/schema/sql-ddl.d.ts +0 -9
  305. package/dist/extract/schema/sql-ddl.d.ts.map +1 -1
  306. package/dist/extract/schema/sql-ddl.js +83 -17
  307. package/dist/extract/schema/sql-ddl.js.map +1 -1
  308. package/dist/extract/test-sources.d.ts +11 -0
  309. package/dist/extract/test-sources.d.ts.map +1 -0
  310. package/dist/extract/test-sources.js +26 -0
  311. package/dist/extract/test-sources.js.map +1 -0
  312. package/dist/features/schema.d.ts +19 -75
  313. package/dist/features/schema.d.ts.map +1 -1
  314. package/dist/features/schema.js +1 -1
  315. package/dist/features/schema.js.map +1 -1
  316. package/dist/governance/schema.d.ts +16 -82
  317. package/dist/governance/schema.d.ts.map +1 -1
  318. package/dist/graph/store.d.ts +116 -185
  319. package/dist/graph/store.d.ts.map +1 -1
  320. package/dist/graph/store.js +2 -2
  321. package/dist/graph/store.js.map +1 -1
  322. package/dist/infer/cards.d.ts.map +1 -1
  323. package/dist/infer/cards.js +28 -1
  324. package/dist/infer/cards.js.map +1 -1
  325. package/dist/infer/context.d.ts.map +1 -1
  326. package/dist/infer/context.js +8 -25
  327. package/dist/infer/context.js.map +1 -1
  328. package/dist/infer/types.d.ts +15 -293
  329. package/dist/infer/types.d.ts.map +1 -1
  330. package/dist/legacy/plans.d.ts +20 -103
  331. package/dist/legacy/plans.d.ts.map +1 -1
  332. package/dist/legacy/schema.d.ts +244 -685
  333. package/dist/legacy/schema.d.ts.map +1 -1
  334. package/dist/migrations/schema.d.ts +17 -65
  335. package/dist/migrations/schema.d.ts.map +1 -1
  336. package/dist/narrate/audit-commands.d.ts +42 -0
  337. package/dist/narrate/audit-commands.d.ts.map +1 -0
  338. package/dist/narrate/audit-commands.js +248 -0
  339. package/dist/narrate/audit-commands.js.map +1 -0
  340. package/dist/narrate/audit-facts.d.ts +15 -0
  341. package/dist/narrate/audit-facts.d.ts.map +1 -0
  342. package/dist/narrate/audit-facts.js +118 -0
  343. package/dist/narrate/audit-facts.js.map +1 -0
  344. package/dist/narrate/audit-mechanical.d.ts +102 -0
  345. package/dist/narrate/audit-mechanical.d.ts.map +1 -0
  346. package/dist/narrate/audit-mechanical.js +533 -0
  347. package/dist/narrate/audit-mechanical.js.map +1 -0
  348. package/dist/narrate/audit-render.d.ts +35 -0
  349. package/dist/narrate/audit-render.d.ts.map +1 -0
  350. package/dist/narrate/audit-render.js +154 -0
  351. package/dist/narrate/audit-render.js.map +1 -0
  352. package/dist/narrate/audit-types.d.ts +86 -0
  353. package/dist/narrate/audit-types.d.ts.map +1 -0
  354. package/dist/narrate/audit-types.js +12 -0
  355. package/dist/narrate/audit-types.js.map +1 -0
  356. package/dist/narrate/audit.d.ts +136 -0
  357. package/dist/narrate/audit.d.ts.map +1 -0
  358. package/dist/narrate/audit.js +693 -0
  359. package/dist/narrate/audit.js.map +1 -0
  360. package/dist/narrate/engine.d.ts +124 -0
  361. package/dist/narrate/engine.d.ts.map +1 -0
  362. package/dist/narrate/engine.js +707 -0
  363. package/dist/narrate/engine.js.map +1 -0
  364. package/dist/narrate/evidence.d.ts +36 -0
  365. package/dist/narrate/evidence.d.ts.map +1 -0
  366. package/dist/narrate/evidence.js +138 -0
  367. package/dist/narrate/evidence.js.map +1 -0
  368. package/dist/narrate/factcheck.d.ts +30 -0
  369. package/dist/narrate/factcheck.d.ts.map +1 -0
  370. package/dist/narrate/factcheck.js +338 -0
  371. package/dist/narrate/factcheck.js.map +1 -0
  372. package/dist/narrate/plan.d.ts +20 -0
  373. package/dist/narrate/plan.d.ts.map +1 -0
  374. package/dist/narrate/plan.js +79 -0
  375. package/dist/narrate/plan.js.map +1 -0
  376. package/dist/narrate/planners/items-data.d.ts +14 -0
  377. package/dist/narrate/planners/items-data.d.ts.map +1 -0
  378. package/dist/narrate/planners/items-data.js +269 -0
  379. package/dist/narrate/planners/items-data.js.map +1 -0
  380. package/dist/narrate/planners/items-evidence.d.ts +37 -0
  381. package/dist/narrate/planners/items-evidence.d.ts.map +1 -0
  382. package/dist/narrate/planners/items-evidence.js +137 -0
  383. package/dist/narrate/planners/items-evidence.js.map +1 -0
  384. package/dist/narrate/planners/items.d.ts +3 -0
  385. package/dist/narrate/planners/items.d.ts.map +1 -0
  386. package/dist/narrate/planners/items.js +130 -0
  387. package/dist/narrate/planners/items.js.map +1 -0
  388. package/dist/narrate/planners/shared.d.ts +45 -0
  389. package/dist/narrate/planners/shared.d.ts.map +1 -0
  390. package/dist/narrate/planners/shared.js +139 -0
  391. package/dist/narrate/planners/shared.js.map +1 -0
  392. package/dist/narrate/planners/synthesis-flows.d.ts +3 -0
  393. package/dist/narrate/planners/synthesis-flows.d.ts.map +1 -0
  394. package/dist/narrate/planners/synthesis-flows.js +94 -0
  395. package/dist/narrate/planners/synthesis-flows.js.map +1 -0
  396. package/dist/narrate/planners/synthesis-security.d.ts +3 -0
  397. package/dist/narrate/planners/synthesis-security.d.ts.map +1 -0
  398. package/dist/narrate/planners/synthesis-security.js +180 -0
  399. package/dist/narrate/planners/synthesis-security.js.map +1 -0
  400. package/dist/narrate/planners/synthesis-shared.d.ts +31 -0
  401. package/dist/narrate/planners/synthesis-shared.d.ts.map +1 -0
  402. package/dist/narrate/planners/synthesis-shared.js +137 -0
  403. package/dist/narrate/planners/synthesis-shared.js.map +1 -0
  404. package/dist/narrate/planners/synthesis.d.ts +11 -0
  405. package/dist/narrate/planners/synthesis.d.ts.map +1 -0
  406. package/dist/narrate/planners/synthesis.js +367 -0
  407. package/dist/narrate/planners/synthesis.js.map +1 -0
  408. package/dist/narrate/questions.d.ts +14 -0
  409. package/dist/narrate/questions.d.ts.map +1 -0
  410. package/dist/narrate/questions.js +42 -0
  411. package/dist/narrate/questions.js.map +1 -0
  412. package/dist/narrate/render.d.ts +36 -0
  413. package/dist/narrate/render.d.ts.map +1 -0
  414. package/dist/narrate/render.js +233 -0
  415. package/dist/narrate/render.js.map +1 -0
  416. package/dist/narrate/sanitize.d.ts +28 -0
  417. package/dist/narrate/sanitize.d.ts.map +1 -0
  418. package/dist/narrate/sanitize.js +190 -0
  419. package/dist/narrate/sanitize.js.map +1 -0
  420. package/dist/narrate/store.d.ts +16 -0
  421. package/dist/narrate/store.d.ts.map +1 -0
  422. package/dist/narrate/store.js +206 -0
  423. package/dist/narrate/store.js.map +1 -0
  424. package/dist/narrate/types.d.ts +161 -0
  425. package/dist/narrate/types.d.ts.map +1 -0
  426. package/dist/narrate/types.js +74 -0
  427. package/dist/narrate/types.js.map +1 -0
  428. package/dist/pilot/schema.d.ts +17 -105
  429. package/dist/pilot/schema.d.ts.map +1 -1
  430. package/dist/pipeline.d.ts +6 -0
  431. package/dist/pipeline.d.ts.map +1 -1
  432. package/dist/pipeline.js +8 -0
  433. package/dist/pipeline.js.map +1 -1
  434. package/dist/plans/schema.d.ts +43 -137
  435. package/dist/plans/schema.d.ts.map +1 -1
  436. package/dist/privacy/benign.d.ts +2 -0
  437. package/dist/privacy/benign.d.ts.map +1 -0
  438. package/dist/privacy/benign.js +59 -0
  439. package/dist/privacy/benign.js.map +1 -0
  440. package/dist/privacy/redact-code.d.ts +25 -0
  441. package/dist/privacy/redact-code.d.ts.map +1 -0
  442. package/dist/privacy/redact-code.js +251 -0
  443. package/dist/privacy/redact-code.js.map +1 -0
  444. package/dist/privacy/redact-config.d.ts +46 -0
  445. package/dist/privacy/redact-config.d.ts.map +1 -0
  446. package/dist/privacy/redact-config.js +471 -0
  447. package/dist/privacy/redact-config.js.map +1 -0
  448. package/dist/privacy/redact-files.d.ts +29 -0
  449. package/dist/privacy/redact-files.d.ts.map +1 -0
  450. package/dist/privacy/redact-files.js +163 -0
  451. package/dist/privacy/redact-files.js.map +1 -0
  452. package/dist/privacy/redact-keyless.d.ts +20 -0
  453. package/dist/privacy/redact-keyless.d.ts.map +1 -0
  454. package/dist/privacy/redact-keyless.js +291 -0
  455. package/dist/privacy/redact-keyless.js.map +1 -0
  456. package/dist/privacy/redact-keys.d.ts +32 -0
  457. package/dist/privacy/redact-keys.d.ts.map +1 -0
  458. package/dist/privacy/redact-keys.js +160 -0
  459. package/dist/privacy/redact-keys.js.map +1 -0
  460. package/dist/privacy/redact-shape.d.ts +42 -0
  461. package/dist/privacy/redact-shape.d.ts.map +1 -0
  462. package/dist/privacy/redact-shape.js +313 -0
  463. package/dist/privacy/redact-shape.js.map +1 -0
  464. package/dist/privacy/redact.d.ts +34 -5
  465. package/dist/privacy/redact.d.ts.map +1 -1
  466. package/dist/privacy/redact.js +171 -46
  467. package/dist/privacy/redact.js.map +1 -1
  468. package/dist/questions/store.d.ts +1 -0
  469. package/dist/questions/store.d.ts.map +1 -1
  470. package/dist/questions/store.js +31 -30
  471. package/dist/questions/store.js.map +1 -1
  472. package/dist/render/index.d.ts.map +1 -1
  473. package/dist/render/index.js +7 -0
  474. package/dist/render/index.js.map +1 -1
  475. package/dist/render/pages/config.d.ts.map +1 -1
  476. package/dist/render/pages/config.js +2 -3
  477. package/dist/render/pages/config.js.map +1 -1
  478. package/dist/render/pages/readme.d.ts.map +1 -1
  479. package/dist/render/pages/readme.js +4 -0
  480. package/dist/render/pages/readme.js.map +1 -1
  481. package/dist/render/pages/tech-stack.d.ts +16 -0
  482. package/dist/render/pages/tech-stack.d.ts.map +1 -0
  483. package/dist/render/pages/tech-stack.js +147 -0
  484. package/dist/render/pages/tech-stack.js.map +1 -0
  485. package/dist/requirements/ids.d.ts +13 -0
  486. package/dist/requirements/ids.d.ts.map +1 -0
  487. package/dist/requirements/ids.js +90 -0
  488. package/dist/requirements/ids.js.map +1 -0
  489. package/dist/requirements/store.d.ts +2 -2
  490. package/dist/requirements/store.d.ts.map +1 -1
  491. package/dist/requirements/store.js +55 -57
  492. package/dist/requirements/store.js.map +1 -1
  493. package/dist/util/boundaries.d.ts.map +1 -1
  494. package/dist/util/boundaries.js +32 -19
  495. package/dist/util/boundaries.js.map +1 -1
  496. package/dist/util/generated.js +1 -1
  497. package/dist/util/generated.js.map +1 -1
  498. package/dist/util/human-records.d.ts +7 -0
  499. package/dist/util/human-records.d.ts.map +1 -0
  500. package/dist/util/human-records.js +23 -0
  501. package/dist/util/human-records.js.map +1 -0
  502. package/dist/verify/expected.d.ts.map +1 -1
  503. package/dist/verify/expected.js +50 -0
  504. package/dist/verify/expected.js.map +1 -1
  505. package/dist/walkthrough/capture.d.ts +14 -184
  506. package/dist/walkthrough/capture.d.ts.map +1 -1
  507. package/dist/walkthrough/schema.d.ts +32 -218
  508. package/dist/walkthrough/schema.d.ts.map +1 -1
  509. package/package.json +3 -3
  510. package/prompts/doc-audit.v1.md +83 -0
  511. package/prompts/doc-unit.v1.md +97 -0
  512. package/prompts/doc-unit.v2.md +116 -0
  513. package/prompts/doc-verify.v1.md +43 -0
  514. package/prompts/doc-verify.v2.md +67 -0
  515. package/prompts/feature-card.v2.md +4 -1
@@ -0,0 +1,707 @@
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import fs from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { extractJsonObject } from '../infer/cards.js';
6
+ import { redactSecrets } from '../privacy/redact.js';
7
+ import { renderAnswersForPrompt } from '../questions/store.js';
8
+ import { toPosix } from '../util/paths.js';
9
+ import { compareStrings } from '../util/sort.js';
10
+ import { buildEvidence } from './evidence.js';
11
+ import { factCheckClaims } from './factcheck.js';
12
+ import { inlineText, safeId } from './sanitize.js';
13
+ import { UNIT_LIMITS, unitBodySchema } from './types.js';
14
+ /** Bumped whenever a prompt changes, so stored units are regenerated. */
15
+ export const UNIT_PROMPT_VERSION = 'doc-unit.v2';
16
+ export const VERIFY_PROMPT_VERSION = 'doc-verify.v2';
17
+ /** After this many backend failures in a row, the rest of the run is not attempted. */
18
+ export const MAX_CONSECUTIVE_BACKEND_FAILURES = 3;
19
+ /**
20
+ * What a stored unit depends on beyond its prompt.
21
+ *
22
+ * A guard removed in a file the unit was never shown changes what the fact
23
+ * check would have let through, and a different model writes different prose.
24
+ * Neither appears in the prompt, so both are folded into the cache key.
25
+ */
26
+ export function cacheSalt(endpoints, model) {
27
+ const facts = endpoints
28
+ .map((endpoint) => `${endpoint.method} ${endpoint.path} ${[...endpoint.middleware].sort(compareStrings).join(',')}`)
29
+ .sort(compareStrings)
30
+ .join('\n');
31
+ return createHash('sha256').update(`${model ?? ''}\u0000${facts}`).digest('hex').slice(0, 16);
32
+ }
33
+ /**
34
+ * Build the exact prompt for a unit without calling anything.
35
+ *
36
+ * Separate from generation so a dry run can report what would be sent, and
37
+ * what it would cost, from the same code that sends it.
38
+ */
39
+ export async function prepareUnit(args) {
40
+ const template = await loadPrompt(UNIT_PROMPT_VERSION);
41
+ const evidence = await buildEvidence({
42
+ root: args.root,
43
+ requests: args.spec.evidence,
44
+ limits: args.limits,
45
+ redact: args.redactSecrets,
46
+ });
47
+ const recorded = args.answers.get(args.spec.id)?.answers ?? [];
48
+ // Redaction is applied to each piece of repository text, not to the finished
49
+ // prompt. The template and its block markers are ours; a redactor that took a
50
+ // marker for a token would cut away the prompt's own structure.
51
+ let promptRedactions = 0;
52
+ const clean = (text) => {
53
+ if (!args.redactSecrets)
54
+ return text;
55
+ const result = redactSecrets(text);
56
+ promptRedactions += result.count;
57
+ return result.text;
58
+ };
59
+ const raw = fill(template, {
60
+ TASK: clean(args.spec.task),
61
+ SECTIONS: args.spec.sections
62
+ .map((section) => `- \`${section.id}\` — ${clean(section.heading)}: ${section.about}`)
63
+ .join('\n'),
64
+ FACTS: asData(clean(args.spec.facts.trim() === '' ? '_None._' : args.spec.facts)),
65
+ ANSWERS: asData(clean(renderAnswersForPrompt(recorded))),
66
+ // Already redacted, file by file, when the excerpts were built.
67
+ EVIDENCE: asData(evidence.text),
68
+ // Marks where repository text begins and ends. Derived from that text, so
69
+ // the prompt stays reproducible and the cache key with it, while nothing
70
+ // written in the repository beforehand can know it.
71
+ DELIM: createHash('sha256').update(`${args.spec.id} ${args.spec.facts} ${evidence.text}`).digest('hex').slice(0, 16),
72
+ });
73
+ const redacted = { text: raw, count: promptRedactions };
74
+ const inputHash = createHash('sha256')
75
+ .update([
76
+ UNIT_PROMPT_VERSION,
77
+ args.verify ? VERIFY_PROMPT_VERSION : 'unverified',
78
+ // Things that change the result without changing the prompt: the facts
79
+ // the fact check compares against, and which model is asked.
80
+ args.salt ?? '',
81
+ redacted.text,
82
+ ].join('\u0000'))
83
+ .digest('hex')
84
+ .slice(0, 32);
85
+ return {
86
+ spec: args.spec,
87
+ evidence,
88
+ prompt: redacted.text,
89
+ inputHash,
90
+ redactions: evidence.redactions + redacted.count,
91
+ };
92
+ }
93
+ /**
94
+ * Generate every unit, one at a time.
95
+ *
96
+ * Each unit passes through four gates, in order of how cheaply they can say no:
97
+ * the response must parse; every claim must cite lines it was shown; claims
98
+ * must not disagree with extracted facts; and a second model pass must judge
99
+ * each survivor supported by its cited lines. A claim that fails any gate is
100
+ * removed and recorded, never repaired.
101
+ */
102
+ export async function generateUnits(options) {
103
+ const units = [];
104
+ const failures = [];
105
+ const reused = [];
106
+ let calls = 0;
107
+ // A backend that fails repeatedly is down, out of quota, or misconfigured.
108
+ // Asking it another fifty times helps nobody and, on a metered backend that
109
+ // bills failed requests, costs money.
110
+ let backendFailures = 0;
111
+ let lastBackendFailure = '';
112
+ for (const [index, spec] of options.specs.entries()) {
113
+ if (backendFailures >= MAX_CONSECUTIVE_BACKEND_FAILURES) {
114
+ failures.push({
115
+ id: spec.id,
116
+ title: spec.title,
117
+ kind: 'backend',
118
+ reason: `Not attempted: the backend failed ${backendFailures} times in a row. Last failure: ${lastBackendFailure}`,
119
+ });
120
+ continue;
121
+ }
122
+ const prepared = await prepareUnit({
123
+ root: options.root,
124
+ spec,
125
+ answers: options.answers,
126
+ limits: options.limits,
127
+ redactSecrets: options.redactSecrets,
128
+ verify: options.verify,
129
+ salt: cacheSalt(options.endpoints, options.model),
130
+ });
131
+ const previous = options.previous?.get(spec.id);
132
+ if (options.force !== true &&
133
+ previous !== undefined &&
134
+ previous.inputHash === prepared.inputHash &&
135
+ previous.promptVersion === UNIT_PROMPT_VERSION) {
136
+ // Headings, facts and order come from the plan, so a reused unit still
137
+ // reflects a retitled section without paying for the prose again.
138
+ units.push(reframe(previous, spec));
139
+ reused.push(spec.id);
140
+ continue;
141
+ }
142
+ options.logger.info(` [${index + 1}/${options.specs.length}] ${spec.title}`);
143
+ options.logger.info(` disclosure: ${prepared.evidence.includedFiles.length} file(s), ${Buffer.byteLength(prepared.prompt)} bytes, ` +
144
+ `provider=${options.backend.id}, model=${options.model ?? 'backend-default'}, redactions=${prepared.redactions}`);
145
+ options.logger.info(` files: ${prepared.evidence.includedFiles.join(', ') || '(none)'}`);
146
+ if (prepared.evidence.includedFiles.length === 0) {
147
+ failures.push({ id: spec.id, title: spec.title, reason: 'No source could be read for this unit.', kind: 'content' });
148
+ continue;
149
+ }
150
+ calls += 1;
151
+ const outcome = await options.backend.run({
152
+ prompt: prepared.prompt,
153
+ cwd: options.root,
154
+ timeoutMs: options.timeoutMs,
155
+ ...(options.model === undefined ? {} : { model: options.model }),
156
+ });
157
+ if (!outcome.ok) {
158
+ failures.push({ id: spec.id, title: spec.title, reason: outcome.reason, kind: 'backend' });
159
+ backendFailures += 1;
160
+ lastBackendFailure = outcome.reason;
161
+ continue;
162
+ }
163
+ backendFailures = 0;
164
+ const parsed = parseUnitBody(outcome.text);
165
+ if (!parsed.ok) {
166
+ failures.push({ id: spec.id, title: spec.title, reason: parsed.reason, kind: 'content' });
167
+ continue;
168
+ }
169
+ const removed = [];
170
+ const questions = [...parsed.body.unknowns];
171
+ const bySection = new Map();
172
+ const known = new Set(spec.sections.map((section) => section.id));
173
+ for (const section of parsed.body.sections) {
174
+ if (!known.has(section.id)) {
175
+ for (const claim of section.claims) {
176
+ removed.push({
177
+ sectionId: section.id,
178
+ text: claim.text,
179
+ stage: 'citation',
180
+ reason: `It was filed under '${section.id}', which is not a section of this unit.`,
181
+ });
182
+ }
183
+ continue;
184
+ }
185
+ const cited = [];
186
+ for (const claim of section.claims) {
187
+ const issue = citationIssue(claim, prepared.evidence.ranges);
188
+ if (issue === undefined)
189
+ cited.push(normaliseClaim(claim));
190
+ else
191
+ removed.push({ sectionId: section.id, text: claim.text, stage: 'citation', reason: issue });
192
+ }
193
+ const checked = factCheckClaims(cited, options.endpoints, subjectOf(spec, section.id));
194
+ removed.push(...checked.removed.map((item) => ({ sectionId: section.id, ...item })));
195
+ questions.push(...checked.questions);
196
+ if (checked.kept.length > 0) {
197
+ bySection.set(section.id, [...(bySection.get(section.id) ?? []), ...checked.kept]);
198
+ }
199
+ }
200
+ let status = 'skipped';
201
+ if (options.verify && bySection.size > 0) {
202
+ calls += 1;
203
+ const verdict = await verifyClaims({
204
+ spec,
205
+ bySection,
206
+ evidenceText: prepared.evidence.text,
207
+ backend: options.backend,
208
+ root: options.root,
209
+ timeoutMs: options.timeoutMs,
210
+ redactSecrets: options.redactSecrets,
211
+ ...(options.model === undefined ? {} : { model: options.model }),
212
+ });
213
+ if (verdict.ok) {
214
+ status = 'checked';
215
+ removed.push(...verdict.removed);
216
+ for (const [sectionId, kept] of verdict.kept) {
217
+ if (kept.length === 0)
218
+ bySection.delete(sectionId);
219
+ else
220
+ bySection.set(sectionId, [...kept]);
221
+ }
222
+ }
223
+ else {
224
+ // Fail closed. Verification was asked for and did not happen, so these
225
+ // statements have not passed the check the page would say they passed.
226
+ // Publishing them anyway is how a rejected statement reached a page.
227
+ failures.push({
228
+ id: spec.id,
229
+ title: spec.title,
230
+ kind: 'backend',
231
+ reason: `The statements were written but could not be verified, so none were published: ${verdict.reason}`,
232
+ });
233
+ backendFailures += 1;
234
+ lastBackendFailure = verdict.reason;
235
+ continue;
236
+ }
237
+ }
238
+ else if (options.verify) {
239
+ status = 'checked';
240
+ }
241
+ const unknowns = dedupeUnknowns(questions).slice(0, UNIT_LIMITS.unknowns);
242
+ if (bySection.size === 0 && unknowns.length === 0) {
243
+ failures.push({
244
+ id: spec.id,
245
+ title: spec.title,
246
+ kind: 'content',
247
+ reason: removed.length === 0
248
+ ? 'The model established nothing for this unit from the supplied source.'
249
+ : `All ${removed.length} statement(s) were removed by the citation, fact and verification checks.`,
250
+ });
251
+ continue;
252
+ }
253
+ units.push({
254
+ id: spec.id,
255
+ slug: spec.slug,
256
+ page: spec.page,
257
+ title: spec.title,
258
+ order: spec.order,
259
+ sections: spec.sections
260
+ .filter((section) => bySection.has(section.id))
261
+ .map((section) => ({ ...section, claims: bySection.get(section.id) ?? [] })),
262
+ unknowns,
263
+ producedBy: options.backend.id,
264
+ promptVersion: UNIT_PROMPT_VERSION,
265
+ inputHash: prepared.inputHash,
266
+ verification: { status, removed },
267
+ sources: await hashSources(options.root, prepared.evidence.includedFiles),
268
+ });
269
+ }
270
+ return {
271
+ units: units.sort(compareUnits),
272
+ failures: failures.sort((a, b) => compareStrings(a.id, b.id)),
273
+ reused,
274
+ calls,
275
+ };
276
+ }
277
+ export function compareUnits(a, b) {
278
+ return compareStrings(a.page, b.page) || a.order - b.order || compareStrings(a.id, b.id);
279
+ }
280
+ /** Content hash of a source file, with line endings normalised so a checkout setting cannot change it. */
281
+ export async function hashSource(root, file) {
282
+ try {
283
+ const contents = await fs.readFile(path.join(root, file), 'utf8');
284
+ // A byte-order mark is an editor setting too, not a change to the code.
285
+ const normalised = (contents.charCodeAt(0) === 0xfeff ? contents.slice(1) : contents).replace(/\r\n/g, '\n');
286
+ return createHash('sha256').update(normalised).digest('hex').slice(0, 16);
287
+ }
288
+ catch {
289
+ return undefined;
290
+ }
291
+ }
292
+ async function hashSources(root, files) {
293
+ const sources = [];
294
+ for (const file of [...files].sort(compareStrings)) {
295
+ const hash = await hashSource(root, file);
296
+ if (hash !== undefined)
297
+ sources.push({ file, hash });
298
+ }
299
+ return sources;
300
+ }
301
+ /** The files a unit was written from that have since changed or gone. */
302
+ export async function changedSources(root, unit) {
303
+ const changed = [];
304
+ for (const source of unit.sources) {
305
+ if ((await hashSource(root, source.file)) !== source.hash)
306
+ changed.push(source.file);
307
+ }
308
+ return changed;
309
+ }
310
+ /**
311
+ * The endpoint a section is about, read from its planner-written heading.
312
+ *
313
+ * Inside the section for `DELETE /users/:id`, "this endpoint requires
314
+ * authentication" names no endpoint, so the fact check needs to be told which
315
+ * one is meant. Headings are fixed by the plan, never by the model.
316
+ */
317
+ function subjectOf(spec, sectionId) {
318
+ const heading = spec.sections.find((section) => section.id === sectionId)?.heading ?? '';
319
+ // The heading is a code span whose fence may be longer than one backtick,
320
+ // padded with a space, when the path itself contains a backtick.
321
+ const match = /^(`+) ?(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|ALL) (\/\S*?) ?\1(?!`)/.exec(heading);
322
+ return match === null ? undefined : { method: match[2], path: match[3] };
323
+ }
324
+ /**
325
+ * Remove statements whose citations no longer point at anything.
326
+ *
327
+ * A link to a deleted file, or to a line past the end of one, cannot be
328
+ * followed, and a statement a reader cannot check is the thing this lane does
329
+ * not publish. Run when the guide is rendered, with no model.
330
+ */
331
+ export async function withLiveCitations(root, unit) {
332
+ const lineCounts = new Map();
333
+ const lineCount = async (file) => {
334
+ if (lineCounts.has(file))
335
+ return lineCounts.get(file);
336
+ let count;
337
+ try {
338
+ const target = path.resolve(root, file);
339
+ const relation = path.relative(path.resolve(root), target);
340
+ if (!relation.startsWith('..') && !path.isAbsolute(relation)) {
341
+ count = countLines(await fs.readFile(target, 'utf8'));
342
+ }
343
+ }
344
+ catch {
345
+ count = undefined;
346
+ }
347
+ lineCounts.set(file, count);
348
+ return count;
349
+ };
350
+ const sections = [];
351
+ for (const section of unit.sections) {
352
+ const claims = [];
353
+ for (const claim of section.claims) {
354
+ let live = claim.evidence.length > 0;
355
+ for (const evidence of claim.evidence) {
356
+ const count = await lineCount(evidence.file);
357
+ if (count === undefined || evidence.line === undefined || evidence.line > count)
358
+ live = false;
359
+ }
360
+ if (live)
361
+ claims.push(claim);
362
+ }
363
+ if (claims.length > 0)
364
+ sections.push({ ...section, claims });
365
+ }
366
+ return { ...unit, sections };
367
+ }
368
+ /** Apply the current plan's headings, facts and order to a stored unit. */
369
+ export function reframe(unit, spec) {
370
+ const specs = new Map(spec.sections.map((section) => [section.id, section]));
371
+ return {
372
+ ...unit,
373
+ slug: spec.slug,
374
+ page: spec.page,
375
+ title: spec.title,
376
+ order: spec.order,
377
+ sections: unit.sections
378
+ // Same id is not enough: the statements were written for a particular
379
+ // subject, named by the heading. If the plan now gives that id to a
380
+ // different heading, they describe something else and are dropped
381
+ // rather than printed under the new subject's verified fact line.
382
+ .filter((section) => specs.get(section.id)?.heading === section.heading)
383
+ .map((section) => ({ ...(specs.get(section.id) ?? section), claims: section.claims })),
384
+ };
385
+ }
386
+ /**
387
+ * The JSON object in a reply that has the given key.
388
+ *
389
+ * A reply may open with prose, and prose may contain braces: "I checked
390
+ * DELETE /users/{id}." Taking the first brace would parse `{id}`, fail, and
391
+ * discard a perfectly good answer after it.
392
+ */
393
+ export function extractJsonWithKey(text, key) {
394
+ for (let start = text.indexOf('{'); start !== -1; start = text.indexOf('{', start + 1)) {
395
+ const candidate = extractJsonObject(text.slice(start));
396
+ if (candidate === undefined)
397
+ continue;
398
+ try {
399
+ const parsed = JSON.parse(candidate);
400
+ if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed) && key in parsed)
401
+ return parsed;
402
+ }
403
+ catch {
404
+ // Not JSON from this brace; try the next one.
405
+ }
406
+ }
407
+ return undefined;
408
+ }
409
+ /** Locate, trim and validate the JSON object in a model response. */
410
+ export function parseUnitBody(text) {
411
+ const raw = extractJsonWithKey(text, 'sections') ?? extractJsonWithKey(text, 'unknowns');
412
+ if (raw === undefined)
413
+ return { ok: false, reason: 'The model returned no JSON object with the expected fields.' };
414
+ const result = unitBodySchema.safeParse(trimOverlong(raw));
415
+ if (!result.success) {
416
+ return {
417
+ ok: false,
418
+ reason: `The model's JSON did not match the required shape: ${result.error.issues
419
+ .slice(0, 5)
420
+ .map((issue) => `${issue.path.join('.') || '(root)'} — ${issue.message}`)
421
+ .join('; ')}`,
422
+ };
423
+ }
424
+ return { ok: true, body: sanitiseBody(result.data) };
425
+ }
426
+ /**
427
+ * Reduce everything the model wrote to single lines of plain prose.
428
+ *
429
+ * Done once here, before anything is checked or stored, so the checks and the
430
+ * page see the same text. See sanitize.ts for why a line break is dangerous.
431
+ */
432
+ function sanitiseBody(body) {
433
+ const seen = new Set();
434
+ return {
435
+ sections: body.sections.map((section) => ({
436
+ id: section.id,
437
+ claims: section.claims
438
+ .map((claim) => ({ text: inlineText(withoutVerdictShape(claim.text)), evidence: claim.evidence }))
439
+ .filter((claim) => claim.text.length > 0),
440
+ })),
441
+ unknowns: body.unknowns
442
+ .map((unknown) => ({
443
+ id: safeId(unknown.id),
444
+ question: inlineText(unknown.question, 500),
445
+ why: inlineText(unknown.why, 500),
446
+ options: unknown.options.map((option) => inlineText(option, 200)).filter((option) => option.length > 0),
447
+ }))
448
+ .filter((unknown) => {
449
+ if (unknown.question.length === 0 || seen.has(unknown.id))
450
+ return false;
451
+ seen.add(unknown.id);
452
+ return true;
453
+ }),
454
+ };
455
+ }
456
+ /**
457
+ * Keep the first N entries of a list the model over-filled.
458
+ *
459
+ * Every kept entry is still validated in full, so this admits nothing the
460
+ * schema would refuse; it only stops one long list discarding a whole unit.
461
+ */
462
+ function trimOverlong(raw) {
463
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
464
+ return raw;
465
+ const body = { ...raw };
466
+ if (Array.isArray(body['unknowns']))
467
+ body['unknowns'] = body['unknowns'].slice(0, UNIT_LIMITS.unknowns);
468
+ if (Array.isArray(body['sections'])) {
469
+ body['sections'] = body['sections'].slice(0, UNIT_LIMITS.sections).map((section) => {
470
+ if (section === null || typeof section !== 'object' || Array.isArray(section))
471
+ return section;
472
+ const copy = { ...section };
473
+ if (Array.isArray(copy['claims']))
474
+ copy['claims'] = copy['claims'].slice(0, UNIT_LIMITS.claimsPerSection);
475
+ return copy;
476
+ });
477
+ }
478
+ return body;
479
+ }
480
+ /** Why a claim's citations are unacceptable, or undefined when all are valid. */
481
+ export function citationIssue(claim, ranges) {
482
+ for (const evidence of claim.evidence) {
483
+ const file = normalisePath(evidence.file);
484
+ if (file === undefined)
485
+ return `It cites an invalid or non-relative path: '${evidence.file}'.`;
486
+ const fileRanges = ranges.filter((range) => range.file === file);
487
+ if (fileRanges.length === 0)
488
+ return `It cites '${evidence.file}', which was not in the supplied source.`;
489
+ if (evidence.line === undefined)
490
+ return `It cites '${evidence.file}' without a line number.`;
491
+ const line = evidence.line;
492
+ if (!fileRanges.some((range) => line >= range.startLine && line <= range.endLine)) {
493
+ return `It cites '${evidence.file}:${line}', a line that was not in the supplied source.`;
494
+ }
495
+ }
496
+ return undefined;
497
+ }
498
+ function normaliseClaim(claim) {
499
+ return {
500
+ text: claim.text.trim(),
501
+ evidence: claim.evidence.map((item) => ({
502
+ file: normalisePath(item.file) ?? item.file,
503
+ ...(item.line === undefined ? {} : { line: item.line }),
504
+ })),
505
+ };
506
+ }
507
+ function normalisePath(value) {
508
+ const normalised = path.posix.normalize(toPosix(value).replace(/^\.\//, ''));
509
+ if (path.posix.isAbsolute(normalised) || normalised === '..' || normalised.startsWith('../'))
510
+ return undefined;
511
+ return normalised;
512
+ }
513
+ function dedupeUnknowns(unknowns) {
514
+ const seen = new Set();
515
+ return unknowns.filter((unknown) => {
516
+ if (seen.has(unknown.id))
517
+ return false;
518
+ seen.add(unknown.id);
519
+ return true;
520
+ });
521
+ }
522
+ /**
523
+ * The second pass: a fresh model call that only judges.
524
+ *
525
+ * It sees the claims and the same excerpts, and returns a verdict per claim.
526
+ * Anything not explicitly `supported` is removed — including a claim the
527
+ * checker simply forgot to rule on, because an unjudged claim has not passed.
528
+ */
529
+ async function verifyClaims(args) {
530
+ const numbered = [];
531
+ for (const [sectionId, claims] of args.bySection) {
532
+ for (const claim of claims)
533
+ numbered.push({ n: numbered.length + 1, sectionId, claim });
534
+ }
535
+ // Chosen now, so nothing written earlier can contain it: not the repository,
536
+ // not the statements. Only a reply carrying it is the checker's own answer.
537
+ const nonce = randomUUID();
538
+ // The pieces are redacted, never the assembled prompt: a redactor that took
539
+ // the run code for a token would leave the checker unable to return it.
540
+ const clean = (text) => (args.redactSecrets ? redactSecrets(text).text : text);
541
+ const template = await loadPrompt(VERIFY_PROMPT_VERSION);
542
+ const raw = fill(template, {
543
+ NONCE: nonce,
544
+ FACTS: asData(clean(args.spec.facts.trim() === '' ? '_None._' : args.spec.facts)),
545
+ CLAIMS: numbered
546
+ .map((item) => `${item.n}. ${asData(clean(item.claim.text))}\n cites: ${item.claim.evidence
547
+ .map((evidence) => `${evidence.file}:${evidence.line ?? '?'}`)
548
+ .join(', ')}`)
549
+ .join('\n'),
550
+ EVIDENCE: asData(args.evidenceText),
551
+ });
552
+ const prompt = raw;
553
+ const outcome = await args.backend.run({
554
+ prompt,
555
+ cwd: args.root,
556
+ timeoutMs: args.timeoutMs,
557
+ ...(args.model === undefined ? {} : { model: args.model }),
558
+ });
559
+ if (!outcome.ok)
560
+ return { ok: false, reason: outcome.reason };
561
+ const verdicts = parseVerdicts(outcome.text, nonce);
562
+ if (verdicts === undefined)
563
+ return { ok: false, reason: 'The checker returned no readable verdicts.' };
564
+ const kept = new Map();
565
+ const removed = [];
566
+ for (const sectionId of args.bySection.keys())
567
+ kept.set(sectionId, []);
568
+ for (const item of numbered) {
569
+ const verdict = verdicts.get(item.n);
570
+ if (verdict?.verdict === 'supported') {
571
+ kept.get(item.sectionId)?.push(item.claim);
572
+ continue;
573
+ }
574
+ removed.push({
575
+ sectionId: item.sectionId,
576
+ text: item.claim.text,
577
+ stage: 'verification',
578
+ reason: verdict === undefined
579
+ ? 'The checker gave no verdict for it, so it was not confirmed.'
580
+ : `Judged ${verdict.verdict}: ${verdict.reason}`,
581
+ });
582
+ }
583
+ return { ok: true, kept, removed };
584
+ }
585
+ /**
586
+ * The checker's verdicts, or undefined when the reply cannot be trusted.
587
+ *
588
+ * A reply is read only from JSON objects that carry this call's nonce. The
589
+ * statements being judged are quoted in the prompt and may be quoted back, and
590
+ * a statement can be written to look like a verdict object; without the nonce,
591
+ * "the first object with a `verdicts` key" could be one the writer supplied.
592
+ * If the reply holds more than one object with the nonce and they disagree on
593
+ * any statement, it is ambiguous, and an ambiguous reply is not a verdict.
594
+ */
595
+ export function parseVerdicts(text, nonce) {
596
+ const replies = topLevelJsonObjects(text).filter((candidate) => candidate['nonce'] === nonce && Array.isArray(candidate['verdicts']));
597
+ if (replies.length === 0)
598
+ return undefined;
599
+ const merged = new Map();
600
+ for (const reply of replies) {
601
+ const own = new Map();
602
+ for (const entry of reply['verdicts']) {
603
+ if (entry === null || typeof entry !== 'object')
604
+ continue;
605
+ const record = entry;
606
+ const n = record['n'];
607
+ const verdict = record['verdict'];
608
+ if (typeof n !== 'number' || !Number.isInteger(n) || typeof verdict !== 'string')
609
+ continue;
610
+ if (verdict !== 'supported' && verdict !== 'unsupported' && verdict !== 'contradicted')
611
+ continue;
612
+ // Two verdicts for one statement inside one reply: the stricter stands.
613
+ const previous = own.get(n);
614
+ if (previous === undefined || (previous.verdict === 'supported' && verdict !== 'supported')) {
615
+ own.set(n, { verdict, reason: typeof record['reason'] === 'string' ? inlineText(record['reason'], 400) : '' });
616
+ }
617
+ }
618
+ for (const [n, verdict] of own) {
619
+ const existing = merged.get(n);
620
+ if (existing !== undefined && existing.verdict !== verdict.verdict)
621
+ return undefined;
622
+ merged.set(n, verdict);
623
+ }
624
+ }
625
+ return merged;
626
+ }
627
+ /** Every JSON object that starts at the top level of a reply, in order. */
628
+ function topLevelJsonObjects(text) {
629
+ const found = [];
630
+ let from = 0;
631
+ for (;;) {
632
+ const start = text.indexOf('{', from);
633
+ if (start === -1)
634
+ break;
635
+ const candidate = extractJsonObject(text.slice(start));
636
+ let parsed;
637
+ if (candidate !== undefined) {
638
+ try {
639
+ parsed = JSON.parse(candidate);
640
+ }
641
+ catch {
642
+ parsed = undefined;
643
+ }
644
+ }
645
+ if (candidate !== undefined && parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
646
+ found.push(parsed);
647
+ // Skip past it: objects nested inside are not replies of their own.
648
+ from = start + candidate.length;
649
+ }
650
+ else {
651
+ from = start + 1;
652
+ }
653
+ }
654
+ return found;
655
+ }
656
+ /**
657
+ * Repository or model text, made unable to end the block it is quoted in.
658
+ *
659
+ * Prompts wrap untrusted material between `<<<BEGIN x>>>` and `<<<END x>>>`
660
+ * lines. Text containing such a line could close the block early and continue
661
+ * as if it were instructions, so the marker shape is broken wherever it occurs.
662
+ */
663
+ function asData(text) {
664
+ return text.replace(/<<<\s*(BEGIN|END)\b/gi, '<< <$1');
665
+ }
666
+ /**
667
+ * Remove what would make a statement look like a checker's reply.
668
+ *
669
+ * Statements are prose. One that carries `{"verdicts": [...]}` is either an
670
+ * accident or an attempt to answer the question it is about to be asked.
671
+ */
672
+ function withoutVerdictShape(text) {
673
+ return text.replace(/["'`]\s*(verdicts?|nonce)\s*["'`]\s*:/gi, '$1 -');
674
+ }
675
+ function countLines(contents) {
676
+ if (contents === '')
677
+ return 0;
678
+ const lines = contents.split('\n').length;
679
+ // A final newline ends the last line; it does not start another.
680
+ return contents.endsWith('\n') ? lines - 1 : lines;
681
+ }
682
+ function fill(template, values) {
683
+ // Function replacement: `$&` and friends in source code must stay literal.
684
+ return template.replace(/\{\{([A-Z]+)\}\}/g, (match, key) => values[key] ?? match);
685
+ }
686
+ const promptCache = new Map();
687
+ async function loadPrompt(version) {
688
+ const cached = promptCache.get(version);
689
+ if (cached !== undefined)
690
+ return cached;
691
+ const here = path.dirname(fileURLToPath(import.meta.url));
692
+ for (const candidate of [
693
+ path.resolve(here, '..', '..', 'prompts', `${version}.md`),
694
+ path.resolve(here, '..', '..', '..', 'prompts', `${version}.md`),
695
+ ]) {
696
+ try {
697
+ const contents = await fs.readFile(candidate, 'utf8');
698
+ promptCache.set(version, contents);
699
+ return contents;
700
+ }
701
+ catch {
702
+ // Try the next location.
703
+ }
704
+ }
705
+ throw new Error(`Could not locate prompt pack ${version}.md`);
706
+ }
707
+ //# sourceMappingURL=engine.js.map