@jjanczur/tyran 0.1.23 → 0.1.25
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +178 -0
- package/README.md +9 -4
- package/package.json +1 -1
- package/scripts/board-html.mjs +409 -4
- package/scripts/board.mjs +234 -9
- package/scripts/project.mjs +21 -1
- package/scripts/scan-repo.mjs +20 -0
- package/scripts/settings.mjs +542 -0
- package/scripts/stop-check.mjs +12 -1
- package/scripts/yaml-lite.mjs +26 -3
- package/scripts/yaml-patch.mjs +350 -0
package/scripts/board-html.mjs
CHANGED
|
@@ -52,7 +52,8 @@ const CSS = `
|
|
|
52
52
|
--hairline:#332e27;--hairline-soft:#26221d;
|
|
53
53
|
--brass:#a8863c;--brass-bright:#cfae63;--brass-low:#221c11;--brass-edge:#5d4c22;
|
|
54
54
|
--steel:#7d9ea9;--steel-bright:#9dbcc6;--steel-low:#17242a;--steel-edge:#3a545d;
|
|
55
|
-
--clay:#c07a70;--clay-bright:#d9998f;--clay-low:#2a1a18;--
|
|
55
|
+
--clay:#c07a70;--clay-bright:#d9998f;--clay-low:#2a1a18;--clay-edge:#5a3430;
|
|
56
|
+
--sage:#88a06a;--sage-bright:#a3ba86;
|
|
56
57
|
--display:ui-serif,'Iowan Old Style','Palatino Linotype',Palatino,'Book Antiqua',Georgia,'Times New Roman',serif;
|
|
57
58
|
--font:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,sans-serif;
|
|
58
59
|
--mono:ui-monospace,SFMono-Regular,'SF Mono',Menlo,Consolas,'Liberation Mono',monospace;
|
|
@@ -139,6 +140,9 @@ h3{font-family:var(--font);color:var(--heading);font-size:.85rem;margin:1.1rem 0
|
|
|
139
140
|
.card .id{font-family:var(--mono);color:var(--heading)}
|
|
140
141
|
.card .init{font-family:var(--mono);color:var(--muted);font-size:.68rem}
|
|
141
142
|
.card .note{color:var(--muted);font-size:.74rem;display:block}
|
|
143
|
+
.card .note.age-warm{color:var(--brass)}
|
|
144
|
+
.card .note.age-cold{color:var(--clay)}
|
|
145
|
+
.card .note.age-dead{color:var(--clay-bright);font-weight:600}
|
|
142
146
|
.empty{color:var(--hairline);font-size:.78rem}
|
|
143
147
|
|
|
144
148
|
/* ---- detail ---- */
|
|
@@ -178,6 +182,39 @@ pre.how .c{color:var(--muted)}
|
|
|
178
182
|
.chartrow.dim .rl{color:var(--muted);font-style:italic}
|
|
179
183
|
.chartrow.dim .rb i{background:var(--hairline)}
|
|
180
184
|
.chartrow .rv{font-family:var(--mono);font-variant-numeric:tabular-nums;color:var(--text);min-width:5.5rem;text-align:right}
|
|
185
|
+
|
|
186
|
+
/* ---- settings ---- */
|
|
187
|
+
.setnote{border:1px solid var(--hairline);border-left:3px solid var(--steel);border-radius:.4rem;padding:.6rem .8rem;margin:.2rem 0 1.2rem;font-size:.85rem;color:var(--muted);line-height:1.6}
|
|
188
|
+
.setnote.warn{border-left-color:var(--brass)}
|
|
189
|
+
.setnote.bad{border-left-color:var(--clay)}
|
|
190
|
+
.setnote b{color:var(--heading);font-weight:600}
|
|
191
|
+
.setnote code{font-family:var(--mono);font-size:.8rem;color:var(--brass-bright);background:var(--brass-low);padding:.08rem .3rem;border-radius:.25rem}
|
|
192
|
+
.sgroup{margin:0 0 1.6rem}
|
|
193
|
+
.sgroup .blurb{font-size:.85rem;color:var(--muted);line-height:1.6;margin:.15rem 0 .9rem;max-width:60rem}
|
|
194
|
+
.srow{display:grid;grid-template-columns:minmax(10rem,14rem) 1fr;gap:.4rem 1.1rem;padding:.75rem 0;border-top:1px solid var(--hairline);align-items:start}
|
|
195
|
+
.srow .sname{font-weight:600;color:var(--heading);font-size:.88rem;padding-top:.3rem}
|
|
196
|
+
.srow .sname .sunit{font-family:var(--mono);font-weight:400;color:var(--muted);font-size:.76rem}
|
|
197
|
+
.srow .sbody{min-width:0}
|
|
198
|
+
.srow select,.srow input[type="text"],.srow textarea{display:block;font-family:var(--font);font-size:.85rem;background:var(--bg-raised);color:var(--text);border:1px solid var(--hairline);border-radius:.35rem;padding:.3rem .5rem;max-width:32rem;width:100%}
|
|
199
|
+
.srow textarea{font-family:var(--mono);font-size:.8rem;line-height:1.7;min-height:5rem;resize:vertical}
|
|
200
|
+
.srow input[type="number"]{display:block;font-family:var(--mono);font-size:.85rem;background:var(--bg-raised);color:var(--text);border:1px solid var(--hairline);border-radius:.35rem;padding:.3rem .5rem;width:7rem}
|
|
201
|
+
.srow select:focus-visible,.srow input:focus-visible,.srow textarea:focus-visible{outline:2px solid var(--steel);outline-offset:1px}
|
|
202
|
+
.srow select:disabled,.srow input:disabled,.srow textarea:disabled{opacity:.55;cursor:not-allowed}
|
|
203
|
+
.srow .shelp{font-size:.8rem;color:var(--muted);line-height:1.6;margin-top:.35rem;max-width:52rem}
|
|
204
|
+
.srow .schoice{font-size:.8rem;color:var(--text);line-height:1.6;margin-top:.3rem;padding-left:.6rem;border-left:2px solid var(--steel-edge)}
|
|
205
|
+
.sstat{font-family:var(--mono);font-size:.75rem;line-height:1.7;margin-top:.35rem;color:var(--muted);word-break:break-word;white-space:pre-wrap}
|
|
206
|
+
.sstat.ok{color:var(--sage-bright)}
|
|
207
|
+
.sstat.bad{color:var(--clay-bright)}
|
|
208
|
+
.sbtn{font-family:var(--font);font-size:.78rem;font-weight:600;background:var(--brass-low);color:var(--brass-bright);border:1px solid var(--brass-edge);border-radius:.35rem;padding:.26rem .7rem;cursor:pointer;margin-top:.4rem}
|
|
209
|
+
.sbtn:hover:not(:disabled){background:var(--brass-edge)}
|
|
210
|
+
.sbtn:disabled{opacity:.5;cursor:not-allowed}
|
|
211
|
+
.sbtn.danger{background:var(--clay-low);color:var(--clay-bright);border-color:var(--clay-edge);margin-top:.5rem}
|
|
212
|
+
.sbtn.danger:hover:not(:disabled){background:var(--clay-edge);color:var(--heading)}
|
|
213
|
+
.rule{display:grid;grid-template-columns:1fr minmax(7rem,9rem);gap:.3rem .9rem;padding:.6rem 0;border-top:1px solid var(--hairline);align-items:start}
|
|
214
|
+
.rule .glob{font-family:var(--mono);font-size:.82rem;color:var(--heading);word-break:break-all}
|
|
215
|
+
.rule .why{font-size:.78rem;color:var(--muted);line-height:1.6;grid-column:1;max-width:52rem}
|
|
216
|
+
.rule .lock{font-family:var(--mono);font-size:.72rem;color:var(--clay-bright);border:1px solid var(--clay-edge);background:var(--clay-low);border-radius:.3rem;padding:.16rem .4rem;text-align:center;align-self:start}
|
|
217
|
+
.rule .sstat{grid-column:1 / -1}
|
|
181
218
|
.caveat{color:var(--muted);font-size:.76rem;margin-top:.5rem;max-width:52rem}
|
|
182
219
|
footer{margin-top:2rem;color:var(--muted);font-size:.72rem;border-top:1px solid var(--hairline-soft);padding-top:.6rem}
|
|
183
220
|
`;
|
|
@@ -301,6 +338,7 @@ if (data.schema !== 1) {
|
|
|
301
338
|
['board', 'Board', null],
|
|
302
339
|
['questions', 'Waiting on you', asks.length],
|
|
303
340
|
['spend', 'Spend', null],
|
|
341
|
+
['settings', 'Settings', null],
|
|
304
342
|
];
|
|
305
343
|
var select = function (key) {
|
|
306
344
|
for (var i = 0; i < TABS.length; i += 1) {
|
|
@@ -333,6 +371,31 @@ if (data.schema !== 1) {
|
|
|
333
371
|
return box;
|
|
334
372
|
};
|
|
335
373
|
|
|
374
|
+
// One staleness vocabulary, used by the agent strip, the logged errors and
|
|
375
|
+
// the lane cards. Three renderings of "how long ago" would let the same
|
|
376
|
+
// gap read as fine in one place and alarming in another.
|
|
377
|
+
//
|
|
378
|
+
// This is the only clock on the page. The ARTEFACT never reads one — "as of"
|
|
379
|
+
// is the newest event timestamp, which is what keeps --check valid for the
|
|
380
|
+
// HTML — so every age here is computed in the reader's own browser.
|
|
381
|
+
var ageMsOf = function (ts) {
|
|
382
|
+
if (!ts) return null;
|
|
383
|
+
var t = Date.parse(ts);
|
|
384
|
+
return isNaN(t) ? null : Date.now() - t;
|
|
385
|
+
};
|
|
386
|
+
var ageClass = function (ms) {
|
|
387
|
+
if (ms === null) return 'age-cold';
|
|
388
|
+
return ms < 600000 ? 'age-fresh' : ms < 1800000 ? 'age-warm' : ms < 10800000 ? 'age-cold' : 'age-dead';
|
|
389
|
+
};
|
|
390
|
+
var ago = function (ts) {
|
|
391
|
+
var ms = ageMsOf(ts);
|
|
392
|
+
if (ms === null) return 'no time recorded';
|
|
393
|
+
if (ms < 60000) return 'just now';
|
|
394
|
+
if (ms < 3600000) return Math.round(ms / 60000) + ' min ago';
|
|
395
|
+
if (ms < 172800000) return Math.round(ms / 3600000) + ' h ago';
|
|
396
|
+
return Math.round(ms / 86400000) + ' d ago';
|
|
397
|
+
};
|
|
398
|
+
|
|
336
399
|
var fmtTokens = function (n) {
|
|
337
400
|
if (n >= 1e9) return (n / 1e9).toFixed(2) + ' B';
|
|
338
401
|
if (n >= 1e6) return (n / 1e6).toFixed(1) + ' M';
|
|
@@ -360,15 +423,14 @@ if (data.schema !== 1) {
|
|
|
360
423
|
// shown it — so the chip could say an agent went quiet without saying
|
|
361
424
|
// what it went quiet in the middle of.
|
|
362
425
|
if (a.next) chip.appendChild(el('div', 'note', 'next: ' + a.next));
|
|
363
|
-
var ageMs = a.last_signal ? Date.now() - Date.parse(a.last_signal) : null;
|
|
364
|
-
var cls = ageMs === null ? 'age-cold' : ageMs < 600000 ? 'age-fresh' : ageMs < 1800000 ? 'age-warm' : 'age-cold';
|
|
365
426
|
// Four buckets, not three. The old top bucket was "30 minutes or six
|
|
366
427
|
// hours", which are not the same event: one is a long test run, the
|
|
367
428
|
// other is an agent that is not coming back.
|
|
429
|
+
var ageMs = ageMsOf(a.last_signal);
|
|
368
430
|
var ageText = ageMs === null ? 'no signal recorded'
|
|
369
431
|
: ageMs >= 10800000 ? Math.round(ageMs / 3600000) + ' HOURS since last signal — likely dead'
|
|
370
432
|
: Math.round(ageMs / 60000) + ' min since last signal';
|
|
371
|
-
chip.appendChild(el('div', ageMs
|
|
433
|
+
chip.appendChild(el('div', ageClass(ageMs), ageText));
|
|
372
434
|
strip.appendChild(chip);
|
|
373
435
|
});
|
|
374
436
|
return strip;
|
|
@@ -376,6 +438,16 @@ if (data.schema !== 1) {
|
|
|
376
438
|
|
|
377
439
|
// ---- overview ---------------------------------------------------------
|
|
378
440
|
var ov = panels.overview;
|
|
441
|
+
// A STOP outranks everything, and it goes first. It is the one state in
|
|
442
|
+
// which a strip of silent agents is the system doing exactly as it was told,
|
|
443
|
+
// and without it that strip reads identically to a fleet that died.
|
|
444
|
+
if (data.stop && data.stop.stopped === true) {
|
|
445
|
+
var stopBox = el('div', 'paused');
|
|
446
|
+
stopBox.appendChild(el('b', null, 'STOPPED \\u2014 '));
|
|
447
|
+
stopBox.appendChild(el('span', null, 'an operator halted this repo: ' + (data.stop.reason || '(no reason given)')));
|
|
448
|
+
stopBox.appendChild(el('div', 'hint', 'Nothing new will be started until .tyran/STOP is deleted. Agents already running are not killed by it.'));
|
|
449
|
+
ov.appendChild(stopBox);
|
|
450
|
+
}
|
|
379
451
|
(data.paused || []).forEach(function (p) {
|
|
380
452
|
ov.appendChild(el('div', 'paused', 'PAUSED — ' + p.init + ': gate ' + p.kind + ' (' + p.result + ') since ' + p.since));
|
|
381
453
|
});
|
|
@@ -446,6 +518,24 @@ if (data.schema !== 1) {
|
|
|
446
518
|
});
|
|
447
519
|
}
|
|
448
520
|
|
|
521
|
+
// An agent that logged a hard error with no ticket to hang it on used to
|
|
522
|
+
// land in that initiative's STATE.md and nowhere else, so the page whose
|
|
523
|
+
// whole job is to say "not all is well" showed nothing at all.
|
|
524
|
+
var logged = data.errors_logged || [];
|
|
525
|
+
if (logged.length > 0) {
|
|
526
|
+
var total = data.errors_logged_total || logged.length;
|
|
527
|
+
ov.appendChild(el('h2', null, 'Errors logged (' + total + ')'));
|
|
528
|
+
ov.appendChild(el('div', 'hint', 'Agents recorded these as failures. Newest first. An error carrying no ticket belongs to the initiative rather than to any one card, which is why it appears here and in no lane.'));
|
|
529
|
+
logged.forEach(function (e) {
|
|
530
|
+
var text = (e.class || 'error') + (e.detail ? ': ' + e.detail : '')
|
|
531
|
+
+ (e.ticket_unknown ? ' \u2014 it names ticket ' + e.ticket + ', which this journal has never declared' : '');
|
|
532
|
+
ov.appendChild(el('div', 'damaged', e.init + ' \\u00b7 ' + text + ' \\u00b7 ' + ago(e.ts)));
|
|
533
|
+
});
|
|
534
|
+
if (total > logged.length) {
|
|
535
|
+
ov.appendChild(el('div', 'hint', 'and ' + (total - logged.length) + ' older \\u2014 the journals have the rest.'));
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
449
539
|
// The same argument one step down. An initiative whose journal is PARTLY
|
|
450
540
|
// damaged folds to a board with nothing wrong on it — the lost half leaves
|
|
451
541
|
// no trace — so it used to render as an initiative in perfect health.
|
|
@@ -465,6 +555,13 @@ if (data.schema !== 1) {
|
|
|
465
555
|
// ---- board ------------------------------------------------------------
|
|
466
556
|
var bd = panels.board;
|
|
467
557
|
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.'));
|
|
558
|
+
// Lanes where a ticket sitting still is worth saying out loud. The backlog
|
|
559
|
+
// and ready lanes are deliberately absent — an unstarted ticket is not
|
|
560
|
+
// stalling, it is waiting its turn, and marking every one of them stale
|
|
561
|
+
// would make the signal worthless on the lanes where it means something.
|
|
562
|
+
// Done, likewise: a merged ticket is supposed to stop moving.
|
|
563
|
+
var STALLABLE = ['blocked', 'changes-requested', 'in-review', 'waiting-operator', 'in-progress', 'paused-limit'];
|
|
564
|
+
|
|
468
565
|
var detail = el('div');
|
|
469
566
|
var selected = null;
|
|
470
567
|
var lanesWrap = el('div', 'lanes');
|
|
@@ -490,6 +587,7 @@ if (data.schema !== 1) {
|
|
|
490
587
|
// is already done — precisely when the running-agents list is empty.
|
|
491
588
|
row('worked by', card.worked_by && card.worked_by.length ? card.worked_by.join(', ') : null);
|
|
492
589
|
row('note', card.annotation);
|
|
590
|
+
row('last event', card.since ? ago(card.since) + ' (' + card.since + ')' : null);
|
|
493
591
|
if (cost) {
|
|
494
592
|
var hit = (cost.by_ticket || []).filter(function (r) { return r.ticket === card.id; })[0];
|
|
495
593
|
if (hit) row('spend', fmtTokens(hit.tokens) + ' tokens · ' + fmtUsd(hit.usd));
|
|
@@ -554,6 +652,18 @@ if (data.schema !== 1) {
|
|
|
554
652
|
if (moved[(c.init || '') + '/' + c.id]) button.appendChild(el('span', 'movedtag', 'moved'));
|
|
555
653
|
if (c.agents && c.agents.length) button.appendChild(el('span', 'note', 'agents: ' + c.agents.join(', ')));
|
|
556
654
|
if (c.annotation) button.appendChild(el('span', 'note', c.annotation));
|
|
655
|
+
// How long this card has stood still, on the lanes where standing still
|
|
656
|
+
// IS the defect. The board would tell you an agent had been quiet for
|
|
657
|
+
// three hours and refuse to tell you a ticket had been blocked for four
|
|
658
|
+
// days — the timestamp has been in board.json since the lanes existed
|
|
659
|
+
// and nothing ever rendered it.
|
|
660
|
+
//
|
|
661
|
+
// Worded as an observation, never a verdict: the board reports the last
|
|
662
|
+
// event on the ticket, and only a human knows whether that is a stall or
|
|
663
|
+
// a long test run.
|
|
664
|
+
if (STALLABLE.indexOf(lane) !== -1 && c.since) {
|
|
665
|
+
button.appendChild(el('span', 'note ' + ageClass(ageMsOf(c.since)), 'no event ' + ago(c.since).replace(/ ago$/, '')));
|
|
666
|
+
}
|
|
557
667
|
button.addEventListener('click', function () { showDetail(c, lane, button); });
|
|
558
668
|
box.appendChild(button);
|
|
559
669
|
buttons.push(button);
|
|
@@ -779,6 +889,301 @@ if (data.schema !== 1) {
|
|
|
779
889
|
});
|
|
780
890
|
}
|
|
781
891
|
|
|
892
|
+
// ---- settings ---------------------------------------------------------
|
|
893
|
+
//
|
|
894
|
+
// The one tab that writes. Everything else on this page is a projection of
|
|
895
|
+
// the journal and hand-editing it would be drift; config and the autonomy
|
|
896
|
+
// policy are the opposite — operator-owned files that nothing generates, and
|
|
897
|
+
// the only place they could be changed until now was an editor and a memory
|
|
898
|
+
// of what each key meant.
|
|
899
|
+
//
|
|
900
|
+
// Served, never embedded, exactly like spend: these are not journal state,
|
|
901
|
+
// so writing them into board.json would break the byte-exact check and make
|
|
902
|
+
// two clones of one journal disagree.
|
|
903
|
+
var st = panels.settings;
|
|
904
|
+
var stBody = el('div');
|
|
905
|
+
st.appendChild(stBody);
|
|
906
|
+
stBody.appendChild(el('div', 'setnote', 'Settings are read from .tyran/config.yaml and .tyran/policies/autonomy.yaml, and they are served rather than embedded — open this board with "board.mjs --serve" to see them.'));
|
|
907
|
+
|
|
908
|
+
// A meta refresh and a form are incompatible: half a typed model name would
|
|
909
|
+
// vanish every thirty seconds. The tag stays in the HTML (a page whose JS
|
|
910
|
+
// never runs still refreshes, and the docs sandbox strips the tag to stop
|
|
911
|
+
// itself reloading), but at boot it is swapped for a timer that can be
|
|
912
|
+
// paused — and the Settings tab pauses it. Present tag, same 30 seconds;
|
|
913
|
+
// absent tag, no timer at all, which is what the sandbox wants.
|
|
914
|
+
var refreshTag = document.querySelector('meta[http-equiv="refresh"]');
|
|
915
|
+
var refreshTimer = null;
|
|
916
|
+
var armRefresh = function () {
|
|
917
|
+
if (refreshTag === null || refreshTimer !== null) return;
|
|
918
|
+
refreshTimer = setTimeout(function () { location.reload(); }, 30000);
|
|
919
|
+
};
|
|
920
|
+
var holdRefresh = function () {
|
|
921
|
+
if (refreshTimer !== null) { clearTimeout(refreshTimer); refreshTimer = null; }
|
|
922
|
+
};
|
|
923
|
+
if (refreshTag !== null && refreshTag.parentNode) {
|
|
924
|
+
refreshTag.parentNode.removeChild(refreshTag);
|
|
925
|
+
armRefresh();
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
var post = function (route, body, status, onDone) {
|
|
929
|
+
status.className = 'sstat';
|
|
930
|
+
status.textContent = 'saving\\u2026';
|
|
931
|
+
fetch(route, {
|
|
932
|
+
method: 'POST',
|
|
933
|
+
headers: { 'content-type': 'application/json' },
|
|
934
|
+
body: JSON.stringify(body)
|
|
935
|
+
}).then(function (r) {
|
|
936
|
+
return r.json().then(function (payload) { return { ok: r.ok, payload: payload }; });
|
|
937
|
+
}).then(function (result) {
|
|
938
|
+
var payload = result.payload || {};
|
|
939
|
+
if (!result.ok || payload.ok !== true) {
|
|
940
|
+
status.className = 'sstat bad';
|
|
941
|
+
status.textContent = show(payload.error || 'the change was refused');
|
|
942
|
+
// A refusal the operator can answer, rather than one they can only
|
|
943
|
+
// read. The server sends back the exact token that answers it, and
|
|
944
|
+
// pressing this re-sends the same change carrying that token — which
|
|
945
|
+
// is why nothing here decides what "confirmed" means.
|
|
946
|
+
if (payload.widens === true && typeof payload.confirm_with === 'string') {
|
|
947
|
+
var go = el('button', 'sbtn danger', 'Yes \\u2014 loosen it');
|
|
948
|
+
go.setAttribute('type', 'button');
|
|
949
|
+
go.addEventListener('click', function () {
|
|
950
|
+
var again = {};
|
|
951
|
+
Object.keys(body).forEach(function (k) { again[k] = body[k]; });
|
|
952
|
+
again.confirm = payload.confirm_with;
|
|
953
|
+
post(route, again, status, onDone);
|
|
954
|
+
});
|
|
955
|
+
status.appendChild(document.createElement('br'));
|
|
956
|
+
status.appendChild(go);
|
|
957
|
+
}
|
|
958
|
+
if (onDone) onDone(false);
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
status.className = 'sstat ok';
|
|
962
|
+
status.textContent = show('saved \\u2014 ' + JSON.stringify(payload.before) + ' \\u2192 ' + JSON.stringify(payload.after));
|
|
963
|
+
if (onDone) onDone(true);
|
|
964
|
+
}).catch(function () {
|
|
965
|
+
status.className = 'sstat bad';
|
|
966
|
+
status.textContent = 'the board server did not answer \\u2014 nothing was written';
|
|
967
|
+
if (onDone) onDone(false);
|
|
968
|
+
});
|
|
969
|
+
};
|
|
970
|
+
|
|
971
|
+
var settingRow = function (setting, writable) {
|
|
972
|
+
var row = el('div', 'srow');
|
|
973
|
+
var name = el('div', 'sname', setting.label);
|
|
974
|
+
if (setting.unit) name.appendChild(el('span', 'sunit', ' ' + setting.unit));
|
|
975
|
+
row.appendChild(name);
|
|
976
|
+
var bodyCell = el('div', 'sbody');
|
|
977
|
+
row.appendChild(bodyCell);
|
|
978
|
+
|
|
979
|
+
var status = el('div', 'sstat');
|
|
980
|
+
var choiceNote = null;
|
|
981
|
+
var control = null;
|
|
982
|
+
|
|
983
|
+
if (setting.present !== true) {
|
|
984
|
+
// Absent is not the same as unset, and saying so beats an empty box: a
|
|
985
|
+
// key that is not in the file has no line for the patcher to edit, and
|
|
986
|
+
// inventing one means choosing where it goes and what comment explains
|
|
987
|
+
// it. That is authoring, and it stays a hand edit.
|
|
988
|
+
bodyCell.appendChild(el('div', 'shelp', 'Not set in this config. Add the key by hand once and it becomes editable here.'));
|
|
989
|
+
bodyCell.appendChild(el('div', 'shelp', setting.help));
|
|
990
|
+
return row;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
if (setting.kind === 'choice') {
|
|
994
|
+
control = el('select');
|
|
995
|
+
setting.choices.forEach(function (c) {
|
|
996
|
+
var option = el('option', null, c.value);
|
|
997
|
+
option.value = c.value;
|
|
998
|
+
if (c.value === setting.value) option.selected = true;
|
|
999
|
+
control.appendChild(option);
|
|
1000
|
+
});
|
|
1001
|
+
choiceNote = el('div', 'schoice');
|
|
1002
|
+
var describe = function () {
|
|
1003
|
+
var picked = setting.choices.filter(function (c) { return c.value === control.value; })[0];
|
|
1004
|
+
choiceNote.textContent = show(picked ? picked.describe : '');
|
|
1005
|
+
};
|
|
1006
|
+
describe();
|
|
1007
|
+
control.addEventListener('change', function () {
|
|
1008
|
+
describe();
|
|
1009
|
+
post('/settings/config', { id: setting.id, value: control.value }, status);
|
|
1010
|
+
});
|
|
1011
|
+
} else if (setting.kind === 'boolean') {
|
|
1012
|
+
control = el('select');
|
|
1013
|
+
[['false', 'off'], ['true', 'on']].forEach(function (pair) {
|
|
1014
|
+
var option = el('option', null, pair[1]);
|
|
1015
|
+
option.value = pair[0];
|
|
1016
|
+
if ((pair[0] === 'true') === (setting.value === true)) option.selected = true;
|
|
1017
|
+
control.appendChild(option);
|
|
1018
|
+
});
|
|
1019
|
+
control.addEventListener('change', function () {
|
|
1020
|
+
post('/settings/config', { id: setting.id, value: control.value === 'true' }, status);
|
|
1021
|
+
});
|
|
1022
|
+
} else if (setting.kind === 'number') {
|
|
1023
|
+
control = el('input');
|
|
1024
|
+
control.type = 'number';
|
|
1025
|
+
control.value = String(setting.value);
|
|
1026
|
+
if (setting.min !== null) control.min = String(setting.min);
|
|
1027
|
+
if (setting.max !== null) control.max = String(setting.max);
|
|
1028
|
+
control.addEventListener('change', function () {
|
|
1029
|
+
post('/settings/config', { id: setting.id, value: Number(control.value) }, status);
|
|
1030
|
+
});
|
|
1031
|
+
} else if (setting.kind === 'list') {
|
|
1032
|
+
control = el('textarea');
|
|
1033
|
+
control.value = (setting.value || []).join('\\n');
|
|
1034
|
+
if (setting.placeholder) control.placeholder = setting.placeholder + '\\n(one per line)';
|
|
1035
|
+
} else {
|
|
1036
|
+
control = el('input');
|
|
1037
|
+
control.type = 'text';
|
|
1038
|
+
control.value = String(setting.value === null ? '' : setting.value);
|
|
1039
|
+
if (setting.placeholder) control.placeholder = setting.placeholder;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
control.disabled = !writable;
|
|
1043
|
+
bodyCell.appendChild(control);
|
|
1044
|
+
|
|
1045
|
+
// Discrete controls save the moment they change; free text does not,
|
|
1046
|
+
// because there is no moment during typing that is the whole value.
|
|
1047
|
+
if (setting.kind === 'list' || setting.kind === 'text') {
|
|
1048
|
+
var save = el('button', 'sbtn', 'Save');
|
|
1049
|
+
save.setAttribute('type', 'button');
|
|
1050
|
+
save.disabled = !writable;
|
|
1051
|
+
control.addEventListener('input', holdRefresh);
|
|
1052
|
+
save.addEventListener('click', function () {
|
|
1053
|
+
var value = setting.kind === 'list'
|
|
1054
|
+
? control.value.split('\\n').map(function (line) { return line.trim(); }).filter(function (line) { return line !== ''; })
|
|
1055
|
+
: control.value;
|
|
1056
|
+
post('/settings/config', { id: setting.id, value: value }, status, function (ok) { if (ok) armRefresh(); });
|
|
1057
|
+
});
|
|
1058
|
+
bodyCell.appendChild(save);
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
if (choiceNote) bodyCell.appendChild(choiceNote);
|
|
1062
|
+
bodyCell.appendChild(el('div', 'shelp', setting.help));
|
|
1063
|
+
bodyCell.appendChild(status);
|
|
1064
|
+
return row;
|
|
1065
|
+
};
|
|
1066
|
+
|
|
1067
|
+
// The address is what the write route is told to change, and it is NOT the
|
|
1068
|
+
// label: the file's own default key is addressed as null, while a rule is
|
|
1069
|
+
// addressed by its path glob. By glob and not by position, so that a file
|
|
1070
|
+
// edited underneath an open page cannot land the write on a neighbouring
|
|
1071
|
+
// boundary — the server re-resolves the glob against the file as it is now.
|
|
1072
|
+
var ruleRow = function (rule, classes, describe, writable, address) {
|
|
1073
|
+
var row = el('div', 'rule');
|
|
1074
|
+
row.appendChild(el('div', 'glob', rule.path));
|
|
1075
|
+
var status = el('div', 'sstat');
|
|
1076
|
+
if (rule.locked) {
|
|
1077
|
+
var lock = el('div', 'lock', rule.class + ' \\u00b7 locked');
|
|
1078
|
+
lock.title = 'This path protects the gate itself and cannot be lowered.';
|
|
1079
|
+
row.appendChild(lock);
|
|
1080
|
+
} else {
|
|
1081
|
+
var pick = el('select');
|
|
1082
|
+
classes.forEach(function (klass) {
|
|
1083
|
+
var option = el('option', null, klass);
|
|
1084
|
+
option.value = klass;
|
|
1085
|
+
if (klass === rule.class) option.selected = true;
|
|
1086
|
+
pick.appendChild(option);
|
|
1087
|
+
});
|
|
1088
|
+
pick.disabled = !writable;
|
|
1089
|
+
pick.addEventListener('change', function () {
|
|
1090
|
+
post('/settings/policy', { path: address, class: pick.value }, status);
|
|
1091
|
+
});
|
|
1092
|
+
row.appendChild(pick);
|
|
1093
|
+
}
|
|
1094
|
+
if (rule.reason) row.appendChild(el('div', 'why', rule.reason));
|
|
1095
|
+
else if (rule.locked) row.appendChild(el('div', 'why', describe[rule.class] || ''));
|
|
1096
|
+
row.appendChild(status);
|
|
1097
|
+
return row;
|
|
1098
|
+
};
|
|
1099
|
+
|
|
1100
|
+
var renderSettings = function (payload) {
|
|
1101
|
+
clear(stBody);
|
|
1102
|
+
var writable = payload.writable === true;
|
|
1103
|
+
var note = el('div', writable ? 'setnote' : 'setnote warn');
|
|
1104
|
+
if (writable) {
|
|
1105
|
+
note.appendChild(el('b', null, 'Changes are written straight to disk.'));
|
|
1106
|
+
note.appendChild(el('span', null,
|
|
1107
|
+
' Comments in these files are kept; the value on one line is all that moves, and every write is checked by the same validator "tyran doctor" runs before it lands. Nothing is written if the result would be invalid. Review what changed with git diff.'));
|
|
1108
|
+
} else {
|
|
1109
|
+
note.appendChild(el('b', null, 'Read-only.'));
|
|
1110
|
+
note.appendChild(el('span', null, ' This board was started without editing. To turn these controls on, restart it with: '));
|
|
1111
|
+
note.appendChild(el('code', null, 'npx @jjanczur/tyran board --dir .tyran --serve --write'));
|
|
1112
|
+
}
|
|
1113
|
+
stBody.appendChild(note);
|
|
1114
|
+
|
|
1115
|
+
[['config', payload.files.config], ['policy', payload.files.policy]].forEach(function (pair) {
|
|
1116
|
+
if (pair[1].present && pair[1].error === null) return;
|
|
1117
|
+
var bad = el('div', 'setnote bad');
|
|
1118
|
+
bad.appendChild(el('b', null, pair[1].present ? 'This file does not parse: ' : 'This file is missing: '));
|
|
1119
|
+
bad.appendChild(el('span', null, pair[1].path + (pair[1].error ? ' \\u2014 ' + pair[1].error : '')));
|
|
1120
|
+
stBody.appendChild(bad);
|
|
1121
|
+
});
|
|
1122
|
+
|
|
1123
|
+
payload.groups.forEach(function (group) {
|
|
1124
|
+
var box = el('div', 'sgroup');
|
|
1125
|
+
box.appendChild(el('h2', null, group.title));
|
|
1126
|
+
box.appendChild(el('div', 'blurb', group.blurb));
|
|
1127
|
+
group.settings.forEach(function (setting) { box.appendChild(settingRow(setting, writable)); });
|
|
1128
|
+
stBody.appendChild(box);
|
|
1129
|
+
});
|
|
1130
|
+
|
|
1131
|
+
var policy = payload.policy || {};
|
|
1132
|
+
var pol = el('div', 'sgroup');
|
|
1133
|
+
pol.appendChild(el('h2', null, 'Autonomy policy'));
|
|
1134
|
+
pol.appendChild(el('div', 'blurb',
|
|
1135
|
+
'Which paths agents may write on their own. The most specific matching rule wins, and a path no rule matches gets the default. ' +
|
|
1136
|
+
(policy.classes || []).map(function (k) { return k + ' \\u2014 ' + (policy.describe || {})[k]; }).join(' \\u00b7 ')));
|
|
1137
|
+
if (policy.default !== null && policy.default !== undefined) {
|
|
1138
|
+
pol.appendChild(ruleRow(
|
|
1139
|
+
{ path: 'default \\u2014 everything no rule matches', class: policy.default, reason: 'GATED is the safe answer: it means "ask me".', locked: false },
|
|
1140
|
+
policy.classes || [], policy.describe || {}, writable, null));
|
|
1141
|
+
}
|
|
1142
|
+
(policy.rules || []).forEach(function (rule) {
|
|
1143
|
+
pol.appendChild(ruleRow(rule, policy.classes || [], policy.describe || {}, writable, rule.path));
|
|
1144
|
+
});
|
|
1145
|
+
stBody.appendChild(pol);
|
|
1146
|
+
};
|
|
1147
|
+
|
|
1148
|
+
// Leaving this tab re-arms the refresh, entering it stops it. A page that
|
|
1149
|
+
// reloads under an open select is a page that loses the change you were
|
|
1150
|
+
// halfway through making, and the board has three other tabs that want to
|
|
1151
|
+
// stay live.
|
|
1152
|
+
Object.keys(buttons).forEach(function (key) {
|
|
1153
|
+
buttons[key].addEventListener('click', function () {
|
|
1154
|
+
if (key === 'settings') holdRefresh(); else armRefresh();
|
|
1155
|
+
});
|
|
1156
|
+
});
|
|
1157
|
+
|
|
1158
|
+
fetch('settings.json', { headers: { accept: 'application/json' } })
|
|
1159
|
+
.then(function (r) { return r.ok ? r.json() : Promise.reject(new Error(String(r.status))); })
|
|
1160
|
+
.then(function (payload) {
|
|
1161
|
+
if (payload.schema !== 1) {
|
|
1162
|
+
clear(stBody);
|
|
1163
|
+
stBody.appendChild(el('div', 'setnote bad', 'Settings were served in a format this page does not know (schema ' +
|
|
1164
|
+
(payload.schema || 'absent') + ') \\u2014 regenerate the board with the Tyran that served it.'));
|
|
1165
|
+
return;
|
|
1166
|
+
}
|
|
1167
|
+
// A failure INSIDE the renderer is not a failure to reach the server,
|
|
1168
|
+
// and reporting it as one sends the operator to restart something that
|
|
1169
|
+
// was answering perfectly well. Caught here so the outer handler keeps
|
|
1170
|
+
// its one meaning: the fetch did not land.
|
|
1171
|
+
try {
|
|
1172
|
+
renderSettings(payload);
|
|
1173
|
+
} catch (err) {
|
|
1174
|
+
clear(stBody);
|
|
1175
|
+
stBody.appendChild(el('div', 'setnote bad',
|
|
1176
|
+
'Settings were served but this page could not draw them: ' + show(String((err && err.message) || err)) +
|
|
1177
|
+
' \\u2014 the board and the Tyran that served it are probably different versions.'));
|
|
1178
|
+
}
|
|
1179
|
+
})
|
|
1180
|
+
.catch(function () {
|
|
1181
|
+
if (String(location.protocol) === 'file:') return;
|
|
1182
|
+
clear(stBody);
|
|
1183
|
+
stBody.appendChild(el('div', 'setnote bad',
|
|
1184
|
+
'Settings could not be read: the board server did not answer. They are served, never embedded \\u2014 start it with: npx @jjanczur/tyran board --dir .tyran --serve --write'));
|
|
1185
|
+
});
|
|
1186
|
+
|
|
782
1187
|
select('overview');
|
|
783
1188
|
|
|
784
1189
|
var foot = el('footer');
|