@parcha/agentrun-serve 0.1.0-beta.32 → 0.1.0-beta.33
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 +37 -0
- package/README.md +78 -46
- package/dist/adapters.d.ts +0 -3
- package/dist/adapters.js +0 -7
- package/dist/agents.d.ts +1 -1
- package/dist/api-only.d.ts +14 -0
- package/dist/api-only.js +33 -0
- package/dist/archil-routes.d.ts +1 -1
- package/dist/box-egress-vm.d.ts +0 -8
- package/dist/box-egress-vm.js +0 -10
- package/dist/box-egress.d.ts +0 -4
- package/dist/box-egress.js +1 -16
- package/dist/box-paths.d.ts +25 -2
- package/dist/box-paths.js +79 -11
- package/dist/box-relay.d.ts +0 -11
- package/dist/box-relay.js +0 -20
- package/dist/box-settings.d.ts +46 -0
- package/dist/box-settings.js +107 -0
- package/dist/boxes.d.ts +4 -1
- package/dist/browser-cost.js +2 -1
- package/dist/browser-person.d.ts +0 -2
- package/dist/browser-person.js +0 -2
- package/dist/budget.d.ts +0 -4
- package/dist/budget.js +0 -7
- package/dist/cap.d.ts +0 -7
- package/dist/cap.js +0 -22
- package/dist/cli.js +23 -8
- package/dist/computers.d.ts +1 -1
- package/dist/console/assets/index-Dn0ngwG9.js +535 -0
- package/dist/console/assets/index-DvW6Aled.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/daytona-api.d.ts +0 -11
- package/dist/daytona-api.js +1 -82
- package/dist/docker-host-addresses.d.ts +37 -0
- package/dist/docker-host-addresses.js +110 -0
- package/dist/files.d.ts +0 -8
- package/dist/files.js +0 -17
- package/dist/github-connection.d.ts +1 -1
- package/dist/github-connection.js +1 -1
- package/dist/harness-install.d.ts +23 -0
- package/dist/harness-install.js +99 -4
- package/dist/harness.d.ts +4 -3
- package/dist/harness.js +16 -1
- package/dist/import.js +52 -13
- package/dist/learn/secrets.d.ts +2 -1
- package/dist/learn/secrets.js +19 -6
- package/dist/learned-workflow.d.ts +5 -4
- package/dist/learned-workflow.js +6 -3
- package/dist/learning-routes.d.ts +9 -46
- package/dist/learning-routes.js +25 -29
- package/dist/learning-run.d.ts +4 -231
- package/dist/learning-run.js +7 -651
- package/dist/live/translate.js +1 -1
- package/dist/mcp-gateway.d.ts +0 -3
- package/dist/mcp-gateway.js +0 -13
- package/dist/mcp-probe.d.ts +2 -2
- package/dist/mcp-probe.js +2 -2
- package/dist/mcp-servers-store.js +1 -1
- package/dist/openapi.js +3 -3
- package/dist/page.js +3 -1
- package/dist/paid-calls.js +3 -2
- package/dist/pause.d.ts +0 -2
- package/dist/pause.js +1 -8
- package/dist/place.d.ts +0 -5
- package/dist/place.js +0 -10
- package/dist/print.d.ts +2 -1
- package/dist/print.js +4 -2
- package/dist/run-db.d.ts +0 -2
- package/dist/run-db.js +0 -4
- package/dist/run-learning-served.d.ts +38 -0
- package/dist/run-learning-served.js +9 -0
- package/dist/run-secrets.d.ts +33 -0
- package/dist/run-secrets.js +53 -0
- package/dist/run-timeline-served.js +5 -2
- package/dist/run-view.d.ts +5 -9
- package/dist/run-view.js +4 -22
- package/dist/runner/adapter-loop.d.ts +8 -2
- package/dist/runner/adapter-loop.js +44 -12
- package/dist/runner/adapter-run-spec.d.ts +8 -0
- package/dist/runner/adapter-run-spec.js +6 -5
- package/dist/runner/adapters/pi.d.ts +4 -0
- package/dist/runner/adapters/pi.js +4 -1
- package/dist/runner/beside.js +19 -8
- package/dist/runner/claim-secrets.js +1 -1
- package/dist/runner/cli-run-spec.js +15 -1
- package/dist/runner/journal-kinds.d.ts +6 -0
- package/dist/runner/live-ticker.d.ts +1 -1
- package/dist/runner/live-ticker.js +28 -4
- package/dist/runner/loop-contract.d.ts +3 -2
- package/dist/runner/main.d.ts +11 -4
- package/dist/runner/main.js +39 -10
- package/dist/runner/mcp-claim.d.ts +1 -1
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/model-route.js +21 -2
- package/dist/runner/redact.d.ts +8 -2
- package/dist/runner/redact.js +11 -2
- package/dist/runner/workflow-spec.js +5 -9
- package/dist/runs-over-store.d.ts +1 -1
- package/dist/runs-over-store.js +16 -5
- package/dist/seal-key.d.ts +54 -15
- package/dist/seal-key.js +272 -84
- package/dist/sealed-settings.d.ts +2 -2
- package/dist/sealed-settings.js +3 -10
- package/dist/secrets.d.ts +2 -10
- package/dist/secrets.js +21 -17
- package/dist/server-secrets-store.js +1 -1
- package/dist/server-secrets.js +3 -0
- package/dist/server.d.ts +10 -6
- package/dist/server.js +89 -41
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/open.d.ts +12 -2
- package/dist/store/open.js +23 -3
- package/dist/store/postgres/migrate.js +18 -1
- package/dist/store/sqlite/store.js +23 -8
- package/dist/store/store.d.ts +3 -0
- package/dist/store-reads/journal.d.ts +16 -0
- package/dist/store-reads/journal.js +82 -6
- package/dist/store-view.js +38 -5
- package/dist/tool-keys.d.ts +4 -3
- package/dist/tool-keys.js +7 -4
- package/dist/tools.d.ts +1 -1
- package/dist/tools.js +4 -1
- package/dist/trigger-schedule.js +2 -1
- package/dist/trigger-secrets-shown.js +5 -1
- package/dist/workspace/computer-deps.d.ts +29 -0
- package/dist/workspace/computer-deps.js +48 -1
- package/dist/workspace/computer-for-claim.d.ts +7 -3
- package/dist/workspace/computer-for-claim.js +1 -1
- package/dist/workspace/computer-providers.d.ts +6 -2
- package/dist/workspace/computer-providers.js +1 -1
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace.d.ts +0 -3
- package/dist/workspace.js +0 -3
- package/launcher/agentrun-serve +6 -33
- package/package.json +14 -14
- package/templates/inbound-lead/agent.md +1 -1
- package/templates/kyb/agent.md +1 -1
- package/dist/app.d.ts +0 -5
- package/dist/app.js +0 -514
- package/dist/bounds.d.ts +0 -26
- package/dist/bounds.js +0 -137
- package/dist/console/assets/index-35-7aeIZ.js +0 -519
- package/dist/console/assets/index-Cejbov-Y.css +0 -1
- package/dist/content-filter.d.ts +0 -7
- package/dist/content-filter.js +0 -23
- package/dist/disk.d.ts +0 -33
- package/dist/disk.js +0 -85
- package/dist/door-line.d.ts +0 -23
- package/dist/door-line.js +0 -83
- package/dist/harness-app.d.ts +0 -69
- package/dist/harness-app.js +0 -1162
- package/dist/request-start.d.ts +0 -27
- package/dist/request-start.js +0 -381
- package/dist/run-box.d.ts +0 -205
- package/dist/run-box.js +0 -661
- package/dist/run-holder.d.ts +0 -52
- package/dist/run-holder.js +0 -139
- package/dist/runs.d.ts +0 -1200
- package/dist/runs.js +0 -4103
- package/dist/served-only.d.ts +0 -5
- package/dist/served-only.js +0 -12
package/dist/harness-install.js
CHANGED
|
@@ -21,8 +21,9 @@
|
|
|
21
21
|
// cut short) is never loaded, and the next install replaces it.
|
|
22
22
|
import { spawn } from "node:child_process";
|
|
23
23
|
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
24
|
-
import { chmod, copyFile, lstat, mkdir, mkdtemp, readdir, readFile, rename, rm } from "node:fs/promises";
|
|
24
|
+
import { chmod, copyFile, lstat, mkdir, mkdtemp, readdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
25
25
|
import { createRequire } from "node:module";
|
|
26
|
+
import { hostname } from "node:os";
|
|
26
27
|
import { basename, dirname, join, sep } from "node:path";
|
|
27
28
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
28
29
|
import { facts as claudeFacts } from "@parcha/agentrun-harness-claude/facts";
|
|
@@ -298,6 +299,80 @@ function runNpm(args, env, timeoutMs, signal, onKilled) {
|
|
|
298
299
|
});
|
|
299
300
|
});
|
|
300
301
|
}
|
|
302
|
+
/** The file an install of a harness into `dir` (`<data>/harnesses/<harness>`) keeps in the data directory while it runs,
|
|
303
|
+
* for every process on this data (a runner beside the server, one of its own, or one in another container on the same
|
|
304
|
+
* volume): the installing host and process, and since when. A failed install leaves why in it until the next install;
|
|
305
|
+
* one that lands removes it. In the data directory, not `<data>/harnesses`: an earlier build left that read-only with
|
|
306
|
+
* its flat install in it, which the install removes first (removeFlatInstall) and which a file of ours would keep. */
|
|
307
|
+
export const installMarkOf = (dir) => join(dirname(dirname(dir)), `.harness-install-${basename(dir)}.json`);
|
|
308
|
+
/** The mark written whole, beside it then renamed over it: a claim reading it while it changes reads the last mark or the
|
|
309
|
+
* new one, never part of one (which would read as no install). */
|
|
310
|
+
async function writeMark(dir, mark) {
|
|
311
|
+
const at = installMarkOf(dir);
|
|
312
|
+
await mkdir(dirname(at), { recursive: true });
|
|
313
|
+
const next = `${at}.${process.pid}.next`;
|
|
314
|
+
await writeFile(next, JSON.stringify(mark));
|
|
315
|
+
await rename(next, at);
|
|
316
|
+
}
|
|
317
|
+
async function readMark(dir) {
|
|
318
|
+
try {
|
|
319
|
+
const mark = JSON.parse(await readFile(installMarkOf(dir), "utf8"));
|
|
320
|
+
if (typeof mark.failed === "string")
|
|
321
|
+
return { failed: mark.failed, at: Number(mark.at) };
|
|
322
|
+
return typeof mark.host === "string" && typeof mark.pid === "number" && typeof mark.startedAt === "number" ? { host: mark.host, pid: mark.pid, startedAt: mark.startedAt } : undefined;
|
|
323
|
+
}
|
|
324
|
+
catch {
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
/** Whether process `pid` is alive (signal 0: one of another user's reads as alive too, by EPERM). */
|
|
329
|
+
const alive = (pid) => {
|
|
330
|
+
try {
|
|
331
|
+
process.kill(pid, 0);
|
|
332
|
+
return true;
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
return error.code === "EPERM";
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
/** Where a run's claim stands on a harness that installs on first use, in `dir`: "installed" once it is whole; while an
|
|
339
|
+
* install runs (its mark started within INSTALL_TIMEOUT_MS, by a live process when it names this host; another host's
|
|
340
|
+
* process can't be read from here, so its mark is trusted within that bound), it waits for that install, polling, never
|
|
341
|
+
* past that bound; `{ failed }` with the install's own words when the last install failed; "none" when nothing installs
|
|
342
|
+
* it (no mark, one past the bound, or one this host's installer that is gone left), so the caller says what is missing
|
|
343
|
+
* as before. `onWait`: told once, as it starts to wait. `signal` aborted (the run stopped, or its claim lost): it stops
|
|
344
|
+
* waiting and rejects; the install goes on. */
|
|
345
|
+
export async function installSettled(entry, dir, pins, { signal, onWait, pollMs = 250, timeoutMs = INSTALL_TIMEOUT_MS, isAlive = alive, host = hostname() } = {}) {
|
|
346
|
+
let waiting = false;
|
|
347
|
+
for (;;) {
|
|
348
|
+
if (entry.lacking(dir, pins) === undefined)
|
|
349
|
+
return "installed";
|
|
350
|
+
const mark = await readMark(dir);
|
|
351
|
+
if (mark === undefined)
|
|
352
|
+
return "none";
|
|
353
|
+
if ("failed" in mark)
|
|
354
|
+
return { failed: mark.failed };
|
|
355
|
+
if (Date.now() - mark.startedAt > timeoutMs || (mark.host === host && !isAlive(mark.pid)))
|
|
356
|
+
return "none";
|
|
357
|
+
signal?.throwIfAborted();
|
|
358
|
+
if (!waiting) {
|
|
359
|
+
waiting = true;
|
|
360
|
+
onWait?.();
|
|
361
|
+
}
|
|
362
|
+
await new Promise((resolve, reject) => {
|
|
363
|
+
const timer = setTimeout(done, pollMs);
|
|
364
|
+
function done() {
|
|
365
|
+
signal?.removeEventListener("abort", stop);
|
|
366
|
+
resolve();
|
|
367
|
+
}
|
|
368
|
+
function stop() {
|
|
369
|
+
clearTimeout(timer);
|
|
370
|
+
reject(signal.reason);
|
|
371
|
+
}
|
|
372
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}
|
|
301
376
|
/** The server's one installer of a harness into `dir`: `ensure()` resolves once it is installed whole, installing it first
|
|
302
377
|
* when it is not, and every caller while an install runs waits for that one. A failed install is not kept: the next call
|
|
303
378
|
* tries again. `stop()` stops an install that runs (its npm) and waits, bounded, for it to end. `onInstalled` hears of an
|
|
@@ -341,11 +416,31 @@ export class HarnessInstall {
|
|
|
341
416
|
if (this.stopping.signal.aborted)
|
|
342
417
|
return Promise.reject(new Error("the server is stopping"));
|
|
343
418
|
this.running ??= (async () => {
|
|
344
|
-
|
|
345
|
-
|
|
419
|
+
// The mark a run's claim reads, in this process or a runner's own (installSettled): installing now, then gone once
|
|
420
|
+
// it is in, or why it failed. Written first, before anything is read, so a claim made as this install starts (a run
|
|
421
|
+
// started just after the save that started it) finds it; gone at once when the harness is installed already.
|
|
422
|
+
await writeMark(this.dir, { host: hostname(), pid: process.pid, startedAt: Date.now() });
|
|
423
|
+
const pins = await this.pins().catch(async (error) => {
|
|
424
|
+
await rm(installMarkOf(this.dir), { force: true }).catch(() => undefined);
|
|
425
|
+
throw error;
|
|
426
|
+
});
|
|
427
|
+
if (this.entry.lacking(this.dir, pins) === undefined) {
|
|
428
|
+
await rm(installMarkOf(this.dir), { force: true });
|
|
346
429
|
return void (this.done = true);
|
|
430
|
+
}
|
|
347
431
|
const started = performance.now();
|
|
348
|
-
|
|
432
|
+
try {
|
|
433
|
+
await this.install(this.entry, this.dir, pins, this.stopping.signal);
|
|
434
|
+
}
|
|
435
|
+
catch (error) {
|
|
436
|
+
// Why it failed, for the runs that waited on it; a server that stops leaves no mark (its npm was stopped, not refused).
|
|
437
|
+
if (this.stopping.signal.aborted)
|
|
438
|
+
await rm(installMarkOf(this.dir), { force: true }).catch(() => undefined);
|
|
439
|
+
else
|
|
440
|
+
await writeMark(this.dir, { failed: error.message, at: Date.now() }).catch(() => undefined);
|
|
441
|
+
throw error;
|
|
442
|
+
}
|
|
443
|
+
await rm(installMarkOf(this.dir), { force: true });
|
|
349
444
|
this.done = true;
|
|
350
445
|
this.onInstalled?.(Math.round(performance.now() - started));
|
|
351
446
|
})().finally(() => (this.running = undefined));
|
package/dist/harness.d.ts
CHANGED
|
@@ -4,9 +4,10 @@ export declare const DEFAULT_HARNESS: HarnessId;
|
|
|
4
4
|
/** One harness as capabilities lists it: whether this server runs it, and when not, why; and whether it takes a message
|
|
5
5
|
* mid-turn (`steer`), or queues it for the turn's end. */
|
|
6
6
|
/** `default_model`: the model this server runs for the harness when a definition names none (`provider/model-id`), or
|
|
7
|
-
* null when it runs none there; harnessOffers sets it. `keys
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* null when it runs none there; harnessOffers sets it. `keys`: the model keys any one of which runs it here, on one
|
|
8
|
+
* unavailable only for want of a model key (any one, saved, lets it run) and on an available one alike (which of the
|
|
9
|
+
* keys it runs on), so a key's row names it before and after any key is saved (tool-keys.ts' rowUnlocks). The
|
|
10
|
+
* server's own: capabilities never serve it. */
|
|
10
11
|
/** `installs`: `on_first_use` on claude-agent or codex while its CLI is not installed in this server's data: its first run
|
|
11
12
|
* (or the first agent made on it) installs it (harness-install.ts). */
|
|
12
13
|
export type HarnessOffer = {
|
package/dist/harness.js
CHANGED
|
@@ -5,6 +5,16 @@
|
|
|
5
5
|
export const HARNESSES = ["pi", "claude-agent", "codex", "opencode"];
|
|
6
6
|
export const DEFAULT_HARNESS = "pi";
|
|
7
7
|
const offered = new WeakMap();
|
|
8
|
+
/** `env` with every model key taken out (each provider's, model.ts PROVIDER_KEYS, and the gateway's), its other
|
|
9
|
+
* properties kept as they are: what a harness would ask for with no model key. */
|
|
10
|
+
async function withoutModelKeys(env) {
|
|
11
|
+
// model.ts imports this module: read late, as the other modules here are.
|
|
12
|
+
const { GATEWAY_KEY_ENV, PROVIDER_KEYS } = await import("./model.js");
|
|
13
|
+
const descriptors = Object.getOwnPropertyDescriptors(env);
|
|
14
|
+
for (const name of [...Object.values(PROVIDER_KEYS).flat(), GATEWAY_KEY_ENV])
|
|
15
|
+
delete descriptors[name];
|
|
16
|
+
return Object.defineProperties({}, descriptors);
|
|
17
|
+
}
|
|
8
18
|
/** What this server offers of each harness, checked once per environment: each one's entry in the harness table says
|
|
9
19
|
* why it does not run here (harness-table.ts: an adapter's package, pins and endpoint, on a model of its wire's vendor),
|
|
10
20
|
* and whether one of its runs fits in this host's memory at all (host.ts). Whether a revision's model fits its harness
|
|
@@ -23,7 +33,12 @@ export function harnessOffers(env) {
|
|
|
23
33
|
// Claude Code not installed yet says so (its install probes the offers again).
|
|
24
34
|
const firstUse = entry.installs && !(await harnessInstalled(entry, env)) ? { installs: "on_first_use" } : {};
|
|
25
35
|
const refused = await entry.refusal(env, undefined, { atStart: true });
|
|
26
|
-
|
|
36
|
+
if (refused !== undefined)
|
|
37
|
+
return { id, available: false, steer: entry.steer, ...refused, ...firstUse };
|
|
38
|
+
// Available: which model keys run it here is what it would ask for with none of them (a key's row names it only
|
|
39
|
+
// when that key is one), so a row reads the same before and after another provider's key is saved.
|
|
40
|
+
const keyless = await entry.refusal(await withoutModelKeys(env), undefined, { atStart: true });
|
|
41
|
+
return { id, available: true, steer: entry.steer, ...(keyless?.keys?.length ? { keys: keyless.keys } : {}), ...firstUse };
|
|
27
42
|
}));
|
|
28
43
|
// A harness that runs here but whose one run is more than this host's memory for runs never starts: said here, so
|
|
29
44
|
// a save warns and a run is refused at once with why (runnable.ts), never a 429 to try again. One that lacks only a
|
package/dist/import.js
CHANGED
|
@@ -21,9 +21,9 @@ import { logLine } from "./print.js";
|
|
|
21
21
|
import { launchBody } from "./run-launch.js";
|
|
22
22
|
import { DEFAULT_PORT } from "./server.js";
|
|
23
23
|
import { REDACTED, secretCut, secretsIn } from "./secret-cut.js";
|
|
24
|
-
import { SECRET_NAMES, withSecrets } from "./secrets.js";
|
|
24
|
+
import { handedSecret, SECRET_NAMES, withSecrets } from "./secrets.js";
|
|
25
25
|
import { SEAL_KEY_ENV } from "./tool-keys.js";
|
|
26
|
-
import { bootSealKey } from "./seal-key.js";
|
|
26
|
+
import { bootSealKey, SealKeyRefused, withSealKey } from "./seal-key.js";
|
|
27
27
|
import { toolKeysOverStore } from "./tool-keys-store.js";
|
|
28
28
|
import { openServerSecretsOverStore } from "./server-secrets-store.js";
|
|
29
29
|
import { WEBHOOK_FILE, webhookSecretIn } from "./webhooks.js";
|
|
@@ -983,16 +983,15 @@ export async function describePlan(plan, store, { verbose = false } = {}) {
|
|
|
983
983
|
export async function importCommand(args, usage, { home = homedir(),
|
|
984
984
|
// The folder whose projects are left out as temporary (the OS's temp directory).
|
|
985
985
|
temp = tmpdir(), env, out = console.log, } = {}) {
|
|
986
|
-
// The server's own secrets, which the switch keeps sealed in the store, open only under the server's seal key:
|
|
987
|
-
// one way the server and runner
|
|
988
|
-
//
|
|
989
|
-
//
|
|
990
|
-
const
|
|
986
|
+
// The server's own secrets, which the switch keeps sealed in the store, open only under the server's seal key: it is
|
|
987
|
+
// booted the one way the server and runner boot it (seal-key.ts bootSealKey) once the store is open (keyed below), and
|
|
988
|
+
// checked against it. The key handed over wins (this process's, else a caller's own environment's: a test's), else the
|
|
989
|
+
// one in the data directory, as the server reads it.
|
|
990
|
+
const handedKey = handedSecret(SEAL_KEY_ENV) ?? env?.[SEAL_KEY_ENV];
|
|
991
|
+
const ownEnv = env === undefined;
|
|
991
992
|
// The server's own keys, which its start moved out of process.env (secrets.ts), read back in: the import cuts them out of
|
|
992
993
|
// what it keeps, as it cuts every other key in the environment.
|
|
993
994
|
env ??= withSecrets(process.env);
|
|
994
|
-
if (env[SEAL_KEY_ENV] === undefined)
|
|
995
|
-
Object.defineProperty(env, SEAL_KEY_ENV, { value: seal.text, enumerable: false, configurable: true });
|
|
996
995
|
// What it prints goes through the cut what it keeps does, with the keys secretlint finds in the lines themselves: a
|
|
997
996
|
// file or project named after a key is printed cut. The lines are held until the end, then scanned and printed.
|
|
998
997
|
const printed = secretCut(env, SECRET_NAMES);
|
|
@@ -1010,6 +1009,27 @@ temp = tmpdir(), env, out = console.log, } = {}) {
|
|
|
1010
1009
|
for (const line of lines.splice(0))
|
|
1011
1010
|
print(printed.text(line));
|
|
1012
1011
|
};
|
|
1012
|
+
let dir;
|
|
1013
|
+
/** The store's seal key, booted against `store` (seal-key.ts), and the environment the import reads given it, so the
|
|
1014
|
+
* store's sealed reads open under it. A dry run (`write` false) makes, moves and records nothing, and a store that holds
|
|
1015
|
+
* no secret and has no key is read with none. The key is cut from what is printed, as every key is. */
|
|
1016
|
+
let releaseKey = () => undefined;
|
|
1017
|
+
const keyed = async (store, write) => {
|
|
1018
|
+
const seal = await bootSealKey(store, dir, { given: handedKey, role: "import", write, say: (line) => void warnings.push(line.trimEnd()) });
|
|
1019
|
+
if (!seal)
|
|
1020
|
+
return;
|
|
1021
|
+
releaseKey = seal.release;
|
|
1022
|
+
printed.add([seal.text]);
|
|
1023
|
+
// The environment the import reads, this process's own or a caller's, with the key the boot checked as its seal key.
|
|
1024
|
+
env = withSealKey(ownEnv ? withSecrets(process.env) : env, seal.text);
|
|
1025
|
+
};
|
|
1026
|
+
/** A start the seal key refuses (seal-key.ts): said, in its words, and the import does not go on. */
|
|
1027
|
+
const sealRefused = (error) => {
|
|
1028
|
+
if (!(error instanceof SealKeyRefused))
|
|
1029
|
+
return false;
|
|
1030
|
+
warnings.push(`agentrun-serve import: ${error.message}`);
|
|
1031
|
+
return true;
|
|
1032
|
+
};
|
|
1013
1033
|
try {
|
|
1014
1034
|
let values;
|
|
1015
1035
|
try {
|
|
@@ -1042,13 +1062,15 @@ temp = tmpdir(), env, out = console.log, } = {}) {
|
|
|
1042
1062
|
console.error(`--from takes ${SOURCES.join(", ")}: not ${unknown.join(", ")}\n\n${usage}`);
|
|
1043
1063
|
return 2;
|
|
1044
1064
|
}
|
|
1045
|
-
|
|
1065
|
+
dir = values.data ?? defaultData({ ...env, HOME: home });
|
|
1046
1066
|
// The import's options, built from the open store: the tool keys the server keeps as sealed rows (tool-keys-store.ts),
|
|
1047
1067
|
// opened here with the seal key this process was handed, and this server's own secrets (server-secrets-store.ts). One
|
|
1048
1068
|
// that does not open is not known here, so not cut: said, as the server says it at its start. A dry run on a data
|
|
1049
1069
|
// directory with no store yet reads neither (none is there).
|
|
1050
1070
|
const optionsFrom = async (store) => {
|
|
1051
|
-
|
|
1071
|
+
// The environment as it is now: once the store's key is booted (keyed), it carries it.
|
|
1072
|
+
const keyEnv = env;
|
|
1073
|
+
const keys = store ? toolKeysOverStore(store, keyEnv, say("tool_keys")) : undefined;
|
|
1052
1074
|
if (keys) {
|
|
1053
1075
|
await keys.load();
|
|
1054
1076
|
keys.view();
|
|
@@ -1059,9 +1081,10 @@ temp = tmpdir(), env, out = console.log, } = {}) {
|
|
|
1059
1081
|
all: values.all === true,
|
|
1060
1082
|
deleted: values["include-deleted"] === true,
|
|
1061
1083
|
temp,
|
|
1062
|
-
env,
|
|
1084
|
+
env: keyEnv,
|
|
1063
1085
|
stored: keys ? keys.values() : {},
|
|
1064
|
-
|
|
1086
|
+
// With no key (a dry run over a store that keeps no secret: seal-key.ts) there is nothing of the server's to open.
|
|
1087
|
+
own: store && keyEnv[SEAL_KEY_ENV] !== undefined ? await ownSecrets(store, dir, keyEnv, say("webhook_secret")) : [],
|
|
1065
1088
|
};
|
|
1066
1089
|
// What it prints is cut with the saved keys too, and with every key the import (or the dry run) finds, as what it
|
|
1067
1090
|
// keeps is.
|
|
@@ -1082,12 +1105,19 @@ temp = tmpdir(), env, out = console.log, } = {}) {
|
|
|
1082
1105
|
let plan;
|
|
1083
1106
|
let found;
|
|
1084
1107
|
try {
|
|
1108
|
+
if (reader)
|
|
1109
|
+
await keyed(reader, false);
|
|
1085
1110
|
const options = await optionsFrom(reader);
|
|
1086
1111
|
plan = await planImport({ ...options, measure: true }, reader);
|
|
1087
1112
|
for (const line of await describePlan(plan, reader, { verbose: values.verbose === true }))
|
|
1088
1113
|
out(line);
|
|
1089
1114
|
found = [...plan.found, ...(reader ? await foundAll(reader, plan.held) : []), ...(await untiedFound(plan))];
|
|
1090
1115
|
}
|
|
1116
|
+
catch (error) {
|
|
1117
|
+
if (sealRefused(error))
|
|
1118
|
+
return 1;
|
|
1119
|
+
throw error;
|
|
1120
|
+
}
|
|
1091
1121
|
finally {
|
|
1092
1122
|
await reader?.close();
|
|
1093
1123
|
}
|
|
@@ -1117,6 +1147,14 @@ temp = tmpdir(), env, out = console.log, } = {}) {
|
|
|
1117
1147
|
throw error;
|
|
1118
1148
|
}
|
|
1119
1149
|
try {
|
|
1150
|
+
try {
|
|
1151
|
+
await keyed(store, true);
|
|
1152
|
+
}
|
|
1153
|
+
catch (error) {
|
|
1154
|
+
if (sealRefused(error))
|
|
1155
|
+
return 1;
|
|
1156
|
+
throw error;
|
|
1157
|
+
}
|
|
1120
1158
|
const options = await optionsFrom(store);
|
|
1121
1159
|
const plan = await planImport(options, store);
|
|
1122
1160
|
const report = await runImport(store, plan, options);
|
|
@@ -1143,6 +1181,7 @@ temp = tmpdir(), env, out = console.log, } = {}) {
|
|
|
1143
1181
|
}
|
|
1144
1182
|
}
|
|
1145
1183
|
finally {
|
|
1184
|
+
releaseKey();
|
|
1146
1185
|
await flush();
|
|
1147
1186
|
}
|
|
1148
1187
|
}
|
package/dist/learn/secrets.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ export declare const PRINT_MAX = 4096;
|
|
|
7
7
|
/** `text` with each of `values` (as written, as JSON writes it, and in each form the matcher finds as it stands: hex in
|
|
8
8
|
* any case, base64, a hex identifier in it folded) and each secret-shaped run replaced by "[redacted]": what the
|
|
9
9
|
* checker prints never holds a secret, wherever it was found, a file's name included, each value as a path names it too
|
|
10
|
-
* (pathSpelling). Every form is found in `text` as given, and overlapping
|
|
10
|
+
* (pathSpelling) and as a URL's path writes it (percentForms). Every form is found in `text` as given, and overlapping
|
|
11
|
+
* finds are redacted as one, so
|
|
11
12
|
* one value never hides part of another from the search. A text
|
|
12
13
|
* that still holds a value or a shape after that (a form not found as it stands: percent encoded, split by whitespace,
|
|
13
14
|
* an NFKC variant), or that is over `max` bytes (PRINT_MAX unless the caller names more), is redacted whole, never in
|
package/dist/learn/secrets.js
CHANGED
|
@@ -61,7 +61,8 @@ export const PRINT_MAX = 4096;
|
|
|
61
61
|
/** `text` with each of `values` (as written, as JSON writes it, and in each form the matcher finds as it stands: hex in
|
|
62
62
|
* any case, base64, a hex identifier in it folded) and each secret-shaped run replaced by "[redacted]": what the
|
|
63
63
|
* checker prints never holds a secret, wherever it was found, a file's name included, each value as a path names it too
|
|
64
|
-
* (pathSpelling). Every form is found in `text` as given, and overlapping
|
|
64
|
+
* (pathSpelling) and as a URL's path writes it (percentForms). Every form is found in `text` as given, and overlapping
|
|
65
|
+
* finds are redacted as one, so
|
|
65
66
|
* one value never hides part of another from the search. A text
|
|
66
67
|
* that still holds a value or a shape after that (a form not found as it stands: percent encoded, split by whitespace,
|
|
67
68
|
* an NFKC variant), or that is over `max` bytes (PRINT_MAX unless the caller names more), is redacted whole, never in
|
|
@@ -72,7 +73,7 @@ export function redactSecrets(text, values, max = PRINT_MAX) {
|
|
|
72
73
|
if (Buffer.byteLength(text) > max)
|
|
73
74
|
return "[redacted]";
|
|
74
75
|
const given = withPathSpellings(values.filter((v) => v.length > 0));
|
|
75
|
-
const forms = new Set(given.flatMap((v) => [v, asJson(v), ...(longEnough(v) ? needlesOf(v).plain : [])]).filter((form) => form.length > 0));
|
|
76
|
+
const forms = new Set(given.flatMap((v) => [v, asJson(v), ...(longEnough(v) ? [...needlesOf(v).plain, ...percentForms(v)] : [])]).filter((form) => form.length > 0));
|
|
76
77
|
const found = [
|
|
77
78
|
...[...forms].flatMap((form) => places(text, form)),
|
|
78
79
|
...given.filter(longEnough).flatMap((v) => spans(text, new RegExp(needlesOf(v).hex, "i"))),
|
|
@@ -125,13 +126,25 @@ function percentDecode(text, plusIsSpace) {
|
|
|
125
126
|
}
|
|
126
127
|
const asJson = (value) => JSON.stringify(value).slice(1, -1);
|
|
127
128
|
/** `value` as a path names it, when that differs: a tool that resolves a path the model wrote (pi's read) collapses each
|
|
128
|
-
* run of "/" to one
|
|
129
|
-
* (a random base64 key does, now and then) comes back so. A
|
|
130
|
-
*
|
|
129
|
+
* run of "/" to one, drops each "." segment ("/./", a leading "./") and a leading and a trailing "/", and its error
|
|
130
|
+
* names that path, so a held value holding "//" (a random base64 key does, now and then) or "/./" comes back so. A
|
|
131
|
+
* "/../" is not resolved: it drops the segment before it, and what is left is no longer the value. Only a spelling
|
|
132
|
+
* still long enough to be a secret is listed. */
|
|
131
133
|
const pathSpelling = (value) => {
|
|
132
|
-
|
|
134
|
+
let path = value;
|
|
135
|
+
for (let before = ""; before !== path;) {
|
|
136
|
+
before = path;
|
|
137
|
+
path = path.replace(/\/{2,}/g, "/").replace(/\/\.(?=\/|$)/g, "").replace(/^\.\//, "").replace(/^\//, "").replace(/\/$/, "");
|
|
138
|
+
}
|
|
133
139
|
return path !== value && longEnough(path) ? [path] : [];
|
|
134
140
|
};
|
|
141
|
+
/** `value` as a URL's path writes it, percent-encoded, when that differs: each byte encodeURIComponent encodes, its hex
|
|
142
|
+
* in upper case as it writes it and in lower case as some encoders do. Cut in place where found as it stands; any other
|
|
143
|
+
* encoding is still found by the matcher's decoded views, and the text is then cut whole. */
|
|
144
|
+
const percentForms = (value) => {
|
|
145
|
+
const upper = encodeURIComponent(value);
|
|
146
|
+
return upper === value ? [] : [...new Set([upper, upper.replace(/%[0-9A-F]{2}/g, (byte) => byte.toLowerCase())])];
|
|
147
|
+
};
|
|
135
148
|
/** Each held value, then its path spelling when it has one: every form a cut or the guard derives, derived of both. */
|
|
136
149
|
const withPathSpellings = (values) => values.flatMap((value) => [value, ...pathSpelling(value)]);
|
|
137
150
|
/** The separators a hex identifier is written with: a UUID's dashes, and the underscores, colons and dots of others. */
|
|
@@ -37,11 +37,12 @@ export type LearnedWorkflowRun = {
|
|
|
37
37
|
complete?: Complete;
|
|
38
38
|
/** The run's gate's permission of a tool now (tool-gate.ts RunGate policy): a call node's tool set to ask or deny is
|
|
39
39
|
* refused before any node runs, and asked again as each call node runs, a composed workflow's inner ones too, so one
|
|
40
|
-
* set to either since the call began is refused there, never run.
|
|
41
|
-
|
|
40
|
+
* set to either since the call began is refused there, never run. Required: a learned workflow never runs a tool
|
|
41
|
+
* on a default of allow (#2153). */
|
|
42
|
+
policy: (tool: string) => string;
|
|
42
43
|
/** Where the gate's permission of a tool was set (tool-gate.ts RunGate denyFrom), so a refusal names it: this agent's
|
|
43
|
-
* settings or this server's.
|
|
44
|
-
denyFrom
|
|
44
|
+
* settings or this server's. */
|
|
45
|
+
denyFrom: (tool: string) => SettingFrom;
|
|
45
46
|
/** Reads the gate's settings again (a runner's are in its store, read anew at each of its gate's decisions), awaited as
|
|
46
47
|
* each call node runs, before `policy` is asked: a tool set to deny since the call began is then refused. None: the
|
|
47
48
|
* gate reads its settings live (main's process). */
|
package/dist/learned-workflow.js
CHANGED
|
@@ -133,7 +133,10 @@ export async function runLearned(run, flow, input, signal, ledger) {
|
|
|
133
133
|
// Checked again at the call, against the agent's own tools as its run has them, before any node runs: what merged under
|
|
134
134
|
// another revision may name one it has no more.
|
|
135
135
|
// The tools the gate allows now; one set to ask or deny is refused in the words a workflow revision's call node is.
|
|
136
|
-
|
|
136
|
+
// A run handed no gate (a caller past the types) runs nothing: a tool is never allowed for want of a policy.
|
|
137
|
+
if (typeof run.policy !== "function" || typeof run.denyFrom !== "function")
|
|
138
|
+
return refuse("its run gave no tool policy for its call nodes");
|
|
139
|
+
const { tools, gated, deniedBy } = learnedDraftTools(run.granted, run.policy, run.plane, run.denyFrom);
|
|
137
140
|
const problems = draftProblems(dsl, flow.workflow, tools, gated, deniedBy);
|
|
138
141
|
if (problems.length)
|
|
139
142
|
return refuse(problems.map(({ detail }) => detail).join("; "));
|
|
@@ -172,9 +175,9 @@ export async function runLearned(run, flow, input, signal, ledger) {
|
|
|
172
175
|
// a tool set to deny since the call began is refused in the gate's words, one set to ask too, since a call node
|
|
173
176
|
// cannot wait for an approval. Neither runs.
|
|
174
177
|
await run.refresh?.();
|
|
175
|
-
const permission = run.policy
|
|
178
|
+
const permission = run.policy(tool);
|
|
176
179
|
if (permission === "deny")
|
|
177
|
-
throw new Error(deniedText(tool, undefined, run.denyFrom
|
|
180
|
+
throw new Error(deniedText(tool, undefined, run.denyFrom(tool)));
|
|
178
181
|
if (permission === "ask")
|
|
179
182
|
throw new Error(`This ${tool} call needs a person's approval, which a workflow's call node cannot wait for; it was not run.`);
|
|
180
183
|
// Its paid requests booked under the tool's call, as a call of its own: the node, its execution path, its item in a map.
|
|
@@ -2,7 +2,7 @@ import type { IncomingMessage, ServerResponse } from "node:http";
|
|
|
2
2
|
import { type Problem } from "./learn/index.js";
|
|
3
3
|
import { type ItemStatus, type Learning, type NoteRuns, type Shown } from "./learning.js";
|
|
4
4
|
import type { Impact } from "./learning-run.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { Store } from "./store/store.js";
|
|
6
6
|
type Page<T> = {
|
|
7
7
|
items: T[];
|
|
8
8
|
total: number;
|
|
@@ -149,47 +149,8 @@ export declare function writeNote(data: string, agentId: string, raw: string, in
|
|
|
149
149
|
text: string;
|
|
150
150
|
etag: string;
|
|
151
151
|
}>;
|
|
152
|
-
/** GET /runs/{id}/learning: the run's learning whole, or null for a run that does not learn: its detail cut of the
|
|
153
|
-
* host's secrets now, and the notes it read and learned as its view shows them (learning.ts notesView). */
|
|
154
|
-
export declare function runLearning(run: Run, shown: Shown, secrets: readonly string[], data: string): Promise<{
|
|
155
|
-
seed: string | null;
|
|
156
|
-
merged: string | null;
|
|
157
|
-
pending: {
|
|
158
|
-
file: string;
|
|
159
|
-
name: string;
|
|
160
|
-
}[];
|
|
161
|
-
verdict: {
|
|
162
|
-
merge: boolean;
|
|
163
|
-
reason: string;
|
|
164
|
-
items: {
|
|
165
|
-
why: string;
|
|
166
|
-
question?: string | undefined;
|
|
167
|
-
origin?: "run" | "you" | undefined;
|
|
168
|
-
pending?: boolean | undefined;
|
|
169
|
-
file: string;
|
|
170
|
-
keep: boolean;
|
|
171
|
-
}[];
|
|
172
|
-
} | null;
|
|
173
|
-
problems: Problem[];
|
|
174
|
-
cost_usd: {
|
|
175
|
-
grade: number | null;
|
|
176
|
-
};
|
|
177
|
-
tokens: {
|
|
178
|
-
grade: import("./learning.js").Tokens | null;
|
|
179
|
-
};
|
|
180
|
-
given?: import("./learning.js").NoteUsed[];
|
|
181
|
-
read?: import("./learning.js").NoteUsed[];
|
|
182
|
-
learned?: import("./learning.js").NoteLearned[];
|
|
183
|
-
skills?: import("./learning.js").LearnedFile[];
|
|
184
|
-
workflows?: import("./learning.js").LearnedFile[];
|
|
185
|
-
run: string;
|
|
186
|
-
state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
|
|
187
|
-
reason: "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "cancelled" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
|
|
188
|
-
detail: string | null;
|
|
189
|
-
at: string;
|
|
190
|
-
} | null>;
|
|
191
152
|
/** GET /runs/{id}/learning's body, from the run's learning as it reads now, the seed it started from and whether it
|
|
192
|
-
* settled: the one shape, read from
|
|
153
|
+
* settled: the one shape, read from the one store (store-reads/learning.ts
|
|
193
154
|
* runLearningOverStore). */
|
|
194
155
|
export declare function runLearningBody(input: {
|
|
195
156
|
readonly id: string;
|
|
@@ -233,11 +194,13 @@ export declare function runLearningBody(input: {
|
|
|
233
194
|
detail: string | null;
|
|
234
195
|
at: string;
|
|
235
196
|
};
|
|
236
|
-
/** GET /runs/{id}/learning/diff: once merged
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
|
|
197
|
+
/** GET /runs/{id}/learning/diff over the one store: once merged (its learning end, store-reads/learning.ts
|
|
198
|
+
* runLearningEnd), its merge commit against its parent, as its merge's script wrote it (`.agentrun/diffs/<run>.json` in
|
|
199
|
+
* its agent's learning folder); before, its kept proposal (new notes only, from its learning_proposals row) against its
|
|
200
|
+
* seed; a run that proposed nothing, no file, against the seed its launch's learning start names. A run that does not
|
|
201
|
+
* learn (no learning start and no learning end) is not_found. A file's patch is withheld when too large (as the script
|
|
202
|
+
* wrote it), or when it holds one of the host's secrets now (`shown`). */
|
|
203
|
+
export declare function runDiffOverStore(data: string, store: Store, runId: string, shown: Shown): Promise<{
|
|
241
204
|
base: string;
|
|
242
205
|
head: string;
|
|
243
206
|
files: ({
|
package/dist/learning-routes.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
1
|
import { approve, buildIndex, CAPS, checkNote, draftProblems, frontKeys, INDEX_FILE, INDEX_LINES, isHeld, LEARNED_KEYS, learnedName, learnedPlace, learnedStatus, NOTE_FILE, NOTE_STATUSES, parseNoteFile, printable, released, retire, retiredLearned, skillProblems, SKILLS_DIR, supersede, unstorable, WORKFLOWS_DIR } from "./learn/index.js";
|
|
3
2
|
import { beforeRetire, blobOid, FolderBusy, FolderRefused, FolderTooLarge, FolderUnreadable, heldOnMain, isBodyMismatch, readLearning, PATCH_CAP, readRunDiff, readSnapshot, snapshotNotes, writeLearning } from "./learn/folder.js";
|
|
4
3
|
import { ApiError, invalid } from "./errors.js";
|
|
5
|
-
import {
|
|
6
|
-
import { currentLearning, holdsForOk, detailShown, learningFolderOf, notesView, PROPOSAL, readPin, secretsShown, withAgentRepo } from "./learning.js";
|
|
4
|
+
import { detailShown, learningFolderOf, notesView, secretsShown, withAgentRepo } from "./learning.js";
|
|
7
5
|
import { isObject } from "./validate.js";
|
|
6
|
+
import { launchOf } from "./handed-values.js";
|
|
7
|
+
import { learningStartOf } from "./run-launch.js";
|
|
8
|
+
import { runLearningEnd } from "./store-reads/learning.js";
|
|
8
9
|
/** The agent view's first pages, and the most a page holds. */
|
|
9
10
|
const NOTES_PAGE = 50;
|
|
10
11
|
const LOG_PAGE = 20;
|
|
@@ -495,18 +496,8 @@ export async function writeNote(data, agentId, raw, input) {
|
|
|
495
496
|
}
|
|
496
497
|
});
|
|
497
498
|
}
|
|
498
|
-
/** GET /runs/{id}/learning: the run's learning whole, or null for a run that does not learn: its detail cut of the
|
|
499
|
-
* host's secrets now, and the notes it read and learned as its view shows them (learning.ts notesView). */
|
|
500
|
-
export async function runLearning(run, shown, secrets, data) {
|
|
501
|
-
// What it held for its owner's OK as it reads now (learning.ts currentLearning); its record stays as the merge wrote it.
|
|
502
|
-
const learning = holdsForOk(run.meta.learning) ? currentLearning(run.meta.learning, await statusesOf(data, run.agentId)) : run.meta.learning;
|
|
503
|
-
if (!learning)
|
|
504
|
-
return null;
|
|
505
|
-
const pin = await readPin(run.dir).catch(() => undefined);
|
|
506
|
-
return runLearningBody({ id: run.id, learning, seed: pin?.seed ?? null, settled: run.settled }, shown, secrets);
|
|
507
|
-
}
|
|
508
499
|
/** GET /runs/{id}/learning's body, from the run's learning as it reads now, the seed it started from and whether it
|
|
509
|
-
* settled: the one shape, read from
|
|
500
|
+
* settled: the one shape, read from the one store (store-reads/learning.ts
|
|
510
501
|
* runLearningOverStore). */
|
|
511
502
|
export function runLearningBody(input, shown, secrets) {
|
|
512
503
|
const { learning } = input;
|
|
@@ -537,28 +528,33 @@ function addedPatch(text) {
|
|
|
537
528
|
const added = [...lines.map((one) => `+${one}\n`), ...(last ? [`+${last}\n\\n`] : [])];
|
|
538
529
|
return `@@ -0,0 +1${added.length === 1 ? "" : `,${added.length}`} @@\n${added.join("")}`;
|
|
539
530
|
}
|
|
540
|
-
/** GET /runs/{id}/learning/diff: once merged
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
531
|
+
/** GET /runs/{id}/learning/diff over the one store: once merged (its learning end, store-reads/learning.ts
|
|
532
|
+
* runLearningEnd), its merge commit against its parent, as its merge's script wrote it (`.agentrun/diffs/<run>.json` in
|
|
533
|
+
* its agent's learning folder); before, its kept proposal (new notes only, from its learning_proposals row) against its
|
|
534
|
+
* seed; a run that proposed nothing, no file, against the seed its launch's learning start names. A run that does not
|
|
535
|
+
* learn (no learning start and no learning end) is not_found. A file's patch is withheld when too large (as the script
|
|
536
|
+
* wrote it), or when it holds one of the host's secrets now (`shown`). */
|
|
537
|
+
export async function runDiffOverStore(data, store, runId, shown) {
|
|
538
|
+
const [end, kept, launch, row] = await Promise.all([runLearningEnd(store, runId), store.learning.proposal(runId), launchOf(store, runId), store.runs.get(runId)]);
|
|
539
|
+
const start = launch ? learningStartOf(launch) : undefined;
|
|
540
|
+
if (!row || (!end && !start))
|
|
547
541
|
throw new ApiError("not_found", "the run does not learn, so it proposed nothing");
|
|
548
542
|
const file = (name, status, patch) => {
|
|
549
543
|
const path = shown.name(name);
|
|
550
544
|
return Buffer.byteLength(patch) > PATCH_CAP ? { path, status, withheld: "too_large" } : shown.holds(patch) ? { path, status, withheld: "secret" } : { path, status, patch };
|
|
551
545
|
};
|
|
552
|
-
if (
|
|
553
|
-
const folder = learningFolderOf(data,
|
|
554
|
-
const diff = await readRunDiff(folder.workspace,
|
|
555
|
-
if (!diff || diff.merge !==
|
|
546
|
+
if (end?.merged) {
|
|
547
|
+
const folder = learningFolderOf(data, row.agentId);
|
|
548
|
+
const diff = await readRunDiff(folder.workspace, runId).catch((error) => Promise.reject(routeFailure(error))).finally(() => folder.end());
|
|
549
|
+
if (!diff || diff.merge !== end.merged)
|
|
556
550
|
throw new ApiError("not_found", "the run's merge is not in its agent's learning folder");
|
|
557
551
|
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 })) };
|
|
558
552
|
}
|
|
559
|
-
const
|
|
560
|
-
const
|
|
561
|
-
if (
|
|
553
|
+
const kept_ = isObject(kept?.proposal) ? kept.proposal.proposal : undefined;
|
|
554
|
+
const proposal = isObject(kept_) && typeof kept_.seed === "string" && Array.isArray(kept_.notes) ? { seed: kept_.seed, notes: kept_.notes } : undefined;
|
|
555
|
+
if (proposal) {
|
|
556
|
+
const notes = proposal.notes.filter((note) => isObject(note) && typeof note.file === "string" && NOTE_FILE.test(note.file) && typeof note.text === "string");
|
|
562
557
|
return { base: proposal.seed, head: null, files: notes.map((note) => file(note.file, "added", addedPatch(note.text))) };
|
|
563
|
-
|
|
558
|
+
}
|
|
559
|
+
return { base: start?.seed ?? null, head: null, files: [] };
|
|
564
560
|
}
|