@qvac/core 1.0.0-rc.0 → 1.0.0-rc.10

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 (579) hide show
  1. package/CHANGELOG.md +1203 -1
  2. package/README.md +56 -45
  3. package/dist-lib/index.d.ts +3 -2
  4. package/dist-lib/index.js +1 -1
  5. package/dist-lib/lib/api/agent-folders.d.ts +22 -0
  6. package/dist-lib/lib/api/agent-folders.js +115 -0
  7. package/dist-lib/lib/api/agents.d.ts +20 -2
  8. package/dist-lib/lib/api/agents.js +128 -24
  9. package/dist-lib/lib/api/app-config.d.ts +7 -1
  10. package/dist-lib/lib/api/app-config.js +37 -6
  11. package/dist-lib/lib/api/approval-rules.d.ts +1 -1
  12. package/dist-lib/lib/api/approval-rules.js +12 -5
  13. package/dist-lib/lib/api/attachments.d.ts +1 -1
  14. package/dist-lib/lib/api/attachments.js +14 -2
  15. package/dist-lib/lib/api/chat-move.d.ts +4 -0
  16. package/dist-lib/lib/api/chat-move.js +7 -0
  17. package/dist-lib/lib/api/chat.d.ts +12 -2
  18. package/dist-lib/lib/api/chat.js +100 -9
  19. package/dist-lib/lib/api/chunk-delta.d.ts +12 -0
  20. package/dist-lib/lib/api/chunk-delta.js +115 -0
  21. package/dist-lib/lib/api/chunks.d.ts +19 -2
  22. package/dist-lib/lib/api/chunks.js +73 -13
  23. package/dist-lib/lib/api/config.d.ts +11 -3
  24. package/dist-lib/lib/api/config.js +51 -5
  25. package/dist-lib/lib/api/current-mesh.d.ts +13 -5
  26. package/dist-lib/lib/api/current-mesh.js +15 -11
  27. package/dist-lib/lib/api/custom-models.d.ts +7 -1
  28. package/dist-lib/lib/api/custom-models.js +12 -12
  29. package/dist-lib/lib/api/device-routes.d.ts +14 -0
  30. package/dist-lib/lib/api/device-routes.js +144 -0
  31. package/dist-lib/lib/api/devices.d.ts +3 -2
  32. package/dist-lib/lib/api/devices.js +28 -28
  33. package/dist-lib/lib/api/diagnostics.d.ts +2 -1
  34. package/dist-lib/lib/api/diagnostics.js +2 -2
  35. package/dist-lib/lib/api/execution.d.ts +16 -1
  36. package/dist-lib/lib/api/execution.js +72 -16
  37. package/dist-lib/lib/api/files.d.ts +1 -1
  38. package/dist-lib/lib/api/files.js +65 -8
  39. package/dist-lib/lib/api/host-run-log.d.ts +2 -41
  40. package/dist-lib/lib/api/host-run-log.js +35 -83
  41. package/dist-lib/lib/api/index.d.ts +39 -7
  42. package/dist-lib/lib/api/index.js +116 -36
  43. package/dist-lib/lib/api/instrument.d.ts +2 -2
  44. package/dist-lib/lib/api/instrument.js +24 -48
  45. package/dist-lib/lib/api/knowledge.d.ts +4 -1
  46. package/dist-lib/lib/api/knowledge.js +25 -7
  47. package/dist-lib/lib/api/local-files.d.ts +5 -1
  48. package/dist-lib/lib/api/local-files.js +9 -5
  49. package/dist-lib/lib/api/logs.js +3 -3
  50. package/dist-lib/lib/api/members.d.ts +10 -1
  51. package/dist-lib/lib/api/members.js +69 -44
  52. package/dist-lib/lib/api/mesh.d.ts +15 -6
  53. package/dist-lib/lib/api/mesh.js +13 -9
  54. package/dist-lib/lib/api/model-download.d.ts +2 -1
  55. package/dist-lib/lib/api/model-download.js +2 -2
  56. package/dist-lib/lib/api/network.d.ts +10 -2
  57. package/dist-lib/lib/api/network.js +8 -2
  58. package/dist-lib/lib/api/notifications.d.ts +3 -1
  59. package/dist-lib/lib/api/notifications.js +14 -9
  60. package/dist-lib/lib/api/projects.d.ts +20 -0
  61. package/dist-lib/lib/api/projects.js +172 -0
  62. package/dist-lib/lib/api/rag-plugin.d.ts +17 -0
  63. package/dist-lib/lib/api/rag-plugin.js +44 -0
  64. package/dist-lib/lib/api/rag.d.ts +0 -1
  65. package/dist-lib/lib/api/rag.js +106 -33
  66. package/dist-lib/lib/api/served.d.ts +17 -0
  67. package/dist-lib/lib/api/served.js +65 -0
  68. package/dist-lib/lib/api/sync.d.ts +2 -1
  69. package/dist-lib/lib/api/sync.js +13 -3
  70. package/dist-lib/lib/api/tool-activity.d.ts +2 -1
  71. package/dist-lib/lib/api/tool-activity.js +4 -3
  72. package/dist-lib/lib/api/tool-configs.d.ts +2 -1
  73. package/dist-lib/lib/api/tool-configs.js +6 -9
  74. package/dist-lib/lib/api/upload-frames.d.ts +0 -1
  75. package/dist-lib/lib/api/upload-frames.js +0 -1
  76. package/dist-lib/lib/api/watchable.d.ts +3 -2
  77. package/dist-lib/lib/api/watchable.js +2 -3
  78. package/dist-lib/lib/api/workspace.d.ts +12 -0
  79. package/dist-lib/lib/api/workspace.js +61 -0
  80. package/dist-lib/lib/assistant/fake-models.d.ts +20 -0
  81. package/dist-lib/lib/assistant/fake-models.js +112 -0
  82. package/dist-lib/lib/assistant/harness.d.ts +48 -31
  83. package/dist-lib/lib/assistant/harness.js +51 -10
  84. package/dist-lib/lib/assistant/history.d.ts +37 -17
  85. package/dist-lib/lib/assistant/history.js +212 -87
  86. package/dist-lib/lib/assistant/host-run-log.d.ts +6 -1
  87. package/dist-lib/lib/assistant/host-run-log.js +24 -36
  88. package/dist-lib/lib/assistant/media-round.d.ts +61 -0
  89. package/dist-lib/lib/assistant/media-round.js +111 -0
  90. package/dist-lib/lib/assistant/message.d.ts +28 -1
  91. package/dist-lib/lib/assistant/message.js +65 -2
  92. package/dist-lib/lib/assistant/model-round.d.ts +118 -0
  93. package/dist-lib/lib/assistant/model-round.js +706 -0
  94. package/dist-lib/lib/assistant/pdf-budget.d.ts +11 -0
  95. package/dist-lib/lib/assistant/pdf-budget.js +12 -0
  96. package/dist-lib/lib/assistant/pdf-pages.d.ts +25 -0
  97. package/dist-lib/lib/assistant/pdf-pages.js +75 -0
  98. package/dist-lib/lib/assistant/round-host.d.ts +65 -0
  99. package/dist-lib/lib/assistant/round-host.js +332 -0
  100. package/dist-lib/lib/assistant/skill-encode.d.ts +2 -1
  101. package/dist-lib/lib/assistant/skill-encode.js +2 -1
  102. package/dist-lib/lib/assistant/upload.d.ts +12 -0
  103. package/dist-lib/lib/assistant/upload.js +36 -0
  104. package/dist-lib/lib/assistant/video-budget.d.ts +13 -0
  105. package/dist-lib/lib/assistant/video-budget.js +29 -0
  106. package/dist-lib/lib/assistant-client.d.ts +5 -1
  107. package/dist-lib/lib/assistant-client.js +54 -14
  108. package/dist-lib/lib/assistant-tree.d.ts +14 -3
  109. package/dist-lib/lib/assistant-tree.js +113 -21
  110. package/dist-lib/lib/assistant.d.ts +115 -25
  111. package/dist-lib/lib/assistant.js +2409 -1245
  112. package/dist-lib/lib/audio-format.js +1 -1
  113. package/dist-lib/lib/chat-suggestion.d.ts +3 -0
  114. package/dist-lib/lib/chat-suggestion.js +47 -0
  115. package/dist-lib/lib/client.d.ts +3 -2
  116. package/dist-lib/lib/client.js +18 -3
  117. package/dist-lib/lib/compaction.d.ts +3 -1
  118. package/dist-lib/lib/compaction.js +18 -4
  119. package/dist-lib/lib/constants.d.ts +10 -0
  120. package/dist-lib/lib/constants.js +10 -0
  121. package/dist-lib/lib/core/agent-copies.d.ts +9 -0
  122. package/dist-lib/lib/core/agent-copies.js +47 -0
  123. package/dist-lib/lib/core/agent-hosting.d.ts +25 -0
  124. package/dist-lib/lib/core/agent-hosting.js +76 -0
  125. package/dist-lib/lib/core/agent.d.ts +9 -1
  126. package/dist-lib/lib/core/agent.js +58 -63
  127. package/dist-lib/lib/core/approval-rules.d.ts +5 -1
  128. package/dist-lib/lib/core/approval-rules.js +17 -9
  129. package/dist-lib/lib/core/archived-mesh.d.ts +14 -7
  130. package/dist-lib/lib/core/archived-mesh.js +75 -59
  131. package/dist-lib/lib/core/async-iterable.js +1 -1
  132. package/dist-lib/lib/core/blind-peers.d.ts +1 -0
  133. package/dist-lib/lib/core/blind-peers.js +1 -0
  134. package/dist-lib/lib/core/chat-activity.d.ts +1 -1
  135. package/dist-lib/lib/core/chat-activity.js +45 -34
  136. package/dist-lib/lib/core/chat-copy.d.ts +42 -0
  137. package/dist-lib/lib/core/chat-copy.js +404 -0
  138. package/dist-lib/lib/core/chat-fork.d.ts +16 -0
  139. package/dist-lib/lib/core/chat-fork.js +246 -0
  140. package/dist-lib/lib/core/chat-group.js +10 -22
  141. package/dist-lib/lib/core/chat-move.d.ts +77 -0
  142. package/dist-lib/lib/core/chat-move.js +601 -0
  143. package/dist-lib/lib/core/chat-order.d.ts +2 -1
  144. package/dist-lib/lib/core/chat-order.js +28 -19
  145. package/dist-lib/lib/core/chat-read.d.ts +4 -0
  146. package/dist-lib/lib/core/chat-read.js +49 -0
  147. package/dist-lib/lib/core/chat-search.js +14 -12
  148. package/dist-lib/lib/core/chat.d.ts +32 -4
  149. package/dist-lib/lib/core/chat.js +135 -61
  150. package/dist-lib/lib/core/chunk.d.ts +35 -7
  151. package/dist-lib/lib/core/chunk.js +271 -72
  152. package/dist-lib/lib/core/collections.d.ts +41 -1
  153. package/dist-lib/lib/core/collections.js +41 -1
  154. package/dist-lib/lib/core/config-value.d.ts +7 -0
  155. package/dist-lib/lib/core/config-value.js +15 -0
  156. package/dist-lib/lib/core/contract/activity.d.ts +7 -2
  157. package/dist-lib/lib/core/contract/activity.js +71 -23
  158. package/dist-lib/lib/core/contract/agent-join.d.ts +10 -0
  159. package/dist-lib/lib/core/contract/agent-join.js +104 -0
  160. package/dist-lib/lib/core/contract/agents.d.ts +5 -0
  161. package/dist-lib/lib/core/contract/agents.js +142 -3
  162. package/dist-lib/lib/core/contract/chat.d.ts +4 -0
  163. package/dist-lib/lib/core/contract/chat.js +53 -3
  164. package/dist-lib/lib/core/contract/chunks.d.ts +7 -0
  165. package/dist-lib/lib/core/contract/chunks.js +125 -38
  166. package/dist-lib/lib/core/contract/devices.js +6 -4
  167. package/dist-lib/lib/core/contract/index.d.ts +2 -3
  168. package/dist-lib/lib/core/contract/index.js +38 -11
  169. package/dist-lib/lib/core/contract/indexing.d.ts +1 -0
  170. package/dist-lib/lib/core/contract/indexing.js +51 -7
  171. package/dist-lib/lib/core/contract/invites.d.ts +3 -14
  172. package/dist-lib/lib/core/contract/invites.js +26 -36
  173. package/dist-lib/lib/core/contract/joined-meshes.js +4 -1
  174. package/dist-lib/lib/core/contract/knowledge.d.ts +1 -0
  175. package/dist-lib/lib/core/contract/knowledge.js +57 -6
  176. package/dist-lib/lib/core/contract/members.d.ts +3 -1
  177. package/dist-lib/lib/core/contract/members.js +48 -12
  178. package/dist-lib/lib/core/contract/mesh-kind.d.ts +3 -3
  179. package/dist-lib/lib/core/contract/mesh-kind.js +20 -16
  180. package/dist-lib/lib/core/contract/mesh-name.d.ts +3 -0
  181. package/dist-lib/lib/core/contract/mesh-name.js +31 -0
  182. package/dist-lib/lib/core/contract/mesh-rules.d.ts +8 -0
  183. package/dist-lib/lib/core/contract/mesh-rules.js +35 -0
  184. package/dist-lib/lib/core/contract/mesh-seeds.d.ts +2 -0
  185. package/dist-lib/lib/core/contract/mesh-seeds.js +26 -0
  186. package/dist-lib/lib/core/contract/model-requests.d.ts +26 -0
  187. package/dist-lib/lib/core/contract/model-requests.js +280 -0
  188. package/dist-lib/lib/core/contract/oldest-version.d.ts +9 -0
  189. package/dist-lib/lib/core/contract/oldest-version.js +20 -0
  190. package/dist-lib/lib/core/contract/open-join.d.ts +2 -0
  191. package/dist-lib/lib/core/contract/open-join.js +77 -0
  192. package/dist-lib/lib/core/contract/project-device-keys.d.ts +9 -0
  193. package/dist-lib/lib/core/contract/project-device-keys.js +38 -0
  194. package/dist-lib/lib/core/contract/project-host-keys.d.ts +9 -0
  195. package/dist-lib/lib/core/contract/project-host-keys.js +52 -0
  196. package/dist-lib/lib/core/contract/project-order.d.ts +2 -0
  197. package/dist-lib/lib/core/contract/project-order.js +25 -0
  198. package/dist-lib/lib/core/contract/projects.d.ts +23 -0
  199. package/dist-lib/lib/core/contract/projects.js +339 -0
  200. package/dist-lib/lib/core/contract/public-mesh.d.ts +3 -0
  201. package/dist-lib/lib/core/contract/public-mesh.js +31 -0
  202. package/dist-lib/lib/core/contract/public-seeds.d.ts +9 -0
  203. package/dist-lib/lib/core/contract/public-seeds.js +43 -0
  204. package/dist-lib/lib/core/contract/roles.d.ts +10 -0
  205. package/dist-lib/lib/core/contract/roles.js +123 -0
  206. package/dist-lib/lib/core/contract/run-requests.d.ts +11 -0
  207. package/dist-lib/lib/core/contract/run-requests.js +114 -0
  208. package/dist-lib/lib/core/contract/seed-defaults.d.ts +3 -1
  209. package/dist-lib/lib/core/contract/seed-defaults.js +17 -4
  210. package/dist-lib/lib/core/contract/shipped-rows.d.ts +2 -0
  211. package/dist-lib/lib/core/contract/shipped-rows.js +22 -0
  212. package/dist-lib/lib/core/contract/skill-secrets.d.ts +3 -0
  213. package/dist-lib/lib/core/contract/skill-secrets.js +32 -0
  214. package/dist-lib/lib/core/contract/tool-activity.js +12 -1
  215. package/dist-lib/lib/core/contract/tool-configs.js +2 -1
  216. package/dist-lib/lib/core/contract/types.d.ts +2 -2
  217. package/dist-lib/lib/core/contract/workspace.d.ts +31 -0
  218. package/dist-lib/lib/core/contract/workspace.js +311 -0
  219. package/dist-lib/lib/core/contract/writers.js +100 -16
  220. package/dist-lib/lib/core/deleted-agent-runs.d.ts +8 -0
  221. package/dist-lib/lib/core/deleted-agent-runs.js +57 -0
  222. package/dist-lib/lib/core/departures.d.ts +18 -5
  223. package/dist-lib/lib/core/departures.js +82 -6
  224. package/dist-lib/lib/core/device-control.d.ts +21 -0
  225. package/dist-lib/lib/core/device-control.js +91 -0
  226. package/dist-lib/lib/core/device-seal.d.ts +4 -0
  227. package/dist-lib/lib/core/device-seal.js +22 -0
  228. package/dist-lib/lib/core/devices.d.ts +2 -1
  229. package/dist-lib/lib/core/devices.js +6 -11
  230. package/dist-lib/lib/core/document-attachment.d.ts +10 -0
  231. package/dist-lib/lib/core/document-attachment.js +14 -0
  232. package/dist-lib/lib/core/files/attachments.d.ts +2 -0
  233. package/dist-lib/lib/core/files/attachments.js +23 -7
  234. package/dist-lib/lib/core/files/index.d.ts +28 -15
  235. package/dist-lib/lib/core/files/index.js +222 -43
  236. package/dist-lib/lib/core/files/knowledge.d.ts +10 -1
  237. package/dist-lib/lib/core/files/knowledge.js +77 -5
  238. package/dist-lib/lib/core/files/preview/index.js +6 -2
  239. package/dist-lib/lib/core/files/processing/claims.d.ts +7 -0
  240. package/dist-lib/lib/core/files/processing/claims.js +33 -7
  241. package/dist-lib/lib/core/files/processing/document.d.ts +8 -0
  242. package/dist-lib/lib/core/files/processing/document.js +26 -2
  243. package/dist-lib/lib/core/files/processing/index.d.ts +12 -3
  244. package/dist-lib/lib/core/files/processing/index.js +122 -73
  245. package/dist-lib/lib/core/files/processing/protocol.d.ts +7 -1
  246. package/dist-lib/lib/core/files/processing/protocol.js +27 -37
  247. package/dist-lib/lib/core/files/processing/source.d.ts +4 -0
  248. package/dist-lib/lib/core/files/processing/source.js +12 -4
  249. package/dist-lib/lib/core/files/processing/state.d.ts +5 -1
  250. package/dist-lib/lib/core/files/processing/state.js +9 -1
  251. package/dist-lib/lib/core/files/rag/build.d.ts +15 -2
  252. package/dist-lib/lib/core/files/rag/build.js +119 -21
  253. package/dist-lib/lib/core/files/rag/failure.d.ts +20 -0
  254. package/dist-lib/lib/core/files/rag/failure.js +58 -0
  255. package/dist-lib/lib/core/files/rag/index.d.ts +21 -5
  256. package/dist-lib/lib/core/files/rag/index.js +38 -9
  257. package/dist-lib/lib/core/files/rag/joined-index.d.ts +6 -0
  258. package/dist-lib/lib/core/files/rag/joined-index.js +35 -0
  259. package/dist-lib/lib/core/files/rag/limits.d.ts +1 -0
  260. package/dist-lib/lib/core/files/rag/limits.js +1 -0
  261. package/dist-lib/lib/core/files/rag/load.d.ts +3 -3
  262. package/dist-lib/lib/core/files/rag/load.js +6 -3
  263. package/dist-lib/lib/core/files/rag/plugin-index.d.ts +32 -0
  264. package/dist-lib/lib/core/files/rag/plugin-index.js +120 -0
  265. package/dist-lib/lib/core/files/rag/policy.d.ts +10 -1
  266. package/dist-lib/lib/core/files/rag/policy.js +23 -2
  267. package/dist-lib/lib/core/files/rag/produce.d.ts +3 -4
  268. package/dist-lib/lib/core/files/rag/produce.js +31 -18
  269. package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +2 -0
  270. package/dist-lib/lib/core/files/rag/retrieval/full-text.js +8 -2
  271. package/dist-lib/lib/core/files/rag/similarity.d.ts +2 -2
  272. package/dist-lib/lib/core/files/rag/similarity.js +2 -3
  273. package/dist-lib/lib/core/files/records/chunks.js +22 -1
  274. package/dist-lib/lib/core/files/records/index.d.ts +1 -1
  275. package/dist-lib/lib/core/files/records/index.js +1 -1
  276. package/dist-lib/lib/core/files/records/knowledge.d.ts +12 -4
  277. package/dist-lib/lib/core/files/records/knowledge.js +34 -30
  278. package/dist-lib/lib/core/files/records/purge.js +13 -8
  279. package/dist-lib/lib/core/files/records/reclaim.js +21 -55
  280. package/dist-lib/lib/core/files/records/routing.d.ts +1 -1
  281. package/dist-lib/lib/core/files/records/routing.js +6 -2
  282. package/dist-lib/lib/core/files/records/source.js +3 -5
  283. package/dist-lib/lib/core/files/records/sweep.d.ts +3 -0
  284. package/dist-lib/lib/core/files/records/sweep.js +9 -3
  285. package/dist-lib/lib/core/files/store/blob.d.ts +2 -0
  286. package/dist-lib/lib/core/files/store/blob.js +2 -2
  287. package/dist-lib/lib/core/files/store/index.d.ts +3 -1
  288. package/dist-lib/lib/core/files/store/index.js +4 -1
  289. package/dist-lib/lib/core/files/store/reference.d.ts +3 -0
  290. package/dist-lib/lib/core/files/store/reference.js +12 -2
  291. package/dist-lib/lib/core/files/store/sweep.js +3 -1
  292. package/dist-lib/lib/core/files/upload.d.ts +5 -1
  293. package/dist-lib/lib/core/files/upload.js +117 -51
  294. package/dist-lib/lib/core/first-event.d.ts +6 -0
  295. package/dist-lib/lib/core/first-event.js +13 -0
  296. package/dist-lib/lib/core/fs-drives.d.ts +6 -3
  297. package/dist-lib/lib/core/fs-drives.js +35 -35
  298. package/dist-lib/lib/core/helpers/index.d.ts +1 -1
  299. package/dist-lib/lib/core/helpers/index.js +2 -2
  300. package/dist-lib/lib/core/id.d.ts +1 -0
  301. package/dist-lib/lib/core/id.js +3 -0
  302. package/dist-lib/lib/core/identity.d.ts +3 -1
  303. package/dist-lib/lib/core/identity.js +25 -4
  304. package/dist-lib/lib/core/invite.d.ts +6 -2
  305. package/dist-lib/lib/core/invite.js +22 -8
  306. package/dist-lib/lib/core/local/files.d.ts +2 -1
  307. package/dist-lib/lib/core/local/files.js +5 -7
  308. package/dist-lib/lib/core/local/index.d.ts +93 -8
  309. package/dist-lib/lib/core/local/index.js +327 -28
  310. package/dist-lib/lib/core/local/run-logs.d.ts +38 -0
  311. package/dist-lib/lib/core/local/run-logs.js +132 -0
  312. package/dist-lib/lib/core/member-key.d.ts +7 -0
  313. package/dist-lib/lib/core/member-key.js +24 -0
  314. package/dist-lib/lib/core/membership.d.ts +3 -14
  315. package/dist-lib/lib/core/membership.js +3 -96
  316. package/dist-lib/lib/core/mesh.d.ts +132 -29
  317. package/dist-lib/lib/core/mesh.js +775 -215
  318. package/dist-lib/lib/core/migrations/agent-catalog.js +2 -8
  319. package/dist-lib/lib/core/migrations/agent-tools-scope.d.ts +2 -0
  320. package/dist-lib/lib/core/migrations/agent-tools-scope.js +18 -0
  321. package/dist-lib/lib/core/migrations/chat-chunks.d.ts +4 -0
  322. package/dist-lib/lib/core/migrations/chat-chunks.js +47 -0
  323. package/dist-lib/lib/core/migrations/file-index.d.ts +1 -1
  324. package/dist-lib/lib/core/migrations/file-index.js +8 -6
  325. package/dist-lib/lib/core/migrations/index.d.ts +2 -1
  326. package/dist-lib/lib/core/migrations/index.js +69 -8
  327. package/dist-lib/lib/core/migrations/writer-links.d.ts +3 -0
  328. package/dist-lib/lib/core/migrations/writer-links.js +30 -0
  329. package/dist-lib/lib/core/model-requests.d.ts +13 -0
  330. package/dist-lib/lib/core/model-requests.js +65 -0
  331. package/dist-lib/lib/core/next-frame.js +2 -1
  332. package/dist-lib/lib/core/notification.js +100 -25
  333. package/dist-lib/lib/core/pdf/figure.d.ts +22 -0
  334. package/dist-lib/lib/core/pdf/figure.js +64 -0
  335. package/dist-lib/lib/core/pdf/rasterize.d.ts +12 -3
  336. package/dist-lib/lib/core/pdf/rasterize.js +77 -28
  337. package/dist-lib/lib/core/peer-duplex.d.ts +34 -0
  338. package/dist-lib/lib/core/{harness-loan.js → peer-duplex.js} +104 -45
  339. package/dist-lib/lib/core/project-keys.d.ts +16 -0
  340. package/dist-lib/lib/core/project-keys.js +65 -0
  341. package/dist-lib/lib/core/prompt-history.js +4 -4
  342. package/dist-lib/lib/core/protocol-pairing.d.ts +11 -0
  343. package/dist-lib/lib/core/protocol-pairing.js +22 -0
  344. package/dist-lib/lib/core/public-mesh.d.ts +25 -0
  345. package/dist-lib/lib/core/public-mesh.js +81 -0
  346. package/dist-lib/lib/core/purge.d.ts +3 -0
  347. package/dist-lib/lib/core/purge.js +7 -0
  348. package/dist-lib/lib/core/run-driver.d.ts +17 -0
  349. package/dist-lib/lib/core/run-driver.js +20 -0
  350. package/dist-lib/lib/core/run-requests.d.ts +14 -0
  351. package/dist-lib/lib/core/run-requests.js +78 -0
  352. package/dist-lib/lib/core/send.d.ts +2 -0
  353. package/dist-lib/lib/core/send.js +17 -4
  354. package/dist-lib/lib/core/senders.d.ts +19 -0
  355. package/dist-lib/lib/core/senders.js +45 -0
  356. package/dist-lib/lib/core/shared-agents.d.ts +40 -0
  357. package/dist-lib/lib/core/shared-agents.js +283 -0
  358. package/dist-lib/lib/core/skill-availability.d.ts +33 -0
  359. package/dist-lib/lib/core/skill-availability.js +67 -0
  360. package/dist-lib/lib/core/skill-secrets.d.ts +13 -18
  361. package/dist-lib/lib/core/skill-secrets.js +93 -72
  362. package/dist-lib/lib/core/sync/background.d.ts +34 -0
  363. package/dist-lib/lib/core/sync/background.js +86 -0
  364. package/dist-lib/lib/core/sync/changed.d.ts +20 -0
  365. package/dist-lib/lib/core/sync/changed.js +7 -0
  366. package/dist-lib/lib/core/sync/devices.js +6 -3
  367. package/dist-lib/lib/core/sync/files.d.ts +1 -0
  368. package/dist-lib/lib/core/sync/files.js +50 -72
  369. package/dist-lib/lib/core/sync/index.d.ts +1 -1
  370. package/dist-lib/lib/core/sync/index.js +193 -81
  371. package/dist-lib/lib/core/sync/view-updates.d.ts +39 -0
  372. package/dist-lib/lib/core/sync/view-updates.js +124 -0
  373. package/dist-lib/lib/core/sync-status.js +99 -43
  374. package/dist-lib/lib/core/system-info.d.ts +2 -2
  375. package/dist-lib/lib/core/system-info.js +10 -11
  376. package/dist-lib/lib/core/tool-activity.js +6 -12
  377. package/dist-lib/lib/core/tool-configs.d.ts +5 -3
  378. package/dist-lib/lib/core/tool-configs.js +27 -39
  379. package/dist-lib/lib/core/transcript-visibility.d.ts +5 -5
  380. package/dist-lib/lib/core/transcript-visibility.js +27 -31
  381. package/dist-lib/lib/core/upgrade-agents.d.ts +11 -0
  382. package/dist-lib/lib/core/upgrade-agents.js +78 -0
  383. package/dist-lib/lib/core/upgrade-summary.d.ts +19 -0
  384. package/dist-lib/lib/core/upgrade-summary.js +67 -0
  385. package/dist-lib/lib/core/vault-managed-skills.d.ts +18 -0
  386. package/dist-lib/lib/core/vault-managed-skills.js +105 -0
  387. package/dist-lib/lib/core/video/attachment.d.ts +1 -0
  388. package/dist-lib/lib/core/video/attachment.js +7 -0
  389. package/dist-lib/lib/core/video/digest.d.ts +16 -0
  390. package/dist-lib/lib/core/video/digest.js +57 -0
  391. package/dist-lib/lib/core/video/frames.d.ts +32 -0
  392. package/dist-lib/lib/core/video/frames.js +224 -0
  393. package/dist-lib/lib/core/view-read.d.ts +4 -0
  394. package/dist-lib/lib/core/view-read.js +23 -0
  395. package/dist-lib/lib/core/workspace-upgrade.d.ts +23 -0
  396. package/dist-lib/lib/core/workspace-upgrade.js +51 -0
  397. package/dist-lib/lib/core.d.ts +345 -88
  398. package/dist-lib/lib/core.js +4275 -1513
  399. package/dist-lib/lib/credential-pusher.d.ts +17 -7
  400. package/dist-lib/lib/credential-pusher.js +111 -62
  401. package/dist-lib/lib/custom-model-pusher.d.ts +2 -4
  402. package/dist-lib/lib/custom-model-task.d.ts +2 -1
  403. package/dist-lib/lib/custom-model-task.js +2 -2
  404. package/dist-lib/lib/device-tree.d.ts +18 -0
  405. package/dist-lib/lib/device-tree.js +32 -0
  406. package/dist-lib/lib/diagnostics.d.ts +7 -0
  407. package/dist-lib/lib/diagnostics.js +22 -0
  408. package/dist-lib/lib/doctor/checks.d.ts +15 -0
  409. package/dist-lib/lib/doctor/checks.js +272 -0
  410. package/dist-lib/lib/doctor/redact.d.ts +4 -0
  411. package/dist-lib/lib/doctor/redact.js +31 -0
  412. package/dist-lib/lib/doctor/render.d.ts +8 -0
  413. package/dist-lib/lib/doctor/render.js +83 -0
  414. package/dist-lib/lib/doctor/tree.d.ts +5 -0
  415. package/dist-lib/lib/doctor/tree.js +167 -0
  416. package/dist-lib/lib/downloads-allowed-pusher.d.ts +8 -0
  417. package/dist-lib/lib/downloads-allowed-pusher.js +37 -0
  418. package/dist-lib/lib/errors.d.ts +814 -0
  419. package/dist-lib/lib/errors.js +748 -0
  420. package/dist-lib/lib/fs-drive-bridge.d.ts +8 -1
  421. package/dist-lib/lib/fs-drive-bridge.js +312 -31
  422. package/dist-lib/lib/guards.d.ts +1 -0
  423. package/dist-lib/lib/guards.js +4 -0
  424. package/dist-lib/lib/inference-calls.d.ts +1 -2
  425. package/dist-lib/lib/inference-calls.js +2 -10
  426. package/dist-lib/lib/integrations/setup-routes.js +7 -5
  427. package/dist-lib/lib/knowledge-search.d.ts +1 -1
  428. package/dist-lib/lib/knowledge-search.js +5 -51
  429. package/dist-lib/lib/kv-cache-ledger.d.ts +22 -0
  430. package/dist-lib/lib/kv-cache-ledger.js +72 -0
  431. package/dist-lib/lib/kv-cache-reclaim.d.ts +2 -1
  432. package/dist-lib/lib/kv-cache-reclaim.js +30 -0
  433. package/dist-lib/lib/kv-cache-retention.d.ts +36 -0
  434. package/dist-lib/lib/kv-cache-retention.js +101 -0
  435. package/dist-lib/lib/latest-frame.d.ts +10 -0
  436. package/dist-lib/lib/latest-frame.js +48 -0
  437. package/dist-lib/lib/llm-model-names.d.ts +1 -1
  438. package/dist-lib/lib/llm-model-names.js +1 -1
  439. package/dist-lib/lib/log.d.ts +7 -6
  440. package/dist-lib/lib/log.js +14 -7
  441. package/dist-lib/lib/logger-type.d.ts +2 -5
  442. package/dist-lib/lib/mesh-scoped-engine.js +47 -2
  443. package/dist-lib/lib/model-context.js +1 -2
  444. package/dist-lib/lib/model-download-status.d.ts +3 -3
  445. package/dist-lib/lib/model-download.d.ts +22 -13
  446. package/dist-lib/lib/model-download.js +106 -37
  447. package/dist-lib/lib/model-idle-pusher.d.ts +2 -4
  448. package/dist-lib/lib/model-memory-cap.d.ts +30 -0
  449. package/dist-lib/lib/model-memory-cap.js +78 -0
  450. package/dist-lib/lib/models-watch.d.ts +1 -1
  451. package/dist-lib/lib/models-watch.js +4 -4
  452. package/dist-lib/lib/oauth/browser-connect.js +3 -2
  453. package/dist-lib/lib/oauth/flow-core.js +5 -3
  454. package/dist-lib/lib/oauth/flow.js +1 -1
  455. package/dist-lib/lib/oauth/loopback.d.ts +1 -0
  456. package/dist-lib/lib/oauth/loopback.js +57 -12
  457. package/dist-lib/lib/oauth/providers.js +4 -2
  458. package/dist-lib/lib/oauth/redirect-types.d.ts +1 -0
  459. package/dist-lib/lib/oauth/register.js +35 -19
  460. package/dist-lib/lib/oauth/request.d.ts +10 -0
  461. package/dist-lib/lib/oauth/request.js +22 -0
  462. package/dist-lib/lib/oauth/resolve.js +42 -13
  463. package/dist-lib/lib/oauth/token-exchange-core.js +40 -31
  464. package/dist-lib/lib/oauth/types.d.ts +3 -0
  465. package/dist-lib/lib/oauth.d.ts +2 -1
  466. package/dist-lib/lib/oauth.js +1 -0
  467. package/dist-lib/lib/persistent-dir.d.ts +1 -0
  468. package/dist-lib/lib/persistent-dir.js +9 -0
  469. package/dist-lib/lib/probe-rounds.d.ts +8 -0
  470. package/dist-lib/lib/probe-rounds.js +10 -0
  471. package/dist-lib/lib/reconnecting-watch.js +19 -11
  472. package/dist-lib/lib/run-input.d.ts +14 -0
  473. package/dist-lib/lib/run-input.js +33 -0
  474. package/dist-lib/lib/run-notices.d.ts +5 -0
  475. package/dist-lib/lib/run-notices.js +13 -2
  476. package/dist-lib/lib/run-replay.d.ts +45 -0
  477. package/dist-lib/lib/run-replay.js +169 -0
  478. package/dist-lib/lib/run-transcript.d.ts +13 -12
  479. package/dist-lib/lib/run-transcript.js +20 -19
  480. package/dist-lib/lib/suspend-lifecycle.js +15 -5
  481. package/dist-lib/lib/task.js +6 -4
  482. package/dist-lib/lib/test-env.d.ts +1 -0
  483. package/dist-lib/lib/test-env.js +4 -0
  484. package/dist-lib/schema/build.js +66 -55
  485. package/dist-lib/schema/config.d.ts +1 -1
  486. package/dist-lib/schema/config.js +1 -1
  487. package/dist-lib/schema/content.d.ts +5 -1
  488. package/dist-lib/schema/content.js +60 -12
  489. package/dist-lib/schema/engine.d.ts +1 -0
  490. package/dist-lib/schema/engine.js +941 -152
  491. package/dist-lib/schema/field-order.js +8 -1
  492. package/dist-lib/schema/indexes.d.ts +10 -0
  493. package/dist-lib/schema/indexes.js +53 -3
  494. package/dist-lib/schema/local.js +83 -5
  495. package/dist-lib/schema/qvac.d.ts +4 -1
  496. package/dist-lib/schema/qvac.js +558 -16
  497. package/dist-lib/spec/bind.js +261 -48
  498. package/dist-lib/spec/calls.js +56 -5
  499. package/dist-lib/spec/capabilities.d.ts +129 -20
  500. package/dist-lib/spec/config/hyperconf/index.js +1 -1
  501. package/dist-lib/spec/hrpc/hrpc.json +870 -207
  502. package/dist-lib/spec/hrpc/index.js +969 -347
  503. package/dist-lib/spec/hrpc/messages.js +7590 -4896
  504. package/dist-lib/spec/hyperschema/index.js +7590 -4896
  505. package/dist-lib/spec/hyperschema/schema.json +5316 -3224
  506. package/dist-lib/spec/hyperschema/types.d.ts +576 -62
  507. package/dist-lib/spec/local/hyperdb/db.json +95 -1
  508. package/dist-lib/spec/local/hyperdb/index.js +459 -2
  509. package/dist-lib/spec/local/hyperdb/messages.js +1588 -488
  510. package/dist-lib/spec/local/hyperschema/index.js +584 -16
  511. package/dist-lib/spec/local/hyperschema/schema.json +369 -1
  512. package/dist-lib/spec/local/hyperschema/types.d.ts +88 -2
  513. package/dist-lib/spec/mesh/hyperdb/db.json +711 -9
  514. package/dist-lib/spec/mesh/hyperdb/index.js +2769 -7
  515. package/dist-lib/spec/mesh/hyperdb/messages.js +7140 -1298
  516. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +205 -1
  517. package/dist-lib/spec/mesh/hyperdispatch/index.js +579 -1
  518. package/dist-lib/spec/mesh/hyperdispatch/messages.js +4017 -267
  519. package/dist-lib/spec/mesh/hyperschema/index.js +4017 -267
  520. package/dist-lib/spec/mesh/hyperschema/schema.json +2193 -19
  521. package/dist-lib/spec/mesh/hyperschema/types.d.ts +550 -6
  522. package/package.json +136 -90
  523. package/tui/README.md +119 -20
  524. package/tui/app.mjs +2000 -621
  525. package/tui/boot.mjs +74 -9
  526. package/tui/cli.mjs +93 -0
  527. package/tui/index.mjs +2 -51
  528. package/tui/lib/connect-sheet.mjs +350 -0
  529. package/tui/lib/device-target.mjs +64 -0
  530. package/tui/lib/folders-command.mjs +84 -0
  531. package/tui/lib/fork-command.mjs +43 -0
  532. package/tui/lib/knowledge-import.mjs +3 -21
  533. package/tui/lib/local-path.mjs +21 -0
  534. package/tui/lib/move-command.mjs +17 -0
  535. package/tui/lib/render.mjs +30 -1
  536. package/tui/lib/setup.mjs +59 -25
  537. package/tui/lib/skill-connect.mjs +145 -0
  538. package/tui/lib/updater.mjs +86 -0
  539. package/tui/main.mjs +44 -18
  540. package/tui/plugins.mjs +158 -0
  541. package/worker/assistant-sidecar.mjs +28 -4
  542. package/worker/stow-entry.mjs +3 -50
  543. package/dist-lib/lib/core/contract/compute.d.ts +0 -11
  544. package/dist-lib/lib/core/contract/compute.js +0 -48
  545. package/dist-lib/lib/core/device-invites.d.ts +0 -11
  546. package/dist-lib/lib/core/device-invites.js +0 -63
  547. package/dist-lib/lib/core/files/processing/settle.d.ts +0 -13
  548. package/dist-lib/lib/core/files/processing/settle.js +0 -86
  549. package/dist-lib/lib/core/grant-expiry.d.ts +0 -11
  550. package/dist-lib/lib/core/grant-expiry.js +0 -66
  551. package/dist-lib/lib/core/handoff-channel.d.ts +0 -47
  552. package/dist-lib/lib/core/handoff-channel.js +0 -123
  553. package/dist-lib/lib/core/harness-loan.d.ts +0 -29
  554. package/dist-lib/lib/core/host-run-log-store.d.ts +0 -114
  555. package/dist-lib/lib/core/host-run-log-store.js +0 -976
  556. package/dist-lib/lib/core/hosted-agents.d.ts +0 -38
  557. package/dist-lib/lib/core/hosted-agents.js +0 -140
  558. package/dist-lib/lib/core/inference-calls-handoff.d.ts +0 -20
  559. package/dist-lib/lib/core/inference-calls-handoff.js +0 -37
  560. package/dist-lib/lib/core/inference-calls-receiver.d.ts +0 -14
  561. package/dist-lib/lib/core/inference-calls-receiver.js +0 -42
  562. package/dist-lib/lib/core/mesh-seed-handoff.d.ts +0 -25
  563. package/dist-lib/lib/core/mesh-seed-handoff.js +0 -52
  564. package/dist-lib/lib/core/migrations/device-indexes.d.ts +0 -2
  565. package/dist-lib/lib/core/migrations/device-indexes.js +0 -7
  566. package/dist-lib/lib/core/secret-handoff.d.ts +0 -17
  567. package/dist-lib/lib/core/secret-handoff.js +0 -29
  568. package/dist-lib/lib/core/skill-overlay-handoff.d.ts +0 -25
  569. package/dist-lib/lib/core/skill-overlay-handoff.js +0 -50
  570. package/dist-lib/lib/core/skill-overlay-receiver.d.ts +0 -8
  571. package/dist-lib/lib/core/skill-overlay-receiver.js +0 -23
  572. package/dist-lib/lib/image-cache-dir.d.ts +0 -1
  573. package/dist-lib/lib/image-cache-dir.js +0 -5
  574. package/dist-lib/lib/log-levels.d.ts +0 -7
  575. package/dist-lib/lib/log-levels.js +0 -1
  576. package/dist-lib/lib/logger.d.ts +0 -5
  577. package/dist-lib/lib/logger.js +0 -18
  578. package/dist-lib/lib/oauth/loopback.stub.d.ts +0 -3
  579. package/dist-lib/lib/oauth/loopback.stub.js +0 -6
