@parcha/agentrun-serve 0.1.0-beta.41 → 0.1.0-beta.43

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.
Files changed (164) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/NOTICE +2 -0
  3. package/README.md +85 -19
  4. package/dist/agent-rows.d.ts +1 -1
  5. package/dist/agents-store.js +3 -1
  6. package/dist/calendar/address.d.ts +49 -0
  7. package/dist/calendar/address.js +153 -0
  8. package/dist/calendar/fetch.d.ts +24 -0
  9. package/dist/calendar/fetch.js +146 -0
  10. package/dist/calendar/ics-faux.d.ts +39 -0
  11. package/dist/calendar/ics-faux.js +236 -0
  12. package/dist/calendar/labels.d.ts +3 -0
  13. package/dist/calendar/labels.js +61 -0
  14. package/dist/calendar/names.d.ts +52 -0
  15. package/dist/calendar/names.js +54 -0
  16. package/dist/calendar/parse.d.ts +108 -0
  17. package/dist/calendar/parse.js +625 -0
  18. package/dist/calendar/routes.d.ts +17 -0
  19. package/dist/calendar/routes.js +81 -0
  20. package/dist/calendar/tools.d.ts +23 -0
  21. package/dist/calendar/tools.js +124 -0
  22. package/dist/cli.js +3 -1
  23. package/dist/computer-record.d.ts +55 -0
  24. package/dist/computer-record.js +315 -0
  25. package/dist/computer-setting.d.ts +1 -0
  26. package/dist/computer-setting.js +15 -2
  27. package/dist/computers.js +2 -14
  28. package/dist/console/assets/index-BrcDSBD8.css +1 -0
  29. package/dist/console/assets/index-Bz6IWncl.js +711 -0
  30. package/dist/console/index.html +2 -2
  31. package/dist/decisions.js +0 -4
  32. package/dist/eval-feed.d.ts +2 -2
  33. package/dist/eval-feed.js +9 -5
  34. package/dist/feed/parse.d.ts +3 -2
  35. package/dist/feed/parse.js +9 -18
  36. package/dist/feed/pointer.d.ts +2 -0
  37. package/dist/feed/pointer.js +17 -0
  38. package/dist/file-types.js +1 -0
  39. package/dist/host-command.d.ts +3 -0
  40. package/dist/host-command.js +18 -0
  41. package/dist/host.d.ts +3 -0
  42. package/dist/host.js +3 -0
  43. package/dist/import-sources.js +25 -5
  44. package/dist/learn/audit.d.ts +123 -0
  45. package/dist/learn/audit.js +159 -0
  46. package/dist/learn/check.d.ts +14 -0
  47. package/dist/learn/check.js +194 -14
  48. package/dist/learn/compile.d.ts +75 -78
  49. package/dist/learn/compile.js +175 -176
  50. package/dist/learn/folder.d.ts +9 -0
  51. package/dist/learn/folder.js +13 -2
  52. package/dist/learn/promote.d.ts +138 -196
  53. package/dist/learn/promote.js +68 -184
  54. package/dist/learn/replay-calls.d.ts +5 -0
  55. package/dist/learn/replay-calls.js +12 -1
  56. package/dist/learn/secrets.d.ts +8 -0
  57. package/dist/learn/secrets.js +12 -0
  58. package/dist/learn/skills.js +2 -4
  59. package/dist/learn/workflow-nodes.d.ts +1 -2
  60. package/dist/learn/workflow-nodes.js +2 -3
  61. package/dist/learned-nodes.d.ts +9 -34
  62. package/dist/learned-nodes.js +11 -23
  63. package/dist/learned-workflow.d.ts +6 -8
  64. package/dist/learned-workflow.js +18 -57
  65. package/dist/learning-batch.d.ts +13 -5
  66. package/dist/learning-batch.js +34 -8
  67. package/dist/learning-cost.d.ts +11 -4
  68. package/dist/learning-cost.js +4 -2
  69. package/dist/learning-routes.js +1 -1
  70. package/dist/learning-setting.d.ts +38 -0
  71. package/dist/learning-setting.js +83 -0
  72. package/dist/learning-words.d.ts +3 -0
  73. package/dist/learning-words.js +3 -0
  74. package/dist/learning.d.ts +3 -2
  75. package/dist/learning.js +5 -3
  76. package/dist/mcp-oauth.d.ts +8 -0
  77. package/dist/mcp-oauth.js +7 -0
  78. package/dist/mcp-private-hosts.d.ts +13 -0
  79. package/dist/mcp-private-hosts.js +16 -0
  80. package/dist/openapi.d.ts +1 -0
  81. package/dist/openapi.js +195 -59
  82. package/dist/run-files.d.ts +6 -2
  83. package/dist/run-files.js +29 -7
  84. package/dist/run-launch.d.ts +6 -3
  85. package/dist/run-launch.js +2 -0
  86. package/dist/run-learning-served.d.ts +2 -2
  87. package/dist/run-reads-over-store.d.ts +5 -1
  88. package/dist/run-reads-over-store.js +8 -4
  89. package/dist/run-recordings.d.ts +20 -0
  90. package/dist/run-recordings.js +133 -0
  91. package/dist/runner/adapter-loop.d.ts +5 -1
  92. package/dist/runner/adapter-loop.js +20 -8
  93. package/dist/runner/adapter-run-spec.d.ts +16 -1
  94. package/dist/runner/adapter-run-spec.js +36 -11
  95. package/dist/runner/audit.d.ts +64 -0
  96. package/dist/runner/audit.js +338 -0
  97. package/dist/runner/beside.js +2 -2
  98. package/dist/runner/cli-run-spec.js +25 -12
  99. package/dist/runner/feedback-round.d.ts +9 -25
  100. package/dist/runner/feedback-round.js +19 -40
  101. package/dist/runner/harness-loops.js +1 -15
  102. package/dist/runner/journal-kinds.d.ts +0 -7
  103. package/dist/runner/journal-kinds.js +0 -7
  104. package/dist/runner/learning-dispatch.d.ts +0 -16
  105. package/dist/runner/learning-dispatch.js +4 -47
  106. package/dist/runner/learning-end.d.ts +62 -13
  107. package/dist/runner/learning-end.js +180 -74
  108. package/dist/runner/learning-factory.d.ts +1 -1
  109. package/dist/runner/learning-factory.js +1 -4
  110. package/dist/runner/learning-loop.d.ts +2 -38
  111. package/dist/runner/learning-loop.js +8 -116
  112. package/dist/runner/main.d.ts +11 -0
  113. package/dist/runner/main.js +30 -3
  114. package/dist/runner/mcp-run.d.ts +2 -2
  115. package/dist/runner/promotion.d.ts +78 -50
  116. package/dist/runner/promotion.js +371 -503
  117. package/dist/runner/reflect-hook.d.ts +15 -0
  118. package/dist/runner/reflect-hook.js +28 -14
  119. package/dist/runner/store-secrets.js +3 -1
  120. package/dist/runner/workflow-first.d.ts +6 -11
  121. package/dist/runner/workflow-first.js +24 -25
  122. package/dist/runs-over-store.d.ts +1 -1
  123. package/dist/sdk/runs.js +2 -1
  124. package/dist/secrets.js +2 -2
  125. package/dist/server.d.ts +4 -3
  126. package/dist/server.js +132 -26
  127. package/dist/store/agent-body.d.ts +5 -3
  128. package/dist/store/agent-body.js +14 -10
  129. package/dist/store/sqlite/store.js +1 -0
  130. package/dist/store/store.d.ts +3 -0
  131. package/dist/store-reads/learning.d.ts +18 -7
  132. package/dist/store-reads/learning.js +36 -23
  133. package/dist/store-reads/loop.d.ts +5 -39
  134. package/dist/store-reads/loop.js +21 -80
  135. package/dist/store-view.d.ts +5 -0
  136. package/dist/store-view.js +16 -2
  137. package/dist/template-eval.d.ts +7 -0
  138. package/dist/template-eval.js +54 -6
  139. package/dist/templates.d.ts +3 -1
  140. package/dist/templates.js +14 -1
  141. package/dist/timeline/computer.js +2 -1
  142. package/dist/tool-list.js +1 -0
  143. package/dist/tools.d.ts +7 -0
  144. package/dist/tools.js +11 -0
  145. package/dist/trigger-feed.js +67 -18
  146. package/dist/validate.js +7 -2
  147. package/dist/workspace/computer-for-claim.d.ts +7 -0
  148. package/dist/workspace/computer-for-claim.js +12 -2
  149. package/dist/workspace/paths.d.ts +4 -0
  150. package/dist/workspace/paths.js +9 -0
  151. package/dist/workspace/resolve-computer.d.ts +3 -1
  152. package/dist/workspace/run-tools.d.ts +1 -1
  153. package/dist/workspace/run-tools.js +14 -3
  154. package/launcher/agentrun-serve +31 -24
  155. package/package.json +10 -9
  156. package/templates/README.md +11 -2
  157. package/dist/console/assets/index-C3gNPz58.css +0 -1
  158. package/dist/console/assets/index-COGhx_2Z.js +0 -711
  159. package/dist/learn/general.d.ts +0 -69
  160. package/dist/learn/general.js +0 -75
  161. package/dist/learn/refit.d.ts +0 -48
  162. package/dist/learn/refit.js +0 -264
  163. package/dist/runner/step-guard.d.ts +0 -62
  164. package/dist/runner/step-guard.js +0 -93
