@qvac/core 0.7.2 → 0.7.5

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.
package/tui/app.mjs CHANGED
@@ -7,6 +7,14 @@ import os from 'os'
7
7
  import path from 'path'
8
8
  import process from 'process'
9
9
  import { scopedKey } from '../dist-lib/lib/oauth/keys.js'
10
+ import {
11
+ MODEL_IDLE_UNLOAD_KEY,
12
+ MODEL_IDLE_UNLOAD_MINUTES,
13
+ MODEL_MEMORY_CAP_DEFAULT,
14
+ MODEL_MEMORY_CAP_KEY,
15
+ MODEL_MEMORY_CAP_MAX,
16
+ MODEL_MEMORY_CAP_MIN
17
+ } from '../dist-lib/lib/constants.js'
10
18
  import { oauthSpecs } from '../dist-lib/lib/oauth/registry.js'
11
19
  import { settingConfigKey } from '../dist-lib/lib/credential-pusher.js'
12
20
  import { customModelTaskRefusal } from '../dist-lib/lib/custom-model-task.js'
@@ -36,6 +44,7 @@ import { wrapBlock, wrapLine } from './lib/wrap.mjs'
36
44
  import { knowledgeCommand } from './lib/knowledge-command.mjs'
37
45
  import { describeMove } from './lib/move-command.mjs'
38
46
  import { forkCut } from './lib/fork-command.mjs'
47
+ import { deviceLines, onDevice, pickDevice } from './lib/device-target.mjs'
39
48
  import { saveUniqueFile } from './lib/save-file.mjs'
40
49
  import { usageReport } from './lib/usage.mjs'
41
50
  import { compactionTriggerRatio } from '../dist-lib/lib/compaction.js'
@@ -209,7 +218,7 @@ const COMMANDS = [
209
218
  },
