heyquilt 0.3.183 → 0.3.185

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/src/ui/home.js CHANGED
@@ -20,6 +20,7 @@ import { feedbackDockHtml, bindFeedback } from './feedback.js'
20
20
  import { openNewCodebase } from './new-session.js'
21
21
  import { projectShellHtml, bindProjectShell } from './projects.js'
22
22
  import { holdProjectBoard } from './project-board.js'
23
+ import { mountConnections } from './connections.js'
23
24
  import { openProjectPop } from './project-pop.js'
24
25
 
25
26
  export const tildify = (p) => state.defaults.home && String(p).startsWith(state.defaults.home) ? `~${String(p).slice(state.defaults.home.length)}` : p
@@ -657,10 +658,11 @@ const SETTINGS_TABS = [['agents', 'Agents', 'bot'], ['git', 'Version control', '
657
658
  // starts with. Your own AI then has a part to itself (Your AI), apart from the agents every project gets.
658
659
  const PROJECT_SETTINGS = [
659
660
  { label: 'You', tabs: [['ai', 'Your AI', 'bot'], ['you', 'Profile', 'user'], ['account', 'Account', 'gear']] },
660
- { label: 'Every project', tabs: [['agents', 'Agents', 'bot'], ['git', 'Version control', 'branch'], ['workspaces', 'Projects', 'grid']] },
661
+ { label: 'Every project', tabs: [['agents', 'Agents', 'bot'], ['connections', 'Connections', 'link'], ['git', 'Version control', 'branch'], ['workspaces', 'Projects', 'grid']] },
661
662
  { label: 'New codebases', tabs: [['session', 'Defaults', 'folder']] }
662
663
  ]
663
- const settingsGroups = () => state.workspacesOn ? PROJECT_SETTINGS : [{ label: '', tabs: SETTINGS_TABS.filter(([id]) => id !== 'workspaces') }]
664
+ // Connections for every project show only while the accounts API has connections on.
665
+ const settingsGroups = () => state.workspacesOn ? PROJECT_SETTINGS.map((g) => ({ ...g, tabs: g.tabs.filter(([id]) => id !== 'connections' || state.connectionsOn) })) : [{ label: '', tabs: SETTINGS_TABS.filter(([id]) => id !== 'workspaces') }]
664
666
  const settingsTabs = () => settingsGroups().flatMap((g) => g.tabs)
665
667
  /** The tab your own AI (the tool on this computer, your cloud AI) is on. */
666
668
  const aiTab = () => state.workspacesOn ? 'ai' : 'agents'
@@ -714,9 +716,10 @@ function settingsHtml (session = null) {
714
716
  const a = state.account || { name: p.name, email: '' }
715
717
  const theme = p.theme || document.documentElement.dataset.theme || 'dark'
716
718
  const tab = settingsTab()
717
- const show = (id) => ({ account: ['account', 'about', 'computer'], you: ['profile', 'appearance', 'sounds'], session: ['sessions'], ai: ['your-ai', 'cloud-ai'], agents: state.workspacesOn ? ['agents'] : ['your-ai', 'cloud-ai', 'agents'], git: ['agents-git'], workspaces: ['workspaces'] })[tab].includes(id)
719
+ const show = (id) => ({ account: ['account', 'about', 'computer'], you: ['profile', 'appearance', 'sounds'], session: ['sessions'], ai: ['your-ai', 'cloud-ai'], agents: state.workspacesOn ? ['agents'] : ['your-ai', 'cloud-ai', 'agents'], git: ['agents-git'], workspaces: ['workspaces'], connections: [] })[tab].includes(id)
718
720
  return `
719
721
  ${tab === 'workspaces' ? workspacesSettingsHtml() : ''}
722
+ ${tab === 'connections' ? '<section class="card settings-sec" id="account-connections-sec"><div class="sec-intro"><h2>Connections for every project</h2><p>Apps the agents in every project of yours can use. Agents never see the logins.</p></div><div class="sec-body"><div data-account-connections></div></div></section>' : ''}
720
723
  ${show('account') ? `<section class="card settings-sec" id="account-sec">
721
724
  <div class="sec-intro"><h2>Account</h2><p>This computer is signed in to your heyquilt.com account.</p></div>
722
725
  <div class="sec-body">
@@ -936,6 +939,8 @@ function bindAgents (root) {
936
939
 
937
940
  /** Wires the settings cards inside `root`; `refresh()` redraws them after a save. */
938
941
  function bindSettings (root, refresh) {
942
+ const own = root.querySelector('[data-account-connections]')
943
+ if (own) mountConnections(own, { type: 'account', id: 'me' })
939
944
  // Projects: Open goes to the project's page (the pop-up closes; the old shell's sidebar binds its own).
940
945
  if (state.workspacesOn) root.querySelectorAll('#workspaces-sec [data-view]').forEach((b) => { b.onclick = () => { $('#settings-back')?.remove(); go(b.dataset.view) } })
941
946
  // Tabs: the pick is kept on this computer, and the cards are drawn again.
package/src/ui/loom.js CHANGED
@@ -60,7 +60,7 @@ export function renderLoom (el, { build, prefs, me, names, meAgent, onAction })
60
60
  if (typing && typing === document.activeElement) return
61
61
  if (!ticker) ticker = setInterval(tickClocks, 30000)
62
62
  const wasLoom = showsLoom(el)
63
- const merged = prefs.layout === 'merged' || (el.clientWidth > 0 && el.clientWidth < MERGE_BELOW)
63
+ const merged = el.clientWidth > 0 && el.clientWidth < MERGE_BELOW
64
64
  lastWidth = el.clientWidth
65
65
  model = build(merged, Math.max(0, el.clientWidth - 14)) // less a scrollbar
66
66
  const html = loomHtml(model, { prefs, me, names, meAgent, merged })
@@ -117,25 +117,14 @@ function loomHtml (m, { prefs, me, names, meAgent, merged }) {
117
117
  const turns = m.items.filter((it) => it.type === 'turn')
118
118
  const convs = new Set(turns.map((t) => `${t.lane}|${t.conv}`)).size
119
119
  const working = lanes.filter((l) => l.working).length
120
- const dens = prefs.density === 'compact' ? 'compact' : 'detailed'
120
+ // One way to look at it: chat and tasks shown, every card in full, a lane per person (one column when narrow).
121
+ const dens = 'detailed'
121
122
  const hidden = (prefs.hidden || []).filter(Boolean)
122
123
 
123
124
  const bar = `<div class="loom-bar">
124
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>
125
126
  <span class="spacer"></span>
126
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('')}
127
- <div class="loom-seg" role="group" aria-label="Show">
128
- <button class="loom-chip${prefs.chat !== false ? ' on' : ''}" data-loom-pref="chat" aria-pressed="${prefs.chat !== false}">${I.chat}<span>Chat</span></button>
129
- <button class="loom-chip${prefs.tasks !== false ? ' on' : ''}" data-loom-pref="tasks" aria-pressed="${prefs.tasks !== false}">${I.board}<span>Tasks</span></button>
130
- </div>
131
- <div class="loom-seg" role="group" aria-label="Detail">
132
- <button class="loom-chip${dens === 'detailed' ? ' on' : ''}" data-loom-density="detailed" aria-pressed="${dens === 'detailed'}">Detailed</button>
133
- <button class="loom-chip${dens === 'compact' ? ' on' : ''}" data-loom-density="compact" aria-pressed="${dens === 'compact'}">Compact</button>
134
- </div>
135
- <div class="loom-seg wide-only" role="group" aria-label="Layout">
136
- <button class="loom-chip${prefs.layout !== 'merged' ? ' on' : ''}" data-loom-layout="lanes" aria-pressed="${prefs.layout !== 'merged'}" title="A lane per person">Lanes</button>
137
- <button class="loom-chip${prefs.layout === 'merged' ? ' on' : ''}" data-loom-layout="merged" aria-pressed="${prefs.layout === 'merged'}" title="One column, in time order">One column</button>
138
- </div>
139
128
  </div>`
140
129
 
141
130
  const heads = merged
@@ -714,9 +703,6 @@ function bind (el) {
714
703
  if ((b = pick('[data-file]'))) return act('file', b.dataset.file)
715
704
  if ((b = pick('[data-loom-hide]'))) return act('hide', b.dataset.loomHide)
716
705
  if ((b = pick('[data-loom-unhide]'))) return act('unhide', b.dataset.loomUnhide)
717
- if ((b = pick('[data-loom-pref]'))) return act('toggle', b.dataset.loomPref)
718
- if ((b = pick('[data-loom-density]'))) return act('density', b.dataset.loomDensity)
719
- if ((b = pick('[data-loom-layout]'))) return act('layout', b.dataset.loomLayout)
720
706
  if (t.closest('a, button')) return
721
707
  if (String(window.getSelection?.() || '')) return // selecting text in a card, not opening it
722
708
  const c = pick('.lc-turn')
@@ -0,0 +1,93 @@
1
+ // A project's channel (projects on): one conversation for everyone in the project, there with no
2
+ // codebase open. The accounts API keeps it (routes/workspace-chat.js); the app asks for what is
3
+ // new every few seconds while a project's page is open. A codebase's own channel is its chat.
4
+ import { I, state, $, esc, api, toast, avatar, clock } from './common.js'
5
+ import { textHtml } from './chat.js'
6
+
7
+ const ASK_MS = 4000
8
+ const chans = new Map() // project id -> { messages, unread, asked, loaded, failed }
9
+ const chan = (id) => { if (!chans.has(id)) chans.set(id, { messages: [], unread: 0, asked: 0, loaded: false, failed: '', draft: '' }); return chans.get(id) }
10
+ let live = null // the channel on the page: { el, id }
11
+
12
+ /** How many messages are new for you in a project's channel, as last heard. */
13
+ export const channelUnread = (id) => chan(id).unread
14
+
15
+ /**
16
+ * Asks for what is new in a project's channel (at most every few seconds; `now` asks at once).
17
+ * `changed()` is called when the count of what is new changes; the open channel draws itself.
18
+ */
19
+ export async function loadChannel (id, changed = () => {}, { now = false } = {}) {
20
+ const c = chan(id)
21
+ if (!now && Date.now() - c.asked < ASK_MS) return
22
+ c.asked = Date.now()
23
+ try {
24
+ const after = c.messages.length ? c.messages[c.messages.length - 1].at : 0
25
+ const r = await api('GET', `/api/workspaces/${encodeURIComponent(id)}/messages${after ? `?after=${after}` : ''}`)
26
+ const had = c.messages.length; const was = c.unread
27
+ const known = new Set(c.messages.map((m) => m.id))
28
+ for (const m of r.messages) if (!known.has(m.id)) c.messages.push(m)
29
+ c.loaded = true; c.failed = ''
30
+ c.unread = r.unread
31
+ const open = live && live.id === id && live.el.isConnected
32
+ if (open && (c.messages.length !== had || !live.drawn)) live.draw()
33
+ // Reading it on the page is reading it: what came in while it is open is not new.
34
+ if (open && c.unread && document.hasFocus()) { c.unread = 0; api('POST', `/api/workspaces/${encodeURIComponent(id)}/messages/read`).catch(() => {}) }
35
+ if (c.unread !== was) changed()
36
+ } catch (err) {
37
+ c.failed = err.message
38
+ if (!c.loaded && live && live.id === id && live.el.isConnected) live.draw()
39
+ }
40
+ }
41
+
42
+ /** Draws a project's channel into `el` and keeps it working. `changed()`: the count of what is new changed (the sidebar shows it). */
43
+ export function mountChannel (el, { d, changed = () => {} }) {
44
+ const id = d.workspace.id
45
+ const c = chan(id)
46
+ const me = state.profile?.name || ''
47
+ const names = () => [...new Set([d.owner?.name, ...(d.members || []).map((m) => m.name), ...(d.agents || []).map((a) => a.name)].filter(Boolean))]
48
+ el.innerHTML = `
49
+ <div class="pj-chan">
50
+ <div class="files-head"><div class="t"><h2 class="crumbs"><span class="pj-hash">#</span>${esc(d.workspace.name)}</h2><p class="hint">Everyone in ${esc(d.workspace.name)} and its agents. It is here with no codebase open.</p></div></div>
51
+ <div class="messages" data-chan-list aria-live="polite"></div>
52
+ <form class="composer" data-chan-form><div class="box"><textarea rows="1" maxlength="8000" placeholder="Message ${esc(d.workspace.name)}…" aria-label="Message ${esc(d.workspace.name)}"></textarea><button type="submit" class="btn primary icon" title="Send" aria-label="Send">${I.send}</button></div></form>
53
+ </div>`
54
+ const list = $('[data-chan-list]', el)
55
+ const box = $('textarea', el)
56
+ const draw = () => {
57
+ const near = list.scrollHeight - list.scrollTop - list.clientHeight < 80
58
+ const all = names()
59
+ list.innerHTML = c.messages.length
60
+ ? c.messages.map((m) => `<div class="msg${m.mine ? ' mine' : ''}"><div style="min-width:0"><div class="head">${m.mine ? '' : avatar(m.by)}<b>${m.mine ? 'You' : esc(m.by)}</b>${m.kind === 'agent' ? `<span class="tag bot">${I.bot}agent</span>` : ''}<span>${esc(clock(m.at))}</span></div><div class="bubble"><div class="text">${textHtml(m.text, all, me)}</div></div></div></div>`).join('')
61
+ : `<div class="day-empty"><div><b>${c.failed ? 'The channel could not be read.' : c.loaded ? 'Say hi.' : 'Loading…'}</b></div><div class="hint">${c.failed ? esc(c.failed) : c.loaded ? `What is written here reaches everyone in ${esc(d.workspace.name)}, whichever codebase they are in.` : ''}</div></div>`
62
+ if (near || !live.drawn) list.scrollTop = list.scrollHeight
63
+ live.drawn = true
64
+ }
65
+ live = { el, id, draw, drawn: false }
66
+ draw()
67
+ const grow = () => { box.style.height = 'auto'; box.style.height = `${Math.min(box.scrollHeight, 160)}px` }
68
+ // The page is drawn again when a codebase's state changes: what was being typed is put back.
69
+ box.value = c.draft
70
+ box.oninput = () => { c.draft = box.value; grow() }
71
+ grow()
72
+ box.onkeydown = (e) => { if (e.key === 'Enter' && !e.shiftKey && !e.isComposing) { e.preventDefault(); $('[data-chan-form]', el).requestSubmit() } }
73
+ $('[data-chan-form]', el).onsubmit = async (e) => {
74
+ e.preventDefault()
75
+ const text = box.value.trim()
76
+ if (!text) return
77
+ box.value = ''; c.draft = ''; grow()
78
+ try {
79
+ const r = await api('POST', `/api/workspaces/${encodeURIComponent(id)}/messages`, { text })
80
+ if (!c.messages.some((m) => m.id === r.message.id)) c.messages.push(r.message)
81
+ draw(); list.scrollTop = list.scrollHeight
82
+ } catch (err) { toast(err.message); if (!box.value) { box.value = text; c.draft = text; grow() } }
83
+ box.focus()
84
+ }
85
+ // Opening it is reading it.
86
+ const read = () => { if (!c.unread) return; c.unread = 0; changed(); api('POST', `/api/workspaces/${encodeURIComponent(id)}/messages/read`).catch(() => {}) }
87
+ loadChannel(id, changed, { now: true }).then(read)
88
+ // Coming back to the window with the channel open is reading it.
89
+ const onFocus = () => { if (!el.isConnected) return window.removeEventListener('focus', onFocus); read() }
90
+ window.addEventListener('focus', onFocus)
91
+ // The cursor goes to the box, unless a pop-up is open over the page.
92
+ if (!document.querySelector('.modal-back')) { box.focus(); box.setSelectionRange(box.value.length, box.value.length) }
93
+ }
@@ -195,3 +195,30 @@ export function projectPeople (d, me = '') {
195
195
  return [...owner, ...(d.members || []).filter((m) => m && !isAgent(m) && !owner.some((o) => o.account === m.account)).map((m) => ({ account: m.account, name: m.name || m.account, access: m.access || 'edit', owner: false }))]
196
196
  .map((m) => ({ ...m, you: !!me && m.account === me }))
197
197
  }
198
+
199
+ // -------------------------------------------------------------- channels --
200
+ /**
201
+ * The people and agents you have direct messages with in a codebase, the latest first:
202
+ * [{ name, ts }]. `messages`: the codebase's chat ({ by, to, ts }); `me`: your name there.
203
+ */
204
+ export function dmThreads (messages = [], me = '') {
205
+ const last = new Map()
206
+ for (const m of messages) {
207
+ if (!m || !m.to || !m.by) continue
208
+ const other = m.by === me ? m.to : m.to === me ? m.by : ''
209
+ if (!other || other === me) continue
210
+ if ((m.ts || 0) >= (last.get(other) ?? -1)) last.set(other, m.ts || 0)
211
+ }
212
+ return [...last].map(([name, ts]) => ({ name, ts })).sort((a, b) => b.ts - a.ts)
213
+ }
214
+
215
+ /**
216
+ * A project's direct messages, across its codebases open here: one row a person, the codebase
217
+ * where you last wrote to each other. `codes`: [{ id, name, messages, me }]. Answers
218
+ * [{ name, ts, code, codeName }], the latest first.
219
+ */
220
+ export function projectDms (codes = []) {
221
+ const best = new Map()
222
+ for (const c of codes) for (const t of dmThreads(c.messages, c.me)) { const b = best.get(t.name); if (!b || t.ts > b.ts) best.set(t.name, { ...t, code: c.id, codeName: c.name }) }
223
+ return [...best.values()].sort((a, b) => b.ts - a.ts)
224
+ }
@@ -444,7 +444,7 @@ export function openProjectPop ({ id, section = 'general', focusInvite = false }
444
444
  if (more) more.onclick = () => { addingAgent = true; pop.redraw() }
445
445
  const fresh = $('[data-agent-new]', el)
446
446
  if (fresh) fresh.onclick = () => { state.settingsTab = 'agents'; openSettings() }
447
- } else if (s === 'connections') mountConnections($('[data-pop-connections]', el), { type: 'workspace', id })
447
+ } else if (s === 'connections') mountConnections($('[data-pop-connections]', el), { type: 'workspace', id, agents: () => (d().agents || []).filter((x) => x.agentId).map((x) => ({ id: x.agentId, name: x.name })) })
448
448
  }
449
449
  })
450
450
  return pop
@@ -4,13 +4,14 @@
4
4
  // (prail.js) moves between projects. home.js draws this in place of its own sidebar and pages.
5
5
  import { I, state, $, esc, ago, api, toast, ask, avatar, COLORS, loadingHtml } from './common.js'
6
6
  import { quiltMark } from './mark.js'
7
- import { quiltBlock, projectCodebases, looseCodebases, whoLine, readFolded } from './project-model.js'
7
+ import { quiltBlock, projectCodebases, looseCodebases, whoLine, readFolded, projectDms } from './project-model.js'
8
+ import { mountChannel, loadChannel, channelUnread } from './project-channel.js'
8
9
  import { tileLetter } from './prail-model.js'
9
10
  import { loadWorkspaces, openWorkspace, wsIdOf } from './workspaces.js'
10
11
  import { openNewProject, openProjectPop } from './project-pop.js'
11
12
  import { artifactsHtml, bindAllFiles } from './files.js'
12
13
  import { mountProjectBoard, projectOpenTasks } from './project-board.js'
13
- import { mountConnections } from './connections.js'
14
+ import { mountConnections, whoWords } from './connections.js'
14
15
  import { toolLogo } from './tool-logo.js'
15
16
  import { FOREIGN_JOINS } from './agent-place.js'
16
17
 
@@ -33,7 +34,7 @@ export function toggleFolded (k) { const f = foldedNow(); f.has(k) ? f.delete(k)
33
34
  /** The project a view shows, as the list of projects has it; null on Home. */
34
35
  const projectOfView = (view) => /^(ws|wsfiles):/.test(view) ? (state.workspaces || []).find((w) => w.id === wsIdOf(view)) || { id: wsIdOf(view), name: '', color: '' } : null
35
36
  /** The page of a project that is showing: its overview, its tasks, its artifacts or its connections. */
36
- const pageOf = (view) => view.startsWith('wsfiles:') ? 'artifacts' : state.projectPage === 'tasks' ? 'tasks' : state.projectPage === 'connections' && state.connectionsOn ? 'connections' : ''
37
+ const pageOf = (view) => view.startsWith('wsfiles:') ? 'artifacts' : state.projectPage === 'tasks' ? 'tasks' : state.projectPage === 'channel' ? 'channel' : state.projectPage === 'connections' && state.connectionsOn ? 'connections' : ''
37
38
 
38
39
  // ---------------------------------------------------------------- header --
39
40
  function headerHtml (p) {
@@ -141,19 +142,34 @@ function projectAgentsHtml (d) {
141
142
  const appFace = (c) => `<span class="pj-face md sq">${c.logo ? `<img src="${esc(c.logo)}" alt="" loading="lazy" referrerpolicy="no-referrer">` : `<i class="show">${esc(String(c.name || '?').slice(0, 1).toUpperCase())}</i>`}</span>`
142
143
  const APP_STATE = { pending: 'Waiting for sign-in', failed: "Didn't connect" }
143
144
 
144
- /** A project's connections, as tiles. `v`: what the accounts API says for the project (null: not asked yet). */
145
- function projectAppsHtml (v) {
145
+ /** Agent id -> name, from what the pages know: your agents and the open project's. */
146
+ function agentNames () {
147
+ const names = new Map((state.placedAgents || []).map((a) => [a.id, a.name]))
148
+ for (const a of (state.workspace && state.workspace.agents) || []) if (a.agentId) names.set(a.agentId, a.name)
149
+ return names
150
+ }
151
+
152
+ /**
153
+ * Connections as tiles: a project's (its own and the ones it gets from above), or on Home your
154
+ * own, which every project of yours gets. `v`: what the accounts API says (null: not asked yet).
155
+ * The switch says whether agents may use it; one for chosen agents wears who they are.
156
+ */
157
+ function appsSectionHtml (v, { home = false } = {}) {
146
158
  const own = v ? v.connections || [] : []
147
159
  const above = v ? v.inherited || [] : []
160
+ const names = agentNames()
161
+ const from = (c, mine) => home ? '' : mine ? scopePill(true) : c.level === 'org' ? `<span class="pill pj-scope" title="Connected for the team">${esc(c.levelName || 'Team')}</span>` : scopePill(false)
162
+ const only = (c) => c.who === 'agents' ? `<span class="pill pj-scope own" title="Agents that were not chosen can't use it">${esc(whoWords(c, names))}</span>` : ''
148
163
  const tile = (c, mine) => `
149
- <div class="pj-app pj-item">${appFace(c)}${sw(`data-app-who="${esc(c.id)}" aria-label="${esc(c.name)}: agents may use it"`, c.who !== 'people' && c.status === 'active', { disabled: !mine || !c.mayChange || c.status !== 'active', why: mine ? '' : `Set where it was connected${c.levelName ? ` (${c.levelName})` : ''}` })}<b>${esc(c.name)}</b><span class="hint" title="Connected by ${esc(c.by)}">${esc(APP_STATE[c.status] || `Connected by ${c.by}`)}</span>${scopePill(mine)}</div>`
164
+ <div class="pj-app pj-item">${appFace(c)}${sw(`data-app-who="${esc(c.id)}" aria-label="${esc(c.name)}: agents may use it"`, c.who !== 'people' && c.status === 'active', { disabled: !mine || !c.mayChange || c.status !== 'active', why: mine ? '' : `Set where it was connected${c.level === 'account' ? ' (Home)' : c.levelName ? ` (${c.levelName})` : ''}` })}<b>${esc(c.name)}</b><span class="hint" title="Connected by ${esc(c.by)}">${esc(APP_STATE[c.status] || `Connected by ${c.by}`)}</span><span class="pj-pills">${from(c, mine)}${only(c)}</span></div>`
150
165
  const n = own.length + above.length
166
+ const manage = home ? 'data-manage-connections' : 'data-page="connections"'
151
167
  return `
152
168
  <section class="pj-sec pj-s-tiles" data-apps>
153
- <div class="sec-head"><h2>Connections</h2><span class="count">${v ? n : ''}</span><span class="hint">Apps this project's agents can use.</span><span class="spacer"></span>
154
- <button type="button" class="btn sm ghost" data-page="connections">${I.gear}<span>Manage</span></button></div>
169
+ <div class="sec-head"><h2>Connections</h2><span class="count">${v ? n : ''}</span><span class="hint">${home ? 'Apps the agents in every project can use.' : "Apps this project's agents can use."}</span><span class="spacer"></span>
170
+ <button type="button" class="btn sm ghost" ${manage}>${I.gear}<span>Manage</span></button></div>
155
171
  ${v ? `<div class="pj-apps pj-cards">${own.map((c) => tile(c, true)).join('')}${above.map((c) => tile(c, false)).join('')}
156
- ${v.canManage ? `<button type="button" class="pj-app pj-slot" data-page="connections"><span class="pj-plus">${I.plus}</span><span>Connect an app</span></button>` : ''}</div>` : '<p class="hint">Loading connections…</p>'}
172
+ ${v.canManage ? `<button type="button" class="pj-app pj-slot" ${manage}><span class="pj-plus">${I.plus}</span><span>Connect an app</span></button>` : ''}</div>` : '<p class="hint">Loading connections…</p>'}
157
173
  </section>`
158
174
  }
159
175
 
@@ -168,6 +184,13 @@ function sideHtml (p, d, page) {
168
184
  const nav = (v, icon, label, n) => `<button type="button" class="${page === v ? 'on' : ''}" data-page="${v}"${page === v ? ' aria-current="page"' : ''}>${icon}<span class="nm">${label}</span>${n === undefined ? '' : `<span class="ct">${n}</span>`}</button>`
169
185
  const isFolded = (k) => foldedNow().has(k)
170
186
  const label = (k, text, n, extra = '') => `<div class="side-label pj-side-label"><button type="button" class="pj-fold" data-fold="${k}" aria-expanded="${!isFolded(k)}" title="${isFolded(k) ? 'Show' : 'Hide'} ${text.toLowerCase()}"><span>${text}</span>${I.chevDown}</button>${isFolded(k) && n ? `<span class="ct">${n}</span>` : ''}${extra}</div>`
187
+ // Channels: the project's own (kept by the accounts API), then one for each codebase open here (its chat).
188
+ const open = list.filter((c) => c.where === 'open')
189
+ const own = channelUnread(p.id)
190
+ const newHere = own + open.reduce((n, c) => n + ((state.sessions.get(c.id)?.status.unread) || 0), 0)
191
+ const room = (attrs, name, n, on) => `<button type="button" class="${on ? 'on' : ''}" ${attrs}${on ? ' aria-current="page"' : ''}><span class="pj-hash">#</span><span class="nm">${esc(name)}</span>${n ? `<span class="ct new">${n > 99 ? '99+' : n}</span>` : ''}</button>`
192
+ // Direct messages, across the codebases open here: a row opens that codebase's chat on them.
193
+ const dms = projectDms(open.map((c) => ({ id: c.id, name: c.name, messages: state.messages.get(c.id) || [], me: state.sessions.get(c.id)?.status.me?.name || '' })))
171
194
  const row = (c) => {
172
195
  const act = c.where === 'open' ? `data-go="${esc(c.id)}"` : c.where === 'here' ? `data-rejoin="${esc(c.dir)}"` : `data-join-room="${esc(c.room)}" data-name="${esc(c.name)}"`
173
196
  const say = c.where === 'away' ? 'Not on this computer yet: join it' : `Open ${c.name}${c.dir ? ` (${c.dir})` : ''}`
@@ -178,6 +201,12 @@ function sideHtml (p, d, page) {
178
201
  <nav class="side-nav" aria-label="Pages">${nav('', I.grid, 'Overview')}${nav('tasks', I.board, 'Tasks', projectOpenTasks(d))}${nav('artifacts', I.folder, 'Artifacts', files)}${state.connectionsOn ? nav('connections', I.link, 'Connections') : ''}</nav>
179
202
  ${label('codebases', 'Codebases', list.length, d.access?.access === 'edit' ? `<button type="button" class="btn sm ghost icon" data-new-codebase title="New codebase" aria-label="New codebase">${I.plus}</button>` : '')}
180
203
  <div class="side-sessions">${isFolded('codebases') ? '' : list.map(row).join('')}</div>
204
+ ${label('channels', 'Channels', newHere)}
205
+ <div class="side-sessions pj-rooms">${isFolded('channels') && page !== 'channel' && !newHere ? '' : `
206
+ ${room(`data-page="channel" title="Everyone in ${esc(p.name)}"`, p.name, own, page === 'channel')}
207
+ ${isFolded('channels') ? '' : open.map((c) => room(`data-go-chat="${esc(c.id)}" title="Everyone working in ${esc(c.name)}"`, c.name, (state.sessions.get(c.id)?.status.unread) || 0, false)).join('')}`}</div>
208
+ ${dms.length ? `${label('dms', 'Direct messages')}
209
+ <div class="side-sessions pj-rooms">${isFolded('dms') ? '' : dms.map((t) => `<button type="button" data-go-dm="${esc(t.code)}" data-name="${esc(t.name)}" title="You and ${esc(t.name)}, in ${esc(t.codeName)}">${avatar(t.name)}<span class="nm">${esc(t.name)}</span></button>`).join('')}</div>` : ''}
181
210
  <div class="side-foot side-nav">
182
211
  <button type="button" data-team title="People and agents in this project"><span class="pj-faces sm">${team.slice(0, 3).map((m) => avatar(m.name)).join('')}</span><span class="nm">Team</span><span class="ct">${count}</span></button>
183
212
  ${d.access?.admin ? `<button type="button" data-invite-project>${I.link}<span class="nm">Invite</span></button>` : ''}
@@ -201,16 +230,19 @@ export function codeCrumbHtml (project) {
201
230
  * `tasks`: its open tasks; `artifacts`: how many the project has, once known; `chatNew`: messages in its channel since it was last looked at;
202
231
  * `people`: who is in it, you first ({ name, color }).
203
232
  */
204
- export function codeSideHtml ({ page, name, project, tasks = 0, artifacts = 0, chatNew = 0, people = [], connections = false, canInvite = true }) {
233
+ export function codeSideHtml ({ page, name, project, tasks = 0, artifacts = 0, chatNew = 0, people = [], connections = false, canInvite = true, dms = [], dmOn = '', call = 0 }) {
205
234
  const nav = (v, icon, label, n, attr = `data-code-page="${v}"`) => `<button type="button" class="${page === v ? 'on' : ''}" ${attr}${page === v ? ' aria-current="page"' : ''}>${icon}<span class="nm">${label}</span>${n ? `<span class="ct">${n}</span>` : ''}</button>`
206
235
  const isFolded = (k) => foldedNow().has(k)
207
236
  const label = (k, text, n) => `<div class="side-label pj-side-label"><button type="button" class="pj-fold" data-fold="${k}" aria-expanded="${!isFolded(k)}" title="${isFolded(k) ? 'Show' : 'Hide'} ${text.toLowerCase()}"><span>${text}</span>${I.chevDown}</button>${isFolded(k) && n ? `<span class="ct new">${n}</span>` : ''}</div>`
208
- // A folded section keeps the row you are on and what is new.
209
- const channel = !isFolded('channels') || page === 'chat' || chatNew
237
+ // A folded section keeps the row you are on, what is new, and a call going on.
238
+ const channel = !isFolded('channels') || page === 'chat' || chatNew || call
239
+ const inDm = page === 'chat' ? dmOn : ''
210
240
  return `
211
241
  <nav class="side-nav" aria-label="Pages">${nav('loom', I.users, 'Loom')}${nav('tasks', I.board, 'Tasks', tasks)}${project ? nav('artifacts', I.folder, 'Artifacts', artifacts) : ''}${connections ? nav('connections', I.link, 'Connections') : ''}</nav>
212
242
  ${label('channels', 'Channels', chatNew)}
213
- <div class="side-sessions pj-rooms">${channel ? `<button type="button" class="${page === 'chat' ? 'on' : ''}" data-code-page="chat" title="Everyone working in ${esc(name)}"${page === 'chat' ? ' aria-current="page"' : ''}><span class="pj-hash">#</span><span class="nm">${esc(name)}</span>${chatNew ? `<span class="ct new">${chatNew > 99 ? '99+' : chatNew}</span>` : ''}</button>` : ''}</div>
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
+ ${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>` : ''}
214
246
  <div class="side-foot side-nav">
215
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>
216
248
  ${canInvite ? `<button type="button" data-code-invite>${I.link}<span class="nm">Invite</span></button>` : ''}
@@ -235,11 +267,14 @@ function loadAgents (rerender) {
235
267
  }).catch(() => { if (!state.placedAgents) { state.placedAgents = []; rerender() } })
236
268
  }
237
269
 
270
+ let channelTimer = null
238
271
  const appsAsked = new Map()
272
+ /** Where a page's connections are: a project's by its id, your own (Home) as 'me'. */
273
+ const appsUrl = (id, rest = '') => `/api/connections/${id === 'me' ? 'account/me' : `workspace/${encodeURIComponent(id)}`}${rest}`
239
274
  function loadApps (id, rerender, { now = false } = {}) {
240
275
  if (!now && Date.now() - (appsAsked.get(id) || 0) < 5000) return
241
276
  appsAsked.set(id, Date.now())
242
- api('GET', `/api/connections/workspace/${encodeURIComponent(id)}`).then((v) => {
277
+ api('GET', appsUrl(id)).then((v) => {
243
278
  const was = JSON.stringify(apps.get(id) || null)
244
279
  apps.set(id, v)
245
280
  if (JSON.stringify(v) !== was) rerender()
@@ -248,7 +283,8 @@ function loadApps (id, rerender, { now = false } = {}) {
248
283
 
249
284
  // ------------------------------------------------------------------ page --
250
285
  function homePageHtml () {
251
- return codebasesHtml(looseCodebases({ sessions: state.sessions, recent: state.recent, projects: state.workspaces || [] })) + homeAgentsHtml()
286
+ return codebasesHtml(looseCodebases({ sessions: state.sessions, recent: state.recent, projects: state.workspaces || [] })) + homeAgentsHtml() +
287
+ (state.connectionsOn ? appsSectionHtml(appsOf('me'), { home: true }) : '')
252
288
  }
253
289
 
254
290
  function projectPageHtml (p, view) {
@@ -263,10 +299,11 @@ function projectPageHtml (p, view) {
263
299
  const page = pageOf(view)
264
300
  const main = page === 'artifacts' ? artifactsHtml(d)
265
301
  : page === 'tasks' ? '<div class="pj-board" data-project-board></div>'
302
+ : page === 'channel' ? '<div class="pj-chanpage" data-project-channel></div>'
266
303
  : page === 'connections' ? `<div class="files-head"><div class="t"><h2 class="crumbs">Connections</h2><p class="hint">Apps this project's agents can use. Agents never see the logins.</p></div></div><div data-project-connections></div>`
267
304
  : codebasesHtml(projectCodebases(d, state.sessions, `person:${state.account?.id}`), { project: p, canAdd: d.access?.access === 'edit' }) +
268
- projectAgentsHtml(d) + (state.connectionsOn ? projectAppsHtml(appsOf(p.id)) : '')
269
- return `${sideHtml(p, d, page)}<div class="pj-pmain${page === 'artifacts' ? ' pj-files' : page === 'tasks' ? ' pj-tasks' : ''}">${main}</div>`
305
+ projectAgentsHtml(d) + (state.connectionsOn ? appsSectionHtml(appsOf(p.id)) : '')
306
+ return `${sideHtml(p, d, page)}<div class="pj-pmain${page === 'artifacts' ? ' pj-files' : page === 'tasks' ? ' pj-tasks' : page === 'channel' ? ' pj-chat' : ''}">${main}</div>`
270
307
  }
271
308
 
272
309
  /** Home or a project's page, under the header, for `view` ('home', 'ws:<id>' or 'wsfiles:<id>'). */
@@ -337,6 +374,15 @@ export function bindProjectShell (view, { go, rerender, newSessionDialog, joinSe
337
374
  } catch (err) { toast(err.message); box.checked = !box.checked }
338
375
  }
339
376
  })
377
+ // Connections as tiles (a project's, or your own on Home): the switch says whether agents may use one.
378
+ const appsId = p ? p.id : 'me'
379
+ if (root.querySelector('[data-apps]')) loadApps(appsId, rerender)
380
+ root.querySelectorAll('[data-app-who]').forEach((box) => {
381
+ box.onchange = async () => {
382
+ try { await api('PATCH', appsUrl(appsId, `/${encodeURIComponent(box.dataset.appWho)}`), { who: box.checked ? 'all' : 'people' }); loadApps(appsId, rerender, { now: true }) } catch (err) { toast(err.message); box.checked = !box.checked }
383
+ }
384
+ })
385
+ root.querySelectorAll('[data-manage-connections]').forEach((b) => { b.onclick = () => { state.settingsTab = 'connections'; openSettings() } })
340
386
  if (!p) return
341
387
  // The sidebar: its pages, closing it, folding a section.
342
388
  const side = $('#pj-side-btn')
@@ -344,7 +390,7 @@ export function bindProjectShell (view, { go, rerender, newSessionDialog, joinSe
344
390
  root.querySelectorAll('[data-page]').forEach((b) => {
345
391
  b.onclick = () => {
346
392
  const page = b.dataset.page
347
- state.projectPage = page === 'connections' || page === 'tasks' ? page : ''
393
+ state.projectPage = page === 'connections' || page === 'tasks' || page === 'channel' ? page : ''
348
394
  const to = page === 'artifacts' ? `wsfiles:${p.id}` : `ws:${p.id}`
349
395
  if (to === state.view) rerender(); else go(to)
350
396
  }
@@ -359,11 +405,29 @@ export function bindProjectShell (view, { go, rerender, newSessionDialog, joinSe
359
405
  if (!d || d.workspace.id !== p.id) return
360
406
  const main = root.querySelector('.pj-pmain')
361
407
  if (pageOf(view) === 'artifacts') bindAllFiles(main, { id: p.id, go, rerender, reload })
408
+ // The project's channel: asked for every few seconds while this project's page is open, so what is new shows with no codebase open.
409
+ // What is new changed: the sidebar says so. With the channel itself open only its count is touched, so what is being typed stays.
410
+ const newCount = () => {
411
+ if (state.view !== view) return
412
+ if (!root.querySelector('[data-project-channel]')) return rerender()
413
+ const row = root.querySelector('[data-page="channel"]'); const n = channelUnread(p.id)
414
+ if (!row) return
415
+ row.querySelector('.ct')?.remove()
416
+ if (n) row.insertAdjacentHTML('beforeend', `<span class="ct new">${n > 99 ? '99+' : n}</span>`)
417
+ }
418
+ clearInterval(channelTimer)
419
+ channelTimer = setInterval(() => { if (state.view !== view || !root.isConnected) return clearInterval(channelTimer); loadChannel(p.id, newCount) }, 4000)
420
+ loadChannel(p.id, newCount)
421
+ const channel = root.querySelector('[data-project-channel]')
422
+ if (channel) mountChannel(channel, { d, changed: newCount })
423
+ // A codebase's channel, or a direct message in it: the codebase opens on its chat.
424
+ root.querySelectorAll('[data-go-chat]').forEach((b) => { b.onclick = () => { state.openChat = b.dataset.goChat; state.to = ''; go(b.dataset.goChat) } })
425
+ root.querySelectorAll('[data-go-dm]').forEach((b) => { b.onclick = () => { state.openChat = b.dataset.goDm; state.to = b.dataset.name; go(b.dataset.goDm) } })
362
426
  const board = root.querySelector('[data-project-board]')
363
427
  // The open count beside Tasks follows the board as it changes.
364
428
  if (board) mountProjectBoard(board, { d, go, reload, changed: () => { const ct = root.querySelector('[data-page="tasks"] .ct'); if (ct) ct.textContent = projectOpenTasks(state.workspace) } })
365
429
  const conns = root.querySelector('[data-project-connections]')
366
- if (conns) mountConnections(conns, { type: 'workspace', id: p.id })
430
+ if (conns) mountConnections(conns, { type: 'workspace', id: p.id, agents: () => ((state.workspace && state.workspace.agents) || []).filter((a) => a.agentId).map((a) => ({ id: a.agentId, name: a.name })) })
367
431
  // An agent's switch in this project: one added here keeps its place and changes whether it is invited; one from above gets this project's own setting.
368
432
  root.querySelectorAll('[data-agent-here]').forEach((box) => {
369
433
  box.onchange = async () => {
@@ -379,12 +443,6 @@ export function bindProjectShell (view, { go, rerender, newSessionDialog, joinSe
379
443
  }
380
444
  })
381
445
  // Connections: asked for when the overview shows them; a switch says whether agents may use one.
382
- if (root.querySelector('[data-apps]')) loadApps(p.id, rerender)
383
- root.querySelectorAll('[data-app-who]').forEach((box) => {
384
- box.onchange = async () => {
385
- try { await api('PATCH', `/api/connections/workspace/${encodeURIComponent(p.id)}/${encodeURIComponent(box.dataset.appWho)}`, { who: box.checked ? 'all' : 'people' }); loadApps(p.id, rerender, { now: true }) } catch (err) { toast(err.message); box.checked = !box.checked }
386
- }
387
- })
388
446
  }
389
447
 
390
448
  /** Moves a codebase on this computer into a project you can edit, picked from a list. */
package/src/ui/session.js CHANGED
@@ -26,8 +26,9 @@ 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, inCallHere } from './voice.js'
29
+ import { callButtonMarkup, callPinMarkup, screenStageMarkup, mountCall, unmountCall, renderCall, callCards, callCount } from './voice.js'
30
30
  import { codeSideHtml, codeCrumbHtml, sideShut, toggleSideShut, toggleFolded } from './projects.js'
31
+ import { dmThreads } from './project-model.js'
31
32
 
32
33
  let current = null // session id being shown
33
34
  let timers = []
@@ -106,6 +107,8 @@ function personInfo (name) {
106
107
  // ------------------------------------------------------------------ mount --
107
108
  export function mountSession (id) {
108
109
  current = id
110
+ // Opened from a channel or a direct message in the project's sidebar: on its chat.
111
+ if (state.openChat === id) { ws(id).side = 'chat'; state.openChat = null }
109
112
  pendingAssign = null
110
113
  resetLoom()
111
114
  boardQuery = '' // a search is for the board it was typed on
@@ -217,7 +220,7 @@ export function mountSession (id) {
217
220
  const st = sum().status
218
221
  const colors = new Map([...st.peers.map((p) => [p.name, p.color]), [st.me.name, st.me.color]])
219
222
  return { owner: !!st.access?.owner, me: st.me, colorOf: (n) => colors.get(n) }
220
- }, () => renderMessages())
223
+ }, () => renderMessages(), () => renderCodeSide())
221
224
  bindAccess()
222
225
  bindChanges(id, mounted.signal, { onOpen: (path) => openFile(path, { tab: 'changes' }), close: () => setGitOpen(false), onCount: renderGitChip })
223
226
  bindCatchUp($('#catchup'), { sessionId: () => current, onOpen: openFile })
@@ -399,7 +402,7 @@ function renderCodeSide () {
399
402
  const page = side || (w.mode === 'tasks' ? 'tasks' : 'loom')
400
403
  const open = (st.tasks || []).filter((t) => !t.archived && (t.column === 'todo' || t.column === 'doing')).length
401
404
  const people = [st.me, ...peopleHere(st)]
402
- 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, connections: !!state.connectionsOn, canInvite: !!st.access?.owner || st.access?.role !== 'viewer' })
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() })
403
406
  const root = $('#ws')
404
407
  root.dataset.sidePage = side
405
408
  $('#code-crumb').innerHTML = codeCrumbHtml(projectHere())
@@ -465,6 +468,8 @@ function bindCodeSide () {
465
468
  el.addEventListener('click', (e) => {
466
469
  const b = e.target.closest('button')
467
470
  if (!b || !el.contains(b)) return
471
+ // The channel is for everyone; a direct message's row is that person alone.
472
+ if (b.dataset.dm !== undefined) { state.to = b.dataset.dm; showCodePage('chat'); renderRecipients(); updatePlaceholder(); return renderCodeSide() }
468
473
  if (b.dataset.codePage) return showCodePage(b.dataset.codePage)
469
474
  if (b.dataset.fold) { toggleFolded(b.dataset.fold); return renderCodeSide() }
470
475
  if (b.dataset.go) return go(b.dataset.go)
@@ -2220,11 +2225,8 @@ async function refreshFile (path, highlight) {
2220
2225
  function loomPrefs (w) {
2221
2226
  const p = w.loom && typeof w.loom === 'object' ? w.loom : {}
2222
2227
  const names = (list) => Array.isArray(list) ? list.filter((n) => typeof n === 'string') : []
2228
+ // The Loom is shown one way (chat and tasks in it, cards in full, a lane each): choices saved by an older app are dropped.
2223
2229
  w.loom = {
2224
- chat: p.chat !== false,
2225
- tasks: p.tasks !== false,
2226
- density: p.density === 'compact' ? 'compact' : 'detailed',
2227
- layout: p.layout === 'merged' ? 'merged' : 'lanes',
2228
2230
  hidden: names(p.hidden),
2229
2231
  pinned: names(p.pinned), // lanes kept open when they don't all fit
2230
2232
  opened: names(p.opened).slice(0, 20), // lanes opened from a strip, latest first
@@ -2282,11 +2284,8 @@ function loomAction (kind, value) {
2282
2284
  }
2283
2285
  if (kind === 'hide') prefs.hidden = [...new Set([...prefs.hidden, value])]
2284
2286
  else if (kind === 'unhide') prefs.hidden = prefs.hidden.filter((n) => n !== value)
2285
- else if (kind === 'toggle') prefs[value] = prefs[value] === false
2286
- else if (kind === 'density') prefs.density = value
2287
- else if (kind === 'layout') prefs.layout = value
2288
2287
  else if (kind === 'pin') prefs.pinned = prefs.pinned.includes(value) ? prefs.pinned.filter((n) => n !== value) : [...prefs.pinned, value]
2289
- else if (kind === 'open-lane') { prefs.opened = [value, ...prefs.opened.filter((n) => n !== value)].slice(0, 20); prefs.layout = 'lanes' }
2288
+ else if (kind === 'open-lane') prefs.opened = [value, ...prefs.opened.filter((n) => n !== value)].slice(0, 20)
2290
2289
  else if (kind === 'conv-name') {
2291
2290
  // Empty: back to the conversation's own name (its tool's title, or its first prompt).
2292
2291
  const rest = Object.fromEntries(Object.entries(prefs.convNames).filter(([k]) => k !== value.conv))
@@ -2442,10 +2441,11 @@ const CHAT_MAX = 640
2442
2441
  const CHAT_SNAP = 220
2443
2442
  let chatSeenTs = Date.now() // messages after this count on the folded rail
2444
2443
  let chatNew = 0 // how many of them there are, for the sidebar's channel row
2444
+ let dmNew = new Map() // and for each direct message's row: who wrote -> how many
2445
2445
 
2446
2446
  // With the sidebar (projects on), chat is a page from the sidebar, not a column: it counts as folded
2447
2447
  // whenever it is not the page showing (a call keeps it beside the page).
2448
- const chatCollapsed = () => pj() && current ? !(ws(current).side === 'chat' || inCallHere(current)) : recall('chat-collapsed', '') === '1'
2448
+ const chatCollapsed = () => pj() && current ? ws(current).side !== 'chat' : recall('chat-collapsed', '') === '1'
2449
2449
  const chatWidthFor = (body, w) => Math.round(Math.min(Math.max(w, CHAT_MIN), Math.max(CHAT_MIN, Math.min(CHAT_MAX, body.clientWidth - 560))))
2450
2450
 
2451
2451
  function applyChatLayout () {
@@ -2473,13 +2473,19 @@ function renderChatBadge () {
2473
2473
  const rail = $('#chat-rail')
2474
2474
  const s = sum()
2475
2475
  if (!badge || !rail) return
2476
- const n = s && chatCollapsed()
2477
- ? renderable(state.messages.get(current)).filter((m) => (m.ts || 0) > chatSeenTs && shownName(m.by, owners(s)) !== s.status.me?.name && !ownAiChatter(m, owners(s))).length
2478
- : 0
2476
+ const fresh = s && chatCollapsed()
2477
+ ? renderable(state.messages.get(current)).filter((m) => (m.ts || 0) > chatSeenTs && shownName(m.by, owners(s)) !== s.status.me?.name && !ownAiChatter(m, owners(s)))
2478
+ : []
2479
+ // With the sidebar, what was written to you alone counts on its own row, the rest on the channel's.
2480
+ const direct = new Map()
2481
+ if (pj()) for (const m of fresh) if (m.to) direct.set(m.by, (direct.get(m.by) || 0) + 1)
2482
+ const n = pj() ? fresh.filter((m) => !m.to).length : fresh.length
2483
+ const dmChanged = JSON.stringify([...direct]) !== JSON.stringify([...dmNew])
2484
+ dmNew = direct
2479
2485
  badge.hidden = !n
2480
2486
  badge.textContent = n > 99 ? '99+' : String(n)
2481
2487
  rail.title = n ? `Open chat · ${n} new message${n === 1 ? '' : 's'}` : 'Open chat'
2482
- if (n !== chatNew) { chatNew = n; renderCodeSide() }
2488
+ if (n !== chatNew || dmChanged) { chatNew = n; renderCodeSide() }
2483
2489
  }
2484
2490
 
2485
2491
  function bindChatPane () {
@@ -2832,8 +2838,10 @@ function renderMessages (incoming = false, force = false) {
2832
2838
  const nearBottom = el.scrollHeight - el.scrollTop - el.clientHeight < 80
2833
2839
  const who = owners(s)
2834
2840
  // A person's AI sessions working things out among themselves isn't shown: only what they say to people.
2835
- const list = renderable(state.messages.get(current)).filter((m) => !ownAiChatter(m, who)) // peers can push anything into the room
2841
+ const every = renderable(state.messages.get(current)).filter((m) => !ownAiChatter(m, who)) // peers can push anything into the room
2836
2842
  const name = s.status.me.name
2843
+ // With the sidebar, a direct message's row shows that conversation alone, and the channel what was said to everyone.
2844
+ const list = !pj() ? every : state.to ? every.filter((m) => m.to && ((m.by === state.to && m.to === name) || (m.to === state.to && shownName(m.by, who) === name))) : every.filter((m) => !m.to)
2837
2845
  const colors = new Map(s.status.peers.map((p) => [p.name, p.color]))
2838
2846
  colors.set(name, s.status.me.color)
2839
2847
  const names = mentionNames(s)