@parcha/agentrun-serve 0.1.0-beta.40 → 0.1.0-beta.42

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.
Files changed (199) hide show
  1. package/CHANGELOG.md +130 -0
  2. package/NOTICE +2 -0
  3. package/README.md +149 -21
  4. package/dist/agent-rows.d.ts +1 -1
  5. package/dist/agents-store.js +3 -1
  6. package/dist/api-only.d.ts +3 -1
  7. package/dist/api-only.js +4 -2
  8. package/dist/api-token.d.ts +30 -0
  9. package/dist/api-token.js +89 -0
  10. package/dist/calendar/address.d.ts +49 -0
  11. package/dist/calendar/address.js +153 -0
  12. package/dist/calendar/fetch.d.ts +24 -0
  13. package/dist/calendar/fetch.js +146 -0
  14. package/dist/calendar/ics-faux.d.ts +39 -0
  15. package/dist/calendar/ics-faux.js +236 -0
  16. package/dist/calendar/labels.d.ts +3 -0
  17. package/dist/calendar/labels.js +61 -0
  18. package/dist/calendar/names.d.ts +52 -0
  19. package/dist/calendar/names.js +54 -0
  20. package/dist/calendar/parse.d.ts +108 -0
  21. package/dist/calendar/parse.js +625 -0
  22. package/dist/calendar/routes.d.ts +17 -0
  23. package/dist/calendar/routes.js +81 -0
  24. package/dist/calendar/tools.d.ts +23 -0
  25. package/dist/calendar/tools.js +124 -0
  26. package/dist/cli.js +22 -6
  27. package/dist/composio-made.d.ts +54 -0
  28. package/dist/composio-made.js +83 -0
  29. package/dist/composio-preset.d.ts +16 -8
  30. package/dist/composio-preset.js +106 -43
  31. package/dist/composio-triggers.d.ts +7 -2
  32. package/dist/composio-triggers.js +13 -7
  33. package/dist/computer-attach.d.ts +29 -11
  34. package/dist/computer-attach.js +141 -47
  35. package/dist/computer-keys.d.ts +4 -0
  36. package/dist/computer-keys.js +5 -0
  37. package/dist/computer-record.d.ts +55 -0
  38. package/dist/computer-record.js +315 -0
  39. package/dist/computer-setting.d.ts +1 -0
  40. package/dist/computer-setting.js +15 -2
  41. package/dist/computers.d.ts +11 -1
  42. package/dist/computers.js +23 -26
  43. package/dist/console/assets/{index-B8Zn1Iqn.css → index-C3gNPz58.css} +1 -1
  44. package/dist/console/assets/index-DYJ_wj27.js +711 -0
  45. package/dist/console/index.html +2 -2
  46. package/dist/decisions.js +9 -2
  47. package/dist/eval-feed.d.ts +26 -0
  48. package/dist/eval-feed.js +72 -0
  49. package/dist/eval-mailbox.d.ts +4 -1
  50. package/dist/eval-mailbox.js +11 -3
  51. package/dist/exa-keyless.d.ts +1 -1
  52. package/dist/exa-keyless.js +1 -1
  53. package/dist/feed/feed-faux.d.ts +62 -0
  54. package/dist/feed/feed-faux.js +123 -0
  55. package/dist/feed/fetch.d.ts +41 -0
  56. package/dist/feed/fetch.js +128 -0
  57. package/dist/feed/parse.d.ts +42 -0
  58. package/dist/feed/parse.js +291 -0
  59. package/dist/feed/pointer.d.ts +2 -0
  60. package/dist/feed/pointer.js +17 -0
  61. package/dist/file-types.js +1 -0
  62. package/dist/host-command.d.ts +3 -0
  63. package/dist/host-command.js +18 -0
  64. package/dist/host.d.ts +3 -0
  65. package/dist/host.js +3 -0
  66. package/dist/learn/check.d.ts +17 -1
  67. package/dist/learn/check.js +240 -5
  68. package/dist/learn/compile.d.ts +48 -27
  69. package/dist/learn/compile.js +134 -101
  70. package/dist/learn/promote.d.ts +61 -5
  71. package/dist/learn/promote.js +12 -2
  72. package/dist/learned-nodes.d.ts +21 -4
  73. package/dist/learned-nodes.js +21 -8
  74. package/dist/learned-workflow.d.ts +3 -3
  75. package/dist/learned-workflow.js +14 -5
  76. package/dist/learning-setting.d.ts +23 -0
  77. package/dist/learning-setting.js +51 -0
  78. package/dist/learning-words.d.ts +3 -0
  79. package/dist/learning-words.js +3 -0
  80. package/dist/learning.d.ts +3 -2
  81. package/dist/learning.js +5 -3
  82. package/dist/mcp-oauth.d.ts +23 -1
  83. package/dist/mcp-oauth.js +46 -5
  84. package/dist/mcp-pin-first.d.ts +4 -2
  85. package/dist/mcp-pin-first.js +4 -3
  86. package/dist/mcp-private-hosts.d.ts +13 -0
  87. package/dist/mcp-private-hosts.js +16 -0
  88. package/dist/mcp-servers-store.d.ts +58 -5
  89. package/dist/mcp-servers-store.js +136 -17
  90. package/dist/mcp.d.ts +2 -2
  91. package/dist/mcp.js +2 -2
  92. package/dist/observation/http.d.ts +4 -1
  93. package/dist/observation/http.js +5 -4
  94. package/dist/openapi.d.ts +1 -0
  95. package/dist/openapi.js +151 -21
  96. package/dist/print.d.ts +6 -3
  97. package/dist/print.js +4 -2
  98. package/dist/run-files.d.ts +6 -2
  99. package/dist/run-files.js +29 -7
  100. package/dist/run-labels.d.ts +23 -0
  101. package/dist/run-labels.js +79 -0
  102. package/dist/run-learning-served.d.ts +1 -1
  103. package/dist/run-reads-over-store.d.ts +5 -1
  104. package/dist/run-reads-over-store.js +8 -4
  105. package/dist/run-recordings.d.ts +20 -0
  106. package/dist/run-recordings.js +133 -0
  107. package/dist/run-secrets.js +12 -4
  108. package/dist/runner/adapter-loop.d.ts +1 -1
  109. package/dist/runner/adapter-loop.js +94 -16
  110. package/dist/runner/adapter-run-spec.d.ts +19 -0
  111. package/dist/runner/adapter-run-spec.js +57 -36
  112. package/dist/runner/beside.d.ts +6 -3
  113. package/dist/runner/beside.js +9 -7
  114. package/dist/runner/cli-run-spec.js +41 -32
  115. package/dist/runner/conformance/harness.js +69 -14
  116. package/dist/runner/conformance/subject.d.ts +4 -1
  117. package/dist/runner/feedback-round.d.ts +9 -25
  118. package/dist/runner/feedback-round.js +22 -40
  119. package/dist/runner/learning-end.d.ts +17 -7
  120. package/dist/runner/learning-end.js +79 -53
  121. package/dist/runner/main.d.ts +12 -1
  122. package/dist/runner/main.js +31 -4
  123. package/dist/runner/mcp-claim.d.ts +3 -0
  124. package/dist/runner/mcp-claim.js +1 -1
  125. package/dist/runner/mcp-run.d.ts +6 -2
  126. package/dist/runner/mcp-run.js +5 -3
  127. package/dist/runner/model-route.d.ts +4 -2
  128. package/dist/runner/model-route.js +8 -8
  129. package/dist/runner/promotion.d.ts +44 -4
  130. package/dist/runner/promotion.js +323 -21
  131. package/dist/runner/reflect-hook.d.ts +5 -0
  132. package/dist/runner/reflect-hook.js +22 -14
  133. package/dist/runner/store-secrets.js +3 -1
  134. package/dist/runner/workflow-first.d.ts +6 -11
  135. package/dist/runner/workflow-first.js +16 -20
  136. package/dist/runs-over-store.d.ts +1 -1
  137. package/dist/runs-over-store.js +5 -2
  138. package/dist/sdk/runs.d.ts +7 -1
  139. package/dist/sdk/runs.js +21 -7
  140. package/dist/secret-cut.js +3 -1
  141. package/dist/secrets.js +5 -3
  142. package/dist/server.d.ts +31 -5
  143. package/dist/server.js +240 -61
  144. package/dist/store/agent-body.d.ts +5 -3
  145. package/dist/store/agent-body.js +14 -10
  146. package/dist/store/dialect.d.ts +3 -0
  147. package/dist/store/dialect.js +1 -0
  148. package/dist/store/index.d.ts +1 -1
  149. package/dist/store/postgres/dialect.js +1 -0
  150. package/dist/store/postgres/migrations/0015_run_labels.sql +5 -0
  151. package/dist/store/postgres/migrations/0016_minted_tokens.sql +21 -0
  152. package/dist/store/schema.d.ts +9 -0
  153. package/dist/store/schema.js +26 -2
  154. package/dist/store/sqlite/connection.js +11 -3
  155. package/dist/store/sqlite/run-patch.d.ts +2 -1
  156. package/dist/store/sqlite/run-patch.js +3 -2
  157. package/dist/store/sqlite/store.js +64 -10
  158. package/dist/store/store.d.ts +38 -1
  159. package/dist/store-reads/journal.js +2 -1
  160. package/dist/store-reads/learning.d.ts +1 -1
  161. package/dist/store-reads/learning.js +6 -1
  162. package/dist/store-reads/loop.d.ts +1 -0
  163. package/dist/store-reads/loop.js +14 -4
  164. package/dist/store-reads/runs.d.ts +4 -3
  165. package/dist/store-reads/runs.js +3 -2
  166. package/dist/store-view.d.ts +5 -0
  167. package/dist/store-view.js +8 -2
  168. package/dist/template-eval.d.ts +11 -0
  169. package/dist/template-eval.js +177 -52
  170. package/dist/templates.d.ts +13 -1
  171. package/dist/templates.js +89 -18
  172. package/dist/timeline/computer.js +2 -1
  173. package/dist/timeline/origin.d.ts +1 -1
  174. package/dist/timeline/origin.js +2 -2
  175. package/dist/tool-list.js +1 -0
  176. package/dist/tools.d.ts +7 -0
  177. package/dist/tools.js +11 -0
  178. package/dist/trigger-adapter.d.ts +9 -4
  179. package/dist/trigger-adapters.js +2 -1
  180. package/dist/trigger-feed.d.ts +12 -0
  181. package/dist/trigger-feed.js +420 -0
  182. package/dist/triggers.d.ts +2 -1
  183. package/dist/triggers.js +23 -5
  184. package/dist/validate.js +7 -2
  185. package/dist/webhooks.js +9 -5
  186. package/dist/workspace/computer-deps.d.ts +5 -1
  187. package/dist/workspace/computer-deps.js +2 -2
  188. package/dist/workspace/computer-for-claim.d.ts +7 -0
  189. package/dist/workspace/computer-for-claim.js +12 -2
  190. package/dist/workspace/index.d.ts +1 -0
  191. package/dist/workspace/index.js +2 -0
  192. package/dist/workspace/paths.d.ts +4 -0
  193. package/dist/workspace/paths.js +9 -0
  194. package/dist/workspace/resolve-computer.d.ts +35 -4
  195. package/dist/workspace/resolve-computer.js +47 -9
  196. package/launcher/agentrun-serve +34 -22
  197. package/package.json +11 -9
  198. package/templates/README.md +38 -4
  199. package/dist/console/assets/index-Jbxjcmdp.js +0 -705
