@parcha/agentrun-serve 0.1.0-beta.44 → 0.1.0-beta.46
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 +148 -5
- package/README.md +385 -305
- 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 +62 -19
- package/dist/composio-preset.js +69 -7
- package/dist/composio-triggers.d.ts +14 -0
- package/dist/composio-triggers.js +79 -15
- 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/computers.d.ts +21 -10
- package/dist/computers.js +39 -28
- package/dist/console/assets/index-C2MYaUBa.css +1 -0
- package/dist/console/assets/index-CZZeCReB.js +701 -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 +3 -1
- package/dist/errors.js +7 -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 +9 -1
- package/dist/harness-table.js +20 -3
- package/dist/harness.d.ts +1 -2
- package/dist/harness.js +3 -4
- package/dist/host.js +2 -1
- package/dist/import.d.ts +10 -0
- package/dist/import.js +28 -8
- 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 +23 -89
- package/dist/learn/check.js +57 -335
- 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 +89 -104
- package/dist/learn/corrections.d.ts +13 -0
- package/dist/learn/corrections.js +23 -0
- package/dist/learn/delete.d.ts +5 -5
- package/dist/learn/delete.js +8 -10
- 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 +23 -5
- package/dist/learn/promote.js +40 -2
- package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +30 -38
- package/dist/learn/{skills.js → workflow-draft.js} +48 -58
- package/dist/learn/workflow-nodes.js +1 -1
- package/dist/learned-workflow.js +2 -2
- package/dist/learning-cost.d.ts +38 -24
- package/dist/learning-cost.js +41 -24
- package/dist/learning-routes.d.ts +91 -170
- package/dist/learning-routes.js +183 -421
- package/dist/learning-run.d.ts +19 -40
- package/dist/learning-run.js +23 -93
- package/dist/learning-setting.d.ts +21 -10
- package/dist/learning-setting.js +47 -11
- package/dist/learning-words.d.ts +28 -74
- package/dist/learning-words.js +64 -162
- package/dist/learning.d.ts +61 -392
- package/dist/learning.js +101 -651
- package/dist/live-reach.d.ts +25 -2
- package/dist/live-reach.js +46 -4
- package/dist/llms.txt +1 -1
- package/dist/local-models.d.ts +3 -11
- package/dist/local-models.js +5 -6
- package/dist/mcp-servers-store.d.ts +4 -4
- package/dist/model-form.js +6 -5
- package/dist/model.d.ts +4 -0
- package/dist/model.js +26 -9
- 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 +273 -319
- package/dist/paid-calls.d.ts +8 -0
- package/dist/paid-calls.js +20 -0
- package/dist/particle-provider.d.ts +11 -0
- package/dist/particle-provider.js +135 -0
- 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 +15 -1
- 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 +15 -89
- package/dist/run-listing.d.ts +34 -0
- package/dist/run-listing.js +128 -0
- package/dist/run-model-key.js +1 -1
- 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 +8 -6
- package/dist/runner/adapter-loop.js +16 -12
- package/dist/runner/adapter-run-spec.d.ts +16 -4
- package/dist/runner/adapter-run-spec.js +64 -58
- package/dist/runner/adapters/index.js +22 -0
- package/dist/runner/adapters/pi.d.ts +4 -12
- package/dist/runner/adapters/pi.js +2 -2
- package/dist/runner/audit.d.ts +1 -1
- package/dist/runner/audit.js +30 -13
- package/dist/runner/beside.d.ts +6 -2
- package/dist/runner/beside.js +38 -9
- package/dist/runner/claim-secrets.d.ts +18 -2
- package/dist/runner/claim-secrets.js +42 -18
- package/dist/runner/cli-run-spec.js +55 -51
- package/dist/runner/conformance/harness.d.ts +6 -0
- package/dist/runner/conformance/harness.js +35 -13
- package/dist/runner/conformance/subject.d.ts +6 -0
- 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 +2 -2
- package/dist/runner/feedback-round.js +7 -7
- package/dist/runner/github-app.js +3 -1
- package/dist/runner/harness-loops.d.ts +0 -8
- package/dist/runner/harness-loops.js +11 -59
- package/dist/runner/held.d.ts +170 -0
- package/dist/runner/held.js +57 -0
- package/dist/runner/journal-kinds.d.ts +2 -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 -69
- package/dist/runner/learning-end.js +250 -303
- package/dist/runner/learning-seed.d.ts +15 -33
- package/dist/runner/learning-seed.js +24 -45
- package/dist/runner/loop-contract.d.ts +2 -3
- package/dist/runner/main.d.ts +17 -9
- package/dist/runner/main.js +82 -20
- package/dist/runner/mcp-run.d.ts +11 -0
- package/dist/runner/mcp-run.js +67 -0
- package/dist/runner/memory-claim.d.ts +10 -5
- package/dist/runner/memory-claim.js +12 -6
- 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 +12 -8
- package/dist/runner/promotion.js +37 -28
- package/dist/runner/reflect-hook.d.ts +64 -95
- package/dist/runner/reflect-hook.js +112 -225
- 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 +1230 -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 +1 -5
- 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 +5 -1
- package/dist/runner/workflow-first.d.ts +5 -0
- package/dist/runner/workflow-first.js +4 -0
- package/dist/runner/workflow-spec.js +7 -2
- package/dist/runs-over-store.d.ts +16 -28
- package/dist/runs-over-store.js +31 -38
- package/dist/sdk/runs.d.ts +6 -11
- package/dist/sdk/runs.js +20 -41
- package/dist/sdk/schema.js +3 -4
- 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 +55 -33
- package/dist/server.js +689 -322
- 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 +2 -2
- package/dist/store/index.js +1 -1
- 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/sqlite/connection.d.ts +2 -0
- package/dist/store/sqlite/connection.js +3 -1
- package/dist/store/sqlite/run-patch.d.ts +0 -17
- package/dist/store/sqlite/run-patch.js +4 -33
- package/dist/store/sqlite/store.js +246 -63
- package/dist/store/sqlite/worker.js +25 -0
- package/dist/store/store.d.ts +193 -36
- package/dist/store/store.js +25 -3
- package/dist/store-reads/learning.d.ts +102 -204
- package/dist/store-reads/learning.js +159 -321
- package/dist/store-reads/loop.d.ts +0 -1
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-view.d.ts +29 -1
- package/dist/store-view.js +97 -31
- package/dist/template-eval.d.ts +3 -6
- package/dist/template-eval.js +22 -36
- package/dist/templates.d.ts +8 -4
- package/dist/templates.js +44 -6
- 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/tools.d.ts +2 -2
- package/dist/tools.js +11 -4
- package/dist/triggers.d.ts +65 -6
- package/dist/triggers.js +125 -19
- package/dist/validate.js +1 -1
- package/dist/webhooks.d.ts +7 -2
- package/dist/webhooks.js +12 -5
- 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 +7 -3
- package/dist/workspace/computer-for-claim.js +119 -22
- 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 +33 -19
- 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 -10
- package/templates/README.md +8 -8
- package/templates/inbound-lead/agent.md +5 -4
- 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/kyb/agent.md +2 -1
- 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-BUktRvS-.css +0 -1
- package/dist/console/assets/index-nB9kTfIN.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 -35
- package/dist/learning-evals.js +0 -99
- 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
|
@@ -1,37 +1,30 @@
|
|
|
1
|
-
// The learning lane's end-of-run
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// (`
|
|
7
|
-
//
|
|
1
|
+
// The learning lane's end-of-run step on the runner (loop-contract.ts EndOfRunTurn): what a run that learns keeps
|
|
2
|
+
// beside its end, with no look-back turn and no grade. Two things, one merge a round on its agent's learning folder:
|
|
3
|
+
// - its owner's feedback (a grade's words, a message after its first), appended to corrections.md as one line, with
|
|
4
|
+
// no model turn;
|
|
5
|
+
// - its compile turn (learn/compile.ts), when one is due: the job written as a workflow, or a revision of a held one,
|
|
6
|
+
// checked (`checkDraft`: the workflow checks, its dry run, the secret and hidden-character refusals) and committed
|
|
7
|
+
// directly, with the compiled record on the run's learning. A compile whose drafts all failed is recorded on the
|
|
8
|
+
// agent's promotion records (compile once: `compileFailed`), never silent.
|
|
9
|
+
// How it ended is kept beside the run's end (learning_proposals): merged with what it wrote, or dropped with its reason
|
|
10
|
+
// and words. What the run must never learn (`refuse`: the host's secrets and what it was handed, its sign-in pointer
|
|
11
|
+
// among them) is refused by the checks and cut from everything the step keeps; a run whose list can't be read learns
|
|
12
|
+
// nothing.
|
|
8
13
|
import { cutStrings } from "../key-refusal.js";
|
|
9
|
-
import {
|
|
10
|
-
import { compileTurn
|
|
11
|
-
import { said, STOPPED } from "../learning-words.js";
|
|
12
|
-
/** How long a run's end-of-run turn may take before it is aborted and the run ends without it. */
|
|
13
|
-
export const REFLECT_TIMEOUT_MS = 5 * 60_000;
|
|
14
|
-
/** The folder of a run's copy of what its agent learned, relative to its work: what the prompt names. */
|
|
15
|
-
const LEARNED_DIR = ".learning";
|
|
14
|
+
import { redactSecrets } from "../learn/index.js";
|
|
15
|
+
import { compileTurn } from "../learn/compile.js";
|
|
16
|
+
import { correctionsCapOf, said, STOPPED } from "../learning-words.js";
|
|
16
17
|
/** A turn the spend cap refused (the cap's refusal words, cap.ts CAP_REFUSAL_PREFIX). */
|
|
17
18
|
export const CAP_REFUSAL = /^spend_cap_reached(?: \([^)]*\))?: /;
|
|
18
|
-
/** A learning
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
* whole). */
|
|
19
|
+
/** A learning kept beside the run's end: its state, reason and words, and what it wrote. */
|
|
20
|
+
const keptRow = (proposal) => ({ table: "learning_proposals", row: { turn: null, proposal } });
|
|
21
|
+
const dropped = (reason, detail, extra = {}) => keptRow({ ...extra, state: "dropped", reason, detail });
|
|
22
|
+
/** A kept row with every string in it cut of `refuse` in every form and of every secret-shaped run (learn/secrets.ts
|
|
23
|
+
* redactSecrets), with an empty list too. */
|
|
24
24
|
const cutRow = (row, refuse) => row.table === "learning_proposals" ? { table: row.table, row: cutStrings(row.row, (text) => redactSecrets(text, refuse, Number.POSITIVE_INFINITY)) } : row;
|
|
25
|
-
/** The first workflow draft the checks left out of `checked` because its dry run failed (learn/skills.ts DRY_RUN_FAILED):
|
|
26
|
-
* its path and the check's words; undefined when none was. */
|
|
27
|
-
function dryRunFailure(checked) {
|
|
28
|
-
const problems = (checked.state === "proposed" ? checked.left ?? [] : checked.state === "dropped" && checked.reason === "checker" ? checked.problems : []);
|
|
29
|
-
const found = problems.find((problem) => problem?.rule === "workflow" && typeof problem.path === "string" && typeof problem.detail === "string" && problem.detail.startsWith(DRY_RUN_FAILED));
|
|
30
|
-
return found ? { path: found.path, detail: found.detail } : undefined;
|
|
31
|
-
}
|
|
32
25
|
/** `rows` with round `round` on each learning row (none on a run's first, round 1). */
|
|
33
|
-
const roundOf = (rows, round) => !rows || round === 1 ? rows : { also: rows.also.map((row) => (row.table === "learning_proposals"
|
|
34
|
-
/** The end-of-run
|
|
26
|
+
const roundOf = (rows, round) => !rows || round === 1 ? rows : { also: rows.also.map((row) => (row.table === "learning_proposals" ? { ...row, row: { ...row.row, round } } : row)) };
|
|
27
|
+
/** The end-of-run step for runs that learn. */
|
|
35
28
|
export function createReflectHook(deps) {
|
|
36
29
|
const round = deps.round ?? 1;
|
|
37
30
|
const hook = async (input) => {
|
|
@@ -39,9 +32,8 @@ export function createReflectHook(deps) {
|
|
|
39
32
|
if (!facts.learns)
|
|
40
33
|
return undefined;
|
|
41
34
|
const now = deps.now ?? Date.now;
|
|
42
|
-
// When the job answered and what it cost
|
|
43
|
-
//
|
|
44
|
-
// which it kept with its prompt (the ask's `kept`): what the earlier attempt spent is the look-back's, never the job's.
|
|
35
|
+
// When the job answered and what it cost: as the step starts, the run's spend so far is the job's. A compile turn an
|
|
36
|
+
// earlier claim asked first (cut by a crash or a lost claim) reads that ask's, which it kept with its prompt.
|
|
45
37
|
let answeredAt = new Date(now()).toISOString();
|
|
46
38
|
let job = facts.costUsd;
|
|
47
39
|
const firstAsk = (kept) => {
|
|
@@ -50,208 +42,88 @@ export function createReflectHook(deps) {
|
|
|
50
42
|
[answeredAt, job] = [kept.answered_at, kept.job_cost_usd];
|
|
51
43
|
return true;
|
|
52
44
|
};
|
|
53
|
-
// A look-back already started (its first ask's figures on the record, keptOf), read before any skip or cut: one this
|
|
54
|
-
// claim closes without asking still keeps when the job answered, its cost, and what looking back spent since.
|
|
55
45
|
const begun = firstAsk(input.keptOf?.(round));
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const cents = (usd) => Math.max(0, Math.round(usd * 1e9) / 1e9);
|
|
65
|
-
// closeLearning: what looking back cost, the run's spend once the turn closed (its re-ask included) less the job's,
|
|
66
|
-
// unknown when either is. Kept with every end the turn reaches from here, beside when the job answered and its cost;
|
|
67
|
-
// with a compile asked, what of it the compile turn spent (`compile_usd`), from its first ask to the close.
|
|
68
|
-
const looked = async (rows) => {
|
|
46
|
+
// What the step's model turns cost: the run's spend once it closed less the job's, unknown when either is. Kept with
|
|
47
|
+
// every end once a compile turn was asked; 0 for an end that asked none. The step's only model turn is its compile
|
|
48
|
+
// turn, so this is the compile's spend: it joins the revision it drafts, or the bill's unattributed when it kept no
|
|
49
|
+
// draft (store-reads/learning.ts compilesOf, learning-cost.ts amortize), never the run's own.
|
|
50
|
+
let asked = begun;
|
|
51
|
+
const spent = async () => {
|
|
52
|
+
if (!asked)
|
|
53
|
+
return { answered_at: answeredAt, job_cost_usd: job, look_back_usd: 0 };
|
|
69
54
|
const total = (await deps.facts(input.runId)).costUsd;
|
|
70
|
-
|
|
71
|
-
const compileUsd = compileFrom === undefined ? {} : { compile_usd: compileFrom === "alone" ? lookBack : total === null || compileFrom.usd === null ? null : cents(total - compileFrom.usd) };
|
|
72
|
-
const answered = { answered_at: answeredAt, job_cost_usd: job, look_back_usd: lookBack, ...compileUsd, ...followUp() };
|
|
73
|
-
return { also: rows.also.map((row) => (row.table === "learning_proposals" ? { ...row, row: { ...row.row, proposal: { ...row.row.proposal, ...answered } } } : row)) };
|
|
55
|
+
return { answered_at: answeredAt, job_cost_usd: job, look_back_usd: total === null || job === null ? null : Math.max(0, Math.round((total - job) * 1e9) / 1e9) };
|
|
74
56
|
};
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
57
|
+
// An end that asks nothing more: its drop alone, or, when an earlier claim asked the compile turn (stopped during it),
|
|
58
|
+
// with that ask's figures and what the turn spent since, so the run's cost stays the job's own and the rest learning's.
|
|
59
|
+
const unasked = async (row) => (begun ? { also: [keptRow({ ...row.row.proposal, ...(await spent()) })] } : { also: [row] });
|
|
60
|
+
// A person's stop, before or during the step, or a fault: nothing kept.
|
|
61
|
+
if (input.cut === "stopped" || facts.cancelled)
|
|
62
|
+
return unasked(dropped("cancelled", said.stopped(STOPPED.cancelled)));
|
|
80
63
|
if (input.cut === "stopped-looking")
|
|
81
|
-
return unasked(
|
|
64
|
+
return unasked(dropped("cancelled", said.stopped(STOPPED.cancelledLooking)));
|
|
82
65
|
if (input.cut === "faulted")
|
|
83
|
-
return unasked(
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
if (facts.cancelled)
|
|
87
|
-
return unasked(droppedRow(null, "cancelled", said.stopped(STOPPED.cancelled)));
|
|
88
|
-
if (facts.capReached)
|
|
89
|
-
return unasked(droppedRow(null, "no_budget", said.noBudget));
|
|
90
|
-
if (facts.capUsd !== undefined && facts.spentUsd === null)
|
|
91
|
-
return unasked(droppedRow(null, "unknown_cost", said.unknownCost));
|
|
92
|
-
// A job that only ran its learned workflows, each answering, with nothing said after its first message, gave nothing
|
|
93
|
-
// new to learn: it is not asked its look-back (no model request), and unless a compile is due (a held revision of
|
|
94
|
-
// its workflow, asked while its champion serves) looking back cost nothing, $0 whether or not the job's own cost is
|
|
95
|
-
// known. Its words are the server's own.
|
|
96
|
-
const workflowOnly = input.outcome === "completed" && deps.nothingNew !== undefined && (await deps.nothingNew(input.runId).catch(() => false));
|
|
97
|
-
// A run of a job that compiles workflows with no word from its owner is not asked its look-back either (ownerSaid):
|
|
98
|
-
// its job's trace is what a compile reads, and a look-back on every agent run cost more than the run. The same way:
|
|
99
|
-
// its compile turn, when due, asked alone, else $0 looking back.
|
|
100
|
-
const unheard = !workflowOnly && deps.ownerSaid !== undefined && !(await deps.ownerSaid(input.runId).catch(() => true));
|
|
101
|
-
const alone = workflowOnly || unheard;
|
|
102
|
-
const notAsked = workflowOnly ? said.onlyWorkflow : said.noFeedback;
|
|
103
|
-
const onlyWorkflow = () => ({ also: [droppedRow(null, "empty", notAsked, { answered_at: answeredAt, job_cost_usd: job, look_back_usd: 0, ...followUp() })] });
|
|
104
|
-
if (alone && !deps.compileFacts)
|
|
105
|
-
return onlyWorkflow();
|
|
106
|
-
// What the run must never learn, read once, before it is asked anything: a run whose list can't be read learns
|
|
107
|
-
// nothing, never over a shorter one.
|
|
66
|
+
return unasked(dropped("crashed", said.stopped(STOPPED.crashed)));
|
|
67
|
+
// What the run must never learn, read once, before anything: a run whose list can't be read learns nothing, never
|
|
68
|
+
// over a shorter one.
|
|
108
69
|
const read = deps.refuse ? await deps.refuse(input.runId).catch(() => "unreadable") : [];
|
|
109
|
-
const refuse = read === "unreadable" ? [] : read;
|
|
110
|
-
// The compile turn's facts (learn/compile.ts), read once: a run not looked back on with none due ends here, as above.
|
|
111
|
-
const compileOf = async () => (deps.compileFacts && read !== "unreadable" ? await deps.compileFacts({ runId: input.runId, agentId: input.agentId, outcome: input.outcome, refuse }).catch(() => undefined) : undefined);
|
|
112
|
-
const early = alone ? await compileOf() : undefined;
|
|
113
|
-
// None due now, but a compile request this run already asked and kept (a crash cut it, another run merged a workflow
|
|
114
|
-
// since) was paid: its cost stays the look-back's, as every other cut's does (`begun`), never the task's.
|
|
115
|
-
if (alone && !early)
|
|
116
|
-
return begun ? unasked(droppedRow(null, "empty", notAsked)) : onlyWorkflow();
|
|
117
|
-
// Every end from here closes through this one function: looked's timings first, then the cut LAST, over every
|
|
118
|
-
// string the kept rows hold, whatever looked adds now or later.
|
|
119
|
-
const close = async (rows) => ({ also: (await looked({ also: rows })).also.map((row) => cutRow(row, refuse)) });
|
|
120
70
|
if (read === "unreadable")
|
|
121
|
-
return
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// The look-back: asked of every run but a workflow-only one or one its owner said nothing on, whose compile turn is
|
|
136
|
-
// asked alone, from no answer of its own: nothing the look-back kept goes with its draft.
|
|
137
|
-
let turn = null;
|
|
138
|
-
let checked = { state: "dropped", reason: "empty" };
|
|
139
|
-
if (alone)
|
|
140
|
-
heard = await deps.asked(input.runId);
|
|
141
|
-
else {
|
|
142
|
-
const { active } = await deps.promptFacts(input.runId, input.agentId);
|
|
143
|
-
const end = await input.ask(reflectPrompt({ dir: LEARNED_DIR, active, ...(round > 1 && deps.before?.looked !== false ? { later: true } : {}) }), { ...ask, deadlineMs, keep: { answered_at: answeredAt, job_cost_usd: job } });
|
|
144
|
-
firstAsk(end.kept);
|
|
145
|
-
// closeLearning: how the turn ended.
|
|
146
|
-
if ("timedOut" in end)
|
|
147
|
-
return close([droppedRow(null, "reflect_timeout", said.stopped(STOPPED.timedOut))]);
|
|
148
|
-
if ("failed" in end)
|
|
149
|
-
return close([CAP_REFUSAL.test(end.failed.message) ? droppedRow(null, "no_budget", said.noBudget) : droppedRow(null, "reflect_failed", said.stopped(STOPPED.failed))]);
|
|
150
|
-
heard = await deps.asked(input.runId);
|
|
151
|
-
turn = turnOf(end.answer);
|
|
152
|
-
const first = await checkOf(turn);
|
|
153
|
-
if (!first)
|
|
154
|
-
return close([droppedRow(turn, "propose_failed", said.stopped(STOPPED.notChecked))]);
|
|
155
|
-
checked = first;
|
|
156
|
-
}
|
|
157
|
-
// An answer the parser refused is asked for again once, in the same turn, saying why in the parser's own words: the
|
|
158
|
-
// second answer is checked as the first was, and refused again it is dropped as before. Never a third time, and only
|
|
159
|
-
// within the turn's own deadline; a re-ask that times out or fails leaves the first answer's drop.
|
|
160
|
-
if (checked.state === "dropped" && checked.reason === "unparsed") {
|
|
161
|
-
const left = deadlineMs - (now() - started);
|
|
162
|
-
const again = left > 0 ? await input.ask(reflectAgain(checked.detail), { ...ask, deadlineMs: left, again: true }) : undefined;
|
|
163
|
-
if (again && "ended" in again) {
|
|
164
|
-
turn = turnOf(again.answer);
|
|
165
|
-
const second = await checkOf(turn);
|
|
166
|
-
if (!second)
|
|
167
|
-
return close([droppedRow(turn, "propose_failed", said.stopped(STOPPED.notChecked))]);
|
|
168
|
-
checked = second;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
// A workflow draft the checks left out because its dry run failed is asked for again once, in the same turn and
|
|
173
|
-
// within its deadline, saying which draft and why: the second answer stands only when the checks keep it and no
|
|
174
|
-
// draft in it still fails its dry run, else the first answer's, that draft left out, stands (a repair that failed
|
|
175
|
-
// never costs a note the first answer kept). Never a third time (a turn asks again once, for either reason).
|
|
176
|
-
const dry = dryRunFailure(checked);
|
|
177
|
-
const left = deadlineMs - (now() - started);
|
|
178
|
-
const again = dry && left > 0 ? await input.ask(reflectDryRun(dry.path, dry.detail), { ...ask, deadlineMs: left, again: true }) : undefined;
|
|
179
|
-
if (again && "ended" in again) {
|
|
180
|
-
const second = turnOf(again.answer);
|
|
181
|
-
const kept = await checkOf(second);
|
|
182
|
-
if (kept?.state === "proposed" && !dryRunFailure(kept)) {
|
|
183
|
-
turn = second;
|
|
184
|
-
checked = kept;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
// The compile turn (learn/compile.ts): the job as a learned workflow, or a revision of one, checked as a draft is,
|
|
189
|
-
// its refusals sent back up to COMPILE_RETRIES times. A draft that passed goes in the proposal beside the notes; one
|
|
190
|
-
// that never did is never silent: its errors go with the learning, and its problems to its end.
|
|
191
|
-
const compile = alone ? early : await compileOf();
|
|
71
|
+
return unasked(dropped("reflect_failed", said.stopped(STOPPED.refuseUnread)));
|
|
72
|
+
const refuse = read;
|
|
73
|
+
const close = async (row) => ({ also: [cutRow(row.table === "learning_proposals" ? keptRow({ ...row.row.proposal, ...(await spent()) }) : row, refuse)] });
|
|
74
|
+
// The owner's words: one line of corrections.md, checked against main now so a refused one never holds a draft back.
|
|
75
|
+
const words = (await deps.feedback(input.runId).catch(() => [])).map((text) => text.trim()).filter(Boolean);
|
|
76
|
+
const correction = words.length ? words.join(" ") : undefined;
|
|
77
|
+
const refusedCorrection = correction === undefined ? [] : await deps.correctionRefused({ runId: input.runId, agentId: input.agentId, round, text: correction, refuse }).catch(() => [{ rule: "encoding", detail: "the owner's correction could not be checked" }]);
|
|
78
|
+
const taken = correction !== undefined && !refusedCorrection.length ? correction : undefined;
|
|
79
|
+
// The compile turn, when one is due and the run's cap has room: a cap it reached, or a spend under it that is unknown,
|
|
80
|
+
// asks no model turn (the cap keeps no reserve).
|
|
81
|
+
const noRoom = facts.capReached ? "no_budget" : facts.capUsd !== undefined && facts.spentUsd === null ? "unknown_cost" : undefined;
|
|
82
|
+
const workflowOnly = input.outcome === "completed" && deps.nothingNew !== undefined && (await deps.nothingNew(input.runId).catch(() => false));
|
|
83
|
+
const compile = !noRoom && deps.compileFacts ? await deps.compileFacts({ runId: input.runId, agentId: input.agentId, outcome: input.outcome, refuse, round }).catch(() => undefined) : undefined;
|
|
84
|
+
let draft;
|
|
192
85
|
let compiled;
|
|
86
|
+
// A draft the checks refused: their problems by rule (a draft never answered refused nothing).
|
|
87
|
+
let draftProblems = [];
|
|
193
88
|
if (compile) {
|
|
194
|
-
// A
|
|
195
|
-
//
|
|
196
|
-
//
|
|
197
|
-
// the figures as they stand once the attempts before it answered (an earlier claim's, when it asked first).
|
|
198
|
-
// A revision of main's text keeps the commit of main it was read at (`compile_base`) with each attempt the same way:
|
|
199
|
-
// an attempt an earlier claim asked answers with that claim's commit, never the one this claim read (main may have
|
|
200
|
-
// moved since: another run's change to the workflow), and the attempts after it keep that one too. It is the revised
|
|
201
|
-
// workflow's conflict base in every check of the turn, so an answer written over an older main never overwrites a
|
|
202
|
-
// change made after it.
|
|
89
|
+
// A revision of main's text keeps the commit of main it was read at (`compile_base`) with each attempt: an attempt
|
|
90
|
+
// an earlier claim asked answers with that claim's commit, never the one this claim read (main may have moved
|
|
91
|
+
// since), and it is the revised workflow's conflict base in every check of the turn.
|
|
203
92
|
let revised = compile.mode === "revise" && compile.base ? { workflow: compile.workflow, base: compile.base } : undefined;
|
|
204
|
-
/** An attempt the cap refused, or whose spend took the run past it: the learning is dropped as the look-back's is. */
|
|
205
93
|
let capped = false;
|
|
206
|
-
// Where the compile turn begins (the run's spend now), kept with each attempt as the job's figures are: a later claim
|
|
207
|
-
// answers with the earlier one's, so what it spent compiling stays the compile's.
|
|
208
|
-
compileFrom = alone ? "alone" : { usd: (await deps.facts(input.runId)).costUsd };
|
|
209
94
|
const result = await compileTurn({
|
|
210
95
|
ask: async (prompt, attempt, left) => {
|
|
211
|
-
|
|
212
|
-
const keep = {
|
|
213
|
-
const
|
|
214
|
-
if ("failed" in
|
|
96
|
+
asked = true;
|
|
97
|
+
const keep = { answered_at: answeredAt, job_cost_usd: job, ...(revised ? { compile_base: revised.base } : {}) };
|
|
98
|
+
const answer = await input.ask(prompt, { origin: "reflect", ...(round > 1 ? { round } : {}), deadlineMs: left, step: `compile-${attempt}`, keep });
|
|
99
|
+
if ("failed" in answer && CAP_REFUSAL.test(answer.failed.message))
|
|
215
100
|
capped = true;
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const keptFrom = said_.kept?.compile_from_usd;
|
|
219
|
-
if (!alone && (typeof keptFrom === "number" || keptFrom === null))
|
|
220
|
-
compileFrom = { usd: keptFrom };
|
|
221
|
-
const base = said_.kept?.compile_base;
|
|
101
|
+
firstAsk(answer.kept);
|
|
102
|
+
const base = answer.kept?.compile_base;
|
|
222
103
|
if (revised && typeof base === "string")
|
|
223
104
|
revised = { ...revised, base };
|
|
224
|
-
return "ended" in
|
|
105
|
+
return "ended" in answer ? { answer: answer.answer } : undefined;
|
|
225
106
|
},
|
|
226
107
|
compile,
|
|
227
108
|
refuse,
|
|
228
|
-
|
|
229
|
-
answer: checked.state === "proposed" && turn ? turn.answer : "",
|
|
230
|
-
check: (answer) => checkOf(turnOf(answer), revised),
|
|
109
|
+
check: (one) => deps.checkDraft({ runId: input.runId, agentId: input.agentId, draft: one, refuse, ...(revised ? { revised } : {}) }),
|
|
231
110
|
...(deps.compileDeadlineMs !== undefined ? { deadlineMs: deps.compileDeadlineMs } : {}),
|
|
232
111
|
now,
|
|
233
112
|
});
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (result.kept
|
|
239
|
-
|
|
240
|
-
turn = turnOf(result.kept.answer);
|
|
241
|
-
checked = { ...result.kept.checked, proposal: { ...result.kept.checked.proposal, compiled: { workflow, from_notes } } };
|
|
113
|
+
if (capped && !result.kept) {
|
|
114
|
+
if (!taken)
|
|
115
|
+
return close(dropped("no_budget", said.noBudget));
|
|
116
|
+
}
|
|
117
|
+
else if (result.kept) {
|
|
118
|
+
draft = result.kept;
|
|
242
119
|
compiled = { record: result.record };
|
|
243
120
|
}
|
|
244
121
|
else if (result.record) {
|
|
245
|
-
const named = result.record.workflow !== UNNAMED ? { path: `workflows/${result.record.workflow}/workflow.json` } : {};
|
|
246
|
-
const problems = result.draftErrors.map((detail) => ({ rule: "workflow", ...named, detail }));
|
|
247
|
-
// Beside what the look-back kept, as what the checks left out; in place of a look-back that kept nothing, as the
|
|
248
|
-
// checks' drop; beside the checks' own drop, with it. A look-back whose answer could not be read keeps its reason,
|
|
249
|
-
// the draft's errors beside it.
|
|
250
|
-
checked = checked.state === "proposed" ? { ...checked, left: [...(checked.left ?? []), ...problems] }
|
|
251
|
-
: checked.reason === "empty" ? { state: "dropped", reason: "checker", problems }
|
|
252
|
-
: checked.reason === "checker" ? { ...checked, problems: [...checked.problems, ...problems] }
|
|
253
|
-
: checked;
|
|
254
122
|
compiled = { record: result.record, draft_errors: result.draftErrors };
|
|
123
|
+
// Each error names its file already (checkDraftOf); one with no rule behind it (an answer the compile could not
|
|
124
|
+
// read) is the workflow's.
|
|
125
|
+
if (result.drafted)
|
|
126
|
+
draftProblems = result.draftProblems ?? result.draftErrors.map((detail) => ({ rule: "workflow", detail }));
|
|
255
127
|
// Compile once: its failed drafts are the compile's attempt, on record before the learning closes. The draft's
|
|
256
128
|
// name and errors are the model's words: cut of `refuse` as the proposal row is (cutRow) before they are saved
|
|
257
129
|
// on the promotion record or logged, whose reads cut only the server's secrets, never this run's.
|
|
@@ -261,24 +133,39 @@ export function createReflectHook(deps) {
|
|
|
261
133
|
}
|
|
262
134
|
}
|
|
263
135
|
const compiledFields = compiled ? { compiled: compiled.record, ...(compiled.draft_errors?.length ? { draft_errors: compiled.draft_errors } : {}) } : {};
|
|
264
|
-
if (
|
|
265
|
-
const
|
|
266
|
-
|
|
136
|
+
if (draft || taken !== undefined) {
|
|
137
|
+
const done = await deps.commit({ runId: input.runId, agentId: input.agentId, round, ...(draft ? { draft } : {}), ...(taken !== undefined ? { correction: taken } : {}), refuse }).catch((error) => ({ ok: false, reason: "unavailable", problems: [{ rule: "encoding", detail: error instanceof Error ? error.message : String(error) }] }));
|
|
138
|
+
if (done.ok) {
|
|
139
|
+
const readme = draft?.files.find((file) => file.path.endsWith("/README.md"));
|
|
140
|
+
const json = draft?.files.find((file) => file.path.endsWith("/workflow.json"));
|
|
141
|
+
const workflows = draft && json ? [{ file: json.path, name: draft.name, ...(readme && draft.held?.includes(readme.path) ? { pending: true } : {}) }] : [];
|
|
142
|
+
// The draft and the correction are judged apart: one the merge left out (corrections.md filled during the compile)
|
|
143
|
+
// is reported as the check before the compile reports one.
|
|
144
|
+
const left = done.refusedCorrection?.length ? done.refusedCorrection : undefined;
|
|
145
|
+
const corrections = taken !== undefined && !left ? 1 : 0;
|
|
146
|
+
const problems = [...refusedCorrection, ...(left ?? []), ...draftProblems];
|
|
147
|
+
return close(keptRow({ state: "merged", reason: null, merged: done.commit, ...(workflows.length ? { workflows } : {}), ...(corrections ? { corrections } : {}), ...(problems.length ? { problems } : {}), ...compiledFields, detail: said.merged(workflows, corrections, problems) }));
|
|
148
|
+
}
|
|
149
|
+
if (done.reason === "unavailable")
|
|
150
|
+
return close(dropped("reflect_failed", said.stopped(STOPPED.failed), compiledFields));
|
|
151
|
+
return close(dropped("checker", correctionWords(done.problems), { problems: [...done.problems], ...compiledFields }));
|
|
267
152
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
if (
|
|
274
|
-
return close(
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
return close([
|
|
279
|
-
{ table: "learning_proposals", row: { turn, proposal: { ...checked, ...compiledFields, detail: said.proposed(checked.notes, checked.skills, checked.workflows) } } },
|
|
280
|
-
{ table: "learning_run", row: { id: deps.newRunId(), ...(deps.gradeModel ? { model: deps.gradeModel } : {}), ...(capUsd !== undefined ? { capUsd } : {}) } },
|
|
281
|
-
]);
|
|
153
|
+
if (refusedCorrection.length)
|
|
154
|
+
return close(dropped("checker", correctionWords(refusedCorrection), { problems: [...refusedCorrection, ...draftProblems], ...compiledFields }));
|
|
155
|
+
if (draftProblems.length)
|
|
156
|
+
return close(dropped("checker", said.checker(draftProblems), { problems: draftProblems, ...compiledFields }));
|
|
157
|
+
// A compile turn that never answered refused nothing: it failed, its attempts kept.
|
|
158
|
+
if (compiled && !draft && compiled.draft_errors?.length)
|
|
159
|
+
return close(dropped("reflect_failed", said.stopped(STOPPED.unanswered), compiledFields));
|
|
160
|
+
if (noRoom && compile === undefined && deps.compileFacts)
|
|
161
|
+
return close(dropped(noRoom, noRoom === "no_budget" ? said.noBudget : said.unknownCost));
|
|
162
|
+
return close(dropped("empty", workflowOnly ? said.onlyWorkflow : said.empty, compiledFields));
|
|
282
163
|
};
|
|
283
164
|
return async (input) => roundOf(await hook(input), round);
|
|
284
165
|
}
|
|
166
|
+
/** Why a correction (or a merge) was refused, in a person's words: the cap's own sentence when the cap refused it, else
|
|
167
|
+
* the checks'. */
|
|
168
|
+
function correctionWords(problems) {
|
|
169
|
+
const cap = correctionsCapOf(problems);
|
|
170
|
+
return cap ? said.correctionsFull(cap.detail) : problems.length ? said.checker(problems) : said.stopped(STOPPED.notChecked);
|
|
171
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Duplex } from "node:stream";
|
|
2
|
+
/** The most a frame may hold, in bytes: a journal commit of a long turn fits many times over. */
|
|
3
|
+
export declare const MAX_FRAME: number;
|
|
4
|
+
/** The channel ended: its socket closed, or a frame broke the protocol. Every call in flight fails with it. */
|
|
5
|
+
export declare class ChannelClosed extends Error {
|
|
6
|
+
name: string;
|
|
7
|
+
}
|
|
8
|
+
/** A call the other side refused before running it: no such target or method. */
|
|
9
|
+
export declare class ChannelRefused extends Error {
|
|
10
|
+
name: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function registerErrors(classes: Record<string, abstract new (...args: never[]) => Error>): void;
|
|
13
|
+
/** What a target exposed by name does with a call: its method and arguments, as decoded. */
|
|
14
|
+
export type Dispatch = (method: string, args: unknown[]) => unknown;
|
|
15
|
+
export interface ChannelOptions {
|
|
16
|
+
/** The most a frame may hold (MAX_FRAME). */
|
|
17
|
+
readonly maxFrame?: number;
|
|
18
|
+
/** Called once when the channel ends, with why. */
|
|
19
|
+
readonly onClose?: (why: Error) => void;
|
|
20
|
+
/** What each call this side makes carries beside its arguments, encoded as they are (a run's process: the ledger of
|
|
21
|
+
* the tool call it is made in, paid-calls.ts). None: nothing. */
|
|
22
|
+
readonly context?: () => unknown;
|
|
23
|
+
/** Runs each call the other side makes inside what it carried (a runner: paid-calls.ts bookedIn on that ledger). */
|
|
24
|
+
readonly within?: (carried: unknown, run: () => unknown) => unknown;
|
|
25
|
+
}
|
|
26
|
+
/** One side of the channel over `socket`. */
|
|
27
|
+
export declare class Channel {
|
|
28
|
+
#private;
|
|
29
|
+
constructor(socket: Duplex, options?: ChannelOptions);
|
|
30
|
+
get closed(): boolean;
|
|
31
|
+
/** How many functions, objects and signals this side has handed the other and still keeps for it. */
|
|
32
|
+
get handed(): number;
|
|
33
|
+
/** Answers calls to `name` with `dispatch`. */
|
|
34
|
+
expose(name: string, dispatch: Dispatch): void;
|
|
35
|
+
/** Calls `method` of target `to` with `args`: its answer, or its error. */
|
|
36
|
+
call(to: string | number, method: string, args: readonly unknown[]): Promise<unknown>;
|
|
37
|
+
/** Sends `method` of target `to` with `args`, with no answer. In order with every call. */
|
|
38
|
+
post(to: string | number, method: string, args: readonly unknown[]): void;
|
|
39
|
+
/** A stand-in for target `name`: `stub.a.b(...args)` calls method "a.b" of it. `props`: values read without a call. */
|
|
40
|
+
remote<T>(name: string, props?: Record<string, unknown>): T;
|
|
41
|
+
/** Ends the channel: every call in flight fails with `why`, and the socket is destroyed. */
|
|
42
|
+
close(why?: Error): void;
|
|
43
|
+
}
|