@parcha/agentrun-serve 0.1.0-beta.50 → 0.1.0-beta.52
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 +185 -0
- package/README.md +236 -30
- package/dist/adapters.js +1 -1
- package/dist/agent-delete.d.ts +13 -2
- package/dist/agent-delete.js +14 -5
- package/dist/agents-store.d.ts +5 -1
- package/dist/agents-store.js +17 -7
- package/dist/api-only.d.ts +6 -3
- package/dist/api-only.js +8 -5
- package/dist/archil-routes.d.ts +1 -0
- package/dist/archil-routes.js +28 -2
- package/dist/capacity.d.ts +50 -0
- package/dist/capacity.js +49 -0
- package/dist/cli-learning/claude-wire.d.ts +41 -0
- package/dist/cli-learning/claude-wire.js +258 -0
- package/dist/cli-learning/cli.d.ts +11 -0
- package/dist/cli-learning/cli.js +241 -0
- package/dist/cli-learning/codex-worktree.d.ts +10 -0
- package/dist/cli-learning/codex-worktree.js +119 -0
- package/dist/cli-learning/connections.d.ts +62 -0
- package/dist/cli-learning/connections.js +87 -0
- package/dist/cli-learning/entry.d.ts +1 -0
- package/dist/cli-learning/entry.js +4 -0
- package/dist/cli-learning/evidence.d.ts +78 -0
- package/dist/cli-learning/evidence.js +492 -0
- package/dist/cli-learning/hook.d.ts +33 -0
- package/dist/cli-learning/hook.js +544 -0
- package/dist/cli-learning/install.d.ts +33 -0
- package/dist/cli-learning/install.js +335 -0
- package/dist/cli-learning/observation-proof.d.ts +14 -0
- package/dist/cli-learning/observation-proof.js +10 -0
- package/dist/cli-learning/policy.d.ts +48 -0
- package/dist/cli-learning/policy.js +363 -0
- package/dist/cli-learning/schema.d.ts +16 -0
- package/dist/cli-learning/schema.js +27 -0
- package/dist/cli-learning/state.d.ts +23 -0
- package/dist/cli-learning/state.js +61 -0
- package/dist/cli.js +24 -2
- package/dist/computer-setting.d.ts +8 -0
- package/dist/computer-setting.js +11 -0
- package/dist/computers.d.ts +6 -2
- package/dist/computers.js +2 -2
- package/dist/console/assets/index-B-D0EM3j.js +733 -0
- package/dist/console/assets/{index-D0mr9wfZ.css → index-DlQepP2J.css} +1 -1
- package/dist/console/index.html +2 -2
- package/dist/email/email-faux.d.ts +3 -1
- package/dist/email/email-faux.js +3 -2
- package/dist/email/routes.js +22 -12
- package/dist/fal-price.d.ts +76 -0
- package/dist/fal-price.js +368 -0
- package/dist/harness-install.d.ts +6 -2
- package/dist/harness-install.js +40 -8
- package/dist/harness.d.ts +1 -1
- package/dist/harness.js +2 -2
- package/dist/learn/commit.d.ts +5 -0
- package/dist/learn/commit.js +4 -1
- package/dist/learn/compile.d.ts +13 -5
- package/dist/learn/compile.js +24 -7
- package/dist/learn/delete.d.ts +12 -6
- package/dist/learn/delete.js +17 -11
- package/dist/learn/folder.d.ts +11 -0
- package/dist/learn/folder.js +20 -3
- package/dist/learn/learning-of.d.ts +8 -0
- package/dist/learn/learning-of.js +8 -0
- package/dist/learn/learning.sh +14 -1
- package/dist/learn/promote.d.ts +51 -7
- package/dist/learn/promote.js +51 -8
- package/dist/learn/secrets.js +14 -3
- package/dist/learning-reset.d.ts +18 -0
- package/dist/learning-reset.js +115 -0
- package/dist/learning-routes.d.ts +1 -1
- package/dist/learning-words.d.ts +6 -1
- package/dist/learning-words.js +6 -1
- package/dist/learning.d.ts +8 -6
- package/dist/learning.js +5 -4
- package/dist/llms.txt +1 -0
- package/dist/mcp-gateway.d.ts +39 -2
- package/dist/mcp-gateway.js +41 -10
- package/dist/mcp-pin-first.js +3 -2
- package/dist/mcp-private-hosts.d.ts +24 -3
- package/dist/mcp-private-hosts.js +53 -3
- package/dist/mcp-servers-store.d.ts +1 -0
- 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-gateway.d.ts +2 -0
- package/dist/model-gateway.js +3 -1
- package/dist/native/runtimes.d.ts +2 -0
- package/dist/native/runtimes.js +2 -0
- package/dist/observation/learning.d.ts +32 -0
- package/dist/observation/learning.js +66 -0
- package/dist/observation/observer.d.ts +8 -1
- package/dist/observation/observer.js +89 -9
- package/dist/observation/schema.js +12 -4
- package/dist/observation/usage-identity.d.ts +9 -0
- package/dist/observation/usage-identity.js +11 -0
- package/dist/openapi.js +133 -24
- package/dist/provider.d.ts +8 -0
- package/dist/provider.js +14 -2
- 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-launch.d.ts +27 -4
- package/dist/run-launch.js +18 -3
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-usage.d.ts +48 -4
- package/dist/run-usage.js +156 -39
- package/dist/run-view.d.ts +2 -0
- package/dist/run-view.js +8 -7
- package/dist/runner/adapter-loop.d.ts +3 -1
- package/dist/runner/adapter-loop.js +41 -35
- package/dist/runner/adapter-run-spec.d.ts +1 -1
- package/dist/runner/adapter-run-spec.js +15 -15
- package/dist/runner/audit.d.ts +8 -3
- package/dist/runner/audit.js +21 -6
- package/dist/runner/beside.d.ts +13 -0
- package/dist/runner/beside.js +27 -8
- package/dist/runner/claim-secrets.d.ts +2 -1
- package/dist/runner/claim-secrets.js +5 -3
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +14 -13
- package/dist/runner/conformance/harness.js +4 -2
- package/dist/runner/disk-free.d.ts +44 -0
- package/dist/runner/disk-free.js +96 -0
- package/dist/runner/dispatch.js +4 -2
- package/dist/runner/feedback-round.d.ts +12 -8
- package/dist/runner/feedback-round.js +16 -30
- package/dist/runner/harness-loops.js +8 -3
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/learning-end.d.ts +2 -1
- package/dist/runner/learning-end.js +51 -22
- package/dist/runner/main.d.ts +17 -6
- package/dist/runner/main.js +187 -45
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/mcp-run.d.ts +9 -0
- package/dist/runner/mcp-run.js +16 -1
- package/dist/runner/model-route.js +7 -4
- package/dist/runner/presence.d.ts +11 -2
- package/dist/runner/presence.js +31 -3
- package/dist/runner/promotion.d.ts +40 -21
- package/dist/runner/promotion.js +130 -59
- package/dist/runner/run-child-host.d.ts +12 -15
- package/dist/runner/run-child-host.js +52 -112
- package/dist/runner/run-errors.js +2 -0
- package/dist/runner/runner-check.d.ts +51 -0
- package/dist/runner/runner-check.js +206 -0
- package/dist/runner/runner-metrics.d.ts +19 -0
- package/dist/runner/runner-metrics.js +49 -0
- package/dist/runner/runner.d.ts +37 -0
- package/dist/runner/runner.js +58 -6
- package/dist/runner/sdk-loop.d.ts +2 -2
- package/dist/runner/sdk-loop.js +37 -25
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/workflow-spec.js +3 -3
- package/dist/runs-over-store.d.ts +13 -3
- package/dist/runs-over-store.js +71 -16
- package/dist/sdk/check.d.ts +6 -5
- package/dist/sdk/check.js +17 -16
- package/dist/sdk/runs.d.ts +22 -2
- package/dist/sdk/runs.js +167 -82
- package/dist/server.d.ts +3 -0
- package/dist/server.js +230 -43
- package/dist/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/start-switches.js +2 -0
- package/dist/stats.d.ts +4 -0
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +16 -0
- package/dist/store/agent-body.js +20 -3
- package/dist/store/dialect.d.ts +2 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.d.ts +2 -0
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/connection.d.ts +5 -2
- package/dist/store/postgres/connection.js +19 -7
- package/dist/store/postgres/dialect.js +1 -0
- package/dist/store/postgres/migrate.d.ts +30 -0
- package/dist/store/postgres/migrate.js +72 -5
- package/dist/store/postgres/migration-lint.d.ts +8 -0
- package/dist/store/postgres/migration-lint.js +119 -0
- package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
- 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/postgres/store.d.ts +8 -3
- package/dist/store/postgres/store.js +31 -11
- package/dist/store/schema.d.ts +32 -2
- package/dist/store/schema.js +74 -5
- package/dist/store/sqlite/run-launch.d.ts +31 -1
- package/dist/store/sqlite/run-launch.js +111 -2
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +4 -3
- package/dist/store/sqlite/store.d.ts +17 -0
- package/dist/store/sqlite/store.js +226 -37
- package/dist/store/store-schema.d.ts +34 -0
- package/dist/store/store-schema.js +125 -0
- package/dist/store/store.d.ts +120 -5
- package/dist/store/store.js +13 -0
- package/dist/store-reads/analytics.d.ts +3 -2
- package/dist/store-reads/analytics.js +20 -8
- 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 +4 -3
- package/dist/store-view.js +11 -7
- package/dist/template-eval.js +4 -4
- package/dist/templates.d.ts +6 -2
- package/dist/templates.js +7 -5
- package/dist/timeline/labels.js +1 -1
- package/dist/tool-gate.d.ts +4 -2
- package/dist/tools.js +1 -1
- package/dist/unified-usage.d.ts +24 -0
- package/dist/unified-usage.js +400 -0
- package/dist/uploads-archil.d.ts +100 -0
- package/dist/uploads-archil.js +431 -0
- package/dist/uploads.d.ts +52 -1
- package/dist/uploads.js +186 -108
- package/dist/validate.js +5 -1
- package/dist/web-save.d.ts +3 -0
- package/dist/web-save.js +17 -2
- package/dist/workspace/archil-disk.d.ts +6 -5
- package/dist/workspace/archil-disk.js +27 -12
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.js +4 -3
- package/dist/workspace/revision-skills.js +24 -11
- package/dist/workspace/synced-folder.d.ts +3 -3
- package/dist/workspace/synced-folder.js +7 -6
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/console/assets/index-D7G6o-1E.js +0 -720
|
@@ -5,11 +5,31 @@
|
|
|
5
5
|
import { StoreLaunchMissing } from "../store.js";
|
|
6
6
|
const RUN_LAUNCH_COLUMNS = "run_id, body, sealed, created_at";
|
|
7
7
|
const runLaunchOf = (r) => ({ runId: r.run_id, body: JSON.parse(r.body), sealed: r.sealed === null ? null : Uint8Array.from(r.sealed), createdAt: r.created_at });
|
|
8
|
+
// For the store's other reads of a run's JSON (a launch body, a command's body, a journal record): one id or flag out of
|
|
9
|
+
// a document whose strings may hold an escaped NUL or a lone surrogate.
|
|
10
|
+
export { postgresReadableJson, postgresUnicodeRefusal };
|
|
11
|
+
/** JSON text `column` as a read of one id or flag out of it inside a transaction takes it, where a refused statement
|
|
12
|
+
* aborts the transaction and can't be read again: on Postgres its copy with those escapes blanked (postgresReadableJson),
|
|
13
|
+
* on SQLite (whose json functions read them) the column itself. */
|
|
14
|
+
export const readableJson = (dialect, column) => (dialect.name === "postgres" ? postgresReadableJson(column) : column);
|
|
8
15
|
/** Writes a run's launch row inside `tx` (the same transaction as the queued run it belongs to): the run path and the
|
|
9
16
|
* trigger path both call it, so the row lands with its run or not at all. */
|
|
10
17
|
export function writeLaunch(tx, runId, launch, at) {
|
|
11
18
|
return tx.run("INSERT INTO run_launch (run_id, body, sealed, created_at) VALUES (?, ?, ?, ?)", runId, JSON.stringify(launch.body ?? null), launch.sealed ?? null, at);
|
|
12
19
|
}
|
|
20
|
+
/** The disk a launch body names as the run's own (runs.disk, RunRow.disk): its `archil_disk` of kind "launch", by its id
|
|
21
|
+
* (run-launch.ts launchBody writes it so); null for none, or its agent's own disk (the default disk). The one read of the
|
|
22
|
+
* body's disk the store makes, at every create of a run, so no path that queues a run can leave it out. */
|
|
23
|
+
export function launchDiskOf(launch) {
|
|
24
|
+
const body = launch?.body;
|
|
25
|
+
if (typeof body !== "object" || body === null)
|
|
26
|
+
return null;
|
|
27
|
+
const disk = body.archil_disk;
|
|
28
|
+
if (typeof disk !== "object" || disk === null)
|
|
29
|
+
return null;
|
|
30
|
+
const { disk_id: id, kind } = disk;
|
|
31
|
+
return kind === "launch" && typeof id === "string" && id !== "" ? id : null;
|
|
32
|
+
}
|
|
13
33
|
/** A message's launch secrets written over the run's (runs.command, runs.reopen), inside `tx`: the bytes as given, or a
|
|
14
34
|
* function's answer to the bytes the launch holds now, read in the same transaction. */
|
|
15
35
|
export async function writeLaunchSealed(tx, runId, launchSealed) {
|
|
@@ -30,11 +50,100 @@ export async function readLaunch(executor, runId) {
|
|
|
30
50
|
throw new StoreLaunchMissing(runId);
|
|
31
51
|
return runLaunchOf(row);
|
|
32
52
|
}
|
|
53
|
+
/** Whether `error` (or a cause of it, six deep) is Postgres refusing a JSON document for an escaped NUL or a lone
|
|
54
|
+
* surrogate in it: the text type keeps them, but every json function decodes the whole document's strings. */
|
|
55
|
+
function postgresUnicodeRefusal(error) {
|
|
56
|
+
for (let cause = error, depth = 0; cause && depth < 6; cause = cause.cause, depth++)
|
|
57
|
+
if (cause.code === "22P05" || (cause.code === "22P02" && cause.reason === "json_surrogate"))
|
|
58
|
+
return true;
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
/** Postgres SQL for JSON text `column` with its escaped NULs and surrogates (\u0000, \ud800-\udfff) read as escaped
|
|
62
|
+
* spaces, for a read of one number or id out of a document whose other strings may hold one (0026_run_disk.sql blanks
|
|
63
|
+
* them for its backfill). A replaced escape stays an escape, so it is still JSON. Only an escape is replaced: u0000 after
|
|
64
|
+
* an escaped backslash (the text \u0000 in an id, written \\u0000) is text and is kept, so an id reads as it is. */
|
|
65
|
+
const postgresReadableJson = (column) => `regexp_replace(${column}, '(?<!\\\\)((?:\\\\\\\\)*)\\\\u(0000|[dD][89a-fA-F][0-9a-fA-F]{2})', '\\1\\\\u0020', 'g')`;
|
|
66
|
+
/** Project accounting facts before crossing the database boundary. An SDK inbox can contain megabytes of replay;
|
|
67
|
+
* the raw-JSON projection preserves strings, nulls and invalid scalar shapes equally on SQLite and Postgres.
|
|
68
|
+
* Uses an ordinary store connection: a PostgreSQL Unicode refusal is retried outside a failed transaction. */
|
|
69
|
+
export async function readUsageMetadata(executor, runId, { completion }) {
|
|
70
|
+
const keys = ["runtime", "session_id", "turn_id"];
|
|
71
|
+
const counters = ["input_tokens", "output_tokens", "cache_read_tokens", "cache_write_tokens"];
|
|
72
|
+
const columns = keys.map(key => `${executor.dialect.jsonValue("l.body", ["cli_learning", key])} AS ${key}`);
|
|
73
|
+
// Launch bodies are written with JSON.stringify: zero is canonically `0`. Read only the historical
|
|
74
|
+
// binding's truthiness, never its potentially private or large provider configuration.
|
|
75
|
+
const grading = executor.dialect.jsonValue("l.body", ["cli_learning", "native_grading"]);
|
|
76
|
+
columns.push(`CASE WHEN ${grading} IS NULL OR ${grading} IN ('null', 'false', '0', '""') THEN 0 ELSE 1 END AS native_grading`);
|
|
77
|
+
if (completion)
|
|
78
|
+
columns.push(...counters.map(key => `${executor.dialect.jsonValue("s.value", ["completion", "usage", key])} AS ${key}`));
|
|
79
|
+
const from = `FROM runs r LEFT JOIN run_launch l ON l.run_id = r.id${completion ? " LEFT JOIN settings s ON s.key = ?" : ""} WHERE r.id = ?`;
|
|
80
|
+
const params = [...(completion ? [`sdk-run:${runId}`] : []), runId];
|
|
81
|
+
let row;
|
|
82
|
+
try {
|
|
83
|
+
row = await executor.get(`SELECT ${columns.join(", ")} ${from}`, ...params);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
// PostgreSQL accepts escaped NUL/lone-surrogate strings in JSON TEXT but cannot extract ANY member of
|
|
87
|
+
// such a document. Only its exact Unicode refusal permits the former JS read/parse cost for that row.
|
|
88
|
+
// Never sanitize native identities or silently lose known counters to an unrelated replay string.
|
|
89
|
+
if (executor.dialect.name !== "postgres" || !postgresUnicodeRefusal(error))
|
|
90
|
+
throw error;
|
|
91
|
+
const raw = await executor.get(`SELECT l.body${completion ? ", s.value AS inbox" : ""} ${from}`, ...params);
|
|
92
|
+
if (!raw)
|
|
93
|
+
return undefined;
|
|
94
|
+
const object = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
95
|
+
const cli = object(object(raw.body == null ? undefined : JSON.parse(raw.body)).cli_learning);
|
|
96
|
+
const usage = object(object(object(raw.inbox == null ? undefined : JSON.parse(raw.inbox)).completion).usage);
|
|
97
|
+
return { cli: { ...Object.fromEntries(keys.map(key => [key, cli[key]])), native_grading: Boolean(cli.native_grading) },
|
|
98
|
+
...(completion ? { completionUsage: Object.fromEntries(counters.map(key => [key, usage[key]])) } : {}) };
|
|
99
|
+
}
|
|
100
|
+
if (!row)
|
|
101
|
+
return undefined;
|
|
102
|
+
const value = (key) => row[key] == null ? undefined : JSON.parse(String(row[key]));
|
|
103
|
+
return { cli: { ...Object.fromEntries(keys.map(key => [key, value(key)])), native_grading: Boolean(row.native_grading) },
|
|
104
|
+
...(completion ? { completionUsage: Object.fromEntries(counters.map(key => [key, value(key)])) } : {}) };
|
|
105
|
+
}
|
|
33
106
|
/** The learning start of every run of agent `agentId` that `where` (a condition on runs' columns) keeps, in one read: only
|
|
34
107
|
* the body's `learning` member (the notes a run was given, its seed, its # Learned section), never the rest of the body
|
|
35
108
|
* and never the sealed bytes, so an agent with thousands of runs reads kilobytes a run, not each run's input. `learning`
|
|
36
109
|
* is the member's JSON text, null when the run's body names none. */
|
|
37
110
|
export async function readLearningStarts(executor, agentId, where) {
|
|
38
|
-
const
|
|
39
|
-
|
|
111
|
+
const learning = executor.dialect.jsonText("body", ["learning"]);
|
|
112
|
+
const runs = `run_id IN (SELECT id FROM runs WHERE agent_id = ? AND ${where})`;
|
|
113
|
+
let rows;
|
|
114
|
+
try {
|
|
115
|
+
rows = await executor.all(`SELECT run_id, ${learning} AS learning FROM run_launch WHERE ${runs}`, agentId);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
// A body holding an escaped NUL or a lone surrogate anywhere (a run's input) makes Postgres refuse the whole read. Read
|
|
119
|
+
// again: `learning` out of each body that holds none, and each body that does whole, parsed here, so a run's notes
|
|
120
|
+
// come back as written, never blanked. On an ordinary store connection, as readUsageMetadata's, so the read again is
|
|
121
|
+
// outside a failed transaction.
|
|
122
|
+
if (executor.dialect.name !== "postgres" || !postgresUnicodeRefusal(error))
|
|
123
|
+
throw error;
|
|
124
|
+
rows = await executor.all(`SELECT run_id, CASE WHEN odd THEN NULL ELSE ${learning} END AS learning, CASE WHEN odd THEN body END AS body
|
|
125
|
+
FROM (SELECT run_id, body, ${postgresReadableJson("body")} <> body AS odd FROM run_launch WHERE ${runs}) AS launch`, agentId);
|
|
126
|
+
}
|
|
127
|
+
return rows.map((row) => ({
|
|
128
|
+
runId: row.run_id,
|
|
129
|
+
learning: row.body != null ? (JSON.parse(row.body)?.learning ?? undefined) : row.learning === null ? undefined : JSON.parse(row.learning),
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
/** The ids of agent `agentId`'s runs started after `at` whose learning seed was read at or before it (the launch body's
|
|
133
|
+
* `learning.seededAt`), in one read of that one number a run started after `at`: never a run's section or input. */
|
|
134
|
+
export async function readSeededBefore(executor, agentId, at) {
|
|
135
|
+
const read = (body) => executor.all(`SELECT run_id, ${executor.dialect.jsonText(body, ["learning", "seededAt"])} AS seeded_at FROM run_launch WHERE run_id IN (SELECT id FROM runs WHERE agent_id = ? AND started_at > ?)`, agentId, at);
|
|
136
|
+
let rows;
|
|
137
|
+
try {
|
|
138
|
+
rows = await read("body");
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
// A body holding an escaped NUL or a lone surrogate anywhere (a run's input) makes Postgres refuse the whole read: the
|
|
142
|
+
// one number is read again from copies with those escapes blanked (postgresReadableJson), never a run's text. On an
|
|
143
|
+
// ordinary store connection, as readUsageMetadata's, so the retry is outside a failed transaction.
|
|
144
|
+
if (executor.dialect.name !== "postgres" || !postgresUnicodeRefusal(error))
|
|
145
|
+
throw error;
|
|
146
|
+
rows = await read(postgresReadableJson("body"));
|
|
147
|
+
}
|
|
148
|
+
return rows.flatMap((row) => (row.seeded_at !== null && Number(row.seeded_at) <= at ? [row.run_id] : []));
|
|
40
149
|
}
|
|
@@ -27,11 +27,12 @@ export type RunRecord = {
|
|
|
27
27
|
imported_from: string | null;
|
|
28
28
|
sign_in_handed: string | null;
|
|
29
29
|
labels: string | null;
|
|
30
|
+
disk: string | null;
|
|
30
31
|
started_at: number;
|
|
31
32
|
ended_at: number | null;
|
|
32
33
|
purged_at: number | null;
|
|
33
34
|
};
|
|
34
|
-
export declare const RUN_COLUMNS = "id, agent_id, revision_id, state, epoch, runner, claimed_until, wake_at, backoff_until, cost_usd, cost_upper_bound, metrics, summary, outcome, archived_at, imported_from, sign_in_handed, labels, started_at, ended_at, purged_at";
|
|
35
|
+
export declare const RUN_COLUMNS = "id, agent_id, revision_id, state, epoch, runner, claimed_until, wake_at, backoff_until, cost_usd, cost_upper_bound, metrics, summary, outcome, archived_at, imported_from, sign_in_handed, labels, disk, started_at, ended_at, purged_at";
|
|
35
36
|
/** A run's exact cost in SQL, for a query that reads runs.cost_usd itself (`alias`: its runs table's): NULL when the
|
|
36
37
|
* stored figure is only the most the run can have cost, as runOf reads it. Every raw read of the column goes through it. */
|
|
37
38
|
export declare const EXACT_COST_USD: (alias: string) => string;
|
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
import { endedReason, FINAL_STATES, Fenced } from "../store.js";
|
|
7
7
|
import { settledBody, SQLITE } from "../dialect.js";
|
|
8
8
|
import { claimFence, storeNow } from "../fence.js";
|
|
9
|
+
import { readableJson } from "./run-launch.js";
|
|
9
10
|
/** A WHERE condition on `runs`: the run is no built-in learning run (one a kept learning names, queued with it), which no
|
|
10
11
|
* list of runs names. */
|
|
11
12
|
export const NOT_A_LEARNING_RUN = "id NOT IN (SELECT learning_run_id FROM learning_proposals WHERE learning_run_id IS NOT NULL)";
|
|
12
13
|
/** The lock a write of a run's sign_in_handed and a sign-in's forget both take (Dialect.lockKey): the forget's check of
|
|
13
14
|
* the running runs' hashes and a launch's write of them are serialized, as SQLite's one writer serializes them. */
|
|
14
15
|
export const SIGN_IN_HANDED_LOCK = "sign_in_handed";
|
|
15
|
-
export const RUN_COLUMNS = "id, agent_id, revision_id, state, epoch, runner, claimed_until, wake_at, backoff_until, cost_usd, cost_upper_bound, metrics, summary, outcome, archived_at, imported_from, sign_in_handed, labels, started_at, ended_at, purged_at";
|
|
16
|
+
export const RUN_COLUMNS = "id, agent_id, revision_id, state, epoch, runner, claimed_until, wake_at, backoff_until, cost_usd, cost_upper_bound, metrics, summary, outcome, archived_at, imported_from, sign_in_handed, labels, disk, started_at, ended_at, purged_at";
|
|
16
17
|
/** A run's exact cost in SQL, for a query that reads runs.cost_usd itself (`alias`: its runs table's): NULL when the
|
|
17
18
|
* stored figure is only the most the run can have cost, as runOf reads it. Every raw read of the column goes through it. */
|
|
18
19
|
export const EXACT_COST_USD = (alias) => `CASE WHEN ${alias}.cost_upper_bound = 1 THEN NULL ELSE ${alias}.cost_usd END`;
|
|
@@ -25,7 +26,7 @@ export const runOf = (r) => ({
|
|
|
25
26
|
wakeAt: r.wake_at, backoffUntil: r.backoff_until, ...costOf(r.cost_usd, r.cost_upper_bound), metrics: r.metrics === null ? null : JSON.parse(r.metrics), summary: r.summary,
|
|
26
27
|
outcome: r.outcome ?? null, archivedAt: r.archived_at, importedFrom: r.imported_from === null ? null : JSON.parse(r.imported_from),
|
|
27
28
|
signInHanded: r.sign_in_handed === null ? null : JSON.parse(r.sign_in_handed), labels: r.labels === null ? {} : JSON.parse(r.labels),
|
|
28
|
-
startedAt: r.started_at, endedAt: r.ended_at, purgedAt: r.purged_at ?? null,
|
|
29
|
+
disk: r.disk, startedAt: r.started_at, endedAt: r.ended_at, purgedAt: r.purged_at ?? null,
|
|
29
30
|
});
|
|
30
31
|
/** Applies `patch` to the claim's run, then writes `also`, through `tx` (an open transaction's handle). Fenced, with nothing
|
|
31
32
|
* of it written once the caller rolls back, when the run's epoch is not the claim's or the claim's lease ran out before
|
|
@@ -110,7 +111,7 @@ export async function applyRunPatch(tx, claim, patch, also, now, dialect = SQLIT
|
|
|
110
111
|
export const REOPEN_SET = "state = 'running', runner = NULL, claimed_until = NULL, wake_at = NULL, backoff_until = NULL, ended_at = NULL, summary = NULL, outcome = NULL";
|
|
111
112
|
export const reopenableWhere = (d) => `(state = 'ended' OR (state = 'stopped' AND outcome = 'stopped')) AND imported_from IS NULL AND purged_at IS NULL
|
|
112
113
|
AND EXISTS (SELECT 1 FROM revisions WHERE revisions.id = runs.revision_id AND revisions.kind = 'agentic')
|
|
113
|
-
AND NOT EXISTS (SELECT 1 FROM run_launch WHERE run_launch.run_id = runs.id AND ${d.jsonText("run_launch.body", ["harness"])} = 'learning')`;
|
|
114
|
+
AND NOT EXISTS (SELECT 1 FROM run_launch WHERE run_launch.run_id = runs.id AND ${d.jsonText(readableJson(d, "run_launch.body"), ["harness"])} = 'learning')`;
|
|
114
115
|
/** After a write that made the run final has taken its own rows: every command row of the run still untaken is refused
|
|
115
116
|
* with the end's reason, in that same transaction. The store takes no new row on a final run (RunFinal), so a row the
|
|
116
117
|
* end left untaken would stay so for good, as it would if the runner died right after the end.
|
|
@@ -22,6 +22,23 @@ export type SqliteStoreOptions = (
|
|
|
22
22
|
/** How long a write waits for another process's lock before StoreBusy. */
|
|
23
23
|
busyTimeoutMs?: number;
|
|
24
24
|
};
|
|
25
|
+
/** The columns a runner of this build needs that an earlier build of this same version may not have: the server adds each
|
|
26
|
+
* at its start (openSqliteStore), and a runner on a file without one waits for that server (StoreAwaitsServer, in `why`'s
|
|
27
|
+
* words; exit 3). store-schema reads the same list, so its report says "waits" where the runner would. */
|
|
28
|
+
export declare const SQLITE_RUNNER_NEEDS: readonly {
|
|
29
|
+
readonly table: string;
|
|
30
|
+
readonly columns: readonly string[];
|
|
31
|
+
readonly why: string;
|
|
32
|
+
}[];
|
|
33
|
+
/** What a runner of this build waits for on a file of this version (SQLITE_RUNNER_NEEDS' first missing column's `why`),
|
|
34
|
+
* or undefined when it opens; `columnsOf` reads a table's columns. */
|
|
35
|
+
export declare function runnerWaitsFor(columnsOf: (table: string) => Promise<ReadonlySet<string>> | ReadonlySet<string>): Promise<string | undefined>;
|
|
36
|
+
/** The files an earlier version kept in a data directory, relative to it: its store (a STORE_FILE with tables and no
|
|
37
|
+
* store_meta row), agent homes (<agent>/agent.sqlite, agents/<agent>/agent.sqlite), run databases (runs/<run>/run.sqlite,
|
|
38
|
+
* disk/agents/<agent>/runs/<run>/run.sqlite), its settings files (EARLIER_ROOT_FILES) and its homes' sign-ins
|
|
39
|
+
* (homes/<home>/sign-ins/sign-ins.json). Read only: nothing is opened for writing or made. The store is read before
|
|
40
|
+
* this server holds its owner lock, so it waits `busyTimeoutMs` for another process's lock on it (isThisVersionsStore). */
|
|
41
|
+
export declare function earlierVersionIn(dataDir: string, busyTimeoutMs: number): string[];
|
|
25
42
|
/** Opens the store in `dataDir` (its file is STORE_FILE there), or at `file` (the store's own tests). As the server (the
|
|
26
43
|
* default): makes the data directory, takes the owner lock (StoreOwned when another server holds it) and, on a store with
|
|
27
44
|
* no schema yet, sets schema SCHEMA_VERSION up in one durable commit. As a runner: makes and sets up nothing. Either
|