kryptheon 0.1.68 → 0.1.69

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.
@@ -878,7 +878,10 @@
878
878
  // The latest re-check, on the finding itself: still open, or newly
879
879
  // broken by a fix for something else.
880
880
  var latest = (f.attempts || [])[f.attempts ? f.attempts.length - 1 : 0];
881
- if (latest) meta.appendChild(el('span', 'tag ' + (VERDICT_TONE[latest.verdict] || ''), (VERDICT_WORDS[latest.verdict] || latest.verdict) + ' ' + ago(latest.at)));
881
+ // A FIXED re-check older than the check that found it again is not the answer any more.
882
+ var foundAgain = latest && latest.verdict === 'fixed' && f.when && String(f.when) > String(latest.at);
883
+ if (foundAgain) meta.appendChild(el('span', 'tag ember', 'FOUND AGAIN ' + ago(f.when) + ' (after a fix ' + ago(latest.at) + ')'));
884
+ else if (latest) meta.appendChild(el('span', 'tag ' + (VERDICT_TONE[latest.verdict] || ''), (VERDICT_WORDS[latest.verdict] || latest.verdict) + ' ' + ago(latest.at)));
882
885
  if (newlyBroken.indexOf(f.id) !== -1) meta.appendChild(el('span', 'tag ember', 'NEWLY BROKEN'));
883
886
  meta.appendChild(el('span', 'f-where', f.where));
884
887
  left.appendChild(meta);
@@ -1285,8 +1288,60 @@
1285
1288
  : 'Switch it on and this dashboard starts by itself every time you sign in to Windows, in a small window on the taskbar. Nothing opens - it just watches for changes. Switch it off here any time.'));
1286
1289
  row.appendChild(text);
1287
1290
  box.appendChild(row);
1291
+ renderDaily(box);
1288
1292
  box.appendChild(el('div', 'keep-off', 'With the laptop off, nothing on it can run. The nightly database check is different: once set up in Start here, it runs inside your database itself, and its result is waiting the next time you open this page.'));
1289
1293
  }
