pisha-server 0.0.0-stage → 0.0.12
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/LICENSE +21 -0
- package/README.md +40 -2
- package/accounts/accounts.js +754 -0
- package/accounts/index.js +1 -0
- package/accounts/passwords.js +41 -0
- package/accounts/totp.js +54 -0
- package/boards/boards.js +1087 -0
- package/boards/github.js +212 -0
- package/boards/index.js +1 -0
- package/boards/sync.js +980 -0
- package/companies.js +294 -0
- package/company-export.js +101 -0
- package/company.js +82 -0
- package/dashboard/dashboard.js +408 -0
- package/dashboard/index.js +1 -0
- package/data-upgrade.js +69 -0
- package/install/linux.sh +181 -0
- package/install/macos.sh +121 -0
- package/install/windows.bat +54 -0
- package/machines/index.js +3 -0
- package/machines/machines.js +910 -0
- package/messaging/inbox.js +252 -0
- package/messaging/index.js +3 -0
- package/messaging/messaging.js +551 -0
- package/messaging/plans.js +67 -0
- package/observation/index.js +1 -0
- package/observation/observation.js +231 -0
- package/organization/index.js +1 -0
- package/organization/organization.js +218 -0
- package/package.json +55 -4
- package/permissions/index.js +1 -0
- package/permissions/permissions.js +211 -0
- package/pisha-host.mjs +3303 -0
- package/pisha-host.mjs.sig +1 -0
- package/platform/acme.js +207 -0
- package/platform/basics.js +14 -0
- package/platform/config.js +154 -0
- package/platform/control.js +93 -0
- package/platform/credentials.js +151 -0
- package/platform/database.js +251 -0
- package/platform/errors.js +13 -0
- package/platform/files.js +50 -0
- package/platform/http.js +207 -0
- package/platform/index.js +58 -0
- package/platform/limits.js +122 -0
- package/platform/listen.js +183 -0
- package/platform/roles.js +6 -0
- package/platform/stream.js +19 -0
- package/platform/text.js +83 -0
- package/platform/ws.js +186 -0
- package/routes.js +405 -0
- package/server.js +65 -0
- package/sessions/index.js +1 -0
- package/sessions/sessions.js +533 -0
- package/ui/LICENSE-affectui.txt +26 -0
- package/ui/addmachine.js +151 -0
- package/ui/api.js +20 -0
- package/ui/app.js +143 -0
- package/ui/attention.js +78 -0
- package/ui/back.js +168 -0
- package/ui/boards.js +958 -0
- package/ui/chat.js +388 -0
- package/ui/content.js +157 -0
- package/ui/dialogs.js +135 -0
- package/ui/doing.js +112 -0
- package/ui/dom.js +6 -0
- package/ui/ds-base.css +146 -0
- package/ui/ds-components.css +229 -0
- package/ui/fonts/LICENSE-space-grotesk.txt +93 -0
- package/ui/fonts/space-grotesk-latin-700-normal.woff2 +0 -0
- package/ui/fonts/space-grotesk-latin-ext-700-normal.woff2 +0 -0
- package/ui/format.js +25 -0
- package/ui/i18n.js +2145 -0
- package/ui/icons/apple-touch-icon.png +0 -0
- package/ui/icons/icon-192.png +0 -0
- package/ui/icons/icon-512.png +0 -0
- package/ui/icons/maskable-512.png +0 -0
- package/ui/icons.js +41 -0
- package/ui/inbox.js +535 -0
- package/ui/index.html +105 -0
- package/ui/machines.js +261 -0
- package/ui/manifest.webmanifest +16 -0
- package/ui/mosaic.js +189 -0
- package/ui/nav.js +142 -0
- package/ui/newteam.js +223 -0
- package/ui/org.js +669 -0
- package/ui/overlays.css +126 -0
- package/ui/palette.js +180 -0
- package/ui/people.js +371 -0
- package/ui/permissions.js +202 -0
- package/ui/qr.js +158 -0
- package/ui/router.js +173 -0
- package/ui/routes.js +47 -0
- package/ui/screen-boards.css +241 -0
- package/ui/screen-inbox.css +201 -0
- package/ui/screen-machines.css +76 -0
- package/ui/screen-mosaic.css +26 -0
- package/ui/screen-newteam.css +90 -0
- package/ui/screen-org.css +119 -0
- package/ui/screen-session.css +99 -0
- package/ui/screen-signin.css +28 -0
- package/ui/screen-team.css +80 -0
- package/ui/screen-teams.css +41 -0
- package/ui/screen-usage.css +60 -0
- package/ui/session.js +42 -0
- package/ui/shell.css +122 -0
- package/ui/signin.js +120 -0
- package/ui/squads.js +371 -0
- package/ui/state.js +59 -0
- package/ui/stream.js +269 -0
- package/ui/styles.css +343 -0
- package/ui/team.js +115 -0
- package/ui/teams.js +58 -0
- package/ui/terminal.js +261 -0
- package/ui/theme.js +32 -0
- package/ui/timeline.js +163 -0
- package/ui/topbar.js +211 -0
- package/ui/usage.js +175 -0
- package/ui/voice-parse.js +98 -0
- package/ui/voice.js +320 -0
- package/usage/index.js +1 -0
- package/usage/usage.js +127 -0
- package/vendor/InterVariable.woff2 +0 -0
- package/vendor/LICENSE-inter +92 -0
- package/vendor/LICENSE-xterm +21 -0
- package/vendor/README.md +8 -0
- package/vendor/addon-fit.js +2 -0
- package/vendor/xterm.css +218 -0
- package/vendor/xterm.js +2 -0
package/ui/index.html
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="es">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Pisha</title>
|
|
7
|
+
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg%20xmlns%3D%22http://www.w3.org/2000/svg%22%20viewBox%3D%220%200%2064%2064%22%3E%3Crect%20width%3D%2264%22%20height%3D%2264%22%20rx%3D%2215%22%20fill%3D%22%23F2B90F%22/%3E%3Ccircle%20cx%3D%2222.5%22%20cy%3D%2225%22%20r%3D%224.8%22%20fill%3D%22%2314213D%22/%3E%3Cpath%20d%3D%22M35%2026.5q5.5-5%2011%200%22%20fill%3D%22none%22%20stroke%3D%22%2314213D%22%20stroke-width%3D%224.6%22%20stroke-linecap%3D%22round%22/%3E%3Cpath%20d%3D%22M19%2037q13%2014%2026%200%22%20fill%3D%22none%22%20stroke%3D%22%2314213D%22%20stroke-width%3D%224.6%22%20stroke-linecap%3D%22round%22/%3E%3C/svg%3E">
|
|
8
|
+
<link rel="manifest" href="/manifest.webmanifest">
|
|
9
|
+
<link rel="apple-touch-icon" href="/icons/apple-touch-icon.png">
|
|
10
|
+
<meta name="theme-color" content="#f6f6f7" media="(prefers-color-scheme: light)">
|
|
11
|
+
<meta name="theme-color" content="#0f1114" media="(prefers-color-scheme: dark)">
|
|
12
|
+
<meta name="apple-mobile-web-app-title" content="Pisha">
|
|
13
|
+
<meta name="mobile-web-app-capable" content="yes">
|
|
14
|
+
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
15
|
+
<meta name="apple-mobile-web-app-status-bar-style" content="default">
|
|
16
|
+
<link rel="preload" href="/vendor/InterVariable.woff2" as="font" type="font/woff2" crossorigin>
|
|
17
|
+
<link rel="preload" href="/fonts/space-grotesk-700.woff2" as="font" type="font/woff2" crossorigin>
|
|
18
|
+
<link rel="stylesheet" href="/ui/styles.css">
|
|
19
|
+
<link rel="stylesheet" href="/ui/ds-base.css">
|
|
20
|
+
<link rel="stylesheet" href="/ui/ds-components.css">
|
|
21
|
+
<link rel="stylesheet" href="/ui/shell.css">
|
|
22
|
+
<link rel="stylesheet" href="/ui/overlays.css">
|
|
23
|
+
<link rel="stylesheet" href="/ui/screen-inbox.css">
|
|
24
|
+
<link rel="stylesheet" href="/ui/screen-teams.css">
|
|
25
|
+
<link rel="stylesheet" href="/ui/screen-org.css">
|
|
26
|
+
<link rel="stylesheet" href="/ui/screen-boards.css">
|
|
27
|
+
<link rel="stylesheet" href="/ui/screen-usage.css">
|
|
28
|
+
<link rel="stylesheet" href="/ui/screen-team.css">
|
|
29
|
+
<link rel="stylesheet" href="/ui/screen-session.css">
|
|
30
|
+
<link rel="stylesheet" href="/ui/screen-machines.css">
|
|
31
|
+
<link rel="stylesheet" href="/ui/screen-signin.css">
|
|
32
|
+
<link rel="stylesheet" href="/ui/screen-newteam.css">
|
|
33
|
+
<link rel="stylesheet" href="/ui/screen-mosaic.css">
|
|
34
|
+
<script>
|
|
35
|
+
// Light or dark, first thing, so the page doesn't flash.
|
|
36
|
+
try { const t = localStorage.getItem('pishaTheme'); if (t === 'light' || t === 'dark') document.documentElement.dataset.theme = t } catch {}
|
|
37
|
+
</script>
|
|
38
|
+
</head>
|
|
39
|
+
<body>
|
|
40
|
+
<svg width="0" height="0" style="position:absolute" aria-hidden="true">
|
|
41
|
+
<symbol id="pisha-logo" viewBox="0 0 64 64">
|
|
42
|
+
<rect width="64" height="64" rx="15" fill="#F2B90F"/>
|
|
43
|
+
<circle cx="22.5" cy="25" r="4.8" fill="#14213D"/>
|
|
44
|
+
<path d="M35 26.5q5.5-5 11 0" fill="none" stroke="#14213D" stroke-width="4.6" stroke-linecap="round"/>
|
|
45
|
+
<path d="M19 37q13 14 26 0" fill="none" stroke="#14213D" stroke-width="4.6" stroke-linecap="round"/>
|
|
46
|
+
</symbol>
|
|
47
|
+
</svg>
|
|
48
|
+
|
|
49
|
+
<div id="splash" hidden></div>
|
|
50
|
+
|
|
51
|
+
<div id="login" hidden>
|
|
52
|
+
<form class="login-card" id="loginForm">
|
|
53
|
+
<div class="brand"><svg class="logo" aria-hidden="true"><use href="#pisha-logo"/></svg><span class="wordmark">pisha</span></div>
|
|
54
|
+
<p id="loginIntro"></p>
|
|
55
|
+
<div id="loginFields"></div>
|
|
56
|
+
<button type="submit" id="loginBtn"></button>
|
|
57
|
+
<div class="login-err" id="loginErr"></div>
|
|
58
|
+
<div class="foot"><span class="ver"></span><span class="prefs"><button type="button" class="theme-btn" data-theme-toggle></button><span class="lang" role="group" aria-label="Language"><button type="button" data-lang="en">EN</button><button type="button" data-lang="es">ES</button></span></span></div>
|
|
59
|
+
</form>
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
<div id="app" hidden>
|
|
63
|
+
<aside id="rail" class="rail">
|
|
64
|
+
<div class="rail-top">
|
|
65
|
+
<div class="rail-brand"><svg class="logo" aria-hidden="true"><use href="#pisha-logo"/></svg><span class="wordmark">pisha</span></div>
|
|
66
|
+
<label class="rail-co" id="companyBox" hidden><span class="sr-only" id="companyLabel"></span><select id="companySelect"></select><svg class="ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 6 6 6-6 6"/></svg></label>
|
|
67
|
+
<div class="rail-co-name" id="companyName" hidden></div>
|
|
68
|
+
<button class="rail-search" id="searchBtn" type="button" aria-haspopup="dialog"></button>
|
|
69
|
+
</div>
|
|
70
|
+
<nav class="rail-scroll" id="nav"></nav>
|
|
71
|
+
<div class="rail-foot"><span class="rail-conn" role="status"><span class="dot" id="connDot"></span><span id="connText"></span></span><button class="rail-settings" id="settingsBtn" type="button" aria-haspopup="dialog"></button></div>
|
|
72
|
+
</aside>
|
|
73
|
+
<main id="main">
|
|
74
|
+
<header class="head">
|
|
75
|
+
<button class="head-back" id="backBtn" type="button" hidden></button>
|
|
76
|
+
<h1 id="topTitle"></h1>
|
|
77
|
+
<div class="head-tabs" id="topTabs"></div>
|
|
78
|
+
<span class="head-sub" id="topSub"></span>
|
|
79
|
+
<span class="head-conn" id="headConn" role="status" hidden></span>
|
|
80
|
+
<div class="head-actions" id="topRight"></div>
|
|
81
|
+
</header>
|
|
82
|
+
<div id="alerts" hidden></div>
|
|
83
|
+
<div id="teams" hidden></div>
|
|
84
|
+
<div id="boards" hidden></div>
|
|
85
|
+
<div id="usage" hidden></div>
|
|
86
|
+
<div id="team" hidden></div>
|
|
87
|
+
<div id="newteam" hidden></div>
|
|
88
|
+
<div id="addmachine" hidden></div>
|
|
89
|
+
<div id="mosaic" hidden></div>
|
|
90
|
+
<div id="archived" hidden></div>
|
|
91
|
+
<div id="inbox" hidden></div>
|
|
92
|
+
<div id="org" hidden></div>
|
|
93
|
+
<div id="session" class="full" hidden></div>
|
|
94
|
+
<div id="hosts" hidden></div>
|
|
95
|
+
<div id="terminal" hidden></div>
|
|
96
|
+
</main>
|
|
97
|
+
<nav class="tabbar" id="tabbar"></nav>
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
<div id="settings" hidden></div>
|
|
101
|
+
<div id="palette" hidden></div>
|
|
102
|
+
|
|
103
|
+
<script type="module" src="/ui/app.js"></script>
|
|
104
|
+
</body>
|
|
105
|
+
</html>
|
package/ui/machines.js
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { inCompany } from './api.js'
|
|
2
|
+
import { $ } from './dom.js'
|
|
3
|
+
import { T, COLLATOR } from './i18n.js'
|
|
4
|
+
import { sessions, hosts, state, can } from './state.js'
|
|
5
|
+
import { esc, dur, now } from './format.js'
|
|
6
|
+
import { status, agentMark } from './content.js'
|
|
7
|
+
import { setHtml } from './nav.js'
|
|
8
|
+
import { currentRoute } from './router.js'
|
|
9
|
+
import { sessionOn, personaTag } from './topbar.js'
|
|
10
|
+
import { closeMenu, dialog, confirmDialog } from './dialogs.js'
|
|
11
|
+
import { icon } from './icons.js'
|
|
12
|
+
import { newSessionDialog, templatesDialog } from './squads.js'
|
|
13
|
+
import { showLogin, serverVersion, olderThan } from './app.js'
|
|
14
|
+
|
|
15
|
+
// machines (pisha-host): list, add, rename, disconnect, open and close sessions
|
|
16
|
+
|
|
17
|
+
// The machine where a session runs, if it was opened from here.
|
|
18
|
+
// Only on the machine the server opened it on (host_id): another machine
|
|
19
|
+
// claiming a session with the same name never gets its terminal button.
|
|
20
|
+
export function terminalOf(name) {
|
|
21
|
+
const owner = sessions.get(name)?.host_id
|
|
22
|
+
if (!owner) return null
|
|
23
|
+
const h = hosts.get(owner)
|
|
24
|
+
const t = h?.online && h.info?.terminals?.find(x => x.id === name)
|
|
25
|
+
return t ? { host: h, term: t } : null
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function postJson(path, body) {
|
|
29
|
+
const r = await fetch(inCompany(path), {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
headers: { 'Content-Type': 'application/json' },
|
|
32
|
+
body: JSON.stringify(body),
|
|
33
|
+
})
|
|
34
|
+
if (r.status === 401) { showLogin(T.sessionEnded); throw new Error(T.unauthorized) }
|
|
35
|
+
const j = await r.json()
|
|
36
|
+
if (!j.ok) {
|
|
37
|
+
const why = j.description.replace(/^(Bad Request|Conflict|Forbidden): /, '')
|
|
38
|
+
// (A machine's own words are said to be its own, never the dashboard's.)
|
|
39
|
+
const r = j.parameters?.reason
|
|
40
|
+
const err = new Error(r === 'name_in_use' ? T.nameTaken(body?.spec?.name ?? '') : r === 'open_on_host' ? T.openOnHost(body?.spec?.name ?? '') : r === 'machine_refused' ? `${T.machineSays}: «${why}»` : why)
|
|
41
|
+
err.reason = r
|
|
42
|
+
throw err
|
|
43
|
+
}
|
|
44
|
+
return j.result
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function hostLine(h) {
|
|
48
|
+
const i = h.info ?? {}
|
|
49
|
+
return [i.hostname && i.hostname !== h.name ? i.hostname : '', [i.platform, i.arch].filter(Boolean).join(' '), i.claude ? `Claude ${i.claude.replace(/\s*\(Claude Code\)/, '')}` : '', i.tmux, i.version ? `host v${i.version}` : ''].filter(Boolean).join(' · ')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// A machine's allowed folders: removable, and one more can be added, when
|
|
53
|
+
// the machine lets the dashboard change them (pisha-host 0.0.3+).
|
|
54
|
+
export function folderChips(h) {
|
|
55
|
+
const i = h.info ?? {}
|
|
56
|
+
const editable = h.online && i.folders_from_dashboard === true
|
|
57
|
+
const chips = (i.folders ?? []).map(f => {
|
|
58
|
+
const home = i.home && f === i.home
|
|
59
|
+
return `<span class="fchip ${home ? 'home' : ''}" title="${esc(home ? T.homeFolder : f)}"><code>${home ? '' : ''}${esc(f)}</code>${editable ? `<button type="button" data-hact="rmfolder" data-h="${esc(h.id)}" data-f="${esc(f)}" title="${esc(T.removeFolder(f))}" aria-label="${esc(T.removeFolder(f))}">✕</button>` : ''}</span>`
|
|
60
|
+
}).join(' ')
|
|
61
|
+
return `${chips || T.noFolders}${editable && can('manager') ? ` <button type="button" class="btn addf" data-hact="addfolder" data-h="${esc(h.id)}">${T.addFolder}</button>` : h.online && i.folders_from_dashboard === false && i.version ? ` <span class="t">· ${T.foldersLocal}</span>` : ''}`
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// What a machine runs, one thing a line: its name on the left, its version on the right.
|
|
65
|
+
function installed(h) {
|
|
66
|
+
const i = h.info ?? {}
|
|
67
|
+
const rows = [
|
|
68
|
+
['pisha-host', i.version ? `v${i.version}` : ''],
|
|
69
|
+
[T.mcPlugin, i.plugin?.installed ? (i.plugin.version ? `v${i.plugin.version}` : T.mcYes) : ''],
|
|
70
|
+
['Claude', i.claude ? i.claude.replace(/\s*\(Claude Code\)/, '') : ''],
|
|
71
|
+
['tmux', i.tmux ? String(i.tmux).replace(/^tmux\s*/i, '') : ''],
|
|
72
|
+
[T.mcSystem, [i.platform, i.arch].filter(Boolean).join(' ')],
|
|
73
|
+
[T.mcHostname, i.hostname && i.hostname !== h.name ? i.hostname : ''],
|
|
74
|
+
].filter(r => r[1])
|
|
75
|
+
return rows.length ? `<dl class="hi-dl">${rows.map(([k, v]) => `<dt>${esc(k)}</dt><dd>${esc(v)}</dd>`).join('')}</dl>` : '—'
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Its folders, one a line (removable when the dashboard may change them;
|
|
79
|
+
// one more is added from its More menu).
|
|
80
|
+
function folderList(h) {
|
|
81
|
+
const i = h.info ?? {}
|
|
82
|
+
const editable = h.online && i.folders_from_dashboard === true && can('manager')
|
|
83
|
+
const rows = (i.folders ?? []).map(f => {
|
|
84
|
+
const home = i.home && f === i.home
|
|
85
|
+
return `<li class="fchip${home ? ' home' : ''}" title="${esc(home ? T.homeFolder : f)}"><code>${esc(f)}</code>${editable ? `<button type="button" data-hact="rmfolder" data-h="${esc(h.id)}" data-f="${esc(f)}" title="${esc(T.removeFolder(f))}" aria-label="${esc(T.removeFolder(f))}">✕</button>` : ''}</li>`
|
|
86
|
+
}).join('')
|
|
87
|
+
const local = h.online && i.folders_from_dashboard === false && i.version ? `<div class="t">${T.foldersLocal}</div>` : ''
|
|
88
|
+
return `${rows ? `<ul class="hi-folders">${rows}</ul>` : esc(T.noFolders)}${local}`
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// One part of what a machine says of itself (what it runs, its folders, its
|
|
92
|
+
// limits): its icon, named for screen readers, then the part, and anything to
|
|
93
|
+
// do about it in a note below.
|
|
94
|
+
function infoRow(ic, label, html, notes = []) {
|
|
95
|
+
return `<div class="hi-row"><span class="hi-ic" title="${esc(label)}">${icon(ic)}<span class="sr-only">${esc(label)}</span></span><div class="hi-b"><div class="hi-t">${html}</div>${notes.filter(Boolean).map(n => `<div class="plugin-missing">${n}</div>`).join('')}</div></div>`
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Connected, disconnected, or enrolled and never connected yet.
|
|
99
|
+
export function hostState(h) {
|
|
100
|
+
if (h.online) return T.hostOnline
|
|
101
|
+
if (h.pending) return T.hostPending(h.created_at ? dur(now() - h.created_at) : '—')
|
|
102
|
+
return T.hostOffline(h.last_seen_at ? dur(now() - h.last_seen_at) : '—')
|
|
103
|
+
}
|
|
104
|
+
// How the machines are, all at once: one row each, what needs doing marked.
|
|
105
|
+
function overview(all) {
|
|
106
|
+
const rows = all.map(h => {
|
|
107
|
+
const i = h.info ?? {}
|
|
108
|
+
const old = i.version && serverVersion && olderThan(i.version, serverVersion)
|
|
109
|
+
const n = (i.terminals ?? []).length
|
|
110
|
+
return `<tr><td><a class="mc-name" href="#/h/${encodeURIComponent(h.id)}">${esc(h.name)}</a></td>
|
|
111
|
+
<td><span class="mc-state"><span class="dot ${h.online ? 'ok' : h.pending ? 'off' : 'err'}" aria-hidden="true"></span>${esc(hostState(h))}</span></td>
|
|
112
|
+
<td class="mc-num">${h.online ? n : '—'}</td>
|
|
113
|
+
<td class="mc-mono">${esc((i.folders ?? []).join(', ') || '—')}</td>
|
|
114
|
+
<td>${old ? `<span class="tag warn">${esc(T.mcUpdate(i.version))}</span>` : `<span class="mc-quiet">${esc(i.version ?? '—')}</span>`}</td></tr>`
|
|
115
|
+
}).join('')
|
|
116
|
+
return `<section class="card mc-card"><div class="mc-scroll"><table class="mc-table"><thead><tr><th scope="col">${esc(T.mcMachine)}</th><th scope="col">${esc(T.mcState)}</th><th scope="col">${esc(T.mcSessions)}</th><th scope="col">${esc(T.folders)}</th><th scope="col">${esc(T.mcVersion)}</th></tr></thead><tbody>${rows}</tbody></table></div></section>`
|
|
117
|
+
}
|
|
118
|
+
// A machine that stopped answering while sessions were open on it: what to check there.
|
|
119
|
+
function trouble(h) {
|
|
120
|
+
const cmd = state.company && state.company !== 'default' ? `pisha-host-${state.company} status` : 'pisha-host status'
|
|
121
|
+
return `<section class="card mc-trouble"><h2>${esc(T.mcNotAnswering(h.name))}</h2><p>${esc(T.mcNotAnsweringHint)}</p>
|
|
122
|
+
<div class="cmdrow"><pre class="cmd">${esc(cmd)}</pre><button type="button" class="btn" data-copy>${esc(T.copy)}</button></div></section>`
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function renderHosts(only) {
|
|
126
|
+
const all = [...hosts.values()].sort((a, b) => (b.online - a.online) || COLLATOR.compare(a.name, b.name))
|
|
127
|
+
const list = all.filter(h => !only || h.id === only)
|
|
128
|
+
if (!list.length) {
|
|
129
|
+
setHtml($('hosts'), only && hosts.size
|
|
130
|
+
? `<div class="empty"><b>${esc(T.machineNotFound)}</b><a class="btn" href="#/hosts">${esc(T.allMachines)}</a></div>`
|
|
131
|
+
: `<div class="empty">${icon('machines', 'empty-ic')}<b>${esc(T.noMachines)}</b><span>${esc(T.mcEmptyHint)}</span>${can('manager') ? `<a class="btn primary" href="#/hosts/new">${esc(T.addMachine)}</a>` : ''}</div>`)
|
|
132
|
+
return
|
|
133
|
+
}
|
|
134
|
+
const stuck = list.filter(h => !h.online && !h.pending && [...sessions.values()].some(x => x.host_id === h.id && !x.archived_at && !x.deleted))
|
|
135
|
+
setHtml($('hosts'), `<div class="host-list">${only ? '' : overview(all)}${stuck.map(trouble).join('')}${list.map(h => {
|
|
136
|
+
const i = h.info ?? {}
|
|
137
|
+
const terms = i.terminals ?? []
|
|
138
|
+
const rows = terms.map(t => {
|
|
139
|
+
const s = sessionOn(h.id, t.id)
|
|
140
|
+
return `<div class="term-row">
|
|
141
|
+
<span class="role ${t.role === 'coordinator' ? 'coord' : t.role === 'solo' ? 'solo' : 'worker'}" aria-hidden="true"></span>${agentMark(sessions.get(t.id) ?? t)}<span class="sr-only">${esc(T.roleName[t.role] ?? '')}</span><span class="n">${esc(t.name)}</span><span class="dot ${s ? status(s).dot || 'off' : 'off'}" title="${esc(s ? status(s).text : '')}" aria-hidden="true"></span>${personaTag(t.persona)}
|
|
142
|
+
<span class="m" title="${esc(t.folder ?? '')}">${esc(t.folder ?? '')}${t.role === 'worker' && t.coordinator ? ` · ${esc(T.coordinatorOf(t.coordinator))}` : ''}</span>
|
|
143
|
+
<span class="acts">
|
|
144
|
+
${h.online && can('operator') ? `<button class="btn" data-go="#/t/${encodeURIComponent(h.id)}/${encodeURIComponent(t.id)}">${T.terminal}</button>` : ''}
|
|
145
|
+
${s ? `<button class="btn" data-go="#/s/${encodeURIComponent(t.id)}/chat">${T.chat}</button>` : ''}
|
|
146
|
+
${h.online && can('operator') ? `<button class="btn danger" data-hact="kill" data-h="${esc(h.id)}" data-t="${esc(t.id)}">${T.closeSession}</button>` : ''}
|
|
147
|
+
</span></div>`
|
|
148
|
+
}).join('')
|
|
149
|
+
return `<div class="host ${h.online ? '' : 'offline'}">
|
|
150
|
+
<div class="host-head"><span class="dot ${h.online ? 'ok' : ''}"></span><span class="n">${esc(h.name)}</span><span class="st">${hostState(h)}</span>
|
|
151
|
+
<span class="acts">${h.online ? (can('operator') ? `<button class="btn" data-hact="new" data-h="${esc(h.id)}">${T.newSession}</button>` : '') : (can('manager') ? `<button class="btn danger" data-hact="disconnect" data-h="${esc(h.id)}">${T.disconnect}</button>` : '')}${can('manager') ? `<button class="btn quiet" data-hmenu="${esc(h.id)}" aria-haspopup="menu" aria-label="${esc(T.actions(h.name))}">${esc(T.svMoreShort)}</button>` : ''}</span></div>
|
|
152
|
+
${i.shares_user ? `<div class="host-warn">${esc(T.sharedUserWarn)}</div>` : ''}
|
|
153
|
+
<div class="host-info">${infoRow('package', T.mcInstalled, installed(h),
|
|
154
|
+
[i.version && serverVersion && olderThan(i.version, serverVersion) ? T.hostOld(esc(i.version), esc(serverVersion)) : '', i.plugin && !(i.plugin.installed && i.plugin.enabled) ? T.pluginMissing(!i.plugin.installed) : ''])}
|
|
155
|
+
${infoRow('folder', T.folders, folderList(h))}
|
|
156
|
+
${infoRow('sliders', T.mcLimits, [i.max_sessions ? T.maxSessions(i.max_sessions) : '', i.allow_input === false ? T.typingOff : T.typingOn].filter(Boolean).join(' · '))}</div>
|
|
157
|
+
<div class="host-terms">${rows || `<div class="host-empty">${T.noTerminals}</div>`}</div>
|
|
158
|
+
</div>`
|
|
159
|
+
}).join('')}</div>`)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
$('hosts').addEventListener('click', e => {
|
|
163
|
+
const copy = e.target.closest('[data-copy]')
|
|
164
|
+
if (copy) return navigator.clipboard?.writeText(copy.previousElementSibling.textContent)
|
|
165
|
+
const m = e.target.closest('[data-hmenu]')
|
|
166
|
+
if (m) return openHostMenu(m, m.dataset.hmenu)
|
|
167
|
+
const go = e.target.closest('[data-go]')
|
|
168
|
+
if (go) location.hash = go.dataset.go
|
|
169
|
+
const act = e.target.closest('[data-hact]')
|
|
170
|
+
if (act) hostAction(act.dataset.hact, act.dataset.h, act.dataset.t ?? act.dataset.f)
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
function openHostMenu(anchor, id) {
|
|
174
|
+
closeMenu()
|
|
175
|
+
const h = hosts.get(id)
|
|
176
|
+
if (!h) return
|
|
177
|
+
state.menuEl = document.createElement('div')
|
|
178
|
+
state.menuEl.className = 'menu'
|
|
179
|
+
// (Adding a folder too, when the machine lets the dashboard change them.)
|
|
180
|
+
const folders = h.online && h.info?.folders_from_dashboard === true ? `<button data-a="addfolder">${T.addFolder}</button>` : ''
|
|
181
|
+
state.menuEl.innerHTML = `${folders}<button data-a="rename">${T.rename}</button><button data-a="disconnect" class="danger">${T.disconnect}</button>`
|
|
182
|
+
document.body.appendChild(state.menuEl)
|
|
183
|
+
const r = anchor.getBoundingClientRect()
|
|
184
|
+
const w = state.menuEl.offsetWidth
|
|
185
|
+
state.menuEl.style.top = `${Math.min(r.bottom + 4, innerHeight - state.menuEl.offsetHeight - 8)}px`
|
|
186
|
+
state.menuEl.style.left = `${Math.max(8, Math.min(r.right - w, innerWidth - w - 8))}px`
|
|
187
|
+
state.menuEl.addEventListener('click', e => {
|
|
188
|
+
const b = e.target.closest('button')
|
|
189
|
+
if (!b) return
|
|
190
|
+
closeMenu()
|
|
191
|
+
hostAction(b.dataset.a, id)
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function hostAction(action, id, term, extra = term) {
|
|
196
|
+
const h = hosts.get(id)
|
|
197
|
+
if (action === 'add') return addMachineDialog()
|
|
198
|
+
if (action === 'new') return newSessionDialog(id)
|
|
199
|
+
if (action === 'templates') return templatesDialog()
|
|
200
|
+
if (action === 'rename' && h) {
|
|
201
|
+
const d = dialog(`<h3>${T.renameTitle}</h3><label class="field"><span>${T.name}</span><input type="text" maxlength="40" value="${esc(h.name)}"></label><div class="err" style="color:var(--err);font-size:13px;min-height:1.2em"></div>
|
|
202
|
+
<div class="actions"><button class="btn" data-cancel>${T.cancel}</button><button class="btn primary" data-ok>${T.save}</button></div>`)
|
|
203
|
+
const input = d.el.querySelector('input')
|
|
204
|
+
input.focus(); input.select()
|
|
205
|
+
const save = async () => {
|
|
206
|
+
try { await postJson('/api/hosts/rename', { host: id, name: input.value }); d.close() } catch (err) { d.el.querySelector('.err').textContent = err.message }
|
|
207
|
+
}
|
|
208
|
+
d.el.querySelector('[data-ok]').addEventListener('click', save)
|
|
209
|
+
input.addEventListener('keydown', e => { if (e.key === 'Enter') save() })
|
|
210
|
+
return
|
|
211
|
+
}
|
|
212
|
+
if (action === 'addfolder' && h) return addFolderDialog(id)
|
|
213
|
+
if (action === 'rmfolder' && h) {
|
|
214
|
+
return confirmDialog({ title: T.removeFolderTitle, text: T.removeFolderText(esc(extra)), confirm: T.stopAllowing, danger: true, run: () => postJson('/api/hosts/folders', { host: id, action: 'remove', path: extra }) })
|
|
215
|
+
}
|
|
216
|
+
if (action === 'disconnect' && h) {
|
|
217
|
+
return confirmDialog({ title: T.disconnectTitle(h.name), text: T.disconnectText(esc(h.name)), confirm: T.disconnect, danger: true, option: T.disconnectSessions, run: all => postJson('/api/hosts/remove', { host: id, disconnect_sessions: all === true }) })
|
|
218
|
+
}
|
|
219
|
+
if (action === 'kill') {
|
|
220
|
+
return confirmDialog({
|
|
221
|
+
title: T.closeSessionTitle(term), text: T.closeSessionText(esc(term), esc(h?.name ?? id)), confirm: T.closeSession, danger: true,
|
|
222
|
+
run: async () => {
|
|
223
|
+
await postJson('/api/terminals/kill', { host: id, term })
|
|
224
|
+
if (currentRoute().view === 'terminal') location.hash = '#/hosts'
|
|
225
|
+
},
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Allow one more folder on a machine: it checks the path against its own
|
|
231
|
+
// rules and says why when it can't be allowed. done(folder) after it is.
|
|
232
|
+
export function addFolderDialog(hostId, done) {
|
|
233
|
+
const h = hosts.get(hostId)
|
|
234
|
+
if (!h) return
|
|
235
|
+
const d = dialog(`<h3>${esc(T.addFolderTitle(h.name))}</h3><p>${T.addFolderText} ${T.addFolderHome}</p>
|
|
236
|
+
<label class="field"><span>${T.folderPath}</span><input type="text" maxlength="4096" placeholder="~/projects" autocomplete="off" spellcheck="false"></label>
|
|
237
|
+
<div class="err" style="color:var(--err);font-size:13px;min-height:1.2em"></div>
|
|
238
|
+
<div class="actions"><button class="btn" data-cancel>${T.cancel}</button><button class="btn primary" data-ok>${T.allow}</button></div>`)
|
|
239
|
+
const input = d.el.querySelector('input')
|
|
240
|
+
input.focus()
|
|
241
|
+
const ok = d.el.querySelector('[data-ok]')
|
|
242
|
+
const save = async () => {
|
|
243
|
+
const path = input.value.trim()
|
|
244
|
+
if (!path) return input.focus()
|
|
245
|
+
ok.disabled = true
|
|
246
|
+
try {
|
|
247
|
+
const r = await postJson('/api/hosts/folders', { host: hostId, action: 'add', path })
|
|
248
|
+
d.close()
|
|
249
|
+
// (The machine's list as it answered: shown now, before its next update arrives.)
|
|
250
|
+
const list = Array.isArray(r.folders) ? r.folders : null
|
|
251
|
+
const host = hosts.get(hostId)
|
|
252
|
+
if (host && list) host.info = { ...(host.info ?? {}), folders: list }
|
|
253
|
+
done?.(list?.[list.length - 1] ?? null)
|
|
254
|
+
} catch (err) { d.el.querySelector('.err').textContent = err.message.replace(/^Bad Request: /, ''); ok.disabled = false }
|
|
255
|
+
}
|
|
256
|
+
ok.addEventListener('click', save)
|
|
257
|
+
input.addEventListener('keydown', e => { if (e.key === 'Enter') save() })
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Adding a machine is a page of its own now (addmachine.js).
|
|
261
|
+
export const addMachineDialog = () => { location.hash = '#/hosts/new' }
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "/",
|
|
3
|
+
"name": "Pisha",
|
|
4
|
+
"short_name": "Pisha",
|
|
5
|
+
"description": "Teams of AI agents, run by a coordinator, with an inbox for your decisions.",
|
|
6
|
+
"start_url": "/",
|
|
7
|
+
"scope": "/",
|
|
8
|
+
"display": "standalone",
|
|
9
|
+
"background_color": "#f6f6f7",
|
|
10
|
+
"theme_color": "#f6f6f7",
|
|
11
|
+
"icons": [
|
|
12
|
+
{ "src": "/icons/icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any" },
|
|
13
|
+
{ "src": "/icons/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any" },
|
|
14
|
+
{ "src": "/icons/maskable-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" }
|
|
15
|
+
]
|
|
16
|
+
}
|
package/ui/mosaic.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { $ } from './dom.js'
|
|
2
|
+
import { T, LOCALE } from './i18n.js'
|
|
3
|
+
import { state, can } from './state.js'
|
|
4
|
+
import { esc, base, num, kfmt } from './format.js'
|
|
5
|
+
import { status, sortedSessions, squadsOf, agentMark } from './content.js'
|
|
6
|
+
import { ChatView } from './chat.js'
|
|
7
|
+
import { setHtml } from './nav.js'
|
|
8
|
+
import { currentRoute, clearMosaic, mosaicPanes, teamStrip, giveWork } from './router.js'
|
|
9
|
+
import { personaTag } from './topbar.js'
|
|
10
|
+
import { icon } from './icons.js'
|
|
11
|
+
import { openMenu, confirmDialog, runAction } from './dialogs.js'
|
|
12
|
+
import { terminalOf } from './machines.js'
|
|
13
|
+
import { addWorkerTo } from './squads.js'
|
|
14
|
+
import { TermView } from './terminal.js'
|
|
15
|
+
|
|
16
|
+
export function paneHead(s) {
|
|
17
|
+
const a = s.activity ?? {}
|
|
18
|
+
const role = s.role === 'coordinator' ? 'coord' : s.role === 'solo' ? 'solo' : 'worker'
|
|
19
|
+
return `<span class="role ${role}" aria-hidden="true"></span>${agentMark(s)}<span class="sr-only">${esc(T.roleName[s.role] ?? '')}</span><button class="title" data-go="#/s/${encodeURIComponent(s.name)}">${esc(s.name)}</button><span class="dot ${status(s).dot || 'off'}" title="${esc(status(s).text)}" aria-hidden="true"></span>${personaTag(s.persona)}
|
|
20
|
+
<span class="meta" title="${esc(a.cwd ?? '')}">${esc(base(a.cwd))}</span>${ctxBadge(a)}
|
|
21
|
+
<button class="icon-btn more" data-menu="${esc(s.name)}" title="${esc(T.actions(s.name))}" aria-label="${esc(T.actions(s.name))}" aria-haspopup="menu">${icon('more')}</button>`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Context gauge: tokens and % of the auto-compact point; amber from 60%, red from 80%.
|
|
25
|
+
function ctxBadge(a) {
|
|
26
|
+
if (!a.context_tokens) return ''
|
|
27
|
+
const pct = a.context_pct == null ? null : num(a.context_pct)
|
|
28
|
+
const cls = pct == null ? '' : pct >= 80 ? 'hot' : pct >= 60 ? 'warm' : ''
|
|
29
|
+
const title = pct != null ? T.contextTitle(pct, kfmt(a.context_tokens), kfmt(a.compact_at ?? 0)) : T.context(kfmt(a.context_tokens))
|
|
30
|
+
return `<span class="ctx ${cls}" title="${esc(title)}">${esc(kfmt(a.context_tokens))}${pct != null ? ` · ${esc(pct)}%` : ' tok'}</span>`
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function paneClass(s) {
|
|
34
|
+
const st = status(s)
|
|
35
|
+
return `pane ${s.role ?? ''} ${st.waiting ? 'attention' : ''} ${s.online ? '' : 'offline'}`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function applyCols() {
|
|
39
|
+
const box = $('mosaic')
|
|
40
|
+
box.classList.toggle('fixed', state.cols !== 'auto')
|
|
41
|
+
if (state.cols !== 'auto') box.style.setProperty('--cols', state.cols)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// A heading row per squad (all-sessions mosaic only), reused across rebuilds.
|
|
45
|
+
const squadRows = new Map() // key -> element
|
|
46
|
+
function squadRow(key, coord, workers) {
|
|
47
|
+
let el = squadRows.get(key)
|
|
48
|
+
if (!el) { el = document.createElement('div'); squadRows.set(key, el) }
|
|
49
|
+
if (!coord) {
|
|
50
|
+
el.className = 'squad-row orphans'
|
|
51
|
+
el.innerHTML = `<span class="n">${key === 'solos' ? T.standalone : T.noCoordinator}</span>`
|
|
52
|
+
return el
|
|
53
|
+
}
|
|
54
|
+
const on = workers.filter(w => w.online).length
|
|
55
|
+
el.className = 'squad-row'
|
|
56
|
+
// Rewritten only when something changed, so a click on its buttons is never lost.
|
|
57
|
+
const html = `<span class="dot ${status(coord).dot}"></span><span class="n">${esc(state.squadMeta.get(coord.name)?.title || coord.name)}</span><span class="m">${esc(T.squadCount(on, workers.length))}</span>
|
|
58
|
+
<span class="acts"><button class="btn" data-go="#/q/${encodeURIComponent(coord.name)}" title="${esc(T.viewSquadTitle(coord.name))}">${T.viewSquad}</button>${can('operator') ? `<button class="btn" data-addworker="${esc(coord.name)}" title="${esc(T.addWorkerTo(coord.name))}">${T.addWorker}</button>` : ''}</span>`
|
|
59
|
+
if (el.dataset.html !== html) { setHtml(el, html); el.dataset.html = html }
|
|
60
|
+
return el
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function buildMosaic() {
|
|
64
|
+
const box = $('mosaic')
|
|
65
|
+
const r = currentRoute()
|
|
66
|
+
// The coordinators view: each coordinator's terminal and its team.
|
|
67
|
+
const leads = r.view === 'leads'
|
|
68
|
+
const key = `${leads ? 'leads' : r.squad ? `q:${r.squad}` : 'all'}:${state.mosaicMode}`
|
|
69
|
+
if (state.mosaicKey !== key) { clearMosaic(); state.mosaicKey = key }
|
|
70
|
+
box.classList.toggle('terms', leads || state.mosaicMode === 'terms')
|
|
71
|
+
box.classList.toggle('leads', leads)
|
|
72
|
+
applyCols()
|
|
73
|
+
const squad = r.squad
|
|
74
|
+
const all = sortedSessions()
|
|
75
|
+
const list = leads ? all.filter(s => s.role === 'coordinator') : squad ? all.filter(s => s.name === squad || (s.role !== 'coordinator' && s.coordinator === squad)) : all
|
|
76
|
+
// The order on screen: in the full mosaic, each squad under its heading row.
|
|
77
|
+
const order = []
|
|
78
|
+
if (squad || leads) order.push(...list.map(s => ({ s })))
|
|
79
|
+
else {
|
|
80
|
+
const { squads, orphans, solos } = squadsOf(all)
|
|
81
|
+
for (const q of squads) order.push({ row: squadRow(`q:${q.coord.name}`, q.coord, q.workers) }, { s: q.coord }, ...q.workers.map(s => ({ s })))
|
|
82
|
+
if (orphans.length) order.push(...(squads.length ? [{ row: squadRow('orphans') }] : []), ...orphans.map(s => ({ s })))
|
|
83
|
+
if (solos.length) order.push({ row: squadRow('solos') }, ...solos.map(s => ({ s })))
|
|
84
|
+
}
|
|
85
|
+
const rowsUsed = new Set(order.filter(o => o.row).map(o => o.row))
|
|
86
|
+
for (const [k, el] of squadRows) if (!rowsUsed.has(el)) { el.remove(); squadRows.delete(k) }
|
|
87
|
+
// keep existing panes (and their scroll/history), add new, drop deleted
|
|
88
|
+
const visible = new Set(list.map(s => s.name))
|
|
89
|
+
for (const [name, p] of mosaicPanes) if (!visible.has(name)) { p.view.destroy(); p.pane.remove(); mosaicPanes.delete(name) }
|
|
90
|
+
if (!list.length) {
|
|
91
|
+
const arch = sortedSessions({ archived: true }).length
|
|
92
|
+
box.innerHTML = `<div class="mosaic-empty">${leads ? T.leadsEmpty : squad ? esc(T.squadEmpty(squad)) : T.mosaicEmpty(arch)}</div>`
|
|
93
|
+
squadRows.clear()
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
box.querySelector('.mosaic-empty')?.remove()
|
|
97
|
+
// Moving a node in the DOM resets its scroll: remember where each chat was.
|
|
98
|
+
const scroll = new Map([...mosaicPanes].filter(([, p]) => p.kind === 'chat').map(([n, p]) => [n, { bottom: p.view.atBottom(), top: p.view.scrollEl.scrollTop }]))
|
|
99
|
+
let prev = null
|
|
100
|
+
for (const { s, row } of order) {
|
|
101
|
+
if (row) {
|
|
102
|
+
const expected = prev ? prev.nextSibling : box.firstChild
|
|
103
|
+
if (expected !== row) box.insertBefore(row, expected)
|
|
104
|
+
prev = row
|
|
105
|
+
continue
|
|
106
|
+
}
|
|
107
|
+
let p = mosaicPanes.get(s.name)
|
|
108
|
+
// Its live terminal (sessions opened on a machine from here), or its chat.
|
|
109
|
+
const term = can('operator') && (leads || state.mosaicMode === 'terms') ? terminalOf(s.name) : null
|
|
110
|
+
const kind = term ? 'term' : 'chat'
|
|
111
|
+
if (p && p.kind !== kind) { p.view.destroy(); p.pane.remove(); mosaicPanes.delete(s.name); p = null }
|
|
112
|
+
if (!p) {
|
|
113
|
+
const pane = document.createElement('section')
|
|
114
|
+
pane.innerHTML = `<div class="pane-head"></div>`
|
|
115
|
+
let view
|
|
116
|
+
if (term) {
|
|
117
|
+
const body = document.createElement('div')
|
|
118
|
+
body.className = 'pane-term'
|
|
119
|
+
pane.appendChild(body)
|
|
120
|
+
view = new TermView(term.host.id, s.name, body, { compact: true })
|
|
121
|
+
} else {
|
|
122
|
+
view = new ChatView(s.name)
|
|
123
|
+
pane.appendChild(view.el)
|
|
124
|
+
}
|
|
125
|
+
if (leads) { const team = document.createElement('div'); team.className = 'team'; pane.appendChild(team) }
|
|
126
|
+
p = { pane, view, kind }
|
|
127
|
+
mosaicPanes.set(s.name, p)
|
|
128
|
+
}
|
|
129
|
+
p.pane.className = paneClass(s)
|
|
130
|
+
setHtml(p.pane.querySelector('.pane-head'), paneHead(s))
|
|
131
|
+
if (leads) setHtml(p.pane.querySelector('.team'), teamStrip(s))
|
|
132
|
+
// Only move panes that are out of order.
|
|
133
|
+
const expected = prev ? prev.nextSibling : box.firstChild
|
|
134
|
+
if (expected !== p.pane) box.insertBefore(p.pane, expected)
|
|
135
|
+
prev = p.pane
|
|
136
|
+
}
|
|
137
|
+
for (const [n, st] of scroll) {
|
|
138
|
+
const p = mosaicPanes.get(n)
|
|
139
|
+
if (!p) continue
|
|
140
|
+
if (st.bottom) p.view.toBottom(); else p.view.scrollEl.scrollTop = st.top
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Counts and dots in the squad headings, without rebuilding the mosaic.
|
|
145
|
+
export function refreshSquadRows() {
|
|
146
|
+
if (!squadRows.size) return
|
|
147
|
+
const { squads } = squadsOf(sortedSessions())
|
|
148
|
+
for (const q of squads) if (squadRows.has(`q:${q.coord.name}`)) squadRow(`q:${q.coord.name}`, q.coord, q.workers)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
$('mosaic').addEventListener('click', e => {
|
|
152
|
+
const gw = e.target.closest('[data-givework]')
|
|
153
|
+
if (gw) return giveWork(gw.dataset.givework)
|
|
154
|
+
const aw = e.target.closest('[data-addworker]')
|
|
155
|
+
if (aw) return addWorkerTo(aw.dataset.addworker)
|
|
156
|
+
const m = e.target.closest('[data-menu]')
|
|
157
|
+
if (m) return openMenu(m, m.dataset.menu)
|
|
158
|
+
const b = e.target.closest('[data-go]')
|
|
159
|
+
if (b) location.hash = b.dataset.go
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
// (Titled as a failure unless the caller says what it is.)
|
|
163
|
+
export function alertBox(text, title = T.couldNotComplete) {
|
|
164
|
+
confirmDialog({ title, text: esc(text), confirm: T.ok, notice: true, run: async () => {} })
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// archived view
|
|
168
|
+
export function renderArchived() {
|
|
169
|
+
const list = sortedSessions({ archived: true })
|
|
170
|
+
setHtml($('archived'), `<div class="arch-list">${list.length ? list.map(s => `
|
|
171
|
+
<div class="arch ${s.role ?? ''}">
|
|
172
|
+
<div class="info">
|
|
173
|
+
<div class="n"><span class="role ${s.role === 'coordinator' ? 'coord' : s.role === 'solo' ? 'solo' : 'worker'}" aria-hidden="true"></span>${agentMark(s)}<span class="sr-only">${esc(T.roleName[s.role] ?? '')}</span><span class="arch-name">${esc(s.name)}</span></div>
|
|
174
|
+
<div class="m">${T.archivedAt(new Date(s.archived_at).toLocaleString(LOCALE))} · ${esc(status(s).text)}${s.activity?.cwd ? ` · ${esc(s.activity.cwd)}` : ''}</div>
|
|
175
|
+
</div>
|
|
176
|
+
<div class="acts">
|
|
177
|
+
<button class="btn" data-go="#/s/${encodeURIComponent(s.name)}">${T.viewChat}</button>
|
|
178
|
+
${can('operator') ? `<button class="btn" data-act="unarchive" data-s="${esc(s.name)}">${T.unarchive}</button>` : ''}
|
|
179
|
+
${can('manager') ? `<button class="btn danger" data-act="delete" data-s="${esc(s.name)}" ${s.online ? 'disabled' : ''}>${T.delete}</button>` : ''}
|
|
180
|
+
</div>
|
|
181
|
+
</div>`).join('') : `<div class="mosaic-empty">${T.noArchived}</div>`}</div>`)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
$('archived').addEventListener('click', e => {
|
|
185
|
+
const go = e.target.closest('[data-go]')
|
|
186
|
+
if (go) location.hash = go.dataset.go
|
|
187
|
+
const act = e.target.closest('[data-act]')
|
|
188
|
+
if (act && !act.disabled) runAction(act.dataset.act, act.dataset.s)
|
|
189
|
+
})
|