@@ -1,15 +1,11 @@
1
1
  // A grade's feedback round: what a run's grade (PUT /runs/{id}/grade, a person's feedback or an eval's label) asks of its
2
2
  // learning, and how the run's next end reads it. The run's path is who wrote its final answer, so a grade never makes
3
3
  // the agent answer the job again:
4
- // - a run its learned workflow answered alone (path `workflow`), graded right: the grade is kept (replay and refit
5
- // read it) and nothing else happens: no turn, $0;
6
- // - the same, graded wrong: a revision ask for that workflow. The run opens again on a feedback round: the grade's
7
- // words are on its record, the agent is asked no turn of the job's, and the run goes straight to its end-of-run turn,
8
- // whose look-back hears the job, the workflow's answer and the grade's words (notes), and whose compile turn asks for
9
- // the workflow again, changed (learning-end.ts compileAskOf). Its spend is learning spend, and the run's path stays
10
- // `workflow`;
4
+ // - a run its learned workflow answered alone (path `workflow`), graded right or wrong: the grade is kept and nothing else happens: no round, no turn, $0. One wrong answer is one sample;
11
5
  // - a run the agent finished (path `agent` or `handed_back`) graded with words (`label`): a look-back round on them
12
- // (#2579's later round, notes), the same way: no turn of the job's, the end-of-run turn reading the words.
6
+ // (#2579's later round, notes). The run opens again on it: the grade's words are on its record, the agent is asked no
7
+ // turn of the job's, and the run goes straight to its end-of-run turn, which reads the words. Its spend is learning
8
+ // spend.
13
9
  // A grade with neither asks for nothing more. The server writes the round's steer (server.ts gradeRun, runs.reopen); the
