@qvac/core 0.7.0 → 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 (61) hide show
  1. package/CHANGELOG.md +67 -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 +5 -0
  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/mesh-scoped-engine.js +3 -0
  40. package/dist-lib/lib/model-download.d.ts +0 -9
  41. package/dist-lib/lib/model-download.js +1 -13
  42. package/dist-lib/schema/engine.js +45 -1
  43. package/dist-lib/schema/field-order.js +1 -1
  44. package/dist-lib/schema/qvac.js +10 -1
  45. package/dist-lib/spec/bind.js +14 -0
  46. package/dist-lib/spec/calls.js +3 -0
  47. package/dist-lib/spec/capabilities.d.ts +6 -0
  48. package/dist-lib/spec/hrpc/hrpc.json +39 -0
  49. package/dist-lib/spec/hrpc/index.js +41 -4
  50. package/dist-lib/spec/hrpc/messages.js +1420 -1289
  51. package/dist-lib/spec/hyperschema/index.js +1420 -1289
  52. package/dist-lib/spec/hyperschema/schema.json +102 -0
  53. package/dist-lib/spec/hyperschema/types.d.ts +29 -0
  54. package/dist-lib/spec/mesh/hyperdb/messages.js +295 -248
  55. package/dist-lib/spec/mesh/hyperdispatch/messages.js +45 -5
  56. package/dist-lib/spec/mesh/hyperschema/index.js +45 -5
  57. package/dist-lib/spec/mesh/hyperschema/schema.json +31 -1
  58. package/dist-lib/spec/mesh/hyperschema/types.d.ts +9 -1
  59. package/package.json +9 -6
  60. package/tui/app.mjs +121 -67
  61. package/tui/lib/fork-command.mjs +43 -0
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
  {
@@ -246,7 +241,8 @@ const COMMANDS = [
246
241
  { name: 'new', desc: '[compute] — open another shared mesh, or lend this device’s model' },
247
242
  { name: 'label', desc: '<n|id> <name> — name a mesh, privately to you' },
248
243
  { 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' }
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' }
250
246
  ]
251
247
  },
252
248
  { name: 'meshes', desc: 'list the meshes this device belongs to', palette: true },
@@ -766,7 +762,6 @@ export function formatSelector(sel) {
766
762
  return formatContextSizes(sel)
767
763
  }
768
764
 
769
- const title = kind === 'skills' ? 'Skills' : 'Tools'
770
765
  if (!rows.length) {
771
766
  return [fg.dim.render(emptySelector(kind, reason, deviceName))]
772
767
  }
@@ -776,7 +771,7 @@ export function formatSelector(sel) {
776
771
  ? '↑/↓ move · space toggle · enter configure · esc return'
777
772
  : '↑/↓ move · space toggle · esc return'
778
773
  const where = deviceName ? `on ${deviceName}` : 'on this device'
779
- 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}`)
780
775
  const lines = rows.map((name, i) => {
781
776
  const point = i === cursor ? fg.magenta.render('❯ ') : ' '
782
777
  const badge = enabled.has(name) ? fg.cyan.render('● on ') : fg.dim.render('○ off')
@@ -1514,10 +1509,8 @@ const AGENT_COMMANDS = new Set([
1514
1509
  'models',
1515
1510
  'activity',
1516
1511
  'skills',
1517
- 'tools',
1518
1512
  'permissions',
1519
1513
  'skill',
1520
- 'tool',
1521
1514
  'scope',
1522
1515
  'connect',
1523
1516
  'cred'
@@ -2294,8 +2287,8 @@ export class ChatApp {
2294
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',
2295
2288
  " /activity — list the active agent's recent tool calls, each with its decision (allowed/denied/auto/skip-all/blocked)",
2296
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',
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)',
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)',
2299
2292
  ' /permissions — approval mode + the toolset switches; ↑/↓ move, space toggles',
2300
2293
  ' /models delete <name> · /models download <name> — remove a model from this device, or fetch it now',
2301
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',
@@ -2315,7 +2308,7 @@ export class ChatApp {
2315
2308
  '',
2316
2309
  'Advanced',
2317
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',
2318
- ' /scope skills|tools all|selected — switch scope',
2311
+ ' /scope skills all|selected — switch scope',
2319
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',
2320
2313
  ' /leave — leave the active mesh; the device lands on another mesh it can write to, or mints a fresh account',
2321
2314
  ' /invite - show this mesh device invite · /invite member - open your shared mesh and invite someone into it (your account is never shared)',
@@ -2703,7 +2696,7 @@ export class ChatApp {
2703
2696
  ? ` · model borrowed from ${b4a.toHex(a.lenderDeviceId).slice(0, 8)}`
2704
2697
  : ''
2705
2698
 
2706
- 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}`
2707
2700
  })
