@parcha/agentrun-serve 0.1.0-beta.48 → 0.1.0-beta.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/README.md +236 -26
- package/dist/agent-delete.d.ts +36 -12
- package/dist/agent-delete.js +213 -30
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +18 -5
- package/dist/agents.d.ts +8 -1
- package/dist/agents.js +14 -4
- package/dist/answer-json.d.ts +2 -2
- package/dist/answer-json.js +3 -4
- package/dist/api-only.d.ts +7 -10
- package/dist/api-only.js +9 -11
- package/dist/archil-routes.d.ts +1 -1
- package/dist/archil-routes.js +4 -3
- package/dist/browser-sessions.d.ts +56 -0
- package/dist/browser-sessions.js +117 -0
- package/dist/compute-cost.d.ts +101 -0
- package/dist/compute-cost.js +250 -0
- package/dist/computer-routes.d.ts +4 -15
- package/dist/computer-routes.js +6 -10
- package/dist/console/assets/index-D0mr9wfZ.css +1 -0
- package/dist/console/assets/index-D7G6o-1E.js +720 -0
- package/dist/console/index.html +2 -2
- package/dist/errors.d.ts +4 -1
- package/dist/errors.js +15 -5
- package/dist/eval-previous.d.ts +52 -0
- package/dist/eval-previous.js +164 -0
- package/dist/file-types.d.ts +2 -0
- package/dist/file-types.js +3 -1
- package/dist/harness.js +2 -1
- package/dist/import.js +4 -3
- package/dist/learn/check.d.ts +16 -4
- package/dist/learn/check.js +30 -26
- package/dist/learn/promote.d.ts +7 -1
- package/dist/learn/promote.js +47 -0
- package/dist/learn/repick.d.ts +43 -0
- package/dist/learn/repick.js +202 -0
- package/dist/learn/workflow-draft.d.ts +4 -0
- package/dist/learn/workflow-draft.js +10 -7
- package/dist/learned-workflow.d.ts +2 -0
- package/dist/learned-workflow.js +19 -2
- package/dist/learning-setting.d.ts +13 -0
- package/dist/learning-setting.js +23 -1
- package/dist/llms.txt +1 -1
- package/dist/openapi.js +180 -14
- package/dist/paid-calls.d.ts +17 -7
- package/dist/paid-calls.js +15 -9
- package/dist/run-launch.d.ts +2 -2
- package/dist/run-launch.js +2 -1
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-usage.d.ts +125 -0
- package/dist/run-usage.js +394 -0
- package/dist/runner/adapter-loop.d.ts +4 -0
- package/dist/runner/adapter-loop.js +66 -21
- package/dist/runner/adapter-run-spec.d.ts +8 -3
- package/dist/runner/adapter-run-spec.js +13 -6
- package/dist/runner/big-writes.d.ts +33 -0
- package/dist/runner/big-writes.js +105 -0
- package/dist/runner/cli-run-spec.js +14 -6
- package/dist/runner/conformance/harness.d.ts +2 -0
- package/dist/runner/conformance/harness.js +18 -4
- package/dist/runner/feedback-round.d.ts +29 -1
- package/dist/runner/feedback-round.js +54 -3
- package/dist/runner/held.d.ts +4 -1
- package/dist/runner/journal-kinds.d.ts +3 -1
- package/dist/runner/learning-end.js +54 -18
- package/dist/runner/loop-contract.d.ts +3 -0
- package/dist/runner/metrics.d.ts +4 -0
- package/dist/runner/metrics.js +9 -0
- package/dist/runner/monid-run.js +2 -2
- package/dist/runner/promotion.js +8 -2
- package/dist/runner/reflect-hook.js +3 -2
- package/dist/runner/run-child-host.d.ts +15 -2
- package/dist/runner/run-child-host.js +24 -8
- package/dist/runner/run-child.js +3 -0
- package/dist/runner/save-slots.d.ts +9 -0
- package/dist/runner/save-slots.js +91 -0
- package/dist/runs-over-store.d.ts +3 -2
- package/dist/runs-over-store.js +9 -7
- package/dist/sdk/runs.d.ts +3 -4
- package/dist/sdk/runs.js +10 -7
- package/dist/sdk/runtimes.d.ts +19 -0
- package/dist/sdk/runtimes.js +23 -0
- package/dist/sdk/schema.d.ts +14 -8
- package/dist/sdk/schema.js +18 -6
- package/dist/server.d.ts +7 -3
- package/dist/server.js +223 -100
- package/dist/store/agent-body.d.ts +2 -3
- package/dist/store/agent-body.js +3 -2
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.js +1 -1
- package/dist/store/open.d.ts +1 -1
- package/dist/store/open.js +1 -1
- package/dist/store/postgres/migrations/0021_purged.sql +13 -0
- package/dist/store/postgres/migrations/0022_computer_intervals.sql +27 -0
- package/dist/store/postgres/migrations/0023_computer_interval_resources.sql +14 -0
- package/dist/store/schema.d.ts +20 -1
- package/dist/store/schema.js +60 -5
- package/dist/store/sqlite/connection.d.ts +4 -1
- package/dist/store/sqlite/connection.js +5 -0
- package/dist/store/sqlite/run-patch.d.ts +8 -3
- package/dist/store/sqlite/run-patch.js +15 -7
- package/dist/store/sqlite/store.d.ts +2 -1
- package/dist/store/sqlite/store.js +279 -68
- package/dist/store/sqlite/worker.d.ts +9 -0
- package/dist/store/sqlite/worker.js +18 -1
- package/dist/store/store.d.ts +149 -9
- package/dist/store/store.js +63 -0
- package/dist/store-reads/analytics.js +2 -1
- package/dist/store-reads/cap.d.ts +17 -7
- package/dist/store-reads/cap.js +54 -4
- package/dist/store-reads/decisions.d.ts +21 -0
- package/dist/store-reads/decisions.js +22 -0
- package/dist/store-reads/journal.d.ts +8 -2
- package/dist/store-reads/journal.js +27 -8
- package/dist/store-reads/learning.d.ts +1 -1
- package/dist/store-reads/learning.js +5 -2
- package/dist/store-reads/runs.js +2 -0
- package/dist/store-reads/stats.js +4 -2
- package/dist/store-view.d.ts +12 -1
- package/dist/store-view.js +98 -38
- package/dist/template-eval.d.ts +15 -1
- package/dist/template-eval.js +92 -13
- package/dist/templates.d.ts +1 -1
- package/dist/templates.js +4 -3
- package/dist/timeline/labels.js +17 -0
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +6 -2
- package/dist/tools.js +22 -1
- package/dist/trigger-targets.d.ts +28 -9
- package/dist/trigger-targets.js +19 -16
- package/dist/triggers.d.ts +2 -1
- package/dist/triggers.js +5 -2
- package/dist/validate.d.ts +4 -2
- package/dist/validate.js +13 -3
- package/dist/viewer-credential.d.ts +3 -4
- package/dist/viewer-credential.js +6 -4
- package/dist/web-fake.d.ts +25 -0
- package/dist/web-fake.js +38 -1
- package/dist/web-save.d.ts +75 -0
- package/dist/web-save.js +235 -0
- package/dist/workspace/archil-claim.d.ts +5 -2
- package/dist/workspace/archil-claim.js +5 -2
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +19 -1
- package/dist/workspace/archil.d.ts +3 -0
- package/dist/workspace/archil.js +101 -16
- package/dist/workspace/computer-for-claim.d.ts +19 -1
- package/dist/workspace/computer-for-claim.js +88 -20
- package/dist/workspace/computer-intervals.d.ts +26 -0
- package/dist/workspace/computer-intervals.js +58 -0
- package/dist/workspace/computer-janitor.d.ts +7 -3
- package/dist/workspace/computer-janitor.js +14 -6
- package/dist/workspace/computer-kept.d.ts +7 -2
- package/dist/workspace/computer-kept.js +9 -2
- package/dist/workspace/pieced.d.ts +14 -0
- package/dist/workspace/pieced.js +23 -0
- package/dist/workspace/resolve-computer.d.ts +7 -4
- package/dist/workspace/resolve-computer.js +21 -32
- package/dist/workspace/run-disk.js +32 -12
- package/dist/workspace/run-end-computers.d.ts +1 -0
- package/dist/workspace/run-end-computers.js +4 -1
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +11 -6
- package/package.json +10 -10
- package/templates/README.md +36 -7
- package/dist/console/assets/index-CTGegcKt.css +0 -1
- package/dist/console/assets/index-D1Se6mgG.js +0 -715
package/dist/console/index.html
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
<meta name="color-scheme" content="light dark" />
|
|
7
7
|
<title>AgentRun</title>
|
|
8
8
|
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' fill='%23ff8000'/%3E%3Cpath d='M12 9l11 7-11 7z' fill='%23000'/%3E%3C/svg%3E" />
|
|
9
|
-
<script type="module" crossorigin src="./assets/index-
|
|
10
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
9
|
+
<script type="module" crossorigin src="./assets/index-D7G6o-1E.js"></script>
|
|
10
|
+
<link rel="stylesheet" crossorigin href="./assets/index-D0mr9wfZ.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
|
13
13
|
<div id="root"></div>
|
package/dist/errors.d.ts
CHANGED
|
@@ -54,9 +54,12 @@ export declare const ERROR_STATUS: {
|
|
|
54
54
|
readonly composio_in_use: 409;
|
|
55
55
|
readonly external_body_conflict: 409;
|
|
56
56
|
readonly replay_conflict: 409;
|
|
57
|
-
readonly agent_not_external: 409;
|
|
58
57
|
readonly runs_in_flight: 409;
|
|
59
58
|
readonly learning_busy: 409;
|
|
59
|
+
readonly agent_not_archived: 409;
|
|
60
|
+
readonly run_not_final: 409;
|
|
61
|
+
readonly run_learning: 409;
|
|
62
|
+
readonly purged: 410;
|
|
60
63
|
readonly model_key_required: 422;
|
|
61
64
|
readonly runner_refused: 503;
|
|
62
65
|
};
|
package/dist/errors.js
CHANGED
|
@@ -73,12 +73,22 @@ export const ERROR_STATUS = {
|
|
|
73
73
|
// A replay its owner asked of a learned workflow's revision that cannot start now (runner/promotion.ts askReplay): one
|
|
74
74
|
// replays already, another revision of it replays, it is promoted, or no graded input fits it.
|
|
75
75
|
replay_conflict: 409,
|
|
76
|
-
// DELETE /agents/{id} (agent-delete.ts):
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
|
|
76
|
+
// DELETE /agents/{id} (agent-delete.ts): another system's agent whose runs did not end by the delete's wait (or one only
|
|
77
|
+
// its application ends, an SDK run's); an agent whose learning refused its delete while learning work was in flight.
|
|
78
|
+
// Both leave the agent refusing runs, and a DELETE sent again finishes it. An agent made here that is not archived:
|
|
79
|
+
// archive it first, then purge it.
|
|
80
80
|
runs_in_flight: 409,
|
|
81
81
|
learning_busy: 409,
|
|
82
|
+
agent_not_archived: 409,
|
|
83
|
+
// DELETE /runs/{id} and /agents/{id} (agent-delete.ts purgeRun): a run, or a run made from it, that is live (not final,
|
|
84
|
+
// or held by a runner). Nothing is purged.
|
|
85
|
+
run_not_final: 409,
|
|
86
|
+
// PUT /runs/{id}/grade on a run that reads ended while it still learns from that end (its look-back: a fresh run's
|
|
87
|
+
// end-of-run step, or a grade's round): graded once that ends. The same grade sent then is taken.
|
|
88
|
+
run_learning: 409,
|
|
89
|
+
// A run or an agent that was purged (DELETE /runs/{id}, /agents/{id}): every route of it reads its tombstone in the
|
|
90
|
+
// error's details, and its DELETE answers 204 again.
|
|
91
|
+
purged: 410,
|
|
82
92
|
// A run start, or a message that would start a turn, with no model_key where the server holds no key for the run's
|
|
83
93
|
// model (run-model-key.ts): nothing to spend, so refused before any model call.
|
|
84
94
|
model_key_required: 422,
|
|
@@ -87,7 +97,7 @@ export const ERROR_STATUS = {
|
|
|
87
97
|
// is started again as the words say.
|
|
88
98
|
runner_refused: 503,
|
|
89
99
|
};
|
|
90
|
-
const RETRYABLE = new Set(["home_busy", "idempotency_in_progress", "rate_limited", "internal", "unavailable", "github_failed", "runs_in_flight", "learning_busy"]);
|
|
100
|
+
const RETRYABLE = new Set(["home_busy", "idempotency_in_progress", "rate_limited", "internal", "unavailable", "github_failed", "runs_in_flight", "learning_busy", "run_learning"]);
|
|
91
101
|
export class ApiError extends Error {
|
|
92
102
|
code;
|
|
93
103
|
status;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Store } from "./store/index.js";
|
|
2
|
+
import { type CompletedOutput, type PreviousHandover } from "./trigger-targets.js";
|
|
3
|
+
import { type Json } from "./validate.js";
|
|
4
|
+
/** One earlier completed run of the trigger: its result.output, and the output schema it was checked against when that
|
|
5
|
+
* is not the package's (`outputSchema`, the fixture's output_schema). */
|
|
6
|
+
export type PreviousResult = {
|
|
7
|
+
output: Json;
|
|
8
|
+
outputSchema?: Json;
|
|
9
|
+
};
|
|
10
|
+
/** A previous case's fixture: the trigger's earlier completed results, oldest first (the last is the one its next run is
|
|
11
|
+
* handed), and the package's schedule trigger that starts the run (filled in by the caller when the fixture names none). */
|
|
12
|
+
export type PreviousFixture = {
|
|
13
|
+
description?: string;
|
|
14
|
+
results: PreviousResult[];
|
|
15
|
+
trigger: string;
|
|
16
|
+
};
|
|
17
|
+
/** `value` read as a previous fixture, each problem through `bad` in words naming `at`; undefined when one does not read.
|
|
18
|
+
* Each output is checked against its own output_schema, else `packageSchema` (the package's output schema), as the
|
|
19
|
+
* server checks a run's answer: a result whose run would have no result.output is refused here, before any run. */
|
|
20
|
+
export declare function previousFixtureOf(value: unknown, at: string, packageSchema: unknown, bad: (message: string) => void): (Omit<PreviousFixture, "trigger"> & {
|
|
21
|
+
trigger?: string;
|
|
22
|
+
}) | undefined;
|
|
23
|
+
/** A result seeded: its run's id, and the fields the output schema of its run's revision names in x-carried (the ones the
|
|
24
|
+
* server reads back for it, TriggerTargetDeps.completedOutput), absent when it names none. */
|
|
25
|
+
export type Seeded = {
|
|
26
|
+
runId: string;
|
|
27
|
+
carried?: readonly string[];
|
|
28
|
+
};
|
|
29
|
+
/** `fixture`'s results seeded in `store` as completed runs of `agentId`, oldest first, each a firing of `triggerId` that
|
|
30
|
+
* started it, ended a day apart before `before` (the clock the case's run fires on): each run's input is `content` (the
|
|
31
|
+
* trigger's), its answer its output as one fenced json block. A result with its own output schema is a run of a revision
|
|
32
|
+
* of its own, the agent's current body with that schema, made and then left behind, so the agent's current revision is
|
|
33
|
+
* the one the case's run starts on. */
|
|
34
|
+
export declare function seedPrevious(store: Store, fixture: PreviousFixture, { agentId, triggerId, content, before }: {
|
|
35
|
+
agentId: string;
|
|
36
|
+
triggerId: string;
|
|
37
|
+
content: string;
|
|
38
|
+
before: number;
|
|
39
|
+
}): Promise<Seeded[]>;
|
|
40
|
+
/** The kinds a `handed` grader expects, PreviousHandover's. */
|
|
41
|
+
export declare const HANDED_KINDS: readonly ["whole", "carried", "too_large", "none"];
|
|
42
|
+
/** What the run whose input content is `content` was handed of its trigger's last result, the last one seeded (`last`),
|
|
43
|
+
* `done` as the server reads it back (its result.output and end as GET /runs/{id} serves them): the handover the trigger
|
|
44
|
+
* makes of it (previousHandover), when the run's input ends with that handover's words; else none. */
|
|
45
|
+
export declare function handedPrevious(content: string, last: Seeded, done: Omit<CompletedOutput, "carried">): PreviousHandover;
|
|
46
|
+
/** A `handed` grader's verdict: the run was handed its previous result as `expect` says (and, for carried fields, each
|
|
47
|
+
* array in `dropped` gave up exactly that many first entries, 0 for none). A field the grader counts that is no carried
|
|
48
|
+
* array the run was handed (a misspelled name, a scalar) fails it by name: never read as 0 dropped. */
|
|
49
|
+
export declare function handedVerdict(handed: PreviousHandover | undefined, expect: PreviousHandover["kind"], dropped?: Readonly<Record<string, number>>): {
|
|
50
|
+
pass: boolean;
|
|
51
|
+
reason: string;
|
|
52
|
+
};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// A template eval case's previous runs (template-eval.ts `previous:`): its fixture, checked when the case is read, and its
|
|
2
|
+
// results seeded in the eval's own server's store as completed runs of the run's agent, each a firing of the package's
|
|
3
|
+
// schedule trigger, before that trigger fires the case's run. So the run is handed what previousResultOf hands a
|
|
4
|
+
// scheduled run (trigger-targets.ts) from the server's own reads: the last result's result.output whole up to
|
|
5
|
+
// PREVIOUS_RESULT_MAX_BYTES, else the fields its run's output schema names in x-carried, trimmed to fit, else nothing,
|
|
6
|
+
// said so. Each result is written as the store writes an ended run it did not run (Store.importRun, its transcript as
|
|
7
|
+
// import.ts transcriptOf lays one out): its answer the output as one fenced json block, on the agent's current revision,
|
|
8
|
+
// or on a revision of its own whose output schema is the result's `output_schema` (the trim reads the producing run's
|
|
9
|
+
// schema), the agent's current one left as it was. What the run was handed is the server's own handover of the last result
|
|
10
|
+
// (trigger-targets.ts previousHandover), when its input carries that handover's words (handedPrevious), for its graders
|
|
11
|
+
// and its report.
|
|
12
|
+
import { carriedFields, carriedProblem, schemaCheck } from "./answer-json.js";
|
|
13
|
+
import { transcriptOf } from "./import.js";
|
|
14
|
+
import { launchBody } from "./run-launch.js";
|
|
15
|
+
import { uuidv7 } from "./runs-over-store.js";
|
|
16
|
+
import { previousHandover } from "./trigger-targets.js";
|
|
17
|
+
import { isObject } from "./validate.js";
|
|
18
|
+
const FIXTURE_FIELDS = ["description", "results", "trigger"];
|
|
19
|
+
const RESULT_FIELDS = ["output", "output_schema"];
|
|
20
|
+
/** `value` read as a previous fixture, each problem through `bad` in words naming `at`; undefined when one does not read.
|
|
21
|
+
* Each output is checked against its own output_schema, else `packageSchema` (the package's output schema), as the
|
|
22
|
+
* server checks a run's answer: a result whose run would have no result.output is refused here, before any run. */
|
|
23
|
+
export function previousFixtureOf(value, at, packageSchema, bad) {
|
|
24
|
+
if (!isObject(value))
|
|
25
|
+
return bad(`${at}: a previous fixture is {description?, results: [{output, output_schema?}, ...], trigger?}`), undefined;
|
|
26
|
+
let ok = true;
|
|
27
|
+
const no = (message) => ((ok = false), bad(`${at}: ${message}`));
|
|
28
|
+
for (const key of Object.keys(value).filter((key) => !FIXTURE_FIELDS.includes(key)))
|
|
29
|
+
no(`no field ${key}: its fields are ${FIXTURE_FIELDS.join(", ")}`);
|
|
30
|
+
if (value.description !== undefined && typeof value.description !== "string")
|
|
31
|
+
no("description is text");
|
|
32
|
+
if (value.trigger !== undefined && (typeof value.trigger !== "string" || !value.trigger))
|
|
33
|
+
no("trigger is the name of the package's schedule trigger that starts the run");
|
|
34
|
+
const results = [];
|
|
35
|
+
if (!Array.isArray(value.results) || !value.results.length)
|
|
36
|
+
no("results is the trigger's earlier completed runs, oldest first, at least one: each {output, output_schema?}");
|
|
37
|
+
else {
|
|
38
|
+
for (const [i, result] of value.results.entries()) {
|
|
39
|
+
const where = `results[${i}]`;
|
|
40
|
+
if (!isObject(result)) {
|
|
41
|
+
no(`${where} is {output, output_schema?}`);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
for (const key of Object.keys(result).filter((key) => !RESULT_FIELDS.includes(key)))
|
|
45
|
+
no(`${where} has no field ${key}: its fields are ${RESULT_FIELDS.join(", ")}`);
|
|
46
|
+
if (!isObject(result.output))
|
|
47
|
+
no(`${where}.output is the run's result.output, a JSON object`);
|
|
48
|
+
const own = result.output_schema;
|
|
49
|
+
if (own !== undefined) {
|
|
50
|
+
const compiled = schemaCheck(own);
|
|
51
|
+
if ("why" in compiled) {
|
|
52
|
+
no(`${where}.output_schema ${compiled.why}`);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const carried = carriedProblem(own);
|
|
56
|
+
if (carried) {
|
|
57
|
+
no(`${where}.output_schema's x-carried ${carried}`);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const schema = own ?? packageSchema;
|
|
62
|
+
if (schema === undefined) {
|
|
63
|
+
no(`${where} has no output schema it was checked against: give it output_schema, or the package an output (a run's result.output is its answer as an output schema checks it)`);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const compiled = schemaCheck(schema);
|
|
67
|
+
if (!isObject(result.output) || "why" in compiled)
|
|
68
|
+
continue;
|
|
69
|
+
const problems = compiled.check(result.output);
|
|
70
|
+
if (problems.length)
|
|
71
|
+
no(`${where}.output does not meet ${own === undefined ? "the package's output schema" : "its output_schema"}: ${problems.slice(0, 3).join("; ")}`);
|
|
72
|
+
else
|
|
73
|
+
results.push({ output: result.output, ...(own !== undefined ? { outputSchema: own } : {}) });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (!ok)
|
|
77
|
+
return undefined;
|
|
78
|
+
return { ...(typeof value.description === "string" ? { description: value.description } : {}), results, ...(typeof value.trigger === "string" ? { trigger: value.trigger } : {}) };
|
|
79
|
+
}
|
|
80
|
+
/** How far apart the seeded results ended, the last that far before the case's run. */
|
|
81
|
+
const SEEDED_APART_MS = 24 * 60 * 60_000;
|
|
82
|
+
/** `fixture`'s results seeded in `store` as completed runs of `agentId`, oldest first, each a firing of `triggerId` that
|
|
83
|
+
* started it, ended a day apart before `before` (the clock the case's run fires on): each run's input is `content` (the
|
|
84
|
+
* trigger's), its answer its output as one fenced json block. A result with its own output schema is a run of a revision
|
|
85
|
+
* of its own, the agent's current body with that schema, made and then left behind, so the agent's current revision is
|
|
86
|
+
* the one the case's run starts on. */
|
|
87
|
+
export async function seedPrevious(store, fixture, { agentId, triggerId, content, before }) {
|
|
88
|
+
const current = (await store.agents.get(agentId))?.currentRevision;
|
|
89
|
+
const revision = current ? await store.agents.revision(current) : undefined;
|
|
90
|
+
if (!current || !revision)
|
|
91
|
+
throw new Error(`the agent ${agentId} has no current revision to seed its previous runs on`);
|
|
92
|
+
const seeded = [];
|
|
93
|
+
for (const [i, result] of fixture.results.entries()) {
|
|
94
|
+
const endedAt = before - (fixture.results.length - i) * SEEDED_APART_MS;
|
|
95
|
+
const startedAt = endedAt - 60_000;
|
|
96
|
+
let revisionId = current;
|
|
97
|
+
if (result.outputSchema !== undefined) {
|
|
98
|
+
revisionId = uuidv7();
|
|
99
|
+
await store.agents.addRevision({
|
|
100
|
+
id: revisionId, agentId, kind: revision.kind, body: { ...revision.body, outputSchema: result.outputSchema },
|
|
101
|
+
...(revision.skills !== null ? { skills: revision.skills } : {}), ...(revision.mcpPin !== null ? { mcpPin: revision.mcpPin } : {}), ...(revision.monidPin !== null ? { monidPin: revision.monidPin } : {}),
|
|
102
|
+
note: "A template eval's previous run, on its own output schema.", ifCurrent: current,
|
|
103
|
+
});
|
|
104
|
+
await store.agents.setCurrent(agentId, current);
|
|
105
|
+
}
|
|
106
|
+
// Run ids sort by their start: each seeded one is older than the next, and than the case's run.
|
|
107
|
+
const runId = uuidv7(startedAt);
|
|
108
|
+
const key = `template-eval-previous-${i + 1}`;
|
|
109
|
+
const answer = `\`\`\`json\n${JSON.stringify(result.output, null, 2)}\n\`\`\``;
|
|
110
|
+
const session = { turns: [{ role: "user", text: content, at: startedAt }, { role: "assistant", text: answer, calls: [], at: endedAt }] };
|
|
111
|
+
await store.importRun({
|
|
112
|
+
id: runId, agentId, revisionId, importedFrom: { source: "pi", session: key + "-" + runId },
|
|
113
|
+
launch: { body: launchBody({ input: { content }, title: `Previous run ${i + 1} of the case`, place: { mode: "runner" }, trigger: { id: triggerId, firing_key: key } }) },
|
|
114
|
+
state: "ended", costUsd: 0, startedAt, endedAt, transcript: transcriptOf(session, (value) => value).batches,
|
|
115
|
+
});
|
|
116
|
+
// The firing that started it, as the trigger's history keeps one: recorded settled (no engine drives it), then started
|
|
117
|
+
// with its run, which moves the trigger's last run to it.
|
|
118
|
+
await store.triggers.record(triggerId, [{ key, by: "schedule", nominalAt: Math.floor(startedAt / 1000) * 1000, status: "skipped" }]);
|
|
119
|
+
await store.triggers.settle(triggerId, key, { status: "started", runId }, { reset: true });
|
|
120
|
+
const carried = carriedFields(result.outputSchema ?? revision.body.outputSchema);
|
|
121
|
+
seeded.push({ runId, ...(carried ? { carried } : {}) });
|
|
122
|
+
}
|
|
123
|
+
return seeded;
|
|
124
|
+
}
|
|
125
|
+
/** The kinds a `handed` grader expects, PreviousHandover's. */
|
|
126
|
+
export const HANDED_KINDS = ["whole", "carried", "too_large", "none"];
|
|
127
|
+
/** What the run whose input content is `content` was handed of its trigger's last result, the last one seeded (`last`),
|
|
128
|
+
* `done` as the server reads it back (its result.output and end as GET /runs/{id} serves them): the handover the trigger
|
|
129
|
+
* makes of it (previousHandover), when the run's input ends with that handover's words; else none. */
|
|
130
|
+
export function handedPrevious(content, last, done) {
|
|
131
|
+
const handover = previousHandover(last.runId, { ...done, ...(last.carried ? { carried: last.carried } : {}) });
|
|
132
|
+
return handover.text && content.endsWith(handover.text) ? handover : { kind: "none", text: "" };
|
|
133
|
+
}
|
|
134
|
+
/** A `handed` grader's verdict: the run was handed its previous result as `expect` says (and, for carried fields, each
|
|
135
|
+
* array in `dropped` gave up exactly that many first entries, 0 for none). A field the grader counts that is no carried
|
|
136
|
+
* array the run was handed (a misspelled name, a scalar) fails it by name: never read as 0 dropped. */
|
|
137
|
+
export function handedVerdict(handed, expect, dropped) {
|
|
138
|
+
if (!handed)
|
|
139
|
+
return { pass: false, reason: "the run has no previous result seeded to read" };
|
|
140
|
+
const said = handedWords(handed);
|
|
141
|
+
if (handed.kind !== expect)
|
|
142
|
+
return { pass: false, reason: `${said}; the grader expects ${KIND_WORDS[expect]}` };
|
|
143
|
+
const lists = Object.keys(handed.dropped ?? {});
|
|
144
|
+
const unknown = Object.keys(dropped ?? {}).filter((field) => !lists.includes(field));
|
|
145
|
+
if (unknown.length)
|
|
146
|
+
return { pass: false, reason: `${said}; the grader counts ${unknown.join(", ")}, which ${unknown.length === 1 ? "is" : "are"} no carried array it was handed (${lists.length ? lists.join(", ") : "none"})` };
|
|
147
|
+
const wrong = Object.entries(dropped ?? {}).filter(([field, n]) => handed.dropped[field] !== n);
|
|
148
|
+
if (wrong.length)
|
|
149
|
+
return { pass: false, reason: `${said}; the grader expects ${wrong.map(([field, n]) => `${field}: the first ${n} dropped`).join(", ")}` };
|
|
150
|
+
return { pass: true, reason: said };
|
|
151
|
+
}
|
|
152
|
+
const KIND_WORDS = {
|
|
153
|
+
whole: "its trigger's last result whole",
|
|
154
|
+
carried: "its trigger's last result as its carried fields",
|
|
155
|
+
too_large: "nothing of its trigger's last result, too large to hand",
|
|
156
|
+
none: "no previous result",
|
|
157
|
+
};
|
|
158
|
+
/** What a run was handed, in words. */
|
|
159
|
+
function handedWords(handed) {
|
|
160
|
+
if (handed.kind !== "carried")
|
|
161
|
+
return `the run was handed ${KIND_WORDS[handed.kind]}`;
|
|
162
|
+
const dropped = Object.entries(handed.dropped ?? {}).filter(([, n]) => n > 0);
|
|
163
|
+
return `the run was handed ${KIND_WORDS.carried} (${(handed.fields ?? []).join(", ")})${dropped.length ? `, ${dropped.map(([field, n]) => `${field}: the first ${n} ${n === 1 ? "entry" : "entries"} dropped`).join("; ")}` : ", nothing dropped"}`;
|
|
164
|
+
}
|
package/dist/file-types.d.ts
CHANGED
|
@@ -2,3 +2,5 @@
|
|
|
2
2
|
export declare const INLINE_TYPES: ReadonlySet<string>;
|
|
3
3
|
/** The type of a file at `path`, by its extension; undefined for one the table does not know. */
|
|
4
4
|
export declare const typeOf: (path: string) => string | undefined;
|
|
5
|
+
/** The usual extension of a file of `type` (the first the table lists for it, so jpg for image/jpeg); undefined for one it does not serve. */
|
|
6
|
+
export declare const extensionOf: (type: string) => string | undefined;
|
package/dist/file-types.js
CHANGED
|
@@ -4,9 +4,11 @@ import { extname } from "node:path";
|
|
|
4
4
|
const TYPES = new Map(Object.entries({
|
|
5
5
|
txt: "text/plain; charset=utf-8", md: "text/markdown; charset=utf-8", csv: "text/csv; charset=utf-8", json: "application/json", jsonl: "application/x-ndjson",
|
|
6
6
|
html: "text/html; charset=utf-8", htm: "text/html; charset=utf-8", png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", gif: "image/gif", webp: "image/webp", pdf: "application/pdf",
|
|
7
|
-
mp4: "video/mp4",
|
|
7
|
+
mp4: "video/mp4", webm: "video/webm", mp3: "audio/mpeg", wav: "audio/wav", m4a: "audio/mp4", ogg: "audio/ogg",
|
|
8
8
|
}));
|
|
9
9
|
/** The types a file is served as in the page (every known type but PDF); any other is a download. */
|
|
10
10
|
export const INLINE_TYPES = new Set([...TYPES.values()].filter((type) => type !== "application/pdf"));
|
|
11
11
|
/** The type of a file at `path`, by its extension; undefined for one the table does not know. */
|
|
12
12
|
export const typeOf = (path) => TYPES.get(extname(path).slice(1).toLowerCase());
|
|
13
|
+
/** The usual extension of a file of `type` (the first the table lists for it, so jpg for image/jpeg); undefined for one it does not serve. */
|
|
14
|
+
export const extensionOf = (type) => [...TYPES].find(([, served]) => served === type)?.[0];
|
package/dist/harness.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SDK_RUNTIMES } from "./sdk/runtimes.js";
|
|
1
2
|
/** The built-in harnesses' ids, in the table's order (harness-table.ts BUILTIN; harness-one-table.test.mjs holds them
|
|
2
3
|
* equal): the ids a definition may name on any server, and the type of a built-in one. What a server runs is its table's
|
|
3
4
|
* (harnessIds), which an owner's harness module may add to. */
|
|
@@ -11,7 +12,7 @@ export const HARNESS_ID_PATTERN = "^[a-z][a-z0-9-]{0,39}$";
|
|
|
11
12
|
* runtime's (sdk/schema.ts SDK_BINDING). Also every name a plain object already has that the id pattern admits
|
|
12
13
|
* (`constructor`): serve looks harnesses up by id in plain objects, where such an id would read Object's own member. */
|
|
13
14
|
export const RESERVED_HARNESS_IDS = Object.freeze([
|
|
14
|
-
"learning", "sdk", "workflow",
|
|
15
|
+
"learning", "sdk", "workflow", ...SDK_RUNTIMES,
|
|
15
16
|
...Object.getOwnPropertyNames(Object.prototype).filter((name) => new RegExp(HARNESS_ID_PATTERN).test(name)),
|
|
16
17
|
]);
|
|
17
18
|
/** The harnesses that run on a person's ChatGPT plan (chatgpt-plan.ts): those whose requests go to OpenAI's Responses
|
package/dist/import.js
CHANGED
|
@@ -378,14 +378,15 @@ async function findKeys(plan, add, cut, held, signal, onProgress) {
|
|
|
378
378
|
/** A project's own text for secretlint: its path, its instructions, and its skills' paths and text. */
|
|
379
379
|
const projectText = (cwd, files) => [cwd, ...Object.values(files.instructions), ...Object.entries(files.skills).flat()].join("\n");
|
|
380
380
|
export const agentIdOf = (cwd) => `imp-${hash(`dir:${cwd}`).slice(0, 32)}`;
|
|
381
|
-
/** The sessions the store holds already, as `source:session`, to their run's id
|
|
382
|
-
|
|
381
|
+
/** The sessions the store holds already, as `source:session`, to their run's id: a purged run's too, so a session its
|
|
382
|
+
* owner purged is never imported again. */
|
|
383
|
+
const importedIn = async (store) => new Map((await store.runs.list({ purged: true })).flatMap((run) => (run.importedFrom ? [[`${run.importedFrom.source}:${run.importedFrom.session}`, run.id]] : [])));
|
|
383
384
|
const sameFile = (seen, stats) => seen !== undefined && seen.size === stats.size && seen.mtime_ms === stats.mtimeMs;
|
|
384
385
|
/** The session files the store's imports read whole, by their path's sha256, with their run: the file stamp an import kept
|
|
385
386
|
* on the run's `imported_from`, so an unchanged file is not parsed again. */
|
|
386
387
|
async function filesIn(store) {
|
|
387
388
|
const out = new Map();
|
|
388
|
-
for (const run of await store.runs.list({})) {
|
|
389
|
+
for (const run of await store.runs.list({ purged: true })) {
|
|
389
390
|
const seen = run.importedFrom?.file;
|
|
390
391
|
if (seen)
|
|
391
392
|
out.set(seen.path_sha256, { path_sha256: seen.path_sha256, size: seen.size, mtime_ms: seen.mtime_ms, run: run.id });
|
package/dist/learn/check.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type RepickSite } from "./repick.js";
|
|
1
2
|
import { type DraftDecisions, type DraftDryRun, type DraftReader } from "./workflow-draft.js";
|
|
2
3
|
/** Byte caps (UTF-8). Over a cap is refused, never cut. */
|
|
3
4
|
export declare const CAPS: Readonly<{
|
|
@@ -37,6 +38,10 @@ export type DraftCheckInput = {
|
|
|
37
38
|
readonly deniedBy?: Readonly<Record<string, "agent" | "server" | "default">>;
|
|
38
39
|
/** Explicit host adapter capabilities; absent keeps the managed runner defaults. */
|
|
39
40
|
readonly workflowAdapters?: readonly ("runNode" | "runJudge")[];
|
|
41
|
+
/** The agent's learning.repick (learning-setting.ts): true, a re-pick loop whose body is the pass marker the host derives
|
|
42
|
+
* from its pass 1 (learn/repick.ts repickPassOne) is read as that pass 1 by the compact state rule, so its clone's page
|
|
43
|
+
* read passes; any other page read on the agent's model is refused as ever. */
|
|
44
|
+
readonly repick?: boolean;
|
|
40
45
|
/** The workflow DSL a draft is read with. */
|
|
41
46
|
readonly dsl: DraftReader;
|
|
42
47
|
/** The decision providers a draft's decision nodes may ask, and the gate's setting of each (workflow-draft.ts
|
|
@@ -75,8 +80,13 @@ export declare function answerTierProblems(doc: unknown): string[];
|
|
|
75
80
|
* child sees an input key as a page when its value reads one. Pages reach a step on the agent's model only through a fast-tier step's
|
|
76
81
|
* output: chain14b's drafts fed whole pages to the answering step (4.1 requests a run at ~70k cached tokens each,
|
|
77
82
|
* $0.364 a served run), where the research shape (a fast extract's compact facts to the answering step) booked ~$0.08.
|
|
78
|
-
* One line each, in words the compile retry acts on.
|
|
79
|
-
|
|
83
|
+
* One line each, in words the compile retry acts on. With `repick` (the agent's learning.repick), the answer's re-pick
|
|
84
|
+
* loop (repickSiteOf), when its body is the host's pass marker, is read as its pass 1 (learn/repick.ts repickMarked):
|
|
85
|
+
* the clone its pass 2 runs reads the pages by the owner's setting, the one page read on the agent's model a draft may
|
|
86
|
+
* hold, and only that exact clone at that place. */
|
|
87
|
+
export declare function compactStateProblems(doc: unknown, { repick }?: {
|
|
88
|
+
readonly repick?: boolean;
|
|
89
|
+
}): string[];
|
|
80
90
|
/** Why a draft's quote check is not code: its answer carries quotes (a `quote` or `quotes` property in its output schema)
|
|
81
91
|
* and it fetches pages (a call step), yet some place in the answer holding quotes has no escalate on quote_missing
|
|
82
92
|
* reading it after the answer is written (quoteRule), or that escalate reads as a page a key holding no page as fetched
|
|
@@ -86,8 +96,10 @@ export declare function compactStateProblems(doc: unknown): string[];
|
|
|
86
96
|
* H5's judge flagged 149 of 170 answers while 416 of 429 quotes were in the pages, and could not tell the 8 answers
|
|
87
97
|
* quoting text no page held from the rest; code can. One line each, in words the compile retry acts on. */
|
|
88
98
|
export declare function quoteCheckProblems(doc: unknown): string[];
|
|
89
|
-
/**
|
|
90
|
-
|
|
99
|
+
/** Where `workflow`'s answer is re-picked (quoteRule `repick`): what learning.repick rewrites (learn/repick.ts). */
|
|
100
|
+
export declare const repickSiteOf: (workflow: unknown) => RepickSite | undefined;
|
|
101
|
+
/** The labels a run's loop events give `workflow`'s quote re-pick (repickSiteOf): what marks a loop's exit a re-pick
|
|
102
|
+
* (learned-nodes.ts LoopRow `repick`). Any other loop that ran twice is an ordinary loop. */
|
|
91
103
|
export declare function repickLabels(workflow: unknown): Set<string>;
|
|
92
104
|
/** What must never be stored, in every change's name and text, whatever the checks would refuse it for first: the
|
|
93
105
|
* name and text scans (nameScanned, textOf) of each change, its text read whole (a file over its cap, one not a regular
|
package/dist/learn/check.js
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
// host's secrets and of text shaped like one, and a field over PRINT_MAX is redacted whole.
|
|
5
5
|
import { placeholdersOf, placeholderValue } from "@parcha/agentrun-dsl";
|
|
6
6
|
import { hiddenCharacter } from "./invisible.js";
|
|
7
|
+
import { REPICK_PASSES, repickCheckOf, repickLabelOf, repickMarked } from "./repick.js";
|
|
7
8
|
import { learnedSecretShapes, redactLearned, valueMatcher } from "./secrets.js";
|
|
8
|
-
import { childNodes, draftProblems, decodedStrings, DECODED_DEPTH, DRY_RUN_FAILED, frontKeys, frontValues, LEARNED_KEYS, learnedPlace, readmeProblems, WORKFLOW_NAME, WORKFLOWS_DIR } from "./workflow-draft.js";
|
|
9
|
+
import { childNodes, draftProblems, decodedStrings, DECODED_DEPTH, DRY_RUN_FAILED, frontKeys, frontValues, LEARNED_KEYS, isNode, isObject, learnedPlace, readmeProblems, WORKFLOW_NAME, WORKFLOWS_DIR } from "./workflow-draft.js";
|
|
9
10
|
/** Byte caps (UTF-8). Over a cap is refused, never cut. */
|
|
10
11
|
export const CAPS = Object.freeze({
|
|
11
12
|
/** One draft's workflow.json. */
|
|
@@ -87,7 +88,6 @@ function decodedScanned(path, text, refused, add, deep = true) {
|
|
|
87
88
|
/** The model node kinds a tier routes (model.ts MODEL_NODES); a decision node (judge, pick, sift) goes to its decision
|
|
88
89
|
* provider, never a tier. */
|
|
89
90
|
export const TIERED_KINDS = new Set(["agent", "decide", "extract", "report"]);
|
|
90
|
-
const isNode = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && typeof value.node === "string";
|
|
91
91
|
/** The state key a step writes (the DSL's writeKeyOf): a report's `report_markdown`, else its `as`, else an agent's,
|
|
92
92
|
* decide's or extract's label. */
|
|
93
93
|
const writeKeyOf = (node) => (node.node === "report" ? "report_markdown" : typeof node.as === "string" && node.as ? node.as : ["agent", "decide", "extract"].includes(node.node) ? node.label : undefined);
|
|
@@ -182,9 +182,14 @@ function pagesRead(value, state, out = new Set(), depth = 0) {
|
|
|
182
182
|
* child sees an input key as a page when its value reads one. Pages reach a step on the agent's model only through a fast-tier step's
|
|
183
183
|
* output: chain14b's drafts fed whole pages to the answering step (4.1 requests a run at ~70k cached tokens each,
|
|
184
184
|
* $0.364 a served run), where the research shape (a fast extract's compact facts to the answering step) booked ~$0.08.
|
|
185
|
-
* One line each, in words the compile retry acts on.
|
|
186
|
-
|
|
185
|
+
* One line each, in words the compile retry acts on. With `repick` (the agent's learning.repick), the answer's re-pick
|
|
186
|
+
* loop (repickSiteOf), when its body is the host's pass marker, is read as its pass 1 (learn/repick.ts repickMarked):
|
|
187
|
+
* the clone its pass 2 runs reads the pages by the owner's setting, the one page read on the agent's model a draft may
|
|
188
|
+
* hold, and only that exact clone at that place. */
|
|
189
|
+
export function compactStateProblems(doc, { repick = false } = {}) {
|
|
187
190
|
const problems = new Set();
|
|
191
|
+
// The answer's re-pick loop alone (repickMarked): a marker anywhere else is read as written.
|
|
192
|
+
const marked = repick ? repickMarked(repickSiteOf(doc)) : undefined;
|
|
188
193
|
const walk = (node, pages, depth) => {
|
|
189
194
|
const after = new Set(pages);
|
|
190
195
|
if (!isNode(node) || depth > 32)
|
|
@@ -233,14 +238,15 @@ export function compactStateProblems(doc) {
|
|
|
233
238
|
// until the marks stop changing. The set read grows on each further pass, so it stops within one pass a key the
|
|
234
239
|
// workflow names, and never past maxIters; each pass's way out holds the ones before it.
|
|
235
240
|
const passes = typeof node.maxIters === "number" && node.maxIters >= 1 ? Math.floor(node.maxIters) : Number.POSITIVE_INFINITY;
|
|
241
|
+
const body = node === marked?.loop ? marked.step : node.body;
|
|
236
242
|
let read = after;
|
|
237
|
-
let out = walk(
|
|
243
|
+
let out = walk(body, read, depth + 1);
|
|
238
244
|
for (let pass = 2; pass <= passes; pass++) {
|
|
239
245
|
const next = new Set([...read, ...out]);
|
|
240
246
|
if (next.size === read.size)
|
|
241
247
|
break;
|
|
242
248
|
read = next;
|
|
243
|
-
out = walk(
|
|
249
|
+
out = walk(body, read, depth + 1);
|
|
244
250
|
}
|
|
245
251
|
return out;
|
|
246
252
|
}
|
|
@@ -292,7 +298,6 @@ export function compactStateProblems(doc) {
|
|
|
292
298
|
}
|
|
293
299
|
/** The property names that make an answer carry quotes. */
|
|
294
300
|
const QUOTE_KEYS = new Set(["quote", "quotes"]);
|
|
295
|
-
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
296
301
|
const QUOTE_SITES_MAX = 8;
|
|
297
302
|
function quoteSite(keys) {
|
|
298
303
|
const lists = keys.filter((key) => key === "[]").length;
|
|
@@ -493,21 +498,20 @@ export function quoteCheckProblems(doc) {
|
|
|
493
498
|
return isObject(doc) ? quoteRule(doc, {}).problems : [];
|
|
494
499
|
}
|
|
495
500
|
const siteKey = (site) => site.keys.join("\u0000");
|
|
496
|
-
/** The passes of a checked answer's re-pick loop: the draft, then one re-pick. */
|
|
497
|
-
const REPICK_PASSES = 2;
|
|
498
501
|
const quoteMissingText = ({ path, field, pages }) => `{"predicate": "quote_missing", "path": ${JSON.stringify(path)}${field ? `, "field": ${JSON.stringify(field)}` : ""}, "pages": ${JSON.stringify(pages)}}`;
|
|
499
|
-
/** The quote_missing a re-pick loop waits on: `step`'s, when it is a loop of REPICK_PASSES until `not` of a quote_missing. */
|
|
500
|
-
const repickCheckOf = (step) => isNode(step) && step.node === "loop" && step.maxIters === REPICK_PASSES && isObject(step.until) && step.until.predicate === "not" && isObject(step.until.of) && step.until.of.predicate === "quote_missing" ? step.until.of : undefined;
|
|
501
502
|
/** Whether `step` is the re-pick of an answer `check` reads: a loop of REPICK_PASSES until that check's quote_missing (its
|
|
502
503
|
* path, field and pages) no longer holds. */
|
|
503
504
|
const repickOn = (step, check) => {
|
|
504
505
|
const of = repickCheckOf(step);
|
|
505
506
|
return !!of && of.path === check.path && (of.field ?? "") === check.field && JSON.stringify(of.pages) === JSON.stringify(check.pages);
|
|
506
507
|
};
|
|
507
|
-
/**
|
|
508
|
-
|
|
508
|
+
/** Where `workflow`'s answer is re-picked (quoteRule `repick`): what learning.repick rewrites (learn/repick.ts). */
|
|
509
|
+
export const repickSiteOf = (workflow) => (isObject(workflow) ? quoteRule(workflow, {}).repick : undefined);
|
|
510
|
+
/** The labels a run's loop events give `workflow`'s quote re-pick (repickSiteOf): what marks a loop's exit a re-pick
|
|
511
|
+
* (learned-nodes.ts LoopRow `repick`). Any other loop that ran twice is an ordinary loop. */
|
|
509
512
|
export function repickLabels(workflow) {
|
|
510
|
-
|
|
513
|
+
const site = repickSiteOf(workflow);
|
|
514
|
+
return new Set(site ? [repickLabelOf(site)] : []);
|
|
511
515
|
}
|
|
512
516
|
/** Whether a step's `state` map names state key `key` as the whole marked placeholder `"{answer?}"` (a whole string):
|
|
513
517
|
* null on a re-pick loop's first pass, before any draft exists, and the failed draft on its second. No path below the
|
|
@@ -555,23 +559,23 @@ const quoteEscalatesIn = (node, depth = 0) => {
|
|
|
555
559
|
* (its path and field; a place no one pair reads is refused, as quote_missing reads none of it). Its pages are state keys holding a page as
|
|
556
560
|
* fetched (holdsPage). A composed workflow node writing the whole answer (its `as` the answer's path) whose child
|
|
557
561
|
* passes this rule in its own state has checked the places in the answer its child's schema declares too; the parent
|
|
558
|
-
* still checks any other place its own schema declares. `checked`: the places a passing workflow checked. `
|
|
559
|
-
* the answer
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
+
* still checks any other place its own schema declares. `checked`: the places a passing workflow checked. `repick`:
|
|
563
|
+
* where the answer is re-picked, whether the rule applies or not: the step writing the answer when it is a loop of
|
|
564
|
+
* REPICK_PASSES until `not` of a quote_missing, else that step's composed child's, which the DSL labels
|
|
565
|
+
* `<step>/<its label>` (scopeDepsToChild). */
|
|
562
566
|
function quoteRule(workflow, schemasAround, depth = 0) {
|
|
563
567
|
const output = isObject(workflow.output) ? workflow.output : {};
|
|
564
568
|
const answerPath = typeof output.path === "string" ? output.path : "";
|
|
565
569
|
const schemas = isObject(workflow.schemas) ? workflow.schemas : schemasAround;
|
|
566
570
|
const schemaId = typeof output.schemaId === "string" ? output.schemaId : "";
|
|
567
571
|
if (!answerPath || depth > 8)
|
|
568
|
-
return { applies: false, problems: [], checked: [],
|
|
572
|
+
return { applies: false, problems: [], checked: [], repick: undefined };
|
|
569
573
|
const steps = isNode(workflow.root) && workflow.root.node === "chain" && Array.isArray(workflow.root.steps) ? workflow.root.steps : [workflow.root];
|
|
570
574
|
const answered = steps.findLastIndex((step) => writesKey(step, answerPath.split(".")[0]));
|
|
571
575
|
const writer = steps[answered];
|
|
572
576
|
const child = isNode(writer) && writer.node === "workflow" && isObject(writer.workflow) ? quoteRule(writer.workflow, schemas, depth + 1) : undefined;
|
|
573
|
-
const
|
|
574
|
-
const none = { applies: false, problems: [], checked: [],
|
|
577
|
+
const repick = !isNode(writer) ? undefined : repickCheckOf(writer) ? { at: answered, step: writer } : child?.repick && { at: answered, step: writer, inner: child.repick };
|
|
578
|
+
const none = { applies: false, problems: [], checked: [], repick };
|
|
575
579
|
if (!Object.hasOwn(schemas, schemaId))
|
|
576
580
|
return none;
|
|
577
581
|
// Its refs read as the DSL reads them (resolveSchemaForWorkflow): the schema's own inline definitions first, then the catalog.
|
|
@@ -581,12 +585,12 @@ function quoteRule(workflow, schemasAround, depth = 0) {
|
|
|
581
585
|
if ((!declared.length && !over) || !fetches(workflow.root))
|
|
582
586
|
return none;
|
|
583
587
|
if (over)
|
|
584
|
-
return { applies: true, checked: [],
|
|
588
|
+
return { applies: true, checked: [], repick, problems: [`the answer's schema (${schemaId.slice(0, 64)}) holds quotes in more than ${QUOTE_SITES_MAX} places or nests past ${QUOTE_SITE_DEPTH} keys, past what the quote check reads, and the workflow fetches pages: give the answer fewer places holding quotes, each a quote, a list of quotes or a list of records holding one`] };
|
|
585
589
|
const where = (site) => `${schemaId}.${site.keys.join(".").replace(/\.(\[\]|\*)/g, "$1")}`.slice(0, 120);
|
|
586
590
|
const pages = pageKeysOf(workflow.root);
|
|
587
591
|
const covered = child?.applies && !child.problems.length && isNode(writer) && writer.as === answerPath ? child.checked : [];
|
|
588
592
|
const sites = declared.filter((site) => !covered.includes(siteKey(site)));
|
|
589
|
-
const passed = { applies: true, problems: [], checked: declared.map(siteKey),
|
|
593
|
+
const passed = { applies: true, problems: [], checked: declared.map(siteKey), repick };
|
|
590
594
|
if (!sites.length)
|
|
591
595
|
return passed;
|
|
592
596
|
// A place no one path and field reads (quotes under two lists, in a map, in records with no quote key): quote_missing
|
|
@@ -641,8 +645,8 @@ function quoteRule(workflow, schemasAround, depth = 0) {
|
|
|
641
645
|
}
|
|
642
646
|
// A composed workflow writing the answer that applies the rule and fails it: its own check is the one to fix.
|
|
643
647
|
if (problems.length && child?.problems.length)
|
|
644
|
-
return { applies: true, checked: [],
|
|
645
|
-
return problems.length ? { applies: true, problems, checked: [],
|
|
648
|
+
return { applies: true, checked: [], repick, problems: child.problems.map((problem) => `the composed workflow step ${JSON.stringify(String(writer.label ?? "(no label)").slice(0, 64))} writes the answer: ${problem}`) };
|
|
649
|
+
return problems.length ? { applies: true, problems, checked: [], repick } : passed;
|
|
646
650
|
}
|
|
647
651
|
/** What a draft may write of a workflow (`place`), by itself: a good folder name, never a deletion, a regular file
|
|
648
652
|
* within CAPS.file (a README within CAPS.readme), its text as textOf takes it, and in shape: a draft the DSL validates
|
|
@@ -677,7 +681,7 @@ function learnedChecked(change, place, refused, input, add) {
|
|
|
677
681
|
// (the SDK bridge's runNode picks every model itself: it names no tier), and its quote check to code.
|
|
678
682
|
if (!problems.length) {
|
|
679
683
|
const doc = JSON.parse(text);
|
|
680
|
-
const compact = input.workflowAdapters === undefined ? compactStateProblems(doc) : [];
|
|
684
|
+
const compact = input.workflowAdapters === undefined ? compactStateProblems(doc, { repick: input.repick === true }) : [];
|
|
681
685
|
problems.push(...[...answerTierProblems(doc), ...compact, ...quoteCheckProblems(doc)].map((detail) => ({ rule: "workflow", detail })));
|
|
682
686
|
}
|
|
683
687
|
for (const { rule, detail } of problems)
|
package/dist/learn/promote.d.ts
CHANGED
|
@@ -200,6 +200,12 @@ export declare const promotionsKey: (agentId: string) => string;
|
|
|
200
200
|
export declare const gradesOf: (settings: Pick<Settings, "get">, agentId: string) => Promise<Grade[]>;
|
|
201
201
|
/** Keeps `grade`, in place of any earlier grade of the same run, the newest GRADES_KEPT kept, at the next `seq`. */
|
|
202
202
|
export declare const putGrade: (settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, grade: Grade) => Promise<Grade>;
|
|
203
|
+
/** Every kept grade of run `runId` dropped (the run's delete, agent-delete.ts); no write when the agent keeps no grades. */
|
|
204
|
+
export declare const dropGrades: (settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, runId: string) => Promise<void>;
|
|
205
|
+
/** What agent `agentId`'s learning copied from run `runId`, gone (the run's purge, agent-delete.ts): its kept grades
|
|
206
|
+
* dropped (dropGrades), and its promotion records' disagreements naming it blanked (forgetRunIn), each record's decision,
|
|
207
|
+
* numbers and run ids kept. No write when nothing names it. */
|
|
208
|
+
export declare const forgetRunCopies: (settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, runId: string) => Promise<void>;
|
|
203
209
|
/** Marks the kept grade `grade` (its run, given at its `at`, kept at its `seq`) with the feedback round it opened and
|
|
204
210
|
* that round's steer, in place: its `seq` stays. A newer grade of the run is left as it is, one given in the same
|
|
205
211
|
* millisecond too (its `seq` is another). The grade, marked. */
|
|
@@ -353,7 +359,7 @@ export declare function comparedOf(value: unknown): Compared | undefined;
|
|
|
353
359
|
export declare const gradeView: (grade: Grade) => {
|
|
354
360
|
source: "feedback" | "eval";
|
|
355
361
|
graded_at: string;
|
|
356
|
-
path: "agent" | "workflow" | "replay" | "
|
|
362
|
+
path: "agent" | "workflow" | "replay" | "audit" | "handed_back";
|
|
357
363
|
workflow: string | null;
|
|
358
364
|
workflow_digest: string | null;
|
|
359
365
|
feedback: "correction" | null;
|