1294
+ // The daily check's controls: made once, so the page's refresh never undoes a time being typed.
1295
+ var dailyTime = el('input');
1296
+ dailyTime.type = 'time';
1297
+ dailyTime.setAttribute('aria-label', 'Time of the daily check');
1298
+ var dailyData = el('input');
1299
+ dailyData.type = 'checkbox';
1300
+ dailyData.setAttribute('aria-label', 'Include the checks that add test data');
1301
+ var dailyDirty = false;
1302
+ dailyTime.addEventListener('input', function () { dailyDirty = true; });
1303
+ function saveDaily(on, input) {
1304
+ post('/api/daily', { on: on, at: dailyTime.value || '09:00', addsData: dailyData.checked }).then(function (r) {
1305
+ dailyDirty = false;
1306
+ toast(on ? 'On: Check my app runs by itself every day at ' + r.daily.at + ' while your laptop is on' : 'Off: no daily check');
1307
+ return load();
1308
+ }).catch(function (err) { if (input) input.checked = !on; toast('Not saved: ' + err.message); });
1309
+ }
1310
+ function renderDaily(box) {
1311
+ var d = state.daily || { on: false, at: '09:00', addsData: false };
1312
+ if (!dailyDirty && document.activeElement !== dailyTime) dailyTime.value = d.at;
1313
+ if (document.activeElement !== dailyData) dailyData.checked = !!d.addsData;
1314
+ var row = el('div', 'keep-row');
1315
+ var sw = el('label', 'switch');
1316
+ var input = el('input');
1317
+ input.type = 'checkbox';
1318
+ input.checked = !!d.on;
1319
+ input.setAttribute('aria-label', 'Check my app every day');
1320
+ input.addEventListener('change', function () { saveDaily(input.checked, input); });
1321
+ sw.appendChild(input);
1322
+ sw.appendChild(el('span', 'track'));
1323
+ row.appendChild(sw);
1324
+ var text = el('div', 'keep-text');
1325
+ var title = el('b', null, 'Check my app every day ');
1326
+ title.appendChild(el('span', 'tag ' + (d.on ? 'leaf' : ''), d.on ? 'on' : 'off'));
1327
+ text.appendChild(title);
1328
+ text.appendChild(el('span', null, 'At this time, while your laptop is on and this dashboard runs, the same checks as Check my app run by themselves, and a note in the corner of your screen says what is new and what got fixed. Your app has to be running too.'));
1329
+ var when = el('div', 'setup-row');
1330
+ when.appendChild(el('span', null, 'Every day at'));
1331
+ when.appendChild(dailyTime);
1332
+ when.appendChild(button('sm', 'check', 'Save the time', function () { saveDaily(true, null); }));
1333
+ text.appendChild(when);
1334
+ var dl = el('label', 'tick setup-row');
1335
+ dl.appendChild(dailyData);
1336
+ dl.appendChild(document.createTextNode(' Include the checks that add test data (API, edge, reliability, roles) - only if this app is a test copy'));
1337
+ dailyData.onchange = function () { if (d.on) saveDaily(true, null); };
1338
+ text.appendChild(dl);
1339
+ if (d.next) text.appendChild(el('div', 'fallback', 'Next: ' + new Date(d.next).toLocaleString()));
1340
+ if (d.last && d.last.note) text.appendChild(el('div', 'fallback', 'Last (' + new Date(d.last.at).toLocaleString() + '): ' + d.last.note.title + ' - ' + d.last.note.body));
1341
+ row.appendChild(text);
1342
+ box.appendChild(row);
1343
+ }
1344
+
1290
1345
  function setAutostart(on, input) {
1291
1346
  post('/api/autostart', { on: on }).then(function () {
1292
1347
  toast(on ? 'On: it starts by itself when you sign in to Windows' : 'Off: it no longer starts by itself');
@@ -1489,6 +1544,212 @@
1489
1544
  }
1490
1545
  }
1491
1546
 
1547
+ /* --------------------------- who may do what, who signs in --------------------------- */
1548
+
1549
+ // Drawn only when asked for, and redrawn only after a save: the page's own refresh every few seconds must never
1550
+ // undo a tick the person has just made.
1551
+ var setupAdd = [];
1552
+ function setupStart() {
1553
+ var who = byId('whoBox');
1554
+ var sign = byId('signBox');
1555
+ if (!who || !sign || who.firstChild) return;
1556
+ who.appendChild(el('p', 'setup-note', 'Kryptheon reads from your code everything your app does, and which roles your code lets do it. Tick who SHOULD be able to do each thing - the roles check then tries every one as each role and tells you where your app does something else.'));
1557
+ who.appendChild(button('sun', 'list', 'Answer the questions', function () { loadSetup(); }));
1558
+ sign.appendChild(el('p', 'setup-note', 'To check your app as each kind of user, Kryptheon signs in as test accounts of your app. Add them here once.'));
1559
+ sign.appendChild(button('', 'list', 'Add test accounts', function () { loadSetup(); }));
1560
+ }
1561
+ function loadSetup() {
1562
+ return fetch('/api/setup' + (setupAdd.length ? '?add=' + encodeURIComponent(setupAdd.join(',')) : ''), { cache: 'no-store' })
1563
+ .then(function (res) { return res.json(); })
1564
+ .then(function (q) { renderWho(q); renderSign(q); })
1565
+ .catch(function (err) { toast('Could not read your app: ' + err.message); });
1566
+ }
1567
+ function renderWho(q) {
1568
+ var box = byId('whoBox');
1569
+ clear(box);
1570
+ if (!q.ran) { box.appendChild(el('p', 'setup-note', 'Could not read your code: ' + q.why)); return; }
1571
+ var open = q.rows.filter(function (r) { return r.everyone; }).length;
1572
+ box.appendChild(el('p', 'setup-note', q.policy.exists
1573
+ ? 'Your answers are already saved. Change any tick and save again.'
1574
+ : 'Ticked = what your code allows today. ' + (open ? open + ' things have no role check in your code at all (orange): every signed-in person can do them. Untick the roles that should not.' : '')));
1575
+ var table = el('table', 'who');
1576
+ var head = el('tr');
1577
+ head.appendChild(el('th', null, 'What your app does'));
1578
+ q.roles.forEach(function (r) { head.appendChild(el('th', null, r)); });
1579
+ table.appendChild(head);
1580
+ var boxes = {};
1581
+ q.rows.forEach(function (row) {
1582
+ var tr = el('tr', row.everyone ? 'open-to-all' : null);
1583
+ var what = el('td', 'what');
1584
+ what.appendChild(document.createTextNode(row.label));
1585
+ what.appendChild(el('small', null, row.routes.join(' · ')));
1586
+ if (row.everyone) what.appendChild(el('span', 'warn', 'No role check in your code - anyone signed in can do this'));
1587
+ tr.appendChild(what);
1588
+ boxes[row.permission] = {};
1589
+ q.roles.forEach(function (r) {
1590
+ var td = el('td');
1591
+ var c = el('input');
1592
+ c.type = 'checkbox';
1593
+ c.checked = row.allowed.indexOf(r) >= 0;
1594
+ c.setAttribute('aria-label', r + ' may ' + row.label);
1595
+ boxes[row.permission][r] = c;
1596
+ td.appendChild(c);
1597
+ tr.appendChild(td);
1598
+ });
1599
+ table.appendChild(tr);
1600
+ });
1601
+ var tableWrap = el('div', 'who-wrap');
1602
+ tableWrap.appendChild(table);
1603
+ box.appendChild(tableWrap);
1604
+
1605
+ var addRow = el('div', 'setup-row');
1606
+ var addInput = el('input');
1607
+ addInput.type = 'text';
1608
+ addInput.placeholder = 'Another role your app has, like viewer';
1609
+ addInput.setAttribute('aria-label', 'Another role');
1610
+ addRow.appendChild(addInput);
1611
+ addRow.appendChild(button('sm', 'arrow', 'Add this role', function () {
1612
+ var v = addInput.value.trim();
1613
+ if (!/^[A-Za-z][A-Za-z0-9_ -]{0,39}$/.test(v)) { toast('A role is a short name, like viewer'); return; }
1614
+ if (setupAdd.indexOf(v) < 0) setupAdd.push(v);
1615
+ loadSetup();
1616
+ }));
1617
+ box.appendChild(addRow);
1618
+
1619
+ var tenantLabel = el('label', 'tick setup-row');
1620
+ var tenant = el('input');
1621
+ tenant.type = 'checkbox';
1622
+ tenant.checked = q.tenants.now === null ? q.tenants.suggested : q.tenants.now;
1623
+ tenantLabel.appendChild(tenant);
1624
+ tenantLabel.appendChild(document.createTextNode(' My app has more than one company or team, and one must never see or change another\'s records'));
1625
+ box.appendChild(tenantLabel);
1626
+
1627
+ var grants = {};
1628
+ if (q.grants.routes.length) {
1629
+ box.appendChild(el('p', 'setup-note', 'Your app gives people roles (' + q.grants.routes.join(', ') + '). Which roles may each role give?'));
1630
+ // by default only the roles the code lets use the route that gives roles may give any, and only roles below them
1631
+ var granters = [];
1632
+ q.rows.forEach(function (row) {
1633
+ if (row.routes.some(function (rt) { return q.grants.routes.indexOf(rt) >= 0; })) row.allowed.forEach(function (r) { if (granters.indexOf(r) < 0) granters.push(r); });
1634
+ });
1635
+ var gt = el('table', 'who');
1636
+ var gh = el('tr');
1637
+ gh.appendChild(el('th', null, 'This role may give'));
1638
+ q.roles.forEach(function (r) { gh.appendChild(el('th', null, r)); });
1639
+ gt.appendChild(gh);
1640
+ q.roles.forEach(function (giver, gi) {
1641
+ var tr = el('tr');
1642
+ tr.appendChild(el('td', null, giver));
1643
+ grants[giver] = {};
1644
+ q.roles.forEach(function (r, ri) {
1645
+ var td = el('td');
1646
+ var c = el('input');
1647
+ c.type = 'checkbox';
1648
+ var saved = q.grants.rules && q.grants.rules[giver];
1649
+ c.checked = saved ? saved.indexOf(r) >= 0 : granters.indexOf(giver) >= 0 && ri > gi;
1650
+ c.setAttribute('aria-label', giver + ' may give ' + r);
1651
+ grants[giver][r] = c;
1652
+ td.appendChild(c);
1653
+ tr.appendChild(td);
1654
+ });
1655
+ gt.appendChild(tr);
1656
+ });
1657
+ var gtWrap = el('div', 'who-wrap');
1658
+ gtWrap.appendChild(gt);
1659
+ box.appendChild(gtWrap);
1660
+ }
1661
+
1662
+ var saveRow = el('div', 'setup-row');
1663
+ var replace = null;
1664
+ if (q.policy.exists) {
1665
+ var rl = el('label', 'tick');
1666
+ replace = el('input');
1667
+ replace.type = 'checkbox';
1668
+ rl.appendChild(replace);
1669
+ rl.appendChild(document.createTextNode(' Replace my permissions-policy.json with these answers'));
1670
+ saveRow.appendChild(rl);
1671
+ }
1672
+ saveRow.appendChild(button('sun', 'check', 'Save who may do what', function () {
1673
+ var allow = {};
1674
+ Object.keys(boxes).forEach(function (p) { allow[p] = q.roles.filter(function (r) { return boxes[p][r].checked; }); });
1675
+ var g = {};
1676
+ Object.keys(grants).forEach(function (giver) { g[giver] = q.roles.filter(function (r) { return grants[giver][r].checked; }); });
1677
+ post('/api/setup/policy', { roles: q.roles, allow: allow, tenants: tenant.checked, grants: g, replace: replace ? replace.checked : false })
1678
+ .then(function () { toast('Saved as permissions-policy.json. The roles check now judges your app by it.'); load(); loadSetup(); },
1679
+ function (err) { toast(err.message); });
1680
+ }));
1681
+ box.appendChild(saveRow);
1682
+ }
1683
+ function renderSign(q) {
1684
+ var box = byId('signBox');
1685
+ clear(box);
1686
+ if (!q.ran) return;
1687
+ var a = q.accounts;
1688
+ var inputs = [];
1689
+ if (a.mode === 'password') {
1690
+ box.appendChild(el('p', 'setup-note', 'Your app signs people in at ' + a.signIn + '. These are the accounts your project names - give each one\'s password (a test account, never a real customer\'s).'));
1691
+ if (!a.list.length) box.appendChild(el('p', 'setup-note', 'Your project names no account yet. Write your test accounts\' emails in your README, then come back.'));
1692
+ a.list.forEach(function (acc) {
1693
+ var row = el('div', 'setup-row');
1694
+ row.appendChild(el('span', null, acc.name));
1695
+ if (acc.set) { row.appendChild(el('span', 'fallback', 'saved in .env')); box.appendChild(row); return; }
1696
+ var pw = el('input');
1697
+ pw.type = 'password';
1698
+ pw.autocomplete = 'off';
1699
+ pw.placeholder = 'its password';
1700
+ pw.setAttribute('aria-label', 'Password of ' + acc.name);
1701
+ inputs.push({ envName: acc.envName, input: pw });
1702
+ row.appendChild(pw);
1703
+ box.appendChild(row);
1704
+ });
1705
+ } else {
1706
+ box.appendChild(el('p', 'setup-note', a.why ? 'Your app has no email-and-password sign-in, so Kryptheon signs in with a token per account (sent as Authorization: Bearer). Add one for each kind of user - at least two, of two different companies if your app has them.' : 'Accounts that sign in with a token:'));
1707
+ a.list.forEach(function (acc) {
1708
+ var row = el('div', 'setup-row');
1709
+ row.appendChild(el('span', null, acc.name));
1710
+ row.appendChild(el('span', 'fallback', 'saved in .env'));
1711
+ box.appendChild(row);
1712
+ });
1713
+ var addOne = function () {
1714
+ var row = el('div', 'setup-row');
1715
+ var name = el('input');
1716
+ name.type = 'text';
1717
+ name.placeholder = 'a name, like Acme owner';
1718
+ name.setAttribute('aria-label', 'Account name');
1719
+ var tok = el('input');
1720
+ tok.type = 'password';
1721
+ tok.autocomplete = 'off';
1722
+ tok.placeholder = 'its token';
1723
+ tok.setAttribute('aria-label', 'Token');
1724
+ inputs.push({ name: name, input: tok });
1725
+ row.appendChild(name);
1726
+ row.appendChild(tok);
1727
+ box.insertBefore(row, saveRow);
1728
+ };
1729
+ var more = button('sm', 'arrow', 'Another account', addOne);
1730
+ box.appendChild(more);
1731
+ }
1732
+ var saveRow = el('div', 'setup-row');
1733
+ saveRow.appendChild(button('sun', 'check', 'Save to .env', function () {
1734
+ var entries = inputs.filter(function (x) { return x.input.value.trim(); }).map(function (x) {
1735
+ return x.envName ? { envName: x.envName, value: x.input.value } : { label: x.name.value.trim(), value: x.input.value };
1736
+ });
1737
+ if (!entries.length) { toast('Nothing to save yet.'); return; }
1738
+ post('/api/setup/accounts', { entries: entries }).then(function (r) {
1739
+ inputs.forEach(function (x) { x.input.value = ''; });
1740
+ toast((r.written.length ? 'Added ' + r.written.length + ' to .env.' : 'Nothing new.') + (r.kept.length ? ' Already there, left as it is: ' + r.kept.length + '.' : ''));
1741
+ load();
1742
+ loadSetup();
1743
+ }, function (err) { toast(err.message); });
1744
+ }));
1745
+ box.appendChild(saveRow);
1746
+ box.appendChild(el('div', 'fallback', 'Added at the end of .env in your app\'s folder; nothing already in it is changed, and .env is added to .gitignore.'));
1747
+ if (a.mode !== 'password' && !a.list.length) {
1748
+ var first = box.querySelector('.btn.sm');
1749
+ if (first) first.click();
1750
+ }
1751
+ }
1752
+
1492
1753
  /* ---------------------------------- account ---------------------------------- */
1493
1754
 
1494
1755
  // Your account: the kryptheon.tech plan this dashboard is connected to, by the connect code from the account page.
@@ -1585,6 +1846,7 @@
1585
1846
  renderTop();
1586
1847
  renderApp();
1587
1848
  renderAccount();
1849
+ setupStart();
1588
1850
  renderNow();
1589
1851
  renderSteps();
1590
1852
  renderKeep();
@@ -1629,7 +1891,7 @@
1629
1891
  // Not while something runs, not while a finding is open being read, not
1630
1892
  // while a yes is being asked for, and not while someone is typing.
1631
1893
  setInterval(function () {
1632
- var typing = document.activeElement === dbInput || document.activeElement === recordInput || document.activeElement === connectInput;
1894
+ var typing = document.activeElement === dbInput || document.activeElement === recordInput || document.activeElement === connectInput || document.activeElement === dailyTime;
1633
1895
  if (!busy && !openRow && !pending && !probeAsking && !paymentsAsking && !typing) load();
1634
1896
  }, 5000);
1635
1897
  })();
