@qvac/core 0.7.0 → 0.7.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 (74) hide show
  1. package/CHANGELOG.md +80 -1
  2. package/dist-lib/lib/api/chat.d.ts +1 -1
  3. package/dist-lib/lib/api/chat.js +9 -0
  4. package/dist-lib/lib/api/index.d.ts +2 -1
  5. package/dist-lib/lib/api/index.js +2 -1
  6. package/dist-lib/lib/api/network.d.ts +8 -1
  7. package/dist-lib/lib/api/network.js +6 -0
  8. package/dist-lib/lib/assistant/harness.d.ts +2 -0
  9. package/dist-lib/lib/assistant.js +9 -4
  10. package/dist-lib/lib/core/agent.d.ts +2 -0
  11. package/dist-lib/lib/core/agent.js +16 -5
  12. package/dist-lib/lib/core/blind-peers.d.ts +4 -0
  13. package/dist-lib/lib/core/blind-peers.js +1 -0
  14. package/dist-lib/lib/core/chat-copy.d.ts +4 -0
  15. package/dist-lib/lib/core/chat-copy.js +1 -1
  16. package/dist-lib/lib/core/chat-fork.d.ts +21 -0
  17. package/dist-lib/lib/core/chat-fork.js +245 -0
  18. package/dist-lib/lib/core/chat-move.js +1 -4
  19. package/dist-lib/lib/core/chat.d.ts +1 -0
  20. package/dist-lib/lib/core/chat.js +1 -1
  21. package/dist-lib/lib/core/departures.d.ts +5 -1
  22. package/dist-lib/lib/core/departures.js +15 -1
  23. package/dist-lib/lib/core/fs-drives.d.ts +8 -1
  24. package/dist-lib/lib/core/fs-drives.js +47 -15
  25. package/dist-lib/lib/core/harness-loan.d.ts +4 -20
  26. package/dist-lib/lib/core/harness-loan.js +7 -184
  27. package/dist-lib/lib/core/id.d.ts +1 -0
  28. package/dist-lib/lib/core/id.js +3 -0
  29. package/dist-lib/lib/core/mesh.d.ts +3 -2
  30. package/dist-lib/lib/core/mesh.js +11 -1
  31. package/dist-lib/lib/core/migrations/agent-tools-scope.d.ts +2 -0
  32. package/dist-lib/lib/core/migrations/agent-tools-scope.js +24 -0
  33. package/dist-lib/lib/core/migrations/index.js +3 -1
  34. package/dist-lib/lib/core/peer-duplex.d.ts +32 -0
  35. package/dist-lib/lib/core/peer-duplex.js +207 -0
  36. package/dist-lib/lib/core.d.ts +17 -1
  37. package/dist-lib/lib/core.js +183 -10
  38. package/dist-lib/lib/doctor/checks.js +4 -1
  39. package/dist-lib/lib/inference-calls.d.ts +1 -2
  40. package/dist-lib/lib/inference-calls.js +1 -5
  41. package/dist-lib/lib/mesh-scoped-engine.js +3 -0
  42. package/dist-lib/lib/model-download.d.ts +0 -9
  43. package/dist-lib/lib/model-download.js +1 -13
  44. package/dist-lib/lib/persistent-dir.d.ts +1 -0
  45. package/dist-lib/lib/persistent-dir.js +9 -0
  46. package/dist-lib/lib/run-replay.d.ts +1 -2
  47. package/dist-lib/lib/run-replay.js +1 -5
  48. package/dist-lib/lib/test-env.d.ts +1 -0
  49. package/dist-lib/lib/test-env.js +4 -0
  50. package/dist-lib/schema/engine.js +45 -1
  51. package/dist-lib/schema/field-order.js +1 -1
  52. package/dist-lib/schema/qvac.js +10 -1
  53. package/dist-lib/spec/bind.js +14 -0
  54. package/dist-lib/spec/calls.js +3 -0
  55. package/dist-lib/spec/capabilities.d.ts +6 -0
  56. package/dist-lib/spec/hrpc/hrpc.json +39 -0
  57. package/dist-lib/spec/hrpc/index.js +41 -4
  58. package/dist-lib/spec/hrpc/messages.js +1420 -1289
  59. package/dist-lib/spec/hyperschema/index.js +1420 -1289
  60. package/dist-lib/spec/hyperschema/schema.json +102 -0
  61. package/dist-lib/spec/hyperschema/types.d.ts +29 -0
  62. package/dist-lib/spec/mesh/hyperdb/messages.js +295 -248
  63. package/dist-lib/spec/mesh/hyperdispatch/messages.js +45 -5
  64. package/dist-lib/spec/mesh/hyperschema/index.js +45 -5
  65. package/dist-lib/spec/mesh/hyperschema/schema.json +31 -1
  66. package/dist-lib/spec/mesh/hyperschema/types.d.ts +9 -1
  67. package/package.json +10 -7
  68. package/tui/README.md +8 -5
  69. package/tui/app.mjs +151 -67
  70. package/tui/boot.mjs +5 -1
  71. package/tui/index.mjs +2 -1
  72. package/tui/lib/fork-command.mjs +43 -0
  73. package/dist-lib/lib/image-cache-dir.d.ts +0 -1
  74. package/dist-lib/lib/image-cache-dir.js +0 -5
