heyquilt 0.3.182 → 0.3.183

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.
Files changed (122) hide show
  1. package/README.md +101 -97
  2. package/RELEASES.md +8 -0
  3. package/bin/quilt.js +32 -32
  4. package/desktop/main.js +1 -1
  5. package/package.json +1 -1
  6. package/src/account.js +2 -2
  7. package/src/admit-policy.js +2 -2
  8. package/src/agent-join.js +3 -3
  9. package/src/agent-task-workflow.js +14 -14
  10. package/src/ai-vm.js +1 -1
  11. package/src/api/agent-placement.js +2 -2
  12. package/src/api/audit.js +1 -1
  13. package/src/api/file-paths.js +1 -1
  14. package/src/api/file-store.js +1 -1
  15. package/src/api/invite-email.js +4 -4
  16. package/src/api/join-text.js +5 -5
  17. package/src/api/notify.js +7 -7
  18. package/src/api/permissions.js +1 -1
  19. package/src/api/routes/agent-wake.js +1 -1
  20. package/src/api/routes/agents.js +2 -2
  21. package/src/api/routes/ai-vm.js +5 -5
  22. package/src/api/routes/connections.js +13 -13
  23. package/src/api/routes/grants.js +2 -2
  24. package/src/api/routes/mail.js +10 -10
  25. package/src/api/routes/relay.js +1 -1
  26. package/src/api/routes/secrets.js +11 -11
  27. package/src/api/routes/session-invites.js +5 -5
  28. package/src/api/routes/sessions.js +3 -3
  29. package/src/api/routes/workspace-agents.js +14 -14
  30. package/src/api/routes/workspace-files.js +12 -12
  31. package/src/api/routes/workspace-invites.js +5 -5
  32. package/src/api/routes/workspaces.js +11 -11
  33. package/src/api/secrets-access.js +1 -1
  34. package/src/api/server.js +3 -3
  35. package/src/api/team-access.js +1 -1
  36. package/src/api/workspace-access.js +1 -1
  37. package/src/api/workspace-reach.js +3 -3
  38. package/src/app-tools.js +10 -10
  39. package/src/autowork.js +4 -4
  40. package/src/branch-view.js +1 -1
  41. package/src/catchup.js +5 -5
  42. package/src/chat-links.js +18 -18
  43. package/src/connection.js +11 -11
  44. package/src/control.js +5 -5
  45. package/src/conversation.js +1 -1
  46. package/src/doctor.js +2 -2
  47. package/src/duties.js +1 -1
  48. package/src/fsutil.js +1 -1
  49. package/src/held.js +4 -4
  50. package/src/hooks.js +3 -3
  51. package/src/hosted-client.js +2 -2
  52. package/src/identity.js +1 -1
  53. package/src/inbox.js +1 -1
  54. package/src/key-cli.js +1 -1
  55. package/src/mail-tools.js +11 -11
  56. package/src/mcp-proxy.js +1 -1
  57. package/src/mcp.js +59 -59
  58. package/src/new-session.js +6 -6
  59. package/src/project-rules.js +2 -2
  60. package/src/relay-ask.js +2 -2
  61. package/src/relay-cluster.js +3 -3
  62. package/src/relay-live-write.js +3 -3
  63. package/src/relay-mcp.js +56 -56
  64. package/src/relay-prune.js +1 -1
  65. package/src/relay-turn-sync.js +1 -1
  66. package/src/secret-import.js +1 -1
  67. package/src/secret-names.js +6 -6
  68. package/src/secret-run.js +3 -3
  69. package/src/server.js +41 -41
  70. package/src/session-access.js +3 -3
  71. package/src/session-name.js +1 -1
  72. package/src/session.js +50 -50
  73. package/src/setup.js +7 -7
  74. package/src/status.js +2 -2
  75. package/src/tasks.js +1 -1
  76. package/src/turn-sync.js +4 -4
  77. package/src/ui/account-sessions.js +2 -2
  78. package/src/ui/agent-env-key.js +1 -1
  79. package/src/ui/agent-guide.js +35 -35
  80. package/src/ui/agent-kinds.js +8 -8
  81. package/src/ui/agent-place.js +16 -16
  82. package/src/ui/agents-table.js +6 -6
  83. package/src/ui/app.css +331 -0
  84. package/src/ui/app.js +28 -13
  85. package/src/ui/board.js +2 -2
  86. package/src/ui/catchup.js +5 -5
  87. package/src/ui/changes-seen.js +2 -2
  88. package/src/ui/changes.js +3 -3
  89. package/src/ui/cloud-ai.js +12 -12
  90. package/src/ui/common.js +1 -1
  91. package/src/ui/connections.js +1 -1
  92. package/src/ui/diffview.js +2 -2
  93. package/src/ui/feed.js +1 -1
  94. package/src/ui/feedback.js +4 -4
  95. package/src/ui/files.js +120 -14
  96. package/src/ui/fileview.js +3 -3
  97. package/src/ui/git-rule.js +3 -3
  98. package/src/ui/home.js +92 -47
  99. package/src/ui/index.html +1 -1
  100. package/src/ui/invite.js +8 -8
  101. package/src/ui/invites.js +3 -3
  102. package/src/ui/new-session.js +3 -3
  103. package/src/ui/prail-model.js +22 -0
  104. package/src/ui/prail.js +43 -0
  105. package/src/ui/project-board.js +359 -0
  106. package/src/ui/project-model.js +197 -0
  107. package/src/ui/project-pop.js +451 -0
  108. package/src/ui/projects.js +406 -0
  109. package/src/ui/sandbox-keys.js +3 -3
  110. package/src/ui/secrets-view.js +5 -5
  111. package/src/ui/session-words.js +2 -2
  112. package/src/ui/session.js +156 -43
  113. package/src/ui/tree.js +3 -3
  114. package/src/ui/voice.js +6 -6
  115. package/src/ui/workspaces.js +23 -23
  116. package/src/ui-server.js +78 -24
  117. package/src/update-check.js +2 -2
  118. package/src/voice.js +7 -7
  119. package/src/wake-tool.js +1 -1
  120. package/src/webhooks.js +1 -1
  121. package/src/workspace-cli.js +12 -12
  122. package/src/workspace-tools.js +33 -33
