@turri-dev/cli 0.4.3-next.7ada234 → 0.4.3-next.853c640

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 (538) hide show
  1. package/README.md +26 -4
  2. package/dist/banner.js +259 -0
  3. package/dist/capture-cli.js +50 -68
  4. package/dist/chat-commands.js +6 -6
  5. package/dist/chat-models.js +17 -15
  6. package/dist/chat-tab-header.js +0 -1
  7. package/dist/chat-tabs.js +1 -1
  8. package/dist/chat-terminal.js +114 -73
  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 +49 -55
  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 -3379
  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 -237
  23. package/dist/panel-view.js +409 -0
  24. package/dist/parse-cli.js +5 -2
  25. package/dist/pi-launch.js +37 -13
  26. package/dist/pi-themes.js +2 -2
  27. package/dist/plain-code-blocks.js +1 -1
  28. package/dist/print-mode.js +20 -0
  29. package/dist/quiet.js +7 -106
  30. package/dist/regenerate/diff-view.js +6 -87
  31. package/dist/regenerate/jobs-tree.js +2 -17
  32. package/dist/regenerate/spec-map-view.js +3 -68
  33. package/dist/regenerate-cli.js +7 -11
  34. package/dist/skill-progress.js +25 -0
  35. package/dist/skill-report.js +52 -0
  36. package/dist/terminal-marks.js +21 -0
  37. package/dist/terminal-notifications.js +74 -19
  38. package/dist/terminal-view.js +239 -0
  39. package/dist/turri-versions.js +64 -6
  40. package/docs/README.md +3 -3
  41. package/docs/capture.md +79 -180
  42. package/docs/chats.md +4 -4
  43. package/docs/claude-subscription.md +1 -1
  44. package/docs/config.md +7 -9
  45. package/docs/development.md +30 -64
  46. package/docs/headless.md +3 -1
  47. package/docs/hosting.md +3 -251
  48. package/docs/installation.md +5 -3
  49. package/docs/launch.md +1 -1
  50. package/docs/sentinel.md +3 -3
  51. package/docs/using.md +6 -6
  52. package/package.json +13 -31
  53. package/dist/ask.d.ts +0 -90
  54. package/dist/ask.js +0 -170
  55. package/dist/background-skills.d.ts +0 -56
  56. package/dist/background-skills.js +0 -129
  57. package/dist/bedrock-region.d.ts +0 -66
  58. package/dist/bedrock-region.js +0 -144
  59. package/dist/brand.d.ts +0 -13
  60. package/dist/btw.d.ts +0 -69
  61. package/dist/btw.js +0 -174
  62. package/dist/capture/agents.d.ts +0 -406
  63. package/dist/capture/agents.js +0 -379
  64. package/dist/capture/area.d.ts +0 -58
  65. package/dist/capture/area.js +0 -197
  66. package/dist/capture/assemble.d.ts +0 -112
  67. package/dist/capture/assemble.js +0 -453
  68. package/dist/capture/capture.d.ts +0 -116
  69. package/dist/capture/capture.js +0 -1315
  70. package/dist/capture/chat.d.ts +0 -29
  71. package/dist/capture/chat.js +0 -94
  72. package/dist/capture/checks.d.ts +0 -142
  73. package/dist/capture/checks.js +0 -649
  74. package/dist/capture/config.d.ts +0 -13
  75. package/dist/capture/config.js +0 -66
  76. package/dist/capture/interface.d.ts +0 -71
  77. package/dist/capture/interface.js +0 -199
  78. package/dist/capture/map.d.ts +0 -56
  79. package/dist/capture/map.js +0 -530
  80. package/dist/capture/models.d.ts +0 -4
  81. package/dist/capture/models.js +0 -16
  82. package/dist/capture/plan.d.ts +0 -7
  83. package/dist/capture/plan.js +0 -13
  84. package/dist/capture/progress.d.ts +0 -111
  85. package/dist/capture/progress.js +0 -266
  86. package/dist/capture/python-interface.d.ts +0 -3
  87. package/dist/capture/python-interface.js +0 -17
  88. package/dist/capture/report.d.ts +0 -75
  89. package/dist/capture/report.js +0 -268
  90. package/dist/capture/runners.d.ts +0 -6
  91. package/dist/capture/runners.js +0 -59
  92. package/dist/capture/scripts.d.ts +0 -26
  93. package/dist/capture/scripts.js +0 -38
  94. package/dist/capture/state.d.ts +0 -310
  95. package/dist/capture/state.js +0 -43
  96. package/dist/capture/trial.d.ts +0 -34
  97. package/dist/capture/trial.js +0 -89
  98. package/dist/capture-cli.d.ts +0 -1
  99. package/dist/chat-commands.d.ts +0 -17
  100. package/dist/chat-idle.d.ts +0 -7
  101. package/dist/chat-idle.js +0 -20
  102. package/dist/chat-models.d.ts +0 -22
  103. package/dist/chat-records.d.ts +0 -50
  104. package/dist/chat-records.js +0 -107
  105. package/dist/chat-scope.d.ts +0 -14
  106. package/dist/chat-scope.js +0 -15
  107. package/dist/chat-skills.d.ts +0 -17
  108. package/dist/chat-skills.js +0 -18
  109. package/dist/chat-tab-header.d.ts +0 -16
  110. package/dist/chat-tabs.d.ts +0 -26
  111. package/dist/chat-terminal.d.ts +0 -24
  112. package/dist/chat-ui.d.ts +0 -33
  113. package/dist/chat-waiting.d.ts +0 -67
  114. package/dist/chats.d.ts +0 -346
  115. package/dist/chats.js +0 -1022
  116. package/dist/cli-options.d.ts +0 -24
  117. package/dist/cli.d.ts +0 -9
  118. package/dist/config-edit.d.ts +0 -83
  119. package/dist/config-edit.js +0 -393
  120. package/dist/config.d.ts +0 -428
  121. package/dist/config.js +0 -816
  122. package/dist/conform-cli.d.ts +0 -1
  123. package/dist/conformance-switch.d.ts +0 -25
  124. package/dist/conformance-switch.js +0 -86
  125. package/dist/cultivate-cli.d.ts +0 -1
  126. package/dist/doctor-tool.d.ts +0 -11
  127. package/dist/doctor-tool.js +0 -33
  128. package/dist/drift-cli.d.ts +0 -1
  129. package/dist/environment.d.ts +0 -37
  130. package/dist/environment.js +0 -109
  131. package/dist/extension.d.ts +0 -209
  132. package/dist/genome.d.ts +0 -77
  133. package/dist/genome.js +0 -288
  134. package/dist/graph.d.ts +0 -52
  135. package/dist/graph.js +0 -247
  136. package/dist/host-session.d.ts +0 -112
  137. package/dist/host-session.js +0 -103
  138. package/dist/host.d.ts +0 -40
  139. package/dist/host.js +0 -54
  140. package/dist/identity.d.ts +0 -7
  141. package/dist/identity.js +0 -75
  142. package/dist/init-config.d.ts +0 -172
  143. package/dist/init-config.js +0 -867
  144. package/dist/installed-providers.d.ts +0 -40
  145. package/dist/installed-providers.js +0 -98
  146. package/dist/jellyfish.d.ts +0 -40
  147. package/dist/judge.d.ts +0 -25
  148. package/dist/judge.js +0 -62
  149. package/dist/launch-agent.d.ts +0 -62
  150. package/dist/launch-agent.js +0 -339
  151. package/dist/launch-cli.d.ts +0 -1
  152. package/dist/launch-session.d.ts +0 -68
  153. package/dist/launch-session.js +0 -225
  154. package/dist/launch-tools.d.ts +0 -28
  155. package/dist/launch-tools.js +0 -72
  156. package/dist/launch-track.d.ts +0 -175
  157. package/dist/launch-track.js +0 -497
  158. package/dist/lineage-cli.d.ts +0 -1
  159. package/dist/loop-cli.d.ts +0 -35
  160. package/dist/loop-tools.d.ts +0 -103
  161. package/dist/loop-tools.js +0 -361
  162. package/dist/model-check.d.ts +0 -72
  163. package/dist/model-check.js +0 -162
  164. package/dist/module-report.d.ts +0 -9
  165. package/dist/new-project.d.ts +0 -10
  166. package/dist/new-project.js +0 -42
  167. package/dist/notice.d.ts +0 -115
  168. package/dist/notice.js +0 -61
  169. package/dist/parse-cli.d.ts +0 -1
  170. package/dist/parse-tool.d.ts +0 -9
  171. package/dist/parse-tool.js +0 -33
  172. package/dist/pi-launch.d.ts +0 -1
  173. package/dist/pi-settings.d.ts +0 -4
  174. package/dist/pi-themes.d.ts +0 -3
  175. package/dist/pi.d.ts +0 -248
  176. package/dist/pi.js +0 -889
  177. package/dist/picture-row.d.ts +0 -10
  178. package/dist/plain/check.d.ts +0 -63
  179. package/dist/plain/check.js +0 -236
  180. package/dist/plain/concepts.d.ts +0 -37
  181. package/dist/plain/concepts.js +0 -283
  182. package/dist/plain/cycles.d.ts +0 -21
  183. package/dist/plain/cycles.js +0 -190
  184. package/dist/plain/errors.d.ts +0 -26
  185. package/dist/plain/errors.js +0 -50
  186. package/dist/plain/files.d.ts +0 -47
  187. package/dist/plain/files.js +0 -161
  188. package/dist/plain/graph.d.ts +0 -107
  189. package/dist/plain/graph.js +0 -194
  190. package/dist/plain/highlight.d.ts +0 -43
  191. package/dist/plain/highlight.js +0 -196
  192. package/dist/plain/index.d.ts +0 -18
  193. package/dist/plain/index.js +0 -18
  194. package/dist/plain/liquid.d.ts +0 -22
  195. package/dist/plain/liquid.js +0 -124
  196. package/dist/plain/markdown.d.ts +0 -103
  197. package/dist/plain/markdown.js +0 -330
  198. package/dist/plain/module-concepts.d.ts +0 -32
  199. package/dist/plain/module-concepts.js +0 -80
  200. package/dist/plain/parser.d.ts +0 -163
  201. package/dist/plain/parser.js +0 -930
  202. package/dist/plain/plain.tmLanguage.json +0 -150
  203. package/dist/plain/project.d.ts +0 -48
  204. package/dist/plain/project.js +0 -155
  205. package/dist/plain/spec.d.ts +0 -152
  206. package/dist/plain/spec.js +0 -265
  207. package/dist/plain/stdlib.d.ts +0 -16
  208. package/dist/plain/stdlib.js +0 -48
  209. package/dist/plain/test-plain-file.d.ts +0 -59
  210. package/dist/plain/test-plain-file.js +0 -232
  211. package/dist/plain-code-blocks.d.ts +0 -14
  212. package/dist/plain-files.d.ts +0 -21
  213. package/dist/plain-files.js +0 -156
  214. package/dist/pointer-hover.d.ts +0 -12
  215. package/dist/question-dialog.d.ts +0 -60
  216. package/dist/questioning.d.ts +0 -55
  217. package/dist/questioning.js +0 -109
  218. package/dist/quiet.d.ts +0 -34
  219. package/dist/regenerate/activity.d.ts +0 -227
  220. package/dist/regenerate/activity.js +0 -250
  221. package/dist/regenerate/agent-env.d.ts +0 -51
  222. package/dist/regenerate/agent-env.js +0 -315
  223. package/dist/regenerate/agent-shell.d.ts +0 -54
  224. package/dist/regenerate/agent-shell.js +0 -121
  225. package/dist/regenerate/arbiter.d.ts +0 -68
  226. package/dist/regenerate/arbiter.js +0 -133
  227. package/dist/regenerate/audit.d.ts +0 -69
  228. package/dist/regenerate/audit.js +0 -212
  229. package/dist/regenerate/base-folder.d.ts +0 -70
  230. package/dist/regenerate/base-folder.js +0 -186
  231. package/dist/regenerate/cases.d.ts +0 -12
  232. package/dist/regenerate/cases.js +0 -149
  233. package/dist/regenerate/change-view.d.ts +0 -23
  234. package/dist/regenerate/change-view.js +0 -153
  235. package/dist/regenerate/chunk-plan.d.ts +0 -217
  236. package/dist/regenerate/chunk-plan.js +0 -937
  237. package/dist/regenerate/codebase.d.ts +0 -21
  238. package/dist/regenerate/codebase.js +0 -75
  239. package/dist/regenerate/command-check.d.ts +0 -66
  240. package/dist/regenerate/command-check.js +0 -577
  241. package/dist/regenerate/compaction.d.ts +0 -13
  242. package/dist/regenerate/compaction.js +0 -20
  243. package/dist/regenerate/confine.d.ts +0 -69
  244. package/dist/regenerate/confine.js +0 -311
  245. package/dist/regenerate/conform.d.ts +0 -66
  246. package/dist/regenerate/conform.js +0 -132
  247. package/dist/regenerate/conformance-agents.d.ts +0 -388
  248. package/dist/regenerate/conformance-agents.js +0 -1162
  249. package/dist/regenerate/conformance.d.ts +0 -191
  250. package/dist/regenerate/conformance.js +0 -1035
  251. package/dist/regenerate/conversation-writes.d.ts +0 -10
  252. package/dist/regenerate/conversation-writes.js +0 -100
  253. package/dist/regenerate/credentials.d.ts +0 -18
  254. package/dist/regenerate/credentials.js +0 -88
  255. package/dist/regenerate/debug-log.d.ts +0 -56
  256. package/dist/regenerate/debug-log.js +0 -236
  257. package/dist/regenerate/debugger.d.ts +0 -36
  258. package/dist/regenerate/debugger.js +0 -133
  259. package/dist/regenerate/delivery.d.ts +0 -2
  260. package/dist/regenerate/diagnose-job.d.ts +0 -2
  261. package/dist/regenerate/diagnose-job.js +0 -40
  262. package/dist/regenerate/diagnose.d.ts +0 -46
  263. package/dist/regenerate/diagnose.js +0 -92
  264. package/dist/regenerate/diff-view.d.ts +0 -64
  265. package/dist/regenerate/drift.d.ts +0 -120
  266. package/dist/regenerate/drift.js +0 -285
  267. package/dist/regenerate/environment-error.d.ts +0 -167
  268. package/dist/regenerate/environment-error.js +0 -342
  269. package/dist/regenerate/failure-reports.d.ts +0 -28
  270. package/dist/regenerate/failure-reports.js +0 -79
  271. package/dist/regenerate/job-log.d.ts +0 -30
  272. package/dist/regenerate/job-log.js +0 -105
  273. package/dist/regenerate/job-panel.d.ts +0 -20
  274. package/dist/regenerate/job-panel.js +0 -54
  275. package/dist/regenerate/jobs-tree.d.ts +0 -76
  276. package/dist/regenerate/jobs.d.ts +0 -231
  277. package/dist/regenerate/jobs.js +0 -522
  278. package/dist/regenerate/lanes.d.ts +0 -16
  279. package/dist/regenerate/lanes.js +0 -32
  280. package/dist/regenerate/launch.d.ts +0 -256
  281. package/dist/regenerate/launch.js +0 -689
  282. package/dist/regenerate/ledger-view.d.ts +0 -87
  283. package/dist/regenerate/ledger-view.js +0 -325
  284. package/dist/regenerate/ledger.d.ts +0 -368
  285. package/dist/regenerate/ledger.js +0 -357
  286. package/dist/regenerate/lineage.d.ts +0 -105
  287. package/dist/regenerate/lineage.js +0 -485
  288. package/dist/regenerate/list-arguments.d.ts +0 -21
  289. package/dist/regenerate/list-arguments.js +0 -121
  290. package/dist/regenerate/loop.d.ts +0 -423
  291. package/dist/regenerate/loop.js +0 -2087
  292. package/dist/regenerate/masking.d.ts +0 -19
  293. package/dist/regenerate/masking.js +0 -95
  294. package/dist/regenerate/model-names.d.ts +0 -33
  295. package/dist/regenerate/model-names.js +0 -92
  296. package/dist/regenerate/notes.d.ts +0 -159
  297. package/dist/regenerate/notes.js +0 -446
  298. package/dist/regenerate/os-sandbox.d.ts +0 -93
  299. package/dist/regenerate/os-sandbox.js +0 -283
  300. package/dist/regenerate/panel-dock.d.ts +0 -23
  301. package/dist/regenerate/paths.d.ts +0 -110
  302. package/dist/regenerate/paths.js +0 -190
  303. package/dist/regenerate/plain-palette.d.ts +0 -34
  304. package/dist/regenerate/prompt.d.ts +0 -230
  305. package/dist/regenerate/prompt.js +0 -741
  306. package/dist/regenerate/pulse-files.d.ts +0 -14
  307. package/dist/regenerate/pulse-files.js +0 -63
  308. package/dist/regenerate/records.d.ts +0 -132
  309. package/dist/regenerate/records.js +0 -327
  310. package/dist/regenerate/regenerate.d.ts +0 -106
  311. package/dist/regenerate/regenerate.js +0 -660
  312. package/dist/regenerate/regression.d.ts +0 -58
  313. package/dist/regenerate/regression.js +0 -188
  314. package/dist/regenerate/renames.d.ts +0 -42
  315. package/dist/regenerate/renames.js +0 -185
  316. package/dist/regenerate/requires.d.ts +0 -117
  317. package/dist/regenerate/requires.js +0 -377
  318. package/dist/regenerate/resources.d.ts +0 -57
  319. package/dist/regenerate/resources.js +0 -162
  320. package/dist/regenerate/scripts-being-written.d.ts +0 -19
  321. package/dist/regenerate/scripts-being-written.js +0 -30
  322. package/dist/regenerate/self-check.d.ts +0 -29
  323. package/dist/regenerate/self-check.js +0 -119
  324. package/dist/regenerate/services.d.ts +0 -28
  325. package/dist/regenerate/services.js +0 -158
  326. package/dist/regenerate/shell.d.ts +0 -91
  327. package/dist/regenerate/shell.js +0 -320
  328. package/dist/regenerate/side-panel.d.ts +0 -64
  329. package/dist/regenerate/spec-map-view.d.ts +0 -147
  330. package/dist/regenerate/spec-map.d.ts +0 -160
  331. package/dist/regenerate/spec-map.js +0 -596
  332. package/dist/regenerate/spec-steps.d.ts +0 -180
  333. package/dist/regenerate/spec-steps.js +0 -729
  334. package/dist/regenerate/standing.d.ts +0 -28
  335. package/dist/regenerate/standing.js +0 -30
  336. package/dist/regenerate/state.d.ts +0 -21
  337. package/dist/regenerate/state.js +0 -10
  338. package/dist/regenerate/steering.d.ts +0 -56
  339. package/dist/regenerate/steering.js +0 -119
  340. package/dist/regenerate/stop-report.d.ts +0 -43
  341. package/dist/regenerate/stop-report.js +0 -160
  342. package/dist/regenerate/submit-work.d.ts +0 -44
  343. package/dist/regenerate/submit-work.js +0 -76
  344. package/dist/regenerate/test-kinds.d.ts +0 -85
  345. package/dist/regenerate/test-kinds.js +0 -171
  346. package/dist/regenerate/test-scripts.d.ts +0 -240
  347. package/dist/regenerate/test-scripts.js +0 -847
  348. package/dist/regenerate/testing-steps.d.ts +0 -52
  349. package/dist/regenerate/testing-steps.js +0 -129
  350. package/dist/regenerate/testing.d.ts +0 -150
  351. package/dist/regenerate/testing.js +0 -438
  352. package/dist/regenerate/transcript-view.d.ts +0 -21
  353. package/dist/regenerate/unit-gate.d.ts +0 -27
  354. package/dist/regenerate/unit-gate.js +0 -20
  355. package/dist/regenerate/unit-review.d.ts +0 -152
  356. package/dist/regenerate/unit-review.js +0 -361
  357. package/dist/regenerate/web.d.ts +0 -61
  358. package/dist/regenerate/web.js +0 -256
  359. package/dist/regenerate/workspace.d.ts +0 -12
  360. package/dist/regenerate/workspace.js +0 -99
  361. package/dist/regenerate-cli.d.ts +0 -1
  362. package/dist/reopen.d.ts +0 -29
  363. package/dist/reopen.js +0 -47
  364. package/dist/resume-line.d.ts +0 -5
  365. package/dist/review/live.d.ts +0 -72
  366. package/dist/review/live.js +0 -166
  367. package/dist/rules.d.ts +0 -20
  368. package/dist/rules.js +0 -47
  369. package/dist/run-report.d.ts +0 -88
  370. package/dist/run-report.js +0 -338
  371. package/dist/screen-padding.d.ts +0 -28
  372. package/dist/self-invocation.d.ts +0 -36
  373. package/dist/self-invocation.js +0 -137
  374. package/dist/sentinel-chat.d.ts +0 -19
  375. package/dist/sentinel-chat.js +0 -226
  376. package/dist/sentinel-check.d.ts +0 -36
  377. package/dist/sentinel-check.js +0 -78
  378. package/dist/sentinel.d.ts +0 -107
  379. package/dist/sentinel.js +0 -601
  380. package/dist/settings.d.ts +0 -45
  381. package/dist/settings.js +0 -378
  382. package/dist/setup.d.ts +0 -97
  383. package/dist/setup.js +0 -436
  384. package/dist/skill-progress.d.ts +0 -46
  385. package/dist/skill.d.ts +0 -102
  386. package/dist/skill.js +0 -147
  387. package/dist/skills.d.ts +0 -54
  388. package/dist/skills.js +0 -111
  389. package/dist/spawn-async.d.ts +0 -18
  390. package/dist/spawn-async.js +0 -35
  391. package/dist/stack.d.ts +0 -80
  392. package/dist/stack.js +0 -206
  393. package/dist/stdlib.d.ts +0 -43
  394. package/dist/stdlib.js +0 -118
  395. package/dist/surface.d.ts +0 -5
  396. package/dist/surface.js +0 -18
  397. package/dist/terminal-images.d.ts +0 -2
  398. package/dist/terminal-notifications.d.ts +0 -37
  399. package/dist/test-plain-files.d.ts +0 -41
  400. package/dist/test-plain-files.js +0 -172
  401. package/dist/tools.d.ts +0 -101
  402. package/dist/tools.js +0 -242
  403. package/dist/turri-versions.d.ts +0 -71
  404. package/genome/capture/capture.md +0 -26
  405. package/genome/capture/check-conventions.md +0 -5
  406. package/genome/capture/check-reference.md +0 -12
  407. package/genome/capture/compact.md +0 -7
  408. package/genome/capture/concepts.md +0 -3
  409. package/genome/capture/divide.md +0 -9
  410. package/genome/capture/feature.md +0 -45
  411. package/genome/capture/interface.md +0 -9
  412. package/genome/capture/modules.md +0 -25
  413. package/genome/capture/outline.md +0 -11
  414. package/genome/capture/python-interface.py +0 -111
  415. package/genome/capture/readability.md +0 -12
  416. package/genome/capture/reference.md +0 -10
  417. package/genome/capture/runners/python-requirements.sh +0 -67
  418. package/genome/capture/split.md +0 -9
  419. package/genome/capture/survey.md +0 -39
  420. package/genome/capture/trial.md +0 -18
  421. package/genome/capture/verify.md +0 -7
  422. package/genome/rules/bullet-continuation.md +0 -61
  423. package/genome/rules/concise-specs-examples.md +0 -460
  424. package/genome/rules/concise-specs-integration-examples.md +0 -281
  425. package/genome/rules/concise-specs.md +0 -80
  426. package/genome/rules/definitions.md +0 -107
  427. package/genome/rules/examples/integration-embedded-testing/run_conformance_tests_java.sh +0 -161
  428. package/genome/rules/examples/integration-embedded-testing/run_unittests_java.sh +0 -50
  429. package/genome/rules/exported-concepts.md +0 -39
  430. package/genome/rules/func-specs.md +0 -164
  431. package/genome/rules/impl-reqs.md +0 -68
  432. package/genome/rules/import-modules.md +0 -49
  433. package/genome/rules/integration-embedded-testing.md +0 -273
  434. package/genome/rules/integration-embedded.md +0 -171
  435. package/genome/rules/integration-standalone.md +0 -135
  436. package/genome/rules/integrations.md +0 -136
  437. package/genome/rules/linked-resources.md +0 -76
  438. package/genome/rules/module-structure.md +0 -112
  439. package/genome/rules/project-model.md +0 -69
  440. package/genome/rules/required-concepts.md +0 -44
  441. package/genome/rules/requires-modules.md +0 -81
  442. package/genome/rules/semantic-ids.md +0 -49
  443. package/genome/rules/stdlib.md +0 -37
  444. package/genome/rules/test-plain-files.md +0 -138
  445. package/genome/rules/test-reqs.md +0 -57
  446. package/genome/rules/turri-regeneration.md +0 -66
  447. package/genome/skills/analyze-2-func-specs/SKILL.md +0 -116
  448. package/genome/skills/analyze-func-specs/SKILL.md +0 -137
  449. package/genome/skills/break-down-func-spec/SKILL.md +0 -229
  450. package/genome/skills/consolidate-concepts/SKILL.md +0 -192
  451. package/genome/skills/convert-old-syntax/SKILL.md +0 -68
  452. package/genome/skills/convert-old-syntax/references/rubric.md +0 -11
  453. package/genome/skills/debug-specs/SKILL.md +0 -194
  454. package/genome/skills/implement-conformance-testing-script/SKILL.md +0 -247
  455. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_cypress.ps1 +0 -337
  456. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_golang.ps1 +0 -111
  457. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_java.sh +0 -151
  458. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_python.ps1 +0 -103
  459. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_python.sh +0 -146
  460. package/genome/skills/implement-unit-testing-script/SKILL.md +0 -171
  461. package/genome/skills/implement-unit-testing-script/assets/run_unittests_flutter.ps1 +0 -87
  462. package/genome/skills/implement-unit-testing-script/assets/run_unittests_golang.ps1 +0 -73
  463. package/genome/skills/implement-unit-testing-script/assets/run_unittests_java.sh +0 -82
  464. package/genome/skills/implement-unit-testing-script/assets/run_unittests_python.ps1 +0 -81
  465. package/genome/skills/implement-unit-testing-script/assets/run_unittests_python.sh +0 -102
  466. package/genome/skills/implement-unit-testing-script/assets/run_unittests_react.ps1 +0 -87
  467. package/genome/skills/refactor-module/SKILL.md +0 -218
  468. package/genome/skills/resolve-section-ownership/SKILL.md +0 -64
  469. package/genome/skills/resolve-spec-conflict/SKILL.md +0 -102
  470. package/stdlib/backend/common.plain +0 -25
  471. package/stdlib/backend/conformance/common.plain +0 -12
  472. package/stdlib/backend/conformance/go-gin.plain +0 -9
  473. package/stdlib/backend/conformance/go-nethttp.plain +0 -9
  474. package/stdlib/backend/conformance/java-springboot.plain +0 -9
  475. package/stdlib/backend/conformance/python-django.plain +0 -9
  476. package/stdlib/backend/conformance/python-fastapi.plain +0 -9
  477. package/stdlib/backend/conformance/python-flask.plain +0 -9
  478. package/stdlib/backend/conformance/rust-axum.plain +0 -9
  479. package/stdlib/backend/conformance/typescript-express.plain +0 -9
  480. package/stdlib/backend/conformance/typescript-fastify.plain +0 -9
  481. package/stdlib/backend/conformance/typescript-nestjs.plain +0 -9
  482. package/stdlib/backend/go-gin.plain +0 -18
  483. package/stdlib/backend/go-nethttp.plain +0 -18
  484. package/stdlib/backend/java-springboot.plain +0 -19
  485. package/stdlib/backend/python-django.plain +0 -19
  486. package/stdlib/backend/python-fastapi.plain +0 -23
  487. package/stdlib/backend/python-flask.plain +0 -23
  488. package/stdlib/backend/rust-axum.plain +0 -17
  489. package/stdlib/backend/typescript-express.plain +0 -19
  490. package/stdlib/backend/typescript-fastify.plain +0 -19
  491. package/stdlib/backend/typescript-nestjs.plain +0 -19
  492. package/stdlib/cli/common.plain +0 -17
  493. package/stdlib/cli/conformance/common.plain +0 -11
  494. package/stdlib/cli/conformance/go-cobra.plain +0 -9
  495. package/stdlib/cli/conformance/go-flag.plain +0 -9
  496. package/stdlib/cli/conformance/java-picocli.plain +0 -9
  497. package/stdlib/cli/conformance/python-argparse.plain +0 -9
  498. package/stdlib/cli/conformance/python-click.plain +0 -9
  499. package/stdlib/cli/conformance/python-typer.plain +0 -9
  500. package/stdlib/cli/conformance/rust-clap.plain +0 -9
  501. package/stdlib/cli/conformance/typescript-commander.plain +0 -9
  502. package/stdlib/cli/go-cobra.plain +0 -14
  503. package/stdlib/cli/go-flag.plain +0 -14
  504. package/stdlib/cli/java-picocli.plain +0 -15
  505. package/stdlib/cli/python-argparse.plain +0 -18
  506. package/stdlib/cli/python-click.plain +0 -16
  507. package/stdlib/cli/python-typer.plain +0 -16
  508. package/stdlib/cli/rust-clap.plain +0 -14
  509. package/stdlib/cli/typescript-commander.plain +0 -17
  510. package/stdlib/frontend/angular.plain +0 -17
  511. package/stdlib/frontend/common.plain +0 -17
  512. package/stdlib/frontend/conformance/angular.plain +0 -5
  513. package/stdlib/frontend/conformance/common.plain +0 -11
  514. package/stdlib/frontend/conformance/react-vite.plain +0 -5
  515. package/stdlib/frontend/conformance/sveltekit-spa.plain +0 -5
  516. package/stdlib/frontend/conformance/vue-vite.plain +0 -5
  517. package/stdlib/frontend/react-vite.plain +0 -16
  518. package/stdlib/frontend/sveltekit-spa.plain +0 -16
  519. package/stdlib/frontend/vue-vite.plain +0 -16
  520. package/stdlib/lang/go.plain +0 -13
  521. package/stdlib/lang/java.plain +0 -12
  522. package/stdlib/lang/python.plain +0 -18
  523. package/stdlib/lang/rust.plain +0 -12
  524. package/stdlib/lang/typescript.plain +0 -13
  525. package/stdlib/library/common.plain +0 -15
  526. package/stdlib/library/conformance/common.plain +0 -9
  527. package/stdlib/library/conformance/go.plain +0 -9
  528. package/stdlib/library/conformance/java-gradle.plain +0 -9
  529. package/stdlib/library/conformance/java-maven.plain +0 -9
  530. package/stdlib/library/conformance/python.plain +0 -9
  531. package/stdlib/library/conformance/rust.plain +0 -9
  532. package/stdlib/library/conformance/typescript.plain +0 -9
  533. package/stdlib/library/go.plain +0 -12
  534. package/stdlib/library/java-gradle.plain +0 -13
  535. package/stdlib/library/java-maven.plain +0 -13
  536. package/stdlib/library/python.plain +0 -13
  537. package/stdlib/library/rust.plain +0 -12
  538. package/stdlib/library/typescript.plain +0 -15
