@qvac/core 0.2.0 → 0.2.2

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 (265) hide show
  1. package/.claude/skills/compaction/SKILL.md +9 -4
  2. package/.claude/skills/pr-create/SKILL.md +24 -3
  3. package/.claude/skills/pr-review/SKILL.md +248 -40
  4. package/CLAUDE.md +1 -3
  5. package/README.md +3 -1
  6. package/dist-lib/client.js +1 -1
  7. package/dist-lib/index.js +8 -8
  8. package/dist-lib/lib/api/agents.d.ts +1 -1
  9. package/dist-lib/lib/api/agents.js +10 -9
  10. package/dist-lib/lib/api/app-config.js +1 -1
  11. package/dist-lib/lib/api/approval-rules.js +9 -5
  12. package/dist-lib/lib/api/attachments.js +25 -3
  13. package/dist-lib/lib/api/chat-groups.d.ts +1 -1
  14. package/dist-lib/lib/api/chat-groups.js +5 -4
  15. package/dist-lib/lib/api/chat.js +8 -8
  16. package/dist-lib/lib/api/chunks.js +11 -11
  17. package/dist-lib/lib/api/config.js +1 -1
  18. package/dist-lib/lib/api/custom-models.js +2 -2
  19. package/dist-lib/lib/api/devices.d.ts +1 -1
  20. package/dist-lib/lib/api/devices.js +9 -9
  21. package/dist-lib/lib/api/diagnostics.js +1 -1
  22. package/dist-lib/lib/api/effective-ctx-size.js +1 -1
  23. package/dist-lib/lib/api/execution.js +4 -4
  24. package/dist-lib/lib/api/files.js +2 -2
  25. package/dist-lib/lib/api/index.d.ts +1 -0
  26. package/dist-lib/lib/api/index.js +33 -33
  27. package/dist-lib/lib/api/instrument.js +1 -1
  28. package/dist-lib/lib/api/knowledge.js +4 -4
  29. package/dist-lib/lib/api/logs.js +1 -1
  30. package/dist-lib/lib/api/members.d.ts +4 -1
  31. package/dist-lib/lib/api/members.js +88 -18
  32. package/dist-lib/lib/api/mesh.d.ts +13 -3
  33. package/dist-lib/lib/api/mesh.js +25 -2
  34. package/dist-lib/lib/api/model-download.js +1 -1
  35. package/dist-lib/lib/api/network.js +1 -1
  36. package/dist-lib/lib/api/notifications.js +3 -3
  37. package/dist-lib/lib/api/rag.js +7 -7
  38. package/dist-lib/lib/api/sync.js +1 -1
  39. package/dist-lib/lib/api/tool-activity.js +4 -4
  40. package/dist-lib/lib/api/tool-configs.js +5 -5
  41. package/dist-lib/lib/api/watchable.js +1 -1
  42. package/dist-lib/lib/assistant/fetch-body.d.ts +5 -0
  43. package/dist-lib/lib/assistant/fetch-body.js +36 -0
  44. package/dist-lib/lib/assistant/harness.d.ts +225 -0
  45. package/dist-lib/lib/assistant/harness.js +154 -0
  46. package/dist-lib/lib/assistant/history.d.ts +32 -0
  47. package/dist-lib/lib/assistant/history.js +232 -0
  48. package/dist-lib/lib/assistant/message.d.ts +45 -0
  49. package/dist-lib/lib/assistant/message.js +47 -0
  50. package/dist-lib/lib/assistant/skill-encode.d.ts +21 -0
  51. package/dist-lib/lib/assistant/skill-encode.js +71 -0
  52. package/dist-lib/lib/assistant-client.js +2 -2
  53. package/dist-lib/lib/assistant-tree.js +10 -4
  54. package/dist-lib/lib/assistant.d.ts +25 -285
  55. package/dist-lib/lib/assistant.js +250 -637
  56. package/dist-lib/lib/audio-format.js +2 -2
  57. package/dist-lib/lib/client.js +2 -2
  58. package/dist-lib/lib/collabora/convert.js +1 -1
  59. package/dist-lib/lib/collabora/entry.js +1 -1
  60. package/dist-lib/lib/collabora/worker.js +1 -1
  61. package/dist-lib/lib/compaction.d.ts +1 -2
  62. package/dist-lib/lib/compaction.js +8 -6
  63. package/dist-lib/lib/constants.js +1 -1
  64. package/dist-lib/lib/core/account-recovery.d.ts +19 -0
  65. package/dist-lib/lib/core/account-recovery.js +50 -0
  66. package/dist-lib/lib/core/agent.js +8 -4
  67. package/dist-lib/lib/core/app-build.d.ts +1 -1
  68. package/dist-lib/lib/core/approval-rules.d.ts +1 -0
  69. package/dist-lib/lib/core/approval-rules.js +3 -1
  70. package/dist-lib/lib/core/archived-mesh.d.ts +25 -0
  71. package/dist-lib/lib/core/archived-mesh.js +162 -0
  72. package/dist-lib/lib/core/chat-activity.js +1 -1
  73. package/dist-lib/lib/core/chat-group.d.ts +1 -0
  74. package/dist-lib/lib/core/chat-group.js +24 -4
  75. package/dist-lib/lib/core/chat-search.js +2 -2
  76. package/dist-lib/lib/core/chat.js +5 -5
  77. package/dist-lib/lib/core/chunk.d.ts +1 -1
  78. package/dist-lib/lib/core/chunk.js +4 -4
  79. package/dist-lib/lib/core/contract/agents.js +1 -1
  80. package/dist-lib/lib/core/contract/approval-rules.js +6 -4
  81. package/dist-lib/lib/core/contract/attestations.js +1 -1
  82. package/dist-lib/lib/core/contract/chat-group.js +1 -1
  83. package/dist-lib/lib/core/contract/chat.js +1 -1
  84. package/dist-lib/lib/core/contract/chunks.js +2 -2
  85. package/dist-lib/lib/core/contract/compute.d.ts +11 -0
  86. package/dist-lib/lib/core/contract/compute.js +45 -0
  87. package/dist-lib/lib/core/contract/devices.js +16 -3
  88. package/dist-lib/lib/core/contract/index.d.ts +3 -1
  89. package/dist-lib/lib/core/contract/index.js +19 -16
  90. package/dist-lib/lib/core/contract/indexing.js +2 -2
  91. package/dist-lib/lib/core/contract/joined-meshes.js +1 -1
  92. package/dist-lib/lib/core/contract/knowledge.js +2 -2
  93. package/dist-lib/lib/core/contract/members.js +2 -2
  94. package/dist-lib/lib/core/contract/seal.d.ts +2 -0
  95. package/dist-lib/lib/core/contract/seal.js +8 -0
  96. package/dist-lib/lib/core/contract/seed-defaults.js +1 -1
  97. package/dist-lib/lib/core/contract/tool-activity.js +1 -1
  98. package/dist-lib/lib/core/contract/tool-configs.js +3 -3
  99. package/dist-lib/lib/core/contract/writers.js +66 -42
  100. package/dist-lib/lib/core/departures.js +1 -1
  101. package/dist-lib/lib/core/device-invites.js +1 -1
  102. package/dist-lib/lib/core/document-attachment.js +2 -2
  103. package/dist-lib/lib/core/files/attachments.js +3 -3
  104. package/dist-lib/lib/core/files/index.d.ts +2 -2
  105. package/dist-lib/lib/core/files/index.js +19 -19
  106. package/dist-lib/lib/core/files/knowledge.js +3 -3
  107. package/dist-lib/lib/core/files/preview/image.js +1 -1
  108. package/dist-lib/lib/core/files/preview/index.js +6 -6
  109. package/dist-lib/lib/core/files/processing/claims.js +1 -1
  110. package/dist-lib/lib/core/files/processing/document.js +5 -5
  111. package/dist-lib/lib/core/files/processing/index.js +8 -8
  112. package/dist-lib/lib/core/files/processing/ownership.js +1 -1
  113. package/dist-lib/lib/core/files/processing/protocol.js +3 -3
  114. package/dist-lib/lib/core/files/processing/source.js +1 -1
  115. package/dist-lib/lib/core/files/rag/artifact/codec.js +1 -1
  116. package/dist-lib/lib/core/files/rag/artifact/id.js +1 -1
  117. package/dist-lib/lib/core/files/rag/artifact/types.d.ts +4 -4
  118. package/dist-lib/lib/core/files/rag/build.js +2 -2
  119. package/dist-lib/lib/core/files/rag/chunk/chunking.js +2 -2
  120. package/dist-lib/lib/core/files/rag/document-types.d.ts +3 -3
  121. package/dist-lib/lib/core/files/rag/extract/document-types.d.ts +9 -9
  122. package/dist-lib/lib/core/files/rag/extract/extract.js +7 -7
  123. package/dist-lib/lib/core/files/rag/extract/html-text.js +1 -1
  124. package/dist-lib/lib/core/files/rag/extract/office-collabora.js +2 -2
  125. package/dist-lib/lib/core/files/rag/extract/pdf-platform.js +1 -1
  126. package/dist-lib/lib/core/files/rag/extract/pdf-text.js +1 -1
  127. package/dist-lib/lib/core/files/rag/extract/text-decoding.js +1 -1
  128. package/dist-lib/lib/core/files/rag/extract/types.d.ts +2 -2
  129. package/dist-lib/lib/core/files/rag/index.js +22 -22
  130. package/dist-lib/lib/core/files/rag/load.js +5 -5
  131. package/dist-lib/lib/core/files/rag/policy.js +2 -2
  132. package/dist-lib/lib/core/files/rag/produce.js +5 -5
  133. package/dist-lib/lib/core/files/rag/retrieval/coverage.js +2 -2
  134. package/dist-lib/lib/core/files/rag/retrieval/diversity.js +1 -1
  135. package/dist-lib/lib/core/files/rag/retrieval/floor.js +2 -2
  136. package/dist-lib/lib/core/files/rag/retrieval/format.js +1 -1
  137. package/dist-lib/lib/core/files/rag/retrieval/full-text.js +18 -11
  138. package/dist-lib/lib/core/files/rag/retrieval/knowledge.js +6 -5
  139. package/dist-lib/lib/core/files/rag/retrieval/scoring.js +2 -2
  140. package/dist-lib/lib/core/files/rag/retrieval/search.js +7 -4
  141. package/dist-lib/lib/core/files/rag/retrieval/selection.d.ts +1 -0
  142. package/dist-lib/lib/core/files/rag/retrieval/selection.js +32 -2
  143. package/dist-lib/lib/core/files/rag/retrieval/sources.js +2 -2
  144. package/dist-lib/lib/core/files/rag/retrieval/terms.js +1 -1
  145. package/dist-lib/lib/core/files/rag/retrieval/types.d.ts +1 -0
  146. package/dist-lib/lib/core/files/rag/retrieval/web-sources.js +1 -1
  147. package/dist-lib/lib/core/files/records/chunks.js +1 -1
  148. package/dist-lib/lib/core/files/records/index.js +8 -8
  149. package/dist-lib/lib/core/files/records/knowledge.js +2 -2
  150. package/dist-lib/lib/core/files/records/output.js +1 -1
  151. package/dist-lib/lib/core/files/records/reclaim.js +5 -5
  152. package/dist-lib/lib/core/files/records/routing.js +7 -7
  153. package/dist-lib/lib/core/files/store/blob.js +2 -2
  154. package/dist-lib/lib/core/files/store/index.js +7 -7
  155. package/dist-lib/lib/core/files/store/reference.js +2 -2
  156. package/dist-lib/lib/core/files/store/server.js +1 -1
  157. package/dist-lib/lib/core/files/store/sweep.js +1 -1
  158. package/dist-lib/lib/core/files/upload-input.js +2 -2
  159. package/dist-lib/lib/core/files/upload.d.ts +1 -1
  160. package/dist-lib/lib/core/files/upload.js +6 -6
  161. package/dist-lib/lib/core/harness-loan.d.ts +29 -0
  162. package/dist-lib/lib/core/harness-loan.js +187 -0
  163. package/dist-lib/lib/core/helpers/index.d.ts +2 -1
  164. package/dist-lib/lib/core/helpers/index.js +4 -4
  165. package/dist-lib/lib/core/hosted-agents.js +2 -2
  166. package/dist-lib/lib/core/identity.d.ts +2 -0
  167. package/dist-lib/lib/core/identity.js +4 -2
  168. package/dist-lib/lib/core/invite.d.ts +1 -0
  169. package/dist-lib/lib/core/invite.js +4 -2
  170. package/dist-lib/lib/core/local/index.d.ts +12 -3
  171. package/dist-lib/lib/core/local/index.js +75 -16
  172. package/dist-lib/lib/core/membership.d.ts +3 -0
  173. package/dist-lib/lib/core/membership.js +15 -1
  174. package/dist-lib/lib/core/mesh-seed-handoff.js +1 -1
  175. package/dist-lib/lib/core/mesh.d.ts +9 -3
  176. package/dist-lib/lib/core/mesh.js +41 -26
  177. package/dist-lib/lib/core/migrations/agent-catalog.js +1 -1
  178. package/dist-lib/lib/core/migrations/index.js +5 -3
  179. package/dist-lib/lib/core/migrations/membership.js +2 -2
  180. package/dist-lib/lib/core/migrations/seal.d.ts +3 -0
  181. package/dist-lib/lib/core/migrations/seal.js +30 -0
  182. package/dist-lib/lib/core/next-frame.js +1 -1
  183. package/dist-lib/lib/core/notification.js +1 -1
  184. package/dist-lib/lib/core/ota-config.js +1 -1
  185. package/dist-lib/lib/core/secret-handoff.js +1 -1
  186. package/dist-lib/lib/core/send.js +3 -3
  187. package/dist-lib/lib/core/skill-overlay-handoff.js +1 -1
  188. package/dist-lib/lib/core/skill-overlay-receiver.js +2 -2
  189. package/dist-lib/lib/core/skill-secrets.js +3 -3
  190. package/dist-lib/lib/core/sync/devices.js +1 -1
  191. package/dist-lib/lib/core/sync/index.js +8 -5
  192. package/dist-lib/lib/core/sync-status.js +1 -1
  193. package/dist-lib/lib/core/system-info.js +1 -1
  194. package/dist-lib/lib/core/tool-activity.js +2 -2
  195. package/dist-lib/lib/core/tool-configs.js +2 -2
  196. package/dist-lib/lib/core.d.ts +41 -3
  197. package/dist-lib/lib/core.js +525 -90
  198. package/dist-lib/lib/credential-pusher.js +4 -4
  199. package/dist-lib/lib/deadline.js +1 -1
  200. package/dist-lib/lib/fs-drive-bridge.js +4 -2
  201. package/dist-lib/lib/integrations/index.js +3 -3
  202. package/dist-lib/lib/integrations/oauth-providers.js +1 -1
  203. package/dist-lib/lib/integrations/setup-routes.d.ts +5 -5
  204. package/dist-lib/lib/integrations/setup-routes.js +3 -3
  205. package/dist-lib/lib/knowledge-search.js +1 -1
  206. package/dist-lib/lib/log.js +3 -3
  207. package/dist-lib/lib/mesh-scoped-engine.d.ts +3 -0
  208. package/dist-lib/lib/mesh-scoped-engine.js +96 -0
  209. package/dist-lib/lib/model-context.d.ts +2 -2
  210. package/dist-lib/lib/model-context.js +1 -1
  211. package/dist-lib/lib/model-download.js +6 -6
  212. package/dist-lib/lib/oauth/asana.js +3 -3
  213. package/dist-lib/lib/oauth/browser-connect.js +1 -1
  214. package/dist-lib/lib/oauth/client.js +2 -2
  215. package/dist-lib/lib/oauth/common.d.ts +1 -1
  216. package/dist-lib/lib/oauth/common.js +1 -1
  217. package/dist-lib/lib/oauth/flow-core.js +3 -3
  218. package/dist-lib/lib/oauth/flow.js +2 -2
  219. package/dist-lib/lib/oauth/google.js +4 -4
  220. package/dist-lib/lib/oauth/host.js +3 -3
  221. package/dist-lib/lib/oauth/loopback.js +1 -1
  222. package/dist-lib/lib/oauth/notion.js +3 -3
  223. package/dist-lib/lib/oauth/providers.js +1 -1
  224. package/dist-lib/lib/oauth/resolve.js +1 -1
  225. package/dist-lib/lib/oauth/spotify.js +3 -3
  226. package/dist-lib/lib/oauth/token-exchange.js +1 -1
  227. package/dist-lib/lib/oauth.client.js +2 -2
  228. package/dist-lib/lib/oauth.js +12 -12
  229. package/dist-lib/lib/run-notices.d.ts +7 -7
  230. package/dist-lib/lib/run-transcript.js +1 -1
  231. package/dist-lib/schema/build.js +12 -6
  232. package/dist-lib/schema/content.d.ts +11 -11
  233. package/dist-lib/schema/engine.js +193 -30
  234. package/dist-lib/schema/field-order.js +2 -2
  235. package/dist-lib/schema/local.js +18 -4
  236. package/dist-lib/schema/qvac.js +15 -6
  237. package/dist-lib/spec/bind.js +41 -0
  238. package/dist-lib/spec/calls.js +12 -0
  239. package/dist-lib/spec/capabilities.d.ts +36 -12
  240. package/dist-lib/spec/hrpc/hrpc.json +161 -5
  241. package/dist-lib/spec/hrpc/index.js +154 -9
  242. package/dist-lib/spec/hrpc/messages.js +549 -129
  243. package/dist-lib/spec/hyperschema/index.js +549 -129
  244. package/dist-lib/spec/hyperschema/schema.json +370 -40
  245. package/dist-lib/spec/hyperschema/types.d.ts +85 -1
  246. package/dist-lib/spec/local/hyperdb/db.json +15 -0
  247. package/dist-lib/spec/local/hyperdb/index.js +70 -1
  248. package/dist-lib/spec/local/hyperdb/messages.js +300 -117
  249. package/dist-lib/spec/local/hyperschema/index.js +97 -4
  250. package/dist-lib/spec/local/hyperschema/schema.json +58 -1
  251. package/dist-lib/spec/local/hyperschema/types.d.ts +14 -0
  252. package/dist-lib/spec/mesh/hyperdb/messages.js +393 -288
  253. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +6 -0
  254. package/dist-lib/spec/mesh/hyperdispatch/index.js +18 -1
  255. package/dist-lib/spec/mesh/hyperdispatch/messages.js +176 -85
  256. package/dist-lib/spec/mesh/hyperschema/index.js +176 -85
  257. package/dist-lib/spec/mesh/hyperschema/schema.json +71 -21
  258. package/dist-lib/spec/mesh/hyperschema/types.d.ts +14 -1
  259. package/package.json +16 -10
  260. package/tui/README.md +7 -0
  261. package/tui/app.mjs +311 -14
  262. package/tui/lib/busy-words.mjs +57 -5
  263. package/tui/lib/export.mjs +1 -0
  264. package/tui/lib/render.mjs +9 -2
  265. package/tui/main.mjs +5 -2