@@ -0,0 +1,291 @@
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
+ import { pointed } from "./pointer.js";
9
+ export { pointed };
10
+ /** The most characters of an item's summary its payload holds. */
11
+ export const SUMMARY_CHARS = 4000;
12
+ /** The most characters of a title. */
13
+ const TITLE_CHARS = 1000;
14
+ /** The most characters of any other text field (an id, a link, an author, a category). */
15
+ const FIELD_CHARS = 2000;
16
+ /** The most categories an item's payload lists. */
17
+ const CATEGORIES = 50;
18
+ /** A body that is no feed this reads: its words. */
19
+ export class FeedUnreadable extends Error {
20
+ name = "FeedUnreadable";
21
+ }
22
+ const clip = (text, max) => (text.length > max ? `${text.slice(0, max - 1)}…` : text);
23
+ const hash = (text) => createHash("sha256").update(text).digest("hex").slice(0, 16);
24
+ const NAMED = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: " ", mdash: "—", ndash: "–", hellip: "…", rsquo: "’", lsquo: "‘", rdquo: "”", ldquo: "“", copy: "©", reg: "®", trade: "™", middot: "·", bull: "•" };
25
+ /** `text`'s HTML character references decoded (the named ones above, and every numeric one). */
26
+ const entities = (text) => text.replace(/&(#x[0-9a-f]{1,6}|#\d{1,7}|[a-z]{2,8});/gi, (whole, ref) => {
27
+ if (ref[0] === "#") {
28
+ const code = ref[1] === "x" || ref[1] === "X" ? parseInt(ref.slice(2), 16) : parseInt(ref.slice(1), 10);
29
+ return code > 0 && code <= 0x10ffff && !(code >= 0xd800 && code <= 0xdfff) ? String.fromCodePoint(code) : "";
30
+ }
31
+ return NAMED[ref.toLowerCase()] ?? whole;
32
+ });
33
+ 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;
34
+ /** HTML as text: scripts and styles dropped, each block its own line, other tags dropped, references decoded, the spaces
35
+ * in each line collapsed and empty lines dropped. */
36
+ export function htmlToText(html) {
37
+ const text = html.replace(/<!--[\s\S]*?-->/g, "").replace(/<(script|style)\b[\s\S]*?<\/\1\s*>/gi, "").replace(BLOCK, "\n").replace(/<[^>]*>/g, "");
38
+ return lines(entities(text));
39
+ }
40
+ /** Plain text: the spaces in each line collapsed, empty lines dropped. */
41
+ const lines = (text) => text.split(/\r?\n/).map((line) => line.replace(/[ \t \f\v\r]+/g, " ").trim()).filter(Boolean).join("\n");
42
+ /** An instant from an RFC 3339 or RFC 822 date, or null. */
43
+ function instant(value) {
44
+ const text = textOf(value);
45
+ if (!text)
46
+ return null;
47
+ const at = Date.parse(text);
48
+ return Number.isFinite(at) ? at : null;
49
+ }
50
+ /** A parsed XML node's text: a string as it is; an element with attributes, its text node; a list, its first. */
51
+ function textOf(node) {
52
+ if (Array.isArray(node))
53
+ return textOf(node[0]);
54
+ if (typeof node === "string")
55
+ return node;
56
+ if (typeof node === "number" || typeof node === "boolean")
57
+ return String(node);
58
+ if (node && typeof node === "object") {
59
+ // Its text and its CDATA, kept apart by the parser: each as it reads (both, in the rare node with both).
60
+ const parts = [node["#text"], ...list(node["#cdata"])].filter((one) => typeof one === "string" || typeof one === "number");
61
+ return parts.length ? parts.map(String).join(" ") : undefined;
62
+ }
63
+ return undefined;
64
+ }
65
+ /** A node's text, trimmed and bounded, or null when it holds none. */
66
+ const field = (node, max = FIELD_CHARS) => {
67
+ const text = textOf(node)?.trim();
68
+ return text ? clip(text, max) : null;
69
+ };
70
+ /** An Atom text construct (a title, a summary, a content) as text: type html read as HTML, text as text; type xhtml (its
71
+ * XHTML inline, which the parser keeps by name, out of order) as the HTML its `ordered` reading writes. */
72
+ const atomText = (node, ordered) => {
73
+ const type = node && typeof node === "object" && !Array.isArray(node) ? node["@_type"] : undefined;
74
+ if (type === "xhtml" && ordered !== undefined)
75
+ return htmlToText(ordered) || null;
76
+ const text = textOf(node);
77
+ if (!text?.trim())
78
+ return null;
79
+ return type === "html" || type === "xhtml" ? htmlToText(text) || null : lines(text) || null;
80
+ };
81
+ const list = (node) => (node === undefined || node === null ? [] : Array.isArray(node) ? node : [node]);
82
+ const attr = (node, name) => (node && typeof node === "object" && !Array.isArray(node) ? textOf(node[`@_${name}`]) : undefined);
83
+ /** The key an item is known by: its id, else its link, else a hash of its title and date (`hash:` and 16 hex). */
84
+ const keyOf = (id, link, title, date, rest) => id ?? link ?? `hash:${hash(`${title ?? rest ?? ""}\n${date === null ? "" : new Date(date).toISOString()}`)}`;
85
+ function item(fields) {
86
+ return { key: keyOf(fields.id, fields.link, fields.title, fields.published ?? fields.updated, fields.summary), ...fields };
87
+ }
88
+ /** XML's own references decoded in one pass, so each decodes once ("&amp;lt;" is "&lt;"): the five XML names and every
89
+ * numeric character reference. Any other name stays as it is written; a document that declares one is refused first. */
90
+ 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) => {
91
+ if (name)
92
+ return XML_NAMED[name] ?? whole;
93
+ const code = dec !== undefined ? parseInt(dec, 10) : parseInt(hex, 16);
94
+ return code > 0 && code <= 0x10ffff && !(code >= 0xd800 && code <= 0xdfff) ? String.fromCodePoint(code) : "";
95
+ });
96
+ const XML_NAMED = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" };
97
+ // The parser expands nothing (processEntities off: no DOCTYPE entity, and no count of references to cap a long feed);
98
+ // text and attribute values are decoded here instead, and a CDATA section is kept apart (#cdata), as it is written.
99
+ const XML = new XMLParser({
100
+ ignoreAttributes: false,
101
+ attributeNamePrefix: "@_",
102
+ textNodeName: "#text",
103
+ cdataPropName: "#cdata",
104
+ parseTagValue: false,
105
+ parseAttributeValue: false,
106
+ trimValues: true,
107
+ processEntities: false,
108
+ htmlEntities: false,
109
+ removeNSPrefix: true,
110
+ tagValueProcessor: (_name, value) => xmlRefs(value),
111
+ attributeValueProcessor: (_name, value) => xmlRefs(value),
112
+ isArray: (name) => ["item", "entry", "category", "link", "author", "creator"].includes(name),
113
+ });
114
+ // The same reading with each element's children in the order they are written (an xhtml text construct's), the spaces
115
+ // between them kept.
116
+ const ORDERED = new XMLParser({
117
+ ignoreAttributes: false,
118
+ attributeNamePrefix: "@_",
119
+ textNodeName: "#text",
120
+ cdataPropName: "#cdata",
121
+ parseTagValue: false,
122
+ parseAttributeValue: false,
123
+ trimValues: false,
124
+ processEntities: false,
125
+ htmlEntities: false,
126
+ removeNSPrefix: true,
127
+ preserveOrder: true,
128
+ tagValueProcessor: (_name, value) => xmlRefs(value),
129
+ attributeValueProcessor: (_name, value) => xmlRefs(value),
130
+ });
131
+ const nameOf = (node) => Object.keys(node).find((key) => key !== ":@");
132
+ const children = (node, name) => (node && Array.isArray(node[name]) ? node[name] : []);
133
+ const escapeHtml = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
134
+ /** Ordered nodes written back as HTML: each element's tag around its children, text escaped, CDATA as text. */
135
+ const markup = (nodes) => nodes
136
+ .map((node) => {
137
+ const name = nameOf(node);
138
+ if (name === undefined)
139
+ return "";
140
+ if (name === "#text")
141
+ return escapeHtml(String(node[name]));
142
+ if (name === "#cdata")
143
+ return children(node, name).map((one) => escapeHtml(String(one["#text"] ?? ""))).join("");
144
+ return `<${name}>${markup(children(node, name))}</${name}>`;
145
+ })
146
+ .join("");
147
+ /** Each xhtml text construct of an Atom document as HTML, written in order: the feed's title, and each entry's (in the
148
+ * order the entries are) title, summary and content; undefined for one that is not xhtml or not there. */
149
+ function atomXhtml(text) {
150
+ const doc = ORDERED.parse(text);
151
+ const feed = doc.find((node) => nameOf(node) === "feed");
152
+ const of = (parent, field) => {
153
+ const node = children(parent, parent ? nameOf(parent) : "").find((one) => nameOf(one) === field);
154
+ return node && node[":@"]?.["@_type"] === "xhtml" ? markup(children(node, field)) : undefined;
155
+ };
156
+ return {
157
+ title: of(feed, "title"),
158
+ entries: children(feed, "feed").filter((node) => nameOf(node) === "entry").map((entry) => ({ title: of(entry, "title"), summary: of(entry, "summary"), content: of(entry, "content") })),
159
+ };
160
+ }
161
+ /** `body` read as a feed. A JSON document is a JSON Feed (its `version` says so) unless `pointers` name a list, else a
162
+ * JSON list; anything else is read as XML: RSS or Atom. Throws FeedUnreadable in words. */
163
+ export function parseFeed(body, pointers = {}) {
164
+ const text = body.replace(/^/, "").trim();
165
+ if (!text)
166
+ throw new FeedUnreadable("its answer is empty");
167
+ if (text[0] === "{" || text[0] === "[") {
168
+ let doc;
169
+ try {
170
+ doc = JSON.parse(text);
171
+ }
172
+ catch {
173
+ throw new FeedUnreadable("its answer is not JSON, RSS or Atom");
174
+ }
175
+ const jsonFeed = doc !== null && typeof doc === "object" && !Array.isArray(doc) && typeof doc.version === "string" && String(doc.version).startsWith("https://jsonfeed.org/version/");
176
+ return jsonFeed && pointers.items === undefined && pointers.id === undefined ? jsonFeedOf(doc) : jsonListOf(doc, pointers);
177
+ }
178
+ // No entity is ever expanded: a document that declares one is refused before it is parsed.
179
+ if (/<!ENTITY/i.test(text))
180
+ throw new FeedUnreadable("it declares XML entities, which a feed is read without");
181
+ const valid = XMLValidator.validate(text);
182
+ if (valid !== true)
183
+ throw new FeedUnreadable(`it is not well-formed XML (line ${valid.err.line}: ${clip(valid.err.msg.replace(/\s+/g, " "), 200)})`);
184
+ let doc;
185
+ try {
186
+ doc = XML.parse(text);
187
+ }
188
+ catch (error) {
189
+ throw new FeedUnreadable(`it is not well-formed XML (${clip(String(error?.message ?? error), 200)})`);
190
+ }
191
+ const rss = doc.rss;
192
+ if (rss && typeof rss === "object") {
193
+ const channel = list(rss.channel)[0];
194
+ const read = channel && typeof channel === "object" ? channel : {};
195
+ return rssOf(read, list(read.item));
196
+ }
197
+ const rdf = doc.RDF;
198
+ if (rdf && typeof rdf === "object")
199
+ return rssOf(list(rdf.channel)[0] ?? {}, list(rdf.item));
200
+ const atom = doc.feed;
201
+ if (atom && typeof atom === "object")
202
+ return atomOf(atom, /\btype\s*=\s*["']xhtml["']/.test(text) ? atomXhtml(text) : undefined);
203
+ throw new FeedUnreadable("it is not RSS, Atom, JSON Feed or a JSON list");
204
+ }
205
+ function rssOf(channel, items) {
206
+ return {
207
+ list: false,
208
+ title: field(channel.title, TITLE_CHARS),
209
+ items: items.filter((one) => !!one && typeof one === "object").map((one) => {
210
+ const guid = field(one.guid);
211
+ const permalink = attr(one.guid, "isPermaLink") !== "false";
212
+ // An RSS item's link is text; an atom:link inside it (its prefix dropped) has an href.
213
+ 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);
214
+ const description = textOf(one.description) ?? textOf(one.encoded);
215
+ return item({
216
+ // A title is text, as written: never read as HTML, so nothing in it is dropped.
217
+ id: guid, link: link ? clip(link, FIELD_CHARS) : null, title: (() => {
218
+ const title = lines(textOf(one.title) ?? "");
219
+ return title ? clip(title, TITLE_CHARS) : null;
220
+ })(),
221
+ published: instant(one.pubDate) ?? instant(one.date), updated: instant(one.updated),
222
+ author: field(one.author) ?? field(one.creator),
223
+ summary: description ? clip(htmlToText(description), SUMMARY_CHARS) || null : null,
224
+ categories: list(one.category).map((c) => field(c)).filter((c) => !!c).slice(0, CATEGORIES),
225
+ });
226
+ }),
227
+ };
228
+ }
229
+ /** An Atom feed; `xhtml`, its xhtml text constructs written in order (atomXhtml), when it has any. */
230
+ function atomOf(feed, xhtml) {
231
+ return {
232
+ list: false,
233
+ title: (() => {
234
+ const title = atomText(feed.title, xhtml?.title);
235
+ return title ? clip(title, TITLE_CHARS) : null;
236
+ })(),
237
+ items: list(feed.entry).map((one, i) => [one, xhtml?.entries[i]]).filter((pair) => !!pair[0] && typeof pair[0] === "object").map(([one, ordered]) => {
238
+ const links = list(one.link);
239
+ const alternate = links.find((l) => (attr(l, "rel") ?? "alternate") === "alternate" && attr(l, "href")) ?? links.find((l) => attr(l, "href"));
240
+ const summary = atomText(one.summary, ordered?.summary) ?? atomText(one.content, ordered?.content);
241
+ const title = atomText(one.title, ordered?.title);
242
+ return item({
243
+ id: field(one.id), link: alternate ? clip(attr(alternate, "href").trim(), FIELD_CHARS) : null, title: title ? clip(title, TITLE_CHARS) : null,
244
+ published: instant(one.published) ?? instant(one.issued), updated: instant(one.updated) ?? instant(one.modified),
245
+ author: field(list(one.author)[0]?.name),
246
+ summary: summary ? clip(summary, SUMMARY_CHARS) : null,
247
+ categories: list(one.category).map((c) => attr(c, "term") ?? field(c)).filter((c) => !!c).map((c) => clip(c, FIELD_CHARS)).slice(0, CATEGORIES),
248
+ });
249
+ }),
250
+ };
251
+ }
252
+ const str = (value, max = FIELD_CHARS) => (typeof value === "string" && value.trim() ? clip(value.trim(), max) : typeof value === "number" && Number.isFinite(value) ? String(value) : null);
253
+ function jsonFeedOf(doc) {
254
+ const items = Array.isArray(doc.items) ? doc.items : [];
255
+ return {
256
+ list: false,
257
+ title: str(doc.title, TITLE_CHARS),
258
+ items: items.filter((one) => !!one && typeof one === "object" && !Array.isArray(one)).map((one) => {
259
+ const authors = Array.isArray(one.authors) ? one.authors : one.author ? [one.author] : [];
260
+ const author = authors.map((a) => (a && typeof a === "object" ? str(a.name) : null)).find(Boolean) ?? null;
261
+ 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) : "";
262
+ return item({
263
+ id: str(one.id), link: str(one.url) ?? str(one.external_url), title: str(one.title, TITLE_CHARS),
264
+ published: instant(one.date_published), updated: instant(one.date_modified), author,
265
+ summary: summary ? clip(summary, SUMMARY_CHARS) : null,
266
+ categories: (Array.isArray(one.tags) ? one.tags : []).map((tag) => str(tag)).filter((tag) => !!tag).slice(0, CATEGORIES),
267
+ });
268
+ }),
269
+ };
270
+ }
271
+ /** The instant a JSON list's `updated` pointer reads, in ms: a date string it names; anything else, none. */
272
+ const instantOf = (value) => {
273
+ const at = typeof value === "string" ? Date.parse(value) : NaN;
274
+ return Number.isNaN(at) ? null : at;
275
+ };
276
+ function jsonListOf(doc, { items: itemsAt = "", id: idAt = "/id", updated: updatedAt }) {
277
+ const items = pointed(doc, itemsAt);
278
+ if (!Array.isArray(items))
279
+ 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");
280
+ return {
281
+ list: true,
282
+ title: null,
283
+ items: items.filter((one) => one !== null && typeof one === "object").map((one) => {
284
+ const object = one;
285
+ const id = str(pointed(object, idAt));
286
+ const link = str(object.html_url) ?? str(object.url) ?? str(object.link);
287
+ const title = str(object.title, TITLE_CHARS) ?? str(object.name, TITLE_CHARS);
288
+ return { key: id ?? link ?? `hash:${hash(title ?? JSON.stringify(one))}`, id, link, title, published: null, updated: updatedAt === undefined ? null : instantOf(pointed(object, updatedAt)), author: null, summary: null, categories: [], raw: one };
289
+ }),
290
+ };
291
+ }
@@ -0,0 +1,2 @@
1
+ /** The value at JSON Pointer `pointer` in `doc`, or undefined. */
2
+ export declare function pointed(doc: unknown, pointer: string): unknown;
@@ -0,0 +1,17 @@
1
+ // A JSON Pointer read (RFC 6901), kept apart from the feed parser so the trigger reads it without loading the parser.
2
+ /** The value at JSON Pointer `pointer` in `doc`, or undefined. */
3
+ export function pointed(doc, pointer) {
4
+ if (pointer === "")
5
+ return doc;
6
+ let at = doc;
7
+ for (const raw of pointer.split("/").slice(1)) {
8
+ const part = raw.replace(/~1/g, "/").replace(/~0/g, "~");
9
+ if (Array.isArray(at) && /^(0|[1-9]\d*)$/.test(part))
10
+ at = at[Number(part)];
11
+ else if (at && typeof at === "object" && !Array.isArray(at) && Object.hasOwn(at, part))
12
+ at = at[part];
13
+ else
14
+ return undefined;
15
+ }
16
+ return at;
17
+ }
@@ -4,6 +4,7 @@ import { extname } from "node:path";
4
4
  const TYPES = new Map(Object.entries({
5
5
  txt: "text/plain; charset=utf-8", md: "text/markdown; charset=utf-8", csv: "text/csv; charset=utf-8", json: "application/json", jsonl: "application/x-ndjson",
6
6
  html: "text/html; charset=utf-8", htm: "text/html; charset=utf-8", png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", gif: "image/gif", webp: "image/webp", pdf: "application/pdf",
7
+ mp4: "video/mp4",
7
8
  }));
