heyquilt 0.3.187 → 0.3.188

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/session.js CHANGED
@@ -53,6 +53,7 @@ import { HELD_MAP, readHeld, findHeld, settleHeld, renderHeld, versionsOf, versi
53
53
  import { RELAY_NAME as RELAY_BY, isRelay } from './ui/chat.js'
54
54
  import { cleanTyping, TYPING_MS, AGENT_TYPING_MS } from './ui/chat.js'
55
55
  import { DEFAULT_KEY, validBranchKey } from './branchdocs.js'
56
+ import { cleanPreview, previewId, previewList, previewsView, branchChoices, hasDevScript, cleanLooking, cleanRunning, APP_ID, MAX_PREVIEWS } from './previews.js'
56
57
  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
58
  import { shareableRemote, repoLabel } from './repo-ref.js'
58
59
  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'
@@ -193,8 +194,13 @@ function writeAndStat (abs, data, mode = undefined) {
193
194
  }
194
195
 
195
196
  export class Session extends EventEmitter {
196
- constructor ({ dir, server, room, secret, key = '', viewSecret = '', name, tool = 'unknown', color = null, prefer = 'remote', kind = 'human', shareAgent = true, summarize = null, identity = null, passes = null, startName = '', startAgentCommits = '', workspace = '', editQuietMs = EDIT_QUIET_MS, aiTasks = null, pushLocalCommits = null, webhookTransport = null, pullWaitMs = PULL_WAIT_MS, bringInUpstream = true, clashReassignMs = CLASH_REASSIGN_MS, clashWaitMs = CLASH_WAIT_MS, clashSettleMs = CLASH_SETTLE_MS, clashIdleMs = CLASH_IDLE_MS, catcherWaitMs = CATCHER_WAIT_MS, gitBacking = true, gitRemote = null, followsRelay = true, turns = false, features = null, localRepos = process.env.QUILT_LOCAL_REPOS === '1', cli = defaultCli() }) {
197
+ constructor ({ dir, server, room, secret, key = '', viewSecret = '', name, tool = 'unknown', color = null, prefer = 'remote', kind = 'human', shareAgent = true, summarize = null, identity = null, passes = null, startName = '', startAgentCommits = '', workspace = '', editQuietMs = EDIT_QUIET_MS, aiTasks = null, pushLocalCommits = null, webhookTransport = null, pullWaitMs = PULL_WAIT_MS, bringInUpstream = true, clashReassignMs = CLASH_REASSIGN_MS, clashWaitMs = CLASH_WAIT_MS, clashSettleMs = CLASH_SETTLE_MS, clashIdleMs = CLASH_IDLE_MS, catcherWaitMs = CATCHER_WAIT_MS, gitBacking = true, gitRemote = null, followsRelay = true, turns = false, features = null, localRepos = process.env.QUILT_LOCAL_REPOS === '1', cli = defaultCli(), followBranch = '', preview = false }) {
197
198
  super()
199
+ // A folder that follows one branch's live copy and never has git of its own (plans/previews.md):
200
+ // the preview machine keeps one for each branch someone is looking at.
201
+ this.followBranch = validBranchKey(followBranch) && followBranch !== DEFAULT_KEY ? followBranch : ''
202
+ // The codebase's preview machine: it has no name in presence, so nobody lists it as a person.
203
+ this.preview = !!preview
198
204
  // An agent that works in turns (agent-join.js keptInProject): the relay shows it away between them.
199
205
  this.turns = turns
200
206
  this.pullWaitMs = pullWaitMs
@@ -261,6 +267,7 @@ export class Session extends EventEmitter {
261
267
  this.chat = this.doc.getArray('chat') // { by, text, ts }
262
268
  this.activity = this.doc.getArray('activity') // { by, path, kind, detail, ts }
263
269
  this.agentFeed = this.doc.getArray('agentFeed') // { id, by, tool, conv, kind, text, ts, summary?, title? }
270
+ this.previewDefs = this.doc.getMap('previews') // id -> { id, name, kind, command, folder, port, url, env, order } (previews.js)
264
271
  this.tasks = this.doc.getMap('tasks') // id -> { id, title, column, by, assignee, forAi, tool, files, conv, verified, qaNotes, recurring, cron, order, ts }
265
272
  this.taskComments = this.doc.getMap('taskComments') // task id -> [{ id, by, text, ts }] (task-comments.js)
266
273
  // Mentions, direct messages and tasks handed to this member (or their AI), for agents to wake on.
@@ -441,7 +448,7 @@ export class Session extends EventEmitter {
441
448
  this.name = name
442
449
  this.kind = kind
443
450
  this.aiOf = aiOf
444
- if (this.conn && this.conn.awareness.getLocalState()) {
451
+ if (this.conn && this.conn.awareness.getLocalState() && !this.preview) {
445
452
  this.conn.awareness.setLocalStateField('name', name)
446
453
  this.conn.awareness.setLocalStateField('kind', kind)
447
454
  this.conn.awareness.setLocalStateField('aiOf', aiOf || undefined)
@@ -585,7 +592,8 @@ export class Session extends EventEmitter {
585
592
  const away = hadState && this.startAway()
586
593
  // The branch document this folder syncs: the one git has it on (still the saved one, until the folder
587
594
  // has moved, when it started away), the set-aside note's, else the room's default (a folder without git).
588
- this.branch = (this.git && this.git.key) || (this.gitAside && this.gitAside.branch) || DEFAULT_KEY
595
+ // A folder told which branch to follow (the preview machine's) is on that one, whatever git would say.
596
+ this.branch = this.followBranch || (this.git && this.git.key) || (this.gitAside && this.gitAside.branch) || DEFAULT_KEY
589
597
  // The form saved is the saved branch's; another branch's is the relay's to say when it is joined.
590
598
  if (this.savedBranch !== this.branch) { this.branchForm = null; this.diffBase = null }
591
599
 
@@ -862,6 +870,7 @@ export class Session extends EventEmitter {
862
870
  this.leaveClosedTicket()
863
871
  })
864
872
  this.taskComments.observe(() => this.scheduleStatusWrite())
873
+ this.previewDefs.observe(() => this.scheduleStatusWrite())
865
874
  // Held conflicts (held.js): the app and quilt_status show every open one as it comes and goes.
866
875
  this.doc.getMap(HELD_MAP).observe(() => { this.scheduleStatusWrite(); this.emit('held', this.heldList()) })
867
876
  this.agentFeed.observe((ev) => {
@@ -2327,7 +2336,7 @@ export class Session extends EventEmitter {
2327
2336
  }
2328
2337
 
2329
2338
  async adoptGit () {
2330
- if (this.git || this.gitAside || this.stopped || this.prefer === 'local' || hasGitDir(this.root)) return false
2339
+ if (this.followBranch || this.git || this.gitAside || this.stopped || this.prefer === 'local' || hasGitDir(this.root)) return false
2331
2340
  const url = this.sessionRepo()
2332
2341
  const branch = this.branchKey()
2333
2342
  if (!url || !validBranchKey(branch) || branch === DEFAULT_KEY || branch.startsWith('@')) return false
@@ -2882,6 +2891,8 @@ export class Session extends EventEmitter {
2882
2891
  const changesIt = (disk ? disk.key : undefined) !== this.sharedKey(rel) || gitDeletion
2883
2892
  const refusal = this.writeRefusal(rel)
2884
2893
  if (refusal && changesIt) {
2894
+ // A preview machine's folder: what an install or a build wrote there stays as it is, shared with nobody.
2895
+ if (this.preview) return false
2885
2896
  this.rejectLocal(rel, disk, refusal)
2886
2897
  return false
2887
2898
  }
@@ -3477,7 +3488,8 @@ export class Session extends EventEmitter {
3477
3488
  return
3478
3489
  }
3479
3490
 
3480
- if (this.ready && disk && disk.key !== known && disk.key !== shared) {
3491
+ // A preview machine's folder takes the codebase's version whatever a build wrote over the last one.
3492
+ if (this.ready && disk && disk.key !== known && disk.key !== shared && !this.preview) {
3481
3493
  // The file changed here in the instant before this remote change arrived: a text both sides
3482
3494
  // have is merged as a live write (ingest, against what this folder last had), never overwritten.
3483
3495
  const t = this.files.get(rel)
@@ -4157,16 +4169,20 @@ export class Session extends EventEmitter {
4157
4169
 
4158
4170
  setupPresence () {
4159
4171
  const color = this.color || COLORS[Math.abs(hashCode(this.name)) % COLORS.length]
4160
- this.conn.awareness.setLocalState({
4161
- name: this.name, tool: this.tool, color, focus: '', editing: {}, agents: [], kind: this.kind,
4162
- agent: { tool: null, status: 'idle', sharing: this.agentSharing }, branch: this.branch,
4163
- ...(this.aiOf ? { aiOf: this.aiOf } : {})
4164
- })
4172
+ // The preview machine says only what it runs (setRunning): with no name it is nobody's partner.
4173
+ if (this.preview) this.conn.awareness.setLocalState({ kind: 'preview', branch: this.branch, machine: '', running: [] })
4174
+ else {
4175
+ this.conn.awareness.setLocalState({
4176
+ name: this.name, tool: this.tool, color, focus: '', editing: {}, agents: [], kind: this.kind,
4177
+ agent: { tool: null, status: 'idle', sharing: this.agentSharing }, branch: this.branch,
4178
+ ...(this.aiOf ? { aiOf: this.aiOf } : {})
4179
+ })
4180
+ }
4165
4181
  this.conn.awareness.on('change', ({ added, removed }, origin) => {
4166
4182
  if (origin === 'local' || origin === 'connection') return
4167
4183
  for (const id of added) {
4168
4184
  const s = this.conn.awareness.getStates().get(id)
4169
- if (s && id !== this.doc.clientID) this.log(`👋 ${s.name} joined (${s.tool})`)
4185
+ if (s && s.name && id !== this.doc.clientID) this.log(`👋 ${s.name} joined (${s.tool})`)
4170
4186
  }
4171
4187
  if (removed.length) this.log(`${removed.length === 1 ? 'a partner' : `${removed.length} partners`} left`)
4172
4188
  for (const id of removed) this.peerTips.delete(id)
@@ -4176,6 +4192,81 @@ export class Session extends EventEmitter {
4176
4192
  })
4177
4193
  }
4178
4194
 
4195
+ // ------------------------------------------------------------- previews --
4196
+
4197
+ /** Whether the codebase has a `dev` script, so an "App" preview of its own (previews.js). */
4198
+ hasDevScript () {
4199
+ try { const f = this.readShared('package.json'); return !!(f && hasDevScript(f.text)) } catch { return false }
4200
+ }
4201
+
4202
+ /**
4203
+ * The codebase's previews (plans/previews.md), each with who is looking at it and what the
4204
+ * preview machine runs of it: [{ id, name, kind, ..., looking, running }].
4205
+ */
4206
+ previews () {
4207
+ const states = this.conn && this.conn.awareness ? [...this.conn.awareness.getStates()] : []
4208
+ return previewsView({ previews: previewList(this.previewDefs.toJSON(), { hasDev: this.hasDevScript() }), states, clientID: this.doc.clientID })
4209
+ }
4210
+
4211
+ /** The branches a preview can show: main, then each ticket with a branch, by its title. */
4212
+ branchChoices () { return branchChoices(this.branchList, this.taskList()) }
4213
+
4214
+ mayChangePreviews () {
4215
+ if (this.preview || (this.access && this.access.role === 'viewer')) throw new Error('You can only view this codebase.')
4216
+ }
4217
+
4218
+ /** Adds a preview (no `id`) or changes one. Returns it as kept. */
4219
+ savePreview (fields = {}) {
4220
+ this.mayChangePreviews()
4221
+ const saved = this.previewDefs.toJSON()
4222
+ const list = previewList(saved, { hasDev: this.hasDevScript() })
4223
+ const was = fields.id ? list.find((p) => p.id === fields.id) : null
4224
+ if (fields.id && !was) throw new Error('No such preview.')
4225
+ if (!was && list.length >= MAX_PREVIEWS) throw new Error(`A codebase has at most ${MAX_PREVIEWS} previews.`)
4226
+ const id = was ? was.id : previewId(fields.name, Object.keys(saved))
4227
+ const { auto, ...kept } = was || {}
4228
+ const next = cleanPreview({ order: list.length ? Math.max(...list.map((p) => p.order)) + 1 : 0, ...kept, ...fields, id })
4229
+ if (!next) throw new Error(fields.kind === 'link' || (was && was.kind === 'link' && !fields.kind) ? 'A link needs a name and an address that starts with http:// or https://.' : 'A preview needs a name, and a folder inside the codebase.')
4230
+ this.previewDefs.set(id, next)
4231
+ return next
4232
+ }
4233
+
4234
+ /** Removes a preview. The "App" one a codebase has by itself is noted as removed, so it stays gone. */
4235
+ removePreview (id) {
4236
+ this.mayChangePreviews()
4237
+ const saved = this.previewDefs.toJSON()
4238
+ if (!previewList(saved, { hasDev: this.hasDevScript() }).some((p) => p.id === id)) throw new Error('No such preview.')
4239
+ if (id === APP_ID) this.previewDefs.set(id, { id, removed: true })
4240
+ else this.previewDefs.delete(id)
4241
+ return true
4242
+ }
4243
+
4244
+ /** Says in presence which preview this app has open, on which branch (null: none). The machine runs what someone has open. */
4245
+ lookAtPreview (open) {
4246
+ if (!this.conn || !this.conn.awareness || this.preview) return null
4247
+ const next = cleanLooking(open)
4248
+ if (JSON.stringify(next) !== JSON.stringify(cleanLooking(this.conn.awareness.getLocalState()?.preview))) this.conn.awareness.setLocalStateField('preview', next)
4249
+ return next
4250
+ }
4251
+
4252
+ /** The preview machine's own: what it runs, for everyone's presence ([{ preview, branch, slot, state, output }]). */
4253
+ setRunning (running, machine = '') {
4254
+ if (!this.preview || !this.conn || !this.conn.awareness.getLocalState()) return
4255
+ this.conn.awareness.setLocalStateField('machine', String(machine))
4256
+ this.conn.awareness.setLocalStateField('running', cleanRunning(running))
4257
+ }
4258
+
4259
+ /** What each person has open, for the preview machine: [{ id, branch, name }]. */
4260
+ previewsWanted () {
4261
+ const out = []
4262
+ if (!this.conn || !this.conn.awareness) return out
4263
+ for (const [id, s] of this.conn.awareness.getStates()) {
4264
+ const l = id !== this.doc.clientID && s && typeof s.name === 'string' && s.name ? cleanLooking(s.preview) : null
4265
+ if (l) out.push({ ...l, name: s.name })
4266
+ }
4267
+ return out
4268
+ }
4269
+
4179
4270
  // ---------------------------------------------------------------- voice --
4180
4271
 
4181
4272
  /**
@@ -6147,6 +6238,10 @@ export class Session extends EventEmitter {
6147
6238
  room: this.room,
6148
6239
  server: this.server,
6149
6240
  branch: this.branch,
6241
+ // The branches a preview can show (previews.js): main, then each ticket with a branch, by its title.
6242
+ branches: this.branchChoices(),
6243
+ // The codebase's previews, each with who is looking and what the preview machine runs of it.
6244
+ previews: this.previews(),
6150
6245
  // A git checkout: where git has the folder, and whether its sync is held (git at work, or moving to the branch `to`).
6151
6246
  git: this.git ? { branch: this.git.branch, key: this.git.key, hold: this.hold ? { kind: this.hold.kind, since: this.hold.since, to: this.hold.to || null, waiting: this.hold.waiting || null } : null } : null,
6152
6247
  // The branch against its upstream, once looked at: commits it is behind and why they wait, or what was last brought in.
package/src/ui/app.css CHANGED
@@ -1763,7 +1763,59 @@ body.has-asks .prail { margin-top: calc(var(--update-bar, 0px) + var(--asks-bar)
1763
1763
  .ws.pj-cb .chat-resize, .ws.pj-cb .chat-rail, .ws.pj-cb #collapse-chat { display: none; }
1764
1764
  .ws.pj-cb[data-side-page="chat"] .ws-main { display: none; }
1765
1765
  .ws.pj-cb[data-side-page="chat"] .ws-chat { display: flex; }
1766
- .ws.pj-cb:is([data-side-page="connections"], [data-side-page="artifacts"]) :is(#main, #mainbar) { display: none; }
1766
+ .ws.pj-cb:is([data-side-page="connections"], [data-side-page="artifacts"], [data-side-page^="preview:"]) :is(#main, #mainbar) { display: none; }
1767
+
1768
+ /* ---- Previews of a codebase (preview-page.js): rows in the sidebars, and a preview's page: its head with the
1769
+ branch picker, and under it the app in a frame, or what it says while it starts. ---- */
1770
+ .pv-run { flex: none; width: 7px; height: 7px; margin: 0 3px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--faint); }
1771
+ .pv-run.on { background: var(--ok); box-shadow: none; }
1772
+ .pv-rows { display: flex; flex-direction: column; gap: 1px; }
1773
+ .pj-side .pv-rows button { display: flex; align-items: center; gap: 8px; width: 100%; height: 26px; padding: 0 10px 0 36px; border: 0; border-radius: 4px; background: transparent; cursor: pointer; color: var(--muted); font: inherit; font-size: 13px; text-align: left; }
1774
+ .pj-side .pv-rows.flat button { height: 28px; padding-left: 10px; gap: 10px; }
1775
+ .pj-side .pv-rows button:hover { background: var(--panel-2); color: var(--text); }
1776
+ .pj-side .pv-rows button.on { background: var(--panel-2); color: var(--text); font-weight: 600; }
1777
+ .pj-side .pv-rows svg { flex: none; width: 14px; height: 14px; color: var(--muted); }
1778
+ .pj-side .pv-rows.flat svg { width: 16px; height: 16px; }
1779
+ .pj-side .pv-rows .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1780
+ .pj-side .pj-side-label .btn.icon { margin-left: auto; }
1781
+ .pj-pmain.pv-view { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
1782
+ .pv-view > [data-pv-head], .pv-view > .pv-head { flex: none; }
1783
+ .pv-head { display: flex; align-items: center; gap: 10px; padding: 14px 24px; margin: 0; border-bottom: 1px solid var(--border); }
1784
+ .pv-head .pj-block, .pv-head > svg:first-child { flex: none; width: 34px; height: 34px; border-radius: 8px; }
1785
+ .pv-head .t { flex: 0 1 auto; min-width: 120px; overflow: hidden; }
1786
+ .pv-head h2, .pv-head p { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
1787
+ .pv-head h2 .sep { margin: 0 6px; color: var(--faint); font-weight: 400; }
1788
+ .pv-head p { display: flex; align-items: center; gap: 4px; }
1789
+ .pv-head p svg { flex: none; width: 13px; height: 13px; }
1790
+ .pv-head .spacer { flex: 1; }
1791
+ .pv-pick { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 30px; margin-left: 14px; padding: 0 4px 0 10px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--panel); color: var(--muted); }
1792
+ .pv-pick svg { width: 14px; height: 14px; }
1793
+ .pv-pick select { max-width: 240px; height: 26px; border: 0; background: none; font: inherit; font-size: 13px; font-weight: 600; color: var(--text); cursor: pointer; text-overflow: ellipsis; }
1794
+ .pv-pick .dd-btn { max-width: 260px; height: 26px; padding: 0 4px; border: 0; background: none; box-shadow: none; font-size: 13px; font-weight: 600; color: var(--text); }
1795
+ .pv-pick:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
1796
+ .pv-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
1797
+ .pv-frame { flex: 1; min-height: 0; display: flex; flex-direction: column; margin: 16px 24px 24px; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; background: var(--panel); }
1798
+ .pv-addr { flex: none; display: flex; align-items: center; height: 34px; padding: 0 12px; background: var(--panel-2); border-bottom: 1px solid var(--border); }
1799
+ .pv-addr .path { flex: 1; min-width: 0; height: 22px; padding: 0 10px; border-radius: 4px; background: var(--panel); font: 12px/22px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1800
+ .pv-addr code { flex: 0 1 auto; min-width: 0; max-width: 40%; margin-left: 10px; font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1801
+ iframe.pv-page { flex: 1; min-height: 0; width: 100%; border: 0; background: #fff; }
1802
+ .pv-wait { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; }
1803
+ .pv-said { display: flex; flex-direction: column; gap: 8px; min-height: 0; flex: 1; padding: 28px 28px 24px; }
1804
+ .pv-said h3 { margin: 0; font-size: 19px; font-weight: 600; }
1805
+ .pv-said p { margin: 0; }
1806
+ .pv-said .row { margin-top: 8px; }
1807
+ .pv-out { flex: 1; min-height: 80px; margin: 8px 0 0; padding: 12px 14px; overflow: auto; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2); font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
1808
+ .pv-form { flex: 1; min-height: 0; overflow-y: auto; padding: 20px 24px 28px; }
1809
+ .pv-form .seg.pv-kind { grid-template-columns: repeat(2, minmax(0, 1fr)); }
1810
+ .pv-form .seg.pv-kind button { font-size: 13px; padding: 9px 8px; }
1811
+ .pv-form-foot { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
1812
+ .pv-form-foot .spacer { flex: 1; }
1813
+ @media (max-width: 760px) {
1814
+ .pv-head { padding: 12px 14px; flex-wrap: wrap; }
1815
+ .pv-pick { margin-left: 0; }
1816
+ .pv-frame { margin: 12px 14px 14px; }
1817
+ .pv-form { padding: 14px; }
1818
+ }
1767
1819
  .ws.pj-cb .ws-main > .pj-pmain { flex: 1; }
1768
1820
  /* a call is in the channel: a screen someone shares there sits in the middle, the channel beside it */
1769
1821
  .ws.pj-cb[data-side-page="chat"]:has(#screen-stage:not([hidden])) .ws-main { display: flex; }
package/src/ui/app.js CHANGED
@@ -54,6 +54,8 @@ async function boot () {
54
54
  state.secretsOn = !!features.secrets
55
55
  // App connections (connections.js): Session settings → Connections, and approvals in the chat.
56
56
  state.connectionsOn = !!features.connections
57
+ // Previews of a codebase (preview-page.js): the rows in the sidebars and the preview's page.
58
+ state.previewsOn = !!features.previews
57
59
  if (state.secretsOn) watchSecretAsks()
58
60
  clearTimeout(waiting)
59
61
  const last = recall('view')
package/src/ui/common.js CHANGED
@@ -99,6 +99,7 @@ export const state = {
99
99
  workspacesOn: false, // the accounts API has workspaces on
100
100
  secretsOn: false, // the accounts API has secrets on (the vault is set up)
101
101
  connectionsOn: false, // the accounts API has app connections on (Composio's key is set)
102
+ previewsOn: false, // the accounts API runs previews of a codebase on cloud machines (plans/previews.md)
102
103
  workspace: null, // the open workspace page's data
103
104
  spaceFilter: 'all', // the home grid's Personal / org switch
104
105
  filesView: { folder: '', picked: null, mode: 'tiles' }, // the All files view: folder shown, file previewed, tiles or list
@@ -0,0 +1,221 @@
1
+ // A preview of a codebase (plans/previews.md): the rows in the sidebars, and the preview's own
2
+ // page. An app's preview runs on the codebase's cloud machine only while someone has it open:
3
+ // this page says it is open (and on which branch) while it shows, the machine starts that
4
+ // branch's app, and the page frames it at its address once it is up. A link is an address to open.
5
+ import { I, esc, avatar, api, toast, ask } from './common.js'
6
+ import { quiltBlock } from './project-model.js'
7
+
8
+ // The app keeps saying "still open" this often; the machine sleeps ten minutes after it stops.
9
+ const KEEP_OPEN_MS = 60 * 1000
10
+ const BRANCH = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="6" cy="5" r="2.5"/><circle cx="6" cy="19" r="2.5"/><circle cx="18" cy="8" r="2.5"/><path d="M6 7.5v9M18 10.5c0 4-6 3-6 6"/></svg>'
11
+
12
+ /** Whether an app's preview is running for anyone: a dot on its row. */
13
+ export const previewRunning = (p) => p.kind === 'app' && (p.running || []).some((r) => r.state !== 'failed')
14
+
15
+ /** A preview's row in a sidebar. `attrs`: what a click does there. */
16
+ export function previewRowHtml (p, { on = false, attrs = '', of = '' } = {}) {
17
+ const say = p.kind === 'link' ? `${p.name}: ${p.url}` : `${p.name}${of ? ` of ${of}` : ''}${previewRunning(p) ? ': someone has it open' : ': starts when you open it'}`
18
+ return `<button type="button" class="${on ? 'on' : ''}" ${attrs} title="${esc(say)}"${on ? ' aria-current="page"' : ''}>${p.kind === 'link' ? I.link : I.globe}<span class="nm">${esc(p.name)}</span>${previewRunning(p) ? '<span class="pv-run on"></span>' : ''}</button>`
19
+ }
20
+
21
+ const branchLabel = (b) => (b.main ? 'Main' : b.name)
22
+ const names = (list) => list.length > 1 ? `${list.slice(0, -1).join(', ')} and ${list.at(-1)}` : list[0] || ''
23
+
24
+ /**
25
+ * Draws preview `id` of the codebase `session` into `el` and keeps it up to date. `id` 'new': the
26
+ * form that adds one. `status()`: the codebase's status now; `saved(id)`: one was added or changed
27
+ * (show it); `gone()`: it was removed. Returns { update, destroy }.
28
+ */
29
+ export function mountPreview (el, { session, id, status, code = '', saved = () => {}, gone = () => {}, pick = {} }) {
30
+ let editing = id === 'new'
31
+ let kind = 'app' // the form's choice, for a new one
32
+ let open = null // what the accounts API answered: { state, machine, domain, ticket }
33
+ let failed = '' // why it could not be opened
34
+ let again = 0
35
+ let asked = '' // the preview and branch last said to be open
36
+ let bodyKey = ''
37
+ let headWas = ''
38
+ let missing = null
39
+ let started = false
40
+ let timer = null
41
+ let dead = false
42
+ const bound = new AbortController() // `el` outlives this page: its listeners go with it
43
+
44
+ const def = () => (status().previews || []).find((p) => p.id === id) || null
45
+ const branches = () => { const list = status().branches || []; return list.length ? list : [{ key: 'main', name: 'main', main: true }] }
46
+ const branch = () => { const list = branches(); return (list.find((b) => b.key === pick[id]) || list[0]).key }
47
+ const mayEdit = () => status().access?.role !== 'viewer'
48
+ const post = (route, body) => api('POST', `/api/sessions/${encodeURIComponent(session)}${route}`, body)
49
+
50
+ /** Tells the codebase (and, for an app, the accounts API) what this page has open. */
51
+ async function sayOpen () {
52
+ const p = def()
53
+ if (dead || !p || editing) return
54
+ const want = `${p.id}\n${branch()}\n${again}`
55
+ asked = want
56
+ try {
57
+ const r = await post('/previews/open', { id: p.id, branch: branch(), ...(again ? { again } : {}) })
58
+ if (dead || asked !== want) return
59
+ open = r.open
60
+ failed = ''
61
+ } catch (err) {
62
+ if (dead || asked !== want) return
63
+ failed = err.message || 'The preview could not be opened.'
64
+ }
65
+ draw()
66
+ }
67
+ const sayClosed = () => { asked = ''; post('/previews/open', { id: null }).catch(() => {}) }
68
+
69
+ // `port`: only in development, where the machine's program runs on this computer.
70
+ const originOf = (o, slot) => `${o.port ? 'http' : 'https'}://${o.machine}-${slot}.${o.domain}${o.port ? `:${o.port}` : ''}`
71
+ const origin = (slot) => originOf(open, slot)
72
+ const run = (p) => (p.running || []).find((r) => r.branch === branch()) || null
73
+
74
+ function headHtml (p) {
75
+ const edit = mayEdit() ? `<button type="button" class="btn sm ghost icon" data-pv-edit title="Change or remove this preview" aria-label="Change or remove this preview">${I.pencil}</button>` : ''
76
+ const title = `<h2 class="crumbs">${esc(code)}<span class="sep">/</span>${esc(p.name)}</h2>`
77
+ if (p.kind === 'link') {
78
+ return `<div class="files-head pv-head">${quiltBlock(code)}<div class="t">${title}<p class="hint">${I.link}<span>A link · ${esc(p.url)}</span></p></div><span class="spacer"></span>${edit}</div>`
79
+ }
80
+ const list = branches()
81
+ const at = branch()
82
+ const others = (p.looking || []).filter((l) => !l.me)
83
+ const here = others.filter((l) => l.branch === at).map((l) => l.name)
84
+ const elsewhere = list.filter((b) => b.key !== at).map((b) => [b, others.filter((l) => l.branch === b.key).map((l) => l.name)]).filter(([, who]) => who.length)
85
+ const who = here.length ? `${names(here)} ${here.length === 1 ? 'is' : 'are'} looking too` : elsewhere.map(([b, w]) => `${names(w)} ${w.length === 1 ? 'is' : 'are'} on ${branchLabel(b)}`).join(', ')
86
+ const r = run(p)
87
+ const word = failed ? 'Not running' : r && r.state === 'running' ? 'Running' : r && r.state === 'failed' ? 'It did not start' : 'Starting'
88
+ const opt = (b) => { const w = others.filter((l) => l.branch === b.key).map((l) => l.name); return `<option value="${esc(b.key)}"${b.key === at ? ' selected' : ''}>${esc(branchLabel(b))}${w.length ? ` · ${esc(w.join(', '))}` : ''}</option>` }
89
+ const up = r && r.state === 'running' && open
90
+ return `<div class="files-head pv-head">${quiltBlock(code)}<div class="t">${title}<p class="hint" title="It runs only while someone has it open."><span class="pv-run${word === 'Running' ? ' on' : ''}"></span><span>${word}</span>${who ? `<span> · ${esc(who)}</span>` : ''}</p></div>
91
+ <label class="pv-pick" title="The branch this preview shows you. Each person picks their own.">${BRANCH}<select data-pv-branch aria-label="Branch to preview">${list.map(opt).join('')}</select></label>
92
+ <span class="spacer"></span>
93
+ ${here.length ? `<span class="pj-faces sm" title="${esc(who)}">${here.map((n) => avatar(n)).join('')}</span>` : ''}
94
+ <button type="button" class="btn sm ghost icon" data-pv-reload title="Reload" aria-label="Reload"${up ? '' : ' disabled'}>${I.refresh}</button><button type="button" class="btn sm ghost icon" data-pv-out title="Open in your browser" aria-label="Open in your browser"${up ? '' : ' disabled'}>${I.external}</button>${edit}</div>`
95
+ }
96
+
97
+ /** What is under the head, and a key that changes only when it has to be drawn again (a running app's frame is left alone). */
98
+ function bodyOf (p) {
99
+ if (p.kind === 'link') {
100
+ return { key: `link ${p.url}`, html: `<div class="pv-frame"><div class="pv-addr"><span class="path">${esc(p.url)}</span></div><div class="pv-wait"><div class="main-empty"><div class="ill">${I.link}</div><h3>${esc(p.name)}</h3><p class="hint">${esc(p.url)}</p><div class="row"><a class="btn primary" href="${esc(p.url)}" target="_blank" rel="noopener noreferrer">${I.external}<span>Open in your browser</span></a></div></div></div></div>` }
101
+ }
102
+ const at = branch()
103
+ const label = branchLabel(branches().find((b) => b.key === at) || { name: at })
104
+ const r = run(p)
105
+ const bar = (path) => `<div class="pv-addr"><span class="path">${esc(path)}</span><code>${esc(at)}</code></div>`
106
+ if (failed) return { key: `failed ${failed}`, html: `<div class="pv-frame">${bar('/')}<div class="pv-wait"><div class="main-empty"><h3>This preview could not be opened</h3><p class="hint">${esc(failed)}</p><div class="row"><button type="button" class="btn primary" data-pv-again>Try again</button></div></div></div></div>` }
107
+ if (r && r.state === 'running' && open && open.machine) {
108
+ const src = `${origin(r.slot)}/?quilt_ticket=${encodeURIComponent(open.ticket)}`
109
+ return { key: `running ${open.machine} ${r.slot}`, html: `<div class="pv-frame">${bar(`${open.machine}-${r.slot}.${open.domain}`)}<iframe class="pv-page" title="${esc(p.name)} on ${esc(label)}" src="${esc(src)}" referrerpolicy="no-referrer" allow="clipboard-read; clipboard-write; fullscreen"></iframe></div>` }
110
+ }
111
+ const out = r && r.output ? `<pre class="pv-out">${esc(r.output)}</pre>` : ''
112
+ if (r && r.state === 'failed') return { key: `did-not-start ${r.output}`, html: `<div class="pv-frame">${bar('/')}<div class="pv-wait"><div class="pv-said"><h3>It did not start</h3><p class="hint">${esc(p.name)} on ${esc(label)} stopped before it was up. The last of what it printed:</p>${out || '<p class="hint">Nothing was printed.</p>'}<div class="row"><button type="button" class="btn primary" data-pv-again>Try again</button></div></div></div></div>` }
113
+ const why = !open ? 'Asking for this codebase\'s preview machine…' : !r ? 'Waking this codebase\'s preview machine and getting this branch\'s files…' : 'Installing and starting it. This page shows it when it is up.'
114
+ return { key: `starting ${at} ${r ? r.output : ''} ${why}`, html: `<div class="pv-frame">${bar('/')}<div class="pv-wait"><div class="pv-said"><h3>Starting ${esc(label)}…</h3><p class="hint">${esc(why)}</p>${out}</div></div></div>` }
115
+ }
116
+
117
+ function formHtml (p) {
118
+ const k = p ? p.kind : kind
119
+ const f = (label, control, hint = '') => `<div class="field"><span class="label">${label}</span>${control}${hint ? `<span class="hint">${hint}</span>` : ''}</div>`
120
+ const v = (x) => esc(x === undefined || x === null || x === 0 ? '' : x)
121
+ return `<div class="files-head pv-head">${quiltBlock(code)}<div class="t"><h2 class="crumbs">${esc(code)}<span class="sep">/</span>${p ? esc(p.name) : 'New preview'}</h2><p class="hint">${p ? 'Everyone in this codebase sees the change.' : 'A preview shows this codebase\'s app running, or is a link everyone here should have at hand.'}</p></div></div>
122
+ <form class="pv-form" data-pv-form>
123
+ ${p ? '' : `<div class="field"><span class="label">What it is</span><div class="seg pv-kind" role="radiogroup" aria-label="What it is"><button type="button" role="radio" data-pv-kind="app" aria-checked="${k === 'app'}" class="${k === 'app' ? 'on' : ''}">The app, running</button><button type="button" role="radio" data-pv-kind="link" aria-checked="${k === 'link'}" class="${k === 'link' ? 'on' : ''}">A link</button></div></div>`}
124
+ ${f('Name', `<input class="input" name="name" maxlength="40" required placeholder="${k === 'link' ? 'Production' : 'Storybook'}" value="${v(p && p.name)}">`)}
125
+ ${k === 'link'
126
+ ? f('Address', `<input class="input mono" name="url" type="url" required spellcheck="false" placeholder="https://" value="${v(p && p.url)}">`)
127
+ : f('Command', `<input class="input mono" name="command" maxlength="300" spellcheck="false" placeholder="npm run dev" value="${v(p && p.command)}">`, 'Left empty, it is the codebase\'s dev script. It is run on a cloud machine, on the branch each person picks.') +
128
+ f('Folder', `<input class="input mono" name="folder" spellcheck="false" placeholder="The codebase's own folder" value="${v(p && p.folder)}">`, 'Where the command is run, for an app that lives in a folder of the codebase.') +
129
+ f('Port', `<input class="input mono" name="port" inputmode="numeric" pattern="[0-9]*" placeholder="Found by itself" value="${v(p && p.port)}">`, 'Only when the app opens another port than the one it is given (PORT) and does not print its address.')}
130
+ <span class="hint warn" data-pv-warn hidden></span>
131
+ <div class="pv-form-foot"><button type="submit" class="btn primary">${p ? 'Save' : 'Add preview'}</button><button type="button" class="btn ghost" data-pv-cancel>Cancel</button><span class="spacer"></span>${p ? `<button type="button" class="btn danger" data-pv-remove>${I.trash}<span>Remove</span></button>` : ''}</div>
132
+ </form>`
133
+ }
134
+
135
+ function draw () {
136
+ if (dead) return
137
+ const p = def()
138
+ // Not there: removed by someone, or added a moment ago and not in this window's status yet.
139
+ if (id !== 'new' && !p) { if (!missing) missing = setTimeout(() => { missing = null; if (!dead && !def()) gone(); else draw() }, 1500); return }
140
+ // Said to be open once it is there to open (one just added arrives a moment after its page).
141
+ if (!started && !editing) { started = true; start() }
142
+ if (editing) {
143
+ if (bodyKey !== 'form') { bodyKey = 'form'; el.innerHTML = formHtml(p); el.querySelector('input[name="name"]')?.focus() }
144
+ return
145
+ }
146
+ const body = bodyOf(p)
147
+ let head = el.querySelector('[data-pv-head]')
148
+ let box = el.querySelector('[data-pv-body]')
149
+ if (!head || !box) { el.innerHTML = '<div data-pv-head></div><div class="pv-body" data-pv-body></div>'; head = el.querySelector('[data-pv-head]'); box = el.querySelector('[data-pv-body]'); bodyKey = ''; headWas = '' }
150
+ // Drawn again only when it changed, and never while the branch picker is open: that would close it.
151
+ const top = headHtml(p)
152
+ if (top !== headWas && !head.querySelector('.dd-btn[aria-expanded="true"]')) { headWas = top; head.innerHTML = top }
153
+ if (body.key !== bodyKey) {
154
+ bodyKey = body.key
155
+ box.innerHTML = body.html
156
+ const out = box.querySelector('.pv-out')
157
+ if (out) out.scrollTop = out.scrollHeight
158
+ }
159
+ }
160
+
161
+ function start () {
162
+ const p = def()
163
+ clearInterval(timer)
164
+ timer = null
165
+ if (!p || editing) return
166
+ open = null
167
+ failed = ''
168
+ sayOpen()
169
+ if (p.kind === 'app') timer = setInterval(sayOpen, KEEP_OPEN_MS)
170
+ }
171
+
172
+ el.addEventListener('change', (e) => {
173
+ const sel = e.target.closest('[data-pv-branch]')
174
+ if (!sel) return
175
+ pick[id] = sel.value
176
+ again = 0
177
+ sel.blur()
178
+ draw()
179
+ start()
180
+ }, { signal: bound.signal })
181
+ el.addEventListener('click', async (e) => {
182
+ const b = e.target.closest('button')
183
+ if (!b || !el.contains(b)) return
184
+ if (b.hasAttribute('data-pv-reload')) { const f = el.querySelector('iframe.pv-page'); const r = run(def()); if (f && r && open) f.src = `${origin(r.slot)}/` }
185
+ if (b.hasAttribute('data-pv-out')) {
186
+ // A fresh ticket: the browser has no cookie for this address yet.
187
+ const r = run(def())
188
+ try { const got = await post('/previews/open', { id, branch: branch() }); if (r && got.open) window.open(`${originOf(got.open, r.slot)}/?quilt_ticket=${encodeURIComponent(got.open.ticket)}`, '_blank', 'noopener') } catch (err) { toast(err.message) }
189
+ }
190
+ if (b.hasAttribute('data-pv-again')) { again++; bodyKey = ''; start(); draw() }
191
+ if (b.hasAttribute('data-pv-edit')) { editing = true; bodyKey = ''; clearInterval(timer); sayClosed(); draw() }
192
+ if (b.dataset.pvKind) { kind = b.dataset.pvKind; bodyKey = ''; draw() }
193
+ if (b.hasAttribute('data-pv-cancel')) { if (id === 'new') return gone(); editing = false; bodyKey = ''; el.innerHTML = ''; draw(); start() }
194
+ if (b.hasAttribute('data-pv-remove')) {
195
+ const p = def()
196
+ if (!(await ask({ title: `Remove ${p.name}?`, message: 'It is removed for everyone in this codebase.', ok: 'Remove', danger: true }))) return
197
+ try { await post('/previews/remove', { id }); gone() } catch (err) { toast(err.message) }
198
+ }
199
+ }, { signal: bound.signal })
200
+ el.addEventListener('submit', async (e) => {
201
+ const form = e.target.closest('[data-pv-form]')
202
+ if (!form) return
203
+ e.preventDefault()
204
+ const p = def()
205
+ const get = (n) => form.elements[n] ? form.elements[n].value.trim() : undefined
206
+ const k = p ? p.kind : kind
207
+ const body = { ...(p ? { id: p.id } : { kind: k }), name: get('name'), ...(k === 'link' ? { url: get('url') } : { command: get('command'), folder: get('folder'), port: Number(get('port')) || 0 }) }
208
+ const warn = form.querySelector('[data-pv-warn]')
209
+ try {
210
+ const r = await post('/previews', body)
211
+ saved(r.preview.id)
212
+ } catch (err) { warn.textContent = err.message; warn.hidden = false }
213
+ }, { signal: bound.signal })
214
+
215
+ draw()
216
+ return {
217
+ /** The codebase's status changed: who is looking, what runs, the branches. */
218
+ update: draw,
219
+ destroy () { dead = true; bound.abort(); clearInterval(timer); clearTimeout(missing); if (asked) sayClosed() }
220
+ }
221
+ }
@@ -14,6 +14,7 @@ import { mountProjectBoard, projectOpenTasks } from './project-board.js'
14
14
  import { mountConnections, whoWords } from './connections.js'
15
15
  import { toolLogo } from './tool-logo.js'
16
16
  import { FOREIGN_JOINS } from './agent-place.js'
17
+ import { previewRowHtml } from './preview-page.js'
17
18
 
18
19
  const colorOf = (w) => COLORS[w.color] || COLORS.lilac
19
20
  const tile = (w, size = '') => `<span class="pj-tile ${size}" style="background:${esc(colorOf(w))}">${esc(tileLetter(w.name))}</span>`
@@ -194,7 +195,9 @@ function sideHtml (p, d, page) {
194
195
  const row = (c) => {
195
196
  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)}"`
196
197
  const say = c.where === 'away' ? 'Not on this computer yet: join it' : `Open ${c.name}${c.dir ? ` (${c.dir})` : ''}`
197
- return `<div class="pj-code${c.where === 'away' ? ' away' : ''}"><button type="button" ${act} title="${esc(say)}">${quiltBlock(c.name)}<span class="nm grow">${esc(c.name)}</span>${faces(c.faces)}</button></div>`
198
+ // Its previews, when it is open here (a codebase's previews are read from the codebase itself).
199
+ const pvs = state.previewsOn && c.where === 'open' ? (state.sessions.get(c.id)?.status.previews || []) : []
200
+ return `<div class="pj-code${c.where === 'away' ? ' away' : ''}"><button type="button" ${act} title="${esc(say)}">${quiltBlock(c.name)}<span class="nm grow">${esc(c.name)}</span>${faces(c.faces)}</button></div>${pvs.length ? `<div class="pv-rows">${pvs.map((p) => previewRowHtml(p, { of: c.name, attrs: `data-go-preview="${esc(c.id)}" data-preview="${esc(p.id)}"` })).join('')}</div>` : ''}`
198
201
  }
199
202
  return `
200
203
  <aside class="pj-side" aria-label="${esc(p.name)}">
@@ -230,15 +233,21 @@ export function codeCrumbHtml (project) {
230
233
  * `tasks`: its open tasks; `artifacts`: how many the project has, once known; `chatNew`: messages in its channel since it was last looked at;
231
234
  * `people`: who is in it, you first ({ name, color }).
232
235
  */
233
- export function codeSideHtml ({ page, name, project, tasks = 0, artifacts = 0, chatNew = 0, people = [], connections = false, canInvite = true, dms = [], dmOn = '', call = 0 }) {
236
+ export function codeSideHtml ({ page, name, project, tasks = 0, artifacts = 0, chatNew = 0, people = [], connections = false, canInvite = true, dms = [], dmOn = '', call = 0, previews = null, canEdit = false }) {
234
237
  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>`
235
238
  const isFolded = (k) => foldedNow().has(k)
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>`
239
+ 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 new">${n}</span>` : ''}${extra}</div>`
240
+ // Previews (preview-page.js): the codebase's app running, and links. `previews` null: this server runs none.
241
+ const pvOn = page.startsWith('preview:') ? page.slice('preview:'.length) : ''
242
+ const pvs = previews || []
243
+ const pvHtml = !previews || (!pvs.length && !canEdit) ? '' : `${label('previews', 'Previews', 0, canEdit ? `<button type="button" class="btn sm ghost icon" data-code-page="preview:new" title="New preview" aria-label="New preview">${I.plus}</button>` : '')}
244
+ <div class="side-sessions pv-rows flat">${pvs.filter((p) => !isFolded('previews') || p.id === pvOn).map((p) => previewRowHtml(p, { on: p.id === pvOn, of: name, attrs: `data-code-page="preview:${esc(p.id)}"` })).join('')}</div>`
237
245
  // A folded section keeps the row you are on, what is new, and a call going on.
238
246
  const channel = !isFolded('channels') || page === 'chat' || chatNew || call
239
247
  const inDm = page === 'chat' ? dmOn : ''
240
248
  return `
241
249
  <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>
250
+ ${pvHtml}
242
251
  ${label('channels', 'Channels', chatNew)}
243
252
  <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
253
  ${dms.length ? `${label('dms', 'Direct messages')}
@@ -422,6 +431,7 @@ export function bindProjectShell (view, { go, rerender, newSessionDialog, joinSe
422
431
  if (channel) mountChannel(channel, { d, changed: newCount })
423
432
  // A codebase's channel, or a direct message in it: the codebase opens on its chat.
424
433
  root.querySelectorAll('[data-go-chat]').forEach((b) => { b.onclick = () => { state.openChat = b.dataset.goChat; state.to = ''; go(b.dataset.goChat) } })
434
+ root.querySelectorAll('[data-go-preview]').forEach((b) => { b.onclick = () => { state.openPreview = { id: b.dataset.goPreview, preview: b.dataset.preview }; go(b.dataset.goPreview) } })
425
435
  root.querySelectorAll('[data-go-dm]').forEach((b) => { b.onclick = () => { state.openChat = b.dataset.goDm; state.to = b.dataset.name; go(b.dataset.goDm) } })
426
436
  const board = root.querySelector('[data-project-board]')
427
437
  // The open count beside Tasks follows the board as it changes.