@parcha/agentrun-serve 0.0.0-stage → 0.1.0-beta.29
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 +560 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +1723 -2
- package/dist/adapters.d.ts +205 -0
- package/dist/adapters.js +459 -0
- package/dist/agents.d.ts +124 -0
- package/dist/agents.js +302 -0
- package/dist/app.d.ts +7 -0
- package/dist/app.js +324 -0
- package/dist/bound-files.d.ts +4 -0
- package/dist/bound-files.js +164 -0
- package/dist/box/record.d.ts +6 -0
- package/dist/box/record.js +41 -0
- package/dist/box/sweep.d.ts +53 -0
- package/dist/box/sweep.js +193 -0
- package/dist/box-image.d.ts +98 -0
- package/dist/box-image.js +283 -0
- package/dist/box-relay.d.ts +42 -0
- package/dist/box-relay.js +222 -0
- package/dist/boxes.d.ts +54 -0
- package/dist/boxes.js +182 -0
- package/dist/cap.d.ts +224 -0
- package/dist/cap.js +721 -0
- package/dist/catalog.d.ts +20 -0
- package/dist/catalog.js +53 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +167 -0
- package/dist/coding-tools.d.ts +31 -0
- package/dist/coding-tools.js +81 -0
- package/dist/console/THIRD-PARTY-NOTICES.txt +1141 -0
- package/dist/console/assets/index-BN7oVcO4.js +445 -0
- package/dist/console/assets/index-By-jkqki.css +1 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-CIEtRijs.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-BB5xRk30.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-BHyURHCj.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-C_uLvvQ5.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-Dj6eZy5f.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-DpeVePZf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-CNojz0t3.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-3KAm9r92.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-B11XCQ5g.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-DXv3JcnD.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-DHMOLxAi.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-DiQlUoE6.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-BeU3T8wf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-ByoDsISC.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-CSpzN4cI.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-Dtizs43-.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-Cph9ettZ.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-DfGZKnlb.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-BGBUNdzT.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-COje25QW.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-4l4lq8zr.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-BGzXWJeR.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-8_E36CQj.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-C27an7Zc.woff +0 -0
- package/dist/console/index.html +15 -0
- package/dist/daytona-api.d.ts +21 -0
- package/dist/daytona-api.js +101 -0
- package/dist/decision-rows.d.ts +11 -0
- package/dist/decision-rows.js +116 -0
- package/dist/decisions.d.ts +94 -0
- package/dist/decisions.js +184 -0
- package/dist/effort-guidance.d.ts +5 -0
- package/dist/effort-guidance.js +14 -0
- package/dist/environment.d.ts +5 -0
- package/dist/environment.js +11 -0
- package/dist/errors.d.ts +72 -0
- package/dist/errors.js +66 -0
- package/dist/exa-keyless.d.ts +35 -0
- package/dist/exa-keyless.js +202 -0
- package/dist/fetch-page.d.ts +114 -0
- package/dist/fetch-page.js +182 -0
- package/dist/files.d.ts +60 -0
- package/dist/files.js +153 -0
- package/dist/grade.d.ts +96 -0
- package/dist/grade.js +348 -0
- package/dist/graph-view.d.ts +100 -0
- package/dist/graph-view.js +212 -0
- package/dist/harness-app.d.ts +38 -0
- package/dist/harness-app.js +626 -0
- package/dist/harness.d.ts +53 -0
- package/dist/harness.js +74 -0
- package/dist/home-path.d.ts +27 -0
- package/dist/home-path.js +78 -0
- package/dist/host-tools.d.ts +20 -0
- package/dist/host-tools.js +140 -0
- package/dist/host.d.ts +39 -0
- package/dist/host.js +81 -0
- package/dist/hosted-search.d.ts +27 -0
- package/dist/hosted-search.js +129 -0
- package/dist/import-sources.d.ts +104 -0
- package/dist/import-sources.js +629 -0
- package/dist/import-summary.d.ts +25 -0
- package/dist/import-summary.js +75 -0
- package/dist/import-worker.d.ts +26 -0
- package/dist/import-worker.js +41 -0
- package/dist/import.d.ts +145 -0
- package/dist/import.js +1221 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/key-check.d.ts +36 -0
- package/dist/key-check.js +108 -0
- package/dist/key-refusal.d.ts +51 -0
- package/dist/key-refusal.js +187 -0
- package/dist/learn/check.d.ts +99 -0
- package/dist/learn/check.js +259 -0
- package/dist/learn/grade.d.ts +79 -0
- package/dist/learn/grade.js +433 -0
- package/dist/learn/index.d.ts +7 -0
- package/dist/learn/index.js +11 -0
- package/dist/learn/invisible.d.ts +5 -0
- package/dist/learn/invisible.js +42 -0
- package/dist/learn/notes.d.ts +59 -0
- package/dist/learn/notes.js +146 -0
- package/dist/learn/reflect.d.ts +49 -0
- package/dist/learn/reflect.js +167 -0
- package/dist/learn/secrets.d.ts +18 -0
- package/dist/learn/secrets.js +111 -0
- package/dist/learn/skills.d.ts +84 -0
- package/dist/learn/skills.js +198 -0
- package/dist/learning-routes.d.ts +196 -0
- package/dist/learning-routes.js +609 -0
- package/dist/learning-run.d.ts +304 -0
- package/dist/learning-run.js +797 -0
- package/dist/learning-words.d.ts +73 -0
- package/dist/learning-words.js +171 -0
- package/dist/learning.d.ts +377 -0
- package/dist/learning.js +801 -0
- package/dist/llm.d.ts +40 -0
- package/dist/llm.js +37 -0
- package/dist/llms.txt +37 -0
- package/dist/mcp-servers.d.ts +115 -0
- package/dist/mcp-servers.js +445 -0
- package/dist/mcp.d.ts +51 -0
- package/dist/mcp.js +392 -0
- package/dist/model.d.ts +184 -0
- package/dist/model.js +484 -0
- package/dist/monid.d.ts +74 -0
- package/dist/monid.js +277 -0
- package/dist/openapi/agentrun-v2.openapi.json +4805 -0
- package/dist/openapi.d.ts +10 -0
- package/dist/openapi.js +1417 -0
- package/dist/owner.d.ts +55 -0
- package/dist/owner.js +222 -0
- package/dist/packs.d.ts +71 -0
- package/dist/packs.js +180 -0
- package/dist/page.d.ts +32 -0
- package/dist/page.js +133 -0
- package/dist/paid-calls.d.ts +46 -0
- package/dist/paid-calls.js +110 -0
- package/dist/pause.d.ts +68 -0
- package/dist/pause.js +97 -0
- package/dist/pdf-pages.d.ts +44 -0
- package/dist/pdf-pages.js +147 -0
- package/dist/place.d.ts +46 -0
- package/dist/place.js +105 -0
- package/dist/print.d.ts +20 -0
- package/dist/print.js +29 -0
- package/dist/propose.d.ts +38 -0
- package/dist/propose.js +82 -0
- package/dist/quiet-sqlite-warning.d.ts +1 -0
- package/dist/quiet-sqlite-warning.js +14 -0
- package/dist/request-start.d.ts +14 -0
- package/dist/request-start.js +226 -0
- package/dist/result.d.ts +3 -0
- package/dist/result.js +5 -0
- package/dist/rows.d.ts +46 -0
- package/dist/rows.js +121 -0
- package/dist/run-box.d.ts +134 -0
- package/dist/run-box.js +440 -0
- package/dist/run-manifest.d.ts +27 -0
- package/dist/run-manifest.js +60 -0
- package/dist/runnable.d.ts +80 -0
- package/dist/runnable.js +162 -0
- package/dist/runs.d.ts +840 -0
- package/dist/runs.js +2279 -0
- package/dist/secret-cut.d.ts +27 -0
- package/dist/secret-cut.js +109 -0
- package/dist/secrets.d.ts +50 -0
- package/dist/secrets.js +140 -0
- package/dist/server-lock.d.ts +44 -0
- package/dist/server-lock.js +140 -0
- package/dist/server.d.ts +626 -0
- package/dist/server.js +1756 -0
- package/dist/sessions.d.ts +4 -0
- package/dist/sessions.js +105 -0
- package/dist/skills.d.ts +31 -0
- package/dist/skills.js +68 -0
- package/dist/stats.d.ts +101 -0
- package/dist/stats.js +82 -0
- package/dist/tool-keys.d.ts +151 -0
- package/dist/tool-keys.js +273 -0
- package/dist/tool-plane.d.ts +143 -0
- package/dist/tool-plane.js +242 -0
- package/dist/tools.d.ts +147 -0
- package/dist/tools.js +253 -0
- package/dist/turn-end.d.ts +23 -0
- package/dist/turn-end.js +14 -0
- package/dist/turns.d.ts +34 -0
- package/dist/turns.js +202 -0
- package/dist/uploads.d.ts +104 -0
- package/dist/uploads.js +474 -0
- package/dist/usage.d.ts +29 -0
- package/dist/usage.js +58 -0
- package/dist/validate.d.ts +55 -0
- package/dist/validate.js +175 -0
- package/dist/web-fetch.d.ts +64 -0
- package/dist/web-fetch.js +262 -0
- package/dist/web-search.d.ts +54 -0
- package/dist/web-search.js +136 -0
- package/dist/webhooks.d.ts +182 -0
- package/dist/webhooks.js +487 -0
- package/dist/workspace-paths.d.ts +33 -0
- package/dist/workspace-paths.js +104 -0
- package/dist/workspace.d.ts +88 -0
- package/dist/workspace.js +369 -0
- package/launcher/agentrun-serve +109 -0
- package/package.json +94 -4
- package/skills/agentrun-serve/SKILL.md +128 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/** Where a skill and a workflow draft live in the folder. */
|
|
2
|
+
export const SKILLS_DIR = "skills";
|
|
3
|
+
export const WORKFLOWS_DIR = "workflows";
|
|
4
|
+
/** The shared skills convention's name: lowercase letters, digits and single dashes, at most 64. */
|
|
5
|
+
export const SKILL_NAME = /^(?=.{1,64}$)[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
6
|
+
/** A workflow's name: lowercase letters, digits, dashes and underscores, at most 64, starting with a letter or digit. */
|
|
7
|
+
export const WORKFLOW_NAME = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
8
|
+
const PLACES = [
|
|
9
|
+
[/^skills\/([^/]+)\/SKILL\.md$/, "skill"],
|
|
10
|
+
[/^workflows\/([^/]+)\/workflow\.json$/, "workflow"],
|
|
11
|
+
[/^workflows\/([^/]+)\/README\.md$/, "readme"],
|
|
12
|
+
];
|
|
13
|
+
/** Where `path` sits among the skills and workflows, its folder's name as written (unchecked); undefined when it is
|
|
14
|
+
* not a skill's or a workflow's file. */
|
|
15
|
+
export function learnedPlace(path) {
|
|
16
|
+
for (const [pattern, kind] of PLACES) {
|
|
17
|
+
const name = pattern.exec(path)?.[1];
|
|
18
|
+
if (name !== undefined)
|
|
19
|
+
return { kind, name };
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
/** Whether `name` is a good name for a folder of `kind`. */
|
|
24
|
+
export const learnedName = (kind, name) => (kind === "skill" ? SKILL_NAME : WORKFLOW_NAME).test(name);
|
|
25
|
+
/** A SKILL.md's or a draft README's front matter: its lines, where it closes (the index of its closing `\n---\n`, in
|
|
26
|
+
* `lf`, the text with LF line ends) and each key's value, a folded or literal block value read as one line. A string
|
|
27
|
+
* is why there is none. */
|
|
28
|
+
function frontOf(text) {
|
|
29
|
+
const lf = text.replace(/\r\n/g, "\n");
|
|
30
|
+
if (!lf.startsWith("---\n"))
|
|
31
|
+
return "it does not start with front matter";
|
|
32
|
+
const end = lf.indexOf("\n---\n", 3);
|
|
33
|
+
if (end < 0)
|
|
34
|
+
return "its front matter is not closed";
|
|
35
|
+
const lines = lf.slice(4, end).split("\n");
|
|
36
|
+
const value = (key) => {
|
|
37
|
+
const at = lines.findIndex((line) => line.startsWith(`${key}:`));
|
|
38
|
+
if (at < 0)
|
|
39
|
+
return undefined;
|
|
40
|
+
const own = lines[at].slice(key.length + 1).trim();
|
|
41
|
+
const more = [];
|
|
42
|
+
for (const line of lines.slice(at + 1))
|
|
43
|
+
if (/^\s+\S/.test(line))
|
|
44
|
+
more.push(line.trim());
|
|
45
|
+
else
|
|
46
|
+
break;
|
|
47
|
+
return (/^[>|][-+]?$/.test(own) ? more.join(" ") : own).replace(/^(["'])(.*)\1$/, "$2").trim();
|
|
48
|
+
};
|
|
49
|
+
return { lf, end, value };
|
|
50
|
+
}
|
|
51
|
+
/** The keys a SKILL.md's or a draft README's front matter sets, in order (each line at its left edge that names one);
|
|
52
|
+
* undefined for a text with no front matter. */
|
|
53
|
+
export function frontKeys(text) {
|
|
54
|
+
const front = frontOf(text);
|
|
55
|
+
if (typeof front === "string")
|
|
56
|
+
return undefined;
|
|
57
|
+
return front.lf.slice(4, front.end).split("\n").flatMap((line) => /^([^\s#:][^:]*):/.exec(line)?.[1] ?? []).map((key) => key.trim());
|
|
58
|
+
}
|
|
59
|
+
/** The front matter keys a learned skill or draft README may hold: what a skill is (its name and when to use it). Claude
|
|
60
|
+
* Code reads directives from more (hooks, allowed-tools, context, agent, model, ...): a hook is a shell command its CLI
|
|
61
|
+
* runs. `status` is the host's (a held one). */
|
|
62
|
+
export const LEARNED_KEYS = ["name", "description"];
|
|
63
|
+
/** `text`, a learned skill's SKILL.md, as a run is given it: front matter with its name and its description alone,
|
|
64
|
+
* written again whatever else its file holds (servedSkill is the one door a learned skill reaches a harness by), then its
|
|
65
|
+
* body as it is. A text with no front matter is as it is. */
|
|
66
|
+
export function servedSkill(text) {
|
|
67
|
+
const front = frontOf(text);
|
|
68
|
+
if (typeof front === "string")
|
|
69
|
+
return text;
|
|
70
|
+
const description = front.value("description") ?? "";
|
|
71
|
+
// Quoted only where YAML would read it as more than one plain line of text.
|
|
72
|
+
const plain = /^[^\s\-?:,[\]{}#&*!|>'"%@`][^\n]*$/.test(description) && !/: |\s#|:$/.test(description);
|
|
73
|
+
const lines = [`name: ${front.value("name") ?? ""}`, `description: ${plain ? description : JSON.stringify(description)}`];
|
|
74
|
+
return `---\n${lines.join("\n")}\n---\n${front.lf.slice(front.end + 5)}`;
|
|
75
|
+
}
|
|
76
|
+
/** Why a `SKILL.md` for the skill `name`, or a draft's `README.md` for the workflow `name`, is out of shape; empty when
|
|
77
|
+
* it is not. Its front matter names the folder's name and a description. */
|
|
78
|
+
export function skillProblems(text, name) {
|
|
79
|
+
const front = frontOf(text);
|
|
80
|
+
if (typeof front === "string")
|
|
81
|
+
return [front];
|
|
82
|
+
const out = [];
|
|
83
|
+
if (front.value("name") !== name)
|
|
84
|
+
out.push(`name is not the folder's name, ${name}`);
|
|
85
|
+
if (!front.value("description"))
|
|
86
|
+
out.push("description is missing or empty");
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
/** A SKILL.md's or a draft README's front matter as a reader shows it: its name, description and status, each absent
|
|
90
|
+
* when it is not there; undefined for a text with no front matter. */
|
|
91
|
+
export function learnedFront(text) {
|
|
92
|
+
const front = frontOf(text);
|
|
93
|
+
if (typeof front === "string")
|
|
94
|
+
return undefined;
|
|
95
|
+
const [name, description, status] = ["name", "description", "status"].map((key) => front.value(key));
|
|
96
|
+
return { ...(name === undefined ? {} : { name }), ...(description === undefined ? {} : { description }), ...(status === undefined ? {} : { status }) };
|
|
97
|
+
}
|
|
98
|
+
/** Whether a SKILL.md or a draft's README.md sets `status`, which only the host does (`held`). */
|
|
99
|
+
export const setsStatus = (text) => {
|
|
100
|
+
const front = frontOf(text);
|
|
101
|
+
return typeof front !== "string" && front.value("status") !== undefined;
|
|
102
|
+
};
|
|
103
|
+
/** A skill or a draft the grader held for its owner's OK: its SKILL.md, or its draft's README.md, says `status:
|
|
104
|
+
* pending`. No run is given a held skill or workflow until a person approves it. */
|
|
105
|
+
export const isHeld = (text) => {
|
|
106
|
+
const front = frontOf(text);
|
|
107
|
+
return typeof front !== "string" && front.value("status") === "pending";
|
|
108
|
+
};
|
|
109
|
+
/** `text`, a SKILL.md or a draft's README.md, as the host merges one the grader held for its owner's OK: `status:
|
|
110
|
+
* pending` last in its front matter, with LF line ends. Throws on a text with no front matter, which the checker never
|
|
111
|
+
* passes. */
|
|
112
|
+
export function held(text) {
|
|
113
|
+
const front = frontOf(text);
|
|
114
|
+
if (typeof front === "string")
|
|
115
|
+
throw new Error(`it cannot be held: ${front}`);
|
|
116
|
+
return `${front.lf.slice(0, front.end)}\nstatus: pending${front.lf.slice(front.end)}`;
|
|
117
|
+
}
|
|
118
|
+
/** `text`, a held SKILL.md or draft README.md, as the host leaves it when its owner approves it: its front matter with
|
|
119
|
+
* no `status` line, so it is given to every later run. Throws on a text with no front matter. */
|
|
120
|
+
export function released(text) {
|
|
121
|
+
const front = frontOf(text);
|
|
122
|
+
if (typeof front === "string")
|
|
123
|
+
throw new Error(`it cannot be approved: ${front}`);
|
|
124
|
+
const kept = front.lf.slice(4, front.end).split("\n").filter((line) => !line.startsWith("status:"));
|
|
125
|
+
return `---\n${kept.join("\n")}${front.lf.slice(front.end)}`;
|
|
126
|
+
}
|
|
127
|
+
/** What a SKILL.md or a draft's README.md says of itself: `pending` while it waits for its owner's OK, `retired` once a
|
|
128
|
+
* person retired it, else `active`. A run is given only an active one. */
|
|
129
|
+
export function learnedStatus(text) {
|
|
130
|
+
const front = frontOf(text);
|
|
131
|
+
const status = typeof front === "string" ? undefined : front.value("status");
|
|
132
|
+
return status === "pending" ? "pending" : status === "retired" ? "retired" : "active";
|
|
133
|
+
}
|
|
134
|
+
/** `text`, a SKILL.md or a draft's README.md, as a person's retire leaves it: `status: retired` last in its front matter
|
|
135
|
+
* (any status line before it dropped), so no later run is given it. Throws on a text with no front matter. */
|
|
136
|
+
export function retiredLearned(text) {
|
|
137
|
+
const front = frontOf(text);
|
|
138
|
+
if (typeof front === "string")
|
|
139
|
+
throw new Error(`it cannot be retired: ${front}`);
|
|
140
|
+
const kept = front.lf.slice(4, front.end).split("\n").filter((line) => !line.startsWith("status:"));
|
|
141
|
+
return `---\n${[...kept, "status: retired"].join("\n")}${front.lf.slice(front.end)}`;
|
|
142
|
+
}
|
|
143
|
+
/** A draft's `README.md` as the host writes it, from the workflow's name and the one-line description its block gives. */
|
|
144
|
+
export const readmeOf = (name, description) => `---\nname: ${name}\ndescription: ${description}\n---\n`;
|
|
145
|
+
/** A workflow block's two files: its `description:` front matter written as the draft's README.md (readmeOf), and the
|
|
146
|
+
* JSON after it as its workflow.json. A block with no front matter, or none that says what the draft is for, gives a
|
|
147
|
+
* README with no description, which the checker refuses; what the JSON holds is the checker's to judge. */
|
|
148
|
+
export function draftFiles(name, block) {
|
|
149
|
+
const front = frontOf(block);
|
|
150
|
+
if (typeof front === "string")
|
|
151
|
+
return { json: block, readme: readmeOf(name, "") };
|
|
152
|
+
const description = (front.value("description") ?? "").replace(/\s+/g, " ").trim();
|
|
153
|
+
return { json: front.lf.slice(front.end + "\n---\n".length), readme: readmeOf(name, description) };
|
|
154
|
+
}
|
|
155
|
+
/** The refusal for a draft that names a tool when the host gave no tool list: the check fails closed. */
|
|
156
|
+
export const NO_TOOL_LIST = "no tool list was given, so a draft that names a tool is refused";
|
|
157
|
+
/** The value at a JSON Pointer (RFC 6901) in `doc`. */
|
|
158
|
+
const at = (doc, pointer) => pointer.split("/").slice(1).reduce((value, key) => value?.[key.replace(/~1/g, "/").replace(/~0/g, "~")], doc);
|
|
159
|
+
/** A draft carries no node that runs code: a `code` node runs in the host's process unless the host isolates it, and a
|
|
160
|
+
* call via shell or executor runs a command. The DSL's inspection lists each node and its pointer. */
|
|
161
|
+
const executableNodes = (dsl, doc) => dsl.inspectWorkflow(doc).nodes.flatMap((node) => {
|
|
162
|
+
if (node.kind === "code")
|
|
163
|
+
return [{ rule: "executable_node", detail: `the code node at ${node.path} runs code in the host's process; a learned draft holds no code node` }];
|
|
164
|
+
const via = node.kind === "call" ? at(doc, node.path)?.via : undefined;
|
|
165
|
+
return via === "shell" || via === "executor" ? [{ rule: "executable_node", detail: `the call node at ${node.path} runs via ${via}; a learned draft never runs a command` }] : [];
|
|
166
|
+
});
|
|
167
|
+
const issuesOf = (dsl, doc, tools) => {
|
|
168
|
+
const valid = dsl.validateWorkflow(doc, { executeCode: false, ...(tools ? { tools } : {}) });
|
|
169
|
+
return valid.ok ? [] : valid.issues;
|
|
170
|
+
};
|
|
171
|
+
/** Why `workflows/<name>/workflow.json` is not a draft the host can run; empty when it is. The DSL's own
|
|
172
|
+
* `validateWorkflow` judges it, with `executeCode: false` so no code it holds is run (a code node is syntax-checked),
|
|
173
|
+
* and with `tools`, so a node that names a tool outside them is its error: a harness's own tool (Bash, exec_command,
|
|
174
|
+
* apply_patch) is never on the list. With no list it fails closed: a draft the DSL refuses only once given an empty
|
|
175
|
+
* list names a tool. */
|
|
176
|
+
export function draftProblems(dsl, text, tools) {
|
|
177
|
+
let doc;
|
|
178
|
+
try {
|
|
179
|
+
doc = JSON.parse(text);
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return [{ rule: "workflow", detail: "it does not parse as JSON" }];
|
|
183
|
+
}
|
|
184
|
+
const issues = issuesOf(dsl, doc, tools);
|
|
185
|
+
if (issues.length)
|
|
186
|
+
return issues.slice(0, 5).map((issue) => ({ rule: "workflow", detail: `the workflow DSL refuses it: ${issue.code} at ${issue.path || "/"}: ${issue.message.slice(0, 200)}` }));
|
|
187
|
+
let out;
|
|
188
|
+
try {
|
|
189
|
+
out = executableNodes(dsl, doc);
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
// The inspection reads the whole document, as validation need not: what it cannot read is refused, never passed.
|
|
193
|
+
return [{ rule: "workflow", detail: `the workflow DSL cannot inspect it: ${error.message.slice(0, 200)}` }];
|
|
194
|
+
}
|
|
195
|
+
if (!tools && issuesOf(dsl, doc, []).length)
|
|
196
|
+
out.push({ rule: "no_tool_list", detail: NO_TOOL_LIST });
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import { type Problem } from "./learn/index.js";
|
|
3
|
+
import { type Shown } from "./learning.js";
|
|
4
|
+
import type { Impact } from "./learning-run.js";
|
|
5
|
+
import type { Run } from "./runs.js";
|
|
6
|
+
type Page<T> = {
|
|
7
|
+
items: T[];
|
|
8
|
+
total: number;
|
|
9
|
+
next_cursor: string | null;
|
|
10
|
+
};
|
|
11
|
+
type NoteView = {
|
|
12
|
+
file: string;
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
type: string;
|
|
16
|
+
status: string;
|
|
17
|
+
origin: string;
|
|
18
|
+
superseded_by: string | null;
|
|
19
|
+
text: string;
|
|
20
|
+
etag: string;
|
|
21
|
+
};
|
|
22
|
+
type Change = {
|
|
23
|
+
by: {
|
|
24
|
+
run: string;
|
|
25
|
+
} | {
|
|
26
|
+
user: true;
|
|
27
|
+
via?: string;
|
|
28
|
+
};
|
|
29
|
+
commit: string;
|
|
30
|
+
at: string;
|
|
31
|
+
reason: string;
|
|
32
|
+
files: string[];
|
|
33
|
+
};
|
|
34
|
+
export type Counts = {
|
|
35
|
+
merged: number;
|
|
36
|
+
dropped: Record<string, number>;
|
|
37
|
+
in_progress: number;
|
|
38
|
+
};
|
|
39
|
+
export { secretsShown, type Shown } from "./learning.js";
|
|
40
|
+
export declare const etagOf: (oid: string) => string;
|
|
41
|
+
/** A skill or a workflow draft as the view lists it: its folder's name, its file (a skill's SKILL.md, a draft's
|
|
42
|
+
* workflow.json, with its `readme`), its description, `pending` while it waits for its owner's OK, the run whose merge
|
|
43
|
+
* last changed it, its size in bytes, and the ETag of the file that says whether it waits (a SKILL.md, a README.md),
|
|
44
|
+
* which an approval names. */
|
|
45
|
+
type LearnedView = {
|
|
46
|
+
name: string;
|
|
47
|
+
file: string;
|
|
48
|
+
readme?: string;
|
|
49
|
+
description: string;
|
|
50
|
+
status: "active" | "pending" | "retired";
|
|
51
|
+
run: string | null;
|
|
52
|
+
bytes: number;
|
|
53
|
+
etag: string;
|
|
54
|
+
};
|
|
55
|
+
/** GET /agents/{id}/learning: main, its index, the first page of its notes and of its log, and how the agent's runs
|
|
56
|
+
* fared and what learning changed for them (`counts`, `impact`: learning-run.ts, from the runs' rows and the learning
|
|
57
|
+
* ledger); an agent with no folder (its learning never on) has an empty one. */
|
|
58
|
+
export declare function agentLearning(data: string, agentId: string, shown: Shown, counts: Counts, impact: Impact): Promise<{
|
|
59
|
+
agent: string;
|
|
60
|
+
main: null;
|
|
61
|
+
index: string;
|
|
62
|
+
notes: Page<never>;
|
|
63
|
+
skills: never[];
|
|
64
|
+
workflows: never[];
|
|
65
|
+
log: Page<never>;
|
|
66
|
+
counts: Counts;
|
|
67
|
+
impact: Impact;
|
|
68
|
+
} | {
|
|
69
|
+
agent: string;
|
|
70
|
+
main: string;
|
|
71
|
+
index: string;
|
|
72
|
+
notes: Page<NoteView>;
|
|
73
|
+
skills: LearnedView[];
|
|
74
|
+
workflows: LearnedView[];
|
|
75
|
+
log: Page<Change>;
|
|
76
|
+
counts: Counts;
|
|
77
|
+
impact: Impact;
|
|
78
|
+
}>;
|
|
79
|
+
/** GET /agents/{id}/learning/notes?cursor=&limit=&status=: a page of the notes, ordered as the view's, from what the
|
|
80
|
+
* commit's first read kept. */
|
|
81
|
+
export declare function learningNotes(data: string, agentId: string, query: URLSearchParams, shown: Shown): Promise<Page<NoteView>>;
|
|
82
|
+
/** GET /agents/{id}/learning/log?cursor=&limit=: a page of the changes on main, newest first, reading only its own. */
|
|
83
|
+
export declare function learningLog(data: string, agentId: string, query: URLSearchParams, shown: Shown): Promise<Page<Change>>;
|
|
84
|
+
/** GET /agents/{id}/learning/files/{file}: the file on main as text, its ETag, and its type (a draft's workflow.json is
|
|
85
|
+
* JSON). */
|
|
86
|
+
export declare function readNote(data: string, agentId: string, raw: string, shown: Shown): Promise<{
|
|
87
|
+
text: string;
|
|
88
|
+
etag: string;
|
|
89
|
+
type?: string;
|
|
90
|
+
}>;
|
|
91
|
+
/** A note (or a skill's or draft's file) as a text answer: its ETag, an explicit type (markdown unless it names one),
|
|
92
|
+
* nosniff, and a sandbox on whatever opens it. */
|
|
93
|
+
export declare function sendNote(res: ServerResponse, status: number, note: {
|
|
94
|
+
text: string;
|
|
95
|
+
etag: string;
|
|
96
|
+
type?: string;
|
|
97
|
+
}, headers?: Record<string, string>): void;
|
|
98
|
+
/** A PUT's body, read to its end (over `max` bytes is 413): the note's whole text, as `text/markdown` or `text/plain`, or
|
|
99
|
+
* as `application/json` `{text}`, the one form the console's page may send under its session (page.ts: a write from
|
|
100
|
+
* the page is JSON from its own origin). A JSON body that is not an object is 400; one whose `text` is missing or not
|
|
101
|
+
* text, or with another field, is 422 by field, as every JSON body here. */
|
|
102
|
+
export declare function noteBody(req: IncomingMessage, max: number): Promise<Buffer>;
|
|
103
|
+
/** PUT /agents/{id}/learning/files/{file} (`body`, the note's whole text), or POST .../retire or .../approve (`approve`;
|
|
104
|
+
* no body), as a person: the precondition, then the checks (a retire's and an approve's, the note's format alone: never
|
|
105
|
+
* its secrets), then one commit on main in the agent's queue, on the folder agentFolder checked: the note, and MEMORY.md
|
|
106
|
+
* rebuilt from main's notes with it, its message `learning: <edited|created|retired|approved> by a person: <file>` and
|
|
107
|
+
* a `Changed-By: user` trailer (and `Approved-Via: console` on an approval), main moved
|
|
108
|
+
* only from the commit it was made on (once more on a main that moved meanwhile), then the checked-out files. A note
|
|
109
|
+
* the checks refuse is never written to git. A retire of a note that is not active, and an edit that changes nothing,
|
|
110
|
+
* commit nothing. `refuse`: the host's secrets. */
|
|
111
|
+
export declare function writeNote(data: string, agentId: string, raw: string, input: {
|
|
112
|
+
ifMatch?: string;
|
|
113
|
+
ifNoneMatch?: string;
|
|
114
|
+
body?: Buffer;
|
|
115
|
+
refuse: readonly string[];
|
|
116
|
+
approve?: boolean;
|
|
117
|
+
}): Promise<{
|
|
118
|
+
status: 200 | 201;
|
|
119
|
+
file: string;
|
|
120
|
+
text: string;
|
|
121
|
+
etag: string;
|
|
122
|
+
}>;
|
|
123
|
+
/** GET /runs/{id}/learning: the run's learning whole, or null for a run that does not learn: its detail cut of the
|
|
124
|
+
* host's secrets now, and the notes it read and learned as its view shows them (learning.ts notesView). */
|
|
125
|
+
export declare function runLearning(run: Run, shown: Shown, secrets: readonly string[]): Promise<{
|
|
126
|
+
seed: string | null;
|
|
127
|
+
merged: string | null;
|
|
128
|
+
pending: {
|
|
129
|
+
file: string;
|
|
130
|
+
name: string;
|
|
131
|
+
}[];
|
|
132
|
+
verdict: {
|
|
133
|
+
merge: boolean;
|
|
134
|
+
reason: string;
|
|
135
|
+
items: {
|
|
136
|
+
why: string;
|
|
137
|
+
question?: string | undefined;
|
|
138
|
+
origin?: "run" | "you" | undefined;
|
|
139
|
+
pending?: boolean | undefined;
|
|
140
|
+
file: string;
|
|
141
|
+
keep: boolean;
|
|
142
|
+
}[];
|
|
143
|
+
} | null;
|
|
144
|
+
problems: Problem[];
|
|
145
|
+
cost_usd: {
|
|
146
|
+
grade: number | null;
|
|
147
|
+
};
|
|
148
|
+
tokens: {
|
|
149
|
+
grade: import("./learning.js").Tokens | null;
|
|
150
|
+
};
|
|
151
|
+
used?: import("./learning.js").NoteUsed[];
|
|
152
|
+
learned?: import("./learning.js").NoteLearned[];
|
|
153
|
+
skills?: import("./learning.js").LearnedFile[];
|
|
154
|
+
workflows?: import("./learning.js").LearnedFile[];
|
|
155
|
+
run: string;
|
|
156
|
+
state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
|
|
157
|
+
reason: "cancelled" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "no_write_tool" | "tool_denied" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "screen" | "screen_down" | "grader" | "grade_failed" | null;
|
|
158
|
+
detail: string | null;
|
|
159
|
+
at: string;
|
|
160
|
+
} | null>;
|
|
161
|
+
/** GET /runs/{id}/learning/diff: once merged, its merge commit against its parent, as git diffs them; before, its proposal
|
|
162
|
+
* (new notes only) against its seed; a run that proposed nothing, no file. A file's patch is withheld when too large, or
|
|
163
|
+
* when it holds one of the host's secrets now. */
|
|
164
|
+
export declare function runDiff(data: string, run: Run, shown: Shown): Promise<{
|
|
165
|
+
base: string;
|
|
166
|
+
head: string;
|
|
167
|
+
files: ({
|
|
168
|
+
path: string;
|
|
169
|
+
status: string;
|
|
170
|
+
withheld: string;
|
|
171
|
+
patch?: undefined;
|
|
172
|
+
} | {
|
|
173
|
+
path: string;
|
|
174
|
+
status: string;
|
|
175
|
+
patch: string;
|
|
176
|
+
withheld?: undefined;
|
|
177
|
+
})[];
|
|
178
|
+
} | {
|
|
179
|
+
base: string;
|
|
180
|
+
head: null;
|
|
181
|
+
files: ({
|
|
182
|
+
path: string;
|
|
183
|
+
status: string;
|
|
184
|
+
withheld: string;
|
|
185
|
+
patch?: undefined;
|
|
186
|
+
} | {
|
|
187
|
+
path: string;
|
|
188
|
+
status: string;
|
|
189
|
+
patch: string;
|
|
190
|
+
withheld?: undefined;
|
|
191
|
+
})[];
|
|
192
|
+
} | {
|
|
193
|
+
base: string | null;
|
|
194
|
+
head: null;
|
|
195
|
+
files: never[];
|
|
196
|
+
}>;
|