@jjanczur/tyran 0.1.22 → 0.1.24
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 +135 -0
- package/README.md +10 -5
- package/package.json +1 -1
- package/scripts/board-html.mjs +331 -1
- package/scripts/board.mjs +170 -7
- package/scripts/project.mjs +7 -0
- package/scripts/scan-repo.mjs +20 -0
- package/scripts/settings.mjs +542 -0
- package/scripts/yaml-lite.mjs +26 -3
- package/scripts/yaml-patch.mjs +350 -0
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
{
|
|
12
12
|
"name": "tyran",
|
|
13
13
|
"description": "A task conductor for Claude Code: multi-agent orchestration with an enforced evidence contract, repo-specific learning, and update-safe local evolution.",
|
|
14
|
-
"version": "0.1.
|
|
14
|
+
"version": "0.1.24",
|
|
15
15
|
"source": "./",
|
|
16
16
|
"author": {
|
|
17
17
|
"name": "Jacek Janczura",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tyran",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24",
|
|
4
4
|
"description": "A task conductor for Claude Code: multi-agent orchestration with an enforced evidence contract, repo-specific learning, and update-safe local evolution.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jacek Janczura",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,140 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.24 — 2026-08-15
|
|
4
|
+
|
|
5
|
+
### Settings: the board can now change what Tyran does
|
|
6
|
+
|
|
7
|
+
`board --serve --write` turns the dashboard's new **Settings** tab into an
|
|
8
|
+
editor for the two operator-owned files — `.tyran/config.yaml` and
|
|
9
|
+
`.tyran/policies/autonomy.yaml`. Every knob carries a sentence saying what
|
|
10
|
+
turning it actually does, and every policy rule shows its own recorded reason.
|
|
11
|
+
Until now the answer to "where do I change this?" was an editor and a memory
|
|
12
|
+
of what each key meant.
|
|
13
|
+
|
|
14
|
+
**Writes are off by default and per-invocation.** Without `--write` the tab
|
|
15
|
+
renders with every control disabled and the command that turns it on. A board
|
|
16
|
+
someone left running is reachable by anything on the machine, and the
|
|
17
|
+
difference between reading that and editing the autonomy policy through it is
|
|
18
|
+
the difference the flag exists to make.
|
|
19
|
+
|
|
20
|
+
**One line moves, and the comments stay.** The plan of record said the
|
|
21
|
+
comments were expendable because the screen could carry the explanations. That
|
|
22
|
+
turned out not to be necessary: `scripts/yaml-patch.mjs` rewrites the line
|
|
23
|
+
that owns a value rather than round-tripping the document through a
|
|
24
|
+
serializer, so `templates/config.yaml` keeps all 60 of its comment lines — the
|
|
25
|
+
only place anyone is told that bare `off` is the YAML boolean false, which is
|
|
26
|
+
also the value that would have silently changed meaning had this been done the
|
|
27
|
+
obvious way.
|
|
28
|
+
|
|
29
|
+
**The edit is proved, not trusted.** Every patch is applied, parsed back, and
|
|
30
|
+
compared against the document that was intended: the target holds the new
|
|
31
|
+
value and every other path holds exactly what it held before. Then the whole
|
|
32
|
+
result goes through the same `validateConfig` / `validatePolicy` that
|
|
33
|
+
`schema.mjs validate` runs. A locator bug cannot ship a wrong file — it can
|
|
34
|
+
only fail loudly, and a refused write leaves the file byte-identical.
|
|
35
|
+
|
|
36
|
+
### Loosening a boundary is not the same click as tightening one
|
|
37
|
+
|
|
38
|
+
Found by an independent review of the above, before it shipped, and it was
|
|
39
|
+
worse than the review guessed. `validatePolicy` defends exactly two globs —
|
|
40
|
+
`hooks/**` and `.tyran/policies/**` — so the first version of this screen
|
|
41
|
+
would take `.claude/settings.json` from KERNEL to AUTO in one press, on a rule
|
|
42
|
+
whose own stated reason is *"anything that can edit it can switch every gate
|
|
43
|
+
off"*. So would `.tyran/STOP` (*"a loop that can clear its own stop signal has
|
|
44
|
+
none"*), and so would the policy `default`, and `autonomy: P1 → P3` sat in an
|
|
45
|
+
ordinary dropdown next to the cost profile.
|
|
46
|
+
|
|
47
|
+
Loosening now takes a second, deliberate act: the first request is refused
|
|
48
|
+
with the rule's own reason quoted back and a confirmation token, and the token
|
|
49
|
+
is **the new value itself** rather than a boolean, so nothing widens a
|
|
50
|
+
boundary by sending a truthy flag beside whatever value it liked. Tightening
|
|
51
|
+
still applies on the first click — friction on making a boundary stricter is
|
|
52
|
+
how you teach someone to stop making boundaries stricter.
|
|
53
|
+
|
|
54
|
+
What guards the route, stated exactly: the `Host` pin, an `Origin` check and a
|
|
55
|
+
required `application/json` content type close the browser paths. They do not
|
|
56
|
+
stop another process on the machine that can already reach loopback; nothing
|
|
57
|
+
served on localhost does. The flag is the control that matters there, and the
|
|
58
|
+
kernel invariant is what holds even when the flag is on. `docs/board.md` says
|
|
59
|
+
this in those words rather than claiming a sandbox.
|
|
60
|
+
|
|
61
|
+
### Two things a fresh install could not do
|
|
62
|
+
|
|
63
|
+
Both found by the same study, both reproduced before being believed.
|
|
64
|
+
|
|
65
|
+
- **`board --dir .tyran` crashed on a repo that had been set up and never
|
|
66
|
+
run** — `ENOENT`, naming a temp file nobody had heard of, on the one command
|
|
67
|
+
the README leads with. `.tyran/state/` is created by the first initiative;
|
|
68
|
+
`writeAllAtomic` staged into it and never made it.
|
|
69
|
+
- **A scanned config carried no `limits:` block at all**, so the entire
|
|
70
|
+
Overnight section of the new Settings tab was seven lines of dead text on
|
|
71
|
+
every fresh install — the editor deliberately refuses to invent keys. It is
|
|
72
|
+
now written out in full at the shipped defaults, with the feature off, which
|
|
73
|
+
is the same inert state as omitting it. `doctor`'s `limit-telemetry-missing`
|
|
74
|
+
could never fire before this either, for the same reason.
|
|
75
|
+
|
|
76
|
+
### Four findings from the independent review, fixed before merge
|
|
77
|
+
|
|
78
|
+
- **The editor only worked on two-space indentation.** `yaml-lite` recurses
|
|
79
|
+
with whatever indent the next line has, so a four-space `config.yaml` is
|
|
80
|
+
entirely legal and `validateConfig` accepts it — but the patcher assumed a
|
|
81
|
+
step of 2, so on such a file eleven of the fifteen controls rendered
|
|
82
|
+
**enabled and populated** (the page reads the parsed document) and then
|
|
83
|
+
failed on click with *"is not in this file"*, which was false, and whose
|
|
84
|
+
paired advice told the operator to add a key that was already there. The
|
|
85
|
+
step is now read from the file. The one step that stays fixed is a sequence
|
|
86
|
+
item's siblings at dash + 2, because `- ` is two characters wide and that is
|
|
87
|
+
what `yaml-lite` itself does.
|
|
88
|
+
- **A value the subset cannot spell returned 500.** `formatScalar` throws for
|
|
89
|
+
a newline or an invisible codepoint — ordinary rejected input, someone
|
|
90
|
+
pasting a model name with a stray newline — and it escaped as a server
|
|
91
|
+
fault, complete with a `settings write failed` line in the terminal the docs
|
|
92
|
+
designate as the audit trail. Now a 400, quietly.
|
|
93
|
+
- **The round-trip proof had no test that failed when it was deleted.** The
|
|
94
|
+
reviewer neutered the comparison and the suite stayed green; 2772 fuzzed
|
|
95
|
+
triples fired it zero times, because every wrong case is refused earlier by
|
|
96
|
+
the locator, the comment guard or `formatScalar`. `sameValue` is now
|
|
97
|
+
exported and tested directly — it is the mutable logic the guarantee rests
|
|
98
|
+
on — and the module says plainly that the proof is defence in depth with no
|
|
99
|
+
known reachable input. Two bare `assert.throws` calls gained an error class;
|
|
100
|
+
the missing one is what let the 500 above through.
|
|
101
|
+
- **A wrong number in three places.** `templates/config.yaml` is 90 lines of
|
|
102
|
+
which 63 are comments, not 60 of 91.
|
|
103
|
+
|
|
104
|
+
Also from the review, unprompted: a failure inside the settings renderer was
|
|
105
|
+
being reported as "the board server did not answer", sending the operator to
|
|
106
|
+
restart something that was answering perfectly well.
|
|
107
|
+
|
|
108
|
+
### The sandbox has a Settings tab too
|
|
109
|
+
|
|
110
|
+
`site/scripts/build-sandbox.mjs` runs the real `readSettings` over the shipped
|
|
111
|
+
templates, so the published sample board shows the real defaults, laid out by
|
|
112
|
+
the code an operator's own board runs, read-only and saying which flag would
|
|
113
|
+
make it otherwise.
|
|
114
|
+
|
|
115
|
+
## 0.1.23 — 2026-08-15
|
|
116
|
+
|
|
117
|
+
### The sandbox Spend tab shows spend
|
|
118
|
+
|
|
119
|
+
The published sample board met a reader with an error where the feature should
|
|
120
|
+
have been: no `cost.json` is served beside a static page, and the tab said so
|
|
121
|
+
honestly and uselessly. It now ships one, generated by **`rollup()` itself** —
|
|
122
|
+
the same function the board server calls — from invented transcripts. A
|
|
123
|
+
hand-written payload would render today and drift silently the first time a
|
|
124
|
+
field moved, on the one page whose whole job is to show what the product looks
|
|
125
|
+
like.
|
|
126
|
+
|
|
127
|
+
The numbers are invented and the page says so: the rate card is labelled
|
|
128
|
+
`sample-rates (invented)` and the models are `sample-large` / `sample-small`,
|
|
129
|
+
because **Tyran does not know what anyone pays** and a demo that reads like a
|
|
130
|
+
price list teaches the opposite. A test fails if a real model name appears
|
|
131
|
+
there — the rule that model names live only under `tiers:` has no sandbox
|
|
132
|
+
exemption.
|
|
133
|
+
|
|
134
|
+
What a reader now sees: 4.5 M tokens over 404 requests, 16.97 under that
|
|
135
|
+
invented rate card, a **55% conductor share**, the composition bar at 91%
|
|
136
|
+
cache read, and all three ranked charts with the tokens/cost toggle live.
|
|
137
|
+
|
|
3
138
|
## 0.1.22 — 2026-08-15
|
|
4
139
|
|
|
5
140
|
### A sandbox board you can click, published with the docs
|
package/README.md
CHANGED
|
@@ -184,10 +184,15 @@ npx @jjanczur/tyran board --dir .tyran --serve
|
|
|
184
184
|
```
|
|
185
185
|
|
|
186
186
|
It prints `board: serving http://127.0.0.1:4173/` — **open that URL.** The
|
|
187
|
-
board is
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
187
|
+
board is bound to loopback, re-rendered on every request, and it reloads itself
|
|
188
|
+
every 30 seconds; `--port <n>` if 4173 is taken, `Ctrl-C` to stop. That command
|
|
189
|
+
is the one place a Node version matters, because `npx` runs the scripts outside
|
|
190
|
+
Claude Code and they need **Node ≥ 22**.
|
|
191
|
+
|
|
192
|
+
Add `--write` and the **Settings** tab becomes an editor for `.tyran/config.yaml`
|
|
193
|
+
and the autonomy policy — every knob with a sentence explaining it, your
|
|
194
|
+
comments kept, and loosening a boundary behind a second deliberate press. It is
|
|
195
|
+
read-only without that flag.
|
|
191
196
|
|
|
192
197
|
No terminal, no server: the same page is written to **`.tyran/state/board.html`**
|
|
193
198
|
after every agent, so you can just open the file —
|
|
@@ -252,7 +257,7 @@ enforces the cap (4352 of 5000 characters). What each one assumes, when it
|
|
|
252
257
|
fires and who invokes it, is in
|
|
253
258
|
[skills and agents](https://jjanczur.github.io/tyran/skills/); the prompts
|
|
254
259
|
themselves are in [`skills/`](skills/) and [`agents/`](agents/). Behind all of
|
|
255
|
-
it:
|
|
260
|
+
it: 1314 unit tests, run with `node --test "tests/**/*.test.mjs"`.
|
|
256
261
|
|
|
257
262
|
## Documentation
|
|
258
263
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jjanczur/tyran",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24",
|
|
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": {
|
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;
|
|
@@ -178,6 +179,39 @@ pre.how .c{color:var(--muted)}
|
|
|
178
179
|
.chartrow.dim .rl{color:var(--muted);font-style:italic}
|
|
179
180
|
.chartrow.dim .rb i{background:var(--hairline)}
|
|
180
181
|
.chartrow .rv{font-family:var(--mono);font-variant-numeric:tabular-nums;color:var(--text);min-width:5.5rem;text-align:right}
|
|
182
|
+
|
|
183
|
+
/* ---- settings ---- */
|
|
184
|
+
.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}
|
|
185
|
+
.setnote.warn{border-left-color:var(--brass)}
|
|
186
|
+
.setnote.bad{border-left-color:var(--clay)}
|
|
187
|
+
.setnote b{color:var(--heading);font-weight:600}
|
|
188
|
+
.setnote code{font-family:var(--mono);font-size:.8rem;color:var(--brass-bright);background:var(--brass-low);padding:.08rem .3rem;border-radius:.25rem}
|
|
189
|
+
.sgroup{margin:0 0 1.6rem}
|
|
190
|
+
.sgroup .blurb{font-size:.85rem;color:var(--muted);line-height:1.6;margin:.15rem 0 .9rem;max-width:60rem}
|
|
191
|
+
.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}
|
|
192
|
+
.srow .sname{font-weight:600;color:var(--heading);font-size:.88rem;padding-top:.3rem}
|
|
193
|
+
.srow .sname .sunit{font-family:var(--mono);font-weight:400;color:var(--muted);font-size:.76rem}
|
|
194
|
+
.srow .sbody{min-width:0}
|
|
195
|
+
.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%}
|
|
196
|
+
.srow textarea{font-family:var(--mono);font-size:.8rem;line-height:1.7;min-height:5rem;resize:vertical}
|
|
197
|
+
.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}
|
|
198
|
+
.srow select:focus-visible,.srow input:focus-visible,.srow textarea:focus-visible{outline:2px solid var(--steel);outline-offset:1px}
|
|
199
|
+
.srow select:disabled,.srow input:disabled,.srow textarea:disabled{opacity:.55;cursor:not-allowed}
|
|
200
|
+
.srow .shelp{font-size:.8rem;color:var(--muted);line-height:1.6;margin-top:.35rem;max-width:52rem}
|
|
201
|
+
.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)}
|
|
202
|
+
.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}
|
|
203
|
+
.sstat.ok{color:var(--sage-bright)}
|
|
204
|
+
.sstat.bad{color:var(--clay-bright)}
|
|
205
|
+
.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}
|
|
206
|
+
.sbtn:hover:not(:disabled){background:var(--brass-edge)}
|
|
207
|
+
.sbtn:disabled{opacity:.5;cursor:not-allowed}
|
|
208
|
+
.sbtn.danger{background:var(--clay-low);color:var(--clay-bright);border-color:var(--clay-edge);margin-top:.5rem}
|
|
209
|
+
.sbtn.danger:hover:not(:disabled){background:var(--clay-edge);color:var(--heading)}
|
|
210
|
+
.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}
|
|
211
|
+
.rule .glob{font-family:var(--mono);font-size:.82rem;color:var(--heading);word-break:break-all}
|
|
212
|
+
.rule .why{font-size:.78rem;color:var(--muted);line-height:1.6;grid-column:1;max-width:52rem}
|
|
213
|
+
.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}
|
|
214
|
+
.rule .sstat{grid-column:1 / -1}
|
|
181
215
|
.caveat{color:var(--muted);font-size:.76rem;margin-top:.5rem;max-width:52rem}
|
|
182
216
|
footer{margin-top:2rem;color:var(--muted);font-size:.72rem;border-top:1px solid var(--hairline-soft);padding-top:.6rem}
|
|
183
217
|
`;
|
|
@@ -301,6 +335,7 @@ if (data.schema !== 1) {
|
|
|
301
335
|
['board', 'Board', null],
|
|
302
336
|
['questions', 'Waiting on you', asks.length],
|
|
303
337
|
['spend', 'Spend', null],
|
|
338
|
+
['settings', 'Settings', null],
|
|
304
339
|
];
|
|
305
340
|
var select = function (key) {
|
|
306
341
|
for (var i = 0; i < TABS.length; i += 1) {
|
|
@@ -779,6 +814,301 @@ if (data.schema !== 1) {
|
|
|
779
814
|
});
|
|
780
815
|
}
|
|
781
816
|
|
|
817
|
+
// ---- settings ---------------------------------------------------------
|
|
818
|
+
//
|
|
819
|
+
// The one tab that writes. Everything else on this page is a projection of
|
|
820
|
+
// the journal and hand-editing it would be drift; config and the autonomy
|
|
821
|
+
// policy are the opposite — operator-owned files that nothing generates, and
|
|
822
|
+
// the only place they could be changed until now was an editor and a memory
|
|
823
|
+
// of what each key meant.
|
|
824
|
+
//
|
|
825
|
+
// Served, never embedded, exactly like spend: these are not journal state,
|
|
826
|
+
// so writing them into board.json would break the byte-exact check and make
|
|
827
|
+
// two clones of one journal disagree.
|
|
828
|
+
var st = panels.settings;
|
|
829
|
+
var stBody = el('div');
|
|
830
|
+
st.appendChild(stBody);
|
|
831
|
+
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.'));
|
|
832
|
+
|
|
833
|
+
// A meta refresh and a form are incompatible: half a typed model name would
|
|
834
|
+
// vanish every thirty seconds. The tag stays in the HTML (a page whose JS
|
|
835
|
+
// never runs still refreshes, and the docs sandbox strips the tag to stop
|
|
836
|
+
// itself reloading), but at boot it is swapped for a timer that can be
|
|
837
|
+
// paused — and the Settings tab pauses it. Present tag, same 30 seconds;
|
|
838
|
+
// absent tag, no timer at all, which is what the sandbox wants.
|
|
839
|
+
var refreshTag = document.querySelector('meta[http-equiv="refresh"]');
|
|
840
|
+
var refreshTimer = null;
|
|
841
|
+
var armRefresh = function () {
|
|
842
|
+
if (refreshTag === null || refreshTimer !== null) return;
|
|
843
|
+
refreshTimer = setTimeout(function () { location.reload(); }, 30000);
|
|
844
|
+
};
|
|
845
|
+
var holdRefresh = function () {
|
|
846
|
+
if (refreshTimer !== null) { clearTimeout(refreshTimer); refreshTimer = null; }
|
|
847
|
+
};
|
|
848
|
+
if (refreshTag !== null && refreshTag.parentNode) {
|
|
849
|
+
refreshTag.parentNode.removeChild(refreshTag);
|
|
850
|
+
armRefresh();
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
var post = function (route, body, status, onDone) {
|
|
854
|
+
status.className = 'sstat';
|
|
855
|
+
status.textContent = 'saving\\u2026';
|
|
856
|
+
fetch(route, {
|
|
857
|
+
method: 'POST',
|
|
858
|
+
headers: { 'content-type': 'application/json' },
|
|
859
|
+
body: JSON.stringify(body)
|
|
860
|
+
}).then(function (r) {
|
|
861
|
+
return r.json().then(function (payload) { return { ok: r.ok, payload: payload }; });
|
|
862
|
+
}).then(function (result) {
|
|
863
|
+
var payload = result.payload || {};
|
|
864
|
+
if (!result.ok || payload.ok !== true) {
|
|
865
|
+
status.className = 'sstat bad';
|
|
866
|
+
status.textContent = show(payload.error || 'the change was refused');
|
|
867
|
+
// A refusal the operator can answer, rather than one they can only
|
|
868
|
+
// read. The server sends back the exact token that answers it, and
|
|
869
|
+
// pressing this re-sends the same change carrying that token — which
|
|
870
|
+
// is why nothing here decides what "confirmed" means.
|
|
871
|
+
if (payload.widens === true && typeof payload.confirm_with === 'string') {
|
|
872
|
+
var go = el('button', 'sbtn danger', 'Yes \\u2014 loosen it');
|
|
873
|
+
go.setAttribute('type', 'button');
|
|
874
|
+
go.addEventListener('click', function () {
|
|
875
|
+
var again = {};
|
|
876
|
+
Object.keys(body).forEach(function (k) { again[k] = body[k]; });
|
|
877
|
+
again.confirm = payload.confirm_with;
|
|
878
|
+
post(route, again, status, onDone);
|
|
879
|
+
});
|
|
880
|
+
status.appendChild(document.createElement('br'));
|
|
881
|
+
status.appendChild(go);
|
|
882
|
+
}
|
|
883
|
+
if (onDone) onDone(false);
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
status.className = 'sstat ok';
|
|
887
|
+
status.textContent = show('saved \\u2014 ' + JSON.stringify(payload.before) + ' \\u2192 ' + JSON.stringify(payload.after));
|
|
888
|
+
if (onDone) onDone(true);
|
|
889
|
+
}).catch(function () {
|
|
890
|
+
status.className = 'sstat bad';
|
|
891
|
+
status.textContent = 'the board server did not answer \\u2014 nothing was written';
|
|
892
|
+
if (onDone) onDone(false);
|
|
893
|
+
});
|
|
894
|
+
};
|
|
895
|
+
|
|
896
|
+
var settingRow = function (setting, writable) {
|
|
897
|
+
var row = el('div', 'srow');
|
|
898
|
+
var name = el('div', 'sname', setting.label);
|
|
899
|
+
if (setting.unit) name.appendChild(el('span', 'sunit', ' ' + setting.unit));
|
|
900
|
+
row.appendChild(name);
|
|
901
|
+
var bodyCell = el('div', 'sbody');
|
|
902
|
+
row.appendChild(bodyCell);
|
|
903
|
+
|
|
904
|
+
var status = el('div', 'sstat');
|
|
905
|
+
var choiceNote = null;
|
|
906
|
+
var control = null;
|
|
907
|
+
|
|
908
|
+
if (setting.present !== true) {
|
|
909
|
+
// Absent is not the same as unset, and saying so beats an empty box: a
|
|
910
|
+
// key that is not in the file has no line for the patcher to edit, and
|
|
911
|
+
// inventing one means choosing where it goes and what comment explains
|
|
912
|
+
// it. That is authoring, and it stays a hand edit.
|
|
913
|
+
bodyCell.appendChild(el('div', 'shelp', 'Not set in this config. Add the key by hand once and it becomes editable here.'));
|
|
914
|
+
bodyCell.appendChild(el('div', 'shelp', setting.help));
|
|
915
|
+
return row;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
if (setting.kind === 'choice') {
|
|
919
|
+
control = el('select');
|
|
920
|
+
setting.choices.forEach(function (c) {
|
|
921
|
+
var option = el('option', null, c.value);
|
|
922
|
+
option.value = c.value;
|
|
923
|
+
if (c.value === setting.value) option.selected = true;
|
|
924
|
+
control.appendChild(option);
|
|
925
|
+
});
|
|
926
|
+
choiceNote = el('div', 'schoice');
|
|
927
|
+
var describe = function () {
|
|
928
|
+
var picked = setting.choices.filter(function (c) { return c.value === control.value; })[0];
|
|
929
|
+
choiceNote.textContent = show(picked ? picked.describe : '');
|
|
930
|
+
};
|
|
931
|
+
describe();
|
|
932
|
+
control.addEventListener('change', function () {
|
|
933
|
+
describe();
|
|
934
|
+
post('/settings/config', { id: setting.id, value: control.value }, status);
|
|
935
|
+
});
|
|
936
|
+
} else if (setting.kind === 'boolean') {
|
|
937
|
+
control = el('select');
|
|
938
|
+
[['false', 'off'], ['true', 'on']].forEach(function (pair) {
|
|
939
|
+
var option = el('option', null, pair[1]);
|
|
940
|
+
option.value = pair[0];
|
|
941
|
+
if ((pair[0] === 'true') === (setting.value === true)) option.selected = true;
|
|
942
|
+
control.appendChild(option);
|
|
943
|
+
});
|
|
944
|
+
control.addEventListener('change', function () {
|
|
945
|
+
post('/settings/config', { id: setting.id, value: control.value === 'true' }, status);
|
|
946
|
+
});
|
|
947
|
+
} else if (setting.kind === 'number') {
|
|
948
|
+
control = el('input');
|
|
949
|
+
control.type = 'number';
|
|
950
|
+
control.value = String(setting.value);
|
|
951
|
+
if (setting.min !== null) control.min = String(setting.min);
|
|
952
|
+
if (setting.max !== null) control.max = String(setting.max);
|
|
953
|
+
control.addEventListener('change', function () {
|
|
954
|
+
post('/settings/config', { id: setting.id, value: Number(control.value) }, status);
|
|
955
|
+
});
|
|
956
|
+
} else if (setting.kind === 'list') {
|
|
957
|
+
control = el('textarea');
|
|
958
|
+
control.value = (setting.value || []).join('\\n');
|
|
959
|
+
if (setting.placeholder) control.placeholder = setting.placeholder + '\\n(one per line)';
|
|
960
|
+
} else {
|
|
961
|
+
control = el('input');
|
|
962
|
+
control.type = 'text';
|
|
963
|
+
control.value = String(setting.value === null ? '' : setting.value);
|
|
964
|
+
if (setting.placeholder) control.placeholder = setting.placeholder;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
control.disabled = !writable;
|
|
968
|
+
bodyCell.appendChild(control);
|
|
969
|
+
|
|
970
|
+
// Discrete controls save the moment they change; free text does not,
|
|
971
|
+
// because there is no moment during typing that is the whole value.
|
|
972
|
+
if (setting.kind === 'list' || setting.kind === 'text') {
|
|
973
|
+
var save = el('button', 'sbtn', 'Save');
|
|
974
|
+
save.setAttribute('type', 'button');
|
|
975
|
+
save.disabled = !writable;
|
|
976
|
+
control.addEventListener('input', holdRefresh);
|
|
977
|
+
save.addEventListener('click', function () {
|
|
978
|
+
var value = setting.kind === 'list'
|
|
979
|
+
? control.value.split('\\n').map(function (line) { return line.trim(); }).filter(function (line) { return line !== ''; })
|
|
980
|
+
: control.value;
|
|
981
|
+
post('/settings/config', { id: setting.id, value: value }, status, function (ok) { if (ok) armRefresh(); });
|
|
982
|
+
});
|
|
983
|
+
bodyCell.appendChild(save);
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
if (choiceNote) bodyCell.appendChild(choiceNote);
|
|
987
|
+
bodyCell.appendChild(el('div', 'shelp', setting.help));
|
|
988
|
+
bodyCell.appendChild(status);
|
|
989
|
+
return row;
|
|
990
|
+
};
|
|
991
|
+
|
|
992
|
+
// The address is what the write route is told to change, and it is NOT the
|
|
993
|
+
// label: the file's own default key is addressed as null, while a rule is
|
|
994
|
+
// addressed by its path glob. By glob and not by position, so that a file
|
|
995
|
+
// edited underneath an open page cannot land the write on a neighbouring
|
|
996
|
+
// boundary — the server re-resolves the glob against the file as it is now.
|
|
997
|
+
var ruleRow = function (rule, classes, describe, writable, address) {
|
|
998
|
+
var row = el('div', 'rule');
|
|
999
|
+
row.appendChild(el('div', 'glob', rule.path));
|
|
1000
|
+
var status = el('div', 'sstat');
|
|
1001
|
+
if (rule.locked) {
|
|
1002
|
+
var lock = el('div', 'lock', rule.class + ' \\u00b7 locked');
|
|
1003
|
+
lock.title = 'This path protects the gate itself and cannot be lowered.';
|
|
1004
|
+
row.appendChild(lock);
|
|
1005
|
+
} else {
|
|
1006
|
+
var pick = el('select');
|
|
1007
|
+
classes.forEach(function (klass) {
|
|
1008
|
+
var option = el('option', null, klass);
|
|
1009
|
+
option.value = klass;
|
|
1010
|
+
if (klass === rule.class) option.selected = true;
|
|
1011
|
+
pick.appendChild(option);
|
|
1012
|
+
});
|
|
1013
|
+
pick.disabled = !writable;
|
|
1014
|
+
pick.addEventListener('change', function () {
|
|
1015
|
+
post('/settings/policy', { path: address, class: pick.value }, status);
|
|
1016
|
+
});
|
|
1017
|
+
row.appendChild(pick);
|
|
1018
|
+
}
|
|
1019
|
+
if (rule.reason) row.appendChild(el('div', 'why', rule.reason));
|
|
1020
|
+
else if (rule.locked) row.appendChild(el('div', 'why', describe[rule.class] || ''));
|
|
1021
|
+
row.appendChild(status);
|
|
1022
|
+
return row;
|
|
1023
|
+
};
|
|
1024
|
+
|
|
1025
|
+
var renderSettings = function (payload) {
|
|
1026
|
+
clear(stBody);
|
|
1027
|
+
var writable = payload.writable === true;
|
|
1028
|
+
var note = el('div', writable ? 'setnote' : 'setnote warn');
|
|
1029
|
+
if (writable) {
|
|
1030
|
+
note.appendChild(el('b', null, 'Changes are written straight to disk.'));
|
|
1031
|
+
note.appendChild(el('span', null,
|
|
1032
|
+
' 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.'));
|
|
1033
|
+
} else {
|
|
1034
|
+
note.appendChild(el('b', null, 'Read-only.'));
|
|
1035
|
+
note.appendChild(el('span', null, ' This board was started without editing. To turn these controls on, restart it with: '));
|
|
1036
|
+
note.appendChild(el('code', null, 'npx @jjanczur/tyran board --dir .tyran --serve --write'));
|
|
1037
|
+
}
|
|
1038
|
+
stBody.appendChild(note);
|
|
1039
|
+
|
|
1040
|
+
[['config', payload.files.config], ['policy', payload.files.policy]].forEach(function (pair) {
|
|
1041
|
+
if (pair[1].present && pair[1].error === null) return;
|
|
1042
|
+
var bad = el('div', 'setnote bad');
|
|
1043
|
+
bad.appendChild(el('b', null, pair[1].present ? 'This file does not parse: ' : 'This file is missing: '));
|
|
1044
|
+
bad.appendChild(el('span', null, pair[1].path + (pair[1].error ? ' \\u2014 ' + pair[1].error : '')));
|
|
1045
|
+
stBody.appendChild(bad);
|
|
1046
|
+
});
|
|
1047
|
+
|
|
1048
|
+
payload.groups.forEach(function (group) {
|
|
1049
|
+
var box = el('div', 'sgroup');
|
|
1050
|
+
box.appendChild(el('h2', null, group.title));
|
|
1051
|
+
box.appendChild(el('div', 'blurb', group.blurb));
|
|
1052
|
+
group.settings.forEach(function (setting) { box.appendChild(settingRow(setting, writable)); });
|
|
1053
|
+
stBody.appendChild(box);
|
|
1054
|
+
});
|
|
1055
|
+
|
|
1056
|
+
var policy = payload.policy || {};
|
|
1057
|
+
var pol = el('div', 'sgroup');
|
|
1058
|
+
pol.appendChild(el('h2', null, 'Autonomy policy'));
|
|
1059
|
+
pol.appendChild(el('div', 'blurb',
|
|
1060
|
+
'Which paths agents may write on their own. The most specific matching rule wins, and a path no rule matches gets the default. ' +
|
|
1061
|
+
(policy.classes || []).map(function (k) { return k + ' \\u2014 ' + (policy.describe || {})[k]; }).join(' \\u00b7 ')));
|
|
1062
|
+
if (policy.default !== null && policy.default !== undefined) {
|
|
1063
|
+
pol.appendChild(ruleRow(
|
|
1064
|
+
{ path: 'default \\u2014 everything no rule matches', class: policy.default, reason: 'GATED is the safe answer: it means "ask me".', locked: false },
|
|
1065
|
+
policy.classes || [], policy.describe || {}, writable, null));
|
|
1066
|
+
}
|
|
1067
|
+
(policy.rules || []).forEach(function (rule) {
|
|
1068
|
+
pol.appendChild(ruleRow(rule, policy.classes || [], policy.describe || {}, writable, rule.path));
|
|
1069
|
+
});
|
|
1070
|
+
stBody.appendChild(pol);
|
|
1071
|
+
};
|
|
1072
|
+
|
|
1073
|
+
// Leaving this tab re-arms the refresh, entering it stops it. A page that
|
|
1074
|
+
// reloads under an open select is a page that loses the change you were
|
|
1075
|
+
// halfway through making, and the board has three other tabs that want to
|
|
1076
|
+
// stay live.
|
|
1077
|
+
Object.keys(buttons).forEach(function (key) {
|
|
1078
|
+
buttons[key].addEventListener('click', function () {
|
|
1079
|
+
if (key === 'settings') holdRefresh(); else armRefresh();
|
|
1080
|
+
});
|
|
1081
|
+
});
|
|
1082
|
+
|
|
1083
|
+
fetch('settings.json', { headers: { accept: 'application/json' } })
|
|
1084
|
+
.then(function (r) { return r.ok ? r.json() : Promise.reject(new Error(String(r.status))); })
|
|
1085
|
+
.then(function (payload) {
|
|
1086
|
+
if (payload.schema !== 1) {
|
|
1087
|
+
clear(stBody);
|
|
1088
|
+
stBody.appendChild(el('div', 'setnote bad', 'Settings were served in a format this page does not know (schema ' +
|
|
1089
|
+
(payload.schema || 'absent') + ') \\u2014 regenerate the board with the Tyran that served it.'));
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
// A failure INSIDE the renderer is not a failure to reach the server,
|
|
1093
|
+
// and reporting it as one sends the operator to restart something that
|
|
1094
|
+
// was answering perfectly well. Caught here so the outer handler keeps
|
|
1095
|
+
// its one meaning: the fetch did not land.
|
|
1096
|
+
try {
|
|
1097
|
+
renderSettings(payload);
|
|
1098
|
+
} catch (err) {
|
|
1099
|
+
clear(stBody);
|
|
1100
|
+
stBody.appendChild(el('div', 'setnote bad',
|
|
1101
|
+
'Settings were served but this page could not draw them: ' + show(String((err && err.message) || err)) +
|
|
1102
|
+
' \\u2014 the board and the Tyran that served it are probably different versions.'));
|
|
1103
|
+
}
|
|
1104
|
+
})
|
|
1105
|
+
.catch(function () {
|
|
1106
|
+
if (String(location.protocol) === 'file:') return;
|
|
1107
|
+
clear(stBody);
|
|
1108
|
+
stBody.appendChild(el('div', 'setnote bad',
|
|
1109
|
+
'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'));
|
|
1110
|
+
});
|
|
1111
|
+
|
|
782
1112
|
select('overview');
|
|
783
1113
|
|
|
784
1114
|
var foot = el('footer');
|