@parcha/agentrun-serve 0.1.0-beta.54 → 0.1.0-beta.56
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 +142 -2
- package/README.md +310 -98
- package/dist/adapters.d.ts +11 -0
- package/dist/adapters.js +49 -0
- package/dist/agent-package.d.ts +3 -3
- package/dist/agent-package.js +6 -13
- package/dist/agents-store.js +6 -5
- package/dist/answer-json.d.ts +6 -2
- package/dist/answer-json.js +22 -4
- package/dist/api-only.d.ts +16 -4
- package/dist/api-only.js +23 -7
- package/dist/calendar/tools.js +3 -2
- package/dist/chatgpt-plan.d.ts +16 -1
- package/dist/chatgpt-plan.js +116 -12
- package/dist/claude-login.d.ts +34 -5
- package/dist/claude-login.js +31 -7
- package/dist/claude-sign-in.d.ts +35 -0
- package/dist/claude-sign-in.js +90 -0
- package/dist/cli.js +5 -3
- package/dist/composio-made.d.ts +26 -1
- package/dist/composio-made.js +39 -2
- package/dist/composio-preset.d.ts +3 -2
- package/dist/composio-preset.js +46 -14
- package/dist/computer-held-routes.js +2 -3
- package/dist/computer-setting.d.ts +4 -2
- package/dist/computer-setting.js +0 -2
- package/dist/computers-running.d.ts +8 -0
- package/dist/computers-running.js +27 -0
- package/dist/console/assets/backend-Boh7tC4i.js +166 -0
- package/dist/console/assets/index-CQ3cJRzI.js +746 -0
- package/dist/console/assets/index-DKkaS3a0.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/docker-host-addresses.d.ts +23 -3
- package/dist/docker-host-addresses.js +90 -18
- package/dist/exa-keyless.d.ts +2 -3
- package/dist/exa-keyless.js +43 -127
- package/dist/firecrawl-keyless.d.ts +41 -0
- package/dist/firecrawl-keyless.js +152 -0
- package/dist/handed-secret.d.ts +3 -1
- package/dist/handed-secret.js +4 -2
- package/dist/harness-keys.d.ts +98 -0
- package/dist/harness-keys.js +247 -0
- package/dist/harness-recipe-entry.d.ts +14 -9
- package/dist/harness-recipe-entry.js +25 -14
- package/dist/harness-table.d.ts +16 -1
- package/dist/harness-table.js +19 -7
- package/dist/harness.d.ts +4 -0
- package/dist/harness.js +12 -1
- package/dist/host-check.d.ts +6 -0
- package/dist/host-check.js +10 -0
- package/dist/import-summary.d.ts +1 -1
- package/dist/import-summary.js +1 -1
- package/dist/import.d.ts +5 -5
- package/dist/import.js +54 -67
- package/dist/key-refusal.d.ts +21 -5
- package/dist/key-refusal.js +231 -37
- package/dist/keyless-mcp.d.ts +36 -0
- package/dist/keyless-mcp.js +127 -0
- package/dist/learn/audit.d.ts +3 -3
- package/dist/learn/audit.js +3 -3
- package/dist/learn/commit.d.ts +8 -7
- package/dist/learn/commit.js +60 -20
- package/dist/learn/compile.d.ts +4 -3
- package/dist/learn/compile.js +7 -5
- package/dist/learn/folder.d.ts +16 -3
- package/dist/learn/folder.js +46 -13
- package/dist/learn/promote.d.ts +37 -13
- package/dist/learn/promote.js +112 -40
- package/dist/learn/secrets.d.ts +20 -10
- package/dist/learn/secrets.js +44 -176
- package/dist/learning-routes.d.ts +22 -17
- package/dist/learning-routes.js +40 -39
- package/dist/learning.js +2 -2
- package/dist/llms.txt +1 -1
- package/dist/manifest.d.ts +10 -0
- package/dist/manifest.js +30 -0
- package/dist/mcp-pin-first.d.ts +4 -2
- package/dist/mcp-pin-first.js +5 -2
- package/dist/mcp-secret-writes.d.ts +16 -7
- package/dist/mcp-secret-writes.js +35 -27
- package/dist/mcp-servers-store.d.ts +30 -6
- package/dist/mcp-servers-store.js +112 -28
- package/dist/mcp-sources.d.ts +10 -2
- package/dist/mcp-sources.js +9 -2
- package/dist/mcp-store.d.ts +13 -7
- package/dist/mcp-store.js +12 -9
- package/dist/model-form.d.ts +3 -2
- package/dist/model-form.js +11 -7
- package/dist/model.d.ts +20 -4
- package/dist/model.js +68 -9
- package/dist/native/history.d.ts +1 -1
- package/dist/native/history.js +2 -2
- package/dist/ollama-provider.d.ts +92 -0
- package/dist/ollama-provider.js +495 -0
- package/dist/openapi/agentrun-v2.openapi.json +2 -2
- package/dist/openapi.d.ts +3 -3
- package/dist/openapi.js +197 -55
- package/dist/page.d.ts +11 -3
- package/dist/page.js +22 -7
- package/dist/place-offers.d.ts +25 -1
- package/dist/place-offers.js +62 -8
- package/dist/print.js +1 -1
- package/dist/purged-workflow.d.ts +35 -7
- package/dist/purged-workflow.js +73 -26
- package/dist/redact/match.d.ts +74 -0
- package/dist/redact/match.js +771 -0
- package/dist/run-computer.d.ts +2 -0
- package/dist/run-computer.js +2 -0
- package/dist/run-files.d.ts +4 -0
- package/dist/run-files.js +4 -0
- package/dist/run-keys.d.ts +2 -4
- package/dist/run-keys.js +6 -7
- package/dist/run-launch.d.ts +4 -0
- package/dist/run-launch.js +4 -0
- package/dist/run-reads-over-store.d.ts +3 -2
- package/dist/run-reads-over-store.js +66 -2
- package/dist/run-secrets.js +5 -2
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +4 -4
- package/dist/runner/adapter-loop.d.ts +9 -3
- package/dist/runner/adapter-loop.js +34 -15
- package/dist/runner/adapter-run-spec.d.ts +3 -0
- package/dist/runner/adapter-run-spec.js +9 -4
- package/dist/runner/audit.js +8 -4
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +13 -5
- package/dist/runner/claim-secrets.d.ts +5 -8
- package/dist/runner/claim-secrets.js +6 -0
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +41 -7
- package/dist/runner/harness-loops.d.ts +22 -9
- package/dist/runner/harness-loops.js +21 -11
- package/dist/runner/held.d.ts +3 -0
- package/dist/runner/learning-end.d.ts +1 -1
- package/dist/runner/learning-end.js +8 -3
- package/dist/runner/loop-contract.d.ts +9 -4
- package/dist/runner/main.js +12 -6
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +26 -2
- package/dist/runner/mcp-run.d.ts +3 -0
- package/dist/runner/mcp-run.js +2 -1
- package/dist/runner/metrics.d.ts +10 -10
- package/dist/runner/metrics.js +19 -38
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +6 -2
- package/dist/runner/presence.d.ts +4 -3
- package/dist/runner/presence.js +4 -2
- package/dist/runner/promotion.d.ts +15 -9
- package/dist/runner/promotion.js +25 -15
- package/dist/runner/run-child-host.d.ts +2 -0
- package/dist/runner/run-child-host.js +19 -9
- package/dist/runner/run-child.js +3 -1
- package/dist/runner/runner.d.ts +4 -0
- package/dist/runner/runner.js +33 -3
- package/dist/runner/sdk-loop.js +2 -0
- package/dist/runner/workflow-loop.d.ts +2 -2
- package/dist/runner/workflow-loop.js +1 -2
- package/dist/runner/workflow-spec.d.ts +1 -1
- package/dist/runner/workflow-spec.js +6 -6
- package/dist/sdk/check.d.ts +4 -1
- package/dist/sdk/check.js +2 -1
- package/dist/sdk/runs.d.ts +2 -2
- package/dist/sdk/runs.js +8 -6
- package/dist/secret-cut.js +2 -1
- package/dist/secret-writes.d.ts +3 -2
- package/dist/secret-writes.js +1 -1
- package/dist/server.d.ts +49 -10
- package/dist/server.js +324 -118
- package/dist/standard-webhooks.d.ts +11 -0
- package/dist/standard-webhooks.js +20 -2
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/dialect.js +3 -0
- package/dist/store/schema.js +5 -2
- package/dist/store/sqlite/store.js +133 -47
- package/dist/store/store.d.ts +64 -15
- package/dist/store/store.js +7 -0
- package/dist/store-reads/journal.d.ts +7 -2
- package/dist/store-reads/journal.js +9 -6
- package/dist/store-reads/learning.d.ts +12 -9
- package/dist/store-reads/learning.js +18 -24
- package/dist/store-view.d.ts +0 -5
- package/dist/store-view.js +10 -9
- package/dist/template-eval.d.ts +51 -6
- package/dist/template-eval.js +177 -53
- package/dist/template-import.js +4 -2
- package/dist/templates.d.ts +5 -3
- package/dist/templates.js +19 -40
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/labels.d.ts +2 -2
- package/dist/timeline/labels.js +2 -2
- package/dist/timeline/timeline.d.ts +14 -9
- package/dist/timeline/timeline.js +15 -7
- package/dist/tool-gate.js +3 -1
- package/dist/tool-plane.d.ts +17 -9
- package/dist/tool-plane.js +38 -17
- package/dist/tools.js +2 -2
- package/dist/trigger-launch-hook.d.ts +16 -8
- package/dist/trigger-launch-hook.js +32 -23
- package/dist/trigger-targets.d.ts +18 -8
- package/dist/trigger-targets.js +42 -19
- package/dist/triggers.d.ts +85 -23
- package/dist/triggers.js +303 -96
- package/dist/validate.js +1 -1
- package/dist/web-fake.js +3 -3
- package/dist/web-fetch-direct.d.ts +4 -0
- package/dist/web-fetch-direct.js +8 -1
- package/dist/web-fetch.d.ts +12 -3
- package/dist/web-fetch.js +47 -14
- package/dist/web-search.d.ts +33 -4
- package/dist/web-search.js +100 -41
- package/dist/webhooks.js +4 -5
- package/dist/workspace/computer-deps.d.ts +2 -1
- package/dist/workspace/computer-deps.js +5 -4
- package/dist/workspace/computer-for-claim.d.ts +8 -2
- package/dist/workspace/computer-for-claim.js +28 -9
- package/dist/workspace/computer-janitor.d.ts +15 -7
- package/dist/workspace/computer-janitor.js +33 -8
- package/dist/workspace/computer-kept.d.ts +52 -4
- package/dist/workspace/computer-kept.js +118 -6
- package/dist/workspace/run-end-computers.d.ts +5 -1
- package/dist/workspace/run-end-computers.js +27 -1
- package/dist/wrapped.d.ts +57 -0
- package/dist/wrapped.js +51 -0
- package/launcher/agentrun-serve +5 -1
- package/package.json +17 -13
- package/templates/README.md +10 -9
- package/dist/console/assets/index-B_85An2t.js +0 -745
- package/dist/console/assets/index-n1YsbnYh.css +0 -1
- package/dist/import-sources.d.ts +0 -116
- package/dist/import-sources.js +0 -693
package/dist/learn/commit.js
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
// it was on the run's seed (or its `bases` commit) is a conflict, never written over;
|
|
7
7
|
// - one line of an owner's feedback appended to corrections.md (appendCorrection), after the refusals;
|
|
8
8
|
// - corrections.md replaced whole by a person (putCorrections), under the ETag they read;
|
|
9
|
-
// - a purged run's learned workflows
|
|
9
|
+
// - a purged run's learned workflows put back as they were before it (off main when it wrote them new) and its feedback
|
|
10
|
+
// lines taken off main, by the host (forgetRunText).
|
|
10
11
|
import { isWorkspaceError } from "../workspace/index.js";
|
|
11
12
|
import { CORRECTIONS_CAP, CORRECTIONS_FILE, correctionLine, correctionsProblems } from "./corrections.js";
|
|
12
|
-
import { blobOid, DIFFS_DIR, folderFailure, FolderMerged, FolderRefused, FolderTooLarge, FolderUnreadable, forgetBody, learningRepair, readLearning, readRunDiff, readSnapshot, runDiffKey, runMergeOf, writeLearning } from "./folder.js";
|
|
13
|
+
import { blobOid, DIFFS_DIR, folderAt, folderFailure, FolderMerged, FolderRefused, FolderTooLarge, FolderUnreadable, forgetBody, learningRepair, readLearning, readRunDiff, readSnapshot, runDiffKey, runMergeOf, writeLearning } from "./folder.js";
|
|
13
14
|
import { held, isHeld } from "./workflow-draft.js";
|
|
14
15
|
/** The blob `path` is on the snapshot's main: corrections.md or a draft's file. */
|
|
15
16
|
function blobOf(snapshot, path) {
|
|
@@ -161,16 +162,17 @@ export async function putCorrections(ws, input) {
|
|
|
161
162
|
}
|
|
162
163
|
/**
|
|
163
164
|
* Run `runId`'s text taken off the folder's current files, at its purge (agent-delete.ts purgeRun): first its learned
|
|
164
|
-
* workflows (forgetRunWorkflows), whether or not it left a diff file; then the
|
|
165
|
-
* corrections.md, as its diff file keeps them, dropped from main in one host commit
|
|
166
|
-
* since is theirs and stays); each other merge's diff that shows such a line as
|
|
167
|
-
* run's diff files deleted, last, so a call stopped part way finds what it has
|
|
168
|
-
* folder's git history until a learning reset or its agent's purge deletes the
|
|
169
|
-
* lands once, nothing left to drop makes no commit, and a run with no diff file
|
|
165
|
+
* workflows (forgetRunWorkflows; `purged`: whether another run is purged), whether or not it left a diff file; then the
|
|
166
|
+
* lines each of its merges added to corrections.md, as its diff file keeps them, dropped from main in one host commit
|
|
167
|
+
* per merge (a line a person edited since is theirs and stays); each other merge's diff that shows such a line as
|
|
168
|
+
* context written without it; then the run's diff files deleted, last, so a call stopped part way finds what it has
|
|
169
|
+
* left to do. Its merges stay in the folder's git history until a learning reset or its agent's purge deletes the
|
|
170
|
+
* folder. Idempotent: each merge's scrub lands once, nothing left to drop makes no commit, and a run with no diff file
|
|
171
|
+
* and no workflow here is no work.
|
|
170
172
|
* `commit`: the host's last commit, when one was made.
|
|
171
173
|
*/
|
|
172
|
-
export async function forgetRunText(ws, runId) {
|
|
173
|
-
let commit = await forgetRunWorkflows(ws, runId);
|
|
174
|
+
export async function forgetRunText(ws, runId, purged) {
|
|
175
|
+
let commit = await forgetRunWorkflows(ws, runId, async (run) => run === runId || (await purged(run)));
|
|
174
176
|
const names = await diffNames(ws);
|
|
175
177
|
const own = new RegExp(`^${runId.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(\\.r\\d+)?\\.json(\\..+)?$`);
|
|
176
178
|
const mine = names.filter((name) => own.test(name));
|
|
@@ -225,19 +227,57 @@ export async function forgetRunText(ws, runId) {
|
|
|
225
227
|
await ws.remove(`${DIFFS_DIR}/${name}`, { force: true }).catch((error) => { throw folderFailure(error); });
|
|
226
228
|
return commit ? { commit } : {};
|
|
227
229
|
}
|
|
228
|
-
/**
|
|
229
|
-
*
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
|
|
230
|
+
/** Each learned workflow on main whose workflow.json run `runId` wrote last (SnapLearned.run, the rule purged-workflow.ts
|
|
231
|
+
* reads) put back in one host commit as it stood at the newest commit where its writer was no purged run (`purged`,
|
|
232
|
+
* `runId` among them), every file of its `workflows/<name>/` folder, its writer that run again (the commit's
|
|
233
|
+
* `Written-By` line: folder.ts writerOf); taken off main whole when the purged runs wrote every version of it. So a
|
|
234
|
+
* purge takes off main only what purged runs put there, and a version another run wrote, a champion included, stays
|
|
235
|
+
* served. The commit, or undefined when main holds none of the run's (a repeat finds its own put back, and one another
|
|
236
|
+
* run wrote since names that run). The snapshot is rebuilt from main first (two execs and a checkout): a merge that
|
|
237
|
+
* moved main and stopped before its snapshot leaves one that names none of that merge's workflows, and finding no work
|
|
238
|
+
* commits nothing that would show it stale. One more read-only exec of main's history when the run wrote one, and one
|
|
239
|
+
* per version put back; either read finding nothing refuses (FolderUnreadable), so no guess takes a folder off. */
|
|
240
|
+
async function forgetRunWorkflows(ws, runId, purged) {
|
|
236
241
|
if (await readSnapshot(ws))
|
|
237
242
|
await learningRepair(ws);
|
|
238
243
|
const done = await writeLearning(ws, async ({ snapshot }) => {
|
|
239
|
-
const
|
|
240
|
-
|
|
244
|
+
const mine = (snapshot?.workflows ?? []).filter((item) => item.run === runId);
|
|
245
|
+
if (!mine.length)
|
|
246
|
+
return { result: false };
|
|
247
|
+
// No history read, no guess: a purge that can't tell what came before the run's version refuses (503, sent again
|
|
248
|
+
// later), and never takes the whole folder off main.
|
|
249
|
+
const unread = () => new FolderUnreadable(false, "the learning folder's history at main can't be read, so a purge puts nothing back and takes nothing off: send the DELETE again");
|
|
250
|
+
const history = await folderAt(ws, snapshot.main);
|
|
251
|
+
if (!history)
|
|
252
|
+
throw unread();
|
|
253
|
+
const writes = [];
|
|
254
|
+
const deletes = [];
|
|
255
|
+
const written = {};
|
|
256
|
+
for (const item of mine) {
|
|
257
|
+
// Newest first: the first writer no purged run is the version to put back, as it stood just before the next
|
|
258
|
+
// writer took the file over.
|
|
259
|
+
const writers = history.writers(item.name);
|
|
260
|
+
let back = [];
|
|
261
|
+
for (let i = 1; i < writers.length; i++) {
|
|
262
|
+
const { run } = writers[i];
|
|
263
|
+
if (run !== null && (await purged(run)))
|
|
264
|
+
continue;
|
|
265
|
+
const before = writers[i - 1].before;
|
|
266
|
+
const at = before ? await folderAt(ws, before) : undefined;
|
|
267
|
+
if (!at)
|
|
268
|
+
throw unread();
|
|
269
|
+
const files = at.snapshot.workflows.find((one) => one.name === item.name)?.files ?? [];
|
|
270
|
+
back = files.map(({ path, oid }) => ({ path, text: at.blobs.get(oid).toString("utf8") }));
|
|
271
|
+
// Named even when `back` is main's bytes already, so the writer still moves (folder.ts writtenIn).
|
|
272
|
+
if (back.length)
|
|
273
|
+
written[item.name] = run;
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
writes.push(...back);
|
|
277
|
+
deletes.push(...[...item.files.map(({ path }) => path), ...(item.links ?? [])].filter((path) => !back.some((file) => file.path === path)));
|
|
278
|
+
}
|
|
279
|
+
const host = writes.length ? "a purged run's workflows put back as they were before it" : "a purged run's workflows removed";
|
|
280
|
+
return { result: true, change: { by: { host, written }, writes, deletes } };
|
|
241
281
|
});
|
|
242
282
|
return done.result ? done.main : undefined;
|
|
243
283
|
}
|
package/dist/learn/compile.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RunRow, Store } from "../store/store.js";
|
|
2
2
|
import type { AuthorHostAddendum } from "@parcha/agentrun-dsl";
|
|
3
|
-
import { type AuditHold, type CheckRecord, type PromotionRecord } from "./promote.js";
|
|
3
|
+
import { type AuditHold, type CheckRecord, type PromotionRecord, type Refused } from "./promote.js";
|
|
4
4
|
import type { Problem } from "./check.js";
|
|
5
5
|
/** The info word that opens a workflow draft's block in a compile answer: ````workflow <name>, fenced with four backticks
|
|
6
6
|
* so a ``` line inside does not close it. */
|
|
@@ -108,8 +108,9 @@ export declare function promotedOf(records: readonly PromotionRecord[], workflow
|
|
|
108
108
|
/** The learned workflows whose newest revision other than their champion (learn/promote.ts championOf, which serves while
|
|
109
109
|
* that revision is held) is held: each one's compile turn is asked for a revision (once per hold). A champion's own
|
|
110
110
|
* hold counts: with it held there is no champion. Not one a check stopped (its recompile's check held it too): nothing
|
|
111
|
-
* compiles it again.
|
|
112
|
-
|
|
111
|
+
* compiles it again. A record `refused` names (the purge gate's: purged-workflow.ts refusedOf) is skipped as championOf
|
|
112
|
+
* skips it, so no purged run's revision is the champion or the hold a compile revises. */
|
|
113
|
+
export declare function heldNamesOf(records: readonly PromotionRecord[], refused?: Refused): Set<string>;
|
|
113
114
|
/** The words a compile's promotion record starts with when every draft of its turn failed its checks (runner/
|
|
114
115
|
* learning-end.ts recordDraftFailed): a hold with nothing checked, the compile's attempt all the same. */
|
|
115
116
|
export declare const DRAFT_FAILED = "its draft failed its checks";
|
package/dist/learn/compile.js
CHANGED
|
@@ -75,11 +75,13 @@ export function promotedOf(records, workflow, digest) {
|
|
|
75
75
|
/** The learned workflows whose newest revision other than their champion (learn/promote.ts championOf, which serves while
|
|
76
76
|
* that revision is held) is held: each one's compile turn is asked for a revision (once per hold). A champion's own
|
|
77
77
|
* hold counts: with it held there is no champion. Not one a check stopped (its recompile's check held it too): nothing
|
|
78
|
-
* compiles it again.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
* compiles it again. A record `refused` names (the purge gate's: purged-workflow.ts refusedOf) is skipped as championOf
|
|
79
|
+
* skips it, so no purged run's revision is the champion or the hold a compile revises. */
|
|
80
|
+
export function heldNamesOf(records, refused) {
|
|
81
|
+
const kept = refused ? records.filter((one) => !refused(one)) : records;
|
|
82
|
+
return new Set([...new Set(kept.map(({ workflow }) => workflow))].filter((name) => {
|
|
83
|
+
const champion = championOf(kept, name)?.digest;
|
|
84
|
+
const newest = kept.findLast((one) => one.workflow === name && one.digest !== champion);
|
|
83
85
|
return newest?.decided === "hold" && !newest.check?.stopped && !newest.audit?.stopped;
|
|
84
86
|
}));
|
|
85
87
|
}
|
package/dist/learn/folder.d.ts
CHANGED
|
@@ -91,6 +91,8 @@ export type RunDiff = {
|
|
|
91
91
|
};
|
|
92
92
|
/** Git's blob id of `bytes`: the sha1 of "blob <length>\0" and the bytes. */
|
|
93
93
|
export declare const blobOid: (bytes: Uint8Array | string) => string;
|
|
94
|
+
/** The draft a path is in, by name: `workflows/<name>/...`; else undefined. */
|
|
95
|
+
export declare function folderOf(path: string): string | undefined;
|
|
94
96
|
/** A commit as the snapshot reads it: its time (git's %cI, as commitTime keeps it), subject, body and trailers. */
|
|
95
97
|
type CommitInfo = {
|
|
96
98
|
at: string;
|
|
@@ -130,7 +132,9 @@ export declare function snapshotOfRead(read: ReturnType<typeof parseRead>): Snap
|
|
|
130
132
|
* that must be on main as they are on another commit (a run's seed). The script checks both on main as it commits. */
|
|
131
133
|
export type FolderChange = {
|
|
132
134
|
/** A run's merge names the run and its reason, and its `round` past the first (a follow-up's correction): its diff is
|
|
133
|
-
* kept under runDiffKey. The host's own book-keeping (an audit row) names what it kept
|
|
135
|
+
* kept under runDiffKey. The host's own book-keeping (an audit row) names what it kept; a purge that puts a workflow's
|
|
136
|
+
* earlier version back names, by workflow, the run that wrote it (`written`: writerOf; null, none), which moves the
|
|
137
|
+
* writer even when the version put back is main's bytes already (the commit then changes no file). */
|
|
134
138
|
by: {
|
|
135
139
|
person: PersonKind;
|
|
136
140
|
file: string;
|
|
@@ -141,6 +145,7 @@ export type FolderChange = {
|
|
|
141
145
|
round?: number;
|
|
142
146
|
} | {
|
|
143
147
|
host: string;
|
|
148
|
+
written?: Readonly<Record<string, string | null>>;
|
|
144
149
|
};
|
|
145
150
|
writes: readonly {
|
|
146
151
|
path: string;
|
|
@@ -272,11 +277,19 @@ export declare function commitChange(ws: Workspace, base: Snapshot | undefined,
|
|
|
272
277
|
/** The snapshot of `commit` as main would have it (the script's read at that commit), or undefined when the folder has
|
|
273
278
|
* no such commit. One exec, read-only: for a run's seed that is no longer main. */
|
|
274
279
|
export declare function snapshotAt(ws: Workspace, commit: string): Promise<Snapshot | undefined>;
|
|
275
|
-
/**
|
|
276
|
-
|
|
280
|
+
/** A commit that made someone a workflow's writer (writerOf), that writer, and the commit before it (none for the first). */
|
|
281
|
+
export type WriterChange = {
|
|
282
|
+
commit: string;
|
|
283
|
+
before: string | undefined;
|
|
284
|
+
run: string | null;
|
|
285
|
+
};
|
|
286
|
+
/** `commit` as main would have it (snapshotAt) with the blobs its tree holds, by oid, as git gave them, and each
|
|
287
|
+
* workflow's writers over its first-parent history, newest first (`writers`): one read-only exec. Undefined when the
|
|
288
|
+
* folder has no such commit. */
|
|
277
289
|
export declare function folderAt(ws: Workspace, commit: string): Promise<{
|
|
278
290
|
snapshot: Snapshot;
|
|
279
291
|
blobs: ReadonlyMap<string, Buffer>;
|
|
292
|
+
writers: (name: string) => WriterChange[];
|
|
280
293
|
} | undefined>;
|
|
281
294
|
/** The texts `commit` holds at `paths` (each a plain path, checkPath), each read alone with one read-only exec (the
|
|
282
295
|
* script's show: git cat-file over each `<commit>:<path>`), never the whole tree, its blobs or its log, so the read is
|
package/dist/learn/folder.js
CHANGED
|
@@ -58,7 +58,7 @@ export const blobOid = (bytes) => {
|
|
|
58
58
|
const keyFile = (name) => `${WORKFLOWS_DIR}/${name}/README.md`;
|
|
59
59
|
const viewFile = (name) => `${WORKFLOWS_DIR}/${name}/workflow.json`;
|
|
60
60
|
/** The draft a path is in, by name: `workflows/<name>/...`; else undefined. */
|
|
61
|
-
function folderOf(path) {
|
|
61
|
+
export function folderOf(path) {
|
|
62
62
|
const [top, name, ...rest] = path.split("/");
|
|
63
63
|
return top === WORKFLOWS_DIR && name && rest.length ? name : undefined;
|
|
64
64
|
}
|
|
@@ -100,6 +100,23 @@ function changeEntry(commit, sha, files) {
|
|
|
100
100
|
const paragraphs = commit.body.split(/\n\s*\n/).map((part) => part.trim()).filter(Boolean);
|
|
101
101
|
return { commit: sha, at: new Date(commit.at).toISOString(), by, reason: paragraphs.slice(0, -1).join(" ") || commit.subject.replace(/^learning: /, ""), files };
|
|
102
102
|
}
|
|
103
|
+
/** Who wrote workflow `name`'s workflow.json once `commit` changed it (SnapLearned.run), so the writer follows the bytes:
|
|
104
|
+
* a run's merge, its run; the host's commit, the run its `Written-By: <name> <run>` line names (a purge that put an
|
|
105
|
+
* earlier version back: commit.ts forgetRunWorkflows; a bare `Written-By: <name>`, none), else none; any other (a
|
|
106
|
+
* person's edit), undefined: the writer before it stays. Asked of a commit that changed the file, or one whose
|
|
107
|
+
* Written-By line names it (writtenIn: a put-back of main's own bytes changes no file). Both snapshot readers and
|
|
108
|
+
* folderAt's writers ask it. */
|
|
109
|
+
function writerOf(commit, name) {
|
|
110
|
+
const runId = commit.runId.split(",")[0].trim();
|
|
111
|
+
if (runId)
|
|
112
|
+
return runId;
|
|
113
|
+
if (!commit.subject.startsWith("host: "))
|
|
114
|
+
return undefined;
|
|
115
|
+
const line = commit.body.split("\n").find((one) => one === `Written-By: ${name}` || one.startsWith(`Written-By: ${name} `));
|
|
116
|
+
return line ? line.slice(`Written-By: ${name}`.length).trim() || null : null;
|
|
117
|
+
}
|
|
118
|
+
/** The workflows a host commit's Written-By lines name (writerOf): its writer moves with them, a file changed or not. */
|
|
119
|
+
const writtenIn = (commit) => commit.subject.startsWith("host: ") ? commit.body.split("\n").flatMap((line) => (line.startsWith("Written-By: ") ? [line.slice("Written-By: ".length).split(" ")[0]] : [])).filter(Boolean) : [];
|
|
103
120
|
/** Whether a commit's message holds a line git's log of changes greps for: `Run-Id: ` or `Changed-By: user`. */
|
|
104
121
|
const isChange = (commit) => `${commit.subject}\n${commit.body}`.split("\n").some((line) => line.startsWith("Run-Id: ") || line === "Changed-By: user");
|
|
105
122
|
const byName = (a, b) => byBytes(a.name, b.name);
|
|
@@ -182,7 +199,6 @@ export function snapshotOfRead(read) {
|
|
|
182
199
|
const log = [];
|
|
183
200
|
let more = false;
|
|
184
201
|
records.forEach(({ commit, sha, files }, i) => {
|
|
185
|
-
const runId = commit.runId.split(",")[0].trim();
|
|
186
202
|
for (const file of files) {
|
|
187
203
|
if (!order.has(file))
|
|
188
204
|
order.set(file, i);
|
|
@@ -191,8 +207,15 @@ export function snapshotOfRead(read) {
|
|
|
191
207
|
history.set(file, foldNewer(undefined, commit));
|
|
192
208
|
else
|
|
193
209
|
foldOlder(known, commit);
|
|
194
|
-
|
|
195
|
-
|
|
210
|
+
const name = folderOf(file);
|
|
211
|
+
const writer = name !== undefined && file === viewFile(name) && !runs.has(file) ? writerOf(commit, name) : undefined;
|
|
212
|
+
if (writer !== undefined)
|
|
213
|
+
runs.set(file, writer);
|
|
214
|
+
}
|
|
215
|
+
for (const name of writtenIn(commit)) {
|
|
216
|
+
const writer = !runs.has(viewFile(name)) ? writerOf(commit, name) : undefined;
|
|
217
|
+
if (writer !== undefined)
|
|
218
|
+
runs.set(viewFile(name), writer);
|
|
196
219
|
}
|
|
197
220
|
if (!isChange(commit))
|
|
198
221
|
return;
|
|
@@ -265,7 +288,8 @@ function messageOf(by) {
|
|
|
265
288
|
// The host's own book-keeping (an audit row): no trailer, so no change in the log a person reads.
|
|
266
289
|
if ("host" in by) {
|
|
267
290
|
const subject = `host: ${clean(by.host).trim() || "kept"}`;
|
|
268
|
-
|
|
291
|
+
const body = Object.entries(by.written ?? {}).map(([name, run]) => `Written-By: ${name}${run ? ` ${run}` : ""}\n`).join("");
|
|
292
|
+
return { message: body ? `${subject}\n\n${body}` : `${subject}\n`, subject, body, runId: "", changedBy: "", approvedVia: "" };
|
|
269
293
|
}
|
|
270
294
|
if ("run" in by) {
|
|
271
295
|
const subject = `learning: ${by.run}: merged`;
|
|
@@ -304,14 +328,15 @@ export function nextSnapshot(before, change, seconds) {
|
|
|
304
328
|
const deletes = new Set(change?.deletes ?? []);
|
|
305
329
|
const changed = [...new Set([...[...writes].filter(([path, { oid }]) => known.get(path) !== oid).map(([path]) => path), ...[...deletes].filter((path) => !writes.has(path))])].sort(byBytes);
|
|
306
330
|
const touched = new Set(changed);
|
|
307
|
-
const runId = commit.runId;
|
|
308
331
|
const written = writes.get(CORRECTIONS_FILE);
|
|
309
332
|
const corrections = written ? { path: CORRECTIONS_FILE, oid: written.oid, bytes: written.bytes } : deletes.has(CORRECTIONS_FILE) ? undefined : before?.corrections;
|
|
310
333
|
const ledger = writes.get(AUDITS_FILE);
|
|
311
334
|
const audits = ledger ? { oid: ledger.oid, bytes: ledger.bytes } : deletes.has(AUDITS_FILE) ? undefined : before?.audits;
|
|
312
335
|
const list = before?.workflows ?? [];
|
|
313
336
|
const hit = new Set(changed.map(folderOf).filter((name) => name !== undefined));
|
|
314
|
-
|
|
337
|
+
// A Written-By line moves its workflow's writer whether or not the commit changes its files (writtenIn).
|
|
338
|
+
const named = new Set(writtenIn(commit));
|
|
339
|
+
const workflows = list.filter((item) => !hit.has(item.name)).map((item) => ({ ...item, order: item.order + 1, ...(named.has(item.name) ? { run: writerOf(commit, item.name) ?? null } : {}) }));
|
|
315
340
|
for (const name of hit) {
|
|
316
341
|
const old = list.find((item) => item.name === name);
|
|
317
342
|
const prefix = `${WORKFLOWS_DIR}/${name}/`;
|
|
@@ -327,10 +352,11 @@ export function nextSnapshot(before, change, seconds) {
|
|
|
327
352
|
const keyText = writes.get(key)?.text;
|
|
328
353
|
// A link the change writes a file over, or deletes, is a link no more.
|
|
329
354
|
const links = (old?.links ?? []).filter((path) => !writes.has(path) && !deletes.has(path));
|
|
355
|
+
const writer = touched.has(viewFile(name)) || named.has(name) ? writerOf(commit, name) : undefined;
|
|
330
356
|
const item = learnedItem(name, [...files.values()], links, (path) => writes.get(path)?.text, {
|
|
331
357
|
order: 0,
|
|
332
358
|
history: touched.has(key) ? foldNewer(old?.history, commit) : (old?.history ?? { at: commit.at }),
|
|
333
|
-
run:
|
|
359
|
+
run: writer !== undefined ? writer : (old?.run ?? null),
|
|
334
360
|
}, keyText === undefined && old ? { description: old.description, status: old.status, ...(old.retired_from ? { retired_from: old.retired_from } : {}) } : undefined);
|
|
335
361
|
if (item)
|
|
336
362
|
workflows.push(item);
|
|
@@ -629,8 +655,10 @@ export class FolderTooLarge extends Error {
|
|
|
629
655
|
export async function commitChange(ws, base, change) {
|
|
630
656
|
const seconds = Math.floor(Date.now() / 1000);
|
|
631
657
|
const { snapshot, changed } = nextSnapshot(base, change, seconds);
|
|
632
|
-
// A change that changes nothing on main is no commit: main stays, and nothing is run.
|
|
633
|
-
|
|
658
|
+
// A change that changes nothing on main is no commit: main stays, and nothing is run. One that moves a workflow's
|
|
659
|
+
// writer is a commit, its files the same (a purge's put-back of main's own bytes: writtenIn).
|
|
660
|
+
const moves = snapshot.workflows.some((item) => base?.workflows.find((one) => one.name === item.name)?.run !== item.run);
|
|
661
|
+
if (base && change && !changed.length && !moves)
|
|
634
662
|
return { landed: true, main: base.main, snapshot: base };
|
|
635
663
|
const writes = change?.writes ?? [];
|
|
636
664
|
for (const { path } of writes)
|
|
@@ -680,8 +708,9 @@ export async function commitChange(ws, base, change) {
|
|
|
680
708
|
export async function snapshotAt(ws, commit) {
|
|
681
709
|
return (await folderAt(ws, commit))?.snapshot;
|
|
682
710
|
}
|
|
683
|
-
/** `commit` as main would have it (snapshotAt) with the blobs its tree holds, by oid, as git gave them
|
|
684
|
-
*
|
|
711
|
+
/** `commit` as main would have it (snapshotAt) with the blobs its tree holds, by oid, as git gave them, and each
|
|
712
|
+
* workflow's writers over its first-parent history, newest first (`writers`): one read-only exec. Undefined when the
|
|
713
|
+
* folder has no such commit. */
|
|
685
714
|
export async function folderAt(ws, commit) {
|
|
686
715
|
if (!/^[0-9a-f]{40}([0-9a-f]{24})?$/.test(commit))
|
|
687
716
|
throw new Error(`${JSON.stringify(commit)} is not a commit`);
|
|
@@ -692,7 +721,11 @@ export async function folderAt(ws, commit) {
|
|
|
692
721
|
throw failed("read", read);
|
|
693
722
|
const parsed = parseRead(read.stdout);
|
|
694
723
|
const snapshot = snapshotOfRead(parsed);
|
|
695
|
-
|
|
724
|
+
const writers = (name) => parsed.records.flatMap(({ commit: info, sha, files }, i) => {
|
|
725
|
+
const run = files.includes(viewFile(name)) || writtenIn(info).includes(name) ? writerOf(info, name) : undefined;
|
|
726
|
+
return run === undefined ? [] : [{ commit: sha, before: parsed.records[i + 1]?.sha, run }];
|
|
727
|
+
});
|
|
728
|
+
return snapshot ? { snapshot, blobs: parsed.blobs, writers } : undefined;
|
|
696
729
|
}
|
|
697
730
|
/** The texts `commit` holds at `paths` (each a plain path, checkPath), each read alone with one read-only exec (the
|
|
698
731
|
* script's show: git cat-file over each `<commit>:<path>`), never the whole tree, its blobs or its log, so the read is
|
package/dist/learn/promote.d.ts
CHANGED
|
@@ -6,6 +6,10 @@ import type { ReplayOutcome } from "../runner/workflow-first.js";
|
|
|
6
6
|
/** How many grades, and how many promotion records, an agent keeps (newest kept). */
|
|
7
7
|
export declare const GRADES_KEPT = 500;
|
|
8
8
|
export declare const PROMOTIONS_KEPT = 200;
|
|
9
|
+
/** How many champions of a workflow the promotions trim keeps back from the one the purge gate's answer leaves, that
|
|
10
|
+
* one included (trimPromotions): a purge that lands inside one write's ask-to-write window and refuses fewer than this
|
|
11
|
+
* many champions in a row still leaves one before them that serves. */
|
|
12
|
+
export declare const CHAMPIONS_KEPT = 5;
|
|
9
13
|
/** The most characters a grade's words (`label`) may hold, and the most of them and of an answer a compile ask shows. */
|
|
10
14
|
export declare const LABEL_MAX = 4000;
|
|
11
15
|
export declare const GRADE_SOURCES: readonly ["feedback", "eval"];
|
|
@@ -259,8 +263,17 @@ export declare const promotionOf: (records: readonly PromotionRecord[], workflow
|
|
|
259
263
|
/** The champion of `workflow`: the newest record of the digest promoted last, while that digest's newest record still
|
|
260
264
|
* says promote. A newer revision replaying or held never stops it; it stops when a newer revision's check promotes that
|
|
261
265
|
* one (then the champion), or when its own newest record is a hold (a held revision its owner replays, askReplay, that
|
|
262
|
-
* promotes wins again). The money rule stops it on its own (runner/workflow-first.ts).
|
|
263
|
-
|
|
266
|
+
* promotes wins again). The money rule stops it on its own (runner/workflow-first.ts). A record `refused` names is
|
|
267
|
+
* skipped, as if absent: one whose commit holds its workflow as a purged run wrote it (purged-workflow.ts refusedOf), so
|
|
268
|
+
* after a purge of the champion's run the newest promotion the purge gate lets through serves again. Undefined: none. */
|
|
269
|
+
export declare function championOf(records: readonly PromotionRecord[], workflow: string, refused?: Refused): PromotionRecord | undefined;
|
|
270
|
+
/** The promotion records championOf skips (purged-workflow.ts refusedOf: the purge gate refuses each at its commit, so
|
|
271
|
+
* it names a record by its workflow and commit, a copy read later included). Every reader that serves or names the
|
|
272
|
+
* champion passes it, and the trim keeps the champion past it (trimPromotions). `unread`: a commit it asked could not be
|
|
273
|
+
* read, so it may refuse too few, and the trim trims nothing on it (recordPromotion fails closed). */
|
|
274
|
+
export type Refused = ((record: PromotionRecord) => boolean) & {
|
|
275
|
+
readonly unread?: boolean;
|
|
276
|
+
};
|
|
264
277
|
/** The newest promotion of `workflow` at `digest`: the promote record that began its newest run of promote records (its
|
|
265
278
|
* first, or the first after a record of that digest that was not promote: an owner's replay that promoted a held
|
|
266
279
|
* revision), or undefined when none was ever promoted. Its `at` names that promotion: an audit row keeps the one serving
|
|
@@ -272,8 +285,8 @@ export declare function promotionStartOf(records: readonly PromotionRecord[], wo
|
|
|
272
285
|
export declare function replayingOf(records: readonly PromotionRecord[], workflow: string, digest: string | null): PromotionRecord[];
|
|
273
286
|
/** What each learned workflow with a record serves, by name: `digest`, its champion's (championOf; null: none serves,
|
|
274
287
|
* the agent takes its runs), and `replaying`, the revision other than it whose check is at work (null: none). What the
|
|
275
|
-
* promotions list says beside the records (GET /agents/{id}/learning/promotions)
|
|
276
|
-
export declare function servingOf(records: readonly PromotionRecord[]): {
|
|
288
|
+
* promotions list says beside the records (GET /agents/{id}/learning/promotions), its champion skipping `refused`. */
|
|
289
|
+
export declare function servingOf(records: readonly PromotionRecord[], refused?: Refused): {
|
|
277
290
|
workflow: string;
|
|
278
291
|
digest: string | null;
|
|
279
292
|
replaying: string | null;
|
|
@@ -289,16 +302,16 @@ export type ServingState = "serving" | "checking" | "held" | "stopped";
|
|
|
289
302
|
/** Whether the money rule stops `workflow` at `digest` from running first: runner/workflow-first.ts costStopOf over the
|
|
290
303
|
* agent's runs, the decision a run's claim reads (workflowFirstOf). */
|
|
291
304
|
export type CostStop = (workflow: string, digest: string) => boolean;
|
|
292
|
-
export declare function servingStateOf(records: readonly PromotionRecord[], workflow: string, costStop: CostStop): ServingState;
|
|
305
|
+
export declare function servingStateOf(records: readonly PromotionRecord[], workflow: string, costStop: CostStop, refused?: Refused): ServingState;
|
|
293
306
|
/** The promotions list as it leaves (GET /agents/{id}/learning/promotions): the records and what serves (servingOf), every
|
|
294
307
|
* text in them cut by `shown` (learning.ts secretsShown, as the other learning reads cut theirs), at any depth and under
|
|
295
308
|
* any field, so a field added later is cut too: a workflow's name whole (`shown.name`), any other text of its part
|
|
296
309
|
* (`shown.text`: a reason, a digest, a run id). Numbers and the rest as they are. A replaying record's `launch` (a run
|
|
297
|
-
* launch: its notes, model and plane) never leaves: aggregates only. */
|
|
310
|
+
* launch: its notes, model and plane) never leaves: aggregates only. Its champions skip `refused` (championOf). */
|
|
298
311
|
export declare function promotionsShown(records: readonly PromotionRecord[], shown: {
|
|
299
312
|
readonly text: (text: string) => string;
|
|
300
313
|
readonly name: (name: string) => string;
|
|
301
|
-
}): {
|
|
314
|
+
}, refused?: Refused): {
|
|
302
315
|
promotions: PromotionRecord[];
|
|
303
316
|
serving: ReturnType<typeof servingOf>;
|
|
304
317
|
};
|
|
@@ -320,14 +333,25 @@ export type Recorded = {
|
|
|
320
333
|
* and of every record kept (`items`: a check across revisions, one at a time, in the same guarded write): so of two
|
|
321
334
|
* claims deciding at once only the first decision is kept, and only its claim acts on it (Recorded.won). What the one
|
|
322
335
|
* there now has blanked is blanked in `record` too (forgetRunIn): a record built on a copy read before a run's purge
|
|
323
|
-
* (a connected agent's next turn, release or decision carries its turns on) never writes that run's text back.
|
|
324
|
-
|
|
336
|
+
* (a connected agent's next turn, release or decision carries its turns on) never writes that run's text back. The trim
|
|
337
|
+
* keeps the champion past what the purge gate refuses too (`refused`, purged-workflow.ts refusedIn: asked before the
|
|
338
|
+
* guarded write when it would trim, over the records that write reads and `record` after them, so a promotion it lands
|
|
339
|
+
* for a revision the gate refuses is skipped as its readers skip it; a write that would trim records other than those
|
|
340
|
+
* it asked over, another writer's landing in between, reads and asks again). Fails closed: a gate that could not read
|
|
341
|
+
* a commit (Refused.unread) or could not be asked leaves every record, the write trims nothing. */
|
|
342
|
+
export declare function recordPromotion(settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, record: PromotionRecord, still: (now: PromotionRecord | undefined, items: readonly PromotionRecord[]) => boolean, refused?: (records: readonly PromotionRecord[]) => Promise<Refused>): Promise<Recorded>;
|
|
325
343
|
/** The newest records, at most PROMOTIONS_KEPT, in order, with each workflow's champion (championOf) the same after as
|
|
326
344
|
* before, whatever was dropped: championOf reads the digest promoted last and its newest record, so the trim keeps both
|
|
327
|
-
* (a held last revision is never trimmed into handing the champion back),
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
|
|
345
|
+
* (a held last revision is never trimmed into handing the champion back), read over every record and again past those
|
|
346
|
+
* `refused` names (the purge gate's: a champion its readers skip, so the earlier one they serve is kept), and a
|
|
347
|
+
* replaying revision's newest record (what its settle, its runs' claims and the one-check-at-a-time rule read: dropped,
|
|
348
|
+
* a newer revision would start a second check while its runs run, and its verdict would never land). Then the newest
|
|
349
|
+
* RECENT_KEPT records (the newest one, the record a write just landed, always: its write said it won, so its decision
|
|
350
|
+
* is there for the next claim). Then, in the room those leave, the champions before the one `refused` leaves, nearest
|
|
351
|
+
* first, CHAMPIONS_KEPT in all from that one (a purge landing after the gate answered refuses every champion its run
|
|
352
|
+
* wrote, two or more in a row: the newest one before them still serves), each one's promote and newest record whole
|
|
353
|
+
* or neither. The rest is the newest records. */
|
|
354
|
+
export declare function trimPromotions(items: readonly PromotionRecord[], refused?: Refused): PromotionRecord[];
|
|
331
355
|
/** How many of a replay's own runs ended each way (a run not ended past its deadline is failed): what each run did. A
|
|
332
356
|
* check record keeps them as it was decided on. */
|
|
333
357
|
export type ReplayOutcomes = Readonly<Record<ReplayOutcome, number>>;
|