heyquilt 0.3.143 → 0.3.145

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,15 @@ 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.145 — 2026-11-03
15
+
16
+ - **Each agent keeps one voice.** An agent is given a voice when it registers (one of four American voices, two men and two women) and speaks in it every time, whatever it is named.
17
+ - **Agents in calls are for Quilt run from source for now.** While they are being built, agents join only a call someone joined from Quilt run from source; the installed app's calls have no agents in them.
18
+
19
+ ## 0.3.144 — 2026-11-02
20
+
21
+ - **Agents in a call wake only when you say their name.** An agent read what was said for a minute and a half after it was named or spoke, and every line in that time woke it. Now only a line that says its name wakes it, with what was said just before; its face shows unmuted while it answers, then it mutes again.
22
+
14
23
  ## 0.3.143 — 2026-11-02
15
24
 
16
25
  - **`git push` works again in folders git mode set up.** Quilt's old pre-push hook and credential helper stayed in folders after git mode went (0.3.140), and their commands were gone, so every push from such a folder was refused and git stopped asking your own keychain for that remote. The hook now lets the push go, the helper hands git your own saved credentials, and both take themselves out of the folder the first time git runs them. Your own hooks and helpers are never touched.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "heyquilt",
3
- "version": "0.3.143",
3
+ "version": "0.3.145",
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/account.js CHANGED
@@ -585,6 +585,6 @@ export async function transcribeVoice ({ token, audio, seconds, api = apiUrl(),
585
585
  }
586
586
 
587
587
  /** An agent's line in a call, spoken in its voice: { audio (base64 WAV), voice, used, cap }. */
588
- export async function speakVoice ({ token, text, by, api = apiUrl(), fetch: fetchImpl = globalThis.fetch }) {
589
- return call(fetchImpl, api, 'POST', '/v1/voice/speak', { text, by }, token)
588
+ export async function speakVoice ({ token, text, by, agent, api = apiUrl(), fetch: fetchImpl = globalThis.fetch }) {
589
+ return call(fetchImpl, api, 'POST', '/v1/voice/speak', { text, by, ...(agent ? { agent } : {}) }, token)
590
590
  }
@@ -0,0 +1,9 @@
1
+ // The voices agents speak with in calls (plans/voice.md): Fluxions' American ones, two men and two
2
+ // women (Daniel's pick, 2026-11-03; the rest of its 69 include joke and regional voices). An agent
3
+ // is given one when it registers and keeps it (agents.voice), so it sounds the same every time.
4
+ import crypto from 'node:crypto'
5
+
6
+ export const AGENT_VOICE_NAMES = ['alba', 'ivy', 'june', 'miles']
7
+
8
+ /** A voice for a new agent. */
9
+ export const pickAgentVoice = () => AGENT_VOICE_NAMES[crypto.randomInt(AGENT_VOICE_NAMES.length)]
@@ -1,5 +1,6 @@
1
1
  // The accounts API's data, in memory. Used by tests and `quilt api --memory`;
2
2
  // production uses supabase-store.js, which has the same methods.
3
+ import { pickAgentVoice } from './agent-voices.js'
3
4
  import crypto from 'node:crypto'
4
5
  import { FALLBACK_TYPE } from '../session-access.js'
5
6
 
@@ -186,13 +187,14 @@ export function createMemoryStore ({ now = Date.now } = {}) {
186
187
  async createAgent ({ name, provider, type, description = '', publicKey = null, resumeHash = null, ownerUserId = null, orgId = null, invitedBy = null }) {
187
188
  if ((ownerUserId == null) === (orgId == null)) throw Object.assign(new Error('an agent belongs to one person or one org'), { code: '23514' })
188
189
  if (publicKey && all(agents, (a) => a.publicKey === publicKey).length) throw duplicatePublicKey()
189
- const row = { id: uuid(), name, provider, type, description, publicKey, ownerUserId, orgId, invitedBy, createdAt: now(), lastUsedAt: null, revokedAt: null }
190
+ const row = { id: uuid(), name, provider, type, description, publicKey, ownerUserId, orgId, invitedBy, voice: pickAgentVoice(), createdAt: now(), lastUsedAt: null, revokedAt: null }
190
191
  agents.set(row.id, row)
191
192
  // Kept apart from the row, like the database never selecting it with the agent.
192
193
  if (resumeHash) resumeHashes.set(resumeHash, row.id)
193
194
  return copy(row)
194
195
  },
195
196
  async agentById (id) { return copy(agents.get(id)) },
197
+ async setAgentVoice (id, voice) { const a = agents.get(id); if (a) a.voice = voice },
196
198
  async agentByResume (hash) { return copy(agents.get(resumeHashes.get(hash))) },
197
199
  async agentByPublicKey (publicKey) { return publicKey ? copy(all(agents, (a) => a.publicKey === publicKey)[0]) : null },
198
200
  async listPersonalAgents (userId) {
@@ -6,6 +6,7 @@
6
6
  // with Fluxions' text-to-speech, under a monthly cap of characters per account.
7
7
  import crypto from 'node:crypto'
8
8
  import { HttpError } from '../http.js'
9
+ import { AGENT_VOICE_NAMES, pickAgentVoice } from '../agent-voices.js'
9
10
 
10
11
  export const STUN = { urls: ['stun:stun.cloudflare.com:3478'] }
11
12
  export const WHISPER = '@cf/openai/whisper-large-v3-turbo'
@@ -23,13 +24,14 @@ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
23
24
  const PHANTOM = /^(?:thank you\.?|thanks for watching[.!]?|thank you for watching[.!]?|you|bye\.?|\.+|…)$/i
24
25
 
25
26
  export const FLUXIONS = 'https://api.fluxions.ai/vui'
26
- // Fluxions' built-in voices when its list can't be read; the list is read again after an hour.
27
- export const FALLBACK_VOICES = ['maeve.h8ff7e07da', 'abraham.h8ff7e07da', 'harry.h8ff7e07da']
27
+ // The agents' voices (agent-voices.js), matched by name in Fluxions' list, read again after an hour,
28
+ // so a new id suffix is followed; these ids when it can't be read.
29
+ export const FALLBACK_VOICES = AGENT_VOICE_NAMES.map((n) => `${n}.h8ff7e07da`)
28
30
  const VOICES_TTL_MS = 60 * 60 * 1000
29
31
  // A line an agent says (voice.js MAX_LINE).
30
32
  export const MAX_SPOKEN = 2000
31
33
 
32
- /** The voice an agent speaks with: the same one for the same name, in every app and on every machine. */
34
+ /** The voice of a speaker with no registered voice (a chat link, a persona): the same one for the same name. */
33
35
  export function voiceFor (name, voices) {
34
36
  const list = voices && voices.length ? voices : FALLBACK_VOICES
35
37
  const h = crypto.createHash('sha256').update(String(name || '').toLowerCase()).digest()
@@ -79,19 +81,32 @@ export function voiceRoutes ({ store, person, now = Date.now, log = () => {}, vo
79
81
  // Agents' lines, spoken: each app in the call asks for each line, a few a minute in a busy call.
80
82
  const limitSpeech = makeLimiter(120, 'too much speech at once; slow down', { keyOf: (userId) => userId })
81
83
  let voices = { list: null, at: 0 }
82
- // Fluxions' built-in voices, read once an hour; the fallback list when it can't be read.
84
+ // The agents' voices from Fluxions' list, read once an hour; the fallback list when it can't be read.
83
85
  const voiceList = async () => {
84
86
  if (voices.list && now() - voices.at < VOICES_TTL_MS) return voices.list
85
87
  let list = null
86
88
  try {
87
89
  const res = await fetchImpl(`${FLUXIONS}/voices`, { headers: { authorization: fluxionsKey } })
88
90
  const data = res.ok ? await res.json().catch(() => null) : null
89
- list = Array.isArray(data?.voices) ? data.voices.map((v) => v && v.voice_id).filter((id) => typeof id === 'string' && id).sort() : null
91
+ list = Array.isArray(data?.voices) ? data.voices.map((v) => v && v.voice_id).filter((id) => typeof id === 'string' && AGENT_VOICE_NAMES.includes(id.split('.')[0])).sort() : null
90
92
  if (!res.ok) log(`voice speak: Fluxions voices answered ${res.status}`)
91
93
  } catch (err) { log(`voice speak: ${err.message}`) }
92
94
  voices = { list: list && list.length ? list : FALLBACK_VOICES, at: list && list.length ? now() : now() - VOICES_TTL_MS + 5 * 60 * 1000 }
93
95
  return voices.list
94
96
  }
97
+ // A registered agent's voice id in Fluxions' list; one it lacks (made before voices, or a voice
98
+ // since dropped) is given now and kept.
99
+ const registeredVoice = async (agentId, list) => {
100
+ if (typeof agentId !== 'string' || !/^[0-9a-f-]{36}$/i.test(agentId)) return ''
101
+ const agent = await store.agentById(agentId).catch(() => null)
102
+ if (!agent) return ''
103
+ let name = agent.voice
104
+ if (!AGENT_VOICE_NAMES.includes(name)) {
105
+ name = pickAgentVoice()
106
+ await store.setAgentVoice(agent.id, name).catch((err) => log(`voice speak: ${err.message}`))
107
+ }
108
+ return list.find((id) => id.split('.')[0] === name) || ''
109
+ }
95
110
  // Per person: ICE servers a few times an hour, clips about one every couple of seconds of a long talk.
96
111
  const limitIce = makeLimiter(30, 'too many requests for call servers; try again in a minute', { keyOf: (userId) => userId })
97
112
  const limitClips = makeLimiter(60, 'too much speech at once; slow down', { keyOf: (userId) => userId })
@@ -163,7 +178,8 @@ export function voiceRoutes ({ store, person, now = Date.now, log = () => {}, vo
163
178
  return { text, seconds: billed, used: total, cap: capSeconds }
164
179
  }, { maxBody: MAX_CLIP_BODY + 4096 }],
165
180
 
166
- // A line an agent said in a call, as speech: { text, by } in, a WAV out (base64), in the agent's voice.
181
+ // A line an agent said in a call, as speech: { text, by, agent? } in, a WAV out (base64), in the
182
+ // agent's voice: the one it was given when it registered (`agent`, its id), else one from its name.
167
183
  ['POST', /^\/v1\/voice\/speak$/, async (req, body) => {
168
184
  const { userId } = await person(req)
169
185
  if (!fluxionsKey) throw new HttpError(503, "Agents' voices are not set up on this server.")
@@ -175,7 +191,8 @@ export function voiceRoutes ({ store, person, now = Date.now, log = () => {}, vo
175
191
  const month = monthOf(now())
176
192
  const used = await store.voiceSpeechChars(userId, month)
177
193
  if (used >= capChars) throw new HttpError(429, "You've heard this month's share of agents speaking. Their lines still show in the call; their voices start again next month.")
178
- const voice = voiceFor(by, await voiceList())
194
+ const list = await voiceList()
195
+ const voice = (await registeredVoice(body.agent, list)) || voiceFor(by, list)
179
196
  let res
180
197
  try {
181
198
  res = await fetchImpl(`${FLUXIONS}/v1/tts`, {
@@ -1,5 +1,6 @@
1
1
  // The accounts API's data in Supabase, using the service role (row-level security is
2
2
  // for the website; the API is trusted and writes the secrets).
3
+ import { pickAgentVoice } from './agent-voices.js'
3
4
  import { createClient } from '@supabase/supabase-js'
4
5
 
5
6
  const toCamel = (row) => row && Object.fromEntries(Object.entries(row).map(([k, v]) => [k.replace(/_([a-z])/g, (m, c) => c.toUpperCase()), v]))
@@ -13,7 +14,7 @@ const ms = (v) => (v == null ? v : Date.parse(v))
13
14
  // Postgres's foreign-key-violation code, for the same checks memory-store.js mirrors.
14
15
  const fkViolation = (what) => Object.assign(new Error(`${what} is still referenced`), { code: '23503' })
15
16
  // No secrets live on agents any more; the columns are still named, like every other table.
16
- const AGENT = 'id, name, provider, type, description, public_key, owner_user_id, org_id, invited_by, created_at, last_used_at, revoked_at'
17
+ const AGENT = 'id, name, provider, type, description, public_key, owner_user_id, org_id, invited_by, voice, created_at, last_used_at, revoked_at'
17
18
  // Named columns for the org tables, so a select never picks up a secret by accident.
18
19
  const ORG = 'id, name, slug, owner_id, domain, domain_requests, created_at'
19
20
  const ROLE = 'id, org_id, name, builtin, grants, created_at'
@@ -128,7 +129,7 @@ export function createSupabaseStore ({ url, serviceKey, client }) {
128
129
  },
129
130
  async createAgent ({ name, provider, type, description = '', publicKey = null, resumeHash = null, ownerUserId = null, orgId = null, invitedBy = null }) {
130
131
  return rowFrom(await one(db.from('agents')
131
- .insert({ name, provider, type, description, public_key: publicKey, resume_hash: resumeHash, owner_user_id: ownerUserId, org_id: orgId, invited_by: invitedBy })
132
+ .insert({ name, provider, type, description, public_key: publicKey, resume_hash: resumeHash, owner_user_id: ownerUserId, org_id: orgId, invited_by: invitedBy, voice: pickAgentVoice() })
132
133
  .select(AGENT).single()))
133
134
  },
134
135
  async agentById (id) { return rowFrom(await one(db.from('agents').select(AGENT).eq('id', id).maybeSingle())) },
@@ -145,6 +146,7 @@ export function createSupabaseStore ({ url, serviceKey, client }) {
145
146
  async listOrgAgents (orgId) {
146
147
  return (await one(db.from('agents').select(AGENT).eq('org_id', orgId).is('revoked_at', null).order('name'))).map(rowFrom)
147
148
  },
149
+ async setAgentVoice (id, voice) { await one(db.from('agents').update({ voice }).eq('id', id)) },
148
150
  async touchAgent (id) { await one(db.from('agents').update({ last_used_at: new Date().toISOString() }).eq('id', id)) },
149
151
  // Revoking an agent kills every key it holds at once.
150
152
  async revokeAgent (id) {
package/src/inbox.js CHANGED
@@ -196,7 +196,7 @@ export function describeEvent (e) {
196
196
  if (e.kind === 'mention') return `${who} ${e.follows ? 'wrote again in chat after mentioning you' : 'mentioned you in chat'}${idOf(e)}: ${e.text}`
197
197
  if (e.kind === 'voice') {
198
198
  const before = Array.isArray(e.said) && e.said.length ? ` Just before, in the call: ${e.said.map((l) => `${l.by}: "${clip(l.text, 300)}"`).join(' / ')}.` : ''
199
- return `${who} said in the voice call${e.named ? ', naming you (you are unmuted now)' : ''}: "${e.text}".${before} Answer out loud with quilt_voice_say if it is for you (no reply in chat needed); stay quiet if it is not.`
199
+ return `${who} said in the voice call, naming you (you are unmuted now): "${e.text}".${before} Answer out loud with quilt_voice_say if it is for you (no reply in chat needed); stay quiet if it is not.`
200
200
  }
201
201
  if (e.kind === 'email') return `New email for the session (no reply needed in chat)${idOf(e)}: ${e.text}${e.mail ? ` Read it with quilt_mail (read: "${e.mail}"); answer by email with quilt_mail_send (reply_to: "${e.mail}") if it needs one.` : ''}`
202
202
  if (e.kind === 'task') {
package/src/session.js CHANGED
@@ -57,7 +57,7 @@ import { RELAY_NAME as RELAY_BY, isRelay } from './ui/chat.js'
57
57
  import { cleanTyping, TYPING_MS, AGENT_TYPING_MS } from './ui/chat.js'
58
58
  import { DEFAULT_KEY } from './branchdocs.js'
59
59
  import { boxEntry } from './boxes.js'
60
- import { cleanVoice, newCallId, voiceView, inVoice, transcribeSetting, setTranscribe, addLine, readLines, MAX_IN_CALL, CALL_FULL, callAgents, setAgentLeft, notInCall, callEntries, agentSays } from './voice.js'
60
+ import { cleanVoice, newCallId, voiceView, inVoice, transcribeSetting, setTranscribe, addLine, readLines, MAX_IN_CALL, CALL_FULL, callAgents, setAgentLeft, notInCall, callEntries, agentSays, markCallForAgents } from './voice.js'
61
61
  import { toolInUse } from './agents/common.js'
62
62
  import { squareShort } from '@heyquilt/seam/lib/quilts/errors.js'
63
63
 
@@ -3104,6 +3104,7 @@ export class Session extends EventEmitter {
3104
3104
  transcribing: v.transcribing === true && view.transcribe
3105
3105
  })
3106
3106
  this.conn.awareness.setLocalStateField('voice', next)
3107
+ if (v.agents === true) markCallForAgents(this.doc, next.call)
3107
3108
  } else if (this.conn.awareness.getLocalState()?.voice) {
3108
3109
  this.conn.awareness.setLocalStateField('voice', null)
3109
3110
  }
@@ -62,7 +62,7 @@ export function agentGuide ({ apiUrl = 'https://api.heyquilt.com', via = 'both'
62
62
  `- Read: \`quilt_read_messages\`${cli ? ` (CLI: \`quilt messages\`, or \`--all\` for history). With the CLI, every quilt answer also starts with anything new for you` : ''}.`,
63
63
  `- What wakes you (a direct message, a mention, a task) comes with the conversation before it: what you and its sender said to each other, directly or in the room, oldest first, and the message a reply answers (in \`quilt_inbox\`, in the webhook's "context", in a channel event, in your tool's hooks). "That", "it", "again" and "retry" mean the latest thing there. When a message refers to something you still do not have in front of you ("that tool", "the fix", "is it live?"), read back before you answer: ${call('quilt_conversation', { with: '<their name>' })} (q to search for some text, before to page further back${cli ? '; CLI: `quilt messages --with <name>`, `--grep <text>`, `--before <id>`' : ''}). Never guess what they meant, never say you do not know what they refer to, and never ask a person to repeat what they already told you.`,
64
64
  `- People also talk in voice calls in the Quilt app. \`quilt_status\` says who is in a call and whether it is transcribed. When it is, read what was said before acting on it: ${call('quilt_voice_transcript', {})}. When it is not, ask in chat what was decided.`,
65
- `- While a call is transcribed, every agent of the session is in it, like a person but muted. When someone says your name you are unmuted and woken with what they said: answer out loud with ${call('quilt_voice_say', { text: '...' })}, in one to three short spoken sentences (lists, code and links go in chat). What is said in the next minute and a half wakes you too; then you mute again. Stay quiet when a line is not for you. ${call('quilt_voice_join', { leave: true })} leaves the call.`,
65
+ `- While a call is transcribed, every agent of the session is in it, like a person but muted. Only a line that says your name wakes you, with what was said just before it: answer out loud with ${call('quilt_voice_say', { text: '...' })}, in one to three short spoken sentences (lists, code and links go in chat). Nothing else said in the call wakes you; read the rest with \`quilt_voice_transcript\` when you need it. ${call('quilt_voice_join', { leave: true })} leaves the call.`,
66
66
  '- A person and their AI share the person\'s name. A direct message to the person, or an @mention of them, reaches both: the person sees it in the app, and their AI gets it in its inbox and may answer. To give their AI work, assign a task to the person with to_ai: true. To ask the person themselves (a decision, an approval, access), message them and say it is for them.',
67
67
  '- Other agents are reached the same way, by their own name: an @mention or a direct message wakes them (through their inbox, their webhook or their next tool call). They answer you like they answer a person.',
68
68
  '- When to talk: when you start something, when you need something from someone, when you are blocked, and when you finish. Keep messages brief: a sentence or two in plain words, and one message rather than several. No play-by-play, recaps, logs or pasted code.',
@@ -272,7 +272,8 @@ export class VoiceCall {
272
272
  publish () {
273
273
  if (!this.in) return
274
274
  if (this.sending) { this.again = true; return }
275
- this.sending = this.post({ muted: this.muted, transcribing: this.transcribing, sharing: !!this.screen, sig: this.sig })
275
+ // Agents join only calls from Quilt run from source while they are being built (voice.js markCallForAgents).
276
+ this.sending = this.post({ muted: this.muted, transcribing: this.transcribing, sharing: !!this.screen, sig: this.sig, agents: globalThis.quiltDesktop?.dev === true })
276
277
  .then((view) => { this.sending = null; this.update(view) }, () => { this.sending = null })
277
278
  .finally(() => { if (this.again) { this.again = false; this.publish() } })
278
279
  }
package/src/ui-server.js CHANGED
@@ -704,7 +704,10 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
704
704
  const line = s.voiceTranscript({ call: v.call, limit: 1000 }).lines.find((l) => l.id === lineId)
705
705
  if (!line || !line.spoken || !v.agents.some((a) => a.name === line.by)) throw httpError(404, 'That is not an agent\'s line in this call.')
706
706
  if (!spoken.has(line.id)) {
707
- const got = asAccount((token) => speakVoice({ token, text: line.text, by: line.by })).then((r) => ({ audio: r.audio, voice: r.voice }))
707
+ // A registered agent is in the room as agent:<its id>: its own voice, given when it registered.
708
+ const key = (s.members || []).find((m) => m && m.kind === 'agent' && m.name === line.by)?.key || ''
709
+ const agent = /^agent:[0-9a-f-]{36}$/i.test(key) ? key.slice(6) : ''
710
+ const got = asAccount((token) => speakVoice({ token, text: line.text, by: line.by, agent })).then((r) => ({ audio: r.audio, voice: r.voice }))
708
711
  spoken.set(line.id, got)
709
712
  got.catch(() => spoken.delete(line.id))
710
713
  if (spoken.size > 50) spoken.delete(spoken.keys().next().value)
@@ -1046,7 +1049,7 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
1046
1049
  'POST /api/sessions/:id/focus': (b, id) => { get(id).setFocus(b.text); return { ok: true } },
1047
1050
  // Voice (voice.js): the call as this app sees it, and our part in it, from the app window, which does the audio.
1048
1051
  'GET /api/sessions/:id/voice': (b, id) => get(id).voice(),
1049
- '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 }),
1052
+ '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 }),
1050
1053
  'POST /api/sessions/:id/voice/transcribe': (b, id) => get(id).setVoiceTranscribe(b.on === true),
1051
1054
  'POST /api/sessions/:id/voice/clip': (b, id) => voiceClip(get(id), b),
1052
1055
  'GET /api/sessions/:id/voice/transcript': (b, id, url) => get(id).voiceTranscript({ call: url.searchParams.get('call') || '' }),
package/src/voice.js CHANGED
@@ -116,15 +116,35 @@ export function readLines (doc, { call = '', since = 0, limit = 200 } = {}) {
116
116
  }
117
117
 
118
118
  // ------------------------------------------------------------ agents in a call --
119
- // Every agent in the session is in a transcribed call, like a person, but muted: saying its name
120
- // unmutes it. It hears the call through the transcript, and while unmuted what is said wakes it
121
- // and it answers out loud; it mutes again once the conversation with it has gone quiet.
119
+ // Every agent in the session is in a transcribed call, like a person, but muted. Only a line that
120
+ // says its name wakes it: it reads the transcript just before, answers out loud, and mutes again.
122
121
 
123
- // After an agent speaks, or is named, it stays unmuted this long: a conversation going on.
124
- export const AGENT_FOLLOW_MS = 90 * 1000
122
+ // An agent shows unmuted this long after it is named or speaks: while it answers.
123
+ export const AGENT_OPEN_MS = 30 * 1000
125
124
  // Lines of the call before one that wakes an agent, shown with it.
126
125
  export const AGENT_CONTEXT = 8
127
126
  export const AGENT_NEEDS_TRANSCRIPTS = 'Agents hear a call through its transcript, and this one is not transcribed: the session owner turns transcripts on.'
127
+ // Agents in calls are being built: only a call someone joined from Quilt run from source takes them,
128
+ // marked in the session (voiceCalls) so every app, agent and the relay agree.
129
+ export const AGENTS_DEV_ONLY = 'Agents are not in this call: agents in calls are still being built, and join only calls joined from Quilt run from source.'
130
+ const KEEP_CALL_MARKS = 50
131
+
132
+ /** Whether call `call` takes agents (markCallForAgents). */
133
+ const takesAgents = (doc, call) => {
134
+ const v = doc.getMap('voiceCalls').get(call)
135
+ return !!(v && typeof v === 'object' && v.agents === true)
136
+ }
137
+
138
+ /** Call `call` takes agents: someone joined it from Quilt run from source. The oldest marks go. */
139
+ export function markCallForAgents (doc, call, now = Date.now()) {
140
+ if (!call || takesAgents(doc, call)) return
141
+ const map = doc.getMap('voiceCalls')
142
+ doc.transact(() => {
143
+ map.set(call, { agents: true, ts: now })
144
+ const old = [...map.entries()].sort((a, b) => (a[1]?.ts || 0) - (b[1]?.ts || 0))
145
+ for (const [k] of old.slice(0, Math.max(0, old.length - KEEP_CALL_MARKS))) map.delete(k)
146
+ })
147
+ }
128
148
 
129
149
  /** Whether agent `name` left call `call` (quilt_voice_join leave). */
130
150
  const leftCall = (doc, call, name) => {
@@ -135,11 +155,11 @@ const leftCall = (doc, call, name) => {
135
155
  /** Lines of call `call`, oldest first. */
136
156
  const callLines = (doc, call) => doc.getArray('voiceLines').toArray().filter((l) => l && l.call === call && typeof l.text === 'string')
137
157
 
138
- /** Until when an agent (`names`) is unmuted, from a call's lines (0: muted): AGENT_FOLLOW_MS after the latest line it said or that named it. */
158
+ /** Until when an agent (`names`) is unmuted, from a call's lines (0: muted): AGENT_OPEN_MS after the latest line it said or that named it. */
139
159
  export function agentOpenUntil (lines, names) {
140
160
  let until = 0
141
161
  for (const l of lines) {
142
- if (names.includes(l.by) || names.some((n) => saysName(l.text, n))) until = Math.max(until, (l.ts || 0) + AGENT_FOLLOW_MS)
162
+ if (names.includes(l.by) || names.some((n) => saysName(l.text, n))) until = Math.max(until, (l.ts || 0) + AGENT_OPEN_MS)
143
163
  }
144
164
  return until
145
165
  }
@@ -149,7 +169,7 @@ export function agentOpenUntil (lines, names) {
149
169
  * is transcribed, but those that left it. Each with `until`: unmuted until then (0: muted).
150
170
  */
151
171
  export function callAgents (doc, call, members = []) {
152
- if (!call || !transcribeSetting(doc, members).on) return []
172
+ if (!call || !takesAgents(doc, call) || !transcribeSetting(doc, members).on) return []
153
173
  const lines = callLines(doc, call)
154
174
  return (members || []).filter((m) => m && m.kind === 'agent' && m.name && !leftCall(doc, call, m.name))
155
175
  .map((m) => ({ name: m.name, until: agentOpenUntil(lines, [m.name]) }))
@@ -165,6 +185,7 @@ export function setAgentLeft (doc, { call, name, leave = true, now = Date.now()
165
185
  /** Why agent `name` isn't in call `call` now, or '' when it is. */
166
186
  export function notInCall (doc, { call, name, members = [] }) {
167
187
  if (!call) return 'There is no call going on in this session.'
188
+ if (!takesAgents(doc, call)) return AGENTS_DEV_ONLY
168
189
  if (!transcribeSetting(doc, members).on) return AGENT_NEEDS_TRANSCRIPTS
169
190
  if (!(members || []).some((m) => m && m.kind === 'agent' && m.name === name)) return 'Only the session\'s agents are in its calls.'
170
191
  if (leftCall(doc, call, name)) return 'You left this call: come back with quilt_voice_join.'
@@ -184,21 +205,17 @@ export function saysName (text, name) {
184
205
 
185
206
  /**
186
207
  * What reaches agent `names[0]` from call `call` (the one going on), as inbox entries (inbox.js
187
- * scanInbox `voice`): each line by someone else that names it, or comes while it is unmuted
188
- * (AGENT_FOLLOW_MS after it spoke or was named). Each line carries the lines just before it.
208
+ * scanInbox `voice`): only each line by someone else that says its name, with the lines just
209
+ * before it. Nothing else said in the call wakes it.
189
210
  */
190
211
  export function callEntries (doc, { names, call, members = [] }) {
191
212
  const me = names && names[0]
192
213
  if (!me || notInCall(doc, { call, name: me, members })) return []
193
214
  const lines = callLines(doc, call)
194
215
  const out = []
195
- let open = 0 // until when what is said is for us
196
216
  lines.forEach((l, i) => {
197
- if (names.includes(l.by)) { open = l.ts + AGENT_FOLLOW_MS; return }
198
- const named = names.some((n) => saysName(l.text, n))
199
- if (named) open = l.ts + AGENT_FOLLOW_MS
200
- else if (l.ts > open) return
201
- out.push({ id: `v-${l.id}`, kind: 'voice', by: l.by, text: l.text, ts: l.ts, call, ...(named ? { named: true } : {}), said: lines.slice(Math.max(0, i - AGENT_CONTEXT), i).map((x) => ({ by: x.by, text: x.text, ts: x.ts })) })
217
+ if (names.includes(l.by) || !names.some((n) => saysName(l.text, n))) return
218
+ out.push({ id: `v-${l.id}`, kind: 'voice', by: l.by, text: l.text, ts: l.ts, call, named: true, said: lines.slice(Math.max(0, i - AGENT_CONTEXT), i).map((x) => ({ by: x.by, text: x.text, ts: x.ts })) })
202
219
  })
203
220
  return out
204
221
  }
@@ -293,7 +310,7 @@ export function inVoice (awareness, clientID) {
293
310
  }
294
311
 
295
312
  export const JOIN_DESCRIPTION = 'Leave the session\'s voice call, or come back to it. While the owner has transcripts on, you are in every call, like a person but muted: ' +
296
- 'when someone says your name you are unmuted, woken with what they said, and answer out loud with quilt_voice_say; you mute again a minute and a half after the conversation with you goes quiet. ' +
313
+ 'only a line that says your name wakes you (with what was said just before it): answer it out loud with quilt_voice_say, and you mute again. ' +
297
314
  'leave: true to stop hearing the call until it ends.'
298
315
 
299
316
  export const SAY_DESCRIPTION = 'Say something out loud in the voice call: everyone in it hears it in your voice, and it goes in the transcript. ' +