cornfield 0.19.0 → 0.19.1
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 +2 -2
- package/core/defuse.js +19 -1
- package/package.json +1 -1
- package/server/run-thread.js +4 -7
package/core/agent-contract.js
CHANGED
|
@@ -50,7 +50,7 @@
|
|
|
50
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
|
|
51
51
|
*/
|
|
52
52
|
|
|
53
|
-
import { defuse } from './defuse.js';
|
|
53
|
+
import { defuse, quoteInert } from './defuse.js';
|
|
54
54
|
|
|
55
55
|
/** Ten (or `n`) random bytes, from the Web Crypto API that Node and the browser both have */
|
|
56
56
|
const randomBytes = (n) => globalThis.crypto.getRandomValues(new Uint8Array(n));
|
|
@@ -543,7 +543,7 @@ export function formatRunComment(runId, body, { line, profiles } = {}) {
|
|
|
543
543
|
const head = oneLine(line ?? defaultLine(runId, checked.type, checked.value));
|
|
544
544
|
// An answer's text is the maintainer's words to the runner: it travels in the block only, never quoted beside it
|
|
545
545
|
const note = checked.type === 'request' || checked.type === 'answer' ? '' : (checked.value.note ?? '').trim();
|
|
546
|
-
const quoted = note ? `\n\n${
|
|
546
|
+
const quoted = note ? `\n\n${quoteInert(note)}` : '';
|
|
547
547
|
const out = `${head}${quoted}\n\n${block}`;
|
|
548
548
|
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.`);
|
|
549
549
|
return out;
|
package/core/defuse.js
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* `#1`, `owner/repo#1`, `GH-1`, and the links the forge would make of `https://…` or `www.…`. A zero-width space after
|
|
6
6
|
* the character keeps the text as it reads and stops it notifying anyone or linking anything. The pipeline's issues
|
|
7
7
|
* (server/pipeline.js), a review that came through the review API (server/reviews.js) and the agent contract
|
|
8
|
-
* (core/agent-contract.js) use it
|
|
8
|
+
* (core/agent-contract.js) use it; `inert` and `quoteInert` also make someone else's words plain Markdown, the way the agent contract
|
|
9
|
+
* and a run's thread (server/run-thread.js) show a runner's note. It imports nothing, so Node and the browser can both load it.
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
12
|
/** A zero-width space: it ends a mention or a reference without showing */
|
|
@@ -15,3 +16,20 @@ export const ZW = '';
|
|
|
15
16
|
export function defuse(text) {
|
|
16
17
|
return String(text).replace(/[@#]/g, (c) => `${c}${ZW}`).replace(/\b(GH)-(?=\d)/gi, `$1${ZW}-`).replace(/:\/\//g, `:${ZW}//`).replace(/\b(www)\./gi, `$1${ZW}.`);
|
|
17
18
|
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Text that makes no Markdown of its own: `\\` escaped first (so no escape of ours is undone), `&` and `<` as entities (no HTML, no
|
|
22
|
+
* character reference), `[` escaped (no link, image or `[[node]]`), backticks made `'` and runs of tildes broken (no code span, no fence).
|
|
23
|
+
* Mentions, references and links are not touched here: `defuse` them first.
|
|
24
|
+
*/
|
|
25
|
+
export function inert(text) {
|
|
26
|
+
return String(text).replace(/\\/g, '\\\\').replace(/&/g, '&').replace(/</g, '<').replace(/\[/g, '\\[').replace(/`/g, "'").replace(/~(?=~)/g, `~${ZW}`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Text quoted line by line, defused and inert: every line end Markdown and the agent contract's reader know (`\r\n`, `\r` alone, `\n`)
|
|
31
|
+
* ends a line here, and every line is behind `> ` (an empty one is `>`), so no line escapes the quote and nothing in it opens a fence.
|
|
32
|
+
*/
|
|
33
|
+
export function quoteInert(text) {
|
|
34
|
+
return inert(defuse(text)).split(/\r\n?|\n/).map((l) => (l.trim() ? `> ${l}` : '>')).join('\n');
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cornfield",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.1",
|
|
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/run-thread.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* by the id it kept (`run_mirrors`), never by the marker: the marker is not trusted as an address.
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
-
import { defuse, ZW } from '../core/defuse.js';
|
|
27
|
+
import { defuse, inert, quoteInert, ZW } from '../core/defuse.js';
|
|
28
28
|
|
|
29
29
|
/** The marker on the first line (an HTML comment, which the forge does not show). It does not contain the contract's tag, `cornfield-run` */
|
|
30
30
|
export const MIRROR_TAG = 'cornfield:run-status';
|
|
@@ -40,19 +40,16 @@ const STATUS_WORDS = {
|
|
|
40
40
|
/** The state of a run as a word, the one the dashboard shows */
|
|
41
41
|
export const statusWord = (status) => STATUS_WORDS[status] ?? String(status);
|
|
42
42
|
|
|
43
|
-
/** Markdown that could make a link, an image or HTML of someone else's words, made plain: `<` as an entity, `[` escaped (so `[[` is no node either) */
|
|
44
|
-
const inert = (s) => s.replace(/&/g, '&').replace(/</g, '<').replace(/\[/g, '\\[');
|
|
45
|
-
|
|
46
43
|
/** Text for someone else's eyes: mentions, references and links broken, no link, image or HTML made of it, and made one line */
|
|
47
|
-
const plain = (s) => inert(defuse(String(s ?? '').replace(/\s+/g, ' ').trim()))
|
|
44
|
+
const plain = (s) => inert(defuse(String(s ?? '').replace(/\s+/g, ' ').trim()));
|
|
48
45
|
|
|
49
46
|
/** A run's note, quoted line by line and cut short */
|
|
50
47
|
function quote(note) {
|
|
51
48
|
const text = String(note ?? '').trim();
|
|
52
49
|
if (!text) return '';
|
|
53
50
|
const cut = text.length > NOTE_SHOWN ? `${text.slice(0, NOTE_SHOWN)} …` : text;
|
|
54
|
-
//
|
|
55
|
-
return
|
|
51
|
+
// Cut before it is made inert, so the cut never lands inside an escape (core/defuse.js)
|
|
52
|
+
return quoteInert(cut);
|
|
56
53
|
}
|
|
57
54
|
|
|
58
55
|
/** An address the forge gave, safe to put in a link; null for anything else */
|