@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,1315 +0,0 @@
1
- import { existsSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
2
- import { join, relative, resolve } from "node:path";
3
- import { CONFIG_FILE, inheritModel, modelSpec, projectModels, readProjectConfig, roleModel, withConfigModule } from "../config.js";
4
- import { captureDefaults } from "./models.js";
5
- import { writeSetting } from "../config-edit.js";
6
- import { slashed } from "../regenerate/paths.js";
7
- import { findTestScripts, testingScriptSkill } from "../regenerate/test-scripts.js";
8
- import { checkPlainFile } from "../plain/check.js";
9
- import { conformanceOf, stdlibCatalogue, stdlibTemplates } from "../stdlib.js";
10
- import { AREAS_TOOL, askAgent, capturePrompt, watched, COMPACT_TOOL, CONCEPTS_TOOL, CONVENTIONS_TOOL, CORRECTIONS_TOOL, definitionsOf, EDITS_TOOL, FEATURE_TOOL, FEATURES_TOOL, INTERFACE_TOOL, leftOutOf, MODULES_TOOL, OWNERS_TOOL, records, REFERENCE_CHECKED_TOOL, REFERENCE_TOOL, strings, SURVEY_TOOL, text, TRIAL_TOOL } from "./agents.js";
11
- import { buildOrder, covers, entriesOf, filesOf, kebab, linesOf, renderArea, testEvidence } from "./area.js";
12
- import { entriesIn, entryFile, entrySurface, interfaceConcept, renderReference, interfaceDefinition, interfaceGaps, interfaceIn, leftOutPaths, namedExactly, namedIn, optionsNotInReference, referenceOf, shownSurface } from "./interface.js";
13
- import { assemble, featureKey, featurePaths, featuresOf, leavesOf, mergedInto, MODULE_SPECS, outlinedFeature, sharedName, writeCapture } from "./assemble.js";
14
- import { conventionProblems, correctionProblems, divisionProblems, moduleProblems, referenceProblems, editProblems, featureProblems, gapProblems, outlineProblems, reconciledProblems, scenarioBudget, splitProblems, surveyProblems, trialProblems, unplaced } from "./checks.js";
15
- import { buildMap, INTERFACE_KINDS } from "./map.js";
16
- import { CaptureTracker, findingLine } from "./progress.js";
17
- import { capturePlan } from "./plan.js";
18
- import { pythonInterface } from "./python-interface.js";
19
- import { configInUse, configInUseProblem, startingConfig } from "./config.js";
20
- import { renderReport, summaryOf } from "./report.js";
21
- import { writeTestingScript } from "./scripts.js";
22
- import { runnerChoices, reuseRunner } from "./runners.js";
23
- import { captureDir, newState, readState, reportFile, saveState } from "./state.js";
24
- import { copyOriginal, trialBatches, trialTestReqs } from "./trial.js";
25
- /** A capture that cannot start, or cannot go on: said as it is, nothing written but what was before. */
26
- export class CaptureError extends Error {
27
- constructor(message) {
28
- super(message);
29
- this.name = "CaptureError";
30
- }
31
- }
32
- /** Lines above which an area is split rather than outlined: about what one agent can outline from a map and a look. */
33
- export const LEAF_LINES = Number(process.env.TURRI_CAPTURE_LEAF_LINES ?? 6000);
34
- /** Characters of the map an agent is shown: about six thousand tokens. */
35
- export const MAP_BUDGET = 24_000;
36
- /** How many agents work at once, unless told. */
37
- export const DEFAULT_PARALLEL = 8;
38
- /** How many concepts one reconciling agent is given, and how many functional specs one readability pass reads. */
39
- const CONFLICTS_PER_AGENT = 20;
40
- const SPECS_PER_PASS = 30;
41
- /** The most surfaces of the interface one writer is given to capture: past this, another writer takes the rest. */
42
- const SURFACES_PER_WRITER = 30;
43
- /** The most surfaces of the interface a writer is shown, file by file. */
44
- const INTERFACE_LISTED = 200;
45
- /** The most lines of the files defining the interface one agent takes it from, and the most files. */
46
- const REFERENCE_LINES = 4000;
47
- const REFERENCE_FILES = 12;
48
- /** Characters of a part's features the agent that gathers them into modules is shown: about thirty thousand tokens. */
49
- const GATHERING_BUDGET = 120_000;
50
- /** Tool calls an agent trying scenarios on the original makes before it is told to hand over: installing it, then a few a scenario. */
51
- const TRIAL_CALLS = 100;
52
- /** The least a turn of an agent trying scenarios may take: installing the original and running them takes a while. */
53
- const TRIAL_TURN_MS = 30 * 60 * 1000;
54
- /** The output folder's state as it stands: nothing there, a capture to go on with, or something capture must not touch. */
55
- export function plainDirState(plainDir) {
56
- if (!existsSync(plainDir))
57
- return { kind: "empty" };
58
- if (!statSync(plainDir).isDirectory())
59
- return { kind: "taken", why: `${plainDir} is a file` };
60
- const state = readState(plainDir);
61
- if (state?.finished !== undefined)
62
- return { kind: "finished" };
63
- if (state !== undefined)
64
- return { kind: "resume", state };
65
- const entries = readdirSync(plainDir).filter((entry) => entry !== ".turri" && entry !== ".DS_Store");
66
- return entries.length === 0 ? { kind: "empty" } : { kind: "taken", why: `${plainDir} holds ${entries.slice(0, 3).join(", ")}${entries.length > 3 ? ", ..." : ""} and no capture of turri's` };
67
- }
68
- /** Run a whole capture - or go on with one stopped part-way. */
69
- export async function runCapture(options) {
70
- const root = resolve(options.root);
71
- if (!existsSync(root) || !statSync(root).isDirectory())
72
- throw new CaptureError(`${root} is not a folder to capture.`);
73
- const plainDir = resolve(options.plainDir ?? join(root, "plain"));
74
- const found = plainDirState(plainDir);
75
- if (found.kind === "finished") {
76
- throw new CaptureError(`${plainDir} holds a finished capture already - its report is ${reportFile(plainDir)}. To capture again, move that folder out of the way.`);
77
- }
78
- if (found.kind === "taken")
79
- throw new CaptureError(`Nothing captured: ${found.why}. Capture writes into a folder of its own - name another.`);
80
- const source = options.configFrom !== undefined ? configInUse(options.configFrom) : undefined;
81
- const configPath = join(plainDir, CONFIG_FILE);
82
- const needsConfig = !existsSync(configPath);
83
- const unusable = needsConfig ? configInUseProblem(source) : undefined;
84
- if (unusable !== undefined)
85
- throw new CaptureError(unusable);
86
- const tracker = new CaptureTracker(root, options.progress, options.watch);
87
- const map = buildMap(root, { exclude: [plainDir] });
88
- if (!map.files.some((file) => file.kind === "source"))
89
- throw new CaptureError(`${root} holds no source code to capture.`);
90
- const state = found.kind === "resume" ? found.state : newState(root);
91
- if (found.kind === "resume")
92
- tracker.said(`going on with the capture started ${state.started}`);
93
- state.plan ??= found.kind === "resume" ? { kind: "staged", reason: "continuing a capture started before compact captures" } : capturePlan(map);
94
- const save = () => {
95
- saveState(plainDir, state);
96
- tracker.counted(state);
97
- };
98
- const initialConfig = needsConfig ? await startingConfig(source, { harnessModel: options.harnessModel ?? options.model, codingModel: options.codingModel }) : undefined;
99
- save();
100
- tracker.said(`${state.plan.kind} capture: ${state.plan.reason}`);
101
- // The config in use, from the start - after the state, so a capture stopped here goes on: its agents run on its models,
102
- // and the project it writes keeps them.
103
- if (initialConfig !== undefined)
104
- writeFileSync(configPath, initialConfig);
105
- const inUse = projectModels(readProjectConfig(plainDir));
106
- const model = options.model ?? options.harnessModel ?? modelSpec(inUse.harness);
107
- const codingModel = options.codingModel ?? modelSpec(inUse.coding);
108
- const run = new CaptureRun({ ...options, root, plainDir, ...(model !== undefined ? { model } : {}), ...(codingModel !== undefined ? { codingModel } : {}) }, map, state, save, tracker);
109
- tracker.stage("surveying");
110
- await run.survey();
111
- await run.checkConventions();
112
- await run.extractInterface();
113
- if (state.plan.kind === "compact")
114
- await run.compact();
115
- if (state.plan.kind === "staged") {
116
- tracker.stage("outlining");
117
- await Promise.all(state.survey.parts.map((part) => run.outlineArea(part.name)));
118
- await run.divide();
119
- tracker.stage("capturing");
120
- await Promise.all(state.survey.parts.map((part) => run.captureFeatures(part.name)));
121
- await run.fillInterface();
122
- await run.gatherModules();
123
- await run.reconcile();
124
- await run.readability();
125
- }
126
- await run.verifyInterface();
127
- await run.trialScenarios();
128
- tracker.stage("writing");
129
- run.write();
130
- await run.scripts();
131
- return run.finish();
132
- }
133
- /** The testing scripts a captured project gets: conformance tests are on in it, so both. */
134
- const SCRIPT_KINDS = ["unit", "conformance"];
135
- /** Runs no more than `limit` at once, the rest waiting their turn. */
136
- function limiter(limit) {
137
- let running = 0;
138
- const waiting = [];
139
- return async (work) => {
140
- if (running >= limit)
141
- await new Promise((go) => waiting.push(go));
142
- running += 1;
143
- try {
144
- return await work();
145
- }
146
- finally {
147
- running -= 1;
148
- waiting.shift()?.();
149
- }
150
- };
151
- }
152
- class CaptureRun {
153
- options;
154
- map;
155
- state;
156
- save;
157
- tracker;
158
- progress;
159
- limited;
160
- leafLines;
161
- budget;
162
- models;
163
- constructor(options, map, state, save, tracker) {
164
- this.options = options;
165
- const defaults = captureDefaults(options.model, options.codingModel);
166
- const config = readProjectConfig(options.plainDir);
167
- const tier = (role) => modelSpec(inheritModel(roleModel(config, role), defaults[role]));
168
- this.models = { capture: tier("capture"), "capture-analysis": tier("capture-analysis"), "capture-exploration": tier("capture-exploration") };
169
- tracker.said(`models: exploration ${this.models["capture-exploration"]}, analysis ${this.models["capture-analysis"]}, reasoning and writing ${this.models.capture}`);
170
- this.map = map;
171
- this.state = state;
172
- this.save = save;
173
- this.tracker = tracker;
174
- this.progress = (line) => tracker.said(line);
175
- this.limited = limiter(Math.max(1, options.parallel ?? DEFAULT_PARALLEL));
176
- this.leafLines = options.leafLines ?? LEAF_LINES;
177
- this.budget = options.mapBudget ?? MAP_BUDGET;
178
- }
179
- stopIfAsked() {
180
- if (this.options.signal?.aborted === true)
181
- throw new CaptureError("The capture was stopped. Run it again to go on from where it was.");
182
- }
183
- agent(label, prompt, context, extra, role = "capture") {
184
- const model = this.models[role];
185
- return {
186
- plainDir: this.options.plainDir,
187
- root: this.options.root,
188
- role,
189
- ...(model !== undefined ? { model } : {}),
190
- ...(this.options.signal !== undefined ? { signal: this.options.signal } : {}),
191
- label: `capture ${label}`,
192
- watch: this.tracker.agent(label, capturePrompt([prompt].flat().at(-1)).split("\n", 1)[0].replace(/^#\s+/, "")),
193
- prompt,
194
- context,
195
- ...extra,
196
- };
197
- }
198
- /** Analysis of evidence: plans, checks and trials, including corrections the evidence requires. */
199
- analysis(label, prompt, context, extra) {
200
- return this.agent(label, prompt, context, { ...extra, rules: false }, "capture-analysis");
201
- }
202
- codebaseBlock() {
203
- return `<codebase>\n${this.options.root}\n</codebase>`;
204
- }
205
- async survey() {
206
- if (this.state.survey !== undefined)
207
- return;
208
- this.stopIfAsked();
209
- this.progress("surveying the codebase");
210
- const context = [
211
- this.codebaseBlock(),
212
- `<map>\n${renderArea(this.map, ["."], this.budget)}\n</map>`,
213
- `<manifests>\n${this.manifests()}\n</manifests>`,
214
- `<docs>\n${this.docs()}\n</docs>`,
215
- `<standard library>\n${stdlibCatalogue()}\n</standard library>`,
216
- ].join("\n\n");
217
- const { answer, problems } = await this.limited(() => askAgent(this.agent("survey", "survey", context, { reads: true, rules: true, calls: 45 }), { ...SURVEY_TOOL, convert: (params) => ({ parts: records(params.parts).map(partOf), leftOut: leftOutOf(params.left_out), assumptions: strings(params.assumptions), separateConcerns: text(params.separate_concerns) || undefined }) }, (survey) => surveyProblems(this.map, survey)));
218
- if (answer === undefined)
219
- throw new CaptureError(`The survey of the codebase did not hold, so nothing could be captured:\n- ${problems.join("\n- ")}`);
220
- this.state.survey = answer;
221
- for (const part of answer.parts)
222
- this.state.areas[part.name] ??= { id: part.name, name: part.name, about: part.about, paths: part.paths, part: part.name };
223
- this.save();
224
- this.progress(`surveyed: ${answer.parts.map((part) => `${part.name}${part.stdlibStack !== undefined ? ` (${part.stdlibStack})` : ""}`).join(", ")}`);
225
- }
226
- /**
227
- * Each part's conventions checked against the code before any writer is given them: every feature follows them, so
228
- * one that is wrong is wrong everywhere. An agent reads the code each names and corrects what does not hold; a check
229
- * that never holds leaves them as surveyed, and the report says so.
230
- */
231
- async checkConventions() {
232
- const pending = this.state.survey.parts.filter((part) => (part.conventions ?? []).length > 0 && this.state.conventionsChecked?.[part.name] === undefined);
233
- if (pending.length === 0)
234
- return;
235
- this.tracker.stage("checking", pending.length);
236
- await Promise.all(pending.map((part) => this.limited(async () => {
237
- this.stopIfAsked();
238
- this.progress(`checking the ${part.conventions.length} conventions of ${part.name} against the code`);
239
- const known = new Set(part.definitions.map((definition) => definition.concept));
240
- const context = [
241
- this.codebaseBlock(),
242
- `<part>\n${part.name} - ${part.about}\n</part>`,
243
- `<concepts>\n${part.definitions.map((definition) => `- ${definition.text}`).join("\n") || "None."}\n</concepts>`,
244
- `<conventions>\n${part.conventions.map((convention, at) => `${at + 1}. ${convention.text}\n decided in: ${convention.where.join(", ")}`).join("\n")}\n</conventions>`,
245
- ].join("\n\n");
246
- const { answer, problems } = await askAgent(this.analysis(`check ${part.name}`, "check-conventions", context, { reads: true, calls: 30 }), { ...CONVENTIONS_TOOL, convert: (params) => ({ conventions: conventionsOf(params.conventions), changes: strings(params.changes) }) }, (answer) => [...(answer.conventions.length === 0 ? ["Give every convention as the code has it - those that hold too."] : []), ...conventionProblems(this.map, answer.conventions, known)]);
247
- if (answer !== undefined)
248
- part.conventions = answer.conventions;
249
- (this.state.conventionsChecked ??= {})[part.name] = answer !== undefined ? { changes: answer.changes } : { changes: [], failed: `the check did not hold: ${problems.join(" ")}` };
250
- this.save();
251
- this.tracker.worked();
252
- this.progress(answer === undefined
253
- ? `could not check the conventions of ${part.name} - kept as surveyed`
254
- : answer.changes.length === 0
255
- ? `every convention of ${part.name} holds`
256
- : `corrected the conventions of ${part.name}: ${answer.changes.length} change${answer.changes.length === 1 ? "" : "s"}`);
257
- })));
258
- }
259
- /**
260
- * Each part's interface taken from the code as data, before any feature is outlined: the files where the map found
261
- * it, so many lines an agent, each agent listing every command, argument, option, route and environment variable they
262
- * define - every name, what it takes, its choices, its default and its help, word for word - with where; every literal
263
- * checked against the code it cites, and every surface the map found listed or excluded with why (`referenceProblems`).
264
- * A part whose interface was taken gets its interface concept, which links the reference every writer then works from.
265
- */
266
- async extractInterface() {
267
- const leftOut = this.state.survey.leftOut.map((item) => item.path);
268
- const parts = this.state.survey.parts.filter((part) => !(this.state.interfaceTaken ?? []).includes(part.name));
269
- const work = [];
270
- for (const part of parts) {
271
- const files = filesOf(this.map, part.paths).filter((file) => file.kind !== "test" && !leftOut.some((path) => covers(path, file.path)) && file.surfaces.some((surface) => INTERFACE_KINDS.has(surface.kind)));
272
- const batches = [];
273
- let batch = [];
274
- let lines = 0;
275
- for (const file of files) {
276
- if (batch.length > 0 && (lines + file.lines > REFERENCE_LINES || batch.length >= REFERENCE_FILES)) {
277
- batches.push(batch);
278
- batch = [];
279
- lines = 0;
280
- }
281
- batch.push(file.path);
282
- lines += file.lines;
283
- }
284
- if (batch.length > 0)
285
- batches.push(batch);
286
- // The map found none: one agent looks for it, from the entry points.
287
- if (batches.length === 0)
288
- batches.push([]);
289
- batches.forEach((files, at) => {
290
- const key = files.join(", ") || "(the map found none)";
291
- if (this.state.interfaces?.[part.name]?.[key] === undefined)
292
- work.push({ part, key, files, label: `reference ${part.name}${batches.length > 1 ? ` ${at + 1}` : ""}` });
293
- });
294
- }
295
- if (work.length > 0) {
296
- this.tracker.stage("extracting", work.length);
297
- this.progress(`taking the interface from the code: ${work.length === 1 ? "an agent" : `${work.length} agents`}`);
298
- await Promise.all(work.map((item) => this.limited(async () => {
299
- this.stopIfAsked();
300
- const listed = item.files.map((path) => {
301
- const file = this.map.files.find((candidate) => candidate.path === path);
302
- const names = [...new Set(file.surfaces.filter((surface) => INTERFACE_KINDS.has(surface.kind)).map((surface) => `\`${surface.name}\``))];
303
- return `- ${path} - ${file.lines} lines; the map found ${names.slice(0, 60).join(", ")}${names.length > 60 ? `, and ${names.length - 60} more` : ""}`;
304
- });
305
- const context = [
306
- this.codebaseBlock(),
307
- `<part>\n${item.part.name} - ${item.part.about}\n</part>`,
308
- `<files>\n${listed.length > 0 ? listed.join("\n") : "The map found no interface in the part's files: find it - from its entry points, where its arguments, routes and variables are read."}\n</files>`,
309
- `<map>\n${renderArea(this.map, item.part.paths, Math.floor(this.budget / 2))}\n</map>`,
310
- ].join("\n\n");
311
- const { answer, problems } = await askAgent(this.agent(item.label, "reference", context, { reads: true, rules: false, calls: 60 }, "capture-exploration"), { ...REFERENCE_TOOL, convert: referenceAnswerOf }, (answer) => referenceProblems(this.map, this.options.root, item.files, answer));
312
- ((this.state.interfaces ??= {})[item.part.name] ??= {})[item.key] = answer ?? { failed: `what its agent handed over did not hold: ${problems.join(" ")}` };
313
- this.save();
314
- this.tracker.worked();
315
- this.progress(answer !== undefined ? `took ${answer.entries.length} piece${answer.entries.length === 1 ? "" : "s"} of ${item.part.name}'s interface from ${item.files.length === 1 ? item.files[0] : `${item.files.length} files`}` : `could not take ${item.part.name}'s interface from ${item.key}`);
316
- })));
317
- }
318
- await this.checkReference(parts);
319
- for (const part of parts) {
320
- const concept = interfaceConcept(part.name);
321
- const api = pythonInterface(this.map, part.paths);
322
- if (api)
323
- (this.state.pythonInterfaces ??= {})[part.name] = api;
324
- if ((api || referenceOf(this.state, part.name).entries.length > 0) && !part.definitions.some((definition) => definition.concept === concept))
325
- part.definitions.push({ concept, text: interfaceDefinition(part.name) });
326
- (this.state.interfaceTaken ??= []).push(part.name);
327
- }
328
- this.save();
329
- }
330
- /**
331
- * Each part of the interface reference checked against the code by a fresh agent, as the conventions are: what the
332
- * checks of the code cannot see - a help text cut to its first line, choices left out or worked out when it runs, an
333
- * environment variable read through a constant - corrected or added, every entry again checked against the code it
334
- * cites. A check that never holds leaves the reference as it was taken, and the report says so.
335
- */
336
- async checkReference(parts) {
337
- const work = parts.flatMap((part) => Object.entries(this.state.interfaces?.[part.name] ?? {}).flatMap(([key, batch], at, all) => "entries" in batch && batch.checked === undefined ? [{ part, key, batch, label: `check reference ${part.name}${all.length > 1 ? ` ${at + 1}` : ""}` }] : []));
338
- if (work.length === 0)
339
- return;
340
- this.tracker.stage("extracting", work.length);
341
- this.progress(`checking the interface reference against the code: ${work.length === 1 ? "an agent" : `${work.length} agents`}`);
342
- await Promise.all(work.map((item) => this.limited(async () => {
343
- this.stopIfAsked();
344
- const files = item.key === "(the map found none)" ? [] : item.key.split(", ");
345
- const context = [
346
- this.codebaseBlock(),
347
- `<part>\n${item.part.name} - ${item.part.about}\n</part>`,
348
- `<the reference>\nAs it was taken from ${files.length > 0 ? files.join(", ") : "the part's code"}:\n\n${renderReference(item.part.name, item.batch.entries)}\n${item.batch.entries.map((entry) => `- \`${entry.name}\`${entry.command !== undefined ? ` of \`${entry.command}\`` : ""}: ${entry.where}${entry.also.length > 0 ? `, also ${entry.also.join(", ")}` : ""}`).join("\n")}\n${item.batch.excluded.length > 0 ? `\nLeft out: ${item.batch.excluded.map((excluded) => `\`${excluded.name}\` (${excluded.path}) - ${excluded.why}`).join("; ")}\n` : ""}</the reference>`,
349
- `<map>\n${renderArea(this.map, item.part.paths, Math.floor(this.budget / 2))}\n</map>`,
350
- ].join("\n\n");
351
- const { answer, problems } = await askAgent(this.analysis(item.label, "check-reference", context, { reads: true, calls: 60 }), { ...REFERENCE_CHECKED_TOOL, convert: (params) => ({ ...referenceAnswerOf(params), changes: strings(params.changes) }) }, (answer) => [...(item.batch.entries.length > 0 && answer.entries.length === 0 ? ["Give every entry as the code has it - those that hold too."] : []), ...referenceProblems(this.map, this.options.root, files, answer)]);
352
- const batch = this.state.interfaces[item.part.name][item.key];
353
- if ("entries" in batch) {
354
- if (answer !== undefined) {
355
- batch.entries = answer.entries;
356
- batch.excluded = answer.excluded;
357
- batch.checked = { changes: answer.changes };
358
- }
359
- else
360
- batch.checked = { failed: `the check did not hold: ${problems.join(" ")}` };
361
- }
362
- this.save();
363
- this.tracker.worked();
364
- this.progress(answer === undefined ? `could not check ${item.part.name}'s interface reference - kept as taken` : answer.changes.length === 0 ? `${item.part.name}'s interface reference holds` : `corrected ${item.part.name}'s interface reference: ${answer.changes.length} change${answer.changes.length === 1 ? "" : "s"}`);
365
- })));
366
- }
367
- /**
368
- * The interface among some paths, for an agent: the reference's entries there - exact, taken from the code - and what
369
- * the map found there that the reference neither lists nor excludes; the map's alone where no reference was taken.
370
- */
371
- interfaceFor(part, paths) {
372
- const reference = referenceOf(this.state, part);
373
- const found = interfaceIn(this.map, paths, leftOutPaths(this.state));
374
- if (reference.entries.length === 0)
375
- return { entries: [], unlisted: found };
376
- const listed = reference.entries.map(entrySurface);
377
- return {
378
- entries: entriesIn(reference.entries, paths),
379
- unlisted: found.filter((surface) => !listed.some((entry) => namedIn(surface, entry.name)) && !reference.excluded.some((item) => namedExactly(surface, item.name))),
380
- };
381
- }
382
- /** What a feature's writer is told of the interface in its files: the reference's entries, exact, and what to do with them. */
383
- writerInterfaceBlock(part, paths) {
384
- const api = this.state.pythonInterfaces?.[part];
385
- const library = api ? `\n<public Python API>\nThese exact public imports and signatures are already in ${interfaceConcept(part)}'s linked reference. Use the concept where you describe their behaviour. Keep literal lists and signatures in the reference; write what a caller observes in the spec.\n${api.slice(0, this.budget)}\n</public Python API>` : "";
386
- const { entries, unlisted } = this.interfaceFor(part, paths);
387
- if (referenceOf(this.state, part).entries.length === 0) {
388
- return interfaceBlock("the interface in your files", "Every option, command, route, screen and environment variable the code defines in your feature's files - capture exactly each your feature owns:", unlisted) + library;
389
- }
390
- const concept = interfaceConcept(part);
391
- return referenceBlock("the interface in your files", `Taken from the code, every literal checked against it: ${concept}'s reference, which every functional spec using ${concept} carries. Of these, capture what each your feature owns does - by its exact name, using ${concept}. What one takes, its choices, its default and its help are the reference's: say them only where a behaviour turns on them, and never otherwise than here.`, entries, unlisted) + library;
392
- }
393
- /** What a writer of the interface no feature captured is given: those pieces, with the reference's entry of each. */
394
- gapBlock(part, gaps) {
395
- const { entries } = referenceOf(this.state, part);
396
- const exact = entries.filter((entry) => gaps.some((gap) => gap.name === entrySurface(entry).name && gap.path === entryFile(entry)));
397
- const rest = gaps.filter((gap) => !exact.some((entry) => gap.name === entrySurface(entry).name && gap.path === entryFile(entry)));
398
- return referenceBlock("the interface to capture", "Named in no functional spec of the part - capture each exactly, or drop it, by name, with why:", exact, rest);
399
- }
400
- /** The manifests near the root, each cut short: what the codebase is built on. */
401
- manifests() {
402
- const files = this.map.files.filter((file) => file.kind === "manifest" && file.path.split("/").length <= 3).sort((a, b) => a.path.split("/").length - b.path.split("/").length);
403
- return this.excerpts(files.map((file) => file.path), 3000, 16_000) || "None found.";
404
- }
405
- /** The READMEs near the root, cut short. */
406
- docs() {
407
- const files = this.map.files.filter((file) => /^readme/i.test(file.path.split("/").at(-1)) && file.path.split("/").length <= 2);
408
- return this.excerpts(files.map((file) => file.path), 6000, 8000) || "None found.";
409
- }
410
- excerpts(paths, each, total) {
411
- const parts = [];
412
- let used = 0;
413
- for (const path of paths) {
414
- if (used >= total)
415
- break;
416
- let body;
417
- try {
418
- body = readFileSync(join(this.map.root, ...path.split("/")), "utf8");
419
- }
420
- catch {
421
- continue;
422
- }
423
- const cut = body.length > each ? `${body.slice(0, each)}\n[... ${body.length - each} more characters]` : body;
424
- parts.push(`### ${path}\n${cut.trimEnd()}`);
425
- used += cut.length;
426
- }
427
- return parts.join("\n\n");
428
- }
429
- part(name) {
430
- return this.state.survey.parts.find((part) => part.name === name);
431
- }
432
- /** Write one small program in one turn. Nothing from a partial draft enters the state: the staged path can take over. */
433
- async compact() {
434
- const parts = this.state.survey.parts;
435
- const expand = (why) => {
436
- this.state.plan = { kind: "staged", reason: `expanded from compact: ${why}` };
437
- this.save();
438
- this.progress(`staged capture: ${this.state.plan.reason}`);
439
- };
440
- if (parts.length !== 1)
441
- return expand(`the survey found ${parts.length} parts`);
442
- if (this.state.survey?.separateConcerns)
443
- return expand(this.state.survey.separateConcerns);
444
- const part = parts[0];
445
- const key = featureKey(part.name, part.name);
446
- if (this.state.features[key]?.captured !== undefined)
447
- return;
448
- const { entries, unlisted } = this.interfaceFor(part.name, part.paths);
449
- const surfaces = [...entries.map(entrySurface), ...unlisted];
450
- const checkedPlan = capturePlan(this.map, surfaces.length);
451
- if (checkedPlan.kind === "staged")
452
- return expand(checkedPlan.reason);
453
- this.stopIfAsked();
454
- this.tracker.stage("compact-writing");
455
- const evidence = testEvidence(this.map, part.paths);
456
- const budget = scenarioBudget(evidence.reduce((sum, file) => sum + file.lines, 0));
457
- const area = this.state.areas[part.name];
458
- const context = [this.areaContext(area, this.budget), stackBlock(part), `<concepts>\n${part.definitions.map((d) => d.text).join("\n")}\n</concepts>`, this.writerInterfaceBlock(part.name, part.paths), testsBlock(evidence, budget)].join("\n\n");
459
- const { answer, problems } = await askAgent(this.agent(`compact ${part.name}`, "compact", context, { reads: true, rules: true, calls: 40 }), { ...COMPACT_TOOL, convert: (params) => ({ feature: params.feature ? capturedOf(params.feature) : undefined, expand: text(params.expand) }) }, ({ feature, expand }) => {
460
- if (feature === undefined)
461
- return expand ? [] : ["Give the feature, or say why it needs separate writers in expand."];
462
- if (expand)
463
- return ["Give only one of feature and expand."];
464
- return [...featureProblems(feature, part.definitions, budget), ...gapProblems(feature, surfaces)];
465
- });
466
- if (answer?.feature === undefined)
467
- return expand(answer?.expand || `the single writer's answer did not hold: ${problems.join(" ")}`);
468
- if (answer.feature.specs.length > (this.options.moduleSpecs ?? MODULE_SPECS))
469
- return expand("the specs do not fit in one module");
470
- area.features = [{ name: part.name, title: part.name, about: part.about, paths: part.paths }];
471
- this.state.features[key] = { key, captured: answer.feature };
472
- this.save();
473
- this.progress(`captured ${part.name} in one pass: ${answer.feature.specs.length} functional specs`);
474
- }
475
- /** Outline an area: split it and outline its areas, or outline it into features - whichever is left to do. */
476
- async outlineArea(id) {
477
- const area = this.state.areas[id];
478
- if (area.failed !== undefined)
479
- return;
480
- if (area.children === undefined && area.features === undefined) {
481
- const files = filesOf(this.map, area.paths);
482
- const splittable = linesOf(files) > this.leafLines && entriesOf(this.map, area.paths).length >= 2;
483
- if (!splittable || !(await this.split(area)))
484
- await this.outline(area);
485
- }
486
- if (area.children !== undefined)
487
- await Promise.all(area.children.map((child) => this.outlineArea(child)));
488
- }
489
- /** Capture a part's features, side by side - all but those the division merged into others. */
490
- async captureFeatures(part) {
491
- await Promise.all(featuresOf(this.state, part).map(({ leaf, feature }) => this.feature(leaf, feature)));
492
- }
493
- /**
494
- * Each part's features divided, once all its areas are outlined: each behaviour given to one feature, a feature that
495
- * is a slice of another's behaviour merged into it. A part outlined as one area was outlined by one agent that saw all
496
- * of it, and a part whose features are being written already keeps them as they are. A division that never holds
497
- * leaves each feature owning what it was outlined for.
498
- */
499
- async divide() {
500
- const pending = this.state.survey.parts.filter((part) => this.state.divided?.[part.name] === undefined && leavesOf(this.state, part.name).length > 1 && !featuresOf(this.state, part.name, { merged: true }).some(({ key }) => this.state.features[key] !== undefined));
501
- if (pending.length === 0)
502
- return;
503
- this.tracker.stage("dividing", pending.length);
504
- await Promise.all(pending.map((part) => this.limited(async () => {
505
- this.stopIfAsked();
506
- const features = featuresOf(this.state, part.name, { merged: true });
507
- const keys = features.map(({ key }) => key);
508
- this.progress(`dividing the ${features.length} features of ${part.name}`);
509
- const context = [`<part>\n${part.name} - ${part.about}\n</part>`, `<features of ${part.name}, in build order>\n${this.featureList(part.name, { paths: true })}\n</features of ${part.name}>`].join("\n\n");
510
- const convert = (params) => ({
511
- owns: records(params.features).map((item) => ({ feature: text(item.feature), owns: text(item.owns) })),
512
- merged: records(params.merged).map((item) => ({ feature: text(item.feature), into: strings(item.into), why: text(item.why) })),
513
- });
514
- const { answer, problems } = await askAgent(this.analysis(`divide ${part.name}`, "divide", context, { reads: false, calls: 3 }), { ...OWNERS_TOOL, convert }, (answer) => divisionProblems(keys, answer));
515
- (this.state.divided ??= {})[part.name] =
516
- answer !== undefined
517
- ? { owns: Object.fromEntries(answer.owns.map((item) => [item.feature, item.owns])), merged: Object.fromEntries(answer.merged.map((item) => [item.feature, { into: item.into, why: item.why }])) }
518
- : { owns: {}, merged: {}, failed: `the division did not hold: ${problems.join(" ")}` };
519
- this.save();
520
- this.tracker.worked();
521
- this.progress(answer !== undefined ? `divided the features of ${part.name}${answer.merged.length > 0 ? `: ${answer.merged.map((item) => `${item.feature} merged into ${item.into.join(", ")}`).join("; ")}` : ""}` : `could not divide the features of ${part.name} - each owns what it was outlined for`);
522
- })));
523
- }
524
- /**
525
- * A part's features in build order, area by area - each with what it owns once divided, else what it was outlined
526
- * for - for the division and for each writer: `mine` marks a writer's own, and leaves out those merged; `paths` adds
527
- * where each is built. Folded to a budget: where each is built goes first, then what the features of other areas own,
528
- * then their titles - a writer's own area is always listed whole.
529
- */
530
- featureList(part, options) {
531
- const division = this.state.divided?.[part];
532
- const mineLeaf = options.mine?.split("#")[0];
533
- const levels = ["paths", "owns", "titles", "keys"];
534
- const render = (fold) => leavesOf(this.state, part)
535
- .flatMap((leaf) => {
536
- const features = (leaf.features ?? []).map((feature) => ({ key: featureKey(leaf.id, feature.name), feature })).filter(({ key }) => options.mine === undefined || division?.merged[key] === undefined);
537
- if (features.length === 0)
538
- return [];
539
- const level = leaf.id === mineLeaf ? "owns" : fold;
540
- return [
541
- `## ${leaf.id} - ${leaf.about}`,
542
- ...features.flatMap(({ key, feature }) => {
543
- const mark = options.mine === undefined ? "- " : key === options.mine ? "-> " : " ";
544
- if (level === "keys")
545
- return [`${mark}${key}`];
546
- if (level === "titles")
547
- return [`${mark}${key} - ${feature.title}`];
548
- const line = `${mark}${key} - ${feature.title}: ${division?.owns[key] ?? feature.about}`;
549
- return options.paths === true && level === "paths" ? [line, ` built in: ${feature.paths.join(", ")}`] : [line];
550
- }),
551
- ];
552
- })
553
- .join("\n");
554
- const budget = options.mine === undefined ? this.budget * 2 : this.budget;
555
- let listed = "";
556
- for (const fold of levels) {
557
- listed = render(fold);
558
- if (listed.length <= budget)
559
- break;
560
- }
561
- return listed;
562
- }
563
- areaContext(area, budget) {
564
- const part = this.part(area.part);
565
- return [
566
- this.codebaseBlock(),
567
- `<part>\n${part.name} - ${part.about}\n</part>`,
568
- `<area>\n${area.id} - ${area.about}\n</area>`,
569
- `<map>\n${renderArea(this.map, area.paths, budget)}\n</map>`,
570
- ].join("\n\n");
571
- }
572
- /** Split an area into areas in build order. False when the split never held - it is outlined instead. */
573
- async split(area) {
574
- this.stopIfAsked();
575
- const convert = (params) => ({
576
- areas: records(params.areas).map((item) => ({ name: kebab(text(item.name)) || text(item.name), about: text(item.about), paths: strings(item.paths).map(trimSlash) })),
577
- leftOut: leftOutOf(params.left_out),
578
- });
579
- const { answer, problems } = await this.limited(() => askAgent(this.analysis(`split ${area.id}`, "split", this.areaContext(area, this.budget), { reads: true, calls: 15 }), { ...AREAS_TOOL, convert }, (answer) => splitProblems(this.map, area.paths, answer)));
580
- if (answer === undefined) {
581
- this.progress(`could not split ${area.id} - outlining it whole: ${problems[0] ?? ""}`);
582
- return false;
583
- }
584
- const ordered = buildOrder(this.map, answer.areas);
585
- area.children = ordered.map((child) => {
586
- const id = `${area.id}/${child.name}`;
587
- this.state.areas[id] = { id, name: child.name, about: child.about, paths: child.paths, part: area.part };
588
- return id;
589
- });
590
- area.leftOut = [...answer.leftOut, ...unplaced(this.map, area.paths, answer.areas, answer.leftOut).map((path) => ({ path, why: "placed in no area by the split" }))];
591
- this.save();
592
- this.progress(`split ${area.id} into ${ordered.map((child) => child.name).join(", ")}`);
593
- return true;
594
- }
595
- async outline(area) {
596
- this.stopIfAsked();
597
- const convert = (params) => ({
598
- features: records(params.features).map((item) => ({ name: kebab(text(item.name)) || text(item.name), title: text(item.title), about: text(item.about), paths: strings(item.paths).map(trimSlash) })),
599
- leftOut: leftOutOf(params.left_out),
600
- });
601
- const { answer, problems } = await this.limited(() => askAgent(this.analysis(`outline ${area.id}`, "outline", `${stackBlock(this.part(area.part))}\n\n${this.areaContext(area, this.budget)}`, { reads: true, calls: 25 }), { ...FEATURES_TOOL, convert }, (answer) => outlineProblems(this.map, area.paths, answer)));
602
- if (answer === undefined) {
603
- area.failed = `its outline did not hold: ${problems.join(" ")}`;
604
- this.save();
605
- this.progress(`could not outline ${area.id}`);
606
- return;
607
- }
608
- area.features = answer.features;
609
- area.leftOut = answer.leftOut;
610
- this.save();
611
- this.progress(`outlined ${area.id}: ${answer.features.length} feature${answer.features.length === 1 ? "" : "s"}`);
612
- }
613
- async feature(area, feature) {
614
- const key = featureKey(area.id, feature.name);
615
- const known = this.state.features[key];
616
- if (known?.captured !== undefined || known?.failed !== undefined)
617
- return;
618
- this.stopIfAsked();
619
- const part = this.part(area.part);
620
- const division = this.state.divided?.[part.name];
621
- // What the division merged into it is its own to capture: the merged features' files are where it is built too.
622
- const taken = mergedInto(this.state, key);
623
- const paths = featurePaths(this.state, key);
624
- const evidence = testEvidence(this.map, paths);
625
- const budget = scenarioBudget(evidence.reduce((sum, file) => sum + file.lines, 0));
626
- // A feature the harness added for the interface no feature captured: its writer captures each surface, or says why not.
627
- const gaps = feature.interface;
628
- const context = [
629
- this.codebaseBlock(),
630
- `<part>\n${part.name} - ${part.about}\n</part>`,
631
- stackBlock(part),
632
- `<concepts>\n${part.definitions.map((definition) => `- ${definition.text}`).join("\n") || "None given."}\n</concepts>`,
633
- `<features of ${part.name}>\nEvery feature of the part, in build order, with what it owns - yours marked:\n${this.featureList(part.name, { mine: key })}\n</features of ${part.name}>`,
634
- [
635
- "<feature>",
636
- `${key} - ${feature.title}: ${feature.about}`,
637
- ...(division?.owns[key] !== undefined ? [`What it owns: ${division.owns[key]}`] : []),
638
- ...taken.map((from) => `Merged into it: ${from.key} - ${outlinedFeature(this.state, from.key)?.about ?? ""} (${from.why})`),
639
- `Where it is built: ${paths.join(", ")}`,
640
- "</feature>",
641
- ].join("\n"),
642
- gaps !== undefined ? this.gapBlock(part.name, gaps) : this.writerInterfaceBlock(part.name, paths),
643
- testsBlock(evidence, budget),
644
- `<map>\n${renderArea(this.map, paths, Math.floor(this.budget / 2))}\n</map>`,
645
- ].join("\n\n");
646
- const { answer, problems } = await this.limited(() => {
647
- this.stopIfAsked();
648
- if (gaps === undefined)
649
- return askAgent(this.agent(`feature ${key}`, "feature", context, { reads: true, rules: true, calls: 40 }), { ...FEATURE_TOOL, convert: capturedOf }, (captured) => featureProblems(captured, part.definitions, budget));
650
- return askAgent(this.agent(`interface ${key}`, ["feature", "interface"], context, { reads: true, rules: true, calls: 40 }), { ...INTERFACE_TOOL, convert: (params) => ({ ...capturedOf(params), title: text(params.title) }) },
651
- // A writer may find none of them is the software's interface: then it drops them all, and writes nothing.
652
- (captured) => [...(captured.title === "" ? ["Give the feature a title."] : []), ...featureProblems(captured, part.definitions, budget, { mayBeEmpty: true }), ...gapProblems(captured, gaps)]);
653
- });
654
- if (answer?.title !== undefined)
655
- feature.title = answer.title;
656
- this.state.features[key] = answer !== undefined ? { key, captured: withoutTitle(answer) } : { key, failed: `what its writer handed over did not hold: ${problems.join(" ")}` };
657
- this.save();
658
- this.progress(answer !== undefined ? `captured ${key}: ${answer.specs.length} functional spec${answer.specs.length === 1 ? "" : "s"}` : `could not capture ${key}`);
659
- }
660
- /**
661
- * The interface no feature captured, once every feature is written: each option, command, route, screen and
662
- * environment variable of the code the part's ***plain names nowhere goes to a writer of its own - a feature added to
663
- * the area whose files define it, so many surfaces a writer - which captures each exactly, or drops it, by name, with
664
- * why. Once a part: a capture stopped part-way asks again only the writers that never answered.
665
- */
666
- async fillInterface() {
667
- const pending = this.state.survey.parts.filter((part) => !(this.state.interfaceFilled ?? []).includes(part.name));
668
- if (pending.length === 0)
669
- return;
670
- const gaps = interfaceGaps(this.map, this.state, assemble(this.state, this.options.moduleSpecs));
671
- const asked = [];
672
- for (const part of pending) {
673
- const leaves = leavesOf(this.state, part.name);
674
- const before = leaves.flatMap((leaf) => (leaf.features ?? []).filter((feature) => feature.interface !== undefined).map((feature) => ({ leaf, feature })));
675
- if (before.length > 0) {
676
- asked.push(...before.filter(({ leaf, feature }) => this.state.features[featureKey(leaf.id, feature.name)] === undefined));
677
- continue;
678
- }
679
- const byLeaf = new Map();
680
- for (const gap of gaps.filter((candidate) => candidate.part === part.name)) {
681
- const leaf = leaves.find((candidate) => candidate.paths.some((path) => covers(path, gap.path))) ?? leaves.at(-1);
682
- if (leaf !== undefined)
683
- byLeaf.set(leaf, [...(byLeaf.get(leaf) ?? []), { path: gap.path, kind: gap.kind, name: gap.name }]);
684
- }
685
- for (const [leaf, surfaces] of byLeaf) {
686
- for (let at = 0; at < surfaces.length; at += SURFACES_PER_WRITER) {
687
- const batch = surfaces.slice(at, at + SURFACES_PER_WRITER);
688
- const taken = new Set((leaf.features ?? []).map((feature) => feature.name));
689
- let name = "interface";
690
- for (let n = 2; taken.has(name); n += 1)
691
- name = `interface-${n}`;
692
- const feature = { name, title: "The rest of its interface", about: "the interface of its code no other feature captured", paths: [...new Set(batch.map((surface) => surface.path))], interface: batch };
693
- (leaf.features ??= []).push(feature);
694
- asked.push({ leaf, feature });
695
- }
696
- }
697
- }
698
- this.save();
699
- if (asked.length > 0) {
700
- const surfaces = asked.reduce((sum, { feature }) => sum + (feature.interface?.length ?? 0), 0);
701
- this.tracker.stage("filling", asked.length);
702
- this.progress(`capturing the interface no feature named: ${surfaces} option${surfaces === 1 ? "" : "s"}, command${surfaces === 1 ? "" : "s"}, route${surfaces === 1 ? "" : "s"} or variable${surfaces === 1 ? "" : "s"}`);
703
- await Promise.all(asked.map(({ leaf, feature }) => this.feature(leaf, feature).then(() => this.tracker.worked())));
704
- }
705
- this.state.interfaceFilled = [...(this.state.interfaceFilled ?? []), ...pending.map((part) => part.name)];
706
- this.save();
707
- }
708
- /**
709
- * Each module's interface checked against the code, once its ***plain reads well: every option, command, route,
710
- * field, message and exit code its functional specs and scenarios state, by an agent that reads the code deciding it
711
- * and corrects what is wrong or left out - over the readability pass, which never sees the code. A correction that
712
- * never holds is not made: what the ***plain said stays.
713
- */
714
- async verifyInterface() {
715
- const { modules, shared } = assemble(this.state, this.options.moduleSpecs);
716
- const pending = modules.filter((module) => !(this.state.verified ?? []).includes(module.name));
717
- if (pending.length === 0)
718
- return;
719
- this.tracker.stage("verifying", pending.length);
720
- this.progress(`checking the interface of ${pending.length} module${pending.length === 1 ? "" : "s"} against the code`);
721
- await Promise.all(pending.map((module) => this.limited(async () => {
722
- this.stopIfAsked();
723
- const sharedModule = shared.find((candidate) => candidate.name === module.shared);
724
- const known = new Set([...sharedModule.definitions, ...module.definitions].map((definition) => definition.concept));
725
- const paths = [...new Set(module.features.flatMap((feature) => featurePaths(this.state, feature.key)))];
726
- const own = this.interfaceFor(module.part, paths);
727
- const reference = referenceOf(this.state, module.part);
728
- const specs = module.features.flatMap((feature) => feature.specs);
729
- // An option the ***plain names that the code does not define: found mechanically, for the check to settle.
730
- const invented = reference.entries.length > 0 ? optionsNotInReference(specs.flatMap((spec) => [spec.text, ...spec.conformance.map((scenario) => scenario.text), ...spec.acceptance.map((scenario) => scenario.text)]).join("\n"), reference.entries) : [];
731
- const corrections = [];
732
- for (let at = 0; at < specs.length; at += SPECS_PER_PASS) {
733
- const chunk = specs.slice(at, at + SPECS_PER_PASS);
734
- const byId = new Map(chunk.map((spec) => [spec.funcId, spec]));
735
- const context = [
736
- this.codebaseBlock(),
737
- readabilityContext(module, sharedModule.definitions, chunk, stackBlock(this.part(module.part))),
738
- referenceBlock("the interface in its code", reference.entries.length > 0
739
- ? `Taken from the code, every literal checked against it - ${interfaceConcept(module.part)}'s reference, which the ***plain carries. The ***plain must agree with it, and with the code:`
740
- : "Every option, command, route, screen and environment variable the code of this module's features defines:", own.entries, own.unlisted),
741
- ...(invented.length > 0 ? [`<options the ***plain names that the reference does not have>\n${invented.map((option) => `\`${option}\``).join(", ")} - an option the code does not define is wrong, unless the code shows otherwise.\n</options the ***plain names that the reference does not have>`] : []),
742
- `<map>\n${renderArea(this.map, paths, Math.floor(this.budget / 2))}\n</map>`,
743
- ].join("\n\n");
744
- const { answer } = await askAgent(this.agent(`verify ${module.name}`, "verify", context, { reads: true, rules: true, calls: 40 }, "capture-analysis"), {
745
- ...CORRECTIONS_TOOL,
746
- convert: (params) => records(params.corrections).map((item) => ({ funcId: text(item.func_id), ...(text(item.scenario_id) !== "" ? { scenarioId: text(item.scenario_id) } : {}), text: text(item.text), why: text(item.why) })),
747
- }, (answer) => correctionProblems(answer, byId, known));
748
- for (const correction of answer ?? []) {
749
- const spec = byId.get(correction.funcId);
750
- const was = correction.scenarioId === undefined ? spec.text : [...spec.conformance, ...spec.acceptance].find((scenario) => scenario.id === correction.scenarioId)?.text;
751
- if (correction.text !== was)
752
- corrections.push(correction);
753
- }
754
- }
755
- (this.state.corrections ??= {})[module.name] = corrections;
756
- (this.state.verified ??= []).push(module.name);
757
- this.save();
758
- this.tracker.worked();
759
- this.progress(corrections.length === 0 ? `the interface of ${module.name} holds` : `corrected the interface of ${module.name}: ${corrections.length} correction${corrections.length === 1 ? "" : "s"}`);
760
- })));
761
- }
762
- /**
763
- * Each part's features gathered into modules by concern and put in the order they are built, once every feature is
764
- * written. A module is a concern of its own - what a person looks for in one file - never one that holds everything:
765
- * the code's areas, gathered by size alone, can put a small codebase's every concern in one. And a module is built on
766
- * the code of the modules before it, its scenarios run as soon as it is: a module whose scenarios send a request comes
767
- * after the one that sends it. The areas are in the order of their code's imports, which is not that order - the code
768
- * that runs everything imports everything, yet everything needs it built first. An agent reads every feature's
769
- * functional specs and scenarios, and the modules as the areas make them, and gathers and orders them, naming what each
770
- * needs of those before it; a scenario that needs a module after its own whatever the order is rewritten. Once only,
771
- * before anything is done module by module: what never holds leaves the modules as the code's areas make them.
772
- */
773
- async gatherModules() {
774
- if (this.state.edited.length > 0 || (this.state.verified ?? []).length > 0 || this.state.written === true)
775
- return;
776
- const { modules } = assemble(this.state, this.options.moduleSpecs);
777
- const pending = this.state.survey.parts.filter((part) => this.state.gathered?.[part.name] === undefined && this.gatheredFeatures(part.name).length > 1);
778
- if (pending.length === 0)
779
- return;
780
- this.tracker.stage("gathering", pending.length);
781
- await Promise.all(pending.map((part) => this.limited(async () => {
782
- this.stopIfAsked();
783
- const features = this.gatheredFeatures(part.name);
784
- const byArea = modules.filter((module) => module.part === part.name);
785
- this.progress(`gathering the ${features.length} features of ${part.name} into modules`);
786
- const given = {
787
- features: new Map(features.map(({ key, specs }) => [key, specs])),
788
- known: this.knownConcepts(part.name),
789
- reserved: new Set(this.state.survey.parts.map((candidate) => sharedName(candidate.name))),
790
- moduleSpecs: this.options.moduleSpecs ?? MODULE_SPECS,
791
- };
792
- const context = [
793
- `<part>\n${part.name} - ${part.about}\n</part>`,
794
- `<features of ${part.name}, area by area, in the order of their code>\n${gatheringList(features, GATHERING_BUDGET)}\n</features of ${part.name}>`,
795
- `<modules as the code's areas make them>\n${byArea.map((module) => `- ${module.name} - ${module.about}: ${module.features.map((feature) => feature.key).join(", ")}`).join("\n")}\n</modules as the code's areas make them>`,
796
- ].join("\n\n");
797
- const convert = (params) => ({
798
- modules: records(params.modules).map((item) => ({ name: kebab(text(item.name)) || text(item.name), about: text(item.about), features: strings(item.features), needs: strings(item.needs) })),
799
- rewrites: records(params.rewrites).map((item) => ({ feature: text(item.feature), funcId: text(item.func_id), scenarioId: text(item.scenario_id), text: text(item.text), why: text(item.why) })),
800
- });
801
- const { answer, problems } = await askAgent(this.agent(`modules ${part.name}`, "modules", context, { reads: false, rules: true, calls: 3 }), { ...MODULES_TOOL, convert }, (answer) => moduleProblems(answer, given));
802
- (this.state.gathered ??= {})[part.name] = answer !== undefined ? answer : { modules: [], rewrites: [], failed: `the gathering did not hold: ${problems.join(" ")}` };
803
- this.save();
804
- this.tracker.worked();
805
- this.progress(answer === undefined
806
- ? `could not gather the features of ${part.name} into modules - they are as the code's areas make them`
807
- : `gathered the features of ${part.name} into ${answer.modules.length} module${answer.modules.length === 1 ? "" : "s"}: ${answer.modules.map((module) => module.name).join(", ")}${answer.rewrites.length > 0 ? `; ${answer.rewrites.length} scenario${answer.rewrites.length === 1 ? "" : "s"} rewritten` : ""}`);
808
- })));
809
- }
810
- /** A part's features a module can hold, in the order of their code: written, with functional specs. */
811
- gatheredFeatures(part) {
812
- const division = this.state.divided?.[part];
813
- return featuresOf(this.state, part).flatMap(({ key, leaf, feature }) => {
814
- const specs = this.state.features[key]?.captured?.specs ?? [];
815
- return specs.length === 0 ? [] : [{ key, area: leaf, title: feature.title, owns: division?.owns[key] ?? feature.about, specs }];
816
- });
817
- }
818
- /**
819
- * Each module's scenarios tried on the original, once its ***plain is checked against the code and before it is
820
- * written. They are what the regenerated code's conformance tests check, written by agents that read the original but
821
- * never ran it - so one can expect a terminal its test will not give, a site on the internet, wrapping at a width
822
- * nobody set. An agent with a shell on a copy of the original - its files, installed there by the agent - runs each as
823
- * its conformance test will, under the test reqs: one the original does otherwise is corrected to what it does, one
824
- * nothing outside can check is removed, and what a test must set up for the original to act as they say joins the test
825
- * reqs. So many scenarios an agent; a module's agents one after another in a copy of its own, removed once they are
826
- * done. What never holds is left as it was, and the report says so.
827
- */
828
- async trialScenarios() {
829
- const assembly = assemble(this.state, this.options.moduleSpecs, { trials: false });
830
- const pending = assembly.modules
831
- .filter((module) => !(this.state.tried ?? []).includes(module.name))
832
- .map((module) => ({ module, batches: trialBatches(module) }))
833
- .map((item) => ({ ...item, left: item.batches.filter((_, at) => this.state.trials?.[item.module.name]?.[String(at + 1)] === undefined).length }));
834
- if (pending.length === 0)
835
- return;
836
- const total = pending.reduce((sum, item) => sum + item.left, 0);
837
- if (total > 0) {
838
- const scenarios = pending.reduce((sum, item) => sum + item.batches.reduce((inner, batch) => inner + batch.length, 0), 0);
839
- this.tracker.stage("trying", total);
840
- this.progress(`trying ${scenarios} scenario${scenarios === 1 ? "" : "s"} on the original: ${total === 1 ? "an agent" : `${total} agents`}`);
841
- }
842
- await Promise.all(pending.map((item) => (item.left === 0 ? this.triedAll(item.module.name) : this.limited(() => this.trialModule(item.module, item.batches, assembly)))));
843
- }
844
- async triedAll(module) {
845
- if (!(this.state.tried ?? []).includes(module))
846
- (this.state.tried ??= []).push(module);
847
- this.save();
848
- }
849
- /** A module's scenarios tried on a copy of the original of its own, so many an agent, one after another. */
850
- async trialModule(module, batches, assembly) {
851
- const dir = join(captureDir(this.options.plainDir), "trial", module.name);
852
- const original = join(dir, "original");
853
- const part = this.part(module.part);
854
- const checked = checkedModule(module, assembly.shared);
855
- try {
856
- for (const [at, batch] of batches.entries()) {
857
- const key = String(at + 1);
858
- if (this.state.trials?.[module.name]?.[key] !== undefined)
859
- continue;
860
- this.stopIfAsked();
861
- const installed = existsSync(original);
862
- if (!installed)
863
- copyOriginal(this.map, original);
864
- const label = `trial ${module.name}${batches.length > 1 ? ` ${at + 1}` : ""}`;
865
- const context = this.trialContext(part, module, batch, assembly, { folder: original, installed });
866
- const convert = (params) => ({
867
- results: records(params.scenarios).map((item) => {
868
- const corrected = text(item.text);
869
- const why = text(item.why);
870
- return { funcId: text(item.func_id), scenarioId: text(item.scenario_id), outcome: text(item.outcome), ran: text(item.ran), ...(corrected !== "" ? { text: corrected } : {}), ...(why !== "" ? { why } : {}) };
871
- }),
872
- specs: records(params.functional_specs).map((item) => ({ funcId: text(item.func_id), text: text(item.text), why: text(item.why) })),
873
- testReqs: strings(params.test_reqs).map((req) => req.replace(/^-\s+/, "")),
874
- });
875
- const { answer, problems } = await askAgent({ ...this.analysis(label, "trial", context, { reads: true, calls: TRIAL_CALLS }), shell: { workdir: original, home: dir }, turnAtLeastMs: TRIAL_TURN_MS }, { ...TRIAL_TOOL, convert }, (answer) => trialProblems(answer, batch, checked));
876
- ((this.state.trials ??= {})[module.name] ??= {})[key] = answer ?? { failed: `what its agent handed over did not hold: ${problems.join(" ")}` };
877
- this.save();
878
- this.tracker.worked();
879
- this.progress(answer === undefined ? `could not try ${label.slice("trial ".length)}'s scenarios on the original - kept as they were` : `tried ${batch.length} scenario${batch.length === 1 ? "" : "s"} of ${module.name} on the original: ${trialSummary(answer.results)}`);
880
- }
881
- await this.triedAll(module.name);
882
- }
883
- finally {
884
- // The copy, its installs, its home and its caches: what an agent ran the original in, never kept.
885
- rmSync(dir, { recursive: true, force: true });
886
- }
887
- }
888
- /** What an agent trying scenarios is given: how the tests run, the conventions, the functional specs, the scenarios, its folder. */
889
- trialContext(part, module, batch, assembly, copy) {
890
- const sharedModule = assembly.shared.find((candidate) => candidate.name === module.shared);
891
- const conformance = part.stdlibStack !== undefined && part.stdlibConformance === true ? stdlibTemplates().find((template) => template.name === conformanceOf(part.stdlibStack)) : undefined;
892
- // What the trials before this one found a test must set up: of this part's modules, so far.
893
- const found = trialTestReqs(assembly.modules.filter((candidate) => candidate.part === part.name).flatMap((candidate) => Object.values(this.state.trials?.[candidate.name] ?? {})));
894
- const reqs = [...sharedModule.testReqs, ...found.filter((req) => !sharedModule.testReqs.includes(req))];
895
- const specs = new Map(module.features.flatMap((feature) => feature.specs).map((spec) => [spec.funcId, spec]));
896
- const funcIds = [...new Set(batch.map((scenario) => scenario.funcId))];
897
- return [
898
- `<part>\n${part.name} - ${part.about}\n</part>`,
899
- [
900
- "<how its conformance tests run>",
901
- ...(conformance !== undefined ? [`### ${conformance.name}`, conformance.text.trim(), ""] : []),
902
- ...(reqs.length > 0 ? ["### The part's test reqs", ...reqs.map((req) => `- ${req}`)] : conformance === undefined ? ["None written: run each scenario as a black-box test would - from outside, its output captured, its input not a terminal."] : []),
903
- "</how its conformance tests run>",
904
- ].join("\n"),
905
- ...((part.conventions ?? []).length > 0 ? [`<conventions>\n${part.conventions.map((convention) => `- ${convention.text}`).join("\n")}\n</conventions>`] : []),
906
- `<definitions>\n${[...sharedModule.definitions, ...module.definitions].map((definition) => `- ${definition.text}`).join("\n") || "None."}\n</definitions>`,
907
- `<functional specs of ${module.name}>\n${funcIds.map((funcId) => `# ${funcId}\n${specs.get(funcId)?.text ?? ""}`).join("\n\n")}\n</functional specs of ${module.name}>`,
908
- `<scenarios to try>\n${batch.map((scenario) => `### ${scenario.funcId}, scenario ${scenario.scenarioId} (${scenario.kind})\n${scenario.text}`).join("\n\n")}\n</scenarios to try>`,
909
- `<your folder>\n${slashed(copy.folder)} - a copy of the original codebase: its files as git has them, ${copy.installed ? "where an agent before you tried other scenarios of the module - what it installed may be there: look before installing again" : "nothing installed"}.\n</your folder>`,
910
- ].join("\n\n");
911
- }
912
- /** Concepts defined in different words by different features, given one definition each. */
913
- async reconcile() {
914
- const conflicts = assemble(this.state, this.options.moduleSpecs).conflicts;
915
- if (conflicts.length === 0)
916
- return;
917
- const batches = [];
918
- for (let at = 0; at < conflicts.length; at += CONFLICTS_PER_AGENT)
919
- batches.push(conflicts.slice(at, at + CONFLICTS_PER_AGENT));
920
- this.tracker.stage("reconciling", batches.length);
921
- this.progress(`reconciling ${conflicts.length} concept${conflicts.length === 1 ? "" : "s"} defined twice`);
922
- await Promise.all(batches.map((batch, index) => this.limited(async () => {
923
- this.stopIfAsked();
924
- const part = batch[0].part;
925
- const known = this.knownConcepts(part);
926
- const others = this.definitionsOf(part);
927
- const context = batch
928
- .map((conflict) => [
929
- `<concept name="${conflict.concept}" part="${conflict.part}">`,
930
- "Its definitions:",
931
- ...conflict.texts.map((given) => `- ${given}`),
932
- "Used in:",
933
- ...conflict.uses.slice(0, 4).map((use) => `- ${use.where}: ${use.text.slice(0, 400).replace(/\n/g, " ")}`),
934
- "</concept>",
935
- ].join("\n"))
936
- .concat(`<concepts you may use>\n${[...known].join(", ")}\n</concepts you may use>`)
937
- .join("\n\n");
938
- const asked = batch.map((conflict) => conflict.concept);
939
- const { answer } = await askAgent(this.agent(`concepts ${index + 1}`, "concepts", context, { reads: false, rules: true, calls: 3 }), { ...CONCEPTS_TOOL, convert: (params) => definitionsOf(params.definitions) }, (answer) => reconciledProblems(answer, asked, known, others));
940
- // What never held keeps the first definition given: one of the writers' own.
941
- for (const conflict of batch) {
942
- const given = answer?.find((definition) => definition.concept === conflict.concept)?.text ?? conflict.texts[0];
943
- (this.state.reconciled[conflict.part] ??= {})[conflict.concept] = given;
944
- }
945
- this.save();
946
- this.tracker.worked();
947
- })));
948
- }
949
- /** Every concept a part's modules may use: the part's own, and every one its features defined. */
950
- knownConcepts(part) {
951
- return new Set(this.definitionsOf(part).map((definition) => definition.concept));
952
- }
953
- /** A part's definitions: its own, and the first of each its features defined - or the one reconciled. */
954
- definitionsOf(part) {
955
- const found = new Map(this.part(part).definitions.map((definition) => [definition.concept, definition]));
956
- const reconciled = this.state.reconciled[part] ?? {};
957
- for (const leaf of leavesOf(this.state, part)) {
958
- for (const feature of leaf.features ?? []) {
959
- for (const definition of this.state.features[featureKey(leaf.id, feature.name)]?.captured?.definitions ?? []) {
960
- if (!found.has(definition.concept))
961
- found.set(definition.concept, reconciled[definition.concept] !== undefined ? { concept: definition.concept, text: reconciled[definition.concept] } : definition);
962
- }
963
- }
964
- }
965
- return [...found.values()];
966
- }
967
- /** Each module's ***plain read for readability alone, its functional specs rewritten where they read as code. */
968
- async readability() {
969
- const { modules, shared } = assemble(this.state, this.options.moduleSpecs);
970
- const pending = modules.filter((module) => !this.state.edited.includes(module.name));
971
- if (pending.length === 0)
972
- return;
973
- this.tracker.stage("reading", pending.length);
974
- this.progress(`reading ${pending.length} module${pending.length === 1 ? "" : "s"} for readability`);
975
- await Promise.all(pending.map((module) => this.limited(async () => {
976
- this.stopIfAsked();
977
- const sharedModule = shared.find((candidate) => candidate.name === module.shared);
978
- const known = new Set([...sharedModule.definitions, ...module.definitions].map((definition) => definition.concept));
979
- const specs = module.features.flatMap((feature) => feature.specs);
980
- const edits = {};
981
- for (let at = 0; at < specs.length; at += SPECS_PER_PASS) {
982
- const chunk = specs.slice(at, at + SPECS_PER_PASS);
983
- const originals = new Map(chunk.map((spec) => [spec.funcId, spec.text]));
984
- const context = readabilityContext(module, sharedModule.definitions, chunk, stackBlock(this.part(module.part)));
985
- const { answer } = await askAgent(this.agent(`readability ${module.name}`, "readability", context, { reads: false, rules: true, calls: 3 }), { ...EDITS_TOOL, convert: (params) => records(params.edits).map((item) => ({ funcId: text(item.func_id), text: text(item.text) })) }, (answer) => answer.flatMap((edit) => editProblems(edit.funcId, edit.text, originals.get(edit.funcId), known)));
986
- // What did not hold is left as the writer had it: the pass is an optimiser, never a gate.
987
- for (const edit of answer ?? [])
988
- if (edit.text !== originals.get(edit.funcId) && editProblems(edit.funcId, edit.text, originals.get(edit.funcId), known).length === 0)
989
- edits[edit.funcId] = edit.text;
990
- }
991
- this.state.edits[module.name] = edits;
992
- this.state.edited.push(module.name);
993
- this.save();
994
- this.tracker.worked();
995
- })));
996
- }
997
- /** Write the ***plain - once: the testing scripts are written for it, and may name themselves in its config. */
998
- write() {
999
- const assembly = assemble(this.state, this.options.moduleSpecs);
1000
- if (assembly.modules.length === 0)
1001
- throw new CaptureError("Nothing could be captured: no feature of the codebase held. Run it again to try the areas and features that failed once more.");
1002
- if (this.state.written === true)
1003
- return;
1004
- writeCapture(this.options.plainDir, this.map, this.state, assembly);
1005
- this.state.written = true;
1006
- this.save();
1007
- }
1008
- /**
1009
- * Each part's testing scripts: reuse a matching stock runner, otherwise use the writing tier. One that is not written
1010
- * does not stop the capture: the report says why, and what to ask.
1011
- */
1012
- async scripts() {
1013
- const assembly = assemble(this.state, this.options.moduleSpecs);
1014
- const parts = this.state.survey.parts;
1015
- const asked = parts.flatMap((part) => {
1016
- const first = assembly.modules.find((module) => module.part === part.name);
1017
- if (first === undefined)
1018
- return [];
1019
- return SCRIPT_KINDS.map((kind) => ({ key: `${part.name}:${kind}`, part, module: first.name, ...(parts.length > 1 ? { configModule: first.name } : {}), kind }));
1020
- });
1021
- const pending = asked.filter((item) => this.state.scripts?.[item.key] === undefined);
1022
- if (pending.length === 0)
1023
- return;
1024
- this.tracker.stage("scripts", pending.length);
1025
- this.progress(`writing ${pending.length === 1 ? "a testing script" : `${pending.length} testing scripts`}`);
1026
- await Promise.all(pending.map((item) => this.limited(async () => {
1027
- this.stopIfAsked();
1028
- const outcome = await this.script(item);
1029
- (this.state.scripts ??= {})[item.key] = outcome;
1030
- this.save();
1031
- this.tracker.worked();
1032
- const { what } = testingScriptSkill(item.kind);
1033
- this.progress("written" in outcome ? `wrote the ${what} of ${item.part.name}: ${outcome.written}${outcome.finding ? ` - ${outcome.finding}` : ""}` : `no ${what} for ${item.part.name}: ${outcome.failed}`);
1034
- })));
1035
- }
1036
- async script(item) {
1037
- const { plainDir, root, signal } = this.options;
1038
- const model = this.models.capture;
1039
- let finding;
1040
- try {
1041
- if (!this.options.writeScript) {
1042
- const reused = reuseRunner(plainDir, this.map, item.part, item.kind, item.configModule);
1043
- if (reused)
1044
- return reused;
1045
- }
1046
- const what = testingScriptSkill(item.kind).what;
1047
- finding = await watched(this.tracker.agent(`${what} ${item.part.name}`, `Write the ${what} for ${item.module}.`), signal, () => (this.options.writeScript ?? writeTestingScript)({
1048
- plainDir,
1049
- root,
1050
- module: item.module,
1051
- ...(item.configModule !== undefined ? { configModule: item.configModule } : {}),
1052
- part: item.part,
1053
- kind: item.kind,
1054
- ...(model !== undefined ? { model } : {}),
1055
- ...(signal !== undefined ? { signal } : {}),
1056
- }));
1057
- }
1058
- catch (error) {
1059
- this.stopIfAsked();
1060
- return { failed: error instanceof Error ? error.message : String(error) };
1061
- }
1062
- const found = withConfigModule(item.configModule, () => findTestScripts(plainDir, join(plainDir, `${item.module}.plain`)))[item.kind];
1063
- if (found === undefined)
1064
- return { failed: "its skill ended with no script written" };
1065
- const written = slashed(relative(plainDir, found));
1066
- // A single-part runner may have been found by name alone. Put its path in the exported config too.
1067
- if (item.configModule === undefined)
1068
- writeSetting(plainDir, item.kind === "unit" ? "unittests-script" : "conformance-tests-script", written);
1069
- return { written, ...(finding ? { finding: findingLine(finding) } : {}) };
1070
- }
1071
- /** Check the ***plain, write the report, and mark the capture finished. */
1072
- finish() {
1073
- const { plainDir } = this.options;
1074
- const assembly = assemble(this.state, this.options.moduleSpecs);
1075
- const checks = assembly.modules.map((module) => checkPlainFile(join(plainDir, `${module.name}.plain`)));
1076
- this.state.finished = new Date().toISOString();
1077
- const report = renderReport({ root: this.options.root, plainDir, map: this.map, state: this.state, assembly, checks });
1078
- writeFileSync(reportFile(plainDir), report);
1079
- this.save();
1080
- const specs = assembly.modules.reduce((sum, module) => sum + module.features.reduce((inner, feature) => inner + feature.specs.length, 0), 0);
1081
- const failedAreas = Object.values(this.state.areas).filter((area) => area.failed !== undefined).length;
1082
- const failedFeatures = Object.values(this.state.features).filter((feature) => feature.failed !== undefined).length;
1083
- return {
1084
- plainDir,
1085
- reportFile: reportFile(plainDir),
1086
- summary: summaryOf({ plainDir, map: this.map, assembly, state: this.state, checks }),
1087
- modules: assembly.modules.map((module) => module.name),
1088
- specs,
1089
- uncaptured: failedAreas + failedFeatures,
1090
- failing: checks.filter((check) => !check.ok).length,
1091
- };
1092
- }
1093
- }
1094
- function trimSlash(path) {
1095
- return path.replace(/^\.\/(?=.)/, "").replace(/\/+$/, "") || ".";
1096
- }
1097
- function partOf(item) {
1098
- const stack = text(item.stdlib_stack);
1099
- return {
1100
- name: kebab(text(item.name)) || text(item.name),
1101
- about: text(item.about),
1102
- paths: strings(item.paths).map(trimSlash),
1103
- ...(stack !== "" ? { stdlibStack: stack.replace(/\.plain$/, "") } : {}),
1104
- ...(item.stdlib_conformance === true ? { stdlibConformance: true } : {}),
1105
- implementationReqs: strings(item.implementation_reqs).map((req) => req.replace(/^-\s+/, "")),
1106
- conventions: conventionsOf(item.conventions),
1107
- testReqs: strings(item.test_reqs).map((req) => req.replace(/^-\s+/, "")),
1108
- definitions: definitionsOf(item.definitions),
1109
- runners: runnerChoices(item.runners),
1110
- };
1111
- }
1112
- function capturedOf(params) {
1113
- const scenarios = (value) => records(value).map((item) => ({ id: text(item.scenario_id), text: text(item.text) }));
1114
- return {
1115
- specs: records(params.functional_specs).map((item) => ({ funcId: text(item.func_id), text: text(item.text), conformance: scenarios(item.conformance), acceptance: scenarios(item.acceptance) })),
1116
- definitions: definitionsOf(params.definitions),
1117
- assumptions: strings(params.assumptions),
1118
- uncertain: strings(params.uncertain),
1119
- dropped: strings(params.dropped),
1120
- };
1121
- }
1122
- /** The interface among some files, file by file, for an agent: each name the code gives it, so many at most. */
1123
- export function interfaceBlock(tag, lead, surfaces) {
1124
- if (surfaces.length === 0)
1125
- return `<${tag}>\nThe map found none in these files: find it in the code.\n</${tag}>`;
1126
- const byFile = new Map();
1127
- for (const surface of surfaces.slice(0, INTERFACE_LISTED))
1128
- byFile.set(surface.path, [...(byFile.get(surface.path) ?? []), surface.kind === "env" ? `\`${surface.name}\` (environment variable)` : `\`${surface.name}\``]);
1129
- const more = surfaces.length > INTERFACE_LISTED ? [`and ${surfaces.length - INTERFACE_LISTED} more, in these files and others of yours`] : [];
1130
- return [`<${tag}>`, lead, ...[...byFile].map(([path, names]) => `- ${path}: ${names.join(", ")}`), ...more, `</${tag}>`].join("\n");
1131
- }
1132
- /**
1133
- * The interface among some files, for an agent: the reference's entries - each with every name, what it takes, its
1134
- * choices and its default, and where - and, after them, what the map found there that the reference does not list.
1135
- */
1136
- export function referenceBlock(tag, lead, entries, unlisted) {
1137
- if (entries.length === 0 && unlisted.length === 0)
1138
- return `<${tag}>\nNone in these files: find it in the code.\n</${tag}>`;
1139
- const line = (entry) => {
1140
- const facts = [
1141
- ...(entry.aliases.length > 0 ? [`also ${entry.aliases.map((alias) => `\`${alias}\``).join(", ")}`] : []),
1142
- ...(entry.takes !== undefined ? [`takes \`${entry.takes}\``] : []),
1143
- ...(entry.choices.length > 0 ? [`one of ${entry.choices.map((choice) => `\`${choice}\``).join(", ")}`] : []),
1144
- ...(entry.default !== undefined ? [`default \`${entry.default}\``] : []),
1145
- ...(entry.hidden === true ? ["hidden"] : []),
1146
- ];
1147
- return `- ${entry.kind}${entry.command !== undefined ? ` of \`${entry.command}\`` : ""} \`${entry.name}\`${facts.length > 0 ? ` - ${facts.join("; ")}` : ""} (${entry.where})`;
1148
- };
1149
- const shown = entries.slice(0, INTERFACE_LISTED).map(line);
1150
- const more = entries.length > INTERFACE_LISTED ? [`and ${entries.length - INTERFACE_LISTED} more - the reference lists them all`] : [];
1151
- const others = unlisted.length > 0
1152
- ? [entries.length > 0 ? "Found by the map, and in no entry of the reference - read each where it is:" : "", ...unlisted.slice(0, INTERFACE_LISTED).map((surface) => `- ${shownSurface(surface)}`)].filter((text) => text !== "")
1153
- : [];
1154
- return [`<${tag}>`, lead, ...shown, ...more, ...others, `</${tag}>`].join("\n");
1155
- }
1156
- /** An agent's part of the interface reference, as it handed it over. */
1157
- function referenceAnswerOf(params) {
1158
- const given = (value) => (typeof value === "string" && value.trim() !== "" ? value.trim() : undefined);
1159
- return {
1160
- entries: records(params.entries).map((item) => {
1161
- const command = given(item.command);
1162
- const takes = given(item.takes);
1163
- const value = typeof item.default === "string" && item.default.trim() !== "" ? item.default.trim() : undefined;
1164
- const help = typeof item.help === "string" && item.help.trim() !== "" ? item.help : undefined;
1165
- return {
1166
- kind: text(item.kind),
1167
- name: text(item.name),
1168
- aliases: strings(item.aliases),
1169
- ...(command !== undefined ? { command } : {}),
1170
- ...(takes !== undefined ? { takes } : {}),
1171
- choices: strings(item.choices),
1172
- ...(value !== undefined ? { default: value } : {}),
1173
- ...(item.repeatable === true ? { repeatable: true } : {}),
1174
- ...(item.required === true ? { required: true } : {}),
1175
- ...(item.hidden === true ? { hidden: true } : {}),
1176
- ...(help !== undefined ? { help } : {}),
1177
- details: strings(item.details),
1178
- where: text(item.where),
1179
- also: strings(item.also).map(trimSlash),
1180
- };
1181
- }),
1182
- excluded: records(params.excluded).map((item) => ({ name: text(item.name), path: trimSlash(text(item.path)), why: text(item.why) })),
1183
- };
1184
- }
1185
- /** A feature's answer as the state keeps it: the title an interface writer gave goes to its outline. */
1186
- function withoutTitle(answer) {
1187
- return { specs: answer.specs, definitions: answer.definitions, assumptions: answer.assumptions, uncertain: answer.uncertain, dropped: answer.dropped };
1188
- }
1189
- /** Conventions as an agent handed them over: each a line, and the files that decide it. */
1190
- function conventionsOf(value) {
1191
- return records(value).map((convention) => ({ text: text(convention.text).replace(/^-\s+/, ""), where: strings(convention.where).map(trimSlash) }));
1192
- }
1193
- /** A module as its order's and its trials' checks see it: its functional specs by func-id, and the concepts it may use. */
1194
- function checkedModule(module, shared) {
1195
- const sharedModule = shared.find((candidate) => candidate.name === module.shared);
1196
- return {
1197
- specs: new Map(module.features.flatMap((feature) => feature.specs).map((spec) => [spec.funcId, spec])),
1198
- known: new Set([...(sharedModule?.definitions ?? []), ...module.definitions].map((definition) => definition.concept)),
1199
- };
1200
- }
1201
- /** A text's first line, cut to so many characters. */
1202
- function cut(text, chars) {
1203
- const line = text.trim().split("\n")[0].trim();
1204
- return line.length > chars ? `${line.slice(0, chars)}...` : line;
1205
- }
1206
- /**
1207
- * A part's features for the agent that gathers them into modules, area by area in the order of their code: each with
1208
- * what it owns, the first line of each functional spec, and its scenarios - cut shorter, then left out, until they fit
1209
- * the budget.
1210
- */
1211
- export function gatheringList(features, budget) {
1212
- const render = (scenarioChars) => {
1213
- const lines = [];
1214
- let area;
1215
- for (const feature of features) {
1216
- if (feature.area.id !== area) {
1217
- if (area !== undefined)
1218
- lines.push("");
1219
- area = feature.area.id;
1220
- lines.push(`## ${feature.area.id} - ${feature.area.about}`);
1221
- }
1222
- lines.push(`### ${feature.key} - ${feature.title}: ${cut(feature.owns, 300)}`);
1223
- for (const spec of feature.specs) {
1224
- lines.push(`- ${spec.funcId}: ${cut(spec.text, 200)}`);
1225
- if (scenarioChars !== undefined)
1226
- for (const scenario of [...spec.conformance, ...spec.acceptance])
1227
- lines.push(` - scenario ${scenario.id}: ${cut(scenario.text, scenarioChars)}`);
1228
- }
1229
- }
1230
- return lines.join("\n");
1231
- };
1232
- for (const chars of [400, 160, 60]) {
1233
- const listed = render(chars);
1234
- if (listed.length <= budget)
1235
- return listed;
1236
- }
1237
- return render(undefined);
1238
- }
1239
- /** What trying some scenarios on the original found, in a line: `22 held, 2 corrected, 1 removed`. */
1240
- function trialSummary(results) {
1241
- const outcomes = [
1242
- ["held", "held"],
1243
- ["corrected", "corrected"],
1244
- ["removed", "removed"],
1245
- ["untried", "not tried"],
1246
- ];
1247
- return outcomes
1248
- .map(([outcome, said]) => [results.filter((result) => result.outcome === outcome).length, said])
1249
- .filter(([count]) => count > 0)
1250
- .map(([count, said]) => `${count} ${said}`)
1251
- .join(", ");
1252
- }
1253
- /** How many test names of one file a writer is shown. */
1254
- const TESTS_LISTED = 15;
1255
- /**
1256
- * The original's tests in a feature's files, for its writer: how many lines each holds and what they are called - where
1257
- * its scenarios go - and how many scenarios it may write, more the more the original tests it.
1258
- */
1259
- export function testsBlock(evidence, budget) {
1260
- const lines = evidence.reduce((sum, file) => sum + file.lines, 0);
1261
- const files = evidence.map((file) => {
1262
- const names = file.tests.slice(0, TESTS_LISTED).join(", ");
1263
- const more = file.tests.length > TESTS_LISTED ? `, and ${file.tests.length - TESTS_LISTED} more` : "";
1264
- return `- ${file.path} - ${file.lines} lines: ${names}${more}`;
1265
- });
1266
- return [
1267
- "<the original's tests>",
1268
- evidence.length === 0
1269
- ? `No file of your feature is a test of the original - its tests may be elsewhere: grep for what it does. You may write up to ${budget} scenarios.`
1270
- : `The original tests your feature's files in ${lines} lines - you may write up to ${budget} scenarios, the most where these are densest:`,
1271
- ...files,
1272
- "</the original's tests>",
1273
- ].join("\n");
1274
- }
1275
- function readabilityContext(module, shared, specs, stack) {
1276
- return [
1277
- stack,
1278
- `<definitions>\n${[...shared, ...module.definitions].map((definition) => `- ${definition.text}`).join("\n") || "None."}\n</definitions>`,
1279
- `<functional specs of ${module.name}>\n${specs.map((spec) => `# ${spec.funcId}\n${spec.text}${scenariosOf(spec)}`).join("\n\n")}\n</functional specs of ${module.name}>`,
1280
- ].join("\n\n");
1281
- }
1282
- /** A functional spec's scenarios, under it, for the readability pass: what they pin, its text need not say. */
1283
- function scenariosOf(spec) {
1284
- const lines = [...spec.conformance.map((scenario) => `- conformance ${scenario.id}: ${scenario.text}`), ...spec.acceptance.map((scenario) => `- acceptance ${scenario.id}: ${scenario.text}`)];
1285
- return lines.length === 0 ? "" : `\n<scenarios of ${spec.funcId}>\n${lines.join("\n")}\n</scenarios of ${spec.funcId}>`;
1286
- }
1287
- /**
1288
- * What a part is built on, as a writer is told it: the standard library's templates it imports - the stack, its kind's
1289
- * common one, its language's - in full, and its own implementation reqs. All of it is the default: what the code does
1290
- * because of it is never restated.
1291
- */
1292
- export function stackBlock(part) {
1293
- const templates = new Map(stdlibTemplates().map((template) => [template.name, template]));
1294
- const imported = [];
1295
- const visit = (name) => {
1296
- const template = templates.get(name);
1297
- if (template === undefined || imported.includes(name) || name.includes("/conformance/"))
1298
- return;
1299
- for (const below of template.imports)
1300
- visit(below);
1301
- imported.push(name);
1302
- };
1303
- if (part.stdlibStack !== undefined)
1304
- visit(part.stdlibStack);
1305
- return [
1306
- "<stack>",
1307
- ...(imported.length > 0 ? ["Built on turri's standard library - what these say the code does is settled already: never write it again.", ""] : []),
1308
- ...imported.flatMap((name) => [`### ${name}`, templates.get(name).text, ""]),
1309
- ...(part.implementationReqs.length > 0 ? ["### The part's own implementation reqs", ...part.implementationReqs.map((req) => `- ${req}`), ""] : []),
1310
- ...((part.conventions ?? []).length > 0
1311
- ? ["### The part's conventions - settled from its code: every functional spec and scenario follows them, and none decides them again", ...part.conventions.map((convention) => `- ${convention.text}`)]
1312
- : []),
1313
- "</stack>",
1314
- ].join("\n");
1315
- }