package/tui/app.mjs CHANGED
@@ -35,6 +35,7 @@ import { center, splash } from './lib/splash.mjs'
35
35
  import { wrapBlock, wrapLine } from './lib/wrap.mjs'
36
36
  import { knowledgeCommand } from './lib/knowledge-command.mjs'
37
37
  import { describeMove } from './lib/move-command.mjs'
38
+ import { forkCut } from './lib/fork-command.mjs'
38
39
  import { saveUniqueFile } from './lib/save-file.mjs'
39
40
  import { usageReport } from './lib/usage.mjs'
40
41
  import { compactionTriggerRatio } from '../dist-lib/lib/compaction.js'
@@ -124,6 +125,10 @@ const COMMANDS = [
124
125
  { name: 'new', desc: '[title] — create and switch to a new chat' },
125
126
  { name: 'use', desc: '<title|id> — switch to another chat' },
126
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
+ },
127
132
  { name: 'del', desc: '<title|id> — delete a chat' },
128
133
  { name: 'websearch', desc: 'on|off — let this chat search the web' },
129
134
  { name: 'rag', desc: 'on|off — retrieve from this chat’s knowledge' }
@@ -172,7 +177,6 @@ const COMMANDS = [
172
177
  desc: 'browse installed skills; ↑/↓ move, space toggles each on/off',
173
178
  palette: true
174
179
  },
175
- { name: 'tools', desc: 'browse installed tools; ↑/↓ move, space toggles each on/off' },
176
180
  {
177
181
  name: 'skill',
178
182
  desc: 'toggle a single skill on/off',
@@ -181,20 +185,11 @@ const COMMANDS = [
181
185
  { name: 'off', desc: '<name> — disable a skill for this agent (sets scope=selected)' }
182
186
  ]
183
187
  },
