@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,259 @@
|
|
|
1
|
+
// The checker of what a run proposes for its agent's learning folder (SPEC.md): its notes, a skill and workflow drafts,
|
|
2
|
+
// each a change against the commit the run started from. Structure only, never whether a note is any good,
|
|
3
|
+
// which is the grader's. The host reads the copy itself (regular files only, never a link followed) and hands each change
|
|
4
|
+
// here with its bytes; nothing the checker refuses is ever written to git. Every problem it reports is printable: its
|
|
5
|
+
// path and detail are cut of the host's secrets and of text shaped like one, and a field over PRINT_MAX is redacted whole.
|
|
6
|
+
import { hiddenCharacter } from "./invisible.js";
|
|
7
|
+
import { INDEX_FILE, INDEX_LINES, NOTE_FILE, parseNoteFile } from "./notes.js";
|
|
8
|
+
import { redactSecrets, secretShapes, valueMatcher } from "./secrets.js";
|
|
9
|
+
import { draftProblems, frontKeys, LEARNED_KEYS, learnedName, learnedPlace, setsStatus, skillProblems, WORKFLOWS_DIR } from "./skills.js";
|
|
10
|
+
/** The most the host adds to a run's note as it merges it: `origin: you` and `status: pending`, a front matter line
|
|
11
|
+
* each (notes.ts mergedNote). */
|
|
12
|
+
const HOST_LINES = Buffer.byteLength("origin: you\nstatus: pending\n");
|
|
13
|
+
/** Byte caps (UTF-8) and counts. Over a cap is refused, never cut. */
|
|
14
|
+
export const CAPS = Object.freeze({
|
|
15
|
+
/** One note's file. */
|
|
16
|
+
note: 4096,
|
|
17
|
+
/** One note a run proposes: the note cap less HOST_LINES, so a run's note stays within `note` once the host merges
|
|
18
|
+
* it, and a person can still retire it and a later run supersede it, each read and checked against `note`. */
|
|
19
|
+
runNote: 4096 - HOST_LINES,
|
|
20
|
+
/** New notes in one run. */
|
|
21
|
+
newNotes: 8,
|
|
22
|
+
/** Notes one run's new notes supersede, together. */
|
|
23
|
+
supersedes: 8,
|
|
24
|
+
/** Changed paths in one run; over it nothing else is read. */
|
|
25
|
+
changes: 64,
|
|
26
|
+
/** One skill's SKILL.md, or one workflow draft's workflow.json: one grader reads each whole beside the notes, so the
|
|
27
|
+
* most a run proposes stays within its prompt (grade.ts GRADE_CAPS.prompt). */
|
|
28
|
+
file: 16_384,
|
|
29
|
+
/** One draft's README.md, which the host writes from the one-line description its block gives. */
|
|
30
|
+
readme: 1_024,
|
|
31
|
+
/** Skills one run adds or changes. */
|
|
32
|
+
skills: 1,
|
|
33
|
+
/** Workflow drafts one run adds or changes. */
|
|
34
|
+
workflows: 1,
|
|
35
|
+
});
|
|
36
|
+
const MODES = { "120000": "a link: never followed", "040000": "a folder: nothing in it was read" };
|
|
37
|
+
/** Why a run's path is none of what it may propose. */
|
|
38
|
+
const OUTSIDE = "a run proposes notes at the folder's top, skills/<name>/SKILL.md, and workflows/<name>/ with its workflow.json and README.md";
|
|
39
|
+
/** `problem` as it may be printed: its path and detail cut of `values` and of secret shapes, whole when over PRINT_MAX. */
|
|
40
|
+
export const printable = (problem, values) => ({
|
|
41
|
+
rule: problem.rule,
|
|
42
|
+
...(problem.path === undefined ? {} : { path: redactSecrets(problem.path, values) }),
|
|
43
|
+
detail: redactSecrets(problem.detail, values),
|
|
44
|
+
});
|
|
45
|
+
/** No secret's shape or the host's values in a file's name: a writer picks its files' names, and they reach main, the
|
|
46
|
+
* index and the logs. */
|
|
47
|
+
function nameScanned(path, refused, add) {
|
|
48
|
+
for (const kind of secretShapes(path))
|
|
49
|
+
add("secret_shape", `its name holds text shaped like a secret (${kind})`, path);
|
|
50
|
+
if (refused(path))
|
|
51
|
+
add("secret_value", "its name holds a value the host named as secret", path);
|
|
52
|
+
}
|
|
53
|
+
/** A note's file name, whoever writes it: nameScanned, and a note's own (a `.md` file at the folder's top). False when
|
|
54
|
+
* it is not a note's name, and nothing else is read. */
|
|
55
|
+
function nameChecked(path, refused, add, outside = "only a .md file at the folder's top is a note") {
|
|
56
|
+
nameScanned(path, refused, add);
|
|
57
|
+
if (path.includes("/") || !path.endsWith(".md"))
|
|
58
|
+
return add("outside", outside, path), false;
|
|
59
|
+
if (!NOTE_FILE.test(path))
|
|
60
|
+
return add("file_name", "a note's name is letters, digits, dots, dashes and underscores, starting with a letter or digit, and ends .md", path), false;
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
/** A note's text by itself, whoever writes it: within the cap, UTF-8, no hidden character, no secret's shape or the host's
|
|
64
|
+
* values, its front matter in shape. The note when it is. */
|
|
65
|
+
function textChecked(path, size, bytes, refused, add, run = false) {
|
|
66
|
+
const cap = run ? CAPS.runNote : CAPS.note;
|
|
67
|
+
if (size > cap)
|
|
68
|
+
return void add("too_large", `${size} bytes; the cap is ${cap}${run ? " for a run's note" : ""}`, path);
|
|
69
|
+
const text = textOf(path, bytes, refused, add);
|
|
70
|
+
if (text === undefined)
|
|
71
|
+
return undefined;
|
|
72
|
+
const note = parseNoteFile(path, text);
|
|
73
|
+
if (Array.isArray(note))
|
|
74
|
+
return void note.forEach((reason) => add("note", reason, path));
|
|
75
|
+
return { ...note, text };
|
|
76
|
+
}
|
|
77
|
+
/** A file's text, whatever it holds: UTF-8, no hidden character, no secret's shape or the host's values. Undefined,
|
|
78
|
+
* with why, when it is not. */
|
|
79
|
+
function textOf(path, bytes, refused, add) {
|
|
80
|
+
if (!bytes)
|
|
81
|
+
throw new TypeError(`${path}: a change that is not a deletion carries its bytes`);
|
|
82
|
+
let text;
|
|
83
|
+
try {
|
|
84
|
+
text = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return void add("encoding", "it is not UTF-8", path);
|
|
88
|
+
}
|
|
89
|
+
let found = false;
|
|
90
|
+
const hidden = hiddenCharacter(text);
|
|
91
|
+
if (hidden)
|
|
92
|
+
found = (add("invisible_unicode", `it holds U+${hidden.code.toString(16).toUpperCase().padStart(4, "0")}, a character a reader does not see, at character ${hidden.at}`, path), true);
|
|
93
|
+
for (const kind of secretShapes(text))
|
|
94
|
+
found = (add("secret_shape", `it holds text shaped like a secret (${kind})`, path), true);
|
|
95
|
+
if (refused(text))
|
|
96
|
+
found = (add("secret_value", "it holds a value the host named as secret", path), true);
|
|
97
|
+
return found ? undefined : text;
|
|
98
|
+
}
|
|
99
|
+
/** What a run may write of a skill or a workflow draft (`place`), by itself: a good folder name, never a deletion, a
|
|
100
|
+
* regular file within CAPS.file (a README within CAPS.readme), its text as textOf takes it, and in shape: a skill's
|
|
101
|
+
* front matter (skillProblems), with no `status`, which is the host's; a draft the DSL validates against `tools` with
|
|
102
|
+
* no node that runs code (draftProblems); a README that names its folder and says what the draft is for. */
|
|
103
|
+
function learnedChecked(change, place, refused, input, add) {
|
|
104
|
+
const { path } = change;
|
|
105
|
+
nameScanned(path, refused, add);
|
|
106
|
+
if (!learnedName(place.kind, place.name))
|
|
107
|
+
return add("file_name", place.kind === "skill" ? "a skill's name is lowercase letters, digits and single dashes, at most 64" : "a workflow's name is lowercase letters, digits, dashes and underscores, at most 64, starting with a letter or digit", path);
|
|
108
|
+
if (change.status === "deleted")
|
|
109
|
+
return add("deleted", "a run never deletes a skill or a workflow", path);
|
|
110
|
+
if (change.mode !== undefined && change.mode !== "100644")
|
|
111
|
+
return add("file_mode", MODES[change.mode] ?? "not a regular file: never read", path);
|
|
112
|
+
const size = change.size ?? change.bytes?.length ?? 0;
|
|
113
|
+
const cap = place.kind === "readme" ? CAPS.readme : CAPS.file;
|
|
114
|
+
if (size > cap)
|
|
115
|
+
return add("too_large", `${size} bytes; the cap is ${cap}`, path);
|
|
116
|
+
// A person's call stands: a skill or a draft whose seed text has a status (retired, or waiting for its owner's OK).
|
|
117
|
+
const readmeOf = `${path.slice(0, path.lastIndexOf("/"))}/README.md`;
|
|
118
|
+
if (input.kept?.includes(path) || (place.kind === "workflow" && input.kept?.includes(readmeOf)))
|
|
119
|
+
return add("skill_status", "a person retired it, or it waits for its owner's OK: a run never changes it", path);
|
|
120
|
+
const text = textOf(path, change.bytes, refused, add);
|
|
121
|
+
if (text === undefined)
|
|
122
|
+
return;
|
|
123
|
+
if (place.kind === "workflow") {
|
|
124
|
+
if (!input.dsl)
|
|
125
|
+
throw new TypeError(`${path}: a workflow draft is read with the workflow DSL, which was not given`);
|
|
126
|
+
for (const { rule, detail } of draftProblems(input.dsl, text, input.tools))
|
|
127
|
+
add(rule, detail, path);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
for (const reason of skillProblems(text, place.name))
|
|
131
|
+
add(place.kind === "skill" ? "skill" : "workflow", reason, path);
|
|
132
|
+
// Its front matter says what it is and nothing more: Claude Code reads directives (a hook is a shell command) from any
|
|
133
|
+
// other key. `status` has its own rule.
|
|
134
|
+
const extra = (frontKeys(text) ?? []).filter((key) => !LEARNED_KEYS.includes(key) && key !== "status");
|
|
135
|
+
if (extra.length)
|
|
136
|
+
add("skill_front_matter", `its front matter sets ${extra.join(", ")}: a learned ${place.kind === "skill" ? "skill" : "workflow"} sets name and description alone`, path);
|
|
137
|
+
if (place.kind === "skill" && setsStatus(text))
|
|
138
|
+
add("status", "a run never sets a skill's status: the host does, when it holds one for its owner's OK", path);
|
|
139
|
+
}
|
|
140
|
+
/** The checks one note's file passes by itself (SPEC.md), as a person writes it through the host: its name, the note cap,
|
|
141
|
+
* UTF-8, hidden characters, secret shapes and the host's values in its name and text, and its front matter. A person
|
|
142
|
+
* may set `status` and `superseded_by`; what a run may not do (edit, delete, set status) is checkProposal's. Every
|
|
143
|
+
* problem is printable. */
|
|
144
|
+
export function checkNote(path, bytes, refuseValues = []) {
|
|
145
|
+
const problems = [];
|
|
146
|
+
const add = (rule, detail, at) => void problems.push(printable(at === undefined ? { rule, detail } : { rule, path: at, detail }, refuseValues));
|
|
147
|
+
const refused = valueMatcher(refuseValues);
|
|
148
|
+
const note = nameChecked(path, refused, add) ? textChecked(path, bytes.length, bytes, refused, add) : undefined;
|
|
149
|
+
return problems.length || !note ? { problems } : { problems, note };
|
|
150
|
+
}
|
|
151
|
+
/** Checks what a run proposes against SPEC.md: its notes, and a skill or workflow drafts beside them (learnedChecked).
|
|
152
|
+
* `MEMORY.md` is the host's: a change to it is ignored, never refused. */
|
|
153
|
+
export function checkProposal(input) {
|
|
154
|
+
const values = input.refuseValues ?? [];
|
|
155
|
+
const problems = [];
|
|
156
|
+
const add = (rule, detail, path) => void problems.push(printable(path === undefined ? { rule, detail } : { rule, path, detail }, values));
|
|
157
|
+
const changes = input.changes.filter((change) => change.path !== INDEX_FILE);
|
|
158
|
+
if (changes.length > CAPS.changes) {
|
|
159
|
+
add("too_many_files", `${changes.length} changed paths; the cap is ${CAPS.changes} a run, and nothing else was read`);
|
|
160
|
+
return { ok: false, problems, notes: [] };
|
|
161
|
+
}
|
|
162
|
+
const refused = valueMatcher(values);
|
|
163
|
+
const base = new Set(input.base.files);
|
|
164
|
+
const notes = [];
|
|
165
|
+
const skills = [];
|
|
166
|
+
const workflows = new Set();
|
|
167
|
+
let added = 0;
|
|
168
|
+
const one = (change) => {
|
|
169
|
+
const { path } = change;
|
|
170
|
+
const place = learnedPlace(path);
|
|
171
|
+
if (place) {
|
|
172
|
+
// What the run writes, under a good name, is counted: a skill against the run's, a draft's file against its pair.
|
|
173
|
+
if (change.status !== "deleted" && learnedName(place.kind, place.name)) {
|
|
174
|
+
if (place.kind === "skill")
|
|
175
|
+
skills.push(path);
|
|
176
|
+
else
|
|
177
|
+
workflows.add(place.name);
|
|
178
|
+
}
|
|
179
|
+
return learnedChecked(change, place, refused, input, add);
|
|
180
|
+
}
|
|
181
|
+
if (change.status === "added")
|
|
182
|
+
added += 1;
|
|
183
|
+
if (!nameChecked(path, refused, add, OUTSIDE))
|
|
184
|
+
return;
|
|
185
|
+
if (change.status === "deleted")
|
|
186
|
+
return add("deleted", "a run never deletes a note", path);
|
|
187
|
+
if (change.mode !== undefined && change.mode !== "100644")
|
|
188
|
+
return add("file_mode", MODES[change.mode] ?? "not a regular file: never read", path);
|
|
189
|
+
if (change.status === "modified")
|
|
190
|
+
return add("edited", "a run never edits a note: to replace one, it adds a new note that supersedes it", path);
|
|
191
|
+
if (base.has(path))
|
|
192
|
+
return add("exists", "the folder has a note by this name", path);
|
|
193
|
+
const note = textChecked(path, change.size ?? change.bytes?.length ?? 0, change.bytes, refused, add, true);
|
|
194
|
+
if (!note)
|
|
195
|
+
return;
|
|
196
|
+
if (note.keys.includes("status") || note.keys.includes("superseded_by") || note.keys.includes("origin"))
|
|
197
|
+
return add("status", "a run never sets status, superseded_by or origin: the host does, when it merges the note or a later one supersedes it", path);
|
|
198
|
+
notes.push(note);
|
|
199
|
+
};
|
|
200
|
+
for (const change of changes)
|
|
201
|
+
one(change);
|
|
202
|
+
if (added > CAPS.newNotes)
|
|
203
|
+
add("too_many_notes", `${added} new notes; the cap is ${CAPS.newNotes} a run`);
|
|
204
|
+
if (skills.length > CAPS.skills)
|
|
205
|
+
add("too_many_skills", `${skills.length} skills added or changed; a run adds or changes at most ${CAPS.skills}`);
|
|
206
|
+
if (workflows.size > CAPS.workflows)
|
|
207
|
+
add("too_many_workflows", `${workflows.size} workflow drafts added or changed; a run adds or changes at most ${CAPS.workflows}`);
|
|
208
|
+
// A skill is what every later run reads as how to do the job: only a run that did it writes one.
|
|
209
|
+
if (input.outcome !== "completed")
|
|
210
|
+
for (const path of skills)
|
|
211
|
+
add("skill_outcome", `the run's outcome is ${input.outcome ?? "not known"}: only a completed run adds or changes a skill`, path);
|
|
212
|
+
// A draft is its workflow.json and its README.md, together, as the folder will hold them.
|
|
213
|
+
const gone = new Set(changes.filter((change) => change.status === "deleted").map((change) => change.path));
|
|
214
|
+
const after = new Set([...base, ...changes.filter((change) => change.status !== "deleted").map((change) => change.path)].filter((path) => !gone.has(path)));
|
|
215
|
+
for (const name of workflows) {
|
|
216
|
+
const [json, readme] = ["workflow.json", "README.md"].map((file) => `${WORKFLOWS_DIR}/${name}/${file}`);
|
|
217
|
+
if (after.has(json) !== after.has(readme))
|
|
218
|
+
add("workflow", `the folder holds ${after.has(json) ? "workflow.json" : "README.md"} without the other file`, after.has(json) ? readme : json);
|
|
219
|
+
}
|
|
220
|
+
if (!problems.length)
|
|
221
|
+
problems.push(...mergeProblems(input.base, notes, values));
|
|
222
|
+
return { ok: problems.length === 0, problems, notes: problems.length ? [] : notes };
|
|
223
|
+
}
|
|
224
|
+
/** The notes the active ones of `notes` supersede, each by the note that supersedes it. A note that waits for its
|
|
225
|
+
* owner's OK (`status: pending`) supersedes nothing until it is approved: what it names stays active. The one rule the
|
|
226
|
+
* merge writes by (grade.ts mergeProposal) and its index is counted by (mergeProblems). */
|
|
227
|
+
export function supersededBy(notes) {
|
|
228
|
+
return new Map(notes.filter((note) => note.status === "active").flatMap((note) => note.supersedes.map((old) => [old, note.file])));
|
|
229
|
+
}
|
|
230
|
+
/** What stops `notes` from joining `base` as they are: a name `base` holds (`exists`), a `supersedes` that names no
|
|
231
|
+
* active note of `base` or one another new note supersedes too, or more than CAPS.supersedes notes superseded, and an
|
|
232
|
+
* index past INDEX_LINES, counted as the merge makes it (supersededBy: a pending note adds no line and replaces none).
|
|
233
|
+
* The checker asks it of the run's seed, where every new note is active; the host asks it again of main at merge time,
|
|
234
|
+
* with each note as it merges it, since other runs may have merged meanwhile. */
|
|
235
|
+
export function mergeProblems(base, notes, refuseValues = []) {
|
|
236
|
+
const files = new Set(base.files);
|
|
237
|
+
const active = new Set(base.active.map((note) => note.file));
|
|
238
|
+
const out = [];
|
|
239
|
+
const replaced = new Set();
|
|
240
|
+
for (const note of notes) {
|
|
241
|
+
if (files.has(note.file))
|
|
242
|
+
out.push({ rule: "exists", path: note.file, detail: "the folder has a note by this name" });
|
|
243
|
+
for (const old of note.supersedes) {
|
|
244
|
+
if (!active.has(old))
|
|
245
|
+
out.push({ rule: "supersedes", path: note.file, detail: `it supersedes ${old}, which is not an active note` });
|
|
246
|
+
else if (replaced.has(old))
|
|
247
|
+
out.push({ rule: "supersedes", path: note.file, detail: `${old} is superseded by another new note too` });
|
|
248
|
+
replaced.add(old);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// The grader reads each note superseded in full (grade.ts): their count is capped, as the new notes' is.
|
|
252
|
+
if (replaced.size > CAPS.supersedes)
|
|
253
|
+
out.push({ rule: "supersedes", detail: `the new notes supersede ${replaced.size} notes; the cap is ${CAPS.supersedes} a run` });
|
|
254
|
+
const gone = supersededBy(notes);
|
|
255
|
+
const lines = [...active].filter((file) => !gone.has(file)).length + notes.filter((note) => note.status === "active").length;
|
|
256
|
+
if (lines > INDEX_LINES)
|
|
257
|
+
out.push({ rule: "index_full", detail: `the index would hold ${lines} lines; it holds at most ${INDEX_LINES}, so supersede a note rather than add one` });
|
|
258
|
+
return out.map((problem) => printable(problem, refuseValues));
|
|
259
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type LearnedNote } from "./notes.js";
|
|
2
|
+
/** What the grader asks of each new note, and when it keeps one. The one statement of it. */
|
|
3
|
+
export declare const GRADE_RUBRIC: string;
|
|
4
|
+
/** A note's file and its whole text. */
|
|
5
|
+
export type NoteText = {
|
|
6
|
+
readonly file: string;
|
|
7
|
+
readonly text: string;
|
|
8
|
+
};
|
|
9
|
+
/** An active note as the index lists it (a LearnedNote will do). */
|
|
10
|
+
export type IndexEntry = Pick<LearnedNote, "file" | "name" | "description">;
|
|
11
|
+
export type GradeInput = {
|
|
12
|
+
/** The run id: it names the run in the prompt and seeds the fence token. */
|
|
13
|
+
readonly run: string;
|
|
14
|
+
/** The agent's standing instructions, as the host keeps them: the prompt holds their first GRADE_CAPS.instructions
|
|
15
|
+
* characters. */
|
|
16
|
+
readonly instructions?: string;
|
|
17
|
+
/** Every active note on main, as the index lists it: the prompt holds each one's index line, cut to
|
|
18
|
+
* GRADE_CAPS.indexLine. */
|
|
19
|
+
readonly active: readonly IndexEntry[];
|
|
20
|
+
/** The whole text of each active note the new notes supersede, and of no other. */
|
|
21
|
+
readonly superseded: readonly NoteText[];
|
|
22
|
+
/** The new notes the run proposes, each checked. */
|
|
23
|
+
readonly proposed: readonly NoteText[];
|
|
24
|
+
/** The skill and workflow draft the run proposes beside them, each checked, by path in the folder: a skill's
|
|
25
|
+
* `skills/<name>/SKILL.md`, a draft's `workflows/<name>/workflow.json` with its `README.md`. */
|
|
26
|
+
readonly files?: readonly NoteText[];
|
|
27
|
+
/** What the user said in the run, in order: the messages the run was sent, never the host's end-of-run turn. The
|
|
28
|
+
* prompt holds the first and the newest, GRADE_CAPS.asked in all, each cut to GRADE_CAPS.askedMessage, with unseen
|
|
29
|
+
* characters taken out. The host cuts them of its secrets first. */
|
|
30
|
+
readonly asked?: readonly string[];
|
|
31
|
+
};
|
|
32
|
+
/** What bounds the grader's prompt, in UTF-16 units, as a completion counts them. `prompt` is the most it ever is:
|
|
33
|
+
* the fixed text, the instructions cut to `instructions`, INDEX_LINES + CAPS.supersedes index lines cut to
|
|
34
|
+
* `indexLine`, `asked` of the user's messages cut to `askedMessage`, and CAPS.supersedes superseded and CAPS.newNotes
|
|
35
|
+
* new notes of at most CAPS.note bytes each, fenced, come to less. */
|
|
36
|
+
export declare const GRADE_CAPS: Readonly<{
|
|
37
|
+
prompt: 200000;
|
|
38
|
+
instructions: 16000;
|
|
39
|
+
indexLine: 300;
|
|
40
|
+
asked: 4;
|
|
41
|
+
askedMessage: 1000;
|
|
42
|
+
}>;
|
|
43
|
+
/** The grader's judgment of one new note: `keep` (true for a pending one too), `pending` when it waits for the user's
|
|
44
|
+
* OK (a risky note, whoever's idea it was, or one the user asked for that the grader dropped on General alone), and
|
|
45
|
+
* `origin`, `you` for what the user asked in their own words, else `run`. `question` is the rubric's question it
|
|
46
|
+
* failed, or `Risky` for one the grader holds. */
|
|
47
|
+
export type VerdictItem = {
|
|
48
|
+
readonly file: string;
|
|
49
|
+
readonly keep: boolean;
|
|
50
|
+
readonly pending?: true;
|
|
51
|
+
readonly origin?: "you" | "run";
|
|
52
|
+
readonly question?: string;
|
|
53
|
+
readonly why: string;
|
|
54
|
+
};
|
|
55
|
+
/** The whole proposal's verdict: `merge` only when every note is kept, and the grader said so or dropped only notes the
|
|
56
|
+
* user asked for, on General alone. */
|
|
57
|
+
export type Verdict = {
|
|
58
|
+
readonly merge: boolean;
|
|
59
|
+
readonly reason: string;
|
|
60
|
+
readonly items: readonly VerdictItem[];
|
|
61
|
+
};
|
|
62
|
+
/** The files the grader gives one item for, in order: the new notes', then each skill and draft's (gradedFiles). */
|
|
63
|
+
export declare const gradedFiles: (proposed: readonly NoteText[], files?: readonly NoteText[]) => string[];
|
|
64
|
+
/** The items the grader judges, with their texts, in gradedFiles' order: what parseVerdict reads, a note's text for the
|
|
65
|
+
* mark its run's turn may have set (runMarkedRisky). */
|
|
66
|
+
export declare const gradedItems: (proposed: readonly NoteText[], files?: readonly NoteText[]) => NoteText[];
|
|
67
|
+
/** The prompt a host sends its grader for what run `run` proposes, once the checker has passed it: the instructions, the
|
|
68
|
+
* index lines of the active notes, the notes the proposal supersedes in full and the new notes, each fenced as data,
|
|
69
|
+
* and never more than GRADE_CAPS.prompt (GRADE_CAPS). Throws on input no checked proposal holds: a run id out of
|
|
70
|
+
* shape, a file name that is no note's or named twice, a new note that is not one or is active already, a superseded
|
|
71
|
+
* note that is not active or that the new notes do not supersede (or one they supersede and that is not given), a
|
|
72
|
+
* count or a note over its cap, or an unseen character. */
|
|
73
|
+
export declare function gradePrompt(input: GradeInput): string;
|
|
74
|
+
/** The grader's verdict from its answer, failing closed: anything it cannot read, an item missing, named twice or for a
|
|
75
|
+
* file it was not asked to judge, or a merge with an item not kept, is no merge. A note the user asked for, dropped on
|
|
76
|
+
* General alone, is kept and waits for the user's OK. `proposed` are the new notes the
|
|
77
|
+
* prompt was built from, or the files it asked an item for (gradedFiles: a note's file, a skill's SKILL.md, a draft's
|
|
78
|
+
* workflow.json). Throws only when `proposed` is not a list a checked proposal could hold, never on the answer. */
|
|
79
|
+
export declare function parseVerdict(text: unknown, proposed: readonly NoteText[] | readonly string[]): Verdict;
|