@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/commit.js
CHANGED
|
@@ -1,62 +1,34 @@
|
|
|
1
|
-
// learningCommit: the writes on an agent's learning folder. Every call is ONE exec of the learning script on the folder's
|
|
2
|
-
// main (learn/folder.ts commitChange, one hold), computed from the folder's snapshot and the bodies it names. A main
|
|
3
|
-
// that moved under it (the script's exit 3) is computed again on the main that won. A folder with no main yet is made
|
|
4
|
-
// in the same call (the script's init first). Four writes:
|
|
5
|
-
// - a run's compiled workflow draft (learningCommit), already checked, its files whole; a file that is not on main as
|
|
6
|
-
// it was on the run's seed (or its `bases` commit) is a conflict, never written over;
|
|
7
|
-
// - one line of an owner's feedback appended to corrections.md (appendCorrection), after the refusals;
|
|
8
|
-
// - corrections.md replaced whole by a person (putCorrections), under the ETag they read;
|
|
9
|
-
// - a purged run's learned workflows put back as they were before it (off main when it wrote them new) and its feedback
|
|
10
|
-
// lines taken off main, by the host (forgetRunText).
|
|
11
|
-
import { isWorkspaceError } from "../workspace/index.js";
|
|
12
1
|
import { CORRECTIONS_CAP, CORRECTIONS_FILE, correctionLine, correctionsProblems } from "./corrections.js";
|
|
13
|
-
import { blobOid,
|
|
2
|
+
import { blobOid, LearningBusy, LearningMerged, LearningRefused, readLearning, readView, runDiffKey, runMergeOf, writeLearning } from "./rows.js";
|
|
14
3
|
import { held, isHeld } from "./workflow-draft.js";
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
if (!snapshot)
|
|
18
|
-
return undefined;
|
|
19
|
-
if (path === CORRECTIONS_FILE)
|
|
20
|
-
return snapshot.corrections?.oid;
|
|
21
|
-
for (const item of snapshot.workflows) {
|
|
22
|
-
const file = item.files.find((one) => one.path === path);
|
|
23
|
-
if (file)
|
|
24
|
-
return file.oid;
|
|
25
|
-
}
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
/** A write's failure as a result: the script's precondition (a file changed since the seed: a conflict), a write past
|
|
29
|
-
* what one exec carries, or the folder unavailable (retry later). */
|
|
4
|
+
/** A write's failure as a result: a precondition (a file changed since the seed, or the seed gone: a conflict), or the
|
|
5
|
+
* store unavailable (retry later). */
|
|
30
6
|
function failure(error) {
|
|
31
|
-
if (error instanceof
|
|
7
|
+
if (error instanceof LearningRefused && error.purged !== undefined)
|
|
8
|
+
return { ok: false, reason: "purged", problems: [{ rule: "kept", detail: "a run's learning was purged after this run started, so what it learned can't be told apart from what the purge took" }] };
|
|
9
|
+
if (error instanceof LearningRefused && error.seed !== undefined)
|
|
32
10
|
return { ok: false, reason: "conflict", problems: [{ rule: "kept", detail: "the agent's learning was reset after the run started, so what it learned has nothing to land on" }] };
|
|
33
|
-
if (error instanceof
|
|
34
|
-
return { ok: false, reason: "conflict", problems:
|
|
35
|
-
if (error instanceof FolderTooLarge)
|
|
36
|
-
return { ok: false, reason: "refused", problems: [{ rule: "too_large", detail: error.message }] };
|
|
11
|
+
if (error instanceof LearningRefused)
|
|
12
|
+
return { ok: false, reason: "conflict", problems: error.same.map((path) => ({ rule: "kept", path, detail: `${path} changed on main after the run started` })) };
|
|
37
13
|
return { ok: false, reason: "unavailable", error: error?.message ?? String(error) };
|
|
38
14
|
}
|
|
39
|
-
/** What a write landed, from writeLearning's answer: its new main and the paths it changed. */
|
|
40
|
-
const landed = (done) => "pending" in done.result
|
|
41
|
-
? { ok: true, main: done.main, commit: done.main, files: done.snapshot?.log[0]?.commit === done.main ? done.snapshot.log[0].files : [], ...(done.result.refusedCorrection ? { refusedCorrection: done.result.refusedCorrection } : {}) }
|
|
42
|
-
: done.result;
|
|
43
15
|
/**
|
|
44
|
-
* A run's merge on the
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* draft
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
16
|
+
* A run's merge on the agent's learning, one save: its files (a held README with `status: pending`) and its owner's
|
|
17
|
+
* correction appended to corrections.md. `ok` with the new version and the paths it changed; `conflict` when a file is
|
|
18
|
+
* 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
|
|
19
|
+
* its seed (or a revised workflow's base), nothing written; `refused` when the correction holds what must never be stored,
|
|
20
|
+
* or, with no draft beside it, would take corrections.md past its cap (nothing written); `unavailable` when the store
|
|
21
|
+
* failed. The draft and the correction are judged apart: a correction past the cap beside a draft (the file filled by
|
|
22
|
+
* another write after the run's check, correctionRefused) is left out alone, and the draft merges, `ok` with the cap's
|
|
23
|
+
* refusal as `refusedCorrection`. A merge whose run already merged (this round) is `ok` with the save that holds it, and
|
|
24
|
+
* writes nothing: its merge key is taken once, in the save's own transaction, so two calls racing for one round (a
|
|
25
|
+
* reclaimed run) merge it once.
|
|
53
26
|
*/
|
|
54
|
-
export async function learningCommit(
|
|
55
|
-
const key = runDiffKey(change.runId, change.round);
|
|
27
|
+
export async function learningCommit(learning, change, opts = {}) {
|
|
56
28
|
try {
|
|
57
|
-
const known = await runMergeOf(
|
|
29
|
+
const known = await runMergeOf(learning, change.runId, change.round);
|
|
58
30
|
if (known)
|
|
59
|
-
return await already(
|
|
31
|
+
return await already(learning, change, known.merge, known);
|
|
60
32
|
const line = change.correction === undefined ? undefined : correctionLine(change.correction);
|
|
61
33
|
// The line alone first: what it holds is refused whatever the file around it holds.
|
|
62
34
|
const own = line === undefined ? [] : correctionProblems(line, change.refuseValues);
|
|
@@ -65,19 +37,18 @@ export async function learningCommit(ws, change, opts = {}) {
|
|
|
65
37
|
const marked = new Set(change.held ?? []);
|
|
66
38
|
const drafts = change.files.map(({ path, text }) => ({ path, text: marked.has(path) && !isHeld(text) ? held(text) : text }));
|
|
67
39
|
const same = change.files.flatMap(({ path }) => {
|
|
68
|
-
const
|
|
69
|
-
return
|
|
40
|
+
const at = change.bases?.[path] ?? change.seed;
|
|
41
|
+
return at ? [{ at, path }] : [];
|
|
70
42
|
});
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return { result: { merged } };
|
|
43
|
+
// Every save the merge's files were read at: a purge after any of them refuses it whole (its correction too). A
|
|
44
|
+
// correction alone copies nothing from them (its line is the owner's new words, appended to the newest
|
|
45
|
+
// corrections.md), so a purge since never refuses it; its `mustHold` still refuses it after a reset.
|
|
46
|
+
const readAt = drafts.length ? [...new Set([change.seed, change.mustHold, ...Object.values(change.bases ?? {})].filter((id) => id !== undefined))] : [];
|
|
47
|
+
const done = await writeLearning(learning, async (read) => {
|
|
77
48
|
const writes = [...drafts];
|
|
78
49
|
let refusedCorrection;
|
|
79
50
|
if (line !== undefined) {
|
|
80
|
-
const text = appended(
|
|
51
|
+
const text = appended(correctionsOf(read), line);
|
|
81
52
|
const full = capProblem(text);
|
|
82
53
|
if (full && !drafts.length)
|
|
83
54
|
return { result: { ok: false, reason: "refused", problems: [full] } };
|
|
@@ -86,30 +57,32 @@ export async function learningCommit(ws, change, opts = {}) {
|
|
|
86
57
|
else
|
|
87
58
|
writes.push({ path: CORRECTIONS_FILE, text });
|
|
88
59
|
}
|
|
89
|
-
// `mustHold`: the
|
|
90
|
-
return { result: { pending: true, ...(refusedCorrection ? { refusedCorrection } : {}) }, change: { by: run(change.runId, change.reason, change.round), writes, ...(same.length ? { same } : {}), ...(change.mustHold ? { seed: change.mustHold } : {}) } };
|
|
60
|
+
// `mustHold`: the whole merge is refused when the agent's learning no longer holds it (a reset removed it).
|
|
61
|
+
return { result: { pending: true, ...(refusedCorrection ? { refusedCorrection } : {}) }, change: { by: run(change.runId, change.reason, change.round), writes, ...(same.length ? { same } : {}), ...(change.mustHold ? { seed: change.mustHold } : {}), ...(readAt.length ? { readAt } : {}) } };
|
|
91
62
|
}, opts.retries ?? 3);
|
|
92
|
-
const { result } = done;
|
|
93
|
-
return "
|
|
63
|
+
const { result, saved } = done;
|
|
64
|
+
return "pending" in result ? { ok: true, main: saved.id, commit: saved.id, files: [...saved.files], ...(result.refusedCorrection ? { refusedCorrection: result.refusedCorrection } : {}) } : result;
|
|
94
65
|
}
|
|
95
66
|
catch (error) {
|
|
96
|
-
// The round merged under this call past
|
|
97
|
-
//
|
|
98
|
-
if (error instanceof
|
|
99
|
-
return already(
|
|
67
|
+
// The round merged under this call past the read above (a reclaimed run's two claims racing): its merge key let one
|
|
68
|
+
// merge of it land, and this call reads that one.
|
|
69
|
+
if (error instanceof LearningMerged)
|
|
70
|
+
return already(learning, change, error.save.id, await runMergeOf(learning, change.runId, change.round).catch(() => undefined)).catch(failure);
|
|
71
|
+
if (error instanceof LearningBusy)
|
|
72
|
+
return { ok: false, reason: "unavailable", error: error.message };
|
|
100
73
|
return failure(error);
|
|
101
74
|
}
|
|
102
75
|
}
|
|
103
|
-
/** A round that merged already, `merge` its
|
|
104
|
-
*
|
|
105
|
-
async function already(
|
|
76
|
+
/** A round that merged already, `merge` its save: `ok` with it and the paths its diff names, nothing written again. Its
|
|
77
|
+
* merge left the correction out only at the cap. */
|
|
78
|
+
async function already(learning, change, merge, known) {
|
|
106
79
|
const left = known !== undefined && change.correction !== undefined && !known.files.some((file) => file.path === CORRECTIONS_FILE);
|
|
107
80
|
const refusedCorrection = left ? [{ rule: "too_large", path: CORRECTIONS_FILE, detail: `${CORRECTIONS_FILE} was at its cap of ${CORRECTIONS_CAP} bytes when the run's merge was written` }] : [];
|
|
108
|
-
return { ok: true, main: (await
|
|
81
|
+
return { ok: true, main: (await readView(learning))?.main ?? merge, commit: merge, files: known ? known.files.map((file) => file.path) : [], already: true, ...(refusedCorrection.length ? { refusedCorrection } : {}) };
|
|
109
82
|
}
|
|
110
83
|
const run = (runId, reason, round) => ({ run: runId, reason, ...(round !== undefined && round > 1 ? { round } : {}) });
|
|
111
|
-
/** corrections.md's text
|
|
112
|
-
const correctionsOf =
|
|
84
|
+
/** corrections.md's text at the version read ("" when it holds none). */
|
|
85
|
+
const correctionsOf = (read) => read.text(CORRECTIONS_FILE) ?? "";
|
|
113
86
|
/** corrections.md's text `before` with `line` appended on a line of its own. */
|
|
114
87
|
const appended = (before, line) => `${before}${before && !before.endsWith("\n") ? "\n" : ""}${line}`;
|
|
115
88
|
/** What a correction's line holds that must never be stored, whatever the file around it holds. */
|
|
@@ -123,224 +96,43 @@ const capProblem = (text) => {
|
|
|
123
96
|
* empty when it would be taken. Read before the run's merge, so a refused correction never holds its draft back. A
|
|
124
97
|
* round (`merge`) whose merge is on main already (a stop after its commit, before the run's end was saved) is never
|
|
125
98
|
* checked for room again, its own line counted twice: empty, and its merge (learningCommit) gives back what it did. */
|
|
126
|
-
export async function correctionRefused(
|
|
99
|
+
export async function correctionRefused(learning, text, refuseValues, merge) {
|
|
127
100
|
const line = correctionLine(text);
|
|
128
101
|
const own = correctionProblems(line, refuseValues);
|
|
129
102
|
if (own.length)
|
|
130
103
|
return own;
|
|
131
|
-
if (merge && (await
|
|
104
|
+
if (merge && (await learning.rows.saveOf(learning.agentId, { mergeKey: runDiffKey(merge.runId, merge.round) })))
|
|
132
105
|
return [];
|
|
133
|
-
const before = await readLearning(
|
|
106
|
+
const before = await readLearning(learning, correctionsOf);
|
|
134
107
|
const full = capProblem(appended(before, line));
|
|
135
108
|
return full ? [full] : [];
|
|
136
109
|
}
|
|
137
110
|
/** One line of an owner's feedback appended to corrections.md on main, by run `runId`'s merge (learningCommit's
|
|
138
111
|
* `correction`, with no draft beside it). */
|
|
139
|
-
export const appendCorrection = (
|
|
140
|
-
/** corrections.md as a person reads it: its text and its ETag's blob (an empty file's when
|
|
141
|
-
export
|
|
142
|
-
|
|
143
|
-
return { text, oid: snapshot?.corrections?.oid ?? blobOid("") };
|
|
112
|
+
export const appendCorrection = (learning, input) => learningCommit(learning, { runId: input.runId, ...(input.round !== undefined ? { round: input.round } : {}), reason: "the owner's correction", files: [], correction: input.text, ...(input.refuseValues ? { refuseValues: input.refuseValues } : {}) });
|
|
113
|
+
/** corrections.md as a person reads it: its text and its ETag's blob (an empty file's when it holds none). */
|
|
114
|
+
export function readCorrections(read) {
|
|
115
|
+
return { text: correctionsOf(read), oid: read.view?.corrections?.oid ?? blobOid("") };
|
|
144
116
|
}
|
|
145
117
|
/**
|
|
146
118
|
* corrections.md replaced whole by a person: `ifMatch`, the blob they read (an ETag, quoted or not; an empty file's when
|
|
147
|
-
*
|
|
119
|
+
* the agent held none), must be the newest's now, else a conflict. Refused, nothing written, as appendCorrection refuses. `ok` with
|
|
148
120
|
* the new text and its blob.
|
|
149
121
|
*/
|
|
150
|
-
export async function putCorrections(
|
|
151
|
-
|
|
122
|
+
export async function putCorrections(learning, input) {
|
|
123
|
+
// Kept as its notes hold it: every line ends in a newline (learn/rows.ts), so the text answered is the text read back.
|
|
124
|
+
const text = input.text === "" || input.text.endsWith("\n") ? input.text : `${input.text}\n`;
|
|
125
|
+
// Judged as sent first, so a refusal counts the bytes the person sent; then with the newline it is kept with.
|
|
126
|
+
const sent = correctionsProblems(input.text, input.refuseValues);
|
|
127
|
+
const problems = sent.length || text === input.text ? sent : correctionsProblems(text, input.refuseValues);
|
|
152
128
|
if (problems.length)
|
|
153
129
|
return { ok: false, reason: "refused", problems };
|
|
154
130
|
const seen = input.ifMatch.trim().replace(/^W\//, "").replace(/^"|"$/g, "");
|
|
155
|
-
const { result } = await writeLearning(
|
|
156
|
-
const now =
|
|
131
|
+
const { result } = await writeLearning(learning, async ({ view }) => {
|
|
132
|
+
const now = view?.corrections?.oid ?? blobOid("");
|
|
157
133
|
if (now !== seen)
|
|
158
134
|
return { result: { ok: false, reason: "conflict", problems: [{ rule: "kept", path: CORRECTIONS_FILE, detail: `${CORRECTIONS_FILE} changed since it was read` }] } };
|
|
159
|
-
return { result: { ok: true, text
|
|
135
|
+
return { result: { ok: true, text, oid: blobOid(text) }, change: { by: { person: "edited", file: CORRECTIONS_FILE }, writes: [{ path: CORRECTIONS_FILE, text }] } };
|
|
160
136
|
});
|
|
161
137
|
return result;
|
|
162
138
|
}
|
|
163
|
-
/**
|
|
164
|
-
* Run `runId`'s text taken off the folder's current files, at its purge (agent-delete.ts purgeRun): first its learned
|
|
165
|
-
* workflows (forgetRunWorkflows; `purged`: whether another run is purged), whether or not it left a diff file; then the
|
|
166
|
-
* lines each of its merges added to corrections.md, as its diff file keeps them, dropped from main in one host commit
|
|
167
|
-
* per merge (a line a person edited since is theirs and stays); each other merge's diff that shows such a line as
|
|
168
|
-
* context written without it; then the run's diff files deleted, last, so a call stopped part way finds what it has
|
|
169
|
-
* left to do. Its merges stay in the folder's git history until a learning reset or its agent's purge deletes the
|
|
170
|
-
* folder. Idempotent: each merge's scrub lands once, nothing left to drop makes no commit, and a run with no diff file
|
|
171
|
-
* and no workflow here is no work.
|
|
172
|
-
* `commit`: the host's last commit, when one was made.
|
|
173
|
-
*/
|
|
174
|
-
export async function forgetRunText(ws, runId, purged) {
|
|
175
|
-
let commit = await forgetRunWorkflows(ws, runId, async (run) => run === runId || (await purged(run)));
|
|
176
|
-
const names = await diffNames(ws);
|
|
177
|
-
const own = new RegExp(`^${runId.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(\\.r\\d+)?\\.json(\\..+)?$`);
|
|
178
|
-
const mine = names.filter((name) => own.test(name));
|
|
179
|
-
if (!mine.length)
|
|
180
|
-
return commit ? { commit } : {};
|
|
181
|
-
const lines = [];
|
|
182
|
-
for (const name of mine.filter(isDiffFile)) {
|
|
183
|
-
const added = ((await diffOrNone(ws, name))?.files ?? []).flatMap((file) => (file.path === CORRECTIONS_FILE && "patch" in file ? addedLines(file.patch) : []));
|
|
184
|
-
if (!added.length)
|
|
185
|
-
continue;
|
|
186
|
-
lines.push(...added);
|
|
187
|
-
// Lands once, by the merge's diff key (the folder's ref for its scrub): a call that stopped after it finds it landed
|
|
188
|
-
// and takes no line again, so another run's same line stays; a merge of the run made since (a purge that stopped
|
|
189
|
-
// before the run's tombstone left it open to a grade) is a key of its own, scrubbed in its turn.
|
|
190
|
-
const done = await writeLearning(ws, async ({ snapshot, body }) => {
|
|
191
|
-
if (!snapshot?.corrections)
|
|
192
|
-
return { result: undefined };
|
|
193
|
-
const before = await body(CORRECTIONS_FILE, snapshot.corrections.oid);
|
|
194
|
-
const after = withoutLines(before, added);
|
|
195
|
-
if (after === before)
|
|
196
|
-
return { result: undefined };
|
|
197
|
-
const write = after ? { writes: [{ path: CORRECTIONS_FILE, text: after }] } : { writes: [], deletes: [CORRECTIONS_FILE] };
|
|
198
|
-
return { result: snapshot.corrections.oid, change: { by: { host: "a purged run's corrections removed" }, purged: name.slice(0, -".json".length), ...write } };
|
|
199
|
-
}).catch((error) => (error instanceof FolderMerged ? { result: undefined, main: undefined } : Promise.reject(error)));
|
|
200
|
-
if (done.result !== undefined) {
|
|
201
|
-
forgetBody(done.result);
|
|
202
|
-
commit = done.main;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
if (lines.length) {
|
|
206
|
-
const gone = new Set(lines);
|
|
207
|
-
for (const name of names.filter((one) => isDiffFile(one) && !own.test(one))) {
|
|
208
|
-
const diff = await diffOrNone(ws, name);
|
|
209
|
-
if (!diff)
|
|
210
|
-
continue;
|
|
211
|
-
let changed = false;
|
|
212
|
-
const files = diff.files.map((file) => {
|
|
213
|
-
if (file.path !== CORRECTIONS_FILE || !("patch" in file))
|
|
214
|
-
return file;
|
|
215
|
-
const patch = withoutContext(file.patch, gone);
|
|
216
|
-
if (patch === file.patch)
|
|
217
|
-
return file;
|
|
218
|
-
changed = true;
|
|
219
|
-
return { ...file, patch };
|
|
220
|
-
});
|
|
221
|
-
if (!changed)
|
|
222
|
-
continue;
|
|
223
|
-
await ws.write(`${DIFFS_DIR}/${name}`, `${JSON.stringify({ ...diff, files })}\n`).catch((error) => { throw folderFailure(error); });
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
for (const name of mine)
|
|
227
|
-
await ws.remove(`${DIFFS_DIR}/${name}`, { force: true }).catch((error) => { throw folderFailure(error); });
|
|
228
|
-
return commit ? { commit } : {};
|
|
229
|
-
}
|
|
230
|
-
/** Each learned workflow on main whose workflow.json run `runId` wrote last (SnapLearned.run, the rule purged-workflow.ts
|
|
231
|
-
* reads) put back in one host commit as it stood at the newest commit where its writer was no purged run (`purged`,
|
|
232
|
-
* `runId` among them), every file of its `workflows/<name>/` folder, its writer that run again (the commit's
|
|
233
|
-
* `Written-By` line: folder.ts writerOf); taken off main whole when the purged runs wrote every version of it. So a
|
|
234
|
-
* purge takes off main only what purged runs put there, and a version another run wrote, a champion included, stays
|
|
235
|
-
* served. The commit, or undefined when main holds none of the run's (a repeat finds its own put back, and one another
|
|
236
|
-
* run wrote since names that run). The snapshot is rebuilt from main first (two execs and a checkout): a merge that
|
|
237
|
-
* moved main and stopped before its snapshot leaves one that names none of that merge's workflows, and finding no work
|
|
238
|
-
* commits nothing that would show it stale. One more read-only exec of main's history when the run wrote one, and one
|
|
239
|
-
* per version put back; either read finding nothing refuses (FolderUnreadable), so no guess takes a folder off. */
|
|
240
|
-
async function forgetRunWorkflows(ws, runId, purged) {
|
|
241
|
-
if (await readSnapshot(ws))
|
|
242
|
-
await learningRepair(ws);
|
|
243
|
-
const done = await writeLearning(ws, async ({ snapshot }) => {
|
|
244
|
-
const mine = (snapshot?.workflows ?? []).filter((item) => item.run === runId);
|
|
245
|
-
if (!mine.length)
|
|
246
|
-
return { result: false };
|
|
247
|
-
// No history read, no guess: a purge that can't tell what came before the run's version refuses (503, sent again
|
|
248
|
-
// later), and never takes the whole folder off main.
|
|
249
|
-
const unread = () => new FolderUnreadable(false, "the learning folder's history at main can't be read, so a purge puts nothing back and takes nothing off: send the DELETE again");
|
|
250
|
-
const history = await folderAt(ws, snapshot.main);
|
|
251
|
-
if (!history)
|
|
252
|
-
throw unread();
|
|
253
|
-
const writes = [];
|
|
254
|
-
const deletes = [];
|
|
255
|
-
const written = {};
|
|
256
|
-
for (const item of mine) {
|
|
257
|
-
// Newest first: the first writer no purged run is the version to put back, as it stood just before the next
|
|
258
|
-
// writer took the file over.
|
|
259
|
-
const writers = history.writers(item.name);
|
|
260
|
-
let back = [];
|
|
261
|
-
for (let i = 1; i < writers.length; i++) {
|
|
262
|
-
const { run } = writers[i];
|
|
263
|
-
if (run !== null && (await purged(run)))
|
|
264
|
-
continue;
|
|
265
|
-
const before = writers[i - 1].before;
|
|
266
|
-
const at = before ? await folderAt(ws, before) : undefined;
|
|
267
|
-
if (!at)
|
|
268
|
-
throw unread();
|
|
269
|
-
const files = at.snapshot.workflows.find((one) => one.name === item.name)?.files ?? [];
|
|
270
|
-
back = files.map(({ path, oid }) => ({ path, text: at.blobs.get(oid).toString("utf8") }));
|
|
271
|
-
// Named even when `back` is main's bytes already, so the writer still moves (folder.ts writtenIn).
|
|
272
|
-
if (back.length)
|
|
273
|
-
written[item.name] = run;
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
writes.push(...back);
|
|
277
|
-
deletes.push(...[...item.files.map(({ path }) => path), ...(item.links ?? [])].filter((path) => !back.some((file) => file.path === path)));
|
|
278
|
-
}
|
|
279
|
-
const host = writes.length ? "a purged run's workflows put back as they were before it" : "a purged run's workflows removed";
|
|
280
|
-
return { result: true, change: { by: { host, written }, writes, deletes } };
|
|
281
|
-
});
|
|
282
|
-
return done.result ? done.main : undefined;
|
|
283
|
-
}
|
|
284
|
-
/** The names in the folder's diffs directory; none when it is not there. */
|
|
285
|
-
const diffNames = (ws) => ws.list(DIFFS_DIR).then((entries) => entries.filter((entry) => entry.kind === "file").map((entry) => entry.name), (error) => (isWorkspaceError(error, "NOT_FOUND") ? [] : Promise.reject(folderFailure(error))));
|
|
286
|
-
/** A merge's diff file, `<key>.json`; not one a stopped write left half written (`.json.<suffix>`). */
|
|
287
|
-
const isDiffFile = (name) => /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}\.json$/.test(name);
|
|
288
|
-
/** Diff file `name` as readRunDiff reads it, or undefined when it does not read as one: a folder that can't be read
|
|
289
|
-
* throws. */
|
|
290
|
-
const diffOrNone = (ws, name) => readRunDiff(ws, name.slice(0, -".json".length)).catch((error) => (error instanceof FolderUnreadable ? Promise.reject(error) : undefined));
|
|
291
|
-
/** The lines a patch (git's hunks) adds and does not take away: what a merge appended. */
|
|
292
|
-
function addedLines(patch) {
|
|
293
|
-
const lines = patch.split("\n");
|
|
294
|
-
const taken = new Map();
|
|
295
|
-
for (const line of lines)
|
|
296
|
-
if (line.startsWith("-"))
|
|
297
|
-
taken.set(line.slice(1), (taken.get(line.slice(1)) ?? 0) + 1);
|
|
298
|
-
return lines.filter((line) => line.startsWith("+")).map((line) => line.slice(1)).filter((line) => {
|
|
299
|
-
const left = taken.get(line) ?? 0;
|
|
300
|
-
if (left)
|
|
301
|
-
taken.set(line, left - 1);
|
|
302
|
-
return !left && line.trim() !== "";
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
/** `text` with the last line equal to each of `lines` left out. */
|
|
306
|
-
function withoutLines(text, lines) {
|
|
307
|
-
const kept = text.split("\n");
|
|
308
|
-
for (const line of lines) {
|
|
309
|
-
const at = kept.lastIndexOf(line);
|
|
310
|
-
if (at >= 0)
|
|
311
|
-
kept.splice(at, 1);
|
|
312
|
-
}
|
|
313
|
-
return kept.join("\n");
|
|
314
|
-
}
|
|
315
|
-
/** `patch` (git's hunks) with each context line that is one of `gone` left out, a hunk that lost one given the header
|
|
316
|
-
* of what it keeps: the start moved past the lines it lost at its top (git names the line before when it keeps none
|
|
317
|
-
* on a side), each count less what it lost. */
|
|
318
|
-
function withoutContext(patch, gone) {
|
|
319
|
-
const lines = patch.split("\n");
|
|
320
|
-
const out = [];
|
|
321
|
-
const dropped = (line) => line.startsWith(" ") && gone.has(line.slice(1));
|
|
322
|
-
for (let i = 0; i < lines.length;) {
|
|
323
|
-
const head = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/.exec(lines[i]);
|
|
324
|
-
if (!head) {
|
|
325
|
-
out.push(lines[i++]);
|
|
326
|
-
continue;
|
|
327
|
-
}
|
|
328
|
-
let end = i + 1;
|
|
329
|
-
while (end < lines.length && !lines[end].startsWith("@@"))
|
|
330
|
-
end++;
|
|
331
|
-
const body = lines.slice(i + 1, end);
|
|
332
|
-
const kept = body.filter((line) => !dropped(line));
|
|
333
|
-
const lost = body.length - kept.length;
|
|
334
|
-
if (!lost)
|
|
335
|
-
out.push(lines[i], ...body);
|
|
336
|
-
else {
|
|
337
|
-
const top = body.findIndex((line) => !dropped(line));
|
|
338
|
-
const lead = top < 0 ? lost : top;
|
|
339
|
-
const [olds, news] = [Number(head[2] ?? 1) - lost, Number(head[4] ?? 1) - lost];
|
|
340
|
-
const at = (start, count) => Number(start) + lead - (count ? 0 : 1);
|
|
341
|
-
out.push(`@@ -${at(head[1], olds)},${olds} +${at(head[3], news)},${news} @@${head[5]}`, ...kept);
|
|
342
|
-
}
|
|
343
|
-
i = end;
|
|
344
|
-
}
|
|
345
|
-
return out.join("\n");
|
|
346
|
-
}
|
package/dist/learn/compile.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RunRow, Store } from "../store/store.js";
|
|
2
2
|
import type { AuthorHostAddendum } from "@parcha/agentrun-dsl";
|
|
3
|
-
import { type AuditHold, type CheckRecord, type PromotionRecord
|
|
3
|
+
import { type AuditHold, type CheckRecord, type PromotionRecord } from "./promote.js";
|
|
4
4
|
import type { Problem } from "./check.js";
|
|
5
5
|
/** The info word that opens a workflow draft's block in a compile answer: ````workflow <name>, fenced with four backticks
|
|
6
6
|
* so a ``` line inside does not close it. */
|
|
@@ -111,9 +111,9 @@ export declare function promotedOf(records: readonly PromotionRecord[], workflow
|
|
|
111
111
|
/** The learned workflows whose newest revision other than their champion (learn/promote.ts championOf, which serves while
|
|
112
112
|
* that revision is held) is held: each one's compile turn is asked for a revision (once per hold). A champion's own
|
|
113
113
|
* hold counts: with it held there is no champion. Not one a check stopped (its recompile's check held it too): nothing
|
|
114
|
-
* compiles it again. A
|
|
115
|
-
*
|
|
116
|
-
export declare function heldNamesOf(records: readonly PromotionRecord[]
|
|
114
|
+
* compiles it again. A purged run's records are gone with it (Store.learning purgeRun): no purged run's revision is the
|
|
115
|
+
* champion or the hold a compile revises. */
|
|
116
|
+
export declare function heldNamesOf(records: readonly PromotionRecord[]): Set<string>;
|
|
117
117
|
/** The words a compile's promotion record starts with when every draft of its turn failed its checks (runner/
|
|
118
118
|
* learning-end.ts recordDraftFailed): a hold with nothing checked, the compile's attempt all the same. */
|
|
119
119
|
export declare const DRAFT_FAILED = "its draft failed its checks";
|
package/dist/learn/compile.js
CHANGED
|
@@ -76,13 +76,12 @@ export function promotedOf(records, workflow, digest) {
|
|
|
76
76
|
/** The learned workflows whose newest revision other than their champion (learn/promote.ts championOf, which serves while
|
|
77
77
|
* that revision is held) is held: each one's compile turn is asked for a revision (once per hold). A champion's own
|
|
78
78
|
* hold counts: with it held there is no champion. Not one a check stopped (its recompile's check held it too): nothing
|
|
79
|
-
* compiles it again. A
|
|
80
|
-
*
|
|
81
|
-
export function heldNamesOf(records
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
const newest = kept.findLast((one) => one.workflow === name && one.digest !== champion);
|
|
79
|
+
* compiles it again. A purged run's records are gone with it (Store.learning purgeRun): no purged run's revision is the
|
|
80
|
+
* champion or the hold a compile revises. */
|
|
81
|
+
export function heldNamesOf(records) {
|
|
82
|
+
return new Set([...new Set(records.map(({ workflow }) => workflow))].filter((name) => {
|
|
83
|
+
const champion = championOf(records, name)?.digest;
|
|
84
|
+
const newest = records.findLast((one) => one.workflow === name && one.digest !== champion);
|
|
86
85
|
return newest?.decided === "hold" && !newest.check?.stopped && !newest.audit?.stopped;
|
|
87
86
|
}));
|
|
88
87
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// An agent's standing corrections: one file, corrections.md, at its learning
|
|
1
|
+
// An agent's standing corrections: one file, corrections.md, at its learning's top, in its owner's words. An
|
|
2
2
|
// owner's feedback (a grade with words, a message after the answer) adds one line; a person may replace it whole over
|
|
3
3
|
// v2. Every run of the agent is served it whole under # Learned. Nothing that must never be stored (a host secret, text
|
|
4
4
|
// shaped like one, a character a reader does not see) is written, and the file never grows past CORRECTIONS_CAP.
|
package/dist/learn/delete.d.ts
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
import { type Store } from "../store/store.js";
|
|
2
|
-
import type { LearningFolder } from "./folder.js";
|
|
3
2
|
/** A delete refused: work of the agent's learning is still in flight (`runs`: a run of the agent not ended, its
|
|
4
3
|
* compile turn, a check's replay or an audit's shadow among them). Nothing was removed. */
|
|
5
4
|
export declare class LearningInFlight extends Error {
|
|
6
5
|
readonly runs: readonly string[];
|
|
7
6
|
constructor(agentId: string, runs: readonly string[]);
|
|
8
7
|
}
|
|
9
|
-
/** Agent `agentId`'s learning deleted:
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
* Refused (LearningInFlight), with nothing removed, while a run of the agent has not ended; `elsewhere` failing leaves
|
|
15
|
-
* this folder and the records for the next call. Idempotent: what is gone already is skipped, so a second call removes
|
|
16
|
-
* nothing. `files`: this folder's entries it removed; `records`: the store's records. `folder` is ended here. */
|
|
17
|
-
export declare function deleteLearning(store: Store, agentId: string, folder: LearningFolder, { keepResetLedger, elsewhere }?: {
|
|
8
|
+
/** Agent `agentId`'s learning deleted: every learning row the store keeps for it (Store.learning: its items, saves,
|
|
9
|
+
* promotions, grades and audits), and the reset ledger and watermark its earlier resets kept, unless `keepResetLedger`
|
|
10
|
+
* (a reset keeps them, the runs they cover staying). Refused (LearningInFlight), with nothing removed, while a run of
|
|
11
|
+
* the agent has not ended. Idempotent: a second call removes nothing. `records`: the settings rows it removed. */
|
|
12
|
+
export declare function deleteLearning(store: Store, agentId: string, { keepResetLedger }?: {
|
|
18
13
|
keepResetLedger?: boolean;
|
|
19
|
-
elsewhere?: () => Promise<void>;
|
|
20
14
|
}): Promise<{
|
|
21
|
-
files: number;
|
|
22
15
|
records: number;
|
|
23
16
|
}>;
|
package/dist/learn/delete.js
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
// deletes the agent's store rows, in that order, so a call again after a crash finishes what a first one began and no
|
|
4
4
|
// learning is left with no agent to own it; DELETE /v2/agents/{id}/learning (learning-reset.ts) keeps the agent and its
|
|
5
5
|
// runs.
|
|
6
|
-
import { isWorkspaceError } from "../workspace/workspace.js";
|
|
7
6
|
import { FINAL_STATES } from "../store/store.js";
|
|
8
|
-
import {
|
|
7
|
+
import { resetAtKey, resetLedgerKey } from "./promote.js";
|
|
9
8
|
/** A delete refused: work of the agent's learning is still in flight (`runs`: a run of the agent not ended, its
|
|
10
9
|
* compile turn, a check's replay or an audit's shadow among them). Nothing was removed. */
|
|
11
10
|
export class LearningInFlight extends Error {
|
|
@@ -16,33 +15,21 @@ export class LearningInFlight extends Error {
|
|
|
16
15
|
this.runs = runs;
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
|
-
/** Agent `agentId`'s learning deleted:
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
await
|
|
33
|
-
|
|
34
|
-
for (const entry of entries)
|
|
35
|
-
await folder.workspace.remove(entry.name, { recursive: true, force: true });
|
|
36
|
-
let records = 0;
|
|
37
|
-
for (const key of [promotionsKey(agentId), gradesKey(agentId), ...(keepResetLedger ? [] : [resetLedgerKey(agentId), resetAtKey(agentId)])]) {
|
|
38
|
-
if ((await store.settings.get(key)) === undefined)
|
|
39
|
-
continue;
|
|
40
|
-
await store.settings.remove(key);
|
|
41
|
-
records += 1;
|
|
42
|
-
}
|
|
43
|
-
return { files: entries.length, records };
|
|
44
|
-
}
|
|
45
|
-
finally {
|
|
46
|
-
await folder.end();
|
|
18
|
+
/** Agent `agentId`'s learning deleted: every learning row the store keeps for it (Store.learning: its items, saves,
|
|
19
|
+
* promotions, grades and audits), and the reset ledger and watermark its earlier resets kept, unless `keepResetLedger`
|
|
20
|
+
* (a reset keeps them, the runs they cover staying). Refused (LearningInFlight), with nothing removed, while a run of
|
|
21
|
+
* the agent has not ended. Idempotent: a second call removes nothing. `records`: the settings rows it removed. */
|
|
22
|
+
export async function deleteLearning(store, agentId, { keepResetLedger = false } = {}) {
|
|
23
|
+
const open = (await store.runs.list({ agentId })).filter((run) => run.agentId === agentId && !FINAL_STATES.includes(run.state)).map((run) => run.id);
|
|
24
|
+
if (open.length)
|
|
25
|
+
throw new LearningInFlight(agentId, open);
|
|
26
|
+
await (keepResetLedger ? store.learning.reset(agentId) : store.learning.erase(agentId));
|
|
27
|
+
let records = 0;
|
|
28
|
+
for (const key of keepResetLedger ? [] : [resetLedgerKey(agentId), resetAtKey(agentId)]) {
|
|
29
|
+
if ((await store.settings.get(key)) === undefined)
|
|
30
|
+
continue;
|
|
31
|
+
await store.settings.remove(key);
|
|
32
|
+
records += 1;
|
|
47
33
|
}
|
|
34
|
+
return { records };
|
|
48
35
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AuditDisagreement, CheckDisagreement, PromotionRecord } from "./promote.js";
|
|
2
|
+
/** A check's disagreement with what it copied from its run blanked: its run id and which way the draft went (an answer,
|
|
3
|
+
* a hand-back, a failed step) and the fields it had wrong (the definition's names, no run text) and where each known
|
|
4
|
+
* answer came from kept, its input, the agent's answer, the draft's, the known answers' values and the grader's words
|
|
5
|
+
* gone. */
|
|
6
|
+
export declare const blankCheck: (one: CheckDisagreement) => CheckDisagreement;
|
|
7
|
+
/** An audit's disagreement blanked the same way: its run ids and whether a grade wrote it kept, its known answer empty. */
|
|
8
|
+
export declare const blankAudit: (one: AuditDisagreement) => AuditDisagreement;
|
|
9
|
+
/** `record` with what it copied from run `runId` blanked: each disagreement naming it (a check's agent run, a connected
|
|
10
|
+
* agent's collected turn too; an audit's served run or shadow run), and the grader's words its reason quotes from one
|
|
11
|
+
* (differentDecisionWords' example). Its decision, numbers and run ids stay. The record itself when it names no such
|
|
12
|
+
* disagreement. */
|
|
13
|
+
export declare function forgetRunIn(record: PromotionRecord, runId: string): PromotionRecord;
|
|
14
|
+
/** The runs whose copies `record` holds (forgetRunIn blanks them): each disagreement's run, a connected agent's collected
|
|
15
|
+
* turn's, an audit's served run and shadow run. */
|
|
16
|
+
export declare function runsNamedIn(record: PromotionRecord): string[];
|