8
9
  /** The types a file is served as in the page (every known type but PDF); any other is a download. */
9
10
  export const INLINE_TYPES = new Set([...TYPES.values()].filter((type) => type !== "application/pdf"));
@@ -0,0 +1,3 @@
1
+ /** Whether a folder of `path` (a PATH value) holds an executable file named `command`; on Windows, with an executable
2
+ * extension too (platform-tools installs adb.exe). */
3
+ export declare function commandOnPath(command: string, path: string | undefined, platform?: string): boolean;
@@ -0,0 +1,18 @@
1
+ // Whether a program this server runs on its own machine is there: a provider's (the phone's adb, computers.ts) and the
2
+ // screen recorder's ffmpeg (computer-record.ts).
3
+ import { accessSync, constants, statSync } from "node:fs";
4
+ import { delimiter, join } from "node:path";
5
+ /** Whether a folder of `path` (a PATH value) holds an executable file named `command`; on Windows, with an executable
6
+ * extension too (platform-tools installs adb.exe). */
7
+ export function commandOnPath(command, path, platform = process.platform) {
8
+ const named = platform === "win32" ? [command, ...[".exe", ".cmd", ".bat"].map((extension) => `${command}${extension}`)] : [command];
9
+ return (path ?? "").split(delimiter).some((folder) => folder !== "" && named.some((file) => {
10
+ try {
11
+ accessSync(join(folder, file), constants.X_OK);
12
+ return statSync(join(folder, file)).isFile();
13
+ }
14
+ catch {
15
+ return false;
16
+ }
17
+ }));
18
+ }
package/dist/host.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import { statfs } from "node:fs/promises";
2
2
  import type { Store } from "./store/index.js";
