@parcha/agentrun-serve 0.1.0-beta.51 → 0.1.0-beta.53
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 +160 -1
- package/README.md +306 -36
- package/dist/adapters.js +1 -1
- package/dist/agent-delete.d.ts +14 -4
- package/dist/agent-delete.js +30 -58
- package/dist/agent-package.d.ts +71 -0
- package/dist/agent-package.js +345 -0
- package/dist/agents-store.d.ts +28 -18
- package/dist/agents-store.js +48 -34
- package/dist/api-only.d.ts +30 -8
- package/dist/api-only.js +40 -16
- package/dist/archil-routes.d.ts +1 -0
- package/dist/archil-routes.js +28 -2
- package/dist/claude-login.d.ts +1 -0
- package/dist/claude-login.js +1 -1
- package/dist/cli-learning/cli.d.ts +3 -0
- package/dist/cli-learning/cli.js +17 -3
- package/dist/cli-learning/connections.js +3 -2
- package/dist/cli-learning/schema.js +2 -1
- package/dist/cli.js +70 -7
- package/dist/composio-preset.d.ts +2 -1
- package/dist/composio-preset.js +4 -3
- package/dist/composio-triggers.d.ts +4 -0
- package/dist/composio-triggers.js +4 -1
- package/dist/computer-needs.d.ts +32 -0
- package/dist/computer-needs.js +80 -0
- package/dist/computer-setting.d.ts +9 -0
- package/dist/computer-setting.js +19 -1
- package/dist/computers.d.ts +6 -2
- package/dist/computers.js +2 -2
- package/dist/console/assets/index-BFgyZzF_.js +734 -0
- package/dist/console/assets/index-DbilxljH.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.d.ts +1 -0
- package/dist/console-links.js +2 -0
- package/dist/env-switch.d.ts +14 -0
- package/dist/env-switch.js +23 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +3 -0
- package/dist/eval-previous.js +4 -3
- package/dist/fal-price.d.ts +76 -0
- package/dist/fal-price.js +365 -0
- package/dist/handed-secret.d.ts +4 -0
- package/dist/handed-secret.js +10 -0
- package/dist/harness-archive.d.ts +15 -5
- package/dist/harness-archive.js +71 -34
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +36 -95
- package/dist/harness-egress.d.ts +23 -0
- package/dist/harness-egress.js +69 -0
- package/dist/harness-recipe-entry.d.ts +71 -0
- package/dist/harness-recipe-entry.js +184 -0
- package/dist/harness-recipe.d.ts +73 -6
- package/dist/harness-recipe.js +185 -31
- package/dist/harness-sign-in.d.ts +29 -0
- package/dist/harness-sign-in.js +122 -0
- package/dist/harness-table.d.ts +21 -0
- package/dist/harness-table.js +58 -3
- package/dist/harness-zip.d.ts +6 -0
- package/dist/harness-zip.js +203 -0
- package/dist/ids.d.ts +11 -0
- package/dist/ids.js +36 -0
- package/dist/learn/commit.d.ts +19 -1
- package/dist/learn/commit.js +160 -2
- package/dist/learn/compile.d.ts +13 -5
- package/dist/learn/compile.js +46 -15
- package/dist/learn/delete.d.ts +12 -6
- package/dist/learn/delete.js +17 -11
- package/dist/learn/folder.d.ts +16 -0
- package/dist/learn/folder.js +30 -4
- package/dist/learn/learning-of.d.ts +8 -0
- package/dist/learn/learning-of.js +8 -0
- package/dist/learn/learning.sh +29 -4
- package/dist/learn/promote.d.ts +51 -7
- package/dist/learn/promote.js +51 -8
- package/dist/learn/secrets.js +30 -7
- package/dist/learning-reset.d.ts +18 -0
- package/dist/learning-reset.js +115 -0
- package/dist/learning-routes.d.ts +23 -11
- package/dist/learning-routes.js +110 -20
- package/dist/learning-words.d.ts +5 -0
- package/dist/learning-words.js +5 -0
- package/dist/learning.d.ts +15 -10
- package/dist/learning.js +14 -8
- package/dist/llms.txt +1 -0
- package/dist/mcp-gateway.d.ts +39 -2
- package/dist/mcp-gateway.js +56 -12
- package/dist/mcp-pin-first.js +1 -1
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +7 -2
- package/dist/mcp-resources.d.ts +44 -0
- package/dist/mcp-resources.js +100 -0
- package/dist/mcp-servers-store.d.ts +17 -12
- package/dist/mcp-servers-store.js +2 -1
- package/dist/media-duration.d.ts +2 -0
- package/dist/media-duration.js +136 -0
- package/dist/model.d.ts +4 -4
- package/dist/model.js +6 -6
- package/dist/native/cli.js +9 -2
- package/dist/native/connection.d.ts +2 -2
- package/dist/native/connection.js +5 -2
- package/dist/native/discovery.d.ts +2 -0
- package/dist/native/discovery.js +10 -6
- package/dist/native/remote-worker-bridge.js +36 -4
- package/dist/native/remote.d.ts +18 -1
- package/dist/native/remote.js +126 -37
- package/dist/native/schema.d.ts +6 -0
- package/dist/native/schema.js +31 -6
- package/dist/native/source-account.d.ts +13 -0
- package/dist/native/source-account.js +114 -0
- package/dist/native/source-capture-hooks.d.ts +5 -0
- package/dist/native/source-capture-hooks.js +102 -0
- package/dist/native/source-mcp-selection.d.ts +13 -0
- package/dist/native/source-mcp-selection.js +72 -0
- package/dist/native/source-runtime-tools.d.ts +19 -0
- package/dist/native/source-runtime-tools.js +103 -0
- package/dist/native/source-snapshot-types.d.ts +138 -0
- package/dist/native/source-snapshot-types.js +12 -0
- package/dist/native/source-snapshot.d.ts +8 -0
- package/dist/native/source-snapshot.js +1201 -0
- package/dist/observation/learning.js +3 -2
- package/dist/openapi.js +211 -47
- package/dist/print.js +1 -1
- package/dist/provider.d.ts +8 -0
- package/dist/provider.js +14 -2
- package/dist/purged-workflow.d.ts +12 -0
- package/dist/purged-workflow.js +43 -0
- package/dist/refusal-words.d.ts +0 -3
- package/dist/refusal-words.js +0 -3
- package/dist/request-metadata.d.ts +20 -0
- package/dist/request-metadata.js +24 -0
- package/dist/run-keys.d.ts +46 -0
- package/dist/run-keys.js +109 -0
- package/dist/run-launch.d.ts +29 -5
- package/dist/run-launch.js +44 -4
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-model-key.d.ts +2 -2
- package/dist/run-model-key.js +5 -5
- package/dist/run-secrets.d.ts +2 -0
- package/dist/run-secrets.js +7 -4
- package/dist/run-usage.d.ts +48 -4
- package/dist/run-usage.js +156 -39
- package/dist/run-view.d.ts +18 -1
- package/dist/run-view.js +28 -8
- package/dist/runner/adapter-loop.d.ts +14 -4
- package/dist/runner/adapter-loop.js +150 -31
- package/dist/runner/adapter-run-spec.d.ts +1 -1
- package/dist/runner/adapter-run-spec.js +35 -22
- package/dist/runner/audit.d.ts +10 -3
- package/dist/runner/audit.js +30 -7
- package/dist/runner/beside.js +2 -1
- package/dist/runner/claim-secrets.d.ts +31 -4
- package/dist/runner/claim-secrets.js +43 -7
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +32 -20
- package/dist/runner/conformance/harness.js +4 -2
- package/dist/runner/dispatch.js +4 -2
- package/dist/runner/harness-loops.d.ts +6 -0
- package/dist/runner/harness-loops.js +16 -3
- package/dist/runner/held.d.ts +4 -0
- package/dist/runner/journal-kinds.d.ts +5 -0
- package/dist/runner/learned-first.d.ts +2 -0
- package/dist/runner/learned-first.js +1 -1
- package/dist/runner/learning-end.d.ts +9 -3
- package/dist/runner/learning-end.js +66 -29
- package/dist/runner/learning-seed.d.ts +9 -3
- package/dist/runner/learning-seed.js +2 -2
- package/dist/runner/main.d.ts +1 -0
- package/dist/runner/main.js +20 -13
- package/dist/runner/mcp-claim.js +7 -2
- package/dist/runner/mcp-run.d.ts +12 -0
- package/dist/runner/mcp-run.js +14 -1
- package/dist/runner/model-route.js +7 -4
- package/dist/runner/monid-run.js +9 -11
- package/dist/runner/project-checkpoint.d.ts +35 -0
- package/dist/runner/project-checkpoint.js +116 -0
- package/dist/runner/project-drain.d.ts +8 -0
- package/dist/runner/project-drain.js +25 -0
- package/dist/runner/project-host.d.ts +10 -0
- package/dist/runner/project-host.js +52 -0
- package/dist/runner/promotion.d.ts +51 -24
- package/dist/runner/promotion.js +206 -78
- package/dist/runner/redact.d.ts +13 -0
- package/dist/runner/redact.js +67 -1
- package/dist/runner/run-channel.d.ts +9 -0
- package/dist/runner/run-channel.js +15 -2
- package/dist/runner/run-child-host.d.ts +8 -4
- package/dist/runner/run-child-host.js +174 -42
- package/dist/runner/run-errors.js +2 -2
- package/dist/runner/runner-check.js +5 -2
- package/dist/runner/runner.js +41 -12
- package/dist/runner/sdk-loop.d.ts +2 -2
- package/dist/runner/sdk-loop.js +3 -3
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/store-secrets.js +7 -3
- package/dist/runner/workflow-first.d.ts +4 -0
- package/dist/runner/workflow-first.js +13 -0
- package/dist/runner/workflow-loop.d.ts +2 -1
- package/dist/runner/workflow-loop.js +2 -1
- package/dist/runner/workflow-spec.js +4 -4
- package/dist/runs-over-store.d.ts +39 -8
- package/dist/runs-over-store.js +147 -32
- package/dist/sdk/check.d.ts +6 -5
- package/dist/sdk/check.js +17 -16
- package/dist/sdk/runs.d.ts +11 -1
- package/dist/sdk/runs.js +185 -78
- package/dist/sdk/schema.js +12 -2
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/server.d.ts +68 -32
- package/dist/server.js +678 -124
- package/dist/skills/agentrun-serve/SKILL.md +2 -1
- package/dist/source-sync/adoption.d.ts +15 -0
- package/dist/source-sync/adoption.js +36 -0
- package/dist/source-sync/auxiliary.d.ts +23 -0
- package/dist/source-sync/auxiliary.js +64 -0
- package/dist/source-sync/capture-git.d.ts +5 -0
- package/dist/source-sync/capture-git.js +272 -0
- package/dist/source-sync/capture-project.d.ts +53 -0
- package/dist/source-sync/capture-project.js +206 -0
- package/dist/source-sync/capture-refusal.d.ts +7 -0
- package/dist/source-sync/capture-refusal.js +16 -0
- package/dist/source-sync/capture.d.ts +11 -0
- package/dist/source-sync/capture.js +22 -0
- package/dist/source-sync/checkpoint-gate.d.ts +21 -0
- package/dist/source-sync/checkpoint-gate.js +52 -0
- package/dist/source-sync/checkpoints.d.ts +66 -0
- package/dist/source-sync/checkpoints.js +168 -0
- package/dist/source-sync/claim.d.ts +11 -0
- package/dist/source-sync/claim.js +48 -0
- package/dist/source-sync/destination.d.ts +47 -0
- package/dist/source-sync/destination.js +239 -0
- package/dist/source-sync/io.d.ts +15 -0
- package/dist/source-sync/io.js +52 -0
- package/dist/source-sync/local.d.ts +43 -0
- package/dist/source-sync/local.js +229 -0
- package/dist/source-sync/prepare.d.ts +59 -0
- package/dist/source-sync/prepare.js +93 -0
- package/dist/source-sync/projects.d.ts +61 -0
- package/dist/source-sync/projects.js +130 -0
- package/dist/source-sync/registry.d.ts +95 -0
- package/dist/source-sync/registry.js +226 -0
- package/dist/source-sync/service.d.ts +33 -0
- package/dist/source-sync/service.js +118 -0
- package/dist/source-sync/skill-edits.d.ts +12 -0
- package/dist/source-sync/skill-edits.js +122 -0
- package/dist/source-sync/snapshots.d.ts +48 -0
- package/dist/source-sync/snapshots.js +448 -0
- package/dist/source-sync/types.d.ts +9 -0
- package/dist/source-sync/types.js +14 -0
- package/dist/source-sync/workspace.d.ts +66 -0
- package/dist/source-sync/workspace.js +273 -0
- package/dist/store/agent-body.d.ts +8 -0
- package/dist/store/agent-body.js +20 -6
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.d.ts +2 -0
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
- package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
- package/dist/store/schema.d.ts +15 -1
- package/dist/store/schema.js +43 -4
- package/dist/store/seal.d.ts +5 -1
- package/dist/store/seal.js +12 -3
- package/dist/store/sqlite/project-checkpoints.d.ts +11 -0
- package/dist/store/sqlite/project-checkpoints.js +70 -0
- package/dist/store/sqlite/run-launch.d.ts +14 -0
- package/dist/store/sqlite/run-launch.js +58 -7
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +4 -3
- package/dist/store/sqlite/store.js +319 -153
- package/dist/store/store-schema.js +2 -2
- package/dist/store/store.d.ts +173 -33
- package/dist/store/store.js +14 -1
- package/dist/store-reads/learning.d.ts +12 -8
- package/dist/store-reads/learning.js +33 -24
- package/dist/store-reads/loop.d.ts +4 -3
- package/dist/store-reads/loop.js +7 -5
- package/dist/store-view.d.ts +3 -1
- package/dist/store-view.js +17 -5
- package/dist/template-eval.js +4 -4
- package/dist/template-import.d.ts +10 -2
- package/dist/template-import.js +116 -13
- package/dist/templates.d.ts +29 -5
- package/dist/templates.js +68 -14
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/labels.js +1 -1
- package/dist/timeline/timeline.d.ts +5 -0
- package/dist/timeline/timeline.js +8 -0
- package/dist/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +8 -8
- package/dist/tools.js +1 -1
- package/dist/trigger-launch-hook.d.ts +47 -0
- package/dist/trigger-launch-hook.js +90 -0
- package/dist/trigger-targets.d.ts +14 -1
- package/dist/trigger-targets.js +20 -0
- package/dist/triggers.d.ts +54 -5
- package/dist/triggers.js +143 -8
- package/dist/uploads-archil.js +2 -1
- package/dist/uploads.d.ts +0 -3
- package/dist/uploads.js +2 -11
- package/dist/validate.js +4 -1
- package/dist/web-save.d.ts +3 -0
- package/dist/web-save.js +17 -2
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.js +1 -1
- package/dist/workspace/computer-for-claim.d.ts +2 -0
- package/dist/workspace/computer-for-claim.js +43 -0
- package/dist/workspace/paths.d.ts +6 -0
- package/dist/workspace/paths.js +6 -0
- package/dist/workspace/resolve-computer.d.ts +1 -0
- package/dist/workspace/revision-skills.js +24 -11
- package/dist/workspace/run-tools.d.ts +2 -0
- package/dist/workspace/run-tools.js +8 -0
- package/dist/workspace/synced-folder.d.ts +3 -3
- package/dist/workspace/synced-folder.js +7 -6
- package/launcher/agentrun-serve +1 -1
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +2 -1
- package/templates/README.md +5 -2
- package/dist/console/assets/index-Bt1B51b7.js +0 -733
- package/dist/console/assets/index-sVftE9Ht.css +0 -1
package/dist/learning-routes.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { CORRECTIONS_CAP, draftProblems, frontKeys, isHeld, LEARNED_KEYS, learnedPlace, learnedStatus, printable, released, restorable, restoredLearned, retiredLearned, UNCLEAR_FRONT, unclearFront, unstorable, WORKFLOW_NAME, WORKFLOWS_DIR } from "./learn/index.js";
|
|
3
3
|
import { readmeProblems } from "./learn/workflow-draft.js";
|
|
4
|
-
import { putCorrections, readCorrections } from "./learn/commit.js";
|
|
5
|
-
import { blobOid, FolderBusy, FolderRefused, FolderTooLarge, FolderUnreadable, readLearning, PATCH_CAP, readRunDiff, readSnapshot, runDiffKey, textsAt, writeLearning } from "./learn/folder.js";
|
|
4
|
+
import { forgetRunText, putCorrections, readCorrections } from "./learn/commit.js";
|
|
5
|
+
import { blobOid, FolderBusy, FolderRefused, FolderTooLarge, FolderUnreadable, readLearning, PATCH_CAP, readRunDiff, readSnapshot, runDiffKey, snapshotAt, textsAt, writeLearning } from "./learn/folder.js";
|
|
6
|
+
import { purgedRun, purgedWorkflows } from "./purged-workflow.js";
|
|
6
7
|
import { ApiError, invalid } from "./errors.js";
|
|
7
8
|
import { detailShown, filesView, learningFolderOf, reasonShown, withAgentRepo } from "./learning.js";
|
|
8
9
|
import { isObject } from "./validate.js";
|
|
@@ -49,6 +50,30 @@ function routeFailure(error) {
|
|
|
49
50
|
return error.link ? new Error(error.message) : new ApiError("unavailable", error.message);
|
|
50
51
|
return error;
|
|
51
52
|
}
|
|
53
|
+
/** Whether a change of `snapshot`'s log is served: none by a purged run (a run's purge, agent-delete.ts purgeRun), so
|
|
54
|
+
* the folder's history reads serve none of its merges. Asked at each read, so a log the folder rebuilds names them and
|
|
55
|
+
* still serves none. */
|
|
56
|
+
async function servedIn(snapshot, purgedOf) {
|
|
57
|
+
const runs = [...new Set(snapshot.log.flatMap(({ by }) => ("run" in by ? [by.run] : [])))];
|
|
58
|
+
const purged = runs.length ? await purgedOf(runs) : new Set();
|
|
59
|
+
return ({ by }) => !("run" in by && purged.has(by.run));
|
|
60
|
+
}
|
|
61
|
+
/** Run `runId`'s text taken off agent `agentId`'s learning folder's current files at its purge (learn/commit.ts
|
|
62
|
+
* forgetRunText), in the agent's queue, as every write of the folder is. */
|
|
63
|
+
export async function forgetRunLearning(data, agentId, runId) {
|
|
64
|
+
await withAgentRepo(data, agentId, async () => {
|
|
65
|
+
const { workspace: ws, end } = learningFolderOf(data, agentId);
|
|
66
|
+
try {
|
|
67
|
+
await forgetRunText(ws, runId);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
throw routeFailure(error);
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
await end();
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
52
77
|
/** A read of agent `agentId`'s folder: `read` over its snapshot and the bodies it names (learn/folder.ts readLearning),
|
|
53
78
|
* `none` for a folder with no main yet; the folder ended after. */
|
|
54
79
|
async function reading(data, agentId, read, none) {
|
|
@@ -110,7 +135,18 @@ function pageAt(agentId, snapshot, at) {
|
|
|
110
135
|
return kept ? { snapshot: kept, offset: at.offset } : { snapshot, offset: 0 };
|
|
111
136
|
}
|
|
112
137
|
/** A page of the changes on main, newest first, cut of the host's secrets. */
|
|
113
|
-
|
|
138
|
+
/** `served` changes only: the offset and the cursor count the log as the snapshot keeps it, so a run purged between two
|
|
139
|
+
* pages moves no change the next page starts at. */
|
|
140
|
+
function logPage(snapshot, offset, limit, shown, served) {
|
|
141
|
+
const { log } = snapshot;
|
|
142
|
+
const items = [];
|
|
143
|
+
let at = offset;
|
|
144
|
+
for (; at < log.length && items.length < limit; at++)
|
|
145
|
+
if (served(log[at]))
|
|
146
|
+
items.push(changeView(log[at], shown));
|
|
147
|
+
const more = log.slice(at).some(served);
|
|
148
|
+
return { items, total: log.filter(served).length, next_cursor: more ? cursorOf(snapshot.main, at) : null };
|
|
149
|
+
}
|
|
114
150
|
/** For tests: how many times a folder's statuses were read (once per commit of its main). */
|
|
115
151
|
export const pendingTestHooks = { reads: 0 };
|
|
116
152
|
/** By agent: its folder's main commit and each draft's status there. */
|
|
@@ -146,21 +182,23 @@ export async function pendingCount(data, agentId) {
|
|
|
146
182
|
const status = await statusesOf(data, agentId);
|
|
147
183
|
return status === undefined ? undefined : [...status.values()].filter((value) => value.status === "pending").length;
|
|
148
184
|
}
|
|
149
|
-
export async function agentLearning(data, agentId, shown, counts, impact, stateOf) {
|
|
185
|
+
export async function agentLearning(data, agentId, shown, counts, impact, stateOf, purgedOf) {
|
|
150
186
|
return reading(data, agentId, async ({ snapshot, body }) => {
|
|
187
|
+
const served = await servedIn(snapshot, purgedOf);
|
|
151
188
|
const corrections = (await readCorrections(snapshot, body)).text;
|
|
152
189
|
// A retired draft whose README.md can't be read is said so (unclearFront), read from its file now, as the snapshot's
|
|
153
190
|
// status was: a few retired items, one read each.
|
|
154
191
|
const unread = async (item) => item.status === "retired" && unclearFront(await body(item.file, item.oid));
|
|
155
|
-
return { agent: agentId, main: snapshot.main, corrections: shown.text(corrections), workflows: await Promise.all(snapshot.workflows.map(async (item) => workflowView(item, shown, stateOf, await unread(item)))), log: logPage(snapshot, 0, LOG_PAGE, shown), counts, impact };
|
|
192
|
+
return { agent: agentId, main: snapshot.main, corrections: shown.text(corrections), workflows: await Promise.all(snapshot.workflows.map(async (item) => workflowView(item, shown, stateOf, await unread(item)))), log: logPage(snapshot, 0, LOG_PAGE, shown, served), counts, impact };
|
|
156
193
|
}, () => ({ agent: agentId, main: null, corrections: "", workflows: [], log: EMPTY, counts, impact }));
|
|
157
194
|
}
|
|
158
|
-
/** GET /agents/{id}/learning/log?cursor=&limit=: a page of the changes on main, newest first
|
|
159
|
-
|
|
195
|
+
/** GET /agents/{id}/learning/log?cursor=&limit=: a page of the changes on main, newest first, a purged run's left out
|
|
196
|
+
* (`purgedOf`). */
|
|
197
|
+
export async function learningLog(data, agentId, query, shown, purgedOf) {
|
|
160
198
|
const { limit, at } = pageRequest(query, LOG_PAGE);
|
|
161
199
|
return reading(data, agentId, async ({ snapshot }) => {
|
|
162
200
|
const page = pageAt(agentId, snapshot, at);
|
|
163
|
-
return logPage(page.snapshot, page.offset, limit, shown);
|
|
201
|
+
return logPage(page.snapshot, page.offset, limit, shown, await servedIn(page.snapshot, purgedOf));
|
|
164
202
|
}, () => EMPTY);
|
|
165
203
|
}
|
|
166
204
|
/** GET /agents/{id}/learning/corrections: corrections.md on main as text (empty when main holds none), its ETag (its blob
|
|
@@ -206,8 +244,9 @@ const REVISIONS_DEFAULT = 20;
|
|
|
206
244
|
* commits on main's log that changed `workflows/<name>/workflow.json`), oldest first, each with the workflow's text at
|
|
207
245
|
* that commit, so a person can step through how it changed. One read-only exec per revision (textsAt), at most `limit`
|
|
208
246
|
* of them. `total` counts every such commit the log holds, `truncated` says the log itself is cut (it keeps the latest
|
|
209
|
-
* LOG_KEEP changes). A workflow no commit of the log changed is
|
|
210
|
-
|
|
247
|
+
* LOG_KEEP changes). A purged run's merge is no revision (`purgedOf`). A workflow no commit of the log changed is
|
|
248
|
+
* not_found. */
|
|
249
|
+
export async function workflowRevisions(data, agentId, name, query, shown, purgedOf) {
|
|
211
250
|
if (!WORKFLOW_NAME.test(name))
|
|
212
251
|
throw new ApiError("bad_request", "A workflow's folder is named with lowercase letters, digits, dashes and underscores.");
|
|
213
252
|
const given = query.get("limit");
|
|
@@ -218,7 +257,8 @@ export async function workflowRevisions(data, agentId, name, query, shown) {
|
|
|
218
257
|
if (shown.name(path) !== path)
|
|
219
258
|
throw new ApiError("not_found", "the agent's learning folder has no such workflow");
|
|
220
259
|
const found = await reading(data, agentId, async ({ ws, snapshot }) => {
|
|
221
|
-
const
|
|
260
|
+
const served = await servedIn(snapshot, purgedOf);
|
|
261
|
+
const touched = snapshot.log.filter((change) => served(change) && change.files.includes(path));
|
|
222
262
|
const latest = touched.slice(0, limit).reverse();
|
|
223
263
|
const revisions = [];
|
|
224
264
|
for (const change of latest) {
|
|
@@ -237,16 +277,22 @@ export async function workflowRevisions(data, agentId, name, query, shown) {
|
|
|
237
277
|
/** Learned workflow `name`'s text at `digest` (a champion's, as its promotion records name it), read by that digest and
|
|
238
278
|
* never by paging the workflow's history: at `commits` (the records' learning commits, newest first), then at main, the
|
|
239
279
|
* first commit whose workflow.json is that digest's text, with the commit it was read at. Undefined when none is (no
|
|
240
|
-
* main yet, or no commit read holds it).
|
|
241
|
-
|
|
280
|
+
* main yet, or no commit read holds it). A commit whose text a purged run wrote is never read (purged-workflow.ts),
|
|
281
|
+
* however old. One read-only exec per commit tried (textsAt), and one more for the commit that holds the digest, unless
|
|
282
|
+
* it is main (snapshotAt). */
|
|
283
|
+
export async function workflowAtDigest(data, agentId, name, digest, commits, store) {
|
|
242
284
|
if (!WORKFLOW_NAME.test(name))
|
|
243
285
|
return undefined;
|
|
244
286
|
const path = `${WORKFLOWS_DIR}/${name}/workflow.json`;
|
|
245
287
|
return reading(data, agentId, async ({ ws, snapshot }) => {
|
|
246
288
|
for (const commit of new Set([...commits, snapshot.main])) {
|
|
247
289
|
const raw = (await textsAt(ws, commit, [path]).catch(() => undefined))?.[path];
|
|
248
|
-
if (raw
|
|
249
|
-
|
|
290
|
+
if (raw === undefined || createHash("sha256").update(raw).digest("hex").slice(0, 16) !== digest)
|
|
291
|
+
continue;
|
|
292
|
+
const at = commit === snapshot.main ? snapshot : await snapshotAt(ws, commit).catch(() => undefined);
|
|
293
|
+
if (!at || (await purgedWorkflows(at, store)).has(name))
|
|
294
|
+
continue;
|
|
295
|
+
return { text: raw, commit };
|
|
250
296
|
}
|
|
251
297
|
return undefined;
|
|
252
298
|
}, () => undefined);
|
|
@@ -279,12 +325,20 @@ function fileOf(raw, use) {
|
|
|
279
325
|
return file;
|
|
280
326
|
}
|
|
281
327
|
/** GET /agents/{id}/learning/files/{file}: a draft's file on main as text, its ETag, and its type (workflow.json is
|
|
282
|
-
* JSON).
|
|
283
|
-
|
|
328
|
+
* JSON). A purged run's workflow left main with its purge (learn/commit.ts forgetRunText), so its files are the 404
|
|
329
|
+
* any missing file is. A workflow.json still on main whose writer is purged (a run purged before purges took its
|
|
330
|
+
* workflows off, until its DELETE is sent again) is 410 purged, as every route of that run is (purged-workflow.ts). */
|
|
331
|
+
export async function readLearnedFile(data, agentId, raw, shown, store) {
|
|
284
332
|
const file = fileOf(raw, "read");
|
|
333
|
+
const place = learnedPlace(file);
|
|
285
334
|
const found = await reading(data, agentId, async ({ snapshot, body }) => {
|
|
286
335
|
const oid = blobIn(snapshot, file);
|
|
287
|
-
|
|
336
|
+
if (oid === undefined)
|
|
337
|
+
return undefined;
|
|
338
|
+
const purged = place.kind === "workflow" ? (await purgedWorkflows(snapshot, store)).get(place.name) : undefined;
|
|
339
|
+
if (purged)
|
|
340
|
+
throw purgedRun(purged);
|
|
341
|
+
return { oid, text: await body(file, oid) };
|
|
288
342
|
}, () => undefined);
|
|
289
343
|
if (!found)
|
|
290
344
|
throw new ApiError("not_found", "the agent's learning folder has no such file on main");
|
|
@@ -476,10 +530,46 @@ export async function runDiffOverStore(data, store, runId, shown) {
|
|
|
476
530
|
};
|
|
477
531
|
if (end?.merged) {
|
|
478
532
|
const folder = learningFolderOf(data, row.agentId);
|
|
479
|
-
const diff = await readRunDiff(folder.workspace, runDiffKey(runId, kept?.round)).catch((error) => Promise.reject(routeFailure(error))).finally(() => folder.end());
|
|
480
|
-
if (!diff
|
|
533
|
+
const diff = await readRunDiff(folder.workspace, runDiffKey(runId, kept?.round)).then((read) => (read && read.merge === end.merged ? againstPurged(folder.workspace, read, store) : undefined)).catch((error) => Promise.reject(routeFailure(error))).finally(() => folder.end());
|
|
534
|
+
if (!diff)
|
|
481
535
|
throw new ApiError("not_found", "the run's merge is not in its agent's learning folder");
|
|
482
536
|
return { base: diff.parent, head: diff.merge, files: diff.files.map((entry) => ("patch" in entry ? file(entry.path, entry.status, entry.patch) : { path: shown.name(entry.path), status: entry.status, withheld: entry.withheld })) };
|
|
483
537
|
}
|
|
484
538
|
return { base: start?.seed ?? null, head: null, files: [] };
|
|
485
539
|
}
|
|
540
|
+
/** `diff` with each file of a learned workflow whose text at its parent a purged run wrote (purged-workflow.ts), its
|
|
541
|
+
* whole `workflows/<name>/` folder (README.md too), diffed against nothing, so its patch never shows that text: its
|
|
542
|
+
* text at the merge as an added file, or, deleted there, no file. One more read-only exec when the merge changed such
|
|
543
|
+
* a file (snapshotAt), and one per file served so. */
|
|
544
|
+
async function againstPurged(ws, diff, store) {
|
|
545
|
+
const replaced = (path, status) => {
|
|
546
|
+
const [dir, name, ...rest] = path.split("/");
|
|
547
|
+
return status !== "added" && dir === WORKFLOWS_DIR && rest.length ? name : undefined;
|
|
548
|
+
};
|
|
549
|
+
if (!diff.files.some(({ path, status }) => replaced(path, status)))
|
|
550
|
+
return diff;
|
|
551
|
+
const purged = await purgedWorkflows(await snapshotAt(ws, diff.parent), store);
|
|
552
|
+
const files = [];
|
|
553
|
+
for (const entry of diff.files) {
|
|
554
|
+
const name = replaced(entry.path, entry.status);
|
|
555
|
+
if (name === undefined || !purged.has(name))
|
|
556
|
+
files.push(entry);
|
|
557
|
+
else if (entry.status === "modified") {
|
|
558
|
+
const text = (await textsAt(ws, diff.merge, [entry.path]))?.[entry.path];
|
|
559
|
+
if (text !== undefined)
|
|
560
|
+
files.push({ path: entry.path, status: "added", patch: addedPatch(text) });
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return { ...diff, files };
|
|
564
|
+
}
|
|
565
|
+
/** `text` as git's unified diff writes an added file, its hunk alone (as the learning script keeps a patch): no hunk for
|
|
566
|
+
* an empty file, a one-line hunk's count left out, and a last line with no newline marked so. */
|
|
567
|
+
function addedPatch(text) {
|
|
568
|
+
if (text === "")
|
|
569
|
+
return "";
|
|
570
|
+
const lines = text.split("\n");
|
|
571
|
+
const ended = text.endsWith("\n");
|
|
572
|
+
if (ended)
|
|
573
|
+
lines.pop();
|
|
574
|
+
return `@@ -0,0 +1${lines.length === 1 ? "" : `,${lines.length}`} @@\n${lines.map((line) => `+${line}\n`).join("")}${ended ? "" : "\\n"}`;
|
|
575
|
+
}
|
package/dist/learning-words.d.ts
CHANGED
|
@@ -23,7 +23,10 @@ export declare const STOPPED: {
|
|
|
23
23
|
readonly unanswered: "the turn that writes its workflow ended before it answered";
|
|
24
24
|
readonly notChecked: "what it learned could not be checked";
|
|
25
25
|
readonly refuseUnread: "what the run must never learn (its agent's browser sign-in, the server's secrets) could not be read back, so nothing it learned is kept";
|
|
26
|
+
readonly otherDisk: "the run is on a disk its start named, and a run there learns nothing yet: it started without what the agent learned, and what it does is not learned";
|
|
26
27
|
};
|
|
28
|
+
/** Why a run whose start has no seed started with nothing learned (run-launch.ts SeedFailed), in words. */
|
|
29
|
+
export declare const seedStopped: (failed: string | undefined) => string;
|
|
27
30
|
/** A run's learning, in words, by where it stands. */
|
|
28
31
|
export declare const said: {
|
|
29
32
|
seeded: (corrections: number, workflows?: number) => string;
|
|
@@ -52,6 +55,8 @@ export declare const said: {
|
|
|
52
55
|
noBudget: string;
|
|
53
56
|
unknownCost: string;
|
|
54
57
|
stopped: (cause: string) => string;
|
|
58
|
+
/** A run whose learning seed predates a reset of its agent's learning (runner/learning-end.ts, reason `reset`). */
|
|
59
|
+
reset: string;
|
|
55
60
|
};
|
|
56
61
|
/** A run's learning in words as a read says them, whole: what it learned and what waits for the owner's OK, said again
|
|
57
62
|
* from its parts (`workflows`, `corrections`, `problems`), each name cut by `cut` first (the host's secrets as they are
|
package/dist/learning-words.js
CHANGED
|
@@ -61,7 +61,10 @@ export const STOPPED = {
|
|
|
61
61
|
unanswered: "the turn that writes its workflow ended before it answered",
|
|
62
62
|
notChecked: "what it learned could not be checked",
|
|
63
63
|
refuseUnread: "what the run must never learn (its agent's browser sign-in, the server's secrets) could not be read back, so nothing it learned is kept",
|
|
64
|
+
otherDisk: "the run is on a disk its start named, and a run there learns nothing yet: it started without what the agent learned, and what it does is not learned",
|
|
64
65
|
};
|
|
66
|
+
/** Why a run whose start has no seed started with nothing learned (run-launch.ts SeedFailed), in words. */
|
|
67
|
+
export const seedStopped = (failed) => failed === "unreadable" ? STOPPED.unreadable : failed === "not_copied" ? STOPPED.notCopied : failed === "other_disk" ? STOPPED.otherDisk : STOPPED.noSeed;
|
|
65
68
|
/** A run's learning, in words, by where it stands. */
|
|
66
69
|
export const said = {
|
|
67
70
|
seeded: (corrections, workflows = 0) => {
|
|
@@ -108,6 +111,8 @@ export const said = {
|
|
|
108
111
|
noBudget: "Skipped: no budget left in this run to write what it learned.",
|
|
109
112
|
unknownCost: "Skipped: this run's spend is unknown, so its budget can't cover writing what it learned.",
|
|
110
113
|
stopped: (cause) => `Not kept: learning stopped (${cause}).`,
|
|
114
|
+
/** A run whose learning seed predates a reset of its agent's learning (runner/learning-end.ts, reason `reset`). */
|
|
115
|
+
reset: "Dropped: its learning seed predates a reset of the agent's learning.",
|
|
111
116
|
};
|
|
112
117
|
/** A run's learning in words as a read says them, whole: what it learned and what waits for the owner's OK, said again
|
|
113
118
|
* from its parts (`workflows`, `corrections`, `problems`), each name cut by `cut` first (the host's secrets as they are
|
package/dist/learning.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Problem } from "./learn/index.js";
|
|
2
2
|
import { type LearningFolder } from "./learn/folder.js";
|
|
3
|
+
import type { Store } from "./store/index.js";
|
|
3
4
|
import type { Workspace } from "./workspace/index.js";
|
|
4
5
|
export { learnsOf } from "./learning-setting.js";
|
|
5
6
|
/** The server's learning switch (`--learning`, AGENTRUN_SERVE_LEARNING; capabilities.features.learning). `on`, the
|
|
@@ -14,7 +15,7 @@ export declare function learningOf(env: NodeJS.ProcessEnv, given?: string): Lear
|
|
|
14
15
|
* is on main, or `dropped` with a reason from the closed list. A learning fault never refuses a run: it starts with
|
|
15
16
|
* nothing learned, `seed_failed`. */
|
|
16
17
|
export declare const LEARNING_STATES: readonly ["seeded", "reflecting", "merged", "dropped"];
|
|
17
|
-
export declare const LEARNING_REASONS: readonly ["seed_failed", "no_budget", "unknown_cost", "cancelled", "crashed", "reflect_failed", "empty", "checker", "use"];
|
|
18
|
+
export declare const LEARNING_REASONS: readonly ["seed_failed", "no_budget", "unknown_cost", "cancelled", "crashed", "reflect_failed", "empty", "checker", "use", "reset"];
|
|
18
19
|
/** A run's own `learning` on its start (POST /agents/{agent_id}/runs): it starts from what its agent learned, as a run that
|
|
19
20
|
* learns does, and keeps nothing (no compile, no correction, at any end), so runs of one agent read one learned state
|
|
20
21
|
* however many run at once. Its learning ends `dropped`, reason `use`. */
|
|
@@ -111,7 +112,7 @@ export declare const detailShown: (learning: Learning, shown: Shown, max?: numbe
|
|
|
111
112
|
export declare const learningView: (learning: Learning, shown: Shown) => {
|
|
112
113
|
workflows?: LearnedFile[];
|
|
113
114
|
state: "dropped" | "merged" | "seeded" | "reflecting";
|
|
114
|
-
reason: "cancelled" | "use" | "empty" | "
|
|
115
|
+
reason: "cancelled" | "reset" | "use" | "empty" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "checker" | null;
|
|
115
116
|
detail: string | null;
|
|
116
117
|
at: string;
|
|
117
118
|
};
|
|
@@ -126,9 +127,9 @@ export declare function shortOf<T extends {
|
|
|
126
127
|
at: string;
|
|
127
128
|
}>({ state, reason, detail, at: _, ...rest }: T): {
|
|
128
129
|
state: "dropped" | "merged" | "seeded" | "reflecting";
|
|
129
|
-
reason: "cancelled" | "use" | "empty" | "
|
|
130
|
+
reason: "cancelled" | "reset" | "use" | "empty" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "checker" | null;
|
|
130
131
|
detail: string | null;
|
|
131
|
-
} & Omit<T, "at" | "reason" | "
|
|
132
|
+
} & Omit<T, "at" | "reason" | "detail" | "state">;
|
|
132
133
|
/** The label of the end-of-run turn's timeline rows, and the kind and label of a run's learning row. */
|
|
133
134
|
export declare const LEARNING_LABEL = "learning";
|
|
134
135
|
/** A message a trigger sent the run that its owner did not write (a webhook body, a Slack or GitHub event), by its
|
|
@@ -138,11 +139,13 @@ export type Triggered = {
|
|
|
138
139
|
text: string;
|
|
139
140
|
};
|
|
140
141
|
/** What a run is seeded from: main's commit (null when the folder has none yet), corrections.md's text ("" when none),
|
|
141
|
-
* and its active learned workflows, by name.
|
|
142
|
+
* and its active learned workflows, by name. `at`: when a run's seed was read (seedOf, epoch ms, in the agent's
|
|
143
|
+
* learning queue), which the agent's reset watermark is set in too: a seed read at or before it predates the reset. */
|
|
142
144
|
export type Seed = {
|
|
143
145
|
sha: string | null;
|
|
144
146
|
corrections: string;
|
|
145
147
|
workflows: LearnedWorkflow[];
|
|
148
|
+
at?: number;
|
|
146
149
|
};
|
|
147
150
|
/** A workflow the agent learned, as a run may run it: its name, the line its README says what it does with, and its
|
|
148
151
|
* workflow.json whole. */
|
|
@@ -170,12 +173,14 @@ export declare const withAgentRepo: <T>(data: string, agentId: string, work: ()
|
|
|
170
173
|
* under `data`. The one point that names the place; its `end()` is called in a finally after every use. */
|
|
171
174
|
export declare const learningFolderOf: (data: string, agentId: string) => LearningFolder;
|
|
172
175
|
/** The seed of a run of agent `agentId` about to be made: main's commit, the folder made first when it is absent (the
|
|
173
|
-
* learning script's init),
|
|
174
|
-
* folder's own script and file API. */
|
|
176
|
+
* learning script's init), what main holds for a run (seedIn), and when it was read (`at`). In the agent's queue, as a
|
|
177
|
+
* reset is (learning-reset.ts). No git in this process: the folder's own script and file API. */
|
|
175
178
|
export declare function seedOf(data: string, agentId: string): Promise<Seed>;
|
|
176
|
-
/** What commit `commit` of the folder holds for a run, as seedOf reads main (one read-only exec of the script)
|
|
177
|
-
*
|
|
178
|
-
|
|
179
|
+
/** What commit `commit` of the folder holds for a run, as seedOf reads main (one read-only exec of the script), but a
|
|
180
|
+
* learned workflow a purged run wrote, by `store`'s runs (purged-workflow.ts): no claim lays, checks, replays or serves
|
|
181
|
+
* it. `store` null: a run's own process, which reads no other run; its runner reads the seed again with its store
|
|
182
|
+
* (runner/learning-seed.ts). No commit (null) is the empty seed; a commit the folder no longer holds throws. */
|
|
183
|
+
export declare function seedAt(ws: Workspace, commit: string | null, store: Pick<Store, "runs"> | null): Promise<Seed>;
|
|
179
184
|
/** Whether `text` holds a host secret (`shown`): as written, or, read as JSON, in any string it decodes to (its escapes
|
|
180
185
|
* decoded), or nested past the bound. The one check a learned workflow's text passes at a run's start (chooseWorkflows)
|
|
181
186
|
* and every text its compile turn is told (runner/learning-end.ts compileAskOf); a text that is not JSON is read as
|
package/dist/learning.js
CHANGED
|
@@ -18,6 +18,7 @@ import { folderAt, learningInit, learningWorkspace, readLearning } from "./learn
|
|
|
18
18
|
import { agentFolderOf, serialBy } from "./files.js";
|
|
19
19
|
import { withoutLoopbackAddresses } from "./key-refusal.js";
|
|
20
20
|
import { DETAIL_MAX, LIST_DETAIL, said, short, wordsOf } from "./learning-words.js";
|
|
21
|
+
import { purgedWorkflows } from "./purged-workflow.js";
|
|
21
22
|
export { learnsOf } from "./learning-setting.js";
|
|
22
23
|
/** The server's learning switch (`--learning`, AGENTRUN_SERVE_LEARNING; capabilities.features.learning). `on`, the
|
|
23
24
|
* default: a run learns when its agent's definition says `learning: true`. `off`: no run this server starts does. */
|
|
@@ -35,7 +36,7 @@ export function learningOf(env, given) {
|
|
|
35
36
|
* is on main, or `dropped` with a reason from the closed list. A learning fault never refuses a run: it starts with
|
|
36
37
|
* nothing learned, `seed_failed`. */
|
|
37
38
|
export const LEARNING_STATES = ["seeded", "reflecting", "merged", "dropped"];
|
|
38
|
-
export const LEARNING_REASONS = ["seed_failed", "no_budget", "unknown_cost", "cancelled", "crashed", "reflect_failed", "empty", "checker", "use"];
|
|
39
|
+
export const LEARNING_REASONS = ["seed_failed", "no_budget", "unknown_cost", "cancelled", "crashed", "reflect_failed", "empty", "checker", "use", "reset"];
|
|
39
40
|
/** A run's own `learning` on its start (POST /agents/{agent_id}/runs): it starts from what its agent learned, as a run that
|
|
40
41
|
* learns does, and keeps nothing (no compile, no correction, at any end), so runs of one agent read one learned state
|
|
41
42
|
* however many run at once. Its learning ends `dropped`, reason `use`. */
|
|
@@ -189,34 +190,39 @@ async function seedIn(sha, snapshot, text) {
|
|
|
189
190
|
return { sha, corrections, workflows };
|
|
190
191
|
}
|
|
191
192
|
/** The seed of a run of agent `agentId` about to be made: main's commit, the folder made first when it is absent (the
|
|
192
|
-
* learning script's init),
|
|
193
|
-
* folder's own script and file API. */
|
|
193
|
+
* learning script's init), what main holds for a run (seedIn), and when it was read (`at`). In the agent's queue, as a
|
|
194
|
+
* reset is (learning-reset.ts). No git in this process: the folder's own script and file API. */
|
|
194
195
|
export function seedOf(data, agentId) {
|
|
195
196
|
return withAgentRepo(data, agentId, async () => {
|
|
196
197
|
const { workspace, end } = learningFolderOf(data, agentId);
|
|
197
198
|
try {
|
|
198
199
|
await learningInit(workspace);
|
|
199
|
-
|
|
200
|
+
const seed = await readLearning(workspace, async ({ snapshot, body }) => seedIn(snapshot?.main ?? null, snapshot, body));
|
|
201
|
+
return { ...seed, at: Date.now() };
|
|
200
202
|
}
|
|
201
203
|
finally {
|
|
202
204
|
await end();
|
|
203
205
|
}
|
|
204
206
|
});
|
|
205
207
|
}
|
|
206
|
-
/** What commit `commit` of the folder holds for a run, as seedOf reads main (one read-only exec of the script)
|
|
207
|
-
*
|
|
208
|
-
|
|
208
|
+
/** What commit `commit` of the folder holds for a run, as seedOf reads main (one read-only exec of the script), but a
|
|
209
|
+
* learned workflow a purged run wrote, by `store`'s runs (purged-workflow.ts): no claim lays, checks, replays or serves
|
|
210
|
+
* it. `store` null: a run's own process, which reads no other run; its runner reads the seed again with its store
|
|
211
|
+
* (runner/learning-seed.ts). No commit (null) is the empty seed; a commit the folder no longer holds throws. */
|
|
212
|
+
export async function seedAt(ws, commit, store) {
|
|
209
213
|
if (commit === null)
|
|
210
214
|
return { sha: null, corrections: "", workflows: [] };
|
|
211
215
|
const at = await folderAt(ws, commit);
|
|
212
216
|
if (!at)
|
|
213
217
|
throw new Error(`the learning folder's read at ${commit} is gone`);
|
|
214
|
-
|
|
218
|
+
const purged = store ? await purgedWorkflows(at.snapshot, store) : new Map();
|
|
219
|
+
const seed = await seedIn(commit, at.snapshot, async (_path, oid) => {
|
|
215
220
|
const bytes = at.blobs.get(oid);
|
|
216
221
|
if (!bytes)
|
|
217
222
|
throw new Error(`the learning folder's read at ${commit} holds no blob ${oid}`);
|
|
218
223
|
return bytes.toString("utf8");
|
|
219
224
|
});
|
|
225
|
+
return { ...seed, workflows: seed.workflows.filter(({ name }) => !purged.has(name)) };
|
|
220
226
|
}
|
|
221
227
|
/** Whether `text` holds a host secret (`shown`): as written, or, read as JSON, in any string it decodes to (its escapes
|
|
222
228
|
* decoded), or nested past the bound. The one check a learned workflow's text passes at a run's start (chooseWorkflows)
|
package/dist/llms.txt
CHANGED
|
@@ -20,6 +20,7 @@ Auth: the API's routes take `Authorization: Bearer <token>`, all but `GET /v2/he
|
|
|
20
20
|
- `POST /v2/files?path=notes.md` with the file's bytes as the body (`curl --data-binary @notes.md`) uploads a file, answered `201` with the file, ready, its `file_id` under `file`. Name it in a run's `file_ids`, and the run finds it at `inputs/notes.md`. `GET /v2/files` lists the uploads, `DELETE /v2/files/{id}` removes one.
|
|
21
21
|
- `GET /v2/runs/{id}`: status (`queued`, `working`, `input_required`, `completed`, `failed`, `cancelled`, `paused`), `result` (`final_answer`, or a workflow's `output`), `error`, `cost` (`usd` is null while unknown, never $0), `path` (`agent`, `workflow`, `handed_back`; null until it ends). A run its learned workflow answered alone (`path` `workflow`), or ran first and handed back (`handed_back`), carries `workflow` (`name`, `digest`, and `repick`: `found` when its answer re-picked after a quote miss and found its quotes, `missed` when the re-pick missed too, else null), on the read and on every `GET /v2/runs` row; null on any other run.
|
|
22
22
|
- An agent that learns: a run its learned workflow served (`path` `workflow`) has the workflow's answer as `result.final_answer`; one handed back (`handed_back`) has the agent's. Its timeline is its `user_message`, the learned_workflow `tool_use` and `tool_result` (its nodes in `learned_nodes`; they write no `decision` rows), then `final_answer` and `usage`; a hand-back puts a `phase` row and the agent's own rows before them. Learning spends on the agent's own model route, key and cap: on `GET /v2/runs/{id}`, `cost.usd` is the run's own spend, the job's; `cost.learning_usd` what learning spent for it (its audit's shadow run and its share of its workflow revision's compile turn and check, spread over the revision's first `compile_after` served runs; a compile that kept no draft is on no run, in the bill's `unattributed_usd`), `cost.all_in_usd` both. A shadow run is in no run list and sends no webhook. `GET /v2/agents/{id}/learning/cost` has the agent's whole bill (`bill`).
|
|
23
|
+
- `DELETE /v2/agents/{id}/learning` resets what the agent learned (its corrections, learned workflows, their history, promotions and grades), on this server and on every Archil disk its runs used, keeping the agent and its runs: `204`, again on a second call; `409 learning_busy` (the runs in `details.runs`) while a run of its own is still going, nothing deleted; `503` while a disk that holds it can't be reached. Learning then reads only the runs after the reset (`compile_after` counts from it); a run that read the agent's learning before it learns nothing (`learning.reason` `reset`).
|
|
23
24
|
- `GET /v2/runs/{id}/timeline?after=0&limit=100` pages its steps; follow `next_after` until a page is `final` with `has_more` false.
|
|
24
25
|
- `GET /v2/runs/{id}/files`, then `GET /v2/runs/{id}/files/{path}`: what it wrote.
|
|
25
26
|
- `POST /v2/runs/{id}/messages` with `{content}` answers a run that asked a question (`input_required`), or follows up; `POST /v2/runs/{id}/cancel` ends one.
|
package/dist/mcp-gateway.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { McpCallResult, McpTool } from "@parcha/agentrun-kernel";
|
|
2
|
+
import { type MediaReader } from "./fal-price.js";
|
|
2
3
|
import { type Workspace } from "./workspace/index.js";
|
|
3
4
|
/** The longest answer the model reads whole; past it, the rest is filed in the run's work/ as lines read pages through
|
|
4
5
|
* (filed-answer.ts). Within the host's result bound (HOST_RESULT_MAX_CHARS), so every harness passes it whole. */
|
|
@@ -6,11 +7,13 @@ export declare const MCP_CLIP = 60000;
|
|
|
6
7
|
/** The longest one upstream call may take, and its first connection. */
|
|
7
8
|
export declare const CALL_MS = 120000;
|
|
8
9
|
export declare const CONNECT_MS = 30000;
|
|
9
|
-
/** Each pinned server: its URL then, the granted tools as it listed them,
|
|
10
|
+
/** Each pinned server: its URL then, the granted tools as it listed them, the prices its owner declared for them, and
|
|
11
|
+
* the meter that prices its other calls (`fal`: fal-price.ts). */
|
|
10
12
|
export type McpPin = Record<string, {
|
|
11
13
|
url: string;
|
|
12
14
|
tools: McpTool[];
|
|
13
15
|
prices?: Record<string, number>;
|
|
16
|
+
meter?: string;
|
|
14
17
|
}>;
|
|
15
18
|
/** Each granted server's URL now, and its credential's headers when that URL is the pinned one (the claim step's). */
|
|
16
19
|
export type McpCredentials = Record<string, {
|
|
@@ -20,14 +23,40 @@ export type McpCredentials = Record<string, {
|
|
|
20
23
|
unopened?: string; /** When its credential ends (ms): a token minted for the run's launch (a github_app server's), whose calls past it are refused unsent, in words. */
|
|
21
24
|
expires_at?: number;
|
|
22
25
|
}>;
|
|
23
|
-
/** The servers a save pins from: each one's URL, its tools as it lists them now,
|
|
26
|
+
/** The servers a save pins from: each one's URL, its tools as it lists them now, its owner's prices, and either its
|
|
27
|
+
* owner's toolkit for it or, for a pin carried over, the meter it was pinned with. */
|
|
24
28
|
export interface McpServerSource {
|
|
25
29
|
server(name: string): {
|
|
26
30
|
url: string;
|
|
27
31
|
tools: readonly McpTool[];
|
|
28
32
|
prices?: Readonly<Record<string, number>>;
|
|
33
|
+
toolkit?: string | null;
|
|
34
|
+
meter?: string;
|
|
29
35
|
} | undefined;
|
|
30
36
|
}
|
|
37
|
+
/** A meter's price for one call: what to hold before it leaves and why (`basis`), why it can't be priced
|
|
38
|
+
* (`unpriceable`, in words; the hold then covers only what could be), and what it charged, by the server's reply
|
|
39
|
+
* (none: no reply came back). Null: unknown. */
|
|
40
|
+
export type McpQuote = {
|
|
41
|
+
holdUsd: number;
|
|
42
|
+
basis: string;
|
|
43
|
+
unpriceable?: string;
|
|
44
|
+
chargeOf(reply: Record<string, unknown> | undefined): number | null;
|
|
45
|
+
};
|
|
46
|
+
/** A server's keys scoped to the run (fal's submission keys, fal-price.ts falKeys): `out`, a call's arguments as they
|
|
47
|
+
* leave; `back`, the text of its answer or error as the model reads it, each scoped key read as the agent's own. */
|
|
48
|
+
export type McpKeys = {
|
|
49
|
+
out(tool: string, args: Record<string, unknown>): Record<string, unknown>;
|
|
50
|
+
back(text: string): string;
|
|
51
|
+
};
|
|
52
|
+
/** A server that prices its own calls. `ask` calls one of the server's tools with the run's credential, unbooked and
|
|
53
|
+
* unrecorded, and answers its raw result (none: it failed). `keys`: the keys it scopes to the run, on every call of
|
|
54
|
+
* the server, billed or not. */
|
|
55
|
+
export interface McpMeter {
|
|
56
|
+
keys?: McpKeys;
|
|
57
|
+
bills(tool: string): boolean;
|
|
58
|
+
quote(tool: string, args: Record<string, unknown>, ask: (tool: string, args: Record<string, unknown>) => Promise<Record<string, unknown> | undefined>, signal: AbortSignal): Promise<McpQuote>;
|
|
59
|
+
}
|
|
31
60
|
/** The most schema nodes, and the deepest nesting, a tool's declarations are checked through: past either the tool is
|
|
32
61
|
* refused, never walked further. */
|
|
33
62
|
export declare const HEADER_SCAN_NODES = 10000;
|
|
@@ -75,6 +104,14 @@ export interface McpGatewayOptions {
|
|
|
75
104
|
* throws (a store read failed, the call was stopped) refuses the call unsent too, in words, and the run goes on. Only
|
|
76
105
|
* the runner's MCP claim step passes it: a github_app token whose App was disconnected or replaced. */
|
|
77
106
|
beforeCall?: (server: string, signal: AbortSignal) => Promise<void>;
|
|
107
|
+
/** Whether the run has a spend cap: under one, a metered call that cannot be priced is refused unsent. None: it has. */
|
|
108
|
+
capped?: () => boolean;
|
|
109
|
+
/** Reads a metered job's input media, for one priced by its length. None: such a job cannot be priced. */
|
|
110
|
+
media?: MediaReader;
|
|
111
|
+
/** For tests: the clock a meter's prices are kept by. */
|
|
112
|
+
now?: () => number;
|
|
113
|
+
/** The run's id: what a meter scopes a server's keys to (McpMeter.keys). None: no key is scoped. */
|
|
114
|
+
run?: string;
|
|
78
115
|
}
|
|
79
116
|
/** A run's journal commit. */
|
|
80
117
|
export type McpCommit = <T>(change: (tx: unknown) => Promise<T>) => Promise<T>;
|