@oakgreencc/canopy 0.0.7 → 0.0.9
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/package.json +1 -1
- package/src/page.mjs +59 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oakgreencc/canopy",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "A local read-only page over cambium's heartbeat and the GitHub queues: mode, ticks, workers, events, and the q:* columns with agent PRs.",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"type": "module",
|
package/src/page.mjs
CHANGED
|
@@ -1,32 +1,39 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
3
|
const CSS = `
|
|
4
|
-
:root{color-scheme:light dark;--bg:#f7f7f5;--panel:#fff;--line:#e4e4e0;--text:#1d1d1b;--muted:#
|
|
5
|
-
--ok:#2f7d4f;--warn:#a5670a;--err:#b42f2f;--accent:#2f5f9e;--chip:#efefeb;--bar:#dcdcd6
|
|
6
|
-
|
|
4
|
+
:root{color-scheme:light dark;--bg:#f7f7f5;--panel:#fff;--line:#e4e4e0;--text:#1d1d1b;--muted:#5f5f5a;--faint:#72726c;
|
|
5
|
+
--ok:#2f7d4f;--warn:#a5670a;--err:#b42f2f;--accent:#2f5f9e;--chip:#efefeb;--bar:#dcdcd6;
|
|
6
|
+
--s1:4px;--s2:8px;--s3:12px;--s4:16px;--s5:24px}
|
|
7
|
+
@media (prefers-color-scheme:dark){:root{--bg:#141413;--panel:#1c1c1a;--line:#2e2e2b;--text:#e6e6e1;--muted:#b0b0aa;--faint:#8a8a84;
|
|
7
8
|
--ok:#6cc08b;--warn:#e0a44a;--err:#ec7b7b;--accent:#86aee6;--chip:#262624;--bar:#353532}}
|
|
8
9
|
*{box-sizing:border-box}
|
|
9
10
|
body{margin:0;background:var(--bg);color:var(--text);font:13px/1.45 system-ui,-apple-system,"Segoe UI",sans-serif;font-variant-numeric:tabular-nums}
|
|
10
|
-
|
|
11
|
+
::selection{background:color-mix(in srgb,var(--accent) 28%,transparent)}
|
|
12
|
+
a{color:var(--accent);text-decoration:none;text-underline-offset:2px}a:hover{text-decoration:underline}
|
|
13
|
+
a:focus-visible{outline:2px solid var(--accent);outline-offset:2px;border-radius:2px}
|
|
11
14
|
code,.mono{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px}
|
|
12
|
-
|
|
15
|
+
#top{position:sticky;top:0;z-index:1}
|
|
16
|
+
header{display:flex;flex-wrap:wrap;align-items:baseline;gap:6px var(--s4);padding:10px var(--s4);border-bottom:1px solid var(--line);background:var(--panel)}
|
|
13
17
|
header h1{font-size:14px;margin:0;font-weight:600}
|
|
14
|
-
main{padding:
|
|
15
|
-
section{background:var(--panel);border:1px solid var(--line);border-radius:6px;padding:
|
|
16
|
-
|
|
18
|
+
main{padding:var(--s4) var(--s4) var(--s5);display:grid;gap:var(--s4);max-width:1600px}
|
|
19
|
+
section{background:var(--panel);border:1px solid var(--line);border-radius:6px;padding:var(--s3) var(--s4);min-width:0}
|
|
20
|
+
section.attn{border-color:color-mix(in srgb,var(--warn) 45%,var(--line))}section.attn>h2 .n{color:var(--warn)}
|
|
21
|
+
h2{font-size:11px;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);margin:0 0 var(--s2);font-weight:600}
|
|
17
22
|
h2 .n{color:var(--faint);margin-left:4px}
|
|
18
23
|
.muted{color:var(--muted)}.faint{color:var(--faint)}.ok{color:var(--ok)}.warn{color:var(--warn)}.err{color:var(--err)}
|
|
19
24
|
.pill{display:inline-block;padding:0 7px;border-radius:9px;background:var(--chip);font-size:12px}
|
|
20
25
|
.pill.ok{background:color-mix(in srgb,var(--ok) 16%,transparent)}.pill.warn{background:color-mix(in srgb,var(--warn) 18%,transparent)}
|
|
21
|
-
.pill.err{background:color-mix(in srgb,var(--err) 16%,transparent)}
|
|
22
|
-
.banner{padding:
|
|
26
|
+
.pill.err{background:color-mix(in srgb,var(--err) 16%,transparent)}.pill .faint{color:var(--muted)}
|
|
27
|
+
.banner{padding:var(--s2) var(--s3);border-radius:6px;border:1px solid var(--line);background:var(--panel)}
|
|
23
28
|
.banner.err{border-color:color-mix(in srgb,var(--err) 45%,var(--line))}.banner.warn{border-color:color-mix(in srgb,var(--warn) 45%,var(--line))}
|
|
24
|
-
.
|
|
25
|
-
.
|
|
26
|
-
.
|
|
27
|
-
.
|
|
29
|
+
.top{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,360px),1fr));gap:var(--s4)}
|
|
30
|
+
.detail{display:grid;grid-template-columns:minmax(0,3fr) minmax(0,2fr);gap:var(--s4);align-items:start}
|
|
31
|
+
.stats{display:flex;flex-wrap:wrap;gap:var(--s1) var(--s4);margin-top:var(--s3);padding-top:var(--s3);border-top:1px solid var(--line)}.stat b{font-size:16px;font-weight:600;margin-right:var(--s1)}
|
|
32
|
+
.steps{display:flex;flex-wrap:wrap;gap:var(--s1)}.steps+.err{margin-top:var(--s1)}
|
|
33
|
+
.cols{display:grid;grid-template-columns:repeat(4,minmax(0,1fr)) minmax(0,1.35fr);gap:var(--s4)}
|
|
34
|
+
.col.prs{border-left:1px solid var(--line);padding-left:var(--s4)}
|
|
28
35
|
.col{min-width:0}.col ul{list-style:none;margin:0;padding:0}
|
|
29
|
-
.col li{padding:
|
|
36
|
+
.col li{padding:6px 0;border-top:1px solid var(--line)}.col li:first-child{border-top:0}
|
|
30
37
|
.t{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
31
38
|
.meta{font-size:12px;color:var(--muted);display:flex;flex-wrap:wrap;gap:2px 8px}
|
|
32
39
|
.empty{color:var(--faint);font-size:12px}
|
|
@@ -34,11 +41,16 @@ table{border-collapse:collapse;width:100%}th{text-align:left;font-weight:500;col
|
|
|
34
41
|
td,th{padding:4px 10px 4px 0;border-top:1px solid var(--line);vertical-align:top;white-space:nowrap}tr.logs td{border-top:0;padding-top:0;white-space:normal;overflow-wrap:anywhere}.scroll{overflow-x:auto}thead th{border-top:0}
|
|
35
42
|
.bar{display:inline-block;width:80px;height:6px;background:var(--bar);border-radius:3px;vertical-align:middle;overflow:hidden;margin-right:6px}
|
|
36
43
|
.bar i{display:block;height:100%;background:var(--ok)}.bar i.warn{background:var(--warn)}.bar i.err{background:var(--err)}
|
|
44
|
+
.events,.scroll{scrollbar-width:thin;scrollbar-color:var(--bar) transparent}
|
|
45
|
+
.events:focus-visible,.scroll:focus-visible{outline:2px solid var(--accent);outline-offset:2px;border-radius:2px}
|
|
46
|
+
body.down #top,body.down main>:not(#down){opacity:.5;transition:opacity .3s ease-out}
|
|
37
47
|
.events{max-height:320px;overflow:auto}.events div{display:grid;grid-template-columns:62px 40px minmax(0,1fr);gap:8px;padding:2px 0}
|
|
38
48
|
.dot{display:inline-block;width:8px;height:8px;border-radius:50%;background:var(--faint);margin-right:5px}
|
|
39
49
|
.dot.ok{background:var(--ok)}.dot.warn{background:var(--warn)}.dot.err{background:var(--err)}
|
|
40
|
-
@media (max-width:1100px){.cols{grid-template-columns:repeat(
|
|
41
|
-
|
|
50
|
+
@media (max-width:1100px){.cols{grid-template-columns:repeat(4,minmax(0,1fr))}.detail{grid-template-columns:1fr}
|
|
51
|
+
.col.prs{grid-column:1/-1;border-left:0;padding-left:0;border-top:1px solid var(--line);padding-top:var(--s3)}}
|
|
52
|
+
@media (max-width:760px){.cols{grid-template-columns:repeat(2,minmax(0,1fr))}}
|
|
53
|
+
@media (max-width:480px){main{padding:var(--s3) var(--s3) var(--s5);gap:var(--s3)}section{padding:var(--s3)}.cols{grid-template-columns:1fr}}
|
|
42
54
|
`
|
|
43
55
|
|
|
44
56
|
const JS = `
|
|
@@ -73,9 +85,9 @@ function header(s, now) {
|
|
|
73
85
|
kids.push(h('span', { class: 'muted' }, d.host || '?', d.pid ? ' · pid ' + d.pid : ''))
|
|
74
86
|
kids.push(h('span', { class: hb.stale ? 'warn' : 'muted' }, 'tick ', d.tick.n ?? '–', ' · ', ago(d.tick.finishedAt, now), d.tick.durationMs != null ? ' · took ' + dur(d.tick.durationMs) : ''))
|
|
75
87
|
if (d.tick.nextAt && !hb.stale) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
88
|
+
const left = Date.parse(d.tick.nextAt) - now
|
|
89
|
+
kids.push(h('span', { class: 'faint' }, left > 0 ? 'next in ' + dur(left) : 'next tick due'))
|
|
90
|
+
}
|
|
79
91
|
}
|
|
80
92
|
const gh = s.github
|
|
81
93
|
kids.push(h('span', { class: 'faint', style: 'margin-left:auto' }, 'GitHub ', gh.fetchedAt ? ago(gh.fetchedAt, now) : '–', s.cacheMs ? ' (cached ' + dur(s.cacheMs) + ')' : ''))
|
|
@@ -103,7 +115,7 @@ function summary(d) {
|
|
|
103
115
|
const steps = h('div', { class: 'steps' }, d.steps.length ? d.steps.map((st) =>
|
|
104
116
|
h('span', { class: 'pill ' + (st.ok ? 'ok' : 'err'), title: st.error || '' }, st.name, ' ', h('span', { class: 'faint' }, st.ms != null ? st.ms + 'ms' : ''))) : h('span', { class: 'empty' }, 'no steps recorded'))
|
|
105
117
|
const errs = d.steps.filter((st) => !st.ok && st.error).map((st) => h('div', { class: 'err mono' }, st.name + ': ' + st.error))
|
|
106
|
-
return
|
|
118
|
+
return section('Last tick', null, steps, errs, stats)
|
|
107
119
|
}
|
|
108
120
|
|
|
109
121
|
function item(i, multi, now) {
|
|
@@ -129,13 +141,20 @@ function pr(p, multi, now) {
|
|
|
129
141
|
h('span', { class: 'faint mono' }, p.branch)))
|
|
130
142
|
}
|
|
131
143
|
|
|
144
|
+
const isMulti = (gh) => new Set(gh.repos.map((r) => r.slug)).size > 1
|
|
145
|
+
const list = (xs, render, multi, now) => xs.length ? h('ul', {}, xs.map((x) => render(x, multi, now))) : h('div', { class: 'empty' }, 'empty')
|
|
146
|
+
|
|
147
|
+
function human(s, now) {
|
|
148
|
+
const xs = s.github.columns.human
|
|
149
|
+
return h('section', { class: 'col' + (xs.length ? ' attn' : '') }, h('h2', {}, 'Human', h('span', { class: 'n' }, xs.length)), list(xs, item, isMulti(s.github), now))
|
|
150
|
+
}
|
|
151
|
+
|
|
132
152
|
function queues(s, now) {
|
|
133
|
-
const gh = s.github, multi =
|
|
134
|
-
const col = (title,
|
|
135
|
-
list.length ? h('ul', {}, list.map((x) => render(x, multi, now))) : h('div', { class: 'empty' }, 'empty'))
|
|
153
|
+
const gh = s.github, multi = isMulti(gh)
|
|
154
|
+
const col = (title, xs, render, cls) => h('div', { class: 'col' + (cls ? ' ' + cls : '') }, h('h2', {}, title, h('span', { class: 'n' }, xs.length)), list(xs, render, multi, now))
|
|
136
155
|
return h('section', {}, h('div', { class: 'cols' },
|
|
137
156
|
col('Intake', gh.columns.intake, item), col('Task', gh.columns.task, item), col('Running', gh.columns.running, item),
|
|
138
|
-
col('
|
|
157
|
+
col('Promote', gh.columns.promote, item), col('Agent PRs', gh.prs, pr, 'prs')))
|
|
139
158
|
}
|
|
140
159
|
|
|
141
160
|
function workers(d, ageMs) {
|
|
@@ -154,14 +173,14 @@ function workers(d, ageMs) {
|
|
|
154
173
|
h('td', { class: 'mono' }, w.branch || '–')),
|
|
155
174
|
logs.length ? h('tr', { class: 'logs' }, h('td', { colspan: 6, class: 'mono faint' }, logs.map((l) => h('div', {}, l)))) : null]
|
|
156
175
|
})
|
|
157
|
-
return section('Workers', d.workers.length, h('div', { class: 'scroll' }, h('table', {},
|
|
176
|
+
return section('Workers', d.workers.length, h('div', { class: 'scroll', tabindex: 0, 'aria-label': 'Workers table' }, h('table', {},
|
|
158
177
|
h('thead', {}, h('tr', {}, ['issue', 'phase', 'attempt', 'pid', 'elapsed / cap', 'branch'].map((t) => h('th', {}, t)))),
|
|
159
178
|
h('tbody', {}, rows))))
|
|
160
179
|
}
|
|
161
180
|
|
|
162
181
|
function events(d) {
|
|
163
182
|
const list = d.events.slice(-60).reverse()
|
|
164
|
-
return section('Recent events', d.events.length, list.length ? h('div', { class: 'events mono' }, list.map((e) => {
|
|
183
|
+
return section('Recent events', d.events.length, list.length ? h('div', { class: 'events mono', tabindex: 0, 'aria-label': 'Recent events' }, list.map((e) => {
|
|
165
184
|
const t = e.at ? new Date(e.at) : null
|
|
166
185
|
return h('div', {}, h('span', { class: 'faint', title: e.at || '' }, t ? t.toLocaleTimeString([], { hour12: false }) : '–'),
|
|
167
186
|
h('span', { class: e.level === 'error' ? 'err' : e.level === 'warn' ? 'warn' : 'faint' }, e.level || ''),
|
|
@@ -173,11 +192,20 @@ function render(s) {
|
|
|
173
192
|
const now = Date.parse(s.now) || Date.now()
|
|
174
193
|
const d = s.heartbeat.data
|
|
175
194
|
const body = [...banners(s)]
|
|
176
|
-
|
|
195
|
+
body.push(h('div', { class: 'top' }, human(s, now), d ? summary(d) : null))
|
|
177
196
|
body.push(queues(s, now))
|
|
178
|
-
if (d) body.push(h('div', { class: '
|
|
197
|
+
if (d) body.push(h('div', { class: 'detail' }, workers(d, s.heartbeat.ageMs), events(d)))
|
|
198
|
+
const focused = document.activeElement, href = focused && focused.getAttribute && focused.getAttribute('href')
|
|
199
|
+
const scrolled = [...document.querySelectorAll('.events,.scroll')].map((el) => [el.className, el.scrollTop, el.scrollLeft])
|
|
179
200
|
$('top').replaceChildren(header(s, now))
|
|
180
201
|
$('main').replaceChildren(...body)
|
|
202
|
+
document.body.classList.remove('down')
|
|
203
|
+
for (const [cls, top, left] of scrolled) {
|
|
204
|
+
const el = document.getElementsByClassName(cls)[0]
|
|
205
|
+
if (el) Object.assign(el, { scrollTop: top, scrollLeft: left })
|
|
206
|
+
}
|
|
207
|
+
if (href) [...document.querySelectorAll('a')].find((a) => a.getAttribute('href') === href)?.focus({ preventScroll: true })
|
|
208
|
+
else if (focused && focused.classList && (focused.classList.contains('events') || focused.classList.contains('scroll'))) document.getElementsByClassName(focused.className)[0]?.focus({ preventScroll: true })
|
|
181
209
|
document.title = 'canopy' + (d ? ' · ' + d.mode : '') + (s.heartbeat.stale ? ' · stale' : '')
|
|
182
210
|
}
|
|
183
211
|
|
|
@@ -191,6 +219,8 @@ async function poll() {
|
|
|
191
219
|
render(s)
|
|
192
220
|
} catch (err) {
|
|
193
221
|
$('down')?.remove()
|
|
222
|
+
document.body.classList.add('down')
|
|
223
|
+
document.title = 'canopy · unreachable'
|
|
194
224
|
$('main').prepend(h('div', { id: 'down', class: 'banner err' },'canopy server unreachable: ' + (err && err.message)))
|
|
195
225
|
}
|
|
196
226
|
setTimeout(poll, pollMs)
|