cornfield 0.15.0 → 0.17.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 +53 -19
- package/core/agent-contract.schema.json +33 -1
- package/core/config.js +16 -3
- package/explorer/forge-panel.js +45 -3
- package/explorer/index.html +1 -0
- package/explorer/runs-model.js +38 -2
- package/explorer/runs-view.js +25 -4
- package/package.json +1 -1
- package/server/agent-api.js +14 -4
- package/server/agent-runs.js +492 -26
- package/server/db.js +78 -1
- package/server/forge-forgejo.js +8 -0
- package/server/forge-github.js +7 -0
- package/server/forge.js +15 -2
- package/server/hooks.js +7 -4
- package/server/server.js +3 -1
- package/server/spec-poll.js +18 -2
package/core/agent-contract.js
CHANGED
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
* - **A run id,** `run-` and a 26 character ULID (Crockford base32): `newRunId`, `isRunId`.
|
|
9
9
|
* - **The request,** JSON v1, checked strictly (`validateRequest`, `createRequest`). It carries no credential, ever: a field
|
|
10
10
|
* named like a token, a secret or a password is refused, and so is a value shaped like one.
|
|
11
|
-
* - **The report** a runner may send (`validateReport`: claimed, working, done, failed, stopped)
|
|
12
|
-
* cornfield sends (`validateStopRequest`: `stop-requested`)
|
|
11
|
+
* - **The report** a runner may send (`validateReport`: claimed, working, waiting, done, failed, stopped), **the stop request**
|
|
12
|
+
* cornfield sends (`validateStopRequest`: `stop-requested`) and **the answer** a maintainer gives a run that reported `waiting`
|
|
13
|
+
* (`validateAnswer`: `answered`, with an `action` of continue, stop or reply).
|
|
13
14
|
* - **The fenced block,** one form for all three, modelled on the review block of ADR 0005 (server/reviews.js):
|
|
14
15
|
*
|
|
15
16
|
* Asked for a code run `run-01JC…` on #12 (maintainer-one, in cornfield).
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
*
|
|
21
22
|
* `formatRunComment` writes it (the human line is defused, so it pings and links nobody), `readRunBlocks` and
|
|
22
23
|
* `parseRunBlocks` read it back: tolerant of the text around a block, strict about what is inside. A block that is not
|
|
23
|
-
* strictly a request, a report
|
|
24
|
+
* strictly a request, a report, a stop request or an answer is skipped, and `readRunBlocks` says which and why.
|
|
24
25
|
* - **The trailer,** `Cornfield-Run: run-…` on its own line of a pull request body or a commit message, with the run id in a
|
|
25
26
|
* branch name as the fallback (`parseTrailer`, `runIdFromBranch`, `findRunId`).
|
|
26
27
|
*
|
|
@@ -40,11 +41,13 @@
|
|
|
40
41
|
* @typedef {{ minutes?: number, turns?: number, cost?: number }} RunLimits
|
|
41
42
|
* @typedef {{ version: 1, runId: string, kind: RunKind, profile?: string, refs: RunRefs, branch?: string, brief: string,
|
|
42
43
|
* limits?: RunLimits, nodes?: string[], requestedBy: string, requestedAt: string, trigger?: { event: 'spec.approved' | 'build.opened' | 'thread.message', by: string, ref: string } }} RunRequest
|
|
43
|
-
* @typedef {'claimed' | 'working' | 'done' | 'failed' | 'stopped'} ReportState
|
|
44
|
+
* @typedef {'claimed' | 'working' | 'waiting' | 'done' | 'failed' | 'stopped'} ReportState
|
|
44
45
|
* @typedef {{ state: ReportState, note?: string, url?: string, tokens?: number, cost?: number }} RunReport
|
|
45
46
|
* @typedef {{ state: 'stop-requested', note?: string }} StopRequest
|
|
47
|
+
* @typedef {'continue' | 'stop' | 'reply'} AnswerAction
|
|
48
|
+
* @typedef {{ state: 'answered', action: AnswerAction, text?: string }} RunAnswer
|
|
46
49
|
* @typedef {{ ok: true, value: any } | { ok: false, error: string }} Checked
|
|
47
|
-
* @typedef {{ runId: string, type: 'request', value: RunRequest } | { runId: string, type: 'report', value: RunReport } | { runId: string, type: 'stop-request', value: StopRequest }} RunBlock
|
|
50
|
+
* @typedef {{ runId: string, type: 'request', value: RunRequest } | { runId: string, type: 'report', value: RunReport } | { runId: string, type: 'stop-request', value: StopRequest } | { runId: string, type: 'answer', value: RunAnswer }} RunBlock
|
|
48
51
|
*/
|
|
49
52
|
|
|
50
53
|
import { defuse } from './defuse.js';
|
|
@@ -58,11 +61,14 @@ const randomBytes = (n) => globalThis.crypto.getRandomValues(new Uint8Array(n));
|
|
|
58
61
|
|
|
59
62
|
export const CONTRACT_VERSION = 1;
|
|
60
63
|
export const RUN_KINDS = ['code', 'summary', 'brief', 'proposal'];
|
|
61
|
-
export const REPORT_STATES = ['claimed', 'working', 'done', 'failed', 'stopped'];
|
|
64
|
+
export const REPORT_STATES = ['claimed', 'working', 'waiting', 'done', 'failed', 'stopped'];
|
|
62
65
|
export const STOP_STATE = 'stop-requested';
|
|
66
|
+
/** The state of an answer block, and what a maintainer may answer a `waiting` run */
|
|
67
|
+
export const ANSWER_STATE = 'answered';
|
|
68
|
+
export const ANSWER_ACTIONS = ['continue', 'stop', 'reply'];
|
|
63
69
|
/** The brief, in characters */
|
|
64
70
|
export const MAX_BRIEF_CHARS = 20000;
|
|
65
|
-
/** A report's or a stop request's note, in characters */
|
|
71
|
+
/** A report's or a stop request's note, and an answer's text, in characters */
|
|
66
72
|
export const MAX_NOTE_CHARS = 4000;
|
|
67
73
|
export const MAX_URL_CHARS = 2000;
|
|
68
74
|
export const MAX_NODES = 100;
|
|
@@ -91,6 +97,7 @@ const REF_KEYS = ['issue', 'proposal', 'pull', 'thread'];
|
|
|
91
97
|
const LIMIT_KEYS = ['minutes', 'turns', 'cost'];
|
|
92
98
|
const REPORT_KEYS = ['state', 'note', 'url', 'tokens', 'cost'];
|
|
93
99
|
const STOP_KEYS = ['state', 'note'];
|
|
100
|
+
const ANSWER_KEYS = ['state', 'action', 'text'];
|
|
94
101
|
|
|
95
102
|
// ---------------------------------------------------------------------------
|
|
96
103
|
// Patterns. Each is plain ECMAScript with no flags, so the JSON Schema can carry the same source.
|
|
@@ -391,7 +398,7 @@ export function createRequest(fields, { profiles, now = Date.now, random } = {})
|
|
|
391
398
|
}
|
|
392
399
|
|
|
393
400
|
// ---------------------------------------------------------------------------
|
|
394
|
-
// The report,
|
|
401
|
+
// The report, the stop request and the answer
|
|
395
402
|
// ---------------------------------------------------------------------------
|
|
396
403
|
|
|
397
404
|
function noteAndUrl(body, no) {
|
|
@@ -448,18 +455,43 @@ export function validateStopRequest(body) {
|
|
|
448
455
|
return { ok: true, value: { state: STOP_STATE, ...(body.note !== undefined ? { note: body.note } : {}) } };
|
|
449
456
|
}
|
|
450
457
|
|
|
458
|
+
/**
|
|
459
|
+
* Checks an answer: `{ state: 'answered', action, text? }`. A maintainer sends it to a run that reported `waiting`: `continue` (go on),
|
|
460
|
+
* `stop` (the same as a stop request) or `reply` (go on with `text`, which a reply must have). cornfield or a maintainer sends it; the
|
|
461
|
+
* runner decides what it means.
|
|
462
|
+
* @param {unknown} body
|
|
463
|
+
* @returns {Checked}
|
|
464
|
+
*/
|
|
465
|
+
export function validateAnswer(body) {
|
|
466
|
+
const no = (error) => ({ ok: false, error });
|
|
467
|
+
if (!isObject(body)) return no('An answer is a JSON object with a state.');
|
|
468
|
+
const keys = keyProblem(body, ANSWER_KEYS, 'An answer');
|
|
469
|
+
if (keys) return no(keys);
|
|
470
|
+
const secret = valueProblem(body, 'The answer');
|
|
471
|
+
if (secret) return no(secret);
|
|
472
|
+
if (body.state !== ANSWER_STATE) return no(`"state" is "${ANSWER_STATE}".`);
|
|
473
|
+
if (!ANSWER_ACTIONS.includes(body.action)) return no(`"action" is one of ${ANSWER_ACTIONS.join(', ')}.`);
|
|
474
|
+
if (body.text !== undefined) {
|
|
475
|
+
const problem = text(body.text, 'text', MAX_NOTE_CHARS);
|
|
476
|
+
if (problem) return no(problem);
|
|
477
|
+
}
|
|
478
|
+
if (body.action === 'reply' && (body.text === undefined || body.text.trim() === '')) return no('A reply has "text": what the maintainer says.');
|
|
479
|
+
return { ok: true, value: { state: ANSWER_STATE, action: body.action, ...(body.text !== undefined && body.text.trim() !== '' ? { text: body.text } : {}) } };
|
|
480
|
+
}
|
|
481
|
+
|
|
451
482
|
/**
|
|
452
483
|
* Checks whatever a `cornfield-run` block holds, by its shape: a `version` makes it a request, the state `stop-requested` a
|
|
453
|
-
* stop request, any other state a report.
|
|
484
|
+
* stop request, the state `answered` an answer, any other state a report.
|
|
454
485
|
* @param {unknown} body
|
|
455
486
|
* @param {{ profiles?: string[] }} [opts]
|
|
456
|
-
* @returns {{ ok: true, type: 'request' | 'report' | 'stop-request', value: any } | { ok: false, error: string }}
|
|
487
|
+
* @returns {{ ok: true, type: 'request' | 'report' | 'stop-request' | 'answer', value: any } | { ok: false, error: string }}
|
|
457
488
|
*/
|
|
458
489
|
export function validateRunBody(body, opts) {
|
|
459
490
|
if (Array.isArray(body)) return { ok: false, error: 'A cornfield-run block holds one JSON object, not a list.' };
|
|
460
491
|
if (!isObject(body)) return { ok: false, error: 'A cornfield-run block holds one JSON object.' };
|
|
461
492
|
const [type, checked] = 'version' in body || 'runId' in body ? ['request', validateRequest(body, opts)]
|
|
462
493
|
: body.state === STOP_STATE ? ['stop-request', validateStopRequest(body)]
|
|
494
|
+
: body.state === ANSWER_STATE ? ['answer', validateAnswer(body)]
|
|
463
495
|
: 'state' in body ? ['report', validateReport(body)]
|
|
464
496
|
: ['request', validateRequest(body, opts)]; // neither shape: the request check names the first key or field that is wrong
|
|
465
497
|
return checked.ok ? { ok: true, type, value: checked.value } : checked;
|
|
@@ -471,7 +503,7 @@ export function validateRunBody(body, opts) {
|
|
|
471
503
|
|
|
472
504
|
const FENCE = '```';
|
|
473
505
|
|
|
474
|
-
/** The block for a checked request, report
|
|
506
|
+
/** The block for a checked request, report, stop request or answer, as text: the fence named for the run, the JSON, the closing fence. Throws on anything that is not strictly one. */
|
|
475
507
|
export function formatRunBlock(runId, body, opts) {
|
|
476
508
|
if (!isRunId(runId)) throw new TypeError(`${shown(runId)} is not a run id.`);
|
|
477
509
|
const checked = validateRunBody(body, opts);
|
|
@@ -492,14 +524,15 @@ function defaultLine(runId, type, value) {
|
|
|
492
524
|
return `Asked for a ${value.kind} run \`${runId}\` on ${about}${value.profile ? ` with the profile ${value.profile}` : ''} (${value.requestedBy}, in cornfield).`;
|
|
493
525
|
}
|
|
494
526
|
if (type === 'stop-request') return `Asked run \`${runId}\` to stop.`;
|
|
527
|
+
if (type === 'answer') return `Answered run \`${runId}\`: ${value.action}.`;
|
|
495
528
|
return `Run \`${runId}\`: ${value.state}.`;
|
|
496
529
|
}
|
|
497
530
|
|
|
498
531
|
/**
|
|
499
|
-
* The text of a comment for a request, a report
|
|
500
|
-
* report or stop request quoted and defused, then the block. The block keeps every value as sent, for the runner.
|
|
532
|
+
* The text of a comment for a request, a report, a stop request or an answer: a human line (defused: it pings and links nobody), the note of a
|
|
533
|
+
* report or stop request quoted and defused (an answer's text is in the block only), then the block. The block keeps every value as sent, for the runner.
|
|
501
534
|
* @param {string} runId
|
|
502
|
-
* @param {RunRequest | RunReport | StopRequest} body
|
|
535
|
+
* @param {RunRequest | RunReport | StopRequest | RunAnswer} body
|
|
503
536
|
* @param {{ line?: string, profiles?: string[] }} [opts] `line`: your own human line, in place of the default
|
|
504
537
|
* @returns {string}
|
|
505
538
|
*/
|
|
@@ -507,7 +540,8 @@ export function formatRunComment(runId, body, { line, profiles } = {}) {
|
|
|
507
540
|
const block = formatRunBlock(runId, body, { profiles });
|
|
508
541
|
const checked = validateRunBody(body, { profiles });
|
|
509
542
|
const head = oneLine(line ?? defaultLine(runId, checked.type, checked.value));
|
|
510
|
-
|
|
543
|
+
// An answer's text is the maintainer's words to the runner: it travels in the block only, never quoted beside it
|
|
544
|
+
const note = checked.type === 'request' || checked.type === 'answer' ? '' : (checked.value.note ?? '').trim();
|
|
511
545
|
const quoted = note ? `\n\n${defuse(note).split(/\r?\n/).map((l) => (l ? `> ${l}` : '>')).join('\n')}` : '';
|
|
512
546
|
const out = `${head}${quoted}\n\n${block}`;
|
|
513
547
|
if (out.length > MAX_COMMENT_CHARS) throw new RangeError(`That is too long for a comment (${out.length} characters, at most ${MAX_COMMENT_CHARS}); shorten the brief or the note.`);
|
|
@@ -545,7 +579,7 @@ export function* fencedBlocks(text) {
|
|
|
545
579
|
|
|
546
580
|
/**
|
|
547
581
|
* Every block a comment's text holds, in order, and every block that was refused with the reason. A block that is not strictly a
|
|
548
|
-
* request, a report
|
|
582
|
+
* request, a report, a stop request or an answer is refused: not JSON, a list, two objects, a key it does not have, a credential, a fence
|
|
549
583
|
* that names no run id, a request for another run than its fence names. Text around a block, a quoted block (`> ```…`), an
|
|
550
584
|
* indented one, one nobody closed, and one inside another fence (a ```` example) are ignored (`fencedBlocks`). Nothing is thrown,
|
|
551
585
|
* and the time it takes is linear in the text.
|
|
@@ -626,8 +660,8 @@ export function runAuthors(comments) {
|
|
|
626
660
|
* - `blocks`: from an author `trust(login)` accepts, in a comment not edited after it was posted;
|
|
627
661
|
* - `ignored`: well formed, but from someone else (or a deleted account), or in an edited comment: the spec wants one audit row
|
|
628
662
|
* for each, so they are kept with the reason;
|
|
629
|
-
* - `refused`: not strictly a request, report
|
|
630
|
-
* Whom to trust is the caller's to decide, because it takes the forge: a maintainer now for a request or
|
|
663
|
+
* - `refused`: not strictly a request, report, stop request or answer (`readRunBlocks`), with the author.
|
|
664
|
+
* Whom to trust is the caller's to decide, because it takes the forge: a maintainer now for a request, a stop or an answer, a login in
|
|
631
665
|
* `agents.runners` or a maintainer for a report (spec 0005). `trust` is asked once per block, with the block, so it can tell them
|
|
632
666
|
* apart.
|
|
633
667
|
* @param {RunComment[]} comments
|
|
@@ -665,7 +699,7 @@ export function parseRunBlocks(body, opts) {
|
|
|
665
699
|
* drops the ones whose author is not a maintainer, or whose comment was edited), or null. Later wins.
|
|
666
700
|
* @param {RunBlock[]} blocks
|
|
667
701
|
* @param {string} runId
|
|
668
|
-
* @param {'request' | 'report' | 'stop-request'} type
|
|
702
|
+
* @param {'request' | 'report' | 'stop-request' | 'answer'} type
|
|
669
703
|
* @returns {RunBlock | null}
|
|
670
704
|
*/
|
|
671
705
|
export function latestBlock(blocks, runId, type) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
3
|
"$id": "https://github.com/popcorn245/CornField/blob/main/core/agent-contract.schema.json",
|
|
4
4
|
"title": "cornfield agent contract, version 1",
|
|
5
|
-
"description": "The JSON a cornfield-run fenced block holds: a request, a report
|
|
5
|
+
"description": "The JSON a cornfield-run fenced block holds: a request, a report, a stop request or an answer. docs/agent-contract.md says what each means. Checks the shape; a few rules are the validator's alone (the configured profile list, that a date is a real one, that a reply has text), and are listed in the docs.",
|
|
6
6
|
"oneOf": [
|
|
7
7
|
{
|
|
8
8
|
"$ref": "#/$defs/request"
|
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
14
|
"$ref": "#/$defs/stopRequest"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"$ref": "#/$defs/answer"
|
|
15
18
|
}
|
|
16
19
|
],
|
|
17
20
|
"$defs": {
|
|
@@ -227,6 +230,7 @@
|
|
|
227
230
|
"enum": [
|
|
228
231
|
"claimed",
|
|
229
232
|
"working",
|
|
233
|
+
"waiting",
|
|
230
234
|
"done",
|
|
231
235
|
"failed",
|
|
232
236
|
"stopped"
|
|
@@ -285,6 +289,34 @@
|
|
|
285
289
|
}
|
|
286
290
|
}
|
|
287
291
|
}
|
|
292
|
+
},
|
|
293
|
+
"answer": {
|
|
294
|
+
"description": "A maintainer answering a run that reported waiting: continue, stop (the same as a stop request) or reply with text. The runner decides what it means.",
|
|
295
|
+
"type": "object",
|
|
296
|
+
"additionalProperties": false,
|
|
297
|
+
"required": [
|
|
298
|
+
"state",
|
|
299
|
+
"action"
|
|
300
|
+
],
|
|
301
|
+
"properties": {
|
|
302
|
+
"state": {
|
|
303
|
+
"const": "answered"
|
|
304
|
+
},
|
|
305
|
+
"action": {
|
|
306
|
+
"enum": [
|
|
307
|
+
"continue",
|
|
308
|
+
"stop",
|
|
309
|
+
"reply"
|
|
310
|
+
]
|
|
311
|
+
},
|
|
312
|
+
"text": {
|
|
313
|
+
"type": "string",
|
|
314
|
+
"maxLength": 4000,
|
|
315
|
+
"not": {
|
|
316
|
+
"pattern": "(?<![A-Za-z0-9])gh[pousr]_[A-Za-z0-9]{30,}|(?<![A-Za-z0-9])github_pat_[A-Za-z0-9_]{20,}|(?<![A-Za-z0-9])glpat-[A-Za-z0-9_-]{15,}|(?<![A-Za-z0-9])gto-[A-Za-z0-9]{20,}|(?<![A-Za-z0-9])cf_(?:rt|at|nt)_[A-Za-z0-9_-]{20,}|(?<![A-Za-z0-9])sk-(?=[A-Za-z0-9_-]{20})[A-Za-z_-]{0,40}[0-9]|(?<![A-Za-z0-9])AKIA[0-9A-Z]{16}|(?<![A-Za-z0-9])AIza[0-9A-Za-z_-]{35}|(?<![A-Za-z0-9])xox[abprs]-[A-Za-z0-9-]{10,}|(?<![A-Za-z0-9])eyJ[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{5,}|-----BEGIN [A-Z ]{0,40}PRIVATE KEY-----|(?<![A-Za-z0-9])[bB][eE][aA][rR][eE][rR][ \\t]+(?=[A-Za-z0-9._~+/=-]{20})[A-Za-z._~+/=-]{0,40}[0-9]|(?<![A-Za-z0-9+.-])[A-Za-z][A-Za-z0-9+.-]{0,31}://[^\\s/@:]+:[^\\s/@]+@"
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
288
320
|
}
|
|
289
321
|
}
|
|
290
322
|
}
|
package/core/config.js
CHANGED
|
@@ -70,7 +70,7 @@ export const FORGE_TYPES = ['github', 'forgejo'];
|
|
|
70
70
|
/** How a pull request cornfield lands is merged (`forge.mergeMethod`): the way the repo lands its pull requests */
|
|
71
71
|
export const MERGE_METHODS = ['merge', 'squash', 'rebase'];
|
|
72
72
|
/** The events a hook may ask for (`hooks[].events`), and what each one means: docs/config.md#hooks */
|
|
73
|
-
export const HOOK_EVENTS = Object.freeze(['spec.ready', 'spec.approved', 'spec.sentBack', 'build.opened', 'pr.landed', 'session.expiring', 'thread.opened', 'thread.message', 'thread.linked', 'agent.requested', 'run.claimed', 'run.state', 'run.stopRequested', 'run.finished', 'trigger.skipped', 'runner.offline']);
|
|
73
|
+
export const HOOK_EVENTS = Object.freeze(['spec.ready', 'spec.approved', 'spec.sentBack', 'build.opened', 'pr.landed', 'session.expiring', 'thread.opened', 'thread.message', 'thread.linked', 'agent.requested', 'run.claimed', 'run.state', 'run.waiting', 'run.answered', 'run.stopRequested', 'run.finished', 'trigger.skipped', 'runner.offline']);
|
|
74
74
|
/** The events that come from looking at threads (server/threads.js): a poll that wants any of them looks at threads too */
|
|
75
75
|
export const THREAD_EVENTS = Object.freeze(['thread.opened', 'thread.message', 'thread.linked']);
|
|
76
76
|
/** The keys of `threads` when it is an object, and the label's longest length */
|
|
@@ -159,7 +159,7 @@ export const DEFAULTS = Object.freeze({
|
|
|
159
159
|
personas: { roles: null, parent: 'root' },
|
|
160
160
|
cloud: { parent: 'root' },
|
|
161
161
|
releaseNotes: { breakingLabel: 'breaking' },
|
|
162
|
-
agents: { authors: [], labels: [], branchPrefixes: [], bots: true, transport: 'forge', maxOpen: DEFAULT_MAX_OPEN, profiles: [], runners: [], quietAfter: DEFAULT_QUIET_AFTER, runnerQuietAfter: DEFAULT_RUNNER_QUIET_AFTER, limits: {}, on: {}, refuseCollisions: false },
|
|
162
|
+
agents: { authors: [], labels: [], branchPrefixes: [], bots: true, transport: 'forge', maxOpen: DEFAULT_MAX_OPEN, profiles: [], runners: [], quietAfter: DEFAULT_QUIET_AFTER, runnerQuietAfter: DEFAULT_RUNNER_QUIET_AFTER, limits: {}, on: {}, refuseCollisions: false, handWritten: true },
|
|
163
163
|
hooks: [],
|
|
164
164
|
hookPoll: { specs: '5m' },
|
|
165
165
|
threads: { label: 'idea' },
|
|
@@ -175,7 +175,7 @@ export const PROPOSALS_KEYS = Object.freeze(['dir', 'approveLands']);
|
|
|
175
175
|
/** The keys of `worktrees` when it is an object: the folder, and how many days without a change leave a worktree out of the list (default: none is left out) */
|
|
176
176
|
export const WORKTREES_KEYS = Object.freeze(['dir', 'maxAgeDays']);
|
|
177
177
|
const MAX_WORKTREE_AGE_DAYS = 36500;
|
|
178
|
-
const AGENT_KEYS = ['authors', 'labels', 'branchPrefixes', 'bots', 'transport', 'maxOpen', 'profiles', 'runners', 'quietAfter', 'runnerQuietAfter', 'limits', 'on', 'refuseCollisions'];
|
|
178
|
+
const AGENT_KEYS = ['authors', 'labels', 'branchPrefixes', 'bots', 'transport', 'maxOpen', 'profiles', 'runners', 'quietAfter', 'runnerQuietAfter', 'limits', 'on', 'refuseCollisions', 'handWritten'];
|
|
179
179
|
const PROFILE_NAME = new RegExp(PROFILE_SOURCE);
|
|
180
180
|
const isObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
181
181
|
const isText = (v) => typeof v === 'string' && v.trim() !== '';
|
|
@@ -249,6 +249,7 @@ export function configProblems(c) {
|
|
|
249
249
|
}
|
|
250
250
|
if (c.agents.bots !== undefined && typeof c.agents.bots !== 'boolean') out.push('agents.bots is true or false: whether a bot account ("[bot]" or the forge\'s Bot type) counts as an agent.');
|
|
251
251
|
out.push(...agentRunProblems(c.agents));
|
|
252
|
+
if (c.agents.handWritten === 'labeled' && c.threads === false) out.push('agents.handWritten is "labeled", which needs the threads label, and threads are off (threads: false): use true or false.');
|
|
252
253
|
if (isObject(c.agents.on) && c.agents.on['thread.message'] !== undefined && c.threads === false) out.push('agents.on["thread.message"] needs threads, which are off (threads: false): the /agent command is read in a thread.');
|
|
253
254
|
}
|
|
254
255
|
}
|
|
@@ -373,6 +374,17 @@ function triggerProblems(a) {
|
|
|
373
374
|
return out;
|
|
374
375
|
}
|
|
375
376
|
|
|
377
|
+
/**
|
|
378
|
+
* Which open issues and pull requests are read for `cornfield-run` request blocks a maintainer wrote by hand (`agents.handWritten`, issue #98):
|
|
379
|
+
* `'all'` (the default, `true`), `'labeled'` (only those carrying the threads label), or `false` for none.
|
|
380
|
+
* @param {{ agents?: { handWritten?: unknown } }} config
|
|
381
|
+
* @returns {false | 'all' | 'labeled'}
|
|
382
|
+
*/
|
|
383
|
+
export const handWrittenMode = (config) => {
|
|
384
|
+
const v = config.agents?.handWritten;
|
|
385
|
+
return v === false ? false : v === 'labeled' ? 'labeled' : 'all';
|
|
386
|
+
};
|
|
387
|
+
|
|
376
388
|
/** The triggers a config turns on, as `[event, { kind, profile?, brief? }]` (none when off, which is the default) */
|
|
377
389
|
export const triggersOf = (config) => Object.entries(isObject(config.agents?.on) ? config.agents.on : {}).filter(([e]) => TRIGGER_EVENTS.includes(e));
|
|
378
390
|
|
|
@@ -381,6 +393,7 @@ function agentRunProblems(a) {
|
|
|
381
393
|
const out = [];
|
|
382
394
|
if (a.transport !== undefined && !AGENT_TRANSPORTS.includes(a.transport)) out.push(`agents.transport is ${AGENT_TRANSPORTS.map((t) => JSON.stringify(t)).join(', ')}: where a request goes: "forge" posts it as a comment (the default), "push" sends it as an agent.requested hook event, "pull" keeps it for a runner to claim (docs/agents.md#transports).`);
|
|
383
395
|
if (a.refuseCollisions !== undefined && typeof a.refuseCollisions !== 'boolean') out.push('agents.refuseCollisions is true or false: whether a new request that names a node an open run is already changing is refused (false unless set).');
|
|
396
|
+
if (a.handWritten !== undefined && a.handWritten !== true && a.handWritten !== false && a.handWritten !== 'labeled') out.push('agents.handWritten is true (the default: a maintainer\'s hand-written request block on any open issue or pull request becomes a run), "labeled" (only on those with the threads label) or false (cornfield follows only the runs it asked for): docs/agents.md#requests-written-by-hand.');
|
|
384
397
|
if (a.maxOpen !== undefined && !(Number.isInteger(a.maxOpen) && a.maxOpen >= 1 && a.maxOpen <= MAX_OPEN_CEILING)) out.push(`agents.maxOpen is a whole number from 1 to ${MAX_OPEN_CEILING}: the most open runs cornfield asks for at once (${DEFAULT_MAX_OPEN} unless set).`);
|
|
385
398
|
if (a.profiles !== undefined) {
|
|
386
399
|
if (!Array.isArray(a.profiles) || a.profiles.length > MAX_PROFILES || !a.profiles.every((p) => typeof p === 'string' && PROFILE_NAME.test(p)) || new Set(a.profiles).size !== a.profiles.length) {
|
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, KINDS, aboutWords, statusWords, statusWhy, runMeta, canStop, runsStatus, runnerState, runnerWords, triggerNotice, startBody, startWords, stopWords, confirmStartWords, litOfRun, changeWords,
|
|
72
|
+
RUNS_URL, runsUrl, stopUrl, answerUrl, answerBody, answerWordsFor, KINDS, aboutWords, statusWords, statusWhy, runMeta, canStop, runsStatus, runnerState, runnerWords, triggerNotice, handLines, startBody, startWords, stopWords, confirmStartWords, litOfRun, changeWords,
|
|
73
73
|
} from './runs-model.js';
|
|
74
74
|
import { runsHtml } from './runs-view.js';
|
|
75
75
|
import { setRunsOnMap, clearRunsOnMap } from './runs-map.js';
|
|
@@ -121,6 +121,7 @@ const ui = {
|
|
|
121
121
|
runSel: null, // the run lit on the map (Light on the map), by id
|
|
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
|
+
runReplies: new Map(), // the reply typed so far for each waiting run, so a repaint (the runs are looked at again) keeps it
|
|
124
125
|
agent: null, // { opener, refs, posting } while the Start an agent dialog is open
|
|
125
126
|
};
|
|
126
127
|
|
|
@@ -1043,6 +1044,8 @@ function findAgain(el) {
|
|
|
1043
1044
|
if (el.dataset.forgeRerun) return `[data-forge-rerun="${el.dataset.forgeRerun}"]`;
|
|
1044
1045
|
if (el.dataset.forgeAgent) return `[data-forge-agent="${el.dataset.forgeAgent}"]`;
|
|
1045
1046
|
if (el.dataset.forgeStop) return `[data-forge-stop="${el.dataset.forgeStop}"]`;
|
|
1047
|
+
if (el.dataset.runReply) return `[data-run-reply="${el.dataset.runReply}"]`;
|
|
1048
|
+
if (el.dataset.runAnswer) return `[data-run-answer="${el.dataset.runAnswer}"][data-run-id="${el.dataset.runId}"]`;
|
|
1046
1049
|
if (el.dataset.runSelect) return `[data-run-select="${el.dataset.runSelect}"]`;
|
|
1047
1050
|
if (el.dataset.runTimeline) return `[data-run-timeline="${el.dataset.runTimeline}"]`;
|
|
1048
1051
|
return null;
|
|
@@ -1130,6 +1133,12 @@ function paintRuns() {
|
|
|
1130
1133
|
trig.hidden = !skipped;
|
|
1131
1134
|
trig.textContent = skipped;
|
|
1132
1135
|
}
|
|
1136
|
+
const hand = $('forge-runs-hand');
|
|
1137
|
+
if (hand) {
|
|
1138
|
+
const lines = data ? handLines(data) : [];
|
|
1139
|
+
hand.hidden = !lines.length;
|
|
1140
|
+
hand.innerHTML = lines.map((l) => `<li>${escHtml(l)}</li>`).join('');
|
|
1141
|
+
}
|
|
1133
1142
|
const list = $('forge-runs-list');
|
|
1134
1143
|
if (!data) { list.innerHTML = ''; return; }
|
|
1135
1144
|
list.innerHTML = data.runs.length ? runsHtml(viewContext(), data.runs) : '<li class="hx-forge-empty hx-faint">No agent has been asked for yet. Start one from an issue or a proposal.</li>';
|
|
@@ -1150,7 +1159,7 @@ function viewContext() {
|
|
|
1150
1159
|
const base = f && safeUrl(f.url) ? f.url.replace(/\/+$/, '') : null;
|
|
1151
1160
|
return {
|
|
1152
1161
|
esc: escHtml, safeUrl, forgeName: forgeName(), forgeType: f ? f.type : 'github', repoUrl: base && f.repo ? `${base}/${f.repo}` : null,
|
|
1153
|
-
now: now(), nodes: state.nodes, selected: ui.runSel, timelines: ui.runTimelines, busy: !!ui.busy,
|
|
1162
|
+
now: now(), nodes: state.nodes, selected: ui.runSel, timelines: ui.runTimelines, replies: ui.runReplies, busy: !!ui.busy,
|
|
1154
1163
|
};
|
|
1155
1164
|
}
|
|
1156
1165
|
|
|
@@ -1547,6 +1556,35 @@ async function stopRun(runId) {
|
|
|
1547
1556
|
paint();
|
|
1548
1557
|
}
|
|
1549
1558
|
|
|
1559
|
+
/** Answers a waiting run: Continue, Stop, or a reply with the text typed. One POST, then the runs are read again */
|
|
1560
|
+
async function answerRun(runId, action) {
|
|
1561
|
+
if (ui.busy) return;
|
|
1562
|
+
const text = ui.runReplies.get(runId) || '';
|
|
1563
|
+
if (action === 'reply' && text.trim() === '') {
|
|
1564
|
+
ui.runNote = { text: 'Write a reply first.', ok: false };
|
|
1565
|
+
announce(ui.runNote.text);
|
|
1566
|
+
paint();
|
|
1567
|
+
return;
|
|
1568
|
+
}
|
|
1569
|
+
// Where the focus goes back to once it is sent: the reply field after a reply (empty, for the next one), the button after Continue; while the
|
|
1570
|
+
// buttons are disabled the focus has nowhere to stay, so it is put back by hand. A run that no longer asks (a Stop) gets its Timeline button
|
|
1571
|
+
const back = action === 'reply' ? `[data-run-reply="${runId}"]` : `[data-run-answer="${action}"][data-run-id="${runId}"]`;
|
|
1572
|
+
ui.busy = 'answer';
|
|
1573
|
+
ui.runNote = null;
|
|
1574
|
+
announce(`Answering ${runId}`);
|
|
1575
|
+
paint();
|
|
1576
|
+
const res = await post(answerUrl(runId), answerBody(action, text));
|
|
1577
|
+
ui.busy = '';
|
|
1578
|
+
if (res.ok && action === 'reply') ui.runReplies.delete(runId);
|
|
1579
|
+
ui.runNote = { text: answerWordsFor(res.status, res.body, runId, action), ok: res.ok };
|
|
1580
|
+
announce(ui.runNote.text);
|
|
1581
|
+
await loadRuns(false, { say: false });
|
|
1582
|
+
paint();
|
|
1583
|
+
const panel = $('forge-panel');
|
|
1584
|
+
const to = panel && [back, `[data-run-timeline="${runId}"]`].map((sel) => panel.querySelector(sel)).find((el) => el && !el.disabled);
|
|
1585
|
+
if (to && to !== document.activeElement) to.focus();
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1550
1588
|
// ---------------------------------------------------------------------------
|
|
1551
1589
|
// Opening and closing
|
|
1552
1590
|
// ---------------------------------------------------------------------------
|
|
@@ -1678,6 +1716,8 @@ function onClick(e) {
|
|
|
1678
1716
|
if (agent) { openAgent(agent.dataset.forgeAgent, `[data-forge-agent="${agent.dataset.forgeAgent}"]`); return; }
|
|
1679
1717
|
const stop = t.closest('[data-forge-stop]');
|
|
1680
1718
|
if (stop) { stopRun(stop.dataset.forgeStop); return; }
|
|
1719
|
+
const answer = t.closest('[data-run-answer]');
|
|
1720
|
+
if (answer) { answerRun(answer.dataset.runId, answer.dataset.runAnswer); return; }
|
|
1681
1721
|
const pick = t.closest('[data-run-select]');
|
|
1682
1722
|
if (pick) { selectRun(pick.dataset.runSelect); return; }
|
|
1683
1723
|
const timeline = t.closest('[data-run-timeline]');
|
|
@@ -1742,6 +1782,7 @@ function onChange(e) {
|
|
|
1742
1782
|
}
|
|
1743
1783
|
|
|
1744
1784
|
function onInput(e) {
|
|
1785
|
+
if (e.target.dataset && e.target.dataset.runReply) { ui.runReplies.set(e.target.dataset.runReply, e.target.value); return; }
|
|
1745
1786
|
if (e.target.id !== 'forge-text') return;
|
|
1746
1787
|
ui.filters.text = e.target.value;
|
|
1747
1788
|
filtersChanged(false);
|
|
@@ -1751,6 +1792,7 @@ function onInput(e) {
|
|
|
1751
1792
|
|
|
1752
1793
|
/** Escape anywhere in the panel closes it, and the button has the focus again (a field's own Escape comes first) */
|
|
1753
1794
|
function onKey(e) {
|
|
1795
|
+
if (e.key === 'Enter' && e.target.dataset && e.target.dataset.runReply && !e.defaultPrevented) { e.preventDefault(); answerRun(e.target.dataset.runReply, 'reply'); return; }
|
|
1754
1796
|
if (e.key === 'Enter' && e.target.id === 'notes-tag' && !e.defaultPrevented) { e.preventDefault(); postDraft(); return; }
|
|
1755
1797
|
if (e.key === 'Escape' && !e.defaultPrevented && ui.notes.confirm && e.target.closest && e.target.closest('#notes-confirm')) {
|
|
1756
1798
|
e.preventDefault();
|
|
@@ -1848,5 +1890,5 @@ export function resetForgePanelForTests(clock = () => Date.now()) {
|
|
|
1848
1890
|
runsTimer = 0;
|
|
1849
1891
|
pageAway = false;
|
|
1850
1892
|
clearRunsOnMap();
|
|
1851
|
-
Object.assign(ui, { runSel: null, runTimelines: new Set(), 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 });
|
|
1893
|
+
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 });
|
|
1852
1894
|
}
|
package/explorer/index.html
CHANGED
|
@@ -281,6 +281,7 @@
|
|
|
281
281
|
<p id="forge-runs-runner" class="hx-forge-meta" hidden></p>
|
|
282
282
|
<p id="forge-runs-note" class="hx-forge-notice" hidden></p>
|
|
283
283
|
<p id="forge-runs-trigger" class="hx-forge-notice" hidden></p>
|
|
284
|
+
<ul id="forge-runs-hand" class="hx-forge-meta" aria-label="Requests written by hand that started nothing" hidden></ul>
|
|
284
285
|
<ul id="forge-runs-list" class="hx-forge-files" aria-label="Runs"></ul>
|
|
285
286
|
</section>
|
|
286
287
|
<section id="forge-detail" class="hx-forge-detail" aria-label="Selected pull request" hidden></section>
|
package/explorer/runs-model.js
CHANGED
|
@@ -11,6 +11,7 @@ import { relativeTime } from './review-model.js';
|
|
|
11
11
|
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
|
+
export const answerUrl = (runId) => `${RUNS_URL}/${encodeURIComponent(runId)}/answer`;
|
|
14
15
|
|
|
15
16
|
/** The kinds of run (the contract's), and what each asks the runner for */
|
|
16
17
|
export const KINDS = Object.freeze([
|
|
@@ -32,7 +33,7 @@ export function aboutWords(refs) {
|
|
|
32
33
|
/** The state of a run, said short */
|
|
33
34
|
export function statusWords(run) {
|
|
34
35
|
const words = {
|
|
35
|
-
requested: 'Requested', claimed: 'Claimed', working: 'Working', done: 'Done', failed: 'Failed', stopped: 'Stopped',
|
|
36
|
+
requested: 'Requested', claimed: 'Claimed', working: 'Working', waiting: 'Waiting', done: 'Done', failed: 'Failed', stopped: 'Stopped',
|
|
36
37
|
'stop-requested': 'Stop requested', quiet: 'Quiet', merged: 'Merged', closed: 'Closed',
|
|
37
38
|
};
|
|
38
39
|
return words[run.status] || run.status;
|
|
@@ -44,13 +45,16 @@ export function statusWhy(run) {
|
|
|
44
45
|
case 'quiet': return 'Nothing reported or pushed for a while, so it no longer counts toward the limit. A report or a push brings it back.';
|
|
45
46
|
case 'stop-requested': return `${run.stopRequested && run.stopRequested.by ? run.stopRequested.by : 'A maintainer'} asked it to stop. The runner decides what that means; this stays until it says stopped, or the run goes quiet.`;
|
|
46
47
|
case 'requested': return 'Waiting for a runner to pick it up. cornfield only asks; it starts nothing.';
|
|
48
|
+
case 'waiting': return run.answer
|
|
49
|
+
? `${run.answer.by || 'A maintainer'} answered: ${answerWords(run.answer)}. The runner picks the answer up and goes on; answer again to change it until it does.`
|
|
50
|
+
: 'The runner stopped to ask and goes on once a maintainer answers: Continue, Stop, or a reply.';
|
|
47
51
|
default: return '';
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
/** A line of facts: who asked and when, the profile, the limits asked for beside what the runner reported */
|
|
52
56
|
export function runMeta(run, nowMs) {
|
|
53
|
-
const parts = [`asked ${relativeTime(run.requestedAt, nowMs)} by ${run.requestedBy}`];
|
|
57
|
+
const parts = [`asked ${relativeTime(run.requestedAt, nowMs)} by ${run.requestedBy}${run.byHand ? ' (by hand)' : ''}`];
|
|
54
58
|
if (run.profile) parts.push(`profile ${run.profile}`);
|
|
55
59
|
const l = run.limits || {};
|
|
56
60
|
const limits = [l.minutes != null && `${l.minutes} min`, l.turns != null && `${l.turns} turns`, l.cost != null && `cost ${l.cost}`].filter(Boolean);
|
|
@@ -82,9 +86,40 @@ export function triggerNotice(data) {
|
|
|
82
86
|
return out.join(' ');
|
|
83
87
|
}
|
|
84
88
|
|
|
89
|
+
/**
|
|
90
|
+
* The hand-written `cornfield-run` blocks that started nothing (`handWritten.refused`), one line each: who wrote it, where, and why. Empty when none.
|
|
91
|
+
* @returns {string[]}
|
|
92
|
+
*/
|
|
93
|
+
export function handLines(data) {
|
|
94
|
+
const list = data && data.handWritten && Array.isArray(data.handWritten.refused) ? data.handWritten.refused : [];
|
|
95
|
+
return list.map((r) => `Request by hand from ${r.by}${r.number ? ` on #${r.number}` : ''}${r.runId ? ` (${r.runId})` : ''} started nothing: ${r.reason || r.why}`);
|
|
96
|
+
}
|
|
97
|
+
|
|
85
98
|
/** Whether a Stop is offered: the run is open and nobody has asked it to stop yet */
|
|
86
99
|
export const canStop = (run) => run.open === true && !run.stopRequested;
|
|
87
100
|
|
|
101
|
+
/** Whether the run asks for an answer (Continue, Stop, Reply): the runner reported `waiting` and nobody has asked it to stop */
|
|
102
|
+
export const canAnswer = (run) => run.open === true && run.status === 'waiting' && !run.stopRequested;
|
|
103
|
+
|
|
104
|
+
/** An answer, said short: "continue", "stop", "reply: use the second plan" */
|
|
105
|
+
export function answerWords(answer) {
|
|
106
|
+
if (!answer) return '';
|
|
107
|
+
return answer.action === 'reply' ? `reply: ${answer.text || ''}`.trim() : answer.action;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The body of an answer: the action, and a reply's text (trimmed); Continue and Stop carry none */
|
|
111
|
+
export function answerBody(action, text) {
|
|
112
|
+
return action === 'reply' ? { action, text: (text || '').trim() } : { action };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** What an answer came to */
|
|
116
|
+
export function answerWordsFor(status, body, runId, action) {
|
|
117
|
+
if (status === null) return 'cornfield did not answer; nothing was sent.';
|
|
118
|
+
if (status === 401) return 'Your sign-in has ended. Sign in again to answer a run.';
|
|
119
|
+
if (body && body.ok) return action === 'stop' ? `Asked ${runId} to stop. The runner decides what that means.` : `Answered ${runId}: ${action}. The runner picks it up and goes on.`;
|
|
120
|
+
return (body && body.error) || `The answer was refused (${status}).`;
|
|
121
|
+
}
|
|
122
|
+
|
|
88
123
|
/** The summary line over the list: "2 open of 3 allowed, 5 runs" */
|
|
89
124
|
export function runsStatus(data) {
|
|
90
125
|
const n = data.runs.length;
|
|
@@ -234,6 +269,7 @@ export function timelineWords(entry) {
|
|
|
234
269
|
case 'pull-opened': return { what: `Opened pull request ${entry.ref || ''}${by}`.trim(), note: '' };
|
|
235
270
|
case 'checks': return { what: { success: 'Checks passed', failure: 'Checks failed', running: 'Checks running', none: 'No checks' }[entry.ref] || 'Checks changed', note: '' };
|
|
236
271
|
case 'stop-requested': return { what: `Asked to stop${by}`, note: entry.note || '' };
|
|
272
|
+
case 'answered': return { what: `Answered ${entry.ref || ''}${by}`.replace(/\s+/g, ' ').trim(), note: entry.note || '' };
|
|
237
273
|
case 'merged': return { what: `Landed: pull request ${entry.ref || ''} merged`, note: '' };
|
|
238
274
|
case 'closed': return { what: `Pull request ${entry.ref || ''} closed without landing`, note: '' };
|
|
239
275
|
case 'quiet': return { what: 'Went quiet: nothing reported or pushed for a while', note: '' };
|
package/explorer/runs-view.js
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { relativeTime } from './review-model.js';
|
|
12
|
-
import { aboutWords, statusWords, statusWhy, runMeta, canStop, groupRuns, compareTitle, limitRows, checksWords, timelineWords, nodeLabels, collisionWords } from './runs-model.js';
|
|
12
|
+
import { aboutWords, statusWords, statusWhy, runMeta, canStop, canAnswer, groupRuns, compareTitle, limitRows, checksWords, timelineWords, nodeLabels, collisionWords, answerWords } from './runs-model.js';
|
|
13
13
|
|
|
14
|
-
const TONE = { done: 'success', merged: 'success', failed: 'failure', quiet: 'queued', 'stop-requested': 'queued' };
|
|
14
|
+
const TONE = { done: 'success', merged: 'success', failed: 'failure', quiet: 'queued', 'stop-requested': 'queued', waiting: 'queued' };
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* @typedef {object} ViewContext
|
|
@@ -25,6 +25,7 @@ const TONE = { done: 'success', merged: 'success', failed: 'failure', quiet: 'qu
|
|
|
25
25
|
* @property {string | null} selected the run lit on the map
|
|
26
26
|
* @property {Set<string>} timelines the runs whose timeline is open
|
|
27
27
|
* @property {boolean} busy an action is in flight
|
|
28
|
+
* @property {Map<string, string>} [replies] the reply typed so far for each waiting run, so a repaint keeps it
|
|
28
29
|
*/
|
|
29
30
|
|
|
30
31
|
/** A link that opens a new tab, said so for a screen reader */
|
|
@@ -45,7 +46,7 @@ function linksHtml(ctx, run) {
|
|
|
45
46
|
thread != null && ctx.repoUrl ? link(ctx, `${ctx.repoUrl}/issues/${thread}`, `Thread #${thread}`) : '',
|
|
46
47
|
run.branch ? link(ctx, branchUrl(ctx, run.branch), `Branch ${run.branch}`) : '',
|
|
47
48
|
run.pull ? link(ctx, run.pull.url, `Pull request #${run.pull.number}`, run.pull.trusted ? '' : ' <span class="hx-faint">(not from a runner, so it moves nothing)</span>') : '',
|
|
48
|
-
link(ctx, run.report && run.report.url, 'Runner\'s log'),
|
|
49
|
+
link(ctx, run.report && run.report.url, run.status === 'waiting' ? 'Runner\'s link' : 'Runner\'s log'),
|
|
49
50
|
].filter(Boolean).join(' · ');
|
|
50
51
|
}
|
|
51
52
|
|
|
@@ -57,6 +58,24 @@ function timelineHtml(ctx, run) {
|
|
|
57
58
|
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
59
|
}
|
|
59
60
|
|
|
61
|
+
/** What was answered, escaped: the action, a reply's words, who and when */
|
|
62
|
+
function answeredHtml(ctx, run) {
|
|
63
|
+
const a = run.answer;
|
|
64
|
+
return `<p class="hx-forge-meta">Answered: ${ctx.esc(answerWords(a))} · ${ctx.esc(a.by || 'a maintainer')}, ${ctx.esc(relativeTime(a.at, ctx.now) || a.at)}</p>`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** A waiting run: what was asked (the note and link are shown above) and the three answers, plain buttons and a reply field */
|
|
68
|
+
function answerHtml(ctx, run) {
|
|
69
|
+
const id = ctx.esc(run.runId);
|
|
70
|
+
const off = ctx.busy ? ' disabled' : '';
|
|
71
|
+
const reply = ctx.replies && ctx.replies.get(run.runId) || '';
|
|
72
|
+
return `${run.answer ? answeredHtml(ctx, run) : ''}<div class="hx-run-actions" role="group" aria-label="Answer run ${id}">
|
|
73
|
+
<button type="button" class="hx-btn hx-forge-act" data-run-answer="continue" data-run-id="${id}" aria-label="Continue run ${id}"${off}>Continue</button>
|
|
74
|
+
<button type="button" class="hx-btn hx-forge-act" data-run-answer="stop" data-run-id="${id}" aria-label="Stop run ${id}"${off}>Stop</button></div>
|
|
75
|
+
<label class="hx-forge-field">Reply to run ${id}<input type="text" class="hx-forge-input" data-run-reply="${id}" value="${ctx.esc(reply)}" maxlength="4000" autocomplete="off" /></label>
|
|
76
|
+
<div class="hx-run-actions"><button type="button" class="hx-btn hx-forge-act" data-run-answer="reply" data-run-id="${id}" aria-label="Send reply to run ${id}"${off}>Reply</button></div>`;
|
|
77
|
+
}
|
|
78
|
+
|
|
60
79
|
/** One run */
|
|
61
80
|
export function runHtml(ctx, run, all) {
|
|
62
81
|
const lit = ctx.selected === run.runId;
|
|
@@ -64,7 +83,8 @@ export function runHtml(ctx, run, all) {
|
|
|
64
83
|
const tone = TONE[run.status] || 'running';
|
|
65
84
|
const why = statusWhy(run);
|
|
66
85
|
const note = run.report && run.report.note ? `<p class="hx-forge-meta">Runner: ${ctx.esc(run.report.note)}</p>` : '';
|
|
67
|
-
const
|
|
86
|
+
const answering = canAnswer(run);
|
|
87
|
+
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>` : '';
|
|
68
88
|
const names = nodeLabels(run.nodes, ctx.nodes);
|
|
69
89
|
const collision = collisionWords(run, all, ctx.nodes);
|
|
70
90
|
const limits = limitRows(run);
|
|
@@ -78,6 +98,7 @@ export function runHtml(ctx, run, all) {
|
|
|
78
98
|
<p class="hx-forge-meta">${ctx.esc(checksWords(run))}</p>
|
|
79
99
|
<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>
|
|
80
100
|
${links ? `<p class="hx-forge-meta">${links}</p>` : ''}
|
|
101
|
+
${answering ? answerHtml(ctx, run) : ''}${run.answer && !answering ? answeredHtml(ctx, run) : ''}
|
|
81
102
|
<div class="hx-run-actions">${stop}
|
|
82
103
|
<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>
|
|
83
104
|
<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>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cornfield",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.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)",
|