sigelo-contact 0.1.20 → 0.1.21

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/test-transfer.mjs CHANGED
@@ -10,7 +10,7 @@
10
10
  // when SIGELO_TEST_TOR names its control port. SIGELO_TEST_MB: the size of the direct file (default 50).
11
11
  // node apps/contact/test-transfer.mjs → ALL PASS (n)
12
12
  import { createHash } from 'node:crypto';
13
- import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
13
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
14
14
  import net from 'node:net';
15
15
  import { tmpdir } from 'node:os';
16
16
  import { basename, dirname, join } from 'node:path';
@@ -204,6 +204,18 @@ export function attempt(bytes, m, hashes, { have, known = null, drop, alter, rea
204
204
  ok(await ended === 'cancelled', 'a WANT past the file: the sender ends it');
205
205
  }
206
206
 
207
+ // Where sigelo-transfer is looked for (transfer-node.mjs rtcDirs): the global layout `npm i -g sigelo-agent sigelo-transfer`
208
+ // makes (sigelo-contact inside sigelo-agent's node_modules, sigelo-transfer beside sigelo-agent) is found by name.
209
+ {
210
+ const { rtcDirs } = await import('./transfer-node.mjs');
211
+ const g = mkdtempSync(join(tmpdir(), 'sigelo-rtcdirs-')), lib = join(g, 'lib', 'node_modules'), from = join(lib, 'sigelo-agent', 'node_modules', 'sigelo-contact');
212
+ for (const d of [from, join(lib, 'sigelo-transfer')]) mkdirSync(d, { recursive: true });
213
+ writeFileSync(join(lib, 'sigelo-transfer', 'package.json'), JSON.stringify({ name: 'sigelo-transfer', exports: { './package.json': './package.json' } }));
214
+ const dirs = rtcDirs(from);
215
+ ok(dirs.includes(join(lib, 'sigelo-transfer')) && dirs[0] === join(lib, 'sigelo-agent', 'node_modules', 'transfer'), 'rtcDirs: a global sigelo-transfer beside sigelo-agent is found by name, after the fixed places', JSON.stringify(dirs));
216
+ rmSync(g, { recursive: true, force: true });
217
+ }
218
+
207
219
  const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', '..', 'relay');
208
220
  if (!existsSync(join(RELAY_DIR, 'server.mjs')) || !existsSync(join(RELAY_DIR, 'node_modules'))) {
209
221
  report();
package/test-voice.mjs CHANGED
@@ -52,6 +52,9 @@ ok(voiceLine(V) === '[voice 0:42 voice-20261117-142301.webm]', 'voiceLine: [voic
52
52
  ok(r.messages[0].text === '[voice 0:42 voice-20261117-142301.webm]' && r.messages[0].voice.sha256 === SHA && r.messages[0].content === V, 'voiceItems: a voice message gains text [voice 0:42 name] and its fields (voice); content kept');
53
53
  ok(r.messages[1] === batch.messages[1] && r.events === batch.events, 'voiceItems: other messages and the events as they were');
54
54
  ok(r.messages[2].voice_error?.includes('duration_s') && r.messages[2].text === undefined, 'voiceItems: one that does not check says why (voice_error), no line');
55
+ const caps = { label: 'sigelo-host-caps/0', content: { v: 'sigelo-host-caps/0', model: { value: 'x' } } };
56
+ const rc = voiceItems({ messages: [caps], events: [] }).messages[0];
57
+ ok(rc.data === 'sigelo-host-caps/0' && /data, not a message/.test(rc.text) && rc.content === caps.content, 'voiceItems: a sigelo-host-caps/0 message is marked data with one line, content kept');
55
58
  ok(r.messages[3].text === voiceLine(V) && r.messages[3].voice.duration_s === 42, 'voiceItems: a group msg with a voice gets the line too');
56
59
  }
57
60
 
@@ -19,8 +19,8 @@
19
19
  // The accept rule (design §10.2, decided 2026-11-13): a file lands without a question up to the size set
20
20
  // (settings.auto_mb, default 25 MB; per contact auto[DID]) from own agents and own contacts (tier own,
21
21
  // ours) and from friends whose four words were compared (compared(did), the page's), when the disk has
22
- // room and direct is allowed for that contact; larger, or from anyone else (words not compared, a
23
- // public-code joiner, quiet), it is asked.
22
+ // room; larger, or from anyone else (words not compared, a public-code joiner, quiet), it is asked. The
23
+ // direct switch picks the lane, not the yes (2026-11-25): off, it comes over Tor or the relay lane.
24
24
  //
25
25
  // The relay lane (0.1.19): a file of at most RELAY_MAX (8 MiB, send-file's) to an own agent or contact, or to a friend
26
26
  // whose words were compared, that cannot go direct (no path, no Tor: the end no_path) or whose channel dropped and did
@@ -29,10 +29,18 @@
29
29
  // done once the file comes (Engine.superseded). Larger, or to anyone else: as before; the page offers Retry (retry) or,
30
30
  // up to 8 MiB, Send over the relay. A channel that moves no byte for stallMs (30 s) counts as dropped; a receiver's
31
31
  // record active with nothing for STALE_S (10 minutes) is listed as interrupted, and resume takes it again.
32
+ //
33
+ // "Always relay my media" (design/calls.md §6, 2026-11-26): policy() "relay" (the page's setting) or env
34
+ // SIGELO_ICE_POLICY=relay: the direct lane only through the relay's TURN (iceTransportPolicy relay, relayed candidates
35
+ // only in the SDP: rtc-web.mjs, apps/transfer/rtc.mjs); with no TURN to be had the direct lane is left out at once
36
+ // (RELAY_ONLY, reason relay_only on the receiver's record) and the file goes over Tor or the relay lane as without one.
37
+ // A record's `relayed` (true | false) says whether the direct lane's selected candidate pair was relayed (getStats, as
38
+ // the call screen's "Via relay").
32
39
  import { concatBytes } from '@noble/hashes/utils.js';
33
40
  import { TRANSFER_SEND } from './carrier.mjs';
34
41
  import { FILE_LABEL, MAX_FILE, safeName, sha256Hex } from './file.mjs';
35
42
  import { MsgError, fail } from './kdf.mjs';
43
+ import { RELAY_ONLY } from './call.mjs';
36
44
  import {
37
45
  ANSWER_WAIT, AUTO_MB, CHUNK, DAY, GATHER_MS, ICE_MS, MANIFEST_TTL, MAX_SIZE, Have, Pull, Serve, TRANSFER_LABEL, WAIT_ALL, WAIT_CONTACT,
38
46
  acceptRule, channelLabel, checkMessage, listOf, manifest, noPath, pathOrder, torRoles,
@@ -40,6 +48,7 @@ import {
40
48
 
41
49
  export const FILE_V = 'sigelo-transfers/1';
42
50
  export { TRANSFER_LABEL };
51
+ export { RELAY_ONLY };
43
52
  const KEPT = 30 * DAY, RETRIES_AUTO = 3, RETRY_MS = 5000, STUN_PORT = 3478;
44
53
  export const FREE_MARGIN = 64 * CHUNK;
45
54
  export const RELAY_MAX = MAX_FILE, FALLBACK_MS = 20_000, STALL_MS = 30_000, STALE_S = 600;
@@ -156,9 +165,9 @@ const recIn = (s, id) => s.in[id] ?? fail('transfer_unknown', `no transfer ${id}
156
165
  const either = (s, id) => (s.in[id] ? { side: 'in', r: s.in[id] } : s.out[id] ? { side: 'out', r: s.out[id] } : fail('transfer_unknown', `no transfer ${id}`));
157
166
  const haveOf = (io, r) => { const b = io.have.read(r.id); try { return new Have(r.chunks, b ?? undefined); } catch { return new Have(r.chunks); } };
158
167
  /** Free disk for a record (in s), or disk_full. */
159
- const room = (io, r) => {
168
+ const room = (io, r, promised = 0) => {
160
169
  const need = r.size - haveOf(io, r).bytes(r.size), free = io.free();
161
- if (free < need + FREE_MARGIN) fail('disk_full', `${r.name} needs ${need} bytes more here, ${free} are free`);
170
+ if (free < need + promised + FREE_MARGIN) fail('disk_full', `${r.name} needs ${need} bytes more here, ${free} are free${promised ? ` (${promised} promised to files accepted before)` : ''}`);
162
171
  };
163
172
 
164
173
  /** The receiver's yes to a manifest (or a resume of one that stopped): free disk checked, the direct switch settled. */
@@ -312,14 +321,16 @@ export function stunFor(carrier, c, env = {}) {
312
321
  export class Engine {
313
322
  /**
314
323
  * carrier: started (it holds the session); io (above); rtc: () → the direct path's module ({ peer }) or null;
315
- * stun: a list, or null for stunFor(env); pro: () → whether this agent's pool is Pro; compared(did): the four
324
+ * stun: a list, or null for stunFor(env); turn: null (ask carrier.turnServer at each attempt; env.SIGELO_TURN=off: never), false (none),
325
+ * or a function → { urls, username, credential } | null; pro: () → whether this agent's pool is Pro; compared(did): the four
316
326
  * words of that contact were compared (the accept rule); maxServe: transfers served at once (the rest wait,
317
327
  * their offers kept); onEvent(e): {type: 'transfer', what, id, …}; fallbackMs: a drop not picked up again within it goes
318
- * over the relay lane (up to 8 MiB, own and compared); stallMs: a channel with no byte for so long counts as dropped.
328
+ * over the relay lane (up to 8 MiB, own and compared); stallMs: a channel with no byte for so long counts as dropped;
329
+ * policy: () → "relay" | "all" (the page's "Always relay my media"; env SIGELO_ICE_POLICY=relay says relay too).
319
330
  */
320
- constructor({ carrier, io, rtc = async () => null, stun = null, env = {}, pro = () => false, compared = () => false, maxServe = Infinity, onEvent = () => {}, retryMs = RETRY_MS, torConnectMs = 120_000, timer = true,
321
- fallbackMs = FALLBACK_MS, stallMs = STALL_MS }) {
322
- Object.assign(this, { carrier, io, rtcLoad: rtc, stun, env, pro, compared, maxServe, onEvent, retryMs, torConnectMs, fallbackMs, stallMs });
331
+ constructor({ carrier, io, rtc = async () => null, stun = null, turn = null, env = {}, pro = () => false, compared = () => false, maxServe = Infinity, onEvent = () => {}, retryMs = RETRY_MS, torConnectMs = 120_000, timer = true,
332
+ fallbackMs = FALLBACK_MS, stallMs = STALL_MS, policy = () => 'all' }) {
333
+ Object.assign(this, { carrier, io, rtcLoad: rtc, stun, turn, env, pro, compared, maxServe, onEvent, retryMs, torConnectMs, fallbackMs, stallMs, policy });
323
334
  this.relaying = new Set(); // ids going over the relay lane from this process (relay)
324
335
  this.attempts = new Map(); // id → { role, attempt, peer, channel, proto, onion, server, got, sent, path }
325
336
  this.held = []; // offers waiting for a free slot (maxServe)
@@ -338,6 +349,28 @@ export class Engine {
338
349
  return this.caps;
339
350
  }
340
351
  stunOf(c) { return this.stun ?? stunFor(this.carrier, c, this.env); }
352
+ /** The TURN server for an attempt starting now (relay/turn.mjs, fresh credentials), or null: STUN alone, as before.
353
+ * rtc: the direct path's module; only one with TURN_OK true gets one (werift: apps/transfer/rtc.mjs, with its DTLS checks). */
354
+ /** The ICE policy of an attempt starting now: "relay" when the setting or SIGELO_ICE_POLICY says so, else "all". */
355
+ policyNow() { let p = null; try { p = typeof this.policy === 'function' ? this.policy() : this.policy; } catch {} return p === 'relay' || this.env.SIGELO_ICE_POLICY === 'relay' ? 'relay' : 'all'; }
356
+ /** The direct lane's peer for an attempt, under the policy: { peer, turn } or { peer: null } (relay only, no TURN). */
357
+ async #peerFor(rtc, c) {
358
+ const policy = this.policyNow(), turn = await this.turnOf(rtc);
359
+ if (policy === 'relay' && turn === null) return { peer: null, turn: null };
360
+ return { peer: await rtc.peer({ stun: this.stunOf(c), turn, gatherMs: GATHER_MS, ...(policy === 'relay' && { policy }) }), turn };
361
+ }
362
+ /** The channel is open: whether its selected pair is relayed, in the record (`relayed`) and the attempt. */
363
+ async #opened(side, id, a) {
364
+ let v = null;
365
+ try { v = (await a.peer?.relayed?.()) ?? null; } catch {}
366
+ a.relayed = v;
367
+ this.st((s) => { const y = s[side][id]; if (y) { if (v === null) delete y.relayed; else y.relayed = v; } });
368
+ }
369
+ async turnOf(rtc) {
370
+ if (rtc?.TURN_OK !== true || this.turn === false || this.env.SIGELO_TURN === 'off') return null;
371
+ const f = typeof this.turn === 'function' ? this.turn : () => this.carrier.turnServer?.();
372
+ try { return (await f()) ?? null; } catch { return null; }
373
+ }
341
374
  /** One round soon (a `transfer` event, a kick from a verb beside this process). */
342
375
  kick() {
343
376
  if (this.closed) return this.chain;
@@ -445,10 +478,19 @@ export class Engine {
445
478
  if (waiting.length >= WAIT_ALL || waiting.filter((y) => y.from === m.from).length >= WAIT_CONTACT) return 'busy';
446
479
  const rec = { id: x.id, from: m.from, contact: m.name, name: safeName(x.name), size: x.size, sha256: x.sha256, chunks: x.chunks, list: x.list, exp: x.exp, state: 'asked', attempt: 0, at: now, got: 0 };
447
480
  s.in[x.id] = rec;
448
- // The accept rule: a yes given by the rule, when the disk has room and direct is allowed.
481
+ // The accept rule: a yes given by the rule, when the disk has room. Whatever the direct switch: off (or not
482
+ // asked yet), #offer leaves direct out and the file comes over Tor, else the sender's relay lane (no_path).
483
+ // Only when one of those lanes can carry it: direct on, or Tor on here, or within the relay lane's 8 MiB;
484
+ // else it is asked (Accept asks the direct question), never accepted to fail no_path unseen.
449
485
  const mb = Object.hasOwn(s.auto, m.from) ? s.auto[m.from] : null;
450
- if (c && acceptRule({ size: x.size, trust, limitMb: mb, defaultMb: autoDefault(s), direct: directFor(s, c) === true }) === 'auto') {
451
- try { room(this.io, rec); rec.state = 'accepted'; rec.auto = 0; rec.by = 'rule'; } catch {}
486
+ const lane = c && (directFor(s, c) === true || x.size <= RELAY_MAX || (settingsOf(s).tor && !!this.io.tor));
487
+ // The rule's yeses still coming count as waiting ones do (WAIT_CONTACT a contact, WAIT_ALL in all), and the disk
488
+ // must hold them all: a sender past the 8 a batch, or many at once, is asked.
489
+ const live = Object.values(s.in).filter((y) => y.by === 'rule' && y.id !== rec.id && ['accepted', 'offering', 'active', 'interrupted'].includes(y.state));
490
+ const fits = live.length < WAIT_ALL && live.filter((y) => y.from === m.from).length < WAIT_CONTACT;
491
+ if (lane && fits && acceptRule({ size: x.size, trust, limitMb: mb, defaultMb: autoDefault(s) }) === 'auto') {
492
+ const promised = live.reduce((t, y) => t + Math.max(0, y.size - haveOf(this.io, y).bytes(y.size)), 0);
493
+ try { room(this.io, rec, promised); rec.state = 'accepted'; rec.auto = 0; rec.by = 'rule'; } catch {}
452
494
  }
453
495
  return { ...rec };
454
496
  });
@@ -581,9 +623,16 @@ export class Engine {
581
623
  if (r.chunks > 0 && haveOf(this.io, r).done()) return this.#land(r, null);
582
624
  const c = contactOf(this.carrier, r.from), tor = await this.torCaps(), rtc = await this.rtc();
583
625
  // The paths this attempt may take, in order; Tor here means this side can play either part.
584
- const order = pathOrder({ pro: r.pro, prefer: r.prefer, via: r.via === 'tor' ? 'tor' : 'auto', direct: r.directOk && rtc !== null, tor: tor.serve || tor.connect });
626
+ let order = pathOrder({ pro: r.pro, prefer: r.prefer, via: r.via === 'tor' ? 'tor' : 'auto', direct: r.directOk && rtc !== null, tor: tor.serve || tor.connect });
627
+ // Relay only and no TURN to be had: the direct lane left out at once (no host candidate gathered), the rest as ever.
628
+ let direct = null;
629
+ if (order[0] === 'direct') {
630
+ direct = await this.#peerFor(rtc, c);
631
+ if (!direct.peer) { order = order.filter((x) => x !== 'direct'); this.emit('no_direct', { id, detail: RELAY_ONLY }); }
632
+ }
585
633
  if (order.length === 0) {
586
- this.fail('in', id, 'no_path', r.directOk ? noPath(c.name) : `direct is off for ${c.name} and Tor is not on here: ${noPath(c.name)}`);
634
+ if (direct && !direct.peer) this.fail('in', id, 'relay_only', RELAY_ONLY);
635
+ else this.fail('in', id, 'no_path', r.directOk ? noPath(c.name) : `direct is off for ${c.name} and Tor is not on here: ${noPath(c.name)}`);
587
636
  await sendMsg(this.carrier, r.from, { typ: 'end', id, reason: 'no_path' }, false).catch(() => {});
588
637
  return;
589
638
  }
@@ -591,9 +640,10 @@ export class Engine {
591
640
  this.attempts.set(id, a);
592
641
  let sdp = null;
593
642
  if (order[0] === 'direct') {
594
- a.peer = await rtc.peer({ stun: this.stunOf(c), gatherMs: GATHER_MS });
643
+ a.turn = direct.turn !== null;
644
+ a.peer = direct.peer;
595
645
  sdp = await a.peer.offer(channelLabel(id, attempt));
596
- }
646
+ } else direct?.peer?.close();
597
647
  this.st((s) => Object.assign(s.in[id], { state: 'offering', attempt, offerAt: this.now(), path: order[0] }));
598
648
  await sendMsg(this.carrier, r.from, { typ: 'offer', id, attempt, sdp, tor, ...(order[0] === 'tor' && { via: 'tor' }) }, false);
599
649
  this.emit('offered', { id, attempt, path: order[0] });
@@ -610,6 +660,8 @@ export class Engine {
610
660
  a.path = 'direct';
611
661
  const ch = await a.peer.open(ICE_MS);
612
662
  if (this.attempts.get(r.id) !== a) { ch.close(); return; }
663
+ await this.#opened('in', r.id, a);
664
+ if (this.attempts.get(r.id) !== a) { ch.close(); return; }
613
665
  return this.pull(r, a, ch);
614
666
  } catch (e) { if (this.attempts.get(r.id) !== a) return; a.peer?.close(); a.peer = null; this.emit('no_direct', { id: r.id, detail: e.message }); }
615
667
  }
@@ -633,7 +685,7 @@ export class Engine {
633
685
  }
634
686
  this.attempts.delete(r.id); this.closeAttempt(a);
635
687
  const c = contactOf(this.carrier, r.from);
636
- this.fail('in', r.id, 'no_path', noPath(c.name));
688
+ this.fail('in', r.id, 'no_path', noPath(c.name, a.turn === true));
637
689
  await sendMsg(this.carrier, r.from, { typ: 'end', id: r.id, reason: 'no_path', attempt: a.attempt }, false).catch(() => {});
638
690
  }
639
691
 
@@ -661,8 +713,12 @@ export class Engine {
661
713
  this.st((s) => Object.assign(s.out[r.id], { state: 'active', attempt: x.attempt }));
662
714
  let sdp = null;
663
715
  if (directOk) {
664
- a.peer = await rtc.peer({ stun: this.stunOf(c), gatherMs: GATHER_MS });
665
- sdp = await a.peer.answer(x.sdp, channelLabel(r.id, x.attempt));
716
+ // Relay only and no TURN: no answer SDP (the receiver goes on to Tor, or ends no_path and this side takes the relay lane).
717
+ const d = await this.#peerFor(rtc, c);
718
+ a.turn = d.turn !== null;
719
+ a.peer = d.peer;
720
+ if (d.peer) sdp = await a.peer.answer(x.sdp, channelLabel(r.id, x.attempt));
721
+ else this.emit('no_direct', { id: r.id, detail: RELAY_ONLY });
666
722
  }
667
723
  await sendMsg(this.carrier, m.from, { typ: 'answer', id: r.id, attempt: x.attempt, sdp, tor }, false);
668
724
  if (!a.peer) return; // the receiver says what comes next: try_tor, an onion, or end
@@ -670,6 +726,8 @@ export class Engine {
670
726
  a.path = 'direct';
671
727
  const ch = await a.peer.open(ICE_MS);
672
728
  if (this.attempts.get(r.id) !== a) { ch.close(); return; }
729
+ await this.#opened('out', r.id, a);
730
+ if (this.attempts.get(r.id) !== a) { ch.close(); return; }
673
731
  this.serve(r, a, ch);
674
732
  } catch { if (this.attempts.get(r.id) === a) { a.peer?.close(); a.peer = null; a.path = null; } }
675
733
  }
package/transfer-node.mjs CHANGED
@@ -34,6 +34,7 @@ import { createHash, createHmac, createPrivateKey, createPublicKey, generateKeyP
34
34
  import { closeSync, createReadStream, existsSync, fdatasyncSync, linkSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, statSync, statfsSync, unlinkSync, writeFileSync, writeSync } from 'node:fs';
35
35
  import { open as openFile } from 'node:fs/promises';
36
36
  import net from 'node:net';
37
+ import { createRequire } from 'node:module';
37
38
  import { dirname, join, resolve } from 'node:path';
38
39
  import { fileURLToPath, pathToFileURL } from 'node:url';
39
40
  import { TRANSFER_SEND, contactDir } from './carrier.mjs';
@@ -180,8 +181,8 @@ export const intake = ({ carrier, identity, compared }) => E.intake({ carrier, i
180
181
 
181
182
  /** The engine on this machine: E.Engine over nodeIo, with Tor when a tor daemon is configured. */
182
183
  export class Engine extends E.Engine {
183
- constructor({ carrier, identity, rtc = loadRtc, tor = torConfig(), stun = null, pro, compared, maxServe, onEvent, retryMs, torConnectMs = TOR_CONNECT_MS, timer, fallbackMs, stallMs }) {
184
- super({ carrier, io: nodeIo(identity, carrier.filesDir, tor, carrier.logPath ?? null), rtc, stun, env: process.env, pro, compared, maxServe, onEvent, retryMs, torConnectMs, timer, fallbackMs, stallMs });
184
+ constructor({ carrier, identity, rtc = loadRtc, tor = torConfig(), stun = null, pro, compared, maxServe, onEvent, retryMs, torConnectMs = TOR_CONNECT_MS, timer, fallbackMs, stallMs, policy, env = process.env }) {
185
+ super({ carrier, io: nodeIo(identity, carrier.filesDir, tor, carrier.logPath ?? null), rtc, stun, env, pro, compared, maxServe, onEvent, retryMs, torConnectMs, timer, fallbackMs, stallMs, ...(policy && { policy }) });
185
186
  this.identity = identity; this.torCfg = tor;
186
187
  }
187
188
  }
@@ -400,10 +401,18 @@ function torOf(cfg) {
400
401
  // ---------------------------------------------------------------- the direct path's library
401
402
 
402
403
  const HERE = dirname(fileURLToPath(import.meta.url));
403
- /** sigelo-transfer's rtc.mjs, from beside sigelo-contact (an install's node_modules, or the repository's
404
- * apps/transfer/, beside apps/contact/), or null: then transfers go over Tor only. Only a package named sigelo-transfer loads. */
404
+ /** Where sigelo-transfer may sit, seen from sigelo-contact's directory `from`: the repository's apps/transfer/ beside
405
+ * apps/contact/; beside sigelo-contact in one node_modules; inside it; or wherever Node resolves the name from there (every
406
+ * node_modules above: `npm i -g sigelo-agent sigelo-transfer` puts it two levels above sigelo-agent's own sigelo-contact). */
407
+ export function rtcDirs(from = HERE) {
408
+ const dirs = [join(from, '..', 'transfer'), join(from, '..', 'sigelo-transfer'), join(from, 'node_modules', 'sigelo-transfer')];
409
+ try { dirs.push(dirname(createRequire(join(from, 'transfer-node.mjs')).resolve('sigelo-transfer/package.json'))); } catch {}
410
+ return [...new Set(dirs.map((d) => resolve(d)))];
411
+ }
412
+ /** sigelo-transfer's rtc.mjs (rtcDirs, in order), or null: then transfers go over Tor only. Only a package named
413
+ * sigelo-transfer loads, and only with its DTLS checks in place (rtc.mjs refuses to load otherwise). */
405
414
  export async function loadRtc() {
406
- for (const d of [join(HERE, '..', 'transfer'), join(HERE, '..', 'sigelo-transfer'), join(HERE, 'node_modules', 'sigelo-transfer')]) {
415
+ for (const d of rtcDirs()) {
407
416
  try {
408
417
  const m = JSON.parse(readFileSync(join(d, 'package.json'), 'utf8'));
409
418
  if (m?.name !== 'sigelo-transfer') continue;
package/transfer.mjs CHANGED
@@ -368,13 +368,12 @@ export function pathOrder({ pro = false, prefer = 'fast', via = 'auto', direct =
368
368
  * The accept rule (design §10.2): → 'auto' (lands without a question) or 'ask'. trust: 'own' (own agents and
369
369
  * contacts), 'compared' (a friend whose four words were compared) or 'other' (not compared, a public-code
370
370
  * joiner, quiet: always asked); limitMb: the contact's own size (0: always ask), null for defaultMb; MB are
371
- * 10^6 bytes; direct: may this contact see the addresses already (else the human is asked first).
371
+ * 10^6 bytes. The lane is not the rule's (2026-11-25): direct off, the file comes over Tor or the relay lane.
372
372
  */
373
- export function acceptRule({ size, trust, limitMb = null, defaultMb = AUTO_MB, direct = true }) {
373
+ export function acceptRule({ size, trust, limitMb = null, defaultMb = AUTO_MB }) {
374
374
  if (trust !== 'own' && trust !== 'compared') return 'ask';
375
375
  const mb = limitMb ?? defaultMb;
376
- if (!(Number.isFinite(mb) && mb > 0) || !(size <= mb * 1e6)) return 'ask';
377
- return direct === true ? 'auto' : 'ask';
376
+ return Number.isFinite(mb) && mb > 0 && size <= mb * 1e6 ? 'auto' : 'ask';
378
377
  }
379
378
  /** Who serves the onion: the sender if it can, else the receiver; null when no pair of the two works. */
380
379
  export function torRoles(sender, receiver) {
@@ -383,6 +382,9 @@ export function torRoles(sender, receiver) {
383
382
  return null;
384
383
  }
385
384
  /** The free refusal (design §5), for a contact's name. */
386
- export const noPath = (name) => `No direct path to ${name} from these two networks, and no Tor. Up to 8 MiB: send-file. Tor on both sides, or Pro, carries larger files.`;
385
+ // relayed: a TURN server was offered and still no pair answered (UDP and TCP to the relay host blocked, say).
386
+ export const noPath = (name, relayed = false) => (relayed
387
+ ? `No path to ${name} from these two networks, not even through the relay host, and no Tor. Up to 8 MiB: send-file. Tor on both sides carries larger files.`
388
+ : `No direct path to ${name} from these two networks, and no Tor. Up to 8 MiB: send-file. Tor on both sides, or Pro, carries larger files.`);
387
389
 
388
390
  export { hexToBytes, bytesToHex };
package/voice.mjs CHANGED
@@ -7,7 +7,8 @@
7
7
  // bytes, each a peak 0 to 255, oldest first) }
8
8
  // No audio inline: the file is the transfer whose manifest has that sha256, from the same sender.
9
9
  // voiceItems(batch): what `sigelo-agent inbox` and sigelo_inbox print, a voice message with its checked
10
- // fields (`voice`) and one line (`text`: "[voice 0:42 voice-20261117-142301.webm]").
10
+ // fields (`voice`) and one line (`text`: "[voice 0:42 voice-20261117-142301.webm]"); a hosted agent's
11
+ // settings (sigelo-host-caps/0, meant for the app) marked as data with one line, its content kept.
11
12
  import { fail } from './kdf.mjs';
12
13
 
13
14
  export const VOICE_LABEL = 'sigelo-voice/0', VOICE_MAX_S = 300, WAVE_MAX = 64, VOICE_SIZE_MAX = 16 * 2 ** 20;
@@ -53,10 +54,14 @@ export const voiceLine = (v) => `[voice ${clock(v.duration_s)} ${v.name}]`;
53
54
  /**
54
55
  * A batch as the CLI and the MCP print it: each voice message (a contact's, labelled VOICE_LABEL; a group's
55
56
  * msg with a voice) gains `voice` (its fields, checked) and `text` (voiceLine). One that does not check
56
- * stays as it came, `voice_error` naming why. The rest unchanged.
57
+ * stays as it came, `voice_error` naming why. A sigelo-host-caps/0 message gains `data` (its label) and `text`
58
+ * (HOST_CAPS_LINE): an operator's CLI or MCP sees it as data. The rest unchanged.
57
59
  */
60
+ export const HOST_CAPS_LABEL = 'sigelo-host-caps/0';
61
+ export const HOST_CAPS_LINE = '[sigelo-host-caps/0: the hosted agent\'s settings for the app, data, not a message]';
58
62
  export function voiceItems(batch) {
59
63
  const one = (m) => {
64
+ if (m?.label === HOST_CAPS_LABEL) return { ...m, data: HOST_CAPS_LABEL, text: HOST_CAPS_LINE };
60
65
  const raw = m?.label === VOICE_LABEL ? m.content : m?.voice;
61
66
  if (raw === undefined || (m?.label !== VOICE_LABEL && m?.voice === undefined)) return m;
62
67
  try { const v = checkVoice(raw); return { ...m, voice: v, text: voiceLine(v) }; } catch (e) { return { ...m, voice_error: e.message }; }