@jjanczur/tyran 0.1.18 → 0.1.20

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.
@@ -9,16 +9,22 @@ import { FORBIDDEN } from './invisible.mjs';
9
9
  * is blocked over file:// in Chromium, so meta-refresh is the one reliable
10
10
  * primitive; under `board.mjs --serve` the same refresh hits the server.
11
11
  *
12
- * ## Style: the landing page's system, not a new one
12
+ * ## Four tabs, because the page answers four questions
13
13
  *
14
- * Tokens are copied from `site/src/styles/landing.css` (operator-decided
15
- * 2026-08-14): the stone/gold/glow palette read off the banner, system font
16
- * stacks (no web fonts), dark only. The semantic mapping keeps the landing's
17
- * own rules — gold is the ONE accent, so it marks the operator's waiting
18
- * queue (the page's only call to action); the glow is a light source, so it
19
- * lights the agent strip (literally the cold light off the agents' screens);
20
- * red stays refusal (the PAUSED banner, the blocked lane); green stays the
21
- * ledger `+` (the done lane).
14
+ * Overview (what is the state), Board (where is every ticket), Waiting on you
15
+ * (what is blocked on a decision, and how to answer it), Spend (what it
16
+ * cost). They were competing for one scroll. The queue keeps its count in the
17
+ * tab label, so "something is waiting on me" survives being on another tab.
18
+ *
19
+ * ## Style: the landing page's system, muted
20
+ *
21
+ * Roles are the landing page's — one warm accent for the operator's call to
22
+ * action, a cool one for the agent strip, red for refusal, green for the
23
+ * ledger's `+`. The TONES are deliberately pulled back from the first
24
+ * version (operator-decided 2026-08-14: "a bit too flashy"), which filled
25
+ * whole bars and whole cards at full saturation. Saturation is now spent on
26
+ * text, edges and 3px rails; every large fill is a muted tone of the same
27
+ * hue. System font stacks, no web fonts, dark only.
22
28
  *
23
29
  * ## Safety
24
30
  *
@@ -36,77 +42,120 @@ import { FORBIDDEN } from './invisible.mjs';
36
42
 
37
43
  const CSS = `
38
44
  :root{
39
- --bg:#12100e;--bg-raised:#1c1917;--bg-sunken:#0d0c0a;
40
- --text:#d9d2c6;--heading:#f5efe3;--muted:#a29788;
41
- --hairline:#3b342c;--hairline-soft:#29241f;
42
- --gold:#d4a017;--gold-bright:#e8bc4d;--gold-low:#2a2110;
43
- --glow:#8fd8ea;--glow-dim:#1e3a44;
44
- --red:#f2665e;--red-low:#35191a;--green:#8fce6a;
45
+ /* Warm near-black ground, unchanged in role. The accents below are the
46
+ change: the first version filled whole bars and whole cards at full
47
+ saturation, which reads as an alarm rather than as information. Colour is
48
+ now spent on small things — text, edges, a 3px rail — and every large
49
+ fill drops to a muted tone of the same hue. */
50
+ --bg:#141210;--bg-raised:#1c1a16;--bg-sunken:#100e0c;
51
+ --text:#cec7ba;--heading:#ece5d7;--muted:#8f8779;
52
+ --hairline:#332e27;--hairline-soft:#26221d;
53
+ --brass:#a8863c;--brass-bright:#cfae63;--brass-low:#221c11;--brass-edge:#5d4c22;
54
+ --steel:#7d9ea9;--steel-bright:#9dbcc6;--steel-low:#17242a;--steel-edge:#3a545d;
55
+ --clay:#c07a70;--clay-low:#2a1a18;--sage:#88a06a;
45
56
  --display:ui-serif,'Iowan Old Style','Palatino Linotype',Palatino,'Book Antiqua',Georgia,'Times New Roman',serif;
46
57
  --font:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,sans-serif;
47
58
  --mono:ui-monospace,SFMono-Regular,'SF Mono',Menlo,Consolas,'Liberation Mono',monospace;
48
- --radius:0.75rem;color-scheme:dark;
59
+ --radius:0.6rem;color-scheme:dark;
49
60
  }
50
61
  *{box-sizing:border-box}
51
62
  body{margin:0;background:var(--bg);color:var(--text);font-family:var(--font);font-size:1rem;line-height:1.55;-webkit-font-smoothing:antialiased;padding:1.25rem}
52
- main{max-width:68rem;margin:0 auto}
53
- h1{font-family:var(--display);color:var(--heading);font-size:1.6rem;margin:0 0 .25rem}
54
- h2{font-family:var(--display);color:var(--heading);font-size:1.05rem;margin:1.5rem 0 .5rem;border-bottom:1px solid var(--hairline-soft);padding-bottom:.3rem}
55
- .meta{color:var(--muted);font-family:var(--mono);font-size:.8rem}
56
- .paused{background:var(--red-low);border:1px solid var(--red);color:var(--red);border-radius:var(--radius);padding:.6rem .9rem;margin:.9rem 0;font-weight:600}
57
- .ask{background:var(--gold-low);border:1px solid var(--gold);border-radius:var(--radius);padding:.7rem .9rem;margin:.5rem 0}
58
- .ask .q{color:var(--gold-bright);font-size:1.05rem;font-weight:600}
59
- .ask .row{margin-top:.25rem;font-size:.9rem}
60
- .ask .label{color:var(--muted);text-transform:uppercase;font-size:.7rem;letter-spacing:.06em;margin-right:.4rem}
61
- .agents{display:flex;flex-wrap:wrap;gap:.5rem}
62
- .agent{background:var(--bg-raised);border:1px solid var(--glow-dim);border-left:3px solid var(--glow);border-radius:var(--radius);padding:.45rem .7rem;font-family:var(--mono);font-size:.8rem;min-width:14rem}
63
- .agent .name{color:var(--glow);font-weight:600}
64
- .agent .age-fresh{color:var(--green)}
65
- .agent .age-warm{color:var(--gold-bright)}
66
- .agent .age-cold{color:var(--red)}
67
- .lanes{display:grid;grid-template-columns:repeat(auto-fill,minmax(15rem,1fr));gap:.7rem;align-items:start}
68
- .lane{background:var(--bg-sunken);border:1px solid var(--hairline-soft);border-radius:var(--radius);padding:.6rem}
69
- .lane h3{margin:0 0 .4rem;font-size:.8rem;color:var(--muted);text-transform:uppercase;letter-spacing:.06em}
70
- .lane h3 .count{color:var(--text)}
71
- .lane.blocked{border-color:var(--red)}
72
- .lane.blocked h3 .count{color:var(--red)}
73
- .lane.done h3 .count{color:var(--green)}
74
- .lane.waiting-operator{border-color:var(--gold-dim, #6d5410)}
75
- .card{background:var(--bg-raised);border:1px solid var(--hairline);border-radius:.5rem;padding:.4rem .55rem;margin:.3rem 0;font-size:.85rem}
63
+ main{max-width:70rem;margin:0 auto}
64
+ h1{font-family:var(--display);color:var(--heading);font-size:1.5rem;margin:0 0 .2rem;font-weight:600}
65
+ h2{font-family:var(--display);color:var(--heading);font-size:1.02rem;margin:1.4rem 0 .5rem;border-bottom:1px solid var(--hairline-soft);padding-bottom:.3rem;font-weight:600}
66
+ h3{font-family:var(--font);color:var(--heading);font-size:.85rem;margin:1.1rem 0 .2rem;font-weight:650}
67
+ .meta{color:var(--muted);font-family:var(--mono);font-size:.78rem}
68
+
69
+ /* ---- tabs ---- */
70
+ .tabs{display:flex;flex-wrap:wrap;gap:.3rem;margin:.9rem 0 1.1rem;border-bottom:1px solid var(--hairline);padding-bottom:.5rem;position:sticky;top:0;background:var(--bg);z-index:5}
71
+ .tabs button{font-family:var(--font);font-size:.82rem;font-weight:600;letter-spacing:.01em;background:transparent;color:var(--muted);border:1px solid transparent;border-radius:.4rem;padding:.34rem .8rem;cursor:pointer}
72
+ .tabs button:hover{color:var(--text);background:var(--bg-raised)}
73
+ .tabs button[aria-selected="true"]{color:var(--brass-bright);background:var(--brass-low);border-color:var(--brass-edge)}
74
+ .tabs button:focus-visible{outline:2px solid var(--steel);outline-offset:2px}
75
+ .tabs .count{font-family:var(--mono);font-size:.72rem;opacity:.85;margin-left:.3rem}
76
+ .panel[hidden]{display:none}
77
+ .hint{color:var(--muted);font-size:.82rem;margin:.2rem 0 .9rem;max-width:52rem}
78
+
79
+ /* ---- banners ---- */
80
+ .paused{background:var(--clay-low);border:1px solid var(--clay);border-left:3px solid var(--clay);color:var(--clay);border-radius:var(--radius);padding:.55rem .85rem;margin:.7rem 0;font-weight:600;font-size:.9rem}
81
+
82
+ /* ---- tiles ---- */
83
+ .tiles{display:grid;grid-template-columns:repeat(auto-fit,minmax(10.5rem,1fr));gap:.55rem;margin:.5rem 0 .2rem}
84
+ .stile{background:var(--bg-raised);border:1px solid var(--hairline);border-radius:.5rem;padding:.6rem .8rem}
85
+ .stile .lbl{display:block;font-family:var(--mono);font-size:.63rem;text-transform:uppercase;letter-spacing:.09em;color:var(--muted)}
86
+ .stile .big{display:block;font-family:var(--mono);font-size:1.3rem;color:var(--heading);font-variant-numeric:tabular-nums;line-height:1.3}
87
+ .stile .sub{display:block;font-family:var(--mono);font-size:.68rem;color:var(--muted)}
88
+ .stile.lead{border-color:var(--brass-edge)}
89
+ .stile.lead .big{color:var(--brass-bright)}
90
+ .stile.warn{border-color:var(--clay)}
91
+ .stile.warn .big{color:var(--clay)}
92
+
93
+ /* ---- agents ---- */
94
+ .agents{display:flex;flex-wrap:wrap;gap:.45rem}
95
+ .agent{background:var(--bg-raised);border:1px solid var(--hairline);border-left:3px solid var(--steel-edge);border-radius:.45rem;padding:.42rem .65rem;font-family:var(--mono);font-size:.76rem;min-width:15rem}
96
+ .agent .name{color:var(--steel-bright);font-weight:600}
97
+ .agent .age-fresh{color:var(--sage)}
98
+ .agent .age-warm{color:var(--brass-bright)}
99
+ .agent .age-cold{color:var(--clay)}
100
+
101
+ /* ---- lanes ---- */
102
+ .lanes{display:grid;grid-template-columns:repeat(auto-fill,minmax(15rem,1fr));gap:.6rem;align-items:start}
103
+ .lane{background:var(--bg-sunken);border:1px solid var(--hairline-soft);border-radius:var(--radius);padding:.55rem}
104
+ .lane h4{margin:0 0 .35rem;font-size:.7rem;color:var(--muted);text-transform:uppercase;letter-spacing:.08em;font-family:var(--font);font-weight:650}
105
+ .lane h4 .count{color:var(--text);font-family:var(--mono)}
106
+ .lane.blocked{border-color:var(--clay)}
107
+ .lane.blocked h4 .count{color:var(--clay)}
108
+ .lane.done h4 .count{color:var(--sage)}
109
+ .lane.waiting-operator{border-color:var(--brass-edge)}
110
+ .lane.waiting-operator h4 .count{color:var(--brass-bright)}
111
+ .card{background:var(--bg-raised);border:1px solid var(--hairline);border-radius:.4rem;padding:.38rem .5rem;margin:.28rem 0;font-size:.82rem;cursor:pointer;text-align:left;width:100%;font-family:var(--font);color:var(--text);display:block}
112
+ .card:hover{border-color:var(--steel-edge)}
113
+ .card[aria-pressed="true"]{border-color:var(--brass);background:var(--brass-low)}
114
+ .card:focus-visible{outline:2px solid var(--steel);outline-offset:1px}
76
115
  .card .id{font-family:var(--mono);color:var(--heading)}
77
- .card .init{font-family:var(--mono);color:var(--muted);font-size:.7rem}
78
- .card .note{color:var(--muted);font-size:.78rem;display:block}
79
- .empty{color:var(--hairline);font-size:.8rem}
80
- footer{margin-top:2rem;color:var(--muted);font-size:.75rem;border-top:1px solid var(--hairline-soft);padding-top:.6rem}
81
- .spend-head{display:flex;flex-wrap:wrap;align-items:baseline;gap:.8rem}
116
+ .card .init{font-family:var(--mono);color:var(--muted);font-size:.68rem}
117
+ .card .note{color:var(--muted);font-size:.74rem;display:block}
118
+ .empty{color:var(--hairline);font-size:.78rem}
119
+
120
+ /* ---- detail ---- */
121
+ .detail{background:var(--bg-raised);border:1px solid var(--hairline);border-left:3px solid var(--brass-edge);border-radius:var(--radius);padding:.8rem 1rem;margin:.9rem 0 0}
122
+ .detail .dt{font-family:var(--mono);color:var(--heading);font-size:.95rem}
123
+ .detail dl{display:grid;grid-template-columns:auto 1fr;gap:.2rem .8rem;margin:.5rem 0 0;font-size:.84rem}
124
+ .detail dt{font-family:var(--mono);font-size:.68rem;text-transform:uppercase;letter-spacing:.07em;color:var(--muted);padding-top:.16rem}
125
+ .detail dd{margin:0;color:var(--text)}
126
+
127
+ /* ---- questions ---- */
128
+ .ask{background:var(--brass-low);border:1px solid var(--brass-edge);border-left:3px solid var(--brass);border-radius:var(--radius);padding:.7rem .9rem;margin:.5rem 0}
129
+ .ask .q{color:var(--brass-bright);font-size:1rem;font-weight:600}
130
+ .ask .row{margin-top:.22rem;font-size:.86rem}
131
+ .ask .label{color:var(--muted);text-transform:uppercase;font-size:.66rem;letter-spacing:.07em;margin-right:.4rem;font-family:var(--mono)}
132
+ pre.how{background:var(--bg-sunken);border:1px solid var(--hairline);border-radius:.45rem;padding:.7rem .85rem;font-family:var(--mono);font-size:.76rem;color:var(--text);overflow-x:auto;margin:.4rem 0 .7rem}
133
+ pre.how .c{color:var(--muted)}
134
+
135
+ /* ---- spend ---- */
136
+ .spend-head{display:flex;flex-wrap:wrap;align-items:baseline;gap:.7rem}
82
137
  .toggle{display:flex;gap:.25rem;margin-left:auto}
83
- .toggle button{font-family:var(--mono);font-size:.7rem;letter-spacing:.06em;text-transform:uppercase;background:var(--bg-raised);color:var(--muted);border:1px solid var(--hairline);border-radius:.35rem;padding:.2rem .6rem;cursor:pointer}
84
- .toggle button[aria-pressed="true"]{background:var(--gold-low);border-color:var(--gold);color:var(--gold-bright)}
85
- .toggle button:focus-visible{outline:2px solid var(--glow);outline-offset:2px}
86
- .tiles{display:grid;grid-template-columns:repeat(auto-fit,minmax(11rem,1fr));gap:.6rem;margin:.6rem 0}
87
- .stile{background:var(--bg-raised);border:1px solid var(--hairline);border-radius:.55rem;padding:.6rem .8rem}
88
- .stile .lbl{display:block;font-family:var(--mono);font-size:.65rem;text-transform:uppercase;letter-spacing:.08em;color:var(--muted)}
89
- .stile .big{display:block;font-family:var(--mono);font-size:1.35rem;color:var(--heading);font-variant-numeric:tabular-nums;line-height:1.25}
90
- .stile .sub{display:block;font-family:var(--mono);font-size:.7rem;color:var(--muted)}
91
- .stile.gold{background:var(--gold-low);border-color:var(--gold)}
92
- .stile.gold .big{color:var(--gold-bright)}
93
- .comp{display:flex;height:1.5rem;border:1px solid var(--hairline);border-radius:.35rem;overflow:hidden}
94
- .comp span{display:flex;align-items:center;justify-content:center;font-family:var(--mono);font-size:.65rem;color:var(--bg);font-weight:700;white-space:nowrap;overflow:hidden}
95
- .comp .s-cache_read{background:var(--gold)}
96
- .comp .s-cache_write{background:var(--glow)}
97
- .comp .s-output{background:var(--green)}
138
+ .toggle button{font-family:var(--mono);font-size:.68rem;letter-spacing:.06em;text-transform:uppercase;background:var(--bg-raised);color:var(--muted);border:1px solid var(--hairline);border-radius:.3rem;padding:.18rem .55rem;cursor:pointer}
139
+ .toggle button[aria-pressed="true"]{background:var(--brass-low);border-color:var(--brass-edge);color:var(--brass-bright)}
140
+ .toggle button:focus-visible{outline:2px solid var(--steel);outline-offset:2px}
141
+ .comp{display:flex;height:1.35rem;border:1px solid var(--hairline);border-radius:.3rem;overflow:hidden;margin-top:.5rem}
142
+ .comp span{display:flex;align-items:center;justify-content:center;font-family:var(--mono);font-size:.63rem;color:var(--bg);font-weight:700;white-space:nowrap;overflow:hidden}
143
+ .comp .s-cache_read{background:var(--brass)}
144
+ .comp .s-cache_write{background:var(--steel)}
145
+ .comp .s-output{background:var(--sage)}
98
146
  .comp .s-input{background:var(--muted)}
99
- .compkey{display:flex;flex-wrap:wrap;gap:.9rem;font-family:var(--mono);font-size:.68rem;color:var(--muted);margin-top:.35rem}
100
- .compkey i{display:inline-block;width:.6rem;height:.6rem;border-radius:.15rem;margin-right:.3rem}
101
- .chart{display:flex;flex-direction:column;gap:.28rem;margin-top:.4rem}
102
- .chartrow{display:grid;grid-template-columns:minmax(7rem,14rem) 1fr auto;gap:.6rem;align-items:center;font-size:.8rem}
147
+ .compkey{display:flex;flex-wrap:wrap;gap:.85rem;font-family:var(--mono);font-size:.66rem;color:var(--muted);margin-top:.3rem}
148
+ .compkey i{display:inline-block;width:.55rem;height:.55rem;border-radius:.12rem;margin-right:.3rem}
149
+ .chart{display:flex;flex-direction:column;gap:.24rem;margin-top:.35rem}
150
+ .chartrow{display:grid;grid-template-columns:minmax(7rem,13rem) 1fr auto;gap:.55rem;align-items:center;font-size:.78rem}
103
151
  .chartrow .rl{font-family:var(--mono);color:var(--heading);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
104
- .chartrow .rb{background:var(--bg-sunken);border-radius:.25rem;height:.85rem;overflow:hidden}
105
- .chartrow .rb i{display:block;height:100%;background:var(--gold);border-radius:.25rem}
152
+ .chartrow .rb{background:var(--bg-sunken);border-radius:.2rem;height:.75rem;overflow:hidden}
153
+ .chartrow .rb i{display:block;height:100%;background:var(--brass);border-radius:.2rem;opacity:.85}
106
154
  .chartrow.dim .rl{color:var(--muted);font-style:italic}
107
155
  .chartrow.dim .rb i{background:var(--hairline)}
108
156
  .chartrow .rv{font-family:var(--mono);font-variant-numeric:tabular-nums;color:var(--text);min-width:5.5rem;text-align:right}
109
- .caveat{color:var(--muted);font-size:.78rem;margin-top:.5rem}
157
+ .caveat{color:var(--muted);font-size:.76rem;margin-top:.5rem;max-width:52rem}
158
+ footer{margin-top:2rem;color:var(--muted);font-size:.72rem;border-top:1px solid var(--hairline-soft);padding-top:.6rem}
110
159
  `;
111
160
 
112
161
  /**
@@ -146,75 +195,70 @@ if (data.schema !== 1) {
146
195
  if (text !== undefined && text !== null) node.textContent = show(text);
147
196
  return node;
148
197
  };
198
+ var clear = function (node) {
199
+ while (node.firstChild) node.removeChild(node.firstChild);
200
+ return node;
201
+ };
202
+
203
+ var totals = data.totals || {};
204
+ var asks = data.asks || [];
205
+ var agents = data.agents || [];
206
+ var lanes = data.lanes || {};
207
+ var errors = data.errors || [];
208
+ var cost = null;
209
+
149
210
  var app = document.getElementById('app');
150
211
  var head = el('div');
151
212
  head.appendChild(el('h1', null, 'Tyran board'));
152
- var totals = data.totals || {};
153
213
  head.appendChild(el('div', 'meta',
154
- (totals.agents || 0) + ' agent(s) running across ' + (totals.initiatives || 0) + ' initiative(s) · ' +
155
- (totals.merged || 0) + '/' + (totals.tickets || 0) + ' tickets merged (' + (totals.percent || 0) + '%) · as of ' + (data.as_of || 'unknown')));
214
+ (totals.initiatives || 0) + ' initiative(s) · ' + (totals.merged || 0) + '/' + (totals.tickets || 0) +
215
+ ' tickets merged (' + (totals.percent || 0) + '%) · as of ' + (data.as_of || 'unknown')));
156
216
  app.appendChild(head);
157
217
 
158
- (data.paused || []).forEach(function (p) {
159
- app.appendChild(el('div', 'paused', 'PAUSED — ' + p.init + ': gate ' + p.kind + ' (' + p.result + ') since ' + p.since));
160
- });
161
-
162
- var asks = data.asks || [];
163
- app.appendChild(el('h2', null, 'Waiting on you (' + asks.length + ')'));
164
- if (asks.length === 0) app.appendChild(el('div', 'empty', 'nothing — the agents have what they need'));
165
- asks.forEach(function (a) {
166
- var card = el('div', 'ask');
167
- card.appendChild(el('div', 'q', a.question || '(no question recorded — gate ' + a.kind + ')'));
168
- [['recommendation', a.recommendation], ['default', a.default],
169
- ['ticket', a.ticket], ['initiative', a.init], ['since', a.since]].forEach(function (pair) {
170
- if (pair[1] === null || pair[1] === undefined) return;
171
- var row = el('div', 'row');
172
- row.appendChild(el('span', 'label', pair[0]));
173
- row.appendChild(el('span', null, pair[1]));
174
- card.appendChild(row);
175
- });
176
- app.appendChild(card);
177
- });
178
-
179
- var agents = data.agents || [];
180
- app.appendChild(el('h2', null, 'Agents (' + agents.length + ')'));
181
- var strip = el('div', 'agents');
182
- if (agents.length === 0) strip.appendChild(el('div', 'empty', 'none running'));
183
- agents.forEach(function (a) {
184
- var chip = el('div', 'agent');
185
- chip.appendChild(el('div', 'name', a.agent + (a.role ? ' · ' + a.role : '')));
186
- chip.appendChild(el('div', null, (a.init ? a.init + ' · ' : '') + (a.ticket || 'no ticket') + ' · ' + a.state));
187
- if (a.detail) chip.appendChild(el('div', 'note', a.detail));
188
- var ageMs = a.last_signal ? Date.now() - Date.parse(a.last_signal) : null;
189
- var cls = ageMs === null ? 'age-cold' : ageMs < 600000 ? 'age-fresh' : ageMs < 1800000 ? 'age-warm' : 'age-cold';
190
- var ageText = ageMs === null ? 'no signal' : Math.round(ageMs / 60000) + ' min since last signal';
191
- chip.appendChild(el('div', cls, ageText));
192
- strip.appendChild(chip);
218
+ // ---- tabs -------------------------------------------------------------
219
+ // The board answers four different questions and they were competing for
220
+ // one scroll. Each gets a panel; the queue keeps its count in the tab, so
221
+ // "something is waiting on me" survives being on another tab.
222
+ var tabbar = el('div', 'tabs');
223
+ tabbar.setAttribute('role', 'tablist');
224
+ var panels = {};
225
+ var buttons = {};
226
+ var TABS = [
227
+ ['overview', 'Overview', null],
228
+ ['board', 'Board', null],
229
+ ['questions', 'Waiting on you', asks.length],
230
+ ['spend', 'Spend', null],
231
+ ];
232
+ var select = function (key) {
233
+ for (var i = 0; i < TABS.length; i += 1) {
234
+ var k = TABS[i][0];
235
+ var on = k === key;
236
+ buttons[k].setAttribute('aria-selected', on ? 'true' : 'false');
237
+ panels[k].hidden = !on;
238
+ }
239
+ };
240
+ TABS.forEach(function (spec) {
241
+ var b = el('button', null, spec[1]);
242
+ b.setAttribute('type', 'button');
243
+ b.setAttribute('role', 'tab');
244
+ if (spec[2] !== null && spec[2] !== undefined) b.appendChild(el('span', 'count', '(' + spec[2] + ')'));
245
+ b.addEventListener('click', function () { select(spec[0]); });
246
+ buttons[spec[0]] = b;
247
+ tabbar.appendChild(b);
248
+ var p = el('div', 'panel');
249
+ p.setAttribute('role', 'tabpanel');
250
+ panels[spec[0]] = p;
193
251
  });
194
- app.appendChild(strip);
252
+ app.appendChild(tabbar);
253
+ TABS.forEach(function (spec) { app.appendChild(panels[spec[0]]); });
195
254
 
196
- app.appendChild(el('h2', null, 'Lanes'));
197
- var lanesWrap = el('div', 'lanes');
198
- Object.keys(data.lanes || {}).forEach(function (lane) {
199
- var cards = data.lanes[lane];
200
- var box = el('div', 'lane ' + lane);
201
- var h = el('h3');
202
- h.appendChild(el('span', null, lane + ' '));
203
- h.appendChild(el('span', 'count', '(' + cards.length + ')'));
204
- box.appendChild(h);
205
- if (cards.length === 0) box.appendChild(el('div', 'empty', '—'));
206
- cards.forEach(function (c) {
207
- var card = el('div', 'card');
208
- card.appendChild(el('span', 'id', c.id));
209
- if (c.title) card.appendChild(el('span', null, ' — ' + c.title));
210
- if (c.init) card.appendChild(el('span', 'init', ' ' + c.init));
211
- if (c.agents && c.agents.length) card.appendChild(el('span', 'note', 'agents: ' + c.agents.join(', ')));
212
- if (c.annotation) card.appendChild(el('span', 'note', c.annotation));
213
- box.appendChild(card);
214
- });
215
- lanesWrap.appendChild(box);
216
- });
217
- app.appendChild(lanesWrap);
255
+ var tile = function (label, big, sub, cls) {
256
+ var box = el('div', cls ? 'stile ' + cls : 'stile');
257
+ box.appendChild(el('span', 'lbl', label));
258
+ box.appendChild(el('span', 'big', big));
259
+ box.appendChild(el('span', 'sub', sub));
260
+ return box;
261
+ };
218
262
 
219
263
  var fmtTokens = function (n) {
220
264
  if (n >= 1e9) return (n / 1e9).toFixed(2) + ' B';
@@ -222,33 +266,151 @@ if (data.schema !== 1) {
222
266
  if (n >= 1e3) return (n / 1e3).toFixed(1) + ' k';
223
267
  return String(n);
224
268
  };
225
- // An amount that rounds to nothing still cost something. Printing $0.00
226
- // there reads as free, which is the one reading that would change a
227
- // routing decision for the wrong reason.
269
+ // An amount that rounds to nothing still cost something; printing $0.00
270
+ // there reads as free.
228
271
  var fmtUsd = function (v) {
229
272
  if (v === null || v === undefined) return '—';
230
273
  if (v > 0 && v < 0.01) return '<$0.01';
231
274
  return '$' + v.toFixed(2);
232
275
  };
233
276
 
234
- var tile = function (label, big, sub, cls) {
235
- var box = el('div', cls ? 'stile ' + cls : 'stile');
236
- box.appendChild(el('span', 'lbl', label));
237
- box.appendChild(el('span', 'big', big));
238
- box.appendChild(el('span', 'sub', sub));
239
- return box;
277
+ var agentStrip = function () {
278
+ var strip = el('div', 'agents');
279
+ if (agents.length === 0) strip.appendChild(el('div', 'empty', 'none running'));
280
+ agents.forEach(function (a) {
281
+ var chip = el('div', 'agent');
282
+ chip.appendChild(el('div', 'name', a.agent + (a.role ? ' · ' + a.role : '')));
283
+ chip.appendChild(el('div', null, (a.init ? a.init + ' · ' : '') + (a.ticket || 'no ticket') + ' · ' + a.state));
284
+ if (a.detail) chip.appendChild(el('div', 'note', a.detail));
285
+ var ageMs = a.last_signal ? Date.now() - Date.parse(a.last_signal) : null;
286
+ var cls = ageMs === null ? 'age-cold' : ageMs < 600000 ? 'age-fresh' : ageMs < 1800000 ? 'age-warm' : 'age-cold';
287
+ var ageText = ageMs === null ? 'no signal' : Math.round(ageMs / 60000) + ' min since last signal';
288
+ chip.appendChild(el('div', cls, ageText));
289
+ strip.appendChild(chip);
290
+ });
291
+ return strip;
292
+ };
293
+
294
+ // ---- overview ---------------------------------------------------------
295
+ var ov = panels.overview;
296
+ (data.paused || []).forEach(function (p) {
297
+ ov.appendChild(el('div', 'paused', 'PAUSED — ' + p.init + ': gate ' + p.kind + ' (' + p.result + ') since ' + p.since));
298
+ });
299
+ var laneCount = function (name) { return (lanes[name] || []).length; };
300
+ var ovTiles = el('div', 'tiles');
301
+ ovTiles.appendChild(tile('waiting on you', String(asks.length),
302
+ asks.length === 0 ? 'nothing blocked on a decision' : 'answer them on the next tab', asks.length > 0 ? 'lead' : null));
303
+ ovTiles.appendChild(tile('agents running', String(agents.length), 'across ' + (totals.initiatives || 0) + ' initiative(s)'));
304
+ ovTiles.appendChild(tile('progress', (totals.percent || 0) + '%', (totals.merged || 0) + ' of ' + (totals.tickets || 0) + ' merged'));
305
+ var stuck = laneCount('blocked') + laneCount('changes-requested');
306
+ ovTiles.appendChild(tile('needs a human', String(stuck),
307
+ laneCount('blocked') + ' blocked · ' + laneCount('changes-requested') + ' changes requested', stuck > 0 ? 'warn' : null));
308
+ ov.appendChild(ovTiles);
309
+ ov.appendChild(el('h2', null, 'Agents'));
310
+ ov.appendChild(agentStrip());
311
+ var ovSpend = el('div');
312
+ ov.appendChild(ovSpend);
313
+
314
+ // An initiative the board could not read is the one thing this page must
315
+ // never omit: a missing card is indistinguishable from an initiative with
316
+ // no work, which is the "all is well" reading the board exists to prevent.
317
+ if (errors.length > 0) {
318
+ ov.appendChild(el('h2', null, 'Unreadable (' + errors.length + ')'));
319
+ errors.forEach(function (e) {
320
+ ov.appendChild(el('div', 'paused', 'UNREADABLE — ' + e.name + ': ' + e.error));
321
+ });
322
+ }
323
+
324
+ // ---- board ------------------------------------------------------------
325
+ var bd = panels.board;
326
+ bd.appendChild(el('div', 'hint', 'Every lane is derived from the journal — moving a ticket means appending an event, never editing this page. Select a card to see what the board knows about it.'));
327
+ var detail = el('div');
328
+ var selected = null;
329
+ var lanesWrap = el('div', 'lanes');
330
+ var showDetail = function (card, lane, button) {
331
+ if (selected) selected.setAttribute('aria-pressed', 'false');
332
+ selected = button;
333
+ button.setAttribute('aria-pressed', 'true');
334
+ clear(detail);
335
+ var box = el('div', 'detail');
336
+ box.appendChild(el('div', 'dt', card.id + (card.title ? ' — ' + card.title : '')));
337
+ var dl = el('dl');
338
+ var row = function (k, v) {
339
+ if (v === null || v === undefined || v === '') return;
340
+ dl.appendChild(el('dt', null, k));
341
+ dl.appendChild(el('dd', null, v));
342
+ };
343
+ row('lane', lane);
344
+ row('initiative', card.init);
345
+ row('agents', card.agents && card.agents.length ? card.agents.join(', ') : null);
346
+ row('note', card.annotation);
347
+ if (cost) {
348
+ var hit = (cost.by_ticket || []).filter(function (r) { return r.ticket === card.id; })[0];
349
+ if (hit) row('spend', fmtTokens(hit.tokens) + ' tokens · ' + fmtUsd(hit.usd));
350
+ }
351
+ box.appendChild(dl);
352
+ detail.appendChild(box);
240
353
  };
354
+ Object.keys(lanes).forEach(function (lane) {
355
+ var cards = lanes[lane];
356
+ var box = el('div', 'lane ' + lane);
357
+ var h = el('h4');
358
+ h.appendChild(el('span', null, lane));
359
+ h.appendChild(el('span', 'count', ' (' + cards.length + ')'));
360
+ box.appendChild(h);
361
+ if (cards.length === 0) box.appendChild(el('div', 'empty', '—'));
362
+ cards.forEach(function (c) {
363
+ var button = el('button', 'card');
364
+ button.setAttribute('type', 'button');
365
+ button.setAttribute('aria-pressed', 'false');
366
+ button.appendChild(el('span', 'id', c.id));
367
+ if (c.title) button.appendChild(el('span', null, ' — ' + c.title));
368
+ if (c.init) button.appendChild(el('span', 'init', ' ' + c.init));
369
+ if (c.agents && c.agents.length) button.appendChild(el('span', 'note', 'agents: ' + c.agents.join(', ')));
370
+ if (c.annotation) button.appendChild(el('span', 'note', c.annotation));
371
+ button.addEventListener('click', function () { showDetail(c, lane, button); });
372
+ box.appendChild(button);
373
+ });
374
+ lanesWrap.appendChild(box);
375
+ });
376
+ bd.appendChild(lanesWrap);
377
+ bd.appendChild(detail);
378
+
379
+ // ---- questions --------------------------------------------------------
380
+ var qs = panels.questions;
381
+ qs.appendChild(el('div', 'hint', 'Every question here is a gate in the journal, and it stays open until you close it. Blank takes the recorded default and is still written down as your decision; a single dash leaves it for next time.'));
382
+ var how = el('pre', 'how');
383
+ how.textContent =
384
+ 'npx @jjanczur/tyran answer render --dir .tyran # writes .tyran/state/ANSWERS.md\\n' +
385
+ '$EDITOR .tyran/state/ANSWERS.md # fill the answer: lines\\n' +
386
+ 'npx @jjanczur/tyran answer apply --dir .tyran # closes what you answered';
387
+ qs.appendChild(how);
388
+ if (asks.length === 0) qs.appendChild(el('div', 'empty', 'nothing — the agents have what they need'));
389
+ asks.forEach(function (a) {
390
+ var card = el('div', 'ask');
391
+ card.appendChild(el('div', 'q', a.question || '(no question recorded — gate ' + a.kind + ')'));
392
+ [['answer with', a.kind], ['recommendation', a.recommendation], ['default', a.default],
393
+ ['ticket', a.ticket], ['initiative', a.init], ['since', a.since]].forEach(function (pair) {
394
+ if (pair[1] === null || pair[1] === undefined) return;
395
+ var row = el('div', 'row');
396
+ row.appendChild(el('span', 'label', pair[0]));
397
+ row.appendChild(el('span', null, pair[1]));
398
+ card.appendChild(row);
399
+ });
400
+ qs.appendChild(card);
401
+ });
402
+
403
+ // ---- spend ------------------------------------------------------------
404
+ var sp = panels.spend;
405
+ var spBody = el('div');
406
+ sp.appendChild(spBody);
407
+ spBody.appendChild(el('div', 'hint', 'Spend is read from the transcripts Claude Code already writes, and it is served rather than embedded — open this board with "board.mjs --serve" to see it. Over file:// there is no server, so this tab stays empty.'));
241
408
 
242
- // One ranked bar chart. The bar is the comparison; the number beside it is
243
- // the fact. A row whose models have no rate shows no bar at all rather than
244
- // a zero-length one, because "not priced" and "cost nothing" must not look
245
- // the same.
246
409
  var chart = function (allRows, key, metric, dimKeys) {
247
410
  var box = el('div', 'chart');
248
- // Ranked by the metric on screen, not by the one the server happened to
249
- // sort by. In cost view a cheap-and-chatty row was being listed above an
250
- // expensive-and-terse one — the precise inversion of the routing signal
251
- // this view exists to give. Rows with no price sort last.
411
+ // Ranked by the metric on screen, not by the one the server sorted by:
412
+ // in cost view a cheap-and-chatty row above an expensive-and-terse one
413
+ // is the exact inversion of the signal this view exists to give.
252
414
  var valueOf = function (r) { return metric === 'usd' ? r.usd : r.tokens; };
253
415
  var rows = allRows.slice().sort(function (a, b) {
254
416
  var av = valueOf(a);
@@ -278,11 +440,10 @@ if (data.schema !== 1) {
278
440
  return box;
279
441
  };
280
442
 
281
- var renderSpend = function (into, cost, metric) {
282
- while (into.firstChild) into.removeChild(into.firstChild);
443
+ var renderSpend = function (into, metric) {
444
+ clear(into);
283
445
  var t = cost.totals || {};
284
446
  var cov = cost.coverage || {};
285
-
286
447
  var header = el('div', 'spend-head');
287
448
  header.appendChild(el('h2', null, 'Spend'));
288
449
  var toggle = el('div', 'toggle');
@@ -290,7 +451,7 @@ if (data.schema !== 1) {
290
451
  var button = el('button', null, pair[1]);
291
452
  button.setAttribute('type', 'button');
292
453
  button.setAttribute('aria-pressed', metric === pair[0] ? 'true' : 'false');
293
- button.addEventListener('click', function () { renderSpend(into, cost, pair[0]); });
454
+ button.addEventListener('click', function () { renderSpend(into, pair[0]); });
294
455
  toggle.appendChild(button);
295
456
  });
296
457
  header.appendChild(toggle);
@@ -298,18 +459,15 @@ if (data.schema !== 1) {
298
459
 
299
460
  var tiles = el('div', 'tiles');
300
461
  tiles.appendChild(tile('tokens', fmtTokens(t.tokens || 0), (t.requests || 0) + ' requests'));
301
- tiles.appendChild(tile(
302
- 'cost through the API', fmtUsd(t.usd),
303
- cost.rate_card ? 'rate card ' + cost.rate_card : 'no rate card set', 'gold'));
304
- tiles.appendChild(tile(
305
- 'conductor overhead', (t.conductor_token_share || 0) + '%', 'of tokens, no ticket'));
306
- tiles.appendChild(tile(
307
- 'attributed', (cov.attributed || 0) + ' / ' + (cov.agent_transcripts || 0),
462
+ tiles.appendChild(tile('cost through the API', fmtUsd(t.usd),
463
+ cost.rate_card ? 'rate card ' + cost.rate_card : 'no rate card set', 'lead'));
464
+ tiles.appendChild(tile('conductor overhead', (t.conductor_token_share || 0) + '%', 'of tokens, no ticket'));
465
+ tiles.appendChild(tile('attributed', (cov.attributed || 0) + ' / ' + (cov.agent_transcripts || 0),
308
466
  (cov.unattributed || 0) + ' agent(s) without a ticket'));
309
467
  into.appendChild(tiles);
310
468
 
311
- // The composition is the point of the whole section: cache reads dominate
312
- // the bill, so the lever is context size and turn count, not model price.
469
+ // The composition is the point of the whole tab: cache reads dominate the
470
+ // bill, so the lever is context size and turn count, not model price.
313
471
  var comp = (cost.composition || []).slice().sort(function (a, b) {
314
472
  return metric === 'usd' ? (b.usd || 0) - (a.usd || 0) : b.tokens - a.tokens;
315
473
  });
@@ -323,15 +481,12 @@ if (data.schema !== 1) {
323
481
  if (value <= 0) return;
324
482
  var pct = Math.round((value / compTotal) * 100);
325
483
  var seg = el('span', 's-' + c.kind, pct >= 8 ? pct + '%' : '');
326
- // Normalised to a share, not set to the raw value: flex-grow below 1
327
- // does not fill its container, and dollar amounts are routinely
328
- // fractions. Measured — the cost view drew a bar 13% of the width
329
- // while the token view, whose values are thousands, filled it.
484
+ // Normalised to a share: flex-grow below 1 does not fill its
485
+ // container, and dollar amounts are routinely fractions.
330
486
  seg.style.flex = String((value / compTotal) * 100);
331
487
  bar.appendChild(seg);
332
488
  var legend = el('span', null);
333
- var swatch = el('i', 's-' + c.kind);
334
- legend.appendChild(swatch);
489
+ legend.appendChild(el('i', 's-' + c.kind));
335
490
  legend.appendChild(el('span', null,
336
491
  c.kind.replace('_', ' ') + ' ' + (metric === 'usd' ? fmtUsd(c.usd) : fmtTokens(c.tokens))));
337
492
  key.appendChild(legend);
@@ -347,17 +502,13 @@ if (data.schema !== 1) {
347
502
  into.appendChild(chart(spec[1], spec[2], metric, spec[3]));
348
503
  });
349
504
 
350
- var notes = [];
351
- notes.push('Conductor context is not attributable to any ticket; it is shown as its own row so the rows sum to the total.');
505
+ var notes = ['Conductor context is not attributable to any ticket; it is its own row so the rows sum to the total.'];
352
506
  if ((cov.unattributed || 0) > 0) {
353
507
  notes.push(cov.unattributed + ' agent(s) carry no ticket id in their task description and are grouped as unattributed.');
354
508
  }
355
509
  if ((cost.unpriced || []).length > 0) {
356
510
  notes.push('Counted in tokens but absent from every amount, having no rate: ' + cost.unpriced.join(', ') + '.');
357
511
  }
358
- // A gap the page must never keep to itself: a transcript appended to while
359
- // it is read ends in a partial record, so the number above is low by an
360
- // amount only this line reports.
361
512
  if ((cov.malformed || 0) > 0 || (cov.skipped_lines || 0) > 0) {
362
513
  notes.push((cov.malformed || 0) + ' unparseable and ' + (cov.skipped_lines || 0) +
363
514
  ' oversized record(s) were skipped; their tokens are missing from every figure here.');
@@ -365,32 +516,28 @@ if (data.schema !== 1) {
365
516
  into.appendChild(el('div', 'caveat', notes.join(' ')));
366
517
  };
367
518
 
368
- // Spend is FETCHED, never embedded. It is derived from transcripts under the
369
- // operator's home directory — machine-local, different in every clone — so
370
- // writing it into board.json would break the byte-exact --check contract and
371
- // make two people with one journal disagree. Opened over file:// there is no
372
- // server, the request fails, and the section simply never appears.
373
- var spendAt = el('div');
374
- app.appendChild(spendAt);
519
+ // Spend is FETCHED, never embedded: it is derived from transcripts under
520
+ // the operator's home directory — machine-local, different in every clone —
521
+ // so writing it into board.json would break the byte-exact --check contract
522
+ // and make two people with one journal disagree.
375
523
  if (typeof fetch === 'function') {
376
524
  fetch('cost.json', { headers: { accept: 'application/json' } })
377
525
  .then(function (r) { return r.ok ? r.json() : null; })
378
- .then(function (cost) {
379
- if (cost && cost.schema === 1 && cost.transcripts_found) renderSpend(spendAt, cost, 'tokens');
526
+ .then(function (payload) {
527
+ if (!payload || payload.schema !== 1 || !payload.transcripts_found) return;
528
+ cost = payload;
529
+ renderSpend(spBody, 'tokens');
530
+ var t = cost.totals || {};
531
+ var strip = el('div', 'tiles');
532
+ strip.appendChild(tile('spend so far', fmtUsd(t.usd),
533
+ fmtTokens(t.tokens || 0) + ' tokens · see the Spend tab'));
534
+ ovSpend.appendChild(el('h2', null, 'Spend'));
535
+ ovSpend.appendChild(strip);
380
536
  })
381
537
  .catch(function () { /* no server: the board is complete without it */ });
382
538
  }
383
539
 
384
- // An initiative the board could not read is the one thing this page must
385
- // never omit: a missing card is indistinguishable from an initiative with
386
- // no work, which is the "all is well" reading the board exists to prevent.
387
- var errors = data.errors || [];
388
- if (errors.length > 0) {
389
- app.appendChild(el('h2', null, 'Unreadable (' + errors.length + ')'));
390
- errors.forEach(function (e) {
391
- app.appendChild(el('div', 'paused', 'UNREADABLE — ' + e.name + ': ' + e.error));
392
- });
393
- }
540
+ select('overview');
394
541
 
395
542
  var foot = el('footer');
396
543
  foot.appendChild(el('div', null, 'GENERATED by tyran scripts/board.mjs — do not edit. Refreshes every 30 s; ages are computed in this browser.'));