@parcha/agentrun-serve 0.1.0-beta.29 → 0.1.0-beta.30
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 +188 -0
- package/README.md +564 -97
- package/dist/adapters.d.ts +35 -6
- package/dist/adapters.js +152 -26
- package/dist/agents.d.ts +11 -5
- package/dist/agents.js +16 -10
- package/dist/app.js +80 -20
- package/dist/background.d.ts +28 -0
- package/dist/background.js +376 -0
- package/dist/box-egress.d.ts +98 -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 +80 -0
- package/dist/box-relay-vm.js +389 -0
- package/dist/box-relay.d.ts +8 -5
- package/dist/box-relay.js +14 -9
- package/dist/boxes.d.ts +21 -3
- package/dist/boxes.js +14 -7
- package/dist/browser-cost.d.ts +41 -0
- package/dist/browser-cost.js +158 -0
- package/dist/cap.d.ts +129 -21
- package/dist/cap.js +338 -67
- 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-34jfpIbQ.js +481 -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/errors.d.ts +2 -0
- package/dist/errors.js +5 -2
- package/dist/files.d.ts +6 -1
- package/dist/files.js +7 -2
- package/dist/grade.d.ts +7 -10
- package/dist/grade.js +31 -51
- 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 +101 -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-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/learn/check.d.ts +10 -1
- package/dist/learn/check.js +19 -1
- package/dist/learn/grade.d.ts +3 -2
- package/dist/learn/grade.js +25 -13
- package/dist/learn/index.d.ts +2 -2
- package/dist/learn/index.js +2 -2
- package/dist/learn/notes.js +2 -1
- package/dist/learn/reflect.d.ts +2 -2
- package/dist/learn/reflect.js +51 -5
- package/dist/learn/secrets.js +28 -8
- package/dist/learn/skills.d.ts +17 -4
- package/dist/learn/skills.js +79 -6
- package/dist/learned-workflow.d.ts +59 -0
- package/dist/learned-workflow.js +191 -0
- package/dist/learning-run.d.ts +7 -5
- package/dist/learning-run.js +45 -23
- package/dist/learning-words.d.ts +6 -3
- package/dist/learning-words.js +8 -5
- package/dist/learning.d.ts +44 -3
- package/dist/learning.js +148 -3
- package/dist/mcp-servers.d.ts +7 -4
- package/dist/mcp-servers.js +5 -0
- 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 +358 -48
- 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 +27 -4
- package/dist/place.js +42 -10
- 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 +173 -23
- package/dist/runnable.d.ts +5 -2
- package/dist/runnable.js +12 -4
- package/dist/runs.d.ts +258 -36
- package/dist/runs.js +830 -89
- package/dist/secrets.d.ts +12 -0
- package/dist/secrets.js +18 -0
- package/dist/server.d.ts +131 -35
- package/dist/server.js +467 -105
- 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 +266 -0
- package/dist/tool-gate.js +554 -0
- package/dist/tool-keys.d.ts +46 -10
- package/dist/tool-keys.js +44 -2
- package/dist/tool-plane.d.ts +112 -27
- package/dist/tool-plane.js +205 -47
- package/dist/tools.d.ts +69 -14
- package/dist/tools.js +143 -24
- 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/webhooks.d.ts +11 -4
- package/dist/webhooks.js +17 -1
- package/launcher/agentrun-serve +1 -1
- package/package.json +19 -13
- package/dist/console/assets/index-BN7oVcO4.js +0 -445
- package/dist/console/assets/index-By-jkqki.css +0 -1
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { defineTool } from "@earendil-works/pi-durable";
|
|
2
|
+
import { registerLabel, registerOutcome } from "@parcha/pi-durable-agent/timeline";
|
|
3
|
+
import { sideRequests } from "./cap.js";
|
|
4
|
+
import { draftProblems, LEARNED_MAX_TURNS } from "./learn/index.js";
|
|
5
|
+
import { workflowLine } from "./learning.js";
|
|
6
|
+
import { ledgerOf } from "./paid-calls.js";
|
|
7
|
+
import { forModel } from "./result.js";
|
|
8
|
+
import { deniedText } from "./tool-gate.js";
|
|
9
|
+
import { allows, CALL_TOOLS, learnedDraftTools, toolOf } from "./tools.js";
|
|
10
|
+
export const LEARNED_WORKFLOW_TOOL = "learned_workflow";
|
|
11
|
+
/** The most of a learned workflow's output its result line shows, and the longest value it shows as written. */
|
|
12
|
+
const LINE_MAX = 120;
|
|
13
|
+
const VALUE_MAX = 60;
|
|
14
|
+
/** One line of a learned workflow's output for its row: an object's fields as `name value`, each value whole or, when
|
|
15
|
+
* longer than VALUE_MAX, only as its size, and whole fields only until LINE_MAX. Nothing is ever cut inside a value:
|
|
16
|
+
* the timeline redacts the line as it says it (its summary's words), and its redactor matches a held value only whole,
|
|
17
|
+
* so a cut value could leave a prefix it would not find. Newlines are flattened, so the one line it keeps holds every
|
|
18
|
+
* field. An output already cut for the model (learnedText) says so. */
|
|
19
|
+
export function outputLine(text) {
|
|
20
|
+
const clipped = /\n\[the workflow's output is cut at (\d+) of (\d+) characters\]$/.exec(text);
|
|
21
|
+
if (clipped)
|
|
22
|
+
return `its output is long, cut at ${clipped[1]} of ${clipped[2]} characters`;
|
|
23
|
+
let output;
|
|
24
|
+
try {
|
|
25
|
+
output = JSON.parse(text);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const said = (value) => {
|
|
31
|
+
const flat = (typeof value === "string" ? value : JSON.stringify(value) ?? String(value)).replace(/\s+/g, " ").trim();
|
|
32
|
+
return flat.length > VALUE_MAX ? `(${flat.length} characters)` : flat;
|
|
33
|
+
};
|
|
34
|
+
if (!output || typeof output !== "object" || Array.isArray(output))
|
|
35
|
+
return said(output);
|
|
36
|
+
const fields = [];
|
|
37
|
+
let length = 0;
|
|
38
|
+
for (const [key, value] of Object.entries(output)) {
|
|
39
|
+
const field = `${key} ${said(value)}`;
|
|
40
|
+
if (fields.length && length + 2 + field.length > LINE_MAX) {
|
|
41
|
+
fields.push("…");
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
fields.push(field);
|
|
45
|
+
length += (fields.length > 1 ? 2 : 0) + field.length;
|
|
46
|
+
}
|
|
47
|
+
return fields.length ? fields.join(", ") : undefined;
|
|
48
|
+
}
|
|
49
|
+
// The timeline's words for a learned workflow's call: the workflow it ran (its name), and, once it returns, its output.
|
|
50
|
+
registerLabel(LEARNED_WORKFLOW_TOOL, (a) => (typeof a.name === "string" && a.name ? `Ran the learned workflow ${a.name}` : "Ran a learned workflow"), undefined, { name: "Run a learned workflow" });
|
|
51
|
+
registerOutcome(LEARNED_WORKFLOW_TOOL, (result) => {
|
|
52
|
+
const line = outputLine(result.text);
|
|
53
|
+
return line === undefined ? undefined : { failed: false, text: line };
|
|
54
|
+
});
|
|
55
|
+
/** The most characters of a learned workflow's output its answer holds, monid's bound (monid.ts CLIP): within the
|
|
56
|
+
* host's result bound, which each CLI is told to pass whole (host-bounds.test). */
|
|
57
|
+
export const LEARNED_CLIP = 60_000;
|
|
58
|
+
/** `text`, a learned workflow's output as JSON, cut at LEARNED_CLIP characters (never inside a surrogate pair), saying
|
|
59
|
+
* so. */
|
|
60
|
+
export function learnedText(text) {
|
|
61
|
+
if (text.length <= LEARNED_CLIP)
|
|
62
|
+
return text;
|
|
63
|
+
const end = /[\uD800-\uDBFF]/.test(text[LEARNED_CLIP - 1] ?? "") ? LEARNED_CLIP - 1 : LEARNED_CLIP;
|
|
64
|
+
return `${text.slice(0, end)}\n[the workflow's output is cut at ${end} of ${text.length} characters]`;
|
|
65
|
+
}
|
|
66
|
+
/** What a learned workflow's model node is refused with when it names a tool: it runs in a session of its own here.
|
|
67
|
+
* The check before the run refuses such a workflow first (draftProblems); this one holds should it not. */
|
|
68
|
+
export const NODE_TOOLS_REFUSED = "a learned workflow's model node runs without tools here";
|
|
69
|
+
/** The tool's description: what it does, and each workflow by name with the line its README says what it does with. */
|
|
70
|
+
export const learnedWorkflowDescription = (workflows) => [
|
|
71
|
+
"Run a workflow this agent learned, as one step: give its name and its input, a JSON object as the workflow's input",
|
|
72
|
+
"schema says. It answers the workflow's output as JSON, or why it did not run. The workflows:",
|
|
73
|
+
...workflows.map(workflowLine),
|
|
74
|
+
].join("\n");
|
|
75
|
+
/** One model request as a pi-ai event stream, sent as a side request through `models.completeSimple`: marked and costed
|
|
76
|
+
* on the run's timeline under `learned_workflow`, and under the run's cap. */
|
|
77
|
+
async function sideStream(models, model, context, options) {
|
|
78
|
+
const { createAssistantMessageEventStream } = await import("@earendil-works/pi-ai");
|
|
79
|
+
const stream = createAssistantMessageEventStream();
|
|
80
|
+
sideRequests.set(context, { label: LEARNED_WORKFLOW_TOOL, extraInputTokens: 0, maxFeeUsd: 0, feeUsd: () => 0 });
|
|
81
|
+
void (async () => {
|
|
82
|
+
try {
|
|
83
|
+
const message = (await models.completeSimple(model, context, options));
|
|
84
|
+
if (message.stopReason === "error" || message.stopReason === "aborted")
|
|
85
|
+
stream.push({ type: "error", reason: message.stopReason, error: message });
|
|
86
|
+
else
|
|
87
|
+
stream.push({ type: "done", reason: message.stopReason, message });
|
|
88
|
+
stream.end(message);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
const failed = { role: "assistant", content: [], stopReason: "error", errorMessage: String(error?.message ?? error), timestamp: Date.now(), usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } } };
|
|
92
|
+
stream.push({ type: "error", reason: "error", error: failed });
|
|
93
|
+
stream.end(failed);
|
|
94
|
+
}
|
|
95
|
+
})();
|
|
96
|
+
return stream;
|
|
97
|
+
}
|
|
98
|
+
/** The run's `learned_workflow` tool over `run.workflows`. */
|
|
99
|
+
export function learnedWorkflowTool(run) {
|
|
100
|
+
const names = run.workflows.map(({ name }) => name);
|
|
101
|
+
return defineTool({
|
|
102
|
+
name: LEARNED_WORKFLOW_TOOL,
|
|
103
|
+
description: learnedWorkflowDescription(run.workflows),
|
|
104
|
+
// Never run again after a crash (pi-durable's "unsafe"; a HostTool's "never": host-tools.ts REPLAY).
|
|
105
|
+
replay: "unsafe",
|
|
106
|
+
parameters: {
|
|
107
|
+
type: "object",
|
|
108
|
+
additionalProperties: false,
|
|
109
|
+
required: ["name", "input"],
|
|
110
|
+
properties: {
|
|
111
|
+
name: { type: "string", enum: names, description: "The learned workflow to run." },
|
|
112
|
+
input: { type: "object", description: "The workflow's input, as its input schema says." },
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
execute: async (args, api, context) => {
|
|
116
|
+
const { name, input } = (args ?? {});
|
|
117
|
+
const flow = run.workflows.find((workflow) => workflow.name === name);
|
|
118
|
+
if (!flow)
|
|
119
|
+
return forModel(`No learned workflow of this agent is named ${JSON.stringify(name)}. Its workflows: ${names.join(", ")}.`, { isError: true });
|
|
120
|
+
const said = await runLearned(run, flow, input, context?.abortSignal, ledgerOf(api, context));
|
|
121
|
+
return forModel(said.text, { isError: said.isError });
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/** `flow` run on `input` for `run`: its output as JSON, or why it did not run. Never throws, but on an abort. `ledger`:
|
|
126
|
+
* the tool call's, which each call node's paid requests are booked under, as a call of its own within it. */
|
|
127
|
+
export async function runLearned(run, flow, input, signal, ledger) {
|
|
128
|
+
const refuse = (why) => ({ text: `The learned workflow ${flow.name} was not run: ${why}`, isError: true });
|
|
129
|
+
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
130
|
+
return refuse("its input must be a JSON object");
|
|
131
|
+
const dsl = await import("@parcha/agentrun-dsl");
|
|
132
|
+
// Checked again at the call, against the agent's own tools as its run has them, before any node runs: what merged under
|
|
133
|
+
// another revision may name one it has no more.
|
|
134
|
+
// The tools the gate allows now; one set to ask or deny is refused in the words a workflow revision's call node is.
|
|
135
|
+
const { tools, gated } = learnedDraftTools(run.granted, (name) => run.policy?.(name) ?? "allow", run.plane);
|
|
136
|
+
const problems = draftProblems(dsl, flow.workflow, tools, gated);
|
|
137
|
+
if (problems.length)
|
|
138
|
+
return refuse(problems.map(({ detail }) => detail).join("; "));
|
|
139
|
+
const doc = JSON.parse(flow.workflow);
|
|
140
|
+
const { createPiHostRunner } = await import("@parcha/agentrun-pi");
|
|
141
|
+
const runners = new Map();
|
|
142
|
+
const runnerFor = async (tier) => {
|
|
143
|
+
const known = runners.get(tier ?? "default");
|
|
144
|
+
if (known)
|
|
145
|
+
return known;
|
|
146
|
+
const ref = run.modelOf(tier);
|
|
147
|
+
if (!ref)
|
|
148
|
+
throw new Error("the run has no model for its model nodes");
|
|
149
|
+
const model = run.models.getModel(ref.provider, ref.modelId);
|
|
150
|
+
if (!model)
|
|
151
|
+
throw new Error(`the model ${ref.provider}/${ref.modelId} is not known here`);
|
|
152
|
+
const registry = { getAll: () => run.models.getModels(), streamSimple: (m, ctx, options) => sideStream(run.models, m, ctx, options) };
|
|
153
|
+
const runner = createPiHostRunner({ cwd: run.work, model: model, modelRegistry: registry }, { tools: [], maxTurns: LEARNED_MAX_TURNS });
|
|
154
|
+
runners.set(tier ?? "default", runner);
|
|
155
|
+
return runner;
|
|
156
|
+
};
|
|
157
|
+
const runNode = async (request) => {
|
|
158
|
+
if (request.tools?.length)
|
|
159
|
+
throw new Error(`${NODE_TOOLS_REFUSED}: its node "${request.label}" names ${request.tools.join(", ")}`);
|
|
160
|
+
// Its own signal, which the DSL ties to the call's (a sibling's failure, a deadline, the call's stop).
|
|
161
|
+
return (await runnerFor(request.tier))(request);
|
|
162
|
+
};
|
|
163
|
+
const runEffect = async ({ node, input: given, signal: own, executionPath, item }) => {
|
|
164
|
+
const tool = node.via === "tool" ? node.tool : undefined;
|
|
165
|
+
const effect = tool && allows(CALL_TOOLS, tool) && tools.includes(tool) ? toolOf(tool)?.effect : undefined;
|
|
166
|
+
if (!effect)
|
|
167
|
+
throw new Error(`call node "${node.label}": this agent runs no tool ${tool ?? `via ${node.via}`}`);
|
|
168
|
+
// The gate's one rule, read as each call node runs, as a workflow revision's call node reads it (app.ts runEffect):
|
|
169
|
+
// a tool set to deny since the call began is refused in the gate's words, one set to ask too, since a call node
|
|
170
|
+
// cannot wait for an approval. Neither runs.
|
|
171
|
+
const permission = run.policy?.(tool) ?? "allow";
|
|
172
|
+
if (permission === "deny")
|
|
173
|
+
throw new Error(deniedText(tool));
|
|
174
|
+
if (permission === "ask")
|
|
175
|
+
throw new Error(`This ${tool} call needs a person's approval, which a workflow's call node cannot wait for; it was not run.`);
|
|
176
|
+
// Its paid requests booked under the tool's call, as a call of its own: the node, its execution path, its item in a map.
|
|
177
|
+
const booked = ledger ? { ledger: { call: `${ledger.call}/${node.label}@${executionPath ?? ""}${item ? `#${item.index}` : ""}`, record: ledger.record } } : {};
|
|
178
|
+
return effect(given, { signal: own, env: run.env, work: run.work, ...(run.complete ? { complete: run.complete } : {}), ...booked });
|
|
179
|
+
};
|
|
180
|
+
try {
|
|
181
|
+
const result = await dsl.runWorkflow(doc, input, { runNode: runNode, runEffect: runEffect, ...(signal ? { signal } : {}) });
|
|
182
|
+
if (result.status !== "complete")
|
|
183
|
+
return refuse(`it ended ${result.status}`);
|
|
184
|
+
return { text: learnedText(JSON.stringify(result.output ?? null)), isError: false };
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
if (signal?.aborted)
|
|
188
|
+
throw error;
|
|
189
|
+
return { text: `The learned workflow ${flow.name} failed: ${String(error?.message ?? error).slice(0, 1000)}`, isError: true };
|
|
190
|
+
}
|
|
191
|
+
}
|
package/dist/learning-run.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export type Reflect = {
|
|
|
14
14
|
timedOut?: true;
|
|
15
15
|
};
|
|
16
16
|
/** Who sent the end-of-run turn: the server, never a person, and no request field sets it. The one value it is sent
|
|
17
|
-
* with, at its one call (reflectTurn); the
|
|
17
|
+
* with, at its one call (reflectTurn); the tool gate reads it there and refuses that turn's writes under work/.learning/ (tool-gate.ts NOTE_ONLY_TEXT). */
|
|
18
18
|
declare const REFLECT_ORIGIN = "reflect";
|
|
19
19
|
export type TurnOrigin = typeof REFLECT_ORIGIN;
|
|
20
20
|
/** The run asked its end-of-run turn and has not ended since. */
|
|
@@ -90,7 +90,7 @@ export type ImpactLearning = {
|
|
|
90
90
|
* note retired), nor one whose learning predates these figures. Null unless both sides hold 2 runs or more. */
|
|
91
91
|
export declare function learningImpact(rows: readonly RunRow[], learningOf: (row: RunRow) => ImpactLearning | null | undefined): Impact;
|
|
92
92
|
/** What learning needs of the server's options: the data directory and the agents, its tokens, the switch, and its bounds. */
|
|
93
|
-
export type LearningOptions = Pick<RunsOptions, "agents" | "token" | "doorToken" | "storedKeys" | "learning" | "learningBudget" | "reflectTimeoutMs" | "gradeTimeoutMs" | "gradeModel">;
|
|
93
|
+
export type LearningOptions = Pick<RunsOptions, "agents" | "token" | "doorToken" | "storedKeys" | "ownSecrets" | "learning" | "learningBudget" | "reflectTimeoutMs" | "gradeTimeoutMs" | "gradeModel">;
|
|
94
94
|
/** What the kernel (runs.ts) hands learning: its runs, and the parts of a run's life learning moves. */
|
|
95
95
|
export type LearningKernel = {
|
|
96
96
|
/** Run `id` when the kernel holds it; read from the agent store the first time (`get`). */
|
|
@@ -236,7 +236,7 @@ export declare class LearningRuns {
|
|
|
236
236
|
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;
|
|
237
237
|
detail: string | null;
|
|
238
238
|
at: string;
|
|
239
|
-
}, "at" | "
|
|
239
|
+
}, "at" | "state" | "reason" | "detail">) | null;
|
|
240
240
|
/** How the runs `rows` holds that tried to learn fared, over `filter` (learningStats): a held run's learning from
|
|
241
241
|
* memory, any other's end from the learning ledger, never a run's files. */
|
|
242
242
|
counts(rows: readonly RunRow[], filter: AnalyticsFilter): Promise<ReturnType<typeof learningStats>>;
|
|
@@ -283,8 +283,10 @@ export declare class LearningRuns {
|
|
|
283
283
|
* the run has ended. Never rejects: `proposed` or `dropped`, `propose_failed` for a fault. A server that goes
|
|
284
284
|
* meanwhile leaves it `reflecting` in serve.json, and the next start checks it again. */
|
|
285
285
|
private proposeOnce;
|
|
286
|
-
/** The tools a run's workflow draft may name: its revision's granted tools a workflow node runs here
|
|
287
|
-
*
|
|
286
|
+
/** The tools a run's workflow draft may name: its revision's granted tools a workflow's call node runs here that the
|
|
287
|
+
* gate allows, under the server's tool settings and the agent's own (tools.ts learnedDraftTools); `gated`, those set to
|
|
288
|
+
* ask or deny, which a draft that calls one is refused for. None for a revision not found, so a draft that names one is
|
|
289
|
+
* refused. */
|
|
288
290
|
private draftTools;
|
|
289
291
|
private propose;
|
|
290
292
|
/** The run's proposal merged into main or dropped (grade.ts), one grade at a time per agent, after the checks and
|
package/dist/learning-run.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import { lstat, readFile } from "node:fs/promises";
|
|
17
17
|
import { join, posix } from "node:path";
|
|
18
18
|
import { ANSWER_MAX, INDEX_FILE, parseNoteFile, redactSecrets } from "./learn/index.js";
|
|
19
|
+
import { learnedWorkflowsOff } from "./adapters.js";
|
|
19
20
|
import { CAP_REFUSAL_PREFIX, SPEND_CAP_REACHED } from "./cap.js";
|
|
20
21
|
import { readJson, RUN_META, runDoorToken } from "./files.js";
|
|
21
22
|
import { activeOf, detailShown, dropSeed, gradeModelOf, keepTurn, KEPT_LEARNING, layLearned, layPinnedSkills, LEARNED_DIR, LEARNING_BUDGET, LEARNING_LABEL, learningBlocker, learningTestHooks, learningView, pinSeed, PROPOSAL, readPin, readTurn, secretsShown, seedAt, seedOf, shortLearning, skillsAt, withAgentGrade } from "./learning.js";
|
|
@@ -26,7 +27,7 @@ import { ended, outcomeOf, outcomes, record } from "./usage.js";
|
|
|
26
27
|
import { isObject } from "./validate.js";
|
|
27
28
|
import { REFLECT_REQUEST } from "./turns.js";
|
|
28
29
|
/** Who sent the end-of-run turn: the server, never a person, and no request field sets it. The one value it is sent
|
|
29
|
-
* with, at its one call (reflectTurn); the
|
|
30
|
+
* with, at its one call (reflectTurn); the tool gate reads it there and refuses that turn's writes under work/.learning/ (tool-gate.ts NOTE_ONLY_TEXT). */
|
|
30
31
|
const REFLECT_ORIGIN = "reflect";
|
|
31
32
|
/** The run asked its end-of-run turn and has not ended since. */
|
|
32
33
|
export const reflecting = (run) => run.meta.reflect !== undefined && run.meta.reflect.until === undefined;
|
|
@@ -259,11 +260,18 @@ export class LearningRuns {
|
|
|
259
260
|
if ("seed" in seeded) {
|
|
260
261
|
try {
|
|
261
262
|
const own = revision.kind === "agentic" ? Object.keys(revision.body.skills) : [];
|
|
262
|
-
|
|
263
|
+
// Its harness's requests going where a learned workflow's could not follow: it is offered none (fail closed).
|
|
264
|
+
const workflowsOff = revision.kind === "agentic" ? await learnedWorkflowsOff(revision.body.harness, this.hostEnv(), revision.body.model) : undefined;
|
|
265
|
+
const pin = await pinSeed(started.dir, started.workspace, seeded.seed, { budget: this.options.learningBudget ?? LEARNING_BUDGET, read, shown: this.shown(), own, ...(workflowsOff ? { workflowsOff } : {}) });
|
|
263
266
|
for (const path of seeded.seed.skipped)
|
|
264
267
|
warn(started.runId, `its learning folder's ${path} was not read`);
|
|
265
268
|
for (const name of pin.skills_left_out ?? [])
|
|
266
269
|
warn(started.runId, `starts without the skill ${name} its agent learned: it is over what is left of the learned skills' budget, or holds a secret`);
|
|
270
|
+
if (pin.workflows_off)
|
|
271
|
+
warn(started.runId, `starts without the workflows its agent learned (${(pin.workflows_left_out ?? []).join(", ")}): ${pin.workflows_off}`);
|
|
272
|
+
else
|
|
273
|
+
for (const name of pin.workflows_left_out ?? [])
|
|
274
|
+
warn(started.runId, `starts without the workflow ${name} its agent learned: its line is over what is left of the learned_workflow tool's description budget, or it holds a secret`);
|
|
267
275
|
}
|
|
268
276
|
catch (error) {
|
|
269
277
|
warn(started.runId, `starts with nothing learned: ${error.message}`);
|
|
@@ -438,7 +446,7 @@ export class LearningRuns {
|
|
|
438
446
|
* once and kept until a person saves or deletes one (keysChanged). */
|
|
439
447
|
shown() {
|
|
440
448
|
const saved = (this.saved ??= new Map(SECRET_NAMES.map((name) => [name, this.options.storedKeys?.(name)])));
|
|
441
|
-
const values = [...hostSecrets(process.env, (name) => saved.get(name)), this.options.token, this.options.doorToken];
|
|
449
|
+
const values = [...hostSecrets(process.env, (name) => saved.get(name)), this.options.token, this.options.doorToken, ...(this.options.ownSecrets?.() ?? [])];
|
|
442
450
|
const key = values.join("\0");
|
|
443
451
|
if (this.cut?.key !== key)
|
|
444
452
|
this.cut = { key, shown: secretsShown(values) };
|
|
@@ -585,8 +593,13 @@ export class LearningRuns {
|
|
|
585
593
|
const seed = await seedAt(this.options.agents.dir, run.agentId, pin.seed);
|
|
586
594
|
await this.kernel.save(run);
|
|
587
595
|
const { reflectPrompt } = await import("./learn/index.js");
|
|
588
|
-
const tools = await this.draftTools(run);
|
|
589
|
-
// The one call that sends the end-of-run turn, with its origin.
|
|
596
|
+
const { tools } = await this.draftTools(run);
|
|
597
|
+
// The one call that sends the end-of-run turn, with its origin. Only while the run is finishing with no outcome yet,
|
|
598
|
+
// read in the same tick the origin's write starts in (toLiveDoor writes it before its first await): a message
|
|
599
|
+
// waits while the run is finishing (runs.ts message), so a write starts only before that wait ends. One whose
|
|
600
|
+
// process went while this turn was made ready has its outcome already: it is asked nothing.
|
|
601
|
+
if (!run.finishing || run.outcome)
|
|
602
|
+
return;
|
|
590
603
|
await this.kernel.toLiveDoor(run, "/submit", { requestId: reflectId(run.id), content: reflectPrompt({ dir: LEARNED_DIR, active: Object.keys(seed.notes).length, tools }), whenBusy: "followUp" }, REFLECT_ORIGIN);
|
|
591
604
|
end = await this.reflectEnd(run, Date.parse(reflect.deadline));
|
|
592
605
|
}
|
|
@@ -664,14 +677,19 @@ export class LearningRuns {
|
|
|
664
677
|
return Promise.resolve();
|
|
665
678
|
return once(this.proposing, run.id, () => this.propose(run));
|
|
666
679
|
}
|
|
667
|
-
/** The tools a run's workflow draft may name: its revision's granted tools a workflow node runs here
|
|
668
|
-
*
|
|
680
|
+
/** The tools a run's workflow draft may name: its revision's granted tools a workflow's call node runs here that the
|
|
681
|
+
* gate allows, under the server's tool settings and the agent's own (tools.ts learnedDraftTools); `gated`, those set to
|
|
682
|
+
* ask or deny, which a draft that calls one is refused for. None for a revision not found, so a draft that names one is
|
|
683
|
+
* refused. */
|
|
669
684
|
async draftTools(run) {
|
|
670
685
|
const known = await this.options.agents.revision(run.agentId, run.revision);
|
|
671
686
|
if (known?.revision.kind !== "agentic")
|
|
672
|
-
return [];
|
|
673
|
-
const {
|
|
674
|
-
|
|
687
|
+
return { tools: [], gated: {} };
|
|
688
|
+
const [{ learnedDraftTools }, { permissionOf }, { readToolSettings }] = await Promise.all([import("./tools.js"), import("./tool-gate.js"), import("./tool-plane.js")]);
|
|
689
|
+
// The server's settings, beside the agent store, as the run's gate reads them, and the agent's own.
|
|
690
|
+
const server = readToolSettings(this.options.agents.dir).settings;
|
|
691
|
+
const agent = (known.revision.body.toolSettings ?? {});
|
|
692
|
+
return learnedDraftTools(known.revision.body.tools, (name) => permissionOf(name, server, agent));
|
|
675
693
|
}
|
|
676
694
|
async propose(run) {
|
|
677
695
|
try {
|
|
@@ -682,9 +700,10 @@ export class LearningRuns {
|
|
|
682
700
|
const { proposeRun } = await import("./propose.js");
|
|
683
701
|
// The secrets this server holds, wherever its launcher put them, the keys saved on it, what each launch handed the
|
|
684
702
|
// run, and its own tokens. How the job ended, before its end-of-run turn: only a completed run keeps a skill.
|
|
685
|
-
const proposed = await proposeRun({ data: this.options.agents.dir, agentId: run.agentId, runDir: run.dir, seed: pin.seed, turn: await readTurn(run.dir), refuse: this.refused(run), ...(run.meta.reflect ? { outcome: run.meta.reflect.outcome } : {}),
|
|
703
|
+
const proposed = await proposeRun({ data: this.options.agents.dir, agentId: run.agentId, runDir: run.dir, seed: pin.seed, turn: await readTurn(run.dir), refuse: this.refused(run), ...(run.meta.reflect ? { outcome: run.meta.reflect.outcome } : {}), ...(await this.draftTools(run)) });
|
|
704
|
+
// What the checks left out goes on with it (`problems`), to be said with what it learned.
|
|
686
705
|
if (proposed.state === "proposed")
|
|
687
|
-
this.setLearning(run, "proposed", null, said.proposed(proposed.notes, proposed.skills, proposed.workflows));
|
|
706
|
+
this.setLearning(run, "proposed", null, said.proposed(proposed.notes, proposed.skills, proposed.workflows), proposed.left ? { problems: proposed.left } : {});
|
|
688
707
|
else if (proposed.reason === "empty")
|
|
689
708
|
this.setLearning(run, "dropped", "empty", said.empty);
|
|
690
709
|
else if (proposed.reason === "unparsed") {
|
|
@@ -715,7 +734,9 @@ export class LearningRuns {
|
|
|
715
734
|
if (before?.state !== "proposed" || this.closing)
|
|
716
735
|
return;
|
|
717
736
|
const data = this.options.agents.dir;
|
|
718
|
-
|
|
737
|
+
// What the checks left out of the proposal (a verdict per item) stays with it to its end.
|
|
738
|
+
const checkedOut = before.problems?.length ? { problems: before.problems } : {};
|
|
739
|
+
let kept = before.verdict ? { ...checkedOut, verdict: before.verdict, graded: before.graded, cost_usd: before.cost_usd, tokens: before.tokens } : { ...checkedOut };
|
|
719
740
|
// Its end saved, and with it its line in the ledger, which carries what the grade spent (onSaved).
|
|
720
741
|
const end = (state, reason, detail, more = {}) => {
|
|
721
742
|
this.setLearning(run, state, reason, detail, { ...kept, ...more });
|
|
@@ -726,7 +747,7 @@ export class LearningRuns {
|
|
|
726
747
|
const known = await this.options.agents.revision(run.agentId, run.revision);
|
|
727
748
|
if (known?.revision.kind !== "agentic")
|
|
728
749
|
throw new Error("the run's revision is not agentic");
|
|
729
|
-
const { judgeProposal, mergeProposal, readForGrade } = await import("./grade.js");
|
|
750
|
+
const { judgeProposal, keptProposal, mergeProposal, readForGrade } = await import("./grade.js");
|
|
730
751
|
const main = kept.verdict ? undefined : await readForGrade(data, run.agentId, run.id, proposal);
|
|
731
752
|
// Main took a note of the same name, or superseded one it supersedes, since the run started: refused before the
|
|
732
753
|
// grader is asked.
|
|
@@ -737,9 +758,7 @@ export class LearningRuns {
|
|
|
737
758
|
const env = this.hostEnv();
|
|
738
759
|
const gradeModel = gradeModelOf(env, this.options.gradeModel);
|
|
739
760
|
const judged = await judgeProposal({ runId: run.id, agent: { instructions, harness, model, thinking }, main, proposed: proposal.notes, ...(proposal.files ? { files: proposal.files } : {}), ...(proposal.asked ? { asked: proposal.asked } : {}), ...(gradeModel ? { gradeModel } : {}), env, signal: this.stopping.signal, ...(this.options.gradeTimeoutMs ? { gradeTimeoutMs: this.options.gradeTimeoutMs } : {}) });
|
|
740
|
-
kept = { cost_usd: { grade: judged.cost.usd }, tokens: { grade: judged.cost.tokens } };
|
|
741
|
-
if ("file" in judged)
|
|
742
|
-
return await end("dropped", judged.reason, judged.reason === "screen" ? said.screen : said.stopped(STOPPED.screenDown));
|
|
761
|
+
kept = { ...checkedOut, cost_usd: { grade: judged.cost.usd }, tokens: { grade: judged.cost.tokens } };
|
|
743
762
|
if ("error" in judged) {
|
|
744
763
|
warn(run.id, `its grader gave no verdict: ${judged.error.message}`);
|
|
745
764
|
return await end("dropped", "grade_failed", said.stopped(STOPPED.noReview));
|
|
@@ -757,21 +776,24 @@ export class LearningRuns {
|
|
|
757
776
|
}
|
|
758
777
|
// A verdict kept with no `graded`: a note the proposal supersedes is refused, never marked on a text nobody knows
|
|
759
778
|
// was read.
|
|
760
|
-
|
|
779
|
+
// A verdict per item: what it keeps merges, what it drops is left out (keptProposal), and said.
|
|
780
|
+
const merging = keptProposal(proposal, kept.verdict);
|
|
781
|
+
const left = (kept.verdict?.items ?? []).filter((item) => !item.keep);
|
|
782
|
+
const merge = await mergeProposal(data, run.agentId, run.id, merging, kept.verdict?.reason || "The grader kept every new note.", kept.graded ?? {}, kept.verdict);
|
|
761
783
|
if ("problems" in merge)
|
|
762
784
|
return await end("dropped", "checker", said.stale(merge.problems), { problems: merge.problems });
|
|
763
785
|
if (merge.checkout)
|
|
764
786
|
warn(run.id, `its merge is on main, but the folder's files were not brought in line: ${merge.checkout.message}`);
|
|
765
787
|
// A note the user asked for whose rule is risky waits on main for their OK: named here, and no run reads it yet.
|
|
766
788
|
const waiting = new Set((kept.verdict?.items ?? []).filter((item) => item.pending).map((item) => item.file));
|
|
767
|
-
const pending =
|
|
789
|
+
const pending = merging.notes.filter(({ file }) => waiting.has(file)).map(({ file, text }) => ({ file, name: nameOf(file, text) }));
|
|
768
790
|
// What it learned: the notes it added that runs read, a note that waits for its OK not among them; and its skill
|
|
769
791
|
// and workflow draft, each pending when it waits.
|
|
770
|
-
const learned = learnedOf(
|
|
771
|
-
const made = (suffix) => (
|
|
792
|
+
const learned = learnedOf(merging).filter(({ file }) => !waiting.has(file));
|
|
793
|
+
const made = (suffix) => (merging.files ?? []).filter(({ file }) => file.endsWith(suffix)).map(({ file }) => ({ file, name: file.split("/")[1], ...(waiting.has(file) ? { pending: true } : {}) }));
|
|
772
794
|
const skills = made("/SKILL.md");
|
|
773
795
|
const workflows = made("/workflow.json");
|
|
774
|
-
await end("merged", null, redactSecrets(said.merged(learned, pending, [...skills, ...workflows]), this.refused(run)), { merged: merge.merged, learned, ...(pending.length ? { pending } : {}), ...(skills.length ? { skills } : {}), ...(workflows.length ? { workflows } : {}) });
|
|
796
|
+
await end("merged", null, redactSecrets(said.merged(learned, pending, [...skills, ...workflows], left, before.problems ?? []), this.refused(run)), { merged: merge.merged, learned, ...(pending.length ? { pending } : {}), ...(skills.length ? { skills } : {}), ...(workflows.length ? { workflows } : {}) });
|
|
775
797
|
}
|
|
776
798
|
catch (error) {
|
|
777
799
|
// A server closing: nothing was decided, and the next start grades the run.
|
|
@@ -786,7 +808,7 @@ export class LearningRuns {
|
|
|
786
808
|
refused(run) {
|
|
787
809
|
// The run's own door token too: its process holds it, so its notes may.
|
|
788
810
|
const own = run.doorToken ?? runDoorToken(run.dir);
|
|
789
|
-
return [...hostSecrets(process.env, this.options.storedKeys), ...(this.handed.get(run.id) ?? []), this.options.token, this.options.doorToken, ...(own ? [own] : [])];
|
|
811
|
+
return [...hostSecrets(process.env, this.options.storedKeys), ...(this.handed.get(run.id) ?? []), this.options.token, this.options.doorToken, ...(this.options.ownSecrets?.() ?? []), ...(own ? [own] : [])];
|
|
790
812
|
}
|
|
791
813
|
/** This server's environment for a call of its own (a grade's screen and grader): its secrets readable, never a
|
|
792
814
|
* child's, the keys saved on it with them (a Jev key saved through the settings API screens as one in the environment
|
package/dist/learning-words.d.ts
CHANGED
|
@@ -37,13 +37,16 @@ export declare const said: {
|
|
|
37
37
|
asked: string;
|
|
38
38
|
proposed: (notes: number, skills?: number, workflows?: number) => string;
|
|
39
39
|
/** What it learned, by name, and how many older notes they replace, and its skill and workflow by name; then what
|
|
40
|
-
* waits for the owner's OK, by name
|
|
40
|
+
* waits for the owner's OK, by name; then, when the grader dropped an item and kept others (a verdict per item), its
|
|
41
|
+
* word on the first it dropped. A merge that only holds things for the OK says that alone. */
|
|
41
42
|
merged: (learned: readonly {
|
|
42
43
|
name: string;
|
|
43
44
|
supersedes: readonly string[];
|
|
44
45
|
}[], pending?: readonly {
|
|
45
46
|
name: string;
|
|
46
|
-
}[], files?: readonly Pick<LearnedFile, "file" | "name" | "pending">[]
|
|
47
|
+
}[], files?: readonly Pick<LearnedFile, "file" | "name" | "pending">[], left?: readonly {
|
|
48
|
+
why: string;
|
|
49
|
+
}[], checked?: readonly Pick<Problem, "rule" | "path">[]) => string;
|
|
47
50
|
empty: string;
|
|
48
51
|
/** The run's answer gave its notes, but not in the format asked for, so none was read. */
|
|
49
52
|
unparsed: string;
|
|
@@ -70,4 +73,4 @@ export declare function notKept(verdict: Pick<Verdict, "reason" | "items">): str
|
|
|
70
73
|
* grader kept nothing, said again from its parts (`learned`, `pending`, `verdict`) each cut by `cut` first (the host's
|
|
71
74
|
* secrets as they are now); any other detail, the server's own sentence, cut as well. The caller cuts the words short
|
|
72
75
|
* after. */
|
|
73
|
-
export declare function wordsOf(learning: Pick<Learning, "state" | "reason" | "detail" | "learned" | "pending" | "verdict" | "skills" | "workflows">, cut: (text: string) => string): string | null;
|
|
76
|
+
export declare function wordsOf(learning: Pick<Learning, "state" | "reason" | "detail" | "learned" | "pending" | "verdict" | "skills" | "workflows" | "problems">, cut: (text: string) => string): string | null;
|
package/dist/learning-words.js
CHANGED
|
@@ -102,20 +102,23 @@ export const said = {
|
|
|
102
102
|
asked: "Looking back on this run.",
|
|
103
103
|
proposed: (notes, skills = 0, workflows = 0) => `Checking ${listed([...(notes || !(skills || workflows) ? [count(notes, "new note")] : []), ...(skills ? [count(skills, "skill")] : []), ...(workflows ? [count(workflows, "workflow")] : [])])}…`,
|
|
104
104
|
/** What it learned, by name, and how many older notes they replace, and its skill and workflow by name; then what
|
|
105
|
-
* waits for the owner's OK, by name
|
|
106
|
-
|
|
105
|
+
* waits for the owner's OK, by name; then, when the grader dropped an item and kept others (a verdict per item), its
|
|
106
|
+
* word on the first it dropped. A merge that only holds things for the OK says that alone. */
|
|
107
|
+
merged: (learned, pending = [], files = [], left = [], checked = []) => {
|
|
107
108
|
const flat = (name) => name.replace(/\s+/g, " ").trim();
|
|
108
109
|
const kind = (file) => `${file.file.startsWith("skills/") ? "skill" : "workflow"} ${flat(file.name)}`;
|
|
109
110
|
const held = [...pending.map((note) => flat(note.name)), ...files.filter((file) => file.pending).map(kind)];
|
|
110
111
|
const waiting = held.length ? `Waiting for your OK: ${held.join("; ")}.` : "";
|
|
111
112
|
const made = files.filter((file) => !file.pending).map(kind);
|
|
113
|
+
const dropped = [left.length ? said.grader(left[0].why) : "", checked.length ? said.checker(checked) : ""].filter(Boolean).join(" ");
|
|
112
114
|
if (!learned.length && !made.length)
|
|
113
|
-
return waiting;
|
|
115
|
+
return [waiting, dropped].filter(Boolean).join(" ");
|
|
114
116
|
const names = learned.map((note) => flat(note.name));
|
|
115
117
|
const replaced = learned.reduce((n, note) => n + note.supersedes.length, 0);
|
|
116
118
|
const notes = names.length ? `${names.length === 1 ? `Learned: ${names[0]}` : `Learned ${names.length} notes: ${names.join("; ")}`}${replaced ? ` (replaces ${count(replaced, "older note")})` : ""}` : "";
|
|
117
119
|
const kept = [notes, made.length ? `${notes ? "Also learned" : "Learned"} ${listed(made.map((made) => `the ${made}`))}` : ""].filter(Boolean).join(". ");
|
|
118
|
-
|
|
120
|
+
const base = waiting ? `${kept}. ${waiting}` : kept;
|
|
121
|
+
return dropped ? `${base}${base.endsWith(".") ? "" : "."} ${dropped}` : base;
|
|
119
122
|
},
|
|
120
123
|
empty: "Nothing new to remember from this run.",
|
|
121
124
|
/** The run's answer gave its notes, but not in the format asked for, so none was read. */
|
|
@@ -163,7 +166,7 @@ export function wordsOf(learning, cut) {
|
|
|
163
166
|
const waiting = Array.isArray(pending) ? pending.filter((note) => typeof note?.name === "string") : [];
|
|
164
167
|
const files = [...(Array.isArray(learning.skills) ? learning.skills : []), ...(Array.isArray(learning.workflows) ? learning.workflows : [])].filter((file) => typeof file?.file === "string" && typeof file.name === "string");
|
|
165
168
|
if (kept.length || waiting.length || files.length)
|
|
166
|
-
return said.merged(kept.map((note) => ({ name: cut(note.name), supersedes: note.supersedes })), waiting.map((note) => ({ name: cut(note.name) })), files.map((file) => ({ file: file.file, name: cut(file.name), ...(file.pending ? { pending: true } : {}) })));
|
|
169
|
+
return said.merged(kept.map((note) => ({ name: cut(note.name), supersedes: note.supersedes })), waiting.map((note) => ({ name: cut(note.name) })), files.map((file) => ({ file: file.file, name: cut(file.name), ...(file.pending ? { pending: true } : {}) })), (verdict?.items ?? []).filter((item) => !item.keep && typeof item.why === "string").map((item) => ({ why: cut(item.why) })), Array.isArray(learning.problems) ? learning.problems : []);
|
|
167
170
|
}
|
|
168
171
|
if (learning.state === "dropped" && learning.reason === "grader" && verdict)
|
|
169
172
|
return notKept({ reason: cut(verdict.reason), items: (verdict.items ?? []).map((item) => ({ ...item, why: cut(item.why) })) });
|
package/dist/learning.d.ts
CHANGED
|
@@ -153,7 +153,7 @@ export declare const shortLearning: (learning: Learning | null, shown: Shown, se
|
|
|
153
153
|
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;
|
|
154
154
|
detail: string | null;
|
|
155
155
|
at: string;
|
|
156
|
-
}, "at" | "
|
|
156
|
+
}, "at" | "state" | "reason" | "detail">) | null;
|
|
157
157
|
/** A run's learning as its view shows it, in short for a list: all of it but its time, its detail cut short. */
|
|
158
158
|
export declare function shortOf<T extends {
|
|
159
159
|
state: LearningState;
|
|
@@ -164,7 +164,7 @@ export declare function shortOf<T extends {
|
|
|
164
164
|
state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
|
|
165
165
|
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;
|
|
166
166
|
detail: string | null;
|
|
167
|
-
} & Omit<T, "at" | "
|
|
167
|
+
} & Omit<T, "at" | "state" | "reason" | "detail">;
|
|
168
168
|
/** The label of the end-of-run turn's timeline rows, and the kind and label of a run's learning row. */
|
|
169
169
|
export declare const LEARNING_LABEL = "learning";
|
|
170
170
|
/** A run's proposal, in its directory (propose.ts): the seed it was checked against, each new note's file and text, its
|
|
@@ -198,13 +198,21 @@ export type Turn = {
|
|
|
198
198
|
/** What a run's pin holds: the commit of main it was seeded from, and what it reads under `# Learned` (learnedOf), when
|
|
199
199
|
* it learned anything. `learned`, the index alone, is a pin an earlier server wrote, read as that server gave it.
|
|
200
200
|
* `skills`: the files of the learned skills laid in its work, by their paths under `.agents/skills/`, as a revision
|
|
201
|
-
* names its own; `skills_left_out`: the learned skills it does not get, over their budget or holding a secret.
|
|
201
|
+
* names its own; `skills_left_out`: the learned skills it does not get, over their budget or holding a secret.
|
|
202
|
+
* `workflows`: the names of the learned workflows the run may run (its `learned_workflow` tool), each written whole in
|
|
203
|
+
* LEARNED_WORKFLOWS_FILE in the run's directory, outside its work; `workflows_left_out`: the learned workflows it does
|
|
204
|
+
* not get, their lines over what is left of the tool's description budget (LEARNED_WORKFLOWS_BUDGET), or holding a
|
|
205
|
+
* secret, or every one when `workflows_off` says why the run is offered none (its harness's requests go where a learned
|
|
206
|
+
* workflow's could not follow: learnedWorkflowsOff). */
|
|
202
207
|
export type Pin = {
|
|
203
208
|
seed: string;
|
|
204
209
|
section?: string;
|
|
205
210
|
learned?: string;
|
|
206
211
|
skills?: string[];
|
|
207
212
|
skills_left_out?: string[];
|
|
213
|
+
workflows?: string[];
|
|
214
|
+
workflows_left_out?: string[];
|
|
215
|
+
workflows_off?: string;
|
|
208
216
|
};
|
|
209
217
|
/** What a run is seeded from: main's commit, its index and its active notes by file, and the name of every entry at its
|
|
210
218
|
* top. `skipped` names what was there and not read. `recent`, when seedOf read it: the active notes' files, the one
|
|
@@ -218,7 +226,23 @@ export type Seed = {
|
|
|
218
226
|
skipped: string[];
|
|
219
227
|
recent?: string[];
|
|
220
228
|
skills?: LearnedSkill[];
|
|
229
|
+
workflows?: LearnedWorkflow[];
|
|
221
230
|
};
|
|
231
|
+
/** A workflow the agent learned, as a run may run it: its name, the line its README says what it does with, and its
|
|
232
|
+
* workflow.json whole. */
|
|
233
|
+
export type LearnedWorkflow = {
|
|
234
|
+
name: string;
|
|
235
|
+
description: string;
|
|
236
|
+
workflow: string;
|
|
237
|
+
};
|
|
238
|
+
/** Where a run keeps the learned workflows its pin names, whole: in the run's directory, beside its pin, never in its
|
|
239
|
+
* work, so nothing the run does changes what its `learned_workflow` tool runs. */
|
|
240
|
+
export declare const LEARNED_WORKFLOWS_FILE = "learned-workflows.json";
|
|
241
|
+
/** The most bytes the `learned_workflow` tool's description gives its workflows, each one's line (workflowLine)
|
|
242
|
+
* together: every harness sends the description with each request, so it never grows with what an agent learned. */
|
|
243
|
+
export declare const LEARNED_WORKFLOWS_BUDGET: number;
|
|
244
|
+
/** A learned workflow's line in the `learned_workflow` tool's description: its name, and what its README says it does. */
|
|
245
|
+
export declare const workflowLine: ({ name, description }: Pick<LearnedWorkflow, "name" | "description">) => string;
|
|
222
246
|
/** The most bytes of learned skills one run gets, every file of each together. They get no more than what the
|
|
223
247
|
* revision's own skills leave of the adapters' cap on a run's skills in all (SKILL_BYTES): over that cap an adapter
|
|
224
248
|
* refuses the whole set, and every skill, the revision's too, would be inlined in the prompt (skills.ts splitSkills). */
|
|
@@ -292,6 +316,19 @@ export declare function readSkills(cwd: string, repo: string, sha: string): Prom
|
|
|
292
316
|
skills: LearnedSkill[];
|
|
293
317
|
skipped: string[];
|
|
294
318
|
}>;
|
|
319
|
+
/** The workflows commit `sha` holds under WORKFLOWS_DIR, read with plumbing, by name: each a folder with a workflow.json
|
|
320
|
+
* 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
|
|
321
|
+
* active one is a run's, by the rule a skill is (readSkills): its README.md sets no status, or `active`; one held for
|
|
322
|
+
* its owner's OK, or retired, is left out. A symbolic link or a submodule under WORKFLOWS_DIR throws. */
|
|
323
|
+
export declare function readWorkflows(cwd: string, repo: string, sha: string): Promise<{
|
|
324
|
+
workflows: LearnedWorkflow[];
|
|
325
|
+
skipped: string[];
|
|
326
|
+
}>;
|
|
327
|
+
/** A learned workflow README's front matter, each key to its value (quotes dropped; a `>` or `|` value's indented lines
|
|
328
|
+
* joined by spaces), or undefined when it does not read one way: no front matter, none closed (`---` on a line of its
|
|
329
|
+
* 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
|
|
330
|
+
* `|` value, or a key set twice. */
|
|
331
|
+
export declare function readmeFront(text: string): Map<string, string> | undefined;
|
|
295
332
|
/** Each file's place in main's first-parent log from `sha`, by the newest commit that changed it: 0 for those the newest
|
|
296
333
|
* commit changed, and so on, so two changes in one second keep their order. A run's notes (seedOf) and a person's view
|
|
297
334
|
* of them (learning-routes.ts) are in this order, the one changed last first. */
|
|
@@ -335,6 +372,7 @@ export type LearnedOptions = {
|
|
|
335
372
|
budget: number;
|
|
336
373
|
read: boolean;
|
|
337
374
|
shown: Shown;
|
|
375
|
+
workflowsOff?: string;
|
|
338
376
|
};
|
|
339
377
|
/** What a run of `seed` reads under `# Learned`, the same for every harness, or undefined when it learned nothing. Only
|
|
340
378
|
* active notes are served: a pending, superseded or retired one is never there, whole or in the index, nor counted
|
|
@@ -375,3 +413,6 @@ export declare function withLearned(runDir: string, work: string, instructions:
|
|
|
375
413
|
instructions: string;
|
|
376
414
|
skills: string[];
|
|
377
415
|
}>;
|
|
416
|
+
/** The learned workflows a run's pin names, as its directory keeps them (LEARNED_WORKFLOWS_FILE): none when the pin
|
|
417
|
+
* names none. A file that is not the list the pin names throws. */
|
|
418
|
+
export declare function pinnedWorkflows(runDir: string, pin: Pin | undefined): Promise<LearnedWorkflow[]>;
|