heyquilt 0.3.165 → 0.3.167
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RELEASES.md +10 -0
- package/package.json +1 -1
- package/src/api/audit.js +0 -1
- package/src/api/composio.js +1 -64
- package/src/api/memory-store.js +0 -7
- package/src/api/routes/connections.js +1 -78
- package/src/api/routes/workspaces.js +3 -43
- package/src/api/supabase-store.js +0 -11
- package/src/control.js +0 -21
- package/src/presence.js +1 -2
- package/src/server.js +1 -15
- package/src/ui/app.css +5 -744
- package/src/ui/app.js +22 -38
- package/src/ui/board.js +7 -17
- package/src/ui/connections.js +41 -235
- package/src/ui/feed.js +8 -23
- package/src/ui/files.js +22 -67
- package/src/ui/home.js +6 -95
- package/src/ui/loom-model.js +8 -11
- package/src/ui/loom.css +2 -183
- package/src/ui/loom.js +55 -132
- package/src/ui/session.js +75 -1065
- package/src/ui/signin.js +6 -4
- package/src/ui/workspaces.js +1 -2
- package/src/ui-server.js +4 -50
- package/src/dev-servers.js +0 -65
- package/src/ui/home-view.js +0 -170
- package/src/ui/palette.js +0 -75
- package/src/ui/people-view.js +0 -116
package/src/ui/signin.js
CHANGED
|
@@ -18,22 +18,24 @@ function screen (inner) {
|
|
|
18
18
|
export function renderSignIn (message = '', onSignedIn = () => window.location.reload()) {
|
|
19
19
|
screen(`
|
|
20
20
|
<h1>Sign in to Quilt</h1>
|
|
21
|
-
<p class="signin-lead">Your sessions, files and agents, in one place. Signing in opens heyquilt.com in your browser, where you approve this computer.</p>
|
|
22
21
|
${message ? `<p class="signin-note">${esc(message)}</p>` : ''}
|
|
23
22
|
<button class="btn primary signin-btn" id="signin-go">Sign in</button>
|
|
24
|
-
<p class="hint">New to Quilt? <a href="${SIGNUP}" target="_blank" rel="noopener">Create an account</a></p>
|
|
23
|
+
<p class="hint">New to Quilt? <a href="${SIGNUP}" id="signin-new" target="_blank" rel="noopener">Create an account</a></p>
|
|
25
24
|
<p class="error" id="signin-error"></p>`)
|
|
26
25
|
$('#signin-go').onclick = () => begin(onSignedIn)
|
|
26
|
+
// A new account also signs this computer in: sign-up comes back to approving it, not to the website.
|
|
27
|
+
$('#signin-new').onclick = (e) => { e.preventDefault(); begin(onSignedIn, true) }
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
async function begin (onSignedIn) {
|
|
30
|
+
async function begin (onSignedIn, signup = false) {
|
|
30
31
|
const btn = $('#signin-go')
|
|
31
32
|
btn.disabled = true
|
|
32
33
|
try {
|
|
33
34
|
const acc = await api('POST', '/api/account/start')
|
|
34
35
|
// A computer linked before is signed straight back in: nothing to approve.
|
|
35
36
|
if (acc.signedIn) return onSignedIn()
|
|
36
|
-
|
|
37
|
+
const verify = new URL(acc.link.verificationUrl)
|
|
38
|
+
window.open(signup ? `${SIGNUP}?next=${encodeURIComponent(verify.pathname + verify.search)}` : verify.href, '_blank', 'noopener')
|
|
37
39
|
waiting(acc.link, onSignedIn)
|
|
38
40
|
} catch (err) {
|
|
39
41
|
btn.disabled = false
|
package/src/ui/workspaces.js
CHANGED
|
@@ -369,8 +369,7 @@ export function bindWorkspacePage (root, { go, rerender, newSessionDialog, invit
|
|
|
369
369
|
if (!d || d.workspace.id !== String(state.view).slice(3)) return
|
|
370
370
|
const id = d.workspace.id
|
|
371
371
|
const reload = async () => { await openWorkspace(id); await loadWorkspaces(); rerender() }
|
|
372
|
-
|
|
373
|
-
if (back) back.onclick = (e) => { e.preventDefault(); go('home') }
|
|
372
|
+
root.querySelector('[data-ws-back]').onclick = (e) => { e.preventDefault(); go('home') }
|
|
374
373
|
root.querySelectorAll('[data-go]').forEach((b) => { b.onclick = () => go(b.dataset.go) })
|
|
375
374
|
root.querySelector('[data-new-session-in]')?.addEventListener('click', () => newSessionDialog(id))
|
|
376
375
|
root.querySelector('[data-invite-ws]')?.addEventListener('click', () => inviteDialog(id))
|
package/src/ui-server.js
CHANGED
|
@@ -18,7 +18,6 @@ import { execFile } from 'node:child_process'
|
|
|
18
18
|
import { installedEditors, openIn, copyToClipboard } from './editors.js'
|
|
19
19
|
import { autowork, autoConfig, publicConfig, AUTO_MODES } from './autowork.js'
|
|
20
20
|
import { migrateDir } from './legacy.js'
|
|
21
|
-
import { devServers } from './dev-servers.js'
|
|
22
21
|
import { writePrivateJson } from './private-file.js'
|
|
23
22
|
import { autoToolFor } from './autowork-tools.js'
|
|
24
23
|
import { readAccount, saveAccount, clearAccount, clearAccountIf, resumeAccount, startLink, waitForLink, fetchMe, signOut, revokeToken, accountFromProfile, renameSession, createAgentInvite, listAgents, agentDetails, listAccessTypes, listCollaborators, listGrants, putGrant, deleteGrant, inviteToSession, listSessionInvites, cancelSessionInvite, listWorkspaces, listOrgs, createWorkspace, getWorkspace, updateWorkspace, deleteWorkspace, putWorkspaceMember, removeWorkspaceMember, getAgentPlacement, putAgentPlacement, listOrgAgents, putWorkspaceAgent, deleteWorkspaceAgent, createWorkspaceAgentInvite, excludeSessionAgent, listExcludedSessionAgents, listSessionAgents, includeSessionAgent, setSessionWorkspace, moveSessionToWorkspace, listWorkspaceInvites, inviteToWorkspace, cancelWorkspaceInvite, listMyInvites, answerMyInvite, listMySessions, announceSessionStarted, announceWhenReported, listWorkspaceFiles, createWorkspaceFile, confirmWorkspaceFile, workspaceFileDownload, updateWorkspaceFile, deleteWorkspaceFile, createWorkspaceFolder, listWorkspaceFileVersions, listSandboxKeys, createSandboxKey, rotateSandboxKey, revokeSandboxKey, removeSandboxKey, aiVmFollow, aiVmUnfollow, aiVmStatus, aiVmConnect, aiVmUpdate, aiVmSignIn, aiVmWake, aiVmDisconnect, voiceIce, transcribeVoice, speakVoice, speakVoiceStream, apiUrl } from './account.js'
|
|
@@ -217,9 +216,6 @@ export const STATIC = {
|
|
|
217
216
|
'/secrets.js': ['secrets.js', 'text/javascript; charset=utf-8'],
|
|
218
217
|
'/secrets-view.js': ['secrets-view.js', 'text/javascript; charset=utf-8'],
|
|
219
218
|
'/connections.js': ['connections.js', 'text/javascript; charset=utf-8'],
|
|
220
|
-
'/home-view.js': ['home-view.js', 'text/javascript; charset=utf-8'],
|
|
221
|
-
'/people-view.js': ['people-view.js', 'text/javascript; charset=utf-8'],
|
|
222
|
-
'/palette.js': ['palette.js', 'text/javascript; charset=utf-8'],
|
|
223
219
|
'/secret-rules.js': ['secret-rules.js', 'text/javascript; charset=utf-8'],
|
|
224
220
|
'/voice.js': ['voice.js', 'text/javascript; charset=utf-8'],
|
|
225
221
|
'/voice-model.js': ['voice-model.js', 'text/javascript; charset=utf-8'],
|
|
@@ -238,8 +234,6 @@ const CSP = [
|
|
|
238
234
|
"style-src 'self' 'unsafe-inline'",
|
|
239
235
|
"img-src 'self' data: https: https://www.google.com https://*.gstatic.com",
|
|
240
236
|
"font-src 'self'",
|
|
241
|
-
// The Preview tab shows the session's links (a dev server, staging, production) in a sandboxed frame.
|
|
242
|
-
"frame-src http: https:",
|
|
243
237
|
"connect-src 'self'",
|
|
244
238
|
"object-src 'none'",
|
|
245
239
|
"base-uri 'none'",
|
|
@@ -962,9 +956,7 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
962
956
|
const enc = (v) => encodeURIComponent(String(v))
|
|
963
957
|
return asAccount(async (token) => {
|
|
964
958
|
const c = secretsApi(token)
|
|
965
|
-
|
|
966
|
-
if (method === 'GET' && oneApp) return apiCall(c, 'GET', `/v1/connections/apps/${oneApp[1]}`)
|
|
967
|
-
if (method === 'GET' && p === '/api/connections/apps') return apiCall(c, 'GET', `/v1/connections/apps?search=${enc(url.searchParams.get('search') || '')}&group=${enc(url.searchParams.get('group') || '')}&offset=${enc(url.searchParams.get('offset') || '0')}&limit=${enc(url.searchParams.get('limit') || '48')}`)
|
|
959
|
+
if (method === 'GET' && p === '/api/connections/apps') return apiCall(c, 'GET', `/v1/connections/apps?search=${enc(url.searchParams.get('search') || '')}&limit=${enc(url.searchParams.get('limit') || '60')}`)
|
|
968
960
|
const sc = p.match(/^\/api\/connections\/(org|workspace|session)\/([^/]+)(?:\/([0-9a-f-]{36}))?$/i)
|
|
969
961
|
if (sc && SECRET_SCOPE_ID[sc[1]].test(decodeURIComponent(sc[2]))) {
|
|
970
962
|
const base = `/v1/connections/${sc[1]}/${enc(decodeURIComponent(sc[2]))}`
|
|
@@ -1033,22 +1025,6 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
1033
1025
|
'GET /api/orgs': () => asAccount(async (token) => ({ orgs: await listOrgs({ token }) })),
|
|
1034
1026
|
'POST /api/workspaces': (b) => asAccount(async (token) => ({ workspace: await createWorkspace({ token, name: String(b.name || ''), description: String(b.description || ''), color: String(b.color || ''), org: b.org ? String(b.org) : undefined }) })),
|
|
1035
1027
|
'GET /api/workspaces/:id': (b, id) => asAccount(async (token) => ({ ...(await getWorkspace({ token, id: needWorkspaceId(id) })), ...ofWorkspace(id) })),
|
|
1036
|
-
// The workspace's home (plans/app-redesign.md): AI time from the accounts API, merges onto main from Seam for
|
|
1037
|
-
// the workspace's sessions open on this computer, and its links (previews).
|
|
1038
|
-
'GET /api/workspaces/:id/insights': (b, id) => asAccount(async (token) => {
|
|
1039
|
-
const wid = needWorkspaceId(id)
|
|
1040
|
-
const ai = await apiCall({ api: apiUrl(), token }, 'GET', `/v1/workspaces/${encodeURIComponent(wid)}/insights?days=14`)
|
|
1041
|
-
const since = Date.now() - 14 * 24 * 60 * 60 * 1000
|
|
1042
|
-
const merges = []
|
|
1043
|
-
for (const [key, r] of runs) {
|
|
1044
|
-
const sm = summary(key)
|
|
1045
|
-
if (!sm || sm.workspace !== wid || !r.run.session.seamMerges) continue
|
|
1046
|
-
try { for (const at of await r.run.session.seamMerges({ since })) merges.push({ room: r.run.session.room, at }) } catch {} // one session's Seam not answering leaves its merges out
|
|
1047
|
-
}
|
|
1048
|
-
return { ...ai, merges }
|
|
1049
|
-
}),
|
|
1050
|
-
'POST /api/workspaces/:id/links': (b, id) => asAccount((token) => apiCall({ api: apiUrl(), token }, 'POST', `/v1/workspaces/${encodeURIComponent(needWorkspaceId(id))}/links`, { name: String(b.name || ''), url: String(b.url || ''), room: b.room ? String(b.room) : null, note: String(b.note || '') })),
|
|
1051
|
-
'POST /api/workspaces/:id/links/:lid/remove': (b, id, url, lid) => asAccount(async (token) => { await apiCall({ api: apiUrl(), token }, 'DELETE', `/v1/workspaces/${encodeURIComponent(needWorkspaceId(id))}/links/${encodeURIComponent(String(lid))}`); return { ok: true } }),
|
|
1052
1028
|
'POST /api/workspaces/:id/update': (b, id) => asAccount(async (token) => ({ workspace: await updateWorkspace({ token, id: needWorkspaceId(id), patch: { name: b.name, description: b.description, color: b.color, archived: b.archived } }) })),
|
|
1053
1029
|
'POST /api/workspaces/:id/delete': (b, id) => asAccount(async (token) => { await deleteWorkspace({ token, id: needWorkspaceId(id) }); return { ok: true } }),
|
|
1054
1030
|
'POST /api/workspaces/:id/members': (b, id) => asAccount(async (token) => ({ member: await putWorkspaceMember({ token, id: needWorkspaceId(id), account: String(b.account || ''), access: String(b.access || ''), sessions: b.sessions === undefined ? undefined : String(b.sessions) }) })),
|
|
@@ -1141,14 +1117,6 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
1141
1117
|
'POST /api/sessions/:id/focus': (b, id) => { get(id).setFocus(b.text); return { ok: true } },
|
|
1142
1118
|
// Voice (voice.js): the call as this app sees it, and our part in it, from the app window, which does the audio.
|
|
1143
1119
|
'GET /api/sessions/:id/voice': (b, id) => get(id).voice(),
|
|
1144
|
-
// The Calls tab (dm06): the session's calls from their transcripts, newest first, each with its opening lines.
|
|
1145
|
-
'GET /api/sessions/:id/calls': (b, id) => {
|
|
1146
|
-
const { lines, calls } = get(id).voiceTranscript({ limit: 1000 })
|
|
1147
|
-
return { calls: calls.reverse().slice(0, 50).map((c) => ({ ...c, opening: lines.filter((l) => l.call === c.call).slice(0, 3).map((l) => ({ by: l.by, text: l.text })) })) }
|
|
1148
|
-
},
|
|
1149
|
-
// The Preview tab: dev servers running from this session's folder on this computer (dev-servers.js).
|
|
1150
|
-
'GET /api/sessions/:id/dev-servers': async (b, id) => { get(id); return { servers: await devServers(runs.get(id)?.run.dir, { skip: [server.address()?.port].filter(Boolean) }) } },
|
|
1151
|
-
'GET /api/sessions/:id/calls/:call': (b, id, url, call) => ({ lines: get(id).voiceTranscript({ call, limit: 1000 }).lines }),
|
|
1152
1120
|
'POST /api/sessions/:id/voice': (b, id) => get(id).setVoice(b.in === false ? null : { muted: b.muted === true, sig: b.sig, transcribing: b.transcribing === true, sharing: b.sharing === true, agents: b.agents === true }),
|
|
1153
1121
|
'POST /api/sessions/:id/voice/transcribe': (b, id) => get(id).setVoiceTranscribe(b.on === true),
|
|
1154
1122
|
'POST /api/sessions/:id/voice/clip': (b, id) => voiceClip(get(id), b),
|
|
@@ -1220,8 +1188,6 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
1220
1188
|
'GET /api/sessions/:id/search': (b, id, url) => get(id).quiltSearch(String(url.searchParams.get('q') || '')),
|
|
1221
1189
|
// In a session that moved into Seam: the square panel's Commit and Merge onto main, as this member (control.js seamTool).
|
|
1222
1190
|
'POST /api/sessions/:id/seam': (b, id) => squareTool(get(id), b),
|
|
1223
|
-
'GET /api/sessions/:id/github': (b, id) => seamGithub(get(id), {}),
|
|
1224
|
-
'POST /api/sessions/:id/github': (b, id) => seamGithub(get(id), b),
|
|
1225
1191
|
'GET /api/sessions/:id/file': (b, id, url) => {
|
|
1226
1192
|
const f = get(id).readShared(url.searchParams.get('path'))
|
|
1227
1193
|
if (!f) throw httpError(404, 'That file is not in this session.')
|
|
@@ -1266,6 +1232,8 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
1266
1232
|
'GET /api/version': async () => {
|
|
1267
1233
|
const version = currentVersion()
|
|
1268
1234
|
const latest = await latestRelease()
|
|
1235
|
+
// A fresh install has nothing new to tell: its first launch opens on sign-in and Home, not the notes.
|
|
1236
|
+
if (!seenVersion()) markSeen(version)
|
|
1269
1237
|
return {
|
|
1270
1238
|
version,
|
|
1271
1239
|
releases: localReleases(),
|
|
@@ -1407,12 +1375,6 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
1407
1375
|
// A workspace's invite, the same way.
|
|
1408
1376
|
const iid = (url.pathname.match(/^\/api\/workspaces\/[^/]+\/invites\/([^/]+)\//) || [])[1]
|
|
1409
1377
|
if (iid) pathKey = pathKey.replace(/^(\/api\/workspaces\/:id\/invites)\/[^/]+/, '$1/:iid')
|
|
1410
|
-
// A workspace's link (a preview), the same way.
|
|
1411
|
-
const lid = (url.pathname.match(/^\/api\/workspaces\/[^/]+\/links\/([^/]+)\//) || [])[1]
|
|
1412
|
-
if (lid) pathKey = pathKey.replace(/^(\/api\/workspaces\/:id\/links)\/[^/]+/, '$1/:lid')
|
|
1413
|
-
// A call's transcript (the Calls tab), by the call's id.
|
|
1414
|
-
const cid = (url.pathname.match(/^\/api\/sessions\/[a-f0-9]+\/calls\/([^/]+)$/) || [])[1]
|
|
1415
|
-
if (cid) pathKey = pathKey.replace(/^(\/api\/sessions\/:id\/calls)\/[^/]+$/, '$1/:call')
|
|
1416
1378
|
const key = `${req.method} ${pathKey}`
|
|
1417
1379
|
const handler = api[key]
|
|
1418
1380
|
if (!handler) {
|
|
@@ -1424,7 +1386,7 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
1424
1386
|
const body = raw ? JSON.parse(raw) : {}
|
|
1425
1387
|
const startedAt = Date.now()
|
|
1426
1388
|
try {
|
|
1427
|
-
const out = await handler(body, sid, url, fid || aid || iid
|
|
1389
|
+
const out = await handler(body, sid, url, fid || aid || iid)
|
|
1428
1390
|
// A reply that streams (an agent's speech): straight through as it comes.
|
|
1429
1391
|
if (out && out[STREAMED]) {
|
|
1430
1392
|
res.writeHead(200, { 'content-type': out.type, 'cache-control': 'no-store' })
|
|
@@ -1646,14 +1608,6 @@ export function underJoinDir (joinDir, name, message = INVALID_INVITE) {
|
|
|
1646
1608
|
* commits first), as this member through Seam's own tools; or open_square, for a folder whose branch has
|
|
1647
1609
|
* none (Session.openSquareHere). The answer as { text }, a refusal as a 400.
|
|
1648
1610
|
*/
|
|
1649
|
-
/** Session settings' GitHub card: Seam's GitHub (the Seam app's installations, and the quilt's export to a repository). */
|
|
1650
|
-
async function seamGithub (s, b) {
|
|
1651
|
-
if (!s.seamGithub) return { quilt: false }
|
|
1652
|
-
const repo = b && typeof b.repo === 'string' ? b.repo.trim() : ''
|
|
1653
|
-
if (repo && !(/^[\w.-]+\/[\w.-]+$/.test(repo) && /^\d+$/.test(String(b.installation || '')))) throw httpError(400, 'Pick a repository the Seam app reaches.')
|
|
1654
|
-
try { return await s.seamGithub(repo ? { repo, installation: String(b.installation) } : b && b.disconnect ? { disconnect: true } : {}) } catch (err) { throw httpError(err.status || 502, err.message) }
|
|
1655
|
-
}
|
|
1656
|
-
|
|
1657
1611
|
export async function squareTool (s, b) {
|
|
1658
1612
|
const tool = String((b && b.tool) || '')
|
|
1659
1613
|
if (tool === 'open_square') {
|
package/src/dev-servers.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// Dev servers running from a session's folder on this computer, for the Preview tab: every program
|
|
2
|
-
// listening on a local TCP port whose working folder is the session's folder (or inside it), found
|
|
3
|
-
// with lsof. Nothing is found where lsof isn't (Windows): the tab still has its saved links.
|
|
4
|
-
import { execFile } from 'node:child_process'
|
|
5
|
-
import fs from 'node:fs'
|
|
6
|
-
import path from 'node:path'
|
|
7
|
-
|
|
8
|
-
const run = (args) => new Promise((resolve) => {
|
|
9
|
-
execFile('lsof', args, { timeout: 3000, maxBuffer: 4 * 1024 * 1024 }, (err, out) => resolve(err && !out ? '' : String(out || '')))
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* lsof's -F output as records: each `p<pid>` starts one, `c<command>` and `n<name>` lines fill it.
|
|
14
|
-
* Answers [{ pid, command, names: [] }].
|
|
15
|
-
*/
|
|
16
|
-
export function parseLsof (text) {
|
|
17
|
-
const out = []
|
|
18
|
-
let cur = null
|
|
19
|
-
for (const line of String(text || '').split('\n')) {
|
|
20
|
-
const tag = line[0]
|
|
21
|
-
const v = line.slice(1)
|
|
22
|
-
if (tag === 'p') { cur = { pid: Number(v), command: '', names: [] }; out.push(cur) } else if (cur && tag === 'c') cur.command = v
|
|
23
|
-
else if (cur && tag === 'n') cur.names.push(v)
|
|
24
|
-
}
|
|
25
|
-
return out
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** The port of a listening socket's name ("*:3000", "127.0.0.1:5173", "[::1]:8080"), or 0. */
|
|
29
|
-
export function portOf (name) {
|
|
30
|
-
const m = /:(\d{2,5})$/.exec(String(name || ''))
|
|
31
|
-
return m ? Number(m[1]) : 0
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// A folder's real path (lsof reports them: on a Mac /var is /private/var), or the path as given.
|
|
35
|
-
const real = (p) => { try { return fs.realpathSync(p) } catch { return path.resolve(p) } }
|
|
36
|
-
|
|
37
|
-
/** Whether `cwd` is `dir` or inside it, comparing real paths. */
|
|
38
|
-
export function within (cwd, dir) {
|
|
39
|
-
const rel = path.relative(real(dir), real(cwd))
|
|
40
|
-
return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel))
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The dev servers running from `dir`: [{ port, url, command, pid }], lowest port first. `skip`: ports
|
|
45
|
-
* that are Quilt's own (its app), never listed.
|
|
46
|
-
*/
|
|
47
|
-
export async function devServers (dir, { skip = [] } = {}) {
|
|
48
|
-
if (process.platform === 'win32' || !dir) return []
|
|
49
|
-
const listening = parseLsof(await run(['-nP', '-iTCP', '-sTCP:LISTEN', '-Fpcn']))
|
|
50
|
-
if (!listening.length) return []
|
|
51
|
-
const cwds = new Map(parseLsof(await run(['-a', '-d', 'cwd', '-Fpn', '-p', listening.map((l) => l.pid).join(',')])).map((r) => [r.pid, r.names[0] || '']))
|
|
52
|
-
const seen = new Set()
|
|
53
|
-
const out = []
|
|
54
|
-
for (const l of listening) {
|
|
55
|
-
const cwd = cwds.get(l.pid)
|
|
56
|
-
if (!cwd || !within(cwd, dir)) continue
|
|
57
|
-
for (const n of l.names) {
|
|
58
|
-
const port = portOf(n)
|
|
59
|
-
if (!port || seen.has(port) || skip.includes(port)) continue
|
|
60
|
-
seen.add(port)
|
|
61
|
-
out.push({ port, url: `http://localhost:${port}`, command: l.command, pid: l.pid })
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return out.sort((a, b) => a.port - b.port)
|
|
65
|
-
}
|
package/src/ui/home-view.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
// A workspace's home (plans/app-redesign.md, the dm06 mockup): charts of AI time and merges, its sessions as
|
|
2
|
-
// cards with who is working in each, and its previews (the links that matter). Drawn inside a session (its
|
|
3
|
-
// header's Home button) and as the workspace's own page. Data: the workspace (GET /api/workspaces/:id), its
|
|
4
|
-
// insights (AI minutes from the accounts API, merges from Seam) and this computer's open sessions.
|
|
5
|
-
import { esc, avatar, ago, I, api, toast, state, basename } from './common.js'
|
|
6
|
-
|
|
7
|
-
const SERIES = 'var(--chart, #2a78d6)' // one hue for every single-series chart
|
|
8
|
-
const DAY_MS = 24 * 60 * 60 * 1000
|
|
9
|
-
const dayStart = (t) => { const d = new Date(t); d.setHours(0, 0, 0, 0); return d.getTime() }
|
|
10
|
-
const hm = (min) => `${Math.floor(min / 60)}h ${String(Math.round(min % 60)).padStart(2, '0')}m`
|
|
11
|
-
|
|
12
|
-
/** The last `n` days (oldest first) with what fell on each: [{ start, label, value }]. */
|
|
13
|
-
function byDay (items, n, value = () => 1) {
|
|
14
|
-
const today = dayStart(Date.now())
|
|
15
|
-
const days = Array.from({ length: n }, (_, i) => ({ start: today - (n - 1 - i) * DAY_MS, value: 0 }))
|
|
16
|
-
for (const it of items) {
|
|
17
|
-
const i = days.findIndex((d) => it.at >= d.start && it.at < d.start + DAY_MS)
|
|
18
|
-
if (i >= 0) days[i].value += value(it)
|
|
19
|
-
}
|
|
20
|
-
return days.map((d, i) => ({ ...d, today: i === n - 1, label: new Date(d.start).toLocaleDateString([], { weekday: 'short' }) }))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function aiChart (ins) {
|
|
24
|
-
const days = byDay(ins.aiHours || [], 7, (h) => h.minutes)
|
|
25
|
-
const total = days.reduce((a, d) => a + d.value, 0)
|
|
26
|
-
const prev = (ins.aiHours || []).filter((h) => h.at < days[0].start && h.at >= days[0].start - 7 * DAY_MS).reduce((a, h) => a + h.minutes, 0)
|
|
27
|
-
const max = Math.max(1, ...days.map((d) => d.value))
|
|
28
|
-
const change = prev ? Math.round(((total - prev) / prev) * 100) : null
|
|
29
|
-
return `<div class="hm-chart"><div class="hm-ch"><small>AI time · last 7 days</small><b>${hm(total)}</b>${change == null ? '<em>Counted from when Quilt started keeping it</em>' : `<em class="${change >= 0 ? 'up' : 'down'}">${change >= 0 ? '+' : ''}${change}% on the week before</em>`}</div>
|
|
30
|
-
<div class="hm-bars">${days.map((d) => `<div class="hm-bar${d.today ? ' today' : ''}" data-tip="${esc(`${d.today ? 'Today' : d.label} · ${hm(d.value)} of AI time`)}"><i style="height:${Math.max(2, (d.value / max) * 100).toFixed(1)}%"></i><span>${esc(d.label.slice(0, 3))}</span></div>`).join('')}</div></div>`
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function mergesChart (ins) {
|
|
34
|
-
const days = byDay(ins.merges || [], 14)
|
|
35
|
-
const week = days.slice(7).reduce((a, d) => a + d.value, 0)
|
|
36
|
-
const last = days.slice(0, 7).reduce((a, d) => a + d.value, 0)
|
|
37
|
-
const W = 280; const H = 90
|
|
38
|
-
const max = Math.max(1, ...days.map((d) => d.value))
|
|
39
|
-
const pts = days.map((d, i) => [i * W / (days.length - 1), H - 6 - (d.value / max) * (H - 16)])
|
|
40
|
-
const line = 'M' + pts.map(([x, y]) => `${x.toFixed(1)},${y.toFixed(1)}`).join(' L')
|
|
41
|
-
const dots = pts.map(([x, y], i) => `<span class="hm-dot" style="left:${(x / W * 100).toFixed(2)}%;top:${(y / H * 100).toFixed(2)}%" data-tip="${esc(`${i === days.length - 1 ? 'Today' : new Date(days[i].start).toLocaleDateString([], { month: 'short', day: 'numeric' })} · ${days[i].value} merge${days[i].value === 1 ? '' : 's'} onto main`)}"></span>`).join('')
|
|
42
|
-
const none = !(ins.merges || []).length
|
|
43
|
-
return `<div class="hm-chart"><div class="hm-ch"><small>Merged onto main · 14 days</small><b>${week} this week</b><em class="${none ? '' : week >= last ? 'up' : 'down'}">${none ? 'From its sessions in Seam open on this computer' : `${week >= last ? '+' : ''}${week - last} on last week`}</em></div>
|
|
44
|
-
<div class="hm-line"><svg viewBox="0 0 ${W} ${H}" preserveAspectRatio="none" aria-hidden="true"><path d="${line} L${W},${H} L0,${H} Z" fill="${SERIES}" fill-opacity=".10"/><path d="${line}" fill="none" stroke="${SERIES}" stroke-width="2" vector-effect="non-scaling-stroke" stroke-linejoin="round"/></svg>${dots}</div>
|
|
45
|
-
<div class="hm-ax"><span>2 weeks ago</span><span>Today</span></div></div>`
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function bySessionChart (ins, names) {
|
|
49
|
-
const since = dayStart(Date.now()) - 6 * DAY_MS
|
|
50
|
-
const per = new Map()
|
|
51
|
-
for (const h of ins.aiHours || []) if (h.at >= since) per.set(h.room, (per.get(h.room) || 0) + h.minutes)
|
|
52
|
-
const rows = [...per].sort((a, b) => b[1] - a[1]).slice(0, 5)
|
|
53
|
-
const max = Math.max(1, ...rows.map(([, v]) => v))
|
|
54
|
-
const top = rows.length ? Math.round(rows[0][1] / rows.reduce((a, [, v]) => a + v, 0) * 100) : 0
|
|
55
|
-
return `<div class="hm-chart"><div class="hm-ch"><small>AI time by session · 7 days</small><b>${rows.length} session${rows.length === 1 ? '' : 's'}</b><em>${rows.length ? `${esc(names.get(rows[0][0]) || rows[0][0])} is ${top}% of it` : 'No AI time yet this week'}</em></div>
|
|
56
|
-
<div class="hm-rows">${rows.map(([room, v]) => `<div class="hm-row" data-tip="${esc(`${names.get(room) || room} · ${hm(v)} of AI time this week`)}"><span class="hm-rn">${esc(names.get(room) || room)}</span><span class="hm-rt"><i style="width:${(v / max * 100).toFixed(1)}%"></i></span><span class="hm-rv">${hm(v)}</span></div>`).join('')}</div></div>`
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Who is working in each of the workspace's sessions open on this computer: room -> { working, faces, id }. */
|
|
60
|
-
function liveByRoom () {
|
|
61
|
-
const out = new Map()
|
|
62
|
-
for (const x of state.sessions.values()) {
|
|
63
|
-
const st = x.status
|
|
64
|
-
if (!st || !st.room) continue
|
|
65
|
-
const faces = [st.me, ...(st.peers || [])].filter((p) => p && p.agent && p.agent.status === 'working')
|
|
66
|
-
out.set(st.room, { id: x.id, working: faces.length, faces, people: [st.me, ...(st.peers || [])].filter(Boolean), name: st.sessionName || basename(x.dir) })
|
|
67
|
-
}
|
|
68
|
-
return out
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const facesHtml = (list, max = 4) => `<span class="hm-faces">${list.slice(0, max).map((p, i) => `<span style="z-index:${10 - i}">${avatar(p.name, p.color)}</span>`).join('')}</span>`
|
|
72
|
-
|
|
73
|
-
function sessionCard (s, live) {
|
|
74
|
-
const l = live.get(s.room)
|
|
75
|
-
const name = s.name || l?.name || s.room
|
|
76
|
-
const state = l ? (l.working ? `<span class="hm-cs lv"><span class="pulse"></span>${l.working} working</span>` : '<span class="hm-cs">Open here</span>') : `<span class="hm-cs">${s.lastActiveAt ? `Quiet · ${esc(ago(s.lastActiveAt))}` : 'Quiet'}</span>`
|
|
77
|
-
const doing = l ? (l.faces.map((p) => p.focus).find(Boolean) || '') : ''
|
|
78
|
-
return `<div class="hm-card${l && l.working ? '' : ' quiet'}" ${l ? `data-hm-open="${esc(l.id)}"` : `data-hm-join="${esc(s.room)}"`} title="${l ? 'Open this session' : 'Open it from the list below the cards'}">
|
|
79
|
-
<div class="hm-ct"><span class="hm-ico">${I.grid}</span><b>${esc(name)}</b>${state}</div>
|
|
80
|
-
<small class="hm-cl">${esc(doing || (l ? `${l.people.length} here` : 'Not open on this computer'))}</small>
|
|
81
|
-
<div class="hm-cf">${l ? facesHtml(l.working ? l.faces : l.people) : '<span></span>'}<span class="hm-room">${esc(name)}</span></div></div>`
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function previewsHtml (d, edit, names, adding) {
|
|
85
|
-
const links = d.links || []
|
|
86
|
-
const rows = links.map((l) => {
|
|
87
|
-
const host = (() => { try { return new URL(l.url).host } catch { return l.url } })()
|
|
88
|
-
const local = /^(localhost|127\.|0\.0\.0\.0)/.test(host)
|
|
89
|
-
return `<div class="hm-pv"><span class="hm-pvdot${local ? ' live' : ''}"></span><div class="hm-pvx"><b>${esc(l.name)}</b><code>${esc(host)}</code><small>${esc([l.room ? names.get(l.room) || '' : '', l.note].filter(Boolean).join(' · ') || 'For the whole workspace')}</small></div>
|
|
90
|
-
<a class="hm-pvo" href="${esc(l.url)}" target="_blank" rel="noopener" title="Open ${esc(l.url)}" aria-label="Open ${esc(l.name)}">${I.external}</a>${edit ? `<button type="button" class="hm-pvx-rm" data-hm-rmlink="${esc(l.id)}" title="Remove ${esc(l.name)}" aria-label="Remove ${esc(l.name)}">${I.x}</button>` : ''}</div>`
|
|
91
|
-
}).join('')
|
|
92
|
-
const form = adding
|
|
93
|
-
? `<form class="hm-pv hm-pvform" data-hm-linkform><input class="input" name="name" placeholder="Name (Production, Staging…)" required maxlength="80"><input class="input" name="url" placeholder="https://…" required maxlength="500"><select class="input" name="room"><option value="">Whole workspace</option>${(d.sessions || []).map((s) => `<option value="${esc(s.room)}">${esc(s.name || s.room)}</option>`).join('')}</select><button class="btn primary" type="submit">Add</button><button class="btn ghost" type="button" data-hm-cancel>Cancel</button></form>`
|
|
94
|
-
: edit ? `<button type="button" class="hm-pv hm-pvadd" data-hm-addlink>${I.plus}Add a link</button>` : ''
|
|
95
|
-
return `<section class="hm-sec"><h3>Previews</h3><div class="hm-pvg">${rows}${form}</div>${!links.length && !edit ? '<p class="hint">No links yet.</p>' : ''}</section>`
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** The home's markup: `ins` may still be loading (null). */
|
|
99
|
-
export function workspaceHomeHtml (d, ins, { adding = false } = {}) {
|
|
100
|
-
const live = liveByRoom()
|
|
101
|
-
const names = new Map((d.sessions || []).map((s) => [s.room, s.name || live.get(s.room)?.name || s.room]))
|
|
102
|
-
const working = (d.sessions || []).reduce((a, s) => a + (live.get(s.room)?.working || 0), 0)
|
|
103
|
-
const busy = (d.sessions || []).filter((s) => live.get(s.room)?.working).length
|
|
104
|
-
const edit = d.access && (d.access.access === 'edit' || d.access.admin)
|
|
105
|
-
const charts = ins ? `<div class="hm-charts">${aiChart(ins)}${mergesChart(ins)}${bySessionChart(ins, names)}</div>` : '<div class="hm-charts loading"><div class="hm-chart"></div><div class="hm-chart"></div><div class="hm-chart"></div></div>'
|
|
106
|
-
return `<div class="hm-page">
|
|
107
|
-
<div class="hm-head"><div><h2>${esc(d.workspace.name)}</h2><small>${working ? `${working} working across ${busy} session${busy === 1 ? '' : 's'} right now` : `${(d.sessions || []).length} session${(d.sessions || []).length === 1 ? '' : 's'} · nobody working right now`}</small></div><span class="hm-sp"></span>
|
|
108
|
-
<button type="button" class="btn" data-hm-invite>${I.users}<span>Invite</span></button><button type="button" class="btn primary" data-hm-new>${I.plus}<span>New session</span></button></div>
|
|
109
|
-
${charts}
|
|
110
|
-
<section class="hm-sec"><h3>Sessions</h3><div class="hm-grid">${(d.sessions || []).map((s) => sessionCard(s, live)).join('') || '<p class="hint">No sessions yet: New session starts one.</p>'}</div></section>
|
|
111
|
-
${previewsHtml(d, edit, names, adding)}
|
|
112
|
-
</div>`
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const insights = new Map() // workspace id -> { at, data }
|
|
116
|
-
let loading = null
|
|
117
|
-
|
|
118
|
-
/** The workspace's insights, cached a minute: calls `then` when fresh ones arrive. */
|
|
119
|
-
export function homeInsights (id, then) {
|
|
120
|
-
const c = insights.get(id)
|
|
121
|
-
if (c && Date.now() - c.at < 60_000) return c.data
|
|
122
|
-
if (loading !== id) {
|
|
123
|
-
loading = id
|
|
124
|
-
api('GET', `/api/workspaces/${encodeURIComponent(id)}/insights`).then((data) => { insights.set(id, { at: Date.now(), data }); then() })
|
|
125
|
-
.catch(() => { insights.set(id, { at: Date.now(), data: { aiHours: [], merges: [] } }); then() })
|
|
126
|
-
.finally(() => { loading = null })
|
|
127
|
-
}
|
|
128
|
-
return c ? c.data : null
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
let tip = null
|
|
132
|
-
/** Clicks, the Add a link form and the charts' tooltips. `reload()` fetches the workspace again. */
|
|
133
|
-
export function bindWorkspaceHome (root, { id, go, reload, newSession, invite, setAdding }) {
|
|
134
|
-
if (!tip) { tip = document.createElement('div'); tip.className = 'hm-tip'; tip.hidden = true; document.body.appendChild(tip) }
|
|
135
|
-
root.onmousemove = (e) => {
|
|
136
|
-
const t = e.target.closest('[data-tip]')
|
|
137
|
-
if (!t || !root.contains(t)) { tip.hidden = true; return }
|
|
138
|
-
tip.textContent = t.dataset.tip
|
|
139
|
-
tip.hidden = false
|
|
140
|
-
tip.style.left = `${Math.min(e.clientX + 14, innerWidth - tip.offsetWidth - 8)}px`
|
|
141
|
-
tip.style.top = `${e.clientY - 34}px`
|
|
142
|
-
}
|
|
143
|
-
root.onmouseleave = () => { tip.hidden = true }
|
|
144
|
-
root.onclick = async (e) => {
|
|
145
|
-
const o = e.target.closest('[data-hm-open]')
|
|
146
|
-
if (o) { tip.hidden = true; go(o.dataset.hmOpen); return }
|
|
147
|
-
if (e.target.closest('[data-hm-join]')) { go(`ws:${id}`); return }
|
|
148
|
-
if (e.target.closest('[data-hm-new]')) return newSession()
|
|
149
|
-
if (e.target.closest('[data-hm-invite]')) return invite()
|
|
150
|
-
if (e.target.closest('[data-hm-addlink]')) { setAdding(true); return }
|
|
151
|
-
if (e.target.closest('[data-hm-cancel]')) { setAdding(false); return }
|
|
152
|
-
const rm = e.target.closest('[data-hm-rmlink]')
|
|
153
|
-
if (rm) {
|
|
154
|
-
try { await api('POST', `/api/workspaces/${encodeURIComponent(id)}/links/${encodeURIComponent(rm.dataset.hmRmlink)}/remove`) } catch (err) { toast(err.message) }
|
|
155
|
-
reload()
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
const form = root.querySelector('[data-hm-linkform]')
|
|
159
|
-
if (form) {
|
|
160
|
-
form.elements.name.focus()
|
|
161
|
-
form.onsubmit = async (e) => {
|
|
162
|
-
e.preventDefault()
|
|
163
|
-
try {
|
|
164
|
-
await api('POST', `/api/workspaces/${encodeURIComponent(id)}/links`, { name: form.elements.name.value, url: form.elements.url.value, room: form.elements.room.value || null })
|
|
165
|
-
setAdding(false)
|
|
166
|
-
reload()
|
|
167
|
-
} catch (err) { toast(err.message) }
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
package/src/ui/palette.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
// The ⌘K palette (plans/app-redesign.md, the dm06 mockup): one box over the window that finds sessions,
|
|
2
|
-
// people, files and actions, grouped, and opens the pick. Pages register what they offer (`paletteSource`);
|
|
3
|
-
// the rail's search button and ⌘K / Ctrl+K open it.
|
|
4
|
-
import { esc, I, avatar } from './common.js'
|
|
5
|
-
|
|
6
|
-
const SEARCH = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>'
|
|
7
|
-
const sources = new Map() // name -> () => [{ group, title, sub, icon | face: { name, color }, run }]
|
|
8
|
-
let box = null
|
|
9
|
-
let items = []
|
|
10
|
-
let sel = 0
|
|
11
|
-
|
|
12
|
-
/** What a page offers in the palette, under `name` (replaced when called again). */
|
|
13
|
-
export function paletteSource (name, fn) { if (fn) sources.set(name, fn); else sources.delete(name) }
|
|
14
|
-
|
|
15
|
-
const mark = (text, q) => {
|
|
16
|
-
if (!q) return esc(text)
|
|
17
|
-
const i = text.toLowerCase().indexOf(q)
|
|
18
|
-
return i < 0 ? esc(text) : `${esc(text.slice(0, i))}<mark>${esc(text.slice(i, i + q.length))}</mark>${esc(text.slice(i + q.length))}`
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function draw () {
|
|
22
|
-
const q = box.querySelector('input').value.trim().toLowerCase()
|
|
23
|
-
const all = [...sources.values()].flatMap((fn) => { try { return fn() || [] } catch { return [] } })
|
|
24
|
-
items = all.filter((it) => !q || `${it.title} ${it.sub || ''} ${it.group}`.toLowerCase().includes(q)).slice(0, 60)
|
|
25
|
-
if (sel >= items.length) sel = Math.max(0, items.length - 1)
|
|
26
|
-
let group = ''
|
|
27
|
-
const rows = items.map((it, i) => {
|
|
28
|
-
const head = it.group !== group ? `<div class="pal-h">${esc((group = it.group))}</div>` : ''
|
|
29
|
-
const ico = it.face ? `<span class="pal-i face">${avatar(it.face.name, it.face.color)}</span>` : `<span class="pal-i">${it.icon || I.arrowRight}</span>`
|
|
30
|
-
return `${head}<div class="pal-r${i === sel ? ' on' : ''}" data-pal-i="${i}" role="option" aria-selected="${i === sel}">${ico}<span class="pal-t"><b>${mark(it.title, q)}</b>${it.sub ? `<small>${mark(it.sub, q)}</small>` : ''}</span><span class="pal-k">↵</span></div>`
|
|
31
|
-
}).join('')
|
|
32
|
-
box.querySelector('.pal-res').innerHTML = rows || `<div class="pal-h none">Nothing matches “${esc(q)}”.</div>`
|
|
33
|
-
box.querySelector('.pal-r.on')?.scrollIntoView({ block: 'nearest' })
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function close () { if (box) { box.hidden = true; box.previousElementSibling.hidden = true } }
|
|
37
|
-
|
|
38
|
-
function pick (i) {
|
|
39
|
-
const it = items[i]
|
|
40
|
-
if (!it) return
|
|
41
|
-
close()
|
|
42
|
-
it.run()
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function openPalette () {
|
|
46
|
-
if (!box) {
|
|
47
|
-
document.body.insertAdjacentHTML('beforeend', `<div class="pal-back" hidden></div><div class="pal" role="dialog" aria-label="Search" hidden>
|
|
48
|
-
<div class="pal-in">${SEARCH}<input placeholder="Search sessions, people and files, or type a command" autocomplete="off" spellcheck="false" aria-label="Search"><kbd>esc</kbd></div>
|
|
49
|
-
<div class="pal-res" role="listbox"></div>
|
|
50
|
-
<div class="pal-ft"><span><kbd>↑</kbd><kbd>↓</kbd> to move</span><span><kbd>↵</kbd> to open</span><span class="pal-sp"></span><span>⌘K opens this anywhere</span></div></div>`)
|
|
51
|
-
box = document.body.lastElementChild
|
|
52
|
-
const input = box.querySelector('input')
|
|
53
|
-
input.addEventListener('input', () => { sel = 0; draw() })
|
|
54
|
-
input.addEventListener('keydown', (e) => {
|
|
55
|
-
if (e.key === 'ArrowDown') { e.preventDefault(); sel = Math.min(items.length - 1, sel + 1); draw() }
|
|
56
|
-
if (e.key === 'ArrowUp') { e.preventDefault(); sel = Math.max(0, sel - 1); draw() }
|
|
57
|
-
if (e.key === 'Enter') { e.preventDefault(); pick(sel) }
|
|
58
|
-
if (e.key === 'Escape') { e.preventDefault(); close() }
|
|
59
|
-
})
|
|
60
|
-
box.querySelector('.pal-res').addEventListener('mousemove', (e) => { const r = e.target.closest('[data-pal-i]'); if (r && Number(r.dataset.palI) !== sel) { sel = Number(r.dataset.palI); draw() } })
|
|
61
|
-
box.querySelector('.pal-res').addEventListener('click', (e) => { const r = e.target.closest('[data-pal-i]'); if (r) pick(Number(r.dataset.palI)) })
|
|
62
|
-
box.previousElementSibling.addEventListener('mousedown', close)
|
|
63
|
-
}
|
|
64
|
-
sel = 0
|
|
65
|
-
box.hidden = false
|
|
66
|
-
box.previousElementSibling.hidden = false
|
|
67
|
-
const input = box.querySelector('input')
|
|
68
|
-
input.value = ''
|
|
69
|
-
draw()
|
|
70
|
-
input.focus()
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
document.addEventListener('keydown', (e) => {
|
|
74
|
-
if ((e.metaKey || e.ctrlKey) && !e.altKey && !e.shiftKey && e.key.toLowerCase() === 'k') { e.preventDefault(); if (box && !box.hidden) close(); else openPalette() }
|
|
75
|
-
})
|
package/src/ui/people-view.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
// The workspace's people (plans/app-redesign.md, the dm06 mockup): Humans and AI, each a grid of cards with
|
|
2
|
-
// its own search, ten at a time and "Load more". Humans are the workspace's members; AI are its agents and
|
|
3
|
-
// each person's AI sessions seen in the sessions open on this computer, with what they are doing now.
|
|
4
|
-
import { esc, avatar, state, basename } from './common.js'
|
|
5
|
-
import { toolLabel } from './tool-logo.js'
|
|
6
|
-
|
|
7
|
-
const PAGE = 10
|
|
8
|
-
|
|
9
|
-
/** Everyone seen in the sessions open here: name -> { status, tool, focus, sessions[] }. */
|
|
10
|
-
function seen () {
|
|
11
|
-
const out = new Map()
|
|
12
|
-
for (const x of state.sessions.values()) {
|
|
13
|
-
const st = x.status
|
|
14
|
-
if (!st) continue
|
|
15
|
-
const where = st.sessionName || basename(x.dir)
|
|
16
|
-
for (const p of [st.me, ...(st.peers || [])]) {
|
|
17
|
-
if (!p || !p.name) continue
|
|
18
|
-
const o = out.get(p.name) || { sessions: [], status: 'away', tool: '', focus: '', kind: p.kind, color: p.color, isMe: p === st.me }
|
|
19
|
-
if (!o.sessions.includes(where)) o.sessions.push(where)
|
|
20
|
-
const working = p.agent && p.agent.status === 'working'
|
|
21
|
-
if (working) o.status = 'working'
|
|
22
|
-
else if (o.status === 'away') o.status = 'idle'
|
|
23
|
-
o.tool = o.tool || (p.agent && p.agent.tool) || p.tool || ''
|
|
24
|
-
o.focus = o.focus || p.focus || ''
|
|
25
|
-
out.set(p.name, o)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return out
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const stateHtml = (st) => `<span class="pp-st ${esc(st)}">${st === 'working' ? '<span class="pulse"></span>' : ''}${esc(st[0].toUpperCase() + st.slice(1))}</span>`
|
|
32
|
-
|
|
33
|
-
function card ({ name, sub, status, lines, actions, color, ai = false, key, face = name }) {
|
|
34
|
-
return `<div class="pp-card${ai ? ' ai' : ''}" data-pp-name="${esc(key.toLowerCase())}">${avatar(face, color)}<div class="pp-m"><b>${esc(name)}</b><small>${esc(sub)}</small></div>${stateHtml(status)}
|
|
35
|
-
<div class="pp-w">${lines.map((l) => `<span>${esc(l)}</span>`).join('')}</div><div class="pp-act">${actions}</div></div>`
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function gridHtml (kind, title, sub, cards, placeholder, shown) {
|
|
39
|
-
return `<section class="pp-sec" data-pp="${kind}">
|
|
40
|
-
<div class="pp-h"><div><h2>${esc(title)} <i>${cards.length}</i></h2><small>${esc(sub)}</small></div><label class="pp-sr"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg><input data-pp-q placeholder="${esc(placeholder)}" aria-label="${esc(placeholder)}"></label></div>
|
|
41
|
-
<div class="pp-g">${cards.map((c, i) => c.replace('class="pp-card', `class="pp-card${i >= shown ? ' more' : ''}`)).join('')}</div>
|
|
42
|
-
<p class="pp-empty" hidden>No one matches.</p>
|
|
43
|
-
${cards.length > shown ? `<button type="button" class="btn pp-moreb" data-pp-more>Load more <i>${cards.length - shown} more</i></button>` : ''}
|
|
44
|
-
</section>`
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** The page: `d` is the workspace (members, agents, owner); `here` the names in the open session (Message opens their DMs). */
|
|
48
|
-
export function peoplePageHtml (d, { me = '', here = new Set() } = {}) {
|
|
49
|
-
const live = seen()
|
|
50
|
-
const msg = (n) => here.has(n) && n !== me ? `<button type="button" class="btn sm" data-pp-dm="${esc(n)}">Message</button>` : ''
|
|
51
|
-
// Profile: their view in the open session (what their AI is doing, their threads, your messages with them).
|
|
52
|
-
const profile = (n) => here.has(n) ? `<button type="button" class="btn sm" data-pp-person="${esc(n)}">Profile</button>` : ''
|
|
53
|
-
const members = (d.members || []).filter((m) => m.kind !== 'agent')
|
|
54
|
-
const names = new Set()
|
|
55
|
-
const humans = []
|
|
56
|
-
const add = (name, role) => {
|
|
57
|
-
if (!name || names.has(name)) return
|
|
58
|
-
names.add(name)
|
|
59
|
-
const l = live.get(name)
|
|
60
|
-
humans.push(card({ key: `${name} ${role} ${l ? l.sessions.join(' ') : ''}`, name: name === me ? `${name} (you)` : name, sub: [role, l?.tool && toolLabel(l.tool)].filter(Boolean).join(' · '), status: l ? l.status : 'away', lines: [l ? `In ${l.sessions.join(', ')}` : 'Not in a session open here'], actions: msg(name) + profile(name), color: l?.color }))
|
|
61
|
-
}
|
|
62
|
-
if (d.owner && d.owner.name) add(d.owner.name, 'Owner')
|
|
63
|
-
for (const m of members) add(m.name, m.access === 'view' ? 'Viewer' : 'Member')
|
|
64
|
-
for (const [name, l] of live) if (l.kind !== 'agent' && !names.has(name)) add(name, 'Member')
|
|
65
|
-
const ai = []
|
|
66
|
-
const agentNames = new Set()
|
|
67
|
-
for (const a of d.agents || []) {
|
|
68
|
-
const name = a.name || 'Agent'
|
|
69
|
-
agentNames.add(name)
|
|
70
|
-
const l = live.get(name)
|
|
71
|
-
ai.push(card({ ai: true, key: `${name} agent ${l ? l.sessions.join(' ') : ''} ${l?.focus || ''}`, name, sub: 'Agent', status: l ? l.status : 'asleep', lines: [l?.focus || (l ? 'No task' : 'Not in a session open here'), ...(l ? [`In ${l.sessions.join(', ')}`] : [])], actions: msg(name) + '<button type="button" class="btn sm" data-pp-settings="agents">Settings</button>', color: l?.color }))
|
|
72
|
-
}
|
|
73
|
-
// Each person's AI, as seen working in the sessions open here.
|
|
74
|
-
for (const [name, l] of live) {
|
|
75
|
-
if (agentNames.has(name)) continue
|
|
76
|
-
if (l.kind === 'agent') {
|
|
77
|
-
ai.push(card({ ai: true, key: `${name} agent ${l.sessions.join(' ')} ${l.focus}`, name, sub: 'Agent', status: l.status, lines: [l.focus || 'No task', `In ${l.sessions.join(', ')}`], actions: msg(name) + '<button type="button" class="btn sm" data-pp-settings="agents">Settings</button>', color: l.color }))
|
|
78
|
-
continue
|
|
79
|
-
}
|
|
80
|
-
if (!l.tool) continue
|
|
81
|
-
// Each person's AI as dm06 names it: "Bob's Cursor", working for Bob.
|
|
82
|
-
const tool = toolLabel(l.tool)
|
|
83
|
-
ai.push(card({ ai: true, key: `${name} ${tool} ${l.sessions.join(' ')} ${l.focus}`, name: name === me ? `Your ${tool}` : `${name}’s ${tool}`, face: name, sub: name === me ? 'Works for you' : `Works for ${name}`, status: l.status === 'working' ? 'working' : 'idle', lines: [l.focus || 'No task', `In ${l.sessions.join(', ')}`], actions: (here.has(name) ? `<button type="button" class="btn sm" data-pp-person="${esc(name)}">Open chats</button>` : '') + '<button type="button" class="btn sm" data-pp-settings="agents">Settings</button>', color: l.color }))
|
|
84
|
-
}
|
|
85
|
-
return `<div class="pp-page"><div class="pp-top"><span>Everyone in ${esc(d.workspace.name)}</span><button type="button" class="btn sm" data-pp-invite>Invite</button></div>${gridHtml('h', 'Humans', `People in ${d.workspace.name}`, humans, 'Search humans', PAGE)}${gridHtml('a', 'AI', 'Agents of the workspace, and each person’s AI', ai, 'Search AI', PAGE)}</div>`
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/** Search and Load more in each grid; Message, Open chats and Settings go through `on`. */
|
|
89
|
-
export function bindPeoplePage (root, on) {
|
|
90
|
-
root.oninput = (e) => {
|
|
91
|
-
if (!e.target.matches('[data-pp-q]')) return
|
|
92
|
-
const s = e.target.closest('[data-pp]')
|
|
93
|
-
const q = e.target.value.trim().toLowerCase()
|
|
94
|
-
let shown = 0
|
|
95
|
-
for (const c of s.querySelectorAll('.pp-card')) { const hit = !q || c.dataset.ppName.includes(q); c.classList.toggle('miss', !hit); if (hit) shown++ }
|
|
96
|
-
s.classList.toggle('searching', !!q)
|
|
97
|
-
s.querySelector('.pp-empty').hidden = shown > 0
|
|
98
|
-
}
|
|
99
|
-
root.onclick = (e) => {
|
|
100
|
-
const more = e.target.closest('[data-pp-more]')
|
|
101
|
-
if (more) {
|
|
102
|
-
const s = more.closest('[data-pp]')
|
|
103
|
-
;[...s.querySelectorAll('.pp-card.more')].slice(0, PAGE).forEach((c) => c.classList.remove('more'))
|
|
104
|
-
const left = s.querySelectorAll('.pp-card.more').length
|
|
105
|
-
if (!left) more.remove(); else more.querySelector('i').textContent = `${left} more`
|
|
106
|
-
return
|
|
107
|
-
}
|
|
108
|
-
const dm = e.target.closest('[data-pp-dm]')
|
|
109
|
-
if (dm) return on.message(dm.dataset.ppDm)
|
|
110
|
-
const p = e.target.closest('[data-pp-person]')
|
|
111
|
-
if (p) return on.person(p.dataset.ppPerson)
|
|
112
|
-
if (e.target.closest('[data-pp-invite]')) return on.invite()
|
|
113
|
-
const st = e.target.closest('[data-pp-settings]')
|
|
114
|
-
if (st) return on.settings(st.dataset.ppSettings)
|
|
115
|
-
}
|
|
116
|
-
}
|