@turri-dev/cli 0.4.3-next.a60ada5 → 0.4.3-next.fd01774

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