210
219
  {
211
220
  name: 'join',
212
- desc: "join another device's mesh with its invite (replaces this one)",
221
+ desc: 'join a mesh from an invite: a device invite replaces this one, a member invite adds one',
213
222
  sub: [
214
223
  { name: 'cancel', desc: 'abort a join still waiting to be admitted' },
215
224
  { name: 'yes', desc: 'confirm a previewed invite and join' }
@@ -288,7 +297,27 @@ const COMMANDS = [
288
297
  { name: 'load', desc: '<model> — load a downloaded model into memory now' },
289
298
  { name: 'unload', desc: '<model> — unload a model; a reply using it starts again' },
290
299
  { name: 'delete', desc: '<name> — remove a downloaded model from this device' },
291
- { name: 'download', desc: '<name> — download a model to this device now' }
300
+ { name: 'download', desc: '<name> — download a model to this device now' },
301
+ { name: 'pause', desc: '<name> — hold a model’s download' },
302
+ { name: 'resume', desc: '<name> — let a held download go on' },
303
+ {
304
+ name: 'idle',
305
+ desc: '<never|minutes> — free loaded models after that long with no request'
306
+ },
307
+ { name: 'cap', desc: '<percent> — the share of the memory for models they may fill' },
308
+ { name: 'settings', desc: 'the idle limit and memory cap of the device /models acts on' }
309
+ ]
310
+ },
311
+ {
312
+ name: 'device',
313
+ desc: 'the device /models acts on: this one, or another device of this account',
314
+ sub: [
315
+ {
316
+ name: 'list',
317
+ desc: 'this account’s devices, whether each is connected, and how many models it has downloaded'
318
+ },
319
+ { name: 'use', desc: '<n|name|id> — point /models at that device' },
320
+ { name: 'here', desc: 'point /models back at this device' }
292
321
  ]
293
322
  },
294
323
  {
@@ -343,7 +372,12 @@ const MODEL_VERBS = new Set([
343
372
  'load',
344
373
  'unload',
345
374
  'delete',
346
- 'download'
375
+ 'download',
376
+ 'idle',
377
+ 'cap',
378
+ 'pause',
379
+ 'resume',
380
+ 'settings'
347
381
  ])
348
382
  // resolved before the SDK addon check so users don't have to know the plugin name
349
383
  const MODEL_TYPE_ALIASES = {
@@ -523,8 +557,16 @@ export function formatModels(rows, type, state = null) {
523
557
 
524
558
  return fg.dim.render('○ not cached')
525
559
  }
526
- const hint = state ? '↑/↓ move · enter use (downloads on next run) · esc return' : 'esc to return'
527
- const header = fg.dim.render(`Models on this device${filter} (${sorted.length}) — ${hint}`)
560
+ const usable = state && !state.device
561
+ let hint = 'esc to return'
562
+ if (usable) {
563
+ hint = '↑/↓ move · enter use (downloads on next run) · esc return'
564
+ } else if (state) {
565
+ hint = '↑/↓ move · esc return'
566
+ }
567
+
568
+ const place = state?.device ?? 'this device'
569
+ const header = fg.dim.render(`Models on ${place}${filter} (${sorted.length}) — ${hint}`)
528
570
  const lines = sorted.map((row, i) => {
529
571
  const name = fg.white.render(row.name.padEnd(nameWidth))
530
572
  const rowType = fg.dim.render(row.type.padEnd(typeWidth))
@@ -533,7 +575,8 @@ export function formatModels(rows, type, state = null) {
533
575
  ? `${mb(row.actualSize)} / ${mb(row.expectedSize)}`
534
576
  : mb(row.expectedSize)
535
577
  const vision = row.supportsImages ? ` ${fg.cyan.render('◈ vision')}` : ''
536
- const inUse = state?.currentModel === row.name ? ` ${fg.magenta.render('▸ in use')}` : ''
578
+ const inUse =
579
+ usable && state.currentModel === row.name ? ` ${fg.magenta.render('▸ in use')}` : ''
537
580
  const point = state && i === state.cursor ? fg.magenta.render('❯ ') : ' '
538
581
 
539
582
  return `${point}${badge(row)} ${name} ${rowType} ${fg.dim.render(size)}${vision}${inUse}`
@@ -557,13 +600,16 @@ async function catalogRow(engine, name) {
557
600
  return entry ? (catalog.find((m) => m.registryPath === entry.registryPath) ?? null) : null
558
601
  }
559
602
 
560
- const NOT_IN_CATALOG = "is not in this device's catalog — /models lists what can download"
603
+ const notOursToUse = (device) =>
604
+ `/models use picks this agent's model, not ${device.name}'s — /device here first`
605
+
606
+ const notInCatalog = (place) => `is not in ${place}'s catalog — /models lists what can download`
561
607
 
562
608
  // the agents still naming the model fetch it again on their next run
563
- async function deleteModel(engine, name) {
609
+ async function deleteModel(engine, name, place = 'this device') {
564
610
  const row = await catalogRow(engine, name)
565
611
  if (!row) {
566
- return `${name} ${NOT_IN_CATALOG}`
612
+ return `${name} ${notInCatalog(place)}`
567
613
  }
568
614
 
569
615
  const { freedBytes } = await engine.deleteModel({ name: row.name })
@@ -583,14 +629,14 @@ async function deleteModel(engine, name) {
583
629
  return lines.join('\n')
584
630
  }
585
631
 
586
- async function downloadModel(engine, name) {
632
+ async function downloadModel(engine, name, place = 'this device') {
587
633
  const row = await catalogRow(engine, name)
588
634
  if (!row) {
589
- return `${name} ${NOT_IN_CATALOG}`
635
+ return `${name} ${notInCatalog(place)}`
590
636
  }
591
637
 
592
638
  if (row.isCached) {
593
- return `${row.name} is already on this device`
639
+ return `${row.name} is already on ${place}`
594
640
  }
595
641
 
596
642
  await engine.retryModelDownload({ name: row.name })
@@ -1466,7 +1512,7 @@ function formatMeshes(meshes, current) {
1466
1512
 
1467
1513
  const rows = meshes.map((mesh, index) => {
1468
1514
  const tags = [
1469
- mesh.account ? 'account' : null,
1515
+ mesh.account ? 'home (your account)' : null,
1470
1516
  mesh.compute ? 'compute' : null,
1471
1517
  !mesh.account && !mesh.compute && mesh.members > 1 ? 'shared' : null,
1472
1518
  mesh.open ? 'open' : 'closed'
@@ -1481,7 +1527,10 @@ function formatMeshes(meshes, current) {
1481
1527
  return `${marker}${index + 1}. ${name} · ${tags.filter(Boolean).join(' · ')}`
1482
1528
  })
1483
1529
 
1484
- return [...rows, '* = this window · /mesh use <n|id> switches'].join('\n')
1530
+ return [
1531
+ ...rows,
1532
+ '* = this window · /mesh use <n|id> switches · /mesh label <n|id> <name> names one'
1533
+ ].join('\n')
1485
1534
  }
1486
1535
 
1487
1536
  // Same selector shape as /knowledge: a list number, a full id, or a unique prefix.
@@ -1722,6 +1771,7 @@ export class ChatApp {
1722
1771
  this._files = []
1723
1772
  this._filesIterator = null
1724
1773
  this._customModels = new Map()
1774
+ this._modelsDevice = null // set by /device: the account device the /models commands act on
1725
1775
  this._pickableFiles = []
1726
1776
  this._statusIterator = null
1727
1777
  this._downloadsIterator = null
@@ -2187,7 +2237,8 @@ export class ChatApp {
2187
2237
  if (this._models) {
2188
2238
  const rows = formatModels(this._models.rows, this._models.filter, {
2189
2239
  cursor: this._models.cursor,
2190
- currentModel: this.agent?.modelName
2240
+ currentModel: this.agent?.modelName,
2241
+ device: this._models.device?.name
2191
2242
  })
2192
2243
  this._setRows(rows, this._models.cursor + 2)
2193
2244
 
@@ -2300,6 +2351,9 @@ export class ChatApp {
2300
2351
  ' /skill on|off <name> — toggle (sets scope=selected)',
2301
2352
  ' /permissions — approval mode + the toolset switches; ↑/↓ move, space toggles',
2302
2353
  ' /models delete <name> · /models download <name> — remove a model from this device, or fetch it now',
2354
+ ' /models load <model> · unload <model> · pause <name> · resume <name> — load or unload a model now, or hold its download',
2355
+ ' /models idle <never|minutes> · cap <percent> · settings — free loaded models after that long with no request, the share of memory they may fill, and both settings',
2356
+ ' /device [list] · /device use <n|name|id> · /device here — point /models at another device of this account, or back at this one',
2303
2357
  ' /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',
2304
2358
  ' /models custom · preview <src|n> [mmproj] · add <label> <src|n> [tools|vision|thinking] · use <name|label> · remove <name|label> — check a GGUF by url or local path, add it, and pick it; its context window caps /ctx',
2305
2359
  ' /image [model <choice> | steps <n> | size <WxH> | reset] — the agent’s image-generation defaults',
@@ -2318,13 +2372,13 @@ export class ChatApp {
2318
2372
  'Advanced',
2319
2373
  ' /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',
2320
2374
  ' /scope skills all|selected — switch scope',
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',
2375
+ ' /join <qvac://mesh/…> — preview who you would join as (ctrl+y copies this mesh’s invite) · /join yes — confirm it (a device invite retires this device’s mesh, a member invite adds one beside it) · /join cancel — abort a join in progress',
2322
2376
  ' /leave — leave the active mesh; the device lands on another mesh it can write to, or mints a fresh account',
2323
2377
  ' /invite - show this mesh device invite · /invite member - open your shared mesh and invite someone into it (your account is never shared)',
2324
2378
  ' /mesh new - open another shared mesh · /mesh new compute - lend this device · /mesh label <n|id> <name> - name a mesh, privately to you',
2325
2379
  ' /members — list mesh members with their devices grouped',
2326
2380
  ' /rename device <name> — name this device · /rename member <name> — name yourself, across every mesh',
2327
- ' /meshes - list the meshes this device belongs to, numbered, marking account / shared / active / open / writable',
2381
+ ' /meshes - list the meshes this device belongs to, numbered, marking home (your account) / shared / active / open / writable',
2328
2382
  ' /mesh use <n|id> - make one of them active; its agent, chat and roster replace the ones on screen',
2329
2383
  ' /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',
2330
2384
  ' /my-device — dump this device\u2019s CPU/GPU inventory (manufacturer, cores, drivers, …)',
@@ -2437,6 +2491,47 @@ export class ChatApp {
2437
2491
  return this._setContextSize(size)
2438
2492
  }
2439
2493
 
2494
+ if (cmd === 'device') {
2495
+ const action = rest[0]?.toLowerCase()
2496
+ const USAGE = 'usage: /device [list] · use <n|name|id> · here'
2497
+ if (action === 'here') {
2498
+ this._modelsDevice = null
2499
+ return notice('/models acts on this device')
2500
+ }
2501
+
2502
+ if (action && action !== 'list' && action !== 'use') {
2503
+ return notice(USAGE)
2504
+ }
2505
+
2506
+ return run(async () => {
2507
+ const listed = await this._accountDevices(await accountMeshId(engine))
2508
+ const devices = (listed ?? []).filter((device) => !device.revoked)
2509
+ const own = this.originDeviceId ?? (await engine.deviceInfo({})).id
2510
+ const target = this._modelsDevice
2511
+ // a roster that could not be read says nothing about whether the target left
2512
+ if (listed && target && !devices.some((device) => b4a.equals(device.id, target.id))) {
2513
+ this._modelsDevice = null
2514
+ }
2515
+
2516
+ if (action === 'use') {
2517
+ const picked = pickDevice(devices, rest.slice(1).join(' '))
2518
+ if (!picked) {
2519
+ return `no such device — /device list shows them\n${USAGE}`
2520
+ }
2521
+
2522
+ this._modelsDevice = b4a.equals(picked.id, own) ? null : picked
2523
+
2524
+ return `/models acts on ${this._modelsDevice ? picked.name : 'this device'}`
2525
+ }
2526
+
2527
+ const connected = new Set(
2528
+ (this.meshStatus?.peerDeviceIds ?? []).map((id) => id.toLowerCase())
2529
+ )
2530
+
2531
+ return deviceLines(devices, { own, target: this._modelsDevice?.id, connected }).join('\n')
2532
+ })
2533
+ }
2534
+
2440
2535
  if (cmd === 'models' && !MODEL_VERBS.has(rest[0]?.toLowerCase())) {
2441
2536
  const raw = rest[0]?.toLowerCase()
2442
2537
  if (!raw) {
@@ -2456,7 +2551,68 @@ export class ChatApp {
2456
2551
  if (cmd === 'models') {
2457
2552
  const raw = rest[0]?.toLowerCase()
2458
2553
  const USAGE =
2459
- 'usage: /models [type] · custom · preview <src|n> [mmproj] · add <label> <src|n> [tools] [vision] [thinking] · use <name|label> · remove <name|label> · load <model> · unload <model> · delete <name> · download <name>'
2554
+ 'usage: /models [type] · custom · preview <src|n> [mmproj] · add <label> <src|n> [tools] [vision] [thinking] · use <name|label> · remove <name|label> · load <model> · unload <model> · delete <name> · download <name> · pause <name> · resume <name> · idle <never|minutes> · cap <percent> · settings'
2555
+ const models = this._modelsEngine()
2556
+ const on = this._modelsDevice
2557
+ const where = (text) => (on ? `${on.name}: ${text}` : text)
2558
+ if (raw === 'idle') {
2559
+ const asked = rest[1]?.toLowerCase()
2560
+ const minutes = asked === 'never' ? 0 : Number(asked)
2561
+ if (!asked || (minutes !== 0 && !MODEL_IDLE_UNLOAD_MINUTES.includes(minutes))) {
2562
+ return notice(`usage: /models idle never|${MODEL_IDLE_UNLOAD_MINUTES.join('|')}`)
2563
+ }
2564
+
2565
+ return run(async () => {
2566
+ await models.configSet({ key: MODEL_IDLE_UNLOAD_KEY, value: minutes })
2567
+ return where(
2568
+ minutes
2569
+ ? `loaded models are freed after ${minutes} min with no request`
2570
+ : 'loaded models are never freed for being idle'
2571
+ )
2572
+ })
2573
+ }
2574
+
2575
+ if (raw === 'cap') {
2576
+ const percent = Number(rest[1])
2577
+ if (
2578
+ !Number.isInteger(percent) ||
2579
+ percent < MODEL_MEMORY_CAP_MIN ||
2580
+ percent > MODEL_MEMORY_CAP_MAX
2581
+ ) {
2582
+ return notice(`usage: /models cap <${MODEL_MEMORY_CAP_MIN}..${MODEL_MEMORY_CAP_MAX}>`)
2583
+ }
2584
+
2585
+ return run(async () => {
2586
+ await models.configSet({ key: MODEL_MEMORY_CAP_KEY, value: percent })
2587
+ return where(`loaded models may fill ${percent}% of the memory usable for models`)
2588
+ })
2589
+ }
2590
+
2591
+ if (raw === 'settings') {
2592
+ return run(async () => {
2593
+ const idle = (await models.configGet({ key: MODEL_IDLE_UNLOAD_KEY })).value
2594
+ const cap = (await models.configGet({ key: MODEL_MEMORY_CAP_KEY })).value
2595
+ return where(
2596
+ [
2597
+ `free when idle: ${idle ? `${idle} min` : 'never'}`,
2598
+ `memory cap: ${cap ? `${cap}%` : `${MODEL_MEMORY_CAP_DEFAULT}% (default)`}`
2599
+ ].join(' · ')
2600
+ )
2601
+ })
2602
+ }
2603
+
2604
+ if (raw === 'pause' || raw === 'resume') {
2605
+ const name = rest.slice(1).join(' ')
2606
+ if (!name) {
2607
+ return notice(`usage: /models ${raw} <name>`)
2608
+ }
2609
+
2610
+ return run(async () => {
2611
+ await models.setModelPaused({ name, paused: raw === 'pause' })
2612
+ return where(`${name} ${raw === 'pause' ? 'paused' : 'resumed'}`)
2613
+ })
2614
+ }
2615
+
2460
2616
  if (raw === 'load' || raw === 'unload') {
2461
2617
  const name = rest.slice(1).join(' ')
2462
2618
  if (!name) {
@@ -2465,18 +2621,22 @@ export class ChatApp {
2465
2621
 
2466
2622
  return run(async () => {
2467
2623
  if (raw === 'unload') {
2468
- const { unloaded } = await engine.unloadModel({ name })
2469
- return unloaded ? `${name} unloaded` : `${name} is still in use — try again shortly`
2624
+ const { unloaded } = await models.unloadModel({ name })
2625
+ return where(
2626
+ unloaded ? `${name} unloaded` : `${name} is still in use — try again shortly`
2627
+ )
2470
2628
  }
2471
2629
 
2472
- const { loaded, reason } = await engine.loadModel({ name })
2630
+ const { loaded, reason } = await models.loadModel({ name })
2473
2631
  if (loaded) {
2474
- return `${name} loaded`
2632
+ return where(`${name} loaded`)
2475
2633
  }
2476
2634
 
2477
- return reason === 'memory'
2478
- ? `${name} would not fit beside the loaded models — unload one first`
2479
- : `${name} could not be loaded`
2635
+ return where(
2636
+ reason === 'memory'
2637
+ ? `${name} would not fit beside the loaded models — unload one first`
2638
+ : `${name} could not be loaded`
2639
+ )
2480
2640
  })
2481
2641
  }
2482
2642
 
@@ -2486,28 +2646,33 @@ export class ChatApp {
2486
2646
  return notice(`usage: /models ${raw} <name>`)
2487
2647
  }
2488
2648
 
2489
- return run(() =>
2490
- raw === 'delete' ? deleteModel(engine, name) : downloadModel(engine, name)
2649
+ return run(async () =>
2650
+ where(
2651
+ await (raw === 'delete'
2652
+ ? deleteModel(models, name, on?.name)
2653
+ : downloadModel(models, name, on?.name))
2654
+ )
2491
2655
  )
2492
2656
  }
2493
2657
 
2494
2658
  if (raw === 'custom') {
2495
2659
  return run(async () => {
2496
- await this._refreshCustomModels()
2497
- const models = [...this._customModels.values()]
2498
- if (models.length === 0) {
2499
- return 'no models added yet — /models add <name> <src>'
2660
+ const added = [...(await this._modelsLibrary()).values()]
2661
+ if (added.length === 0) {
2662
+ return where('no models added yet — /models add <name> <src>')
2500
2663
  }
2501
2664
 
2502
- return models
2503
- .map((m) => {
2504
- const ctx =
2505
- m.contextLength > 0 ? formatTokenCount(m.contextLength) : 'ctx window unknown'
2506
- const about = [m.taskType, m.license].filter(Boolean).join(' · ')
2665
+ return where(
2666
+ added
2667
+ .map((m) => {
2668
+ const ctx =
2669
+ m.contextLength > 0 ? formatTokenCount(m.contextLength) : 'ctx window unknown'
2670
+ const about = [m.taskType, m.license].filter(Boolean).join(' · ')
2507
2671
 
2508
- return `${m.label || m.name} ${m.name}\n ${m.src}\n ${ctx}${about ? ` · ${about}` : ''}`
2509
- })
2510
- .join('\n')
2672
+ return `${m.label || m.name} ${m.name}\n ${m.src}\n ${ctx}${about ? ` · ${about}` : ''}`
2673
+ })
2674
+ .join('\n')
2675
+ )
2511
2676
  })
2512
2677
  }
2513
2678
 
@@ -2518,12 +2683,12 @@ export class ChatApp {
2518
2683
  }
2519
2684
 
2520
2685
  return run(async () => {
2521
- const preview = await engine.previewCustomModel({ src, mmprojSrc: rest[2] })
2686
+ const preview = await models.previewCustomModel({ src, mmprojSrc: rest[2] })
2522
2687
  if (!preview.src && preview.files?.length) {
2523
2688
  this._pickableFiles = preview.files
2524
2689
  }
2525
2690
 
2526
- return formatModelPreview(preview)
2691
+ return where(formatModelPreview(preview))
2527
2692
  })
2528
2693
  }
2529
2694
 
@@ -2537,21 +2702,20 @@ export class ChatApp {
2537
2702
  const flags = new Set(rest.slice(3).map((f) => f.toLowerCase()))
2538
2703
 
2539
2704
  return run(async () => {
2540
- const { id } = await engine.addCustomModel({
2705
+ const { id } = await models.addCustomModel({
2541
2706
  label,
2542
2707
  src,
2543
2708
  supportsTools: flags.has('tools'),
2544
2709
  supportsVision: flags.has('vision'),
2545
2710
  supportsThinking: flags.has('thinking')
2546
2711
  })
2547
- await this._refreshCustomModels()
2548
- const row = this._customModels.get(id)
2712
+ const row = (await this._modelsLibrary()).get(id)
2549
2713
  const ctx =
2550
2714
  row && row.contextLength > 0
2551
2715
  ? `context window ${formatTokenCount(row.contextLength)}`
2552
2716
  : 'context window unknown — the picker uses the default range'
2553
2717
 
2554
- return `added ${label} as ${id}\n ${row?.src ?? src}\n ${ctx}`
2718
+ return where(`added ${label} as ${id}\n ${row?.src ?? src}\n ${ctx}`)
2555
2719
  })
2556
2720
  }
2557
2721
 
@@ -2561,6 +2725,10 @@ export class ChatApp {
2561
2725
  return notice(USAGE)
2562
2726
  }
2563
2727
 
2728
+ if (on) {
2729
+ return notice(notOursToUse(on))
2730
+ }
2731
+
2564
2732
  return run(async () => {
2565
2733
  await this._refreshCustomModels()
2566
2734
  const custom = await this._customModelFor(asked)
@@ -2588,17 +2756,16 @@ export class ChatApp {
2588
2756
  }
2589
2757
 
2590
2758
  return run(async () => {
2591
- await this._refreshCustomModels()
2592
- const custom = await this._customModelFor(asked)
2759
+ const custom = await this._customModelFor(asked, await this._modelsLibrary(), models)
2593
2760
  if (!custom) {
2594
- return deleteModel(engine, asked)
2761
+ return where(await deleteModel(models, asked, on?.name))
2595
2762
  }
2596
2763
 
2597
- const { freedBytes } = await engine.removeCustomModel({ name: custom.name })
2764
+ const { freedBytes } = await models.removeCustomModel({ name: custom.name })
2598
2765
  await this._refreshCustomModels()
2599
2766
  const freed = freedBytes > 0 ? `freed ${bytesToGb(freedBytes)}` : 'nothing was downloaded'
2600
2767
 
2601
- return `removed ${custom.label || custom.name} — ${freed}`
2768
+ return where(`removed ${custom.label || custom.name} — ${freed}`)
2602
2769
  })
2603
2770
  }
2604
2771
 
@@ -3339,13 +3506,15 @@ export class ChatApp {
3339
3506
 
3340
3507
  this._pendingJoinInvite = invite
3341
3508
  let who = 'a device on this account'
3509
+ let effect = 'this device’s current mesh is retired'
3342
3510
  if (preview.memberInvite) {
3343
3511
  who = 'a new person'
3512
+ effect = 'it is added beside your meshes, nothing is retired'
3344
3513
  } else if (preview.inviterName) {
3345
3514
  who = `one of ${preview.inviterName}'s devices`
3346
3515
  }
3347
3516
 
3348
- return `you will join as ${who} — run /join yes to confirm, or /join cancel to back out`
3517
+ return `you will join as ${who}; ${effect} — run /join yes to confirm, or /join cancel to back out`
3349
3518
  })
3350
3519
  }
3351
3520
 
@@ -3406,7 +3575,7 @@ export class ChatApp {
3406
3575
  // ctrl+y copies the active mesh invite, so a shared-mesh invite never lands in this.invite
3407
3576
  const copied = await this._copyQuietly(res.invite)
3408
3577
  if (!member) {
3409
- return `device invite - the joiner is adopted into your member${copied ? ' (copied)' : ''}:\n${res.invite}`
3578
+ return `device invite - the joiner is adopted into your member${copied ? ' (copied)' : ''}; it runs /join, or starts duck --device-join <invite>:\n${res.invite}`
3410
3579
  }
3411
3580
 
3412
3581
  const lines = [await this._meshHeading(res.meshId)]
@@ -3417,6 +3586,7 @@ export class ChatApp {
3417
3586
  const { meshes: listed } = await engine.listMeshes({}).catch(() => ({ meshes: [] }))
3418
3587
  const isCompute = (listed ?? []).find((m) => m.meshId === res.meshId)?.compute
3419
3588
  lines.push(...(isCompute ? COMPUTE_INVITE_DISCLOSURES : MEMBER_INVITE_DISCLOSURES))
3589
+ lines.push('the invitee runs /join <invite>, or starts duck --join <invite>')
3420
3590
  lines.push(`${copied ? 'invite (copied)' : 'invite'}:\n${res.invite}`)
3421
3591
 
3422
3592
  return lines.join('\n')
@@ -4423,7 +4593,8 @@ export class ChatApp {
4423
4593
  }
4424
4594
 
4425
4595
  _showModels(type) {
4426
- const { engine } = this
4596
+ const engine = this._modelsEngine()
4597
+ const device = this._modelsDevice
4427
4598
  return [
4428
4599
  this,
4429
4600
  async () => {
@@ -4432,7 +4603,7 @@ export class ChatApp {
4432
4603
  fullRegistry: true,
4433
4604
  type
4434
4605
  })
4435
- return { type: 'models.result', filter: type, rows: models ?? [] }
4606
+ return { type: 'models.result', filter: type, rows: models ?? [], device }
4436
4607
  } catch (error) {
4437
4608
  return { type: 'models.result', filter: type, rows: null, error }
4438
4609
  }
@@ -4555,28 +4726,51 @@ export class ChatApp {
4555
4726
  return skills ? new Map(skills.map((skill) => [skill.name, skill])) : null
4556
4727
  }
4557
4728
 
4729
+ _modelsEngine() {
4730
+ return onDevice(this.engine, this._modelsDevice?.id)
4731
+ }
4732
+
4733
+ async _customModelsOf(engine) {
4734
+ if (!engine?.customModelsWatch) return null
4735
+ const it = engine.customModelsWatch({})[Symbol.asyncIterator]()
4736
+ try {
4737
+ const frame = await it.next()
4738
+ return frame.done ? null : new Map((frame.value?.models ?? []).map((m) => [m.name, m]))
4739
+ } finally {
4740
+ await it.return?.().catch(noop)
4741
+ }
4742
+ }
4743
+
4744
+ // the agent's own library, which /ctx and /models use read whatever /device points at
4558
4745
  async _refreshCustomModels() {
4559
- if (!this.engine?.customModelsWatch) return
4560
- const it = this.engine.customModelsWatch({})[Symbol.asyncIterator]()
4561
- const frame = await it.next().catch(() => ({ done: true }))
4562
- await it.return?.().catch(noop)
4563
- if (!frame.done) {
4564
- this._customModels = new Map((frame.value?.models ?? []).map((m) => [m.name, m]))
4746
+ const customs = await this._customModelsOf(this.engine).catch(noop)
4747
+ if (customs) {
4748
+ this._customModels = customs
4565
4749
  }
4566
4750
  }
4567
4751
 
4568
- async _customModelFor(nameOrLabel) {
4569
- const byId = this._customModels.get(nameOrLabel)
4752
+ async _modelsLibrary() {
4753
+ if (!this._modelsDevice) {
4754
+ await this._refreshCustomModels()
4755
+ return this._customModels
4756
+ }
4757
+
4758
+ // a target that is away refuses, rather than reading as a library with nothing added
4759
+ return (await this._customModelsOf(this._modelsEngine())) ?? new Map()
4760
+ }
4761
+
4762
+ async _customModelFor(nameOrLabel, customs = this._customModels, engine = this.engine) {
4763
+ const byId = customs.get(nameOrLabel)
4570
4764
  if (byId) {
4571
4765
  return byId
4572
4766
  }
4573
4767
 
4574
- const labelled = [...this._customModels.values()].find((model) => model.label === nameOrLabel)
4768
+ const labelled = [...customs.values()].find((model) => model.label === nameOrLabel)
4575
4769
  if (!labelled) {
4576
4770
  return undefined
4577
4771
  }
4578
4772
 
4579
- const { models } = await this.engine.listModels({ fullRegistry: true })
4773
+ const { models } = await engine.listModels({ fullRegistry: true })
4580
4774
 
4581
4775
  return models?.some((model) => model.name === nameOrLabel) ? undefined : labelled
4582
4776
  }
@@ -5191,13 +5385,21 @@ export class ChatApp {
5191
5385
 
5192
5386
  // nothing downloads here: the provider pulls the model when the agent next runs
5193
5387
  _useModel() {
5194
- const row = this._models.rows[this._models.cursor]
5388
+ const { rows, cursor, device } = this._models
5389
+ const row = rows[cursor]
5195
5390
  this._models = null
5196
5391
  if (!row) {
5197
5392
  this._render()
5198
5393
  return [this, null]
5199
5394
  }
5200
5395
 
5396
+ // the rows are that device's library, and the agent resolves its model from its own
5397
+ if (device) {
5398
+ this.notice = notOursToUse(device)
5399
+ this._render()
5400
+ return [this, null]
5401
+ }
5402
+
5201
5403
  const { engine, agent } = this
5202
5404
 
5203
5405
  return [
@@ -6319,7 +6521,12 @@ export class ChatApp {
6319
6521
  } else {
6320
6522
  this.overlay = null
6321
6523
  this._selector = null
6322
- this._models = { rows: sortModels(msg.rows), filter: msg.filter ?? null, cursor: 0 }
6524
+ this._models = {
6525
+ rows: sortModels(msg.rows),
6526
+ filter: msg.filter ?? null,
6527
+ cursor: 0,
6528
+ device: msg.device ?? null
6529
+ }
6323
6530
  }
6324
6531
 
6325
6532
  this._render()