@@ -346,6 +346,23 @@
346
346
  .act-row { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
347
347
  .act-row .act { margin-top: 0; }
348
348
  .fallback { font: 10.5px/1.4 var(--mono); color: var(--muted); overflow-wrap: anywhere; }
349
+ .who { width: 100%; border-collapse: collapse; font-size: 13.5px; margin-top: 12px; }
350
+ .who th { text-align: center; font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--line, rgba(0,0,0,.12)); }
351
+ .who th:first-child, .who td:first-child { text-align: left; }
352
+ .who td { padding: 7px 4px; border-bottom: 1px solid var(--line, rgba(0,0,0,.08)); text-align: center; vertical-align: top; }
353
+ .who tr.open-to-all td:first-child { box-shadow: inset 3px 0 0 #e8590c; padding-left: 10px; }
354
+ .who .what small { display: block; font: 10.5px/1.4 var(--mono); color: var(--muted); }
355
+ .who .warn { display: block; font-size: 12px; color: #c2410c; margin-top: 2px; }
356
+ .setup-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
357
+ .setup-row input[type=text], .setup-row input[type=password] { flex: 1 1 260px; min-width: 0; max-width: 420px; padding: 9px 12px; border: 1px solid var(--line); background: var(--white); font: inherit; font-size: 14px; }
358
+ .setup-row input[type=text]:focus, .setup-row input[type=password]:focus { outline: 2px solid var(--orange); outline-offset: 1px; }
359
+ .setup-note { font-size: 13.5px; line-height: 1.5; margin-top: 8px; }
360
+ .who-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
361
+ .who-wrap .who { min-width: 560px; }
362
+ input[type=checkbox] { accent-color: var(--orange); }
363
+ .who input[type=checkbox], #whoBox input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }
364
+ .who tbody tr:hover td { background: rgba(255, 77, 0, 0.045); }
365
+ .who th { font: 600 11px/1.3 var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
349
366
  .tag.when { color: var(--on-light); border-style: dotted; }
350
367
  .f-quick { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px; padding: 0 8px 16px 20px; margin-top: -6px; }
351
368
  .keep-row { display: flex; align-items: flex-start; gap: 16px; padding: 18px 8px 18px 0; }
@@ -426,6 +443,14 @@
426
443
  <div class="card-head"><div><h3>Start here</h3><div class="c-sub">Do these in order. A step is done only once it has actually run.</div></div></div>
427
444
  <div class="steps" id="steps"></div>
428
445
  </div>
446
+ <div class="card gap" id="whoCard">
447
+ <div class="card-head"><div><h3>Who may do what</h3><div class="c-sub">A few questions instead of a file - the roles check judges your app by your answers</div></div></div>
448
+ <div id="whoBox"></div>
449
+ </div>
450
+ <div class="card gap" id="signCard">
451
+ <div class="card-head"><div><h3>Who Kryptheon signs in as</h3><div class="c-sub">Test accounts of your app - kept in .env on this computer, never sent anywhere</div></div></div>
452
+ <div id="signBox"></div>
453
+ </div>
429
454
  <div class="card gap" id="keepCard">
430
455
  <div class="card-head"><div><h3>Keep it running</h3><div class="c-sub">So it is watching whenever your laptop is on - without opening anything</div></div></div>
431
456
  <div class="keep" id="keep"></div>
@@ -278,6 +278,8 @@ const PROBE_WORDS = { reliability: { marker: false }, get roles() { return Objec
278
278
  const PROBE_CHECKS = ['edge', 'reliability', 'roles'];
279
279
  // The roles check is loaded when it is first needed.
280
280
  const rolesModule = () => require('./kryptheon-roles.js');
281
+ const questionsModule = () => require('./kryptheon-questions.js');
282
+ const dailyModule = () => require('./kryptheon-daily.js');
281
283
 
282
284
  // "Check my app": one press on the page runs every check that can run from
283
285
  // here, one after another - asked for by the owner: a person who builds with
@@ -320,8 +322,16 @@ function everythingPlan(checks, app, addresses) {
320
322
  if ((id === 'frontend' || id === 'backend' || id === 'api') && app.webOnly) { skip(id, 'your app\'s code is not on this computer - open the dashboard from your app\'s folder'); continue; }
321
323
  if (id === 'regression' && !c.runnable) { skip(id, 'no recordings yet - record one of your flows first'); continue; }
322
324
  if (id === 'api') {
323
- if (!origin) { skip(id, 'it runs only on your app on this computer - start it (for example npm run dev) and save its address, like http://localhost:3000, in Your app'); continue; }
324
- step.origin = origin;
325
+ // A saved address that is not this computer (a live app): the API step still runs, READ-ONLY - GET only, no
326
+ // value kept - and says so in its name. Everything that writes stays for an app on this computer.
327
+ const saved = !origin && /^https?:\/\//i.test(String(app.address || '')) ? String(app.address).replace(/\/+$/, '') : null;
328
+ if (!origin && !saved) { skip(id, 'it runs on your app on this computer - start it (for example npm run dev) and save its address, like http://localhost:3000, in Your app. A live address (https://...) saved there is only read, never written to'); continue; }
329
+ if (saved) {
330
+ step.origin = saved;
331
+ step.readOnly = true;
332
+ step.addsData = false;
333
+ step.label = 'API on your live app (read-only)';
334
+ } else step.origin = origin;
325
335
  }
326
336
  if (id === 'edge' || id === 'reliability' || id === 'roles') {
327
337
  if (!c.asks) { skip(id, 'no recordings yet - record one of your flows first'); continue; }
@@ -742,7 +752,11 @@ function buildState(root, env) {
742
752
 
743
753
  // The API run: what got through on the running app, each with its proof.
744
754
  if (apiLast && config.enabled.api) {
755
+ // a re-check that said FIXED after this run: that finding is closed until a later run finds it again
756
+ const apiFixed = new Set(readHistory(paths.fixes, 500).filter((a) => a && a.check === 'api' && a.verdict === 'fixed' && a.at > (apiLast.checkedAt || ''))
757
+ .map((a) => a.where + '|' + a.headline));
745
758
  for (const f of apiLast.findings || []) {
759
+ if (apiFixed.has(f.where + '|' + f.headline)) continue;
746
760
  findings.push({
747
761
  check: 'api',
748
762
  severity: f.severity,
@@ -1043,6 +1057,8 @@ function buildState(root, env) {
1043
1057
  verification: { state: 'not verified', why: 'Kryptheon Verified is not built yet. No version of this project has been verified.' },
1044
1058
  // Whether this dashboard starts by itself when the person signs in.
1045
1059
  autostart: (() => { const s = autostart.status(root, env); return { available: s.available, on: s.on, why: s.why || '' }; })(),
1060
+ // the daily check: its time, the next run and what the last one found
1061
+ daily: dailyModule().stateOf(paths),
1046
1062
  };
1047
1063
  }
1048
1064
 
@@ -1294,6 +1310,20 @@ function createServer(root, options) {
1294
1310
  const page = fs.readFileSync(path.join(__dirname, 'kryptheon-dashboard.html'), 'utf8');
1295
1311
  let port = 0;
1296
1312
  const jobs = createJobs();
1313
+ // The daily check: "Check my app" by itself once a day while this dashboard runs (kryptheon-daily.js). Its clock
1314
+ // looks once a minute; one run at a time is the jobs' own rule, so it never starts beside a run the person began.
1315
+ let dailyTimer = null;
1316
+ if (typeof opts.everything === 'function' && opts.daily !== false) {
1317
+ const clock = dailyModule().createDaily({
1318
+ paths: store.pathsFor(root, env), jobs, now: opts.now,
1319
+ plan: () => buildState(root, env).everything,
1320
+ findings: () => buildState(root, env).findings || [],
1321
+ everything: (steps, say, control, info) => opts.everything(steps, say, control, info),
1322
+ notify: opts.notify || dailyModule().notifyDesktop,
1323
+ });
1324
+ dailyTimer = setInterval(() => { try { clock.tick(); } catch (err) { /* the next minute tries again */ } }, opts.dailyEveryMs || 60000);
1325
+ if (dailyTimer.unref) dailyTimer.unref();
1326
+ }
1297
1327
 
1298
1328
  const allowedHosts = () => new Set(['127.0.0.1:' + port, 'localhost:' + port]);
1299
1329
  const send = (res, code, type, body) => {
@@ -1340,6 +1370,16 @@ function createServer(root, options) {
1340
1370
  // What the page is sent, for this computer's account: fix prompts past what the plan opens never leave here.
1341
1371
  return json(res, 200, account.lock(buildState(root, env), root, env));
1342
1372
  }
1373
+ // The plain questions that take the place of permissions-policy.json and the passwords in .env. Read from the
1374
+ // code each time it is asked; nothing in it is a secret (accounts say only whether theirs is set).
1375
+ if (req.method === 'GET' && url.pathname === '/api/setup') {
1376
+ const extra = String(url.searchParams.get('add') || '').split(',').map((x) => x.trim()).filter(Boolean).slice(0, 12);
1377
+ try {
1378
+ return json(res, 200, questionsModule().questionsOf(root, { env, extraRoles: extra }));
1379
+ } catch (err) {
1380
+ return json(res, 500, { ran: false, why: 'the code could not be read for the questions' });
1381
+ }
1382
+ }
1343
1383
  if (req.method === 'GET' && url.pathname === '/api/job') {
1344
1384
  return json(res, 200, { job: jobs.get() });
1345
1385
  }
@@ -1357,6 +1397,26 @@ function createServer(root, options) {
1357
1397
  } catch (err) {
1358
1398
  return json(res, 400, { ok: false, why: 'not JSON' });
1359
1399
  }
1400
+ if (url.pathname === '/api/daily') {
1401
+ const r = dailyModule().set(store.pathsFor(root, env), input);
1402
+ return json(res, r.ok ? 200 : 400, r.ok ? { ok: true, daily: dailyModule().stateOf(store.pathsFor(root, env)) } : r);
1403
+ }
1404
+ if (url.pathname === '/api/setup/policy') {
1405
+ const q = questionsModule().questionsOf(root, { env, extraRoles: Array.isArray(input.roles) ? input.roles.slice(0, 20).map(String) : [] });
1406
+ if (!q.ran) return json(res, 400, { ok: false, why: q.why });
1407
+ const made = questionsModule().policyFrom(q, input);
1408
+ if (!made.ok) return json(res, 400, made);
1409
+ const r = questionsModule().savePolicy(root, made.policy, input.replace === true);
1410
+ return json(res, r.ok ? 200 : 409, { ok: r.ok, why: r.why, roles: Object.keys(made.policy.roles) });
1411
+ }
1412
+ if (url.pathname === '/api/setup/accounts') {
1413
+ const qm = questionsModule();
1414
+ const entries = (Array.isArray(input.entries) ? input.entries : []).slice(0, 40)
1415
+ .map((e) => ({ envName: e && e.envName ? String(e.envName) : qm.tokenEnvName(e && e.label), value: e && e.value }));
1416
+ if (entries.some((e) => !e.envName)) return json(res, 400, { ok: false, why: 'give each token a name, like Northstar owner' });
1417
+ const r = qm.saveAccounts(root, entries);
1418
+ return json(res, r.ok ? 200 : 400, r);
1419
+ }
1360
1420
  if (url.pathname === '/api/check') {
1361
1421
  const r = setCheck(store.pathsFor(root, env), String(input.id || ''), input.on);
1362
1422
  return json(res, r.ok ? 200 : 400, r);
@@ -1445,7 +1505,9 @@ function createServer(root, options) {
1445
1505
  .map((s) => ({ id: s.id, label: s.label, why: plan.live.join(', ') + ' is not this computer - tick that it is your own test copy to include this' }))
1446
1506
  .concat(plan.skipped);
1447
1507
  if (!steps.length) return json(res, 400, { ok: false, why: skipped[0].why });
1448
- const command = steps.map((s) => (s.id === 'api' ? RUN_COMMAND.api.replace('http://localhost:3000', s.origin) : RUN_COMMAND[s.id])).join(', then ');
1508
+ const command = steps.map((s) => (s.id === 'api' ? (s.readOnly ? 'npx kryptheon api --live --origin ' + s.origin + ' --yes' : RUN_COMMAND.api.replace('http://localhost:3000', s.origin)) : RUN_COMMAND[s.id])).join(', then ');
1509
+ // the person's own full run: today's daily one is not needed after it
1510
+ if (!jobs.busy()) dailyModule().markFullRun(store.pathsFor(root, env));
1449
1511
  return begin('everything', 'Checking your app', command,
1450
1512
  (say, control) => opts.everything(steps, say, control, { origin: plan.origin, confirmed: ticked ? plan.live : [], skipped: skipped }));
1451
1513
  }