@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
package/dist/chats.js DELETED
@@ -1,1022 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import { existsSync } from "node:fs";
3
- import { currentChat, inChat } from "./chat-scope.js";
4
- import { adoptRun, forgetChat, forgetSessionFile, recordRun } from "./chat-records.js";
5
- import { createChatUi } from "./chat-ui.js";
6
- import { TerminalNotifications } from "./terminal-notifications.js";
7
- import { debugMode } from "./config.js";
8
- import { firstLine, record } from "./regenerate/ledger.js";
9
- import { pulseName, formatDuration } from "./regenerate/jobs.js";
10
- import { newNotice, noticeTask, SENTINEL, sentinelStartChoice, wentWrong } from "./notice.js";
11
- /**
12
- * The chats of a turri session.
13
- *
14
- * One turri process is one session on one project, and holds up to MAX_CHATS chats: conversations, each with its own
15
- * history, model, thinking level and questions, each working while another is shown. What they share is the
16
- * session's: the one job registry and work loop the project's pulses run in - a pulse any chat starts is in every
17
- * chat's side panel - the coding model, launches and the ledger.
18
- *
19
- * A chat is a pi session with turri's extension in it. The extension, built once for each, links itself to its chat
20
- * here (`attach`); its tools, commands and handlers then run inside the chat's scope (chat-scope.ts), so a pulse knows
21
- * which chat asked for it, and is reported back there when it ends - to the chat shown, when that one is closed.
22
- *
23
- * Where the chats live is a driver's: the terminal's (chat-terminal.ts) swaps which one pi's screen shows; a host's
24
- * (`createTurri`) makes a session for each and shows them in its own windows.
25
- *
26
- * With the project's sentinel on (sentinel.ts), every finished pulse goes to the sentinel - a chat of the session's own,
27
- * opened in the background with the first, and again after it is closed - and the chat the person looks at shows only
28
- * that it landed. The sentinel checks each pulse in a conversation of its own: its chat keeps its id, and is given a new
29
- * session for each pulse, one at a time. What the sentinel finds wrong it puts to the person as a notice, in the chat
30
- * they look at. Under `sentinel: ask`, the person is asked first - a notice of turri's own, before it first opens in the
31
- * session - the pulses that end meanwhile held until they answer.
32
- */
33
- /** The most chats a session has open at once. */
34
- export const MAX_CHATS = 9;
35
- /** What a chat is called until something is said in it. */
36
- export const NEW_CHAT_TITLE = "new chat";
37
- /** A second interrupt this soon after one that stopped something stops nothing more and ends nothing: one pressed twice to be sure. */
38
- export const INTERRUPT_SETTLE_MS = 500;
39
- /**
40
- * ctrl+c in a chat, the terminal's or a host's: what the chat is doing stopped - its turn, a skill or a tool in it, a
41
- * `!` command, a compaction, a retry - and nothing in the other chats. `stopTurn` ends its turn: pi's own esc in the
42
- * terminal. A chat doing nothing gets `idle`'s answer - the session ended - unless the last interrupt, at `lastStop`,
43
- * stopped something a moment ago: then it is `ignored`.
44
- */
45
- export function interruptChat(session, asked) {
46
- if (session.isBashRunning || session.isStreaming || session.isCompacting || session.isRetrying) {
47
- if (session.isBashRunning)
48
- session.abortBash();
49
- if (session.isStreaming)
50
- (asked.stopTurn ?? (() => void session.abort()))();
51
- else if (session.isCompacting || session.isRetrying)
52
- void session.abort();
53
- return "stopped";
54
- }
55
- if ((asked.now ?? Date.now()) - asked.lastStop < INTERRUPT_SETTLE_MS)
56
- return "ignored";
57
- return asked.idle();
58
- }
59
- /** A chat's title from what it says: its name, else its first message, short. */
60
- function titleOf(session) {
61
- if (session === undefined)
62
- return undefined;
63
- try {
64
- const named = session.sessionManager.getSessionName()?.trim();
65
- if (named)
66
- return named;
67
- for (const message of session.messages) {
68
- if (message.role !== "user")
69
- continue;
70
- const content = message.content;
71
- const text = typeof content === "string" ? content : Array.isArray(content) ? content.map((part) => part.text ?? "").join(" ") : "";
72
- const words = text.replace(/\s+/g, " ").trim();
73
- if (words !== "")
74
- return words.length > TITLE_CHARS ? `${words.slice(0, TITLE_CHARS - 1)}…` : words;
75
- }
76
- }
77
- catch {
78
- /* a session let go has no title to read */
79
- }
80
- return undefined;
81
- }
82
- const TITLE_CHARS = 32;
83
- export function createChats(options) {
84
- const { cwd, host, jobs } = options;
85
- const chats = [];
86
- const listeners = new Set();
87
- let driver;
88
- let shownId;
89
- let welcomeChat;
90
- let welcomeDismissed = false;
91
- /** The chat whose extension pi is building now. */
92
- let attaching;
93
- /** Chats are opened one at a time: each one's extension is built while it is the one attaching. */
94
- let opening = Promise.resolve();
95
- let notices = [];
96
- /** What the sentinel put to the person, and turri itself, this session: open until answered or superseded. */
97
- const open = [];
98
- /** The work the sentinel's conversation is on, from its brief until its agent is done - `concluded` once it said so. */
99
- let checking;
100
- /** Its check paused while its codebase is launched again: carried on once the codebase's launches are settled. */
101
- let paused;
102
- /** Pulses that finished, and checks asked for, while the sentinel was at work: each taken in turn, in a conversation of its own. */
103
- const waiting = [];
104
- /** The checks hosts asked for this session, by id: what a notice or a conclusion about one is about. */
105
- const checks = new Map();
106
- /** What the sentinel is given is given one at a time: its conversations made, and its pulses and checks put to them, in order. */
107
- let sentinelWork = Promise.resolve();
108
- /**
109
- * Under `sentinel: ask`, whether the person said to start the sentinel this session: asked - the notice `asking` open,
110
- * the pulses that ended meanwhile `held` - started, or not this session.
111
- */
112
- let consent = "unasked";
113
- let asking;
114
- const held = [];
115
- const run = { run: randomUUID().slice(0, 8), pid: process.pid, started: new Date().toISOString(), chats: [] };
116
- const changed = () => {
117
- for (const listener of listeners) {
118
- try {
119
- listener();
120
- }
121
- catch {
122
- /* a listener that fails is left out of this change */
123
- }
124
- }
125
- };
126
- /** A chat nothing was said in yet is a new chat: its number is beside it already, in the strip and the picker. */
127
- const titleFor = (chat) => (chat.role === SENTINEL ? SENTINEL : (titleOf(chat.session) ?? chat.recordedTitle ?? NEW_CHAT_TITLE));
128
- const sentinelChat = () => chats.find((chat) => chat.role === SENTINEL);
129
- /** The person's chats: all but the sentinel. */
130
- const people = () => chats.filter((chat) => chat.role !== SENTINEL);
131
- const setting = () => {
132
- try {
133
- return options.sentinel?.() ?? false;
134
- }
135
- catch {
136
- return false;
137
- }
138
- };
139
- /** On, or asked for - and not declined this session. */
140
- const wantsSentinel = () => {
141
- const now = setting();
142
- return now === true || (now === "ask" && consent !== "declined");
143
- };
144
- /** The chat the person looks at, for what is put to them - never the sentinel: when it is shown, `fallback`, else their first. */
145
- const personFacing = (fallback) => {
146
- const shown = chats.find((chat) => chat.id === shownId);
147
- if (shown !== undefined && shown.role !== SENTINEL && shown.instance !== undefined)
148
- return shown;
149
- return fallback?.instance !== undefined && fallback.role !== SENTINEL ? fallback : people().find((chat) => chat.instance !== undefined);
150
- };
151
- const statusOf = (chat) => (chat.ui?.waiting() ?? 0) > 0 ? "question" : chat.working ? "working" : chat.unread ? "unread" : "idle";
152
- /** What the session keeps of its chats on disk: those with something said in them, in order. */
153
- const persist = () => {
154
- if (options.persist !== true)
155
- return;
156
- // The sentinel last: `--continue` opens the first as pi's own chat, and that is the person's.
157
- run.chats = [...people(), ...chats.filter((chat) => chat.role === SENTINEL)].flatMap((chat) => {
158
- const file = chat.session?.sessionFile;
159
- return file !== undefined && existsSync(file) ? [{ id: chat.id, title: titleFor(chat), sessionFile: file, ...(chat.role !== undefined ? { role: chat.role } : {}) }] : [];
160
- });
161
- recordRun(cwd, run, { keep: debugMode(cwd) });
162
- };
163
- const newChat = (title, role) => {
164
- const id = randomUUID().slice(0, 8);
165
- if (role === undefined)
166
- welcomeChat ??= id;
167
- const chat = {
168
- id,
169
- scope: { id, asking: new Set() },
170
- ...(title !== undefined ? { recordedTitle: title } : {}),
171
- ...(role !== undefined ? { role } : {}),
172
- working: false,
173
- unread: false,
174
- };
175
- chat.dialogs = options.dialogs?.(id);
176
- chats.push(chat);
177
- return chat;
178
- };
179
- /** What the chat's session does, as the session follows it: its turns, its name. */
180
- const follow = (chat) => {
181
- chat.unsubscribe?.();
182
- const session = chat.session;
183
- if (session === undefined)
184
- return;
185
- chat.unsubscribe = session.subscribe((event) => {
186
- if (event.type === "agent_start") {
187
- chat.working = true;
188
- changed();
189
- }
190
- else if (event.type === "agent_end") {
191
- chat.working = false;
192
- if (shownId !== chat.id)
193
- chat.unread = true;
194
- persist();
195
- changed();
196
- }
197
- else if (event.type === "agent_settled") {
198
- // Done with its pulse - or with what the person said to it: the next pulse waiting, in a conversation of its own.
199
- // Settled, not at agent_end: pi's session still streams while agent_end's listeners run, and a retry comes after
200
- // it. Paused for a launch, it is not done: it carries on once the launch is settled.
201
- if (chat.role === SENTINEL && paused === undefined) {
202
- checking = undefined;
203
- toSentinel(() => nextWork(chat));
204
- }
205
- }
206
- else if (event.type === "session_info_changed") {
207
- persist();
208
- changed();
209
- }
210
- });
211
- };
212
- const core = {
213
- notifications: new TerminalNotifications(),
214
- cwd,
215
- host,
216
- jobs,
217
- extension: (pi) => options.extension(pi, core.attach(pi)),
218
- get canOpen() {
219
- return driver !== undefined;
220
- },
221
- get terminal() {
222
- return driver?.terminal === true;
223
- },
224
- welcomeVisible: (id) => !core.terminal || (!welcomeDismissed && welcomeChat === id),
225
- dismissWelcome() {
226
- if (!core.terminal || welcomeDismissed)
227
- return;
228
- welcomeDismissed = true;
229
- changed();
230
- },
231
- chats: () => chats.map((chat) => ({ id: chat.id, title: titleFor(chat), status: statusOf(chat), shown: chat.id === shownId, ...(chat.role !== undefined ? { role: chat.role } : {}) })),
232
- session: (id) => chats.find((chat) => chat.id === id)?.session,
233
- decline(id) {
234
- const chat = chats.find((candidate) => candidate.id === id);
235
- if (chat === undefined)
236
- return "missing";
237
- const asking = [...chat.scope.asking];
238
- for (const decline of asking)
239
- decline();
240
- return asking.length > 0 ? "declined" : "none";
241
- },
242
- shown: () => shownId,
243
- shownChat: () => chats.find((chat) => chat.id === shownId),
244
- chatOfSession: (session) => chats.find((chat) => chat.session === session),
245
- async open(asked = {}) {
246
- if (driver === undefined)
247
- throw new Error("This turri has one chat: there is nowhere to open another.");
248
- const done = opening.then(async () => {
249
- const already = asked.sessionFile !== undefined ? chats.find((chat) => chat.session?.sessionFile === asked.sessionFile) : asked.role === SENTINEL ? sentinelChat() : undefined;
250
- if (already !== undefined)
251
- return already;
252
- // The sentinel has a slot of its own: with it on, the person's chats are one fewer.
253
- const room = asked.role === SENTINEL ? MAX_CHATS - people().length : (wantsSentinel() ? MAX_CHATS - 1 : MAX_CHATS) - people().length;
254
- if (room <= 0) {
255
- const most = wantsSentinel() ? MAX_CHATS - 1 : MAX_CHATS;
256
- throw new Error(`${most} chats are open, the most there can be${wantsSentinel() ? " beside the sentinel" : ""}: close one first.`);
257
- }
258
- const chat = newChat(asked.title, asked.role);
259
- attaching = chat;
260
- try {
261
- await driver.create(chat, asked.sessionFile);
262
- }
263
- catch (error) {
264
- chats.splice(chats.indexOf(chat), 1);
265
- throw error;
266
- }
267
- finally {
268
- attaching = undefined;
269
- }
270
- follow(chat);
271
- inChat(chat.scope, () => record({ kind: "chat.opened", reopened: asked.sessionFile !== undefined, ...(chat.role !== undefined ? { role: chat.role } : {}) }, { project: cwd }));
272
- persist();
273
- changed();
274
- return chat;
275
- });
276
- opening = done.catch(() => undefined);
277
- const chat = await done;
278
- if (asked.hidden !== true)
279
- await core.show(chat.id);
280
- return core.chats().find((info) => info.id === chat.id);
281
- },
282
- async close(id) {
283
- const index = chats.findIndex((chat) => chat.id === id);
284
- if (index === -1)
285
- return;
286
- const chat = chats[index];
287
- if (shownId === id) {
288
- const others = chats.filter((other) => other !== chat);
289
- const next = others.find((other, at) => other.role !== SENTINEL && at >= index) ?? [...others].reverse().find((other) => other.role !== SENTINEL) ?? others[0];
290
- if (next !== undefined)
291
- await core.show(next.id);
292
- else
293
- shownId = undefined;
294
- }
295
- const recorded = run.chats.find((kept) => kept.id === id);
296
- chats.splice(chats.indexOf(chat), 1);
297
- // Closed, the sentinel is let go with what it had to check: the next pulse that finishes opens it again.
298
- if (chat.role === SENTINEL) {
299
- checking = undefined;
300
- paused = undefined;
301
- // A check a host asked for ends all the same: it is told it was not done.
302
- for (const work of waiting.splice(0))
303
- if ("check" in work)
304
- unchecked(work.check, "the sentinel was closed before it got to it");
305
- }
306
- // The question whether to start the sentinel was in it: put again in the chat the person looks at now.
307
- if (asking?.chat === id)
308
- askAgain();
309
- chat.unsubscribe?.();
310
- chat.ui?.close();
311
- inChat(chat.scope, () => record({ kind: "chat.closed" }, { project: cwd }));
312
- try {
313
- await driver?.dispose(chat);
314
- }
315
- finally {
316
- if (options.persist === true) {
317
- forgetChat(cwd, run.run, recorded, { keep: debugMode(cwd) });
318
- run.chats = run.chats.filter((kept) => kept.id !== id);
319
- }
320
- changed();
321
- }
322
- },
323
- async show(id) {
324
- const chat = chats.find((candidate) => candidate.id === id);
325
- if (chat === undefined || shownId === id)
326
- return;
327
- const from = core.shownChat();
328
- if (driver?.show !== undefined)
329
- await driver.show(chat, from);
330
- else
331
- core.showing(chat);
332
- },
333
- showing(chat) {
334
- shownId = chat.id;
335
- chat.unread = false;
336
- for (const [message, level] of notices.splice(0))
337
- core.notify(message, level);
338
- changed();
339
- },
340
- onChats(listener) {
341
- listeners.add(listener);
342
- return () => listeners.delete(listener);
343
- },
344
- changed,
345
- notify(message, level) {
346
- const chat = core.shownChat();
347
- const ui = chat?.ui?.ui ?? chat?.session?.extensionRunner.getUIContext();
348
- if (ui === undefined) {
349
- notices = [...notices, [message, level]].slice(-10);
350
- return;
351
- }
352
- try {
353
- ui.notify(message, level);
354
- }
355
- catch {
356
- /* a chat let go says nothing */
357
- }
358
- },
359
- async dispose(asked = {}) {
360
- for (const chat of chats.splice(0)) {
361
- chat.unsubscribe?.();
362
- chat.ui?.close();
363
- if (chat.session === asked.except)
364
- continue;
365
- try {
366
- await driver?.dispose(chat);
367
- }
368
- catch {
369
- /* let go already */
370
- }
371
- }
372
- changed();
373
- },
374
- attach() {
375
- // The chat pi builds this extension for: the one being opened; else, the session's first - pi makes it itself -
376
- // or, once there is one, the chat shown, rebuilt by pi (a /reload, a /fork).
377
- const chat = attaching ?? core.shownChat() ?? (chats.length === 0 ? newChat() : chats[chats.length - 1]);
378
- return {
379
- id: chat.id,
380
- scope: chat.scope,
381
- dialogs: chat.dialogs,
382
- role: chat.role,
383
- session: () => chat.session,
384
- live: (instance) => {
385
- chat.instance = instance;
386
- },
387
- };
388
- },
389
- adopt(session, services) {
390
- const chat = core.chatOfSession(session) ?? core.shownChat() ?? chats.find((candidate) => candidate.session === undefined) ?? newChat();
391
- if (chat.session !== session) {
392
- chat.session = session;
393
- chat.services = services;
394
- follow(chat);
395
- if (shownId === undefined)
396
- inChat(chat.scope, () => record({ kind: "chat.opened", reopened: session.messages.length > 0 }, { project: cwd }));
397
- }
398
- return chat;
399
- },
400
- sentinelOn: () => driver !== undefined && wantsSentinel(),
401
- jobFinished(job) {
402
- if (core.terminal) {
403
- const didNotPass = job.status === "succeeded" && wentWrong(job);
404
- const result = job.status === "succeeded" ? didNotPass ? "did not pass" : "finished" : job.status;
405
- core.notifications.add(`${pulseName(job)} · ${result} after ${formatDuration(job)}`, job.error ?? job.report ?? job.note ?? "", { warning: job.status === "failed" || didNotPass });
406
- changed();
407
- }
408
- // The question was settled in config.turri.yaml while it was open: what it held goes as the file now says.
409
- if (consent === "asking" && setting() !== "ask")
410
- settleStart(setting() === true ? "given" : "declined", "superseded");
411
- if (core.sentinelOn()) {
412
- if (consent === "asking" || (setting() === "ask" && consent === "unasked" && sentinelChat() === undefined && askToStart(job))) {
413
- held.push({ pulse: job });
414
- changed();
415
- return;
416
- }
417
- sentinelFinished(job);
418
- return;
419
- }
420
- toAsker(job);
421
- },
422
- launchChanged(launch) {
423
- if (launch.status === "running") {
424
- pauseFor(launch, options.launches?.replacing?.(launch) ?? [launch.codebase]);
425
- return;
426
- }
427
- // Replaced - what it started stopped by a newer launch, of its codebase or another module's that needed what it held:
428
- // a check in it waits for the launches to settle, then carries on where its code runs - or is told nothing of it runs.
429
- if (launch.replacedBy !== undefined && launch.status === "launched")
430
- pauseFor(launch, [launch.codebase]);
431
- // One after a pulse, ended, with the sentinel off: its chat is told - the sentinel, on, tests it with the pulse. One a
432
- // newer launch replaced as it ended is not: what it started is stopped the next moment, and the newer one is told.
433
- if (!("pulse" in launch.cause) || (launch.status !== "launched" && launch.status !== "failed") || launch.replacedBy !== undefined || core.sentinelOn())
434
- return;
435
- const job = jobs.get(launch.cause.pulse);
436
- const asked = chats.find((chat) => chat.id === job?.chat && chat.role !== SENTINEL && chat.instance !== undefined);
437
- const where = asked ?? personFacing();
438
- if (where === undefined)
439
- return;
440
- if (where.id !== shownId)
441
- where.unread = true;
442
- try {
443
- where.instance?.launched(launch);
444
- }
445
- catch {
446
- /* a chat let go as it ended: the host still hears of it */
447
- }
448
- changed();
449
- },
450
- check(prepare) {
451
- if (driver === undefined)
452
- return { refused: "There is nowhere to open the sentinel in this session." };
453
- // The question was settled in config.turri.yaml while it was open: what it held goes as the file now says.
454
- if (consent === "asking" && setting() !== "ask")
455
- settleStart(setting() === true ? "given" : "declined", "superseded");
456
- const now = setting();
457
- if (now === false)
458
- return { refused: "The sentinel is off for this project (sentinel: false): nothing checks the functional specs. Turn it on with sentinel: true in config.turri.yaml." };
459
- if (!wantsSentinel())
460
- return { refused: "The sentinel was not started this session - the person said not now when asked: nothing checks the functional specs until turri starts again, or sentinel: true is set." };
461
- const check = prepare();
462
- if ("refused" in check)
463
- return check;
464
- checks.set(check.id, check);
465
- record({ kind: "sentinel.asked", check: check.id, module: check.module, funcIds: check.funcIds }, { project: cwd });
466
- if (consent === "asking" || (now === "ask" && consent === "unasked" && sentinelChat() === undefined && askToStart(check))) {
467
- held.push({ check });
468
- changed();
469
- return { check: check.id };
470
- }
471
- sentinelChecks(check);
472
- return { check: check.id };
473
- },
474
- notice(input) {
475
- // A check's notice is about its module.
476
- const about = input.check !== undefined ? checks.get(input.check) : undefined;
477
- if (about !== undefined && input.module === undefined)
478
- input = { ...input, module: about.module };
479
- const asked = chats.find((chat) => chat.id === (input.job !== undefined ? jobs.get(input.job)?.chat : undefined));
480
- const target = personFacing(asked);
481
- if (target === undefined)
482
- return undefined;
483
- // One notice open a module: a newer one makes the older one's call to action stale. A note of a fix asks nothing.
484
- if (input.module !== undefined && input.kind !== "fixed") {
485
- for (const older of open.filter((notice) => notice.state === "open" && notice.module === input.module))
486
- over(older, "superseded");
487
- }
488
- // Only the sentinel's own may be ignored: never the question whether to start it.
489
- const { ignorable, ...rest } = input;
490
- const notice = newNotice(ignorable === true && input.kind === undefined ? input : rest, target.id);
491
- open.push(notice);
492
- if (core.terminal) {
493
- // notify_person may omit the id; the sentinel still has exactly one review in progress.
494
- const work = checking?.work;
495
- const about = work && currentChat()?.id === sentinelChat()?.id ? ("pulse" in work ? { job: work.pulse.id } : { check: work.check.id }) : undefined;
496
- core.notifications.put(notice, about);
497
- }
498
- else if (target.id !== shownId)
499
- target.unread = true;
500
- inChat(target.scope, () => record({ kind: "notice.put", notice: notice.id, severity: notice.severity, ...(notice.module !== undefined ? { module: notice.module } : {}) }, { project: cwd }));
501
- try {
502
- target.instance?.notice(notice);
503
- }
504
- catch {
505
- /* a chat let go as it was put: the host still hears it */
506
- }
507
- try {
508
- host.onNotice?.(notice);
509
- }
510
- catch {
511
- /* a host that throws must not lose the notice */
512
- }
513
- changed();
514
- return notice;
515
- },
516
- notices: () => open.filter((notice) => notice.state === "open"),
517
- concluded(conclusion) {
518
- // The sentinel's work concluded: a launch from now on does not pause it - it is only saying so.
519
- const work = checking?.work;
520
- if (work !== undefined && ("pulse" in work ? conclusion.job === work.pulse.id : conclusion.check === work.check.id))
521
- checking = { ...checking, concluded: true };
522
- const job = conclusion.job !== undefined ? jobs.get(conclusion.job) : undefined;
523
- const check = conclusion.check !== undefined ? checks.get(conclusion.check) : undefined;
524
- const target = personFacing(chats.find((chat) => chat.id === job?.chat));
525
- if (target === undefined)
526
- return undefined;
527
- const module = conclusion.module ?? job?.module ?? check?.module;
528
- const pulse = conclusion.pulse ?? job?.pulse;
529
- const told = { ...conclusion, ...(module !== undefined ? { module } : {}), ...(pulse !== undefined ? { pulse } : {}) };
530
- if (core.terminal)
531
- core.notifications.concluded(told);
532
- else if (target.id !== shownId)
533
- target.unread = true;
534
- inChat(target.scope, () => record({ kind: "sentinel.concluded", verdict: told.verdict, ...(module !== undefined ? { module } : {}), ...(told.check !== undefined ? { check: told.check } : {}) }, { project: cwd, ...(told.job !== undefined ? { job: told.job } : {}) }));
535
- try {
536
- target.instance?.concluded(told);
537
- }
538
- catch {
539
- /* a chat let go as it was told: the host still hears it */
540
- }
541
- try {
542
- host.onConcluded?.({ ...told, chat: target.id });
543
- }
544
- catch {
545
- /* a host that throws must not lose it */
546
- }
547
- changed();
548
- return target.id;
549
- },
550
- answer(id, answer) {
551
- const notice = open.find((candidate) => candidate.id === id);
552
- if (notice === undefined)
553
- return "missing";
554
- if (notice.state !== "open")
555
- return "over";
556
- // Left as the build has it, for good: nothing done in the chat, and the sentinel told not to raise it again.
557
- if ("ignore" in answer) {
558
- if (notice.ignorable !== true)
559
- return "refused";
560
- try {
561
- options.ignored?.(notice);
562
- }
563
- catch (error) {
564
- sentinelMessage(`The sentinel's guidance could not be written: ${error instanceof Error ? error.message : String(error)}`, "warning");
565
- }
566
- over(notice, "ignored");
567
- return "ignored";
568
- }
569
- if (notice.kind === "sentinel-start")
570
- return answerStart(notice, answer);
571
- const task = noticeTask(notice, answer);
572
- over(notice, "dismiss" in answer ? "dismissed" : "steer" in answer ? "steered" : "accepted");
573
- if (task === undefined)
574
- return "dismissed";
575
- const chat = chats.find((candidate) => candidate.id === notice.chat) ?? personFacing();
576
- chat?.instance?.act(task);
577
- return "done";
578
- },
579
- instanceInScope() {
580
- const scoped = currentChat();
581
- return (chats.find((chat) => chat.id === scoped?.id) ?? core.shownChat() ?? chats[0])?.instance;
582
- },
583
- setDriver(given) {
584
- driver = given;
585
- },
586
- async restore(saved, asked = {}) {
587
- adoptRun(cwd, saved.run);
588
- // The first of the person's chats is the one pi reopened itself (pi-launch.ts): the sentinel is never it.
589
- const first = saved.chats.find((kept) => kept.role === undefined);
590
- if (first !== undefined && asked.skipFirst === true) {
591
- const chat = chats[0];
592
- if (chat !== undefined)
593
- chat.recordedTitle ??= first.title;
594
- }
595
- for (const kept of asked.skipFirst === true ? saved.chats.filter((other) => other !== first) : saved.chats) {
596
- try {
597
- await core.open({ sessionFile: kept.sessionFile, hidden: true, title: kept.title, ...(kept.role !== undefined ? { role: kept.role } : {}) });
598
- }
599
- catch (error) {
600
- core.notify(`The chat "${kept.title}" could not be reopened: ${error instanceof Error ? error.message : String(error)}`, "warning");
601
- }
602
- }
603
- persist();
604
- },
605
- };
606
- /** A notice ended - answered, dismissed, superseded: its dialog closed, and the host told. */
607
- function over(notice, state) {
608
- notice.state = state;
609
- const chat = chats.find((candidate) => candidate.id === notice.chat);
610
- try {
611
- chat?.instance?.noticeOver(notice);
612
- }
613
- catch {
614
- /* a chat let go has no dialog to close */
615
- }
616
- try {
617
- host.onNoticeOver?.(notice);
618
- }
619
- catch {
620
- /* a host that throws must not keep the notice open */
621
- }
622
- if (chat !== undefined)
623
- inChat(chat.scope, () => record({ kind: "notice.over", notice: notice.id, state }, { project: cwd }));
624
- if (core.terminal)
625
- changed();
626
- }
627
- /** A pulse ended, told to the chat that asked for it - as without a sentinel - or the chat shown, when that one is closed. */
628
- function toAsker(job) {
629
- const asked = chats.find((chat) => chat.id === job.chat);
630
- const chat = asked?.instance !== undefined ? asked : (core.shownChat() ?? chats[0]);
631
- if (chat === undefined)
632
- return;
633
- if (chat.id !== shownId)
634
- chat.unread = true;
635
- try {
636
- chat.instance?.announce(job);
637
- }
638
- catch {
639
- // A chat let go as the pulse ended: the one shown is told instead.
640
- const shown = core.shownChat();
641
- if (shown !== undefined && shown !== chat)
642
- shown.instance?.announce(job);
643
- }
644
- changed();
645
- }
646
- /**
647
- * Under `sentinel: ask`, the first pulse that would open the sentinel this session: the person asked whether to start it,
648
- * in the chat they look at. False when there is nothing to ask with, or no chat to ask in: the sentinel opens as asked.
649
- */
650
- function askToStart(about) {
651
- let input;
652
- try {
653
- input = options.sentinelStart?.(about);
654
- }
655
- catch {
656
- input = undefined;
657
- }
658
- if (input === undefined)
659
- return false;
660
- consent = "asking";
661
- asking = core.notice({ ...input, kind: "sentinel-start" });
662
- if (asking === undefined)
663
- consent = "unasked";
664
- return asking !== undefined;
665
- }
666
- /** The chat the question was put in is gone: it is put in the chat the person looks at - none left, the pulses go as without one. */
667
- function askAgain() {
668
- const question = asking;
669
- over(question, "superseded");
670
- asking = undefined;
671
- consent = "unasked";
672
- const first = held[0];
673
- if (!askToStart("pulse" in first ? first.pulse : first.check))
674
- settleStart("declined", "superseded");
675
- }
676
- /** The person answered whether to start the sentinel: written to the project, when they chose for it, and what was held let go. */
677
- function answerStart(notice, answer) {
678
- const choice = sentinelStartChoice(notice, answer);
679
- try {
680
- if (choice === "always" || choice === "never")
681
- options.setSentinel?.(choice === "always");
682
- }
683
- catch (error) {
684
- core.notify(`config.turri.yaml could not be written: ${error instanceof Error ? error.message : String(error)}`, "warning");
685
- }
686
- settleStart(choice === "start" || choice === "always" ? "given" : "declined", "dismiss" in answer ? "dismissed" : "steer" in answer ? "steered" : "accepted");
687
- // Their own words are the chat's to act on: the sentinel is not started.
688
- if ("steer" in answer) {
689
- const task = noticeTask(notice, answer);
690
- const chat = chats.find((candidate) => candidate.id === notice.chat) ?? personFacing();
691
- if (task !== undefined)
692
- chat?.instance?.act(task);
693
- }
694
- return "dismiss" in answer ? "dismissed" : "done";
695
- }
696
- /** Whether to start the sentinel is settled: its question closed, and the pulses held go to it - or, declined, to their chats. */
697
- function settleStart(now, state) {
698
- consent = now;
699
- const question = asking;
700
- asking = undefined;
701
- if (question !== undefined && question.state === "open")
702
- over(question, state);
703
- for (const work of held.splice(0)) {
704
- if ("check" in work) {
705
- if (core.sentinelOn())
706
- sentinelChecks(work.check);
707
- else
708
- unchecked(work.check, "the person did not start the sentinel");
709
- }
710
- else if (core.sentinelOn())
711
- sentinelFinished(work.pulse);
712
- else
713
- toAsker(work.pulse);
714
- }
715
- changed();
716
- }
717
- /**
718
- * A pulse ended, with the sentinel on: the chat the person looks at says so - its agent told of one that landed, to
719
- * tell the person it landed and what the sentinel does with it, and nothing more; of one that went wrong, not, the
720
- * sentinel's notice being what it hears of it - and the sentinel is given it, opened in the background when it is not
721
- * open.
722
- */
723
- function sentinelFinished(job) {
724
- const asked = chats.find((chat) => chat.id === job.chat && chat.role !== SENTINEL);
725
- const where = personFacing(asked);
726
- if (where !== undefined) {
727
- if (where.id !== shownId && !core.terminal)
728
- where.unread = true;
729
- try {
730
- where.instance?.landed(job, { tell: !wentWrong(job) });
731
- }
732
- catch {
733
- /* a chat let go as the pulse ended: the sentinel still hears of it */
734
- }
735
- }
736
- changed();
737
- toSentinel(async () => {
738
- // No room for it, or nowhere to open it: the pulse is told as it is without one.
739
- const sentinel = await openSentinel(() => (asked ?? where)?.instance?.announce(job));
740
- if (sentinel !== undefined)
741
- await takeWork(sentinel, { pulse: job });
742
- });
743
- }
744
- /** A check a host asked for, for the sentinel - opened in the background when it is not open - in its turn. */
745
- function sentinelChecks(check) {
746
- toSentinel(async () => {
747
- const sentinel = await openSentinel((why) => unchecked(check, `the sentinel could not be opened: ${why}`));
748
- if (sentinel !== undefined)
749
- await takeWork(sentinel, { check });
750
- });
751
- }
752
- /** The sentinel's chat, opened hidden when it is not open - none, and `failed` told why, when it cannot be. */
753
- async function openSentinel(failed) {
754
- let sentinel = sentinelChat();
755
- if (sentinel === undefined) {
756
- try {
757
- await core.open({ hidden: true, role: SENTINEL });
758
- sentinel = sentinelChat();
759
- }
760
- catch (error) {
761
- const why = error instanceof Error ? error.message : String(error);
762
- sentinelMessage(`The sentinel could not be opened: ${why}`, "warning");
763
- failed(why);
764
- return undefined;
765
- }
766
- }
767
- return sentinel?.instance !== undefined ? sentinel : undefined;
768
- }
769
- /** A check that will not be done, told as a conclusion of turri's own - the host waits for one. */
770
- function unchecked(check, why) {
771
- core.concluded({ check: check.id, module: check.module, verdict: "unchecked", summary: `Not checked: ${why}.` });
772
- }
773
- function sentinelMessage(message, level) {
774
- if (!core.terminal)
775
- return core.notify(message, level);
776
- core.notifications.add(message, "");
777
- changed();
778
- }
779
- /** The sentinel's work, after what it was given before. */
780
- function toSentinel(work) {
781
- sentinelWork = sentinelWork.then(work).catch((error) => {
782
- sentinelMessage(`The sentinel: ${error instanceof Error ? error.message : String(error)}`, "warning");
783
- });
784
- }
785
- /**
786
- * Whether the sentinel is at work: on a pulse - its turn starts as it is told of one - or on what the person said to it;
787
- * or its check is paused while its codebase is launched again.
788
- */
789
- const sentinelBusy = (sentinel) => sentinel.session?.isStreaming === true || paused !== undefined;
790
- /** A finished pulse or a host's check, for the sentinel: taken now when it is free, else after what waits - every one, in order. */
791
- function takeWork(sentinel, work) {
792
- if (!sentinelBusy(sentinel))
793
- return begin(sentinel, work);
794
- waiting.push(work);
795
- }
796
- /** The sentinel free again: the next pulse or check that waits, taken. */
797
- function nextWork(sentinel) {
798
- if (!chats.includes(sentinel) || sentinelBusy(sentinel))
799
- return;
800
- const work = waiting.shift();
801
- if (work !== undefined)
802
- return begin(sentinel, work);
803
- }
804
- function begin(sentinel, work) {
805
- return "pulse" in work ? check(sentinel, work.pulse) : checkSpecs(sentinel, work.check);
806
- }
807
- /** The codebase a piece of the sentinel's work is tested in: the pulse's, or the check's module's. */
808
- const codebaseOf = (work) => ("pulse" in work ? work.pulse.module : work.check.module);
809
- /**
810
- * What runs cannot be tested for a pulse or a check: recorded, and concluded as unchecked; the next waiting taken. For a
811
- * pulse turri got it wrong - what runs cannot hold its commit - and that is said as an error where the person is too. A
812
- * host's check with nothing launched to test it in is an answer, not an error: its conclusion says it alone.
813
- */
814
- async function refuse(sentinel, work, why) {
815
- const module = codebaseOf(work);
816
- inChat(sentinel.scope, () => record({ kind: "sentinel.refused", ...(module !== undefined ? { module } : {}), ...("check" in work ? { check: work.check.id } : {}), why: firstLine(why, 300) }, { project: cwd, ...("pulse" in work ? { job: work.pulse.id } : {}) }));
817
- if ("pulse" in work && !core.terminal)
818
- core.notify(`The sentinel cannot check pulse ${work.pulse.id}: ${why}`, "error");
819
- core.concluded({
820
- ...("pulse" in work ? { job: work.pulse.id } : { check: work.check.id }),
821
- ...(module !== undefined ? { module } : {}),
822
- verdict: "unchecked",
823
- summary: `Not checked: ${why}`,
824
- });
825
- checking = undefined;
826
- changed();
827
- await nextWork(sentinel);
828
- }
829
- /**
830
- * The sentinel on a host's check, from scratch, as on a pulse: a conversation of its own, once what runs of the module
831
- * is settled - nothing launched for it, and the check ends unchecked.
832
- */
833
- async function checkSpecs(sentinel, check) {
834
- try {
835
- await options.launches?.readyForCheck(check);
836
- }
837
- catch (error) {
838
- return refuse(sentinel, { check }, error instanceof Error ? error.message : String(error));
839
- }
840
- checking = { work: { check } };
841
- inChat(sentinel.scope, () => record({ kind: "sentinel.checking", module: check.module, check: check.id }, { project: cwd }));
842
- const session = sentinel.session;
843
- if (session !== undefined && (session.messages.length > 0 || session.isStreaming))
844
- await freshConversation(sentinel);
845
- if (sentinel.id !== shownId)
846
- sentinel.unread = true;
847
- const where = personFacing();
848
- try {
849
- await sentinel.instance.briefCheck(check, where !== undefined ? { focused: titleFor(where) } : {});
850
- }
851
- catch (error) {
852
- sentinelMessage(`The sentinel could not be told of check ${check.id}: ${error instanceof Error ? error.message : String(error)}`, "warning");
853
- checking = undefined;
854
- }
855
- changed();
856
- }
857
- /**
858
- * The sentinel on a pulse, from scratch: a conversation of its own - its prompt, the project's guidance and this
859
- * pulse's brief, nothing of the pulses before it - once what runs holds the pulse's commit (`readyFor`).
860
- */
861
- async function check(sentinel, job) {
862
- try {
863
- await options.launches?.readyFor(job);
864
- }
865
- catch (error) {
866
- return refuse(sentinel, { pulse: job }, error instanceof Error ? error.message : String(error));
867
- }
868
- checking = { work: { pulse: job } };
869
- const module = job.module;
870
- inChat(sentinel.scope, () => record({ kind: "sentinel.checking", ...(module !== undefined ? { module } : {}) }, { project: cwd, job: job.id }));
871
- const session = sentinel.session;
872
- if (session !== undefined && (session.messages.length > 0 || session.isStreaming))
873
- await freshConversation(sentinel);
874
- if (sentinel.id !== shownId)
875
- sentinel.unread = true;
876
- const asked = chats.find((chat) => chat.id === job.chat && chat.role !== SENTINEL && chat.instance !== undefined);
877
- const where = personFacing(asked);
878
- try {
879
- await sentinel.instance.brief(job, {
880
- ...(asked !== undefined ? { asked: titleFor(asked) } : {}),
881
- ...(where !== undefined ? { focused: titleFor(where) } : {}),
882
- });
883
- }
884
- catch (error) {
885
- sentinelMessage(`The sentinel could not be told of ${job.id}: ${error instanceof Error ? error.message : String(error)}`, "warning");
886
- checking = undefined;
887
- }
888
- changed();
889
- }
890
- /**
891
- * A launch started that replaces what runs of a codebase the sentinel checks a pulse or a check of - its own, or one
892
- * below it in its chain - or what a launch started was stopped for another's: its turn stopped - its conversation kept
893
- * - until the codebase's launches are settled, then carried on in the launch that holds it.
894
- */
895
- function pauseFor(launch, codebases) {
896
- const sentinel = sentinelChat();
897
- const now = checking;
898
- const codebase = now !== undefined ? codebaseOf(now.work) : undefined;
899
- // Concluded, it is only saying so: nothing to carry on.
900
- if (sentinel === undefined || now === undefined || now.concluded === true || paused !== undefined || codebase === undefined || !codebases.includes(codebase))
901
- return;
902
- paused = now;
903
- inChat(sentinel.scope, () => record({ kind: "sentinel.paused", module: launch.codebase, launch: launch.id }, { project: cwd, ...("pulse" in now.work ? { job: now.work.pulse.id } : {}) }));
904
- void sentinel.session?.abort().catch(() => undefined);
905
- changed();
906
- void (async () => {
907
- await options.launches?.settled(codebase);
908
- // Let go meanwhile - closed, or given another conversation: nothing to carry on.
909
- if (paused !== now || !chats.includes(sentinel) || sentinel.instance === undefined) {
910
- if (paused === now)
911
- paused = undefined;
912
- return;
913
- }
914
- paused = undefined;
915
- const resumed = "pulse" in now.work ? { job: now.work.pulse } : { check: now.work.check };
916
- try {
917
- await sentinel.instance.resume(resumed);
918
- inChat(sentinel.scope, () => record({ kind: "sentinel.resumed", module: launch.codebase, launch: launch.id }, { project: cwd, ...("pulse" in now.work ? { job: now.work.pulse.id } : {}) }));
919
- }
920
- catch (error) {
921
- toSentinel(() => refuse(sentinel, now.work, error instanceof Error ? error.message : String(error)));
922
- }
923
- changed();
924
- })();
925
- }
926
- /**
927
- * The sentinel's chat given a new session, under the same id: what it does now stopped, and what it said let go - its
928
- * saved conversation deleted outside debug mode. The model and thinking it had carry over: what the person picked in
929
- * it stands. Shown in the terminal, the screen is drawn from the new one. A new session that cannot be made leaves it
930
- * the one it had.
931
- */
932
- async function freshConversation(chat) {
933
- const old = { session: chat.session, services: chat.services, instance: chat.instance };
934
- chat.unsubscribe?.();
935
- chat.unsubscribe = undefined;
936
- try {
937
- await old.session.abort();
938
- }
939
- catch {
940
- /* stopped already */
941
- }
942
- chat.working = false;
943
- const model = old.session.model;
944
- const thinking = old.session.thinkingLevel;
945
- // Made as a chat is opened, one at a time: its extension built while it is the one attaching.
946
- const made = opening.then(async () => {
947
- attaching = chat;
948
- try {
949
- await driver.create(chat, undefined);
950
- }
951
- finally {
952
- attaching = undefined;
953
- }
954
- });
955
- opening = made.catch(() => undefined);
956
- try {
957
- await made;
958
- }
959
- catch (error) {
960
- Object.assign(chat, old);
961
- follow(chat);
962
- sentinelMessage(`The sentinel goes on in the conversation it had - a new one could not be started: ${error instanceof Error ? error.message : String(error)}`, "warning");
963
- return;
964
- }
965
- const fresh = chat.session;
966
- try {
967
- if (model !== undefined && fresh.model !== model)
968
- await fresh.setModel(model);
969
- if (thinking !== undefined)
970
- fresh.setThinkingLevel(thinking);
971
- }
972
- catch {
973
- /* the model its session started on, then */
974
- }
975
- follow(chat);
976
- if (shownId === chat.id)
977
- await driver?.show?.(chat, undefined);
978
- try {
979
- old.session.dispose();
980
- }
981
- catch {
982
- /* let go already */
983
- }
984
- if (old.session.sessionFile !== undefined && old.session.sessionFile !== fresh.sessionFile)
985
- forgetSessionFile(old.session.sessionFile, { keep: debugMode(cwd) });
986
- try {
987
- host.onChatSession?.(chat.id, fresh);
988
- }
989
- catch {
990
- /* a host that throws still has the chat's new session in session(id) */
991
- }
992
- persist();
993
- changed();
994
- }
995
- return core;
996
- }
997
- /**
998
- * pi's extension API for a chat: every tool, command, shortcut and handler the extension registers runs inside the
999
- * chat's scope - its id on what it starts.
1000
- */
1001
- export function scopedToChat(pi, scope) {
1002
- const within = (work) => work === undefined ? undefined : (...args) => inChat(scope, () => work(...args));
1003
- return new Proxy(pi, {
1004
- get(target, key, receiver) {
1005
- if (key === "registerTool")
1006
- return (tool) => target.registerTool({ ...tool, execute: within(tool.execute) });
1007
- if (key === "registerCommand")
1008
- return (name, command) => target.registerCommand(name, { ...command, handler: within(command.handler) });
1009
- if (key === "registerShortcut")
1010
- return (shortcut, options) => target.registerShortcut(shortcut, { ...options, handler: within(options.handler) });
1011
- if (key === "on")
1012
- return (event, handler) => target.on(event, within(handler));
1013
- const value = Reflect.get(target, key, receiver);
1014
- return typeof value === "function" ? value.bind(target) : value;
1015
- },
1016
- });
1017
- }
1018
- /** A chat's stand-in for the screen, for the terminal's driver. */
1019
- export function terminalUi(chat, screen, onChange) {
1020
- chat.ui ??= createChatUi({ screen, onChange });
1021
- return chat.ui;
1022
- }