@parcha/agentrun-serve 0.1.0-beta.59 → 0.1.0-beta.60
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 +77 -0
- package/README.md +188 -106
- package/dist/agent-delete.d.ts +6 -9
- package/dist/agent-delete.js +5 -3
- package/dist/agent-package.js +11 -1
- package/dist/api-only.d.ts +2 -2
- package/dist/api-only.js +3 -3
- package/dist/archil-routes.d.ts +4 -1
- package/dist/archil-routes.js +15 -12
- package/dist/archil-settings.d.ts +18 -8
- package/dist/archil-settings.js +35 -17
- package/dist/chatgpt-plan.d.ts +4 -2
- package/dist/chatgpt-plan.js +13 -3
- package/dist/claude-login-token.d.ts +5 -0
- package/dist/claude-login-token.js +8 -0
- package/dist/claude-login.d.ts +49 -3
- package/dist/claude-login.js +140 -10
- package/dist/cli-learning/connections.js +1 -1
- package/dist/console/assets/{backend-BztxEAvb.js → backend-QnwGVBeU.js} +1 -1
- package/dist/console/assets/index-DZi-muIj.js +629 -0
- package/dist/console/assets/{share-L84tlUDW.js → share-pz61zIn9.js} +2 -2
- package/dist/console/assets/{styles-CaRKlHke.js → styles-CcceGcu2.js} +31 -31
- package/dist/console/assets/styles-fjQBFfMv.css +1 -0
- package/dist/console/index.html +3 -3
- package/dist/console/share.html +3 -3
- package/dist/decisions.d.ts +1 -1
- package/dist/decisions.js +2 -2
- package/dist/factory-activity.d.ts +68 -0
- package/dist/factory-activity.js +153 -0
- package/dist/factory-runs.d.ts +11 -0
- package/dist/factory-runs.js +52 -0
- package/dist/filed-tool.d.ts +32 -0
- package/dist/filed-tool.js +122 -0
- package/dist/harness-keys.d.ts +1 -2
- package/dist/harness-keys.js +1 -2
- package/dist/harness-table.d.ts +4 -0
- package/dist/harness-table.js +4 -0
- package/dist/harness.js +6 -2
- package/dist/import-worker.js +2 -2
- package/dist/import.d.ts +9 -0
- package/dist/import.js +11 -1
- package/dist/key-refusal.d.ts +5 -0
- package/dist/key-refusal.js +25 -15
- package/dist/learn/audit.d.ts +20 -22
- package/dist/learn/audit.js +72 -55
- package/dist/learn/check.js +1 -1
- package/dist/learn/commit.d.ts +35 -43
- package/dist/learn/commit.js +62 -270
- package/dist/learn/compile.d.ts +4 -4
- package/dist/learn/compile.js +6 -7
- package/dist/learn/corrections.js +1 -1
- package/dist/learn/delete.d.ts +5 -12
- package/dist/learn/delete.js +17 -30
- package/dist/learn/forget-run.d.ts +16 -0
- package/dist/learn/forget-run.js +53 -0
- package/dist/learn/index.js +1 -1
- package/dist/learn/learning-of.d.ts +0 -4
- package/dist/learn/learning-of.js +0 -5
- package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
- package/dist/learn/{folder.js → legacy/folder.js} +4 -7
- package/dist/learn/legacy/place.d.ts +16 -0
- package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
- package/dist/learn/legacy/scrub.d.ts +28 -0
- package/dist/learn/legacy/scrub.js +258 -0
- package/dist/learn/promote.d.ts +40 -66
- package/dist/learn/promote.js +69 -207
- package/dist/learn/reset-ledger.d.ts +18 -0
- package/dist/learn/reset-ledger.js +14 -0
- package/dist/learn/rows.d.ts +186 -0
- package/dist/learn/rows.js +376 -0
- package/dist/learn/workflow-draft.d.ts +4 -1
- package/dist/learn/workflow-draft.js +12 -2
- package/dist/learning-reset.d.ts +1 -1
- package/dist/learning-reset.js +9 -11
- package/dist/learning-routes.d.ts +60 -81
- package/dist/learning-routes.js +187 -360
- package/dist/learning-words.d.ts +2 -0
- package/dist/learning-words.js +2 -0
- package/dist/learning.d.ts +18 -24
- package/dist/learning.js +35 -66
- package/dist/mcp-gateway.d.ts +6 -0
- package/dist/mcp-gateway.js +44 -8
- package/dist/mcp-resources.d.ts +1 -1
- package/dist/native/discovery.d.ts +6 -0
- package/dist/native/discovery.js +14 -1
- package/dist/native/remote.d.ts +5 -0
- package/dist/native/remote.js +16 -0
- package/dist/native/runtime.js +3 -2
- package/dist/observation/observer.d.ts +6 -6
- package/dist/openapi.js +89 -29
- package/dist/place-offers.d.ts +3 -0
- package/dist/place-offers.js +3 -0
- package/dist/place.d.ts +33 -11
- package/dist/place.js +61 -26
- package/dist/purged-workflow.d.ts +0 -33
- package/dist/purged-workflow.js +3 -71
- package/dist/redact/match.d.ts +19 -4
- package/dist/redact/match.js +123 -30
- package/dist/run-launch.d.ts +3 -3
- package/dist/run-learning-served.d.ts +3 -3
- package/dist/run-learning-served.js +1 -1
- package/dist/run-listing.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +6 -5
- package/dist/runnable.js +25 -8
- package/dist/runner/adapter-run-spec.js +11 -20
- package/dist/runner/audit.d.ts +2 -4
- package/dist/runner/audit.js +28 -51
- package/dist/runner/cli-run-spec.js +8 -14
- package/dist/runner/compare-end.d.ts +0 -2
- package/dist/runner/compare-end.js +6 -2
- package/dist/runner/disk-free.d.ts +15 -4
- package/dist/runner/disk-free.js +25 -7
- package/dist/runner/feedback-round.d.ts +1 -1
- package/dist/runner/feedback-round.js +2 -2
- package/dist/runner/harness-loops.js +2 -3
- package/dist/runner/held.d.ts +0 -10
- package/dist/runner/held.js +0 -25
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/journal-kinds.js +1 -1
- package/dist/runner/learned-first.d.ts +0 -2
- package/dist/runner/learned-first.js +3 -3
- package/dist/runner/learning-end.d.ts +12 -16
- package/dist/runner/learning-end.js +41 -75
- package/dist/runner/learning-seed.d.ts +13 -16
- package/dist/runner/learning-seed.js +13 -23
- package/dist/runner/main.js +1 -1
- package/dist/runner/mcp-run.d.ts +4 -0
- package/dist/runner/mcp-run.js +2 -0
- package/dist/runner/native-loop.js +2 -3
- package/dist/runner/promotion.d.ts +19 -28
- package/dist/runner/promotion.js +50 -69
- package/dist/runner/reflect-hook.d.ts +2 -2
- package/dist/runner/reflect-hook.js +4 -1
- package/dist/runner/run-child-host.d.ts +1 -9
- package/dist/runner/run-child-host.js +11 -67
- package/dist/runner/runner.d.ts +1 -1
- package/dist/runner/sdk-loop.js +2 -4
- package/dist/sdk/check.d.ts +1 -4
- package/dist/sdk/check.js +2 -3
- package/dist/sdk/runs.d.ts +20 -7
- package/dist/sdk/runs.js +105 -68
- package/dist/secrets.d.ts +4 -0
- package/dist/secrets.js +44 -10
- package/dist/server-fs.d.ts +1 -1
- package/dist/server-fs.js +1 -1
- package/dist/server-keys.d.ts +6 -0
- package/dist/server-keys.js +12 -0
- package/dist/server.d.ts +15 -15
- package/dist/server.js +214 -164
- package/dist/source-sync/auxiliary.js +2 -2
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
- package/dist/store/schema.d.ts +28 -2
- package/dist/store/schema.js +81 -5
- package/dist/store/sqlite/learning-rows.d.ts +23 -0
- package/dist/store/sqlite/learning-rows.js +559 -0
- package/dist/store/sqlite/store.d.ts +7 -1
- package/dist/store/sqlite/store.js +84 -18
- package/dist/store/store.d.ts +219 -6
- package/dist/store/store.js +13 -0
- package/dist/store-reads/journal.d.ts +33 -3
- package/dist/store-reads/journal.js +99 -4
- package/dist/store-reads/learning.d.ts +18 -22
- package/dist/store-reads/learning.js +35 -26
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-view.d.ts +24 -2
- package/dist/store-view.js +40 -11
- package/dist/templates.d.ts +10 -2
- package/dist/templates.js +31 -4
- package/dist/tool-plane.d.ts +4 -2
- package/dist/tool-plane.js +9 -2
- package/dist/web-holds.d.ts +2 -0
- package/dist/web-holds.js +5 -2
- package/dist/web-run.js +2 -1
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.d.ts +1 -1
- package/dist/workspace/archil.js +1 -1
- package/dist/workspace/computer-deps.js +5 -3
- package/dist/workspace/computer-providers.d.ts +11 -1
- package/dist/workspace/computer-providers.js +29 -2
- package/dist/workspace/index.d.ts +1 -2
- package/dist/workspace/index.js +1 -2
- package/dist/workspace/paths.d.ts +0 -4
- package/dist/workspace/paths.js +0 -6
- package/dist/workspace/workspace.d.ts +1 -1
- package/dist/workspace/workspace.js +1 -1
- package/package.json +13 -13
- package/templates/TOOLS.md +46 -0
- package/dist/console/assets/index-LwNL4L9q.js +0 -619
- package/dist/console/assets/styles-DQo8rzY-.css +0 -1
- package/dist/workspace/learning-workspace.d.ts +0 -24
- /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
|
@@ -12,8 +12,8 @@ import { watchCommandsAt, wakeCommands } from "../command-wake.js";
|
|
|
12
12
|
import { claimFence, storeNow } from "../fence.js";
|
|
13
13
|
import { JOURNAL_FIRST_ID, RunStorage } from "../journal/storage.js";
|
|
14
14
|
import { RUNNER_RECORDS } from "@parcha/agentrun-kernel";
|
|
15
|
-
import { COMMANDS_ONE_ANSWER, COMPUTER_INTERVALS, COMPUTER_INTERVALS_ADDED, COMPUTER_INTERVALS_RUN, DDL, diskUpgrade, HAND_BACKS, HAND_BACKS_AT, HAND_BACKS_KEPT_MS, HAND_BACKS_RUN, IMPORTED_TEMPLATES, LEARNING_LEDGER, LEARNING_LEDGER_ADDED, LEARNING_LEDGER_AGENT, LEARNING_LEDGER_BY_HAND, LEARNING_SPEND, LEARNING_SPEND_AGENT, LEARNING_SPEND_OF_RUN, ledgerUpgrade, listingUpgrade, MINTED_TOKENS, purgeUpgrade, relayUpgrade, NATIVE_COMMANDS_INDEX, PI_TABLE, PI_TABLES, REVISIONS_MCP_PIN, REVISIONS_MONID_PIN, RUN_ATTEMPTS, RUNNERS, RUNNERS_ADDED, RUN_LAUNCH_CENSUS, RUN_LAUNCH_CENSUS_ERASED, RUN_LAUNCH_CENSUS_ERASED_MADE, RUN_LAUNCH_CENSUS_SETTLE, RUNS_COST_UPPER_BOUND, RUNS_LABELS, SCHEMA_VERSION, SETTLED_LIST_STATUS, STORE_META_LEDGER_BACKFILLED, TRIGGERS_TEMPLATE_ID } from "../schema.js";
|
|
16
|
-
import { ActiveRuns, AgentArchived, AgentDeleting, AgentPurged, CommandTaken, ExternalBodyConflict, Fenced, FiringMoved, RunFinal, RunPurged, RunsMadeFromLeft, SchemaVersionUnknown, STORE_WRITE_DEADLINE_MS, StoreAwaitsServer, StoreBusy, StoreConstraint, StoreFromEarlierVersion, TriggerFull, TriggersLeft, UPLOAD_PREFIX, FINAL_STATES, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, SignInHandedTo, SignInMissing, RUN_CHANGES_PAGE, KEPT_PREFIX, RUNNER_ROWS_KEPT_MS, RUNNER_STALE_MS, tombstoneMetrics, } from "../store.js";
|
|
15
|
+
import { COMMANDS_ONE_ANSWER, COMPUTER_INTERVALS, COMPUTER_INTERVALS_ADDED, COMPUTER_INTERVALS_RUN, DDL, diskUpgrade, HAND_BACKS, HAND_BACKS_AT, HAND_BACKS_KEPT_MS, HAND_BACKS_RUN, IMPORTED_TEMPLATES, LEARNING_LEDGER, LEARNING_LEDGER_ADDED, LEARNING_LEDGER_AGENT, LEARNING_LEDGER_BY_HAND, LEARNING_ROWS, LEARNING_SPEND, LEARNING_SPEND_AGENT, LEARNING_SPEND_OF_RUN, ledgerUpgrade, learningRowsUpgrade, listingUpgrade, MINTED_TOKENS, purgeUpgrade, relayUpgrade, NATIVE_COMMANDS_INDEX, PI_TABLE, PI_TABLES, REVISIONS_MCP_PIN, REVISIONS_MONID_PIN, RUN_ATTEMPTS, RUNNERS, RUNNERS_ADDED, RUN_LAUNCH_CENSUS, RUN_LAUNCH_CENSUS_ERASED, RUN_LAUNCH_CENSUS_ERASED_MADE, RUN_LAUNCH_CENSUS_SETTLE, RUNS_COST_UPPER_BOUND, RUNS_LABELS, SCHEMA_VERSION, SETTLED_LIST_STATUS, STORE_META_LEDGER_BACKFILLED, TRIGGERS_TEMPLATE_ID } from "../schema.js";
|
|
16
|
+
import { ActiveRuns, AgentArchived, AgentDeleting, AgentPurged, CommandTaken, ExternalBodyConflict, Fenced, FiringMoved, RunFinal, RunPurged, RunnerBelowFloor, RunsMadeFromLeft, SchemaVersionUnknown, STORE_WRITE_DEADLINE_MS, StoreAwaitsServer, StoreBusy, StoreConstraint, StoreFromEarlierVersion, TriggerFull, TriggersLeft, UPLOAD_PREFIX, FINAL_STATES, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, SignInHandedTo, SignInMissing, RUN_CHANGES_PAGE, KEPT_PREFIX, RUNNER_ROWS_KEPT_MS, RUNNER_STALE_MS, tombstoneMetrics, } from "../store.js";
|
|
17
17
|
/** The run a launch body is made from (Runs.madeFrom): the run whose input it replays (`replay.of`) or audits (`audit.of`). */
|
|
18
18
|
const madeOf = (body) => {
|
|
19
19
|
for (const link of ["replay", "audit"]) {
|
|
@@ -31,6 +31,7 @@ const seqOf = (cursor) => {
|
|
|
31
31
|
};
|
|
32
32
|
import { cleanText, settledBody } from "../dialect.js";
|
|
33
33
|
import { inMemory } from "./memory.js";
|
|
34
|
+
import { dropAgentLearning, dropRunLearning, learningRows } from "./learning-rows.js";
|
|
34
35
|
import { Connection, DEFAULT_BUSY_TIMEOUT_MS } from "./connection.js";
|
|
35
36
|
import { applyRunPatch, backfillLedger, BY_HAND_BEFORE, EXACT_COST_USD, NOT_A_LEARNING_RUN, recordLedger, refuseLeftovers, REOPEN_SET, reopenableWhere, RUN_COLUMNS, runOf, SIGN_IN_HANDED_LOCK } from "./run-patch.js";
|
|
36
37
|
import { launchDiskOf, readableJson, readLaunch, readLearningStarts, readSeededBefore, readUsageMetadata, writeLaunch, writeLaunchSealed } from "./run-launch.js";
|
|
@@ -71,6 +72,11 @@ async function checkSettingsGuards(tx, guards = [], message = "The source grant
|
|
|
71
72
|
export const DEFAULT_LEASE_MS = 30_000;
|
|
72
73
|
/** The store's file in its data directory: only the store names it. */
|
|
73
74
|
export const STORE_FILE = "store.sqlite";
|
|
75
|
+
/** The oldest schema version this release brings up to SCHEMA_VERSION in place at its server's open (version 11,
|
|
76
|
+
* 0.1.0-beta.44 and before): every version from it to the one before SCHEMA_VERSION is upgraded, each step by the
|
|
77
|
+
* version it starts from; an older one is refused (SchemaVersionUnknown). The window follows SCHEMA_VERSION, so a new
|
|
78
|
+
* version never drops the one before it. */
|
|
79
|
+
export const OLDEST_UPGRADED = 11;
|
|
74
80
|
/** No audit's shadow run (learn/audit.ts SHADOW_PREFIX "audit."): the prefix compared as it is, which LIKE does not on
|
|
75
81
|
* SQLite (it folds case). */
|
|
76
82
|
const NOT_A_SHADOW_RUN = "substr(runs.id, 1, 6) <> 'audit.'";
|
|
@@ -275,8 +281,9 @@ async function versionOf(db) {
|
|
|
275
281
|
* the store, is set again. */
|
|
276
282
|
const EARLIER_ROOT_FILES = ["mcp-servers.json", "triggers.json", "tool-keys.json", "trigger-secrets.json", ".door-token"];
|
|
277
283
|
/** The store's earlier versions the server upgrades in place at its open (openSqliteStore), which a runner waits for
|
|
278
|
-
* (StoreAwaitsServer); store-schema reports from the same set.
|
|
279
|
-
|
|
284
|
+
* (StoreAwaitsServer); store-schema reports from the same set. Every version from OLDEST_UPGRADED to the one before
|
|
285
|
+
* SCHEMA_VERSION, so a new version never drops the one before it. */
|
|
286
|
+
export const SQLITE_UPGRADES = new Set(Array.from({ length: SCHEMA_VERSION - OLDEST_UPGRADED }, (_, i) => OLDEST_UPGRADED + i));
|
|
280
287
|
/** The columns a runner of this build needs that an earlier build of this same version may not have: the server adds each
|
|
281
288
|
* at its start (openSqliteStore), and a runner on a file without one waits for that server (StoreAwaitsServer, in `why`'s
|
|
282
289
|
* words; exit 3). store-schema reads the same list, so its report says "waits" where the runner would. */
|
|
@@ -294,6 +301,7 @@ export const SQLITE_RUNNER_NEEDS = [
|
|
|
294
301
|
// A run's end writes its ledger row and spend rows (run-patch.ts applyRunPatch) in its own transaction.
|
|
295
302
|
{ table: "learning_ledger", columns: ["run_id", ...Object.keys(LEARNING_LEDGER_ADDED)], why: "write each run's learning ledger row and spend at its end (learning_ledger, learning_spend)" },
|
|
296
303
|
{ table: "learning_spend", columns: ["run_id"], why: "write each run's learning ledger row and spend at its end (learning_ledger, learning_spend)" },
|
|
304
|
+
{ table: "learning_saves", columns: ["merge_key"], why: "keep each agent's learning as rows (learning_saves, learning_items, learning_records)" },
|
|
297
305
|
];
|
|
298
306
|
/** What a runner of this build waits for on a file of this version (SQLITE_RUNNER_NEEDS' first missing column's `why`),
|
|
299
307
|
* or undefined when it opens; `columnsOf` reads a table's columns. */
|
|
@@ -431,11 +439,16 @@ export async function openSqliteStore(options) {
|
|
|
431
439
|
// (schema.ts relayUpgrade). Version 13 keeps no purge time on a run or an agent: the server adds them (schema.ts
|
|
432
440
|
// purgeUpgrade). Version 14 keeps no disk on a run: the server adds it and writes each run's from its launch (schema.ts
|
|
433
441
|
// diskUpgrade). Version 15 keeps each ledger row's epoch: the server repairs the rows that release could leave wrong
|
|
434
|
-
// and drops it (the ledger's step below, then ledgerUpgrade).
|
|
435
|
-
//
|
|
442
|
+
// and drops it (the ledger's step below, then ledgerUpgrade). Version 16 keeps no learning as rows: the server adds
|
|
443
|
+
// them (schema.ts learningRowsUpgrade), last. A runner refuses each version of SQLITE_UPGRADES until that server has,
|
|
444
|
+
// and a runner of 15, whose end writes the epoch, refuses 16 and later (SchemaVersionUnknown), or stops at its next
|
|
445
|
+
// floor read. A later version is refused too, a runner in words that name its floor (a SQLite runner opens only its
|
|
446
|
+
// own version, so the floor is the version): RunnerBelowFloor.
|
|
436
447
|
const upgrading = found !== null && SQLITE_UPGRADES.has(found);
|
|
437
448
|
if (upgrading && role === "runner")
|
|
438
449
|
throw new StoreAwaitsServer(`bring this store from version ${found} to ${SCHEMA_VERSION}`);
|
|
450
|
+
if (role === "runner" && found !== null && found > SCHEMA_VERSION)
|
|
451
|
+
throw new RunnerBelowFloor(file, found, SCHEMA_VERSION, found);
|
|
439
452
|
if (found !== SCHEMA_VERSION && !upgrading)
|
|
440
453
|
throw new SchemaVersionUnknown(file, found, SCHEMA_VERSION);
|
|
441
454
|
const columns = new Set((await connection.all("SELECT name FROM pragma_table_info('revisions')")).map((column) => column.name));
|
|
@@ -519,6 +532,11 @@ export async function openSqliteStore(options) {
|
|
|
519
532
|
if (role === "runner" && ((await connection.all("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name IN ('learning_ledger', 'learning_spend')")).length < 2 || Object.keys(LEARNING_LEDGER_ADDED).some((column) => !ledgerColumns.has(column)))) {
|
|
520
533
|
throw new StoreAwaitsServer("write each run's learning ledger row and spend at its end (learning_ledger, learning_spend)");
|
|
521
534
|
}
|
|
535
|
+
// A run's merge and purge write the agent's learning rows (schema.ts LEARNING_ROWS) in their own transactions: a runner
|
|
536
|
+
// waits for the server that adds the tables.
|
|
537
|
+
if (role === "runner" && (await connection.all("SELECT name FROM pragma_table_info('learning_saves')")).length === 0) {
|
|
538
|
+
throw new StoreAwaitsServer("keep each agent's learning as rows (learning_saves, learning_items, learning_records)");
|
|
539
|
+
}
|
|
522
540
|
// The per-run viewer table was renamed browser_viewers → computer_viewers (schema.ts). Its rows are ephemeral, so none
|
|
523
541
|
// migrate; the server drops a stale browser_viewers an earlier build of this version left, so none lingers beside it.
|
|
524
542
|
// An earlier build of this version made no one-answer index on commands (schema.ts COMMANDS_ONE_ANSWER), or one that
|
|
@@ -565,6 +583,8 @@ export async function openSqliteStore(options) {
|
|
|
565
583
|
{ sql: LEARNING_SPEND },
|
|
566
584
|
{ sql: LEARNING_SPEND_AGENT },
|
|
567
585
|
{ sql: LEARNING_SPEND_OF_RUN },
|
|
586
|
+
// Nor any agent's learning as rows (schema.ts LEARNING_ROWS): learning kept before it is not read.
|
|
587
|
+
...LEARNING_ROWS.map((sql) => ({ sql })),
|
|
568
588
|
{ sql: NATIVE_COMMANDS_INDEX },
|
|
569
589
|
], { full: true });
|
|
570
590
|
// A computer_intervals an earlier build of this version made has no disk or booked time (schema.ts
|
|
@@ -587,11 +607,13 @@ export async function openSqliteStore(options) {
|
|
|
587
607
|
if (ledgerMissing.length > 0)
|
|
588
608
|
await connection.write(ledgerMissing, { full: true });
|
|
589
609
|
await backfillNativeCommandOwners(connection);
|
|
590
|
-
|
|
610
|
+
// Here `found` is SCHEMA_VERSION or a version in the window (any other was refused above): each step runs for the
|
|
611
|
+
// versions before the one that first kept what it adds.
|
|
612
|
+
if (found <= 11) {
|
|
591
613
|
const present = new Set((await connection.all("SELECT name FROM pragma_table_info('runs')")).map((column) => column.name));
|
|
592
614
|
await connection.write(listingUpgrade(present).map((sql) => ({ sql })), { full: true });
|
|
593
615
|
}
|
|
594
|
-
if (found
|
|
616
|
+
if (found <= 12) {
|
|
595
617
|
const minted = new Set((await connection.all("SELECT name FROM pragma_table_info('minted_tokens')")).map((column) => column.name));
|
|
596
618
|
await connection.write(relayUpgrade(minted).map((sql) => ({ sql })), { full: true });
|
|
597
619
|
}
|
|
@@ -601,7 +623,10 @@ export async function openSqliteStore(options) {
|
|
|
601
623
|
await connection.write(purgeUpgrade(await named("runs"), await named("agents")).map((sql) => ({ sql })), { full: true });
|
|
602
624
|
if (found <= 14)
|
|
603
625
|
await connection.write(diskUpgrade(await named("runs")).map((sql) => ({ sql })), { full: true });
|
|
604
|
-
|
|
626
|
+
if (found <= 15)
|
|
627
|
+
await connection.write(ledgerUpgrade(await named("learning_ledger")).map((sql) => ({ sql })), { full: true });
|
|
628
|
+
// Last: ledgerUpgrade writes 16, and the rows step writes 17 after it.
|
|
629
|
+
await connection.write(learningRowsUpgrade().map((sql) => ({ sql })), { full: true });
|
|
605
630
|
}
|
|
606
631
|
// Every run an earlier build ended gets its ledger row once, here, on the schema this build reads.
|
|
607
632
|
await backfillLedger(connection, options.now ?? Date.now);
|
|
@@ -694,7 +719,7 @@ async function dropLedger(tx, runId) {
|
|
|
694
719
|
}
|
|
695
720
|
/** A run's content in every table that keeps it by the run's id, gone: what a run's purge (Runs.purge) and its delete
|
|
696
721
|
* (Runs.remove) both drop. A table added for a run's content goes here, so neither path leaves it behind. */
|
|
697
|
-
async function dropRunContent(tx, runId) {
|
|
722
|
+
async function dropRunContent(tx, runId, at) {
|
|
698
723
|
for (const table of PI_TABLES)
|
|
699
724
|
await tx.run(`DELETE FROM ${table} WHERE run_id = ?`, runId);
|
|
700
725
|
await tx.run("DELETE FROM commands WHERE run_id = ?", runId);
|
|
@@ -710,11 +735,19 @@ async function dropRunContent(tx, runId) {
|
|
|
710
735
|
await tx.run("DELETE FROM hand_backs WHERE run_id = ?", runId);
|
|
711
736
|
// Its claims' attempts: what each cost is in its tombstone's money, and no read of a purged run splits it.
|
|
712
737
|
await tx.run("DELETE FROM run_attempts WHERE run_id = ?", runId);
|
|
738
|
+
// What it learned and what its agent's learning kept of it (learning-rows.ts dropRunLearning), its agent's alone,
|
|
739
|
+
// under the lock a save of that agent's learning takes: the purge is a save of its own at `at`.
|
|
740
|
+
const agentId = (await tx.get("SELECT agent_id FROM runs WHERE id = ?", runId))?.agent_id;
|
|
741
|
+
if (agentId !== undefined) {
|
|
742
|
+
await tx.dialect.lockKey(tx, `learning:${agentId}`);
|
|
743
|
+
await dropRunLearning(tx, agentId, runId, at);
|
|
744
|
+
}
|
|
713
745
|
}
|
|
714
|
-
/** An agent's own rows no tombstone keeps (its learning, its saved sign-ins
|
|
715
|
-
* purge (Agents.purge) and its delete (Agents.remove) both drop. */
|
|
746
|
+
/** An agent's own rows no tombstone keeps (its learning, under its learning locks: dropAgentLearning; its saved sign-ins
|
|
747
|
+
* and their tombstones), gone: what an agent's purge (Agents.purge) and its delete (Agents.remove) both drop. */
|
|
716
748
|
async function dropAgentPrivate(tx, agentId) {
|
|
717
749
|
await tx.run("DELETE FROM learning WHERE agent_id = ?", agentId);
|
|
750
|
+
await dropAgentLearning(tx, agentId);
|
|
718
751
|
await tx.run("DELETE FROM sign_ins WHERE agent_id = ?", agentId);
|
|
719
752
|
await tx.run("DELETE FROM sign_in_tombstones WHERE agent_id = ?", agentId);
|
|
720
753
|
}
|
|
@@ -1416,10 +1449,12 @@ class SqliteStore {
|
|
|
1416
1449
|
projectCheckpoints: (filter) => readProjectCheckpoints(db, filter),
|
|
1417
1450
|
learningStarts: (agentId) => readLearningStarts(db, agentId, NOT_A_LEARNING_RUN),
|
|
1418
1451
|
seededBefore: (agentId, at) => readSeededBefore(db, agentId, at),
|
|
1419
|
-
list: async ({ agentId, revisionId, state, archived, labels, disk, limit, purged = false }) => {
|
|
1452
|
+
list: async ({ agentId, revisionId, state, archived, labels, disk, limit, purged = false, scope, before }) => {
|
|
1420
1453
|
// A built-in learning run (a run's grade and merge, queued with its kept learning) is no run of a person's: no list,
|
|
1421
1454
|
// count, stat or notice names it. A purged run is a tombstone: only the readers that sum or count ask for it.
|
|
1422
|
-
|
|
1455
|
+
// The Agent Factory's active scope alone lists a learning run: there it is an execution like any other. Its review
|
|
1456
|
+
// scope keeps the runs list's boundary (listed, below): no learning run and no audit's shadow run.
|
|
1457
|
+
const where = [...(scope === "active" ? [] : [NOT_A_LEARNING_RUN]), ...(scope === "review" ? [NOT_A_SHADOW_RUN] : []), ...(purged ? [] : ["purged_at IS NULL"])];
|
|
1423
1458
|
const params = [];
|
|
1424
1459
|
if (agentId !== undefined)
|
|
1425
1460
|
(where.push("agent_id = ?"), params.push(agentId));
|
|
@@ -1436,6 +1471,18 @@ class SqliteStore {
|
|
|
1436
1471
|
where.push("disk IS NULL");
|
|
1437
1472
|
else if (disk !== undefined)
|
|
1438
1473
|
(where.push("disk = ?"), params.push(disk));
|
|
1474
|
+
// Factory visibility is selected before the page limit: an old parked run must not disappear behind newer
|
|
1475
|
+
// history. A person's stopped agentic turn remains continuable; an imported session never executes here.
|
|
1476
|
+
if (scope !== undefined) {
|
|
1477
|
+
where.push("imported_from IS NULL");
|
|
1478
|
+
where.push(scope === "active"
|
|
1479
|
+
? `(state IN ('queued', 'running', 'parked') OR (state = 'stopped' AND outcome = 'stopped' AND ${NOT_A_LEARNING_RUN} AND ${NOT_A_SHADOW_RUN} AND EXISTS (SELECT 1 FROM revisions WHERE revisions.id = runs.revision_id AND revisions.kind = 'agentic')))`
|
|
1480
|
+
: "((state = 'ended' AND outcome = 'escalated') OR state = 'failed') AND archived_at IS NULL AND NOT EXISTS (SELECT 1 FROM agents WHERE agents.id = runs.agent_id AND agents.archived_at IS NOT NULL)");
|
|
1481
|
+
}
|
|
1482
|
+
if (before !== undefined) {
|
|
1483
|
+
where.push("(started_at < ? OR (started_at = ? AND id < ?))");
|
|
1484
|
+
params.push(before.startedAt, before.startedAt, before.id);
|
|
1485
|
+
}
|
|
1439
1486
|
const bounded = typeof limit === "number" && Number.isSafeInteger(limit) && limit >= 0;
|
|
1440
1487
|
if (bounded)
|
|
1441
1488
|
params.push(limit);
|
|
@@ -1486,6 +1533,20 @@ class SqliteStore {
|
|
|
1486
1533
|
more: rows.length > limit,
|
|
1487
1534
|
};
|
|
1488
1535
|
},
|
|
1536
|
+
// The same columns `listed` reads beside a row, for the runs named: one read, whatever their journals. A purged run
|
|
1537
|
+
// is a tombstone, as it is to `listed`: it keeps no listing, and none is built for it.
|
|
1538
|
+
listings: async (runIds) => {
|
|
1539
|
+
if (runIds.length === 0)
|
|
1540
|
+
return [];
|
|
1541
|
+
const n = clock();
|
|
1542
|
+
const behind = listingBehind(n.sql);
|
|
1543
|
+
const rows = await db.all(`SELECT runs.id, agents.archived_at AS agent_archived_at, runs.listing, runs.list_mark, ${behind.sql} AS behind
|
|
1544
|
+
FROM runs JOIN agents ON agents.id = runs.agent_id WHERE runs.purged_at IS NULL AND runs.id IN (${runIds.map(() => "?").join(", ")})`, ...behind.params(n.params), ...runIds);
|
|
1545
|
+
return rows.map((row) => ({
|
|
1546
|
+
id: row.id, agentArchivedAt: row.agent_archived_at, listMark: Number(row.list_mark), behind: Boolean(Number(row.behind)),
|
|
1547
|
+
listing: row.listing === null ? null : JSON.parse(row.listing),
|
|
1548
|
+
}));
|
|
1549
|
+
},
|
|
1489
1550
|
counts: async (agentId) => {
|
|
1490
1551
|
const [row] = await db.all(`SELECT COUNT(*) AS count, SUM(CASE WHEN runs.state IN ('queued', 'running', 'parked')
|
|
1491
1552
|
OR (runs.state = 'stopped' AND runs.outcome = 'stopped' AND runs.imported_from IS NULL AND revisions.kind = 'agentic') THEN 1 ELSE 0 END) AS live
|
|
@@ -1504,10 +1565,10 @@ class SqliteStore {
|
|
|
1504
1565
|
) AS behind ORDER BY held, started_at DESC, id DESC LIMIT ? OFFSET ?`, ...n.params, ...n.params, ...n.params, ...n.params, ...n.params, limit, offset);
|
|
1505
1566
|
return rows.map((row) => ({ id: row.id, mark: Number(row.mark), held: Boolean(Number(row.held)) }));
|
|
1506
1567
|
},
|
|
1507
|
-
putListing: async (runId, mark, { item, cut, status, live, until, flags }) => {
|
|
1568
|
+
putListing: async (runId, mark, { item, cut, status, live, until, flags, factory }) => {
|
|
1508
1569
|
const [result] = await db.write([{
|
|
1509
1570
|
sql: "UPDATE runs SET listing = ?, list_status = ?, listing_mark = ?, listing_live = ?, listing_until = ?, listing_flags = ? WHERE id = ? AND list_mark = ? RETURNING id",
|
|
1510
|
-
params: [json({ item, cut }), status, mark, live ? 1 : 0, until, flags, runId, mark],
|
|
1571
|
+
params: [json({ item, cut, ...(factory !== undefined ? { factory } : {}) }), status, mark, live ? 1 : 0, until, flags, runId, mark],
|
|
1511
1572
|
}]);
|
|
1512
1573
|
return (result?.rows.length ?? 0) > 0;
|
|
1513
1574
|
},
|
|
@@ -1598,7 +1659,7 @@ class SqliteStore {
|
|
|
1598
1659
|
}
|
|
1599
1660
|
if (left.length)
|
|
1600
1661
|
throw new RunsMadeFromLeft(runId, left);
|
|
1601
|
-
await dropRunContent(tx, runId);
|
|
1662
|
+
await dropRunContent(tx, runId, now());
|
|
1602
1663
|
// What names it, let go: a trigger's last run, the firing that started it (its key and status kept, so it never
|
|
1603
1664
|
// fires again; the event it was given, its payload and attributes, gone), a firing's wait behind it (the
|
|
1604
1665
|
// trigger's room is read again, as for a run that ended), the run a machine's token was minted for.
|
|
@@ -1632,7 +1693,7 @@ class SqliteStore {
|
|
|
1632
1693
|
return;
|
|
1633
1694
|
if (!FINAL_STATES.includes(run.state))
|
|
1634
1695
|
throw new StoreConstraint(`run ${runId} is ${run.state}: only a final run is removed`);
|
|
1635
|
-
await dropRunContent(tx, runId);
|
|
1696
|
+
await dropRunContent(tx, runId, now());
|
|
1636
1697
|
await tx.run("DELETE FROM learning_proposals WHERE run_id = ?", runId);
|
|
1637
1698
|
// Its ledger row and every spend row it booked or that audits it, as a purge takes them.
|
|
1638
1699
|
await dropLedger(tx, runId);
|
|
@@ -1996,6 +2057,7 @@ class SqliteStore {
|
|
|
1996
2057
|
// A purged run's kept learning is its state alone (Runs.purge), for the learning meter: no reader of learning reads it.
|
|
1997
2058
|
const NOT_PURGED = "NOT EXISTS (SELECT 1 FROM runs WHERE runs.id = learning_proposals.run_id AND runs.purged_at IS NOT NULL)";
|
|
1998
2059
|
this.learning = {
|
|
2060
|
+
...learningRows(db, now),
|
|
1999
2061
|
// A round asked for, else the run's newest.
|
|
2000
2062
|
proposal: async (runId, round) => {
|
|
2001
2063
|
const row = round === undefined
|
|
@@ -2176,6 +2238,10 @@ class SqliteStore {
|
|
|
2176
2238
|
put: async (name, sealed) => {
|
|
2177
2239
|
await db.write([{ sql: "INSERT INTO sealed_keys (name, sealed, updated_at) VALUES (?, ?, ?) ON CONFLICT (name) DO UPDATE SET sealed = excluded.sealed, updated_at = excluded.updated_at", params: [name, sealed, now()] }]);
|
|
2178
2240
|
},
|
|
2241
|
+
putIfAbsent: async (name, sealed) => {
|
|
2242
|
+
const [result] = await db.write([{ sql: "INSERT INTO sealed_keys (name, sealed, updated_at) VALUES (?, ?, ?) ON CONFLICT (name) DO NOTHING", params: [name, sealed, now()] }]);
|
|
2243
|
+
return result.changes === 1;
|
|
2244
|
+
},
|
|
2179
2245
|
replaceIf: async (name, was, sealed) => {
|
|
2180
2246
|
const [result] = await db.write([{ sql: "UPDATE sealed_keys SET sealed = ?, updated_at = ? WHERE name = ? AND sealed = ?", params: [sealed, now(), name, was] }]);
|
|
2181
2247
|
return result.changes === 1;
|
package/dist/store/store.d.ts
CHANGED
|
@@ -197,10 +197,13 @@ export interface ListedRun {
|
|
|
197
197
|
/** The listing is behind now (Runs.behind's three ways): a list builds it before it shows it. */
|
|
198
198
|
readonly behind: boolean;
|
|
199
199
|
}
|
|
200
|
-
/** A run's listing as its row keeps it (Runs.putListing's item and cut). */
|
|
200
|
+
/** A run's listing as its row keeps it (Runs.putListing's item and cut, and what it kept for the Agent Factory). */
|
|
201
201
|
export interface KeptListing {
|
|
202
202
|
readonly item: Record<string, unknown>;
|
|
203
203
|
readonly cut: string;
|
|
204
|
+
/** What the build kept for the Agent Factory beside the list item (RunListing.factory), or none for a listing an
|
|
205
|
+
* earlier server built. */
|
|
206
|
+
readonly factory?: unknown;
|
|
204
207
|
}
|
|
205
208
|
/** Whether `run`, of a revision of `kind`, was stopped by a person and waits for them (state 'stopped', outcome 'stopped',
|
|
206
209
|
* an agentic run started here): its turn is over, the run is not. A workflow's stop, a cancel and an imported run's stop
|
|
@@ -215,6 +218,9 @@ export interface RunListing {
|
|
|
215
218
|
readonly live: boolean;
|
|
216
219
|
readonly until: number | null;
|
|
217
220
|
readonly flags: number;
|
|
221
|
+
/** What a scoped list (the Agent Factory's) shows of the run beside its list item, as the same build read it (JSON, the
|
|
222
|
+
* server's own: store-view.ts KeptFactory). Kept with the item and cut of the same secrets; no runs list shows it. */
|
|
223
|
+
readonly factory?: unknown;
|
|
218
224
|
}
|
|
219
225
|
export declare function stoppedByPerson(run: Pick<RunRow, "state" | "outcome" | "importedFrom">, kind: string): boolean;
|
|
220
226
|
/** The harness an imported run came from. */
|
|
@@ -468,6 +474,78 @@ export interface Learning {
|
|
|
468
474
|
from: number;
|
|
469
475
|
to: number;
|
|
470
476
|
}): Promise<LearningSpend[]>;
|
|
477
|
+
/** The agent's learning at its newest save, what a run starts from: its items there, and every version's facts (no
|
|
478
|
+
* bodies) up to it. An agent with no save yet is given its first, empty (an `init` save), so every seed names one. */
|
|
479
|
+
seed(agentId: string): Promise<LearningAt>;
|
|
480
|
+
/** The agent's learning at its newest save, as seed reads it; undefined before its first save (none is made). */
|
|
481
|
+
newest(agentId: string): Promise<LearningAt | undefined>;
|
|
482
|
+
/** The id of the agent's newest purge save (a run's purge, the host's save of kind `purged`), undefined when none: the
|
|
483
|
+
* one save that rewrites saves before it in place, so a read across two reads that this moved under reads again. */
|
|
484
|
+
newestPurge(agentId: string): Promise<string | undefined>;
|
|
485
|
+
/** The id of the agent's newest save of any kind (a purge's host save included), undefined before its first: in one
|
|
486
|
+
* read, none of its items, so a read keyed on the newest save (learning-routes.ts statusesOf) is checked cheaply. */
|
|
487
|
+
newestSave(agentId: string): Promise<string | undefined>;
|
|
488
|
+
/** The agent's learning as save `id` (a version id) left it, read now: a purged run's rows are gone from every
|
|
489
|
+
* version. Undefined when the agent's learning holds no such save (a reset removed it, or it never was). */
|
|
490
|
+
itemsAt(agentId: string, id: string): Promise<LearningAt | undefined>;
|
|
491
|
+
/** The agent's saves its log shows (a purged run's left out), newest first: at most `limit`, below version `before`
|
|
492
|
+
* when given; `total`, how many the log shows in all. */
|
|
493
|
+
saves(agentId: string, options?: {
|
|
494
|
+
limit?: number;
|
|
495
|
+
before?: number;
|
|
496
|
+
}): Promise<{
|
|
497
|
+
saves: LearningSave[];
|
|
498
|
+
more: boolean;
|
|
499
|
+
total: number;
|
|
500
|
+
}>;
|
|
501
|
+
/** One save of the agent's, by its version id or by its merge key; undefined when there is none. */
|
|
502
|
+
saveOf(agentId: string, by: {
|
|
503
|
+
id: string;
|
|
504
|
+
} | {
|
|
505
|
+
mergeKey: string;
|
|
506
|
+
}): Promise<LearningSave | undefined>;
|
|
507
|
+
/** Every version of one item, newest first, bodies included (a gone version's body null), each with its save. */
|
|
508
|
+
versions(agentId: string, kind: LearningItemKind, name: string): Promise<(LearningItem & {
|
|
509
|
+
readonly save: LearningSave;
|
|
510
|
+
})[]>;
|
|
511
|
+
/** What save `id` changed: each item it wrote, with its body just before the save and at it (null: none there). */
|
|
512
|
+
diff(agentId: string, id: string): Promise<LearningDiff | undefined>;
|
|
513
|
+
/** One save, in one transaction: refused as stale unless the agent's newest version is `base`, as already done when a
|
|
514
|
+
* save with its merge key is there, as refused when its seed is not held, and as purged when a run's purge came after
|
|
515
|
+
* a save it was read at (`readAt`). */
|
|
516
|
+
save(agentId: string, save: LearningSaveInput): Promise<LearningSaved>;
|
|
517
|
+
/** Run `runId`'s learning gone from its agent `agentId`'s (no other agent's row is touched): the item versions it
|
|
518
|
+
* wrote (a person's change of its text with them), its grades, its audits, and the promotions and audits of each
|
|
519
|
+
* workflow version it wrote. Its saves stay as facts with no text (their merge keys still taken). A purge that
|
|
520
|
+
* changed a row is a save too, the host's (kind `purged`, no item) at the newest version + 1, so every save computed
|
|
521
|
+
* before it is stale. Idempotent: a purge that finds nothing of the run's adds none. */
|
|
522
|
+
purgeRun(agentId: string, runId: string): Promise<void>;
|
|
523
|
+
/** The agent's learning gone: items, saves and records. Its runs and what they cost stay. Under the agent's learning
|
|
524
|
+
* lock, then its records' lock, as a purge takes them: a records write that began before it is in before it. */
|
|
525
|
+
reset(agentId: string): Promise<void>;
|
|
526
|
+
/** Every learning row of the agent gone, its reset's included: its delete. Locked as reset is. */
|
|
527
|
+
erase(agentId: string): Promise<void>;
|
|
528
|
+
/** The agent's records of `kind`, oldest first. */
|
|
529
|
+
records(agentId: string, kind: LearningRecordKind): Promise<LearningRecord[]>;
|
|
530
|
+
/** Adds one record of `kind`, after every other; refused as changeRecords refuses one it adds. */
|
|
531
|
+
addRecord(agentId: string, kind: LearningRecordKind, record: LearningRecordWrite): Promise<LearningRecord>;
|
|
532
|
+
/** The agent's records of `kind` changed in one transaction: `update` reads them all and answers the list they become
|
|
533
|
+
* (a record with its `seq` kept is that record, one without is added after the others), or undefined for no change.
|
|
534
|
+
* `update` reads too, in the same transaction, whether a version of a workflow holds a digest (`held`): a run's purge
|
|
535
|
+
* takes the records' lock before it changes a version, so none goes between the read and the write. Each record the
|
|
536
|
+
* write adds (or moves to another workflow, digest or run) is checked in that transaction: a promotion's or an
|
|
537
|
+
* audit's digest must be held by a version of its workflow (unless it is `anyDigest`, a failed draft's, which no
|
|
538
|
+
* version holds), and its run (the `runId` column) is not purged. Else the write throws LearningRecordRefused and
|
|
539
|
+
* writes nothing. A promotion written (added or changed) is kept with its `commit` a save that holds its digest, and
|
|
540
|
+
* with each purged run's copies its data names blanked (learn/promote.ts forgetRunIn). */
|
|
541
|
+
changeRecords<T>(agentId: string, kind: LearningRecordKind, update: (records: readonly LearningRecord[], held?: (workflow: string, digest: string) => boolean) => {
|
|
542
|
+
records: readonly LearningRecordWrite[];
|
|
543
|
+
result: T;
|
|
544
|
+
} | {
|
|
545
|
+
result: T;
|
|
546
|
+
}, options?: {
|
|
547
|
+
readonly anyDigest?: string;
|
|
548
|
+
}): Promise<T>;
|
|
471
549
|
/** Agent `agentId`'s ledger (learn/ledger.ts), in one read (one snapshot of both tables): every run's row its end
|
|
472
550
|
* recorded, oldest first, and every spend row. With `runIds`, those runs' rows alone and the spend rows they booked or
|
|
473
551
|
* that audit them (none for none). Written only beside a run's end and a heal of its cost (run-patch.ts recordLedger);
|
|
@@ -488,6 +566,116 @@ export interface Learning {
|
|
|
488
566
|
readonly jobUsd: number;
|
|
489
567
|
}[]>;
|
|
490
568
|
}
|
|
569
|
+
/** A learning item: one line of the owner's notes (corrections.md), or one learned workflow's folder. */
|
|
570
|
+
export type LearningItemKind = "note" | "workflow";
|
|
571
|
+
/** What a version of an item was: a run's merge, or a person's change. */
|
|
572
|
+
export type LearningChangeKind = "learned" | "approved" | "edited" | "created" | "retired" | "restored";
|
|
573
|
+
/** One version of an item. A note's body is its line; a workflow's is JSON, its files by path. */
|
|
574
|
+
export interface LearningItem {
|
|
575
|
+
readonly kind: LearningItemKind;
|
|
576
|
+
readonly name: string;
|
|
577
|
+
readonly version: number;
|
|
578
|
+
/** Null: the item is gone at this version. */
|
|
579
|
+
readonly body: string | null;
|
|
580
|
+
/** The run whose text it is: a note's, the run whose merge wrote it, kept by a person's change of it (null: a
|
|
581
|
+
* person's own); a workflow's, its workflow.json's writer (`writers`). */
|
|
582
|
+
readonly byRun: string | null;
|
|
583
|
+
/** A workflow's writer of each of its files, by path: the run whose merge changed the file to its text (a merge that
|
|
584
|
+
* gives it unchanged, and a person's edit of it, keep the writer before; null: a person's own file). Null for a note. */
|
|
585
|
+
readonly writers: Readonly<Record<string, string | null>> | null;
|
|
586
|
+
readonly change: LearningChangeKind;
|
|
587
|
+
readonly person: boolean;
|
|
588
|
+
/** A note's place among the notes. */
|
|
589
|
+
readonly pos: number;
|
|
590
|
+
/** A workflow's digest (its workflow.json's), which its promotions and audits name. */
|
|
591
|
+
readonly digest: string | null;
|
|
592
|
+
readonly at: number;
|
|
593
|
+
}
|
|
594
|
+
/** One save: a version of the agent's learning. `id` is the version id a run's seed names. */
|
|
595
|
+
export interface LearningSave {
|
|
596
|
+
readonly version: number;
|
|
597
|
+
readonly id: string;
|
|
598
|
+
readonly at: number;
|
|
599
|
+
readonly by: LearningSaveBy;
|
|
600
|
+
readonly reason: string;
|
|
601
|
+
/** The paths the save changed, as the folder names them. */
|
|
602
|
+
readonly files: readonly string[];
|
|
603
|
+
readonly mergeKey: string | null;
|
|
604
|
+
}
|
|
605
|
+
/** Who saved: a run's merge (its round past the first), a person's change, or the host: the empty first save of a run's
|
|
606
|
+
* seed (`init`), or a purged run's save with its words gone (`purged`). */
|
|
607
|
+
export type LearningSaveBy = {
|
|
608
|
+
readonly run: string;
|
|
609
|
+
readonly round?: number;
|
|
610
|
+
} | {
|
|
611
|
+
readonly person: Exclude<LearningChangeKind, "learned">;
|
|
612
|
+
readonly file: string;
|
|
613
|
+
readonly approved?: boolean;
|
|
614
|
+
} | {
|
|
615
|
+
readonly host: "init" | "purged";
|
|
616
|
+
};
|
|
617
|
+
/** The agent's learning at one save: the save, its live items, and the facts of every item version up to it. */
|
|
618
|
+
export interface LearningAt {
|
|
619
|
+
readonly save: LearningSave;
|
|
620
|
+
readonly items: readonly LearningItem[];
|
|
621
|
+
readonly history: readonly Omit<LearningItem, "body">[];
|
|
622
|
+
}
|
|
623
|
+
export type LearningItemWrite = Omit<LearningItem, "version" | "at">;
|
|
624
|
+
export interface LearningSaveInput {
|
|
625
|
+
/** The version the save was computed on (0 before the first). */
|
|
626
|
+
readonly base: number;
|
|
627
|
+
readonly by: Exclude<LearningSaveBy, {
|
|
628
|
+
host: string;
|
|
629
|
+
}>;
|
|
630
|
+
readonly reason: string;
|
|
631
|
+
readonly files: readonly string[];
|
|
632
|
+
readonly items: readonly LearningItemWrite[];
|
|
633
|
+
/** A run's merge: one save per key, ever (a purge keeps the key taken). */
|
|
634
|
+
readonly mergeKey?: string;
|
|
635
|
+
/** A version id the agent's learning must still hold (a run's seed). */
|
|
636
|
+
readonly seed?: string;
|
|
637
|
+
/** The saves the write's text was read at (a run's seed, and each save its compile turn read a workflow at): refused
|
|
638
|
+
* as purged when a run's purge came after any of them (its host save, kind `purged`, is newer), since that purge
|
|
639
|
+
* rewrote what was read in place and the write can't be told apart from the purged run's bytes. */
|
|
640
|
+
readonly readAt?: readonly string[];
|
|
641
|
+
}
|
|
642
|
+
export type LearningSaved = {
|
|
643
|
+
readonly saved: LearningSave;
|
|
644
|
+
} | {
|
|
645
|
+
readonly stale: number;
|
|
646
|
+
} | {
|
|
647
|
+
readonly refused: {
|
|
648
|
+
readonly seed: string;
|
|
649
|
+
};
|
|
650
|
+
} | {
|
|
651
|
+
readonly purged: {
|
|
652
|
+
readonly readAt: string;
|
|
653
|
+
};
|
|
654
|
+
} | {
|
|
655
|
+
readonly already: LearningSave;
|
|
656
|
+
};
|
|
657
|
+
export interface LearningDiff {
|
|
658
|
+
readonly save: LearningSave;
|
|
659
|
+
readonly parent: LearningSave | undefined;
|
|
660
|
+
readonly items: readonly {
|
|
661
|
+
readonly kind: LearningItemKind;
|
|
662
|
+
readonly name: string;
|
|
663
|
+
readonly before: string | null;
|
|
664
|
+
readonly after: string | null;
|
|
665
|
+
}[];
|
|
666
|
+
}
|
|
667
|
+
export type LearningRecordKind = "promotion" | "grade" | "audit";
|
|
668
|
+
export interface LearningRecord {
|
|
669
|
+
readonly seq: number;
|
|
670
|
+
readonly runId: string | null;
|
|
671
|
+
readonly workflow: string | null;
|
|
672
|
+
readonly digest: string | null;
|
|
673
|
+
readonly data: unknown;
|
|
674
|
+
readonly at: number;
|
|
675
|
+
}
|
|
676
|
+
export type LearningRecordWrite = Omit<LearningRecord, "seq" | "at"> & {
|
|
677
|
+
readonly seq?: number;
|
|
678
|
+
};
|
|
491
679
|
/** One run's learning end as GET /usage's learning meter counts it (Learning.spend). */
|
|
492
680
|
export interface LearningSpend {
|
|
493
681
|
readonly agentId: string;
|
|
@@ -1162,7 +1350,10 @@ export interface Runs {
|
|
|
1162
1350
|
* false: not); its agent's archive is read apart. A built-in learning run (one a kept learning names) is never listed. `labels`: only runs holding every one of these labels, key and value.
|
|
1163
1351
|
* `disk`: only the runs on that disk (RunRow.disk), null for the default disk's; not given, every disk's.
|
|
1164
1352
|
* A purged run (Runs.purge) only with `purged`: the readers of money and counts (usage, stats, analytics) and an
|
|
1165
|
-
* import's read of the sessions it holds, never a reader of a run's content.
|
|
1353
|
+
* import's read of the sessions it holds, never a reader of a run's content.
|
|
1354
|
+
* `scope` selects, before the limit, the runs the Agent Factory shows, never an imported one: `active`, every
|
|
1355
|
+
* execution still going (a resumable agentic stop and a built-in learning run included); `review`, unarchived ended
|
|
1356
|
+
* escalations and failures. `before` is an exclusive keyset boundary in descending (startedAt, id) order. */
|
|
1166
1357
|
list(filter: {
|
|
1167
1358
|
agentId?: string;
|
|
1168
1359
|
revisionId?: string;
|
|
@@ -1172,6 +1363,11 @@ export interface Runs {
|
|
|
1172
1363
|
disk?: string | null;
|
|
1173
1364
|
limit?: number;
|
|
1174
1365
|
purged?: boolean;
|
|
1366
|
+
scope?: "active" | "review";
|
|
1367
|
+
before?: {
|
|
1368
|
+
startedAt: number;
|
|
1369
|
+
id: string;
|
|
1370
|
+
};
|
|
1175
1371
|
}): Promise<RunRow[]>;
|
|
1176
1372
|
/** A page of a runs list, in one read: newest first, `offset` rows on, at most `limit`, and whether more follow (`more`).
|
|
1177
1373
|
* Each with its listing as its row keeps it (RUN_LISTING_COLUMNS: null while none has been built), whether that is
|
|
@@ -1183,6 +1379,13 @@ export interface Runs {
|
|
|
1183
1379
|
readonly rows: readonly ListedRun[];
|
|
1184
1380
|
readonly more: boolean;
|
|
1185
1381
|
}>;
|
|
1382
|
+
/** The listings of the runs `runIds`, in one read: each run there is that is not purged, with its listing as its row
|
|
1383
|
+
* keeps it, its mark, whether it is behind and its agent's archive time, as `listed` gives them. Whatever the run
|
|
1384
|
+
* otherwise: a built-in learning run and an audit's shadow run too, which the Agent Factory's active scope shows
|
|
1385
|
+
* (`list`'s `scope`). In no order. */
|
|
1386
|
+
listings(runIds: readonly string[]): Promise<readonly (Pick<ListedRun, "agentArchivedAt" | "listing" | "listMark" | "behind"> & {
|
|
1387
|
+
readonly id: string;
|
|
1388
|
+
})[]>;
|
|
1186
1389
|
/** Agent `agentId`'s runs counted in one read (an agent's view): every run it has (`count`), and those still going
|
|
1187
1390
|
* (`live`: queued, running or parked, or an agentic run a person stopped, which a message continues). A built-in learning
|
|
1188
1391
|
* run and an audit's shadow run are none of them. */
|
|
@@ -1211,7 +1414,7 @@ export interface Runs {
|
|
|
1211
1414
|
/** Run `runId`'s list_mark now (the mark a build of its listing starts from), or undefined when there is no such run. */
|
|
1212
1415
|
listMark(runId: string): Promise<number | undefined>;
|
|
1213
1416
|
/** Moves the mark of every run whose listing read something outside the run (`flags`, RUN_LISTING_COLUMNS' listing_flags),
|
|
1214
|
-
* of agent `agentId` when given: the server's keys changed, or an agent's learning
|
|
1417
|
+
* of agent `agentId` when given: the server's keys changed, or an agent's learning did. The number of runs moved. */
|
|
1215
1418
|
relist(options: {
|
|
1216
1419
|
flags: number;
|
|
1217
1420
|
agentId?: string;
|
|
@@ -1240,7 +1443,7 @@ export interface Runs {
|
|
|
1240
1443
|
archive(runId: string, archived: boolean): Promise<void>;
|
|
1241
1444
|
/** Every run of agent `agentId` with its state, oldest first, its built-in learning runs and purged runs included
|
|
1242
1445
|
* (which list leaves out): what deleting the agent stops and removes, with the runner that holds each (null: none),
|
|
1243
|
-
* its purge time and its disk (RunRow.disk
|
|
1446
|
+
* its purge time and its disk (RunRow.disk). */
|
|
1244
1447
|
every(agentId: string): Promise<{
|
|
1245
1448
|
id: string;
|
|
1246
1449
|
state: RunState;
|
|
@@ -1261,8 +1464,8 @@ export interface Runs {
|
|
|
1261
1464
|
* comes first (one that can't be written, a full disk, throws with nothing purged), and a WAL checkpoint (TRUNCATE)
|
|
1262
1465
|
* follows the commit, so with secure_delete neither the file nor its WAL keeps the bytes; a checkpoint another
|
|
1263
1466
|
* connection holds back keeps the marker for the next start's scrub. Postgres keeps old row versions until its
|
|
1264
|
-
* VACUUM. The run's
|
|
1265
|
-
*
|
|
1467
|
+
* VACUUM. The run's learning rows go in the same transaction (Learning.purgeRun): its saves' words, its notes and
|
|
1468
|
+
* workflow files, its records. */
|
|
1266
1469
|
purge(runId: string, kept: PurgeKept): Promise<void>;
|
|
1267
1470
|
/** The run's rows gone, in one transaction: its journal, commands, origin, launch, live view and viewers, its channel
|
|
1268
1471
|
* posts with their tries and what each channel was told of it, its kept learning, its changes in the run-change feed,
|
|
@@ -1639,6 +1842,9 @@ export interface SealedKeys {
|
|
|
1639
1842
|
get(name: string): Promise<Uint8Array | undefined>;
|
|
1640
1843
|
/** Saves `sealed` under `name`, inserted or replaced in place. */
|
|
1641
1844
|
put(name: string, sealed: Uint8Array): Promise<void>;
|
|
1845
|
+
/** Saves `sealed` under `name` only where no row is, in one statement: of two writers racing on one name, one's bytes
|
|
1846
|
+
* are kept. True when it was written; false, writing nothing, when a row was there. */
|
|
1847
|
+
putIfAbsent(name: string, sealed: Uint8Array): Promise<boolean>;
|
|
1642
1848
|
/** Saves `sealed` under `name` only while its row still holds `was` (the bytes as get read them), in one statement: a
|
|
1643
1849
|
* compare-and-set, so of two writers that read one row only one replaces it. Each seal is fresh bytes, so a row any
|
|
1644
1850
|
* writer saved since reads as changed. True when it was replaced; false, writing nothing, when it changed or is gone. */
|
|
@@ -2340,6 +2546,13 @@ export declare class SchemaVersionUnknown extends Error {
|
|
|
2340
2546
|
readonly known: number;
|
|
2341
2547
|
constructor(file: string, found: number | null, known: number);
|
|
2342
2548
|
}
|
|
2549
|
+
/** A learning record write refused in its own transaction, nothing written (Store.learning changeRecords, addRecord): a
|
|
2550
|
+
* promotion or audit of a digest no version of its workflow holds (a run's purge took it since the write read it), or
|
|
2551
|
+
* a record of a run that was purged. */
|
|
2552
|
+
export declare class LearningRecordRefused extends Error {
|
|
2553
|
+
readonly records: readonly LearningRecordWrite[];
|
|
2554
|
+
constructor(agentId: string, records: readonly LearningRecordWrite[], why: "unheld" | "purged");
|
|
2555
|
+
}
|
|
2343
2556
|
/** A store a later build migrated past what this runner can run beside: its schema is ahead of the version this build
|
|
2344
2557
|
* knows, and its runner floor (a breaking migration's version) is above it. Run a runner of the server's release. A
|
|
2345
2558
|
* SchemaVersionUnknown, so every caller that refuses an unknown schema refuses this one the same way (a runner's exit 3). */
|
package/dist/store/store.js
CHANGED
|
@@ -245,6 +245,19 @@ export class SchemaVersionUnknown extends Error {
|
|
|
245
245
|
this.known = known;
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
|
+
/** A learning record write refused in its own transaction, nothing written (Store.learning changeRecords, addRecord): a
|
|
249
|
+
* promotion or audit of a digest no version of its workflow holds (a run's purge took it since the write read it), or
|
|
250
|
+
* a record of a run that was purged. */
|
|
251
|
+
export class LearningRecordRefused extends Error {
|
|
252
|
+
records;
|
|
253
|
+
constructor(agentId, records, why) {
|
|
254
|
+
super(why === "unheld"
|
|
255
|
+
? `agent ${agentId}'s learning holds no version of ${records.map((one) => `${one.workflow}@${one.digest}`).join(", ")}: a run's purge took it, so no record of it is written`
|
|
256
|
+
: `run ${records.map((one) => one.runId).join(", ")} was purged, so no learning record of it is written`);
|
|
257
|
+
this.name = "LearningRecordRefused";
|
|
258
|
+
this.records = records;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
248
261
|
/** A store a later build migrated past what this runner can run beside: its schema is ahead of the version this build
|
|
249
262
|
* knows, and its runner floor (a breaking migration's version) is above it. Run a runner of the server's release. A
|
|
250
263
|
* SchemaVersionUnknown, so every caller that refuses an unknown schema refuses this one the same way (a runner's exit 3). */
|
|
@@ -71,10 +71,40 @@ export type WholeAnswer = {
|
|
|
71
71
|
/** The WholeAnswer of a run whose served words are cut of `values` (run-cut.ts runCutValues). */
|
|
72
72
|
export declare const wholeAnswerFor: (values: readonly string[]) => WholeAnswer;
|
|
73
73
|
export declare const servedSince: (store: Store) => number;
|
|
74
|
-
/** Run `runId`'s answer rows dropped from what the readers of `store` last served (wholeAnswers)
|
|
75
|
-
* run's text kept in no memory of this process (store-view.ts
|
|
76
|
-
* before it keeps what it read. The keys it dropped. */
|
|
74
|
+
/** Run `runId`'s answer rows dropped from what the readers of `store` last served (wholeAnswers), and its texts from what
|
|
75
|
+
* they last cut (rowCutsOnce): a purged or deleted run's text kept in no memory of this process (store-view.ts
|
|
76
|
+
* forgetServed). Counted (servedSince), so no read begun before it keeps what it read. The answer keys it dropped. */
|
|
77
77
|
export declare function forgetServedAnswers(store: Store, runId: string): string[];
|
|
78
|
+
/** The bound in force (CUT_BYTES): a test sets a smaller one to see the oldest go. */
|
|
79
|
+
export declare const cutBudget: {
|
|
80
|
+
bytes: number;
|
|
81
|
+
};
|
|
82
|
+
/** A run's cut as a reader holds it (run-cut.ts runCutValues): its held values and the census its files are cut by, or
|
|
83
|
+
* "unreadable" (its rows withheld, read under no values). */
|
|
84
|
+
export type RowCut = {
|
|
85
|
+
readonly values: readonly string[];
|
|
86
|
+
readonly censusDigest?: string;
|
|
87
|
+
} | "unreadable";
|
|
88
|
+
/** The row redactor (`redact`) and the whole-text check (`holds`) of run `runId`'s rows under its `cut` (run-cut.ts
|
|
89
|
+
* runCutValues), as a reader's TimelineOptions takes them: each text cut once per cut, its values in their order and its
|
|
90
|
+
* census mode (cutsKept), what was cut kept only while no run's text was forgotten since `since` (servedSince, taken
|
|
91
|
+
* before the read began). */
|
|
92
|
+
export declare function rowCutsOnce(store: Store, runId: string, cut: RowCut, since: number): {
|
|
93
|
+
redact: (text: string) => string;
|
|
94
|
+
holds: (text: string) => boolean;
|
|
95
|
+
};
|
|
96
|
+
/** What the readers of `store` keep of their cuts now: the bytes counted (cutBudget bounds it), the texts and the sets, and
|
|
97
|
+
* each kept text (its set, its slot and what was made of it), so a test can read that nothing a run wrote is kept. */
|
|
98
|
+
export declare function cutsKeptOf(store: Store): {
|
|
99
|
+
bytes: number;
|
|
100
|
+
texts: number;
|
|
101
|
+
sets: number;
|
|
102
|
+
kept: {
|
|
103
|
+
set: string;
|
|
104
|
+
slot: string;
|
|
105
|
+
made: string | boolean;
|
|
106
|
+
}[];
|
|
107
|
+
};
|
|
78
108
|
/** `rows` (runTimeline's, rendered with `options`) with each final answer whole, as main served a run's answer: the renderer
|
|
79
109
|
* cuts a row's text at CAPS.text, and its redactor (`options.redact`, key-refusal.ts redacted) reads only the head a row
|
|
80
110
|
* shows and cuts the rest, ending what it cut in "..." (short of the cap when it replaced a held value there), or giving
|