package/tui/app.mjs CHANGED
@@ -1,14 +1,23 @@
1
1
  // the bare-tui chat model, split from the host so it can be driven headlessly with a fake engine
2
2
  import tui from 'bare-tui'
3
+ import updateBanner from 'bare-tui-updater'
3
4
  import { spawn } from 'child_process'
4
5
  import fs from 'fs'
5
6
  import { TOOLSETS } from '@qvac/harness/lib/tools/toolsets.ts'
6
7
  import os from 'os'
7
8
  import path from 'path'
8
9
  import process from 'process'
9
- import { scopedKey } from '../dist-lib/lib/oauth/keys.js'
10
- import { oauthSpecs } from '../dist-lib/lib/oauth/registry.js'
11
- import { settingConfigKey } from '../dist-lib/lib/credential-pusher.js'
10
+ import { oauthRedirectUri } from '../dist-lib/lib/oauth/keys.js'
11
+ import {
12
+ MODEL_IDLE_UNLOAD_KEY,
13
+ MODEL_IDLE_UNLOAD_MINUTES,
14
+ MODEL_MEMORY_CAP_DEFAULT,
15
+ MODEL_MEMORY_CAP_KEY,
16
+ MODEL_MEMORY_CAP_MAX,
17
+ MODEL_MEMORY_CAP_MIN
18
+ } from '../dist-lib/lib/constants.js'
19
+ import { oauthSpecFor } from '../dist-lib/lib/oauth/registry.js'
20
+ import { OBSIDIAN_VAULT_PATH_CREDENTIAL_KEY } from '../dist-lib/lib/obsidian-key.js'
12
21
  import { customModelTaskRefusal } from '../dist-lib/lib/custom-model-task.js'
