@jjanczur/tyran 0.1.17 → 0.1.19

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/bin/tyran.mjs CHANGED
@@ -88,6 +88,10 @@ export const COMMANDS = {
88
88
  'board.mjs',
89
89
  'Render the cross-initiative kanban board — BOARD.md, board.json and the board.html dashboard — from the journals under .tyran/state/.',
90
90
  ],
91
+ cost: [
92
+ 'cost.mjs',
93
+ 'What the work cost, in tokens the platform reported — per model, per agent type and per ticket, priced by your own rate card.',
94
+ ],
91
95
  answer: [
92
96
  'answer.mjs',
93
97
  'Write the sheet of questions waiting on you, then fold your answers back into the journal.',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jjanczur/tyran",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "Command-line scripts for the Tyran task conductor (doctor, journal, schema, and repo tooling) for CI and terminals outside Claude Code. Installing this package does NOT install the Claude Code plugin — add that separately with `/plugin marketplace add jjanczur/tyran` inside Claude Code.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -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,48 +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}
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}
137
+ .toggle{display:flex;gap:.25rem;margin-left:auto}
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)}
146
+ .comp .s-input{background:var(--muted)}
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}
151
+ .chartrow .rl{font-family:var(--mono);color:var(--heading);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
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}
154
+ .chartrow.dim .rl{color:var(--muted);font-style:italic}
155
+ .chartrow.dim .rb i{background:var(--hairline)}
156
+ .chartrow .rv{font-family:var(--mono);font-variant-numeric:tabular-nums;color:var(--text);min-width:5.5rem;text-align:right}
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}
81
159
  `;
82
160
 
83
161
  /**
@@ -117,26 +195,201 @@ if (data.schema !== 1) {
117
195
  if (text !== undefined && text !== null) node.textContent = show(text);
118
196
  return node;
119
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
+
120
210
  var app = document.getElementById('app');
121
211
  var head = el('div');
122
212
  head.appendChild(el('h1', null, 'Tyran board'));
123
- var totals = data.totals || {};
124
213
  head.appendChild(el('div', 'meta',
125
- (totals.agents || 0) + ' agent(s) running across ' + (totals.initiatives || 0) + ' initiative(s) · ' +
126
- (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')));
127
216
  app.appendChild(head);
128
217
 
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;
251
+ });
252
+ app.appendChild(tabbar);
253
+ TABS.forEach(function (spec) { app.appendChild(panels[spec[0]]); });
254
+
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
+ };
262
+
263
+ var fmtTokens = function (n) {
264
+ if (n >= 1e9) return (n / 1e9).toFixed(2) + ' B';
265
+ if (n >= 1e6) return (n / 1e6).toFixed(1) + ' M';
266
+ if (n >= 1e3) return (n / 1e3).toFixed(1) + ' k';
267
+ return String(n);
268
+ };
269
+ // An amount that rounds to nothing still cost something; printing $0.00
270
+ // there reads as free.
271
+ var fmtUsd = function (v) {
272
+ if (v === null || v === undefined) return '—';
273
+ if (v > 0 && v < 0.01) return '<$0.01';
274
+ return '$' + v.toFixed(2);
275
+ };
276
+
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;
129
296
  (data.paused || []).forEach(function (p) {
130
- app.appendChild(el('div', 'paused', 'PAUSED — ' + p.init + ': gate ' + p.kind + ' (' + p.result + ') since ' + p.since));
297
+ ov.appendChild(el('div', 'paused', 'PAUSED — ' + p.init + ': gate ' + p.kind + ' (' + p.result + ') since ' + p.since));
131
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);
132
313
 
133
- var asks = data.asks || [];
134
- app.appendChild(el('h2', null, 'Waiting on you (' + asks.length + ')'));
135
- if (asks.length === 0) app.appendChild(el('div', 'empty', 'nothing — the agents have what they need'));
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);
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'));
136
389
  asks.forEach(function (a) {
137
390
  var card = el('div', 'ask');
138
391
  card.appendChild(el('div', 'q', a.question || '(no question recorded — gate ' + a.kind + ')'));
139
- [['recommendation', a.recommendation], ['default', a.default],
392
+ [['answer with', a.kind], ['recommendation', a.recommendation], ['default', a.default],
140
393
  ['ticket', a.ticket], ['initiative', a.init], ['since', a.since]].forEach(function (pair) {
141
394
  if (pair[1] === null || pair[1] === undefined) return;
142
395
  var row = el('div', 'row');
@@ -144,60 +397,148 @@ if (data.schema !== 1) {
144
397
  row.appendChild(el('span', null, pair[1]));
145
398
  card.appendChild(row);
146
399
  });
147
- app.appendChild(card);
400
+ qs.appendChild(card);
148
401
  });
149
402
 
150
- var agents = data.agents || [];
151
- app.appendChild(el('h2', null, 'Agents (' + agents.length + ')'));
152
- var strip = el('div', 'agents');
153
- if (agents.length === 0) strip.appendChild(el('div', 'empty', 'none running'));
154
- agents.forEach(function (a) {
155
- var chip = el('div', 'agent');
156
- chip.appendChild(el('div', 'name', a.agent + (a.role ? ' · ' + a.role : '')));
157
- chip.appendChild(el('div', null, (a.init ? a.init + ' · ' : '') + (a.ticket || 'no ticket') + ' · ' + a.state));
158
- if (a.detail) chip.appendChild(el('div', 'note', a.detail));
159
- var ageMs = a.last_signal ? Date.now() - Date.parse(a.last_signal) : null;
160
- var cls = ageMs === null ? 'age-cold' : ageMs < 600000 ? 'age-fresh' : ageMs < 1800000 ? 'age-warm' : 'age-cold';
161
- var ageText = ageMs === null ? 'no signal' : Math.round(ageMs / 60000) + ' min since last signal';
162
- chip.appendChild(el('div', cls, ageText));
163
- strip.appendChild(chip);
164
- });
165
- app.appendChild(strip);
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.'));
166
408
 
167
- app.appendChild(el('h2', null, 'Lanes'));
168
- var lanesWrap = el('div', 'lanes');
169
- Object.keys(data.lanes || {}).forEach(function (lane) {
170
- var cards = data.lanes[lane];
171
- var box = el('div', 'lane ' + lane);
172
- var h = el('h3');
173
- h.appendChild(el('span', null, lane + ' '));
174
- h.appendChild(el('span', 'count', '(' + cards.length + ')'));
175
- box.appendChild(h);
176
- if (cards.length === 0) box.appendChild(el('div', 'empty', '—'));
177
- cards.forEach(function (c) {
178
- var card = el('div', 'card');
179
- card.appendChild(el('span', 'id', c.id));
180
- if (c.title) card.appendChild(el('span', null, ' — ' + c.title));
181
- if (c.init) card.appendChild(el('span', 'init', ' ' + c.init));
182
- if (c.agents && c.agents.length) card.appendChild(el('span', 'note', 'agents: ' + c.agents.join(', ')));
183
- if (c.annotation) card.appendChild(el('span', 'note', c.annotation));
184
- box.appendChild(card);
409
+ var chart = function (allRows, key, metric, dimKeys) {
410
+ var box = el('div', 'chart');
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.
414
+ var valueOf = function (r) { return metric === 'usd' ? r.usd : r.tokens; };
415
+ var rows = allRows.slice().sort(function (a, b) {
416
+ var av = valueOf(a);
417
+ var bv = valueOf(b);
418
+ if (typeof av !== 'number' && typeof bv !== 'number') return 0;
419
+ if (typeof av !== 'number') return 1;
420
+ if (typeof bv !== 'number') return -1;
421
+ return bv - av || String(a[key]).localeCompare(String(b[key]));
185
422
  });
186
- lanesWrap.appendChild(box);
187
- });
188
- app.appendChild(lanesWrap);
423
+ var values = rows.map(valueOf);
424
+ var max = 0;
425
+ values.forEach(function (v) { if (typeof v === 'number' && v > max) max = v; });
426
+ rows.forEach(function (r, i) {
427
+ var value = values[i];
428
+ var unpriced = metric === 'usd' && (value === null || value === undefined);
429
+ var dim = unpriced || dimKeys.indexOf(r[key]) !== -1;
430
+ var row = el('div', dim ? 'chartrow dim' : 'chartrow');
431
+ row.appendChild(el('div', 'rl', r[key]));
432
+ var track = el('div', 'rb');
433
+ var fill = el('i');
434
+ fill.style.width = (max > 0 && typeof value === 'number' ? (value / max) * 100 : 0) + '%';
435
+ track.appendChild(fill);
436
+ row.appendChild(track);
437
+ row.appendChild(el('div', 'rv', metric === 'usd' ? fmtUsd(value) : fmtTokens(value)));
438
+ box.appendChild(row);
439
+ });
440
+ return box;
441
+ };
189
442
 
190
- // An initiative the board could not read is the one thing this page must
191
- // never omit: a missing card is indistinguishable from an initiative with
192
- // no work, which is the "all is well" reading the board exists to prevent.
193
- var errors = data.errors || [];
194
- if (errors.length > 0) {
195
- app.appendChild(el('h2', null, 'Unreadable (' + errors.length + ')'));
196
- errors.forEach(function (e) {
197
- app.appendChild(el('div', 'paused', 'UNREADABLE — ' + e.name + ': ' + e.error));
443
+ var renderSpend = function (into, metric) {
444
+ clear(into);
445
+ var t = cost.totals || {};
446
+ var cov = cost.coverage || {};
447
+ var header = el('div', 'spend-head');
448
+ header.appendChild(el('h2', null, 'Spend'));
449
+ var toggle = el('div', 'toggle');
450
+ [['tokens', 'tokens'], ['usd', 'cost']].forEach(function (pair) {
451
+ var button = el('button', null, pair[1]);
452
+ button.setAttribute('type', 'button');
453
+ button.setAttribute('aria-pressed', metric === pair[0] ? 'true' : 'false');
454
+ button.addEventListener('click', function () { renderSpend(into, pair[0]); });
455
+ toggle.appendChild(button);
198
456
  });
457
+ header.appendChild(toggle);
458
+ into.appendChild(header);
459
+
460
+ var tiles = el('div', 'tiles');
461
+ tiles.appendChild(tile('tokens', fmtTokens(t.tokens || 0), (t.requests || 0) + ' requests'));
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),
466
+ (cov.unattributed || 0) + ' agent(s) without a ticket'));
467
+ into.appendChild(tiles);
468
+
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.
471
+ var comp = (cost.composition || []).slice().sort(function (a, b) {
472
+ return metric === 'usd' ? (b.usd || 0) - (a.usd || 0) : b.tokens - a.tokens;
473
+ });
474
+ var compTotal = 0;
475
+ comp.forEach(function (c) { compTotal += metric === 'usd' ? (c.usd || 0) : c.tokens; });
476
+ if (compTotal > 0) {
477
+ var bar = el('div', 'comp');
478
+ var key = el('div', 'compkey');
479
+ comp.forEach(function (c) {
480
+ var value = metric === 'usd' ? (c.usd || 0) : c.tokens;
481
+ if (value <= 0) return;
482
+ var pct = Math.round((value / compTotal) * 100);
483
+ var seg = el('span', 's-' + c.kind, pct >= 8 ? pct + '%' : '');
484
+ // Normalised to a share: flex-grow below 1 does not fill its
485
+ // container, and dollar amounts are routinely fractions.
486
+ seg.style.flex = String((value / compTotal) * 100);
487
+ bar.appendChild(seg);
488
+ var legend = el('span', null);
489
+ legend.appendChild(el('i', 's-' + c.kind));
490
+ legend.appendChild(el('span', null,
491
+ c.kind.replace('_', ' ') + ' ' + (metric === 'usd' ? fmtUsd(c.usd) : fmtTokens(c.tokens))));
492
+ key.appendChild(legend);
493
+ });
494
+ into.appendChild(bar);
495
+ into.appendChild(key);
496
+ }
497
+
498
+ [['By model', cost.by_model || [], 'model', []],
499
+ ['By agent type', cost.by_agent_type || [], 'agent_type', ['conductor']],
500
+ ['By ticket', cost.by_ticket || [], 'ticket', ['conductor', 'unattributed']]].forEach(function (spec) {
501
+ into.appendChild(el('h3', null, spec[0]));
502
+ into.appendChild(chart(spec[1], spec[2], metric, spec[3]));
503
+ });
504
+
505
+ var notes = ['Conductor context is not attributable to any ticket; it is its own row so the rows sum to the total.'];
506
+ if ((cov.unattributed || 0) > 0) {
507
+ notes.push(cov.unattributed + ' agent(s) carry no ticket id in their task description and are grouped as unattributed.');
508
+ }
509
+ if ((cost.unpriced || []).length > 0) {
510
+ notes.push('Counted in tokens but absent from every amount, having no rate: ' + cost.unpriced.join(', ') + '.');
511
+ }
512
+ if ((cov.malformed || 0) > 0 || (cov.skipped_lines || 0) > 0) {
513
+ notes.push((cov.malformed || 0) + ' unparseable and ' + (cov.skipped_lines || 0) +
514
+ ' oversized record(s) were skipped; their tokens are missing from every figure here.');
515
+ }
516
+ into.appendChild(el('div', 'caveat', notes.join(' ')));
517
+ };
518
+
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.
523
+ if (typeof fetch === 'function') {
524
+ fetch('cost.json', { headers: { accept: 'application/json' } })
525
+ .then(function (r) { return r.ok ? r.json() : null; })
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);
536
+ })
537
+ .catch(function () { /* no server: the board is complete without it */ });
199
538
  }
200
539
 
540
+ select('overview');
541
+
201
542
  var foot = el('footer');
202
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.'));
203
544
  app.appendChild(foot);