@parcha/agentrun-serve 0.1.0-beta.39 → 0.1.0-beta.41
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/CHANGELOG.md +114 -0
- package/README.md +129 -16
- package/dist/api-only.d.ts +3 -1
- package/dist/api-only.js +4 -2
- package/dist/api-token.d.ts +30 -0
- package/dist/api-token.js +89 -0
- package/dist/cli.js +19 -5
- package/dist/composio-made.d.ts +54 -0
- package/dist/composio-made.js +83 -0
- package/dist/composio-preset.d.ts +16 -8
- package/dist/composio-preset.js +106 -43
- package/dist/composio-triggers.d.ts +7 -2
- package/dist/composio-triggers.js +13 -7
- package/dist/computer-attach.d.ts +29 -11
- package/dist/computer-attach.js +141 -47
- package/dist/computer-keys.d.ts +4 -0
- package/dist/computer-keys.js +5 -0
- package/dist/computers.d.ts +11 -1
- package/dist/computers.js +21 -12
- package/dist/console/assets/index-C3gNPz58.css +1 -0
- package/dist/console/assets/index-COGhx_2Z.js +711 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.js +9 -2
- package/dist/email/account.d.ts +0 -1
- package/dist/email/account.js +3 -3
- package/dist/email/answer.d.ts +5 -0
- package/dist/email/answer.js +35 -0
- package/dist/email/mail.js +19 -26
- package/dist/email/names.d.ts +30 -0
- package/dist/email/names.js +34 -0
- package/dist/email/routes.d.ts +1 -0
- package/dist/email/routes.js +1 -1
- package/dist/email/tools.d.ts +11 -4
- package/dist/email/tools.js +91 -46
- package/dist/eval-feed.d.ts +26 -0
- package/dist/eval-feed.js +68 -0
- package/dist/eval-mailbox.d.ts +5 -2
- package/dist/eval-mailbox.js +14 -6
- package/dist/exa-keyless.d.ts +1 -1
- package/dist/exa-keyless.js +1 -1
- package/dist/feed/feed-faux.d.ts +62 -0
- package/dist/feed/feed-faux.js +123 -0
- package/dist/feed/fetch.d.ts +41 -0
- package/dist/feed/fetch.js +128 -0
- package/dist/feed/parse.d.ts +41 -0
- package/dist/feed/parse.js +300 -0
- package/dist/learn/check.d.ts +3 -1
- package/dist/learn/check.js +57 -2
- package/dist/learn/compile.d.ts +3 -2
- package/dist/learn/compile.js +7 -6
- package/dist/learn/promote.d.ts +25 -14
- package/dist/learn/promote.js +32 -14
- package/dist/learned-nodes.d.ts +21 -4
- package/dist/learned-nodes.js +21 -8
- package/dist/learned-workflow.d.ts +3 -3
- package/dist/learned-workflow.js +14 -5
- package/dist/learning-cost.d.ts +17 -8
- package/dist/learning-cost.js +12 -4
- package/dist/local-models.d.ts +7 -1
- package/dist/local-models.js +11 -5
- package/dist/mcp-oauth.d.ts +15 -1
- package/dist/mcp-oauth.js +39 -5
- package/dist/mcp-pin-first.d.ts +4 -2
- package/dist/mcp-pin-first.js +4 -3
- package/dist/mcp-servers-store.d.ts +58 -5
- package/dist/mcp-servers-store.js +136 -17
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +2 -2
- package/dist/observation/http.d.ts +4 -1
- package/dist/observation/http.js +5 -4
- package/dist/openapi.d.ts +1 -1
- package/dist/openapi.js +63 -27
- package/dist/port-models.d.ts +4 -1
- package/dist/port-models.js +1 -0
- package/dist/print.d.ts +6 -3
- package/dist/print.js +4 -2
- package/dist/refusal-words.d.ts +3 -0
- package/dist/refusal-words.js +3 -0
- package/dist/run-labels.d.ts +23 -0
- package/dist/run-labels.js +79 -0
- package/dist/run-launch.d.ts +2 -0
- package/dist/run-launch.js +2 -0
- package/dist/run-secrets.js +12 -4
- package/dist/run-view.d.ts +3 -4
- package/dist/run-view.js +26 -24
- package/dist/runner/adapter-loop.d.ts +6 -2
- package/dist/runner/adapter-loop.js +136 -22
- package/dist/runner/adapter-run-spec.d.ts +5 -0
- package/dist/runner/adapter-run-spec.js +75 -32
- package/dist/runner/beside.d.ts +6 -3
- package/dist/runner/beside.js +9 -7
- package/dist/runner/cli-run-spec.js +33 -26
- package/dist/runner/conformance/harness.js +69 -14
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/journal-kinds.d.ts +22 -0
- package/dist/runner/journal-kinds.js +39 -0
- package/dist/runner/main.d.ts +1 -1
- package/dist/runner/main.js +2 -2
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/mcp-run.d.ts +4 -0
- package/dist/runner/mcp-run.js +5 -3
- package/dist/runner/model-route.d.ts +7 -3
- package/dist/runner/model-route.js +24 -9
- package/dist/runner/promotion.d.ts +16 -8
- package/dist/runner/promotion.js +178 -55
- package/dist/runner/workflow-first.d.ts +6 -5
- package/dist/runner/workflow-first.js +9 -7
- package/dist/runs-over-store.js +5 -2
- package/dist/sdk/runs.d.ts +7 -1
- package/dist/sdk/runs.js +19 -6
- package/dist/secret-cut.js +3 -1
- package/dist/secrets.js +3 -1
- package/dist/server.d.ts +27 -2
- package/dist/server.js +181 -56
- package/dist/store/dialect.d.ts +6 -0
- package/dist/store/dialect.js +2 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/postgres/connection.d.ts +11 -5
- package/dist/store/postgres/connection.js +44 -17
- package/dist/store/postgres/dialect.js +6 -0
- package/dist/store/postgres/migrations/0015_run_labels.sql +5 -0
- package/dist/store/postgres/migrations/0016_minted_tokens.sql +21 -0
- package/dist/store/postgres/store.d.ts +7 -3
- package/dist/store/postgres/store.js +1 -0
- package/dist/store/schema.d.ts +9 -0
- package/dist/store/schema.js +26 -2
- package/dist/store/sqlite/connection.js +80 -8
- package/dist/store/sqlite/run-launch.d.ts +11 -0
- package/dist/store/sqlite/run-launch.js +8 -0
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +3 -2
- package/dist/store/sqlite/store.js +101 -26
- package/dist/store/sqlite/worker.d.ts +2 -0
- package/dist/store/sqlite/worker.js +13 -10
- package/dist/store/store.d.ts +53 -1
- package/dist/store-reads/journal.js +2 -1
- package/dist/store-reads/learning.d.ts +30 -13
- package/dist/store-reads/learning.js +130 -51
- package/dist/store-reads/runs.d.ts +4 -3
- package/dist/store-reads/runs.js +3 -2
- package/dist/store-view.js +4 -2
- package/dist/template-eval.d.ts +4 -0
- package/dist/template-eval.js +127 -50
- package/dist/templates.d.ts +24 -1
- package/dist/templates.js +129 -21
- package/dist/timeline/origin.d.ts +1 -1
- package/dist/timeline/origin.js +2 -2
- package/dist/tool-gate.d.ts +5 -3
- package/dist/tool-gate.js +5 -2
- package/dist/tools.d.ts +13 -0
- package/dist/tools.js +15 -10
- package/dist/trigger-adapter.d.ts +12 -36
- package/dist/trigger-adapters.js +2 -1
- package/dist/trigger-email.js +30 -77
- package/dist/trigger-feed.d.ts +12 -0
- package/dist/trigger-feed.js +371 -0
- package/dist/triggers.d.ts +27 -14
- package/dist/triggers.js +121 -80
- package/dist/webhooks.js +9 -5
- package/dist/workflow/decision-recovery.js +5 -2
- package/dist/workflow/decisions.d.ts +7 -0
- package/dist/workspace/computer-deps.d.ts +5 -1
- package/dist/workspace/computer-deps.js +2 -2
- package/dist/workspace/index.d.ts +1 -0
- package/dist/workspace/index.js +2 -0
- package/dist/workspace/resolve-computer.d.ts +32 -3
- package/dist/workspace/resolve-computer.js +47 -9
- package/launcher/agentrun-serve +6 -1
- package/package.json +10 -9
- package/templates/README.md +27 -2
- package/dist/console/assets/index-BNhZs-jp.css +0 -1
- package/dist/console/assets/index-BQv5aOGB.js +0 -700
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
// A feed's body read into its items (trigger-feed.ts): RSS 2.0 (and 1.0), Atom, JSON Feed, or a JSON list (an API's
|
|
2
|
+
// array of objects, GitHub's pulls, read at an items pointer and keyed at an id pointer). XML is read with
|
|
3
|
+
// fast-xml-parser, checked well-formed first, and one that declares entities is refused: none is ever expanded, and only
|
|
4
|
+
// XML's five named references and numeric ones decode. Every text is untrusted and bounded; HTML is read as text (its
|
|
5
|
+
// tags dropped, its entities decoded, a block a line).
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import { XMLParser, XMLValidator } from "fast-xml-parser";
|
|
8
|
+
/** The most characters of an item's summary its payload holds. */
|
|
9
|
+
export const SUMMARY_CHARS = 4000;
|
|
10
|
+
/** The most characters of a title. */
|
|
11
|
+
const TITLE_CHARS = 1000;
|
|
12
|
+
/** The most characters of any other text field (an id, a link, an author, a category). */
|
|
13
|
+
const FIELD_CHARS = 2000;
|
|
14
|
+
/** The most categories an item's payload lists. */
|
|
15
|
+
const CATEGORIES = 50;
|
|
16
|
+
/** A body that is no feed this reads: its words. */
|
|
17
|
+
export class FeedUnreadable extends Error {
|
|
18
|
+
name = "FeedUnreadable";
|
|
19
|
+
}
|
|
20
|
+
const clip = (text, max) => (text.length > max ? `${text.slice(0, max - 1)}…` : text);
|
|
21
|
+
const hash = (text) => createHash("sha256").update(text).digest("hex").slice(0, 16);
|
|
22
|
+
const NAMED = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: " ", mdash: "—", ndash: "–", hellip: "…", rsquo: "’", lsquo: "‘", rdquo: "”", ldquo: "“", copy: "©", reg: "®", trade: "™", middot: "·", bull: "•" };
|
|
23
|
+
/** `text`'s HTML character references decoded (the named ones above, and every numeric one). */
|
|
24
|
+
const entities = (text) => text.replace(/&(#x[0-9a-f]{1,6}|#\d{1,7}|[a-z]{2,8});/gi, (whole, ref) => {
|
|
25
|
+
if (ref[0] === "#") {
|
|
26
|
+
const code = ref[1] === "x" || ref[1] === "X" ? parseInt(ref.slice(2), 16) : parseInt(ref.slice(1), 10);
|
|
27
|
+
return code > 0 && code <= 0x10ffff && !(code >= 0xd800 && code <= 0xdfff) ? String.fromCodePoint(code) : "";
|
|
28
|
+
}
|
|
29
|
+
return NAMED[ref.toLowerCase()] ?? whole;
|
|
30
|
+
});
|
|
31
|
+
const BLOCK = /<\s*\/?\s*(?:p|div|br|li|ul|ol|dl|dt|dd|h[1-6]|tr|table|thead|tbody|blockquote|pre|section|article|header|footer|hr|figure|figcaption)\b[^>]*>/gi;
|
|
32
|
+
/** HTML as text: scripts and styles dropped, each block its own line, other tags dropped, references decoded, the spaces
|
|
33
|
+
* in each line collapsed and empty lines dropped. */
|
|
34
|
+
export function htmlToText(html) {
|
|
35
|
+
const text = html.replace(/<!--[\s\S]*?-->/g, "").replace(/<(script|style)\b[\s\S]*?<\/\1\s*>/gi, "").replace(BLOCK, "\n").replace(/<[^>]*>/g, "");
|
|
36
|
+
return lines(entities(text));
|
|
37
|
+
}
|
|
38
|
+
/** Plain text: the spaces in each line collapsed, empty lines dropped. */
|
|
39
|
+
const lines = (text) => text.split(/\r?\n/).map((line) => line.replace(/[ \t \f\v\r]+/g, " ").trim()).filter(Boolean).join("\n");
|
|
40
|
+
/** An instant from an RFC 3339 or RFC 822 date, or null. */
|
|
41
|
+
function instant(value) {
|
|
42
|
+
const text = textOf(value);
|
|
43
|
+
if (!text)
|
|
44
|
+
return null;
|
|
45
|
+
const at = Date.parse(text);
|
|
46
|
+
return Number.isFinite(at) ? at : null;
|
|
47
|
+
}
|
|
48
|
+
/** A parsed XML node's text: a string as it is; an element with attributes, its text node; a list, its first. */
|
|
49
|
+
function textOf(node) {
|
|
50
|
+
if (Array.isArray(node))
|
|
51
|
+
return textOf(node[0]);
|
|
52
|
+
if (typeof node === "string")
|
|
53
|
+
return node;
|
|
54
|
+
if (typeof node === "number" || typeof node === "boolean")
|
|
55
|
+
return String(node);
|
|
56
|
+
if (node && typeof node === "object") {
|
|
57
|
+
// Its text and its CDATA, kept apart by the parser: each as it reads (both, in the rare node with both).
|
|
58
|
+
const parts = [node["#text"], ...list(node["#cdata"])].filter((one) => typeof one === "string" || typeof one === "number");
|
|
59
|
+
return parts.length ? parts.map(String).join(" ") : undefined;
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
/** A node's text, trimmed and bounded, or null when it holds none. */
|
|
64
|
+
const field = (node, max = FIELD_CHARS) => {
|
|
65
|
+
const text = textOf(node)?.trim();
|
|
66
|
+
return text ? clip(text, max) : null;
|
|
67
|
+
};
|
|
68
|
+
/** An Atom text construct (a title, a summary, a content) as text: type html read as HTML, text as text; type xhtml (its
|
|
69
|
+
* XHTML inline, which the parser keeps by name, out of order) as the HTML its `ordered` reading writes. */
|
|
70
|
+
const atomText = (node, ordered) => {
|
|
71
|
+
const type = node && typeof node === "object" && !Array.isArray(node) ? node["@_type"] : undefined;
|
|
72
|
+
if (type === "xhtml" && ordered !== undefined)
|
|
73
|
+
return htmlToText(ordered) || null;
|
|
74
|
+
const text = textOf(node);
|
|
75
|
+
if (!text?.trim())
|
|
76
|
+
return null;
|
|
77
|
+
return type === "html" || type === "xhtml" ? htmlToText(text) || null : lines(text) || null;
|
|
78
|
+
};
|
|
79
|
+
const list = (node) => (node === undefined || node === null ? [] : Array.isArray(node) ? node : [node]);
|
|
80
|
+
const attr = (node, name) => (node && typeof node === "object" && !Array.isArray(node) ? textOf(node[`@_${name}`]) : undefined);
|
|
81
|
+
/** The key an item is known by: its id, else its link, else a hash of its title and date (`hash:` and 16 hex). */
|
|
82
|
+
const keyOf = (id, link, title, date, rest) => id ?? link ?? `hash:${hash(`${title ?? rest ?? ""}\n${date === null ? "" : new Date(date).toISOString()}`)}`;
|
|
83
|
+
function item(fields) {
|
|
84
|
+
return { key: keyOf(fields.id, fields.link, fields.title, fields.published ?? fields.updated, fields.summary), ...fields };
|
|
85
|
+
}
|
|
86
|
+
/** XML's own references decoded in one pass, so each decodes once ("&lt;" is "<"): the five XML names and every
|
|
87
|
+
* numeric character reference. Any other name stays as it is written; a document that declares one is refused first. */
|
|
88
|
+
const xmlRefs = (text) => text.indexOf("&") === -1 ? text : text.replace(/&(?:(amp|lt|gt|quot|apos)|#(\d{1,7})|#x([0-9a-f]{1,6}));/gi, (whole, name, dec, hex) => {
|
|
89
|
+
if (name)
|
|
90
|
+
return XML_NAMED[name] ?? whole;
|
|
91
|
+
const code = dec !== undefined ? parseInt(dec, 10) : parseInt(hex, 16);
|
|
92
|
+
return code > 0 && code <= 0x10ffff && !(code >= 0xd800 && code <= 0xdfff) ? String.fromCodePoint(code) : "";
|
|
93
|
+
});
|
|
94
|
+
const XML_NAMED = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" };
|
|
95
|
+
// The parser expands nothing (processEntities off: no DOCTYPE entity, and no count of references to cap a long feed);
|
|
96
|
+
// text and attribute values are decoded here instead, and a CDATA section is kept apart (#cdata), as it is written.
|
|
97
|
+
const XML = new XMLParser({
|
|
98
|
+
ignoreAttributes: false,
|
|
99
|
+
attributeNamePrefix: "@_",
|
|
100
|
+
textNodeName: "#text",
|
|
101
|
+
cdataPropName: "#cdata",
|
|
102
|
+
parseTagValue: false,
|
|
103
|
+
parseAttributeValue: false,
|
|
104
|
+
trimValues: true,
|
|
105
|
+
processEntities: false,
|
|
106
|
+
htmlEntities: false,
|
|
107
|
+
removeNSPrefix: true,
|
|
108
|
+
tagValueProcessor: (_name, value) => xmlRefs(value),
|
|
109
|
+
attributeValueProcessor: (_name, value) => xmlRefs(value),
|
|
110
|
+
isArray: (name) => ["item", "entry", "category", "link", "author", "creator"].includes(name),
|
|
111
|
+
});
|
|
112
|
+
// The same reading with each element's children in the order they are written (an xhtml text construct's), the spaces
|
|
113
|
+
// between them kept.
|
|
114
|
+
const ORDERED = new XMLParser({
|
|
115
|
+
ignoreAttributes: false,
|
|
116
|
+
attributeNamePrefix: "@_",
|
|
117
|
+
textNodeName: "#text",
|
|
118
|
+
cdataPropName: "#cdata",
|
|
119
|
+
parseTagValue: false,
|
|
120
|
+
parseAttributeValue: false,
|
|
121
|
+
trimValues: false,
|
|
122
|
+
processEntities: false,
|
|
123
|
+
htmlEntities: false,
|
|
124
|
+
removeNSPrefix: true,
|
|
125
|
+
preserveOrder: true,
|
|
126
|
+
tagValueProcessor: (_name, value) => xmlRefs(value),
|
|
127
|
+
attributeValueProcessor: (_name, value) => xmlRefs(value),
|
|
128
|
+
});
|
|
129
|
+
const nameOf = (node) => Object.keys(node).find((key) => key !== ":@");
|
|
130
|
+
const children = (node, name) => (node && Array.isArray(node[name]) ? node[name] : []);
|
|
131
|
+
const escapeHtml = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
132
|
+
/** Ordered nodes written back as HTML: each element's tag around its children, text escaped, CDATA as text. */
|
|
133
|
+
const markup = (nodes) => nodes
|
|
134
|
+
.map((node) => {
|
|
135
|
+
const name = nameOf(node);
|
|
136
|
+
if (name === undefined)
|
|
137
|
+
return "";
|
|
138
|
+
if (name === "#text")
|
|
139
|
+
return escapeHtml(String(node[name]));
|
|
140
|
+
if (name === "#cdata")
|
|
141
|
+
return children(node, name).map((one) => escapeHtml(String(one["#text"] ?? ""))).join("");
|
|
142
|
+
return `<${name}>${markup(children(node, name))}</${name}>`;
|
|
143
|
+
})
|
|
144
|
+
.join("");
|
|
145
|
+
/** Each xhtml text construct of an Atom document as HTML, written in order: the feed's title, and each entry's (in the
|
|
146
|
+
* order the entries are) title, summary and content; undefined for one that is not xhtml or not there. */
|
|
147
|
+
function atomXhtml(text) {
|
|
148
|
+
const doc = ORDERED.parse(text);
|
|
149
|
+
const feed = doc.find((node) => nameOf(node) === "feed");
|
|
150
|
+
const of = (parent, field) => {
|
|
151
|
+
const node = children(parent, parent ? nameOf(parent) : "").find((one) => nameOf(one) === field);
|
|
152
|
+
return node && node[":@"]?.["@_type"] === "xhtml" ? markup(children(node, field)) : undefined;
|
|
153
|
+
};
|
|
154
|
+
return {
|
|
155
|
+
title: of(feed, "title"),
|
|
156
|
+
entries: children(feed, "feed").filter((node) => nameOf(node) === "entry").map((entry) => ({ title: of(entry, "title"), summary: of(entry, "summary"), content: of(entry, "content") })),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/** `body` read as a feed. A JSON document is a JSON Feed (its `version` says so) unless `pointers` name a list, else a
|
|
160
|
+
* JSON list; anything else is read as XML: RSS or Atom. Throws FeedUnreadable in words. */
|
|
161
|
+
export function parseFeed(body, pointers = {}) {
|
|
162
|
+
const text = body.replace(/^/, "").trim();
|
|
163
|
+
if (!text)
|
|
164
|
+
throw new FeedUnreadable("its answer is empty");
|
|
165
|
+
if (text[0] === "{" || text[0] === "[") {
|
|
166
|
+
let doc;
|
|
167
|
+
try {
|
|
168
|
+
doc = JSON.parse(text);
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
throw new FeedUnreadable("its answer is not JSON, RSS or Atom");
|
|
172
|
+
}
|
|
173
|
+
const jsonFeed = doc !== null && typeof doc === "object" && !Array.isArray(doc) && typeof doc.version === "string" && String(doc.version).startsWith("https://jsonfeed.org/version/");
|
|
174
|
+
return jsonFeed && pointers.items === undefined && pointers.id === undefined ? jsonFeedOf(doc) : jsonListOf(doc, pointers);
|
|
175
|
+
}
|
|
176
|
+
// No entity is ever expanded: a document that declares one is refused before it is parsed.
|
|
177
|
+
if (/<!ENTITY/i.test(text))
|
|
178
|
+
throw new FeedUnreadable("it declares XML entities, which a feed is read without");
|
|
179
|
+
const valid = XMLValidator.validate(text);
|
|
180
|
+
if (valid !== true)
|
|
181
|
+
throw new FeedUnreadable(`it is not well-formed XML (line ${valid.err.line}: ${clip(valid.err.msg.replace(/\s+/g, " "), 200)})`);
|
|
182
|
+
let doc;
|
|
183
|
+
try {
|
|
184
|
+
doc = XML.parse(text);
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
throw new FeedUnreadable(`it is not well-formed XML (${clip(String(error?.message ?? error), 200)})`);
|
|
188
|
+
}
|
|
189
|
+
const rss = doc.rss;
|
|
190
|
+
if (rss && typeof rss === "object") {
|
|
191
|
+
const channel = list(rss.channel)[0];
|
|
192
|
+
const read = channel && typeof channel === "object" ? channel : {};
|
|
193
|
+
return rssOf(read, list(read.item));
|
|
194
|
+
}
|
|
195
|
+
const rdf = doc.RDF;
|
|
196
|
+
if (rdf && typeof rdf === "object")
|
|
197
|
+
return rssOf(list(rdf.channel)[0] ?? {}, list(rdf.item));
|
|
198
|
+
const atom = doc.feed;
|
|
199
|
+
if (atom && typeof atom === "object")
|
|
200
|
+
return atomOf(atom, /\btype\s*=\s*["']xhtml["']/.test(text) ? atomXhtml(text) : undefined);
|
|
201
|
+
throw new FeedUnreadable("it is not RSS, Atom, JSON Feed or a JSON list");
|
|
202
|
+
}
|
|
203
|
+
function rssOf(channel, items) {
|
|
204
|
+
return {
|
|
205
|
+
list: false,
|
|
206
|
+
title: field(channel.title, TITLE_CHARS),
|
|
207
|
+
items: items.filter((one) => !!one && typeof one === "object").map((one) => {
|
|
208
|
+
const guid = field(one.guid);
|
|
209
|
+
const permalink = attr(one.guid, "isPermaLink") !== "false";
|
|
210
|
+
// An RSS item's link is text; an atom:link inside it (its prefix dropped) has an href.
|
|
211
|
+
const link = list(one.link).map((l) => (typeof l === "string" ? l.trim() : attr(l, "href"))).find((l) => !!l) ?? (guid && permalink && /^https?:\/\//i.test(guid) ? guid : null);
|
|
212
|
+
const description = textOf(one.description) ?? textOf(one.encoded);
|
|
213
|
+
return item({
|
|
214
|
+
// A title is text, as written: never read as HTML, so nothing in it is dropped.
|
|
215
|
+
id: guid, link: link ? clip(link, FIELD_CHARS) : null, title: (() => {
|
|
216
|
+
const title = lines(textOf(one.title) ?? "");
|
|
217
|
+
return title ? clip(title, TITLE_CHARS) : null;
|
|
218
|
+
})(),
|
|
219
|
+
published: instant(one.pubDate) ?? instant(one.date), updated: instant(one.updated),
|
|
220
|
+
author: field(one.author) ?? field(one.creator),
|
|
221
|
+
summary: description ? clip(htmlToText(description), SUMMARY_CHARS) || null : null,
|
|
222
|
+
categories: list(one.category).map((c) => field(c)).filter((c) => !!c).slice(0, CATEGORIES),
|
|
223
|
+
});
|
|
224
|
+
}),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/** An Atom feed; `xhtml`, its xhtml text constructs written in order (atomXhtml), when it has any. */
|
|
228
|
+
function atomOf(feed, xhtml) {
|
|
229
|
+
return {
|
|
230
|
+
list: false,
|
|
231
|
+
title: (() => {
|
|
232
|
+
const title = atomText(feed.title, xhtml?.title);
|
|
233
|
+
return title ? clip(title, TITLE_CHARS) : null;
|
|
234
|
+
})(),
|
|
235
|
+
items: list(feed.entry).map((one, i) => [one, xhtml?.entries[i]]).filter((pair) => !!pair[0] && typeof pair[0] === "object").map(([one, ordered]) => {
|
|
236
|
+
const links = list(one.link);
|
|
237
|
+
const alternate = links.find((l) => (attr(l, "rel") ?? "alternate") === "alternate" && attr(l, "href")) ?? links.find((l) => attr(l, "href"));
|
|
238
|
+
const summary = atomText(one.summary, ordered?.summary) ?? atomText(one.content, ordered?.content);
|
|
239
|
+
const title = atomText(one.title, ordered?.title);
|
|
240
|
+
return item({
|
|
241
|
+
id: field(one.id), link: alternate ? clip(attr(alternate, "href").trim(), FIELD_CHARS) : null, title: title ? clip(title, TITLE_CHARS) : null,
|
|
242
|
+
published: instant(one.published) ?? instant(one.issued), updated: instant(one.updated) ?? instant(one.modified),
|
|
243
|
+
author: field(list(one.author)[0]?.name),
|
|
244
|
+
summary: summary ? clip(summary, SUMMARY_CHARS) : null,
|
|
245
|
+
categories: list(one.category).map((c) => attr(c, "term") ?? field(c)).filter((c) => !!c).map((c) => clip(c, FIELD_CHARS)).slice(0, CATEGORIES),
|
|
246
|
+
});
|
|
247
|
+
}),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
const str = (value, max = FIELD_CHARS) => (typeof value === "string" && value.trim() ? clip(value.trim(), max) : typeof value === "number" && Number.isFinite(value) ? String(value) : null);
|
|
251
|
+
function jsonFeedOf(doc) {
|
|
252
|
+
const items = Array.isArray(doc.items) ? doc.items : [];
|
|
253
|
+
return {
|
|
254
|
+
list: false,
|
|
255
|
+
title: str(doc.title, TITLE_CHARS),
|
|
256
|
+
items: items.filter((one) => !!one && typeof one === "object" && !Array.isArray(one)).map((one) => {
|
|
257
|
+
const authors = Array.isArray(one.authors) ? one.authors : one.author ? [one.author] : [];
|
|
258
|
+
const author = authors.map((a) => (a && typeof a === "object" ? str(a.name) : null)).find(Boolean) ?? null;
|
|
259
|
+
const summary = typeof one.summary === "string" && one.summary.trim() ? lines(one.summary) : typeof one.content_text === "string" && one.content_text.trim() ? lines(one.content_text) : typeof one.content_html === "string" ? htmlToText(one.content_html) : "";
|
|
260
|
+
return item({
|
|
261
|
+
id: str(one.id), link: str(one.url) ?? str(one.external_url), title: str(one.title, TITLE_CHARS),
|
|
262
|
+
published: instant(one.date_published), updated: instant(one.date_modified), author,
|
|
263
|
+
summary: summary ? clip(summary, SUMMARY_CHARS) : null,
|
|
264
|
+
categories: (Array.isArray(one.tags) ? one.tags : []).map((tag) => str(tag)).filter((tag) => !!tag).slice(0, CATEGORIES),
|
|
265
|
+
});
|
|
266
|
+
}),
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
/** The value at JSON Pointer `pointer` in `doc`, or undefined. */
|
|
270
|
+
export function pointed(doc, pointer) {
|
|
271
|
+
if (pointer === "")
|
|
272
|
+
return doc;
|
|
273
|
+
let at = doc;
|
|
274
|
+
for (const raw of pointer.split("/").slice(1)) {
|
|
275
|
+
const part = raw.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
276
|
+
if (Array.isArray(at) && /^(0|[1-9]\d*)$/.test(part))
|
|
277
|
+
at = at[Number(part)];
|
|
278
|
+
else if (at && typeof at === "object" && !Array.isArray(at) && Object.hasOwn(at, part))
|
|
279
|
+
at = at[part];
|
|
280
|
+
else
|
|
281
|
+
return undefined;
|
|
282
|
+
}
|
|
283
|
+
return at;
|
|
284
|
+
}
|
|
285
|
+
function jsonListOf(doc, { items: itemsAt = "", id: idAt = "/id" }) {
|
|
286
|
+
const items = pointed(doc, itemsAt);
|
|
287
|
+
if (!Array.isArray(items))
|
|
288
|
+
throw new FeedUnreadable(itemsAt ? `nothing at ${itemsAt} in its JSON is a list` : "its JSON is no list, and the trigger names no items pointer to one");
|
|
289
|
+
return {
|
|
290
|
+
list: true,
|
|
291
|
+
title: null,
|
|
292
|
+
items: items.filter((one) => one !== null && typeof one === "object").map((one) => {
|
|
293
|
+
const object = one;
|
|
294
|
+
const id = str(pointed(object, idAt));
|
|
295
|
+
const link = str(object.html_url) ?? str(object.url) ?? str(object.link);
|
|
296
|
+
const title = str(object.title, TITLE_CHARS) ?? str(object.name, TITLE_CHARS);
|
|
297
|
+
return { key: id ?? link ?? `hash:${hash(title ?? JSON.stringify(one))}`, id, link, title, published: null, updated: null, author: null, summary: null, categories: [], raw: one };
|
|
298
|
+
}),
|
|
299
|
+
};
|
|
300
|
+
}
|
package/dist/learn/check.d.ts
CHANGED
|
@@ -112,7 +112,9 @@ export declare function answerTierProblems(doc: unknown): string[];
|
|
|
112
112
|
/** Why a draft's quote check is not code: its answer carries quotes (a `quote` or `quotes` property in its output schema)
|
|
113
113
|
* and it fetches pages (a call step), yet some place in the answer holding quotes has no escalate on quote_missing
|
|
114
114
|
* reading it after the answer is written (quoteRule), or that escalate reads as a page a key holding no page as fetched
|
|
115
|
-
* (a model's summary of a page is no page)
|
|
115
|
+
* (a model's summary of a page is no page), or, those checks in place, the step writing the answer hands back on its
|
|
116
|
+
* first miss instead of re-picking once (a loop of REPICK_PASSES until its check passes), or its quotes have more than
|
|
117
|
+
* one check (a loop's `until` waits on one: the others would hand back with no re-pick). A judge or an `ask` is never the quote check:
|
|
116
118
|
* H5's judge flagged 149 of 170 answers while 416 of 429 quotes were in the pages, and could not tell the 8 answers
|
|
117
119
|
* quoting text no page held from the rest; code can. One line each, in words the compile retry acts on. */
|
|
118
120
|
export declare function quoteCheckProblems(doc: unknown): string[];
|
package/dist/learn/check.js
CHANGED
|
@@ -377,13 +377,47 @@ const writesKey = (node, key) => isNode(node) && (writeKeyOf(node) === key || (n
|
|
|
377
377
|
/** Why a draft's quote check is not code: its answer carries quotes (a `quote` or `quotes` property in its output schema)
|
|
378
378
|
* and it fetches pages (a call step), yet some place in the answer holding quotes has no escalate on quote_missing
|
|
379
379
|
* reading it after the answer is written (quoteRule), or that escalate reads as a page a key holding no page as fetched
|
|
380
|
-
* (a model's summary of a page is no page)
|
|
380
|
+
* (a model's summary of a page is no page), or, those checks in place, the step writing the answer hands back on its
|
|
381
|
+
* first miss instead of re-picking once (a loop of REPICK_PASSES until its check passes), or its quotes have more than
|
|
382
|
+
* one check (a loop's `until` waits on one: the others would hand back with no re-pick). A judge or an `ask` is never the quote check:
|
|
381
383
|
* H5's judge flagged 149 of 170 answers while 416 of 429 quotes were in the pages, and could not tell the 8 answers
|
|
382
384
|
* quoting text no page held from the rest; code can. One line each, in words the compile retry acts on. */
|
|
383
385
|
export function quoteCheckProblems(doc) {
|
|
384
386
|
return isObject(doc) ? quoteRule(doc, {}).problems : [];
|
|
385
387
|
}
|
|
386
388
|
const siteKey = (site) => site.keys.join("\u0000");
|
|
389
|
+
/** The passes of a checked answer's re-pick loop: the draft, then one re-pick. */
|
|
390
|
+
const REPICK_PASSES = 2;
|
|
391
|
+
const quoteMissingText = ({ path, field, pages }) => `{"predicate": "quote_missing", "path": ${JSON.stringify(path)}${field ? `, "field": ${JSON.stringify(field)}` : ""}, "pages": ${JSON.stringify(pages)}}`;
|
|
392
|
+
/** Whether `step` is the re-pick of an answer `check` reads: a loop of REPICK_PASSES until that check's quote_missing (its
|
|
393
|
+
* path, field and pages) no longer holds. */
|
|
394
|
+
const repicks = (step, check) => {
|
|
395
|
+
if (!isNode(step) || step.node !== "loop" || step.maxIters !== REPICK_PASSES || !isObject(step.until) || step.until.predicate !== "not" || !isObject(step.until.of))
|
|
396
|
+
return false;
|
|
397
|
+
const of = step.until.of;
|
|
398
|
+
return of.predicate === "quote_missing" && of.path === check.path && (of.field ?? "") === check.field && JSON.stringify(of.pages) === JSON.stringify(check.pages);
|
|
399
|
+
};
|
|
400
|
+
/** The labels of the steps inside `node` (a loop's body) that write state key `key` from a `state` map. The DSL sends
|
|
401
|
+
* such a step only the keys its map names (each pass a fresh model session), so on a re-pick it never sees the failed
|
|
402
|
+
* draft, and a map naming the answer fails the first pass, which has none yet: only a step with no map reads the whole
|
|
403
|
+
* state. A map's or a composed workflow's own steps write their item's or child's state, not this one. */
|
|
404
|
+
const answersFromStateMap = (node, key, depth = 0) => {
|
|
405
|
+
if (!isNode(node) || depth > 32)
|
|
406
|
+
return [];
|
|
407
|
+
const own = writeKeyOf(node) === key && node.state !== undefined ? [String(node.label ?? node.node).slice(0, 64)] : [];
|
|
408
|
+
const inner = node.node === "map" || node.node === "workflow" ? [] : childNodes(node).flatMap((child) => answersFromStateMap(child, key, depth + 1));
|
|
409
|
+
return [...own, ...inner];
|
|
410
|
+
};
|
|
411
|
+
/** The labels of the quote_missing escalates inside `node` (a loop's body), a composed workflow's included: each hands
|
|
412
|
+
* back on the first pass's miss, so a re-pick loop around one never re-picks. */
|
|
413
|
+
const quoteEscalatesIn = (node, depth = 0) => {
|
|
414
|
+
if (!isNode(node) || depth > 32)
|
|
415
|
+
return [];
|
|
416
|
+
if (node.node === "escalate")
|
|
417
|
+
return isObject(node.when) && node.when.predicate === "quote_missing" ? [String(node.label ?? "(no label)").slice(0, 64)] : [];
|
|
418
|
+
const inner = node.node === "workflow" && isObject(node.workflow) ? [node.workflow.root] : childNodes(node);
|
|
419
|
+
return inner.flatMap((child) => quoteEscalatesIn(child, depth + 1));
|
|
420
|
+
};
|
|
387
421
|
/** quoteCheckProblems for one workflow (the draft's, or a composed workflow node's child, its schemas its own else
|
|
388
422
|
* `schemasAround`): whether the rule applies (its answer carries quotes and it fetches pages), and why it fails. Only a
|
|
389
423
|
* run's path through its top-level chain is sure to pass a step: a check is an escalate on quote_missing that is a step
|
|
@@ -439,7 +473,7 @@ function quoteRule(workflow, schemasAround, depth = 0) {
|
|
|
439
473
|
const field = read.field ?? "";
|
|
440
474
|
if (checks.some((check) => check.path === path && check.field === field))
|
|
441
475
|
continue;
|
|
442
|
-
const predicate =
|
|
476
|
+
const predicate = quoteMissingText({ path, field, pages });
|
|
443
477
|
problems.push(`the answer carries quotes (${where(site)}) and the workflow fetches pages: check them in code, with an escalate ${predicate} as a step of its top-level chain after the step that writes the answer (pages: the state keys its call steps write), never a judge`);
|
|
444
478
|
}
|
|
445
479
|
for (const { label, pages: read } of checks)
|
|
@@ -448,6 +482,27 @@ function quoteRule(workflow, schemasAround, depth = 0) {
|
|
|
448
482
|
if (!pages.includes(head))
|
|
449
483
|
problems.push(`the quote_missing escalate ${JSON.stringify(label)} reads ${JSON.stringify(String(page).slice(0, 64))} as a page, which no call step fetched: its pages are the state keys its call steps write (${pages.join(", ")})`);
|
|
450
484
|
}
|
|
485
|
+
// Once the checks hold, the answer re-picks once before one hands back (H5d, preregistered: the answer step once more
|
|
486
|
+
// over the run's pages kept 26 of 31 misses, right 76.9% against the draft's 50.0%, at 11.6% of the agent's cost
|
|
487
|
+
// where handing every miss back cost 21.7%): the step writing it is a loop of REPICK_PASSES until its check passes.
|
|
488
|
+
// A loop's `until` is one predicate and none joins two, so the loop waits on every check only when they are all one
|
|
489
|
+
// check (the same path, field and pages): a loop watching one of several lets the others hand back with no re-pick.
|
|
490
|
+
const [first] = checks;
|
|
491
|
+
const distinct = new Set(checks.map(quoteMissingText)).size;
|
|
492
|
+
if (!problems.length && distinct > 1) {
|
|
493
|
+
problems.push(`the answer's quotes are checked by ${distinct} different quote_missing escalates, and a re-pick loop's "until" reads one check (no predicate joins two), so the loop would let the others hand back with no re-pick: give the answer's quotes one place one check reads (a quote, a list of quotes or a list of records each holding its quote at one field), one quote_missing escalate on it after the step that writes the answer, and that step the body of a loop {"node": "loop", "label": "repick", "maxIters": ${REPICK_PASSES}, "until": {"predicate": "not", "of": <that same quote_missing>}, "body": <the step>}`);
|
|
494
|
+
}
|
|
495
|
+
else if (!problems.length && first && isNode(writer) && writer.node === "loop" && quoteEscalatesIn(writer.body).length) {
|
|
496
|
+
// A check inside the loop's body hands back on the first draft's miss: the loop never re-picks.
|
|
497
|
+
problems.push(`the re-pick loop ${JSON.stringify(String(writer.label ?? "(no label)").slice(0, 64))} holds the quote_missing escalate ${JSON.stringify(quoteEscalatesIn(writer.body)[0])} in its body, which hands back on the first draft's miss, so the loop never re-picks: the check after the loop, never inside it, as a step of the top-level chain`);
|
|
498
|
+
}
|
|
499
|
+
else if (!problems.length && first && isNode(writer) && writer.node === "loop" && repicks(writer, first) && answersFromStateMap(writer.body, answerPath.split(".")[0]).length) {
|
|
500
|
+
// The re-pick must see the failed draft: its step reads the whole state (no `state` map).
|
|
501
|
+
problems.push(`the step ${JSON.stringify(answersFromStateMap(writer.body, answerPath.split(".")[0])[0])} in the re-pick loop ${JSON.stringify(String(writer.label ?? "(no label)").slice(0, 64))} writes the answer from a "state" map, which passes it only the keys it names, so its second pass never sees the failed draft (and naming the answer there fails the first pass, before any draft exists): give it no "state" map, so it reads the whole run state, the failed draft included`);
|
|
502
|
+
}
|
|
503
|
+
else if (!problems.length && first && !checks.every((check) => repicks(writer, check))) {
|
|
504
|
+
problems.push(`the step ${JSON.stringify(String(isNode(writer) ? writer.label ?? writer.node : "(no label)").slice(0, 64))} writes the answer and the escalate ${JSON.stringify(first.label)} hands it back on its first quote miss: give it one re-pick first, the step in a loop {"node": "loop", "label": "repick", "maxIters": ${REPICK_PASSES}, "until": {"predicate": "not", "of": ${quoteMissingText(first)}}, "body": <the step>} in its place, its instructions saying that a draft already in state failed the quote check, so a draft quoting text no page holds is written once more and only a second miss hands back: the check after the loop, never inside it`);
|
|
505
|
+
}
|
|
451
506
|
}
|
|
452
507
|
// A composed workflow writing the answer that applies the rule and fails it: its own check is the one to fix.
|
|
453
508
|
if (problems.length && child.problems.length)
|
package/dist/learn/compile.d.ts
CHANGED
|
@@ -119,11 +119,12 @@ export type CompiledRecord = {
|
|
|
119
119
|
};
|
|
120
120
|
/** Whether the draft a compile kept at `digest` serves (learn/promote.ts records, newest wins): true once promoted, or
|
|
121
121
|
* once a threshold refit of it was (its new revision serves in its place); false while held, or once a newer revision
|
|
122
|
-
*
|
|
122
|
+
* was skipped for a newer one; undefined while it is queued or replayed, or before its first claim decides it. */
|
|
123
123
|
export declare function promotedOf(records: readonly PromotionRecord[], workflow: string, digest: string): boolean | undefined;
|
|
124
124
|
/** The learned workflows whose newest revision other than their champion (learn/promote.ts championOf, which serves while
|
|
125
125
|
* that revision is held) is held: each one's compile turn is asked for a revision (once per hold). A champion's own
|
|
126
|
-
* graded hold counts: with it held there is no champion.
|
|
126
|
+
* graded hold counts: with it held there is no champion. One with a revision queued is not: that newer revision replays
|
|
127
|
+
* next (a replay ahead of it held meanwhile asks for nothing). */
|
|
127
128
|
export declare function heldNamesOf(records: readonly PromotionRecord[]): Set<string>;
|
|
128
129
|
/** Whether a run's look-back compiles its agent's job: the run completed, the agent has no learned workflow (active or
|
|
129
130
|
* waiting for its owner's OK), none of its last COMPILE_QUIET_RUNS runs compiled, and it keeps COMPILE_AFTER_NOTES
|
package/dist/learn/compile.js
CHANGED
|
@@ -14,7 +14,7 @@ import { createHash } from "node:crypto";
|
|
|
14
14
|
import { childNodes, LEARNED_MAX_TURNS, frontMatter, WORKFLOW_NAME, WORKFLOWS_DIR } from "./skills.js";
|
|
15
15
|
import { NOTE_BLOCK, parseReflection, SKILL_BLOCK, WORKFLOW_BLOCK } from "./reflect.js";
|
|
16
16
|
import { NOTE_FILE } from "./notes.js";
|
|
17
|
-
import { answersAlone, championOf, LABEL_MAX, PROMOTE_BAR, promotionOf } from "./promote.js";
|
|
17
|
+
import { answersAlone, championOf, LABEL_MAX, PROMOTE_BAR, promotionOf, replayingOf } from "./promote.js";
|
|
18
18
|
import { redactSecrets } from "./secrets.js";
|
|
19
19
|
/** How many active notes an agent keeps before its look-back compiles its job. */
|
|
20
20
|
export const COMPILE_AFTER_NOTES = 3;
|
|
@@ -39,22 +39,23 @@ const ERRORS_MAX = 10;
|
|
|
39
39
|
const ERROR_MAX = 400;
|
|
40
40
|
/** Whether the draft a compile kept at `digest` serves (learn/promote.ts records, newest wins): true once promoted, or
|
|
41
41
|
* once a threshold refit of it was (its new revision serves in its place); false while held, or once a newer revision
|
|
42
|
-
*
|
|
42
|
+
* was skipped for a newer one; undefined while it is queued or replayed, or before its first claim decides it. */
|
|
43
43
|
export function promotedOf(records, workflow, digest) {
|
|
44
44
|
const own = promotionOf(records, workflow, digest);
|
|
45
45
|
if (own?.decided === "promote")
|
|
46
46
|
return true;
|
|
47
47
|
if (records.some((one) => one.workflow === workflow && one.decided === "promote" && one.source === "refit" && one.refit?.from === digest))
|
|
48
48
|
return true;
|
|
49
|
-
return own?.decided === "hold" || own?.decided === "
|
|
49
|
+
return own?.decided === "hold" || own?.decided === "skipped" ? false : undefined;
|
|
50
50
|
}
|
|
51
51
|
/** The learned workflows whose newest revision other than their champion (learn/promote.ts championOf, which serves while
|
|
52
52
|
* that revision is held) is held: each one's compile turn is asked for a revision (once per hold). A champion's own
|
|
53
|
-
* graded hold counts: with it held there is no champion.
|
|
53
|
+
* graded hold counts: with it held there is no champion. One with a revision queued is not: that newer revision replays
|
|
54
|
+
* next (a replay ahead of it held meanwhile asks for nothing). */
|
|
54
55
|
export function heldNamesOf(records) {
|
|
55
56
|
return new Set([...new Set(records.map(({ workflow }) => workflow))].filter((name) => {
|
|
56
57
|
const champion = championOf(records, name)?.digest;
|
|
57
|
-
return records.findLast((one) => one.workflow === name && one.digest !== champion)?.decided === "hold";
|
|
58
|
+
return records.findLast((one) => one.workflow === name && one.digest !== champion)?.decided === "hold" && !replayingOf(records, name, null, "queued").length;
|
|
58
59
|
}));
|
|
59
60
|
}
|
|
60
61
|
/** Whether a run's look-back compiles its agent's job: the run completed, the agent has no learned workflow (active or
|
|
@@ -75,7 +76,7 @@ const guardOf = (signal) => ({ signal, threshold: GUARD_THRESHOLD });
|
|
|
75
76
|
const guardText = (signal) => `\`"guard": {"signal": "${signal}", "threshold": ${GUARD_THRESHOLD}}\``;
|
|
76
77
|
/** The quote check a compiled workflow's answer gets when it quotes fetched pages (check.ts quoteCheckProblems refuses a
|
|
77
78
|
* draft without it): code, never a judge. */
|
|
78
|
-
const QUOTE_CHECK_RULE = "An answer that quotes pages a call step fetched is checked in code: an escalate on `{\"predicate\": \"quote_missing\", \"path\": \"<the answer's quotes, e.g. answer.evidence>\", \"field\": \"quote\", \"pages\": [<the keys the call steps write>]}`, a step of the top-level chain after the step that writes the answer, hands back an answer quoting text no fetched page holds. Its pages are what the calls fetched, never a model's summary of them. Never ask a judge, an `ask` or a guard whether quotes are verbatim.";
|
|
79
|
+
const QUOTE_CHECK_RULE = "An answer that quotes pages a call step fetched is checked in code: an escalate on `{\"predicate\": \"quote_missing\", \"path\": \"<the answer's quotes, e.g. answer.evidence>\", \"field\": \"quote\", \"pages\": [<the keys the call steps write>]}`, a step of the top-level chain after the step that writes the answer, hands back an answer quoting text no fetched page holds. Its pages are what the calls fetched, never a model's summary of them. Never ask a judge, an `ask` or a guard whether quotes are verbatim. Give the answer one re-pick before it hands back: make the step that writes the answer the body of a `loop` with `\"maxIters\": 2` and `\"until\": {\"predicate\": \"not\", \"of\": <that same quote_missing>}`, its instructions saying that a draft already in state failed the quote check (recopy each quote exactly from the page it names, or quote another line); the step in the loop has no `state` map, so it reads the whole run state and its second pass sees the failed draft (a `state` map passes only the keys it names, and naming the answer there fails the first pass, before any draft exists); and keep the escalate a step of the top-level chain: the check after the loop, never inside it (a check in its body hands back on the first miss, so the loop never re-picks); only a second miss hands back. The loop's `until` reads one check: keep the answer's quotes in one place one `quote_missing` reads (a quote, a list of quotes or a list of records each holding its quote at one field), never a quote that may be a string or records, nor quotes in two places.";
|
|
79
80
|
/** This host's addendum to the DSL's author contract: the node kinds it runs, and its rules, each one the checks hold a
|
|
80
81
|
* draft to (learn/skills.ts draftProblems; propose.ts). `jev`: the run can call Jev (one of its decision providers,
|
|
81
82
|
* not denied), so every step is asked for a guard Jev reads. */
|
package/dist/learn/promote.d.ts
CHANGED
|
@@ -66,8 +66,10 @@ export declare const scoreOf: (x: ReplayScore) => ReplayScore;
|
|
|
66
66
|
export declare const answersAlone: (score: Pick<ReplayScore, "n" | "handed_back">) => boolean;
|
|
67
67
|
/** A learned workflow's promotion record at one digest. `decided`: `promote` (it serves first), `hold` (it does not: the
|
|
68
68
|
* champion, championOf, takes its runs, else the agent, until a new revision), `replaying` (its replay runs, `runs`,
|
|
69
|
-
* are at work; the champion serves meanwhile, else the agent),
|
|
70
|
-
*
|
|
69
|
+
* are at work; the champion serves meanwhile, else the agent), `queued` (it came while another revision replayed: one
|
|
70
|
+
* replays at a time, and a running replay finishes; it replays next once that one is decided, unless a newer revision
|
|
71
|
+
* comes first), or `skipped` (a newer revision, `skipped_by`, came while it was queued: only the newest queued one
|
|
72
|
+
* replays next, so it never replayed and never serves). `source`: `replay` (decided on its replay), `dry_run` (fewer than REPLAY_MIN graded inputs: promoted on
|
|
71
73
|
* its passing dry run), `refit` (a threshold refit wrote this revision, decided on the rows it was fit on), `graded` (a
|
|
72
74
|
* serving revision's graded runs fell below the bar: held). `replay`: the numbers it was decided on, with the graded runs
|
|
73
75
|
* replayed (`of`), what its replay runs cost (`cost_usd`, null when one's is unknown), its runs' outcomes (`outcomes`,
|
|
@@ -83,7 +85,7 @@ export interface PromotionRecord {
|
|
|
83
85
|
readonly workflow: string;
|
|
84
86
|
readonly digest: string;
|
|
85
87
|
readonly at: string;
|
|
86
|
-
readonly decided: "promote" | "hold" | "replaying" | "
|
|
88
|
+
readonly decided: "promote" | "hold" | "replaying" | "queued" | "skipped";
|
|
87
89
|
readonly source: "replay" | "dry_run" | "refit" | "graded";
|
|
88
90
|
readonly reason: string;
|
|
89
91
|
readonly replay?: ReplayScore & {
|
|
@@ -123,8 +125,8 @@ export interface PromotionRecord {
|
|
|
123
125
|
* inputs), and on a replay's hold: a replay of the revision promotes it only once it answered (or handed back) on every
|
|
124
126
|
* one (runner/promotion.ts heldOn). */
|
|
125
127
|
readonly held_on?: readonly string[];
|
|
126
|
-
/** A
|
|
127
|
-
readonly
|
|
128
|
+
/** A skipped revision's newer one: the digest that came while it was queued, and replays in its place. */
|
|
129
|
+
readonly skipped_by?: string;
|
|
128
130
|
/** The learning commit whose workflows/<workflow>/workflow.json is this digest's text: the seed of the claim that
|
|
129
131
|
* recorded it, or a refit's own commit. What the digest serves from as the champion (championOf) once a newer revision
|
|
130
132
|
* is on the folder's main. */
|
|
@@ -171,7 +173,11 @@ export declare const putGrade: (settings: Pick<Settings, "get" | "putIfAbsent" |
|
|
|
171
173
|
* that round's steer, in place: its `seq` stays, so a serving digest's check never counts it twice. A newer grade of the
|
|
172
174
|
* run is left as it is, one given in the same millisecond too (its `seq` is another). The grade, marked. */
|
|
173
175
|
export declare const markGradeRound: (settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, grade: Grade, opened: OpenedRound) => Promise<Grade>;
|
|
174
|
-
/** The agent's promotion records, oldest first.
|
|
176
|
+
/** The agent's promotion records, oldest first. A beta.39 store may hold `decided: "superseded"` (a replay a newer draft
|
|
177
|
+
* cancelled; beta.40 writes `skipped` for an older draft instead): read as `skipped`, `skipped_by` the draft that
|
|
178
|
+
* superseded it, with a reason that says when. Only the read maps (readAs, also what a guarded write compares): the stored
|
|
179
|
+
* record is never rewritten. */
|
|
180
|
+
export declare const readAs: (one: PromotionRecord) => PromotionRecord;
|
|
175
181
|
export declare const promotionsOf: (settings: Pick<Settings, "get">, agentId: string) => Promise<PromotionRecord[]>;
|
|
176
182
|
/** The newest record of `workflow` at `digest`, or undefined. */
|
|
177
183
|
export declare const promotionOf: (records: readonly PromotionRecord[], workflow: string, digest: string) => PromotionRecord | undefined;
|
|
@@ -182,12 +188,13 @@ export declare const promotionOf: (records: readonly PromotionRecord[], workflow
|
|
|
182
188
|
* revision its owner replays (runner/promotion.ts askReplay) and the replay promotes wins again: the champion from then.
|
|
183
189
|
* The money rule stops it on its own (runner/workflow-first.ts). Undefined: none. */
|
|
184
190
|
export declare function championOf(records: readonly PromotionRecord[], workflow: string): PromotionRecord | undefined;
|
|
185
|
-
/** The revisions of `workflow` other than `digest` whose newest record still says replaying,
|
|
186
|
-
*
|
|
187
|
-
|
|
191
|
+
/** The revisions of `workflow` other than `digest` whose newest record still says `decided` (replaying, else queued),
|
|
192
|
+
* newest first: at most one replaying (one replay at a time, the reservation's guarded write), and at most one queued
|
|
193
|
+
* once each newer one skips the one queued before it (runner/promotion.ts). */
|
|
194
|
+
export declare function replayingOf(records: readonly PromotionRecord[], workflow: string, digest: string | null, decided?: "replaying" | "queued"): PromotionRecord[];
|
|
188
195
|
/** What each learned workflow with a record serves, by name: `digest`, its champion's (championOf; null: none serves,
|
|
189
|
-
* the agent takes its runs), and `replaying`, the revision other than it whose replay is at work (null: none; a
|
|
190
|
-
*
|
|
196
|
+
* the agent takes its runs), and `replaying`, the revision other than it whose replay is at work (null: none; a queued
|
|
197
|
+
* one is not at work yet). What the promotions list says beside the records
|
|
191
198
|
* (GET /agents/{id}/learning/promotions). */
|
|
192
199
|
export declare function servingOf(records: readonly PromotionRecord[]): {
|
|
193
200
|
workflow: string;
|
|
@@ -216,15 +223,19 @@ export type Recorded = {
|
|
|
216
223
|
};
|
|
217
224
|
/** Keeps `record` as the newest of its workflow at its digest, when `still` holds of the one there now (none: undefined)
|
|
218
225
|
* and of every record kept (`items`: a check across revisions, one challenger at a time, in the same guarded write): so
|
|
219
|
-
* of two claims deciding at once only the first decision is kept, and only its claim acts on it (Recorded.won).
|
|
220
|
-
|
|
226
|
+
* of two claims deciding at once only the first decision is kept, and only its claim acts on it (Recorded.won). `also`:
|
|
227
|
+
* records kept after it in the same write, all or none (a queue change and the skips it makes, runner/promotion.ts). */
|
|
228
|
+
export declare function recordPromotion(settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, record: PromotionRecord, still: (now: PromotionRecord | undefined, items: readonly PromotionRecord[]) => boolean, also?: readonly PromotionRecord[]): Promise<Recorded>;
|
|
221
229
|
/** The newest records, at most PROMOTIONS_KEPT, in order, with each workflow's champion (championOf) the same after as
|
|
222
230
|
* before, whatever was dropped. championOf reads two things, and the trim keeps both: the place of every digest it can
|
|
223
231
|
* still see promoted (a promote record kept keeps its win, winsOf, beside it, so an older revision's late graded check
|
|
224
232
|
* never reads as a newer promotion), and the digest promoted last, its latest win and its newest record (so a held last
|
|
225
233
|
* revision is never trimmed into handing the champion back). The kept records are a run of the newest plus those wins,
|
|
226
234
|
* and a win's own run reaches no further back than it: a record that ended an older run of the same digest is newer
|
|
227
|
-
* than every record of that run, so a run is never joined to an older one by the trim.
|
|
235
|
+
* than every record of that run, so a run is never joined to an older one by the trim. The queue's state is kept too,
|
|
236
|
+
* whatever its age: a replaying revision's newest record (what its settle, its runs' claims and the one-replay-at-a-time
|
|
237
|
+
* check read: dropped, a newer revision would start a second replay while its runs run, and its verdict would never
|
|
238
|
+
* land) and a queued one's (what replays next). Neither is a promote record, so championOf reads the same. */
|
|
228
239
|
export declare function trimPromotions(items: readonly PromotionRecord[]): PromotionRecord[];
|
|
229
240
|
/** One replayed input: the graded run it replays (`of`), its recorded answer, its grade and the path it took (whose
|
|
230
241
|
* answer it is: agentRight), and what the workflow
|