14
10
  // adapter loop takes it (adapter-loop.ts steer: a FEEDBACK entry, no turn), and the end-of-run step reads it
15
11
  // (learning-end.ts: heard, never "nothing new"; adapter-loop.ts askEndOfRun: feedbackAsk before the prompt).
@@ -18,24 +14,12 @@ import { readLaunchBody } from "../run-launch.js";
18
14
  import { RunFinal } from "../store/store.js";
19
15
  import { KINDS } from "./journal-kinds.js";
20
16
  import { commandRequest } from "./loop.js";
21
- import { servedAnswerText } from "./workflow-first.js";
22
- export const FEEDBACK_ROUNDS = ["revise", "look_back"];
23
- /** What a grade asks for: `revise` for a wrong grade of a run its learned workflow answered alone, `look_back` for a
24
- * graded run the agent finished when the grade has words, else none (undefined). A replay run is never graded. */
17
+ export const FEEDBACK_ROUNDS = ["look_back"];
18
+ /** What a grade asks for: `look_back` for a graded run the agent finished when the grade has words, else none
19
+ * (undefined): a run its learned workflow answered alone opens none, right or wrong (its grade is kept). A replay run
20
+ * is never graded. */
25
21
  export function feedbackRoundOf(grade, label) {
26
- if (grade.path === "workflow")
27
- return !grade.correct && grade.workflow ? "revise" : undefined;
28
- if (grade.path === "agent" || grade.path === "handed_back")
29
- return label ? "look_back" : undefined;
30
- return undefined;
31
- }
32
- /** The grade's words as the round says them: its `label`, else the fields a right answer holds (`expected`), else
33
- * "(no words)". Never the verdict: feedbackAsk and the compile ask each say it once. (A right grade opens a round only
34
- * with a label (feedbackRoundOf), so none reaches here without one.) */
35
- export function feedbackWords(label, expected) {
36
- if (label?.trim())
37
- return label.trim();
38
- return expected ? `A right answer holds: ${JSON.stringify(expected)}` : "(no words)";
22
+ return (grade.path === "agent" || grade.path === "handed_back") && label ? "look_back" : undefined;
39
23
  }
40
24
  /** The feedback round a steer's body asks for (`body.feedback`, the server's own: server.ts gradeRun writes it, and the
41
25
  * message API never does), else undefined. */
@@ -44,7 +28,7 @@ export function feedbackOf(body) {
44
28
  const text = body?.text;
45
29
  if (!fed || typeof fed !== "object" || !FEEDBACK_ROUNDS.includes(fed.round) || typeof fed.correct !== "boolean" || typeof text !== "string")
46
30
  return undefined;
47
- return { round: fed.round, correct: fed.correct, ...(typeof fed.workflow === "string" ? { workflow: fed.workflow } : {}), text };
31
+ return { round: fed.round, correct: fed.correct, text };
48
32
  }
49
33
  /** The feedback round the run's root `entries` say its next end closes: its newest FEEDBACK entry when no end came after
50
34
  * it, else undefined. */
@@ -54,13 +38,9 @@ export function pendingFeedbackOf(entries) {
54
38
  return undefined;
55
39
  return feedbackOf({ feedback: entries[at].data, text: entries[at].data?.text });
56
40
  }