package/tui/app.mjs CHANGED
@@ -16,6 +16,13 @@ import {
16
16
  scopedKey,
17
17
  SPOTIFY_CREDENTIAL_KEY
18
18
  } from '../dist-lib/lib/oauth/keys.js'
19
+ import {
20
+ COMPACTION_MIN_CTX_SIZE,
21
+ contextOptionsForModel,
22
+ defaultContextForModel,
23
+ formatTokenCount,
24
+ maxContextForModel
25
+ } from '../dist-lib/lib/model-context.js'
19
26
  import {
20
27
  busyStatus,
21
28
  findPendingApproval,
@@ -81,6 +88,7 @@ const COMMANDS = [
81
88
  { name: 'new-chat', desc: 'create and switch to a new chat', palette: true },
82
89
  { name: 'agents', desc: 'switch between your agents (interactive picker)', palette: true },
83
90
  { name: 'agent', desc: 'show, list, create, rename, or switch the active agent' },
91
+ { name: 'ctx', desc: "show or set the agent's context size; ↑/↓ move, enter sets" },
84
92
  {
85
93
  name: 'activity',
86
94
  desc: "list the active agent's tool-call activity (allowed/denied/auto/skip-all/blocked)"
@@ -93,6 +101,10 @@ const COMMANDS = [
93
101
  palette: true
94
102
  },
95
103
  { name: 'knowledge', desc: 'list, download, or remove knowledge in the active chat' },
104
+ {
105
+ name: 'compact',
106
+ desc: 'fold the older turns of this chat into a summary now, as a full window would'
107
+ },
96
108
  { name: 'files', desc: 'show file readiness, progress, and failures in this chat' },
97
109
  {
98
110
  name: 'skills',
@@ -119,6 +131,10 @@ const COMMANDS = [
119
131
  palette: true
120
132
  },
121
133
  { name: 'join', desc: "join another device's mesh with its invite (replaces this one)" },
134
+ {
135
+ name: 'leave',
136
+ desc: 'leave the active mesh; a fresh account is minted when nothing else is writable'
137
+ },
122
138
  {
123
139
  name: 'invite',
124
140
  desc: 'show this mesh device invite - /invite member opens your shared room and invites someone into it (your account is never shared)',
@@ -392,6 +408,58 @@ export function formatPermissions(sel) {
392
408
  return [header, '', ...lines]
393
409
  }
394
410
 
411
+ // /ctx overlay: the model's context options, with the size in use, the default and the ceiling
412
+ // marked. An agent without a size of its own is at the default, and the header says so.
413
+ export function formatContextSizes(sel) {
414
+ const { rows, cursor, model, current, inUse, max, defaultSize } = sel
415
+ const state = current ? '' : ' (default)'
416
+ const header = fg.dim.render(
417
+ `Context size · ${model} — ${formatTokenCount(inUse)} in use${state} · max ${formatTokenCount(max)} — ↑/↓ move · enter set · esc return`
418
+ )
419
+ const lines = rows.map((size, i) => {
420
+ const point = i === cursor ? fg.magenta.render('❯ ') : ' '
421
+ const badge = size === inUse ? fg.cyan.render('● ') : fg.dim.render('○ ')
422
+ const notes = []
423
+ if (size === defaultSize) notes.push('default')
424
+ if (size === max) notes.push('max')
425
+ if (size < COMPACTION_MIN_CTX_SIZE) notes.push('no compaction')
426
+ const label = formatTokenCount(size).padEnd(10)
427
+ return `${point}${badge}${fg.white.render(label)} ${fg.dim.render(notes.join(' · '))}`
428
+ })
429
+ return [header, '', ...lines]
430
+ }
431
+
432
+ // `8k` is how the picker prints a size, so it reads back the same way (k = 1,024)
433
+ export function parseTokenCount(raw) {
434
+ const match = /^(\d+(?:\.\d+)?)([km])?$/i.exec(raw)
435
+ if (!match) return null
436
+ const scale = match[2] ? (match[2].toLowerCase() === 'k' ? 1_024 : 1_048_576) : 1
437
+ const size = Math.round(Number(match[1]) * scale)
438
+ return size > 0 ? size : null
439
+ }
440
+
441
+ function contextSizeNotice(agent, size) {
442
+ const max = formatTokenCount(maxContextForModel(agent.modelName ?? ''))
443
+ if (!size) {
444
+ const fallback = formatTokenCount(defaultContextForModel(agent.modelName ?? ''))
445
+ return `${agent.name} context size cleared — runs at the default ${fallback} (max ${max}) — lands on the next message`
446
+ }
447
+ const floor =
448
+ size < COMPACTION_MIN_CTX_SIZE
449
+ ? ' · under the 4K compaction floor: a full window is not folded, the overflow ladder handles it'
450
+ : ''
451
+ return `${agent.name} context size set to ${formatTokenCount(size)} (max ${max})${floor} — lands on the next message`
452
+ }
453
+
454
+ // the menu row already answers the two numbers the picker is about
455
+ function contextSizeHint(agent) {
456
+ const model = agent?.modelName ?? ''
457
+ const now = agent?.ctxSize
458
+ ? formatTokenCount(agent.ctxSize)
459
+ : `${formatTokenCount(defaultContextForModel(model))} default`
460
+ return `${now} · max ${formatTokenCount(maxContextForModel(model))}`
461
+ }
462
+
395
463
  const SKILL_STATUS_PAINT = {
396
464
  ready: 'dim',
397
465
  'needs-setup': 'amber',
@@ -410,6 +478,7 @@ const SKILL_STATUS_PAINT = {
410
478
  export function formatSelector(sel) {
411
479
  const { kind, rows, enabled, scope, cursor, detail } = sel
412
480
  if (kind === 'permissions') return formatPermissions(sel)
481
+ if (kind === 'ctx') return formatContextSizes(sel)
413
482
  const title = kind === 'skills' ? 'Skills' : 'Tools'
414
483
  if (!rows.length) {
415
484
  return [fg.dim.render(`(no ${kind} advertised — provider offline or pre-upgrade)`)]
@@ -526,6 +595,8 @@ export function renderTurn(turn, agentName, deviceLabels, opts = {}) {
526
595
  // A requested-but-not-yet-started run has a turn (so busy derives from it)
527
596
  // but nothing to say — the busy line is its visible side.
528
597
  if (turn.from === 'agent' && !turn.segments.length && !turn.status) return ''
598
+ // the turns above it stay on screen; only the prompt the model reads shrank
599
+ if (turn.from === 'compaction') return fg.dim.render('── compacted session ──')
529
600
  const userLabel =
530
601
  (turn.deviceId && deviceLabels?.get(turn.deviceId)) || turn.deviceId?.slice(0, 8) || 'you'
531
602
  const label = turn.from === 'user' ? fg.cyan.render(userLabel) : fg.magenta.render(agentName)
@@ -534,7 +605,7 @@ export function renderTurn(turn, agentName, deviceLabels, opts = {}) {
534
605
  if (segment.type === 'thinking') {
535
606
  // a model that skips its reasoning still streams the think tags' newlines
536
607
  const thought = segment.text.trim()
537
- if (thought) lines.push(fg.dim.render(` (thinking: ${thought})`))
608
+ if (thought) lines.push(fg.dim.render(` (thinking: ${thought})`), '')
538
609
  } else if (segment.type === 'tool-call') {
539
610
  const call = ` → ${segment.detail.name}(${JSON.stringify(segment.detail.arguments)})`
540
611
  lines.push(fg.amber.render(clampTool(call, opts)))
@@ -582,7 +653,14 @@ export function renderTurn(turn, agentName, deviceLabels, opts = {}) {
582
653
  if (turn.status === 'failed') {
583
654
  lines.push(fg.err.render(` [failed${turn.statusReason ? `: ${turn.statusReason}` : ''}]`))
584
655
  }
656
+ // the gap after a thought separates it from the answer, not from the busy line
657
+ if (lines.at(-1) === '') lines.pop()
585
658
  const metrics = turn.status === 'completed' ? turn.statusDetail?.metrics : null
659
+ // the SDK stops a turn at the ceiling with what it has and the run completes, so this line
660
+ // is the only thing that says the answer is not whole
661
+ if (metrics?.stopReason === 'length') {
662
+ lines.push(fg.amber.render(' [answer cut by the context window]'))
663
+ }
586
664
  if (metrics) {
587
665
  const parts = [`${metrics.totalTokens} tok`]
588
666
  if (metrics.tokensPerSecond) parts.push(`${metrics.tokensPerSecond.toFixed(1)} tok/s`)
@@ -800,6 +878,14 @@ const MEMBER_INVITE_DISCLOSURES = [
800
878
  'and today a co-member approval rule governs your tool calls in this room (tracked separately)'
801
879
  ]
802
880
 
881
+ // A compute mesh carries no conversation and no approval rules, so two of the disclosures above
882
+ // would be false of one. What is true of it is the key material and the device inventory.
883
+ const COMPUTE_INVITE_DISCLOSURES = [
884
+ 'everyone ever admitted to this mesh holds its key material for good - a kick revokes a writer, never the key',
885
+ 'co-members see each of your devices: name, platform, app version, installed tools, skills, models and tool catalog',
886
+ 'nothing else travels: no chats, no documents, no knowledge, no agents, no tool settings'
887
+ ]
888
+
803
889
  // A mesh has no name, only its 64-char key, so the list is read by its number:
804
890
  // `/mesh use <n>` takes the same index.
805
891
  // `shared` is occupancy, not the registry marker: what the user wants to know is which of these
@@ -809,7 +895,8 @@ function formatMeshes(meshes) {
809
895
  const rows = meshes.map((mesh, index) => {
810
896
  const tags = [
811
897
  mesh.home ? 'account' : null,
812
- !mesh.home && mesh.members > 1 ? 'shared' : null,
898
+ mesh.compute ? 'compute' : null,
899
+ !mesh.home && !mesh.compute && mesh.members > 1 ? 'shared' : null,
813
900
  mesh.open ? 'open' : 'closed'
814
901
  ]
815
902
  if (mesh.open) tags.push(mesh.writable ? 'writable' : 'read-only')
@@ -837,6 +924,11 @@ function resolveMesh(meshes, selector) {
837
924
  // How long a bootstrap waits for the mesh's own seed to replicate before minting its own.
838
925
  const SEED_REPLICATION_MS = 10_000
839
926
 
927
+ // a room holds one default per member, each pinned to its owner's device; ours runs here
928
+ const isOwnDefault = (agent, deviceId) =>
929
+ Boolean(deviceId) && agent.isDefault === true && agent.providerDeviceId?.equals(deviceId) === true
930
+ const ownDefault = (agents, deviceId) => agents.find((agent) => isOwnDefault(agent, deviceId))
931
+
840
932
  // The mesh seeds its default agent at birth and a joiner waits for it to replicate - watch-driven
841
933
  // (agentsWatch fires on every change), no polling. This device mints one as a fallback if none
842
934
  // shows within the timeout: an unbounded wait here blocks the composer for good, and a mesh can
@@ -851,7 +943,8 @@ async function firstAgent(engine, deviceId, modelName) {
851
943
  while (true) {
852
944
  const { value, done } = await Promise.race([watch.next(), timeout])
853
945
  if (done) break
854
- const live = value.agents?.[0]
946
+ const agents = value.agents ?? []
947
+ const live = ownDefault(agents, deviceId) ?? agents[0]
855
948
  if (live) return live
856
949
  }
857
950
  } finally {
@@ -976,6 +1069,7 @@ export class ChatApp {
976
1069
  this.vp = viewport.create({ width: 0, height: Math.max(1, this.height - CHROME_ROWS) })
977
1070
  this.spin = spinner.create({ fps: 10 })
978
1071
  this.busy = false
1072
+ this._busySince = 0 // when busy last flipped on — the busy word's clock (see busyWord's slips)
979
1073
  this.modelState = null // last 'model' event from the harness (loading/downloading/ready/unloading)
980
1074
  this.status = ''
981
1075
  this.notice = null // last /command output, rendered as a trailing transcript block
@@ -1018,6 +1112,7 @@ export class ChatApp {
1018
1112
  this._chats = []
1019
1113
  this._groups = []
1020
1114
  this._chatsIterator = null
1115
+ this._ownDefaultIterator = null
1021
1116
  this._turns = [] // last rendered turns — re-combined with the busy line on every render
1022
1117
  // Derived from _turns on every _setTranscript, not bridged in from the
1023
1118
  // harness — approval state lives entirely in the chunk stream (see
@@ -1168,6 +1263,26 @@ export class ChatApp {
1168
1263
  }
1169
1264
  }
1170
1265
 
1266
+ // a joiner boots onto whatever agent the room holds; its own default is seeded after the join
1267
+ _watchOwnDefault() {
1268
+ if (!this.engine.agentsWatch || isOwnDefault(this.agent, this.originDeviceId)) return null
1269
+ const gen = this.gen
1270
+ const booted = this.agent?.id
1271
+ const it = this.engine.agentsWatch({})[Symbol.asyncIterator]()
1272
+ this._ownDefaultIterator = it
1273
+ return async () => {
1274
+ while (true) {
1275
+ const { value, done } = await it.next()
1276
+ if (done) return { type: 'own-default', gen, booted, agent: null }
1277
+ const agent = ownDefault(value.agents ?? [], this.originDeviceId)
1278
+ if (agent) {
1279
+ await it.return?.()
1280
+ return { type: 'own-default', gen, booted, agent }
1281
+ }
1282
+ }
1283
+ }
1284
+ }
1285
+
1171
1286
  // Device names for the per-device user labels — same re-arm/stale-guard
1172
1287
  // shape as the other watch loops. Null when the engine lacks the
1173
1288
  // capability (e.g. a headless test fake).
@@ -1237,6 +1352,7 @@ export class ChatApp {
1237
1352
  if (lastTurn?.from === 'agent') this._awaitingRun = false
1238
1353
  const wasBusy = this.busy
1239
1354
  this.busy = running || this._awaitingRun
1355
+ if (this.busy && !wasBusy) this._busySince = Date.now()
1240
1356
  // The most recent run's id, for _requestStop() below to stopRun() —
1241
1357
  // undefined once nothing is running.
1242
1358
  this._runningRunId = this.busy ? (lastChunk?.runId ?? this._runningRunId) : null
@@ -1263,7 +1379,7 @@ export class ChatApp {
1263
1379
  if (this.pendingApproval) return null
1264
1380
  if (!this.busy) return null
1265
1381
  const runTurn = runningAgentTurn(this._turns)
1266
- const { text, on } = busyStatus(this.modelState, runTurn)
1382
+ const { text, on } = busyStatus(this.modelState, runTurn, Date.now() - this._busySince)
1267
1383
  const where =
1268
1384
  on === 'local'
1269
1385
  ? this._deviceName(this.originDeviceId?.toString('hex'))
@@ -1394,13 +1510,15 @@ export class ChatApp {
1394
1510
  ' /group order <group> after <group>|first — reorder the groups themselves',
1395
1511
  ' /knowledge [list] · /knowledge add <file> · /knowledge add-dir <directory> · /knowledge download <n|id> · /knowledge remove <n|id>',
1396
1512
  ' /files — show upload progress, local readiness, and failures for this chat',
1513
+ ' /compact — fold the older turns of this chat into a summary now (what a full context window triggers on its own); the notice shows the summary or why the fold was refused',
1397
1514
  ' /attach <path> [<path> …] — attach local files to this chat (quote paths that contain spaces)',
1398
1515
  ' /save [n] — download the latest (or n-th) attachment to ~/Downloads',
1399
1516
  ' /export [n] — write the last run (or last n) to a markdown file: prompt, thinking, answer, tools',
1400
1517
  '',
1401
1518
  'Agent',
1402
- ' /agents — pick from your agents to switch (interactive) · /agent — show current · /agent list · /agent new <name> · /agent rename <name> · /agent use <name|id>',
1519
+ ' /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',
1403
1520
  " /activity — list the active agent's recent tool calls, each with its decision (allowed/denied/auto/skip-all/blocked)",
1521
+ ' /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',
1404
1522
  ' /skills · /tools — browse installed; ↑/↓ move, space toggles each on/off (sets scope=selected), enter sets up or reconfigures the skill, esc returns',
1405
1523
  ' /skill on|off <name> · /tool on|off <name> — toggle (sets scope=selected)',
1406
1524
  ' /permissions — approval mode + the toolset switches; ↑/↓ move, space toggles',
@@ -1424,8 +1542,9 @@ export class ChatApp {
1424
1542
  ' /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',
1425
1543
  ' /scope skills|tools all|selected — switch scope',
1426
1544
  ' /join <qvac://mesh/…> — retire this device’s mesh and join that one (ctrl+y copies this mesh’s invite) · /join cancel — abort a join in progress',
1545
+ ' /leave — leave the active mesh; the device lands on another mesh it can write to, or mints a fresh account',
1427
1546
  ' /invite - show this mesh device invite · /invite member - open your shared room and invite someone into it (your account is never shared)',
1428
- ' /mesh new - open another shared room · /mesh label <n|id> <name> - name a room, privately to you',
1547
+ ' /mesh new - open another shared room · /mesh new compute - lend this device · /mesh label <n|id> <name> - name a room, privately to you',
1429
1548
  ' /members — list mesh members with their devices grouped',
1430
1549
  ' /meshes - list the meshes this device belongs to, numbered, marking account / shared / active / open / writable',
1431
1550
  ' /mesh use <n|id> - make one of them active; its agent, chat and roster replace the ones on screen',
@@ -1459,8 +1578,33 @@ export class ChatApp {
1459
1578
 
1460
1579
  if (cmd === 'new-chat') return this._newChat('New Chat')
1461
1580
 
1581
+ if (cmd === 'compact') {
1582
+ if (rawArgs.trim()) return notice('usage: /compact')
1583
+ if (this.busy) return notice('a run is in flight — /compact once it has finished')
1584
+ return run(async () => {
1585
+ const result = await engine.compactChat({ id: this.chatId })
1586
+ if (!result.compacted) return `not compacted: ${result.reason ?? 'unknown reason'}`
1587
+ const { chunks } = await engine.listChunks({ chatId: this.chatId, type: 'compaction' })
1588
+ const summary = chunks?.at(-1)?.compaction?.summary ?? ''
1589
+ return `compacted ${result.foldedTurns} turn(s) into:\n${summary}`
1590
+ })
1591
+ }
1592
+
1462
1593
  if (cmd === 'my-device') return this._showDiagnostics()
1463
1594
 
1595
+ if (cmd === 'ctx') {
1596
+ const raw = rest[0]?.toLowerCase()
1597
+ if (!raw) return this._showContextSizes()
1598
+ const max = maxContextForModel(agent.modelName ?? '')
1599
+ const size = raw === 'auto' ? 0 : parseTokenCount(raw)
1600
+ if (rest.length > 1 || size === null || size > max) {
1601
+ return notice(
1602
+ `usage: /ctx · /ctx <tokens>|auto — up to ${formatTokenCount(max)} for ${agent.modelName ?? 'this model'}`
1603
+ )
1604
+ }
1605
+ return this._setContextSize(size)
1606
+ }
1607
+
1464
1608
  if (cmd === 'models') {
1465
1609
  const raw = rest[0]?.toLowerCase()
1466
1610
  if (!raw) return this._showModels(null)
@@ -1535,7 +1679,10 @@ export class ChatApp {
1535
1679
  if (!action) {
1536
1680
  return run(async () => {
1537
1681
  const a = await engine.getAgent({ id: agent.id })
1538
- return `agent ${a.name} (${a.id.slice(0, 8)}) · skills=${a.skillsScope ?? 'all'} tools=${a.toolsScope ?? 'all'}`
1682
+ const lender = a.lenderDeviceId
1683
+ ? ` · model borrowed from ${a.lenderDeviceId.toString('hex').slice(0, 8)}`
1684
+ : ''
1685
+ return `agent ${a.name} (${a.id.slice(0, 8)}) · skills=${a.skillsScope ?? 'all'} tools=${a.toolsScope ?? 'all'}${lender}`
1539
1686
  })
1540
1687
  }
1541
1688
  if (action === 'list') {
@@ -1566,6 +1713,21 @@ export class ChatApp {
1566
1713
  return `renamed to ${this.agent.name} (${this.agent.id.slice(0, 8)})`
1567
1714
  })
1568
1715
  }
1716
+ if (action === 'borrow') {
1717
+ return run(async () => {
1718
+ if (arg === 'none') {
1719
+ this.agent = await engine.updateAgent({ id: agent.id, clearLenderDeviceId: true })
1720
+ return `${this.agent.name} answers on this device again`
1721
+ }
1722
+ if (arg) return 'usage: /agent borrow · /agent borrow none'
1723
+ const { computeLenderId } = await engine.deviceInfo({})
1724
+ if (!computeLenderId) {
1725
+ return 'no single device to borrow from - /mesh new compute lends one, and two lenders is no choice'
1726
+ }
1727
+ this.agent = await engine.updateAgent({ id: agent.id, lenderDeviceId: computeLenderId })
1728
+ return `${this.agent.name} borrows its model from ${computeLenderId.toString('hex').slice(0, 8)}`
1729
+ })
1730
+ }
1569
1731
  if (action === 'use') {
1570
1732
  if (!arg) return notice('usage: /agent use <name|id>')
1571
1733
  return run(async () => {
@@ -1576,7 +1738,7 @@ export class ChatApp {
1576
1738
  return `selected ${found.name} (${found.id.slice(0, 8)})`
1577
1739
  })
1578
1740
  }
1579
- return notice('usage: /agent [list|new <name>|rename <name>|use <name|id>]')
1741
+ return notice('usage: /agent [list|new <name>|rename <name>|use <name|id>|borrow [none]]')
1580
1742
  }
1581
1743
 
1582
1744
  if (cmd === 'activity') {
@@ -2006,6 +2168,27 @@ export class ChatApp {
2006
2168
  ]
2007
2169
  }
2008
2170
 
2171
+ if (cmd === 'leave') {
2172
+ if (rawArgs.trim()) return notice('usage: /leave')
2173
+ // the menu bypasses _submit's block, and the refusal below would drop a parked join's
2174
+ if (this._booting) return notice('a mesh transition is already in flight')
2175
+ this._booting = true
2176
+ this.status = 'leaving mesh…'
2177
+ this.notice = null
2178
+ return [
2179
+ this,
2180
+ async () => {
2181
+ try {
2182
+ await engine.leaveMesh({})
2183
+ const next = await engine.meshInvite({}).catch(() => null)
2184
+ return { type: 'mesh.left', invite: next?.invite ?? null }
2185
+ } catch (error) {
2186
+ return { type: 'mesh.left', error }
2187
+ }
2188
+ }
2189
+ ]
2190
+ }
2191
+
2009
2192
  if (cmd === 'invite') {
2010
2193
  const member = rest[0] === 'member'
2011
2194
  const target = member ? rest[1] : null
@@ -2029,7 +2212,9 @@ export class ChatApp {
2029
2212
  }
2030
2213
  const lines = [await this._roomHeading(res.meshId)]
2031
2214
  if (res.notice) lines.push(res.notice)
2032
- lines.push(...MEMBER_INVITE_DISCLOSURES)
2215
+ const { meshes: listed } = await engine.listMeshes({}).catch(() => ({ meshes: [] }))
2216
+ const isCompute = (listed ?? []).find((m) => m.meshId === res.meshId)?.compute
2217
+ lines.push(...(isCompute ? COMPUTE_INVITE_DISCLOSURES : MEMBER_INVITE_DISCLOSURES))
2033
2218
  lines.push(`${copied ? 'invite (copied)' : 'invite'}:\n${res.invite}`)
2034
2219
  return lines.join('\n')
2035
2220
  })
@@ -2047,7 +2232,7 @@ export class ChatApp {
2047
2232
  const lines = []
2048
2233
  for (const m of members) {
2049
2234
  const hex = m.id.toString('hex')
2050
- lines.push(`${m.name} (${hex.slice(0, 8)})`)
2235
+ lines.push(`${m.name} (${hex.slice(0, 8)})${m.removed ? ' (removed)' : ''}`)
2051
2236
  for (const d of devices) {
2052
2237
  if (d.memberId?.toString('hex') !== hex) continue
2053
2238
  lines.push(` · ${d.name}${d.revoked ? ' (revoked)' : ''}`)
@@ -2076,9 +2261,11 @@ export class ChatApp {
2076
2261
  const [action, target, ...labelParts] = rest
2077
2262
  if (action === 'use' && target) return this._selectMesh(target)
2078
2263
  if (action === 'new') {
2264
+ const compute = target === 'compute'
2079
2265
  return run(async () => {
2080
- const { meshId } = await engine.createRoom({})
2081
- return `${await this._roomHeading(meshId)}\n/invite member <n|id> invites someone into it`
2266
+ const { meshId } = await engine.createRoom({ compute })
2267
+ const invite = '/invite member <n|id> invites someone into it'
2268
+ return `${await this._roomHeading(meshId)}\n${invite}`
2082
2269
  })
2083
2270
  }
2084
2271
  if (action === 'label' && target) {
@@ -2091,7 +2278,7 @@ export class ChatApp {
2091
2278
  return `${named.meshId.slice(0, 8)} is "${label}" to you - the room co-members never see it`
2092
2279
  })
2093
2280
  }
2094
- return notice('usage: /mesh use <n|id> · /mesh new · /mesh label <n|id> <name>')
2281
+ return notice('usage: /mesh use <n|id> · /mesh new [compute] · /mesh label <n|id> <name>')
2095
2282
  }
2096
2283
 
2097
2284
  // /chats + /agents open the same interactive pickers as the menu's Switch
@@ -2423,6 +2610,8 @@ export class ChatApp {
2423
2610
  _resetMeshWatches() {
2424
2611
  this._devicesIterator?.return?.().catch(() => {})
2425
2612
  this._devicesIterator = null
2613
+ this._ownDefaultIterator?.return?.().catch(() => {})
2614
+ this._ownDefaultIterator = null
2426
2615
  this.deviceLabels = new Map()
2427
2616
  this.deviceMembers = new Map()
2428
2617
  this.memberNames = new Map()
@@ -2662,6 +2851,55 @@ export class ChatApp {
2662
2851
  return skills ? new Map(skills.map((skill) => [skill.name, skill])) : null
2663
2852
  }
2664
2853
 
2854
+ // The rows are the model's own catalog options, so a size it cannot load never shows.
2855
+ _showContextSizes() {
2856
+ const { engine, agent } = this
2857
+ return [
2858
+ this,
2859
+ async () => {
2860
+ try {
2861
+ const fresh = await engine.getAgent({ id: agent.id })
2862
+ const model = fresh.modelName ?? ''
2863
+ return {
2864
+ type: 'ctx.result',
2865
+ model,
2866
+ options: contextOptionsForModel(model),
2867
+ current: fresh.ctxSize || 0,
2868
+ max: maxContextForModel(model),
2869
+ defaultSize: defaultContextForModel(model)
2870
+ }
2871
+ } catch (error) {
2872
+ return { type: 'ctx.result', error }
2873
+ }
2874
+ }
2875
+ ]
2876
+ }
2877
+
2878
+ // 0 clears the agent's own size, so the device default (and past it the harness) applies again
2879
+ _setContextSize(size) {
2880
+ const { engine, agent } = this
2881
+ const patch = size ? { ctxSize: size } : { clearCtxSize: true }
2882
+ return [
2883
+ this,
2884
+ async () => {
2885
+ try {
2886
+ this.agent = await engine.updateAgent({ id: agent.id, ...patch })
2887
+ return { type: 'notice', text: contextSizeNotice(this.agent, size) }
2888
+ } catch (error) {
2889
+ return { type: 'run.error', error }
2890
+ }
2891
+ }
2892
+ ]
2893
+ }
2894
+
2895
+ // one value, not a set: the pick closes the overlay and the notice says what landed
2896
+ _pickContextSize(s) {
2897
+ const size = s.rows[s.cursor]
2898
+ this._selector = null
2899
+ this._render()
2900
+ return this._setContextSize(size)
2901
+ }
2902
+
2665
2903
  // The PRD's Tools screen: the approval mode on top, then the toolset switches. Rows come
2666
2904
  // from TOOLSETS, not the provider catalog — a toolset with nothing installed here still shows,
2667
2905
  // so it can be switched off before the agent ever runs somewhere that has it.
@@ -2723,6 +2961,7 @@ export class ChatApp {
2723
2961
  { label: 'Tools', hint: 'toggle tools on/off', overlay: 'tools' },
2724
2962
  { label: 'Permissions', hint: 'approval mode & toolsets', overlay: 'permissions' },
2725
2963
  { label: 'Model', hint: "pick the agent's model", overlay: 'models' },
2964
+ { label: 'Context size', hint: contextSizeHint(this.agent), overlay: 'ctx' },
2726
2965
  { label: 'Image defaults', hint: 'model, steps, size', command: '/image' },
2727
2966
  { label: 'Activity', hint: 'recent tool calls', command: '/activity' },
2728
2967
  {
@@ -2814,6 +3053,7 @@ export class ChatApp {
2814
3053
  { label: 'Move to group…', hint: '/group move <group>|-', prefill: '/group move ' },
2815
3054
  { label: 'New group…', hint: '/group new <name>', prefill: '/group new ' },
2816
3055
  { label: 'Knowledge', hint: 'list chat knowledge', command: '/knowledge' },
3056
+ { label: 'Compact', hint: 'fold older turns into a summary now', command: '/compact' },
2817
3057
  { label: 'Files', hint: 'readiness, progress, and failures', command: '/files' },
2818
3058
  { label: 'Attach file…', hint: '/attach <path>', prefill: '/attach ' },
2819
3059
  { label: 'Save attachment', hint: 'latest → save dir', command: '/save' },
@@ -2830,6 +3070,7 @@ export class ChatApp {
2830
3070
  { label: 'Meshes', hint: 'the meshes this device belongs to', command: '/meshes' },
2831
3071
  { label: 'Switch mesh…', hint: '/mesh use <n|id>', prefill: '/mesh use ' },
2832
3072
  { label: 'Join mesh…', hint: '/join <qvac://mesh/…>', prefill: '/join ' },
3073
+ { label: 'Leave mesh', hint: 'leave the active mesh', command: '/leave' },
2833
3074
  { label: 'Cancel join', hint: 'abort a join in progress', command: '/join cancel' }
2834
3075
  ]
2835
3076
  }
@@ -2974,6 +3215,7 @@ export class ChatApp {
2974
3215
  if (entry.overlay === 'models') return this._showModels(null)
2975
3216
  if (entry.overlay === 'diagnostics') return this._showDiagnostics()
2976
3217
  if (entry.overlay === 'permissions') return this._showPermissions()
3218
+ if (entry.overlay === 'ctx') return this._showContextSizes()
2977
3219
  return this._showSelector(entry.overlay)
2978
3220
  }
2979
3221
  if (entry.prefill) {
@@ -3123,6 +3365,7 @@ export class ChatApp {
3123
3365
  // Optimistic: the row updates now, the engine call syncs this.agent after.
3124
3366
  _toggleSelector() {
3125
3367
  const s = this._selector
3368
+ if (s.kind === 'ctx') return this._pickContextSize(s)
3126
3369
  const name = s.rows[s.cursor]
3127
3370
  if (!name) return [this, null]
3128
3371
  if (s.kind === 'permissions') return this._togglePermission(s, name)
@@ -3156,6 +3399,7 @@ export class ChatApp {
3156
3399
  // prints its steps. The overlay closes either way — the setup is the next step.
3157
3400
  _setupSelected() {
3158
3401
  const s = this._selector
3402
+ if (s.kind === 'ctx') return this._pickContextSize(s)
3159
3403
  if (s.kind !== 'skills' || !s.detail) return [this, null]
3160
3404
  const skill = s.detail.get(s.rows[s.cursor])
3161
3405
  if (!skill) return [this, null]
@@ -3731,6 +3975,19 @@ export class ChatApp {
3731
3975
  return [this, this._adoptMesh(msg.invite, 'joined — resolving the mesh’s agent and chat…')]
3732
3976
  }
3733
3977
 
3978
+ if (msg.type === 'mesh.left') {
3979
+ if (msg.error) {
3980
+ this._booting = false
3981
+ this.status = fg.err.render(`leave failed: ${msg.error.message}`)
3982
+ this._render()
3983
+ return [this, null]
3984
+ }
3985
+ return [
3986
+ this,
3987
+ this._adoptMesh(msg.invite, 'left — resolving the landing mesh’s agent and chat…')
3988
+ ]
3989
+ }
3990
+
3734
3991
  // /mesh use settled. Same landing as a join, minus the admission: the target
3735
3992
  // mesh was already ours, so only the agent, chat and roster have to catch up.
3736
3993
  if (msg.type === 'mesh.selected') {
@@ -3766,13 +4023,25 @@ export class ChatApp {
3766
4023
  this.chatId = msg.chat.id
3767
4024
  this._booting = false
3768
4025
  this._render()
3769
- return [this, batch(this._watchNext(), this._watchNextFiles())]
4026
+ return [this, batch(this._watchNext(), this._watchNextFiles(), this._watchOwnDefault())]
3770
4027
  }
3771
4028
  if (msg.type === 'boot-error') {
3772
4029
  this.status = fg.err.render(`startup failed: ${msg.error.message}`)
3773
4030
  this._render()
3774
4031
  return [this, null]
3775
4032
  }
4033
+ if (msg.type === 'own-default') {
4034
+ // a stale one-shot must not clear the field a newer watch owns
4035
+ if (msg.gen !== this.gen) return [this, null]
4036
+ this._ownDefaultIterator = null
4037
+ if (!msg.agent) return [this, null]
4038
+ // the seed lands whenever it replicates, and a /agent pick since the watch armed outranks it
4039
+ if (msg.booted !== this.agent?.id) return [this, null]
4040
+ this.agent = msg.agent
4041
+ this.notice = `selected ${msg.agent.name} (${msg.agent.id.slice(0, 8)}) · this device's default`
4042
+ this._render()
4043
+ return [this, null]
4044
+ }
3776
4045
 
3777
4046
  if (msg.type === 'mesh-status') {
3778
4047
  if (msg.gen !== this.gen) return [this, null]
@@ -3889,6 +4158,29 @@ export class ChatApp {
3889
4158
  this._render()
3890
4159
  return [this, null]
3891
4160
  }
4161
+ if (msg.type === 'ctx.result') {
4162
+ if (msg.error) {
4163
+ this._selector = null
4164
+ this.overlay = [fg.err.render(`/ctx failed: ${msg.error.message}`)]
4165
+ } else {
4166
+ this._models = null
4167
+ this.overlay = null
4168
+ // an agent with no size of its own runs at the default, so that is the row in use
4169
+ const inUse = msg.current || msg.defaultSize
4170
+ this._selector = {
4171
+ kind: 'ctx',
4172
+ rows: msg.options,
4173
+ model: msg.model,
4174
+ current: msg.current,
4175
+ inUse,
4176
+ max: msg.max,
4177
+ defaultSize: msg.defaultSize,
4178
+ cursor: Math.max(0, msg.options.indexOf(inUse))
4179
+ }
4180
+ }
4181
+ this._render()
4182
+ return [this, null]
4183
+ }
3892
4184
  if (msg.type === 'selector.saved') return [this, null] // the toggle already re-rendered; sync only
3893
4185
 
3894
4186
  // A fetched menu page resolved. From a menu row (menu open) it drills in as a
@@ -4247,6 +4539,11 @@ export class ChatApp {
4247
4539
  const { meshes } = await this.engine.listMeshes({}).catch(() => ({ meshes: [] }))
4248
4540
  const index = (meshes ?? []).findIndex((mesh) => mesh.meshId === meshId)
4249
4541
  const where = index < 0 ? '/meshes lists it' : `/mesh use ${index + 1} to open it`
4542
+ // a compute mesh is not a room to talk in: there is nothing to select into, so saying
4543
+ // "shared room" of one would promise a place to work that it deliberately is not
4544
+ if ((meshes ?? [])[index]?.compute) {
4545
+ return `compute mesh ${meshId.slice(0, 8)} - lends this device, carries nothing`
4546
+ }
4250
4547
  return `shared room ${meshId.slice(0, 8)} - not selected, ${where}`
4251
4548
  }
4252
4549