@turri-dev/cli 0.4.3-next.aea3ca1 → 0.5.0

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 (481) hide show
  1. package/README.md +26 -3
  2. package/dist/banner.js +259 -0
  3. package/dist/capture-cli.js +59 -0
  4. package/dist/chat-commands.js +9 -63
  5. package/dist/chat-models.js +17 -15
  6. package/dist/chat-tab-header.js +90 -0
  7. package/dist/chat-tabs.js +100 -0
  8. package/dist/chat-terminal.js +162 -54
  9. package/dist/chat-waiting.js +0 -20
  10. package/dist/cli-options.js +11 -7
  11. package/dist/cli-root.js +141 -0
  12. package/dist/cli.js +40 -28
  13. package/dist/conform-cli.js +4 -6
  14. package/dist/cultivate-cli.js +65 -97
  15. package/dist/doctor-cli.js +99 -0
  16. package/dist/drift-cli.js +2 -7
  17. package/dist/entry-renderers.js +107 -0
  18. package/dist/extension.js +14 -3211
  19. package/dist/init-config-cli.js +218 -0
  20. package/dist/launch-cli.js +55 -91
  21. package/dist/lineage-cli.js +2 -4
  22. package/dist/loop-cli.js +118 -233
  23. package/dist/panel-view.js +409 -0
  24. package/dist/parse-cli.js +5 -2
  25. package/dist/pi-launch.js +39 -13
  26. package/dist/pi-themes.js +21 -0
  27. package/dist/plain-code-blocks.js +56 -0
  28. package/dist/pointer-hover.js +48 -0
  29. package/dist/print-mode.js +20 -0
  30. package/dist/question-dialog.js +26 -3
  31. package/dist/quiet.js +7 -106
  32. package/dist/regenerate/diff-view.js +6 -87
  33. package/dist/regenerate/jobs-tree.js +7 -18
  34. package/dist/regenerate/side-panel.js +158 -22
  35. package/dist/regenerate/spec-map-view.js +25 -70
  36. package/dist/regenerate-cli.js +7 -11
  37. package/dist/skill-progress.js +25 -0
  38. package/dist/skill-report.js +52 -0
  39. package/dist/terminal-marks.js +21 -0
  40. package/dist/terminal-notifications.js +219 -0
  41. package/dist/terminal-view.js +239 -0
  42. package/dist/turri-versions.js +64 -6
  43. package/docs/README.md +4 -2
  44. package/docs/capture.md +126 -0
  45. package/docs/chats.md +14 -10
  46. package/docs/claude-subscription.md +1 -1
  47. package/docs/config.md +20 -8
  48. package/docs/development.md +30 -61
  49. package/docs/headless.md +3 -1
  50. package/docs/hosting.md +3 -251
  51. package/docs/installation.md +5 -3
  52. package/docs/launch.md +3 -3
  53. package/docs/regenerating.md +1 -1
  54. package/docs/sandbox.md +4 -2
  55. package/docs/sentinel.md +13 -13
  56. package/docs/theming.md +3 -3
  57. package/docs/using.md +14 -6
  58. package/package.json +13 -31
  59. package/dist/ask.d.ts +0 -90
  60. package/dist/ask.js +0 -170
  61. package/dist/background-skills.d.ts +0 -53
  62. package/dist/background-skills.js +0 -121
  63. package/dist/bedrock-region.d.ts +0 -66
  64. package/dist/bedrock-region.js +0 -144
  65. package/dist/brand.d.ts +0 -13
  66. package/dist/btw.d.ts +0 -69
  67. package/dist/btw.js +0 -174
  68. package/dist/chat-commands.d.ts +0 -25
  69. package/dist/chat-idle.d.ts +0 -7
  70. package/dist/chat-idle.js +0 -20
  71. package/dist/chat-models.d.ts +0 -22
  72. package/dist/chat-records.d.ts +0 -50
  73. package/dist/chat-records.js +0 -107
  74. package/dist/chat-scope.d.ts +0 -14
  75. package/dist/chat-scope.js +0 -15
  76. package/dist/chat-skills.d.ts +0 -17
  77. package/dist/chat-skills.js +0 -18
  78. package/dist/chat-terminal.d.ts +0 -24
  79. package/dist/chat-ui.d.ts +0 -33
  80. package/dist/chat-waiting.d.ts +0 -67
  81. package/dist/chats.d.ts +0 -338
  82. package/dist/chats.js +0 -996
  83. package/dist/cli-options.d.ts +0 -24
  84. package/dist/cli.d.ts +0 -9
  85. package/dist/config-edit.d.ts +0 -83
  86. package/dist/config-edit.js +0 -390
  87. package/dist/config.d.ts +0 -415
  88. package/dist/config.js +0 -757
  89. package/dist/conform-cli.d.ts +0 -1
  90. package/dist/conformance-switch.d.ts +0 -25
  91. package/dist/conformance-switch.js +0 -86
  92. package/dist/cultivate-cli.d.ts +0 -1
  93. package/dist/doctor-tool.d.ts +0 -11
  94. package/dist/doctor-tool.js +0 -33
  95. package/dist/drift-cli.d.ts +0 -1
  96. package/dist/environment.d.ts +0 -37
  97. package/dist/environment.js +0 -109
  98. package/dist/extension.d.ts +0 -208
  99. package/dist/genome.d.ts +0 -77
  100. package/dist/genome.js +0 -288
  101. package/dist/graph.d.ts +0 -52
  102. package/dist/graph.js +0 -247
  103. package/dist/host-session.d.ts +0 -112
  104. package/dist/host-session.js +0 -103
  105. package/dist/host.d.ts +0 -40
  106. package/dist/host.js +0 -54
  107. package/dist/identity.d.ts +0 -7
  108. package/dist/identity.js +0 -74
  109. package/dist/init-config.d.ts +0 -169
  110. package/dist/init-config.js +0 -840
  111. package/dist/installed-providers.d.ts +0 -40
  112. package/dist/installed-providers.js +0 -98
  113. package/dist/jellyfish.d.ts +0 -40
  114. package/dist/judge.d.ts +0 -25
  115. package/dist/judge.js +0 -62
  116. package/dist/launch-agent.d.ts +0 -62
  117. package/dist/launch-agent.js +0 -339
  118. package/dist/launch-cli.d.ts +0 -1
  119. package/dist/launch-session.d.ts +0 -68
  120. package/dist/launch-session.js +0 -225
  121. package/dist/launch-tools.d.ts +0 -28
  122. package/dist/launch-tools.js +0 -72
  123. package/dist/launch-track.d.ts +0 -175
  124. package/dist/launch-track.js +0 -497
  125. package/dist/lineage-cli.d.ts +0 -1
  126. package/dist/loop-cli.d.ts +0 -35
  127. package/dist/loop-tools.d.ts +0 -103
  128. package/dist/loop-tools.js +0 -357
  129. package/dist/model-check.d.ts +0 -72
  130. package/dist/model-check.js +0 -162
  131. package/dist/module-report.d.ts +0 -9
  132. package/dist/new-project.d.ts +0 -5
  133. package/dist/new-project.js +0 -31
  134. package/dist/notice.d.ts +0 -115
  135. package/dist/notice.js +0 -61
  136. package/dist/parse-cli.d.ts +0 -1
  137. package/dist/parse-tool.d.ts +0 -9
  138. package/dist/parse-tool.js +0 -33
  139. package/dist/pi-launch.d.ts +0 -1
  140. package/dist/pi-settings.d.ts +0 -4
  141. package/dist/pi.d.ts +0 -248
  142. package/dist/pi.js +0 -889
  143. package/dist/picture-row.d.ts +0 -10
  144. package/dist/plain/check.d.ts +0 -63
  145. package/dist/plain/check.js +0 -236
  146. package/dist/plain/concepts.d.ts +0 -37
  147. package/dist/plain/concepts.js +0 -283
  148. package/dist/plain/cycles.d.ts +0 -21
  149. package/dist/plain/cycles.js +0 -190
  150. package/dist/plain/errors.d.ts +0 -26
  151. package/dist/plain/errors.js +0 -50
  152. package/dist/plain/files.d.ts +0 -47
  153. package/dist/plain/files.js +0 -161
  154. package/dist/plain/graph.d.ts +0 -107
  155. package/dist/plain/graph.js +0 -194
  156. package/dist/plain/highlight.d.ts +0 -43
  157. package/dist/plain/highlight.js +0 -196
  158. package/dist/plain/index.d.ts +0 -18
  159. package/dist/plain/index.js +0 -18
  160. package/dist/plain/liquid.d.ts +0 -22
  161. package/dist/plain/liquid.js +0 -124
  162. package/dist/plain/markdown.d.ts +0 -103
  163. package/dist/plain/markdown.js +0 -330
  164. package/dist/plain/module-concepts.d.ts +0 -32
  165. package/dist/plain/module-concepts.js +0 -80
  166. package/dist/plain/parser.d.ts +0 -163
  167. package/dist/plain/parser.js +0 -930
  168. package/dist/plain/plain.tmLanguage.json +0 -150
  169. package/dist/plain/project.d.ts +0 -48
  170. package/dist/plain/project.js +0 -155
  171. package/dist/plain/spec.d.ts +0 -152
  172. package/dist/plain/spec.js +0 -265
  173. package/dist/plain/stdlib.d.ts +0 -16
  174. package/dist/plain/stdlib.js +0 -48
  175. package/dist/plain/test-plain-file.d.ts +0 -59
  176. package/dist/plain/test-plain-file.js +0 -232
  177. package/dist/plain-files.d.ts +0 -21
  178. package/dist/plain-files.js +0 -156
  179. package/dist/question-dialog.d.ts +0 -55
  180. package/dist/questioning.d.ts +0 -55
  181. package/dist/questioning.js +0 -109
  182. package/dist/quiet.d.ts +0 -34
  183. package/dist/regenerate/activity.d.ts +0 -227
  184. package/dist/regenerate/activity.js +0 -250
  185. package/dist/regenerate/agent-env.d.ts +0 -51
  186. package/dist/regenerate/agent-env.js +0 -311
  187. package/dist/regenerate/agent-shell.d.ts +0 -54
  188. package/dist/regenerate/agent-shell.js +0 -121
  189. package/dist/regenerate/arbiter.d.ts +0 -68
  190. package/dist/regenerate/arbiter.js +0 -133
  191. package/dist/regenerate/audit.d.ts +0 -69
  192. package/dist/regenerate/audit.js +0 -212
  193. package/dist/regenerate/base-folder.d.ts +0 -70
  194. package/dist/regenerate/base-folder.js +0 -186
  195. package/dist/regenerate/cases.d.ts +0 -12
  196. package/dist/regenerate/cases.js +0 -149
  197. package/dist/regenerate/change-view.d.ts +0 -23
  198. package/dist/regenerate/change-view.js +0 -153
  199. package/dist/regenerate/chunk-plan.d.ts +0 -217
  200. package/dist/regenerate/chunk-plan.js +0 -937
  201. package/dist/regenerate/codebase.d.ts +0 -21
  202. package/dist/regenerate/codebase.js +0 -75
  203. package/dist/regenerate/command-check.d.ts +0 -66
  204. package/dist/regenerate/command-check.js +0 -508
  205. package/dist/regenerate/compaction.d.ts +0 -13
  206. package/dist/regenerate/compaction.js +0 -20
  207. package/dist/regenerate/confine.d.ts +0 -69
  208. package/dist/regenerate/confine.js +0 -311
  209. package/dist/regenerate/conform.d.ts +0 -66
  210. package/dist/regenerate/conform.js +0 -132
  211. package/dist/regenerate/conformance-agents.d.ts +0 -388
  212. package/dist/regenerate/conformance-agents.js +0 -1162
  213. package/dist/regenerate/conformance.d.ts +0 -191
  214. package/dist/regenerate/conformance.js +0 -1035
  215. package/dist/regenerate/conversation-writes.d.ts +0 -10
  216. package/dist/regenerate/conversation-writes.js +0 -100
  217. package/dist/regenerate/credentials.d.ts +0 -18
  218. package/dist/regenerate/credentials.js +0 -88
  219. package/dist/regenerate/debug-log.d.ts +0 -56
  220. package/dist/regenerate/debug-log.js +0 -236
  221. package/dist/regenerate/debugger.d.ts +0 -36
  222. package/dist/regenerate/debugger.js +0 -133
  223. package/dist/regenerate/delivery.d.ts +0 -2
  224. package/dist/regenerate/diagnose-job.d.ts +0 -2
  225. package/dist/regenerate/diagnose-job.js +0 -40
  226. package/dist/regenerate/diagnose.d.ts +0 -46
  227. package/dist/regenerate/diagnose.js +0 -92
  228. package/dist/regenerate/diff-view.d.ts +0 -64
  229. package/dist/regenerate/drift.d.ts +0 -120
  230. package/dist/regenerate/drift.js +0 -285
  231. package/dist/regenerate/environment-error.d.ts +0 -167
  232. package/dist/regenerate/environment-error.js +0 -342
  233. package/dist/regenerate/failure-reports.d.ts +0 -28
  234. package/dist/regenerate/failure-reports.js +0 -79
  235. package/dist/regenerate/job-log.d.ts +0 -30
  236. package/dist/regenerate/job-log.js +0 -105
  237. package/dist/regenerate/job-panel.d.ts +0 -122
  238. package/dist/regenerate/job-panel.js +0 -339
  239. package/dist/regenerate/jobs-tree.d.ts +0 -75
  240. package/dist/regenerate/jobs.d.ts +0 -231
  241. package/dist/regenerate/jobs.js +0 -522
  242. package/dist/regenerate/lanes.d.ts +0 -16
  243. package/dist/regenerate/lanes.js +0 -32
  244. package/dist/regenerate/launch.d.ts +0 -256
  245. package/dist/regenerate/launch.js +0 -689
  246. package/dist/regenerate/ledger-view.d.ts +0 -87
  247. package/dist/regenerate/ledger-view.js +0 -325
  248. package/dist/regenerate/ledger.d.ts +0 -368
  249. package/dist/regenerate/ledger.js +0 -357
  250. package/dist/regenerate/lineage.d.ts +0 -105
  251. package/dist/regenerate/lineage.js +0 -485
  252. package/dist/regenerate/list-arguments.d.ts +0 -21
  253. package/dist/regenerate/list-arguments.js +0 -121
  254. package/dist/regenerate/loop.d.ts +0 -423
  255. package/dist/regenerate/loop.js +0 -2079
  256. package/dist/regenerate/masking.d.ts +0 -19
  257. package/dist/regenerate/masking.js +0 -95
  258. package/dist/regenerate/model-names.d.ts +0 -33
  259. package/dist/regenerate/model-names.js +0 -92
  260. package/dist/regenerate/notes.d.ts +0 -159
  261. package/dist/regenerate/notes.js +0 -446
  262. package/dist/regenerate/os-sandbox.d.ts +0 -93
  263. package/dist/regenerate/os-sandbox.js +0 -283
  264. package/dist/regenerate/panel-dock.d.ts +0 -23
  265. package/dist/regenerate/paths.d.ts +0 -110
  266. package/dist/regenerate/paths.js +0 -190
  267. package/dist/regenerate/plain-palette.d.ts +0 -34
  268. package/dist/regenerate/prompt.d.ts +0 -230
  269. package/dist/regenerate/prompt.js +0 -741
  270. package/dist/regenerate/pulse-files.d.ts +0 -14
  271. package/dist/regenerate/pulse-files.js +0 -63
  272. package/dist/regenerate/records.d.ts +0 -132
  273. package/dist/regenerate/records.js +0 -327
  274. package/dist/regenerate/regenerate.d.ts +0 -106
  275. package/dist/regenerate/regenerate.js +0 -660
  276. package/dist/regenerate/regression.d.ts +0 -58
  277. package/dist/regenerate/regression.js +0 -188
  278. package/dist/regenerate/renames.d.ts +0 -42
  279. package/dist/regenerate/renames.js +0 -185
  280. package/dist/regenerate/requires.d.ts +0 -117
  281. package/dist/regenerate/requires.js +0 -377
  282. package/dist/regenerate/resources.d.ts +0 -57
  283. package/dist/regenerate/resources.js +0 -162
  284. package/dist/regenerate/scripts-being-written.d.ts +0 -19
  285. package/dist/regenerate/scripts-being-written.js +0 -30
  286. package/dist/regenerate/self-check.d.ts +0 -29
  287. package/dist/regenerate/self-check.js +0 -119
  288. package/dist/regenerate/services.d.ts +0 -28
  289. package/dist/regenerate/services.js +0 -158
  290. package/dist/regenerate/shell.d.ts +0 -91
  291. package/dist/regenerate/shell.js +0 -320
  292. package/dist/regenerate/side-panel.d.ts +0 -59
  293. package/dist/regenerate/spec-map-view.d.ts +0 -139
  294. package/dist/regenerate/spec-map.d.ts +0 -160
  295. package/dist/regenerate/spec-map.js +0 -596
  296. package/dist/regenerate/spec-steps.d.ts +0 -180
  297. package/dist/regenerate/spec-steps.js +0 -729
  298. package/dist/regenerate/standing.d.ts +0 -28
  299. package/dist/regenerate/standing.js +0 -30
  300. package/dist/regenerate/state.d.ts +0 -21
  301. package/dist/regenerate/state.js +0 -10
  302. package/dist/regenerate/steering.d.ts +0 -56
  303. package/dist/regenerate/steering.js +0 -119
  304. package/dist/regenerate/stop-report.d.ts +0 -43
  305. package/dist/regenerate/stop-report.js +0 -160
  306. package/dist/regenerate/submit-work.d.ts +0 -44
  307. package/dist/regenerate/submit-work.js +0 -76
  308. package/dist/regenerate/test-kinds.d.ts +0 -85
  309. package/dist/regenerate/test-kinds.js +0 -171
  310. package/dist/regenerate/test-scripts.d.ts +0 -235
  311. package/dist/regenerate/test-scripts.js +0 -843
  312. package/dist/regenerate/testing-steps.d.ts +0 -52
  313. package/dist/regenerate/testing-steps.js +0 -129
  314. package/dist/regenerate/testing.d.ts +0 -150
  315. package/dist/regenerate/testing.js +0 -438
  316. package/dist/regenerate/transcript-view.d.ts +0 -21
  317. package/dist/regenerate/unit-gate.d.ts +0 -27
  318. package/dist/regenerate/unit-gate.js +0 -20
  319. package/dist/regenerate/unit-review.d.ts +0 -152
  320. package/dist/regenerate/unit-review.js +0 -361
  321. package/dist/regenerate/web.d.ts +0 -61
  322. package/dist/regenerate/web.js +0 -256
  323. package/dist/regenerate/workspace.d.ts +0 -12
  324. package/dist/regenerate/workspace.js +0 -99
  325. package/dist/regenerate-cli.d.ts +0 -1
  326. package/dist/resume-line.d.ts +0 -5
  327. package/dist/review/live.d.ts +0 -72
  328. package/dist/review/live.js +0 -166
  329. package/dist/rules.d.ts +0 -20
  330. package/dist/rules.js +0 -47
  331. package/dist/run-report.d.ts +0 -88
  332. package/dist/run-report.js +0 -338
  333. package/dist/screen-padding.d.ts +0 -28
  334. package/dist/self-invocation.d.ts +0 -36
  335. package/dist/self-invocation.js +0 -137
  336. package/dist/sentinel-chat.d.ts +0 -19
  337. package/dist/sentinel-chat.js +0 -221
  338. package/dist/sentinel-check.d.ts +0 -36
  339. package/dist/sentinel-check.js +0 -78
  340. package/dist/sentinel.d.ts +0 -107
  341. package/dist/sentinel.js +0 -599
  342. package/dist/settings.d.ts +0 -45
  343. package/dist/settings.js +0 -378
  344. package/dist/setup.d.ts +0 -97
  345. package/dist/setup.js +0 -428
  346. package/dist/skill-progress.d.ts +0 -46
  347. package/dist/skill.d.ts +0 -102
  348. package/dist/skill.js +0 -147
  349. package/dist/skills.d.ts +0 -54
  350. package/dist/skills.js +0 -111
  351. package/dist/spawn-async.d.ts +0 -18
  352. package/dist/spawn-async.js +0 -35
  353. package/dist/stack.d.ts +0 -80
  354. package/dist/stack.js +0 -206
  355. package/dist/stdlib.d.ts +0 -43
  356. package/dist/stdlib.js +0 -118
  357. package/dist/surface.d.ts +0 -5
  358. package/dist/surface.js +0 -18
  359. package/dist/terminal-images.d.ts +0 -2
  360. package/dist/test-plain-files.d.ts +0 -41
  361. package/dist/test-plain-files.js +0 -172
  362. package/dist/tools.d.ts +0 -101
  363. package/dist/tools.js +0 -242
  364. package/dist/turri-versions.d.ts +0 -71
  365. package/genome/rules/bullet-continuation.md +0 -61
  366. package/genome/rules/concise-specs-examples.md +0 -460
  367. package/genome/rules/concise-specs-integration-examples.md +0 -281
  368. package/genome/rules/concise-specs.md +0 -80
  369. package/genome/rules/definitions.md +0 -107
  370. package/genome/rules/examples/integration-embedded-testing/run_conformance_tests_java.sh +0 -161
  371. package/genome/rules/examples/integration-embedded-testing/run_unittests_java.sh +0 -50
  372. package/genome/rules/exported-concepts.md +0 -39
  373. package/genome/rules/func-specs.md +0 -164
  374. package/genome/rules/impl-reqs.md +0 -68
  375. package/genome/rules/import-modules.md +0 -49
  376. package/genome/rules/integration-embedded-testing.md +0 -273
  377. package/genome/rules/integration-embedded.md +0 -171
  378. package/genome/rules/integration-standalone.md +0 -135
  379. package/genome/rules/integrations.md +0 -136
  380. package/genome/rules/linked-resources.md +0 -76
  381. package/genome/rules/module-structure.md +0 -112
  382. package/genome/rules/project-model.md +0 -69
  383. package/genome/rules/required-concepts.md +0 -44
  384. package/genome/rules/requires-modules.md +0 -81
  385. package/genome/rules/semantic-ids.md +0 -49
  386. package/genome/rules/stdlib.md +0 -37
  387. package/genome/rules/test-plain-files.md +0 -138
  388. package/genome/rules/test-reqs.md +0 -57
  389. package/genome/rules/turri-regeneration.md +0 -66
  390. package/genome/skills/analyze-2-func-specs/SKILL.md +0 -116
  391. package/genome/skills/analyze-func-specs/SKILL.md +0 -137
  392. package/genome/skills/break-down-func-spec/SKILL.md +0 -229
  393. package/genome/skills/consolidate-concepts/SKILL.md +0 -192
  394. package/genome/skills/convert-old-syntax/SKILL.md +0 -68
  395. package/genome/skills/convert-old-syntax/references/rubric.md +0 -11
  396. package/genome/skills/debug-specs/SKILL.md +0 -194
  397. package/genome/skills/implement-conformance-testing-script/SKILL.md +0 -247
  398. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_cypress.ps1 +0 -337
  399. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_golang.ps1 +0 -111
  400. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_java.sh +0 -151
  401. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_python.ps1 +0 -103
  402. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_python.sh +0 -146
  403. package/genome/skills/implement-unit-testing-script/SKILL.md +0 -171
  404. package/genome/skills/implement-unit-testing-script/assets/run_unittests_flutter.ps1 +0 -87
  405. package/genome/skills/implement-unit-testing-script/assets/run_unittests_golang.ps1 +0 -73
  406. package/genome/skills/implement-unit-testing-script/assets/run_unittests_java.sh +0 -82
  407. package/genome/skills/implement-unit-testing-script/assets/run_unittests_python.ps1 +0 -81
  408. package/genome/skills/implement-unit-testing-script/assets/run_unittests_python.sh +0 -102
  409. package/genome/skills/implement-unit-testing-script/assets/run_unittests_react.ps1 +0 -87
  410. package/genome/skills/refactor-module/SKILL.md +0 -218
  411. package/genome/skills/resolve-section-ownership/SKILL.md +0 -64
  412. package/genome/skills/resolve-spec-conflict/SKILL.md +0 -102
  413. package/stdlib/backend/common.plain +0 -25
  414. package/stdlib/backend/conformance/common.plain +0 -12
  415. package/stdlib/backend/conformance/go-gin.plain +0 -9
  416. package/stdlib/backend/conformance/go-nethttp.plain +0 -9
  417. package/stdlib/backend/conformance/java-springboot.plain +0 -9
  418. package/stdlib/backend/conformance/python-django.plain +0 -9
  419. package/stdlib/backend/conformance/python-fastapi.plain +0 -9
  420. package/stdlib/backend/conformance/python-flask.plain +0 -9
  421. package/stdlib/backend/conformance/rust-axum.plain +0 -9
  422. package/stdlib/backend/conformance/typescript-express.plain +0 -9
  423. package/stdlib/backend/conformance/typescript-fastify.plain +0 -9
  424. package/stdlib/backend/conformance/typescript-nestjs.plain +0 -9
  425. package/stdlib/backend/go-gin.plain +0 -18
  426. package/stdlib/backend/go-nethttp.plain +0 -18
  427. package/stdlib/backend/java-springboot.plain +0 -19
  428. package/stdlib/backend/python-django.plain +0 -19
  429. package/stdlib/backend/python-fastapi.plain +0 -23
  430. package/stdlib/backend/python-flask.plain +0 -23
  431. package/stdlib/backend/rust-axum.plain +0 -17
  432. package/stdlib/backend/typescript-express.plain +0 -19
  433. package/stdlib/backend/typescript-fastify.plain +0 -19
  434. package/stdlib/backend/typescript-nestjs.plain +0 -19
  435. package/stdlib/cli/common.plain +0 -17
  436. package/stdlib/cli/conformance/common.plain +0 -11
  437. package/stdlib/cli/conformance/go-cobra.plain +0 -9
  438. package/stdlib/cli/conformance/go-flag.plain +0 -9
  439. package/stdlib/cli/conformance/java-picocli.plain +0 -9
  440. package/stdlib/cli/conformance/python-argparse.plain +0 -9
  441. package/stdlib/cli/conformance/python-click.plain +0 -9
  442. package/stdlib/cli/conformance/python-typer.plain +0 -9
  443. package/stdlib/cli/conformance/rust-clap.plain +0 -9
  444. package/stdlib/cli/conformance/typescript-commander.plain +0 -9
  445. package/stdlib/cli/go-cobra.plain +0 -14
  446. package/stdlib/cli/go-flag.plain +0 -14
  447. package/stdlib/cli/java-picocli.plain +0 -15
  448. package/stdlib/cli/python-argparse.plain +0 -18
  449. package/stdlib/cli/python-click.plain +0 -16
  450. package/stdlib/cli/python-typer.plain +0 -16
  451. package/stdlib/cli/rust-clap.plain +0 -14
  452. package/stdlib/cli/typescript-commander.plain +0 -17
  453. package/stdlib/frontend/angular.plain +0 -17
  454. package/stdlib/frontend/common.plain +0 -17
  455. package/stdlib/frontend/conformance/angular.plain +0 -5
  456. package/stdlib/frontend/conformance/common.plain +0 -11
  457. package/stdlib/frontend/conformance/react-vite.plain +0 -5
  458. package/stdlib/frontend/conformance/sveltekit-spa.plain +0 -5
  459. package/stdlib/frontend/conformance/vue-vite.plain +0 -5
  460. package/stdlib/frontend/react-vite.plain +0 -16
  461. package/stdlib/frontend/sveltekit-spa.plain +0 -16
  462. package/stdlib/frontend/vue-vite.plain +0 -16
  463. package/stdlib/lang/go.plain +0 -13
  464. package/stdlib/lang/java.plain +0 -12
  465. package/stdlib/lang/python.plain +0 -18
  466. package/stdlib/lang/rust.plain +0 -12
  467. package/stdlib/lang/typescript.plain +0 -13
  468. package/stdlib/library/common.plain +0 -15
  469. package/stdlib/library/conformance/common.plain +0 -9
  470. package/stdlib/library/conformance/go.plain +0 -9
  471. package/stdlib/library/conformance/java-gradle.plain +0 -9
  472. package/stdlib/library/conformance/java-maven.plain +0 -9
  473. package/stdlib/library/conformance/python.plain +0 -9
  474. package/stdlib/library/conformance/rust.plain +0 -9
  475. package/stdlib/library/conformance/typescript.plain +0 -9
  476. package/stdlib/library/go.plain +0 -12
  477. package/stdlib/library/java-gradle.plain +0 -13
  478. package/stdlib/library/java-maven.plain +0 -13
  479. package/stdlib/library/python.plain +0 -13
  480. package/stdlib/library/rust.plain +0 -12
  481. package/stdlib/library/typescript.plain +0 -15
