@qvac/core 0.6.7 → 0.7.1

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 (146) hide show
  1. package/CHANGELOG.md +211 -1
  2. package/README.md +2 -0
  3. package/dist-lib/lib/api/app-config.d.ts +3 -1
  4. package/dist-lib/lib/api/app-config.js +15 -4
  5. package/dist-lib/lib/api/chat.d.ts +1 -1
  6. package/dist-lib/lib/api/chat.js +9 -0
  7. package/dist-lib/lib/api/index.d.ts +2 -1
  8. package/dist-lib/lib/api/index.js +2 -1
  9. package/dist-lib/lib/api/network.d.ts +8 -1
  10. package/dist-lib/lib/api/network.js +6 -0
  11. package/dist-lib/lib/assistant/fake-models.d.ts +22 -0
  12. package/dist-lib/lib/assistant/fake-models.js +112 -0
  13. package/dist-lib/lib/assistant/harness.d.ts +12 -0
  14. package/dist-lib/lib/assistant/harness.js +26 -0
  15. package/dist-lib/lib/assistant/history.d.ts +5 -1
  16. package/dist-lib/lib/assistant/history.js +14 -2
  17. package/dist-lib/lib/assistant-tree.d.ts +4 -0
  18. package/dist-lib/lib/assistant-tree.js +45 -7
  19. package/dist-lib/lib/assistant.d.ts +15 -2
  20. package/dist-lib/lib/assistant.js +181 -42
  21. package/dist-lib/lib/constants.d.ts +6 -0
  22. package/dist-lib/lib/constants.js +6 -0
  23. package/dist-lib/lib/core/agent.d.ts +2 -0
  24. package/dist-lib/lib/core/agent.js +16 -5
  25. package/dist-lib/lib/core/blind-peers.d.ts +4 -0
  26. package/dist-lib/lib/core/blind-peers.js +1 -0
  27. package/dist-lib/lib/core/chat-activity.d.ts +1 -1
  28. package/dist-lib/lib/core/chat-activity.js +3 -0
  29. package/dist-lib/lib/core/chat-copy.d.ts +4 -0
  30. package/dist-lib/lib/core/chat-copy.js +1 -1
  31. package/dist-lib/lib/core/chat-fork.d.ts +21 -0
  32. package/dist-lib/lib/core/chat-fork.js +245 -0
  33. package/dist-lib/lib/core/chat-move.js +1 -4
  34. package/dist-lib/lib/core/chat.d.ts +1 -0
  35. package/dist-lib/lib/core/chat.js +1 -1
  36. package/dist-lib/lib/core/collections.d.ts +1 -0
  37. package/dist-lib/lib/core/collections.js +1 -0
  38. package/dist-lib/lib/core/contract/compute.d.ts +1 -1
  39. package/dist-lib/lib/core/contract/compute.js +2 -1
  40. package/dist-lib/lib/core/contract/index.js +6 -1
  41. package/dist-lib/lib/core/contract/invites.d.ts +1 -11
  42. package/dist-lib/lib/core/contract/invites.js +3 -3
  43. package/dist-lib/lib/core/contract/mesh-seeds.d.ts +2 -0
  44. package/dist-lib/lib/core/contract/mesh-seeds.js +26 -0
  45. package/dist-lib/lib/core/contract/open-join.d.ts +2 -0
  46. package/dist-lib/lib/core/contract/open-join.js +57 -0
  47. package/dist-lib/lib/core/departures.d.ts +8 -1
  48. package/dist-lib/lib/core/departures.js +59 -2
  49. package/dist-lib/lib/core/fs-drives.d.ts +8 -1
  50. package/dist-lib/lib/core/fs-drives.js +47 -15
  51. package/dist-lib/lib/core/harness-loan.d.ts +4 -20
  52. package/dist-lib/lib/core/harness-loan.js +7 -184
  53. package/dist-lib/lib/core/id.d.ts +1 -0
  54. package/dist-lib/lib/core/id.js +3 -0
  55. package/dist-lib/lib/core/identity.d.ts +1 -1
  56. package/dist-lib/lib/core/identity.js +6 -4
  57. package/dist-lib/lib/core/invite.d.ts +2 -0
  58. package/dist-lib/lib/core/invite.js +6 -2
  59. package/dist-lib/lib/core/membership.d.ts +1 -12
  60. package/dist-lib/lib/core/membership.js +1 -94
  61. package/dist-lib/lib/core/mesh.d.ts +11 -15
  62. package/dist-lib/lib/core/mesh.js +52 -88
  63. package/dist-lib/lib/core/migrations/agent-tools-scope.d.ts +2 -0
  64. package/dist-lib/lib/core/migrations/agent-tools-scope.js +24 -0
  65. package/dist-lib/lib/core/migrations/index.js +3 -1
  66. package/dist-lib/lib/core/peer-duplex.d.ts +32 -0
  67. package/dist-lib/lib/core/peer-duplex.js +207 -0
  68. package/dist-lib/lib/core/sync/index.js +2 -16
  69. package/dist-lib/lib/core.d.ts +47 -50
  70. package/dist-lib/lib/core.js +524 -878
  71. package/dist-lib/lib/diagnostics.d.ts +7 -0
  72. package/dist-lib/lib/diagnostics.js +22 -0
  73. package/dist-lib/lib/doctor/checks.d.ts +15 -0
  74. package/dist-lib/lib/doctor/checks.js +272 -0
  75. package/dist-lib/lib/doctor/redact.d.ts +4 -0
  76. package/dist-lib/lib/doctor/redact.js +31 -0
  77. package/dist-lib/lib/doctor/render.d.ts +8 -0
  78. package/dist-lib/lib/doctor/render.js +83 -0
  79. package/dist-lib/lib/doctor/tree.d.ts +5 -0
  80. package/dist-lib/lib/doctor/tree.js +167 -0
  81. package/dist-lib/lib/downloads-allowed-pusher.d.ts +10 -0
  82. package/dist-lib/lib/downloads-allowed-pusher.js +37 -0
  83. package/dist-lib/lib/guards.d.ts +1 -0
  84. package/dist-lib/lib/guards.js +4 -0
  85. package/dist-lib/lib/inference-calls.js +1 -5
  86. package/dist-lib/lib/kv-cache-reclaim.d.ts +2 -1
  87. package/dist-lib/lib/kv-cache-reclaim.js +24 -0
  88. package/dist-lib/lib/mesh-scoped-engine.js +4 -0
  89. package/dist-lib/lib/model-download-status.d.ts +1 -1
  90. package/dist-lib/lib/model-download.d.ts +9 -10
  91. package/dist-lib/lib/model-download.js +49 -16
  92. package/dist-lib/lib/model-memory-cap.d.ts +29 -0
  93. package/dist-lib/lib/model-memory-cap.js +69 -0
  94. package/dist-lib/lib/models-watch.d.ts +1 -1
  95. package/dist-lib/lib/models-watch.js +4 -4
  96. package/dist-lib/lib/oauth/flow.js +1 -1
  97. package/dist-lib/lib/oauth/loopback.js +16 -2
  98. package/dist-lib/lib/oauth/redirect-types.d.ts +1 -0
  99. package/dist-lib/lib/run-replay.d.ts +26 -0
  100. package/dist-lib/lib/run-replay.js +107 -0
  101. package/dist-lib/schema/config.d.ts +1 -1
  102. package/dist-lib/schema/config.js +1 -1
  103. package/dist-lib/schema/content.js +9 -1
  104. package/dist-lib/schema/engine.js +75 -6
  105. package/dist-lib/schema/field-order.js +1 -1
  106. package/dist-lib/schema/local.js +3 -2
  107. package/dist-lib/schema/qvac.js +28 -2
  108. package/dist-lib/spec/bind.js +17 -0
  109. package/dist-lib/spec/calls.js +4 -0
  110. package/dist-lib/spec/capabilities.d.ts +8 -0
  111. package/dist-lib/spec/config/hyperconf/index.js +1 -1
  112. package/dist-lib/spec/hrpc/hrpc.json +52 -0
  113. package/dist-lib/spec/hrpc/index.js +53 -4
  114. package/dist-lib/spec/hrpc/messages.js +1498 -1278
  115. package/dist-lib/spec/hyperschema/index.js +1498 -1278
  116. package/dist-lib/spec/hyperschema/schema.json +182 -0
  117. package/dist-lib/spec/hyperschema/types.d.ts +49 -3
  118. package/dist-lib/spec/local/hyperdb/messages.js +22 -10
  119. package/dist-lib/spec/local/hyperschema/index.js +16 -7
  120. package/dist-lib/spec/local/hyperschema/schema.json +10 -1
  121. package/dist-lib/spec/local/hyperschema/types.d.ts +3 -2
  122. package/dist-lib/spec/mesh/hyperdb/db.json +16 -1
  123. package/dist-lib/spec/mesh/hyperdb/index.js +71 -2
  124. package/dist-lib/spec/mesh/hyperdb/messages.js +530 -246
  125. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +13 -1
  126. package/dist-lib/spec/mesh/hyperdispatch/index.js +35 -1
  127. package/dist-lib/spec/mesh/hyperdispatch/messages.js +223 -10
  128. package/dist-lib/spec/mesh/hyperschema/index.js +223 -10
  129. package/dist-lib/spec/mesh/hyperschema/schema.json +128 -1
  130. package/dist-lib/spec/mesh/hyperschema/types.d.ts +34 -2
  131. package/package.json +14 -19
  132. package/tui/README.md +7 -1
  133. package/tui/app.mjs +366 -78
  134. package/tui/boot.mjs +1 -0
  135. package/tui/index.mjs +1 -0
  136. package/tui/lib/fork-command.mjs +43 -0
  137. package/tui/lib/render.mjs +25 -1
  138. package/worker/assistant-sidecar.mjs +5 -2
  139. package/dist-lib/lib/core/device-invites.d.ts +0 -11
  140. package/dist-lib/lib/core/device-invites.js +0 -63
  141. package/dist-lib/lib/core/grant-expiry.d.ts +0 -11
  142. package/dist-lib/lib/core/grant-expiry.js +0 -66
  143. package/dist-lib/lib/core/mesh-seed-handoff.d.ts +0 -27
  144. package/dist-lib/lib/core/mesh-seed-handoff.js +0 -53
  145. package/dist-lib/lib/oauth/loopback.stub.d.ts +0 -3
  146. package/dist-lib/lib/oauth/loopback.stub.js +0 -6