184
- {
185
- name: 'tool',
186
- desc: 'toggle a single tool on/off',
187
- sub: [
188
- { name: 'on', desc: '<name> — enable a tool for this agent (sets scope=selected)' },
189
- { name: 'off', desc: '<name> — disable a tool for this agent (sets scope=selected)' }
190
- ]
191
- },
192
188
  {
193
189
  name: 'scope',
194
- desc: 'switch skills/tools scope between all and selected',
190
+ desc: 'switch skills scope between all and selected',
195
191
  sub: [
196
- { name: 'skills', desc: 'all|selected — every installed skill, or only the enabled list' },
197
- { 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' }
198
193
  ]
199
194
  },
200
195
  {
@@ -236,6 +231,15 @@ const COMMANDS = [
236
231
  ]
237
232
  },
238
233
  { name: 'members', desc: 'list mesh members with their devices grouped', palette: true },
234
+ {
235
+ name: 'rename',
236
+ desc: 'name this device, or yourself across every mesh',
237
+ palette: true,
238
+ sub: [
239
+ { name: 'device', desc: '<name> — name this device; every mesh it is in shows it' },
240
+ { name: 'member', desc: '<name> — name yourself, in every mesh at once' }
241
+ ]
242
+ },
239
243
  // before `meshes`, so a bare /mesh offers the verb first and the list second
240
244
  {
241
245
  name: 'mesh',
@@ -246,7 +250,8 @@ const COMMANDS = [
246
250
  { name: 'new', desc: '[compute] — open another shared mesh, or lend this device’s model' },
247
251
  { name: 'label', desc: '<n|id> <name> — name a mesh, privately to you' },
248
252
  { name: 'move', desc: '<n|id> [chat] — move this chat, or a named one, into another mesh' },
249
- { name: 'moved', desc: '[chat] — how the last move from this window is going' }
253
+ { name: 'moved', desc: '[chat] — how the last move from this window is going' },
254
+ { name: 'fork', desc: '<n|id> [turn] [before] — copy this chat into another mesh' }
250
255
  ]
251
256
  },
252
257
  { name: 'meshes', desc: 'list the meshes this device belongs to', palette: true },
@@ -766,7 +771,6 @@ export function formatSelector(sel) {
766
771
  return formatContextSizes(sel)
767
772
  }
768
773
 
769
- const title = kind === 'skills' ? 'Skills' : 'Tools'
770
774
  if (!rows.length) {
771
775
  return [fg.dim.render(emptySelector(kind, reason, deviceName))]
772
776
  }
@@ -776,7 +780,7 @@ export function formatSelector(sel) {
776
780
  ? '↑/↓ move · space toggle · enter configure · esc return'
777
781
  : '↑/↓ move · space toggle · esc return'
778
782
  const where = deviceName ? `on ${deviceName}` : 'on this device'
779
- const header = fg.dim.render(`${title} ${where} — scope=${scope} (${rows.length}) — ${hint}`)
783
+ const header = fg.dim.render(`Skills ${where} — scope=${scope} (${rows.length}) — ${hint}`)
780
784
  const lines = rows.map((name, i) => {
781
785
  const point = i === cursor ? fg.magenta.render('❯ ') : ' '
782
786
  const badge = enabled.has(name) ? fg.cyan.render('● on ') : fg.dim.render('○ off')
@@ -1514,10 +1518,8 @@ const AGENT_COMMANDS = new Set([
1514
1518
  'models',
1515
1519
  'activity',
1516
1520
  'skills',
1517
- 'tools',
1518
1521
  'permissions',
1519
1522
  'skill',
1520
- 'tool',
1521
1523
  'scope',
1522
1524
  'connect',
1523
1525
  'cred'
@@ -2294,8 +2296,8 @@ export class ChatApp {
2294
2296
  ' /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',
2295
2297
  " /activity — list the active agent's recent tool calls, each with its decision (allowed/denied/auto/skip-all/blocked)",
2296
2298
  ' /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',
2297
- ' /skills · /tools — browse installed; ↑/↓ move, space toggles each on/off (sets scope=selected), enter sets up or reconfigures the skill, esc returns',
2298
- ' /skill on|off <name> · /tool on|off <name> — toggle (sets scope=selected)',
2299
+ ' /skills — browse installed; ↑/↓ move, space toggles each on/off (sets scope=selected), enter sets up or reconfigures the skill, esc returns',
2300
+ ' /skill on|off <name> — toggle (sets scope=selected)',
2299
2301
  ' /permissions — approval mode + the toolset switches; ↑/↓ move, space toggles',
2300
2302
  ' /models delete <name> · /models download <name> — remove a model from this device, or fetch it now',
2301
2303
  ' /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',
@@ -2315,12 +2317,13 @@ export class ChatApp {
2315
2317
  '',
2316
2318
  'Advanced',
2317
2319
  ' /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',
2318
- ' /scope skills|tools all|selected — switch scope',
2320
+ ' /scope skills all|selected — switch scope',
2319
2321
  ' /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',
2320
2322
  ' /leave — leave the active mesh; the device lands on another mesh it can write to, or mints a fresh account',
2321
2323
  ' /invite - show this mesh device invite · /invite member - open your shared mesh and invite someone into it (your account is never shared)',
2322
2324
  ' /mesh new - open another shared mesh · /mesh new compute - lend this device · /mesh label <n|id> <name> - name a mesh, privately to you',
2323
2325
  ' /members — list mesh members with their devices grouped',
2326
+ ' /rename device <name> — name this device · /rename member <name> — name yourself, across every mesh',
2324
2327
  ' /meshes - list the meshes this device belongs to, numbered, marking account / shared / active / open / writable',
2325
2328
  ' /mesh use <n|id> - make one of them active; its agent, chat and roster replace the ones on screen',
2326
2329
  ' /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',
@@ -2703,7 +2706,7 @@ export class ChatApp {
2703
2706
  ? ` · model borrowed from ${b4a.toHex(a.lenderDeviceId).slice(0, 8)}`
2704
2707
  : ''
2705
2708
 
2706
- return `agent ${a.name} (${a.id.slice(0, 8)}) · skills=${a.skillsScope ?? 'all'} tools=${a.toolsScope ?? 'all'}${lender}`
2709
+ return `agent ${a.name} (${a.id.slice(0, 8)}) · skills=${a.skillsScope ?? 'all'}${lender}`
2707
2710
  })
2708
2711
  }
2709
2712
 
@@ -2736,7 +2739,7 @@ export class ChatApp {
2736
2739
  })
2737
2740
  await this._handChatTo(created)
2738
2741
 
2739
- return `created + selected ${created.name} (${created.id.slice(0, 8)}) · no skills/tools enabled`
2742
+ return `created + selected ${created.name} (${created.id.slice(0, 8)}) · no skills enabled`
2740
2743
  })
2741
2744
  }
2742
2745
 
@@ -2829,7 +2832,7 @@ export class ChatApp {
2829
2832
  })
2830
2833
  }