@@ -1,1035 +0,0 @@
1
- import { existsSync, mkdirSync, readFileSync } from "node:fs";
2
- import { basename, extname, join, relative, resolve } from "node:path";
3
- import { ask, BEGIN, createExecutor, refuseIfModelIsBlind } from "../pi.js";
4
- import { PLAIN_SOURCE_FILE_EXTENSION, plainFileParser } from "../plain/parser.js";
5
- import { ACCEPTANCE_TESTS, CONFORMANCE_TESTS, DEFINITIONS, FUNCTIONAL_REQUIREMENTS, NON_FUNCTIONAL_REQUIREMENTS, getFrids, getInheritedFunctionalSpecs, getSpecificationsForFrid, TEST_REQUIREMENTS, } from "../plain/spec.js";
6
- import { reportActivity, reportLogNote, reportSpec, reportStage, unitOf } from "./activity.js";
7
- import { confinedTools } from "./confine.js";
8
- import { abandonWork, diffSinceSnapshot, landWork, moduleDirOf, startWork, workDiff, workSnapshot } from "./lineage.js";
9
- import { firstLine, record } from "./ledger.js";
10
- import { createWorkLedger, describeAccounts, SUBMIT_WORK_NOTE, unanswered, unansweredPrompt } from "./submit-work.js";
11
- import { CONFORMANCE_COMPACTION } from "./compaction.js";
12
- import { NOTES_TURN, notesForSession, passedOutcome, readNotes, reflectOnReview, withNotes } from "./notes.js";
13
- import { labelsPrompt, labelsPromptFor, misplacedConformanceTests, misplacedTestsPrompt, missingTestLabels, orphanedLabels, orphansPrompt, testedSpecsOf } from "./test-kinds.js";
14
- import { createScriptTool, findTestScripts, projectRootFor, requireTestScripts, runConformanceScript, runUnitScript, failureSignature, STUCK_ROUNDS, scriptFailure, staticChecksOnly, withTestingScripts, } from "./test-scripts.js";
15
- import { createWebTools, WEB_TOOLS } from "./web.js";
16
- import { createMyDiffTool } from "./self-check.js";
17
- import { createServiceTools } from "./services.js";
18
- import { missingToolchainError, runEnvironmentError, scriptFaultError, timeLimitError, toolchainError } from "./environment-error.js";
19
- import { workspaceBlock } from "./workspace.js";
20
- import { codeFixPrompt, conflictKey, escalatedFixPrompt, createCodeFixer, answerAsExplorer, createAskExplorerTool, exploreInvocation, judgeFailure, SPEC_CONFLICT_RAISES, ENVIRONMENT_RAISES, environmentCheckPrompt, createTestReviewer, testReviewRequest, reviewFeedbackPrompt, testsFixPrompt, sortedRefs, } from "./conformance-agents.js";
21
- import { resolveRequiresChain } from "./requires.js";
22
- import { notesToRead, recordNote } from "./notes.js";
23
- import { reportSpecConflict } from "./activity.js";
24
- import { ATTEMPTS } from "./stop-report.js";
25
- import { ARBITER_AFTER, arbitrateReview, dismissedNote, REVIEW_LIMIT } from "./arbiter.js";
26
- import { sectionsOf } from "./state.js";
27
- import { configForSpec, inheritModel, modelOnly, modelSpec, testDirOf } from "../config.js";
28
- import { defaultBuildDir, modulesRoot, testsDirUnder, projectDirOf } from "./paths.js";
29
- import { buildConformancePrompt, functionalitiesByModule, moduleSection, scenariosBlock, section, sectionModules, specChangeBlock } from "./prompt.js";
30
- import { diffFiles, digestFiles } from "./codebase.js";
31
- import { createCopyResourceTool, loadLinkedResources, resourceImages } from "./resources.js";
32
- import { resolveTemplateDirs } from "./paths.js";
33
- import { findTestRemovals, inventoryTests, listFiles, removalChallengePrompt, shownOutput, truncateOutput, verifyUnitSuite, } from "./testing.js";
34
- const DEFAULT_MAX_ROUNDS = ATTEMPTS.conformance;
35
- /**
36
- * A module's conformance tests: one directory, `plain_modules/<module>/tests`, organised
37
- * however the tests are best organised. It holds the tests of the modules it requires too,
38
- * copied up with their code, so running it is the regression suite of the whole chain.
39
- */
40
- export function conformanceDirFor(moduleName, root) {
41
- return testsDirUnder(root ?? modulesRoot(), moduleName);
42
- }
43
- /**
44
- * Write black-box conformance tests for one functionality of a .plain specification.
45
- *
46
- * Runs after the functionality has been rendered: the build directory is the subject,
47
- * and this refuses to start without one.
48
- */
49
- export async function renderConformanceTests(options) {
50
- if (extname(options.plainFile) !== PLAIN_SOURCE_FILE_EXTENSION) {
51
- throw new Error(`Expected a ${PLAIN_SOURCE_FILE_EXTENSION} file, got '${options.plainFile}'.`);
52
- }
53
- const templateDirs = resolveTemplateDirs(options.plainFile, options.templateDirs);
54
- const [moduleName, tree] = options.spec
55
- ? [options.spec.moduleName, options.spec.tree]
56
- : plainFileParser(basename(options.plainFile), templateDirs, { testDir: testDirOf(options.plainFile) });
57
- // For a spec change, the tests follow the change, whatever it touches - a definition, a req -
58
- // with or without a functional spec yet; for one functionality, they are that functionality's.
59
- const forChange = options.diff !== undefined;
60
- const funcIds = [...getFrids(tree)];
61
- const funcId = options.funcId ?? (forChange ? funcIds.at(-1) : funcIds[0]);
62
- if (funcId === undefined && !forChange)
63
- throw new Error(`Module '${moduleName}' has no functionalities.`);
64
- if (funcId !== undefined && !funcIds.includes(funcId)) {
65
- throw new Error(`Functionality ${funcId} does not exist. Available: ${funcIds.join(", ")}.`);
66
- }
67
- const buildDir = resolve(options.buildDir ?? defaultBuildDir(moduleName, projectDirOf(options.plainFile)));
68
- // The agents that give a verdict - the judge, the test review - may run on a stronger model than the rest.
69
- const judgeModel = options.judgeModel ?? modelSpec(inheritModel(configForSpec(options.plainFile).judgeModel, modelOnly(options.model)));
70
- const conformanceDir = resolve(options.conformanceDir ?? conformanceDirFor(moduleName, modulesRoot(projectDirOf(options.plainFile))));
71
- const stage = (label) => {
72
- if (!options.dryRun)
73
- reportStage(`${forChange ? unitOf(moduleName) : unitOf(moduleName, funcId)}: ${label}`);
74
- };
75
- stage(options.diff !== undefined ? "conformance tests for the spec change" : `conformance tests for functionality ${funcId}`);
76
- if (!options.dryRun && !forChange)
77
- reportSpec(buildingSpec(moduleName, funcId, funcIds.length, getSpecificationsForFrid(tree, funcId)[0]));
78
- // From the last known good state, unless this step continues work not yet committed.
79
- // On its own it is one unit - its tests, and any change to the code - landed whole or undone
80
- // whole. Continuing work already under way, it is part of that work's unit instead.
81
- let start;
82
- if (!options.dryRun && options.continuing !== true) {
83
- stage("starting from the codebase's last commit");
84
- start = startWork([buildDir, conformanceDir], moduleName);
85
- }
86
- const manifest = listFiles(buildDir);
87
- if (manifest.length === 0) {
88
- throw new Error(`Nothing to test: ${buildDir} is empty or missing. ` +
89
- `Build the code first: turri regenerate ${relative(process.cwd(), options.plainFile)}.`);
90
- }
91
- // The spec as it stands: every section, and the functional specs - none, for a change made
92
- // before any was written.
93
- const specifications = funcId !== undefined
94
- ? getSpecificationsForFrid(tree, funcId)[0]
95
- : { ...sectionsOf(tree), [FUNCTIONAL_REQUIREMENTS]: [], [CONFORMANCE_TESTS]: [], [ACCEPTANCE_TESTS]: [] };
96
- // Conformance tests are written from the test reqs: they say how the suite is built and
97
- // run. Without them there is nothing to write tests against, and an agent asked anyway
98
- // would invent a convention that nothing else in the project shares.
99
- if (specifications[TEST_REQUIREMENTS].length === 0) {
100
- throw new Error(`Module '${moduleName}' has no ${TEST_REQUIREMENTS}, so conformance tests cannot be written. ` +
101
- `Add a ${TEST_REQUIREMENTS} section saying how conformance tests are written and run, or render ` +
102
- "with conformance turned off.");
103
- }
104
- // A functional spec's tests are its scenarios': one with none - no test plain file - has nothing to test.
105
- if (!forChange && (specifications[CONFORMANCE_TESTS] ?? []).length + (specifications[ACCEPTANCE_TESTS] ?? []).length === 0) {
106
- throw new Error(`${moduleName}:${funcId} has no scenarios - no test plain file - so there is nothing to test: write its conformance or ` +
107
- "acceptance scenarios first.");
108
- }
109
- // Whether the tests pass is the project's conformance testing script - and, when the code is
110
- // changed, its unit testing script: without them, nothing is written.
111
- stage("finding the project's testing scripts");
112
- const root = projectRootFor(options.plainFile, buildDir);
113
- const scripts = findTestScripts(root, options.plainFile, buildDir);
114
- if (!options.dryRun)
115
- requireTestScripts(moduleName, scripts, { conformance: true });
116
- const linkedResources = loadLinkedResources(tree, forChange ? null : funcId, templateDirs);
117
- // The spec's images need a model that reads them: refused before any of its agents starts.
118
- if (!options.dryRun)
119
- await refuseIfModelIsBlind(options.model, resourceImages(linkedResources).length);
120
- const required = getInheritedFunctionalSpecs(tree);
121
- const prompt = withTestingScripts(buildConformancePrompt({
122
- ...(options.cases !== undefined ? { cases: options.cases } : {}),
123
- moduleName,
124
- funcId,
125
- specifications,
126
- funcIds,
127
- modules: sectionModules(tree, moduleName),
128
- linkedResources,
129
- manifest,
130
- codeDir: buildDir,
131
- existingTests: listFiles(conformanceDir),
132
- required,
133
- diff: options.change ?? options.diff,
134
- }), scripts, ["conformance", "unit"], root);
135
- if (options.dryRun) {
136
- return {
137
- moduleName,
138
- funcId: funcId ?? "",
139
- buildDir,
140
- conformanceDir,
141
- prompt,
142
- response: "",
143
- files: listFiles(conformanceDir),
144
- runs: [],
145
- passed: false,
146
- codeChanged: false,
147
- testRemovals: [],
148
- };
149
- }
150
- mkdirSync(conformanceDir, { recursive: true });
151
- reportLogNote(` conformance testing script: ${relative(root, scripts.conformance)}`);
152
- reportActivity(` the suite so far: ${listFiles(conformanceDir).length} files in ${relative(root, conformanceDir)}`);
153
- const runs = [];
154
- const unitRuns = [];
155
- const testRemovals = [];
156
- const codeBefore = digestFiles(buildDir);
157
- // The code and the tests at the last green run: the whole suite and the unit tests passing on them.
158
- let green;
159
- const codeChanged = () => {
160
- const diff = diffFiles(codeBefore, digestFiles(buildDir));
161
- return diff.added.length + diff.changed.length + diff.removed.length > 0;
162
- };
163
- // The code and its tests are rendered apart: the tests in their own folder, by an agent that
164
- // may read the code but writes only tests. An explorer reads the code first and writes down how the
165
- // software is invoked, which is what the tests are written against.
166
- const label = `${moduleName} ${options.diff !== undefined ? "spec change" : funcId}`;
167
- // For a spec change: the functionalities it touches, whose scenarios are carried out, labelled, checked and reviewed.
168
- const touched = forChange ? touchedFunctionalities(tree, funcIds, options.diff, moduleName, options.cases) : [];
169
- // The scenarios the run's tests carry out: those of every functionality the change touches, or of the one under test.
170
- const carriedOut = forChange ? touched : [testedSpecOf(specifications, funcId)];
171
- const specContext = { moduleName, text: specText(specifications, moduleName, funcIds, required, carriedOut, options.change ?? options.diff, sectionModules(tree, moduleName)) };
172
- // Any functionality of the codebase - this module's, and those of the modules it requires. A
173
- // functionality's run may raise a spec conflict only with that functionality; a spec diff's, between any two.
174
- const own = (forChange ? funcIds : funcIds.slice(0, funcIds.indexOf(funcId) + 1)).map((id) => ({ module: moduleName, funcId: id }));
175
- const scope = {
176
- functionalities: [...required.map((spec) => ({ module: spec.module, funcId: spec.funcId })), ...own],
177
- ...(forChange ? { touchedModules: [...new Set(touched.map((item) => item.module ?? moduleName))] } : { tested: { module: moduleName, funcId: funcId } }),
178
- };
179
- /** How many times each spec conflict has been raised in this run, by the two functionalities it names. */
180
- const conflicts = new Map();
181
- /**
182
- * How many times each failure has come back in this run - in a row or not: a run that swings
183
- * between two failures, each side undoing the other, is as stuck as one that repeats one.
184
- */
185
- const seenFailures = new Map();
186
- let reExplored = false;
187
- let stuck;
188
- /** What the review last found, while it has not passed. */
189
- let lastReview;
190
- /** The run's test reviewer, made at its first review and kept; what it saw last; what the arbiter let go of its last review. */
191
- let reviewer;
192
- let reviewSeen;
193
- let reviewLetGo = [];
194
- let failedReviews = 0;
195
- let reviewWaived;
196
- /** What each review that sent the tests back found, oldest first: what the arbiter weighs the next one against. */
197
- // The config's `review:` - off unless it says true: the tests are not reviewed.
198
- const reviewOn = configForSpec(options.plainFile).review === true;
199
- const reviewHistory = [];
200
- let specConflict;
201
- /** How many times in a row the run's environment, or the testing script, was judged what is wrong: the person's to fix. */
202
- let environmentRaises = 0;
203
- /** How many fixes in a row - the code's or the tests' - changed no file: an agent that will not, or cannot, act on the verdict. */
204
- let idleFixes = 0;
205
- /** The last fix was the tests', for a failure judged theirs: should the run fail the same way again, the judge weighs escalating it. */
206
- let testsFix;
207
- /** A failure escalated to the code: should the run still fail the same way after the code's fix, the run stops. */
208
- let escalated;
209
- let escalation;
210
- /**
211
- * One attempt at the failing run, written into the notes' pitfalls - what the next judge reads
212
- * first - as cause and effect: what failed, how it was judged, and what was changed; the next
213
- * attempt's line shows what came of it. Numbered in the line itself: two attempts that went the
214
- * same way are two lines, not one.
215
- */
216
- const recordAttempt = (attempt, run, judged, change) => {
217
- const files = change.files.length === 0 ? "nothing" : `${change.files.slice(0, 6).join(", ")}${change.files.length > 6 ? ` and ${change.files.length - 6} more` : ""}`;
218
- recordNote(conformanceDir, "pitfalls", `attempt ${attempt}: ${typeof run === "string" ? run : `failed with ${failureLine(run)}`} → judged ${judged.replace(/\s+/g, " ").slice(0, 240)} → the ${change.who} changed ${files}`, `${label} conformance attempt ${attempt}`);
219
- };
220
- /** Run a fix, and say which files of the code and the tests it changed. */
221
- const changing = async (work) => {
222
- const code = digestFiles(buildDir);
223
- const tests = digestFiles(conformanceDir);
224
- const result = await work();
225
- const named = (prefix, diff) => [
226
- ...diff.added.map((file) => `${prefix}/${file} (added)`),
227
- ...diff.changed.map((file) => `${prefix}/${file}`),
228
- ...diff.removed.map((file) => `${prefix}/${file} (removed)`),
229
- ];
230
- return { result, files: [...named("code", diffFiles(code, digestFiles(buildDir))), ...named("tests", diffFiles(tests, digestFiles(conformanceDir)))] };
231
- };
232
- stage(`exploring the code for how it is invoked${options.model ? ` (${options.model})` : ""}`);
233
- // The explorer reads the conformance testing script too: it is how the tests are built and run, and so how they reach the software.
234
- // The prepare script, where there is one, runs on the build before it - and only once it passes does the suite run.
235
- const testingScripts = [
236
- ...(scripts.prepare !== undefined
237
- ? [{ path: relative(root, scripts.prepare), runs: "<script> <copy of the build>, before every run of the conformance testing script", content: readFileSync(scripts.prepare, "utf8"), prepare: true }]
238
- : []),
239
- { path: relative(root, scripts.conformance), runs: "<script> <copy of the build> <copy of the whole conformance suite>", content: readFileSync(scripts.conformance, "utf8") },
240
- ];
241
- let invocation = await exploreInvocation({ buildDir, spec: specContext, scope, testingScripts, label, model: options.model, onDelta: options.onDelta });
242
- reportActivity(` how to invoke it: ${invocation.split("\n")[0].slice(0, 120)}`);
243
- const agentPrompt = withTestingScripts(buildConformancePrompt({
244
- ...(options.cases !== undefined ? { cases: options.cases } : {}),
245
- moduleName,
246
- funcId,
247
- specifications,
248
- funcIds,
249
- modules: sectionModules(tree, moduleName),
250
- linkedResources,
251
- manifest,
252
- existingTests: listFiles(conformanceDir),
253
- required,
254
- diff: options.change ?? options.diff,
255
- invocation,
256
- readCode: buildDir,
257
- manifests: buildManifests(buildDir),
258
- touched,
259
- }), scripts, ["conformance"], root);
260
- // The conformance agent: its file tools write the tests folder and read the code too - how it is reached, what it is
261
- // called - and its shell holds only the tests. The full outputs of test runs come through read_output, not by path.
262
- const fence = confinedTools({ workdir: conformanceDir, read: [conformanceDir, buildDir], write: [conformanceDir], reportsEnvironment: true });
263
- // Its notes are the tests' own, beside them: what it learns of black-box testing this module is no coding agent's to read.
264
- const notes = notesForSession(conformanceDir, `${label} conformance`);
265
- // Each agent runs the suite three times a turn at most: the third ends its turn, and the harness runs it and judges.
266
- const conformanceRuns = turnLimited(createScriptTool({
267
- kind: "conformance",
268
- script: scripts.conformance,
269
- run: () => runConformanceScript(buildDir, [conformanceDir], scripts),
270
- runs,
271
- onRun: options.onRun,
272
- }), RUNS_PER_TURN);
273
- const fixerConformanceRuns = turnLimited(createScriptTool({ kind: "conformance", script: scripts.conformance, run: () => runConformanceScript(buildDir, [conformanceDir], scripts), runs: [] }), RUNS_PER_TURN);
274
- // What the code fixer starts to try the code - a server - stopped when the run ends.
275
- const fixerServices = createServiceTools({ dir: buildDir, read: [buildDir, conformanceDir], write: [buildDir] });
276
- // What it hands over at the end of a turn, for its reviewer.
277
- const work = createWorkLedger();
278
- stage(`starting the conformance agent${options.model ? ` (${options.model})` : ""}`);
279
- // One session for the whole run: its task is its instructions, its work compacted as it gets longer.
280
- const executor = await createExecutor({
281
- cwd: conformanceDir,
282
- customTools: [
283
- notes.tool,
284
- notes.gapTool,
285
- work.tool,
286
- ...createWebTools(),
287
- ...fence.tools,
288
- conformanceRuns.tool,
289
- createMyDiffTool({ dir: conformanceDir, what: "tests" }),
290
- createAskExplorerTool({
291
- ask: (question) => {
292
- stage("the conformance agent asks the explorer");
293
- return answerAsExplorer({ buildDir, spec: specContext, account: invocation, question, label, model: options.model, onDelta: options.onDelta });
294
- },
295
- }),
296
- createCopyResourceTool({ resources: linkedResources, dir: conformanceDir }),
297
- ],
298
- tools: [...fence.names, "run_conformance_tests", "my_diff", "ask_explorer", "update_notes", "report_spec_gap", "submit_work", "copy_resource", ...WEB_TOOLS],
299
- model: options.model,
300
- label: `${label} conformance agent`,
301
- role: "conformance",
302
- system: `${fence.note}\n\n${workspaceBlock({ dir: conformanceDir, hasMyDiff: true })}`,
303
- task: [withNotes(agentPrompt, conformanceDir), "", ...SUBMIT_WORK_NOTE].join("\n"),
304
- compaction: { instructions: CONFORMANCE_COMPACTION },
305
- checkEnvironment: { run: () => runConformanceScript(buildDir, [conformanceDir], scripts), script: scripts.conformance },
306
- images: resourceImages(linkedResources),
307
- });
308
- /** A turn of the conformance agent: a fresh count of its runs of the suite. */
309
- const askConformance = (text, onDelta, turn) => {
310
- conformanceRuns.newTurn();
311
- return ask(executor, text, onDelta, turn);
312
- };
313
- // The coding agent, made the first time the code is what is wrong.
314
- let fixer;
315
- const fixerNotes = notesForSession(buildDir, `${label} conformance code fix`);
316
- const askFixer = async (text) => {
317
- fixer ??= await createCodeFixer({
318
- buildDir,
319
- conformanceDir,
320
- label,
321
- model: options.model,
322
- spec: specContext,
323
- // The unit tests, and the conformance suite - to reproduce the failure and check the fix, seeing only its output.
324
- tools: [
325
- fixerNotes.tool,
326
- fixerNotes.gapTool,
327
- createScriptTool({ kind: "unit", script: scripts.unit, run: () => runUnitScript(buildDir, scripts.unit), runs: unitRuns }),
328
- fixerConformanceRuns.tool,
329
- ...fixerServices.tools,
330
- ],
331
- toolNames: ["run_unit_tests", "run_conformance_tests", ...fixerServices.names, "update_notes", "report_spec_gap"],
332
- checkEnvironment: { run: () => runUnitScript(buildDir, scripts.unit), script: scripts.unit },
333
- testingScripts: { scripts, root },
334
- });
335
- fixerConformanceRuns.newTurn();
336
- return ask(fixer, withNotes(text, buildDir), options.onDelta);
337
- };
338
- try {
339
- let inventory = inventoryTests(conformanceDir);
340
- // What the tests were when this run began: what it adds or changes is what the review gate reads.
341
- const testsAtStart = digestFiles(conformanceDir);
342
- let unitInventory = inventoryTests(buildDir);
343
- const scenarios = carriedOut.reduce((count, item) => count + item.conformance.length + item.acceptance.length, 0);
344
- stage(options.diff !== undefined
345
- ? "turri is bringing the conformance tests in line with the spec change"
346
- : `turri is writing the conformance tests of its ${scenarios} scenario${scenarios === 1 ? "" : "s"}`);
347
- let response = await askConformance(BEGIN, options.onDelta);
348
- const maxRounds = options.maxRounds ?? DEFAULT_MAX_ROUNDS;
349
- let verified = false;
350
- let rounds = 0;
351
- let labelAsks = 0;
352
- let unlabelled;
353
- for (let round = 0; round < maxRounds; round += 1) {
354
- const current = inventoryTests(conformanceDir);
355
- const removals = findTestRemovals(inventory, current);
356
- if (removals.length > 0) {
357
- stage(`justifying ${removals.length} removed conformance test${removals.length === 1 ? "" : "s"}`);
358
- testRemovals.push(...removals);
359
- inventory = current;
360
- response = await askConformance(removalChallengePrompt(removals, "conformance tests"), options.onDelta);
361
- continue;
362
- }
363
- // The coding agent keeps the unit tests it found.
364
- const unitNow = inventoryTests(buildDir);
365
- const unitRemovals = findTestRemovals(unitInventory, unitNow);
366
- unitInventory = unitNow;
367
- if (unitRemovals.length > 0 && fixer !== undefined) {
368
- stage(`justifying ${unitRemovals.length} removed unit test${unitRemovals.length === 1 ? "" : "s"}`);
369
- testRemovals.push(...unitRemovals);
370
- await askFixer(removalChallengePrompt(unitRemovals, "unit tests"));
371
- continue;
372
- }
373
- // A test for each scenario has to be there, and labelled as the scenario it carries out, before anything else counts.
374
- if (options.diff === undefined) {
375
- const missing = missingTestLabels(conformanceDir, moduleName, carriedOut[0]);
376
- if (missing.length > 0) {
377
- if (labelAsks >= LABEL_ASKS) {
378
- stage(`the tests were sent back ${LABEL_ASKS} times to be written and labelled, and still are not - stopping`);
379
- unlabelled = missing;
380
- break;
381
- }
382
- labelAsks += 1;
383
- stage(listFiles(conformanceDir).length === 0 ? "no tests in the tests folder - the conformance agent writes them" : "labelling the tests of the scenarios");
384
- response = await askConformance(labelsPrompt(moduleName, funcId, missing, listFiles(conformanceDir).length === 0), options.onDelta);
385
- continue;
386
- }
387
- }
388
- else {
389
- // A spec change: every functionality it touches, as a functionality's own run would have it - every one missing
390
- // asked for in one request, checked whole again after each answer, so none is asked for in place of another.
391
- // And every other functional spec the tests are written for: each of its scenarios has its labelled test too.
392
- const touchedKeys = new Set(touched.map((item) => `${item.module ?? moduleName}:${item.funcId}`));
393
- const others = testedSpecsOf(options.recorded).filter((item) => !touchedKeys.has(`${item.module ?? moduleName}:${item.funcId}`));
394
- const pending = [...touched, ...others]
395
- .map((item) => ({ funcId: item.funcId, ...(item.module !== undefined ? { module: item.module } : {}), missing: missingTestLabels(conformanceDir, moduleName, item) }))
396
- .filter((item) => item.missing.length > 0);
397
- if (pending.length > 0) {
398
- if (labelAsks >= LABEL_ASKS) {
399
- stage(`the tests were sent back ${LABEL_ASKS} times to be written and labelled, and still are not - stopping`);
400
- unlabelled = pending.flatMap((item) => item.missing);
401
- break;
402
- }
403
- labelAsks += 1;
404
- stage(`labelling the tests of the scenarios of ${pending.map((item) => `${item.module ?? moduleName}:${item.funcId}`).join(", ")}, which the change touches`);
405
- response = await askConformance(labelsPromptFor(moduleName, pending, listFiles(conformanceDir).length === 0), options.onDelta);
406
- continue;
407
- }
408
- // A label that names nothing the tests are written for - a scenario or a functional spec taken out, a label
409
- // mistyped, a test invented beside the scenarios: sent back to be removed or relabelled.
410
- const orphans = options.recorded !== undefined ? orphanedLabels(conformanceDir, moduleName, testedSpecsOf(options.recorded)) : [];
411
- if (orphans.length > 0) {
412
- if (labelAsks >= LABEL_ASKS) {
413
- stage(`the tests were sent back ${LABEL_ASKS} times to be written and labelled, and still are not - stopping`);
414
- unlabelled = orphans.map((orphan) => `${orphan.file} is labelled "${orphan.label}", which names nothing the tests are written for.`);
415
- break;
416
- }
417
- labelAsks += 1;
418
- stage(`${orphans.length} label${orphans.length === 1 ? "" : "s"} in the tests name${orphans.length === 1 ? "s" : ""} nothing they are written for - the conformance agent removes or relabels them`);
419
- response = await askConformance(orphansPrompt(orphans), options.onDelta);
420
- continue;
421
- }
422
- }
423
- // The suite is the tests folder: a conformance test in the code folder is in the wrong place,
424
- // and not the coding agent's to write.
425
- const misplaced = misplacedConformanceTests(buildDir);
426
- if (misplaced.length > 0) {
427
- stage(`conformance tests in the code folder - the coding agent removes ${misplaced.length === 1 ? "it" : "them"}`);
428
- await askFixer(misplacedTestsPrompt(misplaced, buildDir, conformanceDir));
429
- continue;
430
- }
431
- // Whether it is done is the harness's run of the project's conformance testing script, on
432
- // every functionality's tests - and the code's unit testing script.
433
- stage(`running the conformance testing script on the whole suite (attempt ${rounds + 1} of ${maxRounds})`);
434
- rounds += 1;
435
- record({ kind: "gate.round", gate: "conformance", round: rounds, of: maxRounds });
436
- let recheck = await runConformanceScript(buildDir, [conformanceDir], scripts);
437
- runs.push({ command: recheck.command, exitCode: recheck.exitCode });
438
- options.onRun?.(recheck.command, recheck.exitCode);
439
- // The script cannot find its toolchain: the machine lacks it, and no change to the tests or the code would pass it.
440
- // The pulse stops - rolled back by the loop - and the person is told; no agent is sent to work around it.
441
- const lacking = recheck.exitCode !== 0 ? missingToolchainError(recheck, { moduleName, script: scripts.conformance, kind: "conformance" }) : undefined;
442
- if (lacking !== undefined) {
443
- if (start !== undefined)
444
- abandonWork(start, moduleName, "the conformance testing script could not run");
445
- throw lacking;
446
- }
447
- // A failure escalated to the code, still the same after the code's fix: neither agent could fix it, and the run stops
448
- // with why the judge found it the code's. Anything else it fails on is a new failure, judged as any other.
449
- if (escalated !== undefined && recheck.exitCode !== 0 && failureSignature(recheck) === escalated.signature) {
450
- escalation = { reason: escalated.reason, evidence: escalated.evidence, error: failureLine(recheck), failure: truncateOutput(recheck.output, undefined).slice(-4000) };
451
- stage("the failure escalated to the code is still there after the coding agent's fix - stopping");
452
- recordNote(conformanceDir, "pitfalls", `stopped after ${rounds} attempts: failed with ${failureLine(recheck)}, escalated to the code - ${escalated.reason.replace(/\s+/g, " ").slice(0, 240)} - and the code's fix did not change it`, `${label} conformance`);
453
- break;
454
- }
455
- escalated = undefined;
456
- if (recheck.exitCode !== 0) {
457
- // Nothing changing: the same failure, taken the same way, round after round. Once, the explorer
458
- // is asked what the tests lack - most often how they reach the software; after that, it stops.
459
- const unmoved = async () => {
460
- const key = failureSignature(recheck);
461
- const seen = (seenFailures.get(key) ?? 0) + 1;
462
- seenFailures.set(key, seen);
463
- if (seen < STUCK_ROUNDS)
464
- return undefined;
465
- seenFailures.clear();
466
- if (reExplored) {
467
- stuck = { failure: truncateOutput(recheck.output, undefined).slice(-4000), rounds, error: failureLine(recheck), times: STUCK_ROUNDS };
468
- stage(`the same failure ${STUCK_ROUNDS} times again, after the explorer was asked - stopping`);
469
- recordNote(conformanceDir, "pitfalls", `stuck after ${rounds} attempts: failed with ${failureLine(recheck)} ${STUCK_ROUNDS} times, before and after the explorer was asked again`, `${label} conformance`);
470
- return "stuck";
471
- }
472
- reExplored = true;
473
- stage(`the same failure ${STUCK_ROUNDS} times - asking the explorer again what the tests lack`);
474
- invocation = await exploreInvocation({
475
- buildDir,
476
- spec: specContext,
477
- scope,
478
- testingScripts,
479
- question: { failure: shownOutput(buildDir, "conformance-stuck", recheck.output), account: invocation },
480
- label,
481
- model: options.model,
482
- onDelta: options.onDelta,
483
- });
484
- const asked = await changing(() => ask(executor, [
485
- `The conformance tests have failed the same way ${STUCK_ROUNDS} times, so the explorer was asked again what they`,
486
- "lack. This is its new account - it replaces the one you had. Read it, and the conformance testing script at",
487
- "the top of your prompt, for how the tests reach the software; then fix the tests accordingly.",
488
- "",
489
- `<how to invoke it>\n${invocation.trim()}\n</how to invoke it>`,
490
- "",
491
- ...buildManifests(buildDir).map((manifest) => `<code build file path="${manifest.path}">\n${manifest.content.trimEnd()}\n</code build file>\n`),
492
- "<failing run>",
493
- recheck.output.trimEnd().slice(-6000),
494
- "</failing run>",
495
- ].join("\n"), options.onDelta));
496
- response = asked.result;
497
- recordAttempt(rounds, recheck, `the same failure ${STUCK_ROUNDS} times - the explorer was asked again what the tests lack`, { who: "conformance agent", files: asked.files });
498
- return "asked";
499
- };
500
- // The tests pass and only their static checks do not: the findings are in the tests, the conformance agent's
501
- // alone - no judge is asked whether the code or the tests are wrong.
502
- if (staticChecksOnly(recheck)) {
503
- const moved = await unmoved();
504
- if (moved === "stuck")
505
- break;
506
- if (moved === "asked")
507
- continue;
508
- stage("the conformance tests pass, and their static checks do not - back to the conformance agent");
509
- const fixed = await changing(() => askConformance(scriptFailure(recheck, "conformance testing"), options.onDelta));
510
- response = fixed.result;
511
- recordAttempt(rounds, recheck, "the tests' static checks", { who: "conformance agent", files: fixed.files });
512
- if (fixed.files.length === 0 && ++idleFixes >= IDLE_FIXES) {
513
- stuck = { failure: truncateOutput(recheck.output, undefined).slice(-4000), rounds, error: failureLine(recheck), times: idleFixes, changedNothing: true };
514
- stage(`${IDLE_FIXES} fixes in a row changed nothing - stopping`);
515
- break;
516
- }
517
- if (fixed.files.length > 0)
518
- idleFixes = 0;
519
- continue;
520
- }
521
- stage(`conformance tests failing - working out whether the code, the tests or the spec are wrong${judgeModel ? ` (${judgeModel})` : ""}`);
522
- // A fix that changed no file leaves the next run as this one: IDLE_FIXES of them in a row, and nothing will change.
523
- const idle = (files) => {
524
- idleFixes = files.length === 0 ? idleFixes + 1 : 0;
525
- if (idleFixes < IDLE_FIXES)
526
- return false;
527
- stuck = { failure: truncateOutput(recheck.output, undefined).slice(-4000), rounds, error: failureLine(recheck), times: idleFixes, changedNothing: true };
528
- stage(`${IDLE_FIXES} fixes in a row changed nothing - stopping`);
529
- recordNote(conformanceDir, "pitfalls", `stuck after ${rounds} attempts: failed with ${failureLine(recheck)}, and ${IDLE_FIXES} fixes in a row changed nothing`, `${label} conformance`);
530
- return true;
531
- };
532
- // The tests were fixed for this very failure, and it is still here: the judge weighs whether it is the code's.
533
- const signature = failureSignature(recheck);
534
- const escalating = testsFix !== undefined && testsFix.signature === signature ? { reason: testsFix.reason, changed: testsFix.files } : undefined;
535
- testsFix = undefined;
536
- if (escalating !== undefined)
537
- stage("the tests' fix did not make the failure go away - the judge weighs whether it is the code's");
538
- const verdict = await judgeFailure({
539
- buildDir,
540
- conformanceDir,
541
- spec: specContext,
542
- run: recheck,
543
- invocation,
544
- scope,
545
- // The tests' notes - every attempt so far - and the code's: it weighs the one against the other.
546
- notes: [notesToRead(conformanceDir), notesToRead(buildDir)].filter((part) => part !== "").join("\n\n"),
547
- // The script itself, so the judge checks the explorer's account against it rather than repeating it.
548
- testingScripts,
549
- ...(escalating !== undefined ? { escalation: escalating } : {}),
550
- label,
551
- model: judgeModel,
552
- onDelta: options.onDelta,
553
- });
554
- const reason = verdict.reason.split("\n")[0].slice(0, 160);
555
- record({ kind: "judge.verdict", culprit: verdict.culprit, round: rounds, reason: firstLine(verdict.reason, 300) });
556
- // Stopped by the time limit while it was still getting on: no agent can give it more time. The pulse stops now -
557
- // rolled back, no retry - and the person is told how to raise the limit.
558
- if (verdict.culprit === "environment" && recheck.timedOut === true) {
559
- stage(`the conformance run needs more than the ${Math.round(recheck.timeoutMs / 1000)}s a test run may take - stopping`);
560
- if (start !== undefined)
561
- abandonWork(start, moduleName, "the conformance testing script needs more time than a test run may take");
562
- throw timeLimitError(recheck, { moduleName, script: scripts.conformance, kind: "conformance", reason: verdict.reason });
563
- }
564
- // The environment - what the run is given - or the testing script itself is the person's to fix: once judged so
565
- // twice in a row, the pulse stops - rolled back, no retry - and the person is told what to fix.
566
- if (verdict.culprit === "environment" || verdict.culprit === "script") {
567
- const culprit = verdict.culprit;
568
- const what = culprit === "script" ? "the conformance testing script itself" : "the run's environment";
569
- environmentRaises += 1;
570
- reportActivity(` ${what} (judged ${environmentRaises} of ${ENVIRONMENT_RAISES} in a row): ${reason}`);
571
- if (environmentRaises >= ENVIRONMENT_RAISES) {
572
- stage(`${what} is what is wrong, and only the person can fix it - stopping`);
573
- if (start !== undefined)
574
- abandonWork(start, moduleName, `${what} is what is wrong`);
575
- throw culprit === "script"
576
- ? scriptFaultError("script", { moduleName, script: scripts.conformance, kind: "conformance", reason: `judged so ${environmentRaises} times in a row: ${verdict.reason}` })
577
- : runEnvironmentError({ moduleName, script: scripts.conformance, reason: verdict.reason, times: environmentRaises });
578
- }
579
- stage(`${what} is judged wrong (${environmentRaises} of ${ENVIRONMENT_RAISES}) - the conformance agent checks the tests do not cause it`);
580
- const fixed = await changing(() => askConformance(environmentCheckPrompt({ run: recheck, reason: verdict.reason, culprit }), options.onDelta));
581
- response = fixed.result;
582
- recordAttempt(rounds, recheck, `${what}: ${verdict.reason}`, { who: "conformance agent", files: fixed.files });
583
- continue;
584
- }
585
- environmentRaises = 0;
586
- // A spec conflict has counting of its own; code or tests the same way, again and again, is nothing changing.
587
- if (verdict.culprit !== "spec") {
588
- const moved = await unmoved();
589
- if (moved === "stuck")
590
- break;
591
- if (moved === "asked")
592
- continue;
593
- }
594
- if (verdict.culprit === "spec") {
595
- // Counted per pair of functionalities: it stops the run only when the same two are named often enough.
596
- const pair = sortedRefs(verdict.functionalities);
597
- const key = conflictKey(pair);
598
- const said = [...(conflicts.get(key) ?? []), verdict.reason.trim()];
599
- conflicts.set(key, said);
600
- const raised = said.length;
601
- reportActivity(` the spec, functionalities ${key} (raised ${raised} of ${SPEC_CONFLICT_RAISES}): ${reason}`);
602
- if (raised >= SPEC_CONFLICT_RAISES) {
603
- stage(`the spec contradicts itself: functionalities ${key} cannot both hold - stopping`);
604
- specConflict = { functionalities: pair, reason: verdict.reason };
605
- // For the person, whole: both functional specs as their modules have them, and every time it was raised.
606
- const ownSpecs = specifications[FUNCTIONAL_REQUIREMENTS];
607
- const files = plainFilesOf(options.plainFile, templateDirs);
608
- reportSpecConflict({
609
- moduleName,
610
- plainFile: options.plainFile,
611
- specs: pair.map((ref) => ({
612
- ...ref,
613
- plainFile: files.get(ref.module) ?? options.plainFile,
614
- text: ref.module === moduleName
615
- ? (ownSpecs[funcIds.indexOf(ref.funcId)] ?? "")
616
- : (required.find((spec) => spec.module === ref.module && spec.funcId === ref.funcId)?.spec ?? ""),
617
- })),
618
- reasons: said,
619
- });
620
- recordNote(conformanceDir, "pitfalls", `functionalities ${key} of the spec conflict: ${verdict.reason.replace(/\s+/g, " ").slice(0, 300)}`, `${label} conformance`);
621
- break;
622
- }
623
- // Recorded, and the round still changes something: the tests are looked at again, so the
624
- // next judgement is of a new run rather than the same one asked about again.
625
- stage(`a spec conflict between functionalities ${key} is recorded (${raised} of ${SPEC_CONFLICT_RAISES}) - the conformance agent looks at the tests again`);
626
- const fixed = await changing(() => ask(executor, testsFixPrompt({
627
- run: recheck,
628
- reason: `Functionalities ${key} of the specification may conflict: ${verdict.reason}\n\n` +
629
- "Before that is taken as the answer, check the tests of both against the specification once more: " +
630
- "that each asserts only what its functionality says, and sets up what it needs without undoing what the other relies on.",
631
- }), options.onDelta));
632
- response = fixed.result;
633
- recordAttempt(rounds, recheck, `a spec conflict between functionalities ${key}: ${verdict.reason}`, { who: "conformance agent", files: fixed.files });
634
- }
635
- else if (verdict.culprit === "code") {
636
- if (escalating !== undefined) {
637
- // Escalated: the coding agent is handed the script's error, the tests as they stand and the judge's evidence.
638
- // Its fix is the last attempt at this failure - should the run fail the same way after it, the run stops.
639
- const evidence = verdict.evidence ?? [];
640
- reportActivity(` escalated to the code: ${reason}`);
641
- stage("the judge finds the failure the code's - escalated to the coding agent");
642
- const tests = listFiles(conformanceDir).map((path) => ({ path, content: readFileSync(join(conformanceDir, path), "utf8") }));
643
- const fixed = await changing(() => askFixer(escalatedFixPrompt({ run: recheck, reason: verdict.reason, evidence, tests })));
644
- recordAttempt(rounds, recheck, `escalated to the code: ${verdict.reason}`, { who: "coding agent", files: fixed.files });
645
- if (fixed.files.length === 0) {
646
- escalation = { reason: verdict.reason, evidence, error: failureLine(recheck), failure: truncateOutput(recheck.output, undefined).slice(-4000), changedNothing: true };
647
- stage("the coding agent changed nothing for the failure escalated to it - stopping");
648
- break;
649
- }
650
- idleFixes = 0;
651
- escalated = { signature, reason: verdict.reason, evidence };
652
- }
653
- else {
654
- reportActivity(` the code: ${reason}`);
655
- stage("the code is wrong - the coding agent fixes it");
656
- // One fixer for the run, starting each fix from what the ones before it tried: its work is compacted as
657
- // it gets longer, so a session carried through the run does not re-read every earlier fix and suite output
658
- // whole.
659
- const fixed = await changing(() => askFixer(codeFixPrompt({ run: recheck, reason: verdict.reason })));
660
- recordAttempt(rounds, recheck, `the code wrong: ${verdict.reason}`, { who: "coding agent", files: fixed.files });
661
- if (idle(fixed.files))
662
- break;
663
- }
664
- // The fix has to build and pass its own unit tests before the suite runs again: a build
665
- // error is the coding agent's to fix, not a judge's to work out from the suite's output.
666
- for (let again = 0; again < FIX_UNIT_CHECKS; again += 1) {
667
- stage("checking the fix: the code's unit tests");
668
- const unit = await verifyUnitSuite(buildDir, unitRuns, scripts.unit);
669
- if (unit.ok)
670
- break;
671
- if (unit.missing !== undefined)
672
- throw toolchainError(unit.missing, { moduleName, script: scripts.unit, kind: "unit" });
673
- stage("the fix does not build or pass its unit tests - back to the coding agent");
674
- await changing(() => askFixer(`Your fix does not build or pass the code's unit tests - it has to before the conformance suite runs again.\n\n${unit.prompt}`));
675
- }
676
- }
677
- else {
678
- reportActivity(` the tests: ${reason}`);
679
- stage("the tests are wrong - the conformance agent fixes them");
680
- const fixed = await changing(() => askConformance(testsFixPrompt({ run: recheck, reason: verdict.reason }), options.onDelta));
681
- response = fixed.result;
682
- recordAttempt(rounds, recheck, `the tests wrong: ${verdict.reason}`, { who: "conformance agent", files: fixed.files });
683
- testsFix = { signature, reason: verdict.reason, files: fixed.files };
684
- // A fix that changed nothing does not stop the run before the judge has weighed escalating the failure.
685
- if (escalating === undefined)
686
- idleFixes = fixed.files.length === 0 ? idleFixes + 1 : 0;
687
- else if (idle(fixed.files))
688
- break;
689
- }
690
- continue;
691
- }
692
- stage(`conformance tests pass (attempt ${rounds})`);
693
- // Done is both: the conformance suite passing, and the unit tests with it - whether or not
694
- // the code looks changed. Conformance passing on code whose unit tests fail is not done.
695
- stage("running the unit testing script too");
696
- const unit = await verifyUnitSuite(buildDir, unitRuns, scripts.unit);
697
- if (!unit.ok && unit.missing !== undefined)
698
- throw toolchainError(unit.missing, { moduleName, script: scripts.unit, kind: "unit" });
699
- if (!unit.ok) {
700
- stage("unit tests NOT passing - the coding agent fixes the code");
701
- await askFixer(`The conformance tests pass, but the code's unit tests do not - and both have to.\n\n${unit.prompt}`);
702
- continue;
703
- }
704
- stage("unit tests pass too");
705
- green = { code: digestFiles(buildDir), tests: digestFiles(conformanceDir) };
706
- // The review gate: passing tests prove nothing when they assert nothing, mock the software, or leave out
707
- // what the spec asks for. It has to pass, as the suite and the unit tests do.
708
- const testChanges = diffFiles(testsAtStart, digestFiles(conformanceDir));
709
- const changedTests = [...testChanges.added, ...testChanges.changed];
710
- // After the last review's problems were worked on, the tests go on once they pass: not reviewed again. With
711
- // the review off in the config, they go on once they pass from the first.
712
- if (reviewOn && changedTests.length > 0 && failedReviews < REVIEW_LIMIT) {
713
- stage(`optimising the tests (review ${failedReviews + 1} of at most ${REVIEW_LIMIT}): black box, and every scenario carried out`);
714
- // One reviewer for the run, made the first time the tests are reviewed.
715
- reviewer ??= await createTestReviewer({
716
- ...(options.cases !== undefined ? { cases: options.cases } : {}),
717
- buildDir,
718
- conformanceDir,
719
- spec: specContext,
720
- functionalities: carriedOut,
721
- forChange,
722
- invocation,
723
- label,
724
- model: judgeModel,
725
- onDelta: options.onDelta,
726
- });
727
- const account = describeAccounts(work.take(), lastReview);
728
- const request = reviewSeen === undefined || lastReview === undefined
729
- ? testReviewRequest({ diff: workDiff(conformanceDir), changed: changedTests, account })
730
- : testReviewRequest({ diff: diffSinceSnapshot(conformanceDir, reviewSeen), changed: changedTests, account, earlier: lastReview, letGo: reviewLetGo });
731
- reviewSeen = workSnapshot(conformanceDir);
732
- reviewLetGo = [];
733
- const review = await reviewer.review(request);
734
- if (!review.pass) {
735
- failedReviews += 1;
736
- let problems = review.problems;
737
- const letGo = (why, waived) => {
738
- stage(why);
739
- reviewWaived = [...(reviewWaived ?? []), ...waived];
740
- lastReview = undefined;
741
- verified = true;
742
- };
743
- // After the first REVIEW_ROUNDS reviews that send them back, the arbiter weighs each: only what it upholds goes to the conformance agent.
744
- if (failedReviews > REVIEW_ROUNDS) {
745
- stage(`the review sent the tests back ${failedReviews === 1 ? "once" : `${failedReviews} times`} - the arbiter weighs what it found`);
746
- const ruling = await arbitrateReview({
747
- subject: `the conformance tests of ${forChange ? `the spec change in module \`${moduleName}\`` : `functional spec ${moduleName}:${funcId}`}`,
748
- workdir: conformanceDir,
749
- read: [conformanceDir, buildDir],
750
- uphold: [
751
- "- uphold it when because of it the functionality is not tested black box - a scenario's test",
752
- " the specification states missing, cut down or skipping what it checks, the software mocked or not reached",
753
- " from outside, a test that cannot fail. Then the reviewer is right, and the conformance agent fixes it.",
754
- ],
755
- changed: changedTests,
756
- spec: `<specification>\n${specContext.text.trim()}\n</specification>`,
757
- problems: review.problems,
758
- history: reviewHistory,
759
- label: `${label} conformance`,
760
- ...(judgeModel !== undefined ? { model: judgeModel } : {}),
761
- ...(options.onDelta !== undefined ? { onDelta: options.onDelta } : {}),
762
- });
763
- // No ruling: the review stands.
764
- if (ruling !== undefined) {
765
- if (ruling.dismissed.length > 0)
766
- recordNote(conformanceDir, "pitfalls", dismissedNote(ruling, "conformance test"), `${label} conformance`);
767
- if (ruling.upheld.length === 0) {
768
- letGo("the arbiter approved the tests as they are - what the review still raised is let go, and in the notes", ruling.dismissed.map((entry) => entry.problem));
769
- break;
770
- }
771
- reviewWaived = [...(reviewWaived ?? []), ...ruling.dismissed.map((entry) => entry.problem)];
772
- stage(`the arbiter upheld ${ruling.upheld.length} of the review's ${review.problems.length} problem${review.problems.length === 1 ? "" : "s"} - the conformance agent fixes ${ruling.upheld.length === 1 ? "it" : "those"}`);
773
- problems = ruling.upheld.map((entry) => entry.problem);
774
- reviewLetGo = ruling.dismissed.map((entry) => entry.problem);
775
- }
776
- }
777
- // An optimiser, not a gate: what the last review sends back goes to the conformance agent once more, and the
778
- // tests go on once the suite and the unit tests pass - they are not reviewed again.
779
- if (failedReviews >= REVIEW_LIMIT) {
780
- recordNote(conformanceDir, "pitfalls", `the conformance tests went on after ${REVIEW_LIMIT} reviews, the last one's problems worked on but not reviewed again: ${problems.map((problem) => `${problem.file}${problem.test ? ` ${problem.test}` : ""}: ${problem.what.trim()}`).join("; ").slice(0, 600)}`, `${label} conformance`);
781
- stage(`the last of ${REVIEW_LIMIT} reviews sends the tests back once more - after that they go on once they pass, without another review`);
782
- }
783
- reviewHistory.push(review.problems);
784
- lastReview = problems;
785
- const blocking = problems.filter((problem) => problem.blocking === true);
786
- reportActivity(` the review found ${problems.length} problem${problems.length === 1 ? "" : "s"}: ${problems[0].what.slice(0, 140)}`);
787
- stage(blocking.length > 0
788
- ? `the review found the functionality not yet tested black box (${blocking.length} of ${problems.length} problem${problems.length === 1 ? "" : "s"}) - the conformance agent completes the tests`
789
- : `the review found ${problems.length} way${problems.length === 1 ? "" : "s"} to improve the tests - the conformance agent improves them`);
790
- const pitfalls = readNotes(conformanceDir).pitfalls;
791
- const fixed = await changing(async () => {
792
- const answered = await askConformance(reviewFeedbackPrompt(problems), options.onDelta);
793
- // Every problem answered - fixed, or declined and why - so the reviewer knows what became of each: sent back once.
794
- const missing = unanswered(work.peek(), problems.length);
795
- return missing.length > 0 ? askConformance(unansweredPrompt(missing), options.onDelta) : answered;
796
- });
797
- // The lesson, left for the agents after it: the next functionality's conformance tests start from it.
798
- await reflectOnReview(conformanceDir, pitfalls, (prompt) => askConformance(prompt, options.onDelta));
799
- response = fixed.result;
800
- recordAttempt(rounds, "passed, but the review found " + problems.map((problem) => `${problem.kind} ${problem.file}: ${problem.what}`).join("; ").slice(0, 220), "the tests", { who: "conformance agent", files: fixed.files });
801
- continue;
802
- }
803
- stage("the review has nothing left to improve in the tests");
804
- }
805
- lastReview = undefined;
806
- verified = true;
807
- break;
808
- }
809
- // Notes are kept only with work that lands: work that does not is rolled back, notes and all.
810
- if (verified) {
811
- stage("checking the working notes were left");
812
- await notes.ensureWritten((next) => askConformance(next, options.onDelta, NOTES_TURN), passedOutcome("conformance testing script"));
813
- if (fixer !== undefined)
814
- await fixerNotes.ensureWritten((next) => ask(fixer, next, options.onDelta, NOTES_TURN), passedOutcome("conformance testing script"));
815
- }
816
- const changed = codeChanged();
817
- if (verified) {
818
- // The tests, and the code when it changed: one commit if they share a module folder.
819
- const subject = `conformance ${moduleName} ${options.diff !== undefined ? "for a spec change" : `fs ${funcId}`}${changed ? " (code changed)" : ""}`;
820
- stage(`committing the conformance tests${changed ? " and the code changes" : ""}`);
821
- landWork(conformanceDir, subject);
822
- if (moduleDirOf(buildDir) !== moduleDirOf(conformanceDir))
823
- landWork(buildDir, subject);
824
- }
825
- else if (start !== undefined) {
826
- const why = notLandedWhy(options.diff !== undefined ? "for the spec change" : `of functionality ${funcId}`, unlabelled);
827
- stage(`${why} - undoing them`);
828
- abandonWork(start, moduleName, why);
829
- }
830
- return {
831
- moduleName,
832
- funcId: funcId ?? "",
833
- buildDir,
834
- conformanceDir,
835
- prompt: agentPrompt,
836
- response,
837
- files: listFiles(conformanceDir),
838
- runs,
839
- passed: verified,
840
- rounds,
841
- codeChanged: changed,
842
- testRemovals,
843
- ...(specConflict !== undefined ? { specConflict } : {}),
844
- ...(stuck !== undefined ? { stuck } : {}),
845
- ...(escalation !== undefined ? { escalation } : {}),
846
- ...(unlabelled !== undefined ? { unlabelled } : {}),
847
- ...(reviewWaived !== undefined ? { reviewWaived } : {}),
848
- ...(verified && green !== undefined ? { green } : {}),
849
- ...(!verified && lastReview !== undefined ? { review: lastReview } : {}),
850
- };
851
- }
852
- finally {
853
- executor.dispose();
854
- fixer?.dispose();
855
- reviewer?.dispose();
856
- await fixerServices.stopAll();
857
- }
858
- }
859
- /**
860
- * Why conformance tests did not land, in a line. Tests sent back to be labelled and never labelled may well pass: the
861
- * line says so, rather than that they failed.
862
- */
863
- export function notLandedWhy(what, unlabelled) {
864
- if (unlabelled === undefined)
865
- return `the conformance tests ${what} do not pass`;
866
- return `the conformance tests ${what} were not written and labelled after ${LABEL_ASKS} requests - still missing: ${unlabelled.join("; ")} - whatever the test runs said`;
867
- }
868
- /** Each module of the chain, by name, and its .plain file - for a conflict that crosses modules. */
869
- function plainFilesOf(plainFile, templateDirs) {
870
- try {
871
- return new Map(resolveRequiresChain(plainFile, templateDirs).map((entry) => [entry.moduleName, entry.plainFile]));
872
- }
873
- catch {
874
- return new Map();
875
- }
876
- }
877
- /**
878
- * The functionalities with scenarios a spec change touches - by the job's cases, else those whose functional spec, or one of
879
- * whose scenarios, has a line the change adds or removes - with their scenarios: what a spec diff's
880
- * conformance run labels, checks and reviews, as a functionality's run does for its one.
881
- */
882
- export function touchedFunctionalities(tree, funcIds, diff, moduleName, cases) {
883
- const tested = (funcId) => {
884
- const spec = testedSpecOf(getSpecificationsForFrid(tree, funcId)[0], funcId);
885
- return spec.conformance.length + spec.acceptance.length > 0 ? spec : undefined;
886
- };
887
- // The job's cases say which: what it adds, changes or regenerates again - the modules' below first, in the chain's
888
- // order, as the tip's suite holds their tests too, then the module's own.
889
- if (cases !== undefined) {
890
- const own = (touched) => touched.module === undefined || touched.module === moduleName;
891
- const touched = [...cases.add, ...cases.patch, ...cases.again];
892
- const named = new Set(touched.filter(own).map((spec) => spec.funcId));
893
- const below = new Set(touched.filter((spec) => !own(spec)).map((spec) => `${spec.module}:${spec.funcId}`));
894
- const inherited = getInheritedFunctionalSpecs(tree)
895
- .filter((spec) => below.has(`${spec.module}:${spec.funcId}`) && spec.conformanceTests.length + spec.acceptanceTests.length > 0)
896
- .map((spec) => ({ funcId: spec.funcId, module: spec.module, conformance: spec.conformanceTests, acceptance: spec.acceptanceTests }));
897
- return [...inherited, ...funcIds.filter((funcId) => named.has(funcId)).flatMap((funcId) => tested(funcId) ?? [])];
898
- }
899
- // Else what the diff's lines touch: a functional spec's text, or one of its scenarios'.
900
- const bare = (line) => line.trim().replace(/^-\s+/, "").replace(/\s+/g, " ");
901
- const changed = new Set(diff
902
- .split("\n")
903
- .filter((line) => /^[+-]/.test(line) && !/^(\+\+\+|---)/.test(line))
904
- .map((line) => bare(line.slice(1)))
905
- .filter((line) => line.length > 12));
906
- return funcIds.flatMap((funcId) => {
907
- const spec = tested(funcId);
908
- if (spec === undefined)
909
- return [];
910
- const text = getSpecificationsForFrid(tree, funcId)[0][FUNCTIONAL_REQUIREMENTS].at(-1) ?? "";
911
- const lines = [text, ...spec.conformance.map((scenario) => scenario.text), ...spec.acceptance.map((scenario) => scenario.text)].flatMap((item) => item.split("\n")).map(bare);
912
- return lines.some((line) => changed.has(line)) ? [spec] : [];
913
- });
914
- }
915
- /** From the how-manieth review that sends the tests back the arbiter weighs each one (see arbiter.ts). */
916
- export const REVIEW_ROUNDS = ARBITER_AFTER;
917
- /** How many times the tests are sent back to be written and labelled before the run stops. */
918
- export const LABEL_ASKS = 3;
919
- /** How many times a code fix that does not build or pass its unit tests goes back to the coding agent before the suite runs again. */
920
- export const FIX_UNIT_CHECKS = 3;
921
- /** How many times an agent runs the conformance suite in a turn before its turn ends and the harness takes over. */
922
- export const RUNS_PER_TURN = 3;
923
- /**
924
- * A testing script tool an agent may call so many times a turn. The last allowed call ends its turn
925
- * with the result - the harness then runs the suite itself and judges what is wrong - so an agent
926
- * cannot spend its turn rerunning a failure it cannot fix. `newTurn` starts the count again.
927
- */
928
- export function turnLimited(tool, limit) {
929
- let calls = 0;
930
- const limited = {
931
- ...tool,
932
- execute: async (...args) => {
933
- calls += 1;
934
- if (calls > limit) {
935
- return {
936
- content: [{ type: "text", text: `Not run: that is ${limit} runs this turn. Your turn ends here - the harness runs the suite itself and works out what is wrong.` }],
937
- details: {},
938
- terminate: true,
939
- };
940
- }
941
- const result = (await tool.execute(...args));
942
- if (calls < limit)
943
- return result;
944
- return {
945
- ...result,
946
- content: [...result.content, { type: "text", text: `\n\nThat was your ${limit}rd run this turn: your turn ends here. The harness runs the suite itself, works out whether the code or the tests are wrong, and sends it to whichever it is.` }],
947
- terminate: true,
948
- };
949
- },
950
- };
951
- return { tool: limited, newTurn: () => void (calls = 0) };
952
- }
953
- export { failureSignature, STUCK_ROUNDS };
954
- /** How many fixes in a row that change no file - the code's or the tests' - is nothing changing. */
955
- export const IDLE_FIXES = 2;
956
- /** The build files a project's name, coordinates and version live in, by ecosystem. */
957
- const BUILD_MANIFESTS = [
958
- "pom.xml",
959
- "build.gradle",
960
- "build.gradle.kts",
961
- "settings.gradle",
962
- "settings.gradle.kts",
963
- "package.json",
964
- "pyproject.toml",
965
- "setup.py",
966
- "setup.cfg",
967
- "go.mod",
968
- "Cargo.toml",
969
- "composer.json",
970
- "Gemfile",
971
- "mix.exs",
972
- ];
973
- /**
974
- * The code's own build files, at the top of its folder, as they are - read by the harness, for the
975
- * author of the conformance tests, who cannot read the code. They are interface, not implementation:
976
- * what a separate test project has to point at - the name, the coordinates, the version.
977
- */
978
- export function buildManifests(buildDir) {
979
- return BUILD_MANIFESTS.filter((name) => existsSync(join(buildDir, name))).map((name) => {
980
- const content = readFileSync(join(buildDir, name), "utf8");
981
- return { path: name, content: content.length > 20_000 ? `${content.slice(0, 20_000)}\n… [${content.length - 20_000} more characters]` : content };
982
- });
983
- }
984
- /** What a failing run failed with, in one line as it said it: its first line that says what went wrong. */
985
- export function failureLine(run) {
986
- if (run.timedOut === true)
987
- return "the time limit - the run did not finish";
988
- const lines = run.output.split("\n").map((line) => line.trim()).filter((line) => line !== "");
989
- // The error itself - `AssertionError: …`, `ConnectException: …` - says more than a summary line: up to two, each once.
990
- const errors = [...new Set(lines.filter((line) => /\w(Error|Exception)\b[^\n]*:/.test(line)))];
991
- const telling = errors.length > 0 ? errors : lines.filter((line) => /error|exception|fail|refused|cannot|unable|not found|denied/i.test(line));
992
- const picked = telling.length > 0 ? telling.slice(0, 2) : [lines.at(-1) ?? `exit ${run.exitCode}`];
993
- return picked.map((line) => `"${line.length > 160 ? `${line.slice(0, 159)}…` : line}"`).join(" and ");
994
- }
995
- /**
996
- * The spec as the explorer, the judge and the coding agent are shown it - its functional specs
997
- * named by their func-ids, so a spec conflict can name them, and the scenarios the run carries
998
- * out labelled as their tests are, so a verdict can quote them.
999
- */
1000
- function specText(specifications, moduleName, funcIds, required, carriedOut, diff, modules) {
1001
- // Every functionality in the codebase, each with its module: the required modules' first, then this one's.
1002
- const numbered = (key, items) => key === FUNCTIONAL_REQUIREMENTS
1003
- ? [
1004
- functionalitiesByModule([...required, ...items.map((item, index) => ({ module: moduleName, funcId: funcIds[index] ?? String(index + 1), spec: item }))], moduleName),
1005
- ]
1006
- : items;
1007
- // Each section in its tag, as every agent is shown it (see specPrimer).
1008
- const sections = [DEFINITIONS, NON_FUNCTIONAL_REQUIREMENTS, TEST_REQUIREMENTS, FUNCTIONAL_REQUIREMENTS]
1009
- .map((key) => [key, specifications[key] ?? []])
1010
- .filter(([, items]) => items.length > 0)
1011
- .map(([key, items]) => (key === FUNCTIONAL_REQUIREMENTS ? section(key, numbered(key, items)) : moduleSection(key, items, moduleName, modules)));
1012
- // Not only the last functionality's: a spec change's run carries out the scenarios of every one it touches.
1013
- const scenarios = scenariosBlock(moduleName, carriedOut);
1014
- if (scenarios !== null)
1015
- sections.push(scenarios);
1016
- if (diff !== undefined)
1017
- sections.push(specChangeBlock(diff, true));
1018
- return sections.join("\n\n");
1019
- }
1020
- /** A functional spec's scenarios, as its specifications carry them: those its conformance tests carry out. */
1021
- function testedSpecOf(specifications, funcId) {
1022
- return { funcId, conformance: specifications[CONFORMANCE_TESTS] ?? [], acceptance: specifications[ACCEPTANCE_TESTS] ?? [] };
1023
- }
1024
- /**
1025
- * The functional spec a conformance run writes tests for, for the person watching: which one of how
1026
- * many, and its text as the spec has it, with its scenarios after it.
1027
- */
1028
- export function buildingSpec(moduleName, funcId, total, specifications) {
1029
- const kind = (name, scenarios) => (scenarios ?? []).length > 0 ? ["", `${name}:`, ...(scenarios ?? []).map((scenario) => `# ${scenario.id}\n${scenario.text.trim()}`)] : [];
1030
- return {
1031
- spec: { module: moduleName, funcId },
1032
- label: `${moduleName}:${funcId}, functional spec of ${total}`,
1033
- text: [(specifications["functional specs"].at(-1) ?? "").trim(), ...kind("conformance tests", specifications[CONFORMANCE_TESTS]), ...kind("acceptance tests", specifications[ACCEPTANCE_TESTS])].join("\n"),
1034
- };
1035
- }