@parcha/agentrun-serve 0.1.0-beta.59 → 0.1.0-beta.61
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 +135 -0
- package/README.md +230 -120
- package/dist/acp-package.d.ts +4 -0
- 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 +21 -3
- package/dist/api-only.js +41 -6
- 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/browser-person.d.ts +1 -1
- package/dist/browser-person.js +1 -1
- package/dist/calendar/tools.js +1 -1
- 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/cli.js +42 -10
- package/dist/console/assets/{backend-BztxEAvb.js → backend-C9ffXUR5.js} +1 -1
- package/dist/console/assets/index-BnZV3lvW.js +639 -0
- package/dist/console/assets/{share-L84tlUDW.js → share-B1o5mJ56.js} +2 -2
- package/dist/console/assets/{styles-CaRKlHke.js → styles-D_znYrHR.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/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- 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-check.js +2 -1
- package/dist/harness-keys.d.ts +1 -2
- package/dist/harness-keys.js +1 -2
- package/dist/harness-recipe.d.ts +13 -2
- package/dist/harness-recipe.js +30 -7
- package/dist/harness-sign-in.js +2 -1
- package/dist/harness-table.d.ts +9 -3
- package/dist/harness-table.js +11 -5
- 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 +30 -18
- 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/secrets.d.ts +2 -1
- package/dist/learn/secrets.js +2 -2
- package/dist/learn/workflow-draft.d.ts +4 -1
- package/dist/learn/workflow-draft.js +12 -2
- package/dist/learned-nodes.d.ts +36 -0
- package/dist/learned-nodes.js +23 -0
- 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/local-model.d.ts +144 -0
- package/dist/local-model.js +214 -0
- package/dist/mcp-gateway.d.ts +6 -0
- package/dist/mcp-gateway.js +44 -8
- package/dist/mcp-probe.d.ts +7 -0
- package/dist/mcp-probe.js +7 -0
- 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/ollama-provider.d.ts +35 -0
- package/dist/ollama-provider.js +108 -2
- package/dist/openapi.js +147 -35
- package/dist/place-offers.d.ts +3 -0
- package/dist/place-offers.js +3 -0
- package/dist/place.d.ts +35 -12
- package/dist/place.js +67 -29
- package/dist/print.js +1 -1
- package/dist/purged-workflow.d.ts +0 -33
- package/dist/purged-workflow.js +3 -71
- package/dist/redact/match.d.ts +36 -8
- package/dist/redact/match.js +179 -44
- package/dist/run-export.js +4 -2
- 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/run-usage.js +3 -2
- package/dist/runnable.js +25 -8
- package/dist/runner/adapter-loop.d.ts +8 -1
- package/dist/runner/adapter-loop.js +100 -20
- package/dist/runner/adapter-run-spec.d.ts +3 -5
- package/dist/runner/adapter-run-spec.js +35 -61
- package/dist/runner/adapters/pi.d.ts +3 -2
- package/dist/runner/adapters/pi.js +3 -1
- package/dist/runner/audit.d.ts +3 -5
- package/dist/runner/audit.js +28 -51
- package/dist/runner/cli-run-spec.js +19 -22
- package/dist/runner/compare-end.d.ts +1 -3
- 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/dispatch.js +2 -2
- package/dist/runner/feedback-round.d.ts +1 -1
- package/dist/runner/feedback-round.js +2 -2
- package/dist/runner/harness-loops.d.ts +9 -0
- package/dist/runner/harness-loops.js +49 -7
- package/dist/runner/held.d.ts +4 -11
- 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/live-ticker.js +3 -4
- package/dist/runner/main.js +1 -1
- package/dist/runner/mcp-claim.js +3 -2
- package/dist/runner/mcp-run.d.ts +23 -4
- package/dist/runner/mcp-run.js +31 -2
- package/dist/runner/metrics.d.ts +4 -0
- package/dist/runner/metrics.js +9 -3
- package/dist/runner/monid-run.js +3 -1
- package/dist/runner/native-loop.js +3 -4
- package/dist/runner/promotion.d.ts +19 -28
- package/dist/runner/promotion.js +50 -69
- package/dist/runner/redact.d.ts +3 -0
- package/dist/runner/redact.js +7 -0
- 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 +12 -68
- package/dist/runner/runner.d.ts +1 -1
- package/dist/runner/sdk-loop.js +7 -7
- package/dist/runner/workflow-calls.d.ts +4 -1
- package/dist/runner/workflow-calls.js +35 -18
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-loop.js +3 -1
- package/dist/runner/workflow-spec.d.ts +4 -0
- package/dist/runner/workflow-spec.js +18 -13
- package/dist/runs-over-store.d.ts +2 -2
- package/dist/runs-over-store.js +1 -1
- 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/secret-cut.js +7 -4
- package/dist/secret-rules.js +97 -83
- 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 +22 -15
- package/dist/server.js +311 -198
- package/dist/slack.js +2 -1
- 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/migrate.js +3 -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 +23 -26
- package/dist/store-reads/learning.js +42 -30
- 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 +27 -3
- package/dist/tool-plane.js +79 -4
- package/dist/tools.d.ts +12 -2
- package/dist/tools.js +42 -7
- package/dist/trigger-launch-hook.d.ts +2 -2
- package/dist/trigger-launch-hook.js +1 -1
- package/dist/triggers.d.ts +7 -4
- package/dist/triggers.js +4 -4
- 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
package/dist/learn/audit.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Store } from "../store/store.js";
|
|
2
2
|
import type { AuditLoop } from "../learning-setting.js";
|
|
3
3
|
import type { RunLaunch } from "../run-launch.js";
|
|
4
|
-
import {
|
|
5
|
-
import { type CostStop, type PromotionRecord, type Refused, type ServingState } from "./promote.js";
|
|
6
|
-
export { AUDITS_FILE };
|
|
7
|
-
/** The newest rows the ledger keeps: twice the widest window a definition may set (AUDIT_MAX), and a file well under the
|
|
8
|
-
* folder's file cap (a line is a few hundred bytes); with them, the started lines of theirs, and every open one. */
|
|
9
|
-
export declare const AUDITS_KEPT = 2000;
|
|
4
|
+
import { type CostStop, type PromotionRecord, type ServingState } from "./promote.js";
|
|
10
5
|
/** What every shadow run's id starts with: its served run's id follows (shadowRunId). No server-minted id starts so. */
|
|
11
6
|
export declare const SHADOW_PREFIX = "audit.";
|
|
7
|
+
/** The newest rows the ledger keeps: twice the widest window a definition may set (AUDIT_MAX); with them, the started
|
|
8
|
+
* lines of theirs, and every open one (addAuditLines trims it in the write that adds). */
|
|
9
|
+
export declare const AUDITS_KEPT = 2000;
|
|
12
10
|
/** One finished audit. `run`: the served run; `shadow_run`: its shadow (null for a grade's row, or one never started);
|
|
13
11
|
* `workflow` at `digest` served it, under the promotion begun at `promoted_at` (learn/promote.ts promotionStartOf: the
|
|
14
12
|
* one serving when its shadow started, or at the grade; null: none); `agreed`: whether the served answer is right
|
|
@@ -75,22 +73,22 @@ export declare const auditsOffWords: (tool: string) => string;
|
|
|
75
73
|
* uploaded files. A triggered run's context (a GitHub event's checkout, the thread it answers on) is never rebuilt for a
|
|
76
74
|
* shadow, which could answer there too: its served run is not auditable (its record's metrics.not_auditable). */
|
|
77
75
|
export declare const auditableLaunch: (launch: Pick<RunLaunch, "trigger" | "inputOrigin" | "files">) => boolean;
|
|
78
|
-
/** The
|
|
79
|
-
export
|
|
80
|
-
/** The
|
|
81
|
-
export declare
|
|
82
|
-
/** The ledger's
|
|
83
|
-
export declare
|
|
84
|
-
/** The ledger's rows on the folder's main: its finished audits, oldest first. */
|
|
85
|
-
export declare const readAudits: (ws: Workspace) => Promise<AuditRow[]>;
|
|
76
|
+
/** The store's learning records, as the ledger is read and written. */
|
|
77
|
+
export type AuditRecords = Pick<Store["learning"], "records" | "changeRecords">;
|
|
78
|
+
/** The agent's ledger, in the order written (none before the first line). */
|
|
79
|
+
export declare const ledgerOf: (rows: Pick<AuditRecords, "records">, agentId: string) => Promise<LedgerLine[]>;
|
|
80
|
+
/** The ledger's rows: its finished audits, oldest first. */
|
|
81
|
+
export declare const readAudits: (rows: Pick<AuditRecords, "records">, agentId: string) => Promise<AuditRow[]>;
|
|
86
82
|
/** A line's place in the ledger: one per served run and source (a started line's, its shadow's row, a grade's row). */
|
|
87
83
|
export declare const lineKey: (line: LedgerLine) => string;
|
|
88
|
-
/**
|
|
89
|
-
*
|
|
90
|
-
|
|
84
|
+
/** Appends `lines` to the ledger, each not there yet (lineKey), in one transaction: `replace`, a line whose key is there
|
|
85
|
+
* takes the place of the one there (a grade's row of a run graded again). The ledger after (`all`) with the lines it
|
|
86
|
+
* appended. A line of a digest no version of its workflow holds (a run's purge took it since the line was read), or of a
|
|
87
|
+
* run that was purged, is never appended (Store.learning changeRecords refuses it): the others are. */
|
|
88
|
+
export declare function addAuditLines(rows: AuditRecords, agentId: string, lines: readonly LedgerLine[], replace?: boolean): Promise<{
|
|
89
|
+
all: LedgerLine[];
|
|
91
90
|
added: LedgerLine[];
|
|
92
|
-
|
|
93
|
-
};
|
|
91
|
+
}>;
|
|
94
92
|
/** The rows the hold rule counts for `workflow` at `digest` under the promotion begun at `promotedAt` (learn/promote.ts
|
|
95
93
|
* promotionStartOf; none counted for null): those with a verdict, the newest `hold_window` of them. A served run an
|
|
96
94
|
* owner graded is counted by its grade's row alone: the grade is its known answer, as it is the check's, so its
|
|
@@ -112,7 +110,7 @@ export declare function auditLineOf(rows: readonly AuditRow[], workflow: string,
|
|
|
112
110
|
/** What the promotions read says of each learned workflow beside what serves (learn/promote.ts servingOf, in its order):
|
|
113
111
|
* `state` (learn/promote.ts servingStateOf with the money rule's decision, `costStop`: the word the learning view's
|
|
114
112
|
* `status` says too), its newest decided check's numbers, and its audit line over the rows of the serving (else the
|
|
115
|
-
* newest) revision's newest promotion (the ones the hold rule counts).
|
|
113
|
+
* newest) revision's newest promotion (the ones the hold rule counts). */
|
|
116
114
|
export type ServingLine = {
|
|
117
115
|
readonly state: ServingState;
|
|
118
116
|
readonly check: {
|
|
@@ -123,4 +121,4 @@ export type ServingLine = {
|
|
|
123
121
|
} | null;
|
|
124
122
|
readonly audit: AuditLine | null;
|
|
125
123
|
};
|
|
126
|
-
export declare function servingLinesOf(records: readonly PromotionRecord[], rows: readonly AuditRow[], loop: Pick<AuditLoop, "hold_window" | "hold_disagree">, costStop: CostStop
|
|
124
|
+
export declare function servingLinesOf(records: readonly PromotionRecord[], rows: readonly AuditRow[], loop: Pick<AuditLoop, "hold_window" | "hold_disagree">, costStop: CostStop): ServingLine[];
|
package/dist/learn/audit.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// The audit ledger:
|
|
2
|
-
// alone (runner/audit.ts, and the server for an owner's grade). A `started` line is a shadow audit begun (written before
|
|
1
|
+
// The audit ledger: the agent's audit records (Store.learning records of kind audit), one line each, appended by the
|
|
2
|
+
// host alone (runner/audit.ts, and the server for an owner's grade). A `started` line is a shadow audit begun (written before
|
|
3
3
|
// its shadow run is created); a row is one finished audit of a run a promoted learned workflow served first: its shadow
|
|
4
4
|
// run's answer (the same agent on the same input, learning off) against the served one (source `shadow`, the started
|
|
5
5
|
// line's result), or an owner's grade of the served run (source `grade`: the served answer against the grade's known
|
|
@@ -10,15 +10,14 @@
|
|
|
10
10
|
// run cost.
|
|
11
11
|
import { createHash } from "node:crypto";
|
|
12
12
|
import { COMPUTER_TOOLS } from "@parcha/agentrun-kernel/kernel";
|
|
13
|
+
import { LearningRecordRefused } from "../store/store.js";
|
|
13
14
|
import { pinAnnotations, toolClassOf, toolWord } from "./replay-calls.js";
|
|
14
|
-
import { AUDITS_FILE, readLearning } from "./folder.js";
|
|
15
15
|
import { promotionStartOf, servingOf, servingStateOf } from "./promote.js";
|
|
16
|
-
export { AUDITS_FILE };
|
|
17
|
-
/** The newest rows the ledger keeps: twice the widest window a definition may set (AUDIT_MAX), and a file well under the
|
|
18
|
-
* folder's file cap (a line is a few hundred bytes); with them, the started lines of theirs, and every open one. */
|
|
19
|
-
export const AUDITS_KEPT = 2_000;
|
|
20
16
|
/** What every shadow run's id starts with: its served run's id follows (shadowRunId). No server-minted id starts so. */
|
|
21
17
|
export const SHADOW_PREFIX = "audit.";
|
|
18
|
+
/** The newest rows the ledger keeps: twice the widest window a definition may set (AUDIT_MAX); with them, the started
|
|
19
|
+
* lines of theirs, and every open one (addAuditLines trims it in the write that adds). */
|
|
20
|
+
export const AUDITS_KEPT = 2_000;
|
|
22
21
|
/** The rows of `lines` (the finished audits), oldest first. */
|
|
23
22
|
export const rowsOf = (lines) => lines.filter((line) => line.source !== "started");
|
|
24
23
|
/** The started lines of `lines` with no result row yet: the audits settlement still owes, oldest first. */
|
|
@@ -76,57 +75,75 @@ const isLine = (value) => {
|
|
|
76
75
|
const noVerdictOf = (line) => line.agreed !== null ? {} : line.skipped === "no allowance" ? { skipped: "no allowance" } : line.parked === true ? { parked: true } : {};
|
|
77
76
|
/** A line's turn (AuditRow.turn), as written: none when it has none. */
|
|
78
77
|
const turnOf = (line) => (line.turn === undefined ? {} : { turn: line.turn });
|
|
79
|
-
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
/** A ledger line as read back, or undefined for one out of shape. */
|
|
79
|
+
function lineOf(value) {
|
|
80
|
+
if (!isLine(value))
|
|
81
|
+
return undefined;
|
|
82
|
+
const { run, workflow, digest, promoted_at, at } = value;
|
|
83
|
+
return value.source === "started"
|
|
84
|
+
? { source: "started", run, shadow_run: value.shadow_run, workflow, digest, promoted_at, ...turnOf(value), at }
|
|
85
|
+
: { run, shadow_run: value.shadow_run, workflow, digest, promoted_at, source: value.source, agreed: value.agreed, served_cost: value.served_cost, shadow_cost: value.shadow_cost, ...turnOf(value), ...noVerdictOf(value), at };
|
|
86
|
+
}
|
|
87
|
+
const linesOf = (records) => records.flatMap((one) => { const line = lineOf(one.data); return line ? [line] : []; });
|
|
88
|
+
/** A line's record: its served run, so the run's purge deletes it. */
|
|
89
|
+
const lineWrite = (line) => ({ runId: line.run, workflow: line.workflow, digest: line.digest, data: line });
|
|
90
|
+
/** The agent's ledger, in the order written (none before the first line). */
|
|
91
|
+
export const ledgerOf = async (rows, agentId) => linesOf(await rows.records(agentId, "audit"));
|
|
92
|
+
/** The ledger's rows: its finished audits, oldest first. */
|
|
93
|
+
export const readAudits = async (rows, agentId) => rowsOf(await ledgerOf(rows, agentId));
|
|
94
|
+
/** A line's place in the ledger: one per served run and source (a started line's, its shadow's row, a grade's row). */
|
|
95
|
+
export const lineKey = (line) => `${line.source}:${line.run}`;
|
|
96
|
+
/** Appends `lines` to the ledger, each not there yet (lineKey), in one transaction: `replace`, a line whose key is there
|
|
97
|
+
* takes the place of the one there (a grade's row of a run graded again). The ledger after (`all`) with the lines it
|
|
98
|
+
* appended. A line of a digest no version of its workflow holds (a run's purge took it since the line was read), or of a
|
|
99
|
+
* run that was purged, is never appended (Store.learning changeRecords refuses it): the others are. */
|
|
100
|
+
export async function addAuditLines(rows, agentId, lines, replace = false) {
|
|
101
|
+
let left = lines;
|
|
102
|
+
for (let tries = 0;; tries++) {
|
|
85
103
|
try {
|
|
86
|
-
|
|
87
|
-
if (!isLine(value))
|
|
88
|
-
continue;
|
|
89
|
-
const { run, workflow, digest, promoted_at, at } = value;
|
|
90
|
-
out.push(value.source === "started"
|
|
91
|
-
? { source: "started", run, shadow_run: value.shadow_run, workflow, digest, promoted_at, ...turnOf(value), at }
|
|
92
|
-
: { run, shadow_run: value.shadow_run, workflow, digest, promoted_at, source: value.source, agreed: value.agreed, served_cost: value.served_cost, shadow_cost: value.shadow_cost, ...turnOf(value), ...noVerdictOf(value), at });
|
|
104
|
+
return await appendLines(rows, agentId, left, replace);
|
|
93
105
|
}
|
|
94
|
-
catch {
|
|
95
|
-
// A
|
|
106
|
+
catch (error) {
|
|
107
|
+
// A purged run's line, refused in the write's own transaction: the write again without it.
|
|
108
|
+
if (!(error instanceof LearningRecordRefused) || tries >= 2)
|
|
109
|
+
throw error;
|
|
110
|
+
const refused = new Set(error.records.map((one) => one.runId));
|
|
111
|
+
const kept = left.filter((line) => !refused.has(line.run));
|
|
112
|
+
if (kept.length === left.length)
|
|
113
|
+
throw error;
|
|
114
|
+
left = kept;
|
|
96
115
|
}
|
|
97
116
|
}
|
|
98
|
-
return out;
|
|
99
|
-
}
|
|
100
|
-
/** The ledger's text for `lines`: from the AUDITS_KEPT-th newest row on, and every open started line before it. */
|
|
101
|
-
export function auditsText(lines) {
|
|
102
|
-
const rows = lines.flatMap((line, i) => (line.source === "started" ? [] : [i]));
|
|
103
|
-
const from = rows.length > AUDITS_KEPT ? rows[rows.length - AUDITS_KEPT] : 0;
|
|
104
|
-
const open = new Set(openAudits(lines));
|
|
105
|
-
return lines.filter((line, i) => i >= from || open.has(line)).map((line) => JSON.stringify(line)).join("\n") + "\n";
|
|
106
117
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
118
|
+
function appendLines(rows, agentId, lines, replace) {
|
|
119
|
+
return rows.changeRecords(agentId, "audit", (records, held) => {
|
|
120
|
+
const keys = new Set(lines.map(lineKey));
|
|
121
|
+
const kept = records.filter((one) => { const line = lineOf(one.data); return !replace || !line || !keys.has(lineKey(line)); });
|
|
122
|
+
const before = linesOf(kept);
|
|
123
|
+
const known = new Set(before.map(lineKey));
|
|
124
|
+
const added = [];
|
|
125
|
+
for (const line of lines) {
|
|
126
|
+
if (known.has(lineKey(line)))
|
|
127
|
+
continue;
|
|
128
|
+
if (held !== undefined && !held(line.workflow, line.digest))
|
|
129
|
+
continue;
|
|
130
|
+
known.add(lineKey(line));
|
|
131
|
+
added.push(line);
|
|
132
|
+
}
|
|
133
|
+
if (!added.length && kept.length === records.length)
|
|
134
|
+
return { result: { all: before, added } };
|
|
135
|
+
const writes = trimmed([...kept.map((one) => ({ seq: one.seq, runId: one.runId, workflow: one.workflow, digest: one.digest, data: one.data })), ...added.map(lineWrite)]);
|
|
136
|
+
return { records: writes, result: { all: linesOf(writes), added } };
|
|
137
|
+
});
|
|
111
138
|
}
|
|
112
|
-
/** The ledger's
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const added = [];
|
|
121
|
-
for (const line of lines) {
|
|
122
|
-
if (known.has(lineKey(line)))
|
|
123
|
-
continue;
|
|
124
|
-
known.add(lineKey(line));
|
|
125
|
-
added.push(line);
|
|
126
|
-
}
|
|
127
|
-
const rows = rowsOf(added).length;
|
|
128
|
-
const said = rows ? `${rows} audit row${rows === 1 ? "" : "s"}` : `${added.length} audit${added.length === 1 ? "" : "s"} started`;
|
|
129
|
-
return added.length ? { added, change: { by: { host: said }, writes: [{ path: AUDITS_FILE, text: auditsText([...before, ...added]) }] } } : { added };
|
|
139
|
+
/** The ledger's records from the AUDITS_KEPT-th newest row on, and every open started line before it (main's folder
|
|
140
|
+
* ledger kept the same): so it never grows past its cap. */
|
|
141
|
+
function trimmed(writes) {
|
|
142
|
+
const lines = writes.map((one) => lineOf(one.data));
|
|
143
|
+
const rows = lines.flatMap((line, i) => (line && line.source !== "started" ? [i] : []));
|
|
144
|
+
const from = rows.length > AUDITS_KEPT ? rows[rows.length - AUDITS_KEPT] : 0;
|
|
145
|
+
const open = new Set(openAudits(lines.filter((line) => line !== undefined)));
|
|
146
|
+
return writes.filter((_, i) => i >= from || (lines[i] !== undefined && open.has(lines[i])));
|
|
130
147
|
}
|
|
131
148
|
/** The rows the hold rule counts for `workflow` at `digest` under the promotion begun at `promotedAt` (learn/promote.ts
|
|
132
149
|
* promotionStartOf; none counted for null): those with a verdict, the newest `hold_window` of them. A served run an
|
|
@@ -148,14 +165,14 @@ export function auditLineOf(rows, workflow, digest, promotedAt, loop) {
|
|
|
148
165
|
const counted = windowOf(rows, workflow, digest, promotedAt, loop);
|
|
149
166
|
return { window: loop.hold_window, disagree: loop.hold_disagree, rows: counted.length, disagreed: counted.filter((row) => row.agreed === false).length };
|
|
150
167
|
}
|
|
151
|
-
export function servingLinesOf(records, rows, loop, costStop
|
|
152
|
-
return servingOf(records
|
|
168
|
+
export function servingLinesOf(records, rows, loop, costStop) {
|
|
169
|
+
return servingOf(records).map(({ workflow, digest }) => {
|
|
153
170
|
const own = records.filter((one) => one.workflow === workflow);
|
|
154
171
|
const newest = own.at(-1);
|
|
155
172
|
const checked = own.findLast((one) => one.check?.n !== undefined)?.check;
|
|
156
173
|
const at = digest ?? newest?.digest;
|
|
157
174
|
return {
|
|
158
|
-
state: servingStateOf(records, workflow, costStop
|
|
175
|
+
state: servingStateOf(records, workflow, costStop),
|
|
159
176
|
check: checked ? { n: checked.n, agreed: checked.agreed ?? 0, alone: checked.alone ?? 0, attempt: checked.attempt } : null,
|
|
160
177
|
audit: at === undefined ? null : auditLineOf(rows, workflow, at, promotionStartOf(records, workflow, at)?.at ?? null, loop),
|
|
161
178
|
};
|
package/dist/learn/check.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The checker of a workflow draft a run's compile turn gives its agent's learning
|
|
1
|
+
// The checker of a workflow draft a run's compile turn gives its agent's learning (SPEC.md): its workflow.json and
|
|
2
2
|
// README.md, each a change against what the folder holds. Structure only, and what must never be stored; nothing the
|
|
3
3
|
// checker refuses is ever written to git. Every problem it reports is printable: its path and detail are cut of the
|
|
4
4
|
// host's secrets and of text shaped like one, and a field over PRINT_MAX is redacted whole.
|
package/dist/learn/commit.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { type Workspace } from "../workspace/index.js";
|
|
2
1
|
import type { Problem } from "./check.js";
|
|
3
|
-
import { type
|
|
2
|
+
import { type AgentLearning, type LearningRead } from "./rows.js";
|
|
4
3
|
/** A run's merge, one a round: its compiled draft's files, already checked, and its owner's correction. */
|
|
5
4
|
export type LearningChange = {
|
|
6
|
-
/** The run that learned
|
|
5
|
+
/** The run that learned, and with `round` its merge key (runDiffKey). */
|
|
7
6
|
runId: string;
|
|
8
7
|
/** Which of the run's merges this is (absent: its first): a follow-up's later round merges once of its own. */
|
|
9
8
|
round?: number;
|
|
10
|
-
/** Why: the
|
|
9
|
+
/** Why: the log's `reason`. */
|
|
11
10
|
reason: string;
|
|
12
11
|
/** What merges: a draft's files, each whole. */
|
|
13
12
|
files: {
|
|
@@ -20,16 +19,15 @@ export type LearningChange = {
|
|
|
20
19
|
refuseValues?: readonly string[];
|
|
21
20
|
/** Paths written with `status: pending` (waiting for the owner's OK): a draft's README.md. */
|
|
22
21
|
held?: string[];
|
|
23
|
-
/** The
|
|
24
|
-
* another run's merge changed it) is a conflict.
|
|
22
|
+
/** The save the run started from: a file that is not at the newest version as it was at it (a person retired or
|
|
23
|
+
* approved it, another run's merge changed it) is a conflict. */
|
|
25
24
|
seed?: string;
|
|
26
|
-
/** A
|
|
27
|
-
* the run's seed, when
|
|
28
|
-
* learning since removed it, so the whole merge is a conflict that says so.
|
|
29
|
-
* another folder than this one (a Mode 2 run's end writes the folder on its disk). */
|
|
25
|
+
/** A save the agent's learning must still hold for the merge to land, its correction alone included (which no `same`
|
|
26
|
+
* covers): the run's seed, when it was held as the run's end began (runner/learning-end.ts). A reset of the agent's
|
|
27
|
+
* learning since removed it, so the whole merge is a conflict that says so. */
|
|
30
28
|
mustHold?: string;
|
|
31
|
-
/** A file checked against another
|
|
32
|
-
*
|
|
29
|
+
/** A file checked against another save than `seed`, by its path: a workflow the run's compile turn revised from the
|
|
30
|
+
* newest text, against the save it read that text at. */
|
|
33
31
|
bases?: Readonly<Record<string, string>>;
|
|
34
32
|
};
|
|
35
33
|
export type LearningCommitResult =
|
|
@@ -50,52 +48,60 @@ export type LearningCommitResult =
|
|
|
50
48
|
ok: false;
|
|
51
49
|
reason: "refused";
|
|
52
50
|
problems: Problem[];
|
|
51
|
+
}
|
|
52
|
+
/** A run's purge came after the save the run's merge was read at (its seed): that purge rewrote what the run started
|
|
53
|
+
* from, so its draft can't be told apart from the purged run's bytes, and nothing of it is written. */
|
|
54
|
+
| {
|
|
55
|
+
ok: false;
|
|
56
|
+
reason: "purged";
|
|
57
|
+
problems: Problem[];
|
|
53
58
|
} | {
|
|
54
59
|
ok: false;
|
|
55
60
|
reason: "unavailable";
|
|
56
61
|
error: string;
|
|
57
62
|
};
|
|
58
63
|
/**
|
|
59
|
-
* A run's merge on the
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* draft
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
64
|
+
* A run's merge on the agent's learning, one save: its files (a held README with `status: pending`) and its owner's
|
|
65
|
+
* correction appended to corrections.md. `ok` with the new version and the paths it changed; `conflict` when a file is
|
|
66
|
+
* not at the newest version as it was at the run's seed; `purged` when the merge gives files and a run's purge came after
|
|
67
|
+
* its seed (or a revised workflow's base), nothing written; `refused` when the correction holds what must never be stored,
|
|
68
|
+
* or, with no draft beside it, would take corrections.md past its cap (nothing written); `unavailable` when the store
|
|
69
|
+
* failed. The draft and the correction are judged apart: a correction past the cap beside a draft (the file filled by
|
|
70
|
+
* another write after the run's check, correctionRefused) is left out alone, and the draft merges, `ok` with the cap's
|
|
71
|
+
* refusal as `refusedCorrection`. A merge whose run already merged (this round) is `ok` with the save that holds it, and
|
|
72
|
+
* writes nothing: its merge key is taken once, in the save's own transaction, so two calls racing for one round (a
|
|
73
|
+
* reclaimed run) merge it once.
|
|
68
74
|
*/
|
|
69
|
-
export declare function learningCommit(
|
|
75
|
+
export declare function learningCommit(learning: AgentLearning, change: LearningChange, opts?: {
|
|
70
76
|
retries?: number;
|
|
71
77
|
}): Promise<LearningCommitResult>;
|
|
72
78
|
/** Why run `runId`'s correction (`text`) would be refused on main as it is now: its line's own problems, else the cap's;
|
|
73
79
|
* empty when it would be taken. Read before the run's merge, so a refused correction never holds its draft back. A
|
|
74
80
|
* round (`merge`) whose merge is on main already (a stop after its commit, before the run's end was saved) is never
|
|
75
81
|
* checked for room again, its own line counted twice: empty, and its merge (learningCommit) gives back what it did. */
|
|
76
|
-
export declare function correctionRefused(
|
|
82
|
+
export declare function correctionRefused(learning: AgentLearning, text: string, refuseValues?: readonly string[], merge?: {
|
|
77
83
|
runId: string;
|
|
78
84
|
round?: number;
|
|
79
85
|
}): Promise<Problem[]>;
|
|
80
86
|
/** One line of an owner's feedback appended to corrections.md on main, by run `runId`'s merge (learningCommit's
|
|
81
87
|
* `correction`, with no draft beside it). */
|
|
82
|
-
export declare const appendCorrection: (
|
|
88
|
+
export declare const appendCorrection: (learning: AgentLearning, input: {
|
|
83
89
|
runId: string;
|
|
84
90
|
round?: number;
|
|
85
91
|
text: string;
|
|
86
92
|
refuseValues?: readonly string[];
|
|
87
93
|
}) => Promise<LearningCommitResult>;
|
|
88
|
-
/** corrections.md as a person reads it: its text and its ETag's blob (an empty file's when
|
|
89
|
-
export declare function readCorrections(
|
|
94
|
+
/** corrections.md as a person reads it: its text and its ETag's blob (an empty file's when it holds none). */
|
|
95
|
+
export declare function readCorrections(read: LearningRead): {
|
|
90
96
|
text: string;
|
|
91
97
|
oid: string;
|
|
92
|
-
}
|
|
98
|
+
};
|
|
93
99
|
/**
|
|
94
100
|
* corrections.md replaced whole by a person: `ifMatch`, the blob they read (an ETag, quoted or not; an empty file's when
|
|
95
|
-
*
|
|
101
|
+
* the agent held none), must be the newest's now, else a conflict. Refused, nothing written, as appendCorrection refuses. `ok` with
|
|
96
102
|
* the new text and its blob.
|
|
97
103
|
*/
|
|
98
|
-
export declare function putCorrections(
|
|
104
|
+
export declare function putCorrections(learning: AgentLearning, input: {
|
|
99
105
|
text: string;
|
|
100
106
|
ifMatch: string;
|
|
101
107
|
refuseValues?: readonly string[];
|
|
@@ -108,17 +114,3 @@ export declare function putCorrections(ws: Workspace, input: {
|
|
|
108
114
|
reason: "conflict" | "refused";
|
|
109
115
|
problems: Problem[];
|
|
110
116
|
}>;
|
|
111
|
-
/**
|
|
112
|
-
* Run `runId`'s text taken off the folder's current files, at its purge (agent-delete.ts purgeRun): first its learned
|
|
113
|
-
* workflows (forgetRunWorkflows; `purged`: whether another run is purged), whether or not it left a diff file; then the
|
|
114
|
-
* lines each of its merges added to corrections.md, as its diff file keeps them, dropped from main in one host commit
|
|
115
|
-
* per merge (a line a person edited since is theirs and stays); each other merge's diff that shows such a line as
|
|
116
|
-
* context written without it; then the run's diff files deleted, last, so a call stopped part way finds what it has
|
|
117
|
-
* left to do. Its merges stay in the folder's git history until a learning reset or its agent's purge deletes the
|
|
118
|
-
* folder. Idempotent: each merge's scrub lands once, nothing left to drop makes no commit, and a run with no diff file
|
|
119
|
-
* and no workflow here is no work.
|
|
120
|
-
* `commit`: the host's last commit, when one was made.
|
|
121
|
-
*/
|
|
122
|
-
export declare function forgetRunText(ws: Workspace, runId: string, purged: (run: string) => Promise<boolean>): Promise<{
|
|
123
|
-
commit?: string;
|
|
124
|
-
}>;
|