@turri-dev/cli 0.4.2 → 0.4.3-next.4908c8d

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 (484) hide show
  1. package/README.md +24 -3
  2. package/dist/banner.js +259 -0
  3. package/dist/capture-cli.js +77 -0
  4. package/dist/capture-view.js +99 -0
  5. package/dist/chat-commands.js +9 -63
  6. package/dist/chat-models.js +17 -15
  7. package/dist/chat-tab-header.js +90 -0
  8. package/dist/chat-tabs.js +100 -0
  9. package/dist/chat-terminal.js +170 -61
  10. package/dist/chat-waiting.js +7 -24
  11. package/dist/cli-options.js +11 -7
  12. package/dist/cli-root.js +141 -0
  13. package/dist/cli.js +48 -36
  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 -3211
  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 -233
  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 +56 -0
  29. package/dist/pointer-hover.js +48 -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 +7 -18
  35. package/dist/regenerate/side-panel.js +158 -22
  36. package/dist/regenerate/spec-map-view.js +25 -70
  37. package/dist/regenerate-cli.js +7 -11
  38. package/dist/reopen.js +80 -0
  39. package/dist/resume-line.js +5 -2
  40. package/dist/skill-progress.js +25 -0
  41. package/dist/skill-report.js +52 -0
  42. package/dist/terminal-marks.js +21 -0
  43. package/dist/terminal-notifications.js +219 -0
  44. package/dist/terminal-view.js +275 -0
  45. package/dist/turri-versions.js +64 -6
  46. package/docs/README.md +4 -2
  47. package/docs/capture.md +227 -0
  48. package/docs/chats.md +14 -10
  49. package/docs/claude-subscription.md +1 -1
  50. package/docs/config.md +23 -8
  51. package/docs/development.md +30 -61
  52. package/docs/headless.md +3 -1
  53. package/docs/hosting.md +3 -251
  54. package/docs/installation.md +5 -3
  55. package/docs/launch.md +3 -3
  56. package/docs/regenerating.md +1 -1
  57. package/docs/sandbox.md +4 -2
  58. package/docs/sentinel.md +13 -13
  59. package/docs/theming.md +3 -3
  60. package/docs/using.md +14 -6
  61. package/package.json +15 -33
  62. package/dist/ask.d.ts +0 -90
  63. package/dist/ask.js +0 -170
  64. package/dist/background-skills.d.ts +0 -53
  65. package/dist/background-skills.js +0 -121
  66. package/dist/bedrock-region.d.ts +0 -66
  67. package/dist/bedrock-region.js +0 -144
  68. package/dist/brand.d.ts +0 -13
  69. package/dist/btw.d.ts +0 -69
  70. package/dist/btw.js +0 -174
  71. package/dist/chat-commands.d.ts +0 -25
  72. package/dist/chat-idle.d.ts +0 -7
  73. package/dist/chat-idle.js +0 -20
  74. package/dist/chat-models.d.ts +0 -22
  75. package/dist/chat-records.d.ts +0 -50
  76. package/dist/chat-records.js +0 -107
  77. package/dist/chat-scope.d.ts +0 -14
  78. package/dist/chat-scope.js +0 -15
  79. package/dist/chat-skills.d.ts +0 -17
  80. package/dist/chat-skills.js +0 -18
  81. package/dist/chat-terminal.d.ts +0 -24
  82. package/dist/chat-ui.d.ts +0 -33
  83. package/dist/chat-waiting.d.ts +0 -64
  84. package/dist/chats.d.ts +0 -338
  85. package/dist/chats.js +0 -996
  86. package/dist/cli-options.d.ts +0 -24
  87. package/dist/cli.d.ts +0 -9
  88. package/dist/config-edit.d.ts +0 -83
  89. package/dist/config-edit.js +0 -390
  90. package/dist/config.d.ts +0 -415
  91. package/dist/config.js +0 -757
  92. package/dist/conform-cli.d.ts +0 -1
  93. package/dist/conformance-switch.d.ts +0 -25
  94. package/dist/conformance-switch.js +0 -86
  95. package/dist/cultivate-cli.d.ts +0 -1
  96. package/dist/doctor-tool.d.ts +0 -11
  97. package/dist/doctor-tool.js +0 -33
  98. package/dist/drift-cli.d.ts +0 -1
  99. package/dist/environment.d.ts +0 -37
  100. package/dist/environment.js +0 -109
  101. package/dist/extension.d.ts +0 -208
  102. package/dist/genome.d.ts +0 -77
  103. package/dist/genome.js +0 -288
  104. package/dist/graph.d.ts +0 -52
  105. package/dist/graph.js +0 -247
  106. package/dist/host-session.d.ts +0 -112
  107. package/dist/host-session.js +0 -103
  108. package/dist/host.d.ts +0 -40
  109. package/dist/host.js +0 -54
  110. package/dist/identity.d.ts +0 -7
  111. package/dist/identity.js +0 -74
  112. package/dist/init-config.d.ts +0 -169
  113. package/dist/init-config.js +0 -840
  114. package/dist/installed-providers.d.ts +0 -40
  115. package/dist/installed-providers.js +0 -98
  116. package/dist/jellyfish.d.ts +0 -40
  117. package/dist/judge.d.ts +0 -25
  118. package/dist/judge.js +0 -62
  119. package/dist/launch-agent.d.ts +0 -62
  120. package/dist/launch-agent.js +0 -339
  121. package/dist/launch-cli.d.ts +0 -1
  122. package/dist/launch-session.d.ts +0 -68
  123. package/dist/launch-session.js +0 -225
  124. package/dist/launch-tools.d.ts +0 -28
  125. package/dist/launch-tools.js +0 -72
  126. package/dist/launch-track.d.ts +0 -175
  127. package/dist/launch-track.js +0 -497
  128. package/dist/lineage-cli.d.ts +0 -1
  129. package/dist/loop-cli.d.ts +0 -35
  130. package/dist/loop-tools.d.ts +0 -103
  131. package/dist/loop-tools.js +0 -357
  132. package/dist/model-check.d.ts +0 -72
  133. package/dist/model-check.js +0 -162
  134. package/dist/module-report.d.ts +0 -9
  135. package/dist/new-project.d.ts +0 -5
  136. package/dist/new-project.js +0 -31
  137. package/dist/notice.d.ts +0 -115
  138. package/dist/notice.js +0 -61
  139. package/dist/parse-cli.d.ts +0 -1
  140. package/dist/parse-tool.d.ts +0 -9
  141. package/dist/parse-tool.js +0 -33
  142. package/dist/pi-launch.d.ts +0 -1
  143. package/dist/pi-settings.d.ts +0 -4
  144. package/dist/pi.d.ts +0 -248
  145. package/dist/pi.js +0 -889
  146. package/dist/picture-row.d.ts +0 -10
  147. package/dist/plain/check.d.ts +0 -63
  148. package/dist/plain/check.js +0 -236
  149. package/dist/plain/concepts.d.ts +0 -37
  150. package/dist/plain/concepts.js +0 -283
  151. package/dist/plain/cycles.d.ts +0 -21
  152. package/dist/plain/cycles.js +0 -190
  153. package/dist/plain/errors.d.ts +0 -26
  154. package/dist/plain/errors.js +0 -50
  155. package/dist/plain/files.d.ts +0 -47
  156. package/dist/plain/files.js +0 -161
  157. package/dist/plain/graph.d.ts +0 -107
  158. package/dist/plain/graph.js +0 -194
  159. package/dist/plain/highlight.d.ts +0 -43
  160. package/dist/plain/highlight.js +0 -196
  161. package/dist/plain/index.d.ts +0 -18
  162. package/dist/plain/index.js +0 -18
  163. package/dist/plain/liquid.d.ts +0 -22
  164. package/dist/plain/liquid.js +0 -124
  165. package/dist/plain/markdown.d.ts +0 -103
  166. package/dist/plain/markdown.js +0 -330
  167. package/dist/plain/module-concepts.d.ts +0 -32
  168. package/dist/plain/module-concepts.js +0 -80
  169. package/dist/plain/parser.d.ts +0 -163
  170. package/dist/plain/parser.js +0 -930
  171. package/dist/plain/plain.tmLanguage.json +0 -150
  172. package/dist/plain/project.d.ts +0 -48
  173. package/dist/plain/project.js +0 -155
  174. package/dist/plain/spec.d.ts +0 -152
  175. package/dist/plain/spec.js +0 -265
  176. package/dist/plain/stdlib.d.ts +0 -16
  177. package/dist/plain/stdlib.js +0 -48
  178. package/dist/plain/test-plain-file.d.ts +0 -59
  179. package/dist/plain/test-plain-file.js +0 -232
  180. package/dist/plain-files.d.ts +0 -21
  181. package/dist/plain-files.js +0 -156
  182. package/dist/question-dialog.d.ts +0 -55
  183. package/dist/questioning.d.ts +0 -55
  184. package/dist/questioning.js +0 -109
  185. package/dist/quiet.d.ts +0 -34
  186. package/dist/regenerate/activity.d.ts +0 -227
  187. package/dist/regenerate/activity.js +0 -250
  188. package/dist/regenerate/agent-env.d.ts +0 -51
  189. package/dist/regenerate/agent-env.js +0 -311
  190. package/dist/regenerate/agent-shell.d.ts +0 -54
  191. package/dist/regenerate/agent-shell.js +0 -121
  192. package/dist/regenerate/arbiter.d.ts +0 -68
  193. package/dist/regenerate/arbiter.js +0 -133
  194. package/dist/regenerate/audit.d.ts +0 -69
  195. package/dist/regenerate/audit.js +0 -212
  196. package/dist/regenerate/base-folder.d.ts +0 -70
  197. package/dist/regenerate/base-folder.js +0 -186
  198. package/dist/regenerate/cases.d.ts +0 -12
  199. package/dist/regenerate/cases.js +0 -149
  200. package/dist/regenerate/change-view.d.ts +0 -23
  201. package/dist/regenerate/change-view.js +0 -153
  202. package/dist/regenerate/chunk-plan.d.ts +0 -217
  203. package/dist/regenerate/chunk-plan.js +0 -937
  204. package/dist/regenerate/codebase.d.ts +0 -21
  205. package/dist/regenerate/codebase.js +0 -75
  206. package/dist/regenerate/command-check.d.ts +0 -66
  207. package/dist/regenerate/command-check.js +0 -508
  208. package/dist/regenerate/compaction.d.ts +0 -13
  209. package/dist/regenerate/compaction.js +0 -20
  210. package/dist/regenerate/confine.d.ts +0 -69
  211. package/dist/regenerate/confine.js +0 -311
  212. package/dist/regenerate/conform.d.ts +0 -66
  213. package/dist/regenerate/conform.js +0 -132
  214. package/dist/regenerate/conformance-agents.d.ts +0 -388
  215. package/dist/regenerate/conformance-agents.js +0 -1162
  216. package/dist/regenerate/conformance.d.ts +0 -191
  217. package/dist/regenerate/conformance.js +0 -1035
  218. package/dist/regenerate/conversation-writes.d.ts +0 -10
  219. package/dist/regenerate/conversation-writes.js +0 -100
  220. package/dist/regenerate/credentials.d.ts +0 -18
  221. package/dist/regenerate/credentials.js +0 -88
  222. package/dist/regenerate/debug-log.d.ts +0 -56
  223. package/dist/regenerate/debug-log.js +0 -236
  224. package/dist/regenerate/debugger.d.ts +0 -36
  225. package/dist/regenerate/debugger.js +0 -133
  226. package/dist/regenerate/delivery.d.ts +0 -2
  227. package/dist/regenerate/diagnose-job.d.ts +0 -2
  228. package/dist/regenerate/diagnose-job.js +0 -40
  229. package/dist/regenerate/diagnose.d.ts +0 -46
  230. package/dist/regenerate/diagnose.js +0 -92
  231. package/dist/regenerate/diff-view.d.ts +0 -64
  232. package/dist/regenerate/drift.d.ts +0 -120
  233. package/dist/regenerate/drift.js +0 -285
  234. package/dist/regenerate/environment-error.d.ts +0 -167
  235. package/dist/regenerate/environment-error.js +0 -342
  236. package/dist/regenerate/failure-reports.d.ts +0 -28
  237. package/dist/regenerate/failure-reports.js +0 -79
  238. package/dist/regenerate/job-log.d.ts +0 -30
  239. package/dist/regenerate/job-log.js +0 -105
  240. package/dist/regenerate/job-panel.d.ts +0 -122
  241. package/dist/regenerate/job-panel.js +0 -339
  242. package/dist/regenerate/jobs-tree.d.ts +0 -75
  243. package/dist/regenerate/jobs.d.ts +0 -231
  244. package/dist/regenerate/jobs.js +0 -522
  245. package/dist/regenerate/lanes.d.ts +0 -16
  246. package/dist/regenerate/lanes.js +0 -32
  247. package/dist/regenerate/launch.d.ts +0 -256
  248. package/dist/regenerate/launch.js +0 -689
  249. package/dist/regenerate/ledger-view.d.ts +0 -87
  250. package/dist/regenerate/ledger-view.js +0 -325
  251. package/dist/regenerate/ledger.d.ts +0 -368
  252. package/dist/regenerate/ledger.js +0 -357
  253. package/dist/regenerate/lineage.d.ts +0 -105
  254. package/dist/regenerate/lineage.js +0 -485
  255. package/dist/regenerate/list-arguments.d.ts +0 -21
  256. package/dist/regenerate/list-arguments.js +0 -121
  257. package/dist/regenerate/loop.d.ts +0 -423
  258. package/dist/regenerate/loop.js +0 -2079
  259. package/dist/regenerate/masking.d.ts +0 -19
  260. package/dist/regenerate/masking.js +0 -95
  261. package/dist/regenerate/model-names.d.ts +0 -33
  262. package/dist/regenerate/model-names.js +0 -92
  263. package/dist/regenerate/notes.d.ts +0 -159
  264. package/dist/regenerate/notes.js +0 -446
  265. package/dist/regenerate/os-sandbox.d.ts +0 -93
  266. package/dist/regenerate/os-sandbox.js +0 -283
  267. package/dist/regenerate/panel-dock.d.ts +0 -23
  268. package/dist/regenerate/paths.d.ts +0 -110
  269. package/dist/regenerate/paths.js +0 -190
  270. package/dist/regenerate/plain-palette.d.ts +0 -34
  271. package/dist/regenerate/prompt.d.ts +0 -230
  272. package/dist/regenerate/prompt.js +0 -741
  273. package/dist/regenerate/pulse-files.d.ts +0 -14
  274. package/dist/regenerate/pulse-files.js +0 -63
  275. package/dist/regenerate/records.d.ts +0 -132
  276. package/dist/regenerate/records.js +0 -327
  277. package/dist/regenerate/regenerate.d.ts +0 -106
  278. package/dist/regenerate/regenerate.js +0 -660
  279. package/dist/regenerate/regression.d.ts +0 -58
  280. package/dist/regenerate/regression.js +0 -188
  281. package/dist/regenerate/renames.d.ts +0 -42
  282. package/dist/regenerate/renames.js +0 -185
  283. package/dist/regenerate/requires.d.ts +0 -117
  284. package/dist/regenerate/requires.js +0 -377
  285. package/dist/regenerate/resources.d.ts +0 -57
  286. package/dist/regenerate/resources.js +0 -162
  287. package/dist/regenerate/scripts-being-written.d.ts +0 -19
  288. package/dist/regenerate/scripts-being-written.js +0 -30
  289. package/dist/regenerate/self-check.d.ts +0 -29
  290. package/dist/regenerate/self-check.js +0 -119
  291. package/dist/regenerate/services.d.ts +0 -28
  292. package/dist/regenerate/services.js +0 -158
  293. package/dist/regenerate/shell.d.ts +0 -91
  294. package/dist/regenerate/shell.js +0 -320
  295. package/dist/regenerate/side-panel.d.ts +0 -59
  296. package/dist/regenerate/spec-map-view.d.ts +0 -139
  297. package/dist/regenerate/spec-map.d.ts +0 -160
  298. package/dist/regenerate/spec-map.js +0 -596
  299. package/dist/regenerate/spec-steps.d.ts +0 -180
  300. package/dist/regenerate/spec-steps.js +0 -729
  301. package/dist/regenerate/standing.d.ts +0 -28
  302. package/dist/regenerate/standing.js +0 -30
  303. package/dist/regenerate/state.d.ts +0 -21
  304. package/dist/regenerate/state.js +0 -10
  305. package/dist/regenerate/steering.d.ts +0 -56
  306. package/dist/regenerate/steering.js +0 -119
  307. package/dist/regenerate/stop-report.d.ts +0 -43
  308. package/dist/regenerate/stop-report.js +0 -160
  309. package/dist/regenerate/submit-work.d.ts +0 -44
  310. package/dist/regenerate/submit-work.js +0 -76
  311. package/dist/regenerate/test-kinds.d.ts +0 -85
  312. package/dist/regenerate/test-kinds.js +0 -171
  313. package/dist/regenerate/test-scripts.d.ts +0 -235
  314. package/dist/regenerate/test-scripts.js +0 -843
  315. package/dist/regenerate/testing-steps.d.ts +0 -52
  316. package/dist/regenerate/testing-steps.js +0 -129
  317. package/dist/regenerate/testing.d.ts +0 -150
  318. package/dist/regenerate/testing.js +0 -438
  319. package/dist/regenerate/transcript-view.d.ts +0 -21
  320. package/dist/regenerate/unit-gate.d.ts +0 -27
  321. package/dist/regenerate/unit-gate.js +0 -20
  322. package/dist/regenerate/unit-review.d.ts +0 -152
  323. package/dist/regenerate/unit-review.js +0 -361
  324. package/dist/regenerate/web.d.ts +0 -61
  325. package/dist/regenerate/web.js +0 -256
  326. package/dist/regenerate/workspace.d.ts +0 -12
  327. package/dist/regenerate/workspace.js +0 -99
  328. package/dist/regenerate-cli.d.ts +0 -1
  329. package/dist/resume-line.d.ts +0 -2
  330. package/dist/review/live.d.ts +0 -72
  331. package/dist/review/live.js +0 -166
  332. package/dist/rules.d.ts +0 -20
  333. package/dist/rules.js +0 -47
  334. package/dist/run-report.d.ts +0 -88
  335. package/dist/run-report.js +0 -338
  336. package/dist/screen-padding.d.ts +0 -28
  337. package/dist/self-invocation.d.ts +0 -36
  338. package/dist/self-invocation.js +0 -137
  339. package/dist/sentinel-chat.d.ts +0 -19
  340. package/dist/sentinel-chat.js +0 -221
  341. package/dist/sentinel-check.d.ts +0 -36
  342. package/dist/sentinel-check.js +0 -78
  343. package/dist/sentinel.d.ts +0 -107
  344. package/dist/sentinel.js +0 -599
  345. package/dist/settings.d.ts +0 -45
  346. package/dist/settings.js +0 -378
  347. package/dist/setup.d.ts +0 -97
  348. package/dist/setup.js +0 -428
  349. package/dist/skill-progress.d.ts +0 -46
  350. package/dist/skill.d.ts +0 -102
  351. package/dist/skill.js +0 -147
  352. package/dist/skills.d.ts +0 -54
  353. package/dist/skills.js +0 -111
  354. package/dist/spawn-async.d.ts +0 -18
  355. package/dist/spawn-async.js +0 -35
  356. package/dist/stack.d.ts +0 -80
  357. package/dist/stack.js +0 -206
  358. package/dist/stdlib.d.ts +0 -43
  359. package/dist/stdlib.js +0 -118
  360. package/dist/surface.d.ts +0 -5
  361. package/dist/surface.js +0 -18
  362. package/dist/terminal-images.d.ts +0 -2
  363. package/dist/test-plain-files.d.ts +0 -41
  364. package/dist/test-plain-files.js +0 -172
  365. package/dist/tools.d.ts +0 -101
  366. package/dist/tools.js +0 -242
  367. package/dist/turri-versions.d.ts +0 -71
  368. package/genome/rules/bullet-continuation.md +0 -61
  369. package/genome/rules/concise-specs-examples.md +0 -460
  370. package/genome/rules/concise-specs-integration-examples.md +0 -281
  371. package/genome/rules/concise-specs.md +0 -80
  372. package/genome/rules/definitions.md +0 -107
  373. package/genome/rules/examples/integration-embedded-testing/run_conformance_tests_java.sh +0 -161
  374. package/genome/rules/examples/integration-embedded-testing/run_unittests_java.sh +0 -50
  375. package/genome/rules/exported-concepts.md +0 -39
  376. package/genome/rules/func-specs.md +0 -164
  377. package/genome/rules/impl-reqs.md +0 -68
  378. package/genome/rules/import-modules.md +0 -49
  379. package/genome/rules/integration-embedded-testing.md +0 -273
  380. package/genome/rules/integration-embedded.md +0 -171
  381. package/genome/rules/integration-standalone.md +0 -135
  382. package/genome/rules/integrations.md +0 -136
  383. package/genome/rules/linked-resources.md +0 -76
  384. package/genome/rules/module-structure.md +0 -112
  385. package/genome/rules/project-model.md +0 -69
  386. package/genome/rules/required-concepts.md +0 -44
  387. package/genome/rules/requires-modules.md +0 -81
  388. package/genome/rules/semantic-ids.md +0 -49
  389. package/genome/rules/stdlib.md +0 -37
  390. package/genome/rules/test-plain-files.md +0 -138
  391. package/genome/rules/test-reqs.md +0 -57
  392. package/genome/rules/turri-regeneration.md +0 -66
  393. package/genome/skills/analyze-2-func-specs/SKILL.md +0 -116
  394. package/genome/skills/analyze-func-specs/SKILL.md +0 -137
  395. package/genome/skills/break-down-func-spec/SKILL.md +0 -229
  396. package/genome/skills/consolidate-concepts/SKILL.md +0 -192
  397. package/genome/skills/convert-old-syntax/SKILL.md +0 -68
  398. package/genome/skills/convert-old-syntax/references/rubric.md +0 -11
  399. package/genome/skills/debug-specs/SKILL.md +0 -194
  400. package/genome/skills/implement-conformance-testing-script/SKILL.md +0 -247
  401. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_cypress.ps1 +0 -337
  402. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_golang.ps1 +0 -111
  403. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_java.sh +0 -151
  404. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_python.ps1 +0 -103
  405. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_python.sh +0 -146
  406. package/genome/skills/implement-unit-testing-script/SKILL.md +0 -171
  407. package/genome/skills/implement-unit-testing-script/assets/run_unittests_flutter.ps1 +0 -87
  408. package/genome/skills/implement-unit-testing-script/assets/run_unittests_golang.ps1 +0 -73
  409. package/genome/skills/implement-unit-testing-script/assets/run_unittests_java.sh +0 -82
  410. package/genome/skills/implement-unit-testing-script/assets/run_unittests_python.ps1 +0 -81
  411. package/genome/skills/implement-unit-testing-script/assets/run_unittests_python.sh +0 -102
  412. package/genome/skills/implement-unit-testing-script/assets/run_unittests_react.ps1 +0 -87
  413. package/genome/skills/refactor-module/SKILL.md +0 -218
  414. package/genome/skills/resolve-section-ownership/SKILL.md +0 -64
  415. package/genome/skills/resolve-spec-conflict/SKILL.md +0 -102
  416. package/stdlib/backend/common.plain +0 -25
  417. package/stdlib/backend/conformance/common.plain +0 -12
  418. package/stdlib/backend/conformance/go-gin.plain +0 -9
  419. package/stdlib/backend/conformance/go-nethttp.plain +0 -9
  420. package/stdlib/backend/conformance/java-springboot.plain +0 -9
  421. package/stdlib/backend/conformance/python-django.plain +0 -9
  422. package/stdlib/backend/conformance/python-fastapi.plain +0 -9
  423. package/stdlib/backend/conformance/python-flask.plain +0 -9
  424. package/stdlib/backend/conformance/rust-axum.plain +0 -9
  425. package/stdlib/backend/conformance/typescript-express.plain +0 -9
  426. package/stdlib/backend/conformance/typescript-fastify.plain +0 -9
  427. package/stdlib/backend/conformance/typescript-nestjs.plain +0 -9
  428. package/stdlib/backend/go-gin.plain +0 -18
  429. package/stdlib/backend/go-nethttp.plain +0 -18
  430. package/stdlib/backend/java-springboot.plain +0 -19
  431. package/stdlib/backend/python-django.plain +0 -19
  432. package/stdlib/backend/python-fastapi.plain +0 -23
  433. package/stdlib/backend/python-flask.plain +0 -23
  434. package/stdlib/backend/rust-axum.plain +0 -17
  435. package/stdlib/backend/typescript-express.plain +0 -19
  436. package/stdlib/backend/typescript-fastify.plain +0 -19
  437. package/stdlib/backend/typescript-nestjs.plain +0 -19
  438. package/stdlib/cli/common.plain +0 -17
  439. package/stdlib/cli/conformance/common.plain +0 -11
  440. package/stdlib/cli/conformance/go-cobra.plain +0 -9
  441. package/stdlib/cli/conformance/go-flag.plain +0 -9
  442. package/stdlib/cli/conformance/java-picocli.plain +0 -9
  443. package/stdlib/cli/conformance/python-argparse.plain +0 -9
  444. package/stdlib/cli/conformance/python-click.plain +0 -9
  445. package/stdlib/cli/conformance/python-typer.plain +0 -9
  446. package/stdlib/cli/conformance/rust-clap.plain +0 -9
  447. package/stdlib/cli/conformance/typescript-commander.plain +0 -9
  448. package/stdlib/cli/go-cobra.plain +0 -14
  449. package/stdlib/cli/go-flag.plain +0 -14
  450. package/stdlib/cli/java-picocli.plain +0 -15
  451. package/stdlib/cli/python-argparse.plain +0 -18
  452. package/stdlib/cli/python-click.plain +0 -16
  453. package/stdlib/cli/python-typer.plain +0 -16
  454. package/stdlib/cli/rust-clap.plain +0 -14
  455. package/stdlib/cli/typescript-commander.plain +0 -17
  456. package/stdlib/frontend/angular.plain +0 -17
  457. package/stdlib/frontend/common.plain +0 -17
  458. package/stdlib/frontend/conformance/angular.plain +0 -5
  459. package/stdlib/frontend/conformance/common.plain +0 -11
  460. package/stdlib/frontend/conformance/react-vite.plain +0 -5
  461. package/stdlib/frontend/conformance/sveltekit-spa.plain +0 -5
  462. package/stdlib/frontend/conformance/vue-vite.plain +0 -5
  463. package/stdlib/frontend/react-vite.plain +0 -16
  464. package/stdlib/frontend/sveltekit-spa.plain +0 -16
  465. package/stdlib/frontend/vue-vite.plain +0 -16
  466. package/stdlib/lang/go.plain +0 -13
  467. package/stdlib/lang/java.plain +0 -12
  468. package/stdlib/lang/python.plain +0 -18
  469. package/stdlib/lang/rust.plain +0 -12
  470. package/stdlib/lang/typescript.plain +0 -13
  471. package/stdlib/library/common.plain +0 -15
  472. package/stdlib/library/conformance/common.plain +0 -9
  473. package/stdlib/library/conformance/go.plain +0 -9
  474. package/stdlib/library/conformance/java-gradle.plain +0 -9
  475. package/stdlib/library/conformance/java-maven.plain +0 -9
  476. package/stdlib/library/conformance/python.plain +0 -9
  477. package/stdlib/library/conformance/rust.plain +0 -9
  478. package/stdlib/library/conformance/typescript.plain +0 -9
  479. package/stdlib/library/go.plain +0 -12
  480. package/stdlib/library/java-gradle.plain +0 -13
  481. package/stdlib/library/java-maven.plain +0 -13
  482. package/stdlib/library/python.plain +0 -13
  483. package/stdlib/library/rust.plain +0 -12
  484. 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
- }