13
22
  import {
14
23
  COMPACTION_MIN_CTX_SIZE,
@@ -18,6 +27,9 @@ import {
18
27
  MODEL_CONTEXT_TARGET,
19
28
  maxContextForModel
20
29
  } from '../dist-lib/lib/model-context.js'
30
+ import { runChecks } from '../dist-lib/lib/doctor/checks.js'
31
+ import { checkLines, summarize } from '../dist-lib/lib/doctor/render.js'
32
+ import { diagnosticsLines, headerLine } from '../dist-lib/lib/doctor/tree.js'
21
33
  import {
22
34
  busyStatus,
23
35
  findPendingApproval,
@@ -30,20 +42,50 @@ import { exportMarkdown } from './lib/export.mjs'
30
42
  import { paintSelection, selectionText } from './lib/select.mjs'
31
43
  import { center, splash } from './lib/splash.mjs'
32
44
  import { wrapBlock, wrapLine } from './lib/wrap.mjs'
45
+ import { foldersCommand } from './lib/folders-command.mjs'
33
46
  import { knowledgeCommand } from './lib/knowledge-command.mjs'
47
+ import { describeMove } from './lib/move-command.mjs'
48
+ import { forkCut } from './lib/fork-command.mjs'
49
+ import { deviceLines, onDevice, pickDevice } from './lib/device-target.mjs'
34
50
  import { saveUniqueFile } from './lib/save-file.mjs'
35
51
  import { usageReport } from './lib/usage.mjs'
36
52
  import { compactionTriggerRatio } from '../dist-lib/lib/compaction.js'
37
53
  import { rememberSelection } from './lib/selection.mjs'
38
54
  import {
39
55
  configureActions,
40
- connectSlug,
56
+ closestSkill,
57
+ declaredCredentials,
58
+ findSkill,
41
59
  isReady,
42
60
  setupAction,
43
61
  setupActions,
44
62
  setupPlan,
63
+ skillRoutes,
45
64
  statusLabel
46
65
  } from './lib/setup.mjs'
66
+ import {
67
+ backspace,
68
+ currentRoute,
69
+ enteredValues,
70
+ focusField,
71
+ focused,
72
+ formatSheet,
73
+ hasField,
74
+ moveFocus,
75
+ openSheet,
76
+ pickRoute,
77
+ routeFields,
78
+ sheetFields,
79
+ typeInto
80
+ } from './lib/connect-sheet.mjs'
81
+ import {
82
+ cancelOAuth,
83
+ connectSkill,
84
+ disconnect,
85
+ envClient,
86
+ saveFields,
87
+ savedClient
88
+ } from './lib/skill-connect.mjs'
47
89
  import {
48
90
  firstSelectable,
49
91
  moveRows,
@@ -98,9 +140,8 @@ const COMMANDS = [
98
140
  { name: 'rename', desc: '<name> — rename the active agent' },
99
141
  {
100
142
  name: 'use',
101
- desc: '<name|id> — switch the active agent (same chat; re-targets the next run)'
102
- },
103
- { name: 'borrow', desc: '[none] — borrow the model from the compute mesh, or stop borrowing' }
143
+ desc: '<name|id> — switch the active agent and hand it the open chat'
144
+ }
104
145
  ]
105
146
  },
106
147
  {
@@ -120,6 +161,10 @@ const COMMANDS = [
120
161
  { name: 'new', desc: '[title] — create and switch to a new chat' },
121
162
  { name: 'use', desc: '<title|id> — switch to another chat' },
122
163
  { name: 'rename', desc: '<title> — rename this chat' },
164
+ {
165
+ name: 'fork',
166
+ desc: '[turn] [before] — copy this chat, through a turn or before it, into a new one'
167
+ },
123
168
  { name: 'del', desc: '<title|id> — delete a chat' },
124
169
  { name: 'websearch', desc: 'on|off — let this chat search the web' },
125
170
  { name: 'rag', desc: 'on|off — retrieve from this chat’s knowledge' }
@@ -168,35 +213,26 @@ const COMMANDS = [
168
213
  desc: 'browse installed skills; ↑/↓ move, space toggles each on/off',
169
214
  palette: true
170
215
  },
171
- { name: 'tools', desc: 'browse installed tools; ↑/↓ move, space toggles each on/off' },
172
216
  {
173
217
  name: 'skill',
174
- desc: 'toggle a single skill on/off',
218
+ desc: '<name> — set a skill up, or toggle one on/off',
175
219
  sub: [
176
220
  { name: 'on', desc: '<name> — enable a skill for this agent (sets scope=selected)' },
177
221
  { name: 'off', desc: '<name> — disable a skill for this agent (sets scope=selected)' }
178
222
  ]
179
223
  },
180
- {
181
- name: 'tool',
182
- desc: 'toggle a single tool on/off',
183
- sub: [
184
- { name: 'on', desc: '<name> — enable a tool for this agent (sets scope=selected)' },
185
- { name: 'off', desc: '<name> — disable a tool for this agent (sets scope=selected)' }
186
- ]
187
- },
188
224
  {
189
225
  name: 'scope',
190
- desc: 'switch skills/tools scope between all and selected',
226
+ desc: 'switch skills scope between all and selected',
191
227
  sub: [
192
- { name: 'skills', desc: 'all|selected — every installed skill, or only the enabled list' },
193
- { name: 'tools', desc: 'all|selected — every installed tool, or only the enabled list' }
228
+ { name: 'skills', desc: 'all|selected — every installed skill, or only the enabled list' }
194
229
  ]
195
230
  },
196
231
  {
197
- name: 'permissions',
198
- desc: "the agent's approval mode and its toolset switches; space toggles"
232
+ name: 'tools',
233
+ desc: "the agent's toolset switches and the tools in each; space toggles a set"
199
234
  },
235
+ { name: 'permissions', desc: "the agent's approval mode; space toggles" },
200
236
  { name: 'attach', desc: 'attach one or more local files to this chat by path', palette: true },
201
237
  {
202
238
  name: 'save',
@@ -210,7 +246,7 @@ const COMMANDS = [
210
246
  },
211
247
  {
212
248
  name: 'join',
213
- desc: "join another device's mesh with its invite (replaces this one)",
249
+ desc: 'join a mesh from an invite: a device invite replaces this one, a member invite adds one',
214
250
  sub: [
215
251
  { name: 'cancel', desc: 'abort a join still waiting to be admitted' },
216
252
  { name: 'yes', desc: 'confirm a previewed invite and join' }
@@ -232,24 +268,54 @@ const COMMANDS = [
232
268
  ]
233
269
  },
234
270
  { name: 'members', desc: 'list mesh members with their devices grouped', palette: true },
271
+ {
272
+ name: 'rename',
273
+ desc: 'name this device, or yourself across every mesh',
274
+ palette: true,
275
+ sub: [
276
+ { name: 'device', desc: '<name> — name this device; every mesh it is in shows it' },
277
+ { name: 'member', desc: '<name> — name yourself, in every mesh at once' }
278
+ ]
279
+ },
235
280
  // before `meshes`, so a bare /mesh offers the verb first and the list second
236
281
  {
237
282
  name: 'mesh',
238
- desc: 'switch which mesh is the active one, open another, or name one',
283
+ desc: 'switch which mesh is the active one, open another, name one, or move a chat into one',
239
284
  palette: true,
240
285
  sub: [
241
286
  { name: 'use', desc: '<n|id> — make one of your meshes the active one' },
242
- { name: 'new', desc: '[compute] — open another shared mesh, or lend this device’s model' },
243
- { name: 'label', desc: '<n|id> <name> — name a mesh, privately to you' }
287
+ { name: 'new', desc: 'create a workspace' },
288
+ { name: 'label', desc: '<n|id> <name> — name a mesh, privately to you' },
289
+ { name: 'move', desc: '<n|id> [chat] — move this chat, or a named one, into another mesh' },
290
+ { name: 'moved', desc: '[chat] — how the last move from this window is going' },
291
+ { name: 'fork', desc: '<n|id> [turn] [before] — copy this chat into another mesh' }
244
292
  ]
245
293
  },
246
294
  { name: 'meshes', desc: 'list the meshes this device belongs to', palette: true },
247
- { name: 'cred', desc: 'set a credential value for this agent' },
248
- { name: 'connect', desc: 'OAuth-connect a skill for this agent', palette: true },
295
+ {
296
+ name: 'folders',
297
+ desc: 'the folders on this device the agent may read or edit with its file tools',
298
+ sub: [
299
+ { name: 'list', desc: 'the shared folders, each ro or rw' },
300
+ { name: 'add', desc: '<path> [ro|rw] — share a folder, read-only unless rw' },
301
+ { name: 'remove', desc: '<path> — stop sharing a folder' }
302
+ ]
303
+ },
304
+ {
305
+ name: 'connect',
306
+ desc: '<name> — set a skill up and sign in (same as /skill <name> connect)',
307
+ palette: true
308
+ },
249
309
  {
250
310
  name: 'my-device',
251
311
  desc: 'CPU/GPU inventory for this device (manufacturer, cores, drivers, …)'
252
312
  },
313
+ {
314
+ name: 'doctor',
315
+ desc: 'health checks for this device, with secrets redacted for pasting',
316
+ palette: true,
317
+ sub: [{ name: 'debug', desc: 'the raw diagnostics frame behind the checks' }]
318
+ },
253
319
  {
254
320
  name: 'models',
255
321
  desc: 'browse the SDK registry (optional type filter), or check and add your own GGUF',
@@ -261,7 +327,7 @@ const COMMANDS = [
261
327
  },
262
328
  {
263
329
  name: 'add',
264
- desc: '<label> <src|n> [tools|vision|thinking] — add a gguf url or path'
330
+ desc: '<label> <src|n> [mmproj] [tools|vision|thinking] — add a gguf url or path'
265
331
  },
266
332
  { name: 'use', desc: '<name|label> — make a model the agent’s model' },
267
333
  {
@@ -271,7 +337,27 @@ const COMMANDS = [
271
337
  { name: 'load', desc: '<model> — load a downloaded model into memory now' },
272
338
  { name: 'unload', desc: '<model> — unload a model; a reply using it starts again' },
273
339
  { name: 'delete', desc: '<name> — remove a downloaded model from this device' },
274
- { name: 'download', desc: '<name> — download a model to this device now' }
340
+ { name: 'download', desc: '<name> — download a model to this device now' },
341
+ { name: 'pause', desc: '<name> — hold a model’s download' },
342
+ { name: 'resume', desc: '<name> — let a held download go on' },
343
+ {
344
+ name: 'idle',
345
+ desc: '<never|minutes> — free loaded models after that long with no request'
346
+ },
347
+ { name: 'cap', desc: '<percent> — the share of the memory for models they may fill' },
348
+ { name: 'settings', desc: 'the idle limit and memory cap of the device /models acts on' }
349
+ ]
350
+ },
351
+ {
352
+ name: 'device',
353
+ desc: 'the device /models acts on: this one, or another device of this account',
354
+ sub: [
355
+ {
356
+ name: 'list',
357
+ desc: 'this account’s devices, whether each is connected, and how many models it has downloaded'
358
+ },
359
+ { name: 'use', desc: '<n|name|id> — point /models at that device' },
360
+ { name: 'here', desc: 'point /models back at this device' }
275
361
  ]
276
362
  },
277
363
  {
@@ -317,6 +403,7 @@ const MODEL_TYPES = new Set([
317
403
  'vad',
318
404
  'other'
319
405
  ])
406
+ const MODEL_ADD_FLAGS = new Set(['tools', 'vision', 'thinking'])
320
407
  const MODEL_VERBS = new Set([
321
408
  'custom',
322
409
  'preview',
@@ -326,7 +413,12 @@ const MODEL_VERBS = new Set([
326
413
  'load',
327
414
  'unload',
328
415
  'delete',
329
- 'download'
416
+ 'download',
417
+ 'idle',
418
+ 'cap',
419
+ 'pause',
420
+ 'resume',
421
+ 'settings'
330
422
  ])
331
423
  // resolved before the SDK addon check so users don't have to know the plugin name
332
424
  const MODEL_TYPE_ALIASES = {
@@ -335,10 +427,6 @@ const MODEL_TYPE_ALIASES = {
335
427
  image: 'diffusion'
336
428
  }
337
429
 
338
- export function credKey(agentId, key) {
339
- return scopedKey(agentId, key)
340
- }
341
-
342
430
  function openInBrowser(url) {
343
431
  const command = process.platform === 'darwin' ? 'open' : 'xdg-open'
344
432
  try {
@@ -370,11 +458,29 @@ export const fg = {
370
458
  cyan: style().foreground('brightcyan'),
371
459
  dim: style().foreground('gray').italic(true),
372
460
  white: style(),
461
+ green: style().foreground('brightgreen'),
373
462
  amber: style().foreground('brightyellow'),
374
463
  magenta: style().foreground('brightmagenta').bold(true),
464
+ heading: style().foreground('brightcyan').bold(true),
375
465
  err: style().foreground('brightred')
376
466
  }
377
467
 
468
+ // long enough for the engine's sampler to tick, so flushes/delay can move
469
+ const DOCTOR_SAMPLE_GAP_MS = 1500
470
+
471
+ // the glyph carries the severity and the titles the structure, so only those are coloured
472
+ const DOCTOR_PAINT = {
473
+ pass: fg.green,
474
+ warn: fg.amber,
475
+ fail: fg.err,
476
+ declared: fg.dim,
477
+ pending: fg.dim,
478
+ title: fg.cyan,
479
+ explain: fg.dim
480
+ }
481
+
482
+ const paintDoctor = (text, kind) => (DOCTOR_PAINT[kind] ?? fg.white).render(text)
483
+
378
484
  // an IEEE-float WAV header (format tag 3) so the engine's raw PCM plays in any player
379
485
  export function floatPcmToWav(pcm, sampleRate) {
380
486
  const blockAlign = 4
@@ -489,8 +595,16 @@ export function formatModels(rows, type, state = null) {
489
595
 
490
596
  return fg.dim.render('○ not cached')
491
597
  }
492
- const hint = state ? '↑/↓ move · enter use (downloads on next run) · esc return' : 'esc to return'
493
- const header = fg.dim.render(`Models on this device${filter} (${sorted.length}) — ${hint}`)
598
+ const usable = state && !state.device
599
+ let hint = 'esc to return'
600
+ if (usable) {
601
+ hint = '↑/↓ move · enter use (downloads on next run) · esc return'
602
+ } else if (state) {
603
+ hint = '↑/↓ move · esc return'
604
+ }
605
+
606
+ const place = state?.device ?? 'this device'
607
+ const header = fg.dim.render(`Models on ${place}${filter} (${sorted.length}) — ${hint}`)
494
608
  const lines = sorted.map((row, i) => {
495
609
  const name = fg.white.render(row.name.padEnd(nameWidth))
496
610
  const rowType = fg.dim.render(row.type.padEnd(typeWidth))
@@ -499,7 +613,8 @@ export function formatModels(rows, type, state = null) {
499
613
  ? `${mb(row.actualSize)} / ${mb(row.expectedSize)}`
500
614
  : mb(row.expectedSize)
501
615
  const vision = row.supportsImages ? ` ${fg.cyan.render('◈ vision')}` : ''
502
- const inUse = state?.currentModel === row.name ? ` ${fg.magenta.render('▸ in use')}` : ''
616
+ const inUse =
617
+ usable && state.currentModel === row.name ? ` ${fg.magenta.render('▸ in use')}` : ''
503
618
  const point = state && i === state.cursor ? fg.magenta.render('❯ ') : ' '
504
619
 
505
620
  return `${point}${badge(row)} ${name} ${rowType} ${fg.dim.render(size)}${vision}${inUse}`
@@ -523,13 +638,32 @@ async function catalogRow(engine, name) {
523
638
  return entry ? (catalog.find((m) => m.registryPath === entry.registryPath) ?? null) : null
524
639
  }
525
640
 
526
- const NOT_IN_CATALOG = "is not in this device's catalog — /models lists what can download"
641
+ // the harness guesses at a bare name it cannot place, and can land on another file
642
+ async function isListedModel(engine, name) {
643
+ if (/^(\/|~|\.|file:|https?:|registry:|pear:|hyper:)/.test(name)) {
644
+ return true
645
+ }
646
+
647
+ const { models } = await engine.listModels({})
648
+ if ((models ?? []).some((m) => m.name === name)) {
649
+ return true
650
+ }
651
+
652
+ const { models: registry } = await engine.listModels({ fullRegistry: true })
653
+
654
+ return (registry ?? []).some((m) => m.name === name)
655
+ }
656
+
657
+ const notOursToUse = (device) =>
658
+ `/models use picks this agent's model, not ${device.name}'s — /device here first`
659
+
660
+ const notInCatalog = (place) => `is not in ${place}'s catalog — /models lists what can download`
527
661
 
528
662
  // the agents still naming the model fetch it again on their next run
529
- async function deleteModel(engine, name) {
663
+ async function deleteModel(engine, name, place = 'this device') {
530
664
  const row = await catalogRow(engine, name)
531
665
  if (!row) {
532
- return `${name} ${NOT_IN_CATALOG}`
666
+ return `${name} ${notInCatalog(place)}`
533
667
  }
534
668
 
535
669
  const { freedBytes } = await engine.deleteModel({ name: row.name })
@@ -549,14 +683,14 @@ async function deleteModel(engine, name) {
549
683
  return lines.join('\n')
550
684
  }
551
685
 
552
- async function downloadModel(engine, name) {
686
+ async function downloadModel(engine, name, place = 'this device') {
553
687
  const row = await catalogRow(engine, name)
554
688
  if (!row) {
555
- return `${name} ${NOT_IN_CATALOG}`
689
+ return `${name} ${notInCatalog(place)}`
556
690
  }
557
691
 
558
692
  if (row.isCached) {
559
- return `${row.name} is already on this device`
693
+ return `${row.name} is already on ${place}`
560
694
  }
561
695
 
562
696
  await engine.retryModelDownload({ name: row.name })
@@ -587,27 +721,111 @@ const MODE_HINT = {
587
721
  'skip-all': '⚠ acts on this device without ever asking'
588
722
  }
589
723
 
590
- // /permissions overlay: the approval mode on the first row, then one row per toolset.
591
724
  export function formatPermissions(sel) {
592
- const { rows, enabled, mode, cursor } = sel
593
- const nameWidth = Math.max(...rows.map((name) => name.length))
594
- const header = fg.dim.render(
595
- 'How should QV.AC actions be approved? — ↑/↓ move · space toggle · esc return'
596
- )
597
- const lines = rows.map((name, i) => {
598
- const point = i === cursor ? fg.magenta.render('❯ ') : ' '
599
- if (name === MODE_ROW) {
600
- const paint = mode === 'skip-all' ? fg.err : fg.cyan
601
- const hint =
602
- mode === 'skip-all' ? fg.err.render(MODE_HINT[mode]) : fg.dim.render(MODE_HINT[mode])
725
+ const { mode } = sel
726
+ const header = fg.dim.render('How should QV.AC actions be approved? — space toggle · esc return')
727
+ const paint = mode === 'skip-all' ? fg.err : fg.cyan
728
+ const hint = mode === 'skip-all' ? fg.err.render(MODE_HINT[mode]) : fg.dim.render(MODE_HINT[mode])
603
729
 
604
- return `${point}${paint.render(MODE_LABEL[mode])} ${hint}`
605
- }
730
+ return [header, '', `${fg.magenta.render('❯ ')}${paint.render(MODE_LABEL[mode])} ${hint}`]
731
+ }
606
732
 
607
- const badge = enabled.has(name) ? fg.cyan.render('● on ') : fg.dim.render('○ off')
733
+ const TOOL_SUMMARY_MAX = 72
734
+
735
+ // knowledge reaches the model by injection, so its switch gates retrieval rather than a tool
736
+ const NO_TOOL_NOTE = { knowledge: 'no tool — it gates the excerpts added to each prompt' }
737
+
738
+ // the catalog description is written for the model, so its opening sentence is the human part
739
+ function toolSummary(description) {
740
+ const first = description.split(/(?<=\.)\s/)[0].replace(/\.$/, '')
741
+
742
+ return first.length > TOOL_SUMMARY_MAX ? `${first.slice(0, TOOL_SUMMARY_MAX - 1)}…` : first
743
+ }
744
+
745
+ const branch = (i, count) => fg.dim.render(` ${i === count - 1 ? '└' : '├'} `)
746
+
747
+ // one column across every set, so the summaries line up down the whole overlay
748
+ function toolLines(tools, { on, nameWidth }) {
749
+ return tools.map((tool, i) => {
750
+ const name = tool.name.padEnd(nameWidth)
751
+ // another device advertises its tools without descriptions
752
+ const notes = [tool.description && toolSummary(tool.description)]
753
+ if (tool.skillGated) {
754
+ notes.push('once its skill loads')
755
+ }
608
756
 
609
- return `${point}${badge} ${fg.white.render(name.padEnd(nameWidth))} ${fg.dim.render(TOOLSET_HINTS[name] ?? '')}`
757
+ return `${branch(i, tools.length)}${on ? fg.white.render(name) : fg.dim.render(name)} ${fg.dim.render(notes.filter(Boolean).join(' · '))}`
610
758
  })
759
+ }
760
+
761
+ function toolsetBlock(sel, name, i) {
762
+ const { rows, enabled, cursor, catalog, deviceName } = sel
763
+ const nameWidth = Math.max(...rows.map((row) => row.length))
764
+ const on = enabled.has(name)
765
+ const point = i === cursor ? fg.magenta.render('❯ ') : ' '
766
+ const badge = on ? fg.cyan.render('● on ') : fg.dim.render('○ off')
767
+ const title = on
768
+ ? fg.heading.render(name.padEnd(nameWidth))
769
+ : fg.dim.render(name.padEnd(nameWidth))
770
+ const head = `${point}${badge} ${title} ${fg.dim.render(TOOLSET_HINTS[name] ?? '')}`
771
+ if (!catalog) {
772
+ return [head]
773
+ }
774
+
775
+ const tools = catalog.filter((tool) => tool.toolset === name)
776
+ if (!tools.length) {
777
+ return [
778
+ head,
779
+ branch(0, 1) +
780
+ fg.dim.render(NO_TOOL_NOTE[name] ?? `no tools on ${deviceName ?? 'this device'}`)
781
+ ]
782
+ }
783
+
784
+ return [head, ...toolLines(tools, { on, nameWidth: toolNameWidth(catalog) })]
785
+ }
786
+
787
+ const toolNameWidth = (catalog) => Math.max(...catalog.map((tool) => tool.name.length))
788
+
789
+ // the line the cursor's set starts on, since every set spends a row per tool beneath it
790
+ export function toolsCursorLine(sel) {
791
+ let line = 2
792
+ for (let i = 0; i < sel.cursor; i++) {
793
+ line += toolsetBlock(sel, sel.rows[i], i).length
794
+ }
795
+
796
+ return line
797
+ }
798
+
799
+ // the switches still work when the host's list cannot be read, so the reason replaces the rows
800
+ function missingTools(reason, deviceName) {
801
+ if (reason === 'not-ours') {
802
+ return "(this agent runs on another member's device, which does not share its tool list)"
803
+ }
804
+
805
+ return reason
806
+ ? emptySelector('tools', reason, deviceName)
807
+ : "(the agent's device could not list its tools)"
808
+ }
809
+
810
+ // /tools overlay: one switch per toolset, each listing the tools it gates on the agent's device.
811
+ export function formatTools(sel) {
812
+ const { rows, catalog, reason, deviceName } = sel
813
+ const header = fg.dim.render(
814
+ `Tools on ${deviceName ?? 'this device'}, by toolset — ↑/↓ move · space toggle a set · esc return`
815
+ )
816
+ const lines = rows.flatMap((name, i) => toolsetBlock(sel, name, i))
817
+ const loose = (catalog ?? []).filter((tool) => !tool.toolset)
818
+ if (loose.length) {
819
+ lines.push(
820
+ '',
821
+ ` ${fg.heading.render('no toolset')} ${fg.dim.render('no switch turns these off')}`
822
+ )
823
+ lines.push(...toolLines(loose, { on: true, nameWidth: toolNameWidth(catalog) }))
824
+ }
825
+
826
+ if (!catalog) {
827
+ lines.push('', fg.dim.render(` ${missingTools(reason, deviceName)}`))
828
+ }
611
829
 
612
830
  return [header, '', ...lines]
613
831
  }
@@ -696,6 +914,65 @@ const SKILL_STATUS_PAINT = {
696
914
  disabled: 'dim'
697
915
  }
698
916
 
917
+ const SETUP_KINDS = {
918
+ oauth: 'sign in',
919
+ token: 'token',
920
+ picker: 'folder',
921
+ install: 'install',
922
+ instructions: 'steps'
923
+ }
924
+
925
+ // the states a setup can clear; an unsupported or too-small-model skill stays as it is
926
+ const SETUP_FIXES = new Set(['needs-setup', 'disconnected', 'failed'])
927
+
928
+ const SKILL_USAGE =
929
+ 'usage: /skill <name> [connect | disconnect | set <field> [value]] · /skill on|off <name>'
930
+
931
+ const OAUTH_STAGES = {
932
+ 'awaiting-callback': 'waiting for the browser — approve access there',
933
+ 'exchanging-code': 'finishing sign-in…'
934
+ }
935
+
936
+ // a value typed after `set` is a secret more often than not, so it never reaches ↑ history
937
+ const SECRET_COMMAND = /^\/skill\s+\S+\s+set\s+\S+\s+\S/
938
+
939
+ function expandHome(folder) {
940
+ return folder === '~' || folder.startsWith('~/')
941
+ ? path.join(os.homedir(), folder.slice(1))
942
+ : folder
943
+ }
944
+
945
+ // a key the skill declares stays settable where its authored setup gives it no field
946
+ function settableRoute(skill, field) {
947
+ const route = skillRoutes(skill).find((entry) => hasField(entry, field))
948
+ if (route || !declaredCredentials(skill).includes(field)) {
949
+ return route ?? null
950
+ }
951
+
952
+ return { kind: 'token', credentialKey: field }
953
+ }
954
+
955
+ // the harness reads a vault only with its `.obsidian` config folder; it does not export that check
956
+ function folderProblem(folder, route) {
957
+ if (!isDirectory(folder)) {
958
+ return `no folder at ${folder}`
959
+ }
960
+
961
+ const vault = route.credentialKey === OBSIDIAN_VAULT_PATH_CREDENTIAL_KEY
962
+
963
+ return vault && !isDirectory(path.join(folder, '.obsidian'))
964
+ ? `${folder} is not an Obsidian vault: it has no .obsidian folder`
965
+ : null
966
+ }
967
+
968
+ function isDirectory(folder) {
969
+ try {
970
+ return fs.statSync(folder).isDirectory()
971
+ } catch {
972
+ return false
973
+ }
974
+ }
975
+
699
976
  // which nothing this is: a shared mesh publishes no inventory, so "offline" is rarely the reason
700
977
  function emptySelector(kind, reason, deviceName) {
701
978
  const whose = deviceName ? `${deviceName}` : 'that device'
@@ -733,11 +1010,14 @@ export function formatSelector(sel) {
733
1010
  return formatPermissions(sel)
734
1011
  }
735
1012
 
1013
+ if (kind === 'tools') {
1014
+ return formatTools(sel)
1015
+ }
1016
+
736
1017
  if (kind === 'ctx') {
737
1018
  return formatContextSizes(sel)
738
1019
  }
739
1020
 
740
- const title = kind === 'skills' ? 'Skills' : 'Tools'
741
1021
  if (!rows.length) {
742
1022
  return [fg.dim.render(emptySelector(kind, reason, deviceName))]
743
1023
  }
@@ -747,39 +1027,40 @@ export function formatSelector(sel) {
747
1027
  ? '↑/↓ move · space toggle · enter configure · esc return'
748
1028
  : '↑/↓ move · space toggle · esc return'
749
1029
  const where = deviceName ? `on ${deviceName}` : 'on this device'
750
- const header = fg.dim.render(`${title} ${where} — scope=${scope} (${rows.length}) — ${hint}`)
1030
+ const header = fg.dim.render(`Skills ${where} — scope=${scope} (${rows.length}) — ${hint}`)
751
1031
  const lines = rows.map((name, i) => {
752
1032
  const point = i === cursor ? fg.magenta.render('❯ ') : ' '
753
1033
  const badge = enabled.has(name) ? fg.cyan.render('● on ') : fg.dim.render('○ off')
754
1034
  const skill = detail?.get(name)
755
1035
  const state = skill
756
- ? ` ${fg[SKILL_STATUS_PAINT[skill.status] ?? 'dim'].render(statusLabel(skill.status))}`
1036
+ ? ` ${fg[SKILL_STATUS_PAINT[skill.status] ?? 'dim'].render(skillState(skill))}`
757
1037
  : ''
758
1038
 
759
1039
  return `${point}${badge} ${fg.white.render(name.padEnd(nameWidth))}${state}`
760
1040
  })
761
1041
 
762
- return [header, '', ...lines, ...formatSkillDetail(detail?.get(rows[cursor]))]
1042
+ // a setup that just finished says so on the list it returned to, in the line kept blank otherwise
1043
+ const notice = sel.notice ? fg.green.render(sel.notice) : ''
1044
+
1045
+ return [header, notice, ...lines, ...formatSkillDetail(detail?.get(rows[cursor]))]
1046
+ }
1047
+
1048
+ // a skill that needs setup says what kind, so it reads before the sheet is opened
1049
+ function skillState(skill) {
1050
+ const kind = isReady(skill) ? null : SETUP_KINDS[setupAction(skill)?.kind]
1051
+ return kind ? `${statusLabel(skill.status)} · ${kind}` : statusLabel(skill.status)
763
1052
  }
764
1053
 
765
1054
  function formatSkillDetail(skill) {
766
1055
  if (!skill) return []
767
1056
  const lines = ['', fg.white.render(`${skill.name} — ${skill.description}`)]
768
1057
  const state = statusLabel(skill.status)
769
- const runnables = configureActions(skill)
770
1058
  if (isReady(skill)) {
771
- if (!runnables.length) {
772
- return [...lines, fg.dim.render(state)]
773
- }
774
-
775
- const [first, ...rest] = runnables
776
- lines.push(fg.dim.render(`${state} — enter to change it: ${first.label}`))
777
- lines.push(fg.cyan.render(`enter → ${first.command ?? `${first.prefill}<value>`}`))
778
- for (const other of rest) {
779
- lines.push(fg.dim.render(`or ${other.label}${runnable(other)}`))
780
- }
781
-
782
- return lines
1059
+ const [first] = configureActions(skill)
1060
+ return [
1061
+ ...lines,
1062
+ fg.dim.render(first ? `${state} — enter to change it: ${first.label}` : state)
1063
+ ]
783
1064
  }
784
1065
 
785
1066
  const action = setupAction(skill)
@@ -788,25 +1069,7 @@ function formatSkillDetail(skill) {
788
1069
  }
789
1070
 
790
1071
  lines.push(fg.amber.render(`${state} — ${action.label}`))
791
- if (action.command) {
792
- lines.push(fg.cyan.render(`enter → ${action.command}`))
793
- }
794
-
795
- if (action.prefill) {
796
- lines.push(fg.cyan.render(`enter → ${action.prefill}<value>`))
797
- }
798
-
799
- for (const step of action.steps) {
800
- lines.push(fg.dim.render(` • ${step}`))
801
- }
802
-
803
- if (action.helpUrl) {
804
- lines.push(fg.dim.render(` ${action.helpUrl}`))
805
- }
806
-
807
- for (const other of setupPlan(skill).others) {
808
- lines.push(fg.dim.render(`or ${other.label}${runnable(other)}`))
809
- }
1072
+ lines.push(fg.cyan.render(`enter → set it up (${action.command})`))
810
1073
 
811
1074
  return lines
812
1075
  }
@@ -1002,7 +1265,7 @@ export function formatModelPreview(preview) {
1002
1265
 
1003
1266
  if (!preview.src && preview.files?.length) {
1004
1267
  return [
1005
- 'several models here — pick one by number: /models preview <n> · /models add <name> <n>',
1268
+ 'several models here — pick one by number: /models preview <n> [mmproj] · /models add <name> <n> [mmproj]',
1006
1269
  ...preview.files.map(
1007
1270
  (file, index) =>
1008
1271
  ` ${index + 1}. ${file.label} ${bytesToGb(file.sizeBytes) ?? 'size unknown'}\n ${file.src}`
@@ -1022,7 +1285,8 @@ export function formatModelPreview(preview) {
1022
1285
  ` context ${preview.contextLength ? formatTokenCount(preview.contextLength) : 'unknown'}`,
1023
1286
  ` ${[preview.taskType, preview.architecture].filter(Boolean).join(' · ') || 'task unknown'}`,
1024
1287
  ` license ${preview.license || 'unknown'}`,
1025
- ` fit ${fit}${reasons}`
1288
+ ` fit ${fit}${reasons}`,
1289
+ ...(preview.mmprojSrc ? [` projector ${preview.mmprojSrc}`] : [])
1026
1290
  ].join('\n')
1027
1291
  }
1028
1292
 
@@ -1356,11 +1620,6 @@ export function formatDiagnostics(stats) {
1356
1620
  return [header, '', ...formatCpuLines(stats.cpu), '', ...formatGpuLines(stats.gpu)]
1357
1621
  }
1358
1622
 
1359
- function runnable(action) {
1360
- if (action.command) return `: ${action.command}`
1361
- return action.prefill ? `: ${action.prefill}<value>` : ''
1362
- }
1363
-
1364
1623
  // a non-ready skill appends its fix, so it is in the TUI rather than somewhere in the docs
1365
1624
  export function renderSkill(s) {
1366
1625
  const lines = [`${s.name}: ${s.status || 'unknown'} — ${s.description}`]
@@ -1374,7 +1633,7 @@ export function renderSkill(s) {
1374
1633
 
1375
1634
  if (isReady(s)) {
1376
1635
  for (const action of configureActions(s)) {
1377
- lines.push(` change it: ${action.label}${runnable(action)}`)
1636
+ lines.push(` change it: ${action.label}: ${action.command}`)
1378
1637
  }
1379
1638
 
1380
1639
  return lines.join('\n')
@@ -1386,26 +1645,11 @@ export function renderSkill(s) {
1386
1645
 
1387
1646
  const { primary, others } = setupPlan(s)
1388
1647
  if (primary) {
1389
- lines.push(` ${primary.label}`)
1390
- if (primary.command) {
1391
- lines.push(` run: ${primary.command}`)
1392
- }
1393
-
1394
- if (primary.prefill) {
1395
- lines.push(` run: ${primary.prefill}<value>`)
1396
- }
1397
-
1398
- for (const step of primary.steps) {
1399
- lines.push(` - ${step}`)
1400
- }
1401
-
1402
- if (primary.helpUrl) {
1403
- lines.push(` ${primary.helpUrl}`)
1404
- }
1648
+ lines.push(` ${primary.label}`, ` run: ${primary.command}`)
1405
1649
  }
1406
1650
 
1407
1651
  for (const other of others) {
1408
- lines.push(` or ${other.label}${runnable(other)}${other.helpUrl ? ` (${other.helpUrl})` : ''}`)
1652
+ lines.push(` or ${other.label}`)
1409
1653
  }
1410
1654
 
1411
1655
  return lines.join('\n')
@@ -1418,13 +1662,6 @@ const MEMBER_INVITE_DISCLOSURES = [
1418
1662
  'co-members see each of your devices: name, platform, capability profile, recommended model and which skills the agents you host here can run'
1419
1663
  ]
1420
1664
 
1421
- // A compute mesh has no conversation and no agents, so only the key material and the row hold.
1422
- const COMPUTE_INVITE_DISCLOSURES = [
1423
- 'everyone ever admitted to this mesh holds its key material for good - a kick revokes a writer, never the key',
1424
- 'co-members see each of your devices: name, platform, capability profile and recommended model',
1425
- 'nothing else travels: no chats, no documents, no knowledge, no agents, no tool settings'
1426
- ]
1427
-
1428
1665
  // a mesh has no name, only its key, so the list is numbered for `/mesh use <n>`
1429
1666
  function formatMeshes(meshes, current) {
1430
1667
  if (!meshes.length) {
@@ -1433,9 +1670,9 @@ function formatMeshes(meshes, current) {
1433
1670
 
1434
1671
  const rows = meshes.map((mesh, index) => {
1435
1672
  const tags = [
1436
- mesh.account ? 'account' : null,
1437
- mesh.compute ? 'compute' : null,
1438
- !mesh.account && !mesh.compute && mesh.members > 1 ? 'shared' : null,
1673
+ mesh.account ? 'home (your account)' : null,
1674
+ mesh.workspace ? 'workspace' : null,
1675
+ !mesh.account && mesh.members > 1 ? 'shared' : null,
1439
1676
  mesh.open ? 'open' : 'closed'
1440
1677
  ]
1441
1678
  if (mesh.open) {
@@ -1443,12 +1680,16 @@ function formatMeshes(meshes, current) {
1443
1680
  }
1444
1681
 
1445
1682
  const marker = mesh.meshId === current ? '* ' : ' '
1446
- const name = mesh.label ? `${mesh.meshId.slice(0, 8)} "${mesh.label}"` : mesh.meshId.slice(0, 8)
1683
+ const title = mesh.label || mesh.name
1684
+ const name = title ? `${mesh.meshId.slice(0, 8)} "${title}"` : mesh.meshId.slice(0, 8)
1447
1685
 
1448
1686
  return `${marker}${index + 1}. ${name} · ${tags.filter(Boolean).join(' · ')}`
1449
1687
  })
1450
1688
 
1451
- return [...rows, '* = this window · /mesh use <n|id> switches'].join('\n')
1689
+ return [
1690
+ ...rows,
1691
+ '* = this window · /mesh use <n|id> switches · /mesh label <n|id> <name> names one'
1692
+ ].join('\n')
1452
1693
  }
1453
1694
 
1454
1695
  // Same selector shape as /knowledge: a list number, a full id, or a unique prefix.
@@ -1488,10 +1729,9 @@ const AGENT_COMMANDS = new Set([
1488
1729
  'tools',
1489
1730
  'permissions',
1490
1731
  'skill',
1491
- 'tool',
1492
1732
  'scope',
1493
1733
  'connect',
1494
- 'cred'
1734
+ 'folders'
1495
1735
  ])
1496
1736
  const NO_AGENT = 'no agent in this mesh · /agent new <name> or /agent use <name|id>'
1497
1737
 
@@ -1503,6 +1743,12 @@ const isOwnDefault = (agent, deviceId) =>
1503
1743
  b4a.equals(agent.providerDeviceId, deviceId)
1504
1744
  const ownDefault = (agents, deviceId) => agents.find((agent) => isOwnDefault(agent, deviceId))
1505
1745
 
1746
+ // deviceInfo carries no model: the recommendation lives on the device's own row in the account
1747
+ async function recommendedModel(engine, deviceId) {
1748
+ const meshId = await accountMeshId(engine)
1749
+ return (await engine.getDevice({ meshId, deviceId })).recommendedModelName
1750
+ }
1751
+
1506
1752
  // mints one on timeout: an unbounded wait blocks the composer, and an account may hold no agent
1507
1753
  async function firstAgent(engine, meshId, { deviceId, modelName, remembered, account }) {
1508
1754
  const watch = engine.agentsWatch({ meshId })[Symbol.asyncIterator]()
@@ -1549,14 +1795,14 @@ async function firstAgent(engine, meshId, { deviceId, modelName, remembered, acc
1549
1795
  name: 'QV.AC',
1550
1796
  bio: 'You are a helpful local assistant. Be clear, practical, and concise.',
1551
1797
  providerDeviceId: deviceId,
1552
- modelName: modelName || (await engine.deviceInfo({})).recommendedModelName,
1798
+ modelName: modelName || (await recommendedModel(engine, deviceId)),
1553
1799
  isDefault: true
1554
1800
  }
1555
1801
  })
1556
1802
  }
1557
1803
 
1558
- // the account's birth op seeds a default chat; the provider mints one if none replicates in time
1559
- async function firstChat(engine, meshId, { agent, isProvider, remembered, account }) {
1804
+ // a new account seeds no chat, so any of its devices mints one when none replicates in time
1805
+ async function firstChat(engine, meshId, { agent, remembered, account }) {
1560
1806
  const watch = engine.chatsWatch({ meshId })[Symbol.asyncIterator]()
1561
1807
  let timer
1562
1808
  const timeout = new Promise((resolve) => {
@@ -1588,14 +1834,31 @@ async function firstChat(engine, meshId, { agent, isProvider, remembered, accoun
1588
1834
  return null
1589
1835
  }
1590
1836
 
1591
- if (isProvider) {
1592
- return engine.createChat({ meshId, agentId: agent.id, config: { title: 'New Chat' } })
1837
+ return engine.createChat({ meshId, agentId: agent.id, config: { title: 'New Chat' } })
1838
+ }
1839
+
1840
+ const NO_WORKSPACE = 'you are in no workspace - /mesh new creates one, /join <invite> joins one'
1841
+
1842
+ // the workspace a window opens on: the last chat's if still listed, else the first, else none
1843
+ async function windowWorkspace(engine) {
1844
+ // from joined on, an empty list means no workspace rather than one still being minted
1845
+ for await (const status of engine.meshStatusWatch?.({}) ?? []) {
1846
+ if (status.state === 'joined') break
1847
+ }
1848
+
1849
+ const { meshes } = await engine.listMeshes({})
1850
+ const workspaces = (meshes ?? []).filter((mesh) => mesh.workspace)
1851
+ const config = engine.getConfig ? await engine.getConfig({}) : null
1852
+ for (const { meshId } of config?.activeChatId ? workspaces : []) {
1853
+ if (await engine.getChat({ meshId, chatId: config.activeChatId }).catch(() => null)) {
1854
+ return meshId
1855
+ }
1593
1856
  }
1594
1857
 
1595
- throw new Error('no chat replicated before timeout')
1858
+ return workspaces[0]?.meshId ?? null
1596
1859
  }
1597
1860
 
1598
- // the account, where a window starts; a kicked device has none until Core adopts or mints the next
1861
+ // the account, where agents and devices live; a kicked device has none until Core mints the next
1599
1862
  async function accountMeshId(engine) {
1600
1863
  for await (const account of engine.accountWatch({})) {
1601
1864
  if (account.meshId) return account.meshId
@@ -1630,15 +1893,22 @@ export class ChatApp {
1630
1893
  copyToClipboard,
1631
1894
  resolvePastedFile,
1632
1895
  resolveFileAttachment,
1896
+ applyUpdate,
1633
1897
  saveDir,
1634
- skills
1898
+ skills,
1899
+ openUrl
1635
1900
  }) {
1636
1901
  this.engine = engine
1637
1902
  // Core holds no selection, so the mesh this window looks at is the client's choice
1638
1903
  this.meshId = meshId || null
1639
1904
  this._skills = skills || null
1905
+ // the form a skill is being set up through, drawn over everything else while open
1906
+ this._sheet = null
1907
+ this._openUrl = openUrl || openInBrowser
1640
1908
  this.agent = agent
1641
1909
  this.chatId = chatId
1910
+ // the chat /mesh moved reports on when named none: its source row is purged once it lands
1911
+ this._lastMove = null
1642
1912
  // applied only if this device is the agent's provider; null on a joiner
1643
1913
  this._modelName = modelName || null
1644
1914
  // run as init()'s first command so the connection happens inside the TUI, not before render
@@ -1652,6 +1922,9 @@ export class ChatApp {
1652
1922
  this._resolvePastedFile = resolvePastedFile || null
1653
1923
  // `/attach <path>` resolver: named path -> attachment, or throws.
1654
1924
  this._resolveFileAttachment = resolveFileAttachment || null
1925
+ this.updateBanner = applyUpdate
1926
+ ? updateBanner.create({ onAccept: applyUpdate, acceptKey: 'ctrl+u' })
1927
+ : null
1655
1928
  this._selection = null // { anchor, focus, edge } in content cells, while a drag selects text
1656
1929
  this._dragToken = 0 // stale-guards the edge auto-scroll beats
1657
1930
  this._saveDir = saveDir || path.join(os.homedir(), 'Downloads')
@@ -1684,8 +1957,12 @@ export class ChatApp {
1684
1957
  this._files = []
1685
1958
  this._filesIterator = null
1686
1959
  this._customModels = new Map()
1960
+ this._modelsDevice = null // set by /device: the account device the /models commands act on
1687
1961
  this._pickableFiles = []
1962
+ this._previewedProjections = new Map() // src → the projector its last preview checked, for /models add
1688
1963
  this._statusIterator = null
1964
+ this._downloadsIterator = null
1965
+ this.modelDownloads = new Map()
1689
1966
  this.meshStatus = null // last meshStatusWatch frame — rendered in the header
1690
1967
  this._devicesIterator = null
1691
1968
  this.deviceLabels = new Map() // hex device id → name, from devicesWatch
@@ -1695,6 +1972,8 @@ export class ChatApp {
1695
1972
  this._diagnosticsIterator = null
1696
1973
  this.overlay = null
1697
1974
  this._pinnedOverlay = null
1975
+ // { overlay, text } for ctrl+y, keyed on overlay identity so any other overlay invalidates it
1976
+ this._doctorReport = null
1698
1977
  // apart from `overlay` because its rows respond to ↑/↓ and enter
1699
1978
  this._models = null
1700
1979
  this._selector = null
@@ -1738,6 +2017,7 @@ export class ChatApp {
1738
2017
  _engineWatches() {
1739
2018
  return [
1740
2019
  this._watchNextStatus(),
2020
+ this._watchNextDownloads(),
1741
2021
  this._watchNextDiagnostics(),
1742
2022
  this._watchNextMeshes(),
1743
2023
  this._enterMesh()
@@ -1758,7 +2038,8 @@ export class ChatApp {
1758
2038
  _resolveAccount() {
1759
2039
  return async () => {
1760
2040
  try {
1761
- return { type: 'mesh.account', meshId: await accountMeshId(this.engine) }
2041
+ const meshId = await windowWorkspace(this.engine)
2042
+ return meshId ? { type: 'mesh.account', meshId } : { type: 'mesh.none' }
1762
2043
  } catch (error) {
1763
2044
  return { type: 'boot-error', error }
1764
2045
  }
@@ -1780,14 +2061,15 @@ export class ChatApp {
1780
2061
  _bootstrap() {
1781
2062
  return async () => {
1782
2063
  try {
1783
- const { account } = await firstWritable(this.engine, this.meshId)
2064
+ // a chat names a workspace now, so the first agent and chat are minted in one as in the account
2065
+ const { account, workspace } = await firstWritable(this.engine, this.meshId)
1784
2066
  // the pick the last session persisted; null on a fake engine that has no config
1785
2067
  const config = this.engine.getConfig ? await this.engine.getConfig({}) : null
1786
2068
  let agent = await firstAgent(this.engine, this.meshId, {
1787
2069
  deviceId: this.originDeviceId,
1788
2070
  modelName: this._modelName,
1789
2071
  remembered: config?.activeAgentId,
1790
- account
2072
+ account: account || workspace
1791
2073
  })
1792
2074
  if (!agent) {
1793
2075
  return { type: 'booted', agent: null, chat: null, remembered: false }
@@ -1806,9 +2088,8 @@ export class ChatApp {
1806
2088
 
1807
2089
  const chat = await firstChat(this.engine, this.meshId, {
1808
2090
  agent,
1809
- isProvider,
1810
2091
  remembered: config?.activeChatId,
1811
- account
2092
+ account: account || workspace
1812
2093
  })
1813
2094
  if (!chat) {
1814
2095
  return { type: 'booted', agent, chat: null, remembered: false }
@@ -1992,6 +2273,21 @@ export class ChatApp {
1992
2273
  }
1993
2274
  }
1994
2275
 
2276
+ _reopenMeshes(meshes) {
2277
+ if (!this.engine.openMesh) return null
2278
+
2279
+ return meshes
2280
+ .filter((mesh) => !mesh.open)
2281
+ .map((mesh) => async () => {
2282
+ try {
2283
+ await this.engine.openMesh({ meshId: mesh.meshId })
2284
+ return null
2285
+ } catch (error) {
2286
+ return { type: 'mesh.reopen-failed', meshId: mesh.meshId, error }
2287
+ }
2288
+ })
2289
+ }
2290
+
1995
2291
  // the window's mesh can go without the window doing anything: a kick retires the account
1996
2292
  _watchNextMeshes() {
1997
2293
  if (!this.engine.meshesWatch) return null
@@ -2030,6 +2326,24 @@ export class ChatApp {
2030
2326
  }
2031
2327
  }
2032
2328
 
2329
+ _watchNextDownloads() {
2330
+ const gen = this.gen
2331
+ if (!this._downloadsIterator) {
2332
+ this._downloadsIterator = this.engine.modelDownloadsWatch({})[Symbol.asyncIterator]()
2333
+ }
2334
+
2335
+ const it = this._downloadsIterator
2336
+
2337
+ return async () => {
2338
+ const { value, done } = await it.next()
2339
+ if (done) {
2340
+ return { type: 'model-downloads.done', gen }
2341
+ }
2342
+
2343
+ return { type: 'model-downloads', gen, downloads: value.downloads ?? [] }
2344
+ }
2345
+ }
2346
+
2033
2347
  _setTranscript(chunks) {
2034
2348
  this._turns = turnsFromChunks(chunks)
2035
2349
  this.pendingApproval = findPendingApproval(this._turns)
@@ -2067,7 +2381,11 @@ export class ChatApp {
2067
2381
  if (this.pendingApproval) return null
2068
2382
  if (!this.busy) return null
2069
2383
  const runTurn = runningAgentTurn(this._turns)
2070
- const { text, on } = busyStatus(this.modelState, runTurn, Date.now() - this._busySince)
2384
+ const { text, on } = busyStatus(this.modelState, runTurn, {
2385
+ elapsed: Date.now() - this._busySince,
2386
+ selfId: this.originDeviceId ? b4a.toHex(this.originDeviceId) : '',
2387
+ downloads: this.modelDownloads
2388
+ })
2071
2389
  const where = this._busyDevice(on, runTurn)
2072
2390
 
2073
2391
  return fg.dim.render(`${this.spin.view()} ${text}${where ? ` (on ${where})` : ''}`)
@@ -2119,10 +2437,18 @@ export class ChatApp {
2119
2437
  }
2120
2438
 
2121
2439
  _render() {
2440
+ if (this._sheet) {
2441
+ const { lines, at } = formatSheet(this._sheet, fg)
2442
+ this._setRows(lines, at)
2443
+
2444
+ return
2445
+ }
2446
+
2122
2447
  if (this._models) {
2123
2448
  const rows = formatModels(this._models.rows, this._models.filter, {
2124
2449
  cursor: this._models.cursor,
2125
- currentModel: this.agent?.modelName
2450
+ currentModel: this.agent?.modelName,
2451
+ device: this._models.device?.name
2126
2452
  })
2127
2453
  this._setRows(rows, this._models.cursor + 2)
2128
2454
 
@@ -2130,7 +2456,12 @@ export class ChatApp {
2130
2456
  }
2131
2457
 
2132
2458
  if (this._selector) {
2133
- this._setRows(formatSelector(this._selector), this._selector.cursor + 2)
2459
+ const line =
2460
+ this._selector.kind === 'tools'
2461
+ ? toolsCursorLine(this._selector)
2462
+ : this._selector.cursor + 2
2463
+ this._setRows(formatSelector(this._selector), line)
2464
+
2134
2465
  return
2135
2466
  }
2136
2467
 
@@ -2228,20 +2559,26 @@ export class ChatApp {
2228
2559
  ' /export [n] — write the last run (or last n) to a markdown file: prompt, thinking, answer, tools',
2229
2560
  '',
2230
2561
  'Agent',
2231
- ' /agents — pick from your agents to switch (interactive) · /agent — show current · /agent list · /agent new <name> · /agent rename <name> · /agent use <name|id> · /agent borrow [none] - borrow the model from the compute mesh, or stop',
2562
+ ' /agents — pick from your agents to switch (interactive) · /agent — show current · /agent list · /agent new <name> · /agent rename <name> · /agent use <name|id>',
2232
2563
  " /activity — list the active agent's recent tool calls, each with its decision (allowed/denied/auto/skip-all/blocked)",
2233
2564
  ' /ctx — pick the agent’s context size (the current one and the model’s maximum shown) · /ctx <tokens> (8192, 8k; k = 1,024) · /ctx auto — clear it so the device default applies',
2234
- ' /skills · /tools — browse installed; ↑/↓ move, space toggles each on/off (sets scope=selected), enter sets up or reconfigures the skill, esc returns',
2235
- ' /skill on|off <name> · /tool on|off <name> — toggle (sets scope=selected)',
2236
- ' /permissions — approval mode + the toolset switches; ↑/↓ move, space toggles',
2565
+ ' /skills — browse installed; ↑/↓ move, space toggles each on/off (sets scope=selected; one that needs setup opens it first), enter sets up or reconfigures the skill, esc returns',
2566
+ ' /skill on|off <name> — toggle (sets scope=selected); turning on one that needs setup opens its setup, and it turns on once that succeeds',
2567
+ ' /tools — the toolset switches, each listing the tools it gates; ↑/↓ move, space toggles a set',
2568
+ ' /permissions — the approval mode; space toggles',
2237
2569
  ' /models delete <name> · /models download <name> — remove a model from this device, or fetch it now',
2570
+ ' /models load <model> · unload <model> · pause <name> · resume <name> — load or unload a model now, or hold its download',
2571
+ ' /models idle <never|minutes> · cap <percent> · settings — free loaded models after that long with no request, the share of memory they may fill, and both settings',
2572
+ ' /device [list] · /device use <n|name|id> · /device here — point /models at another device of this account, or back at this one',
2238
2573
  ' /models [type] — browse every model in the SDK registry; type is an SDK addon (llm, tts, whisper, embeddings, diffusion, …) or an alias (transcription, embedding, image); ↑/↓ move, space selects',
2239
- ' /models custom · preview <src|n> [mmproj] · add <label> <src|n> [tools|vision|thinking] · use <name|label> · remove <name|label> — check a GGUF by url or local path, add it, and pick it; its context window caps /ctx',
2574
+ ' /models custom · preview <src|n> [mmproj] · add <label> <src|n> [mmproj] [tools|vision|thinking] · use <name|label> · remove <name|label> — check a GGUF by url or local path, add it, and pick it; its context window caps /ctx',
2240
2575
  ' /image [model <choice> | steps <n> | size <WxH> | reset] — the agent’s image-generation defaults',
2241
2576
  '',
2242
- 'Connections — a skill that needs an account or a token (Menu ▸ Agent ▸ Connections lists them with their state)',
2243
- ' /connect <skill> — OAuth-connect a skill that declares one (the Connections page lists them)',
2244
- ' the client app credentials come from <PROVIDER>_OAUTH_CLIENT_ID and <PROVIDER>_OAUTH_CLIENT_SECRET; a skill that registers its own client needs neither',
2577
+ 'Connections — a skill that needs an account, a token, a folder or an install (Menu ▸ Agent ▸ Connections lists them with their state)',
2578
+ ' /skill <name> — set a skill up: what it needs, its fields (secrets masked, ctrl+r shows them), then sign in or save · /connect <name> is the same',
2579
+ ' /skill <name> connect · disconnect — sign in again, or remove what the skill stored (an OAuth client app is kept)',
2580
+ ' /skill <name> set <field> [value] — set one field from a script; without a value the sheet opens on that field so a secret stays off screen',
2581
+ ' an OAuth skill with no client typed in uses <PROVIDER>_OAUTH_CLIENT_ID and <PROVIDER>_OAUTH_CLIENT_SECRET when both are set',
2245
2582
  '',
2246
2583
  'Voice',
2247
2584
  ' /speak <text> — synthesize speech (TTS) to a WAV file in the save dir',
@@ -2251,16 +2588,20 @@ export class ChatApp {
2251
2588
  ' /record [seconds] [device] — record from the mic via ffmpeg (macOS avfoundation) and transcribe',
2252
2589
  '',
2253
2590
  'Advanced',
2254
- ' /cred <key> <value> — set a credential by hand for this agent (e.g. /cred github_access_token ghp_…); /skills, enter on the skill, fills this in for you',
2255
- ' /scope skills|tools all|selected — switch scope',
2256
- ' /join <qvac://mesh/…> — preview who you would join as (ctrl+y copies this mesh’s invite) · /join yes — confirm and retire this device’s mesh for that one · /join cancel — abort a join in progress',
2591
+ ' /folders — the folders on this device the agent may use with its file tools · /folders add <path> [ro|rw] — share one, read-only unless rw · /folders remove <path>',
2592
+ ' /scope skills all|selected — switch scope',
2593
+ ' /join <qvac://device/… or qvac://workspace/…> — preview who you would join as (ctrl+y copies this mesh’s invite) · /join yes — confirm it (a device invite retires this device’s mesh, a member invite adds one beside it) · /join cancel — abort a join in progress',
2257
2594
  ' /leave — leave the active mesh; the device lands on another mesh it can write to, or mints a fresh account',
2258
2595
  ' /invite - show this mesh device invite · /invite member - open your shared mesh and invite someone into it (your account is never shared)',
2259
- ' /mesh new - open another shared mesh · /mesh new compute - lend this device · /mesh label <n|id> <name> - name a mesh, privately to you',
2596
+ ' /mesh new - open another shared mesh · /mesh label <n|id> <name> - name a mesh, privately to you',
2260
2597
  ' /members — list mesh members with their devices grouped',
2261
- ' /meshes - list the meshes this device belongs to, numbered, marking account / shared / active / open / writable',
2598
+ ' /rename device <name> — name this device · /rename member <name> — name yourself, across every mesh',
2599
+ ' /meshes - list the meshes this device belongs to, numbered, marking home (your account) / shared / active / open / writable',
2262
2600
  ' /mesh use <n|id> - make one of them active; its agent, chat and roster replace the ones on screen',
2263
- ' /my-device — dump this device\u2019s CPU/GPU inventory (manufacturer, cores, drivers, …)'
2601
+ ' /mesh move <n|id> [chat] - move this chat (or the named one) into another mesh, its files and running turn with it · /mesh moved [chat] - how that move is going',
2602
+ ' /my-device — dump this device\u2019s CPU/GPU inventory (manufacturer, cores, drivers, …)',
2603
+ ' /doctor — check this device: hardware, engine, model backends, mesh, network. ctrl+y copies the report, secrets redacted',
2604
+ ' /doctor debug — the raw diagnostics frame behind those checks'
2264
2605
  ].join('\n')
2265
2606
 
2266
2607
  const notice = (t) => [this, async () => ({ type: 'notice', text: t })]
@@ -2330,6 +2671,19 @@ export class ChatApp {
2330
2671
  return this._showDiagnostics()
2331
2672
  }
2332
2673
 
2674
+ if (cmd === 'doctor') {
2675
+ const action = rest[0]?.toLowerCase()
2676
+ if (!action) {
2677
+ return this._runDoctor()
2678
+ }
2679
+
2680
+ if (action === 'debug') {
2681
+ return this._showDoctor()
2682
+ }
2683
+
2684
+ return notice('usage: /doctor [debug] — checks, or the raw diagnostics frame')
2685
+ }
2686
+
2333
2687
  if (cmd === 'usage') {
2334
2688
  if (rawArgs.trim()) {
2335
2689
  return notice('usage: /usage')
@@ -2355,6 +2709,47 @@ export class ChatApp {
2355
2709
  return this._setContextSize(size)
2356
2710
  }
2357
2711
 
2712
+ if (cmd === 'device') {
2713
+ const action = rest[0]?.toLowerCase()
2714
+ const USAGE = 'usage: /device [list] · use <n|name|id> · here'
2715
+ if (action === 'here') {
2716
+ this._modelsDevice = null
2717
+ return notice('/models acts on this device')
2718
+ }
2719
+
2720
+ if (action && action !== 'list' && action !== 'use') {
2721
+ return notice(USAGE)
2722
+ }
2723
+
2724
+ return run(async () => {
2725
+ const listed = await this._accountDevices(await accountMeshId(engine))
2726
+ const devices = (listed ?? []).filter((device) => !device.revoked)
2727
+ const own = this.originDeviceId ?? (await engine.deviceInfo({})).id
2728
+ const target = this._modelsDevice
2729
+ // a roster that could not be read says nothing about whether the target left
2730
+ if (listed && target && !devices.some((device) => b4a.equals(device.id, target.id))) {
2731
+ this._modelsDevice = null
2732
+ }
2733
+
2734
+ if (action === 'use') {
2735
+ const picked = pickDevice(devices, rest.slice(1).join(' '))
2736
+ if (!picked) {
2737
+ return `no such device — /device list shows them\n${USAGE}`
2738
+ }
2739
+
2740
+ this._modelsDevice = b4a.equals(picked.id, own) ? null : picked
2741
+
2742
+ return `/models acts on ${this._modelsDevice ? picked.name : 'this device'}`
2743
+ }
2744
+
2745
+ const connected = new Set(
2746
+ (this.meshStatus?.peerDeviceIds ?? []).map((id) => id.toLowerCase())
2747
+ )
2748
+
2749
+ return deviceLines(devices, { own, target: this._modelsDevice?.id, connected }).join('\n')
2750
+ })
2751
+ }
2752
+
2358
2753
  if (cmd === 'models' && !MODEL_VERBS.has(rest[0]?.toLowerCase())) {
2359
2754
  const raw = rest[0]?.toLowerCase()
2360
2755
  if (!raw) {
@@ -2374,7 +2769,68 @@ export class ChatApp {
2374
2769
  if (cmd === 'models') {
2375
2770
  const raw = rest[0]?.toLowerCase()
2376
2771
  const USAGE =
2377
- 'usage: /models [type] · custom · preview <src|n> [mmproj] · add <label> <src|n> [tools] [vision] [thinking] · use <name|label> · remove <name|label> · load <model> · unload <model> · delete <name> · download <name>'
2772
+ 'usage: /models [type] · custom · preview <src|n> [mmproj] · add <label> <src|n> [mmproj] [tools] [vision] [thinking] · use <name|label> · remove <name|label> · load <model> · unload <model> · delete <name> · download <name> · pause <name> · resume <name> · idle <never|minutes> · cap <percent> · settings'
2773
+ const models = this._modelsEngine()
2774
+ const on = this._modelsDevice
2775
+ const where = (text) => (on ? `${on.name}: ${text}` : text)
2776
+ if (raw === 'idle') {
2777
+ const asked = rest[1]?.toLowerCase()
2778
+ const minutes = asked === 'never' ? 0 : Number(asked)
2779
+ if (!asked || (minutes !== 0 && !MODEL_IDLE_UNLOAD_MINUTES.includes(minutes))) {
2780
+ return notice(`usage: /models idle never|${MODEL_IDLE_UNLOAD_MINUTES.join('|')}`)
2781
+ }
2782
+
2783
+ return run(async () => {
2784
+ await models.configSet({ key: MODEL_IDLE_UNLOAD_KEY, value: minutes })
2785
+ return where(
2786
+ minutes
2787
+ ? `loaded models are freed after ${minutes} min with no request`
2788
+ : 'loaded models are never freed for being idle'
2789
+ )
2790
+ })
2791
+ }
2792
+
2793
+ if (raw === 'cap') {
2794
+ const percent = Number(rest[1])
2795
+ if (
2796
+ !Number.isInteger(percent) ||
2797
+ percent < MODEL_MEMORY_CAP_MIN ||
2798
+ percent > MODEL_MEMORY_CAP_MAX
2799
+ ) {
2800
+ return notice(`usage: /models cap <${MODEL_MEMORY_CAP_MIN}..${MODEL_MEMORY_CAP_MAX}>`)
2801
+ }
2802
+
2803
+ return run(async () => {
2804
+ await models.configSet({ key: MODEL_MEMORY_CAP_KEY, value: percent })
2805
+ return where(`loaded models may fill ${percent}% of the memory usable for models`)
2806
+ })
2807
+ }
2808
+
2809
+ if (raw === 'settings') {
2810
+ return run(async () => {
2811
+ const idle = (await models.configGet({ key: MODEL_IDLE_UNLOAD_KEY })).value
2812
+ const cap = (await models.configGet({ key: MODEL_MEMORY_CAP_KEY })).value
2813
+ return where(
2814
+ [
2815
+ `free when idle: ${idle ? `${idle} min` : 'never'}`,
2816
+ `memory cap: ${cap ? `${cap}%` : `${MODEL_MEMORY_CAP_DEFAULT}% (default)`}`
2817
+ ].join(' · ')
2818
+ )
2819
+ })
2820
+ }
2821
+
2822
+ if (raw === 'pause' || raw === 'resume') {
2823
+ const name = rest.slice(1).join(' ')
2824
+ if (!name) {
2825
+ return notice(`usage: /models ${raw} <name>`)
2826
+ }
2827
+
2828
+ return run(async () => {
2829
+ await models.setModelPaused({ name, paused: raw === 'pause' })
2830
+ return where(`${name} ${raw === 'pause' ? 'paused' : 'resumed'}`)
2831
+ })
2832
+ }
2833
+
2378
2834
  if (raw === 'load' || raw === 'unload') {
2379
2835
  const name = rest.slice(1).join(' ')
2380
2836
  if (!name) {
@@ -2383,18 +2839,22 @@ export class ChatApp {
2383
2839
 
2384
2840
  return run(async () => {
2385
2841
  if (raw === 'unload') {
2386
- const { unloaded } = await engine.unloadModel({ name })
2387
- return unloaded ? `${name} unloaded` : `${name} is still in use — try again shortly`
2842
+ const { unloaded } = await models.unloadModel({ name })
2843
+ return where(
2844
+ unloaded ? `${name} unloaded` : `${name} is still in use — try again shortly`
2845
+ )
2388
2846
  }
2389
2847
 
2390
- const { loaded, reason } = await engine.loadModel({ name })
2848
+ const { loaded, reason } = await models.loadModel({ name })
2391
2849
  if (loaded) {
2392
- return `${name} loaded`
2850
+ return where(`${name} loaded`)
2393
2851
  }
2394
2852
 
2395
- return reason === 'memory'
2396
- ? `${name} would not fit beside the loaded models — unload one first`
2397
- : `${name} could not be loaded`
2853
+ return where(
2854
+ reason === 'memory'
2855
+ ? `${name} would not fit beside the loaded models — unload one first`
2856
+ : `${name} could not be loaded`
2857
+ )
2398
2858
  })
2399
2859
  }
2400
2860
 
@@ -2404,28 +2864,34 @@ export class ChatApp {
2404
2864
  return notice(`usage: /models ${raw} <name>`)
2405
2865
  }
2406
2866
 
2407
- return run(() =>
2408
- raw === 'delete' ? deleteModel(engine, name) : downloadModel(engine, name)
2867
+ return run(async () =>
2868
+ where(
2869
+ await (raw === 'delete'
2870
+ ? deleteModel(models, name, on?.name)
2871
+ : downloadModel(models, name, on?.name))
2872
+ )
2409
2873
  )
2410
2874
  }
2411
2875
 
2412
2876
  if (raw === 'custom') {
2413
2877
  return run(async () => {
2414
- await this._refreshCustomModels()
2415
- const models = [...this._customModels.values()]
2416
- if (models.length === 0) {
2417
- return 'no models added yet — /models add <name> <src>'
2878
+ const added = [...(await this._modelsLibrary()).values()]
2879
+ if (added.length === 0) {
2880
+ return where('no models added yet — /models add <name> <src>')
2418
2881
  }
2419
2882
 
2420
- return models
2421
- .map((m) => {
2422
- const ctx =
2423
- m.contextLength > 0 ? formatTokenCount(m.contextLength) : 'ctx window unknown'
2424
- const about = [m.taskType, m.license].filter(Boolean).join(' · ')
2425
-
2426
- return `${m.label || m.name} ${m.name}\n ${m.src}\n ${ctx}${about ? ` · ${about}` : ''}`
2427
- })
2428
- .join('\n')
2883
+ return where(
2884
+ added
2885
+ .map((m) => {
2886
+ const ctx =
2887
+ m.contextLength > 0 ? formatTokenCount(m.contextLength) : 'ctx window unknown'
2888
+ const about = [m.taskType, m.license].filter(Boolean).join(' · ')
2889
+ const projector = m.mmprojSrc ? `\n projector ${m.mmprojSrc}` : ''
2890
+
2891
+ return `${m.label || m.name} ${m.name}\n ${m.src}${projector}\n ${ctx}${about ? ` · ${about}` : ''}`
2892
+ })
2893
+ .join('\n')
2894
+ )
2429
2895
  })
2430
2896
  }
2431
2897
 
@@ -2435,41 +2901,48 @@ export class ChatApp {
2435
2901
  return notice(USAGE)
2436
2902
  }
2437
2903
 
2904
+ const mmprojSrc = rest[2]
2905
+
2438
2906
  return run(async () => {
2439
- const preview = await engine.previewCustomModel({ src, mmprojSrc: rest[2] })
2907
+ const preview = await models.previewCustomModel({ src, mmprojSrc })
2440
2908
  if (!preview.src && preview.files?.length) {
2441
2909
  this._pickableFiles = preview.files
2442
2910
  }
2443
2911
 
2444
- return formatModelPreview(preview)
2912
+ this._previewedProjections.set(src, preview.mmprojSrc)
2913
+
2914
+ return where(formatModelPreview(preview))
2445
2915
  })
2446
2916
  }
2447
2917
 
2448
2918
  if (raw === 'add') {
2449
2919
  const label = rest[1]
2450
2920
  const src = this._pickedSource(rest[2])
2451
- if (!label || !src) {
2921
+ const flags = new Set(rest.slice(3).map((f) => f.toLowerCase()))
2922
+ const projections = rest.slice(3).filter((f) => !MODEL_ADD_FLAGS.has(f.toLowerCase()))
2923
+ if (!label || !src || projections.length > 1) {
2452
2924
  return notice(USAGE)
2453
2925
  }
2454
2926
 
2455
- const flags = new Set(rest.slice(3).map((f) => f.toLowerCase()))
2456
-
2457
2927
  return run(async () => {
2458
- const { id } = await engine.addCustomModel({
2928
+ const mmprojSrc = projections[0] ?? (await this._pairedProjection(src))
2929
+ const { id } = await models.addCustomModel({
2459
2930
  label,
2460
2931
  src,
2932
+ mmprojSrc,
2461
2933
  supportsTools: flags.has('tools'),
2462
- supportsVision: flags.has('vision'),
2934
+ supportsVision: flags.has('vision') || Boolean(mmprojSrc),
2463
2935
  supportsThinking: flags.has('thinking')
2464
2936
  })
2465
- await this._refreshCustomModels()
2466
- const row = this._customModels.get(id)
2937
+ const row = (await this._modelsLibrary()).get(id)
2467
2938
  const ctx =
2468
2939
  row && row.contextLength > 0
2469
2940
  ? `context window ${formatTokenCount(row.contextLength)}`
2470
2941
  : 'context window unknown — the picker uses the default range'
2471
2942
 
2472
- return `added ${label} as ${id}\n ${row?.src ?? src}\n ${ctx}`
2943
+ const projector = row?.mmprojSrc ? `\n projector ${row.mmprojSrc}` : ''
2944
+
2945
+ return where(`added ${label} as ${id}\n ${row?.src ?? src}${projector}\n ${ctx}`)
2473
2946
  })
2474
2947
  }
2475
2948
 
@@ -2479,12 +2952,20 @@ export class ChatApp {
2479
2952
  return notice(USAGE)
2480
2953
  }
2481
2954
 
2955
+ if (on) {
2956
+ return notice(notOursToUse(on))
2957
+ }
2958
+
2482
2959
  return run(async () => {
2483
2960
  await this._refreshCustomModels()
2484
2961
  const custom = await this._customModelFor(asked)
2485
2962
  const unrunnable = customModelTaskRefusal(custom?.taskType)
2486
2963
  if (unrunnable) {
2487
- return `${asked} was not set — ${unrunnable}`
2964
+ return `${asked} was not set \u2014 ${unrunnable.message}`
2965
+ }
2966
+
2967
+ if (!custom && !(await isListedModel(engine, asked))) {
2968
+ return `${asked} was not set \u2014 no added model has that name, and it ${notInCatalog('this device')}`
2488
2969
  }
2489
2970
 
2490
2971
  const name = custom?.name ?? asked
@@ -2506,17 +2987,16 @@ export class ChatApp {
2506
2987
  }
2507
2988
 
2508
2989
  return run(async () => {
2509
- await this._refreshCustomModels()
2510
- const custom = await this._customModelFor(asked)
2990
+ const custom = await this._customModelFor(asked, await this._modelsLibrary(), models)
2511
2991
  if (!custom) {
2512
- return deleteModel(engine, asked)
2992
+ return where(await deleteModel(models, asked, on?.name))
2513
2993
  }
2514
2994
 
2515
- const { freedBytes } = await engine.removeCustomModel({ name: custom.name })
2995
+ const { freedBytes } = await models.removeCustomModel({ name: custom.name })
2516
2996
  await this._refreshCustomModels()
2517
2997
  const freed = freedBytes > 0 ? `freed ${bytesToGb(freedBytes)}` : 'nothing was downloaded'
2518
2998
 
2519
- return `removed ${custom.label || custom.name} — ${freed}`
2999
+ return where(`removed ${custom.label || custom.name} — ${freed}`)
2520
3000
  })
2521
3001
  }
2522
3002
 
@@ -2594,7 +3074,7 @@ export class ChatApp {
2594
3074
 
2595
3075
  return run(async () => {
2596
3076
  // persist through the runtime's own clamp/snap so the stored size is the effective one
2597
- const { settingsDimension } = await import('@qvac/harness/lib/tools/generate-image.ts')
3077
+ const { settingsDimension } = await import('@qvac/harness/plugins/image')
2598
3078
  const width = settingsDimension(Number(match[1]))
2599
3079
  const height = settingsDimension(Number(match[2]))
2600
3080
  if (!width || !height) {
@@ -2620,11 +3100,8 @@ export class ChatApp {
2620
3100
  if (!action) {
2621
3101
  return run(async () => {
2622
3102
  const a = await engine.getAgent({ meshId: this.meshId, agentId: agent.id })
2623
- const lender = a.lenderDeviceId
2624
- ? ` · model borrowed from ${b4a.toHex(a.lenderDeviceId).slice(0, 8)}`
2625
- : ''
2626
3103
 
2627
- return `agent ${a.name} (${a.id.slice(0, 8)}) · skills=${a.skillsScope ?? 'all'} tools=${a.toolsScope ?? 'all'}${lender}`
3104
+ return `agent ${a.name} (${a.id.slice(0, 8)}) · skills=${a.skillsScope ?? 'all'}`
2628
3105
  })
2629
3106
  }
2630
3107
 
@@ -2649,13 +3126,15 @@ export class ChatApp {
2649
3126
  name: arg,
2650
3127
  bio: `${arg} — test agent`,
2651
3128
  providerDeviceId: this.originDeviceId,
2652
- modelName: agent?.modelName ?? (await engine.deviceInfo({})).recommendedModelName
3129
+ modelName:
3130
+ agent?.modelName ??
3131
+ this._modelName ??
3132
+ (await recommendedModel(engine, this.originDeviceId))
2653
3133
  }
2654
3134
  })
2655
- this.agent = created
2656
- await this._persistSelection()
3135
+ await this._handChatTo(created)
2657
3136
 
2658
- return `created + selected ${created.name} (${created.id.slice(0, 8)}) · no skills/tools enabled`
3137
+ return `created + selected ${created.name} (${created.id.slice(0, 8)}) · no skills enabled`
2659
3138
  })
2660
3139
  }
2661
3140
 
@@ -2673,41 +3152,11 @@ export class ChatApp {
2673
3152
  return `renamed to ${this.agent.name} (${this.agent.id.slice(0, 8)})`
2674
3153
  })
2675
3154
  }
2676
-
2677
- if (action === 'borrow') {
2678
- return run(async () => {
2679
- if (arg === 'none') {
2680
- this.agent = await engine.updateAgent({
2681
- meshId: this.meshId,
2682
- agentId: agent.id,
2683
- config: { clearLenderDeviceId: true }
2684
- })
2685
- return `${this.agent.name} answers on this device again`
2686
- }
2687
-
2688
- if (arg) {
2689
- return 'usage: /agent borrow · /agent borrow none'
2690
- }
2691
-
2692
- const { computeLenderId } = await engine.deviceInfo({})
2693
- if (!computeLenderId) {
2694
- return 'no single device to borrow from - /mesh new compute lends one, and two lenders is no choice'
2695
- }
2696
-
2697
- this.agent = await engine.updateAgent({
2698
- meshId: this.meshId,
2699
- agentId: agent.id,
2700
- config: { lenderDeviceId: computeLenderId }
2701
- })
2702
-
2703
- return `${this.agent.name} borrows its model from ${b4a.toHex(computeLenderId).slice(0, 8)}`
2704
- })
2705
- }
2706
-
2707
- if (action === 'use') {
2708
- if (!arg) {
2709
- return notice('usage: /agent use <name|id>')
2710
- }
3155
+
3156
+ if (action === 'use') {
3157
+ if (!arg) {
3158
+ return notice('usage: /agent use <name|id>')
3159
+ }
2711
3160
 
2712
3161
  return run(async () => {
2713
3162
  const { agents } = await engine.listAgents({ meshId: this.meshId })
@@ -2716,14 +3165,13 @@ export class ChatApp {
2716
3165
  return `no agent matching: ${arg}`
2717
3166
  }
2718
3167
 
2719
- this.agent = found
2720
- await this._persistSelection()
3168
+ await this._handChatTo(found)
2721
3169
 
2722
3170
  return `selected ${found.name} (${found.id.slice(0, 8)})`
2723
3171
  })
2724
3172
  }
2725
3173
 
2726
- return notice('usage: /agent [list|new <name>|rename <name>|use <name|id>|borrow [none]]')
3174
+ return notice('usage: /agent [list|new <name>|rename <name>|use <name|id>]')
2727
3175
  }
2728
3176
 
2729
3177
  if (cmd === 'activity') {
@@ -2749,65 +3197,40 @@ export class ChatApp {
2749
3197
  })
2750
3198
  }
2751
3199
 
2752
- if (cmd === 'skills' || cmd === 'tools') {
3200
+ if (cmd === 'skills') {
2753
3201
  return this._showSelector(cmd)
2754
3202
  }
2755
3203
 
3204
+ if (cmd === 'tools') {
3205
+ return this._showTools()
3206
+ }
3207
+
2756
3208
  if (cmd === 'permissions') {
2757
3209
  return this._showPermissions()
2758
3210
  }
2759
3211
 
2760
- if (cmd === 'skill' || cmd === 'tool') {
2761
- const [action, name] = rest
2762
- if ((action !== 'on' && action !== 'off') || !name) {
2763
- return notice(`usage: /${cmd} on|off <name>`)
3212
+ if (cmd === 'skill') {
3213
+ const [action = '', name] = rest
3214
+ if ((action === 'on' || action === 'off') && name) {
3215
+ return action === 'on'
3216
+ ? this._skillOn(name)
3217
+ : run(() => this._toggleSkill(name, { on: false }))
2764
3218
  }
2765
3219
 
2766
- const field = cmd === 'skill' ? 'enabledSkills' : 'enabledTools'
2767
- const scopeField = cmd === 'skill' ? 'skillsScope' : 'toolsScope'
2768
-
2769
- return run(async () => {
2770
- const fresh = await engine.getAgent({ meshId: this.meshId, agentId: agent.id })
2771
- const set = new Set(fresh[field] ?? [])
2772
- if (action === 'on') {
2773
- set.add(name)
2774
- } else {
2775
- set.delete(name)
2776
- }
2777
-
2778
- const updated = await engine.updateAgent({
2779
- meshId: this.meshId,
2780
- agentId: agent.id,
2781
- config: { [field]: [...set], [scopeField]: 'selected' }
2782
- })
2783
- this.agent = updated
2784
- const line = `${cmd} ${name} ${action} · ${field}=[${[...set].join(', ')}] scope=selected`
2785
- if (cmd !== 'skill' || action !== 'on') {
2786
- return line
2787
- }
2788
-
2789
- const skill = (await this._skillDetail())?.get(name)
2790
- if (!skill || isReady(skill)) {
2791
- return line
2792
- }
2793
-
2794
- return `${line}\n${renderSkill(skill)}`
2795
- })
3220
+ return this._skillCommand(rawArgs) ?? notice(SKILL_USAGE)
2796
3221
  }
2797
3222
 
2798
3223
  if (cmd === 'scope') {
2799
3224
  const [which, value] = rest
2800
- if ((which !== 'skills' && which !== 'tools') || (value !== 'all' && value !== 'selected')) {
2801
- return notice('usage: /scope skills|tools all|selected')
3225
+ if (which !== 'skills' || (value !== 'all' && value !== 'selected')) {
3226
+ return notice('usage: /scope skills all|selected')
2802
3227
  }
2803
3228
 
2804
- const scopeField = which === 'skills' ? 'skillsScope' : 'toolsScope'
2805
-
2806
3229
  return run(async () => {
2807
3230
  const updated = await engine.updateAgent({
2808
3231
  meshId: this.meshId,
2809
3232
  agentId: agent.id,
2810
- config: { [scopeField]: value }
3233
+ config: { skillsScope: value }
2811
3234
  })
2812
3235
  this.agent = updated
2813
3236
 
@@ -3095,137 +3518,30 @@ export class ChatApp {
3095
3518
  )
3096
3519
  }
3097
3520
 
3521
+ // the name it had before /skill took over; the sheet it opens is the same one
3098
3522
  if (cmd === 'connect') {
3099
- const [slug = ''] = rest
3100
- if (!slug) {
3101
- return notice('usage: /connect <skill> — Menu ▸ Agent ▸ Connections lists them')
3102
- }
3103
-
3104
- return run(async () => {
3105
- let skills
3106
- try {
3107
- skills = this._skills ? await this._skills(agent.id, agent.modelName, this.meshId) : []
3108
- } catch (error) {
3109
- return `could not read the skill catalog: ${error?.message ?? error}`
3110
- }
3111
-
3112
- const matches = oauthSpecs(skills ?? []).filter(
3113
- (candidate) => connectSlug(candidate.credentialKey) === slug
3114
- )
3115
- if (matches.length === 0) {
3116
- return `no connectable skill named ${slug} — Menu ▸ Agent ▸ Connections`
3117
- }
3118
-
3119
- if (matches.length > 1) {
3120
- const keys = matches.map((m) => m.credentialKey).join(', ')
3121
- return `${slug} is ambiguous — matches ${keys}, use the full credential key`
3122
- }
3123
-
3124
- const [spec] = matches
3125
- // setup fields are stored per declaring skill, and a `secret` one in the credential namespace
3126
- const owner = (skills ?? []).find((skill) =>
3127
- (skill.setup?.routes ?? []).some((route) => route.credentialKey === spec.credentialKey)
3128
- )
3129
- const ownerRoute = (owner?.setup?.routes ?? []).find(
3130
- (route) => route.credentialKey === spec.credentialKey
3131
- )
3132
- const storedField = async (name) => {
3133
- const field = (ownerRoute?.fields ?? []).find((entry) => entry.key === name)
3134
- if (!field || !owner) {
3135
- return ''
3136
- }
3137
-
3138
- const key =
3139
- field.secret === true
3140
- ? credKey(agent.id, field.key)
3141
- : settingConfigKey(agent.id, owner.name, field.key)
3142
- const { value } = await engine.configGet({ key })
3143
-
3144
- return typeof value === 'string' ? value : ''
3145
- }
3146
- const env = spec.provider.toUpperCase().replaceAll('-', '_')
3147
- const idVar = `${env}_OAUTH_CLIENT_ID`
3148
- const secretVar = `${env}_OAUTH_CLIENT_SECRET`
3149
- const needsSecret = spec.tokenAuth !== 'pkce-only'
3150
- const clientId = (await storedField('clientId')) || process.env[idVar] || ''
3151
- const clientSecret = (await storedField('clientSecret')) || process.env[secretVar] || ''
3152
- // registrationEndpoint implies pkce-only, so a DCR skill never hits the secret check below
3153
- if (!clientId && !spec.registrationEndpoint) {
3154
- return needsSecret
3155
- ? `set ${idVar} and ${secretVar}, then retry`
3156
- : `set ${idVar}, then retry`
3157
- }
3158
-
3159
- if (needsSecret && !clientSecret) {
3160
- return `set ${idVar} and ${secretVar}, then retry`
3161
- }
3162
-
3163
- const { buildProviderConfig, runOAuthFlow } = await import('../dist-lib/lib/oauth.js')
3164
- let registeredClientId = ''
3165
- const tokens = await runOAuthFlow(
3166
- buildProviderConfig(spec, {
3167
- clientId,
3168
- clientSecret: needsSecret ? clientSecret : undefined
3169
- }),
3170
- {
3171
- openUrl: (url) => {
3172
- this.status = fg.dim.render(`authorize in your browser: ${url}`)
3173
- this._render()
3174
- openInBrowser(url)
3175
- },
3176
- getClientId: async () => {
3177
- // read back a client a prior run registered instead of registering anew every /connect
3178
- const { value } = await engine.configGet({ key: credKey(agent.id, spec.stateKey) })
3179
- try {
3180
- const state = typeof value === 'string' ? JSON.parse(value) : null
3181
- return state?.clientId || undefined
3182
- } catch {
3183
- return undefined
3184
- }
3185
- },
3186
- saveClientId: async (id) => {
3187
- registeredClientId = id
3188
- }
3189
- }
3190
- )
3191
- await engine.configSet({
3192
- key: credKey(agent.id, spec.credentialKey),
3193
- value: tokens.accessToken
3194
- })
3195
- await engine.configSet({
3196
- key: credKey(agent.id, spec.stateKey),
3197
- value: JSON.stringify({
3198
- refreshToken: tokens.refreshToken,
3199
- expiresAt: tokens.expiresAt,
3200
- clientId: clientId || registeredClientId,
3201
- clientSecret: needsSecret ? clientSecret : undefined
3202
- })
3203
- })
3204
-
3205
- return `${slug} connected for agent ${agent.name} — token stored, auto-refreshes on use`
3206
- })
3523
+ const [name] = rest
3524
+ return name ? this._skillSheet(name, { start: true }) : notice(SKILL_USAGE)
3207
3525
  }
3208
3526
 
3209
- if (cmd === 'cred') {
3210
- const [key, ...valueParts] = rest
3211
- const value = valueParts.join(' ')
3212
- if (!key || !value) {
3213
- return notice('usage: /cred <key> <value>')
3214
- }
3215
-
3216
- return run(async () => {
3217
- const storageKey = credKey(agent.id, key)
3218
- await engine.configSet({ key: storageKey, value })
3527
+ if (cmd === 'folders') {
3528
+ return [
3529
+ this,
3530
+ async () => {
3531
+ const provider = agent.providerDeviceId
3532
+ const remote = provider && !(await this._hostedHere(provider))
3533
+ const host = remote ? this._deviceName(b4a.toHex(provider)) : null
3219
3534
 
3220
- return `set ${key} for agent ${agent.name} (${value.length} chars) — scoped, not shared`
3221
- })
3535
+ return foldersCommand(engine, { agent, host }, rawArgs)
3536
+ }
3537
+ ]
3222
3538
  }
3223
3539
 
3224
3540
  // sending blocks for the join: everything held goes stale once the window lands on the new mesh
3225
3541
  if (cmd === 'join') {
3226
3542
  const arg = rawArgs.trim()
3227
3543
  if (!arg) {
3228
- return notice('usage: /join <qvac://mesh/…> · /join cancel')
3544
+ return notice('usage: /join <qvac://device/… or qvac://workspace/…> · /join cancel')
3229
3545
  }
3230
3546
 
3231
3547
  if (rest[0] === 'cancel') {
@@ -3239,7 +3555,9 @@ export class ChatApp {
3239
3555
  if (rest[0] === 'yes') {
3240
3556
  const pending = this._pendingJoinInvite
3241
3557
  if (!pending) {
3242
- return notice('usage: /join <qvac://mesh/…> to preview an invite first')
3558
+ return notice(
3559
+ 'usage: /join <qvac://device/… or qvac://workspace/…> to preview an invite first'
3560
+ )
3243
3561
  }
3244
3562
 
3245
3563
  this._pendingJoinInvite = null
@@ -3261,13 +3579,15 @@ export class ChatApp {
3261
3579
 
3262
3580
  this._pendingJoinInvite = invite
3263
3581
  let who = 'a device on this account'
3582
+ let effect = 'this device’s current mesh is retired'
3264
3583
  if (preview.memberInvite) {
3265
3584
  who = 'a new person'
3585
+ effect = 'it is added beside your meshes, nothing is retired'
3266
3586
  } else if (preview.inviterName) {
3267
3587
  who = `one of ${preview.inviterName}'s devices`
3268
3588
  }
3269
3589
 
3270
- return `you will join as ${who} — run /join yes to confirm, or /join cancel to back out`
3590
+ return `you will join as ${who}; ${effect} — run /join yes to confirm, or /join cancel to back out`
3271
3591
  })
3272
3592
  }
3273
3593
 
@@ -3328,7 +3648,7 @@ export class ChatApp {
3328
3648
  // ctrl+y copies the active mesh invite, so a shared-mesh invite never lands in this.invite
3329
3649
  const copied = await this._copyQuietly(res.invite)
3330
3650
  if (!member) {
3331
- return `device invite - the joiner is adopted into your member${copied ? ' (copied)' : ''}:\n${res.invite}`
3651
+ return `device invite - the joiner is adopted into your member${copied ? ' (copied)' : ''}; it runs /join, or starts duck --device-join <invite>:\n${res.invite}`
3332
3652
  }
3333
3653
 
3334
3654
  const lines = [await this._meshHeading(res.meshId)]
@@ -3336,9 +3656,8 @@ export class ChatApp {
3336
3656
  lines.push(res.notice)
3337
3657
  }
3338
3658
 
3339
- const { meshes: listed } = await engine.listMeshes({}).catch(() => ({ meshes: [] }))
3340
- const isCompute = (listed ?? []).find((m) => m.meshId === res.meshId)?.compute
3341
- lines.push(...(isCompute ? COMPUTE_INVITE_DISCLOSURES : MEMBER_INVITE_DISCLOSURES))
3659
+ lines.push(...MEMBER_INVITE_DISCLOSURES)
3660
+ lines.push('the invitee runs /join <invite>, or starts duck --join <invite>')
3342
3661
  lines.push(`${copied ? 'invite (copied)' : 'invite'}:\n${res.invite}`)
3343
3662
 
3344
3663
  return lines.join('\n')
@@ -3379,6 +3698,26 @@ export class ChatApp {
3379
3698
  })
3380
3699
  }
3381
3700
 
3701
+ if (cmd === 'rename') {
3702
+ const [action, ...nameParts] = rest
3703
+ const name = nameParts.join(' ')
3704
+ if (!name || (action !== 'device' && action !== 'member')) {
3705
+ return notice('usage: /rename device <name> · /rename member <name>')
3706
+ }
3707
+
3708
+ return run(async () => {
3709
+ if (action === 'device') {
3710
+ await engine.renameDevice({ meshId: this.meshId, config: { name } })
3711
+
3712
+ return `this device is now "${name}"`
3713
+ }
3714
+
3715
+ await engine.updateMember({ config: { name } })
3716
+
3717
+ return `you are now "${name}" in every mesh`
3718
+ })
3719
+ }
3720
+
3382
3721
  if (cmd === 'meshes') {
3383
3722
  return run(async () => {
3384
3723
  const { meshes } = await engine.listMeshes({})
@@ -3394,9 +3733,8 @@ export class ChatApp {
3394
3733
  }
3395
3734
 
3396
3735
  if (action === 'new') {
3397
- const compute = target === 'compute'
3398
3736
  return run(async () => {
3399
- const { meshId } = await engine.createMesh({ config: { compute } })
3737
+ const { meshId } = await engine.createWorkspace({ config: { name: 'Workspace' } })
3400
3738
  const invite = '/invite member <n|id> invites someone into it'
3401
3739
  return `${await this._meshHeading(meshId)}\n${invite}`
3402
3740
  })
@@ -3420,7 +3758,21 @@ export class ChatApp {
3420
3758
  })
3421
3759
  }
3422
3760
 
3423
- return notice('usage: /mesh use <n|id> · /mesh new [compute] · /mesh label <n|id> <name>')
3761
+ if (action === 'move' && target) {
3762
+ return run(() => this._moveChat(target, labelParts.join(' ')))
3763
+ }
3764
+
3765
+ if (action === 'moved') {
3766
+ return run(() => this._movedChat(target))
3767
+ }
3768
+
3769
+ if (action === 'fork' && target) {
3770
+ return run(() => this._forkChatInto(target, labelParts))
3771
+ }
3772
+
3773
+ return notice(
3774
+ 'usage: /mesh use <n|id> · /mesh new · /mesh label <n|id> <name> · /mesh move <n|id> [chat] · /mesh moved [chat] · /mesh fork <n|id> [turn] [before]'
3775
+ )
3424
3776
  }
3425
3777
 
3426
3778
  // the same interactive pickers as the menu's Switch rows, rather than a list to /…use by id
@@ -3462,6 +3814,10 @@ export class ChatApp {
3462
3814
  return this._deleteChat(arg)
3463
3815
  }
3464
3816
 
3817
+ if (action === 'fork') {
3818
+ return this._forkChat(argParts)
3819
+ }
3820
+
3465
3821
  if (action === 'rename') {
3466
3822
  if (!arg) {
3467
3823
  return notice('usage: /chat rename <title>')
@@ -3494,7 +3850,7 @@ export class ChatApp {
3494
3850
  }
3495
3851
 
3496
3852
  return notice(
3497
- 'usage: /chat [new <title>|use <id>|rename <title>|del <id>|websearch on|off|rag on|off]'
3853
+ 'usage: /chat [new <title>|use <id>|rename <title>|fork [turn] [before]|del <id>|websearch on|off|rag on|off]'
3498
3854
  )
3499
3855
  }
3500
3856
 
@@ -3835,6 +4191,73 @@ export class ChatApp {
3835
4191
  ]
3836
4192
  }
3837
4193
 
4194
+ // the fork opens in this window, since it lands in the mesh this window is on
4195
+ _forkChat(args) {
4196
+ return [
4197
+ this,
4198
+ async () => {
4199
+ try {
4200
+ if (!this.chatId) {
4201
+ return { type: 'notice', text: 'no chat is open' }
4202
+ }
4203
+
4204
+ const cut = await this._forkCutOf(args)
4205
+ if (cut.miss) {
4206
+ return { type: 'notice', text: cut.miss }
4207
+ }
4208
+
4209
+ const chatId = this.chatId
4210
+ const fork = await this.engine.forkChat({ meshId: this.meshId, chatId, ...cut.request })
4211
+ const notice = `forked ${cut.label} into "${fork.title}" (${fork.id.slice(0, 8)})`
4212
+
4213
+ return { type: 'chat.switch', chat: fork, agent: await this._agentFor(fork), notice }
4214
+ } catch (error) {
4215
+ return { type: 'run.error', error }
4216
+ }
4217
+ }
4218
+ ]
4219
+ }
4220
+
4221
+ async _forkCutOf(args) {
4222
+ const { chunks } = await this.engine.listChunks({ meshId: this.meshId, chatId: this.chatId })
4223
+ return forkCut(chunks ?? [], args)
4224
+ }
4225
+
4226
+ // the target's first agent answers it there, as a move picks one; a mesh with none cannot take it
4227
+ async _forkChatInto(selector, args) {
4228
+ const named = await this._resolveMesh(selector)
4229
+ if (named.error) {
4230
+ return named.error
4231
+ }
4232
+
4233
+ if (!this.chatId) {
4234
+ return 'no chat is open'
4235
+ }
4236
+
4237
+ const cut = await this._forkCutOf(args)
4238
+ if (cut.miss) {
4239
+ return cut.miss
4240
+ }
4241
+
4242
+ const { agents } = await this.engine.listAgents({ meshId: named.meshId })
4243
+ if (!agents?.length) {
4244
+ return `${named.meshId.slice(0, 8)} has no agent to answer a fork - /agent new there first`
4245
+ }
4246
+
4247
+ const fork = await this.engine.forkChat({
4248
+ meshId: this.meshId,
4249
+ chatId: this.chatId,
4250
+ targetMeshId: named.meshId,
4251
+ agentId: agents[0].id,
4252
+ ...cut.request
4253
+ })
4254
+ const { meshes } = await this.engine.listMeshes({}).catch(() => ({ meshes: [] }))
4255
+ const index = (meshes ?? []).findIndex((mesh) => mesh.meshId === named.meshId)
4256
+ const where = index < 0 ? '/meshes lists it' : `/mesh use ${index + 1} to open it`
4257
+
4258
+ return `forked ${cut.label} into "${fork.title}" in ${named.meshId.slice(0, 8)} - ${where}`
4259
+ }
4260
+
3838
4261
  _deleteChat(needle) {
3839
4262
  return [
3840
4263
  this,
@@ -3963,6 +4386,20 @@ export class ChatApp {
3963
4386
  }
3964
4387
  }
3965
4388
 
4389
+ // the chat row names its agent, or reopening the chat or another device hands it back to the old one
4390
+ async _handChatTo(agent) {
4391
+ if (this.chatId) {
4392
+ await this.engine.setChatAgent({
4393
+ meshId: this.meshId,
4394
+ chatId: this.chatId,
4395
+ agentId: agent.id
4396
+ })
4397
+ }
4398
+
4399
+ this.agent = agent
4400
+ await this._persistSelection()
4401
+ }
4402
+
3966
4403
  // kept in Core's device-local config, the same record the desktop app resumes from
3967
4404
  async _persistSelection() {
3968
4405
  if (!this.engine.getConfig || !this.agent || !this.chatId) return
@@ -3981,7 +4418,7 @@ export class ChatApp {
3981
4418
  }
3982
4419
  }
3983
4420
 
3984
- _switchTo(chat, agent) {
4421
+ _switchTo(chat, agent, notice) {
3985
4422
  this._resetChatWatches()
3986
4423
  this.chatId = chat.id
3987
4424
  if (agent) {
@@ -3993,7 +4430,7 @@ export class ChatApp {
3993
4430
  this._awaitingRun = false
3994
4431
  this._runningRunId = null
3995
4432
  this.pendingApproval = null
3996
- this.notice = `switched to "${chat.title}" (${chat.id.slice(0, 8)})`
4433
+ this.notice = notice ?? `switched to "${chat.title}" (${chat.id.slice(0, 8)})`
3997
4434
  this._render()
3998
4435
  }
3999
4436
 
@@ -4022,6 +4459,11 @@ export class ChatApp {
4022
4459
  return
4023
4460
  }
4024
4461
 
4462
+ if (this._sheet) {
4463
+ typeInto(this._sheet, text.trim())
4464
+ return
4465
+ }
4466
+
4025
4467
  const lines = text.split('\n').length
4026
4468
  if (lines === 1) {
4027
4469
  return this._insertText(text)
@@ -4086,7 +4528,7 @@ export class ChatApp {
4086
4528
  this._historyAt = null
4087
4529
  this._historyDraft = ''
4088
4530
  const value = line.trim()
4089
- if (!value || this._history[this._history.length - 1] === value) {
4531
+ if (!value || SECRET_COMMAND.test(value) || this._history[this._history.length - 1] === value) {
4090
4532
  return
4091
4533
  }
4092
4534
 
@@ -4132,6 +4574,77 @@ export class ChatApp {
4132
4574
  ]
4133
4575
  }
4134
4576
 
4577
+ // every verdict but the deltas answers from one frame, so the report renders before the gap
4578
+ _runDoctor() {
4579
+ const { engine } = this
4580
+ return [
4581
+ this,
4582
+ async () => {
4583
+ try {
4584
+ const first = (await engine.diagnostics({})).stats
4585
+ return { type: 'doctor.checks', samples: { first } }
4586
+ } catch (error) {
4587
+ return { type: 'doctor.checks', error }
4588
+ }
4589
+ }
4590
+ ]
4591
+ }
4592
+
4593
+ // only the movement rows are still open, so this re-renders over the report on screen
4594
+ _settleDoctor(first, overlay) {
4595
+ const { engine } = this
4596
+ return async () => {
4597
+ try {
4598
+ // lunte-disable-next-line qvac/no-sleep -- a sampling interval: the deltas need frames apart
4599
+ await new Promise((resolve) => setTimeout(resolve, DOCTOR_SAMPLE_GAP_MS))
4600
+ const second = (await engine.diagnostics({})).stats
4601
+ return { type: 'doctor.checks', samples: { first, second }, overlay }
4602
+ } catch (error) {
4603
+ return { type: 'doctor.checks', error, overlay }
4604
+ }
4605
+ }
4606
+ }
4607
+
4608
+ // a fresh snapshot, not this.diagnostics: the watch only runs while the footer is live
4609
+ _showDoctor() {
4610
+ const { engine } = this
4611
+ return [
4612
+ this,
4613
+ async () => {
4614
+ try {
4615
+ const { stats } = await engine.diagnostics({})
4616
+ return { type: 'doctor.result', stats }
4617
+ } catch (error) {
4618
+ return { type: 'doctor.result', error }
4619
+ }
4620
+ }
4621
+ ]
4622
+ }
4623
+
4624
+ // null when no doctor report is on screen, so ctrl+y falls through to the invite
4625
+ _copyReport() {
4626
+ const report = this._doctorReport
4627
+ if (!report || report.overlay !== this.overlay || !this._copyToClipboard) {
4628
+ return null
4629
+ }
4630
+
4631
+ const { text } = report
4632
+ const copy = this._copyToClipboard
4633
+ const token = ++this._statusToken
4634
+
4635
+ return [
4636
+ this,
4637
+ async () => {
4638
+ try {
4639
+ await copy(text)
4640
+ return { type: 'transient-status', token, text: 'report copied ✓' }
4641
+ } catch (err) {
4642
+ return { type: 'transient-status', token, text: `copy failed: ${err.message}` }
4643
+ }
4644
+ }
4645
+ ]
4646
+ }
4647
+
4135
4648
  // /usage: the chat's run statuses carry the last run's own numbers; the folds say why they dropped
4136
4649
  _showUsage() {
4137
4650
  const { engine, chatId } = this
@@ -4155,7 +4668,8 @@ export class ChatApp {
4155
4668
  }
4156
4669
 
4157
4670
  _showModels(type) {
4158
- const { engine } = this
4671
+ const engine = this._modelsEngine()
4672
+ const device = this._modelsDevice
4159
4673
  return [
4160
4674
  this,
4161
4675
  async () => {
@@ -4164,7 +4678,7 @@ export class ChatApp {
4164
4678
  fullRegistry: true,
4165
4679
  type
4166
4680
  })
4167
- return { type: 'models.result', filter: type, rows: models ?? [] }
4681
+ return { type: 'models.result', filter: type, rows: models ?? [], device }
4168
4682
  } catch (error) {
4169
4683
  return { type: 'models.result', filter: type, rows: null, error }
4170
4684
  }
@@ -4173,69 +4687,100 @@ export class ChatApp {
4173
4687
  }
4174
4688
 
4175
4689
  // resolved by where the provider is, not by the mesh on screen: a shared mesh carries no inventory
4176
- async _providerCaps(kind, detail) {
4690
+ async _providerCaps(detail) {
4177
4691
  const provider = this.agent?.providerDeviceId
4178
4692
  if (!provider) {
4179
4693
  return { names: [], reason: 'no-provider' }
4180
4694
  }
4181
4695
 
4182
- // originDeviceId is bound late, so an early selector must ask rather than guess
4183
- const own = this.originDeviceId ?? (await this.engine.deviceInfo({})).id
4184
- if (own && b4a.equals(own, provider)) {
4185
- const names = await this._localCaps(kind, detail)
4696
+ if (await this._hostedHere(provider)) {
4697
+ const names = await this._localCaps(detail)
4186
4698
  if (names.length) {
4187
4699
  return { names, reason: null }
4188
4700
  }
4189
4701
 
4190
- // a harness that cannot describe its tools still published its catalog to the account
4191
- return this._rosterCaps(kind, provider, 'none-installed')
4702
+ // a device that resolves no skills locally still published its catalog to the account
4703
+ return this._rosterCaps(provider, 'none-installed')
4192
4704
  }
4193
4705
 
4194
- return this._rosterCaps(kind, provider, 'none-advertised')
4706
+ return this._rosterCaps(provider, 'none-advertised')
4195
4707
  }
4196
4708
 
4197
- async _localCaps(kind, detail) {
4198
- if (kind === 'tools') {
4199
- const { tools } = (await this.engine.tools?.()) ?? { tools: [] }
4200
- return (tools ?? []).map((t) => t.name)
4201
- }
4202
-
4709
+ async _localCaps(detail) {
4203
4710
  // detail is passed in, never re-fetched: it is already this device's resolved skill list
4204
4711
  if (detail) {
4205
4712
  return [...detail.keys()]
4206
4713
  }
4207
4714
 
4208
- const skills = (await this._skills?.(this.agent?.id, this.agent?.modelName, this.meshId)) ?? []
4715
+ const skills = (await this._readSkills()) ?? []
4209
4716
 
4210
4717
  return skills.map((s) => s.name)
4211
4718
  }
4212
4719
 
4720
+ async _hostedHere(provider) {
4721
+ // originDeviceId is bound late, so an early selector must ask rather than guess
4722
+ const own = this.originDeviceId ?? (await this.engine.deviceInfo({})).id
4723
+
4724
+ return !!own && b4a.equals(own, provider)
4725
+ }
4726
+
4727
+ async _rosterCaps(provider, emptyReason) {
4728
+ const { dev, reason, deviceName } = await this._rosterDevice(provider)
4729
+ if (!dev) {
4730
+ return { names: [], reason, deviceName }
4731
+ }
4732
+
4733
+ const names = dev.installedSkillNames ?? []
4734
+
4735
+ return { names, reason: names.length ? null : emptyReason, deviceName: dev.name }
4736
+ }
4737
+
4213
4738
  // the account may have been closed, so it is named and opened, never assumed
4214
- async _rosterCaps(kind, provider, emptyReason) {
4739
+ async _rosterDevice(provider) {
4215
4740
  const { meshes } = await this.engine.listMeshes({})
4216
4741
  const account = (meshes ?? []).find((m) => m.account)?.meshId
4217
4742
  if (!account) {
4218
- return { names: [], reason: 'no-account' }
4743
+ return { reason: 'no-account' }
4219
4744
  }
4220
4745
 
4221
4746
  const listed = await this._accountDevices(account)
4222
4747
  if (!listed) {
4223
- return { names: [], reason: 'account-closed' }
4748
+ return { reason: 'account-closed' }
4224
4749
  }
4225
4750
 
4226
4751
  const hex = b4a.toHex(provider)
4227
4752
  const dev = listed.find((d) => b4a.toHex(d.id) === hex)
4228
4753
  if (!dev) {
4229
- return { names: [], reason: 'not-ours' }
4754
+ return { reason: 'not-ours' }
4230
4755
  }
4231
4756
 
4232
4757
  if (dev.revoked) {
4233
- return { names: [], reason: 'removed', deviceName: dev.name }
4758
+ return { reason: 'removed', deviceName: dev.name }
4759
+ }
4760
+
4761
+ return { dev }
4762
+ }
4763
+
4764
+ // the host's own catalog, since the switches gate the tools of the device the agent runs on
4765
+ async _providerTools() {
4766
+ const provider = this.agent?.providerDeviceId
4767
+ if (!provider) {
4768
+ return { catalog: null, reason: 'no-provider' }
4234
4769
  }
4235
4770
 
4236
- const names = (kind === 'tools' ? dev.installedToolNames : dev.installedSkillNames) ?? []
4771
+ if (await this._hostedHere(provider)) {
4772
+ return { catalog: (await this.engine.tools({})).tools, reason: null }
4773
+ }
4237
4774
 
4238
- return { names, reason: names.length ? null : emptyReason, deviceName: dev.name }
4775
+ const { dev, reason, deviceName } = await this._rosterDevice(provider)
4776
+ if (!dev) {
4777
+ return { catalog: null, reason, deviceName }
4778
+ }
4779
+
4780
+ // an older build publishes no catalog, which is not the same as having no tools
4781
+ const catalog = dev.toolCatalog ?? null
4782
+
4783
+ return { catalog, reason: catalog ? null : 'none-advertised', deviceName: dev.name }
4239
4784
  }
4240
4785
 
4241
4786
  // a close racing the read rejects here, and an unreadable account is a message, not a failure
@@ -4259,10 +4804,10 @@ export class ChatApp {
4259
4804
  async () => {
4260
4805
  try {
4261
4806
  const fresh = await engine.getAgent({ meshId: this.meshId, agentId: agent.id })
4262
- const scope = (kind === 'skills' ? fresh.skillsScope : fresh.toolsScope) ?? 'selected'
4263
- const enabled = (kind === 'skills' ? fresh.enabledSkills : fresh.enabledTools) ?? []
4264
- const detail = kind === 'skills' ? await this._skillDetail() : null
4265
- const caps = await this._providerCaps(kind, detail)
4807
+ const scope = fresh.skillsScope ?? 'selected'
4808
+ const enabled = fresh.enabledSkills ?? []
4809
+ const detail = await this._skillDetail()
4810
+ const caps = await this._providerCaps(detail)
4266
4811
  const installed = caps.names
4267
4812
  const { reason, deviceName } = caps
4268
4813
  return {
@@ -4285,35 +4830,63 @@ export class ChatApp {
4285
4830
  // null when a pre-upgrade provider cannot report it; the selector then renders as it always did
4286
4831
  async _skillDetail() {
4287
4832
  if (!this._skills) return null
4288
- const skills = await this._skills(this.agent?.id, this.agent?.modelName, this.meshId).catch(
4289
- noop
4290
- )
4833
+ const skills = await this._readSkills().catch(noop)
4291
4834
 
4292
4835
  return skills ? new Map(skills.map((skill) => [skill.name, skill])) : null
4293
4836
  }
4294
4837
 
4838
+ _modelsEngine() {
4839
+ return onDevice(this.engine, this._modelsDevice?.id)
4840
+ }
4841
+
4842
+ async _customModelsOf(engine) {
4843
+ if (!engine?.customModelsWatch) return null
4844
+ const it = engine.customModelsWatch({})[Symbol.asyncIterator]()
4845
+ try {
4846
+ const frame = await it.next()
4847
+ return frame.done ? null : new Map((frame.value?.models ?? []).map((m) => [m.name, m]))
4848
+ } finally {
4849
+ await it.return?.().catch(noop)
4850
+ }
4851
+ }
4852
+
4853
+ // the agent's own library, which /ctx and /models use read whatever /device points at
4295
4854
  async _refreshCustomModels() {
4296
- if (!this.engine?.customModelsWatch) return
4297
- const it = this.engine.customModelsWatch({})[Symbol.asyncIterator]()
4298
- const frame = await it.next().catch(() => ({ done: true }))
4299
- await it.return?.().catch(noop)
4300
- if (!frame.done) {
4301
- this._customModels = new Map((frame.value?.models ?? []).map((m) => [m.name, m]))
4855
+ const customs = await this._customModelsOf(this.engine).catch(noop)
4856
+ if (customs) {
4857
+ this._customModels = customs
4858
+ }
4859
+ }
4860
+
4861
+ async _modelsLibrary() {
4862
+ if (!this._modelsDevice) {
4863
+ await this._refreshCustomModels()
4864
+ return this._customModels
4302
4865
  }
4866
+
4867
+ // a target that is away refuses, rather than reading as a library with nothing added
4868
+ return (await this._customModelsOf(this._modelsEngine())) ?? new Map()
4869
+ }
4870
+
4871
+ // Core takes a re-added row whole, so a rename that names no projector keeps the one it had
4872
+ async _pairedProjection(src) {
4873
+ const stored = [...(await this._modelsLibrary()).values()].find((m) => m.src === src)
4874
+
4875
+ return this._previewedProjections.get(src) ?? stored?.mmprojSrc
4303
4876
  }
4304
4877
 
4305
- async _customModelFor(nameOrLabel) {
4306
- const byId = this._customModels.get(nameOrLabel)
4878
+ async _customModelFor(nameOrLabel, customs = this._customModels, engine = this.engine) {
4879
+ const byId = customs.get(nameOrLabel)
4307
4880
  if (byId) {
4308
4881
  return byId
4309
4882
  }
4310
4883
 
4311
- const labelled = [...this._customModels.values()].find((model) => model.label === nameOrLabel)
4884
+ const labelled = [...customs.values()].find((model) => model.label === nameOrLabel)
4312
4885
  if (!labelled) {
4313
4886
  return undefined
4314
4887
  }
4315
4888
 
4316
- const { models } = await this.engine.listModels({ fullRegistry: true })
4889
+ const { models } = await engine.listModels({ fullRegistry: true })
4317
4890
 
4318
4891
  return models?.some((model) => model.name === nameOrLabel) ? undefined : labelled
4319
4892
  }
@@ -4387,7 +4960,6 @@ export class ChatApp {
4387
4960
  return this._setContextSize(size)
4388
4961
  }
4389
4962
 
4390
- // rows come from TOOLSETS so an uninstalled toolset can still be switched off ahead of time
4391
4963
  _showPermissions() {
4392
4964
  const { engine, agent } = this
4393
4965
  return [
@@ -4397,126 +4969,688 @@ export class ChatApp {
4397
4969
  const fresh = await engine.getAgent({ meshId: this.meshId, agentId: agent.id })
4398
4970
  return {
4399
4971
  type: 'permissions.result',
4400
- mode: fresh.approvalMode === 'skip-all' ? 'skip-all' : 'ask',
4401
- disabled: fresh.disabledToolsets ?? []
4972
+ mode: fresh.approvalMode === 'skip-all' ? 'skip-all' : 'ask'
4402
4973
  }
4403
4974
  } catch (error) {
4404
4975
  return { type: 'permissions.result', error }
4405
4976
  }
4406
4977
  }
4407
- ]
4408
- }
4978
+ ]
4979
+ }
4980
+
4981
+ // rows come from TOOLSETS so an uninstalled toolset can still be switched off ahead of time
4982
+ _showTools() {
4983
+ const { engine, agent } = this
4984
+ return [
4985
+ this,
4986
+ async () => {
4987
+ try {
4988
+ const [fresh, host] = await Promise.all([
4989
+ engine.getAgent({ meshId: this.meshId, agentId: agent.id }),
4990
+ // the switches still work without the list, so a failed read only loses the tool rows
4991
+ this._providerTools().catch(() => ({ catalog: null, reason: null }))
4992
+ ])
4993
+ return { type: 'tools.result', disabled: fresh.disabledToolsets ?? [], ...host }
4994
+ } catch (error) {
4995
+ return { type: 'tools.result', error }
4996
+ }
4997
+ }
4998
+ ]
4999
+ }
5000
+
5001
+ // ctrl+p / /menu: open the menu at its root, clearing any other overlay first.
5002
+ _openMenu() {
5003
+ this._models = null
5004
+ this._selector = null
5005
+ this.overlay = null
5006
+ this._menu = { pages: [this._rootMenu()] }
5007
+ this._render()
5008
+
5009
+ return [this, null]
5010
+ }
5011
+
5012
+ // an entry carries exactly one of submenu, overlay, command or prefill
5013
+ _rootMenu() {
5014
+ return {
5015
+ title: 'Menu',
5016
+ cursor: 0,
5017
+ entries: [
5018
+ { label: 'Agent', hint: 'skills, tools, permissions, model', submenu: true },
5019
+ { label: 'Chat', hint: 'this chat, knowledge, attachments', submenu: true },
5020
+ { label: 'Models', hint: "browse and pick the agent's model", overlay: 'models' },
5021
+ {
5022
+ label: 'Custom models',
5023
+ hint: 'register a GGUF by url/path; read its context window',
5024
+ command: '/models custom'
5025
+ },
5026
+ { label: 'Voice', hint: 'speak, transcribe, converse', submenu: true },
5027
+ { label: 'My device', hint: 'CPU / GPU inventory', overlay: 'diagnostics' },
5028
+ { label: 'Mesh', hint: 'join another device’s mesh', submenu: true },
5029
+ { label: 'Advanced', hint: 'credentials, scope, skill setup status', submenu: true },
5030
+ { label: 'Help', hint: 'list every command', command: '/help' }
5031
+ ]
5032
+ }
5033
+ }
5034
+
5035
+ _agentMenu() {
5036
+ return {
5037
+ title: `Agent · ${this.agent?.name ?? '?'}`,
5038
+ cursor: 0,
5039
+ entries: [
5040
+ { label: 'Skills', hint: 'toggle skills on/off', overlay: 'skills' },
5041
+ { label: 'Tools', hint: 'toolset switches & their tools', overlay: 'tools' },
5042
+ { label: 'Permissions', hint: 'approval mode', overlay: 'permissions' },
5043
+ { label: 'Model', hint: "pick the agent's model", overlay: 'models' },
5044
+ {
5045
+ label: 'Context size',
5046
+ hint: contextSizeHint(this.agent, this._contextOpts(this.agent?.modelName)),
5047
+ overlay: 'ctx'
5048
+ },
5049
+ { label: 'Image defaults', hint: 'model, steps, size', command: '/image' },
5050
+ { label: 'Activity', hint: 'recent tool calls', command: '/activity' },
5051
+ {
5052
+ label: 'Connections',
5053
+ hint: 'set up skills that need an account',
5054
+ submenu: true,
5055
+ connections: true
5056
+ },
5057
+ { label: 'Switch agent', hint: 'pick from your agents', submenu: true, agents: true },
5058
+ { label: 'New agent…', hint: '/agent new <name>', prefill: '/agent new ' },
5059
+ { label: 'Rename agent…', hint: '/agent rename <name>', prefill: '/agent rename ' }
5060
+ ]
5061
+ }
5062
+ }
5063
+
5064
+ // which skills are connectable is theirs to declare, so all this offers is the command itself
5065
+ _connectMenu() {
5066
+ return {
5067
+ title: 'Connections',
5068
+ cursor: 0,
5069
+ entries: [{ label: 'Set up a skill…', hint: '/skill <name>', prefill: '/skill ' }]
5070
+ }
5071
+ }
5072
+
5073
+ // one row per skill that takes setup; its sheet lists the ways in when there are several
5074
+ _connectPage() {
5075
+ return [
5076
+ this,
5077
+ async () => {
5078
+ const detail = await this._skillDetail()
5079
+ const skills = [...(detail?.values() ?? [])].filter((skill) => setupActions(skill).length)
5080
+ if (!skills.length) {
5081
+ return { type: 'menu.page', page: this._connectMenu() }
5082
+ }
5083
+
5084
+ const entries = skills.map((skill) => ({
5085
+ label: `${isReady(skill) ? '●' : '○'} ${skill.name}`,
5086
+ hint: skillState(skill),
5087
+ command: `/skill ${skill.name}`
5088
+ }))
5089
+
5090
+ return { type: 'menu.page', page: { title: 'Connections', cursor: 0, entries } }
5091
+ }
5092
+ ]
5093
+ }
5094
+
5095
+ // scoped to this agent on its own model, the way the harness gates a skill
5096
+ _readSkills({ refresh = false } = {}) {
5097
+ return this._skills?.(this.agent?.id, {
5098
+ modelName: this.agent?.modelName,
5099
+ meshId: this.meshId,
5100
+ refresh
5101
+ })
5102
+ }
5103
+
5104
+ // `/skill <name> [connect | disconnect | set <field> [value]]`; null is a usage error
5105
+ _skillCommand(args) {
5106
+ const [, name, verb = '', field, value] =
5107
+ args.match(/^(\S+)(?:\s+(\S+))?(?:\s+(\S+))?\s*(.*)$/) ?? []
5108
+ if (!name || name === 'on' || name === 'off') {
5109
+ return null
5110
+ }
5111
+
5112
+ if (!verb) {
5113
+ return this._skillSheet(name)
5114
+ }
5115
+
5116
+ if (verb === 'connect' || verb === 'disconnect') {
5117
+ return verb === 'connect'
5118
+ ? this._skillSheet(name, { start: true })
5119
+ : this._skillDisconnect(name)
5120
+ }
5121
+
5122
+ if (verb !== 'set' || !field) {
5123
+ return null
5124
+ }
5125
+
5126
+ return value ? this._skillSet(name, field, value) : this._skillSheet(name, { field })
5127
+ }
5128
+
5129
+ // asked afresh each time, so a name resolves against what is installed now
5130
+ async _lookupSkill(name) {
5131
+ if (!this._skills) {
5132
+ return { missing: 'this provider does not report its skills' }
5133
+ }
5134
+
5135
+ const skills = (await this._readSkills()) ?? []
5136
+ const skill = findSkill(skills, name)
5137
+ if (skill) {
5138
+ return { skill }
5139
+ }
5140
+
5141
+ const near = closestSkill(skills, name)
5142
+ const hint = near ? ` — did you mean ${near}?` : ''
5143
+
5144
+ return { missing: `no skill named ${name}${hint} · /skills lists them` }
5145
+ }
5146
+
5147
+ async _skillRow(name) {
5148
+ const skills = await this._readSkills({ refresh: true })
5149
+
5150
+ return skills?.find((skill) => skill.name === name) ?? null
5151
+ }
5152
+
5153
+ // the same write as the /skills space bar, so either moves the agent to scope=selected
5154
+ async _toggleSkill(name, { on }) {
5155
+ const { engine, agent } = this
5156
+ const fresh = await engine.getAgent({ meshId: this.meshId, agentId: agent.id })
5157
+ const set = new Set(fresh.enabledSkills ?? [])
5158
+ if (on) {
5159
+ set.add(name)
5160
+ } else {
5161
+ set.delete(name)
5162
+ }
5163
+
5164
+ this.agent = await engine.updateAgent({
5165
+ meshId: this.meshId,
5166
+ agentId: agent.id,
5167
+ config: { enabledSkills: [...set], skillsScope: 'selected' }
5168
+ })
5169
+
5170
+ return `skill ${name} ${on ? 'on' : 'off'} · enabledSkills=[${[...set].join(', ')}] scope=selected`
5171
+ }
5172
+
5173
+ // a skill that cannot work yet is set up first, and turned on once it can
5174
+ _skillOn(name) {
5175
+ return [
5176
+ this,
5177
+ async () => {
5178
+ try {
5179
+ const { skill, missing } = this._skills ? await this._lookupSkill(name) : {}
5180
+ if (missing) {
5181
+ return { type: 'notice', text: missing }
5182
+ }
5183
+
5184
+ if (skill && SETUP_FIXES.has(skill.status) && setupAction(skill)) {
5185
+ return { type: 'sheet.open', skill, enable: true }
5186
+ }
5187
+
5188
+ return { type: 'notice', text: await this._toggleSkill(name, { on: true }) }
5189
+ } catch (error) {
5190
+ return { type: 'run.error', error }
5191
+ }
5192
+ }
5193
+ ]
5194
+ }
5195
+
5196
+ _skillSheet(name, { start = false, field = null } = {}) {
5197
+ return this._withSkill(name, (skill) => {
5198
+ const routes = skillRoutes(skill)
5199
+ if (!routes.length) {
5200
+ return { type: 'notice', text: `${renderSkill(skill)}\n nothing to set up` }
5201
+ }
5202
+
5203
+ if (field && !routes.some((route) => hasField(route, field))) {
5204
+ const fields = routes.flatMap((route) => routeFields(route).map((entry) => entry.key))
5205
+ if (declaredCredentials(skill).includes(field)) {
5206
+ return {
5207
+ type: 'notice',
5208
+ text: `${field} has no field in ${skill.name}'s setup — /skill ${skill.name} set ${field} <value>`
5209
+ }
5210
+ }
5211
+
5212
+ return {
5213
+ type: 'notice',
5214
+ text: `${skill.name} has no field ${field} — it takes ${fields.join(', ')}`
5215
+ }
5216
+ }
5217
+
5218
+ return { type: 'sheet.open', skill, start, field }
5219
+ })
5220
+ }
5221
+
5222
+ // a value typed on the command line, for scripts; the sheet is where a secret stays off screen
5223
+ _skillSet(name, field, value) {
5224
+ return this._withSkill(name, async (skill) => {
5225
+ const route = settableRoute(skill, field)
5226
+ if (!route) {
5227
+ return {
5228
+ type: 'notice',
5229
+ text: `${skill.name} has no field ${field} · /skill ${skill.name} shows them`
5230
+ }
5231
+ }
5232
+
5233
+ const stored = route.kind === 'picker' ? expandHome(value) : value
5234
+ const { agent } = this
5235
+ await saveFields(this.engine, {
5236
+ agentId: agent.id,
5237
+ skillName: skill.name,
5238
+ route,
5239
+ values: { [field]: stored }
5240
+ })
5241
+ const secret = routeFields(route).find((entry) => entry.key === field)?.secret
5242
+ const shown = secret ? `(${stored.length} chars)` : `= ${stored}`
5243
+ const next = route.kind === 'oauth' ? ` · /skill ${skill.name} connect` : ''
5244
+
5245
+ return {
5246
+ type: 'notice',
5247
+ text: `${skill.name} ${field} ${shown} for agent ${agent.name}${next}`
5248
+ }
5249
+ })
5250
+ }
5251
+
5252
+ _skillDisconnect(name) {
5253
+ return this._withSkill(name, async (skill) => {
5254
+ const route = skillRoutes(skill).find((entry) => entry.credentialKey)
5255
+ if (!route) {
5256
+ return { type: 'notice', text: `${skill.name} stores nothing to disconnect` }
5257
+ }
5258
+
5259
+ await disconnect(this.engine, { agentId: this.agent.id, route })
5260
+ const kept = route.kind === 'oauth' ? ' — its client app is kept' : ''
5261
+
5262
+ return {
5263
+ type: 'notice',
5264
+ text: `${skill.name} disconnected for agent ${this.agent.name}${kept}`
5265
+ }
5266
+ })
5267
+ }
5268
+
5269
+ _withSkill(name, fn) {
5270
+ return [
5271
+ this,
5272
+ async () => {
5273
+ try {
5274
+ const { skill, missing } = await this._lookupSkill(name)
5275
+ return missing ? { type: 'notice', text: missing } : await fn(skill)
5276
+ } catch (error) {
5277
+ return { type: 'run.error', error }
5278
+ }
5279
+ }
5280
+ ]
5281
+ }
5282
+
5283
+ // the sheet sits over whatever opened it, so closing it lands back on the /skills list
5284
+ _openSheet(skill, { enable = false, field = null, start = false } = {}) {
5285
+ this._sheet = openSheet(skill, { routes: skillRoutes(skill), enable, field })
5286
+ this._menu = null
5287
+ this.overlay = null
5288
+ this._render()
5289
+
5290
+ return [this, this._loadSheet(this._sheet, { start })]
5291
+ }
5292
+
5293
+ // what an OAuth route already has, so the form says what may be left blank
5294
+ _loadSheet(sheet, { start = false } = {}) {
5295
+ const route = currentRoute(sheet)
5296
+ if (route?.kind !== 'oauth') {
5297
+ return null
5298
+ }
5299
+
5300
+ const { engine, agent } = this
5301
+
5302
+ return async () => {
5303
+ const spec = oauthSpecFor([sheet.skill], route.credentialKey)
5304
+ if (!spec) {
5305
+ return { type: 'sheet.client', sheet, oauth: { spec: null } }
5306
+ }
5307
+
5308
+ const saved = await savedClient(engine, { agentId: agent.id, stateKey: spec.stateKey })
5309
+ const env = envClient(spec.provider)
5310
+ const needsSecret = spec.tokenAuth !== 'pkce-only'
5311
+ const builtIn =
5312
+ !!spec.registrationEndpoint || !!(env.clientId && (!needsSecret || env.clientSecret))
5313
+ const oauth = {
5314
+ spec,
5315
+ builtIn,
5316
+ redirectUri: spec.port ? oauthRedirectUri(spec.port) : null,
5317
+ savedClientId: saved.clientId,
5318
+ savedSecret: Boolean(saved.clientSecret)
5319
+ }
5320
+
5321
+ return { type: 'sheet.client', sheet, start, oauth }
5322
+ }
5323
+ }
5324
+
5325
+ _sheetClient(msg) {
5326
+ const { sheet, oauth } = msg
5327
+ if (sheet !== this._sheet) {
5328
+ return [this, null]
5329
+ }
5330
+
5331
+ sheet.oauth = oauth
5332
+ if (!oauth.spec) {
5333
+ sheet.error = `${sheet.skill.name}'s sign-in settings cannot be used from here`
5334
+ }
5335
+
5336
+ if (
5337
+ oauth.savedClientId &&
5338
+ !sheet.values.clientId &&
5339
+ hasField(currentRoute(sheet), 'clientId')
5340
+ ) {
5341
+ sheet.values.clientId = oauth.savedClientId
5342
+ }
5343
+
5344
+ this._render()
5345
+
5346
+ return msg.start && oauth.spec ? this._sheetConnect(sheet) : [this, null]
5347
+ }
5348
+
5349
+ _sheetKey(msg) {
5350
+ const sheet = this._sheet
5351
+ const route = currentRoute(sheet)
5352
+ if (!route) {
5353
+ return this._routePickerKey(sheet, msg)
5354
+ }
5355
+
5356
+ if (sheet.phase === 'waiting') {
5357
+ if (key.matches(msg, 'escape', 'enter')) {
5358
+ return this._cancelSheet(sheet)
5359
+ }
5360
+
5361
+ return key.matches(msg, 'ctrl+y') ? this._copySheetText(sheet.url, 'link') : [this, null]
5362
+ }
5363
+
5364
+ if (key.matches(msg, 'escape')) {
5365
+ return this._sheetEscape(sheet)
5366
+ }
5367
+
5368
+ if (key.matches(msg, 'ctrl+y')) {
5369
+ return this._copySheetText(sheet.oauth?.redirectUri, 'redirect URI')
5370
+ }
5371
+
5372
+ const { button } = focused(sheet)
5373
+ if (button && key.matches(msg, 'enter')) {
5374
+ return this._sheetPress(sheet, button.id)
5375
+ }
5376
+
5377
+ this._sheetEdit(sheet, msg)
5378
+ this._render()
5379
+
5380
+ return [this, null]
5381
+ }
5382
+
5383
+ // several routes step back to the choice between them before the sheet closes
5384
+ _sheetEscape(sheet) {
5385
+ if (sheet.routes.length > 1 && sheet.phase === 'edit') {
5386
+ sheet.route = null
5387
+ this._render()
5388
+
5389
+ return [this, null]
5390
+ }
5391
+
5392
+ return this._closeSheet()
5393
+ }
5394
+
5395
+ _sheetEdit(sheet, msg) {
5396
+ if (key.matches(msg, 'enter', 'tab', 'down')) {
5397
+ moveFocus(sheet, 1)
5398
+ } else if (key.matches(msg, 'shift+tab', 'up')) {
5399
+ moveFocus(sheet, -1)
5400
+ } else if (key.matches(msg, 'ctrl+r')) {
5401
+ sheet.revealed = !sheet.revealed
5402
+ } else if (key.matches(msg, 'backspace')) {
5403
+ backspace(sheet)
5404
+ } else if (this._isTypingKey(msg)) {
5405
+ typeInto(sheet, msg.sequence)
5406
+ }
5407
+ }
5408
+
5409
+ _routePickerKey(sheet, msg) {
5410
+ if (key.matches(msg, 'escape')) {
5411
+ return this._closeSheet()
5412
+ }
5413
+
5414
+ if (key.matches(msg, 'up', 'down')) {
5415
+ const delta = key.matches(msg, 'up') ? -1 : 1
5416
+ sheet.cursor = Math.max(0, Math.min(sheet.routes.length - 1, sheet.cursor + delta))
5417
+ this._render()
5418
+
5419
+ return [this, null]
5420
+ }
5421
+
5422
+ if (!key.matches(msg, 'enter')) {
5423
+ return [this, null]
5424
+ }
5425
+
5426
+ pickRoute(sheet, sheet.cursor)
5427
+ this._render()
5428
+
5429
+ return [this, this._loadSheet(sheet)]
5430
+ }
5431
+
5432
+ _sheetPress(sheet, id) {
5433
+ if (id === 'cancel') {
5434
+ return this._closeSheet()
5435
+ }
5436
+
5437
+ if (id === 'connect') {
5438
+ return this._sheetConnect(sheet)
5439
+ }
5440
+
5441
+ if (id === 'save') {
5442
+ return this._sheetSave(sheet)
5443
+ }
5444
+
5445
+ const route = currentRoute(sheet)
5446
+ if (id === 'disconnect') {
5447
+ return this._sheetRun(sheet, (engine, agentId) => disconnect(engine, { agentId, route }), {
5448
+ text: `${sheet.skill.name} disconnected for agent ${this.agent.name}`,
5449
+ stay: true
5450
+ })
5451
+ }
5452
+
5453
+ return this._sheetRun(sheet, () => null, { text: `${sheet.skill.name} is ready`, verify: true })
5454
+ }
5455
+
5456
+ _sheetConnect(sheet) {
5457
+ const spec = sheet.oauth?.spec
5458
+ if (!spec) {
5459
+ sheet.error ??= 'still reading this skill — try again in a moment'
5460
+ this._render()
5461
+
5462
+ return [this, null]
5463
+ }
5464
+
5465
+ const entered = enteredValues(sheet)
5466
+ const openUrl = (url) => {
5467
+ sheet.url = url
5468
+ this._repaint()
5469
+ this._openUrl(url)
5470
+ }
5471
+ const onStage = (stage) => {
5472
+ sheet.stage = OAUTH_STAGES[stage] ?? sheet.stage
5473
+ this._repaint()
5474
+ }
5475
+ sheet.phase = 'waiting'
5476
+ sheet.stage = null
5477
+ sheet.url = null
5478
+ sheet.focus = sheetFields(sheet).length
5479
+
5480
+ return this._sheetRun(
5481
+ sheet,
5482
+ (engine, agentId) => connectSkill(engine, { agentId, spec, entered, openUrl, onStage }),
5483
+ { text: `${sheet.skill.name} connected for agent ${this.agent.name} — auto-refreshes on use` }
5484
+ )
5485
+ }
5486
+
5487
+ _sheetSave(sheet) {
5488
+ const route = currentRoute(sheet)
5489
+ const values = enteredValues(sheet)
5490
+ const empty = routeFields(route).find((field) => !values[field.key])
5491
+ if (empty) {
5492
+ sheet.error = `${empty.label} is empty — type or paste it`
5493
+ focusField(sheet, empty.key)
5494
+ this._render()
5495
+
5496
+ return [this, null]
5497
+ }
5498
+
5499
+ if (route.kind === 'picker') {
5500
+ const folder = expandHome(values[route.credentialKey])
5501
+ const problem = folderProblem(folder, route)
5502
+ if (problem) {
5503
+ sheet.error = problem
5504
+ this._render()
5505
+
5506
+ return [this, null]
5507
+ }
5508
+
5509
+ values[route.credentialKey] = folder
5510
+ }
5511
+
5512
+ const skillName = sheet.skill.name
5513
+
5514
+ return this._sheetRun(
5515
+ sheet,
5516
+ (engine, agentId) => saveFields(engine, { agentId, skillName, route, values }),
5517
+ { text: `${skillName} saved for agent ${this.agent.name}` }
5518
+ )
5519
+ }
5520
+
5521
+ // a write is done once stored; only a re-check has to wait for the skill to read ready
5522
+ _sheetRun(sheet, work, { text, stay = false, verify = false }) {
5523
+ const attempt = ++sheet.attempt
5524
+ sheet.error = null
5525
+ this._render()
5526
+ const { engine, agent } = this
5527
+
5528
+ return [
5529
+ this,
5530
+ async () => {
5531
+ try {
5532
+ const outcome = await work(engine, agent.id)
5533
+ if (outcome?.need) {
5534
+ return { type: 'sheet.result', sheet, attempt, need: outcome.need }
5535
+ }
5536
+
5537
+ const skill = (await this._skillRow(sheet.skill.name)) ?? sheet.skill
5538
+ const done = !stay && (!verify || isReady(skill))
5539
+ const on = sheet.enable && done ? await this._toggleSkill(skill.name, { on: true }) : null
5540
+
5541
+ return {
5542
+ type: 'sheet.result',
5543
+ sheet,
5544
+ attempt,
5545
+ skill,
5546
+ done,
5547
+ stay,
5548
+ text: on ? `${text} · ${on}` : text
5549
+ }
5550
+ } catch (error) {
5551
+ return { type: 'sheet.result', sheet, attempt, error }
5552
+ }
5553
+ }
5554
+ ]
5555
+ }
5556
+
5557
+ _sheetResult(msg) {
5558
+ const { sheet } = msg
5559
+ if (sheet !== this._sheet || msg.attempt !== sheet.attempt) {
5560
+ return [this, null]
5561
+ }
5562
+
5563
+ sheet.phase = 'edit'
5564
+ if (msg.need) {
5565
+ const missing = msg.need.clientId ? 'clientId' : 'clientSecret'
5566
+ sheet.error = `${msg.need.clientId ? 'Client ID' : 'Client Secret'} is needed — paste it from your app`
5567
+ focusField(sheet, missing)
5568
+ } else if (msg.error) {
5569
+ sheet.error = msg.error.message ?? String(msg.error)
5570
+ } else {
5571
+ sheet.skill = msg.skill
5572
+ this._syncSelector(msg.skill)
5573
+ this.notice = msg.text
5574
+ sheet.focus = 0
5575
+ // a finished setup hands back to whatever opened it, the line above the input says how it went
5576
+ if (msg.done) {
5577
+ this._sheet = null
5578
+ if (this._selector?.kind === 'skills') {
5579
+ this._selector.notice = msg.text
5580
+ }
5581
+ } else if (!msg.stay) {
5582
+ sheet.error = `${msg.skill.name} still reads ${statusLabel(msg.skill.status)}`
5583
+ }
5584
+ }
4409
5585
 
4410
- // ctrl+p / /menu: open the menu at its root, clearing any other overlay first.
4411
- _openMenu() {
4412
- this._models = null
4413
- this._selector = null
4414
- this.overlay = null
4415
- this._menu = { pages: [this._rootMenu()] }
4416
5586
  this._render()
4417
5587
 
4418
5588
  return [this, null]
4419
5589
  }
4420
5590
 
4421
- // an entry carries exactly one of submenu, overlay, command or prefill
4422
- _rootMenu() {
4423
- return {
4424
- title: 'Menu',
4425
- cursor: 0,
4426
- entries: [
4427
- { label: 'Agent', hint: 'skills, tools, permissions, model', submenu: true },
4428
- { label: 'Chat', hint: 'this chat, knowledge, attachments', submenu: true },
4429
- { label: 'Models', hint: "browse and pick the agent's model", overlay: 'models' },
4430
- {
4431
- label: 'Custom models',
4432
- hint: 'register a GGUF by url/path; read its context window',
4433
- command: '/models custom'
4434
- },
4435
- { label: 'Voice', hint: 'speak, transcribe, converse', submenu: true },
4436
- { label: 'My device', hint: 'CPU / GPU inventory', overlay: 'diagnostics' },
4437
- { label: 'Mesh', hint: 'join another device’s mesh', submenu: true },
4438
- { label: 'Advanced', hint: 'credentials, scope, skill setup status', submenu: true },
4439
- { label: 'Help', hint: 'list every command', command: '/help' }
4440
- ]
5591
+ _syncSelector(skill) {
5592
+ const s = this._selector
5593
+ if (s?.kind !== 'skills') {
5594
+ return
4441
5595
  }
5596
+
5597
+ s.detail?.set(skill.name, skill)
5598
+ s.enabled = new Set(this.agent?.enabledSkills ?? [])
4442
5599
  }
4443
5600
 
4444
- _agentMenu() {
4445
- return {
4446
- title: `Agent · ${this.agent?.name ?? '?'}`,
4447
- cursor: 0,
4448
- entries: [
4449
- { label: 'Skills', hint: 'toggle skills on/off', overlay: 'skills' },
4450
- { label: 'Tools', hint: 'toggle tools on/off', overlay: 'tools' },
4451
- { label: 'Permissions', hint: 'approval mode & toolsets', overlay: 'permissions' },
4452
- { label: 'Model', hint: "pick the agent's model", overlay: 'models' },
4453
- {
4454
- label: 'Context size',
4455
- hint: contextSizeHint(this.agent, this._contextOpts(this.agent?.modelName)),
4456
- overlay: 'ctx'
4457
- },
4458
- { label: 'Image defaults', hint: 'model, steps, size', command: '/image' },
4459
- { label: 'Activity', hint: 'recent tool calls', command: '/activity' },
4460
- {
4461
- label: 'Connections',
4462
- hint: 'set up skills that need an account',
4463
- submenu: true,
4464
- connections: true
4465
- },
4466
- { label: 'Switch agent', hint: 'pick from your agents', submenu: true, agents: true },
4467
- { label: 'New agent…', hint: '/agent new <name>', prefill: '/agent new ' },
4468
- { label: 'Rename agent…', hint: '/agent rename <name>', prefill: '/agent rename ' }
4469
- ]
4470
- }
5601
+ // the loopback holds a port until its timeout, so a sheet that stops waiting releases it
5602
+ _cancelSheet(sheet) {
5603
+ sheet.attempt++
5604
+ sheet.phase = 'edit'
5605
+ sheet.error = 'sign-in cancelled'
5606
+ this._render()
5607
+
5608
+ return [this, () => cancelOAuth(sheet.oauth.spec).then(() => ({ type: 'sheet.cancelled' }))]
4471
5609
  }
4472
5610
 
4473
- // which skills are connectable is theirs to declare, so all this offers is the command itself
4474
- _connectMenu() {
4475
- return {
4476
- title: 'Connections',
4477
- cursor: 0,
4478
- entries: [
4479
- { label: 'Connect a skill…', hint: '/connect <skill>', prefill: '/connect ' },
4480
- { label: 'Set a credential…', hint: '/cred <key> <value>', prefill: '/cred ' }
4481
- ]
5611
+ _closeSheet() {
5612
+ const sheet = this._sheet
5613
+ this._sheet = null
5614
+ this._render()
5615
+ if (sheet.phase === 'waiting') {
5616
+ return [this, () => cancelOAuth(sheet.oauth.spec).then(() => ({ type: 'sheet.cancelled' }))]
4482
5617
  }
5618
+
5619
+ return [this, null]
4483
5620
  }
4484
5621
 
4485
- // a pasted-token skill (github) sits beside the OAuth ones instead of being invisible here
4486
- _connectPage() {
5622
+ _copySheetText(text, what) {
5623
+ if (!text || !this._copyToClipboard) {
5624
+ return [this, null]
5625
+ }
5626
+
5627
+ const copy = this._copyToClipboard
5628
+ const token = ++this._statusToken
5629
+
4487
5630
  return [
4488
5631
  this,
4489
5632
  async () => {
4490
- const detail = await this._skillDetail()
4491
- const rows = [...(detail?.values() ?? [])].flatMap((skill) =>
4492
- setupActions(skill)
4493
- .filter((action) => action.command || action.prefill)
4494
- .map((action) => ({ skill, action }))
4495
- )
4496
- if (!rows.length) {
4497
- return { type: 'menu.page', page: this._connectMenu() }
5633
+ try {
5634
+ await copy(text)
5635
+ return { type: 'transient-status', token, text: `${what} copied ✓` }
5636
+ } catch (err) {
5637
+ return { type: 'transient-status', token, text: `copy failed: ${err.message}` }
4498
5638
  }
4499
-
4500
- const entries = rows.map(({ skill, action }) => ({
4501
- label: `${isReady(skill) ? '●' : '○'} ${action.label}`,
4502
- hint: `${skill.name} · ${statusLabel(skill.status)}`,
4503
- command: action.command,
4504
- prefill: action.prefill
4505
- }))
4506
-
4507
- return { type: 'menu.page', page: { title: 'Connections', cursor: 0, entries } }
4508
5639
  }
4509
5640
  ]
4510
5641
  }
4511
5642
 
5643
+ _repaint() {
5644
+ this._render()
5645
+ this._requestRepaint()
5646
+ }
5647
+
4512
5648
  _advancedMenu() {
4513
5649
  return {
4514
5650
  title: 'Advanced',
4515
5651
  cursor: 0,
4516
5652
  entries: [
4517
- { label: 'Set credential…', hint: '/cred <key> <value>', prefill: '/cred ' },
4518
- { label: 'Skills scope…', hint: '/scope skills all|selected', prefill: '/scope skills ' },
4519
- { label: 'Tools scope…', hint: '/scope tools all|selected', prefill: '/scope tools ' }
5653
+ { label: 'Skills scope…', hint: '/scope skills all|selected', prefill: '/scope skills ' }
4520
5654
  ]
4521
5655
  }
4522
5656
  }
@@ -4553,7 +5687,11 @@ export class ChatApp {
4553
5687
  entries: [
4554
5688
  { label: 'Meshes', hint: 'the meshes this device belongs to', command: '/meshes' },
4555
5689
  { label: 'Switch mesh…', hint: '/mesh use <n|id>', prefill: '/mesh use ' },
4556
- { label: 'Join mesh…', hint: '/join <qvac://mesh/…>', prefill: '/join ' },
5690
+ {
5691
+ label: 'Join mesh…',
5692
+ hint: '/join <qvac://device/… or qvac://workspace/…>',
5693
+ prefill: '/join '
5694
+ },
4557
5695
  { label: 'Leave mesh', hint: 'leave the active mesh', command: '/leave' },
4558
5696
  { label: 'Cancel join', hint: 'abort a join in progress', command: '/join cancel' }
4559
5697
  ]
@@ -4735,6 +5873,10 @@ export class ChatApp {
4735
5873
  return this._showModels(null)
4736
5874
  }
4737
5875
 
5876
+ if (entry.overlay === 'tools') {
5877
+ return this._showTools()
5878
+ }
5879
+
4738
5880
  if (entry.overlay === 'permissions') {
4739
5881
  return this._showPermissions()
4740
5882
  }
@@ -4930,13 +6072,21 @@ export class ChatApp {
4930
6072
 
4931
6073
  // nothing downloads here: the provider pulls the model when the agent next runs
4932
6074
  _useModel() {
4933
- const row = this._models.rows[this._models.cursor]
6075
+ const { rows, cursor, device } = this._models
6076
+ const row = rows[cursor]
4934
6077
  this._models = null
4935
6078
  if (!row) {
4936
6079
  this._render()
4937
6080
  return [this, null]
4938
6081
  }
4939
6082
 
6083
+ // the rows are that device's library, and the agent resolves its model from its own
6084
+ if (device) {
6085
+ this.notice = notOursToUse(device)
6086
+ this._render()
6087
+ return [this, null]
6088
+ }
6089
+
4940
6090
  const { engine, agent } = this
4941
6091
 
4942
6092
  return [
@@ -4959,7 +6109,7 @@ export class ChatApp {
4959
6109
  ]
4960
6110
  }
4961
6111
 
4962
- // the same write as /skill|/tool on|off, so any toggle moves the agent to scope=selected
6112
+ // the same write as /skill on|off, so any toggle moves the agent to scope=selected
4963
6113
  _toggleSelector() {
4964
6114
  const s = this._selector
4965
6115
  if (s.kind === 'ctx') {
@@ -4972,7 +6122,17 @@ export class ChatApp {
4972
6122
  }
4973
6123
 
4974
6124
  if (s.kind === 'permissions') {
4975
- return this._togglePermission(s, name)
6125
+ return this._toggleMode(s)
6126
+ }
6127
+
6128
+ if (s.kind === 'tools') {
6129
+ return this._toggleToolset(s, name)
6130
+ }
6131
+
6132
+ // turning on a skill that cannot work yet opens its setup; it turns on once that succeeds
6133
+ const skill = s.detail?.get(name)
6134
+ if (!s.enabled.has(name) && SETUP_FIXES.has(skill?.status) && setupAction(skill)) {
6135
+ return this._openSheet(skill, { enable: true })
4976
6136
  }
4977
6137
 
4978
6138
  if (s.enabled.has(name)) {
@@ -4983,8 +6143,6 @@ export class ChatApp {
4983
6143
 
4984
6144
  s.scope = 'selected'
4985
6145
  this._render()
4986
- const field = s.kind === 'skills' ? 'enabledSkills' : 'enabledTools'
4987
- const scopeField = s.kind === 'skills' ? 'skillsScope' : 'toolsScope'
4988
6146
  const enabled = [...s.enabled]
4989
6147
  const { engine, agent } = this
4990
6148
 
@@ -4995,7 +6153,7 @@ export class ChatApp {
4995
6153
  this.agent = await engine.updateAgent({
4996
6154
  meshId: this.meshId,
4997
6155
  agentId: agent.id,
4998
- config: { [field]: enabled, [scopeField]: 'selected' }
6156
+ config: { enabledSkills: enabled, skillsScope: 'selected' }
4999
6157
  })
5000
6158
  return { type: 'selector.saved' }
5001
6159
  } catch (error) {
@@ -5005,7 +6163,7 @@ export class ChatApp {
5005
6163
  ]
5006
6164
  }
5007
6165
 
5008
- // the overlay closes either way: the setup is the next step
6166
+ // the sheet opens over the list, so esc lands back on it with the row refreshed
5009
6167
  _setupSelected() {
5010
6168
  const s = this._selector
5011
6169
  if (s.kind === 'ctx') {
@@ -5017,23 +6175,11 @@ export class ChatApp {
5017
6175
  }
5018
6176
 
5019
6177
  const skill = s.detail.get(s.rows[s.cursor])
5020
- if (!skill) {
6178
+ if (!skill || !skillRoutes(skill).length) {
5021
6179
  return [this, null]
5022
6180
  }
5023
6181
 
5024
- const action = configureActions(skill)[0]
5025
- this._selector = null
5026
- if (action?.command) {
5027
- return this._command(action.command)
5028
- }
5029
-
5030
- if (action?.prefill) {
5031
- this._setInput(action.prefill)
5032
- }
5033
-
5034
- this._render()
5035
-
5036
- return [this, async () => ({ type: 'notice', text: renderSkill(skill) })]
6182
+ return this._openSheet(skill)
5037
6183
  }
5038
6184
 
5039
6185
  // it draws from the chats watch, so it opens on what has replicated: no fetch, no flicker
@@ -5243,26 +6389,27 @@ export class ChatApp {
5243
6389
  return null
5244
6390
  }
5245
6391
 
5246
- // optimistic, like the skills/tools selector: the row moves now, the engine call follows
5247
- _togglePermission(s, name) {
5248
- if (name === MODE_ROW) {
5249
- s.mode = s.mode === 'skip-all' ? 'ask' : 'skip-all'
5250
- } else if (s.enabled.has(name)) {
6392
+ _toggleMode(s) {
6393
+ s.mode = s.mode === 'skip-all' ? 'ask' : 'skip-all'
6394
+
6395
+ return this._saveAgent({ approvalMode: s.mode })
6396
+ }
6397
+
6398
+ _toggleToolset(s, name) {
6399
+ if (s.enabled.has(name)) {
5251
6400
  s.enabled.delete(name)
5252
6401
  } else {
5253
6402
  s.enabled.add(name)
5254
6403
  }
5255
6404
 
6405
+ return this._saveAgent({
6406
+ disabledToolsets: [...TOOLSETS.filter((toolset) => !s.enabled.has(toolset)), ...s.unknown]
6407
+ })
6408
+ }
6409
+
6410
+ // optimistic, like the skills selector: the row moves now, the engine call follows
6411
+ _saveAgent(patch) {
5256
6412
  this._render()
5257
- const patch =
5258
- name === MODE_ROW
5259
- ? { approvalMode: s.mode }
5260
- : {
5261
- disabledToolsets: [
5262
- ...TOOLSETS.filter((toolset) => !s.enabled.has(toolset)),
5263
- ...s.unknown
5264
- ]
5265
- }
5266
6413
  const { engine, agent } = this
5267
6414
 
5268
6415
  return [
@@ -5720,7 +6867,7 @@ export class ChatApp {
5720
6867
  }
5721
6868
 
5722
6869
  if (msg.type === 'chat.switch') {
5723
- this._switchTo(msg.chat, msg.agent)
6870
+ this._switchTo(msg.chat, msg.agent, msg.notice)
5724
6871
  return [this, batch(this._watchNext(), this._watchNextFiles(), this._rememberSelection())]
5725
6872
  }
5726
6873
 
@@ -5735,14 +6882,6 @@ export class ChatApp {
5735
6882
  return [this, null]
5736
6883
  }
5737
6884
 
5738
- if (msg.compute) {
5739
- this._booting = false
5740
- this.notice = `joined compute mesh ${msg.compute.slice(0, 8)} - it carries no chats, so this window stays here`
5741
- this._render()
5742
-
5743
- return [this, null]
5744
- }
5745
-
5746
6885
  this.meshId = msg.meshId
5747
6886
 
5748
6887
  return [this, this._adoptMesh(msg.invite, 'joined — resolving the mesh’s agent and chat…')]
@@ -5778,13 +6917,42 @@ export class ChatApp {
5778
6917
  return [this, this._enterMesh()]
5779
6918
  }
5780
6919
 
6920
+ if (msg.type === 'mesh.none') {
6921
+ this._booting = false
6922
+ this.status = ''
6923
+ this.notice = NO_WORKSPACE
6924
+ this._render()
6925
+ return [this, null]
6926
+ }
6927
+
5781
6928
  if (msg.type === 'meshes') {
5782
6929
  const ids = new Set(msg.meshes.map((mesh) => mesh.meshId))
5783
6930
  // a mesh transition in flight moves the window itself
5784
6931
  const lost = !this._booting && this._meshIds?.has(this.meshId) && !ids.has(this.meshId)
6932
+ // only the startup frame: a later closed mesh was closed on purpose
6933
+ const first = this._meshIds === null
5785
6934
  this._meshIds = ids
6935
+ // a window in no workspace opens the first one created or joined
6936
+ const arrived = !this.meshId && !this._booting && msg.meshes.some((mesh) => mesh.workspace)
6937
+
6938
+ return [
6939
+ this,
6940
+ batch(
6941
+ this._watchNextMeshes(),
6942
+ lost ? this._lostMesh(this.meshId) : null,
6943
+ first ? this._reopenMeshes(msg.meshes) : null,
6944
+ arrived ? this._enterMesh() : null
6945
+ )
6946
+ ]
6947
+ }
5786
6948
 
5787
- return [this, batch(this._watchNextMeshes(), lost ? this._lostMesh(this.meshId) : null)]
6949
+ if (msg.type === 'mesh.reopen-failed') {
6950
+ this.status = fg.err.render(
6951
+ `could not reopen mesh ${msg.meshId.slice(0, 8)}: ${msg.error.message}`
6952
+ )
6953
+ this._render()
6954
+
6955
+ return [this, null]
5788
6956
  }
5789
6957
 
5790
6958
  if (msg.type === 'meshes.done') {
@@ -5889,6 +7057,26 @@ export class ChatApp {
5889
7057
  return [this, this._watchNextStatus()]
5890
7058
  }
5891
7059
 
7060
+ if (msg.type === 'model-downloads') {
7061
+ if (msg.gen !== this.gen) {
7062
+ return [this, null]
7063
+ }
7064
+
7065
+ this.modelDownloads = new Map(msg.downloads.map((row) => [row.name, row]))
7066
+
7067
+ return [this, this._watchNextDownloads()]
7068
+ }
7069
+
7070
+ if (msg.type === 'model-downloads.done') {
7071
+ if (msg.gen !== this.gen) {
7072
+ return [this, null]
7073
+ }
7074
+
7075
+ this.modelDownloads = new Map()
7076
+
7077
+ return [this, null]
7078
+ }
7079
+
5892
7080
  if (msg.type === 'mesh-status.done') {
5893
7081
  if (msg.gen !== this.gen) {
5894
7082
  return [this, null]
@@ -5964,6 +7152,60 @@ export class ChatApp {
5964
7152
  return [this, null]
5965
7153
  }
5966
7154
 
7155
+ if (msg.type === 'doctor.checks') {
7156
+ // a settle pass belongs to the report it started from; esc or another overlay since drops it
7157
+ if (msg.overlay && msg.overlay !== this.overlay) {
7158
+ return [this, null]
7159
+ }
7160
+
7161
+ this._models = null
7162
+ this._selector = null
7163
+ if (msg.error) {
7164
+ this.overlay = [fg.err.render(`/doctor failed: ${msg.error.message}`)]
7165
+ this._render()
7166
+ return [this, null]
7167
+ }
7168
+
7169
+ const { first, second } = msg.samples
7170
+ const checks = runChecks(msg.samples)
7171
+ const head = [headerLine(second ?? first), summarize(checks)]
7172
+ this.overlay = [
7173
+ fg.dim.render('Doctor — ctrl+y copies · /doctor debug for the raw frame · esc to return'),
7174
+ '',
7175
+ ...head,
7176
+ ...checkLines(checks, { paint: paintDoctor })
7177
+ ]
7178
+ // the clipboard gets the same report without escape codes
7179
+ this._doctorReport = {
7180
+ overlay: this.overlay,
7181
+ text: [...head, ...checkLines(checks)].join('\n')
7182
+ }
7183
+ this._render()
7184
+
7185
+ return [this, second === undefined ? this._settleDoctor(first, this.overlay) : null]
7186
+ }
7187
+
7188
+ if (msg.type === 'doctor.result') {
7189
+ this._models = null
7190
+ this._selector = null
7191
+ if (msg.error) {
7192
+ this.overlay = [fg.err.render(`/doctor failed: ${msg.error.message}`)]
7193
+ this._render()
7194
+ return [this, null]
7195
+ }
7196
+
7197
+ const report = diagnosticsLines(msg.stats)
7198
+ this.overlay = [
7199
+ fg.dim.render('Doctor — raw diagnostics — ctrl+y copies · esc to return'),
7200
+ '',
7201
+ ...report
7202
+ ]
7203
+ this._doctorReport = { overlay: this.overlay, text: report.join('\n') }
7204
+ this._render()
7205
+
7206
+ return [this, null]
7207
+ }
7208
+
5967
7209
  if (msg.type === 'usage.result') {
5968
7210
  this._models = null
5969
7211
  this._selector = null
@@ -5986,7 +7228,12 @@ export class ChatApp {
5986
7228
  } else {
5987
7229
  this.overlay = null
5988
7230
  this._selector = null
5989
- this._models = { rows: sortModels(msg.rows), filter: msg.filter ?? null, cursor: 0 }
7231
+ this._models = {
7232
+ rows: sortModels(msg.rows),
7233
+ filter: msg.filter ?? null,
7234
+ cursor: 0,
7235
+ device: msg.device ?? null
7236
+ }
5990
7237
  }
5991
7238
 
5992
7239
  this._render()
@@ -6023,17 +7270,34 @@ export class ChatApp {
6023
7270
  if (msg.error) {
6024
7271
  this._selector = null
6025
7272
  this.overlay = [fg.err.render(`/permissions failed: ${msg.error.message}`)]
7273
+ } else {
7274
+ this._models = null
7275
+ this.overlay = null
7276
+ this._selector = { kind: 'permissions', rows: [MODE_ROW], mode: msg.mode, cursor: 0 }
7277
+ }
7278
+
7279
+ this._render()
7280
+
7281
+ return [this, null]
7282
+ }
7283
+
7284
+ if (msg.type === 'tools.result') {
7285
+ if (msg.error) {
7286
+ this._selector = null
7287
+ this.overlay = [fg.err.render(`/tools failed: ${msg.error.message}`)]
6026
7288
  } else {
6027
7289
  this._models = null
6028
7290
  this.overlay = null
6029
7291
  const off = new Set(msg.disabled)
6030
7292
  this._selector = {
6031
- kind: 'permissions',
6032
- rows: [MODE_ROW, ...TOOLSETS],
7293
+ kind: 'tools',
7294
+ rows: [...TOOLSETS],
6033
7295
  enabled: new Set(TOOLSETS.filter((name) => !off.has(name))),
6034
7296
  // unknown ids must survive the write, or an older device switches a newer build's toolset back on
6035
7297
  unknown: msg.disabled.filter((name) => !TOOLSETS.includes(name)),
6036
- mode: msg.mode,
7298
+ catalog: msg.catalog,
7299
+ reason: msg.reason,
7300
+ deviceName: msg.deviceName,
6037
7301
  cursor: 0
6038
7302
  }
6039
7303
  }
@@ -6098,6 +7362,18 @@ export class ChatApp {
6098
7362
  return [this, null]
6099
7363
  } // completion arrives via the chunk stream itself
6100
7364
 
7365
+ if (msg.type === 'sheet.open') {
7366
+ return this._openSheet(msg.skill, msg)
7367
+ }
7368
+
7369
+ if (msg.type === 'sheet.client') {
7370
+ return this._sheetClient(msg)
7371
+ }
7372
+
7373
+ if (msg.type === 'sheet.result') {
7374
+ return this._sheetResult(msg)
7375
+ }
7376
+
6101
7377
  if (msg.type === 'notice') {
6102
7378
  // transcript, not the footer: any status tick overwrites the footer's one truncated line
6103
7379
  this.notice = msg.text
@@ -6114,6 +7390,15 @@ export class ChatApp {
6114
7390
  return [this, null]
6115
7391
  }
6116
7392
 
7393
+ if (
7394
+ this.updateBanner &&
7395
+ (msg.type.startsWith('update.') ||
7396
+ (msg.type === 'spinner.tick' && msg.id === this.updateBanner.spinner.id))
7397
+ ) {
7398
+ const [, cmd] = this.updateBanner.update(msg)
7399
+ return [this, cmd]
7400
+ }
7401
+
6117
7402
  if (msg.type === 'spinner.tick') {
6118
7403
  const [s, cmd] = this.spin.update(msg)
6119
7404
  this.spin = s
@@ -6218,9 +7503,13 @@ export class ChatApp {
6218
7503
  return [this, quit]
6219
7504
  }
6220
7505
 
7506
+ if (this._sheet) {
7507
+ return this._sheetKey(msg)
7508
+ }
7509
+
6221
7510
  // modifier keys never collide with typing or the y/n approval answers
6222
7511
  if (key.matches(msg, 'ctrl+y')) {
6223
- return this._copyInvite()
7512
+ return this._copyReport() ?? this._copyInvite()
6224
7513
  }
6225
7514
 
6226
7515
  if (key.matches(msg, 'ctrl+v')) {
@@ -6239,6 +7528,12 @@ export class ChatApp {
6239
7528
  return this._toggleToolOutput()
6240
7529
  }
6241
7530
 
7531
+ // only the accept chord reaches the banner: its own u/enter/esc are typing here
7532
+ if (this.updateBanner && key.matches(msg, 'ctrl+u')) {
7533
+ const [, cmd] = this.updateBanner.update(msg)
7534
+ return [this, cmd]
7535
+ }
7536
+
6242
7537
  // typing dismisses an overlay into the input; other keys are swallowed so they can't leak through
6243
7538
  if (this._models || this._selector || this.overlay || this._menu) {
6244
7539
  const handled = this._overlayKey(msg)
@@ -6284,6 +7579,11 @@ export class ChatApp {
6284
7579
 
6285
7580
  return [this, null]
6286
7581
  }
7582
+
7583
+ if (['ready', 'applied', 'error'].includes(this.updateBanner?.state)) {
7584
+ this.updateBanner.update({ type: 'update.dismiss' })
7585
+ return [this, null]
7586
+ }
6287
7587
  }
6288
7588
 
6289
7589
  if (this.pendingApproval) {
@@ -6523,6 +7823,76 @@ export class ChatApp {
6523
7823
  ]
6524
7824
  }
6525
7825
 
7826
+ // the target's first agent answers it there; a mesh with none leaves the chat waiting for one
7827
+ async _moveChat(selector, chatNeedle) {
7828
+ const named = await this._resolveMesh(selector)
7829
+ if (named.error) {
7830
+ return named.error
7831
+ }
7832
+
7833
+ const chat = await this._chatToMove(chatNeedle)
7834
+ if (chat.miss) {
7835
+ return chat.miss
7836
+ }
7837
+
7838
+ const { agents } = await this.engine.listAgents({ meshId: named.meshId })
7839
+ const move = await this.engine.moveChatToMesh({
7840
+ meshId: this.meshId,
7841
+ chatId: chat.id,
7842
+ targetMeshId: named.meshId,
7843
+ agentId: agents?.[0]?.id
7844
+ })
7845
+ this._lastMove = { id: chat.id, title: chat.title }
7846
+
7847
+ return this._describeMove(move, chat.title)
7848
+ }
7849
+
7850
+ async _movedChat(chatNeedle) {
7851
+ const chat = chatNeedle ? await this._chatToMove(chatNeedle) : this._lastMove
7852
+ if (!chat || chat.miss) {
7853
+ return chat?.miss ?? 'no move from this window yet - /mesh move <n|id> [chat]'
7854
+ }
7855
+
7856
+ const frames = this.engine.chatMoveWatch({ meshId: this.meshId, chatId: chat.id })
7857
+ try {
7858
+ for await (const move of frames) {
7859
+ return this._describeMove(move, chat.title)
7860
+ }
7861
+ } finally {
7862
+ frames.destroy()
7863
+ }
7864
+
7865
+ return 'the move watch ended'
7866
+ }
7867
+
7868
+ async _describeMove(move, title) {
7869
+ const { meshes } = await this.engine.listMeshes({}).catch(() => ({ meshes: [] }))
7870
+ const index = (meshes ?? []).findIndex((mesh) => mesh.meshId === move.targetMeshId)
7871
+ const where = index < 0 ? '/meshes lists it' : `/mesh use ${index + 1} to open it`
7872
+
7873
+ return describeMove(move, { title, where })
7874
+ }
7875
+
7876
+ async _chatToMove(needle) {
7877
+ if (!needle) {
7878
+ if (!this.chatId) {
7879
+ return { miss: 'no chat is open' }
7880
+ }
7881
+
7882
+ const { chats } = await this.engine.listChats({ meshId: this.meshId })
7883
+ const open = (chats ?? []).find((c) => c.id === this.chatId)
7884
+
7885
+ return { id: this.chatId, title: open?.title || 'this chat' }
7886
+ }
7887
+
7888
+ const { chat, ambiguous } = await this._resolveChat(needle)
7889
+ if (ambiguous) {
7890
+ return { miss: `"${needle}" matches ${ambiguous} chats — be specific` }
7891
+ }
7892
+
7893
+ return chat ? { id: chat.id, title: chat.title } : { miss: `no chat matching "${needle}"` }
7894
+ }
7895
+
6526
7896
  // The same selector /mesh use takes, so a mesh is named by its list number as well as its id
6527
7897
  async _resolveMesh(selector) {
6528
7898
  const { meshes } = await this.engine.listMeshes({})
@@ -6537,11 +7907,6 @@ export class ChatApp {
6537
7907
  const { meshes } = await this.engine.listMeshes({}).catch(() => ({ meshes: [] }))
6538
7908
  const index = (meshes ?? []).findIndex((mesh) => mesh.meshId === meshId)
6539
7909
  const where = index < 0 ? '/meshes lists it' : `/mesh use ${index + 1} to open it`
6540
- // a compute mesh is no place to work, so calling it a "shared mesh" would promise one
6541
- if ((meshes ?? [])[index]?.compute) {
6542
- return `compute mesh ${meshId.slice(0, 8)} - lends this device, carries nothing`
6543
- }
6544
-
6545
7910
  return `shared mesh ${meshId.slice(0, 8)} - this window is elsewhere, ${where}`
6546
7911
  }
6547
7912
 
@@ -6592,10 +7957,6 @@ export class ChatApp {
6592
7957
  await engine.joinMesh({ invite })
6593
7958
  const joined = decodeMeshInvite(invite)
6594
7959
  const meshId = b4a.toHex(joined.baseKey)
6595
- if (joined.compute) {
6596
- return { type: 'mesh.joined', compute: meshId }
6597
- }
6598
-
6599
7960
  const next = await engine.meshInvite({ meshId }).catch(noop)
6600
7961
 
6601
7962
  return { type: 'mesh.joined', meshId, invite: next?.invite ?? null }
@@ -6696,6 +8057,12 @@ export class ChatApp {
6696
8057
  : '↑/↓: chat · shift+↑/↓: reorder · enter: open · m: move to group · esc: close · ctrl+c: quit'
6697
8058
  }
6698
8059
 
8060
+ if (this._sheet) {
8061
+ return this._sheet.phase === 'waiting'
8062
+ ? 'esc: cancel sign-in · ctrl+y: copy link · ctrl+c: quit'
8063
+ : 'tab/↑↓: move · enter: select · ctrl+r: show secrets · esc: back · ctrl+c: quit'
8064
+ }
8065
+
6699
8066
  if (this._models) return '↑/↓: move · enter: use · esc: back · ctrl+c: quit'
6700
8067
  if (this._selector) {
6701
8068
  const setup = this._selector.detail ? ' · enter: configure' : ''
@@ -6703,7 +8070,8 @@ export class ChatApp {
6703
8070
  }
6704
8071
 
6705
8072
  if (this.overlay) {
6706
- return 'esc: back · ↑/↓: scroll · ctrl+c: quit'
8073
+ const copy = this._doctorReport?.overlay === this.overlay ? ' · ctrl+y: copy report' : ''
8074
+ return `esc: back · ↑/↓: scroll${copy} · ctrl+c: quit`
6707
8075
  }
6708
8076
 
6709
8077
  if (this._menu) {
@@ -6754,9 +8122,8 @@ export class ChatApp {
6754
8122
  return rows.slice(start, start + max)
6755
8123
  }
6756
8124
 
6757
- // every extra input row costs the transcript one: the frame stays exactly as tall as the terminal
6758
- _fitViewport(inputRows) {
6759
- const height = Math.max(1, this.height - CHROME_ROWS - (inputRows - 1))
8125
+ _fitViewport(inputRows, bannerRows = 0) {
8126
+ const height = Math.max(1, this.height - CHROME_ROWS - (inputRows - 1) - bannerRows)
6760
8127
  if (this.vp.height === height) {
6761
8128
  return
6762
8129
  }
@@ -6892,7 +8259,17 @@ export class ChatApp {
6892
8259
  .render(title.slice(0, Math.max(0, this.width - 4)))
6893
8260
 
6894
8261
  const inputRows = this._inputRows()
6895
- this._fitViewport(inputRows.length)
8262
+ if (this.updateBanner) {
8263
+ this.updateBanner.width = this.width - 4
8264
+ }
8265
+
8266
+ let banner = this.updateBanner?.view() ?? ''
8267
+ const bannerRows = banner ? banner.split('\n').length : 0
8268
+ if (this.height - CHROME_ROWS - (inputRows.length - 1) - bannerRows < 1) {
8269
+ banner = ''
8270
+ }
8271
+
8272
+ this._fitViewport(inputRows.length, banner ? bannerRows : 0)
6896
8273
  const lines = this._viewLines()
6897
8274
  const vpLines =
6898
8275
  this._selection?.region === 'transcript'
@@ -6932,7 +8309,9 @@ export class ChatApp {
6932
8309
  // a wrapped footer row shifts the whole frame and scrolls the header off — never let it wrap
6933
8310
  const footer = fg.dim.render(hints.slice(0, Math.max(0, this.width - 1)))
6934
8311
 
6935
- return [header, body, this._skillsLine(), inputBox, footer].join('\n')
8312
+ return [header, body, this._skillsLine(), inputBox, ...(banner ? [banner] : []), footer].join(
8313
+ '\n'
8314
+ )
6936
8315
  }
6937
8316
  }
6938
8317