2708
2701
  }
2709
2702
 
@@ -2736,7 +2729,7 @@ export class ChatApp {
2736
2729
  })
2737
2730
  await this._handChatTo(created)
2738
2731
 
2739
- 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`
2740
2733
  })
2741
2734
  }
2742
2735
 
@@ -2829,7 +2822,7 @@ export class ChatApp {
2829
2822
  })
2830
2823
  }
2831
2824
 
2832
- if (cmd === 'skills' || cmd === 'tools') {
2825
+ if (cmd === 'skills') {
2833
2826
  return this._showSelector(cmd)
2834
2827
  }
2835
2828
 
@@ -2837,18 +2830,15 @@ export class ChatApp {
2837
2830
  return this._showPermissions()
2838
2831
  }
2839
2832
 
2840
- if (cmd === 'skill' || cmd === 'tool') {
2833
+ if (cmd === 'skill') {
2841
2834
  const [action, name] = rest
2842
2835
  if ((action !== 'on' && action !== 'off') || !name) {
2843
- return notice(`usage: /${cmd} on|off <name>`)
2836
+ return notice('usage: /skill on|off <name>')
2844
2837
  }
2845
2838
 
2846
- const field = cmd === 'skill' ? 'enabledSkills' : 'enabledTools'
2847
- const scopeField = cmd === 'skill' ? 'skillsScope' : 'toolsScope'
2848
-
2849
2839
  return run(async () => {
2850
2840
  const fresh = await engine.getAgent({ meshId: this.meshId, agentId: agent.id })
2851
- const set = new Set(fresh[field] ?? [])
2841
+ const set = new Set(fresh.enabledSkills ?? [])
2852
2842
  if (action === 'on') {
2853
2843
  set.add(name)
2854
2844
  } else {
@@ -2858,11 +2848,11 @@ export class ChatApp {
2858
2848
  const updated = await engine.updateAgent({
2859
2849
  meshId: this.meshId,
2860
2850
  agentId: agent.id,
2861
- config: { [field]: [...set], [scopeField]: 'selected' }
2851
+ config: { enabledSkills: [...set], skillsScope: 'selected' }
2862
2852
  })
2863
2853
  this.agent = updated
2864
- const line = `${cmd} ${name} ${action} · ${field}=[${[...set].join(', ')}] scope=selected`
2865
- if (cmd !== 'skill' || action !== 'on') {
2854
+ const line = `skill ${name} ${action} · enabledSkills=[${[...set].join(', ')}] scope=selected`
2855
+ if (action !== 'on') {
2866
2856
  return line
2867
2857
  }
2868
2858
 
@@ -2877,17 +2867,15 @@ export class ChatApp {
2877
2867
 
2878
2868
  if (cmd === 'scope') {
2879
2869
  const [which, value] = rest
2880
- if ((which !== 'skills' && which !== 'tools') || (value !== 'all' && value !== 'selected')) {
2881
- return notice('usage: /scope skills|tools all|selected')
2870
+ if (which !== 'skills' || (value !== 'all' && value !== 'selected')) {
2871
+ return notice('usage: /scope skills all|selected')
2882
2872
  }
2883
2873
 
2884
- const scopeField = which === 'skills' ? 'skillsScope' : 'toolsScope'
2885
-
2886
2874
  return run(async () => {
2887
2875
  const updated = await engine.updateAgent({
2888
2876
  meshId: this.meshId,
2889
2877
  agentId: agent.id,
2890
- config: { [scopeField]: value }
2878
+ config: { skillsScope: value }
2891
2879
  })
2892
2880
  this.agent = updated
2893
2881
 
@@ -3508,8 +3496,12 @@ export class ChatApp {
3508
3496
  return run(() => this._movedChat(target))
3509
3497
  }
3510
3498
 
3499
+ if (action === 'fork' && target) {
3500
+ return run(() => this._forkChatInto(target, labelParts))
3501
+ }
3502
+
3511
3503
  return notice(
3512
- '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]'
3513
3505
  )
3514
3506
  }
3515
3507
 
@@ -3552,6 +3544,10 @@ export class ChatApp {
3552
3544
  return this._deleteChat(arg)
3553
3545
  }
3554
3546
 
3547
+ if (action === 'fork') {
3548
+ return this._forkChat(argParts)
3549
+ }
3550
+
3555
3551
  if (action === 'rename') {
3556
3552
  if (!arg) {
3557
3553
  return notice('usage: /chat rename <title>')
@@ -3584,7 +3580,7 @@ export class ChatApp {
3584
3580
  }
3585
3581
 
3586
3582
  return notice(
3587
- '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]'
3588
3584
  )
3589
3585
  }
3590
3586
 
@@ -3925,6 +3921,73 @@ export class ChatApp {
3925
3921
  ]
3926
3922
  }
3927
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
+
3928
3991
  _deleteChat(needle) {
3929
3992
  return [
3930
3993
  this,
@@ -4085,7 +4148,7 @@ export class ChatApp {
4085
4148
  }
4086
4149
  }
4087
4150
 
4088
- _switchTo(chat, agent) {
4151
+ _switchTo(chat, agent, notice) {
4089
4152
  this._resetChatWatches()
4090
4153
  this.chatId = chat.id
4091
4154
  if (agent) {
@@ -4097,7 +4160,7 @@ export class ChatApp {
4097
4160
  this._awaitingRun = false
4098
4161
  this._runningRunId = null
4099
4162
  this.pendingApproval = null
4100
- this.notice = `switched to "${chat.title}" (${chat.id.slice(0, 8)})`
4163
+ this.notice = notice ?? `switched to "${chat.title}" (${chat.id.slice(0, 8)})`
4101
4164
  this._render()
4102
4165
  }
4103
4166
 
@@ -4348,7 +4411,7 @@ export class ChatApp {
4348
4411
  }
4349
4412
 
4350
4413
  // resolved by where the provider is, not by the mesh on screen: a shared mesh carries no inventory
4351
- async _providerCaps(kind, detail) {
4414
+ async _providerCaps(detail) {
4352
4415
  const provider = this.agent?.providerDeviceId
4353
4416
  if (!provider) {
4354
4417
  return { names: [], reason: 'no-provider' }
@@ -4357,24 +4420,19 @@ export class ChatApp {
4357
4420
  // originDeviceId is bound late, so an early selector must ask rather than guess
4358
4421
  const own = this.originDeviceId ?? (await this.engine.deviceInfo({})).id
4359
4422
  if (own && b4a.equals(own, provider)) {
4360
- const names = await this._localCaps(kind, detail)
4423
+ const names = await this._localCaps(detail)
4361
4424
  if (names.length) {
4362
4425
  return { names, reason: null }
4363
4426
  }
4364
4427
 
4365
- // a harness that cannot describe its tools still published its catalog to the account
4366
- 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')
4367
4430
  }
4368
4431
 
4369
- return this._rosterCaps(kind, provider, 'none-advertised')
4432
+ return this._rosterCaps(provider, 'none-advertised')
4370
4433
  }
4371
4434
 
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
-
4435
+ async _localCaps(detail) {
4378
4436
  // detail is passed in, never re-fetched: it is already this device's resolved skill list
4379
4437
  if (detail) {
4380
4438
  return [...detail.keys()]
@@ -4386,7 +4444,7 @@ export class ChatApp {
4386
4444
  }
4387
4445
 
4388
4446
  // the account may have been closed, so it is named and opened, never assumed
4389
- async _rosterCaps(kind, provider, emptyReason) {
4447
+ async _rosterCaps(provider, emptyReason) {
4390
4448
  const { meshes } = await this.engine.listMeshes({})
4391
4449
  const account = (meshes ?? []).find((m) => m.account)?.meshId
4392
4450
  if (!account) {
@@ -4408,7 +4466,7 @@ export class ChatApp {
4408
4466
  return { names: [], reason: 'removed', deviceName: dev.name }
4409
4467
  }
4410
4468
 
4411
- const names = (kind === 'tools' ? dev.installedToolNames : dev.installedSkillNames) ?? []
4469
+ const names = dev.installedSkillNames ?? []
4412
4470
 
4413
4471
  return { names, reason: names.length ? null : emptyReason, deviceName: dev.name }
4414
4472
  }
@@ -4434,10 +4492,10 @@ export class ChatApp {
4434
4492
  async () => {
4435
4493
  try {
4436
4494
  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)
4495
+ const scope = fresh.skillsScope ?? 'selected'
4496
+ const enabled = fresh.enabledSkills ?? []
4497
+ const detail = await this._skillDetail()
4498
+ const caps = await this._providerCaps(detail)
4441
4499
  const installed = caps.names
4442
4500
  const { reason, deviceName } = caps
4443
4501
  return {
@@ -4622,7 +4680,6 @@ export class ChatApp {
4622
4680
  cursor: 0,
4623
4681
  entries: [
4624
4682
  { label: 'Skills', hint: 'toggle skills on/off', overlay: 'skills' },
4625
- { label: 'Tools', hint: 'toggle tools on/off', overlay: 'tools' },
4626
4683
  { label: 'Permissions', hint: 'approval mode & toolsets', overlay: 'permissions' },
4627
4684
  { label: 'Model', hint: "pick the agent's model", overlay: 'models' },
4628
4685
  {
@@ -4690,8 +4747,7 @@ export class ChatApp {
4690
4747
  cursor: 0,
4691
4748
  entries: [
4692
4749
  { 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 ' }
4750
+ { label: 'Skills scope…', hint: '/scope skills all|selected', prefill: '/scope skills ' }
4695
4751
  ]
4696
4752
  }
4697
4753
  }
@@ -5134,7 +5190,7 @@ export class ChatApp {
5134
5190
  ]
5135
5191
  }
5136
5192
 
5137
- // 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
5138
5194
  _toggleSelector() {
5139
5195
  const s = this._selector
5140
5196
  if (s.kind === 'ctx') {
@@ -5158,8 +5214,6 @@ export class ChatApp {
5158
5214
 
5159
5215
  s.scope = 'selected'
5160
5216
  this._render()
5161
- const field = s.kind === 'skills' ? 'enabledSkills' : 'enabledTools'
5162
- const scopeField = s.kind === 'skills' ? 'skillsScope' : 'toolsScope'
5163
5217
  const enabled = [...s.enabled]
5164
5218
  const { engine, agent } = this
5165
5219
 
@@ -5170,7 +5224,7 @@ export class ChatApp {
5170
5224
  this.agent = await engine.updateAgent({
5171
5225
  meshId: this.meshId,
5172
5226
  agentId: agent.id,
5173
- config: { [field]: enabled, [scopeField]: 'selected' }
5227
+ config: { enabledSkills: enabled, skillsScope: 'selected' }
5174
5228
  })
5175
5229
  return { type: 'selector.saved' }
5176
5230
  } catch (error) {
@@ -5418,7 +5472,7 @@ export class ChatApp {
5418
5472
  return null
5419
5473
  }
5420
5474
 
5421
- // 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
5422
5476
  _togglePermission(s, name) {
5423
5477
  if (name === MODE_ROW) {
5424
5478
  s.mode = s.mode === 'skip-all' ? 'ask' : 'skip-all'
@@ -5895,7 +5949,7 @@ export class ChatApp {
5895
5949
  }
5896
5950
 
5897
5951
  if (msg.type === 'chat.switch') {
5898
- this._switchTo(msg.chat, msg.agent)
5952
+ this._switchTo(msg.chat, msg.agent, msg.notice)
5899
5953
  return [this, batch(this._watchNext(), this._watchNextFiles(), this._rememberSelection())]
5900
5954
  }
5901
5955
 
@@ -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
+ }