2831
2834
 
2832
- if (cmd === 'skills' || cmd === 'tools') {
2835
+ if (cmd === 'skills') {
2833
2836
  return this._showSelector(cmd)
2834
2837
  }
2835
2838
 
@@ -2837,18 +2840,15 @@ export class ChatApp {
2837
2840
  return this._showPermissions()
2838
2841
  }
2839
2842
 
2840
- if (cmd === 'skill' || cmd === 'tool') {
2843
+ if (cmd === 'skill') {
2841
2844
  const [action, name] = rest
2842
2845
  if ((action !== 'on' && action !== 'off') || !name) {
2843
- return notice(`usage: /${cmd} on|off <name>`)
2846
+ return notice('usage: /skill on|off <name>')
2844
2847
  }
2845
2848
 
2846
- const field = cmd === 'skill' ? 'enabledSkills' : 'enabledTools'
2847
- const scopeField = cmd === 'skill' ? 'skillsScope' : 'toolsScope'
2848
-
2849
2849
  return run(async () => {
2850
2850
  const fresh = await engine.getAgent({ meshId: this.meshId, agentId: agent.id })
2851
- const set = new Set(fresh[field] ?? [])
2851
+ const set = new Set(fresh.enabledSkills ?? [])
2852
2852
  if (action === 'on') {
2853
2853
  set.add(name)
2854
2854
  } else {
@@ -2858,11 +2858,11 @@ export class ChatApp {
2858
2858
  const updated = await engine.updateAgent({
2859
2859
  meshId: this.meshId,
2860
2860
  agentId: agent.id,
2861
- config: { [field]: [...set], [scopeField]: 'selected' }
2861
+ config: { enabledSkills: [...set], skillsScope: 'selected' }
2862
2862
  })
2863
2863
  this.agent = updated
2864
- const line = `${cmd} ${name} ${action} · ${field}=[${[...set].join(', ')}] scope=selected`
2865
- if (cmd !== 'skill' || action !== 'on') {
2864
+ const line = `skill ${name} ${action} · enabledSkills=[${[...set].join(', ')}] scope=selected`
2865
+ if (action !== 'on') {
2866
2866
  return line
2867
2867
  }
2868
2868
 
@@ -2877,17 +2877,15 @@ export class ChatApp {
2877
2877
 
2878
2878
  if (cmd === 'scope') {
2879
2879
  const [which, value] = rest
2880
- if ((which !== 'skills' && which !== 'tools') || (value !== 'all' && value !== 'selected')) {
2881
- return notice('usage: /scope skills|tools all|selected')
2880
+ if (which !== 'skills' || (value !== 'all' && value !== 'selected')) {
2881
+ return notice('usage: /scope skills all|selected')
2882
2882
  }
2883
2883
 
2884
- const scopeField = which === 'skills' ? 'skillsScope' : 'toolsScope'
2885
-
2886
2884
  return run(async () => {
2887
2885
  const updated = await engine.updateAgent({
2888
2886
  meshId: this.meshId,
2889
2887
  agentId: agent.id,
2890
- config: { [scopeField]: value }
2888
+ config: { skillsScope: value }
2891
2889
  })
2892
2890
  this.agent = updated
2893
2891
 
@@ -3459,6 +3457,26 @@ export class ChatApp {
3459
3457
  })
3460
3458
  }
3461
3459
 
3460
+ if (cmd === 'rename') {
3461
+ const [action, ...nameParts] = rest
3462
+ const name = nameParts.join(' ')
3463
+ if (!name || (action !== 'device' && action !== 'member')) {
3464
+ return notice('usage: /rename device <name> · /rename member <name>')
3465
+ }
3466
+
3467
+ return run(async () => {
3468
+ if (action === 'device') {
3469
+ await engine.renameDevice({ meshId: this.meshId, config: { name } })
3470
+
3471
+ return `this device is now "${name}"`
3472
+ }
3473
+
3474
+ await engine.updateMember({ config: { name } })
3475
+
3476
+ return `you are now "${name}" in every mesh`
3477
+ })
3478
+ }
3479
+
3462
3480
  if (cmd === 'meshes') {
3463
3481
  return run(async () => {
3464
3482
  const { meshes } = await engine.listMeshes({})
@@ -3508,8 +3526,12 @@ export class ChatApp {
3508
3526
  return run(() => this._movedChat(target))
3509
3527
  }
3510
3528
 
3529
+ if (action === 'fork' && target) {
3530
+ return run(() => this._forkChatInto(target, labelParts))
3531
+ }
3532
+
3511
3533
  return notice(
3512
- 'usage: /mesh use <n|id> · /mesh new [compute] · /mesh label <n|id> <name> · /mesh move <n|id> [chat] · /mesh moved [chat]'
3534
+ '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]'
3513
3535
  )
3514
3536
  }
3515
3537
 
@@ -3552,6 +3574,10 @@ export class ChatApp {
3552
3574
  return this._deleteChat(arg)
3553
3575
  }
3554
3576
 
3577
+ if (action === 'fork') {
3578
+ return this._forkChat(argParts)
3579
+ }
3580
+
3555
3581
  if (action === 'rename') {
3556
3582
  if (!arg) {
3557
3583
  return notice('usage: /chat rename <title>')
@@ -3584,7 +3610,7 @@ export class ChatApp {
3584
3610
  }
3585
3611
 
3586
3612
  return notice(
3587
- 'usage: /chat [new <title>|use <id>|rename <title>|del <id>|websearch on|off|rag on|off]'
3613
+ 'usage: /chat [new <title>|use <id>|rename <title>|fork [turn] [before]|del <id>|websearch on|off|rag on|off]'
3588
3614
  )
3589
3615
  }
3590
3616
 
@@ -3925,6 +3951,73 @@ export class ChatApp {
3925
3951
  ]
3926
3952
  }
3927
3953
 
3954
+ // the fork opens in this window, since it lands in the mesh this window is on
3955
+ _forkChat(args) {
3956
+ return [
3957
+ this,
3958
+ async () => {
3959
+ try {
3960
+ if (!this.chatId) {
3961
+ return { type: 'notice', text: 'no chat is open' }
3962
+ }
3963
+
3964
+ const cut = await this._forkCutOf(args)
3965
+ if (cut.miss) {
3966
+ return { type: 'notice', text: cut.miss }
3967
+ }
3968
+
3969
+ const chatId = this.chatId
3970
+ const fork = await this.engine.forkChat({ meshId: this.meshId, chatId, ...cut.request })
3971
+ const notice = `forked ${cut.label} into "${fork.title}" (${fork.id.slice(0, 8)})`
3972
+
3973
+ return { type: 'chat.switch', chat: fork, agent: await this._agentFor(fork), notice }
3974
+ } catch (error) {
3975
+ return { type: 'run.error', error }
3976
+ }
3977
+ }
3978
+ ]
3979
+ }
3980
+
3981
+ async _forkCutOf(args) {
3982
+ const { chunks } = await this.engine.listChunks({ meshId: this.meshId, chatId: this.chatId })
3983
+ return forkCut(chunks ?? [], args)
3984
+ }
3985
+
3986
+ // the target's first agent answers it there, as a move picks one; a mesh with none cannot take it
3987
+ async _forkChatInto(selector, args) {
3988
+ const named = await this._resolveMesh(selector)
3989
+ if (named.error) {
3990
+ return named.error
3991
+ }
3992
+
3993
+ if (!this.chatId) {
3994
+ return 'no chat is open'
3995
+ }
3996
+
3997
+ const cut = await this._forkCutOf(args)
3998
+ if (cut.miss) {
3999
+ return cut.miss
4000
+ }
4001
+
4002
+ const { agents } = await this.engine.listAgents({ meshId: named.meshId })
4003
+ if (!agents?.length) {
4004
+ return `${named.meshId.slice(0, 8)} has no agent to answer a fork - /agent new there first`
4005
+ }
4006
+
4007
+ const fork = await this.engine.forkChat({
4008
+ meshId: this.meshId,
4009
+ chatId: this.chatId,
4010
+ targetMeshId: named.meshId,
4011
+ agentId: agents[0].id,
4012
+ ...cut.request
4013
+ })
4014
+ const { meshes } = await this.engine.listMeshes({}).catch(() => ({ meshes: [] }))
4015
+ const index = (meshes ?? []).findIndex((mesh) => mesh.meshId === named.meshId)
4016
+ const where = index < 0 ? '/meshes lists it' : `/mesh use ${index + 1} to open it`
4017
+
4018
+ return `forked ${cut.label} into "${fork.title}" in ${named.meshId.slice(0, 8)} - ${where}`
4019
+ }
4020
+
3928
4021
  _deleteChat(needle) {
3929
4022
  return [
3930
4023
  this,
@@ -4085,7 +4178,7 @@ export class ChatApp {
4085
4178
  }
4086
4179
  }
4087
4180
 
4088
- _switchTo(chat, agent) {
4181
+ _switchTo(chat, agent, notice) {
4089
4182
  this._resetChatWatches()
4090
4183
  this.chatId = chat.id
4091
4184
  if (agent) {
@@ -4097,7 +4190,7 @@ export class ChatApp {
4097
4190
  this._awaitingRun = false
4098
4191
  this._runningRunId = null
4099
4192
  this.pendingApproval = null
4100
- this.notice = `switched to "${chat.title}" (${chat.id.slice(0, 8)})`
4193
+ this.notice = notice ?? `switched to "${chat.title}" (${chat.id.slice(0, 8)})`
4101
4194
  this._render()
4102
4195
  }
4103
4196
 
@@ -4348,7 +4441,7 @@ export class ChatApp {
4348
4441
  }
4349
4442
 
4350
4443
  // resolved by where the provider is, not by the mesh on screen: a shared mesh carries no inventory
4351
- async _providerCaps(kind, detail) {
4444
+ async _providerCaps(detail) {
4352
4445
  const provider = this.agent?.providerDeviceId
4353
4446
  if (!provider) {
4354
4447
  return { names: [], reason: 'no-provider' }
@@ -4357,24 +4450,19 @@ export class ChatApp {
4357
4450
  // originDeviceId is bound late, so an early selector must ask rather than guess
4358
4451
  const own = this.originDeviceId ?? (await this.engine.deviceInfo({})).id
4359
4452
  if (own && b4a.equals(own, provider)) {
4360
- const names = await this._localCaps(kind, detail)
4453
+ const names = await this._localCaps(detail)
4361
4454
  if (names.length) {
4362
4455
  return { names, reason: null }
4363
4456
  }
4364
4457
 
4365
- // a harness that cannot describe its tools still published its catalog to the account
4366
- return this._rosterCaps(kind, provider, 'none-installed')
4458
+ // a device that resolves no skills locally still published its catalog to the account
4459
+ return this._rosterCaps(provider, 'none-installed')
4367
4460
  }
4368
4461
 
4369
- return this._rosterCaps(kind, provider, 'none-advertised')
4462
+ return this._rosterCaps(provider, 'none-advertised')
4370
4463
  }
4371
4464
 
4372
- async _localCaps(kind, detail) {
4373
- if (kind === 'tools') {
4374
- const { tools } = (await this.engine.tools?.()) ?? { tools: [] }
4375
- return (tools ?? []).map((t) => t.name)
4376
- }
4377
-
4465
+ async _localCaps(detail) {
4378
4466
  // detail is passed in, never re-fetched: it is already this device's resolved skill list
4379
4467
  if (detail) {
4380
4468
  return [...detail.keys()]
@@ -4386,7 +4474,7 @@ export class ChatApp {
4386
4474
  }
4387
4475
 
4388
4476
  // the account may have been closed, so it is named and opened, never assumed
4389
- async _rosterCaps(kind, provider, emptyReason) {
4477
+ async _rosterCaps(provider, emptyReason) {
4390
4478
  const { meshes } = await this.engine.listMeshes({})
4391
4479
  const account = (meshes ?? []).find((m) => m.account)?.meshId
4392
4480
  if (!account) {
@@ -4408,7 +4496,7 @@ export class ChatApp {
4408
4496
  return { names: [], reason: 'removed', deviceName: dev.name }
4409
4497
  }
4410
4498
 
4411
- const names = (kind === 'tools' ? dev.installedToolNames : dev.installedSkillNames) ?? []
4499
+ const names = dev.installedSkillNames ?? []
4412
4500
 
4413
4501
  return { names, reason: names.length ? null : emptyReason, deviceName: dev.name }
4414
4502
  }
@@ -4434,10 +4522,10 @@ export class ChatApp {
4434
4522
  async () => {
4435
4523
  try {
4436
4524
  const fresh = await engine.getAgent({ meshId: this.meshId, agentId: agent.id })
4437
- const scope = (kind === 'skills' ? fresh.skillsScope : fresh.toolsScope) ?? 'selected'
4438
- const enabled = (kind === 'skills' ? fresh.enabledSkills : fresh.enabledTools) ?? []
4439
- const detail = kind === 'skills' ? await this._skillDetail() : null
4440
- const caps = await this._providerCaps(kind, detail)
4525
+ const scope = fresh.skillsScope ?? 'selected'
4526
+ const enabled = fresh.enabledSkills ?? []
4527
+ const detail = await this._skillDetail()
4528
+ const caps = await this._providerCaps(detail)
4441
4529
  const installed = caps.names
4442
4530
  const { reason, deviceName } = caps
4443
4531
  return {
@@ -4622,7 +4710,6 @@ export class ChatApp {
4622
4710
  cursor: 0,
4623
4711
  entries: [
4624
4712
  { label: 'Skills', hint: 'toggle skills on/off', overlay: 'skills' },
4625
- { label: 'Tools', hint: 'toggle tools on/off', overlay: 'tools' },
4626
4713
  { label: 'Permissions', hint: 'approval mode & toolsets', overlay: 'permissions' },
4627
4714
  { label: 'Model', hint: "pick the agent's model", overlay: 'models' },
4628
4715
  {
@@ -4690,8 +4777,7 @@ export class ChatApp {
4690
4777
  cursor: 0,
4691
4778
  entries: [
4692
4779
  { label: 'Set credential…', hint: '/cred <key> <value>', prefill: '/cred ' },
4693
- { label: 'Skills scope…', hint: '/scope skills all|selected', prefill: '/scope skills ' },
4694
- { label: 'Tools scope…', hint: '/scope tools all|selected', prefill: '/scope tools ' }
4780
+ { label: 'Skills scope…', hint: '/scope skills all|selected', prefill: '/scope skills ' }
4695
4781
  ]
4696
4782
  }
4697
4783
  }
@@ -5134,7 +5220,7 @@ export class ChatApp {
5134
5220
  ]
5135
5221
  }
5136
5222
 
5137
- // the same write as /skill|/tool on|off, so any toggle moves the agent to scope=selected
5223
+ // the same write as /skill on|off, so any toggle moves the agent to scope=selected
5138
5224
  _toggleSelector() {
5139
5225
  const s = this._selector
5140
5226
  if (s.kind === 'ctx') {
@@ -5158,8 +5244,6 @@ export class ChatApp {
5158
5244
 
5159
5245
  s.scope = 'selected'
5160
5246
  this._render()
5161
- const field = s.kind === 'skills' ? 'enabledSkills' : 'enabledTools'
5162
- const scopeField = s.kind === 'skills' ? 'skillsScope' : 'toolsScope'
5163
5247
  const enabled = [...s.enabled]
5164
5248
  const { engine, agent } = this
5165
5249
 
@@ -5170,7 +5254,7 @@ export class ChatApp {
5170
5254
  this.agent = await engine.updateAgent({
5171
5255
  meshId: this.meshId,
5172
5256
  agentId: agent.id,
5173
- config: { [field]: enabled, [scopeField]: 'selected' }
5257
+ config: { enabledSkills: enabled, skillsScope: 'selected' }
5174
5258
  })
5175
5259
  return { type: 'selector.saved' }
5176
5260
  } catch (error) {
@@ -5418,7 +5502,7 @@ export class ChatApp {
5418
5502
  return null
5419
5503
  }
5420
5504
 
5421
- // optimistic, like the skills/tools selector: the row moves now, the engine call follows
5505
+ // optimistic, like the skills selector: the row moves now, the engine call follows
5422
5506
  _togglePermission(s, name) {
5423
5507
  if (name === MODE_ROW) {
5424
5508
  s.mode = s.mode === 'skip-all' ? 'ask' : 'skip-all'
@@ -5895,7 +5979,7 @@ export class ChatApp {
5895
5979
  }
5896
5980
 
5897
5981
  if (msg.type === 'chat.switch') {
5898
- this._switchTo(msg.chat, msg.agent)
5982
+ this._switchTo(msg.chat, msg.agent, msg.notice)
5899
5983
  return [this, batch(this._watchNext(), this._watchNextFiles(), this._rememberSelection())]
5900
5984
  }
5901
5985
 
package/tui/boot.mjs CHANGED
@@ -40,7 +40,7 @@ async function startSidecar({ entry, config, logger }) {
40
40
  }
41
41
  }
42
42
 
43
- // joining a mesh is /join inside the app: the engine takes an invite live, so it is never a flag
43
+ // --join is the headless way in, /join the interactive one; both hand the engine the invite live
44
44
  export async function boot(args) {
45
45
  const connectStart = Date.now()
46
46
  // only an explicit QVAC_MODEL overrides, or resuming a shared mesh rewrites the desktop's agent
@@ -95,6 +95,10 @@ export async function boot(args) {
95
95
  })
96
96
  // the device id is its public key: the raw 32-byte buffer end to end, never a hex string
97
97
  const deviceId = (await engine.deviceInfo({})).id
98
+ if (args.join) {
99
+ await engine.joinMesh({ invite: args.join })
100
+ }
101
+
98
102
  const meshInvite = (await engine.meshInvite({})).invite ?? null
99
103
 
100
104
  return {
package/tui/index.mjs CHANGED
@@ -12,7 +12,8 @@ const cmd = command(
12
12
  ),
13
13
  flag('--storage|-s [dir]', 'a self-contained root, its own corestore and SDK home'),
14
14
  flag('--temp', 'the same, in a throwaway dir'),
15
- flag('--headless', 'no TUI: print the mesh invite and stream logs until ctrl+C'),
15
+ flag('--headless', 'no TUI: print the device invite and stream logs until ctrl+C'),
16
+ flag('--join|-j <invite>', 'join this invite at boot'),
16
17
  flag('--fake-models', 'adds the quack model: a deterministic fake LLM for testing without AI'),
17
18
  flag('--version|-v', 'versions of core, harness and the SDK')
18
19
  )
@@ -0,0 +1,43 @@
1
+ export const FORK_USAGE = 'usage: /chat fork [turn] [before] · /mesh fork <n|id> [turn] [before]'
2
+
3
+ // `[turn] [before]` to a forkChat cut: turn n is the n-th message, through its answer or before it
4
+ export function forkCut(chunks, args) {
5
+ const [turn, mode, ...extra] = args
6
+ if (!turn) {
7
+ return { request: {}, label: 'every finished turn' }
8
+ }
9
+
10
+ const n = Number(turn)
11
+ if (!Number.isInteger(n) || n < 1 || (mode && mode !== 'before') || extra.length > 0) {
12
+ return { miss: FORK_USAGE }
13
+ }
14
+
15
+ const before = mode === 'before'
16
+ const runId = turnRunId(chunks, { n, before })
17
+ if (!runId) {
18
+ return { miss: `turn ${n} has no answer to fork at` }
19
+ }
20
+
21
+ return {
22
+ request: { runId, exclusive: before },
23
+ label: before ? `everything before turn ${n}` : `through turn ${n}`
24
+ }
25
+ }
26
+
27
+ // a retry answers the same message again, so `through` takes its last answer and `before` its first
28
+ function turnRunId(chunks, { n, before }) {
29
+ const messages = chunks.filter((chunk) => chunk.type === 'user-message' && !chunk.runId)
30
+ const message = messages[n - 1]
31
+ if (!message) {
32
+ return null
33
+ }
34
+
35
+ const next = messages[n]?.seq ?? Infinity
36
+ const answers = chunks.filter(
37
+ (chunk) =>
38
+ chunk.type === 'run-request' && chunk.seq > message.seq && chunk.seq < next && chunk.runId
39
+ )
40
+ const answer = before ? answers[0] : answers.at(-1)
41
+
42
+ return answer?.runId ?? null
43
+ }
@@ -1 +0,0 @@
1
- export declare function defaultImageCacheDir(): string;
@@ -1,5 +0,0 @@
1
- import { persistent } from 'bare-storage';
2
- import { join } from 'path';
3
- export function defaultImageCacheDir() {
4
- return join(persistent(), 'qvac', 'image-cache');
5
- }