57
- /** What the end-of-run turn of a feedback round is told before its prompt: for a run whose agent never took the job (its
58
- * learned workflow answered alone, so its session saw nothing), the job and what the workflow answered first
59
- * (`job`, `served`); then the grade and its words. The look-back keeps notes only: a revision's ask to give the workflow
60
- * again changed is the compile turn's, after it (learning-end.ts compileAskOf reads the round, learn/compile.ts asks). */
61
- export function feedbackAsk(feedback, seen) {
62
- const graded = `A reviewer graded ${seen ? "that" : "this run's"} answer ${feedback.correct ? "right" : "wrong"}. What they said:`;
63
- return [...(seen ? [seen.job, servedAnswerText(seen.served.workflow, seen.served.answer)] : []), graded, "", feedback.text].join("\n\n").replace(/\n{3,}/g, "\n\n");
41
+ /** What the end-of-run turn of a feedback round is told before its prompt: the grade and its words. */
42
+ export function feedbackAsk(feedback) {
43
+ return [`A reviewer graded this run's answer ${feedback.correct ? "right" : "wrong"}. What they said:`, "", feedback.text].join("\n\n").replace(/\n{3,}/g, "\n\n");
64
44
  }
65
45
  /** How a feedback round stands (GET /runs/{id}/learning `graded.feedback_status`): `running` until it settles; `ended`,
66
46
  * its run took the grade's words and ended after them; `not_run`, its run ended before it took them. */
@@ -83,16 +63,15 @@ export function feedbackStatus(entries, command) {
83
63
  return command.refused !== null ? "not_run" : "running";
84
64
  }
85
65
  /** Opens run `grade.run` again on the feedback round its grade asks for (feedbackRoundOf), with the grade's words
86
- * (`label`, else feedbackWords'), and says which, with its steer: only a run that learns (its launch's learning start,
87
- * never one that only uses what was learned, nor a notes-only run's revision ask), whose runner supports managed
88
- * feedback, neither archived nor of an archived
66
+ * (`label`), and says which, with its steer: only a run that learns (its launch's learning start,
67
+ * never one that only uses what was learned), whose runner supports managed feedback, neither archived nor of an archived
89
68
  * agent (closed history: a grade of it starts no paid work), and one the store opens again (an agentic run that answered
90
69
  * or that a person stopped). Null when the grade asks for nothing more, or the run can't be opened again (the grade is
91
70
  * kept either way). */
92
71
  export async function openFeedbackRound(store, grade, label) {
93
72
  const words = label?.trim() ? label.trim() : undefined;
94
73
  const round = feedbackRoundOf(grade, words);
95
- if (!round)
74
+ if (!round || !words)
96
75
  return null;
97
76
  const run = await store.runs.get(grade.run);
98
77
  if (!run || run.archivedAt !== null || (await store.agents.get(run.agentId))?.archivedAt !== null)
@@ -103,11 +82,11 @@ export async function openFeedbackRound(store, grade, label) {
103
82
  if (launch?.native || launch?.sdk)
104
83
  return null;
105
84
  const learning = launch?.learning;
106
- if (!learning || learning.use || (round === "revise" && learning.notesOnly))
85
+ if (!learning || learning.use)
107
86
  return null;
108
- const feedback = { round, correct: grade.correct, ...(round === "revise" && grade.workflow ? { workflow: grade.workflow } : {}) };
87
+ const feedback = { round, correct: grade.correct };
109
88
  try {
110
- const steer = await store.runs.reopen(grade.run, { kind: "steer", body: { text: feedbackWords(words, grade.expected), feedback } });
89
+ const steer = await store.runs.reopen(grade.run, { kind: "steer", body: { text: words, feedback } });
111
90
  return { round, command: steer.id };
112
91
  }
113
92
  catch (error) {
@@ -15,10 +15,7 @@ import { hostMemory, neverFits } from "../host.js";
15
15
  import { resolveHarness } from "./adapters/index.js";
16
16
  import { adapterRunSpecFromLaunch, PI_WIRES } from "./adapter-run-spec.js";
17
17
  import { createAdapterLoop } from "./adapter-loop.js";
18
- import { hostDecisionKeys, savedModelKeys, withModelKeys } from "./claim-secrets.js";
19
- import { decisionProvidersIn, DEFAULT_DECISION_PROVIDER, FAUX_JEV_ENV } from "../decisions.js";
20
- import { FAUX_ENV } from "../model.js";
21
- import { generalThresholdOf } from "../learn/general.js";
18
+ import { savedModelKeys, withModelKeys } from "./claim-secrets.js";
22
19
  import { createDispatchLoop } from "./dispatch.js";
23
20
  import { cliRunSpecFromLaunch } from "./cli-run-spec.js";
24
21
  import { gradeModelFor, gradeRouteOf, learningLoopOf } from "./learning-dispatch.js";
@@ -78,17 +75,6 @@ export function resolveRunnerLoop(deps) {
78
75
  },
79
76
  ...(deps.log ? { log: deps.log } : {}),
80
77
  ...(deps.gradeBound ? { gradeBound: deps.gradeBound } : {}),
81
- // The generality pre-check (learn/general.ts) on this host's Jev, built as a learning end builds its check's
82
- // decision providers (hostDecisionKeys: the runner's environment first, then the key saved in Settings), on the
83
- // client and model a workflow's decision node gets when it names none. No Jev key: none asked. A faux host asks only
84
- // its faux Jev (FAUX_JEV_ENV), as its grade goes only to the faux route: a key it inherited never sends a note out.
85
- jev: async () => {
86
- const env = deps.env ?? process.env;
87
- if (env[FAUX_ENV] && !env[FAUX_JEV_ENV])
88
- return undefined;
89
- return (await decisionProvidersIn({ ...env, ...(await hostDecisionKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, [DEFAULT_DECISION_PROVIDER])) }))?.providers[DEFAULT_DECISION_PROVIDER];
90
- },
91
- generalThreshold: generalThresholdOf(deps.env ?? process.env),
92
78
  });
93
79
  }
94
80
  // The harness's own entry decides which spec builds the run, by the entry's facts and never the harness's name: an entry
