@turri-dev/cli 0.4.3-next.8482fed → 0.4.3-next.8c1b0fa

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