@@ -0,0 +1,451 @@
1
+ // The pop-ups of a project (projects on): New project, and a project's own settings (what it is,
2
+ // its people, its agents, its connections). Both are the one pop-up the app has: the Settings
3
+ // pop-up's size, a list on the left, the picked part on the right, and for the one that makes
4
+ // something a bar along the bottom with the button that makes it.
5
+ import { I, state, $, esc, api, toast, ask, avatar, COLORS, bytes } from './common.js'
6
+ import { go, pickFolder, drawRail } from './app.js'
7
+ import { renderShell, tildify, openSettings } from './home.js'
8
+ import { loadWorkspaces, openWorkspace } from './workspaces.js'
9
+ import { mountConnections } from './connections.js'
10
+ import { tileLetter } from './prail-model.js'
11
+ import { toolLogo } from './tool-logo.js'
12
+ import { FOREIGN_JOINS } from './agent-place.js'
13
+ import { quiltMark } from './mark.js'
14
+ import { readEmails, newProjectSteps, newProjectSummary, projectPeople } from './project-model.js'
15
+
16
+ const wsUrl = (id, rest = '') => `/api/workspaces/${encodeURIComponent(id)}${rest}`
17
+ const card = (h2, p, body, extra = '') => `<section class="card settings-sec"><div class="sec-intro"><h2>${h2}</h2><p>${p}</p>${extra}</div><div class="sec-body">${body}</div></section>`
18
+ const field = (label, control, hint = '') => `<div class="field"><span class="label">${label}</span>${control}${hint ? `<span class="hint">${hint}</span>` : ''}</div>`
19
+ const swatches = (picked, disabled = false) => `<div class="swatches">${Object.entries(COLORS).map(([k, c]) => `<label class="swatch"><input type="radio" name="color" value="${k}" ${picked === k ? 'checked' : ''} ${disabled ? 'disabled' : ''}><span style="background:${c}"></span></label>`).join('')}</div>`
20
+ const tile = (name, color, size = '') => `<span class="pj-tile ${size}" style="background:${esc(COLORS[color] || COLORS.lilac)}">${esc(tileLetter(name))}</span>`
21
+ const sw = (attrs, on, { disabled = false, why = '' } = {}) => `<label class="toggle"${why ? ` title="${esc(why)}"` : ''}><input type="checkbox" ${attrs} ${on ? 'checked' : ''} ${disabled ? 'disabled' : ''}><span class="track"><span class="knob"></span></span></label>`
22
+ const scopePill = (own) => `<span class="pill pj-scope${own ? ' own' : ''}">${own ? 'This project' : 'Every project'}</span>`
23
+ /** One row of a list in a card: an icon, a name with what it is under it, and its control on the right. */
24
+ const row = (icon, name, hint, control, pill = '') => `<div class="pj-g-row"><span class="pj-face ink">${icon}</span><div class="t"><b>${name}${pill}</b>${hint ? `<span class="hint">${hint}</span>` : ''}</div><span class="pj-g-act">${control}</span></div>`
25
+ const agentHint = (a) => [a.provider ? `${toolLogo(a.provider, { className: 'pj-tool' })}${esc(a.provider)}` : '', esc(a.description || a.type || '')].filter(Boolean).join(' · ')
26
+
27
+ /**
28
+ * The pop-up. `groups`: [{ label, items: [{ id, label, heading?, icon }] }], the list on the left;
29
+ * `body(id)`: the picked part's HTML; `bind(id, el)`: makes it work, after each drawing; `foot`:
30
+ * { hint, go } for a pop-up that makes something; `summary`: { label, rows() } under the list.
31
+ * Returns { back, pick, redraw, close, setGo, drawSummary, error, busy }.
32
+ */
33
+ export function popup ({ id, title, lead, mark = '', groups, section, body, bind = () => {}, foot = null, summary = null }) {
34
+ $(`#${id}`)?.remove()
35
+ const back = document.createElement('div')
36
+ back.id = id
37
+ back.className = 'modal-back settings-back'
38
+ const all = groups.flatMap((g) => g.items)
39
+ back.innerHTML = `
40
+ <div class="settings-modal pj-pop" role="dialog" aria-modal="true" aria-labelledby="${id}-title">
41
+ <nav class="ss-nav settings-nav" aria-label="${esc(title)}">
42
+ <h3 id="${id}-title">${mark}<span>${esc(title)}</span></h3>
43
+ <p class="lead settings-scope">${esc(lead)}</p>
44
+ ${groups.map((g) => `${g.label ? `<div class="label nc-label">${esc(g.label)}</div>` : ''}<div class="ss-tabs settings-tabs" role="tablist" aria-orientation="vertical">${g.items.map((t) => `<button type="button" role="tab" class="ss-tab" data-tab="${t.id}">${t.icon || ''}<span>${esc(t.label)}</span></button>`).join('')}</div>`).join('')}
45
+ ${summary ? '<div class="nc-sum" data-sum></div>' : ''}
46
+ </nav>
47
+ <div class="ss-main">
48
+ <div class="ss-head"><h4 class="ss-name"></h4><button class="btn sm ghost icon ss-close" type="button" data-pop-close aria-label="Close">${I.x}</button></div>
49
+ <div class="settings-body" role="tabpanel"></div>
50
+ ${foot ? `<div class="nc-foot"><div class="grow"><span class="hint">${esc(foot.hint)}</span><p class="error" data-pop-error></p></div>
51
+ <button type="button" class="btn ghost" data-pop-close>Cancel</button><button type="button" class="btn primary" data-pop-go><span>${esc(foot.go)}</span>${I.arrowRight}</button></div>` : ''}
52
+ </div>
53
+ </div>`
54
+ document.body.appendChild(back)
55
+ const el = $('.settings-body', back)
56
+ let picked = ''
57
+ const close = () => back.remove()
58
+ const drawSummary = () => { if (summary) $('[data-sum]', back).innerHTML = `<div class="label">${esc(summary.label)}</div>${summary.rows().map(([k, v]) => `<div class="nc-sum-row"><span>${esc(k)}</span><b title="${esc(v)}">${esc(v)}</b></div>`).join('')}` }
59
+ const redraw = () => {
60
+ const scroll = el.scrollTop
61
+ el.innerHTML = body(picked)
62
+ el.scrollTop = scroll
63
+ drawSummary()
64
+ bind(picked, el)
65
+ }
66
+ const pick = (to) => {
67
+ const t = all.find((x) => x.id === to) || all[0]
68
+ picked = t.id
69
+ for (const b of back.querySelectorAll('.ss-tab')) { const on = b.dataset.tab === t.id; b.classList.toggle('on', on); b.setAttribute('aria-selected', on); b.tabIndex = on ? 0 : -1 }
70
+ $('.ss-name', back).textContent = t.heading || t.label
71
+ el.scrollTop = 0
72
+ redraw()
73
+ }
74
+ back.addEventListener('mousedown', (e) => { if (e.target === back) close() })
75
+ back.addEventListener('keydown', (e) => { if (e.key === 'Escape') close() })
76
+ back.addEventListener('click', (e) => {
77
+ if (e.target.closest('[data-pop-close]')) return close()
78
+ const tab = e.target.closest('.ss-tab')
79
+ if (tab && !tab.classList.contains('on')) { pick(tab.dataset.tab); tab.focus() }
80
+ })
81
+ $('.ss-nav', back).addEventListener('keydown', (e) => {
82
+ if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return
83
+ e.preventDefault()
84
+ const i = all.findIndex((t) => t.id === picked)
85
+ pick(all[(i + (e.key === 'ArrowDown' ? 1 : all.length - 1)) % all.length].id)
86
+ back.querySelector('.ss-tab.on')?.focus()
87
+ })
88
+ const goBtn = $('[data-pop-go]', back)
89
+ const pop = {
90
+ back,
91
+ pick,
92
+ redraw,
93
+ close,
94
+ drawSummary,
95
+ picked: () => picked,
96
+ setGo: (text) => { if (goBtn && !goBtn.disabled) goBtn.firstElementChild.textContent = text },
97
+ setTitle: (text, markHtml = '') => { $('.ss-nav h3', back).innerHTML = `${markHtml}<span>${esc(text)}</span>` },
98
+ error: (text) => { const p = $('[data-pop-error]', back); if (p) p.textContent = text || '' },
99
+ /** The bottom button while the thing is being made: what it is doing, or null when it stopped. */
100
+ busy: (text, label) => {
101
+ if (!goBtn) return
102
+ goBtn.disabled = text !== null
103
+ goBtn.innerHTML = text !== null ? `${quiltMark({ word: false, loop: true, cls: 'qm-inline' })}<span>${esc(text)}</span>` : `<span>${esc(label)}</span>${I.arrowRight}`
104
+ }
105
+ }
106
+ pick(section)
107
+ ;(el.querySelector('input:not([type=radio]):not([type=checkbox])') || back.querySelector('.ss-tab.on'))?.focus()
108
+ return pop
109
+ }
110
+
111
+ /** A box of email addresses as chips: Enter, a comma or a space adds what is typed; × takes one out. */
112
+ function chipsHtml (emails, placeholder = 'Add an email') {
113
+ return `<div class="input pj-chips" data-chips>${emails.map((e) => `<span>${esc(e)}<button type="button" data-chip-x="${esc(e)}" aria-label="Remove ${esc(e)}">${I.x}</button></span>`).join('')}<input type="email" placeholder="${esc(placeholder)}" aria-label="${esc(placeholder)}" autocomplete="off"></div><span class="hint warn" data-chips-warn hidden></span>`
114
+ }
115
+ function bindChips (root, emails, changed) {
116
+ const box = $('[data-chips]', root)
117
+ if (!box) return
118
+ const input = $('input', box)
119
+ const warn = $('[data-chips-warn]', root)
120
+ // Takes the addresses out of what is typed; what is not one stays in the box, with why.
121
+ const take = () => {
122
+ const { good, bad } = readEmails(input.value)
123
+ if (!good.length && !bad.length) return false
124
+ for (const e of good) if (!emails.includes(e)) emails.push(e)
125
+ input.value = bad.join(' ')
126
+ warn.hidden = !bad.length
127
+ warn.textContent = bad.length ? `Not an email address: ${bad.join(', ')}` : ''
128
+ return good.length > 0
129
+ }
130
+ // The part is drawn again with the new chips: what was left in the box, and the cursor, are put back.
131
+ const drawn = (refocus) => {
132
+ const left = input.value; const why = warn.textContent
133
+ changed()
134
+ const again = $('[data-chips] input', root); const w = $('[data-chips-warn]', root)
135
+ if (!again) return
136
+ again.value = left
137
+ if (w) { w.textContent = why; w.hidden = !why }
138
+ if (refocus) again.focus()
139
+ }
140
+ box.onclick = (e) => {
141
+ const x = e.target.closest('[data-chip-x]')
142
+ if (x) { emails.splice(emails.indexOf(x.dataset.chipX), 1); drawn(true) } else input.focus()
143
+ }
144
+ input.onkeydown = (e) => {
145
+ if (e.key === 'Enter' || e.key === ',' || e.key === ' ') { e.preventDefault(); if (take()) drawn(true) } else if (e.key === 'Backspace' && !input.value && emails.length) { emails.pop(); drawn(true) }
146
+ }
147
+ input.onblur = () => { if (take()) drawn(false) }
148
+ input.onpaste = () => setTimeout(() => { if (/[\s,;]/.test(input.value) && take()) drawn(true) })
149
+ }
150
+
151
+ /** Your agents with where each works, asked once for a pop-up that lists them. */
152
+ async function placedAgents () {
153
+ if (!state.placedAgents) { try { state.placedAgents = (await api('GET', '/api/agents/placed')).agents || [] } catch { state.placedAgents = [] } }
154
+ return state.placedAgents
155
+ }
156
+
157
+ // ------------------------------------------------------------ New project --
158
+ const CODE_WAYS = {
159
+ github: { icon: 'github', add: 'Add from GitHub', placeholder: 'owner/name or https://github.com/owner/name', says: (l) => `Cloned to ${tildify(l.dir)}` },
160
+ folder: { icon: 'folder', add: 'Add a folder', says: (l) => l.git ? 'This folder has git already.' : 'No git here yet: Quilt sets it up.' },
161
+ scratch: { icon: 'plus', add: 'Start from scratch', placeholder: 'Its name, like neon-dungeon', says: (l) => `A new folder, ${tildify(l.dir)}` }
162
+ }
163
+
164
+ /** New project: its name, colour and about; the repositories to start with, the people to invite and the agents it gets. */
165
+ export function openNewProject (section = 'basics') {
166
+ const v = { name: '', about: '', color: 'peach', code: [], emails: [], agents: {} } // agents: { id: on } where you changed one
167
+ let adding = '' // the way a codebase is being added right now ('github' | 'scratch')
168
+ let agents = null
169
+ const on = (a) => v.agents[a.id] ?? (a.placement?.reach === 'all')
170
+ const named = () => v.name.trim()
171
+ const preview = () => `
172
+ <div class="pj-preview">
173
+ <div><span class="label">On the left</span><div class="pj-preview-rail">${tile(named() || 'Your project', v.color, 'on')}</div></div>
174
+ <div><span class="label">At the top</span><div class="pj-preview-top">${tile(named() || 'Your project', v.color, 'xs')}<b>${esc(named() || 'Your project')}</b></div>${v.about.trim() ? `<p class="hint">${esc(v.about.trim())}</p>` : ''}</div>
175
+ </div>`
176
+ const bodies = {
177
+ basics: () => card('Basics', 'Only the name is needed.', `
178
+ ${field('Name', `<input class="input" id="np-name" maxlength="80" placeholder="Fire Tower" value="${esc(v.name)}">`)}
179
+ ${field('About', `<input class="input" id="np-about" maxlength="500" placeholder="What it is, in a sentence" value="${esc(v.about)}">`)}
180
+ ${field('Colour', swatches(v.color))}`) + card('How it will look', 'Everyone in the project sees it this way.', `<div id="np-preview">${preview()}</div>`),
181
+ code: () => card('Code', 'Each repository becomes a codebase the team can open. Add them now or later.', `
182
+ ${v.code.length ? `<div class="pj-g">${v.code.map((c, i) => row(I[CODE_WAYS[c.source].icon], esc(c.name), esc(CODE_WAYS[c.source].says(c)), `<button type="button" class="btn sm ghost" data-code-x="${i}">Remove</button>`)).join('')}</div>` : ''}
183
+ ${adding ? `<form class="pj-add-form" data-code-form><input class="input grow${adding === 'github' ? ' mono' : ''}" spellcheck="false" placeholder="${esc(CODE_WAYS[adding].placeholder)}" aria-label="${esc(CODE_WAYS[adding].add)}" required><button class="btn primary" type="submit">Add</button><button type="button" class="btn ghost" data-code-cancel>Cancel</button></form><span class="hint warn" data-code-warn hidden></span>`
184
+ : `<div class="pj-add-row">${Object.entries(CODE_WAYS).map(([k, w]) => `<button type="button" class="btn sm" data-code-add="${k}">${I[w.icon]}<span>${w.add}</span></button>`).join('')}</div>`}
185
+ <input type="hidden" data-code-dir>`),
186
+ people: () => card('People', 'They see every codebase and artifact in the project.', `${chipsHtml(v.emails)}<p class="hint pj-note">They get an invite in Quilt and by email, and can edit. Change that after they join.</p>`),
187
+ agents: () => card('Agents', 'Your agents for every project are on already. Turn one off for this project, or turn on one only it has.', agents === null
188
+ ? '<p class="hint">Loading agents…</p>'
189
+ : `<div class="pj-g pj-g-flat">${agents.map((a) => row(I.bot, esc(a.name), agentHint(a), sw(`data-np-agent="${esc(a.id)}" aria-label="${esc(a.name)}: works in this project"`, on(a)), a.placement?.reach === 'all' ? scopePill(false) : on(a) ? scopePill(true) : '')).join('') || '<div class="pj-g-row pj-g-empty"><span class="hint">No agents yet.</span></div>'}
190
+ <button type="button" class="pj-g-add" data-np-manage>${I.plus}<span>Add an agent</span></button></div>`)
191
+ }
192
+ const pop = popup({
193
+ id: 'np-back',
194
+ title: 'New project',
195
+ lead: 'A product or an idea. Its codebases, artifacts, agents, connections and people live together.',
196
+ groups: [{ label: 'Set up', items: [{ id: 'basics', label: 'Basics', icon: I.grid }, { id: 'code', label: 'Code', icon: I.branch }, { id: 'people', label: 'People', icon: I.users }, { id: 'agents', label: 'Agents', icon: I.bot }] }],
197
+ section,
198
+ body: (id) => bodies[id](),
199
+ foot: { hint: 'You can change all of this later, in the project.', go: 'Create project' },
200
+ summary: { label: 'So far', rows: () => newProjectSummary({ ...v, agentsOn: agents ? agents.filter(on).length : null }) },
201
+ bind: (id, el) => {
202
+ if (id === 'basics') {
203
+ const redraw = () => { $('#np-preview', el).innerHTML = preview(); pop.setGo(named() ? `Create ${named()}` : 'Create project'); pop.drawSummary() }
204
+ $('#np-name', el).oninput = (e) => { v.name = e.target.value; pop.error(''); redraw() }
205
+ $('#np-about', el).oninput = (e) => { v.about = e.target.value; redraw() }
206
+ for (const r of el.querySelectorAll('.swatch input')) r.onchange = () => { v.color = r.value; redraw() }
207
+ } else if (id === 'code') bindCode(el)
208
+ else if (id === 'people') bindChips(el, v.emails, () => pop.redraw())
209
+ else if (id === 'agents') {
210
+ if (agents === null) placedAgents().then((list) => { agents = list; if (pop.back.isConnected && pop.picked() === 'agents') pop.redraw(); else pop.drawSummary() })
211
+ for (const box of el.querySelectorAll('[data-np-agent]')) box.onchange = () => { v.agents[box.dataset.npAgent] = box.checked; pop.redraw() }
212
+ const manage = $('[data-np-manage]', el)
213
+ if (manage) manage.onclick = () => { state.settingsTab = 'agents'; openSettings() }
214
+ }
215
+ }
216
+ })
217
+ placedAgents().then((list) => { agents = list; if (pop.back.isConnected) pop.drawSummary() })
218
+
219
+ // A codebase to start with: what the app's server says starting from it would do (where it goes, its name) is kept with it.
220
+ const addCode = async (source, value, warn) => {
221
+ const body = source === 'github' ? { source, repo: value } : source === 'scratch' ? { source, name: value } : { source, dir: value }
222
+ try {
223
+ const look = await api('POST', '/api/new-session/look', body)
224
+ if (v.code.some((c) => c.dir === look.dir)) throw new Error(`${look.name} is on the list already.`)
225
+ v.code.push({ ...body, name: look.name, dir: look.dir, git: !!look.git })
226
+ adding = ''
227
+ pop.redraw()
228
+ } catch (err) { if (warn) { warn.textContent = err.message; warn.hidden = false } else toast(err.message) }
229
+ }
230
+ function bindCode (el) {
231
+ for (const b of el.querySelectorAll('[data-code-x]')) b.onclick = () => { v.code.splice(Number(b.dataset.codeX), 1); pop.redraw() }
232
+ for (const b of el.querySelectorAll('[data-code-add]')) {
233
+ b.onclick = async () => {
234
+ if (b.dataset.codeAdd !== 'folder') { adding = b.dataset.codeAdd; pop.redraw(); return $('[data-code-form] input', el)?.focus() }
235
+ const dir = $('[data-code-dir]', el)
236
+ dir.value = ''
237
+ await pickFolder(dir)
238
+ if (dir.value) addCode('folder', dir.value, null)
239
+ }
240
+ }
241
+ const form = $('[data-code-form]', el)
242
+ if (!form) return
243
+ form.onsubmit = (e) => { e.preventDefault(); const value = $('input', form).value.trim(); if (value) addCode(adding, value, $('[data-code-warn]', el)) }
244
+ $('[data-code-cancel]', form).onclick = () => { adding = ''; pop.redraw() }
245
+ }
246
+
247
+ // Create: the project first, then what was set up for it, one after another. What fails is said and the rest goes on.
248
+ $('[data-pop-go]', pop.back).onclick = async () => {
249
+ if (!named()) { pop.pick('basics'); pop.error('Give the project a name.'); return $('#np-name', pop.back)?.focus() }
250
+ const steps = newProjectSteps({ ...v, agentList: agents || [] })
251
+ const failed = []
252
+ let id = ''
253
+ for (const s of steps) {
254
+ pop.busy(s.says)
255
+ try {
256
+ if (s.kind === 'project') id = (await api('POST', '/api/workspaces', s.body)).workspace.id
257
+ else if (s.kind === 'agent-off') await api('POST', wsUrl(id, `/agents/${encodeURIComponent(s.agent)}`), { excluded: true })
258
+ else if (s.kind === 'agent-on') await api('POST', wsUrl(id, '/members'), { account: `agent:${s.agent}`, access: 'edit', sessions: 'all' })
259
+ else if (s.kind === 'invite') await api('POST', wsUrl(id, '/invites'), { to: { email: s.to }, access: 'edit' })
260
+ else if (s.kind === 'codebase') { const sum = await api('POST', '/api/sessions', { mode: 'create', workspace: id, ...s.body }); state.sessions.set(sum.id, sum) }
261
+ } catch (err) {
262
+ if (s.kind === 'project') { pop.busy(null, named() ? `Create ${named()}` : 'Create project'); return pop.error(err.message) }
263
+ failed.push(`${s.what}: ${err.message}`)
264
+ }
265
+ }
266
+ await loadWorkspaces()
267
+ pop.close()
268
+ await go(`ws:${id}`)
269
+ if (failed.length) toast(`${named()} is made. Not done: ${failed.join('; ')}`)
270
+ }
271
+ return pop
272
+ }
273
+
274
+ // ------------------------------------------- a project's people and settings --
275
+ /** A project's own pop-up: General, People, Agents, Connections. The project is the one open on the page. */
276
+ export function openProjectPop ({ id, section = 'general', focusInvite = false }) {
277
+ if (!state.workspace || state.workspace.workspace.id !== id) return null
278
+ const d = () => state.workspace
279
+ const admin = () => !!d().access?.admin
280
+ const invite = { emails: [], waiting: null, known: null }
281
+ let addingAgent = false
282
+ let pop = null
283
+ // After a change: the project is read again, the page behind is drawn again, and so is this part.
284
+ const reload = async () => {
285
+ await openWorkspace(id).catch((err) => toast(err.message))
286
+ await loadWorkspaces()
287
+ if (!state.workspace || state.workspace.workspace.id !== id) return pop.close()
288
+ renderShell(state.view)
289
+ drawRail()
290
+ const now = state.workspace.workspace
291
+ pop.setTitle(now.name, tile(now.name, now.color, 'sm'))
292
+ if (pop.back.isConnected) pop.redraw()
293
+ }
294
+ const act = async (fn, said = '') => { try { await fn(); if (said) toast(said); await reload() } catch (err) { toast(err.message); if (pop.back.isConnected) pop.redraw() } }
295
+ const usage = () => {
296
+ const u = d().usage
297
+ const n = (d().files || []).filter((f) => f.kind !== 'folder').length
298
+ const used = !u ? '' : Number.isFinite(u.quotaBytes) ? ` · ${bytes(u.usedBytes || 0)} of ${bytes(u.quotaBytes)}` : ` · ${bytes(u.usedBytes || 0)}`
299
+ return `${n} artifact${n === 1 ? '' : 's'}${used}`
300
+ }
301
+ const bodies = {
302
+ general: () => {
303
+ const w = d().workspace
304
+ const no = admin() ? '' : ' disabled'
305
+ return card('About', 'How the project shows on the left and at the top.', `
306
+ <form data-about autocomplete="off">
307
+ ${field('Name', `<input class="input" name="name" maxlength="80" required value="${esc(w.name)}"${no}>`)}
308
+ ${field('About', `<input class="input" name="description" maxlength="500" value="${esc(w.description || '')}"${no}>`)}
309
+ ${field('Colour', swatches(w.color || 'lilac', !admin()))}
310
+ <div class="sec-actions"><span class="hint">${admin() ? esc(usage()) : "Only the project's admins change this."}</span>${admin() ? '<button class="btn primary" type="submit">Save</button>' : ''}</div>
311
+ </form>`) +
312
+ (admin()
313
+ ? card('Put away', w.archivedAt ? 'This project is archived: kept, and off the left. Bring it back to work in it again.' : 'Archive keeps everything but takes the project off the left. Deleting cannot be undone.', `<div class="sec-actions pj-flat">
314
+ <button class="btn" type="button" data-archive>${w.archivedAt ? 'Bring it back' : 'Archive project'}</button>${d().canDelete ? '<button class="btn danger" type="button" data-delete>Delete project</button>' : ''}</div>`)
315
+ : '')
316
+ },
317
+ people: () => {
318
+ const people = projectPeople(d(), `person:${state.account?.id}`)
319
+ const person = (m) => `<div class="pj-person">${avatar(m.name)}<div><b>${esc(m.name)}${m.you ? ' (you)' : ''}</b>${m.owner || !admin()
320
+ ? `<span class="hint">${m.owner ? 'Owner' : m.access === 'view' ? 'View only' : 'Can edit'}</span>`
321
+ : `<select class="input sm" data-person-access="${esc(m.account)}" aria-label="What ${esc(m.name)} can do"><option value="edit"${m.access === 'view' ? '' : ' selected'}>Can edit</option><option value="view"${m.access === 'view' ? ' selected' : ''}>View only</option></select>`}</div>
322
+ ${admin() && !m.owner ? `<button type="button" class="btn sm ghost" data-person-x="${esc(m.account)}" data-name="${esc(m.name)}">Remove</button>` : ''}</div>`
323
+ const known = (invite.known || []).filter((c) => !people.some((m) => m.account === c.account) && !(invite.waiting || []).some((i) => i.account === c.account)).slice(0, 8)
324
+ return card('People', 'They see every codebase and artifact in this project.', `<div class="pj-people">${people.map(person).join('')}</div>`) +
325
+ (admin()
326
+ ? card('Invite', 'By email. They get an invite in Quilt too.', `${chipsHtml(invite.emails)}
327
+ ${known.length ? `<div class="pj-known"><span class="hint">People you have worked with:</span>${known.map((c) => `<button type="button" class="btn sm" data-invite-known="${esc(c.account)}" data-name="${esc(c.name)}">${I.plus}<span>${esc(c.name)}</span></button>`).join('')}</div>` : ''}
328
+ <div class="sec-actions"><span class="hint">New people can edit. Change it after they join.</span><button class="btn primary" type="button" data-send-invites>Send invites</button></div>
329
+ ${invite.waiting && invite.waiting.length ? `<div class="label pj-waiting">Waiting to accept</div><div class="pj-g">${invite.waiting.map((i) => row(I.link, esc(i.email || i.name || ''), i.access === 'view' ? 'View only' : 'Can edit', `<button type="button" class="btn sm ghost" data-invite-x="${esc(i.id)}">Cancel</button>`)).join('')}</div>` : ''}`)
330
+ : '')
331
+ },
332
+ agents: () => {
333
+ const mine = new Map((state.placedAgents || []).map((a) => [a.id, a]))
334
+ const list = (d().agents || []).filter((a) => a.agentId)
335
+ const here = new Set(list.map((a) => a.agentId))
336
+ const more = (state.placedAgents || []).filter((a) => !here.has(a.id))
337
+ const one = (a) => {
338
+ const why = !admin() ? "Only the project's admins change this" : a.foreign ? FOREIGN_JOINS : a.excluded ? 'Kept out of this project' : ''
339
+ const side = !admin() ? '' : a.excluded ? `<button type="button" class="btn sm ghost" data-agent-back="${esc(a.agentId)}">Let back in</button>`
340
+ : a.via === 'member' ? `<button type="button" class="btn sm ghost" data-agent-x="${esc(a.account)}" data-name="${esc(a.name)}">Remove</button>`
341
+ : `<button type="button" class="btn sm ghost" data-agent-out="${esc(a.agentId)}" data-name="${esc(a.name)}" title="It leaves this project and its codebases, and keeps its other projects">Keep out</button>`
342
+ return row(I.bot, esc(a.name), agentHint({ provider: a.provider, ...(mine.get(a.agentId) || {}) }), `${side}${sw(`data-agent-here="${esc(a.agentId)}" aria-label="${esc(a.name)}: invited to every new codebase in this project"`, !a.excluded && a.sessions === 'all', { disabled: !!why, why })}`, scopePill(a.via !== 'global'))
343
+ }
344
+ return card('Agents', 'They work in every codebase in this project. On: invited to every new codebase. Ones marked Every project are set on Home.', `<div class="pj-g pj-g-flat">
345
+ ${list.map(one).join('') || '<div class="pj-g-row pj-g-empty"><span class="hint">No agents in this project yet.</span></div>'}
346
+ ${addingAgent ? (more.map((a) => row(I.bot, esc(a.name), agentHint(a), `<button type="button" class="btn sm" data-agent-add="${esc(a.id)}">Add</button>`)).join('') || '<div class="pj-g-row pj-g-empty"><span class="hint">Every agent of yours is in this project.</span></div>') +
347
+ `<button type="button" class="pj-g-add" data-agent-new>${I.gear}<span>Make a new agent, in Settings</span></button>`
348
+ : admin() ? `<button type="button" class="pj-g-add" data-agent-more>${I.plus}<span>Add an agent to this project</span></button>` : ''}</div>`)
349
+ },
350
+ connections: () => card('Connections', "Apps this project's agents can use. Agents never see the logins.", '<div data-pop-connections></div>')
351
+ }
352
+ const w = d().workspace
353
+ pop = popup({
354
+ id: 'pp-back',
355
+ title: w.name,
356
+ mark: tile(w.name, w.color, 'sm'),
357
+ lead: 'This project: what it is, who is in it, and what its agents can use.',
358
+ groups: [{ label: 'This project', items: [{ id: 'general', label: 'General', icon: I.gear }, { id: 'people', label: 'People', icon: I.users }, { id: 'agents', label: 'Agents', icon: I.bot }, ...(state.connectionsOn ? [{ id: 'connections', label: 'Connections', icon: I.link }] : [])] }],
359
+ section,
360
+ body: (s) => bodies[s](),
361
+ bind: (s, el) => {
362
+ const url = (rest) => wsUrl(id, rest)
363
+ if (s === 'general') {
364
+ const form = $('[data-about]', el)
365
+ form.onsubmit = (e) => { e.preventDefault(); const f = new FormData(form); act(() => api('POST', url('/update'), { name: f.get('name'), description: f.get('description'), color: f.get('color') }), 'Saved') }
366
+ const arch = $('[data-archive]', el)
367
+ if (arch) {
368
+ arch.onclick = async () => {
369
+ const was = !!d().workspace.archivedAt
370
+ const name = d().workspace.name
371
+ try {
372
+ await api('POST', url('/update'), { archived: !was })
373
+ if (was) return reload()
374
+ await loadWorkspaces(); pop.close(); await go('home'); toast(`${name} is archived. It is in Settings, under Projects.`)
375
+ } catch (err) { toast(err.message) }
376
+ }
377
+ }
378
+ const del = $('[data-delete]', el)
379
+ if (del) {
380
+ del.onclick = async () => {
381
+ const name = d().workspace.name
382
+ const typed = await ask({ title: `Delete ${name}?`, message: 'Its codebases stay, in no project. Type the project\'s name to confirm.', ok: 'Delete', danger: true, input: { placeholder: name } })
383
+ if (typed !== name) { if (typed) toast('That is not the name.'); return }
384
+ try { await api('POST', url('/delete')); await loadWorkspaces(); pop.close(); go('home') } catch (err) { toast(err.message) }
385
+ }
386
+ }
387
+ } else if (s === 'people') {
388
+ if (admin() && invite.waiting === null) {
389
+ invite.waiting = []
390
+ Promise.all([api('GET', url('/invites')).then((r) => r.invites.filter((i) => i.status === 'waiting'), () => []), api('GET', '/api/collaborators').then((r) => r.collaborators.filter((c) => c.kind !== 'agent' && c.account), () => [])])
391
+ .then(([waiting, known]) => {
392
+ invite.waiting = waiting; invite.known = known
393
+ const box = $('[data-chips] input', pop.back)
394
+ if (!pop.back.isConnected || pop.picked() !== 'people' || box?.value) return
395
+ const had = document.activeElement === box // the cursor stays in the box it was in
396
+ pop.redraw()
397
+ if (had) $('[data-chips] input', pop.back)?.focus()
398
+ })
399
+ }
400
+ const waitingAgain = async () => { invite.waiting = await api('GET', url('/invites')).then((r) => r.invites.filter((i) => i.status === 'waiting'), () => invite.waiting) }
401
+ bindChips(el, invite.emails, () => pop.redraw())
402
+ for (const sel of el.querySelectorAll('[data-person-access]')) sel.onchange = () => act(() => api('POST', url('/members'), { account: sel.dataset.personAccess, access: sel.value }), 'Saved')
403
+ for (const b of el.querySelectorAll('[data-person-x]')) {
404
+ b.onclick = async () => {
405
+ if (!await ask({ title: `Remove ${b.dataset.name} from this project?`, message: 'They lose its codebases and artifacts, unless a codebase\'s owner lets them in directly.', ok: 'Remove', danger: true })) return
406
+ act(() => api('POST', url('/members/remove'), { account: b.dataset.personX }))
407
+ }
408
+ }
409
+ for (const b of el.querySelectorAll('[data-invite-known]')) b.onclick = () => act(async () => { await api('POST', url('/invites'), { to: { account: b.dataset.inviteKnown }, access: 'edit' }); await waitingAgain() }, `${b.dataset.name} is invited`)
410
+ for (const b of el.querySelectorAll('[data-invite-x]')) b.onclick = () => act(async () => { await api('POST', url(`/invites/${encodeURIComponent(b.dataset.inviteX)}/cancel`)); await waitingAgain() })
411
+ const send = $('[data-send-invites]', el)
412
+ if (send) {
413
+ send.onclick = async () => {
414
+ const typed = readEmails($('[data-chips] input', el).value)
415
+ for (const e of typed.good) if (!invite.emails.includes(e)) invite.emails.push(e)
416
+ if (typed.bad.length) return toast(`Not an email address: ${typed.bad.join(', ')}`)
417
+ if (!invite.emails.length) return $('[data-chips] input', el).focus()
418
+ send.disabled = true
419
+ const failed = []
420
+ for (const to of [...invite.emails]) {
421
+ try { await api('POST', url('/invites'), { to: { email: to }, access: 'edit' }); invite.emails.splice(invite.emails.indexOf(to), 1) } catch (err) { failed.push(`${to}: ${err.message}`) }
422
+ }
423
+ await waitingAgain()
424
+ toast(failed.length ? `Not sent: ${failed.join('; ')}` : 'Invites sent')
425
+ pop.redraw()
426
+ }
427
+ }
428
+ if (focusInvite) { focusInvite = false; $('[data-chips] input', el)?.focus() }
429
+ } else if (s === 'agents') {
430
+ if (!state.placedAgents) placedAgents().then(() => { if (pop.back.isConnected && pop.picked() === 'agents') pop.redraw() })
431
+ for (const box of el.querySelectorAll('[data-agent-here]')) {
432
+ box.onchange = () => {
433
+ const a = (d().agents || []).find((x) => x.agentId === box.dataset.agentHere)
434
+ if (!a) return
435
+ const sessions = box.checked ? 'all' : 'invited'
436
+ act(() => a.via === 'member' ? api('POST', url('/members'), { account: a.account, access: a.access, sessions }) : api('POST', url(`/agents/${encodeURIComponent(a.agentId)}`), { sessions }))
437
+ }
438
+ }
439
+ for (const b of el.querySelectorAll('[data-agent-x]')) b.onclick = () => act(() => api('POST', url('/members/remove'), { account: b.dataset.agentX }), `${b.dataset.name} is out of this project`)
440
+ for (const b of el.querySelectorAll('[data-agent-out]')) b.onclick = () => act(() => api('POST', url(`/agents/${encodeURIComponent(b.dataset.agentOut)}`), { excluded: true }), `${b.dataset.name} is kept out of this project`)
441
+ for (const b of el.querySelectorAll('[data-agent-back]')) b.onclick = () => act(() => api('POST', url(`/agents/${encodeURIComponent(b.dataset.agentBack)}/remove`)), 'Back in')
442
+ for (const b of el.querySelectorAll('[data-agent-add]')) b.onclick = () => { addingAgent = false; act(() => api('POST', url('/members'), { account: `agent:${b.dataset.agentAdd}`, access: 'edit', sessions: 'all' })) }
443
+ const more = $('[data-agent-more]', el)
444
+ if (more) more.onclick = () => { addingAgent = true; pop.redraw() }
445
+ const fresh = $('[data-agent-new]', el)
446
+ if (fresh) fresh.onclick = () => { state.settingsTab = 'agents'; openSettings() }
447
+ } else if (s === 'connections') mountConnections($('[data-pop-connections]', el), { type: 'workspace', id })
448
+ }
449
+ })
450
+ return pop
451
+ }