heyquilt 0.3.154 → 0.3.155

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.
@@ -0,0 +1,116 @@
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
+ }