@@ -97,13 +97,6 @@ export declare const KINDS: {
97
97
  * sent it to. On the node log (NODE_LOG_SESSION), for GET /runs/{id}/graph's nodes' `model` (graph-view.ts). Neither a
98
98
  * call nor a message. */
99
99
  readonly nodeModel: "agentrun.node.model";
100
- /** A learning run's generality pre-check (learn/general.ts), its Jev requests about to leave: committed and made
101
- * durable before they do, as a grade request's record is (learning-ask.ts bookedAsk), so a restart that finds one with
102
- * no answer after it books what they spent as unknown (null) before it asks again. Paid, and Jev dedupes none. */
103
- readonly learningGeneralSent: "agentrun.learning.general.sent";
104
- /** That check's end, kept before the grader starts: its scores, or why it could not run (`unchecked`), and what it spent.
105
- * A restart reuses it and never asks Jev again. */
106
- readonly learningGeneral: "agentrun.learning.general";
107
100
  /** A learning run's grade: the verdict and what it spent, written before its merge (a resumed run never asks again). */
108
101
  readonly learningGraded: "agentrun.learning.graded";
109
102
  /** A learning run's merge: the new main and its commit, with the run's end. */
@@ -97,13 +97,6 @@ export const KINDS = {
97
97
  * sent it to. On the node log (NODE_LOG_SESSION), for GET /runs/{id}/graph's nodes' `model` (graph-view.ts). Neither a
98
98
  * call nor a message. */
99
99
  nodeModel: "agentrun.node.model",
100
- /** A learning run's generality pre-check (learn/general.ts), its Jev requests about to leave: committed and made
101
- * durable before they do, as a grade request's record is (learning-ask.ts bookedAsk), so a restart that finds one with
102
- * no answer after it books what they spent as unknown (null) before it asks again. Paid, and Jev dedupes none. */
103
- learningGeneralSent: "agentrun.learning.general.sent",
104
- /** That check's end, kept before the grader starts: its scores, or why it could not run (`unchecked`), and what it spent.
105
- * A restart reuses it and never asks Jev again. */
106
- learningGeneral: "agentrun.learning.general",
107
100
  /** A learning run's grade: the verdict and what it spent, written before its merge (a resumed run never asks again). */
108
101
  learningGraded: "agentrun.learning.graded",
109
102
  /** A learning run's merge: the new main and its commit, with the run's end. */
@@ -1,7 +1,4 @@
1
1
  import type { BeforeRequest } from "@parcha/agentrun-kernel";
2
- import type { DecisionProvider } from "@parcha/agentrun-dsl";
3
- import { type GeneralSource } from "../learn/general.js";
4
- import type { NoteText } from "../learn/grade.js";
5
2
  import { type GraderRoute } from "./learning-ask.js";
6
3
  import type { LoopFactory } from "./loop-contract.js";
7
4
  import type { Store } from "../store/store.js";
@@ -27,11 +24,6 @@ export interface LearningDispatchDeps {
27
24
  readonly now?: () => number;
28
25
  /** For tests: the grade's bound, as a signal. Default: GRADE_TIMEOUT_MS from the ask. */
29
26
  readonly gradeBound?: () => AbortSignal;
30
- /** This host's Jev, for the generality pre-check (learn/general.ts): undefined when it has no Jev key, read at each
31
- * learning run so a key saved in Settings with no restart is used by the next one. */
32
- readonly jev?: () => Promise<DecisionProvider | undefined>;
33
- /** The bar a note's Jev score must reach to be graded (learn/general.ts generalThresholdOf). */
34
- readonly generalThreshold?: number;
35
27
  }
36
28
  /** The grade's route for `model` (the grade model the server names; undefined, the agent's own), from the runner's one
37
29
  * route (`routeOf`), but where this host reaches the model's vendor only through OpenRouter (provider.ts
@@ -49,13 +41,5 @@ export declare function gradeRouteOf(model: string | undefined, env: NodeJS.Proc
49
41
  * output bound as the least it may be sent with, so a grade never runs on a cut answer. Another model than the route's is
50
42
  * priced by nothing here: refused. */
51
43
  export declare function gradeCap(capUsd: number, route: GraderRoute): BeforeRequest;
52
- /** The worst case of the generality check's requests to `jev` (learn/general.ts generalRequest, one a note), each held as a
53
- * workflow's decision is under its run's cap (decision-cap.ts holdOf); unpriced when any one's price is not known
54
- * here. */
55
- export declare function generalHeld(jev: DecisionProvider, notes: readonly NoteText[], source: GeneralSource): Promise<{
56
- usd: number;
57
- } | {
58
- unpriced: string;
59
- }>;
60
44
  /** The loop for a launch of harness "learning": the runner's dispatch calls it for each such run it claims. */
61
45
  export declare function learningLoopOf(deps: LearningDispatchDeps): LoopFactory;
@@ -7,23 +7,15 @@
7
7
  // learning-end.ts gradeCapOf), and each grader call is judged against it before it leaves by the kernel's one rule
8
8
  // (beforeRequestOf, over the learning run's one booking) at its worst case: its input uncached and its whole output bound
9
9
  // (GRADE_MAX_TOKENS), never cut down to fit, so a verdict is never lost to a short answer. A call that doesn't fit is
10
- // never sent, and the grade is skipped, said so (learning-loop.ts GradeOverCap). The generality pre-check's Jev requests
11
- // are the grade's spend too: before they leave, their worst case (decision-cap.ts holdOf: the rule a workflow's
12
- // decision is held at under its run's cap) is judged against the same cap, less what an earlier attempt's cut check may
13
- // have spent; a check that doesn't fit is never sent, and is skipped, said so (learning-loop.ts GeneralOverCap), the
14
- // grader then judged on its own. What the check spent is outside the grade's records, so each grader call's room is the
15
- // cap less it (the ask's `beside`: its kept dollars, else its worst case). An uncapped run's grade is capped by nothing. A
10
+ // never sent, and the grade is skipped, said so (learning-loop.ts GradeOverCap). An uncapped run's grade is capped by nothing. A
16
11
  // grader that never answers is cut at the grade's bound, and what it spent is unknown (null).
17
12
  import { beforeRequestOf } from "@parcha/agentrun-kernel/kernel/cap";
18
- import { money } from "../cap.js";
19
- import { holdOf } from "../decision-cap.js";
20
- import { generalRequest, generalScores } from "../learn/general.js";
21
13
  import { FAUX_ENV } from "../model.js";
22
14
  import { anthropicModelId, openRouterOnly, providerFor } from "../provider.js";
23
15
  import { capModelOf } from "./adapter-run-spec.js";
24
16
  import { bookedAsk } from "./learning-ask.js";
25
17
  import { learningLoopFactory } from "./learning-factory.js";
26
- import { GeneralOverCap, GRADE_TIMEOUT_MS } from "./learning-loop.js";
18
+ import { GRADE_TIMEOUT_MS } from "./learning-loop.js";
27
19
  /** The model a grade runs on, main's order: the grade model the server names, else the agent's own (the model its
28
20
  * revision names), else none (the host's default, which the route picks). */
29
21
  export const gradeModelFor = (grade) => grade.model ?? grade.own;
@@ -81,19 +73,6 @@ export function gradeCap(capUsd, route) {
81
73
  const judge = beforeRequestOf({ capUsd: () => capUsd, modelOf: (id) => (id === route.model ? model : undefined) });
82
74
  return (request) => judge({ ...request, ...(request.outputTokensAsked !== undefined ? { outputTokensLeast: request.outputTokensAsked } : {}) });
83
75
  }
84
- /** The worst case of the generality check's requests to `jev` (learn/general.ts generalRequest, one a note), each held as a
85
- * workflow's decision is under its run's cap (decision-cap.ts holdOf); unpriced when any one's price is not known
86
- * here. */
87
- export async function generalHeld(jev, notes, source) {
88
- let usd = 0;
89
- for (const note of notes) {
90
- const hold = await holdOf(jev, generalRequest(note, source));
91
- if ("unpriced" in hold)
92
- return hold;
93
- usd += hold.usd;
94
- }
95
- return { usd };
96
- }
97
76
  /** The loop for a launch of harness "learning": the runner's dispatch calls it for each such run it claims. */
98
77
  export function learningLoopOf(deps) {
99
78
  return (loopDeps) => {
@@ -105,31 +84,9 @@ export function learningLoopOf(deps) {
105
84
  const route = await deps.routeOf(grade.route);
106
85
  // The loop's own signal (a stop, a lost claim, its bound) and the grade's bound, both: whichever ends first cuts it.
107
86
  const bound = deps.gradeBound ? deps.gradeBound() : AbortSignal.timeout(GRADE_TIMEOUT_MS);
108
- // Under a cap, the room for the call is what the cap leaves once the generality check's spend beside the grade's
109
- // records is counted.
110
- const capUsd = grade.capUsd === undefined ? undefined : Math.max(0, grade.capUsd - (request.beside ?? 0));
111
- return bookedAsk({ ...route, ...(capUsd !== undefined ? { beforeRequest: gradeCap(capUsd, route) } : {}) })(request, AbortSignal.any([signal, bound]), run);
112
- };
113
- // The generality pre-check on this host's Jev; none set up here, none asked. Under a cap, its requests' worst case
114
- // is judged against what the cap leaves (less `before`, an earlier attempt's cut check's) before any leaves.
115
- const general = async (notes, source, signal, run, sending, before) => {
116
- const jev = await deps.jev?.();
117
- if (!jev)
118
- return undefined;
119
- if (claimed === undefined)
120
- throw new Error("the learning run's generality check was asked before its claim");
121
- const { capUsd } = await gradeOf(deps.store, claimed);
122
- if (capUsd === undefined)
123
- return generalScores(jev, notes, source, signal, run, sending && (() => sending()));
124
- const held = await generalHeld(jev, notes, source);
125
- const room = Math.max(0, capUsd - (before ?? 0));
126
- if ("unpriced" in held)
127
- throw new GeneralOverCap(held.unpriced, true);
128
- if (held.usd > room)
129
- throw new GeneralOverCap(`its worst case of ${money(held.usd)} is over the ${money(room)} the cap leaves`, false);
130
- return generalScores(jev, notes, source, signal, run, sending && (() => sending(held.usd)));
87
+ return bookedAsk({ ...route, ...(grade.capUsd !== undefined ? { beforeRequest: gradeCap(grade.capUsd, route) } : {}) })(request, AbortSignal.any([signal, bound]), run);
131
88
  };
132
- const loop = learningLoopFactory({ store: deps.store, data: deps.data, ask, ...(deps.sourceInstructions ? { sourceInstructions: deps.sourceInstructions } : {}), ...(deps.jev ? { general } : {}), ...(deps.generalThreshold !== undefined ? { generalThreshold: deps.generalThreshold } : {}), ...(deps.log ? { log: deps.log } : {}), ...(deps.now ? { now: deps.now } : {}) })(loopDeps);
89
+ const loop = learningLoopFactory({ store: deps.store, data: deps.data, ask, ...(deps.sourceInstructions ? { sourceInstructions: deps.sourceInstructions } : {}), ...(deps.log ? { log: deps.log } : {}), ...(deps.now ? { now: deps.now } : {}) })(loopDeps);
133
90
  return {
134
91
  start: (claim) => {
135
92
  claimed = claim.runId;
@@ -4,7 +4,7 @@ import { type CompileAsk, type CompileTrace } from "../learn/compile.js";
4
4
  import type { RunPath } from "../learning-cost.js";
5
5
  import { type RunLaunch } from "../run-launch.js";
6
6
  import { type SignInReader } from "../run-view.js";
7
- import type { Store } from "../store/store.js";
7
+ import { type AlsoRow, type Store } from "../store/store.js";
8
8
  import type { EndOfRunTurn } from "./loop-contract.js";
9
9
  /** What the step reads: the run's store, the data directory (the server's tool settings a draft's tools are read with),
10
10
  * the agent's learning folder (where the run's place keeps it), the runner's environment (the host's secrets a
@@ -40,12 +40,25 @@ export interface LearningEndDeps {
40
40
  * does not learn is asked nothing and keeps nothing), else the reflect hook over the run's store. */
41
41
  export declare function learningEndOfRun(launch: RunLaunch, deps: LearningEndDeps): EndOfRunTurn | undefined;
42
42
  /** What every cap gate of run `runId` reads as spent beside it on its behalf (adapter-loop.ts RunCapConfig.beside): its
43
- * learning runs' grades (Store.learning.spentBeside, the one figure), for a capped run that learns, the only run whose
44
- * ends queue them; none for any other, whose gates read only its own sessions. */
45
- export declare function spentBesideOf(launch: RunLaunch, store: Pick<Store, "learning">, runId: string): (() => Promise<number | null>) | undefined;
43
+ * learning runs' grades and its audit's shadow run (besideOf), for a capped run with a learning start, the only run
44
+ * whose ends queue them (one that only uses what its agent learned queues no grade, but may start a shadow); none for any
45
+ * other, whose gates read only its own sessions. */
46
+ export declare function spentBesideOf(launch: RunLaunch, store: Pick<Store, "learning" | "runs">, runId: string): (() => Promise<number | null>) | undefined;
47
+ /** What was spent beside run `runId` on its behalf, the one figure its cap gates and its grades' caps read: its learning
48
+ * runs' grades (Store.learning.spentBeside; `beforeRound`: its earlier rounds' alone) and its audit's shadow run
49
+ * (runner/audit.ts, started at its end with what its cap left): the shadow at its cost once it ended, at its own cap while
50
+ * it has not (the most it may take) or when it ended at a cost not known, 0 when none was started. Null: unknown. */
51
+ export declare function besideOf(store: Pick<Store, "learning" | "runs">, runId: string, options?: {
52
+ beforeRound?: number;
53
+ }): Promise<number | null>;
54
+ /** What run `runId`'s cap leaves its audit's shadow run at its end (runner/audit.ts startAudit): the cap it is held to now
55
+ * (capNowOf: its newest raise's, else `launchCapUsd`), less what it spent under it (capSpendOf over `entries`, its
56
+ * journal: its job, its look-back, every grade an earlier round queued) and the cap of the grade this end queues
57
+ * (`queued`, the end's rows: it is not in the store until the end commits). Null when that spend is unknown. */
58
+ export declare function auditRoomOf(store: Pick<Store, "learning" | "runs">, runId: string, launchCapUsd: number, entries: readonly EntryLike[], queued: readonly AlsoRow[]): Promise<number | null>;
46
59
  /** What capped run `runId` has spent under its cap, as every gate of the run reads it: its sessions' booking as the kernel
47
60
  * cap counts it (metrics.ts bookedCapSpend over `entries`, its journal) and what was spent beside it on its behalf
48
- * (Learning.spentBeside; `beforeRound`: its earlier rounds' grades alone). Null when either is unknown.
61
+ * (besideOf: its grades, `beforeRound` its earlier rounds' alone, and its audit's shadow). Null when either is unknown.
49
62
  *
50
63
  * The rule for a cost no one knows (a request answered with no price of its own, one cut short or lost): under a cap it
51
64
  * counts at the figure the cap held it at when it was admitted (its worst case at the model's price, and a lost one's
@@ -54,7 +67,7 @@ export declare function spentBesideOf(launch: RunLaunch, store: Pick<Store, "lea
54
67
  * unknown (a held figure is the cap's, never a charge). Only a request held at no figure (none is, under a cap) leaves
55
68
  * the spend itself unknown: then nothing more is sent under the cap, and the words say the spend is unknown, as the
56
69
  * kernel's unknownSpend refusal does, never "no room". */
57
- export declare function capSpendOf(store: Pick<Store, "learning">, runId: string, entries: readonly EntryLike[], beforeRound?: number): Promise<number | null>;
70
+ export declare function capSpendOf(store: Pick<Store, "learning" | "runs">, runId: string, entries: readonly EntryLike[], beforeRound?: number): Promise<number | null>;
58
71
  /** The cap the grade of round `round` of run `runId` runs under (its learning run's max_cost_usd), so the run's grades
59
72
  * never take it past its cap: the cap the run is held to now (capNowOf: its newest raise's, else `launchCapUsd`), less
60
73
  * what the run spent under it (its job, its follow-ups and every look-back) and what was spent beside it on its behalf by
@@ -62,6 +75,17 @@ export declare function capSpendOf(store: Pick<Store, "learning">, runId: string
62
75
  * when that spend is unknown, or a read fails: the grade is then not run, said so (said.gradeUnknownSpend), never run
63
76
  * with a room nobody knows and never told it has none. */
64
77
  export declare function gradeCapOf(store: Store, runId: string, round: number, launchCapUsd: number): Promise<number | null>;
78
+ /** A workflow text written straight onto the agent's learning folder as a merge by `runId`, from the claim's `seed`: the
79
+ * one direct commit a runner makes outside a learning run (a compile turn's revision). A file changed on main since the
80
+ * seed is a conflict, never written over. The learning commit it landed as, or null when it did not (the reason is
81
+ * logged). The folder is always released. */
82
+ export declare function commitDirect(deps: {
83
+ readonly folder: () => LearningFolder;
84
+ readonly log: (line: string) => void;
85
+ }, files: {
86
+ path: string;
87
+ text: string;
88
+ }[], reason: string, runId: string, seed?: string): Promise<string | null>;
65
89
  /** The learning run of round `round` of run `runId`'s learning: `<runId>-learning` for its first, `<runId>-learning-<n>`
66
90
  * for each later one. */
67
91
  export declare const learningRunIdOf: (runId: string, round?: number) => string;
@@ -78,6 +102,15 @@ export declare function modelsOwn(rows: readonly TimelineEvent[]): (row: Timelin
78
102
  * came in. Anything else is asked its end-of-run turn. Read on the job's turns (withoutFeedbackRounds): a grade's
79
103
  * feedback round is no message of the job's. */
80
104
  export declare function onlyLearnedWorkflows(rows: readonly TimelineEvent[]): boolean;
105
+ /** Whether a run carries its owner's feedback, the only thing a run of a job that compiles workflows is looked back on
106
+ * for: a grade's words its end closes (a feedback round, feedback-round.ts pendingFeedbackOf over its root `entries`),
107
+ * or a person's message after its first in its timeline `rows` (a follow-up, or a word while it ran: traceFrom's
108
+ * feedback), the end-of-run turn's own, a grade's round's and a subagent's (a child conversation's rows carry its
109
+ * spawning call, parent_tool_use_id: its task prompt is the job's, not the owner's) rows left out. */
110
+ export declare function ownerSaid(entries: readonly {
111
+ readonly kind: string;
112
+ readonly data?: unknown;
113
+ }[], rows: readonly TimelineEvent[]): boolean;
81
114
  /** The path a run took (learning-cost.ts RunPath), by its timeline `rows` as runTimeline labels them (its end-of-run
82
115
  * turn's rows, LEARNING_LABEL, are the learning's and left out): `workflow` when its job did only what
83
116
  * onlyLearnedWorkflows asks of a run with nothing new to look back on, `handed_back` when it called a learned workflow
@@ -89,6 +122,20 @@ export declare function workflowNameOf(calls: readonly {
89
122
  tool: string;
90
123
  args: Record<string, unknown>;
91
124
  }[]): string | null;
125
+ /** Compile once: run `runId`'s compile turn whose drafts all failed their checks is the compile's attempt, kept as a
126
+ * promotion record of the shape a check's stop has (runner/promotion.ts stopUnchecked): a hold with nothing checked,
127
+ * its reason (DRAFT_FAILED) naming the failed checks. A first compile's earns the one recompile, as a check's hold
128
+ * does (the agent's next due run compiles once more: learn/compile.ts newCompileAttempt); a recompile's (a revision of
129
+ * a held workflow, or a new one after a first compile's failed drafts) stops (compileStoppedOf, heldNamesOf): nothing
130
+ * compiles it again. One record per run (its digest is the run's), written once: a claim that ends the run again
131
+ * writes none. */
132
+ export declare function recordDraftFailed(deps: Pick<LearningEndDeps, "store" | "log">, input: {
133
+ runId: string;
134
+ agentId: string;
135
+ compile: CompileAsk;
136
+ workflow: string;
137
+ errors: readonly string[];
138
+ }): Promise<void>;
92
139
  /** One earlier run as the compile turn reads it (learn/compile.ts CompileTrace), from its timeline (traceFrom). */
93
140
  export declare function traceOf(store: Store, runId: string, refuse: readonly string[]): Promise<CompileTrace>;
94
141
  /** A run's trace from its timeline rows, the end-of-run turn's (LEARNING_LABEL) left out: its first message (the
@@ -99,12 +146,15 @@ export declare function traceOf(store: Store, runId: string, refuse: readonly st
99
146
  * shape. */
100
147
  export declare function traceFrom(timeline: readonly TimelineEvent[], refuse: readonly string[]): CompileTrace;
101
148
  /** The compile turn's facts for run `runId` of agent `agentId` (learn/compile.ts): a revision of the learned workflow
102
- * that handed the run back or that the money rule stopped (workflow-first.ts servedOf, reviseOf), its text as main holds
103
- * it; or of the one that fits the run's input and whose promotion holds it at main's digest (runner/promotion.ts: its
104
- * replay on the agent's graded inputs, or its graded served runs, fell under the bar; its champion served the run, or the
105
- * agent did by hand), with the
106
- * hold's numbers, once per hold (none when any run since the hold compiled it, read from the agent's kept learning); else, when the job is due (compileDue: the run completed, the agent has no learned workflow active or waiting, none
107
- * of its last COMPILE_QUIET_RUNS runs compiled, and it keeps enough notes or has run enough), a new one. Either way the
149
+ * that fits the run's input and whose promotion holds it at main's digest (runner/promotion.ts: its one check on the
150
+ * agent's own runs fell under the bar; its champion served the run, or the agent did by hand), its text as main holds
151
+ * it, with the check's numbers and the inputs it disagreed on, once per hold (none when any run since the hold compiled
152
+ * it, read from the agent's kept learning; a stopped check's none); else, when the job is due (compileDue: the run
153
+ * completed, the agent has no learned workflow active or waiting, and it has its definition's compile_after completed
154
+ * agent runs), a new one, compiled once: none while the last compile's passing draft waits on its grade
155
+ * (draftAwaitingGrade), one more after a first compile whose drafts all failed their checks, and none after a
156
+ * recompile's (recordDraftFailed). Nothing else asks one: a hand-back, a wrong grade of a served answer and the money rule's
157
+ * stop are single runs, which the hold reads among many. Either way the
108
158
  * agent's active notes whole, the traces of its last COMPILE_TRACES completed runs before this one, the tools a call node
109
159
  * may run (draftTools) with what each takes and gives, its decision providers, the run's input (`input`, its fields for
110
160
  * the workflow's input schema), the agent's output schema when it has one (its final output's shape) and the DSL's
@@ -116,6 +166,5 @@ export declare function compileAskOf(deps: LearningEndDeps, input: {
116
166
  outcome: "completed" | "failed";
117
167
  refuse: readonly string[];
118
168
  input?: unknown;
119
- seedNotes?: number;
120
169
  seedWorkflows?: number;
121
170
  }): Promise<CompileAsk | undefined>;