3
+ /** The port a server listens on unless --port says otherwise (cli.ts), and the one a standalone runner's loopback reads
4
+ * never go to (runner/main.ts runnerLoopback). */
5
+ export declare const DEFAULT_PORT = 7340;
3
6
  /** Memory the server keeps for itself, before any run, in MiB. Measured with the runs' (harness-table.ts): the server's anon
4
7
  * 3 s after its start, 32 starts at limits of 512M to 2048M, was 58 to 81 MB, with no peak at the start over that;
5
8
  * reserved for the high end, 81, plus 47 (+58%), since what it holds grows with the agents and runs it keeps. That is
package/dist/host.js CHANGED
@@ -7,6 +7,9 @@ import { totalmem } from "node:os";
7
7
  import { REQUEST_BUSY_MS, whenFree } from "./agents.js";
8
8
  import { DEFAULT_HARNESS, HARNESSES } from "./harness.js";
9
9
  import { builtinHarness } from "./harness-table.js";
10
+ /** The port a server listens on unless --port says otherwise (cli.ts), and the one a standalone runner's loopback reads
11
+ * never go to (runner/main.ts runnerLoopback). */
12
+ export const DEFAULT_PORT = 7340;
10
13
  const MiB = 2 ** 20;
11
14
  /** Memory the server keeps for itself, before any run, in MiB. Measured with the runs' (harness-table.ts): the server's anon
12
15
  * 3 s after its start, 32 starts at limits of 512M to 2048M, was 58 to 81 MB, with no peak at the start over that;
@@ -109,10 +109,26 @@ export declare const printable: (problem: Problem, values: readonly string[]) =>
109
109
  * its item and are never the answer; a loop's body writes the state around it. Legwork on fast and an answer on strong
110
110
  * pass. Out of sample (H1), the same answering step on the fast model scored 8.5-9.6 points lower than on the agent's. */
