cornfield 0.20.0 → 0.22.0
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/core/agent-contract.js +7 -2
- package/core/agent-contract.schema.json +4 -0
- package/core/config.js +5 -0
- package/core/theme.js +337 -0
- package/core/validate.js +37 -0
- package/explorer/explorer.css +3 -0
- package/explorer/forge-panel.js +99 -21
- package/explorer/index.html +16 -3
- package/explorer/plugins.js +2 -0
- package/explorer/runs-model.js +47 -11
- package/explorer/runs-view.js +22 -6
- package/explorer/theme-boot.js +22 -2
- package/explorer/theme-model.js +19 -0
- package/explorer/theme-names.js +61 -0
- package/package.json +1 -1
- package/server/agent-api.js +11 -3
- package/server/agent-runs.js +50 -10
- package/server/server.js +98 -4
package/explorer/forge-panel.js
CHANGED
|
@@ -69,7 +69,7 @@ import { relativeTime } from './review-model.js';
|
|
|
69
69
|
import { LAYER_DEFS, toggleLayer } from './layers.js';
|
|
70
70
|
import { WORK_URL, groupWork, filterGroups, groupWords, workStatus, markWords } from './agents-model.js';
|
|
71
71
|
import {
|
|
72
|
-
RUNS_URL, runsUrl, stopUrl, runOnThread, threadRunWords, runTone, answerUrl, answerBody, answerWordsFor, KINDS, aboutWords, statusWords, statusWhy, runMeta, canStop, runsStatus, runnerState, runnerWords, triggerNotice, totalsLines, handLines,
|
|
72
|
+
RUNS_URL, runsUrl, stopUrl, runOnThread, threadRunWords, canRetry, retryRefs, retryWords, limitsFromFields, defaultLimits, LIMIT_KEYS, briefUrl, runTone, answerUrl, answerBody, answerWordsFor, KINDS, aboutWords, statusWords, statusWhy, runMeta, canStop, runsStatus, runnerState, runnerWords, triggerNotice, totalsLines, handLines, startBody, startWords, stopWords, confirmStartWords, litOfRun, changeWords,
|
|
73
73
|
} from './runs-model.js';
|
|
74
74
|
import { runsHtml, totalsHtml } from './runs-view.js';
|
|
75
75
|
import { setRunsOnMap, clearRunsOnMap } from './runs-map.js';
|
|
@@ -122,7 +122,8 @@ const ui = {
|
|
|
122
122
|
runnerSaid: null, // the runner state last shown ('online', 'offline', 'none'; null off the pull transport), so a change is said once
|
|
123
123
|
runTimelines: new Set(), // the runs whose timeline is open
|
|
124
124
|
runReplies: new Map(), // the reply typed so far for each waiting run, so a repaint (the runs are looked at again) keeps it
|
|
125
|
-
agent: null, // { opener, refs, posting } while the Start an agent dialog is open
|
|
125
|
+
agent: null, // { opener, refs, posting, retryOf, filled } while the Start an agent dialog is open
|
|
126
|
+
retrying: false, // a Start again reading its run's whole brief, so a second click does nothing
|
|
126
127
|
};
|
|
127
128
|
|
|
128
129
|
/** The Release notes view: the draft loaded for a tag, and where the confirm step is */
|
|
@@ -1052,6 +1053,7 @@ function findAgain(el) {
|
|
|
1052
1053
|
if (el.dataset.forgeRerun) return `[data-forge-rerun="${el.dataset.forgeRerun}"]`;
|
|
1053
1054
|
if (el.dataset.forgeAgent) return `[data-forge-agent="${el.dataset.forgeAgent}"]`;
|
|
1054
1055
|
if (el.dataset.forgeStop) return `[data-forge-stop="${el.dataset.forgeStop}"]`;
|
|
1056
|
+
if (el.dataset.forgeRetry) return `[data-forge-retry="${el.dataset.forgeRetry}"]`;
|
|
1055
1057
|
if (el.dataset.runReply) return `[data-run-reply="${el.dataset.runReply}"]`;
|
|
1056
1058
|
if (el.dataset.runAnswer) return `[data-run-answer="${el.dataset.runAnswer}"][data-run-id="${el.dataset.runId}"]`;
|
|
1057
1059
|
if (el.dataset.runSelect) return `[data-run-select="${el.dataset.runSelect}"]`;
|
|
@@ -1451,25 +1453,37 @@ function keepFocusInAgent(e) {
|
|
|
1451
1453
|
if (ui.agent && el && !el.contains(e.target)) $('agent-kind').focus();
|
|
1452
1454
|
}
|
|
1453
1455
|
|
|
1454
|
-
/**
|
|
1455
|
-
|
|
1456
|
+
/**
|
|
1457
|
+
* Opens the Start an agent dialog for `issue:<n>` or `proposal:<slug>`; the focus goes to the first field. The limit fields hold what the request
|
|
1458
|
+
* starts from (the config's, for the profile). With `again` (a run that failed or was stopped) it is **Start again**: the same kind, refs,
|
|
1459
|
+
* profile, brief and limits filled in, all editable, and the request will carry `retryOf`. `brief` is that run's whole brief when the list's was cut
|
|
1460
|
+
*/
|
|
1461
|
+
async function openAgent(ref, opener, again = null, brief = null) {
|
|
1456
1462
|
if (!agentEl() || ui.agent) return;
|
|
1457
1463
|
const at = ref.indexOf(':');
|
|
1458
1464
|
const type = ref.slice(0, at);
|
|
1459
1465
|
const value = ref.slice(at + 1);
|
|
1460
|
-
const refs = type === 'proposal' ? { proposal: value } : { issue: Number(value) };
|
|
1461
|
-
ui.agent = { opener, refs, posting: false };
|
|
1466
|
+
const refs = again ? retryRefs(again) : type === 'proposal' ? { proposal: value } : { issue: Number(value) };
|
|
1467
|
+
ui.agent = { opener, refs, posting: false, retryOf: again ? again.runId : null };
|
|
1462
1468
|
// The profiles the config lists come with the runs: asked for if the Agents tab has not been opened yet
|
|
1463
1469
|
if (!ui.runs) { await loadRuns(false); if (ui.kind === 'work') paint(); }
|
|
1464
1470
|
if (!ui.agent) return;
|
|
1465
1471
|
const profiles = (ui.runs && ui.runs.data && ui.runs.data.profiles) || [];
|
|
1466
1472
|
$('agent-start-about').textContent = `About ${aboutWords(refs)}`;
|
|
1467
1473
|
paintRunner('agent-start-runner', ui.runs && ui.runs.data);
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
$('agent-
|
|
1474
|
+
const kind = again ? again.kind : 'code';
|
|
1475
|
+
// The old run's profile stays on offer even if the config no longer lists it: the server then says so, in its words
|
|
1476
|
+
const shown = again && again.profile && !profiles.includes(again.profile) ? [...profiles, again.profile] : profiles;
|
|
1477
|
+
$('agent-kind').innerHTML = KINDS.map(([v, l]) => option(v, l, v === kind)).join('');
|
|
1478
|
+
$('agent-profile').innerHTML = option('', 'No profile', !(again && again.profile)) + shown.map((p) => option(p, p, !!again && p === again.profile)).join('');
|
|
1479
|
+
$('agent-profile-field').hidden = !shown.length;
|
|
1480
|
+
$('agent-profile').value = again && again.profile ? again.profile : ''; // as well as `selected`, which not every DOM honours
|
|
1481
|
+
$('agent-start-title').textContent = again ? 'Start again' : 'Start an agent';
|
|
1482
|
+
const note = $('agent-retry-note');
|
|
1483
|
+
note.hidden = !again;
|
|
1484
|
+
note.textContent = again ? retryWords(again) : '';
|
|
1485
|
+
fillLimits(again ? again.limits || {} : limitDefaultsNow());
|
|
1486
|
+
$('agent-brief').value = brief ?? (again && typeof again.brief === 'string' ? again.brief : '');
|
|
1473
1487
|
$('agent-force').checked = false;
|
|
1474
1488
|
$('agent-force-field').hidden = true;
|
|
1475
1489
|
$('agent-start-msg').hidden = true;
|
|
@@ -1482,16 +1496,54 @@ async function openAgent(ref, opener) {
|
|
|
1482
1496
|
document.addEventListener('focusin', keepFocusInAgent);
|
|
1483
1497
|
agentEl().hidden = false;
|
|
1484
1498
|
$('agent-kind').focus();
|
|
1485
|
-
announce(
|
|
1499
|
+
announce(`${again ? 'Start again' : 'Start an agent'} on ${aboutWords(refs)}. ${confirmStartWords(refs, forgeName())}`);
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
/** "Start again" on a run that failed or was stopped. A brief the list shows cut is read whole first: the dialog never starts from part of one */
|
|
1503
|
+
async function startAgain(runId) {
|
|
1504
|
+
const run = ui.runs && ui.runs.data ? ui.runs.data.runs.find((r) => r.runId === runId) : null;
|
|
1505
|
+
if (!run || !canRetry(run) || ui.agent || ui.retrying) return;
|
|
1506
|
+
let brief = null;
|
|
1507
|
+
if (run.briefCut) {
|
|
1508
|
+
ui.retrying = true;
|
|
1509
|
+
const res = await request(briefUrl(runId), false);
|
|
1510
|
+
ui.retrying = false;
|
|
1511
|
+
if (!res.ok || typeof res.body.brief !== 'string') {
|
|
1512
|
+
ui.runNote = { text: `The brief of ${runId} could not be read, so Start again did not open: ${errorWords(res.status, res.body)}`, ok: false };
|
|
1513
|
+
paint();
|
|
1514
|
+
announce(ui.runNote.text);
|
|
1515
|
+
return;
|
|
1516
|
+
}
|
|
1517
|
+
brief = res.body.brief;
|
|
1518
|
+
}
|
|
1519
|
+
const about = run.refs.proposal != null ? `proposal:${run.refs.proposal}` : `issue:${run.refs.issue ?? run.refs.thread}`;
|
|
1520
|
+
openAgent(about, `[data-forge-retry="${runId}"]`, run, brief);
|
|
1486
1521
|
}
|
|
1487
1522
|
|
|
1488
|
-
/**
|
|
1489
|
-
function
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1523
|
+
/** Takes the person to another run of the list: the row scrolls into view and has the focus */
|
|
1524
|
+
function goToRun(runId) {
|
|
1525
|
+
bringIntoView([...document.querySelectorAll('#forge-runs-list [data-run]')].find((r) => r.dataset.run === runId));
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
/** The limits the config gives a request under the chosen profile */
|
|
1529
|
+
const limitDefaultsNow = () => defaultLimits(ui.runs && ui.runs.data && ui.runs.data.limits, $('agent-profile-field').hidden ? '' : $('agent-profile').value);
|
|
1530
|
+
/** What the four limit fields hold, as text */
|
|
1531
|
+
const limitFields = () => Object.fromEntries(LIMIT_KEYS.map((k) => [k, $(`agent-limit-${k}`).value]));
|
|
1532
|
+
|
|
1533
|
+
/** Fills the four limit fields (blank where `limits` has none) and remembers what was filled */
|
|
1534
|
+
function fillLimits(limits) {
|
|
1535
|
+
for (const k of LIMIT_KEYS) {
|
|
1536
|
+
const field = $(`agent-limit-${k}`);
|
|
1537
|
+
field.value = limits && limits[k] != null ? String(limits[k]) : '';
|
|
1538
|
+
field.removeAttribute('aria-invalid');
|
|
1539
|
+
field.removeAttribute('aria-describedby');
|
|
1540
|
+
}
|
|
1541
|
+
if (ui.agent) ui.agent.filled = JSON.stringify(limitFields());
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
/** Another profile: its limits fill the fields, unless the person has typed in them */
|
|
1545
|
+
function onAgentProfile() {
|
|
1546
|
+
if (ui.agent && ui.agent.filled === JSON.stringify(limitFields())) fillLimits(limitDefaultsNow());
|
|
1495
1547
|
}
|
|
1496
1548
|
|
|
1497
1549
|
/** Closes the dialog; the focus goes back to the button that opened it unless told not to */
|
|
@@ -1517,8 +1569,30 @@ async function submitAgent(e) {
|
|
|
1517
1569
|
go.setAttribute('aria-busy', 'true');
|
|
1518
1570
|
go.textContent = 'Asking …';
|
|
1519
1571
|
$('agent-start-msg').hidden = true;
|
|
1572
|
+
const again = ui.agent.retryOf;
|
|
1573
|
+
const fields = limitFields();
|
|
1574
|
+
const limits = limitsFromFields(fields);
|
|
1575
|
+
// Each field that is not a number above zero is marked, and the first has the focus; the message says why
|
|
1576
|
+
const wrong = LIMIT_KEYS.filter((k) => limitsFromFields({ [k]: fields[k] }) === null);
|
|
1577
|
+
for (const k of LIMIT_KEYS) {
|
|
1578
|
+
const field = $(`agent-limit-${k}`);
|
|
1579
|
+
if (wrong.includes(k)) { field.setAttribute('aria-invalid', 'true'); field.setAttribute('aria-describedby', 'agent-start-msg'); } else { field.removeAttribute('aria-invalid'); field.removeAttribute('aria-describedby'); }
|
|
1580
|
+
}
|
|
1581
|
+
if (limits === null) {
|
|
1582
|
+
ui.agent.posting = false;
|
|
1583
|
+
go.disabled = false;
|
|
1584
|
+
go.removeAttribute('aria-busy');
|
|
1585
|
+
go.textContent = 'Ask the runner';
|
|
1586
|
+
const bad = $('agent-start-msg');
|
|
1587
|
+
bad.textContent = `A limit is a number above zero, or blank for the config's (${wrong.join(', ')}).`;
|
|
1588
|
+
bad.hidden = false;
|
|
1589
|
+
$(`agent-limit-${wrong[0]}`).focus();
|
|
1590
|
+
announce(bad.textContent);
|
|
1591
|
+
return;
|
|
1592
|
+
}
|
|
1520
1593
|
const res = await post(RUNS_URL, startBody({
|
|
1521
1594
|
kind: $('agent-kind').value, profile: $('agent-profile-field').hidden ? '' : $('agent-profile').value, brief: $('agent-brief').value, refs: ui.agent.refs, force: $('agent-force').checked,
|
|
1595
|
+
limits, ...(again ? { retryOf: again } : {}),
|
|
1522
1596
|
}));
|
|
1523
1597
|
if (!ui.agent) return;
|
|
1524
1598
|
ui.agent.posting = false;
|
|
@@ -1823,6 +1897,10 @@ function onClick(e) {
|
|
|
1823
1897
|
if (agent) { openAgent(agent.dataset.forgeAgent, `[data-forge-agent="${agent.dataset.forgeAgent}"]`); return; }
|
|
1824
1898
|
const stop = t.closest('[data-forge-stop]');
|
|
1825
1899
|
if (stop) { stopRun(stop.dataset.forgeStop); return; }
|
|
1900
|
+
const retry = t.closest('[data-forge-retry]');
|
|
1901
|
+
if (retry) { startAgain(retry.dataset.forgeRetry); return; }
|
|
1902
|
+
const goto = t.closest('[data-run-goto]');
|
|
1903
|
+
if (goto) { goToRun(goto.dataset.runGoto); return; }
|
|
1826
1904
|
const answer = t.closest('[data-run-answer]');
|
|
1827
1905
|
if (answer) { answerRun(answer.dataset.runId, answer.dataset.runAnswer); return; }
|
|
1828
1906
|
const pick = t.closest('[data-run-select]');
|
|
@@ -1956,7 +2034,7 @@ export function initForgePanel(config, opts = {}) {
|
|
|
1956
2034
|
agent.addEventListener('click', onAgentClick);
|
|
1957
2035
|
agent.addEventListener('keydown', onAgentKey);
|
|
1958
2036
|
agent.querySelector('form').addEventListener('submit', submitAgent);
|
|
1959
|
-
$('agent-profile').addEventListener('change',
|
|
2037
|
+
$('agent-profile').addEventListener('change', onAgentProfile);
|
|
1960
2038
|
}
|
|
1961
2039
|
const confirm = confirmEl();
|
|
1962
2040
|
if (confirm) {
|
|
@@ -1998,5 +2076,5 @@ export function resetForgePanelForTests(clock = () => Date.now()) {
|
|
|
1998
2076
|
runsTimer = 0;
|
|
1999
2077
|
pageAway = false;
|
|
2000
2078
|
clearRunsOnMap();
|
|
2001
|
-
Object.assign(ui, { runSel: null, runTimelines: new Set(), runReplies: new Map(), thread: null, threadDetail: null, threadError: '', litThread: null, idea: freshIdea(), config: null, open: false, kind: 'pulls', filters: defaultFilters(), lists: {}, work: null, workFilters: { agentsOnly: false, finished: false }, loading: false, error: '', selected: null, detail: null, landing: null, detailError: '', lit: null, deploy: null, deployItem: null, litDeploy: null, nodesSeen: null, busy: '', note: null, confirm: null, actNote: null, notes: freshNotes(), runs: null, runnerSaid: null, runNote: null, agent: null });
|
|
2079
|
+
Object.assign(ui, { runSel: null, runTimelines: new Set(), runReplies: new Map(), thread: null, threadDetail: null, threadError: '', litThread: null, idea: freshIdea(), config: null, open: false, kind: 'pulls', filters: defaultFilters(), lists: {}, work: null, workFilters: { agentsOnly: false, finished: false }, loading: false, error: '', selected: null, detail: null, landing: null, detailError: '', lit: null, deploy: null, deployItem: null, litDeploy: null, nodesSeen: null, busy: '', note: null, confirm: null, actNote: null, notes: freshNotes(), runs: null, runnerSaid: null, runNote: null, agent: null, retrying: false });
|
|
2002
2080
|
}
|
package/explorer/index.html
CHANGED
|
@@ -8,10 +8,14 @@
|
|
|
8
8
|
<!--@importmap-->
|
|
9
9
|
|
|
10
10
|
<!-- The explorer's own stylesheet and modules (explorer/): no build step, no CDN -->
|
|
11
|
-
<!-- Light or dark on <html data-theme> before the first paint (theme-boot.js; theme.js keeps it after) -->
|
|
12
|
-
<script src="/explorer/theme-boot.js"></script>
|
|
13
11
|
<link rel="stylesheet" href="/explorer/explorer.css" />
|
|
14
12
|
<link rel="stylesheet" href="/explorer/house.css" />
|
|
13
|
+
<!-- The config's theme (server/server.js puts it here, so it comes after cornfield's own CSS): font stylesheets, the repo's theme.css, a named theme -->
|
|
14
|
+
<!--@theme-->
|
|
15
|
+
<!-- Light or dark on <html data-theme>, and the named theme on <html data-theme-name>, before the first paint (theme-boot.js; theme.js
|
|
16
|
+
keeps it after). A classic script in the head, after every stylesheet link: it runs before the body is parsed, so before anything is
|
|
17
|
+
drawn, and the named theme's <link> above already exists when it runs. Keep it the last thing in the head. -->
|
|
18
|
+
<script src="/explorer/theme-boot.js"></script>
|
|
15
19
|
</head>
|
|
16
20
|
<body>
|
|
17
21
|
<!-- Top bar: layers, data-flow preset, search, layout mode, zoom, links -->
|
|
@@ -157,6 +161,9 @@
|
|
|
157
161
|
</svg>
|
|
158
162
|
</button>
|
|
159
163
|
|
|
164
|
+
<!-- The named themes of the config (`theme.names`): filled and shown by explorer/theme-names.js; hidden when there are none -->
|
|
165
|
+
<select id="theme-name-select" class="hx-forge-select" style="width:auto;max-width:9rem" aria-label="Theme" title="Theme" hidden></select>
|
|
166
|
+
|
|
160
167
|
<!-- The config's links (cornfield.config.js `links`), filled by explorer/plugins.js -->
|
|
161
168
|
<span id="cf-links" class="hx-links"></span>
|
|
162
169
|
</div>
|
|
@@ -365,10 +372,16 @@
|
|
|
365
372
|
<h2 id="agent-start-title" class="hx-confirm-title">Start an agent</h2>
|
|
366
373
|
<p id="agent-start-about" class="hx-forge-meta"></p>
|
|
367
374
|
<p id="agent-start-runner" class="hx-forge-meta" hidden></p>
|
|
375
|
+
<p id="agent-retry-note" class="hx-forge-meta" hidden></p>
|
|
368
376
|
<form id="agent-start-form" class="hx-forge-confirm" novalidate>
|
|
369
377
|
<label class="hx-forge-field">Kind of run<select id="agent-kind" class="hx-forge-select"></select></label>
|
|
370
378
|
<label id="agent-profile-field" class="hx-forge-field" hidden>Profile<select id="agent-profile" class="hx-forge-select"></select></label>
|
|
371
|
-
<
|
|
379
|
+
<fieldset id="agent-limits-edit" class="hx-forge-field hx-forge-limits"><legend>Limits, hints for the runner (one left blank takes the config's, if any)</legend>
|
|
380
|
+
<label class="hx-forge-field">Minutes<input type="number" id="agent-limit-minutes" class="hx-forge-input" min="0" step="any" inputmode="decimal" /></label>
|
|
381
|
+
<label class="hx-forge-field">Turns<input type="number" id="agent-limit-turns" class="hx-forge-input" min="0" step="1" inputmode="numeric" /></label>
|
|
382
|
+
<label class="hx-forge-field">Cost<input type="number" id="agent-limit-cost" class="hx-forge-input" min="0" step="any" inputmode="decimal" /></label>
|
|
383
|
+
<label class="hx-forge-field">Tokens<input type="number" id="agent-limit-tokens" class="hx-forge-input" min="0" step="1" inputmode="numeric" /></label>
|
|
384
|
+
</fieldset>
|
|
372
385
|
<label class="hx-forge-field">Brief for the runner<textarea id="agent-brief" class="hx-forge-preview" rows="6" maxlength="20000" spellcheck="true"></textarea></label>
|
|
373
386
|
<label id="agent-force-field" class="hx-forge-toggle" hidden><input type="checkbox" id="agent-force" /> Ask for another run on purpose</label>
|
|
374
387
|
<p id="agent-start-words" class="hx-confirm-note"></p>
|
package/explorer/plugins.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { escHtml } from './state.js';
|
|
18
|
+
import { initThemePicker } from './theme-names.js';
|
|
18
19
|
|
|
19
20
|
/** What the live layer shows when the repo names no live source */
|
|
20
21
|
export const NO_SOURCE = Object.freeze({
|
|
@@ -43,6 +44,7 @@ export function applyBranding(doc, config) {
|
|
|
43
44
|
if (title && config.title) title.textContent = config.title;
|
|
44
45
|
const heading = doc.getElementById('cf-heading');
|
|
45
46
|
if (heading && config.title) heading.textContent = `${config.title}: the map`;
|
|
47
|
+
initThemePicker(doc, config.theme);
|
|
46
48
|
const links = doc.getElementById('cf-links');
|
|
47
49
|
if (!links) return;
|
|
48
50
|
const html = Array.isArray(config.links) ? config.links
|
package/explorer/runs-model.js
CHANGED
|
@@ -12,6 +12,8 @@ export const RUNS_URL = '/api/agent-runs';
|
|
|
12
12
|
export const runsUrl = (follow) => (follow ? `${RUNS_URL}?follow=1` : RUNS_URL);
|
|
13
13
|
export const stopUrl = (runId) => `${RUNS_URL}/${encodeURIComponent(runId)}/stop`;
|
|
14
14
|
export const answerUrl = (runId) => `${RUNS_URL}/${encodeURIComponent(runId)}/answer`;
|
|
15
|
+
/** A run's whole brief, for Start again: the list carries its first 2000 characters */
|
|
16
|
+
export const briefUrl = (runId) => `${RUNS_URL}/${encodeURIComponent(runId)}/brief`;
|
|
15
17
|
|
|
16
18
|
/** The kinds of run (the contract's), and what each asks the runner for */
|
|
17
19
|
export const KINDS = Object.freeze([
|
|
@@ -202,29 +204,61 @@ export function runnerWords(presence, nowMs) {
|
|
|
202
204
|
|
|
203
205
|
/**
|
|
204
206
|
* The body of a start. Only what the person chose; the server writes the run id, the time and who asked, and checks the rest.
|
|
205
|
-
* @param {{ kind: string, profile?: string, brief?: string, refs: object, force?: boolean }} input
|
|
207
|
+
* @param {{ kind: string, profile?: string, brief?: string, refs: object, force?: boolean, limits?: object, retryOf?: string }} input `limits`: the
|
|
208
|
+
* dialog's fields, blanks left out (the server fills those from the config); `retryOf` only with Start again
|
|
206
209
|
*/
|
|
207
|
-
export function startBody({ kind, profile, brief, refs, force }) {
|
|
210
|
+
export function startBody({ kind, profile, brief, refs, force, limits, retryOf }) {
|
|
208
211
|
const out = { kind, refs, brief: (brief || '').trim() };
|
|
209
212
|
if (profile) out.profile = profile;
|
|
213
|
+
if (limits && Object.keys(limits).length) out.limits = limits;
|
|
214
|
+
if (retryOf) out.retryOf = retryOf;
|
|
210
215
|
if (force) out.force = true;
|
|
211
216
|
return out;
|
|
212
217
|
}
|
|
213
218
|
|
|
214
|
-
|
|
219
|
+
/** The four limits a request may carry, in the order the Start dialog's fields show them */
|
|
220
|
+
export const LIMIT_KEYS = Object.freeze(['minutes', 'turns', 'cost', 'tokens']);
|
|
215
221
|
|
|
216
222
|
/**
|
|
217
|
-
* The limits a request for `profile`
|
|
218
|
-
* over them key by key (as core/config.js `limitDefaults
|
|
223
|
+
* The limits a request for `profile` starts from, to fill the Start dialog's fields: the config's flat `agents.limits`, then the profile's own
|
|
224
|
+
* over them key by key (as core/config.js `limitDefaults`, which the server applies to a field left blank). `{}` when the config sets none.
|
|
219
225
|
* @param {Record<string, any> | undefined} limits the `limits` of `GET /api/agent-runs`
|
|
220
226
|
* @param {string} profile '' for none
|
|
221
227
|
*/
|
|
222
|
-
export function
|
|
223
|
-
if (!limits || typeof limits !== 'object'
|
|
224
|
-
const
|
|
225
|
-
const
|
|
226
|
-
const
|
|
227
|
-
return
|
|
228
|
+
export function defaultLimits(limits, profile) {
|
|
229
|
+
if (!limits || typeof limits !== 'object') return {};
|
|
230
|
+
const own = profile && !LIMIT_KEYS.includes(profile) && limits[profile] && typeof limits[profile] === 'object' ? limits[profile] : {};
|
|
231
|
+
const out = {};
|
|
232
|
+
for (const k of LIMIT_KEYS) { const n = own[k] ?? limits[k]; if (typeof n === 'number') out[k] = n; }
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** Start again is offered on a run that failed (a runner's refusal is a `failed` report too) or was stopped, and on nothing else */
|
|
237
|
+
export const canRetry = (run) => run.status === 'failed' || run.status === 'stopped';
|
|
238
|
+
|
|
239
|
+
/** The refs a run is started again on: the subject it had (the spec pull request of a proposal is found again by the server) */
|
|
240
|
+
export function retryRefs(run) {
|
|
241
|
+
const refs = {};
|
|
242
|
+
for (const k of ['issue', 'thread', 'proposal']) if (run.refs && run.refs[k] != null) refs[k] = run.refs[k];
|
|
243
|
+
return refs;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** The four limits as the dialog's fields hold them (text), to the object a request carries: blanks are left out, and `null` when a field is not a number above zero */
|
|
247
|
+
export function limitsFromFields(fields) {
|
|
248
|
+
const out = {};
|
|
249
|
+
for (const k of LIMIT_KEYS) {
|
|
250
|
+
const text = String(fields[k] ?? '').trim();
|
|
251
|
+
if (text === '') continue;
|
|
252
|
+
const n = Number(text);
|
|
253
|
+
if (!Number.isFinite(n) || n <= 0) return null;
|
|
254
|
+
out[k] = n;
|
|
255
|
+
}
|
|
256
|
+
return out;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** The line under the dialog's title when it starts a run again */
|
|
260
|
+
export function retryWords(run) {
|
|
261
|
+
return `Starts again on ${run.runId}.`;
|
|
228
262
|
}
|
|
229
263
|
|
|
230
264
|
/** What a start came to, in words */
|
|
@@ -324,6 +358,8 @@ export function timelineWords(entry) {
|
|
|
324
358
|
const by = who ? ` by ${who}` : '';
|
|
325
359
|
switch (entry.kind) {
|
|
326
360
|
case 'requested': return { what: `Requested${by}${entry.ref ? ` under the profile ${entry.ref}` : ''}`, note: '' };
|
|
361
|
+
case 'retry-of': return { what: `Starts again on ${entry.ref || 'an earlier run'}`, note: '' };
|
|
362
|
+
case 'retried-by': return { what: `Started again as ${entry.ref || 'a new run'}`, note: '' };
|
|
327
363
|
case 'claimed': return { what: `Claimed${by}`, note: entry.note || '' };
|
|
328
364
|
case 'report': return { what: `Reported ${entry.ref || 'in'}${by}`, note: entry.note || '' };
|
|
329
365
|
// When cornfield saw it, not when it was pushed: the forge does not say
|
package/explorer/runs-view.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { relativeTime } from './review-model.js';
|
|
12
|
-
import { runTone, aboutWords, statusWords, statusWhy, runMeta, canStop, canAnswer, groupRuns, compareTitle, limitRows, checksWords, timelineWords, nodeLabels, collisionWords, answerWords } from './runs-model.js';
|
|
12
|
+
import { runTone, canRetry, aboutWords, statusWords, statusWhy, runMeta, canStop, canAnswer, groupRuns, compareTitle, limitRows, checksWords, timelineWords, nodeLabels, collisionWords, answerWords } from './runs-model.js';
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -49,10 +49,24 @@ function linksHtml(ctx, run) {
|
|
|
49
49
|
].filter(Boolean).join(' · ');
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
/** A run id that is another run of the list is a button that takes you to it; otherwise it is plain text */
|
|
53
|
+
function runLink(ctx, runId, all) {
|
|
54
|
+
const there = (all || []).some((r) => r.runId === runId);
|
|
55
|
+
return there ? `<button type="button" class="hx-btn hx-forge-act" data-run-goto="${ctx.esc(runId)}" aria-label="Go to run ${ctx.esc(runId)}">${ctx.esc(runId)}</button>` : ctx.esc(runId);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Which run this one starts again, and which start it again */
|
|
59
|
+
function retryHtml(ctx, run, all) {
|
|
60
|
+
const again = Array.isArray(run.retriedBy) ? run.retriedBy : [];
|
|
61
|
+
if (!run.retryOf && !again.length) return '';
|
|
62
|
+
return `<p class="hx-forge-meta">${run.retryOf ? `Starts again on ${runLink(ctx, run.retryOf, all)}` : ''}${run.retryOf && again.length ? ' · ' : ''}${again.length ? `Started again as ${again.map((id) => runLink(ctx, id, all)).join(', ')}` : ''}</p>`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function timelineHtml(ctx, run, all) {
|
|
53
66
|
const items = (run.timeline || []).map((e) => {
|
|
54
67
|
const w = timelineWords(e);
|
|
55
|
-
|
|
68
|
+
const goto = (e.kind === 'retry-of' || e.kind === 'retried-by') && e.ref && (all || []).some((r) => r.runId === e.ref) ? ` <button type="button" class="hx-btn hx-forge-act" data-run-goto="${ctx.esc(e.ref)}" aria-label="Go to run ${ctx.esc(e.ref)}">Go to it</button>` : '';
|
|
69
|
+
return `<li><time datetime="${ctx.esc(e.at)}" title="${ctx.esc(e.at)}">${ctx.esc(relativeTime(e.at, ctx.now) || e.at)}</time>${ctx.esc(w.what)}${goto}${w.note ? `<span class="hx-run-note">${ctx.esc(w.note)}</span>` : ''}</li>`;
|
|
56
70
|
});
|
|
57
71
|
return `<ol class="hx-run-timeline" id="run-tl-${ctx.esc(run.runId)}" aria-label="Timeline of ${ctx.esc(run.runId)}, oldest first">${items.join('')}</ol>`;
|
|
58
72
|
}
|
|
@@ -88,25 +102,27 @@ export function runHtml(ctx, run, all) {
|
|
|
88
102
|
const why = statusWhy(run);
|
|
89
103
|
const note = run.report && run.report.note ? `<p class="hx-forge-meta">Runner: ${ctx.esc(run.report.note)}</p>` : '';
|
|
90
104
|
const answering = canAnswer(run);
|
|
105
|
+
const retry = canRetry(run) ? `<button type="button" class="hx-btn hx-forge-act" data-forge-retry="${ctx.esc(run.runId)}" aria-label="Start again on run ${ctx.esc(run.runId)}"${ctx.busy ? ' disabled' : ''}>Start again</button>` : '';
|
|
91
106
|
const stop = canStop(run) && !answering ? `<button type="button" class="hx-btn hx-forge-act" data-forge-stop="${ctx.esc(run.runId)}" aria-label="Stop run ${ctx.esc(run.runId)}"${ctx.busy ? ' disabled' : ''}>Stop</button>` : '';
|
|
92
107
|
const names = nodeLabels(run.nodes, ctx.nodes);
|
|
93
108
|
const collision = collisionWords(run, all, ctx.nodes);
|
|
94
109
|
const limits = limitRows(run);
|
|
95
110
|
const count = (run.timeline || []).length;
|
|
96
111
|
const links = linksHtml(ctx, run);
|
|
97
|
-
return `<li class="hx-run hx-forge-file" data-run="${ctx.esc(run.runId)}">
|
|
112
|
+
return `<li class="hx-run hx-forge-file" data-run="${ctx.esc(run.runId)}" tabindex="-1">
|
|
98
113
|
<div class="hx-run-head"><span class="hx-forge-state hx-forge-state--${tone}">${ctx.esc(statusWords(run))}</span> <span class="hx-name">${ctx.esc(run.kind)} on ${ctx.esc(aboutWords(run.refs))}</span>${run.profile ? ` <span class="hx-faint">profile ${ctx.esc(run.profile)}</span>` : ''}</div>
|
|
99
114
|
${collision ? `<p class="hx-run-collide"><span aria-hidden="true">⚠</span> ${ctx.esc(collision)}</p>` : ''}
|
|
100
115
|
<p class="hx-forge-meta">${ctx.esc(runMeta(run, ctx.now))}</p>${why ? `<p class="hx-forge-why hx-faint">${ctx.esc(why)}</p>` : ''}${note}
|
|
101
116
|
<dl class="hx-run-limits" aria-label="Limits and what the runner reported">${limits.length ? limits.map((r) => `<dt>${ctx.esc(r.name)}</dt><dd>limit: ${ctx.esc(r.limit)}; reported: ${ctx.esc(r.reported)}</dd>`).join('') : '<dt>Limits</dt><dd>none asked, nothing reported</dd>'}</dl>
|
|
102
117
|
<p class="hx-forge-meta">${ctx.esc(checksWords(run))}</p>
|
|
103
118
|
<p class="hx-forge-meta">${names.length ? `Changing ${run.nodesFrom === 'files' ? '' : 'or expected to change '}${ctx.esc(names.join(', '))}` : 'No node on the map yet.'}</p>
|
|
119
|
+
${retryHtml(ctx, run, all)}
|
|
104
120
|
${links ? `<p class="hx-forge-meta">${links}</p>` : ''}
|
|
105
121
|
${answering ? answerHtml(ctx, run) : ''}${run.answer && !answering ? answeredHtml(ctx, run) : ''}
|
|
106
|
-
<div class="hx-run-actions">${stop}
|
|
122
|
+
<div class="hx-run-actions">${stop}${retry}
|
|
107
123
|
<button type="button" class="hx-btn hx-forge-act" data-run-select="${ctx.esc(run.runId)}" aria-pressed="${lit}" aria-label="Light the nodes of ${ctx.esc(run.runId)} on the map"${(run.nodes || []).length ? '' : ' disabled'}>${lit ? 'Lit on the map' : 'Light on the map'}</button>
|
|
108
124
|
<button type="button" class="hx-btn hx-forge-act" data-run-timeline="${ctx.esc(run.runId)}" aria-expanded="${open}" aria-controls="run-tl-${ctx.esc(run.runId)}">Timeline (${count})</button></div>
|
|
109
|
-
${open ? timelineHtml(ctx, run) : ''}</li>`;
|
|
125
|
+
${open ? timelineHtml(ctx, run, all) : ''}</li>`;
|
|
110
126
|
}
|
|
111
127
|
|
|
112
128
|
/**
|
package/explorer/theme-boot.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Before the first paint (a classic script in the head of explorer/index.html, not a module, so it
|
|
3
|
-
* before the page is drawn): puts the theme on <html data-theme>, so a light page never flashes dark. The
|
|
2
|
+
* Before the first paint (a classic script, the last thing in the head of explorer/index.html, not a module, so it
|
|
3
|
+
* runs before the body is parsed and the page is drawn): puts the theme on <html data-theme>, so a light page never flashes dark. The
|
|
4
4
|
* same rule as theme-model.js `themeChoiceFrom` and `resolveTheme` (a test holds them together); theme.js
|
|
5
5
|
* takes over once the modules load.
|
|
6
6
|
*/
|
|
@@ -14,3 +14,23 @@
|
|
|
14
14
|
|| (choice !== 'dark' && !!(window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches));
|
|
15
15
|
document.documentElement.setAttribute('data-theme', light ? 'light' : 'dark');
|
|
16
16
|
})();
|
|
17
|
+
|
|
18
|
+
/*
|
|
19
|
+
* The named themes of the config (`theme.names`, docs/config.md#theme): the server puts them on <html data-theme-names="a b"
|
|
20
|
+
* data-theme-default="a">. This puts the viewer's pick (localStorage, when it is one of them) or the default on
|
|
21
|
+
* <html data-theme-name> before the first paint, and points the named theme's <link id="cf-theme-name-css"> at it (that link comes
|
|
22
|
+
* before this script in the head, so it exists now). Only a plain name (theme-model.js `themeNameHref`) ever reaches the attribute or
|
|
23
|
+
* the URL. The same rule as theme-model.js `themeNameFrom` (a test holds them together).
|
|
24
|
+
*/
|
|
25
|
+
(function () {
|
|
26
|
+
var root = document.documentElement;
|
|
27
|
+
var names = (root.getAttribute('data-theme-names') || '').split(' ').filter(function (n) { return /^[a-z0-9][a-z0-9-]{0,31}$/.test(n); });
|
|
28
|
+
if (!names.length) return;
|
|
29
|
+
var stored = null;
|
|
30
|
+
try { stored = window.localStorage.getItem('cornfield:theme-name'); } catch (e) { stored = null; }
|
|
31
|
+
var fallback = root.getAttribute('data-theme-default');
|
|
32
|
+
var name = stored && names.indexOf(stored) >= 0 ? stored : (fallback && names.indexOf(fallback) >= 0 ? fallback : '');
|
|
33
|
+
if (name) root.setAttribute('data-theme-name', name); else root.removeAttribute('data-theme-name');
|
|
34
|
+
var link = document.getElementById('cf-theme-name-css');
|
|
35
|
+
if (link) { if (name) link.setAttribute('href', '/cornfield/theme/' + name + '.css'); else link.removeAttribute('href'); }
|
|
36
|
+
})();
|
package/explorer/theme-model.js
CHANGED
|
@@ -30,6 +30,25 @@
|
|
|
30
30
|
export const THEME_CHOICES = ['system', 'light', 'dark'];
|
|
31
31
|
/** Where the choice is kept in the browser (theme.js); `?theme=` in the address wins over it, without being kept */
|
|
32
32
|
export const THEME_STORAGE_KEY = 'topology-explorer:theme';
|
|
33
|
+
/** Where a viewer's pick among the config's named themes is kept (theme-names.js); theme-boot.js reads the same key */
|
|
34
|
+
export const THEME_NAME_STORAGE_KEY = 'cornfield:theme-name';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The named theme in force: the stored pick when it is one of `names`, else the config's default when that is one, else none ('').
|
|
38
|
+
* The same rule as theme-boot.js (a test holds them together).
|
|
39
|
+
* @param {string|null} stored what THEME_NAME_STORAGE_KEY holds
|
|
40
|
+
* @param {string[]} names the config's theme names
|
|
41
|
+
* @param {string|null} fallback the config's default
|
|
42
|
+
* @returns {string}
|
|
43
|
+
*/
|
|
44
|
+
export function themeNameFrom(stored, names, fallback) {
|
|
45
|
+
if (stored && names.includes(stored)) return stored;
|
|
46
|
+
return fallback && names.includes(fallback) ? fallback : '';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Where a named theme's stylesheet is served (server/server.js); '' for no named theme */
|
|
50
|
+
export const themeNameHref = (name) => (/^[a-z0-9][a-z0-9-]{0,31}$/.test(name) ? `/cornfield/theme/${name}.css` : '');
|
|
51
|
+
|
|
33
52
|
/** The light page's ground (--hx-bg in explorer.css): what the light colours are measured against */
|
|
34
53
|
export const LIGHT_GROUND = '#f4f6fa';
|
|
35
54
|
/** The dark page's ground, for checking what the dark theme already does */
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/theme-names
|
|
3
|
+
*
|
|
4
|
+
* The named themes of the config (`theme.names`, docs/config.md#theme), the half that touches the page after load. theme-boot.js has
|
|
5
|
+
* already put the pick on <html data-theme-name> before the first paint; this fills the small <select> in the header with the names,
|
|
6
|
+
* and on a change sets the attribute, points the named theme's stylesheet link at it, and keeps the pick in localStorage
|
|
7
|
+
* (THEME_NAME_STORAGE_KEY). A theme is CSS only: nothing here loads anything but a stylesheet from this origin.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { THEME_NAME_STORAGE_KEY, themeNameFrom, themeNameHref } from './theme-model.js';
|
|
11
|
+
|
|
12
|
+
function readStored() {
|
|
13
|
+
try { return window.localStorage.getItem(THEME_NAME_STORAGE_KEY); } catch { return null; }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function store(name, fallback) {
|
|
17
|
+
try {
|
|
18
|
+
if (name === fallback) window.localStorage.removeItem(THEME_NAME_STORAGE_KEY);
|
|
19
|
+
else window.localStorage.setItem(THEME_NAME_STORAGE_KEY, name);
|
|
20
|
+
} catch { /* storage blocked: the pick still holds for this visit */ }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Puts a named theme in force on the page ('' for none) */
|
|
24
|
+
export function setThemeName(doc, name) {
|
|
25
|
+
const root = doc.documentElement;
|
|
26
|
+
if (name) root.setAttribute('data-theme-name', name); else root.removeAttribute('data-theme-name');
|
|
27
|
+
const link = doc.getElementById('cf-theme-name-css');
|
|
28
|
+
const href = themeNameHref(name);
|
|
29
|
+
if (link) { if (href) link.setAttribute('href', href); else link.removeAttribute('href'); }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Fills the header's picker from the config (`{ names, default }`, from /cornfield/config.json) and wires it. Hidden when there are no names.
|
|
34
|
+
* @param {Document} doc
|
|
35
|
+
* @param {{ names?: string[], default?: string | null } | null | undefined} theme
|
|
36
|
+
*/
|
|
37
|
+
export function initThemePicker(doc, theme) {
|
|
38
|
+
const select = doc.getElementById('theme-name-select');
|
|
39
|
+
if (!select) return;
|
|
40
|
+
const names = theme && Array.isArray(theme.names) ? theme.names.filter((n) => themeNameHref(n)) : [];
|
|
41
|
+
if (!names.length) { select.hidden = true; return; }
|
|
42
|
+
const fallback = theme.default && names.includes(theme.default) ? theme.default : '';
|
|
43
|
+
select.textContent = '';
|
|
44
|
+
const add = (value, label) => {
|
|
45
|
+
const o = doc.createElement('option');
|
|
46
|
+
o.value = value;
|
|
47
|
+
o.textContent = label;
|
|
48
|
+
select.appendChild(o);
|
|
49
|
+
};
|
|
50
|
+
if (!fallback) add('', 'Standard');
|
|
51
|
+
for (const n of names) add(n, n);
|
|
52
|
+
const current = themeNameFrom(readStored(), names, fallback);
|
|
53
|
+
setThemeName(doc, current);
|
|
54
|
+
select.value = current;
|
|
55
|
+
select.hidden = false;
|
|
56
|
+
select.onchange = () => {
|
|
57
|
+
const next = names.includes(select.value) ? select.value : '';
|
|
58
|
+
setThemeName(doc, next);
|
|
59
|
+
store(next, fallback);
|
|
60
|
+
};
|
|
61
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cornfield",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "popcorn245 (https://github.com/popcorn245)",
|
package/server/agent-api.js
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The routes that ask for agent runs and show them (issue #80, spec 0005 D10; the engine is server/agent-runs.js).
|
|
5
5
|
*
|
|
6
|
-
* POST /api/agent-requests { kind, refs, profile?, brief?, branch?, limits?, nodes?, force? }, with `Authorization: Bearer cf_at_…`
|
|
6
|
+
* POST /api/agent-requests { kind, refs, profile?, brief?, branch?, limits?, nodes?, retryOf?, force? }, with `Authorization: Bearer cf_at_…`
|
|
7
7
|
* GET /api/agent-requests the queue, for a runner token: server/runner-api.js (and the pull transport's claim and report routes)
|
|
8
8
|
* GET /api/agent-tokens the signed-in maintainer's agent tokens (and POST, and /<id>/revoke: server/review-api.js)
|
|
9
9
|
* GET /api/agent-runs[?follow=1] the runs, newest first, with the cap and how many are open; `follow=1` looks at the forge first
|
|
10
10
|
* GET /api/agent-runs/<runId> one run
|
|
11
|
+
* GET /api/agent-runs/<runId>/brief its whole brief, for Start again (the run shows the first 2000 characters): the signed-in maintainer's only
|
|
11
12
|
* POST /api/agent-runs the dashboard's Start an agent: the same body as the API
|
|
12
13
|
* POST /api/agent-runs/<runId>/stop { note? } asks the runner to stop
|
|
13
14
|
* POST /api/agent-runs/<runId>/answer { action: 'continue' | 'stop' | 'reply', text? } answers a run that reported `waiting`
|
|
@@ -157,11 +158,12 @@ export async function serveAgentCall(req, res, ctx) {
|
|
|
157
158
|
* @returns {Promise<boolean>} whether the path was one of these
|
|
158
159
|
*/
|
|
159
160
|
export async function serveRunRoutes(req, res, reqPath, ctx) {
|
|
160
|
-
const m = /^\/api\/agent-runs(?:\/(run-[0-9A-Za-z]{26}))?(\/stop|\/answer)?$/.exec(reqPath);
|
|
161
|
+
const m = /^\/api\/agent-runs(?:\/(run-[0-9A-Za-z]{26}))?(\/stop|\/answer|\/brief)?$/.exec(reqPath);
|
|
161
162
|
if (!m || (m[2] && !m[1])) return false;
|
|
162
163
|
const { auth, runs, session } = ctx;
|
|
163
164
|
const runId = m[1] ?? null;
|
|
164
|
-
const
|
|
165
|
+
const reading = m[2] === '/brief';
|
|
166
|
+
const allow = reading ? 'GET, HEAD' : m[2] ? 'POST' : runId ? 'GET, HEAD' : 'GET, HEAD, POST';
|
|
165
167
|
if (!allow.split(', ').includes(req.method || '')) {
|
|
166
168
|
req.resume();
|
|
167
169
|
send(res, 405, { ok: false, error: 'Method not allowed.', code: 'invalid' }, { Allow: allow });
|
|
@@ -175,6 +177,12 @@ export async function serveRunRoutes(req, res, reqPath, ctx) {
|
|
|
175
177
|
|
|
176
178
|
if (req.method === 'GET' || req.method === 'HEAD') {
|
|
177
179
|
req.resume();
|
|
180
|
+
if (reading) {
|
|
181
|
+
// A session's only (the guard reads cookies, never a token), and a run of this repo's only
|
|
182
|
+
const brief = await runs.brief(/** @type {string} */ (runId));
|
|
183
|
+
send(res, brief !== null ? 200 : 404, brief !== null ? { ok: true, runId, brief } : { ok: false, error: 'cornfield has no such run.', code: 'not-found' });
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
178
186
|
if (runId) {
|
|
179
187
|
const run = isRunId(runId) ? await runs.get(runId) : null;
|
|
180
188
|
send(res, run ? 200 : 404, run ? { ok: true, run } : { ok: false, error: 'cornfield has no such run.', code: 'not-found' });
|