@parcha/agentrun-serve 0.1.0-beta.43 → 0.1.0-beta.45
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 +231 -0
- package/README.md +580 -320
- package/dist/acp-package.d.ts +28 -0
- package/dist/acp-package.js +23 -0
- package/dist/adapter-facts.d.ts +8 -1
- package/dist/adapter-facts.js +9 -1
- package/dist/adapters.d.ts +5 -0
- package/dist/adapters.js +36 -3
- package/dist/agent-delete.d.ts +50 -0
- package/dist/agent-delete.js +125 -0
- package/dist/agents-store.d.ts +9 -3
- package/dist/agents-store.js +22 -8
- package/dist/agents.d.ts +5 -1
- package/dist/agents.js +8 -4
- package/dist/api-only.d.ts +8 -3
- package/dist/api-only.js +10 -4
- package/dist/archil-routes.d.ts +5 -1
- package/dist/archil-routes.js +57 -2
- package/dist/browser-wait-ended.d.ts +2 -0
- package/dist/browser-wait-ended.js +2 -0
- package/dist/calendar/ics-faux.d.ts +3 -1
- package/dist/calendar/ics-faux.js +12 -2
- package/dist/calendar/tools.js +5 -2
- package/dist/chatgpt-plan.js +3 -1
- package/dist/claude-login.d.ts +135 -0
- package/dist/claude-login.js +244 -0
- package/dist/cli.js +92 -22
- package/dist/composio-preset.d.ts +4 -3
- package/dist/composio-preset.js +81 -11
- package/dist/composio-triggers.d.ts +34 -2
- package/dist/composio-triggers.js +261 -31
- package/dist/computer-attach.d.ts +40 -5
- package/dist/computer-attach.js +130 -15
- package/dist/computer-keys.d.ts +3 -0
- package/dist/computer-keys.js +7 -1
- package/dist/computer-live.js +3 -2
- package/dist/computer-lost.d.ts +11 -0
- package/dist/computer-lost.js +19 -0
- package/dist/computer-record.d.ts +10 -2
- package/dist/computer-record.js +50 -18
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +2 -2
- package/dist/computers.d.ts +21 -10
- package/dist/computers.js +39 -28
- package/dist/console/assets/index-3O2Yl6hZ.js +701 -0
- package/dist/console/assets/index-DaFsZuzQ.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.d.ts +1 -1
- package/dist/dial-relay.d.ts +29 -0
- package/dist/dial-relay.js +94 -0
- package/dist/email/tools.js +10 -5
- package/dist/env-proxy.d.ts +2 -0
- package/dist/env-proxy.js +35 -0
- package/dist/errors.d.ts +4 -1
- package/dist/errors.js +10 -4
- package/dist/faux-computers.d.ts +8 -2
- package/dist/faux-computers.js +83 -6
- package/dist/harness-archive.d.ts +67 -0
- package/dist/harness-archive.js +177 -0
- package/dist/harness-goose.d.ts +34 -0
- package/dist/harness-goose.js +87 -0
- package/dist/harness-install.d.ts +21 -0
- package/dist/harness-install.js +24 -11
- package/dist/harness-opencode/adapter.js +1 -1
- package/dist/harness-table.d.ts +59 -3
- package/dist/harness-table.js +119 -14
- package/dist/harness.d.ts +17 -1
- package/dist/harness.js +22 -11
- package/dist/host.d.ts +12 -10
- package/dist/host.js +19 -16
- package/dist/import-worker.d.ts +3 -0
- package/dist/import-worker.js +7 -5
- package/dist/import.d.ts +22 -1
- package/dist/import.js +141 -28
- package/dist/key-check.js +3 -0
- package/dist/learn/audit.d.ts +6 -6
- package/dist/learn/audit.js +3 -7
- package/dist/learn/check.d.ts +26 -89
- package/dist/learn/check.js +58 -336
- package/dist/learn/commit.d.ts +63 -90
- package/dist/learn/commit.js +124 -316
- package/dist/learn/compile.d.ts +53 -50
- package/dist/learn/compile.js +88 -103
- package/dist/learn/corrections.d.ts +13 -0
- package/dist/learn/corrections.js +23 -0
- package/dist/learn/delete.d.ts +17 -0
- package/dist/learn/delete.js +42 -0
- package/dist/learn/folder.d.ts +35 -47
- package/dist/learn/folder.js +118 -134
- package/dist/learn/index.d.ts +3 -5
- package/dist/learn/index.js +6 -9
- package/dist/learn/learning.sh +45 -15
- package/dist/learn/promote.d.ts +20 -2
- package/dist/learn/promote.js +17 -4
- package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +34 -38
- package/dist/learn/{skills.js → workflow-draft.js} +65 -59
- package/dist/learn/workflow-nodes.d.ts +22 -1
- package/dist/learn/workflow-nodes.js +29 -10
- package/dist/learned-workflow.js +2 -2
- package/dist/learning-cost.d.ts +127 -13
- package/dist/learning-cost.js +142 -10
- package/dist/learning-routes.d.ts +99 -170
- package/dist/learning-routes.js +199 -420
- package/dist/learning-run.d.ts +19 -40
- package/dist/learning-run.js +23 -93
- package/dist/learning-setting.d.ts +4 -4
- package/dist/learning-setting.js +6 -6
- package/dist/learning-words.d.ts +28 -74
- package/dist/learning-words.js +64 -162
- package/dist/learning.d.ts +62 -393
- package/dist/learning.js +101 -651
- package/dist/listen-first.d.ts +30 -0
- package/dist/listen-first.js +115 -0
- package/dist/live-reach.d.ts +25 -2
- package/dist/live-reach.js +46 -4
- package/dist/llms.txt +2 -1
- package/dist/local-models.d.ts +3 -11
- package/dist/local-models.js +5 -6
- package/dist/mcp-servers-store.d.ts +16 -16
- package/dist/model-form.js +6 -5
- package/dist/model.d.ts +12 -4
- package/dist/model.js +41 -16
- package/dist/native/binding.js +1 -1
- package/dist/native/connection.js +1 -1
- package/dist/native/discovery.js +1 -1
- package/dist/native/instructions.d.ts +3 -0
- package/dist/native/instructions.js +5 -3
- package/dist/native/remote-worker-bridge.js +9 -43
- package/dist/native/remote.d.ts +8 -15
- package/dist/native/remote.js +3 -3
- package/dist/native/schema.js +1 -1
- package/dist/native/types.d.ts +2 -2
- package/dist/openapi.js +375 -347
- package/dist/owner.d.ts +8 -0
- package/dist/owner.js +11 -0
- package/dist/paid-calls.d.ts +14 -0
- package/dist/paid-calls.js +31 -1
- package/dist/particle-provider.d.ts +11 -0
- package/dist/particle-provider.js +135 -0
- package/dist/place.d.ts +8 -3
- package/dist/place.js +13 -9
- package/dist/port-models.d.ts +12 -4
- package/dist/port-models.js +28 -11
- package/dist/print.d.ts +27 -0
- package/dist/print.js +21 -0
- package/dist/provider.d.ts +7 -0
- package/dist/provider.js +30 -2
- package/dist/reflect-range.js +2 -3
- package/dist/run-launch.d.ts +14 -28
- package/dist/run-launch.js +9 -12
- package/dist/run-learning-served.d.ts +16 -90
- package/dist/run-listing.d.ts +34 -0
- package/dist/run-listing.js +128 -0
- package/dist/run-model-key.d.ts +64 -0
- package/dist/run-model-key.js +147 -0
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-trace.d.ts +97 -0
- package/dist/run-trace.js +253 -0
- package/dist/run-view.d.ts +15 -0
- package/dist/run-view.js +9 -0
- package/dist/runnable.js +2 -1
- package/dist/runner/adapter-loop.d.ts +14 -6
- package/dist/runner/adapter-loop.js +25 -14
- package/dist/runner/adapter-run-spec.d.ts +22 -7
- package/dist/runner/adapter-run-spec.js +130 -77
- package/dist/runner/adapters/index.d.ts +4 -2
- package/dist/runner/adapters/index.js +35 -4
- package/dist/runner/adapters/pi.d.ts +4 -12
- package/dist/runner/adapters/pi.js +2 -2
- package/dist/runner/audit.d.ts +5 -1
- package/dist/runner/audit.js +31 -12
- package/dist/runner/beside.d.ts +7 -2
- package/dist/runner/beside.js +41 -9
- package/dist/runner/claim-secrets.d.ts +66 -1
- package/dist/runner/claim-secrets.js +136 -3
- package/dist/runner/cli-run-spec.d.ts +2 -1
- package/dist/runner/cli-run-spec.js +82 -59
- package/dist/runner/commands.d.ts +3 -6
- package/dist/runner/conformance/harness.d.ts +6 -0
- package/dist/runner/conformance/harness.js +16 -5
- package/dist/runner/dispatch.d.ts +2 -2
- package/dist/runner/end-of-run.d.ts +6 -14
- package/dist/runner/end-of-run.js +8 -33
- package/dist/runner/feedback-round.d.ts +5 -4
- package/dist/runner/feedback-round.js +14 -10
- package/dist/runner/github-app.js +3 -1
- package/dist/runner/harness-loops.d.ts +0 -8
- package/dist/runner/harness-loops.js +30 -56
- package/dist/runner/held.d.ts +170 -0
- package/dist/runner/held.js +57 -0
- package/dist/runner/journal-kinds.d.ts +7 -3
- package/dist/runner/journal-kinds.js +2 -3
- package/dist/runner/learned-first.d.ts +40 -0
- package/dist/runner/learned-first.js +32 -0
- package/dist/runner/learning-end.d.ts +77 -66
- package/dist/runner/learning-end.js +250 -299
- package/dist/runner/learning-seed.d.ts +15 -33
- package/dist/runner/learning-seed.js +24 -45
- package/dist/runner/loop-contract.d.ts +8 -3
- package/dist/runner/loop-contract.js +4 -0
- package/dist/runner/loop.js +6 -2
- package/dist/runner/main.d.ts +18 -9
- package/dist/runner/main.js +82 -22
- package/dist/runner/mcp-run.d.ts +11 -0
- package/dist/runner/mcp-run.js +67 -0
- package/dist/runner/memory-claim.d.ts +14 -6
- package/dist/runner/memory-claim.js +18 -9
- package/dist/runner/model-route.d.ts +7 -4
- package/dist/runner/model-route.js +22 -10
- package/dist/runner/native-loop.d.ts +0 -7
- package/dist/runner/native-loop.js +9 -101
- package/dist/runner/promotion.d.ts +13 -6
- package/dist/runner/promotion.js +63 -17
- package/dist/runner/reflect-hook.d.ts +64 -91
- package/dist/runner/reflect-hook.js +112 -206
- package/dist/runner/run-channel.d.ts +43 -0
- package/dist/runner/run-channel.js +467 -0
- package/dist/runner/run-child-host.d.ts +169 -0
- package/dist/runner/run-child-host.js +1222 -0
- package/dist/runner/run-child.d.ts +1 -0
- package/dist/runner/run-child.js +254 -0
- package/dist/runner/run-errors.d.ts +2 -0
- package/dist/runner/run-errors.js +20 -0
- package/dist/runner/runner.js +58 -9
- package/dist/runner/sdk-ask.d.ts +78 -0
- package/dist/runner/sdk-ask.js +158 -0
- package/dist/runner/sdk-loop.d.ts +2 -4
- package/dist/runner/sdk-loop.js +29 -49
- package/dist/runner/store-secrets.d.ts +5 -3
- package/dist/runner/store-secrets.js +14 -6
- package/dist/runner/workflow-first.d.ts +5 -0
- package/dist/runner/workflow-first.js +4 -0
- package/dist/runner/workflow-spec.js +17 -4
- package/dist/runs-over-store.d.ts +21 -32
- package/dist/runs-over-store.js +44 -41
- package/dist/sdk/runs.d.ts +6 -11
- package/dist/sdk/runs.js +20 -41
- package/dist/sdk/schema.js +3 -4
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/seal-key.d.ts +5 -0
- package/dist/seal-key.js +7 -0
- package/dist/secrets.d.ts +3 -0
- package/dist/secrets.js +16 -3
- package/dist/server.d.ts +119 -83
- package/dist/server.js +1121 -419
- package/dist/sign-ins-store.d.ts +8 -0
- package/dist/sign-ins-store.js +36 -1
- package/dist/skills.js +1 -1
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.js +3 -0
- package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
- package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
- package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
- package/dist/store/schema.d.ts +53 -4
- package/dist/store/schema.js +137 -6
- package/dist/store/seal.d.ts +20 -2
- package/dist/store/seal.js +24 -8
- package/dist/store/sqlite/connection.d.ts +2 -0
- package/dist/store/sqlite/connection.js +3 -1
- package/dist/store/sqlite/run-launch.d.ts +4 -1
- package/dist/store/sqlite/run-launch.js +12 -0
- package/dist/store/sqlite/run-patch.d.ts +0 -17
- package/dist/store/sqlite/run-patch.js +4 -33
- package/dist/store/sqlite/store.d.ts +3 -2
- package/dist/store/sqlite/store.js +360 -75
- package/dist/store/sqlite/worker.js +25 -0
- package/dist/store/store.d.ts +231 -39
- package/dist/store/store.js +25 -3
- package/dist/store-reads/analytics.js +11 -1
- package/dist/store-reads/learning.d.ts +131 -194
- package/dist/store-reads/learning.js +292 -301
- package/dist/store-reads/loop.d.ts +0 -1
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-reads/stats.js +13 -3
- package/dist/store-view.d.ts +34 -2
- package/dist/store-view.js +108 -41
- package/dist/telemetry.d.ts +59 -0
- package/dist/telemetry.js +153 -0
- package/dist/template-eval.d.ts +3 -6
- package/dist/template-eval.js +22 -36
- package/dist/templates.d.ts +2 -1
- package/dist/templates.js +6 -3
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +5 -1
- package/dist/timeline/timeline.js +16 -0
- package/dist/tool-gate.d.ts +0 -7
- package/dist/tool-gate.js +1 -15
- package/dist/tool-keys-store.d.ts +1 -1
- package/dist/tool-keys.d.ts +6 -4
- package/dist/tool-keys.js +12 -6
- package/dist/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +13 -13
- package/dist/tools.js +29 -9
- package/dist/trigger-adapter.d.ts +3 -0
- package/dist/trigger-adapters.d.ts +4 -0
- package/dist/trigger-adapters.js +13 -0
- package/dist/trigger-composio.d.ts +58 -1
- package/dist/trigger-composio.js +160 -6
- package/dist/triggers.d.ts +64 -5
- package/dist/triggers.js +141 -17
- package/dist/validate.d.ts +11 -7
- package/dist/validate.js +9 -8
- package/dist/webhooks.d.ts +4 -1
- package/dist/webhooks.js +11 -4
- package/dist/workspace/agent-computer.d.ts +2 -0
- package/dist/workspace/agent-computer.js +2 -0
- package/dist/workspace/archil-claim.d.ts +7 -0
- package/dist/workspace/archil-claim.js +29 -0
- package/dist/workspace/archil.d.ts +9 -1
- package/dist/workspace/archil.js +165 -3
- package/dist/workspace/attach.d.ts +3 -1
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/attached-computers.d.ts +16 -5
- package/dist/workspace/attached-computers.js +25 -9
- package/dist/workspace/computer-deps.js +1 -1
- package/dist/workspace/computer-for-claim.d.ts +22 -8
- package/dist/workspace/computer-for-claim.js +339 -46
- package/dist/workspace/computer-hold.js +2 -1
- package/dist/workspace/computer-kept.d.ts +11 -1
- package/dist/workspace/computer-kept.js +24 -3
- package/dist/workspace/resolve-computer.d.ts +41 -21
- package/dist/workspace/resolve-computer.js +172 -64
- package/dist/workspace/revision-skills.d.ts +1 -2
- package/dist/workspace/revision-skills.js +3 -4
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +5 -0
- package/dist/workspace/synced-folder.d.ts +85 -0
- package/dist/workspace/synced-folder.js +230 -0
- package/dist/workspace/workspace.d.ts +4 -0
- package/launcher/agentrun-serve +1 -1
- package/package.json +10 -9
- package/templates/README.md +7 -7
- package/templates/inbound-lead/agent.md +3 -3
- package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
- package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
- package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
- package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
- package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
- package/templates/inbound-lead/lead.schema.json +6 -5
- package/templates/inbound-lead/rules/RUBRIC.md +4 -4
- package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
- package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
- package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
- package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
- package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
- package/templates/release-notes/evals/learned-style/case.yaml +4 -4
- package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
- package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
- package/templates/release-notes/evals/learned-style/prompt.md +1 -1
- package/dist/console/assets/index-BrcDSBD8.css +0 -1
- package/dist/console/assets/index-Bz6IWncl.js +0 -711
- package/dist/learn/grade.d.ts +0 -138
- package/dist/learn/grade.js +0 -682
- package/dist/learn/notes.d.ts +0 -81
- package/dist/learn/notes.js +0 -178
- package/dist/learn/reflect.d.ts +0 -77
- package/dist/learn/reflect.js +0 -228
- package/dist/learn/relevance.d.ts +0 -24
- package/dist/learn/relevance.js +0 -91
- package/dist/learn/seed-check.d.ts +0 -74
- package/dist/learn/seed-check.js +0 -103
- package/dist/learning-batch.d.ts +0 -291
- package/dist/learning-batch.js +0 -600
- package/dist/learning-evals.d.ts +0 -33
- package/dist/learning-evals.js +0 -98
- package/dist/native/context.d.ts +0 -6
- package/dist/native/context.js +0 -22
- package/dist/propose.d.ts +0 -52
- package/dist/propose.js +0 -224
- package/dist/runner/learning-ask.d.ts +0 -47
- package/dist/runner/learning-ask.js +0 -128
- package/dist/runner/learning-dispatch.d.ts +0 -45
- package/dist/runner/learning-dispatch.js +0 -99
- package/dist/runner/learning-factory.d.ts +0 -16
- package/dist/runner/learning-factory.js +0 -50
- package/dist/runner/learning-loop.d.ts +0 -273
- package/dist/runner/learning-loop.js +0 -521
- package/dist/usage.d.ts +0 -11
- package/dist/usage.js +0 -11
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
- package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
- package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
- package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
package/dist/learn/commit.js
CHANGED
|
@@ -1,340 +1,148 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// the main that won, as long as no oid the caller read (`graded`, `ifMatch`) changed: a change it did not see is a
|
|
6
|
-
// conflict, never written over. A folder with no main yet is made in the same call (the script's init first).
|
|
7
|
-
import { isHeld, held, retiredLearned, WORKFLOWS_DIR } from "./skills.js";
|
|
8
|
-
import { buildIndex, compiledInto, INDEX_FILE, INDEX_LINES, mergedNote, NOTE_FILE, parseNoteFile, ruleOf, supersede } from "./notes.js";
|
|
9
|
-
import { mergeProblems, supersededBy } from "./check.js";
|
|
10
|
-
import { FolderRefused, FolderTooLarge, readLearning, readRunDiff, readSnapshot, runDiffKey, snapshotNotes, textsAt, topOf, writeLearning } from "./folder.js";
|
|
11
|
-
/** The blob `path` is on the snapshot's main: the index, a note, a learned folder's file. */
|
|
1
|
+
import { CORRECTIONS_CAP, CORRECTIONS_FILE, correctionLine, correctionsProblems } from "./corrections.js";
|
|
2
|
+
import { blobOid, FolderMerged, FolderRefused, FolderTooLarge, readLearning, readRunDiff, readSnapshot, runDiffKey, runMergeOf, writeLearning } from "./folder.js";
|
|
3
|
+
import { held, isHeld } from "./workflow-draft.js";
|
|
4
|
+
/** The blob `path` is on the snapshot's main: corrections.md or a draft's file. */
|
|
12
5
|
function blobOf(snapshot, path) {
|
|
13
6
|
if (!snapshot)
|
|
14
7
|
return undefined;
|
|
15
|
-
if (path ===
|
|
16
|
-
return snapshot.
|
|
17
|
-
const
|
|
18
|
-
if (note)
|
|
19
|
-
return note.oid;
|
|
20
|
-
for (const item of [...snapshot.skills, ...snapshot.workflows]) {
|
|
8
|
+
if (path === CORRECTIONS_FILE)
|
|
9
|
+
return snapshot.corrections?.oid;
|
|
10
|
+
for (const item of snapshot.workflows) {
|
|
21
11
|
const file = item.files.find((one) => one.path === path);
|
|
22
12
|
if (file)
|
|
23
13
|
return file.oid;
|
|
24
14
|
}
|
|
25
15
|
return undefined;
|
|
26
16
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
if (path.endsWith("/SKILL.md") || path.endsWith("/README.md"))
|
|
36
|
-
return isHeld(text) ? text : held(text);
|
|
37
|
-
return text;
|
|
17
|
+
/** A write's failure as a result: the script's precondition (a file changed since the seed: a conflict), a write past
|
|
18
|
+
* what one exec carries, or the folder unavailable (retry later). */
|
|
19
|
+
function failure(error) {
|
|
20
|
+
if (error instanceof FolderRefused)
|
|
21
|
+
return { ok: false, reason: "conflict", problems: [...error.same, ...error.absent].map((path) => ({ rule: "kept", path, detail: `${path} changed on main after the run started` })) };
|
|
22
|
+
if (error instanceof FolderTooLarge)
|
|
23
|
+
return { ok: false, reason: "refused", problems: [{ rule: "too_large", detail: error.message }] };
|
|
24
|
+
return { ok: false, reason: "unavailable", error: error?.message ?? String(error) };
|
|
38
25
|
}
|
|
26
|
+
/** What a write landed, from writeLearning's answer: its new main and the paths it changed. */
|
|
27
|
+
const landed = (done) => "pending" in done.result
|
|
28
|
+
? { 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 } : {}) }
|
|
29
|
+
: done.result;
|
|
39
30
|
/**
|
|
40
|
-
*
|
|
41
|
-
* `ok` with the new main
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
31
|
+
* A run's merge on the folder's main, one exec of the learning script: its files (a held README with `status: pending`)
|
|
32
|
+
* and its owner's correction appended to corrections.md. `ok` with the new main and the paths the commit changed;
|
|
33
|
+
* `conflict` when a file is not on main as it was on the run's seed; `refused` when the correction holds what must never
|
|
34
|
+
* be stored, or, with no draft beside it, would take corrections.md past its cap (nothing written); `unavailable` when
|
|
35
|
+
* the workspace or the exec failed. The draft and the correction are judged apart: a correction past the cap beside a
|
|
36
|
+
* draft (the file filled by another write after the run's check, correctionRefused) is left out alone, and the draft
|
|
37
|
+
* merges, `ok` with the cap's refusal as `refusedCorrection`. A merge whose run already merged here (this round) is `ok`
|
|
38
|
+
* with the commit that holds it, and writes nothing: checked before the write, again on each main it is computed on, and
|
|
39
|
+
* by the script in the commit's own ref transaction, so two calls racing for one round (a reclaimed run) merge it once.
|
|
45
40
|
*/
|
|
46
41
|
export async function learningCommit(ws, change, opts = {}) {
|
|
42
|
+
const key = runDiffKey(change.runId, change.round);
|
|
47
43
|
try {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
44
|
+
const known = await runMergeOf(ws, change.runId, change.round);
|
|
45
|
+
if (known)
|
|
46
|
+
return await already(ws, change, known.merge, known);
|
|
47
|
+
const line = change.correction === undefined ? undefined : correctionLine(change.correction);
|
|
48
|
+
// The line alone first: what it holds is refused whatever the file around it holds.
|
|
49
|
+
const own = line === undefined ? [] : correctionProblems(line, change.refuseValues);
|
|
50
|
+
if (own.length)
|
|
51
|
+
return { ok: false, reason: "refused", problems: own };
|
|
52
|
+
const marked = new Set(change.held ?? []);
|
|
53
|
+
const drafts = change.files.map(({ path, text }) => ({ path, text: marked.has(path) && !isHeld(text) ? held(text) : text }));
|
|
54
|
+
const same = change.files.flatMap(({ path }) => {
|
|
55
|
+
const commit = change.bases?.[path] ?? change.seed;
|
|
56
|
+
return commit ? [{ commit, path }] : [];
|
|
57
|
+
});
|
|
58
|
+
const done = await writeLearning(ws, async ({ snapshot, body }) => {
|
|
59
|
+
// Read again on each main the write is computed on: a call that merged this round since the check above (a
|
|
60
|
+
// reclaimed run's two claims racing) wrote its diff before the snapshot this call read.
|
|
61
|
+
const merged = await readRunDiff(ws, key);
|
|
62
|
+
if (merged)
|
|
63
|
+
return { result: { merged } };
|
|
64
|
+
const writes = [...drafts];
|
|
65
|
+
let refusedCorrection;
|
|
66
|
+
if (line !== undefined) {
|
|
67
|
+
const text = appended(await correctionsOf(snapshot, body), line);
|
|
68
|
+
const full = capProblem(text);
|
|
69
|
+
if (full && !drafts.length)
|
|
70
|
+
return { result: { ok: false, reason: "refused", problems: [full] } };
|
|
71
|
+
if (full)
|
|
72
|
+
refusedCorrection = [full];
|
|
73
|
+
else
|
|
74
|
+
writes.push({ path: CORRECTIONS_FILE, text });
|
|
61
75
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const left = done.result.left?.length ? { left: done.result.left } : {};
|
|
67
|
-
return { ok: true, main: done.main, commit: done.main, files: done.snapshot?.log[0]?.commit === done.main ? done.snapshot.log[0].files : [], ...left };
|
|
76
|
+
return { result: { pending: true, ...(refusedCorrection ? { refusedCorrection } : {}) }, change: { by: run(change.runId, change.reason, change.round), writes, ...(same.length ? { same } : {}) } };
|
|
77
|
+
}, opts.retries ?? 3);
|
|
78
|
+
const { result } = done;
|
|
79
|
+
return "merged" in result ? await already(ws, change, result.merged.merge, result.merged) : landed({ ...done, result });
|
|
68
80
|
}
|
|
69
81
|
catch (error) {
|
|
70
|
-
// The
|
|
71
|
-
//
|
|
72
|
-
if (error instanceof
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return { ok: false, reason: "refused", problems: error.absent.map((path) => ({ rule: "exists", path, detail: "the folder has a note by this name" })) };
|
|
76
|
-
}
|
|
77
|
-
if (error instanceof FolderTooLarge)
|
|
78
|
-
return { ok: false, reason: "refused", problems: [{ rule: "too_large", detail: error.message }] };
|
|
79
|
-
return { ok: false, reason: "unavailable", error: error?.message ?? String(error) };
|
|
82
|
+
// The round merged under this call past both reads (its diff not written yet): the script's ref transaction let
|
|
83
|
+
// one merge of it land, and this call reads that one.
|
|
84
|
+
if (error instanceof FolderMerged)
|
|
85
|
+
return already(ws, change, error.merge, await readRunDiff(ws, key).catch(() => undefined)).catch(failure);
|
|
86
|
+
return failure(error);
|
|
80
87
|
}
|
|
81
88
|
}
|
|
82
|
-
/** A
|
|
83
|
-
*
|
|
84
|
-
async function
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
const leftOut = new Set(left.map(({ path }) => path));
|
|
89
|
-
// Each new note as main keeps it (mergedNote): its own origin, `status: pending` when held, the run's risky mark gone.
|
|
90
|
-
// A skill's SKILL.md or a draft's README.md held: `status: pending` last in its front matter.
|
|
91
|
-
const files = new Map(change.files.filter(({ path }) => !leftOut.has(path)).map(({ path, text }) => {
|
|
92
|
-
if (isNote(path) && blobOf(snapshot, path) === undefined) {
|
|
93
|
-
const note = parseNoteFile(path, text);
|
|
94
|
-
return [path, Array.isArray(note) ? text : mergedNote(text, { origin: note.origin, pending: held.has(path) })];
|
|
95
|
-
}
|
|
96
|
-
return [path, held.has(path) ? heldText(path, text) : text];
|
|
97
|
-
}));
|
|
98
|
-
// Each re-filed skill main holds, not retired, retired in this write (`retire`), unless its note was left out as taken.
|
|
99
|
-
const retiring = [];
|
|
100
|
-
// The rules main's active notes hold now, apart from the notes this merge supersedes: a skill retires only while its rule
|
|
101
|
-
// has an active note, the re-filed note written here or another main holds as this merge commits (a person may have
|
|
102
|
-
// edited or retired it since the grade read main), so the rule is never left with no active copy.
|
|
103
|
-
const superseding = new Set([...(change.supersede ?? []).map(({ path }) => path), ...[...files].filter(([path]) => isNote(path) && !held.has(path)).flatMap(([path, text]) => {
|
|
104
|
-
const one = parseNoteFile(path, text);
|
|
105
|
-
return Array.isArray(one) ? [] : one.supersedes;
|
|
106
|
-
})]);
|
|
107
|
-
const holding = new Set();
|
|
108
|
-
if (change.retire?.length) {
|
|
109
|
-
for (const one of snapshotNotes(snapshot).filter((note) => note.status === "active" && !superseding.has(note.file))) {
|
|
110
|
-
const text = parseNoteFile(one.file, await body(one.file, blobOf(snapshot, one.file)));
|
|
111
|
-
if (!Array.isArray(text))
|
|
112
|
-
holding.add(ruleOf(text.body));
|
|
113
|
-
}
|
|
114
|
-
for (const [path, text] of files) {
|
|
115
|
-
// A replacement written here counts held or not: a pending note retires its skill as before (the owner's OK makes it
|
|
116
|
-
// the rule); only one that is not written at all (left out, or gone from main) must find another holder.
|
|
117
|
-
const one = isNote(path) ? parseNoteFile(path, text) : undefined;
|
|
118
|
-
if (one && !Array.isArray(one))
|
|
119
|
-
holding.add(ruleOf(one.body));
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
for (const { skill, note, rule } of change.retire ?? []) {
|
|
123
|
-
if (left.some((one) => one.path === note && one.reason === "taken"))
|
|
124
|
-
continue;
|
|
125
|
-
if (!holding.has(rule))
|
|
126
|
-
continue;
|
|
127
|
-
const oid = blobOf(snapshot, skill);
|
|
128
|
-
const item = snapshot?.skills.find((one) => one.files.some((file) => file.path === skill));
|
|
129
|
-
if (oid === undefined || !item || item.status === "retired")
|
|
130
|
-
continue;
|
|
131
|
-
files.set(skill, retiredLearned(await body(skill, oid)));
|
|
132
|
-
retiring.push(skill);
|
|
133
|
-
}
|
|
134
|
-
// Nothing left to write: every new note is one main holds already, or a name it holds. No commit.
|
|
135
|
-
if (![...files.keys()].length)
|
|
136
|
-
return { result: { ok: true, main: snapshot?.main ?? "", commit: snapshot?.main ?? "", files: [], left } };
|
|
137
|
-
const notes = snapshotNotes(snapshot);
|
|
138
|
-
const active = new Set(notes.filter((note) => note.status === "active").map((note) => note.file));
|
|
139
|
-
const refused = [];
|
|
140
|
-
const fresh = [...files].filter(([path]) => isNote(path) && (blobOf(snapshot, path) === undefined || replaced.has(path))).flatMap(([path, text]) => {
|
|
141
|
-
const note = parseNoteFile(path, text);
|
|
142
|
-
return Array.isArray(note) ? [] : [note];
|
|
143
|
-
});
|
|
144
|
-
// A note written over main's by its own name supersedes that note by being it: never a mark of itself.
|
|
145
|
-
const marks = change.supersede ?? [...supersededBy(fresh)].filter(([path, by]) => path !== by).map(([path, by]) => ({ path, by }));
|
|
146
|
-
// The verdict was on the blobs the grade read: one this merge would write (mark or replace) that is another blob on
|
|
147
|
-
// main now is the caller's conflict, named by the note that would mark it. One it leaves alone (a held note marks
|
|
148
|
-
// nothing) is not written over, so it stands.
|
|
149
|
-
const touched = new Set([...marks.map((mark) => mark.path), ...change.files.map(({ path }) => path)]);
|
|
150
|
-
const conflicts = Object.entries(change.graded).filter(([path, oid]) => touched.has(path) && blobOf(snapshot, path) !== oid).map(([path]) => ({ rule: "supersedes", path: marks.find((mark) => mark.path === path)?.by ?? path, detail: `${path} changed after the grade read it` }));
|
|
151
|
-
if (conflicts.length)
|
|
152
|
-
return { result: { ok: false, reason: "conflict", problems: conflicts } };
|
|
153
|
-
for (const { path, by } of marks) {
|
|
154
|
-
if (!active.has(path))
|
|
155
|
-
refused.push({ rule: "supersedes", path: by, detail: `it supersedes ${path}, which is not an active note` });
|
|
156
|
-
else
|
|
157
|
-
files.set(path, supersede(await body(path, blobOf(snapshot, path)), by));
|
|
158
|
-
}
|
|
159
|
-
// The notes the merge's compiled workflow does the work of, marked: an active one this merge writes nothing else to
|
|
160
|
-
// (a note it supersedes is no longer one to serve), its text on main as it is now. One gone or not active is left alone.
|
|
161
|
-
const compiledMarks = new Set();
|
|
162
|
-
if (change.compiled && files.has(`${WORKFLOWS_DIR}/${change.compiled.workflow}/workflow.json`)) {
|
|
163
|
-
for (const path of change.compiled.notes) {
|
|
164
|
-
if (!active.has(path) || files.has(path))
|
|
165
|
-
continue;
|
|
166
|
-
files.set(path, compiledInto(await body(path, blobOf(snapshot, path)), change.compiled.workflow));
|
|
167
|
-
compiledMarks.add(path);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
const added = [];
|
|
171
|
-
const written = [];
|
|
172
|
-
for (const [path, text] of files) {
|
|
173
|
-
if (!isNote(path))
|
|
174
|
-
continue;
|
|
175
|
-
const note = parseNoteFile(path, text);
|
|
176
|
-
if (Array.isArray(note)) {
|
|
177
|
-
refused.push({ rule: "note", path, detail: note.join("; ") });
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
written.push(note);
|
|
181
|
-
// A merge adds notes and marks the ones they supersede: it never writes over another note main holds.
|
|
182
|
-
if (blobOf(snapshot, path) === undefined)
|
|
183
|
-
added.push(note);
|
|
184
|
-
else if (!marks.some((one) => one.path === path) && !replaced.has(path) && !compiledMarks.has(path))
|
|
185
|
-
refused.push({ rule: "exists", path, detail: "the folder has a note by this name" });
|
|
186
|
-
}
|
|
187
|
-
// mergeProblems asks of the new notes what a merge always asks: a free name, what they supersede active and named
|
|
188
|
-
// once, the index's lines.
|
|
189
|
-
if (!refused.length)
|
|
190
|
-
refused.push(...mergeProblems({ files: topOf(snapshot), active: notes.filter((note) => note.status === "active") }, added));
|
|
191
|
-
if (refused.length)
|
|
192
|
-
return { result: { ok: false, reason: "refused", problems: refused } };
|
|
193
|
-
const marked = new Set(written.map((note) => note.file));
|
|
194
|
-
files.set(INDEX_FILE, buildIndex([...notes.filter((note) => !marked.has(note.file)), ...written]));
|
|
195
|
-
return {
|
|
196
|
-
result: { pending: true, ...(left.length ? { left } : {}) },
|
|
197
|
-
change: {
|
|
198
|
-
by: { run: change.runId, reason: change.reason, ...(change.round !== undefined && change.round > 1 ? { round: change.round } : {}) },
|
|
199
|
-
writes: [...files].map(([path, text]) => ({ path, text })),
|
|
200
|
-
absent: added.map((note) => note.file),
|
|
201
|
-
...(change.seed || change.bases ? { same: [...change.files.filter(({ path }) => !isNote(path)).map(({ path }) => path), ...retiring].flatMap((path) => {
|
|
202
|
-
const commit = change.bases?.[path] ?? change.seed;
|
|
203
|
-
return commit ? [{ commit, path }] : [];
|
|
204
|
-
}) } : {}),
|
|
205
|
-
},
|
|
206
|
-
};
|
|
89
|
+
/** A round that merged already, `merge` its commit: `ok` with it and the paths its diff names (none when its diff is
|
|
90
|
+
* not written yet), nothing written again. Its merge left the correction out only at the cap. */
|
|
91
|
+
async function already(ws, change, merge, known) {
|
|
92
|
+
const left = known !== undefined && change.correction !== undefined && !known.files.some((file) => file.path === CORRECTIONS_FILE);
|
|
93
|
+
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` }] : [];
|
|
94
|
+
return { ok: true, main: (await readSnapshot(ws))?.main ?? merge, commit: merge, files: known ? known.files.map((file) => file.path) : [], already: true, ...(refusedCorrection.length ? { refusedCorrection } : {}) };
|
|
207
95
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
if (!going.has(note.file))
|
|
235
|
-
rules.set(ruleOf(text.body), note.file);
|
|
236
|
-
}
|
|
237
|
-
for (const { path, text } of newNotes) {
|
|
238
|
-
const note = parseNoteFile(path, text);
|
|
239
|
-
if (Array.isArray(note))
|
|
240
|
-
continue;
|
|
241
|
-
const rule = ruleOf(note.body);
|
|
242
|
-
const onMain = blobOf(snapshot, path);
|
|
243
|
-
if (onMain !== undefined && !replaced.has(path)) {
|
|
244
|
-
const theirs = parseNoteFile(path, await body(path, onMain));
|
|
245
|
-
// The same rule only when main's note keeps it active: a retired or superseded one is a name main holds.
|
|
246
|
-
left.push({ path, reason: !Array.isArray(theirs) && theirs.status === "active" && ruleOf(theirs.body) === rule ? "same" : "taken" });
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
const holder = rules.get(rule);
|
|
250
|
-
if (holder !== undefined && holder !== path && !note.supersedes.includes(holder)) {
|
|
251
|
-
const original = onMainRules.get(rule);
|
|
252
|
-
// An update of the rule's holder on main, after a copy of it: the update holds the rule, the copy is the repeat.
|
|
253
|
-
if (original === undefined || holder === original || !note.supersedes.includes(original) || held.has(path)) {
|
|
254
|
-
left.push({ path, reason: "same" });
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
left.push({ path: holder, reason: "same" });
|
|
258
|
-
}
|
|
259
|
-
rules.set(rule, path);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return left;
|
|
263
|
-
}
|
|
264
|
-
/** A person's write on main as the snapshot has it: the file and what the action also changes, MEMORY.md rebuilt. */
|
|
265
|
-
async function personOf(change, snapshot) {
|
|
266
|
-
const current = blobOf(snapshot, change.file);
|
|
267
|
-
const seen = change.ifMatch?.replace(/^"|"$/g, "") ?? null;
|
|
268
|
-
if (change.action === "created" ? current !== undefined : seen === null || current !== seen) {
|
|
269
|
-
return { result: { ok: false, reason: "conflict", problems: [{ rule: change.action === "created" ? "exists" : "supersedes", path: change.file, detail: current === undefined ? `${change.file} is not on main` : change.action === "created" ? "the folder has a note by this name" : `${change.file} changed since it was read` }] } };
|
|
270
|
-
}
|
|
271
|
-
const writes = [{ path: change.file, text: change.text }, ...(change.also ?? [])];
|
|
272
|
-
const changed = new Map(writes.filter(({ path }) => isNote(path)).map(({ path, text }) => [path, parseNoteFile(path, text)]));
|
|
273
|
-
const refused = [...changed].filter(([, note]) => Array.isArray(note)).map(([path, note]) => ({ rule: "note", path, detail: note.join("; ") }));
|
|
274
|
-
if (refused.length)
|
|
275
|
-
return { result: { ok: false, reason: "refused", problems: refused } };
|
|
276
|
-
const after = [...snapshotNotes(snapshot).filter((note) => !changed.has(note.file)), ...[...changed.values()]];
|
|
277
|
-
const lines = after.filter((note) => note.status === "active").length;
|
|
278
|
-
if (lines > INDEX_LINES)
|
|
279
|
-
return { result: { ok: false, reason: "refused", problems: [{ rule: "index_full", detail: `the index would hold ${lines} lines; it holds at most ${INDEX_LINES}, so retire a note first` }] } };
|
|
280
|
-
return {
|
|
281
|
-
result: { pending: true },
|
|
282
|
-
change: { by: { person: change.action, file: change.file, approved: change.via === "console" }, writes: [...writes, { path: INDEX_FILE, text: buildIndex(after) }], ...(change.action === "created" ? { absent: [change.file] } : {}) },
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
/** The texts main holds at `paths`, each a note's file, by path: one main holds no note at is not in it. From the
|
|
286
|
-
* folder's snapshot and its bodies: no git, no exec. What a skill the grader re-filed as a note (grade.ts skillAsNote)
|
|
287
|
-
* would be written over, read before its merge. */
|
|
288
|
-
export async function mainTexts(ws, paths) {
|
|
289
|
-
if (!paths.length)
|
|
290
|
-
return {};
|
|
291
|
-
return readLearning(ws, async ({ snapshot, body }) => {
|
|
292
|
-
const oids = new Map((snapshot?.notes ?? []).map((note) => [note.file, note.oid]));
|
|
293
|
-
const held = paths.filter((path) => oids.has(path));
|
|
294
|
-
return Object.fromEntries(await Promise.all(held.map(async (path) => [path, await body(path, oids.get(path))])));
|
|
295
|
-
});
|
|
96
|
+
const run = (runId, reason, round) => ({ run: runId, reason, ...(round !== undefined && round > 1 ? { round } : {}) });
|
|
97
|
+
/** corrections.md's text as main holds it now ("" when it holds none). */
|
|
98
|
+
const correctionsOf = async (snapshot, body) => snapshot?.corrections ? body(CORRECTIONS_FILE, snapshot.corrections.oid) : "";
|
|
99
|
+
/** corrections.md's text `before` with `line` appended on a line of its own. */
|
|
100
|
+
const appended = (before, line) => `${before}${before && !before.endsWith("\n") ? "\n" : ""}${line}`;
|
|
101
|
+
/** What a correction's line holds that must never be stored, whatever the file around it holds. */
|
|
102
|
+
const correctionProblems = (line, refuseValues) => correctionsProblems(line, refuseValues).filter((problem) => problem.rule !== "too_large");
|
|
103
|
+
/** The cap's refusal of corrections.md as `text`, in its words; none within the cap. */
|
|
104
|
+
const capProblem = (text) => {
|
|
105
|
+
const bytes = Buffer.byteLength(text, "utf8");
|
|
106
|
+
return bytes > CORRECTIONS_CAP ? { rule: "too_large", path: CORRECTIONS_FILE, detail: `${CORRECTIONS_FILE} would hold ${bytes} bytes; the cap is ${CORRECTIONS_CAP} bytes` } : undefined;
|
|
107
|
+
};
|
|
108
|
+
/** Why run `runId`'s correction (`text`) would be refused on main as it is now: its line's own problems, else the cap's;
|
|
109
|
+
* empty when it would be taken. Read before the run's merge, so a refused correction never holds its draft back. A
|
|
110
|
+
* round (`merge`) whose merge is on main already (a stop after its commit, before the run's end was saved) is never
|
|
111
|
+
* checked for room again, its own line counted twice: empty, and its merge (learningCommit) gives back what it did. */
|
|
112
|
+
export async function correctionRefused(ws, text, refuseValues, merge) {
|
|
113
|
+
const line = correctionLine(text);
|
|
114
|
+
const own = correctionProblems(line, refuseValues);
|
|
115
|
+
if (own.length)
|
|
116
|
+
return own;
|
|
117
|
+
if (merge && (await runMergeOf(ws, merge.runId, merge.round)))
|
|
118
|
+
return [];
|
|
119
|
+
const before = await readLearning(ws, ({ snapshot, body }) => correctionsOf(snapshot, body));
|
|
120
|
+
const full = capProblem(appended(before, line));
|
|
121
|
+
return full ? [full] : [];
|
|
296
122
|
}
|
|
297
|
-
/**
|
|
298
|
-
* `
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
export async function
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
return undefined;
|
|
305
|
-
const texts = await textsAt(ws, diff.merge, paths);
|
|
306
|
-
if (!texts)
|
|
307
|
-
throw new Error(`the run's merge ${diff.merge} is not in the learning folder`);
|
|
308
|
-
return { texts };
|
|
123
|
+
/** One line of an owner's feedback appended to corrections.md on main, by run `runId`'s merge (learningCommit's
|
|
124
|
+
* `correction`, with no draft beside it). */
|
|
125
|
+
export const appendCorrection = (ws, input) => learningCommit(ws, { runId: input.runId, ...(input.round !== undefined ? { round: input.round } : {}), reason: "the owner's correction", files: [], correction: input.text, ...(input.refuseValues ? { refuseValues: input.refuseValues } : {}) });
|
|
126
|
+
/** corrections.md as a person reads it: its text and its ETag's blob (an empty file's when main holds none). */
|
|
127
|
+
export async function readCorrections(snapshot, body) {
|
|
128
|
+
const text = await correctionsOf(snapshot, body);
|
|
129
|
+
return { text, oid: snapshot?.corrections?.oid ?? blobOid("") };
|
|
309
130
|
}
|
|
310
|
-
/**
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
const
|
|
317
|
-
if (
|
|
318
|
-
return {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
const taken = [];
|
|
326
|
-
for (const note of added) {
|
|
327
|
-
if (!oids.has(note.file))
|
|
328
|
-
continue;
|
|
329
|
-
const theirs = parseNoteFile(note.file, await body(note.file, oids.get(note.file)));
|
|
330
|
-
taken.push({ path: note.file, reason: !Array.isArray(theirs) && theirs.status === "active" && ruleOf(theirs.body) === ruleOf(note.body) ? "same" : "taken" });
|
|
331
|
-
}
|
|
332
|
-
const notes = added.filter((note) => !oids.has(note.file));
|
|
333
|
-
const problems = mergeProblems({ files: topOf(snapshot), active: main.filter((note) => note.status === "active") }, notes);
|
|
334
|
-
if (problems.length)
|
|
335
|
-
return { problems };
|
|
336
|
-
// mergeProblems passed: each note superseded is active on main, and named once.
|
|
337
|
-
const superseded = await Promise.all(notes.flatMap((note) => note.supersedes).map(async (file) => ({ file, text: await body(file, oids.get(file)) })));
|
|
338
|
-
return { active: main.filter((note) => note.status === "active").map(({ file, name, description }) => ({ file, name, description })), superseded, graded: Object.fromEntries(superseded.map(({ file }) => [file, oids.get(file)])), ...(taken.length ? { taken } : {}) };
|
|
131
|
+
/**
|
|
132
|
+
* corrections.md replaced whole by a person: `ifMatch`, the blob they read (an ETag, quoted or not; an empty file's when
|
|
133
|
+
* main held none), must be main's now, else a conflict. Refused, nothing written, as appendCorrection refuses. `ok` with
|
|
134
|
+
* the new text and its blob.
|
|
135
|
+
*/
|
|
136
|
+
export async function putCorrections(ws, input) {
|
|
137
|
+
const problems = correctionsProblems(input.text, input.refuseValues);
|
|
138
|
+
if (problems.length)
|
|
139
|
+
return { ok: false, reason: "refused", problems };
|
|
140
|
+
const seen = input.ifMatch.trim().replace(/^W\//, "").replace(/^"|"$/g, "");
|
|
141
|
+
const { result } = await writeLearning(ws, async ({ snapshot }) => {
|
|
142
|
+
const now = snapshot?.corrections?.oid ?? blobOid("");
|
|
143
|
+
if (now !== seen)
|
|
144
|
+
return { result: { ok: false, reason: "conflict", problems: [{ rule: "kept", path: CORRECTIONS_FILE, detail: `${CORRECTIONS_FILE} changed since it was read` }] } };
|
|
145
|
+
return { result: { ok: true, text: input.text, oid: blobOid(input.text) }, change: { by: { person: "edited", file: CORRECTIONS_FILE }, writes: [{ path: CORRECTIONS_FILE, text: input.text }] } };
|
|
339
146
|
});
|
|
147
|
+
return result;
|
|
340
148
|
}
|