@@ -1,847 +0,0 @@
1
- import { fixMethod } from "./prompt.js";
2
- import { randomUUID } from "node:crypto";
3
- import { accessSync, constants, copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
4
- import { basename, delimiter, dirname, join, posix, relative, resolve, sep } from "node:path";
5
- import { CONFIG_FILE, CONFIG_KEYS, configModuleFor, configModuleOf, configModulePinned, moduleConfigFile, moduleConfigFileIn, moduleConfigsOf, projectConfigFile, readProjectConfig } from "../config.js";
6
- import { reportActivity, reportLogNote, reportNote } from "./activity.js";
7
- import { record, signatureHash } from "./ledger.js";
8
- import { ensureInModulesScratch, isWithin, modulesScratchDir, slashed } from "./paths.js";
9
- import { defineTool } from "@earendil-works/pi-coding-agent";
10
- import { Type } from "typebox";
11
- import { keepTestOutput, listFiles, shownTestOutput } from "./testing.js";
12
- import { digestFiles } from "./codebase.js";
13
- import { NOTES_FILE } from "./notes.js";
14
- import { COMMAND_TIMEOUT_MS, runCommand } from "./shell.js";
15
- /**
16
- * The scripts, with the conformance testing script set aside because conformance was turned
17
- * off: no conformance tests are written or run - not even those already in the codebase - and
18
- * no agent is shown it.
19
- */
20
- export function withoutConformance(scripts) {
21
- const { conformance: _ignored, prepare: _alsoIgnored, ...rest } = scripts;
22
- return { ...rest, conformanceOff: true };
23
- }
24
- /** The names the skills give each script. Only a file by one of these names is ever run. */
25
- const NAMES = {
26
- unit: /^run_unit_?tests[^/]*\.sh$/i,
27
- conformance: /^run_conformance_?tests[^/]*\.sh$/i,
28
- };
29
- export function scriptKind(name) {
30
- return Object.keys(NAMES).find((kind) => NAMES[kind].test(basename(name)));
31
- }
32
- /** The name the prepare script has: `prepare_environment_<lang>.sh`. */
33
- export const PREPARE_NAME = /^prepare_environment[^/]*\.sh$/i;
34
- function isFile(path) {
35
- try {
36
- return statSync(path).isFile();
37
- }
38
- catch {
39
- return false;
40
- }
41
- }
42
- /** The key in the project's config.turri.yaml that names each script. */
43
- const SCRIPT_KEYS = {
44
- unit: CONFIG_KEYS.unittestsScript,
45
- conformance: CONFIG_KEYS.conformanceTestsScript,
46
- };
47
- export const SCRIPTS_DIR = "test_scripts";
48
- /**
49
- * The project a build belongs to: the folder that holds its plain_modules. A build folder
50
- * elsewhere belongs to the folder of its spec.
51
- */
52
- export function projectRootFor(plainFile, buildDir) {
53
- const parts = resolve(buildDir).split(sep);
54
- const index = parts.lastIndexOf("plain_modules");
55
- return index > 0 ? parts.slice(0, index).join(sep) : dirname(resolve(plainFile));
56
- }
57
- /**
58
- * The one script of a kind in a folder, by the names the skills give them; two or more say which. What `claimed` holds -
59
- * the scripts other modules' own files name - is never one of them.
60
- */
61
- function onlyScriptIn(dir, kind, claimed = new Set()) {
62
- if (!existsSync(dir))
63
- return {};
64
- const candidates = readdirSync(dir)
65
- .filter((name) => (kind === "prepare" ? PREPARE_NAME.test(name) : scriptKind(name) === kind) && isFile(join(dir, name)) && !claimed.has(resolve(dir, name)))
66
- .sort();
67
- if (candidates.length === 1)
68
- return { path: join(dir, candidates[0]) };
69
- return candidates.length > 1 ? { several: candidates } : {};
70
- }
71
- /**
72
- * The project's testing scripts, looked for in this order:
73
- *
74
- * 1. `config.turri.yaml` at the project root, with the module's own `config.turri.<module>.yaml` over it - or the one of a
75
- * module it requires (`configModuleFor`) -
76
- * `unittests-script:` and `conformance-tests-script:`, paths from the root;
77
- * 2. the project root itself - the one `run_unittests*.sh` / `run_conformance_tests*.sh` there;
78
- * 3. `test_scripts/` - the one of each there.
79
- *
80
- * The prepare script - `prepare-environment-script:`, else the one `prepare_environment*.sh` - is looked for the same
81
- * way, and is optional: without one, the conformance testing script runs alone.
82
- *
83
- * A folder holding two of a kind does not say which is meant: it is skipped, and noted, so the
84
- * error that stops the build can say to name one in config.turri.yaml.
85
- *
86
- * Where modules have config files of their own and none applies to this one, a script one of those files names is that
87
- * module's - of its stack - and never found in a folder for this one: a frontend is not tested with the backend's script.
88
- */
89
- export function findTestScripts(root, plainFile, buildDir) {
90
- const found = {};
91
- const notes = {};
92
- // The module's own file over the project's - the one pinned, else the one of the module asked about: its scripts.
93
- const own = configModulePinned() ? configModuleOf(root) : plainFile !== undefined ? moduleOfSpec(plainFile) : undefined;
94
- const config = readProjectConfig(root, own);
95
- const file = own !== undefined ? `${moduleConfigFileIn(root, own)} (over ${projectConfigFile(root)})` : projectConfigFile(root);
96
- // Modules with files of their own, none of them this one's: its scripts are likely named in theirs.
97
- const others = own === undefined ? moduleConfigsOf(root) : [];
98
- // What their files name is theirs: never this module's, found in a folder.
99
- const claimed = new Set(others.flatMap((each) => {
100
- const theirs = readProjectConfig(root, each);
101
- return [theirs.unittestsScript, theirs.conformanceTestsScript, theirs.prepareEnvironmentScript].flatMap((named) => (named !== undefined ? [resolve(root, named.trim())] : []));
102
- }));
103
- // Where a script is named: the module's own file - or, where modules have their own, the one of the module that builds it.
104
- const nameIn = own !== undefined
105
- ? moduleConfigFileIn(root, own)
106
- : others.length > 0
107
- ? "the module's own config.turri.<module>.yaml"
108
- : `${CONFIG_FILE} - or the module's own config.turri.<module>.yaml`;
109
- if (config.testingScriptsRunOn !== undefined)
110
- found.runOn = config.testingScriptsRunOn;
111
- for (const kind of Object.keys(SCRIPT_KEYS)) {
112
- const named = kind === "unit" ? config.unittestsScript : config.conformanceTestsScript;
113
- if (named !== undefined) {
114
- const path = resolve(root, named.trim());
115
- // Agents write in plain_modules: a script there could be changed by the work it judges.
116
- if (path.split(sep).includes("plain_modules")) {
117
- notes[kind] = `${file} names ${named.trim()} as the ${SCRIPT_KEYS[kind]}, inside plain_modules - where agents write, so it is not used.`;
118
- }
119
- else if (isFile(path)) {
120
- found[kind] = path;
121
- continue;
122
- }
123
- else {
124
- notes[kind] = `${file} names ${named.trim()} as the ${SCRIPT_KEYS[kind]}, and there is no such file.`;
125
- }
126
- }
127
- for (const dir of [root, join(root, SCRIPTS_DIR)]) {
128
- const { path, several } = onlyScriptIn(dir, kind, claimed);
129
- if (path !== undefined) {
130
- found[kind] = path;
131
- break;
132
- }
133
- if (several !== undefined && notes[kind] === undefined) {
134
- notes[kind] = `${dir === root ? "The project root" : `${SCRIPTS_DIR}/`} holds ${several.join(", ")} - name the one to use in ${nameIn}.`;
135
- }
136
- }
137
- }
138
- // Optional: found the same way, and nothing is missing without it.
139
- const prepareNamed = config.prepareEnvironmentScript;
140
- const preparePath = prepareNamed !== undefined ? resolve(root, prepareNamed.trim()) : undefined;
141
- if (preparePath !== undefined && preparePath.split(sep).includes("plain_modules")) {
142
- notes.prepare = `${file} names ${prepareNamed.trim()} as the ${CONFIG_KEYS.prepareEnvironmentScript}, inside plain_modules - where agents write, so it is not used.`;
143
- }
144
- else if (preparePath !== undefined && isFile(preparePath)) {
145
- found.prepare = preparePath;
146
- }
147
- else {
148
- if (preparePath !== undefined)
149
- notes.prepare = `${file} names ${prepareNamed.trim()} as the ${CONFIG_KEYS.prepareEnvironmentScript}, and there is no such file.`;
150
- for (const dir of [root, join(root, SCRIPTS_DIR)]) {
151
- const { path, several } = onlyScriptIn(dir, "prepare", claimed);
152
- if (path !== undefined) {
153
- found.prepare = path;
154
- break;
155
- }
156
- if (several !== undefined && notes.prepare === undefined) {
157
- notes.prepare = `${dir === root ? "The project root" : `${SCRIPTS_DIR}/`} holds ${several.join(", ")} - name the one to use in ${nameIn}, as ${CONFIG_KEYS.prepareEnvironmentScript}:.`;
158
- }
159
- }
160
- }
161
- // Modules with files of their own, none of them this one's: the note says which name a script, and where its own goes.
162
- if (others.length > 0) {
163
- for (const kind of Object.keys(SCRIPT_KEYS)) {
164
- if (found[kind] !== undefined)
165
- continue;
166
- const named = others.flatMap((each) => {
167
- const script = kind === "unit" ? readProjectConfig(root, each).unittestsScript : readProjectConfig(root, each).conformanceTestsScript;
168
- return script !== undefined ? [`${moduleConfigFile(each)} names ${script.trim()}`] : [];
169
- });
170
- notes[kind] = [
171
- ...(notes[kind] !== undefined ? [notes[kind]] : []),
172
- `No module config file applies here, so ${CONFIG_FILE} alone is read - the modules' own are ${others.map(moduleConfigFile).join(", ")}${named.length > 0 ? `, and ${named.join("; ")}` : ""}. ` +
173
- "A module takes its own config.turri.<module>.yaml, else the one of a module it requires: name its scripts in its own file - in the chat, the settings tool with module.",
174
- ].join(" ");
175
- }
176
- }
177
- if (Object.keys(notes).length > 0)
178
- found.notes = notes;
179
- return found;
180
- }
181
- /**
182
- * The exit code a testing script ends with when the tests passed and only its static checks - the formatter in check
183
- * mode, the linter, the type checker - did not. Every other failure is the script's own exit code. The harness tells the
184
- * two apart: a unit run says it was the static checks, and a conformance run sends its tests' findings straight to the
185
- * conformance agent, with no judge asked whether the code or the tests are wrong.
186
- */
187
- export const STATIC_CHECKS_FAILED = 80;
188
- /** Whether a failed run of a testing script failed on its static checks alone: the tests passed. */
189
- export function staticChecksOnly(run) {
190
- return run.exitCode === STATIC_CHECKS_FAILED && run.timedOut !== true;
191
- }
192
- const SKILL = {
193
- unit: { skill: "implement-unit-testing-script", file: "run_unittests", what: "unit testing script" },
194
- conformance: { skill: "implement-conformance-testing-script", file: "run_conformance_tests", what: "conformance testing script" },
195
- };
196
- /** The skill that writes a testing script of a kind, and what the script is called in words. */
197
- export function testingScriptSkill(kind) {
198
- return { skill: SKILL[kind].skill, what: SKILL[kind].what };
199
- }
200
- /** The kind of testing script a skill writes, by its name - one that writes none, undefined. */
201
- export function scriptKindOfSkill(skill) {
202
- return Object.keys(SKILL).find((kind) => SKILL[kind].skill === skill);
203
- }
204
- /** Raised before a build starts when the script that would decide it is done is missing. */
205
- export class MissingTestScriptError extends Error {
206
- // Declared fields, not parameter properties: node's own type stripping cannot run those.
207
- moduleName;
208
- kind;
209
- constructor(moduleName, kind, note) {
210
- const { skill, file, what } = SKILL[kind];
211
- super([
212
- `Stopped before building ${moduleName}: it has no ${what}, so nothing can decide when its ${kind === "unit" ? "unit" : "conformance"} tests pass.`,
213
- ...(note !== undefined ? ["", note] : []),
214
- "",
215
- "What to change in the project:",
216
- `- Add one with the \`${skill}\` skill: it writes \`${SCRIPTS_DIR}/${file}_<language>.sh\`.`,
217
- `- It is looked for in \`${CONFIG_FILE}\` at the project root (\`${SCRIPT_KEYS[kind]}: <path>\`) - or the module's own`,
218
- ` \`config.turri.<module>.yaml\` beside it, or the one of a module it requires - then in the root,`,
219
- ` then in \`${SCRIPTS_DIR}/\` - one ${file}*.sh in either folder is used.`,
220
- "",
221
- "Then build again.",
222
- ].join("\n"));
223
- this.name = "MissingTestScriptError";
224
- this.moduleName = moduleName;
225
- this.kind = kind;
226
- }
227
- }
228
- /** The scripts a build needs, or the error that stops it before it starts. */
229
- export function requireTestScripts(moduleName, scripts, needs) {
230
- if (scripts.unit === undefined)
231
- throw new MissingTestScriptError(moduleName, "unit", scripts.notes?.unit);
232
- if (needs.conformance && scripts.conformance === undefined) {
233
- throw new MissingTestScriptError(moduleName, "conformance", scripts.notes?.conformance);
234
- }
235
- }
236
- /**
237
- * The scripts that decide an agent's work, in its prompt - only those that will be run on it: a
238
- * conformance testing script an agent's work is never judged by is left out. The whole script,
239
- * read from the project as it is now.
240
- */
241
- export function withTestingScripts(prompt, scripts, kinds, root) {
242
- const used = kinds.filter((kind) => scripts[kind] !== undefined);
243
- if (used.length === 0)
244
- return prompt;
245
- const named = (path) => (path.startsWith(`${root}${sep}`) ? path.slice(root.length + 1) : basename(path));
246
- const script = (kind, path) => `<script kind="${kind}" path="${named(path)}">\n${readFileSync(path, "utf8").trimEnd()}\n</script>`;
247
- // The prepare script runs before the conformance testing script: shown with it, before it.
248
- const prepare = used.includes("conformance") ? scripts.prepare : undefined;
249
- const rendered = used.flatMap((kind) => [
250
- ...(kind === "conformance" && prepare !== undefined ? [script("prepare environment", prepare)] : []),
251
- script(kind === "unit" ? "unit tests" : "conformance tests", scripts[kind]),
252
- ]);
253
- const tools = used.map((kind) => (kind === "unit" ? "run_unit_tests" : "run_conformance_tests")).join(" and ");
254
- const inPlace = (scripts.runOn ?? readProjectConfig(root).testingScriptsRunOn) !== "copy";
255
- return [
256
- "<testing scripts>",
257
- rendered.join("\n\n"),
258
- "</testing scripts>",
259
- "",
260
- `The harness decides whether your work is done by running ${used.length === 1 ? "this script" : "these scripts"} itself, ` +
261
- (inPlace
262
- ? "on this machine, in place, against the host codebase it merges your code into: "
263
- : "on this machine, on a fresh copy of your work: ") +
264
- used
265
- .map((kind) => kind === "unit"
266
- ? "the unit testing script as `<script> <build folder>`"
267
- : `${prepare !== undefined ? "the prepare script as `<script> <build folder>` and, once it passes, " : ""}the conformance testing script as \`<script> <build folder> <whole conformance suite folder>\``)
268
- .join(", ") +
269
- ". Make the tests pass the way the script runs them.",
270
- `A testing script may run static checks before its tests - the formatter in check mode, the linter, the type checker, ` +
271
- `on what it tests: the code for the unit testing script, the tests for the conformance one. They count as the tests ` +
272
- `do, and exit ${STATIC_CHECKS_FAILED} means the tests passed and only the checks did not. Formatting is yours: run the ` +
273
- "formatter the script checks with on the files you change, in your shell, before the final run.",
274
- `${used.length === 1 ? "It is" : "They are"} shown so you know what runs your tests - not to be run by you. ${used.length === 1 ? "It is" : "They are"} not in your ` +
275
- `workspace, and the path above is the project's, not one you can reach. Never copy, recreate or adapt ${used.length === 1 ? "it" : "them"} in the ` +
276
- `codebase, and never write a test runner of your own: call ${tools}, which run ${used.length === 1 ? "it" : "them"} exactly as the harness does - ` +
277
- "that run is the one that counts. Run a single test or file with bash while you work, as you like.",
278
- "They run in the person's own environment, with this machine's toolchains - the ones your shell has too. A toolchain " +
279
- "or system library the script needs and this machine lacks is not yours to install: say what is missing, and the " +
280
- "person installs it. What the code needs to be built and run belongs in the code (its dependency manifest), so " +
281
- `${inPlace ? "it builds where the script puts it" : "a fresh copy of it builds"}.`,
282
- "",
283
- prompt,
284
- ].join("\n");
285
- }
286
- /**
287
- * Where one script run is staged - in the project's scratch, and new for every run: the scripts
288
- * work in /tmp/<lang>_<basename of the build>, so the build is named for the module and this run
289
- * too, and no two runs - two modules testing at once - share that folder.
290
- */
291
- function stagingFor(buildDir) {
292
- const key = randomUUID().slice(0, 12);
293
- const root = join(modulesScratchDir(buildDir), "scripts", key);
294
- return { root, build: join(root, `${basename(dirname(resolve(buildDir)))}-${key}`), tests: join(root, "tests") };
295
- }
296
- /** The code, copied for a run; how many files. */
297
- function stageBuild(buildDir, target) {
298
- // There even when the build is empty: the scripts cd into it.
299
- mkdirSync(target, { recursive: true });
300
- const files = listFiles(buildDir);
301
- for (const file of files) {
302
- mkdirSync(dirname(join(target, file)), { recursive: true });
303
- copyFileSync(join(buildDir, file), join(target, file));
304
- }
305
- return files.length;
306
- }
307
- /** Every functionality's tests in one folder. A name already taken is renamed, never overwritten. */
308
- function stageTests(testsDirs, target) {
309
- mkdirSync(target, { recursive: true });
310
- const taken = new Set();
311
- testsDirs.forEach((dir, index) => {
312
- if (!existsSync(dir))
313
- return;
314
- for (const file of listFiles(dir)) {
315
- let name = file;
316
- if (taken.has(name)) {
317
- const renamed = `${index + 1}_${basename(file)}`;
318
- name = posix.dirname(file) === "." ? renamed : posix.join(posix.dirname(file), renamed);
319
- }
320
- taken.add(name);
321
- mkdirSync(dirname(join(target, name)), { recursive: true });
322
- copyFileSync(join(dir, file), join(target, name));
323
- }
324
- });
325
- return taken.size;
326
- }
327
- /** What the project calls a script: its path from the spec's folder when it is under it. */
328
- function shown(script) {
329
- const parent = dirname(dirname(script));
330
- return isWithin(script, parent) ? relative(parent, script) : basename(script);
331
- }
332
- /** How long a test run may take: the command time limit. Over it, the run counts as failed. */
333
- let scriptTimeoutMs = COMMAND_TIMEOUT_MS;
334
- /** For tests: a shorter limit than two minutes. */
335
- export function setScriptTimeoutForTests(ms) {
336
- scriptTimeoutMs = ms ?? COMMAND_TIMEOUT_MS;
337
- }
338
- /**
339
- * The project a build belongs to - the folder above its `plain_modules`, where the testing scripts'
340
- * own paths start - and whether they run on the code in place (the default), rather than on a fresh copy
341
- * (`testing-scripts-run-on: copy`).
342
- */
343
- /** Whether the testing scripts run on the code in `buildDir` itself, not on a copy of it. */
344
- export function scriptsRunInPlace(buildDir) {
345
- return projectOfBuild(buildDir).inPlace;
346
- }
347
- function projectOfBuild(buildDir) {
348
- const parts = resolve(buildDir).split(sep);
349
- const index = parts.lastIndexOf("plain_modules");
350
- const root = index > 0 ? parts.slice(0, index).join(sep) : dirname(resolve(buildDir));
351
- // The module's own file decides, when it says.
352
- return { root, inPlace: readProjectConfig(root, configModuleOf(root)).testingScriptsRunOn !== "copy" };
353
- }
354
- /** The model providers' keys, kept out of what runs on this machine: the tests are agents' code. */
355
- const PROVIDER_KEY = /^(ANTHROPIC|OPENAI|AZURE_OPENAI|GEMINI|GOOGLE|GOOGLE_GENERATIVE_AI|MISTRAL|GROQ|XAI|OPENROUTER|DEEPSEEK|CEREBRAS|TOGETHER|FIREWORKS)_API_KEY$|^AWS_BEARER_TOKEN_BEDROCK$/;
356
- /** The environment a testing script runs in: the person's own, but for turri's model providers' keys. */
357
- function scriptEnv() {
358
- return Object.fromEntries(Object.entries(process.env).filter(([key]) => !PROVIDER_KEY.test(key)));
359
- }
360
- /**
361
- * A testing script run on this machine - `bash <script> <args>` from `cwd`, through the host runner: a process group of
362
- * its own, so the time limit and a stopped job end it and all it started. `named`: the path the script names itself by
363
- * in its output, shown as the project's script.
364
- */
365
- async function runScript(cwd, script, args, logDir, options = {}) {
366
- const timeoutMs = options.limitMs ?? scriptTimeoutMs;
367
- const started = Date.now();
368
- // Where and how it runs, for the log: how it ended is what the activity says.
369
- reportLogNote(` ▶ ${shown(script)} on this machine, ${options.named !== undefined ? "on a fresh copy of the code" : `in place, from ${cwd}`} (limit ${Math.round(timeoutMs / 1000)}s)`);
370
- const { exitCode, output, timedOut } = await runCommand(scriptCommand(options.named ?? script, args), {
371
- cwd,
372
- env: scriptEnv(),
373
- timeoutMs,
374
- timeoutNote: (ms) => `\n[stopped after ${Math.round(ms / 1000)}s, the time limit for a test run: counted as failed]`,
375
- });
376
- const took = ((Date.now() - started) / 1000).toFixed(1);
377
- reportActivity(timedOut === true
378
- ? ` ✗ ${shown(script)} did not finish in ${Math.round(timeoutMs / 1000)}s - stopped, counted as failed`
379
- : ` ${exitCode === 0 ? "✓" : "✗"} ${shown(script)} exited ${exitCode} after ${took}s`);
380
- // The copy's path, where the script names itself, reads as the project's script.
381
- const text = options.named !== undefined ? output.split(options.named).join(shown(script)) : output;
382
- const noted = withScriptLineNote(text, script);
383
- // Its failures, counts and end are what the agent is shown; the whole is kept, a read_output away.
384
- const log = keepTestOutput(logDir, basename(script), noted);
385
- const run = {
386
- command: shown(script),
387
- exitCode: timedOut === true ? 124 : exitCode,
388
- output: shownTestOutput(noted, log),
389
- timedOut: timedOut === true,
390
- timeoutMs,
391
- elapsedMs: Date.now() - started,
392
- ...(log !== undefined ? { log } : {}),
393
- };
394
- record({
395
- kind: "script.run",
396
- script: basename(script),
397
- exit: run.exitCode,
398
- ms: run.elapsedMs,
399
- timedOut: run.timedOut === true,
400
- inPlace: options.named === undefined,
401
- // On code changed for the run - can_it_fail's bug: failing is what it is for.
402
- ...(options.mutated === true ? { mutated: true } : {}),
403
- ...(run.exitCode !== 0 ? { signature: signatureHash(failureSignature(run)) } : {}),
404
- });
405
- return run;
406
- }
407
- /** What bash says when a line of the script itself cannot run: a command or file that is not there, or not runnable. */
408
- const OWN_LINE_FAILURE = /: (No such file or directory|command not found|Permission denied)$/;
409
- /** The script lines already told to the person, by script, line and error - once each, in this process. */
410
- const toldScriptLines = new Set();
411
- /**
412
- * A run's output, with a note at its top when a line of the script itself fails where it runs - a macOS-only
413
- * `/usr/libexec/java_home` in a Linux sandbox. The agent is told it is the person's script, not its code, so it does not
414
- * go looking for what the line names; the person is told once, in the job's log.
415
- */
416
- function withScriptLineNote(output, script) {
417
- const name = basename(script);
418
- const prefix = new RegExp(`^(?:.*[/\\\\])?${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}: line (\\d+): (.+)$`);
419
- const failures = output
420
- .split("\n")
421
- .map((line) => prefix.exec(line))
422
- .filter((found) => found !== null && OWN_LINE_FAILURE.test(found[2]));
423
- if (failures.length === 0)
424
- return output;
425
- const notes = failures.map(([, line, error]) => {
426
- const key = `${script}\n${line}\n${error}`;
427
- if (!toldScriptLines.has(key)) {
428
- toldScriptLines.add(key);
429
- reportNote(` ⚠ line ${line} of ${name} fails where it runs - \`${error}\`: the script is yours to fix; the agents are told it is not theirs`);
430
- }
431
- return (`[turri: line ${line} of the project's testing script, ${name}, fails where it runs - \`${error}\`. That is the person's ` +
432
- "script, not your code: they have been told. Do not go looking for what it names; judge the run by what the tests " +
433
- "themselves report.]");
434
- });
435
- return `${[...new Set(notes)].join("\n")}\n\n${output}`;
436
- }
437
- /**
438
- * The command a testing script runs by: `bash <script> <args>`, every path quoted and written with `/`. On Windows bash is
439
- * Git Bash, whose tools may read a backslash as an escape - GNU tar reads the `\a` of `C:\Users\anton` as a bell - while
440
- * Windows and Git Bash both take `C:/Users/anton`.
441
- */
442
- export function scriptCommand(script, args) {
443
- return `bash ${[script, ...args].map((path) => quote(slashed(path))).join(" ")}`;
444
- }
445
- /** A path, quoted for bash. */
446
- function quote(path) {
447
- return `'${path.replace(/'/g, "'\\''")}'`;
448
- }
449
- /** A testing script run on a fresh copy of the code: the project's script copied fresh into the staging folder, beside it. */
450
- async function runOnCopy(stagingRoot, script, args, logDir, limitMs, mutated) {
451
- const copy = join(stagingRoot, basename(script));
452
- writeFileSync(copy, readFileSync(script));
453
- return runScript(stagingRoot, script, args, logDir, { named: copy, ...(limitMs !== undefined ? { limitMs } : {}), ...(mutated === true ? { mutated } : {}) });
454
- }
455
- /**
456
- * The harness's run of the unit testing script on the code as it is now - and run_unit_tests'.
457
- *
458
- * On this machine, on the code in place, or - `testing-scripts-run-on: copy` - on a fresh copy of the code
459
- * (see the top of this file). This and runConformanceScript are the only ways the testing
460
- * scripts are ever run.
461
- */
462
- export async function runUnitScript(buildDir, script) {
463
- return runOnCode(buildDir, script, "unit testing script");
464
- }
465
- /** How long the last passing run of a script on a codebase took, by codebase and script. */
466
- const lastPassing = new Map();
467
- /** How long the last passing run of `script` on the code in `buildDir` took, in this process - undefined before one has. */
468
- export function lastPassingMs(buildDir, script) {
469
- return lastPassing.get(`${resolve(buildDir)}\n${script}`);
470
- }
471
- /** Files changed in place for a run under way, and what each held: put back however the run ends - the process exiting too. */
472
- const changedInPlace = new Map();
473
- let restoreOnExit = false;
474
- function putBack(path) {
475
- const original = changedInPlace.get(path);
476
- if (original === undefined)
477
- return;
478
- writeFileSync(path, original);
479
- changedInPlace.delete(path);
480
- }
481
- /**
482
- * `run` with `change` made to the code itself, and undone once it ends - passed, failed, timed out, thrown, or the process
483
- * exiting. Killed outright, the change is left: the next unit of work starts from the last commit (lineage.ts startWork).
484
- */
485
- async function withChangeInPlace(buildDir, change, run) {
486
- const path = resolve(buildDir, change.file);
487
- if (changedInPlace.has(path))
488
- throw new Error(`${change.file} is being changed for another run already.`);
489
- if (!restoreOnExit) {
490
- restoreOnExit = true;
491
- process.once("exit", () => {
492
- for (const changed of [...changedInPlace.keys()])
493
- putBack(changed);
494
- });
495
- }
496
- changedInPlace.set(path, readFileSync(path));
497
- try {
498
- writeFileSync(path, change.text);
499
- return await run();
500
- }
501
- finally {
502
- putBack(path);
503
- }
504
- }
505
- /**
506
- * A script that takes the code folder - the unit testing script - run where the testing scripts run. `change`: one file
507
- * as it is for this run - made to the fresh copy, or, in place, to the code itself and undone once the run ends.
508
- */
509
- export async function runOnCode(buildDir, script, what, change,
510
- /** A time limit of its own, in place of a test run's. */
511
- limitMs) {
512
- const project = projectOfBuild(buildDir);
513
- const passed = (run, started) => {
514
- if (change === undefined && run.exitCode === 0)
515
- lastPassing.set(`${resolve(buildDir)}\n${script}`, Date.now() - started);
516
- return run;
517
- };
518
- if (project.inPlace) {
519
- const inPlace = () => runScript(project.root, script, [resolve(buildDir)], buildDir, { ...(limitMs !== undefined ? { limitMs } : {}), ...(change !== undefined ? { mutated: true } : {}) });
520
- const started = Date.now();
521
- if (change === undefined)
522
- return passed(await inPlace(), started);
523
- reportActivity(` changing ${change.file} in place for the ${what} - put back once it has run`);
524
- return withChangeInPlace(buildDir, change, inPlace);
525
- }
526
- const staging = stagingFor(buildDir);
527
- rmSync(staging.root, { recursive: true, force: true });
528
- ensureInModulesScratch(buildDir, staging.root);
529
- try {
530
- reportActivity(` copying ${stageBuild(buildDir, staging.build)} files of the code for the ${what}`);
531
- if (change !== undefined)
532
- writeFileSync(join(staging.build, change.file), change.text);
533
- const started = Date.now();
534
- return passed(await runOnCopy(staging.root, script, [staging.build], buildDir, limitMs, change !== undefined), started);
535
- }
536
- finally {
537
- rmSync(staging.root, { recursive: true, force: true });
538
- }
539
- }
540
- /**
541
- * The harness's run of the conformance testing script - and run_conformance_tests': the code, and
542
- * the codebase's whole conformance suite - every functionality's tests, and those carried up from
543
- * the modules below - in one folder, run at once. As runUnitScript runs: on a copy of the code staged beside the tests,
544
- * or in place.
545
- */
546
- export async function runConformanceScript(buildDir, testsDirs, scripts) {
547
- if (scripts.conformance === undefined)
548
- throw new Error("No conformance testing script to run.");
549
- const project = projectOfBuild(buildDir);
550
- const staging = stagingFor(buildDir);
551
- rmSync(staging.root, { recursive: true, force: true });
552
- ensureInModulesScratch(buildDir, staging.root);
553
- try {
554
- let build;
555
- let tests;
556
- if (project.inPlace) {
557
- // The real folders: the real tests folder when there is one; several merged into one, first.
558
- build = resolve(buildDir);
559
- if (testsDirs.length === 1)
560
- tests = resolve(testsDirs[0]);
561
- else {
562
- stageTests(testsDirs, staging.tests);
563
- tests = staging.tests;
564
- }
565
- }
566
- else {
567
- const code = stageBuild(buildDir, staging.build);
568
- const count = stageTests(testsDirs, staging.tests);
569
- reportActivity(` copying ${code} files of the code and the whole conformance suite (${count} files) for the conformance testing script`);
570
- const prepared = scripts.prepare !== undefined ? await runOnCopy(staging.root, scripts.prepare, [staging.build], buildDir) : undefined;
571
- if (prepared !== undefined && prepared.exitCode !== 0)
572
- return preparationFailed(prepared, scripts.conformance);
573
- return withPrepared(await runOnCopy(staging.root, scripts.conformance, [staging.build, staging.tests], buildDir), prepared);
574
- }
575
- // The environment first, on the same build the conformance tests get: the conformance testing script runs only once it passes.
576
- const prepared = scripts.prepare !== undefined ? await runScript(project.root, scripts.prepare, [build], buildDir) : undefined;
577
- if (prepared !== undefined && prepared.exitCode !== 0)
578
- return preparationFailed(prepared, scripts.conformance);
579
- return withPrepared(await runScript(project.root, scripts.conformance, [build, tests], buildDir), prepared);
580
- }
581
- finally {
582
- rmSync(staging.root, { recursive: true, force: true });
583
- }
584
- }
585
- /** A prepare script that failed: the run, said to be the preparation's - the conformance tests were not run. */
586
- function preparationFailed(prepared, conformance) {
587
- return {
588
- ...prepared,
589
- output: `${prepared.command} - the project's prepare script, run on the build before ${shown(conformance)} - exited ${prepared.exitCode}, so the conformance tests were not run.\n\n${prepared.output}`,
590
- };
591
- }
592
- /** A conformance run, with a line at its top saying the prepare script ran first and passed. */
593
- function withPrepared(run, prepared) {
594
- return prepared === undefined ? run : { ...run, output: `${prepared.command} prepared the build first, and passed.\n\n${run.output}` };
595
- }
596
- /**
597
- * `run_unit_tests` / `run_conformance_tests`: the agent's final check before it finishes - the
598
- * project's testing script, run exactly as the harness will run it to decide whether the work is
599
- * done. It takes no command. Everything else - one test, one file, another configuration, while
600
- * the agent works - is what bash is for.
601
- */
602
- export function createScriptTool(options) {
603
- const unit = options.kind === "unit";
604
- const name = unit ? "run_unit_tests" : "run_conformance_tests";
605
- const script = options.script !== undefined ? basename(options.script) : "the project's script";
606
- return defineTool({
607
- name,
608
- label: unit ? "Run unit tests" : "Run conformance tests",
609
- description: unit
610
- ? `Final check before you finish: run the project's unit testing script, ${script}, ` +
611
- "on the code as it is now - exactly as the harness runs it to decide whether this is done. It takes no command. To " +
612
- "run one test, one file, or the tests any other way while you work, use bash."
613
- : `Run the project's conformance testing script, ${script}, on a fresh copy of the code with the whole conformance ` +
614
- "suite - exactly as the harness runs it to decide whether this is done. It takes no command. Your shell holds " +
615
- "only the tests, not the code, so this is how you run them against the code: while you work, and as the final " +
616
- "check before you finish.",
617
- promptSnippet: `${name}: the final check - the project's ${unit ? "unit" : "conformance"} testing script, as the harness runs it`,
618
- parameters: Type.Object({}),
619
- async execute() {
620
- const run = await options.run();
621
- options.runs.push({ command: run.command, exitCode: run.exitCode });
622
- options.onRun?.(run.command, run.exitCode);
623
- const text = run.timedOut === true
624
- ? timedOutFailure(run, unit ? "unit testing" : "conformance testing").replace("The harness ran", "You ran")
625
- : `${run.command} exited ${run.exitCode}\n\n${run.output}`;
626
- const loop = options.watch?.see(run);
627
- return {
628
- content: [{ type: "text", text: loop === undefined ? text : `${text}\n\n${loopNotice(loop)}` }],
629
- details: { command: run.command, exitCode: run.exitCode, ...(loop !== undefined ? { loop } : {}) },
630
- // Going round in circles a second time: its turn ends here, and the harness takes it from there.
631
- ...(loop === "stop" ? { terminate: true } : {}),
632
- };
633
- },
634
- });
635
- }
636
- /** How many of the agent's own runs failing the same way, one after another, are a loop. */
637
- export const LOOP_RUNS = 6;
638
- export function createLoopWatch(dir) {
639
- /** The code folder at each failing run, as a digest of its files. */
640
- const failedStates = new Set();
641
- let strikes = 0;
642
- let stuck = false;
643
- let failing = 0;
644
- let last;
645
- let streak = 0;
646
- const stateOf = () => [...digestFiles(dir)]
647
- .filter(([file]) => file !== NOTES_FILE && !file.endsWith(`/${NOTES_FILE}`))
648
- .sort(([a], [b]) => a.localeCompare(b))
649
- .map(([file, digest]) => `${file} ${digest}`)
650
- .join("\n");
651
- return {
652
- see(run) {
653
- if (run.exitCode === 0 && run.timedOut !== true) {
654
- failedStates.clear();
655
- strikes = 0;
656
- stuck = false;
657
- failing = 0;
658
- last = undefined;
659
- streak = 0;
660
- return undefined;
661
- }
662
- failing += 1;
663
- const state = stateOf();
664
- const signature = failureSignature(run);
665
- streak = signature === last ? streak + 1 : 1;
666
- last = signature;
667
- const revisited = failedStates.has(state);
668
- failedStates.add(state);
669
- if (!revisited && streak < LOOP_RUNS)
670
- return undefined;
671
- streak = 0;
672
- strikes += 1;
673
- if (strikes === 1)
674
- return "warn";
675
- stuck = true;
676
- return "stop";
677
- },
678
- get stuck() {
679
- return stuck;
680
- },
681
- get failing() {
682
- return failing;
683
- },
684
- reset() {
685
- strikes = 0;
686
- stuck = false;
687
- streak = 0;
688
- last = undefined;
689
- },
690
- };
691
- }
692
- /** What the agent is told with a run when it is going round in circles. */
693
- function loopNotice(loop) {
694
- if (loop === "warn") {
695
- return [
696
- "You are going round in circles: the code is back exactly as it was at an earlier failing run, or the tests have",
697
- "failed the same way run after run. Another variation on what you have tried will not fix it. Stop editing and",
698
- "find the cause first: read the code under test where the failure points - how it calls what the test replaces,",
699
- "with which arguments - and the test, line by line, against it. Then make the one change that the cause calls for.",
700
- ].join("\n");
701
- }
702
- return [
703
- "You are still going round in circles, so your turn ends here. Change nothing more now: a debugger will look at",
704
- "the failure with fresh eyes, and you will be given what it finds.",
705
- ].join("\n");
706
- }
707
- /**
708
- * How long a run took against its time limit, in a line: for whoever judges it or works out its cause - so a run that
709
- * ended on its own is never taken for one the limit stopped, nor the other way.
710
- */
711
- export function runTiming(run) {
712
- const seconds = (ms) => `${(ms / 1000).toFixed(1)}s`;
713
- const limit = seconds(run.timeoutMs);
714
- if (run.timedOut === true) {
715
- return `The time limit stopped this run: it had run ${seconds(run.elapsedMs ?? run.timeoutMs)} of the ${limit} a test run may take, and had not finished.`;
716
- }
717
- const took = run.elapsedMs !== undefined ? `after ${seconds(run.elapsedMs)} of the ${limit} a test run may take` : `well within the ${limit} a test run may take`;
718
- return `This run ended on its own - exit ${run.exitCode}, ${took}. The time limit did not stop it and played no part in how it ended.`;
719
- }
720
- /** A run the time limit stopped: failed, and what most often keeps a test run from ending. */
721
- function timedOutFailure(run, what) {
722
- const limit = Math.round(run.timeoutMs / 1000);
723
- return [
724
- `The harness ran the project's ${what} script, \`${run.command}\`, and it had not finished after ${limit} seconds - the`,
725
- "time limit for a test run - so it was stopped, and counts as failed. This is what it had printed by then:",
726
- "",
727
- run.output.trimEnd(),
728
- "",
729
- "The output ends where it was stopped: the test running then, or the step after the last one it printed, is the one",
730
- "that does not finish. Most often a test waits for something that never comes:",
731
- "- a server or a watcher started in the foreground, instead of in the background and stopped afterwards;",
732
- "- a prompt waiting for input, or a command that pages its output;",
733
- "- a network call that never answers - a service on localhost that is not running, a host that is down;",
734
- "- a lock, a queue or a thread nothing releases, or a loop that never ends.",
735
- "Find it - run the tests on their own with bash, under `timeout`, a file or a case at a time - and fix what is wrong,",
736
- `in the test or in the code, against the specification. If the tests are only slow, make them faster: every run has`,
737
- `the same ${limit} seconds, and a skipped or deleted test does not count as a fix.`,
738
- ].join("\n");
739
- }
740
- /** A command `timeout` could not start, or a shell could not find - on a line of its own. */
741
- const COULD_NOT_RUN = /^(?:[^:]*: )?failed to run command [‘'`"]?([\w.+-]+)[’'`"]?: No such file or directory$/;
742
- const NOT_FOUND = /^(?:[^:]*: )?(?:line \d+: )?([\w.+-]+): command not found$/;
743
- /**
744
- * What a failed run says is not installed where it ran - the command, when its output names it - or undefined when
745
- * the run failed for another reason. A missing command is the cause only on evidence that it ended the run: exit 69,
746
- * the testing scripts' own way to say a toolchain is missing, or 127, what a shell or `timeout` gives for a command it
747
- * could not find - else a command not found on the last line the run printed, nothing having run after it. Earlier in
748
- * the output it is a warning, not the failure: a shell profile's, an optional tool probed for, a fallback taken - and a
749
- * run that failed for its own reasons is the agent's to fix, not a stop for the person.
750
- */
751
- export function missingToolchain(run) {
752
- if (run.exitCode === 0)
753
- return undefined;
754
- const lines = run.output.split("\n").map((line) => line.trim()).filter((line) => line !== "");
755
- const named = (line) => COULD_NOT_RUN.exec(line)?.[1] ?? NOT_FOUND.exec(line)?.[1];
756
- if (run.exitCode === 69 || run.exitCode === 127) {
757
- // The command is the last one named: the one the run stopped on.
758
- for (let at = lines.length - 1; at >= 0; at -= 1) {
759
- const command = named(lines[at]);
760
- if (command !== undefined)
761
- return { command };
762
- }
763
- return {};
764
- }
765
- const last = lines.at(-1);
766
- const command = last !== undefined ? named(last) : undefined;
767
- return command !== undefined ? { command } : undefined;
768
- }
769
- /** Where `command` is on this machine's PATH - `env`'s, by default turri's own - or undefined when it is not there. */
770
- export function onThisMachine(command, env = process.env) {
771
- for (const dir of (env.PATH ?? "").split(delimiter)) {
772
- if (dir === "")
773
- continue;
774
- const path = join(dir, command);
775
- try {
776
- accessSync(path, constants.X_OK);
777
- return path;
778
- }
779
- catch {
780
- /* not here */
781
- }
782
- }
783
- return undefined;
784
- }
785
- /** What a failed script run means, for the agent that has to fix it. */
786
- export function scriptFailure(run, what) {
787
- if (run.timedOut === true)
788
- return timedOutFailure(run, what);
789
- const missing = missingToolchain(run);
790
- const needs = missing?.command !== undefined ? `\`${missing.command}\`` : "the toolchain it needs";
791
- const cause = missing !== undefined
792
- ? `It could not run: ${needs} is not installed on this machine, where the testing scripts run. That is the person's ` +
793
- "to install, not yours: do not work around it, and do not change the code or the tests for it. Call " +
794
- "report_environment_error with exactly what is missing."
795
- : [
796
- ...fixMethod({
797
- what: what === "unit testing" ? "unit tests" : "conformance tests",
798
- fixes: what === "unit testing" ? "code" : "tests",
799
- runTool: what === "unit testing" ? "run_unit_tests" : "run_conformance_tests",
800
- }),
801
- ].join("\n");
802
- return [
803
- `The harness ran the project's ${what} script, \`${run.command}\`, and it failed (exit ${run.exitCode}).`,
804
- ...(missing === undefined && staticChecksOnly(run)
805
- ? [
806
- `Exit ${STATIC_CHECKS_FAILED}: the tests pass, and the script's static checks - the formatter, the linter, the type checker - ` +
807
- "do not. Fix each finding at its cause; never silence one (a type-ignore or lint-disable comment, a rule " +
808
- "turned off in the checker's configuration). A formatting finding goes by running the formatter.",
809
- ]
810
- : []),
811
- "",
812
- run.output.trimEnd(),
813
- "",
814
- cause,
815
- ].join("\n");
816
- }
817
- /** How many rounds running the same failure, taken the same way, is nothing changing. */
818
- export const STUCK_ROUNDS = 3;
819
- /**
820
- * A failing run, as a fingerprint: the lines that say what went wrong, without what changes from run
821
- * to run - numbers, times, paths, ids. Two runs failing the same way have the same one.
822
- */
823
- export function failureSignature(run) {
824
- if (run.timedOut === true)
825
- return "the run did not finish in the time limit";
826
- const lines = run.output.split("\n").map((line) => line.trim()).filter((line) => line !== "");
827
- const telling = lines.filter((line) => /error|exception|fail|refused|timed out|cannot|unable|not found|denied/i.test(line));
828
- const normal = (line) => line
829
- // Colour codes, and ids a service makes up for each response - a request's UUID, a correlation id in hex.
830
- .replace(/\x1B\[[0-9;]*m/g, "")
831
- .replace(/\/[^\s:'"]+/g, "<path>")
832
- .replace(/\b[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}\b/gi, "<id>")
833
- .replace(/\b(?=[0-9a-f]*\d)(?=[0-9a-f]*[a-f])[0-9a-f]{4,}\b/gi, "<id>")
834
- .replace(/\b[0-9a-f]{8,}\b/gi, "<id>")
835
- .replace(/\d+(\.\d+)?/g, "<n>")
836
- .replace(/\s+/g, " ");
837
- return [...new Set((telling.length > 0 ? telling : lines.slice(-20)).map(normal))].slice(0, 30).join("\n");
838
- }
839
- /** The module whose config file builds a module, for finding its scripts - none when it cannot be told: the parse says why. */
840
- function moduleOfSpec(plainFile) {
841
- try {
842
- return configModuleFor(plainFile);
843
- }
844
- catch {
845
- return undefined;
846
- }
847
- }