111
111
  export declare function answerTierProblems(doc: unknown): string[];
112
+ /** Why a draft's model step off the fast tier reads a page (compact state): an agent, decide or extract step with no
113
+ * `"tier": "fast"` whose `state` map names a key that may hold a page a call step fetched (a call's result, a map's
114
+ * collected one, a pick or sift over pages, a composed workflow's answer when it is one, the key or anything under it),
115
+ * or, with no `state` map, which reads the whole state while such a key is in it (pagesRead: the engine's own lookup).
116
+ * Read in run order: a key holds a page from the step that fetched it until a model step writes over it; a parallel's
117
+ * branches each start from the same state and their writes merge, so a key one branch replaced is no page after it; a
118
+ * route runs one branch, so a key stays a page unless every branch replaced it; a loop's body is read pass after pass,
119
+ * each on every page its passes may leave, until the marks stop changing (within its maxIters); a map's body sees
120
+ * `item` as a page when its list is one, and its failedAs rows are short errors, never pages; a composed workflow's
121
+ * child sees an input key as a page when its value reads one. Pages reach a step on the agent's model only through a fast-tier step's
122
+ * output: chain14b's drafts fed whole pages to the answering step (4.1 requests a run at ~70k cached tokens each,
123
+ * $0.364 a served run), where the research shape (a fast extract's compact facts to the answering step) booked ~$0.08.
124
+ * One line each, in words the compile retry acts on. */
125
+ export declare function compactStateProblems(doc: unknown): string[];
112
126
  /** Why a draft's quote check is not code: its answer carries quotes (a `quote` or `quotes` property in its output schema)
113
127
  * and it fetches pages (a call step), yet some place in the answer holding quotes has no escalate on quote_missing
114
128
  * 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). A judge or an `ask` is never the quote check:
129
+ * (a model's summary of a page is no page), or, those checks in place, the step writing the answer hands back on its
130
+ * first miss instead of re-picking once (a loop of REPICK_PASSES until its check passes), or its quotes have more than
131
+ * 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
132
  * 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
133
  * quoting text no page held from the rest; code can. One line each, in words the compile retry acts on. */
118
134
  export declare function quoteCheckProblems(doc: unknown): string[];