heyquilt 0.3.185 → 0.3.186

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/RELEASES.md CHANGED
@@ -11,6 +11,10 @@ Format: `## <version> — <YYYY-MM-DD>`, an optional one-line summary, then bull
11
11
  Lead each bullet with a short bold phrase. Inline `code` and **bold** are rendered;
12
12
  nothing else is.
13
13
 
14
+ ## 0.3.186 — 2026-11-23
15
+
16
+ - **Nothing above the Loom.** The bar over the Loom ("Everyone" and its counts) is gone, so the lanes start at the top. A lane you hid leaves its chip in a row under the lane heads, there only while a lane is hidden: click it to bring the lane back.
17
+
14
18
  ## 0.3.185 — 2026-11-23
15
19
 
16
20
  - **A simpler Loom.** The three switches above the Loom are gone: Chat and Tasks, Detailed and Compact, Lanes and One column. The Loom always shows chat and tasks, every card in full, and a lane for each person (one column when the window is narrow).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "heyquilt",
3
- "version": "0.3.185",
3
+ "version": "0.3.186",
4
4
  "description": "Real-time, tool-agnostic pair vibe coding: sync a project folder live between collaborators using any AI coding tool.",
5
5
  "author": {
6
6
  "name": "Daniel Carmichael",
package/src/session.js CHANGED
@@ -55,7 +55,7 @@ import { cleanTyping, TYPING_MS, AGENT_TYPING_MS } from './ui/chat.js'
55
55
  import { DEFAULT_KEY, validBranchKey } from './branchdocs.js'
56
56
  import { headKey, headName, branchTip, busy as gitBusy, leftoverLock, indexStamp, filesAt, blobAt, treeState, watchGit, SETTLE_MS as GIT_SETTLE_MS, STALE_LOCK_MS, upstreamOf, fetchUpstream, aheadBehind, changesBetween, fastForward, stage, hasBranch, switchBranch, defaultRemote, remoteBranch, follow, adoptRepo, originUrl } from './gitstate.js'
57
57
  import { shareableRemote, repoLabel } from './repo-ref.js'
58
- import { cleanVoice, newCallId, voiceView, inVoice, transcribeSetting, setTranscribe, addLine, readLines, MAX_IN_CALL, CALL_FULL, callAgents, setAgentLeft, notInCall, agentSays, markCallForAgents, namedAgents, callPing, spokenReply, AGENT_REPLY_MS } from './voice.js'
58
+ import { cleanVoice, cleanDmVoice, dmVoiceView, dmCallers, newCallId, voiceView, inVoice, transcribeSetting, setTranscribe, addLine, readLines, MAX_IN_CALL, CALL_FULL, callAgents, setAgentLeft, notInCall, agentSays, markCallForAgents, namedAgents, callPing, spokenReply, AGENT_REPLY_MS } from './voice.js'
59
59
  import { toolInUse } from './agents/common.js'
60
60
 
61
61
  export { applyTextDiff }
@@ -4181,9 +4181,11 @@ export class Session extends EventEmitter {
4181
4181
  /**
4182
4182
  * Joins, updates or leaves the session's voice call (src/voice.js): `v` is null to leave, or
4183
4183
  * { muted, sig, transcribing, sharing } from the app window, which does the audio. Only people talk.
4184
+ * `dm`: a person's name, for the call with them alone (a direct message's call) instead.
4184
4185
  */
4185
- setVoice (v) {
4186
+ setVoice (v, { dm = '' } = {}) {
4186
4187
  if (!this.conn || !this.conn.awareness) throw new Error('Not connected to the codebase yet.')
4188
+ if (dm) return this.setDmVoice(v, String(dm).trim())
4187
4189
  if (v && v.in !== false) {
4188
4190
  if (this.kind === 'agent') throw new Error('Voice is for people: agents read the transcript instead.')
4189
4191
  if (!this.mayTalk()) throw new Error(TALK_REFUSED)
@@ -4199,6 +4201,8 @@ export class Session extends EventEmitter {
4199
4201
  // Speech goes to the transcript only while the owner has it on.
4200
4202
  transcribing: v.transcribing === true && view.transcribe
4201
4203
  })
4204
+ // One call at a time: joining the codebase's leaves a call with one person.
4205
+ if (this.conn.awareness.getLocalState()?.voiceDm) this.conn.awareness.setLocalStateField('voiceDm', null)
4202
4206
  this.conn.awareness.setLocalStateField('voice', next)
4203
4207
  if (v.agents === true) markCallForAgents(this.doc, next.call)
4204
4208
  } else if (this.conn.awareness.getLocalState()?.voice) {
@@ -4208,9 +4212,44 @@ export class Session extends EventEmitter {
4208
4212
  return this.voice()
4209
4213
  }
4210
4214
 
4211
- /** The call as this app sees it (voiceView): who is in, and the signals left for us. */
4212
- voice () {
4215
+ /** Joins, updates or leaves the call with `partner` alone (voice.js dmVoiceView): never transcribed, and nobody else is in it. */
4216
+ setDmVoice (v, partner) {
4217
+ const aw = this.conn.awareness
4218
+ const was = cleanDmVoice(aw.getLocalState()?.voiceDm)
4219
+ if (v && v.in !== false) {
4220
+ if (this.kind === 'agent') throw new Error('Voice is for people: agents read the transcript instead.')
4221
+ if (!this.mayTalk()) throw new Error(TALK_REFUSED)
4222
+ const who = [...this.members, ...[...aw.getStates().values()].filter((s) => s && s.name)].find((m) => m.name === partner)
4223
+ if (!who || who.kind === 'agent' || partner === this.name) throw new Error(`${partner || 'That'} is not a person in this codebase you can call.`)
4224
+ const same = was && was.with === partner ? was : null
4225
+ const view = this.voice({ dm: partner })
4226
+ const next = cleanDmVoice({
4227
+ ...v,
4228
+ in: true,
4229
+ with: partner,
4230
+ since: same ? same.since : Date.now(),
4231
+ call: same ? same.call : (view.peers[0] && view.peers[0].call) || newCallId()
4232
+ })
4233
+ // One call at a time: a call with one person leaves the codebase's.
4234
+ if (aw.getLocalState()?.voice) aw.setLocalStateField('voice', null)
4235
+ aw.setLocalStateField('voiceDm', next)
4236
+ } else if (was && was.with === partner) {
4237
+ aw.setLocalStateField('voiceDm', null)
4238
+ }
4239
+ this.scheduleStatusWrite()
4240
+ return this.voice({ dm: partner })
4241
+ }
4242
+
4243
+ /** The calls with one person that are going on for us: { name: its view }, ours and anyone's who is calling us. */
4244
+ voiceDms () {
4245
+ if (!this.conn || !this.conn.awareness) return {}
4246
+ return Object.fromEntries(dmCallers({ awareness: this.conn.awareness, clientID: this.doc.clientID, name: this.name }).map((n) => [n, this.voice({ dm: n })]))
4247
+ }
4248
+
4249
+ /** The call as this app sees it (voiceView): who is in, and the signals left for us. `dm`: the call with that person alone. */
4250
+ voice ({ dm = '' } = {}) {
4213
4251
  if (!this.conn || !this.conn.awareness) return { me: 0, in: false, muted: false, call: '', transcribe: false, peers: [] }
4252
+ if (dm) return dmVoiceView({ awareness: this.conn.awareness, clientID: this.doc.clientID, name: this.name, partner: dm })
4214
4253
  return voiceView({ awareness: this.conn.awareness, clientID: this.doc.clientID, members: this.members, doc: this.doc })
4215
4254
  }
4216
4255
 
package/src/ui/loom.css CHANGED
@@ -12,8 +12,6 @@
12
12
  .loom-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
13
13
  .loom-title b { font-weight: 600; font-size: 14px; }
14
14
  .loom-title .hint { font-size: 12px; color: var(--muted); white-space: nowrap; }
15
- .loom-live { display: inline-flex; align-items: center; gap: 5px; color: var(--accent); font-weight: 600; }
16
- .loom-live .pulse { width: 7px; height: 7px; }
17
15
  .loom-bar .spacer { flex: 1; }
18
16
  .loom-seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 4px; overflow: hidden; }
19
17
  .loom-seg .loom-chip { border: 0; border-radius: 0; }
@@ -23,6 +21,9 @@
23
21
  .loom-chip:hover { color: var(--text); }
24
22
  .loom-chip.on { background: var(--panel-2); color: var(--text); }
25
23
  .loom-chip.off { border-style: dashed; }
24
+ /* lanes you hid: a row of chips under the lane heads, there only while a lane is hidden */
25
+ .loom-hidden { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 8px 18px; border-bottom: 1px solid var(--border); }
26
+ .loom-hidden .hint { font-size: 12px; color: var(--muted); }
26
27
 
27
28
  /* ---------- lanes ---------- */
28
29
  .loom-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; position: relative; scrollbar-width: thin; } /* lanes fold to fit, so never sideways */
package/src/ui/loom.js CHANGED
@@ -114,18 +114,14 @@ function loomHtml (m, { prefs, me, names, meAgent, merged }) {
114
114
  const WIDTH = { open: 'minmax(250px, 1fr)', strip: '46px', crowd: '58px', merged: 'minmax(0, 1fr)' }
115
115
  const cols = m.columns.length ? m.columns.map((c) => WIDTH[c.kind]).join(' ') : 'minmax(0, 1fr)'
116
116
  const colorOf = new Map(lanes.map((l) => [l.name, colorFor(l.name, l.color)]))
117
- const turns = m.items.filter((it) => it.type === 'turn')
118
- const convs = new Set(turns.map((t) => `${t.lane}|${t.conv}`)).size
119
- const working = lanes.filter((l) => l.working).length
120
117
  // One way to look at it: chat and tasks shown, every card in full, a lane per person (one column when narrow).
121
118
  const dens = 'detailed'
122
119
  const hidden = (prefs.hidden || []).filter(Boolean)
123
120
 
124
- const bar = `<div class="loom-bar">
125
- <div class="loom-title"><b>Everyone</b><span class="hint">${convs} conversation${convs === 1 ? '' : 's'} · ${m.files.size} file${m.files.size === 1 ? '' : 's'} changed${working ? ` · <span class="loom-live"><span class="pulse"></span>${working} working</span>` : ''}</span></div>
126
- <span class="spacer"></span>
127
- ${hidden.map((n) => `<button class="loom-chip off" data-loom-unhide="${esc(n)}" title="Show ${esc(n)}'s lane">${I.eye}<span>${esc(n)}</span></button>`).join('')}
128
- </div>`
121
+ // Nothing sits above the lanes. A lane you hid leaves a chip beside the lane heads, to bring it back.
122
+ const back = hidden.length
123
+ ? `<div class="loom-hidden" role="group" aria-label="Hidden lanes"><span class="hint">Hidden</span>${hidden.map((n) => `<button class="loom-chip off" data-loom-unhide="${esc(n)}" title="Show ${esc(n)}'s lane">${I.eye}<span>${esc(n)}</span></button>`).join('')}</div>`
124
+ : ''
129
125
 
130
126
  const heads = merged
131
127
  ? ''
@@ -172,9 +168,9 @@ function loomHtml (m, { prefs, me, names, meAgent, merged }) {
172
168
  })
173
169
 
174
170
  return `<div class="loom${merged ? ' merged' : ''}${convFocus ? ' following' : ''}" data-density="${dens}">
175
- ${bar}
176
171
  <div class="loom-scroll">
177
172
  ${heads}
173
+ ${back}
178
174
  <div class="loom-grid" role="feed" aria-label="Everyone's AI conversations, chat and task notes" style="grid-template-columns:${cols}">
179
175
  ${parts.join('')}
180
176
  <svg class="loom-stitches" aria-hidden="true"></svg>
@@ -242,7 +242,7 @@ export function codeSideHtml ({ page, name, project, tasks = 0, artifacts = 0, c
242
242
  ${label('channels', 'Channels', chatNew)}
243
243
  <div class="side-sessions pj-rooms">${channel ? `<button type="button" class="${page === 'chat' && !inDm ? 'on' : ''}" data-code-page="chat" data-dm="" title="Everyone working in ${esc(name)}"${page === 'chat' && !inDm ? ' aria-current="page"' : ''}><span class="pj-hash">#</span><span class="nm">${esc(name)}</span>${call ? `<span class="pj-call" title="${call === 1 ? '1 person is' : `${call} people are`} in a call here">${I.headset}${call}</span>` : ''}${chatNew ? `<span class="ct new">${chatNew > 99 ? '99+' : chatNew}</span>` : ''}</button>` : ''}</div>
244
244
  ${dms.length ? `${label('dms', 'Direct messages')}
245
- <div class="side-sessions pj-rooms">${isFolded('dms') && !inDm && !dms.some((t) => t.n) ? '' : dms.filter((t) => !isFolded('dms') || t.name === inDm || t.n).map((t) => `<button type="button" class="${t.name === inDm ? 'on' : ''}" data-dm="${esc(t.name)}" title="You and ${esc(t.name)}"${t.name === inDm ? ' aria-current="page"' : ''}>${avatar(t.name)}<span class="nm">${esc(t.name)}</span>${t.n ? `<span class="ct new">${t.n > 99 ? '99+' : t.n}</span>` : ''}</button>`).join('')}</div>` : ''}
245
+ <div class="side-sessions pj-rooms">${isFolded('dms') && !inDm && !dms.some((t) => t.n || t.call) ? '' : dms.filter((t) => !isFolded('dms') || t.name === inDm || t.n || t.call).map((t) => `<button type="button" class="${t.name === inDm ? 'on' : ''}" data-dm="${esc(t.name)}" title="You and ${esc(t.name)}"${t.name === inDm ? ' aria-current="page"' : ''}>${avatar(t.name)}<span class="nm">${esc(t.name)}</span>${t.call ? `<span class="pj-call" title="${t.call === 1 ? `${esc(t.name)} is calling you` : `You and ${esc(t.name)} are in a call`}">${I.headset}${t.call}</span>` : ''}${t.n ? `<span class="ct new">${t.n > 99 ? '99+' : t.n}</span>` : ''}</button>`).join('')}</div>` : ''}
246
246
  <div class="side-foot side-nav">
247
247
  <button type="button" data-code-team title="People in this codebase"><span class="pj-faces sm">${people.slice(0, 3).map((m) => avatar(m.name, m.color)).join('')}</span><span class="nm">Team</span><span class="ct">${people.length}</span></button>
248
248
  ${canInvite ? `<button type="button" data-code-invite>${I.link}<span class="nm">Invite</span></button>` : ''}
package/src/ui/session.js CHANGED
@@ -26,7 +26,7 @@ import { workspaceFilePicker, artifactsHtml, bindAllFiles } from './files.js'
26
26
  import { sessionAgentsHtml } from './agent-place.js'
27
27
  import { renderCatchUp, bindCatchUp } from './catchup.js'
28
28
  import { heldCard } from './session-words.js'
29
- import { callButtonMarkup, callPinMarkup, screenStageMarkup, mountCall, unmountCall, renderCall, callCards, callCount } from './voice.js'
29
+ import { callButtonMarkup, callPinMarkup, screenStageMarkup, mountCall, unmountCall, renderCall, callCards, callCounts, callScope } from './voice.js'
30
30
  import { codeSideHtml, codeCrumbHtml, sideShut, toggleSideShut, toggleFolded } from './projects.js'
31
31
  import { dmThreads } from './project-model.js'
32
32
 
@@ -219,7 +219,9 @@ export function mountSession (id) {
219
219
  mountCall(id, mounted.signal, () => {
220
220
  const st = sum().status
221
221
  const colors = new Map([...st.peers.map((p) => [p.name, p.color]), [st.me.name, st.me.color]])
222
- return { owner: !!st.access?.owner, me: st.me, colorOf: (n) => colors.get(n) }
222
+ // Who can be called alone: a person in the codebase, never an agent or someone's AI.
223
+ const canCall = (n) => n !== st.me.name && [...st.peers, ...(st.members || [])].some((p) => p.name === n && p.kind !== 'agent' && !p.persona)
224
+ return { owner: !!st.access?.owner, me: st.me, colorOf: (n) => colors.get(n), canCall }
223
225
  }, () => renderMessages(), () => renderCodeSide())
224
226
  bindAccess()
225
227
  bindChanges(id, mounted.signal, { onOpen: (path) => openFile(path, { tab: 'changes' }), close: () => setGitOpen(false), onCount: renderGitChip })
@@ -393,6 +395,12 @@ const pj = () => !!state.workspacesOn
393
395
  const projectHere = () => { const id = sum()?.workspace; return (id && (state.workspaces || []).find((w) => w.id === id)) || null }
394
396
  let codeConns = null // the Connections card while its page shows
395
397
 
398
+ /** Under "Chat": who is in the conversation on screen. With the sidebar, a direct message is the two of you. */
399
+ function chatSub (st) {
400
+ if (pj() && state.to) return `only you and ${state.to}`
401
+ return st.peers.length ? `with ${peopleHere(st).map((p) => p.sessions && p.mine ? 'your AI' : p.name).join(', ')}` : 'just you so far'
402
+ }
403
+
396
404
  function renderCodeSide () {
397
405
  const el = $('#code-side')
398
406
  if (!el || !current || !sum()) return
@@ -402,7 +410,16 @@ function renderCodeSide () {
402
410
  const page = side || (w.mode === 'tasks' ? 'tasks' : 'loom')
403
411
  const open = (st.tasks || []).filter((t) => !t.archived && (t.column === 'todo' || t.column === 'doing')).length
404
412
  const people = [st.me, ...peopleHere(st)]
405
- el.innerHTML = codeSideHtml({ page, name: st.sessionName || basename(sum().dir), project: projectHere(), tasks: open, artifacts: (projectData()?.files || []).filter((f) => f.kind !== 'folder').length, chatNew, people, dms: dmThreads(renderable(state.messages.get(current)), st.me?.name || '').map((t) => ({ ...t, n: dmNew.get(t.name) || 0 })), dmOn: state.to || '', connections: !!state.connectionsOn, canInvite: !!st.access?.owner || st.access?.role !== 'viewer', call: callCount() })
413
+ // A call is in its conversation: the codebase's in the channel, one with a person in your messages with them.
414
+ if (side === 'chat') callScope(state.to || '')
415
+ const calls = callCounts()
416
+ const dms = dmThreads(renderable(state.messages.get(current)), st.me?.name || '').map((t) => ({ ...t, n: dmNew.get(t.name) || 0, call: calls.dms[t.name] || 0 }))
417
+ // Someone calling you has a row, whether or not you have written to each other.
418
+ for (const name of Object.keys(calls.dms)) if (!dms.some((t) => t.name === name)) dms.unshift({ name, ts: Date.now(), n: 0, call: calls.dms[name] })
419
+ // So does the conversation on screen, before anything is written in it.
420
+ if (side === 'chat' && state.to && !dms.some((t) => t.name === state.to)) dms.unshift({ name: state.to, ts: Date.now(), n: 0, call: 0 })
421
+ if ($('#chat-sub')) $('#chat-sub').textContent = chatSub(st)
422
+ el.innerHTML = codeSideHtml({ page, name: st.sessionName || basename(sum().dir), project: projectHere(), tasks: open, artifacts: (projectData()?.files || []).filter((f) => f.kind !== 'folder').length, chatNew, people, dms, dmOn: state.to || '', connections: !!state.connectionsOn, canInvite: !!st.access?.owner || st.access?.role !== 'viewer', call: calls.channel })
406
423
  const root = $('#ws')
407
424
  root.dataset.sidePage = side
408
425
  $('#code-crumb').innerHTML = codeCrumbHtml(projectHere())
@@ -733,7 +750,7 @@ function renderTop () {
733
750
  $('#rename-btn').hidden = !st.access?.owner
734
751
  $('#move-ws-btn').hidden = !(st.access?.owner && state.workspacesOn && (state.workspaces || []).some((w) => w.access === 'edit'))
735
752
  renderTaskButton()
736
- $('#chat-sub').textContent = st.peers.length ? `with ${peopleHere(st).map((p) => p.sessions && p.mine ? 'your AI' : p.name).join(', ')}` : 'just you so far'
753
+ $('#chat-sub').textContent = chatSub(st)
737
754
  }
738
755
 
739
756
  // --------------------------------------------------------------- source control --
@@ -2573,7 +2590,8 @@ function bindChat () {
2573
2590
  input.addEventListener('keydown', (e) => {
2574
2591
  if (e.key === 'Enter' && !e.shiftKey && !e.isComposing && !e.defaultPrevented) { e.preventDefault(); $('#composer').requestSubmit() }
2575
2592
  })
2576
- $('#to-select').onchange = (e) => { state.to = e.target.value; updatePlaceholder() }
2593
+ // With the sidebar, who you write to is the conversation on screen: its row, its messages, its call.
2594
+ $('#to-select').onchange = (e) => { state.to = e.target.value; updatePlaceholder(); if (pj()) { renderCodeSide(); renderMessages() } }
2577
2595
  $('#attach-btn').onclick = () => $('#file-input').click()
2578
2596
  $('#file-input').onchange = (e) => { addFiles(e.target.files); e.target.value = '' }
2579
2597
  $('[data-attach-workspace]')?.addEventListener('click', async () => {
package/src/ui/voice.js CHANGED
@@ -10,11 +10,18 @@ import { VoiceCall } from './voice-call.js'
10
10
  import { screenShown, shareRefused } from './voice-model.js'
11
11
  import { playSound } from './sounds.js'
12
12
 
13
- const views = new Map() // session id -> the call as that session's server sees it
13
+ const views = new Map() // a call's key -> the call as its session's server sees it
14
+ // A call's key: the codebase's own call is its session id; a call with one person (a direct
15
+ // message's) is the session id, a line break, and that person's name.
16
+ const keyOf = (id, to) => to ? `${id}\n${to}` : id
17
+ const sidOf = (key) => key.split('\n')[0]
18
+ const toOf = (key) => key.split('\n')[1] || ''
19
+ const voiceUrl = (key) => `/api/sessions/${sidOf(key)}/voice${toOf(key) ? `?to=${encodeURIComponent(toOf(key))}` : ''}`
14
20
  const EMPTY = { peers: [], transcribe: false, recent: [], calls: [], since: 0, call: '', agents: [] }
15
21
  const FULL = 6 // voice.js MAX_IN_CALL: everyone connects to everyone, so a call holds six
16
- let live = null // { sid, call }: the call this window is in (one at a time)
17
- let shown = null // { id, who, chatChanged }: the session on screen
22
+ let live = null // { sid, call }: the call this window is in (one at a time); `sid` is the call's key
23
+ let shown = null // { id, to, key, who, chatChanged, callChanged }: the session on screen, and whose conversation ('' the channel's)
24
+ const rung = new Set() // calls with one person we were told about, so each says so once
18
25
  let joining = false
19
26
  let asking = false // a transcribed call: what joining means, shown before the microphone opens
20
27
  let options = false // the transcript choices, open in the pinned call
@@ -50,7 +57,7 @@ window.quiltDesktop?.onPickScreen?.((ask) => pickScreen(ask))
50
57
  /** Shows what can be shared (`sources`, or `blocked` when the system doesn't let Quilt see the screen); resolves to the id picked, or null. */
51
58
  export function pickScreen ({ sources = [], blocked = false } = {}) {
52
59
  endPicking(null)
53
- if (!shown || !live || live.sid !== shown.id) return Promise.resolve(null)
60
+ if (!shown || !live || sidOf(live.sid) !== shown.id) return Promise.resolve(null)
54
61
  return new Promise((resolve) => { picking = { sources, blocked, resolve }; renderCall() })
55
62
  }
56
63
 
@@ -66,7 +73,7 @@ function endPicking (id) {
66
73
  * `chatChanged()`: the chat's calls changed, draw its messages again.
67
74
  */
68
75
  export function mountCall (id, signal, who, chatChanged = () => {}, callChanged = () => {}) {
69
- shown = { id, who, chatChanged, callChanged, count: 0 }
76
+ shown = { id, to: '', key: id, who, chatChanged, callChanged, counts: '' }
70
77
  asking = false
71
78
  options = false
72
79
  drawn = ''
@@ -77,30 +84,89 @@ export function mountCall (id, signal, who, chatChanged = () => {}, callChanged
77
84
  $('#self-share')?.addEventListener('click', onClick, { signal })
78
85
  const tick = setInterval(renderCall, 20000) // the call's minutes
79
86
  signal.addEventListener('abort', () => clearInterval(tick))
80
- api('GET', `/api/sessions/${id}/voice`).then((v) => voiceEvent(id, v), () => {})
87
+ api('GET', voiceUrl(id)).then((v) => voiceEvent(id, v), () => {})
81
88
  renderCall()
82
89
  }
83
90
 
84
91
  export function unmountCall () { endPicking(null); shown = null; asking = false; options = false }
85
92
 
86
- /** The call as the app's server sees it now (a `voice` event, or an answer). */
93
+ /**
94
+ * The conversation on screen changed: `to` is a person's name for the call with them alone (a
95
+ * direct message's), '' for the codebase's own. The call button and the pinned call follow it.
96
+ */
97
+ export function callScope (to = '') {
98
+ if (!shown || shown.to === to) return
99
+ shown.to = to
100
+ shown.key = keyOf(shown.id, to)
101
+ asking = false
102
+ options = false
103
+ drawn = ''
104
+ renderCall()
105
+ }
106
+
107
+ /** How many people are in each call of the codebase on screen: { channel, dms: { name: n } } (0 and left out: no call). */
108
+ export function callCounts () {
109
+ const out = { channel: 0, dms: {} }
110
+ if (!shown) return out
111
+ const n = (v) => v ? v.peers.length + (v.in ? 1 : 0) : 0
112
+ out.channel = n(views.get(shown.id))
113
+ for (const [k, v] of views) if (toOf(k) && sidOf(k) === shown.id && n(v)) out.dms[toOf(k)] = n(v)
114
+ return out
115
+ }
116
+
117
+ /** Keeps an answer about one call: the codebase's comes with the calls with one person going on beside it (`dms`). */
118
+ function keep (key, view) {
119
+ if (toOf(key)) { views.set(key, view); return view }
120
+ const { dms, ...own } = view
121
+ views.set(key, own)
122
+ if (dms) {
123
+ for (const k of views.keys()) if (toOf(k) && sidOf(k) === key && !dms[toOf(k)]) views.delete(k)
124
+ for (const [name, v] of Object.entries(dms)) views.set(keyOf(key, name), v)
125
+ }
126
+ return view
127
+ }
128
+
129
+ /** The call as the app's server sees it now (a `voice` event, or an answer): the codebase's, with its `dms`. */
87
130
  export function voiceEvent (id, view) {
88
- views.set(id, view)
89
- // Left in the call by a window that closed or reloaded without leaving: out now.
90
- if (!checked.has(id)) {
91
- checked.add(id)
92
- if (view.in && !(live && live.sid === id)) { api('POST', `/api/sessions/${id}/voice`, { in: false }).then((v) => voiceEvent(id, v), () => {}); return }
131
+ keep(id, view)
132
+ for (const key of [id, ...Object.keys(view.dms || {}).map((n) => keyOf(id, n))]) {
133
+ const v = views.get(key)
134
+ // Left in the call by a window that closed or reloaded without leaving: out now.
135
+ if (!checked.has(key)) {
136
+ checked.add(key)
137
+ if (v.in && !(live && live.sid === key)) { api('POST', voiceUrl(key), { in: false }).then((r) => answered(key, r), () => {}); continue }
138
+ }
139
+ // Someone started a call with us alone: say so once, where it can be answered.
140
+ if (toOf(key) && !v.in && v.peers.length && v.call && !rung.has(v.call)) {
141
+ rung.add(v.call)
142
+ if (shown && shown.id === id && shown.key !== key) toast(`${toOf(key)} is calling you: open your messages with ${toOf(key)} to join.`)
143
+ }
93
144
  }
145
+ changed(id)
146
+ }
147
+
148
+ /** An answer about one call (`key`), from joining, leaving or a setting. */
149
+ function answered (key, view) {
150
+ if (toOf(key)) { keep(key, view); changed(sidOf(key)) } else voiceEvent(key, view)
151
+ }
152
+
153
+ /** What we know of session `id`'s calls changed: the call we're in hears it, and the page draws it. */
154
+ function changed (id) {
94
155
  // The call we're in: it plays the join and leave sounds itself (onPeople), so a relay blip plays neither.
95
- if (live && live.sid === id) { live.call.update(view); speakAgents(id, view) }
96
- if (shown && shown.id === id) {
97
- renderCall()
98
- // A call ended: its card joins the chat. The call going on now changes every few seconds and
99
- // has no card, so it never redraws the chat.
100
- const now = going(view)
101
- const calls = JSON.stringify(view.calls.filter((c) => c.call !== now))
102
- if (calls !== callsDrawn) { callsDrawn = calls; shown.chatChanged() }
156
+ if (live && sidOf(live.sid) === id) {
157
+ const v = views.get(live.sid)
158
+ if (v) { live.call.update(v); if (!toOf(live.sid)) speakAgents(id, v) }
103
159
  }
160
+ if (!shown || shown.id !== id) return
161
+ renderCall()
162
+ const counts = JSON.stringify(callCounts())
163
+ if (counts !== shown.counts) { shown.counts = counts; shown.callChanged() }
164
+ // A call ended: its card joins the chat. The call going on now changes every few seconds and
165
+ // has no card, so it never redraws the chat.
166
+ const view = views.get(id) || EMPTY
167
+ const now = going(view)
168
+ const calls = JSON.stringify(view.calls.filter((c) => c.call !== now))
169
+ if (calls !== callsDrawn) { callsDrawn = calls; shown.chatChanged() }
104
170
  }
105
171
 
106
172
  /** The call going on now, if anyone is in one: its id. */
@@ -114,9 +180,9 @@ async function join (id, transcribing) {
114
180
  try {
115
181
  if (live) await leave()
116
182
  const call = new VoiceCall({
117
- post: (b) => api('POST', `/api/sessions/${id}/voice`, b).then((v) => { views.set(id, v); return v }),
183
+ post: (b) => api('POST', voiceUrl(id), b).then((v) => keep(id, v)),
118
184
  ice: () => api('GET', '/api/voice/ice'),
119
- clip: (b) => api('POST', `/api/sessions/${id}/voice/clip`, b).catch((err) => {
185
+ clip: (b) => api('POST', `/api/sessions/${sidOf(id)}/voice/clip`, b).catch((err) => {
120
186
  // Over the month's minutes, transcripts not set up, or a Quilt server without them yet:
121
187
  // stop sending, and say why once.
122
188
  if (err.status === 429 || err.status === 503 || err.status === 404) {
@@ -129,7 +195,7 @@ async function join (id, transcribing) {
129
195
  }
130
196
  throw err
131
197
  }),
132
- onChange: () => { if (shown && shown.id === id) renderCall() },
198
+ onChange: () => { if (shown && shown.id === sidOf(id)) renderCall() },
133
199
  onPeople: (sound) => playSound(sound, { force: true })
134
200
  })
135
201
  live = { sid: id, call }
@@ -158,7 +224,7 @@ async function leave () {
158
224
  selfClosed = false
159
225
  if (selfVideo) selfVideo.srcObject = null
160
226
  const v = await call.leave().catch(() => null)
161
- if (v) voiceEvent(sid, v)
227
+ if (v) answered(sid, v)
162
228
  playSound('callOut', { force: true })
163
229
  renderCall()
164
230
  }
@@ -166,13 +232,13 @@ async function leave () {
166
232
  // Closing or reloading the window leaves the call (the page can't wait for an answer).
167
233
  window.addEventListener('pagehide', () => {
168
234
  if (!live) return
169
- navigator.sendBeacon(`/api/sessions/${live.sid}/voice?t=${encodeURIComponent(TOKEN || '')}`, new Blob([JSON.stringify({ in: false })], { type: 'application/json' }))
235
+ navigator.sendBeacon(`${voiceUrl(live.sid)}${toOf(live.sid) ? '&' : '?'}t=${encodeURIComponent(TOKEN || '')}`, new Blob([JSON.stringify({ in: false })], { type: 'application/json' }))
170
236
  })
171
237
 
172
238
  async function onClick (e) {
173
239
  const t = e.target.closest('button')
174
240
  if (!t || !shown || !t.closest('#chat-call, #call-pin, #screen-stage, #self-share, .call-card')) return
175
- const id = shown.id
241
+ const id = shown.key
176
242
  const view = views.get(id) || EMPTY
177
243
  const d = t.dataset
178
244
  if (d.callJoin === 'ask') {
@@ -196,7 +262,7 @@ async function onClick (e) {
196
262
  renderCall()
197
263
  } else if (d.screenHide !== undefined) {
198
264
  // Hidden until they stop sharing: everyone sharing now, so another screen doesn't take its place.
199
- for (const p of view.peers) if (p.sharing) hiddenScreens.add(p.id)
265
+ for (const p of ((live && views.get(live.sid)) || view).peers) if (p.sharing) hiddenScreens.add(p.id)
200
266
  renderCall()
201
267
  } else if (d.selfShare) {
202
268
  selfClosed = d.selfShare === 'close'
@@ -221,7 +287,7 @@ async function onClick (e) {
221
287
  renderCall()
222
288
  } else if (d.callOwner) {
223
289
  try {
224
- voiceEvent(id, await api('POST', `/api/sessions/${id}/voice/transcribe`, { on: d.callOwner === 'on' }))
290
+ voiceEvent(shown.id, await api('POST', `/api/sessions/${shown.id}/voice/transcribe`, { on: d.callOwner === 'on' }))
225
291
  } catch (err) { toast(err.message) }
226
292
  } else if (d.callRead) {
227
293
  const c = d.callRead
@@ -229,7 +295,7 @@ async function onClick (e) {
229
295
  else {
230
296
  opened.add(c)
231
297
  if (!full.has(c)) {
232
- try { full.set(c, (await api('GET', `/api/sessions/${id}/voice/transcript?call=${encodeURIComponent(c)}`)).lines) } catch (err) { toast(err.message); opened.delete(c) }
298
+ try { full.set(c, (await api('GET', `/api/sessions/${shown.id}/voice/transcript?call=${encodeURIComponent(c)}`)).lines) } catch (err) { toast(err.message); opened.delete(c) }
233
299
  }
234
300
  }
235
301
  shown.chatChanged()
@@ -290,45 +356,49 @@ function lineHtml (l, colorOf) {
290
356
 
291
357
  /** Rings on whoever speaks now, without redrawing (it changes many times a second). */
292
358
  function paintTalk () {
293
- if (!live || !shown || live.sid !== shown.id) return
359
+ if (!live || !shown || live.sid !== shown.key) return
294
360
  for (const el of document.querySelectorAll('#call-pin [data-face]')) {
295
361
  const k = el.dataset.face
296
362
  el.classList.toggle('talk', k.startsWith('agent:') ? live.call.agentTalking === k.slice(6) : live.call.speaking(k === 'me' ? 'me' : Number(k)))
297
363
  }
298
364
  }
299
365
 
300
- /** How many people are in the call of the codebase on screen (0: no call). */
301
- export const callCount = () => (shown && shown.count) || 0
302
-
303
366
  /** The chat's call button and the pinned call, for the session on screen. */
304
367
  export function renderCall () {
305
368
  const btn = $('#chat-call')
306
369
  const pin = $('#call-pin')
307
370
  if (!btn || !pin || !shown) return
308
- const id = shown.id
371
+ const id = shown.key
372
+ const to = shown.to
309
373
  const view = views.get(id) || EMPTY
310
- const { me, owner, colorOf } = shown.who()
374
+ const who = shown.who()
375
+ const { me, colorOf } = who
376
+ // Transcripts are the codebase's call's: a call with one person is never written down.
377
+ const owner = who.owner && !to
311
378
  // In the call once the microphone is open and the server has us.
312
379
  const here = !!(live && live.sid === id && live.call.in)
313
380
  const elsewhere = !!(live && live.sid !== id)
314
381
  const others = view.peers
315
382
  const c = here ? live.call : null
316
- // How many are in the call, for whoever shows it elsewhere (the channel's row in the sidebar).
317
- const count = others.length + (here ? 1 : 0)
318
- if (count !== shown.count) { shown.count = count; shown.callChanged(count) }
319
- btn.hidden = here || joining || asking || others.length > 0
383
+ // A person can be called; an agent, or someone who is not in the codebase, can't.
384
+ btn.hidden = here || joining || asking || others.length > 0 || !!(to && !(who.canCall && who.canCall(to)))
320
385
  btn.disabled = elsewhere
386
+ btn.title = elsewhere ? 'Leave your other call first' : to ? `Call ${to}` : 'Start a voice call in this codebase'
321
387
  pin.hidden = !(here || joining || asking || others.length)
322
388
  // The latest lines change every few seconds: they're drawn on their own, so the controls above
323
389
  // them (Join, mute, leave) are never redrawn under a click.
324
390
  const lines = here && view.recent.length ? view.recent.map((l) => lineHtml(l, colorOf)).join('') : ''
325
391
  // A screen hidden stays hidden until its person stops sharing; the next time they share, it shows.
326
- for (const pid of [...hiddenScreens]) if (!others.some((p) => p.id === pid && p.sharing)) hiddenScreens.delete(pid)
327
- const showing = here ? screenShown({ peers: others, picked, hidden: hiddenScreens }) : null
328
- renderStage({ here, showing, others, colorOf })
392
+ // The screens are the call's we are in, whichever conversation is on screen: in the channel while
393
+ // in a call with one person, their screen still fills the middle.
394
+ const mine = live && sidOf(live.sid) === shown.id && live.call.in ? live : null
395
+ const sharers = mine ? (views.get(mine.sid) || EMPTY).peers : []
396
+ for (const pid of [...hiddenScreens]) if (!sharers.some((p) => p.id === pid && p.sharing)) hiddenScreens.delete(pid)
397
+ const showing = mine ? screenShown({ peers: sharers, picked, hidden: hiddenScreens }) : null
398
+ renderStage({ here: !!mine, showing, others: sharers, colorOf })
329
399
  // Closing the preview lasts until we stop sharing; the next share shows it again.
330
- if (!c?.sharing) selfClosed = false
331
- renderSelf(c)
400
+ if (!mine?.call.sharing) selfClosed = false
401
+ renderSelf(mine ? mine.call : null)
332
402
  const now = Date.now()
333
403
  const agents = view.agents || []
334
404
  redrawWhenMuted(agents, now)
@@ -351,7 +421,7 @@ export function renderCall () {
351
421
  <div class="cp-two"><button type="button" class="btn sm primary" data-call-join="transcribed">${others.length ? 'Join' : 'Start'}, transcribed</button><button type="button" class="btn sm" data-call-join="plain">${others.length ? 'Join' : 'Start'}, not transcribed</button></div>`
352
422
  } else if (!here) {
353
423
  pin.innerHTML = `<div class="cp-top"><span class="call-dot"></span><span class="call-faces">${others.map((p) => face(p.id, p.name, p.color, p.muted)).join('')}${agentFaces}</span>
354
- <span class="cp-what"><b>${esc(names(others.map((p) => p.name)))} ${others.length === 1 ? 'is' : 'are'} in a call</b><span class="call-sub">${[dur, view.transcribe ? 'transcribed' : '', ...others.filter((p) => p.sharing).map((p) => `${esc(p.name)} sharing a screen`)].filter(Boolean).join(' · ')}</span></span>
424
+ <span class="cp-what"><b>${to ? `${esc(to)} is calling you` : `${esc(names(others.map((p) => p.name)))} ${others.length === 1 ? 'is' : 'are'} in a call`}</b><span class="call-sub">${[dur, view.transcribe ? 'transcribed' : '', ...others.filter((p) => p.sharing).map((p) => `${esc(p.name)} sharing a screen`)].filter(Boolean).join(' · ')}</span></span>
355
425
  <button type="button" class="btn sm primary cp-end" data-call-join="ask" ${elsewhere ? 'disabled title="Leave your other call first"' : others.length >= FULL ? 'disabled title="This call is full: calls hold six people for now."' : ''}>Join</button></div>`
356
426
  } else {
357
427
  const mine = c.transcribing && view.transcribe
@@ -472,7 +542,8 @@ function paintLines (pin, html) {
472
542
 
473
543
  /** Finished calls with a transcript, as cards for the chat: [{ ts, html }], at when each began. */
474
544
  export function callCards (id) {
475
- if (!shown || shown.id !== id) return []
545
+ // The codebase's calls: a conversation with one person shows none.
546
+ if (!shown || shown.id !== id || shown.to) return []
476
547
  const view = views.get(id) || EMPTY
477
548
  const now = going(view)
478
549
  const { colorOf } = shown.who()
package/src/ui-server.js CHANGED
@@ -584,7 +584,7 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
584
584
  let voiceWas = ''
585
585
  const pushVoice = () => {
586
586
  if (runs.get(id) !== entry) return
587
- const voice = s.voice()
587
+ const voice = callView(s)
588
588
  const now = JSON.stringify(voice)
589
589
  if (now !== voiceWas) { voiceWas = now; broadcast('voice', { id, voice }) }
590
590
  }
@@ -741,6 +741,9 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
741
741
  // still connect directly through a public STUN server.
742
742
  const STUN_ONLY = { iceServers: [{ urls: ['stun:stun.cloudflare.com:3478'] }], turn: false }
743
743
  let ice = null
744
+ // The codebase's call with, beside it, the calls with one person going on for us (`dms`); or one of those alone.
745
+ const callView = (s, dm = '') => dm ? s.voice({ dm }) : { ...s.voice(), dms: s.voiceDms() }
746
+
744
747
  async function voiceServers () {
745
748
  if (ice && ice.expiresAt - Date.now() > 10 * 60 * 1000) return ice
746
749
  try {
@@ -1214,8 +1217,13 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
1214
1217
  'POST /api/sessions/:id/say': (b, id) => get(id).say(b.text, { to: b.to || null }),
1215
1218
  'POST /api/sessions/:id/focus': (b, id) => { get(id).setFocus(b.text); return { ok: true } },
1216
1219
  // Voice (voice.js): the call as this app sees it, and our part in it, from the app window, which does the audio.
1217
- 'GET /api/sessions/:id/voice': (b, id) => get(id).voice(),
1218
- 'POST /api/sessions/:id/voice': (b, id) => get(id).setVoice(b.in === false ? null : { muted: b.muted === true, sig: b.sig, transcribing: b.transcribing === true, sharing: b.sharing === true, agents: b.agents === true }),
1220
+ // `?to=<name>`: the call with that person alone (a direct message's), instead of the codebase's.
1221
+ 'GET /api/sessions/:id/voice': (b, id, url) => callView(get(id), url.searchParams.get('to') || ''),
1222
+ 'POST /api/sessions/:id/voice': (b, id, url) => {
1223
+ const dm = url.searchParams.get('to') || ''
1224
+ get(id).setVoice(b.in === false ? null : { muted: b.muted === true, sig: b.sig, transcribing: b.transcribing === true, sharing: b.sharing === true, agents: b.agents === true }, { dm })
1225
+ return callView(get(id), dm)
1226
+ },
1219
1227
  'POST /api/sessions/:id/voice/transcribe': (b, id) => get(id).setVoiceTranscribe(b.on === true),
1220
1228
  'POST /api/sessions/:id/voice/clip': (b, id) => voiceClip(get(id), b),
1221
1229
  'GET /api/sessions/:id/voice/transcript': (b, id, url) => get(id).voiceTranscript({ call: url.searchParams.get('call') || '' }),
package/src/voice.js CHANGED
@@ -58,6 +58,69 @@ export function cleanVoice (raw) {
58
58
  }
59
59
  }
60
60
 
61
+ // ------------------------------------------------------- a call with one person --
62
+ // A direct message's call: the two people in it, nobody else. It rides presence like the
63
+ // codebase's call, in a field of its own (`voiceDm`, with who it is with), so an older app, an
64
+ // agent's status and the codebase's own call never count it. It is never transcribed.
65
+
66
+ /** Our part in a call with one person, cleaned: null when not in one. */
67
+ export function cleanDmVoice (raw) {
68
+ const v = cleanVoice(raw)
69
+ const to = raw && typeof raw.with === 'string' ? raw.with.trim().slice(0, 80) : ''
70
+ if (!v || !to) return null
71
+ const { transcribing, ...rest } = v
72
+ return { ...rest, with: to }
73
+ }
74
+
75
+ /**
76
+ * The call between us (`name`) and `partner`, as one app sees it: voiceView's shape. Only the
77
+ * partner's presence that names us counts, so nobody else is ever a peer.
78
+ */
79
+ export function dmVoiceView ({ awareness, clientID, name, partner }) {
80
+ const mine = cleanDmVoice(awareness.getLocalState()?.voiceDm)
81
+ const me = mine && mine.with === partner ? mine : null
82
+ const peers = []
83
+ const here = []
84
+ for (const [id, s] of awareness.getStates()) {
85
+ if (id === clientID || !s || !s.name) continue
86
+ here.push(id)
87
+ if (s.name !== partner || partner === name) continue
88
+ const v = cleanDmVoice(s.voiceDm)
89
+ if (!v || v.with !== name) continue
90
+ peers.push({ id, name: s.name, color: s.color || '', muted: v.muted, since: v.since, call: v.call, ...(v.sharing ? { sharing: true } : {}), signal: v.sig[String(clientID)] || null })
91
+ }
92
+ peers.sort((a, b) => a.since - b.since || a.id - b.id)
93
+ const starts = [...(me ? [me.since] : []), ...peers.map((p) => p.since)].filter((x) => x > 0)
94
+ return {
95
+ me: clientID,
96
+ in: !!me,
97
+ muted: !!(me && me.muted),
98
+ sharing: !!(me && me.sharing),
99
+ call: me ? me.call : (peers[0] ? peers[0].call : ''),
100
+ since: starts.length ? Math.min(...starts) : 0,
101
+ transcribe: false,
102
+ peers,
103
+ here,
104
+ recent: [],
105
+ calls: [],
106
+ agents: [],
107
+ with: partner
108
+ }
109
+ }
110
+
111
+ /** Everyone we are in a call with, or who is in one with us and waiting: their names, sorted. */
112
+ export function dmCallers ({ awareness, clientID, name }) {
113
+ const out = new Set()
114
+ const mine = cleanDmVoice(awareness.getLocalState()?.voiceDm)
115
+ if (mine) out.add(mine.with)
116
+ for (const [id, s] of awareness.getStates()) {
117
+ if (id === clientID || !s || !s.name || s.name === name) continue
118
+ const v = cleanDmVoice(s.voiceDm)
119
+ if (v && v.with === name) out.add(s.name)
120
+ }
121
+ return [...out].sort()
122
+ }
123
+
61
124
  /** A new call's id, when nobody is in voice yet. */
62
125
  export function newCallId (now = Date.now()) {
63
126
  return `${now.toString(36)}-${crypto.randomBytes(4).toString('hex')}`