@parcha/agentrun-serve 0.1.0-beta.29 → 0.1.0-beta.31
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 +238 -0
- package/README.md +739 -116
- package/dist/adapters.d.ts +35 -6
- package/dist/adapters.js +152 -26
- package/dist/agents.d.ts +18 -7
- package/dist/agents.js +19 -10
- package/dist/app.js +101 -26
- package/dist/background.d.ts +29 -0
- package/dist/background.js +397 -0
- package/dist/box-egress-vm.d.ts +125 -0
- package/dist/box-egress-vm.js +350 -0
- package/dist/box-egress.d.ts +99 -0
- package/dist/box-egress.js +259 -0
- package/dist/box-image.d.ts +1 -1
- package/dist/box-image.js +9 -7
- package/dist/box-relay-vm.d.ts +84 -0
- package/dist/box-relay-vm.js +410 -0
- package/dist/box-relay.d.ts +8 -5
- package/dist/box-relay.js +14 -9
- package/dist/boxes.d.ts +28 -5
- package/dist/boxes.js +44 -18
- package/dist/browser-cost.d.ts +41 -0
- package/dist/browser-cost.js +158 -0
- package/dist/cap.d.ts +130 -21
- package/dist/cap.js +339 -67
- package/dist/cli.js +30 -4
- package/dist/coding-tools.d.ts +7 -3
- package/dist/coding-tools.js +16 -10
- package/dist/console/THIRD-PARTY-NOTICES.txt +580 -0
- package/dist/console/assets/index-CnJBf7Lc.js +486 -0
- package/dist/console/assets/index-DUHbWcIP.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/decision-rows.d.ts +11 -3
- package/dist/decision-rows.js +18 -11
- package/dist/decisions.d.ts +3 -3
- package/dist/decisions.js +4 -3
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +5 -2
- package/dist/files.d.ts +9 -1
- package/dist/files.js +10 -2
- package/dist/grade.d.ts +11 -11
- package/dist/grade.js +43 -55
- package/dist/graph-served.d.ts +23 -0
- package/dist/graph-served.js +75 -0
- package/dist/graph-view.d.ts +7 -5
- package/dist/graph-view.js +10 -3
- package/dist/harness-app.d.ts +4 -2
- package/dist/harness-app.js +110 -19
- package/dist/harness-opencode/adapter.d.ts +45 -0
- package/dist/harness-opencode/adapter.js +272 -0
- package/dist/harness-opencode/binary.d.ts +18 -0
- package/dist/harness-opencode/binary.js +87 -0
- package/dist/harness-opencode/config.d.ts +24 -0
- package/dist/harness-opencode/config.js +61 -0
- package/dist/harness-opencode/harness.d.ts +77 -0
- package/dist/harness-opencode/harness.js +620 -0
- package/dist/harness-opencode/host/mcp.d.ts +40 -0
- package/dist/harness-opencode/host/mcp.js +208 -0
- package/dist/harness-opencode/host/policy.d.ts +71 -0
- package/dist/harness-opencode/host/policy.js +419 -0
- package/dist/harness-opencode/host/server.d.ts +55 -0
- package/dist/harness-opencode/host/server.js +165 -0
- package/dist/harness-opencode/index.d.ts +9 -0
- package/dist/harness-opencode/index.js +6 -0
- package/dist/harness-opencode/verify.d.ts +32 -0
- package/dist/harness-opencode/verify.js +75 -0
- package/dist/harness-opencode/versions.d.ts +33 -0
- package/dist/harness-opencode/versions.js +64 -0
- package/dist/harness.d.ts +4 -1
- package/dist/harness.js +5 -2
- package/dist/host-check.d.ts +12 -0
- package/dist/host-check.js +34 -0
- package/dist/host-tools.d.ts +12 -2
- package/dist/host-tools.js +26 -12
- package/dist/host.js +6 -2
- package/dist/hosted-search.js +5 -1
- package/dist/import.d.ts +2 -2
- package/dist/import.js +4 -3
- package/dist/key-check.d.ts +3 -2
- package/dist/key-check.js +7 -3
- package/dist/key-refusal.js +8 -4
- package/dist/key-words.d.ts +37 -0
- package/dist/key-words.js +40 -0
- package/dist/learn/check.d.ts +10 -1
- package/dist/learn/check.js +19 -1
- package/dist/learn/grade.d.ts +6 -2
- package/dist/learn/grade.js +28 -14
- package/dist/learn/index.d.ts +3 -3
- package/dist/learn/index.js +3 -3
- package/dist/learn/notes.js +2 -1
- package/dist/learn/reflect.d.ts +2 -2
- package/dist/learn/reflect.js +53 -5
- package/dist/learn/secrets.js +28 -8
- package/dist/learn/skills.d.ts +19 -4
- package/dist/learn/skills.js +95 -6
- package/dist/learned-workflow.d.ts +59 -0
- package/dist/learned-workflow.js +191 -0
- package/dist/learning-routes.d.ts +30 -1
- package/dist/learning-routes.js +173 -19
- package/dist/learning-run.d.ts +8 -6
- package/dist/learning-run.js +70 -27
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +34 -13
- package/dist/learning.d.ts +52 -3
- package/dist/learning.js +204 -4
- package/dist/mcp-gateway.d.ts +96 -0
- package/dist/mcp-gateway.js +408 -0
- package/dist/mcp-meta.d.ts +17 -0
- package/dist/mcp-meta.js +38 -0
- package/dist/mcp-servers.d.ts +33 -9
- package/dist/mcp-servers.js +58 -10
- package/dist/mcp.js +5 -5
- package/dist/model.d.ts +13 -11
- package/dist/model.js +11 -10
- package/dist/openapi/agentrun-v2.openapi.json +1 -0
- package/dist/openapi.js +407 -54
- package/dist/page.d.ts +2 -0
- package/dist/page.js +3 -0
- package/dist/paid-calls.d.ts +5 -1
- package/dist/paid-calls.js +1 -1
- package/dist/pause.d.ts +2 -0
- package/dist/place.d.ts +29 -5
- package/dist/place.js +51 -11
- package/dist/print.d.ts +7 -0
- package/dist/print.js +13 -0
- package/dist/propose.d.ts +2 -0
- package/dist/propose.js +38 -8
- package/dist/request-start.d.ts +12 -4
- package/dist/request-start.js +139 -15
- package/dist/run-box.d.ts +56 -4
- package/dist/run-box.js +183 -23
- package/dist/runnable.d.ts +13 -3
- package/dist/runnable.js +63 -6
- package/dist/runs.d.ts +266 -37
- package/dist/runs.js +884 -90
- package/dist/secrets.d.ts +27 -0
- package/dist/secrets.js +38 -2
- package/dist/server.d.ts +141 -36
- package/dist/server.js +562 -118
- package/dist/sign-ins.d.ts +99 -0
- package/dist/sign-ins.js +288 -0
- package/dist/skills.d.ts +16 -4
- package/dist/skills.js +35 -7
- package/dist/stats.d.ts +7 -2
- package/dist/stats.js +28 -7
- package/dist/tool-gate.d.ts +281 -0
- package/dist/tool-gate.js +585 -0
- package/dist/tool-keys.d.ts +48 -11
- package/dist/tool-keys.js +46 -8
- package/dist/tool-plane.d.ts +116 -27
- package/dist/tool-plane.js +232 -50
- package/dist/tools.d.ts +69 -14
- package/dist/tools.js +148 -26
- package/dist/trigger-secrets.d.ts +32 -0
- package/dist/trigger-secrets.js +143 -0
- package/dist/triggers.d.ts +439 -0
- package/dist/triggers.js +863 -0
- package/dist/turn-end.d.ts +3 -2
- package/dist/turn-end.js +3 -2
- package/dist/usage-lines.d.ts +26 -0
- package/dist/usage-lines.js +28 -0
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +11 -2
- package/dist/web-fetch.js +3 -3
- package/dist/webhooks.d.ts +11 -4
- package/dist/webhooks.js +17 -1
- package/launcher/agentrun-serve +1 -1
- package/package.json +16 -14
- package/dist/console/assets/index-BN7oVcO4.js +0 -445
- package/dist/console/assets/index-By-jkqki.css +0 -1
package/dist/learning.js
CHANGED
|
@@ -33,7 +33,7 @@ import { constants, existsSync } from "node:fs";
|
|
|
33
33
|
import { lstat, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
34
34
|
import { dirname, join, posix, relative } from "node:path";
|
|
35
35
|
import { SKILL_BYTES } from "@parcha/agentrun-kernel";
|
|
36
|
-
import { INDEX_FILE, loadedIndex, NOTE_FILE, parseNoteFile, redactSecrets, secretShapes, servedSkill, SKILLS_DIR, valueMatcher } from "./learn/index.js";
|
|
36
|
+
import { INDEX_FILE, loadedIndex, NOTE_FILE, parseNoteFile, redactSecrets, secretShapes, servedSkill, SKILLS_DIR, valueMatcher, WORKFLOW_NAME, WORKFLOWS_DIR } from "./learn/index.js";
|
|
37
37
|
import { homeOf, serialBy, writeDurable } from "./files.js";
|
|
38
38
|
import { DETAIL_MAX, LIST_DETAIL, short, wordsOf } from "./learning-words.js";
|
|
39
39
|
import { isObject } from "./validate.js";
|
|
@@ -139,6 +139,69 @@ export const LEARNED_DIR = ".learning";
|
|
|
139
139
|
/** What the run's end-of-run turn answered, and what the user said in the run, kept in the run's directory as the run
|
|
140
140
|
* settles (learning-run.ts beforeSettle), where the host alone reads it: what propose.ts checks. */
|
|
141
141
|
export const LEARNING_TURN = "learning-turn.json";
|
|
142
|
+
/** Where a run keeps the learned workflows its pin names, whole: in the run's directory, beside its pin, never in its
|
|
143
|
+
* work, so nothing the run does changes what its `learned_workflow` tool runs. */
|
|
144
|
+
export const LEARNED_WORKFLOWS_FILE = "learned-workflows.json";
|
|
145
|
+
/** The most bytes the `learned_workflow` tool's description gives its workflows, each one's line (workflowLine)
|
|
146
|
+
* together: every harness sends the description with each request, so it never grows with what an agent learned. */
|
|
147
|
+
export const LEARNED_WORKFLOWS_BUDGET = 8 * 1024;
|
|
148
|
+
/** A learned workflow's line in the `learned_workflow` tool's description: its name, and what its README says it does. */
|
|
149
|
+
export const workflowLine = ({ name, description, workflow }) => [`- ${name}: ${description || "(no description)"}`, ...inputLine(workflow)].join("\n");
|
|
150
|
+
/** The most of a field's description a workflow's input line carries. */
|
|
151
|
+
const FIELD_DESCRIPTION = 60;
|
|
152
|
+
/** A workflow's input as its line in learned_workflow's description says it: its input schema, compact (inputSchema), on
|
|
153
|
+
* a line of its own, so a call names the fields the workflow takes; none for a workflow whose input names no schema. */
|
|
154
|
+
function inputLine(workflow) {
|
|
155
|
+
let doc;
|
|
156
|
+
try {
|
|
157
|
+
doc = workflow ? JSON.parse(workflow) : undefined;
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
const id = doc?.input?.schemaId;
|
|
163
|
+
const schema = typeof id === "string" ? doc?.schemas?.[id] : undefined;
|
|
164
|
+
if (!schema)
|
|
165
|
+
return [];
|
|
166
|
+
const shown = compactSchema(schema, doc?.schemas ?? {}, 0, definitionsOf(schema));
|
|
167
|
+
return [` input: ${shown}${shown.includes("*") ? " (* required)" : ""}`];
|
|
168
|
+
}
|
|
169
|
+
/** A schema's own inline definitions (`definitions`, `$defs`), which its `#/definitions/` references read first. */
|
|
170
|
+
const definitionsOf = (schema) => {
|
|
171
|
+
const s = schema && typeof schema === "object" ? schema : {};
|
|
172
|
+
return { ...(s.$defs ?? {}), ...(s.definitions ?? {}) };
|
|
173
|
+
};
|
|
174
|
+
/** A JSON Schema in one line: an object's fields as `name type`, a required one marked `*`, each with its description cut
|
|
175
|
+
* short; an array as `array of <items>`; a reference to another of the workflow's schemas followed, two levels deep. */
|
|
176
|
+
function compactSchema(schema, schemas, depth = 0, defs = {}) {
|
|
177
|
+
const s = schema && typeof schema === "object" ? schema : undefined;
|
|
178
|
+
if (!s)
|
|
179
|
+
return "any";
|
|
180
|
+
if (typeof s.$ref === "string") {
|
|
181
|
+
// As the DSL resolves it: `#/definitions/` and `#/$defs/` in the schema's own inline definitions first, then the
|
|
182
|
+
// workflow's schemas by that name.
|
|
183
|
+
const inline = /^#\/(?:definitions|\$defs)\//.test(s.$ref);
|
|
184
|
+
const name = s.$ref.replace(/^#\/(?:schemas|definitions|\$defs)\//, "");
|
|
185
|
+
const target = (inline ? defs[name] : undefined) ?? schemas[name];
|
|
186
|
+
return depth > 2 || !target ? name : compactSchema(target, schemas, depth + 1, defs);
|
|
187
|
+
}
|
|
188
|
+
if (s.properties && typeof s.properties === "object") {
|
|
189
|
+
if (depth > 2)
|
|
190
|
+
return "object";
|
|
191
|
+
const required = new Set(Array.isArray(s.required) ? s.required : []);
|
|
192
|
+
const fields = Object.entries(s.properties).map(([key, value]) => {
|
|
193
|
+
const said = value && typeof value === "object" ? value.description : undefined;
|
|
194
|
+
const words = typeof said === "string" && said.trim() ? ` "${said.trim().length > FIELD_DESCRIPTION ? `${said.trim().slice(0, FIELD_DESCRIPTION - 1)}…` : said.trim()}"` : "";
|
|
195
|
+
return `${key}${required.has(key) ? "*" : ""} ${compactSchema(value, schemas, depth + 1, defs)}${words}`;
|
|
196
|
+
});
|
|
197
|
+
return `{${fields.join(", ")}}`;
|
|
198
|
+
}
|
|
199
|
+
if (s.type === "array")
|
|
200
|
+
return `array of ${compactSchema(s.items, schemas, depth + 1, defs)}`;
|
|
201
|
+
if (Array.isArray(s.enum))
|
|
202
|
+
return s.enum.map((value) => JSON.stringify(value)).join("|");
|
|
203
|
+
return typeof s.type === "string" ? s.type : Array.isArray(s.type) ? s.type.join("|") : "any";
|
|
204
|
+
}
|
|
142
205
|
/** The most bytes of learned skills one run gets, every file of each together. They get no more than what the
|
|
143
206
|
* revision's own skills leave of the adapters' cap on a run's skills in all (SKILL_BYTES): over that cap an adapter
|
|
144
207
|
* refuses the whole set, and every skill, the revision's too, would be inlined in the prompt (skills.ts splitSkills). */
|
|
@@ -467,6 +530,100 @@ export async function readSkills(cwd, repo, sha) {
|
|
|
467
530
|
}
|
|
468
531
|
return { skills, skipped };
|
|
469
532
|
}
|
|
533
|
+
/** The workflows commit `sha` holds under WORKFLOWS_DIR, read with plumbing, by name: each a folder with a workflow.json
|
|
534
|
+
* and a README.md, each a regular file (mode 100644) of at most FILE_CAP bytes in UTF-8; else named in `skipped`. Only an
|
|
535
|
+
* active one is a run's, by the rule a skill is (readSkills): its README.md sets no status, or `active`; one held for
|
|
536
|
+
* its owner's OK, or retired, is left out. A symbolic link or a submodule under WORKFLOWS_DIR throws. */
|
|
537
|
+
export async function readWorkflows(cwd, repo, sha) {
|
|
538
|
+
const listed = (await git(cwd, repo, ["ls-tree", "-r", "-t", "-l", "-z", "--full-tree", sha, "--", WORKFLOWS_DIR])).toString("utf8").split("\0").filter(Boolean);
|
|
539
|
+
const found = new Map();
|
|
540
|
+
const refused = new Set();
|
|
541
|
+
const skipped = [];
|
|
542
|
+
for (const entry of listed) {
|
|
543
|
+
const tab = entry.indexOf("\t");
|
|
544
|
+
const [mode, type, oid, size] = entry.slice(0, tab).split(/\s+/);
|
|
545
|
+
const path = entry.slice(tab + 1);
|
|
546
|
+
if (path !== WORKFLOWS_DIR && !path.startsWith(`${WORKFLOWS_DIR}/`))
|
|
547
|
+
continue;
|
|
548
|
+
if (mode === "120000" || mode === "160000")
|
|
549
|
+
throw new Error(`the learning folder's ${path} is a ${mode === "120000" ? "symbolic link" : "submodule"}, and the host never reads one for a run`);
|
|
550
|
+
if (type === "tree")
|
|
551
|
+
continue;
|
|
552
|
+
const [name = "", file = "", ...more] = path.slice(WORKFLOWS_DIR.length + 1).split("/");
|
|
553
|
+
const why = !WORKFLOW_NAME.test(name) || more.length || (file !== "workflow.json" && file !== "README.md") ? "not a workflow's workflow.json or README.md" : mode !== "100644" || type !== "blob" || !oid ? `mode ${mode}` : Number(size) > FILE_CAP ? `over ${FILE_CAP} bytes` : undefined;
|
|
554
|
+
if (why) {
|
|
555
|
+
refused.add(name);
|
|
556
|
+
skipped.push(`${path} (${why})`);
|
|
557
|
+
}
|
|
558
|
+
else
|
|
559
|
+
(found.get(name) ?? found.set(name, {}).get(name))[file] = oid;
|
|
560
|
+
}
|
|
561
|
+
const workflows = [];
|
|
562
|
+
for (const [name, oids] of [...found].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) {
|
|
563
|
+
if (refused.has(name))
|
|
564
|
+
continue;
|
|
565
|
+
if (!oids["workflow.json"] || !oids["README.md"]) {
|
|
566
|
+
skipped.push(`${WORKFLOWS_DIR}/${name} (no ${oids["workflow.json"] ? "README.md" : "workflow.json"})`);
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
const [json, readme] = await readBlobs(cwd, repo, [oids["workflow.json"], oids["README.md"]]);
|
|
570
|
+
let texts;
|
|
571
|
+
try {
|
|
572
|
+
texts = [utf8.decode(json), utf8.decode(readme)];
|
|
573
|
+
}
|
|
574
|
+
catch {
|
|
575
|
+
skipped.push(`${WORKFLOWS_DIR}/${name} (not UTF-8)`);
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
// Its README read one way only, or not at all: one whose front matter is not closed, or holds a line that is no key
|
|
579
|
+
// at its left edge, could hold a status a reader other than this one sees, so it is never read as active.
|
|
580
|
+
const front = readmeFront(texts[1]);
|
|
581
|
+
if (!front) {
|
|
582
|
+
skipped.push(`${WORKFLOWS_DIR}/${name} (its README.md's front matter does not read one way)`);
|
|
583
|
+
continue;
|
|
584
|
+
}
|
|
585
|
+
const status = front.get("status");
|
|
586
|
+
if (status !== undefined && status !== "active")
|
|
587
|
+
continue;
|
|
588
|
+
workflows.push({ name, description: front.get("description") ?? "", workflow: texts[0] });
|
|
589
|
+
}
|
|
590
|
+
return { workflows, skipped };
|
|
591
|
+
}
|
|
592
|
+
/** A learned workflow README's front matter, each key to its value (quotes dropped; a `>` or `|` value's indented lines
|
|
593
|
+
* joined by spaces), or undefined when it does not read one way: no front matter, none closed (`---` on a line of its
|
|
594
|
+
* own, the last line or not), a line that is neither a key at its left edge, a comment, blank, nor a line of a `>` or
|
|
595
|
+
* `|` value, or a key set twice. */
|
|
596
|
+
export function readmeFront(text) {
|
|
597
|
+
const lf = text.replace(/\r\n/g, "\n");
|
|
598
|
+
if (!lf.startsWith("---\n"))
|
|
599
|
+
return undefined;
|
|
600
|
+
const close = /\n---(?:\n|$)/.exec(lf.slice(3));
|
|
601
|
+
if (!close)
|
|
602
|
+
return undefined;
|
|
603
|
+
const front = new Map();
|
|
604
|
+
let block;
|
|
605
|
+
for (const line of lf.slice(4, 3 + close.index).split("\n")) {
|
|
606
|
+
if (block !== undefined && (/^\s+\S/.test(line) || line.trim() === "")) {
|
|
607
|
+
if (line.trim())
|
|
608
|
+
front.set(block, `${front.get(block)} ${line.trim()}`.trim());
|
|
609
|
+
continue;
|
|
610
|
+
}
|
|
611
|
+
block = undefined;
|
|
612
|
+
if (line.trim() === "" || line.startsWith("#"))
|
|
613
|
+
continue;
|
|
614
|
+
const pair = /^([A-Za-z_][\w-]*):(?:\s+(.*))?$/.exec(line);
|
|
615
|
+
if (!pair || front.has(pair[1]))
|
|
616
|
+
return undefined;
|
|
617
|
+
const value = (pair[2] ?? "").trim();
|
|
618
|
+
if (/^[>|][-+]?$/.test(value)) {
|
|
619
|
+
block = pair[1];
|
|
620
|
+
front.set(block, "");
|
|
621
|
+
}
|
|
622
|
+
else
|
|
623
|
+
front.set(pair[1], value.replace(/^(["'])(.*)\1$/, "$2"));
|
|
624
|
+
}
|
|
625
|
+
return front;
|
|
626
|
+
}
|
|
470
627
|
/** Each file's place in main's first-parent log from `sha`, by the newest commit that changed it: 0 for those the newest
|
|
471
628
|
* commit changed, and so on, so two changes in one second keep their order. A run's notes (seedOf) and a person's view
|
|
472
629
|
* of them (learning-routes.ts) are in this order, the one changed last first. */
|
|
@@ -507,6 +664,9 @@ export function seedOf(data, agentId) {
|
|
|
507
664
|
const placeOf = (skill) => skillPlace.get(skill.name) ?? Number.POSITIVE_INFINITY;
|
|
508
665
|
seed.skills = [...skills].sort((a, b) => placeOf(a) - placeOf(b) || 0);
|
|
509
666
|
seed.skipped.push(...skipped);
|
|
667
|
+
const flows = await readWorkflows(home, repo, sha);
|
|
668
|
+
seed.workflows = flows.workflows;
|
|
669
|
+
seed.skipped.push(...flows.skipped);
|
|
510
670
|
return seed;
|
|
511
671
|
});
|
|
512
672
|
}
|
|
@@ -707,7 +867,34 @@ export async function pinSeed(runDir, work, seed, options) {
|
|
|
707
867
|
const section = learnedOf(seed, options);
|
|
708
868
|
const { taken, left } = await chooseSkills(work, seed, options.own ?? [], options.shown);
|
|
709
869
|
const skills = taken.flatMap(({ name, files = {} }) => Object.keys(files).sort().map((path) => `${name}/${path}`));
|
|
710
|
-
|
|
870
|
+
// The learned workflows the run may run, whole, in its directory before the pin names them (a reopen keeps them):
|
|
871
|
+
// by name, each while its line fits what is left of the tool's description budget; one that does not, or holds a
|
|
872
|
+
// secret, is left out, and the pin names it.
|
|
873
|
+
const flows = [];
|
|
874
|
+
const flowsLeft = [];
|
|
875
|
+
let room = LEARNED_WORKFLOWS_BUDGET;
|
|
876
|
+
for (const flow of seed.workflows ?? []) {
|
|
877
|
+
// None, when the run is offered none (learnedWorkflowsOff): each is named, but for a name that is itself a secret.
|
|
878
|
+
if (options.workflowsOff !== undefined) {
|
|
879
|
+
if (!options.shown.holds(flow.name))
|
|
880
|
+
flowsLeft.push(flow.name);
|
|
881
|
+
continue;
|
|
882
|
+
}
|
|
883
|
+
if (options.shown.holds(flow.workflow) || options.shown.holds(flow.description) || options.shown.holds(flow.name)) {
|
|
884
|
+
// Named, but for a name that is itself a secret.
|
|
885
|
+
if (!options.shown.holds(flow.name))
|
|
886
|
+
flowsLeft.push(flow.name);
|
|
887
|
+
continue;
|
|
888
|
+
}
|
|
889
|
+
const bytes = Buffer.byteLength(`${workflowLine(flow)}\n`, "utf8");
|
|
890
|
+
if (bytes > room)
|
|
891
|
+
flowsLeft.push(flow.name);
|
|
892
|
+
else
|
|
893
|
+
(room -= bytes), flows.push(flow);
|
|
894
|
+
}
|
|
895
|
+
if (flows.length)
|
|
896
|
+
await writeDurable(join(runDir, LEARNED_WORKFLOWS_FILE), `${JSON.stringify(flows)}\n`);
|
|
897
|
+
const pin = { seed: seed.sha, ...(section ? { section } : {}), ...(skills.length ? { skills } : {}), ...(left.length ? { skills_left_out: left } : {}), ...(flows.length ? { workflows: flows.map(({ name }) => name) } : {}), ...(options.workflowsOff !== undefined && flowsLeft.length ? { workflows_off: options.workflowsOff } : {}), ...(flowsLeft.length ? { workflows_left_out: flowsLeft } : {}) };
|
|
711
898
|
// The pin names the skills before they are laid: a server that goes down while they are takes them back (dropSeed).
|
|
712
899
|
await writeDurable(pinFile, `${JSON.stringify(pin)}\n`);
|
|
713
900
|
await laySkills(work, taken, made);
|
|
@@ -718,6 +905,7 @@ export async function pinSeed(runDir, work, seed, options) {
|
|
|
718
905
|
// writeDurable renames the pin into place before it syncs the run's directory, so a failure there leaves the pin
|
|
719
906
|
// behind: it goes too, or the run's instructions would still say what it learned, of notes it has no copy of.
|
|
720
907
|
await rm(pinFile, { force: true }).catch(() => undefined);
|
|
908
|
+
await rm(join(runDir, LEARNED_WORKFLOWS_FILE), { force: true }).catch(() => undefined);
|
|
721
909
|
await rm(dir, { recursive: true, force: true }).catch(() => undefined);
|
|
722
910
|
await takeSkills(work, made).catch(() => undefined);
|
|
723
911
|
throw error;
|
|
@@ -763,7 +951,7 @@ export async function readPin(runDir) {
|
|
|
763
951
|
const pin = JSON.parse(text);
|
|
764
952
|
const names = (value, shape) => value === undefined || (Array.isArray(value) && value.every((entry) => typeof entry === "string" && shape(entry)));
|
|
765
953
|
const skillFile = (entry) => SKILL_NAME.test(entry.split("/")[0]) && SKILL_FILE_PATH.test(entry.slice(entry.indexOf("/") + 1)) && entry.includes("/");
|
|
766
|
-
if (!isObject(pin) || typeof pin.seed !== "string" || (pin.section !== undefined && typeof pin.section !== "string") || (pin.learned !== undefined && typeof pin.learned !== "string") || !names(pin.skills, skillFile) || !names(pin.skills_left_out, () => true))
|
|
954
|
+
if (!isObject(pin) || typeof pin.seed !== "string" || (pin.section !== undefined && typeof pin.section !== "string") || (pin.learned !== undefined && typeof pin.learned !== "string") || !names(pin.skills, skillFile) || !names(pin.skills_left_out, () => true) || !names(pin.workflows, (entry) => WORKFLOW_NAME.test(entry)) || !names(pin.workflows_left_out, (entry) => WORKFLOW_NAME.test(entry)) || (pin.workflows_off !== undefined && typeof pin.workflows_off !== "string"))
|
|
767
955
|
throw new Error(`the run's ${LEARNING_PIN} is not a learning pin`);
|
|
768
956
|
return pin;
|
|
769
957
|
}
|
|
@@ -771,7 +959,7 @@ export async function readPin(runDir) {
|
|
|
771
959
|
export const LEARNED_HEADING = "# Learned";
|
|
772
960
|
/** What every run that learns is told first under it, notes or none: a run not told it learns saves what the person
|
|
773
961
|
* asks it to remember in a file, or says it cannot, and that is never kept. */
|
|
774
|
-
const LEARNS = "You learn from your runs. When this run ends you are asked what to keep for later runs, anything the person asked you to remember included, and only your answer then is kept: a file you write is not. So when the person asks you to remember something, don't put it in a file or say you can't: tell them you will keep it for later runs. A secret (a password, key or token) is never kept, so say so instead.";
|
|
962
|
+
const LEARNS = "You learn from your runs. When this run ends you are asked what to keep for later runs, anything the person asked you to remember included, and only your answer then is kept: a file you write is not. So when the person asks you to remember something, don't put it in a file or say you can't: tell them you will keep it for later runs, in one short sentence at the start of your reply, never after a closing line or sign-off they asked you to end with. A secret (a password, key or token) is never kept, so say so instead.";
|
|
775
963
|
/** What a run that starts with no note is told in place of what it learned. */
|
|
776
964
|
const NOTHING_YET = "Nothing learned yet.";
|
|
777
965
|
/** A run's instructions, with `# Learned` after them when its pin in `runDir` says it learns: that it learns, then what
|
|
@@ -799,3 +987,15 @@ export async function withLearned(runDir, work, instructions, own = []) {
|
|
|
799
987
|
skills: [...own, ...learned.filter((path) => whole.has(path.split("/")[0]))],
|
|
800
988
|
};
|
|
801
989
|
}
|
|
990
|
+
/** The learned workflows a run's pin names, as its directory keeps them (LEARNED_WORKFLOWS_FILE): none when the pin
|
|
991
|
+
* names none. A file that is not the list the pin names throws. */
|
|
992
|
+
export async function pinnedWorkflows(runDir, pin) {
|
|
993
|
+
const names = pin?.workflows ?? [];
|
|
994
|
+
if (!names.length)
|
|
995
|
+
return [];
|
|
996
|
+
const kept = JSON.parse(await readFile(join(runDir, LEARNED_WORKFLOWS_FILE), "utf8"));
|
|
997
|
+
const ok = (entry) => isObject(entry) && typeof entry.name === "string" && typeof entry.description === "string" && typeof entry.workflow === "string";
|
|
998
|
+
if (!Array.isArray(kept) || !kept.every(ok) || kept.map(({ name }) => name).join("\n") !== names.join("\n"))
|
|
999
|
+
throw new Error(`the run's ${LEARNED_WORKFLOWS_FILE} is not the workflows its pin names`);
|
|
1000
|
+
return kept;
|
|
1001
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type ToolRegistration } from "@earendil-works/pi-durable";
|
|
2
|
+
import type { McpCallResult, McpTool, SessionMcp } from "@parcha/agentrun-kernel";
|
|
3
|
+
import { type Gate, type Park } from "./tool-gate.js";
|
|
4
|
+
/** The run's pinned MCP tools, in its directory: written once, at its first launch. */
|
|
5
|
+
export declare const MCP_PIN = "mcp-tools.json";
|
|
6
|
+
/** A catalog name of an MCP tool: `mcp:<server>/<tool>`. A server name has no `_`, so `mcp__<server>__<tool>` splits one way. */
|
|
7
|
+
export declare const MCP_NAME: RegExp;
|
|
8
|
+
/** The longest answer the model reads whole; the rest is filed in the run's work/ (monid's rule). */
|
|
9
|
+
export declare const MCP_CLIP = 60000;
|
|
10
|
+
/** The most of one upstream answer read. */
|
|
11
|
+
export declare const MAX_RESPONSE: number;
|
|
12
|
+
/** The longest one upstream call may take, and its first connection. */
|
|
13
|
+
export declare const CALL_MS = 120000;
|
|
14
|
+
export declare const CONNECT_MS = 30000;
|
|
15
|
+
/** Each pinned server: its URL then, the granted tools as it listed them, and the prices its owner declared for them. */
|
|
16
|
+
export type McpPin = Record<string, {
|
|
17
|
+
url: string;
|
|
18
|
+
tools: McpTool[];
|
|
19
|
+
prices?: Record<string, number>;
|
|
20
|
+
}>;
|
|
21
|
+
/** The pipe's entry: each granted server's URL now, and its credential's headers when that URL is the pinned one. */
|
|
22
|
+
export type McpCredentials = Record<string, {
|
|
23
|
+
url: string;
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
}>;
|
|
26
|
+
/** The servers saved on this server (mcp-servers.ts), as a launch reads them. */
|
|
27
|
+
export interface McpServerSource {
|
|
28
|
+
server(name: string): {
|
|
29
|
+
url: string;
|
|
30
|
+
tools: readonly McpTool[];
|
|
31
|
+
prices?: Readonly<Record<string, number>>;
|
|
32
|
+
} | undefined;
|
|
33
|
+
/** The server's credential, opened now: its headers, or undefined when it has none or it does not open. */
|
|
34
|
+
headers(name: string): Record<string, string> | undefined;
|
|
35
|
+
}
|
|
36
|
+
/** `mcp:<server>/<tool>` read, or undefined for a name that is not one. */
|
|
37
|
+
export declare const mcpNameOf: (name: string) => {
|
|
38
|
+
server: string;
|
|
39
|
+
tool: string;
|
|
40
|
+
} | undefined;
|
|
41
|
+
/** The most schema nodes, and the deepest nesting, a tool's declarations are checked through: past either the tool is
|
|
42
|
+
* refused, never walked further. */
|
|
43
|
+
export declare const HEADER_SCAN_NODES = 10000;
|
|
44
|
+
export declare const HEADER_SCAN_DEPTH = 64;
|
|
45
|
+
/** Why a tool's `x-mcp-header` declarations (SEP-2243, the 2026-07-28 revision) cannot be mirrored into `Mcp-Param-*`
|
|
46
|
+
* headers, by the rules the SDK client applies when it lists tools: only on a property reached through `properties`
|
|
47
|
+
* alone, a non-empty RFC 9110 token, on a string, integer or boolean, unique without regard to case. Undefined when they
|
|
48
|
+
* can, or there are none. The SDK does the mirroring itself (callTool's `toolDefinition`), but it exports no form of this
|
|
49
|
+
* check, which it runs only inside its own `listTools()`. Each object is visited once, from an explicit stack, within
|
|
50
|
+
* HEADER_SCAN_NODES and HEADER_SCAN_DEPTH. */
|
|
51
|
+
export declare function mcpHeaderProblem(inputSchema: unknown): string | undefined;
|
|
52
|
+
/** The pin of a run granted `names`: each MCP tool among them, as its server's snapshot holds it. Keyed by server name
|
|
53
|
+
* with no prototype, as every map of names here is: a server named `constructor` is a server like any other. A granted
|
|
54
|
+
* tool that cannot be pinned (its server no longer saved, the tool gone since a refresh, a header declaration it cannot
|
|
55
|
+
* send) throws, naming it and why: the run is refused, never started without it. */
|
|
56
|
+
export declare function mcpPinOf(names: readonly string[], source: McpServerSource): McpPin;
|
|
57
|
+
/** What a launch hands the run for its pin: each pinned server's URL now, with its headers only when it has not moved. A
|
|
58
|
+
* server no longer saved is absent. */
|
|
59
|
+
export declare function mcpCredentialsOf(pin: McpPin, source: McpServerSource): McpCredentials;
|
|
60
|
+
export interface McpGatewayOptions {
|
|
61
|
+
pin: McpPin;
|
|
62
|
+
credentials: McpCredentials;
|
|
63
|
+
/** The run's work/, where an answer too long for the model is filed. */
|
|
64
|
+
work: () => string;
|
|
65
|
+
/** For tests: the fetch the upstream client sends with. */
|
|
66
|
+
fetch?: typeof fetch;
|
|
67
|
+
/** For tests: the bound on one call (CALL_MS) and on a server's first connection (CONNECT_MS). */
|
|
68
|
+
bounds?: {
|
|
69
|
+
callMs?: number;
|
|
70
|
+
connectMs?: number;
|
|
71
|
+
};
|
|
72
|
+
/** The run's tool gate, which every run's process passes (app.ts): each call enters it here, the only place an MCP
|
|
73
|
+
* call is gated (pi's wrapper and the harnesses' hooks leave MCP calls to it). Only a test omits it, and then every
|
|
74
|
+
* call is let go. Its `executor` and `spill`, where it has them, run an approved call and pass a result through. */
|
|
75
|
+
gate?: Pick<Gate, "enter"> & Partial<Pick<Gate, "executor" | "spill">>;
|
|
76
|
+
/** The run's commit to its store, once it is open: a parked call's request, a priced call's mark and charge, and an
|
|
77
|
+
* unpriced call's "not metered" are written on its root. None: a priced call is refused unsent, as a paid call with
|
|
78
|
+
* nowhere to book it is (paid-calls.ts). */
|
|
79
|
+
commit?: () => Park["commit"] | undefined;
|
|
80
|
+
}
|
|
81
|
+
/** The gateway: a session's servers, and a call that takes the gate's `park` of the harness it came from (its journal's
|
|
82
|
+
* commit, and how it ends a parked call's turn); none, the run's root commit. */
|
|
83
|
+
export type McpGateway = Omit<SessionMcp, "call"> & {
|
|
84
|
+
call(server: string, tool: string, args: Record<string, unknown>, context: {
|
|
85
|
+
signal: AbortSignal;
|
|
86
|
+
callId?: string;
|
|
87
|
+
park?: Park;
|
|
88
|
+
}): Promise<McpCallResult>;
|
|
89
|
+
};
|
|
90
|
+
export declare function mcpGateway(options: McpGatewayOptions): McpGateway;
|
|
91
|
+
/** Whether the gateway's answer is a call the gate parked for a person's approval: the harness ends the turn on it. A
|
|
92
|
+
* symbol, so it never reaches a harness's MCP client in the answer's JSON. */
|
|
93
|
+
export declare const isParked: (result: McpCallResult) => boolean;
|
|
94
|
+
/** pi's tools for the gateway's servers: each granted tool under its wire name (`mcp__<server>__<tool>`), with the pinned
|
|
95
|
+
* description and schema, never run again after a crash. */
|
|
96
|
+
export declare function mcpRegistrations(gateway: McpGateway): ToolRegistration[];
|