package/tui/app.mjs CHANGED
@@ -18,6 +18,9 @@ import {
18
18
  MODEL_CONTEXT_TARGET,
19
19
  maxContextForModel
20
20
  } from '../dist-lib/lib/model-context.js'
21
+ import { runChecks } from '../dist-lib/lib/doctor/checks.js'
22
+ import { checkLines, summarize } from '../dist-lib/lib/doctor/render.js'
23
+ import { diagnosticsLines, headerLine } from '../dist-lib/lib/doctor/tree.js'
21
24
  import {
22
25
  busyStatus,
23
26
  findPendingApproval,
@@ -32,6 +35,7 @@ import { center, splash } from './lib/splash.mjs'
32
35
  import { wrapBlock, wrapLine } from './lib/wrap.mjs'
33
36
  import { knowledgeCommand } from './lib/knowledge-command.mjs'
34
37
  import { describeMove } from './lib/move-command.mjs'
38
+ import { forkCut } from './lib/fork-command.mjs'
35
39
  import { saveUniqueFile } from './lib/save-file.mjs'
36
40
  import { usageReport } from './lib/usage.mjs'
37
41
  import { compactionTriggerRatio } from '../dist-lib/lib/compaction.js'
@@ -99,7 +103,7 @@ const COMMANDS = [
99
103
  { name: 'rename', desc: '<name> — rename the active agent' },
100
104
  {
101
105
  name: 'use',
102
- desc: '<name|id> — switch the active agent (same chat; re-targets the next run)'
106
+ desc: '<name|id> — switch the active agent and hand it the open chat'
103
107
  },
104
108
  { name: 'borrow', desc: '[none] — borrow the model from the compute mesh, or stop borrowing' }
105
109
  ]
@@ -121,6 +125,10 @@ const COMMANDS = [
121
125
  { name: 'new', desc: '[title] — create and switch to a new chat' },
122
126
  { name: 'use', desc: '<title|id> — switch to another chat' },
123
127
  { name: 'rename', desc: '<title> — rename this chat' },
128
+ {
129
+ name: 'fork',
130
+ desc: '[turn] [before] — copy this chat, through a turn or before it, into a new one'
131
+ },
124
132
  { name: 'del', desc: '<title|id> — delete a chat' },
125
133
  { name: 'websearch', desc: 'on|off — let this chat search the web' },
126
134
  { name: 'rag', desc: 'on|off — retrieve from this chat’s knowledge' }
@@ -169,7 +177,6 @@ const COMMANDS = [
169
177
  desc: 'browse installed skills; ↑/↓ move, space toggles each on/off',
170
178
  palette: true
171
179
  },
172
- { name: 'tools', desc: 'browse installed tools; ↑/↓ move, space toggles each on/off' },
173
180
  {
174
181
  name: 'skill',
175
182
  desc: 'toggle a single skill on/off',
@@ -178,20 +185,11 @@ const COMMANDS = [
178
185
  { name: 'off', desc: '<name> — disable a skill for this agent (sets scope=selected)' }
179
186
  ]
180
187
  },
181
- {
182
- name: 'tool',
183
- desc: 'toggle a single tool on/off',
184
- sub: [
185
- { name: 'on', desc: '<name> — enable a tool for this agent (sets scope=selected)' },
186
- { name: 'off', desc: '<name> — disable a tool for this agent (sets scope=selected)' }
187
- ]
188
- },
189
188
  {
190
189
  name: 'scope',
191
- desc: 'switch skills/tools scope between all and selected',
190
+ desc: 'switch skills scope between all and selected',
192
191
  sub: [
193
- { name: 'skills', desc: 'all|selected — every installed skill, or only the enabled list' },
194
- { name: 'tools', desc: 'all|selected — every installed tool, or only the enabled list' }
192
+ { name: 'skills', desc: 'all|selected — every installed skill, or only the enabled list' }
195
193
  ]
196
194
  },
197
195
  {
@@ -243,7 +241,8 @@ const COMMANDS = [
243
241
  { name: 'new', desc: '[compute] — open another shared mesh, or lend this device’s model' },
244
242
  { name: 'label', desc: '<n|id> <name> — name a mesh, privately to you' },
245
243
  { name: 'move', desc: '<n|id> [chat] — move this chat, or a named one, into another mesh' },
246
- { name: 'moved', desc: '[chat] — how the last move from this window is going' }
244
+ { name: 'moved', desc: '[chat] — how the last move from this window is going' },
245
+ { name: 'fork', desc: '<n|id> [turn] [before] — copy this chat into another mesh' }
247
246
  ]
248
247
  },
249
248
  { name: 'meshes', desc: 'list the meshes this device belongs to', palette: true },
@@ -253,6 +252,12 @@ const COMMANDS = [
253
252
  name: 'my-device',
254
253
  desc: 'CPU/GPU inventory for this device (manufacturer, cores, drivers, …)'
255
254
  },
255
+ {
256
+ name: 'doctor',
257
+ desc: 'health checks for this device, with secrets redacted for pasting',
258
+ palette: true,
259
+ sub: [{ name: 'debug', desc: 'the raw diagnostics frame behind the checks' }]
260
+ },
256
261
  {
257
262
  name: 'models',
258
263
  desc: 'browse the SDK registry (optional type filter), or check and add your own GGUF',
@@ -373,11 +378,28 @@ export const fg = {
373
378
  cyan: style().foreground('brightcyan'),
374
379
  dim: style().foreground('gray').italic(true),
375
380
  white: style(),
381
+ green: style().foreground('brightgreen'),
376
382
  amber: style().foreground('brightyellow'),
377
383
  magenta: style().foreground('brightmagenta').bold(true),
378
384
  err: style().foreground('brightred')
379
385
  }
380
386
 
387
+ // long enough for the engine's sampler to tick, so flushes/delay can move
388
+ const DOCTOR_SAMPLE_GAP_MS = 1500
389
+
390
+ // the glyph carries the severity and the titles the structure, so only those are coloured
391
+ const DOCTOR_PAINT = {
392
+ pass: fg.green,
393
+ warn: fg.amber,
394
+ fail: fg.err,
395
+ declared: fg.dim,
396
+ pending: fg.dim,
397
+ title: fg.cyan,
398
+ explain: fg.dim
399
+ }
400
+
401
+ const paintDoctor = (text, kind) => (DOCTOR_PAINT[kind] ?? fg.white).render(text)
402
+
381
403
  // an IEEE-float WAV header (format tag 3) so the engine's raw PCM plays in any player
382
404
  export function floatPcmToWav(pcm, sampleRate) {
383
405
  const blockAlign = 4
@@ -740,7 +762,6 @@ export function formatSelector(sel) {
740
762
  return formatContextSizes(sel)
741
763
  }
742
764
 
743
- const title = kind === 'skills' ? 'Skills' : 'Tools'
744
765
  if (!rows.length) {
745
766
  return [fg.dim.render(emptySelector(kind, reason, deviceName))]
746
767
  }
@@ -750,7 +771,7 @@ export function formatSelector(sel) {
750
771
  ? '↑/↓ move · space toggle · enter configure · esc return'
751
772
  : '↑/↓ move · space toggle · esc return'
752
773
  const where = deviceName ? `on ${deviceName}` : 'on this device'
753
- const header = fg.dim.render(`${title} ${where} — scope=${scope} (${rows.length}) — ${hint}`)
774
+ const header = fg.dim.render(`Skills ${where} — scope=${scope} (${rows.length}) — ${hint}`)
754
775
  const lines = rows.map((name, i) => {
755
776
  const point = i === cursor ? fg.magenta.render('❯ ') : ' '
756
777
  const badge = enabled.has(name) ? fg.cyan.render('● on ') : fg.dim.render('○ off')
@@ -1488,10 +1509,8 @@ const AGENT_COMMANDS = new Set([
1488
1509
  'models',
1489
1510
  'activity',
1490
1511
  'skills',
1491
- 'tools',
1492
1512
  'permissions',
1493
1513
  'skill',
1494
- 'tool',
1495
1514
  'scope',
1496
1515
  'connect',
1497
1516
  'cred'
@@ -1506,6 +1525,11 @@ const isOwnDefault = (agent, deviceId) =>
1506
1525
  b4a.equals(agent.providerDeviceId, deviceId)
1507
1526
  const ownDefault = (agents, deviceId) => agents.find((agent) => isOwnDefault(agent, deviceId))
1508
1527
 
1528
+ // deviceInfo carries no model: the recommendation lives on the device's own row in the mesh
1529
+ async function recommendedModel(engine, meshId, deviceId) {
1530
+ return (await engine.getDevice({ meshId, deviceId })).recommendedModelName
1531
+ }
1532
+
1509
1533
  // mints one on timeout: an unbounded wait blocks the composer, and an account may hold no agent
1510
1534
  async function firstAgent(engine, meshId, { deviceId, modelName, remembered, account }) {
1511
1535
  const watch = engine.agentsWatch({ meshId })[Symbol.asyncIterator]()
@@ -1552,7 +1576,7 @@ async function firstAgent(engine, meshId, { deviceId, modelName, remembered, acc
1552
1576
  name: 'QV.AC',
1553
1577
  bio: 'You are a helpful local assistant. Be clear, practical, and concise.',
1554
1578
  providerDeviceId: deviceId,
1555
- modelName: modelName || (await engine.deviceInfo({})).recommendedModelName,
1579
+ modelName: modelName || (await recommendedModel(engine, meshId, deviceId)),
1556
1580
  isDefault: true
1557
1581
  }
1558
1582
  })
@@ -1691,6 +1715,8 @@ export class ChatApp {
1691
1715
  this._customModels = new Map()
1692
1716
  this._pickableFiles = []
1693
1717
  this._statusIterator = null
1718
+ this._downloadsIterator = null
1719
+ this.modelDownloads = new Map()
1694
1720
  this.meshStatus = null // last meshStatusWatch frame — rendered in the header
1695
1721
  this._devicesIterator = null
1696
1722
  this.deviceLabels = new Map() // hex device id → name, from devicesWatch
@@ -1700,6 +1726,8 @@ export class ChatApp {
1700
1726
  this._diagnosticsIterator = null
1701
1727
  this.overlay = null
1702
1728
  this._pinnedOverlay = null
1729
+ // { overlay, text } for ctrl+y, keyed on overlay identity so any other overlay invalidates it
1730
+ this._doctorReport = null
1703
1731
  // apart from `overlay` because its rows respond to ↑/↓ and enter
1704
1732
  this._models = null
1705
1733
  this._selector = null
@@ -1743,6 +1771,7 @@ export class ChatApp {
1743
1771
  _engineWatches() {
1744
1772
  return [
1745
1773
  this._watchNextStatus(),
1774
+ this._watchNextDownloads(),
1746
1775
  this._watchNextDiagnostics(),
1747
1776
  this._watchNextMeshes(),
1748
1777
  this._enterMesh()
@@ -2035,6 +2064,24 @@ export class ChatApp {
2035
2064
  }
2036
2065
  }
2037
2066
 
2067
+ _watchNextDownloads() {
2068
+ const gen = this.gen
2069
+ if (!this._downloadsIterator) {
2070
+ this._downloadsIterator = this.engine.modelDownloadsWatch({})[Symbol.asyncIterator]()
2071
+ }
2072
+
2073
+ const it = this._downloadsIterator
2074
+
2075
+ return async () => {
2076
+ const { value, done } = await it.next()
2077
+ if (done) {
2078
+ return { type: 'model-downloads.done', gen }
2079
+ }
2080
+
2081
+ return { type: 'model-downloads', gen, downloads: value.downloads ?? [] }
2082
+ }
2083
+ }
2084
+
2038
2085
  _setTranscript(chunks) {
2039
2086
  this._turns = turnsFromChunks(chunks)
2040
2087
  this.pendingApproval = findPendingApproval(this._turns)
@@ -2072,7 +2119,11 @@ export class ChatApp {
2072
2119
  if (this.pendingApproval) return null
2073
2120
  if (!this.busy) return null
2074
2121
  const runTurn = runningAgentTurn(this._turns)
2075
- const { text, on } = busyStatus(this.modelState, runTurn, Date.now() - this._busySince)
2122
+ const { text, on } = busyStatus(this.modelState, runTurn, {
2123
+ elapsed: Date.now() - this._busySince,
2124
+ selfId: this.originDeviceId ? b4a.toHex(this.originDeviceId) : '',
2125
+ downloads: this.modelDownloads
2126
+ })
2076
2127
  const where = this._busyDevice(on, runTurn)
2077
2128
 
2078
2129
  return fg.dim.render(`${this.spin.view()} ${text}${where ? ` (on ${where})` : ''}`)
@@ -2236,8 +2287,8 @@ export class ChatApp {
2236
2287
  ' /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',
2237
2288
  " /activity — list the active agent's recent tool calls, each with its decision (allowed/denied/auto/skip-all/blocked)",
2238
2289
  ' /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',
2239
- ' /skills · /tools — browse installed; ↑/↓ move, space toggles each on/off (sets scope=selected), enter sets up or reconfigures the skill, esc returns',
2240
- ' /skill on|off <name> · /tool on|off <name> — toggle (sets scope=selected)',
2290
+ ' /skills — browse installed; ↑/↓ move, space toggles each on/off (sets scope=selected), enter sets up or reconfigures the skill, esc returns',
2291
+ ' /skill on|off <name> — toggle (sets scope=selected)',
2241
2292
  ' /permissions — approval mode + the toolset switches; ↑/↓ move, space toggles',
2242
2293
  ' /models delete <name> · /models download <name> — remove a model from this device, or fetch it now',
2243
2294
  ' /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',
@@ -2257,7 +2308,7 @@ export class ChatApp {
2257
2308
  '',
2258
2309
  'Advanced',
2259
2310
  ' /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',
2260
- ' /scope skills|tools all|selected — switch scope',
2311
+ ' /scope skills all|selected — switch scope',
2261
2312
  ' /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',
2262
2313
  ' /leave — leave the active mesh; the device lands on another mesh it can write to, or mints a fresh account',
2263
2314
  ' /invite - show this mesh device invite · /invite member - open your shared mesh and invite someone into it (your account is never shared)',
@@ -2266,7 +2317,9 @@ export class ChatApp {
2266
2317
  ' /meshes - list the meshes this device belongs to, numbered, marking account / shared / active / open / writable',
2267
2318
  ' /mesh use <n|id> - make one of them active; its agent, chat and roster replace the ones on screen',
2268
2319
  ' /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',
2269
- ' /my-device — dump this device\u2019s CPU/GPU inventory (manufacturer, cores, drivers, …)'
2320
+ ' /my-device — dump this device\u2019s CPU/GPU inventory (manufacturer, cores, drivers, …)',
2321
+ ' /doctor — check this device: hardware, engine, model backends, mesh, network. ctrl+y copies the report, secrets redacted',
2322
+ ' /doctor debug — the raw diagnostics frame behind those checks'
2270
2323
  ].join('\n')
2271
2324
 
2272
2325
  const notice = (t) => [this, async () => ({ type: 'notice', text: t })]
@@ -2336,6 +2389,19 @@ export class ChatApp {
2336
2389
  return this._showDiagnostics()
2337
2390
  }
2338
2391
 
2392
+ if (cmd === 'doctor') {
2393
+ const action = rest[0]?.toLowerCase()
2394
+ if (!action) {
2395
+ return this._runDoctor()
2396
+ }
2397
+
2398
+ if (action === 'debug') {
2399
+ return this._showDoctor()
2400
+ }
2401
+
2402
+ return notice('usage: /doctor [debug] — checks, or the raw diagnostics frame')
2403
+ }
2404
+
2339
2405
  if (cmd === 'usage') {
2340
2406
  if (rawArgs.trim()) {
2341
2407
  return notice('usage: /usage')
@@ -2630,7 +2696,7 @@ export class ChatApp {
2630
2696
  ? ` · model borrowed from ${b4a.toHex(a.lenderDeviceId).slice(0, 8)}`
2631
2697
  : ''
2632
2698
 
2633
- return `agent ${a.name} (${a.id.slice(0, 8)}) · skills=${a.skillsScope ?? 'all'} tools=${a.toolsScope ?? 'all'}${lender}`
2699
+ return `agent ${a.name} (${a.id.slice(0, 8)}) · skills=${a.skillsScope ?? 'all'}${lender}`
2634
2700
  })
2635
2701
  }
2636
2702
 
@@ -2655,13 +2721,15 @@ export class ChatApp {
2655
2721
  name: arg,
2656
2722
  bio: `${arg} — test agent`,
2657
2723
  providerDeviceId: this.originDeviceId,
2658
- modelName: agent?.modelName ?? (await engine.deviceInfo({})).recommendedModelName
2724
+ modelName:
2725
+ agent?.modelName ??
2726
+ this._modelName ??
2727
+ (await recommendedModel(engine, this.meshId, this.originDeviceId))
2659
2728
  }
2660
2729
  })
2661
- this.agent = created
2662
- await this._persistSelection()
2730
+ await this._handChatTo(created)
2663
2731
 
2664
- return `created + selected ${created.name} (${created.id.slice(0, 8)}) · no skills/tools enabled`
2732
+ return `created + selected ${created.name} (${created.id.slice(0, 8)}) · no skills enabled`
2665
2733
  })
2666
2734
  }
2667
2735
 
@@ -2722,8 +2790,7 @@ export class ChatApp {
2722
2790
  return `no agent matching: ${arg}`
2723
2791
  }
2724
2792
 
2725
- this.agent = found
2726
- await this._persistSelection()
2793
+ await this._handChatTo(found)
2727
2794
 
2728
2795
  return `selected ${found.name} (${found.id.slice(0, 8)})`
2729
2796
  })
@@ -2755,7 +2822,7 @@ export class ChatApp {
2755
2822
  })
2756
2823
  }
2757
2824
 
2758
- if (cmd === 'skills' || cmd === 'tools') {
2825
+ if (cmd === 'skills') {
2759
2826
  return this._showSelector(cmd)
2760
2827
  }
2761
2828
 
@@ -2763,18 +2830,15 @@ export class ChatApp {
2763
2830
  return this._showPermissions()
2764
2831
  }
2765
2832
 
2766
- if (cmd === 'skill' || cmd === 'tool') {
2833
+ if (cmd === 'skill') {
2767
2834
  const [action, name] = rest
2768
2835
  if ((action !== 'on' && action !== 'off') || !name) {
2769
- return notice(`usage: /${cmd} on|off <name>`)
2836
+ return notice('usage: /skill on|off <name>')
2770
2837
  }
2771
2838
 
2772
- const field = cmd === 'skill' ? 'enabledSkills' : 'enabledTools'
2773
- const scopeField = cmd === 'skill' ? 'skillsScope' : 'toolsScope'
2774
-
2775
2839
  return run(async () => {
2776
2840
  const fresh = await engine.getAgent({ meshId: this.meshId, agentId: agent.id })
2777
- const set = new Set(fresh[field] ?? [])
2841
+ const set = new Set(fresh.enabledSkills ?? [])
2778
2842
  if (action === 'on') {
2779
2843
  set.add(name)
2780
2844
  } else {
@@ -2784,11 +2848,11 @@ export class ChatApp {
2784
2848
  const updated = await engine.updateAgent({
2785
2849
  meshId: this.meshId,
2786
2850
  agentId: agent.id,
2787
- config: { [field]: [...set], [scopeField]: 'selected' }
2851
+ config: { enabledSkills: [...set], skillsScope: 'selected' }
2788
2852
  })
2789
2853
  this.agent = updated
2790
- const line = `${cmd} ${name} ${action} · ${field}=[${[...set].join(', ')}] scope=selected`
2791
- if (cmd !== 'skill' || action !== 'on') {
2854
+ const line = `skill ${name} ${action} · enabledSkills=[${[...set].join(', ')}] scope=selected`
2855
+ if (action !== 'on') {
2792
2856
  return line
2793
2857
  }
2794
2858
 
@@ -2803,17 +2867,15 @@ export class ChatApp {
2803
2867
 
2804
2868
  if (cmd === 'scope') {
2805
2869
  const [which, value] = rest
2806
- if ((which !== 'skills' && which !== 'tools') || (value !== 'all' && value !== 'selected')) {
2807
- return notice('usage: /scope skills|tools all|selected')
2870
+ if (which !== 'skills' || (value !== 'all' && value !== 'selected')) {
2871
+ return notice('usage: /scope skills all|selected')
2808
2872
  }
2809
2873
 
2810
- const scopeField = which === 'skills' ? 'skillsScope' : 'toolsScope'
2811
-
2812
2874
  return run(async () => {
2813
2875
  const updated = await engine.updateAgent({
2814
2876
  meshId: this.meshId,
2815
2877
  agentId: agent.id,
2816
- config: { [scopeField]: value }
2878
+ config: { skillsScope: value }
2817
2879
  })
2818
2880
  this.agent = updated
2819
2881
 
@@ -3434,8 +3496,12 @@ export class ChatApp {
3434
3496
  return run(() => this._movedChat(target))
3435
3497
  }
3436
3498
 
3499
+ if (action === 'fork' && target) {
3500
+ return run(() => this._forkChatInto(target, labelParts))
3501
+ }
3502
+
3437
3503
  return notice(
3438
- 'usage: /mesh use <n|id> · /mesh new [compute] · /mesh label <n|id> <name> · /mesh move <n|id> [chat] · /mesh moved [chat]'
3504
+ 'usage: /mesh use <n|id> · /mesh new [compute] · /mesh label <n|id> <name> · /mesh move <n|id> [chat] · /mesh moved [chat] · /mesh fork <n|id> [turn] [before]'
3439
3505
  )
3440
3506
  }
3441
3507
 
@@ -3478,6 +3544,10 @@ export class ChatApp {
3478
3544
  return this._deleteChat(arg)
3479
3545
  }
3480
3546
 
3547
+ if (action === 'fork') {
3548
+ return this._forkChat(argParts)
3549
+ }
3550
+
3481
3551
  if (action === 'rename') {
3482
3552
  if (!arg) {
3483
3553
  return notice('usage: /chat rename <title>')
@@ -3510,7 +3580,7 @@ export class ChatApp {
3510
3580
  }
3511
3581
 
3512
3582
  return notice(
3513
- 'usage: /chat [new <title>|use <id>|rename <title>|del <id>|websearch on|off|rag on|off]'
3583
+ 'usage: /chat [new <title>|use <id>|rename <title>|fork [turn] [before]|del <id>|websearch on|off|rag on|off]'
3514
3584
  )
3515
3585
  }
3516
3586
 
@@ -3851,6 +3921,73 @@ export class ChatApp {
3851
3921
  ]
3852
3922
  }
3853
3923
 
3924
+ // the fork opens in this window, since it lands in the mesh this window is on
3925
+ _forkChat(args) {
3926
+ return [
3927
+ this,
3928
+ async () => {
3929
+ try {
3930
+ if (!this.chatId) {
3931
+ return { type: 'notice', text: 'no chat is open' }
3932
+ }
3933
+
3934
+ const cut = await this._forkCutOf(args)
3935
+ if (cut.miss) {
3936
+ return { type: 'notice', text: cut.miss }
3937
+ }
3938
+
3939
+ const chatId = this.chatId
3940
+ const fork = await this.engine.forkChat({ meshId: this.meshId, chatId, ...cut.request })
3941
+ const notice = `forked ${cut.label} into "${fork.title}" (${fork.id.slice(0, 8)})`
3942
+
3943
+ return { type: 'chat.switch', chat: fork, agent: await this._agentFor(fork), notice }
3944
+ } catch (error) {
3945
+ return { type: 'run.error', error }
3946
+ }
3947
+ }
3948
+ ]
3949
+ }
3950
+
3951
+ async _forkCutOf(args) {
3952
+ const { chunks } = await this.engine.listChunks({ meshId: this.meshId, chatId: this.chatId })
3953
+ return forkCut(chunks ?? [], args)
3954
+ }
3955
+
3956
+ // the target's first agent answers it there, as a move picks one; a mesh with none cannot take it
3957
+ async _forkChatInto(selector, args) {
3958
+ const named = await this._resolveMesh(selector)
3959
+ if (named.error) {
3960
+ return named.error
3961
+ }
3962
+
3963
+ if (!this.chatId) {
3964
+ return 'no chat is open'
3965
+ }
3966
+
3967
+ const cut = await this._forkCutOf(args)
3968
+ if (cut.miss) {
3969
+ return cut.miss
3970
+ }
3971
+
3972
+ const { agents } = await this.engine.listAgents({ meshId: named.meshId })
3973
+ if (!agents?.length) {
3974
+ return `${named.meshId.slice(0, 8)} has no agent to answer a fork - /agent new there first`
3975
+ }
3976
+
3977
+ const fork = await this.engine.forkChat({
3978
+ meshId: this.meshId,
3979
+ chatId: this.chatId,
3980
+ targetMeshId: named.meshId,
3981
+ agentId: agents[0].id,
3982
+ ...cut.request
3983
+ })
3984
+ const { meshes } = await this.engine.listMeshes({}).catch(() => ({ meshes: [] }))
3985
+ const index = (meshes ?? []).findIndex((mesh) => mesh.meshId === named.meshId)
3986
+ const where = index < 0 ? '/meshes lists it' : `/mesh use ${index + 1} to open it`
3987
+
3988
+ return `forked ${cut.label} into "${fork.title}" in ${named.meshId.slice(0, 8)} - ${where}`
3989
+ }
3990
+
3854
3991
  _deleteChat(needle) {
3855
3992
  return [
3856
3993
  this,
@@ -3979,6 +4116,20 @@ export class ChatApp {
3979
4116
  }
3980
4117
  }
3981
4118
 
4119
+ // the chat row names its agent, or reopening the chat or another device hands it back to the old one
4120
+ async _handChatTo(agent) {
4121
+ if (this.chatId) {
4122
+ await this.engine.setChatAgent({
4123
+ meshId: this.meshId,
4124
+ chatId: this.chatId,
4125
+ agentId: agent.id
4126
+ })
4127
+ }
4128
+
4129
+ this.agent = agent
4130
+ await this._persistSelection()
4131
+ }
4132
+
3982
4133
  // kept in Core's device-local config, the same record the desktop app resumes from
3983
4134
  async _persistSelection() {
3984
4135
  if (!this.engine.getConfig || !this.agent || !this.chatId) return
@@ -3997,7 +4148,7 @@ export class ChatApp {
3997
4148
  }
3998
4149
  }
3999
4150
 
4000
- _switchTo(chat, agent) {
4151
+ _switchTo(chat, agent, notice) {
4001
4152
  this._resetChatWatches()
4002
4153
  this.chatId = chat.id
4003
4154
  if (agent) {
@@ -4009,7 +4160,7 @@ export class ChatApp {
4009
4160
  this._awaitingRun = false
4010
4161
  this._runningRunId = null
4011
4162
  this.pendingApproval = null
4012
- this.notice = `switched to "${chat.title}" (${chat.id.slice(0, 8)})`
4163
+ this.notice = notice ?? `switched to "${chat.title}" (${chat.id.slice(0, 8)})`
4013
4164
  this._render()
4014
4165
  }
4015
4166
 
@@ -4148,6 +4299,77 @@ export class ChatApp {
4148
4299
  ]
4149
4300
  }
4150
4301
 
4302
+ // every verdict but the deltas answers from one frame, so the report renders before the gap
4303
+ _runDoctor() {
4304
+ const { engine } = this
4305
+ return [
4306
+ this,
4307
+ async () => {
4308
+ try {
4309
+ const first = (await engine.diagnostics({})).stats
4310
+ return { type: 'doctor.checks', samples: { first } }
4311
+ } catch (error) {
4312
+ return { type: 'doctor.checks', error }
4313
+ }
4314
+ }
4315
+ ]
4316
+ }
4317
+
4318
+ // only the movement rows are still open, so this re-renders over the report on screen
4319
+ _settleDoctor(first, overlay) {
4320
+ const { engine } = this
4321
+ return async () => {
4322
+ try {
4323
+ // lunte-disable-next-line qvac/no-sleep -- a sampling interval: the deltas need frames apart
4324
+ await new Promise((resolve) => setTimeout(resolve, DOCTOR_SAMPLE_GAP_MS))
4325
+ const second = (await engine.diagnostics({})).stats
4326
+ return { type: 'doctor.checks', samples: { first, second }, overlay }
4327
+ } catch (error) {
4328
+ return { type: 'doctor.checks', error, overlay }
4329
+ }
4330
+ }
4331
+ }
4332
+
4333
+ // a fresh snapshot, not this.diagnostics: the watch only runs while the footer is live
4334
+ _showDoctor() {
4335
+ const { engine } = this
4336
+ return [
4337
+ this,
4338
+ async () => {
4339
+ try {
4340
+ const { stats } = await engine.diagnostics({})
4341
+ return { type: 'doctor.result', stats }
4342
+ } catch (error) {
4343
+ return { type: 'doctor.result', error }
4344
+ }
4345
+ }
4346
+ ]
4347
+ }
4348
+
4349
+ // null when no doctor report is on screen, so ctrl+y falls through to the invite
4350
+ _copyReport() {
4351
+ const report = this._doctorReport
4352
+ if (!report || report.overlay !== this.overlay || !this._copyToClipboard) {
4353
+ return null
4354
+ }
4355
+
4356
+ const { text } = report
4357
+ const copy = this._copyToClipboard
4358
+ const token = ++this._statusToken
4359
+
4360
+ return [
4361
+ this,
4362
+ async () => {
4363
+ try {
4364
+ await copy(text)
4365
+ return { type: 'transient-status', token, text: 'report copied ✓' }
4366
+ } catch (err) {
4367
+ return { type: 'transient-status', token, text: `copy failed: ${err.message}` }
4368
+ }
4369
+ }
4370
+ ]
4371
+ }
4372
+
4151
4373
  // /usage: the chat's run statuses carry the last run's own numbers; the folds say why they dropped
4152
4374
  _showUsage() {
4153
4375
  const { engine, chatId } = this
@@ -4189,7 +4411,7 @@ export class ChatApp {
4189
4411
  }
4190
4412
 
4191
4413
  // resolved by where the provider is, not by the mesh on screen: a shared mesh carries no inventory
4192
- async _providerCaps(kind, detail) {
4414
+ async _providerCaps(detail) {
4193
4415
  const provider = this.agent?.providerDeviceId
4194
4416
  if (!provider) {
4195
4417
  return { names: [], reason: 'no-provider' }
@@ -4198,24 +4420,19 @@ export class ChatApp {
4198
4420
  // originDeviceId is bound late, so an early selector must ask rather than guess
4199
4421
  const own = this.originDeviceId ?? (await this.engine.deviceInfo({})).id
4200
4422
  if (own && b4a.equals(own, provider)) {
4201
- const names = await this._localCaps(kind, detail)
4423
+ const names = await this._localCaps(detail)
4202
4424
  if (names.length) {
4203
4425
  return { names, reason: null }
4204
4426
  }
4205
4427
 
4206
- // a harness that cannot describe its tools still published its catalog to the account
4207
- return this._rosterCaps(kind, provider, 'none-installed')
4428
+ // a device that resolves no skills locally still published its catalog to the account
4429
+ return this._rosterCaps(provider, 'none-installed')
4208
4430
  }
4209
4431
 
4210
- return this._rosterCaps(kind, provider, 'none-advertised')
4432
+ return this._rosterCaps(provider, 'none-advertised')
4211
4433
  }
4212
4434
 
4213
- async _localCaps(kind, detail) {
4214
- if (kind === 'tools') {
4215
- const { tools } = (await this.engine.tools?.()) ?? { tools: [] }
4216
- return (tools ?? []).map((t) => t.name)
4217
- }
4218
-
4435
+ async _localCaps(detail) {
4219
4436
  // detail is passed in, never re-fetched: it is already this device's resolved skill list
4220
4437
  if (detail) {
4221
4438
  return [...detail.keys()]
@@ -4227,7 +4444,7 @@ export class ChatApp {
4227
4444
  }
4228
4445
 
4229
4446
  // the account may have been closed, so it is named and opened, never assumed
4230
- async _rosterCaps(kind, provider, emptyReason) {
4447
+ async _rosterCaps(provider, emptyReason) {
4231
4448
  const { meshes } = await this.engine.listMeshes({})
4232
4449
  const account = (meshes ?? []).find((m) => m.account)?.meshId
4233
4450
  if (!account) {
@@ -4249,7 +4466,7 @@ export class ChatApp {
4249
4466
  return { names: [], reason: 'removed', deviceName: dev.name }
4250
4467
  }
4251
4468
 
4252
- const names = (kind === 'tools' ? dev.installedToolNames : dev.installedSkillNames) ?? []
4469
+ const names = dev.installedSkillNames ?? []
4253
4470
 
4254
4471
  return { names, reason: names.length ? null : emptyReason, deviceName: dev.name }
4255
4472
  }
@@ -4275,10 +4492,10 @@ export class ChatApp {
4275
4492
  async () => {
4276
4493
  try {
4277
4494
  const fresh = await engine.getAgent({ meshId: this.meshId, agentId: agent.id })
4278
- const scope = (kind === 'skills' ? fresh.skillsScope : fresh.toolsScope) ?? 'selected'
4279
- const enabled = (kind === 'skills' ? fresh.enabledSkills : fresh.enabledTools) ?? []
4280
- const detail = kind === 'skills' ? await this._skillDetail() : null
4281
- const caps = await this._providerCaps(kind, detail)
4495
+ const scope = fresh.skillsScope ?? 'selected'
4496
+ const enabled = fresh.enabledSkills ?? []
4497
+ const detail = await this._skillDetail()
4498
+ const caps = await this._providerCaps(detail)
4282
4499
  const installed = caps.names
4283
4500
  const { reason, deviceName } = caps
4284
4501
  return {
@@ -4463,7 +4680,6 @@ export class ChatApp {
4463
4680
  cursor: 0,
4464
4681
  entries: [
4465
4682
  { label: 'Skills', hint: 'toggle skills on/off', overlay: 'skills' },
4466
- { label: 'Tools', hint: 'toggle tools on/off', overlay: 'tools' },
4467
4683
  { label: 'Permissions', hint: 'approval mode & toolsets', overlay: 'permissions' },
4468
4684
  { label: 'Model', hint: "pick the agent's model", overlay: 'models' },
4469
4685
  {
@@ -4531,8 +4747,7 @@ export class ChatApp {
4531
4747
  cursor: 0,
4532
4748
  entries: [
4533
4749
  { label: 'Set credential…', hint: '/cred <key> <value>', prefill: '/cred ' },
4534
- { label: 'Skills scope…', hint: '/scope skills all|selected', prefill: '/scope skills ' },
4535
- { label: 'Tools scope…', hint: '/scope tools all|selected', prefill: '/scope tools ' }
4750
+ { label: 'Skills scope…', hint: '/scope skills all|selected', prefill: '/scope skills ' }
4536
4751
  ]
4537
4752
  }
4538
4753
  }
@@ -4975,7 +5190,7 @@ export class ChatApp {
4975
5190
  ]
4976
5191
  }
4977
5192
 
4978
- // the same write as /skill|/tool on|off, so any toggle moves the agent to scope=selected
5193
+ // the same write as /skill on|off, so any toggle moves the agent to scope=selected
4979
5194
  _toggleSelector() {
4980
5195
  const s = this._selector
4981
5196
  if (s.kind === 'ctx') {
@@ -4999,8 +5214,6 @@ export class ChatApp {
4999
5214
 
5000
5215
  s.scope = 'selected'
5001
5216
  this._render()
5002
- const field = s.kind === 'skills' ? 'enabledSkills' : 'enabledTools'
5003
- const scopeField = s.kind === 'skills' ? 'skillsScope' : 'toolsScope'
5004
5217
  const enabled = [...s.enabled]
5005
5218
  const { engine, agent } = this
5006
5219
 
@@ -5011,7 +5224,7 @@ export class ChatApp {
5011
5224
  this.agent = await engine.updateAgent({
5012
5225
  meshId: this.meshId,
5013
5226
  agentId: agent.id,
5014
- config: { [field]: enabled, [scopeField]: 'selected' }
5227
+ config: { enabledSkills: enabled, skillsScope: 'selected' }
5015
5228
  })
5016
5229
  return { type: 'selector.saved' }
5017
5230
  } catch (error) {
@@ -5259,7 +5472,7 @@ export class ChatApp {
5259
5472
  return null
5260
5473
  }
5261
5474
 
5262
- // optimistic, like the skills/tools selector: the row moves now, the engine call follows
5475
+ // optimistic, like the skills selector: the row moves now, the engine call follows
5263
5476
  _togglePermission(s, name) {
5264
5477
  if (name === MODE_ROW) {
5265
5478
  s.mode = s.mode === 'skip-all' ? 'ask' : 'skip-all'
@@ -5736,7 +5949,7 @@ export class ChatApp {
5736
5949
  }
5737
5950
 
5738
5951
  if (msg.type === 'chat.switch') {
5739
- this._switchTo(msg.chat, msg.agent)
5952
+ this._switchTo(msg.chat, msg.agent, msg.notice)
5740
5953
  return [this, batch(this._watchNext(), this._watchNextFiles(), this._rememberSelection())]
5741
5954
  }
5742
5955
 
@@ -5905,6 +6118,26 @@ export class ChatApp {
5905
6118
  return [this, this._watchNextStatus()]
5906
6119
  }
5907
6120
 
6121
+ if (msg.type === 'model-downloads') {
6122
+ if (msg.gen !== this.gen) {
6123
+ return [this, null]
6124
+ }
6125
+
6126
+ this.modelDownloads = new Map(msg.downloads.map((row) => [row.name, row]))
6127
+
6128
+ return [this, this._watchNextDownloads()]
6129
+ }
6130
+
6131
+ if (msg.type === 'model-downloads.done') {
6132
+ if (msg.gen !== this.gen) {
6133
+ return [this, null]
6134
+ }
6135
+
6136
+ this.modelDownloads = new Map()
6137
+
6138
+ return [this, null]
6139
+ }
6140
+
5908
6141
  if (msg.type === 'mesh-status.done') {
5909
6142
  if (msg.gen !== this.gen) {
5910
6143
  return [this, null]
@@ -5980,6 +6213,60 @@ export class ChatApp {
5980
6213
  return [this, null]
5981
6214
  }
5982
6215
 
6216
+ if (msg.type === 'doctor.checks') {
6217
+ // a settle pass belongs to the report it started from; esc or another overlay since drops it
6218
+ if (msg.overlay && msg.overlay !== this.overlay) {
6219
+ return [this, null]
6220
+ }
6221
+
6222
+ this._models = null
6223
+ this._selector = null
6224
+ if (msg.error) {
6225
+ this.overlay = [fg.err.render(`/doctor failed: ${msg.error.message}`)]
6226
+ this._render()
6227
+ return [this, null]
6228
+ }
6229
+
6230
+ const { first, second } = msg.samples
6231
+ const checks = runChecks(msg.samples)
6232
+ const head = [headerLine(second ?? first), summarize(checks)]
6233
+ this.overlay = [
6234
+ fg.dim.render('Doctor — ctrl+y copies · /doctor debug for the raw frame · esc to return'),
6235
+ '',
6236
+ ...head,
6237
+ ...checkLines(checks, { paint: paintDoctor })
6238
+ ]
6239
+ // the clipboard gets the same report without escape codes
6240
+ this._doctorReport = {
6241
+ overlay: this.overlay,
6242
+ text: [...head, ...checkLines(checks)].join('\n')
6243
+ }
6244
+ this._render()
6245
+
6246
+ return [this, second === undefined ? this._settleDoctor(first, this.overlay) : null]
6247
+ }
6248
+
6249
+ if (msg.type === 'doctor.result') {
6250
+ this._models = null
6251
+ this._selector = null
6252
+ if (msg.error) {
6253
+ this.overlay = [fg.err.render(`/doctor failed: ${msg.error.message}`)]
6254
+ this._render()
6255
+ return [this, null]
6256
+ }
6257
+
6258
+ const report = diagnosticsLines(msg.stats)
6259
+ this.overlay = [
6260
+ fg.dim.render('Doctor — raw diagnostics — ctrl+y copies · esc to return'),
6261
+ '',
6262
+ ...report
6263
+ ]
6264
+ this._doctorReport = { overlay: this.overlay, text: report.join('\n') }
6265
+ this._render()
6266
+
6267
+ return [this, null]
6268
+ }
6269
+
5983
6270
  if (msg.type === 'usage.result') {
5984
6271
  this._models = null
5985
6272
  this._selector = null
@@ -6236,7 +6523,7 @@ export class ChatApp {
6236
6523
 
6237
6524
  // modifier keys never collide with typing or the y/n approval answers
6238
6525
  if (key.matches(msg, 'ctrl+y')) {
6239
- return this._copyInvite()
6526
+ return this._copyReport() ?? this._copyInvite()
6240
6527
  }
6241
6528
 
6242
6529
  if (key.matches(msg, 'ctrl+v')) {
@@ -6789,7 +7076,8 @@ export class ChatApp {
6789
7076
  }
6790
7077
 
6791
7078
  if (this.overlay) {
6792
- return 'esc: back · ↑/↓: scroll · ctrl+c: quit'
7079
+ const copy = this._doctorReport?.overlay === this.overlay ? ' · ctrl+y: copy report' : ''
7080
+ return `esc: back · ↑/↓: scroll${copy} · ctrl+c: quit`
6793
7081
  }
6794
7082
 
6795
7083
  if (this._menu) {