@parcha/agentrun-serve 0.1.0-beta.56 → 0.1.0-beta.58

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 (312) hide show
  1. package/CHANGELOG.md +281 -0
  2. package/README.md +246 -66
  3. package/dist/acp-package.d.ts +2 -0
  4. package/dist/adapters.d.ts +15 -3
  5. package/dist/adapters.js +17 -6
  6. package/dist/agent-package.d.ts +3 -3
  7. package/dist/agent-package.js +17 -8
  8. package/dist/api-keys.d.ts +76 -0
  9. package/dist/api-keys.js +217 -0
  10. package/dist/api-only.d.ts +15 -5
  11. package/dist/api-only.js +32 -8
  12. package/dist/box-paths.d.ts +4 -3
  13. package/dist/box-paths.js +7 -4
  14. package/dist/browser-hold.d.ts +23 -0
  15. package/dist/browser-hold.js +48 -0
  16. package/dist/browser-person.d.ts +3 -0
  17. package/dist/browser-person.js +4 -1
  18. package/dist/chatgpt-plan.d.ts +18 -8
  19. package/dist/chatgpt-plan.js +91 -34
  20. package/dist/claude-login-token.d.ts +117 -0
  21. package/dist/claude-login-token.js +737 -0
  22. package/dist/claude-login.d.ts +120 -22
  23. package/dist/claude-login.js +347 -63
  24. package/dist/claude-sign-in.d.ts +17 -6
  25. package/dist/claude-sign-in.js +42 -39
  26. package/dist/cli.js +33 -10
  27. package/dist/composio-made.d.ts +4 -0
  28. package/dist/composio-made.js +4 -0
  29. package/dist/composio-preset.d.ts +43 -2
  30. package/dist/composio-preset.js +92 -4
  31. package/dist/computer-attach.d.ts +35 -17
  32. package/dist/computer-attach.js +301 -49
  33. package/dist/computer-held-routes.d.ts +5 -4
  34. package/dist/computer-held-routes.js +29 -8
  35. package/dist/computer-held.d.ts +6 -1
  36. package/dist/computer-held.js +14 -0
  37. package/dist/computer-record.js +4 -2
  38. package/dist/computer-viewer.js +4 -1
  39. package/dist/computers.d.ts +10 -10
  40. package/dist/computers.js +5 -5
  41. package/dist/console/assets/{backend-Boh7tC4i.js → backend-CSAWUqtZ.js} +19 -19
  42. package/dist/console/assets/index-Bwn1oTem.css +1 -0
  43. package/dist/console/assets/index-DPh29cyz.js +747 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/decisions.d.ts +1 -1
  46. package/dist/decisions.js +1 -1
  47. package/dist/dial-relay.d.ts +25 -4
  48. package/dist/dial-relay.js +129 -1
  49. package/dist/docker-host-addresses.d.ts +22 -11
  50. package/dist/docker-host-addresses.js +38 -26
  51. package/dist/env-switch.d.ts +8 -0
  52. package/dist/env-switch.js +31 -2
  53. package/dist/errors.d.ts +1 -0
  54. package/dist/errors.js +2 -0
  55. package/dist/fal-price.d.ts +56 -20
  56. package/dist/fal-price.js +400 -90
  57. package/dist/handed-values.d.ts +43 -1
  58. package/dist/handed-values.js +119 -2
  59. package/dist/harness-archive.d.ts +13 -10
  60. package/dist/harness-archive.js +60 -34
  61. package/dist/harness-check.d.ts +3 -1
  62. package/dist/harness-check.js +25 -46
  63. package/dist/harness-keys.d.ts +73 -27
  64. package/dist/harness-keys.js +194 -61
  65. package/dist/harness-recipe-entry.d.ts +8 -7
  66. package/dist/harness-recipe-entry.js +21 -32
  67. package/dist/harness-recipe.d.ts +38 -25
  68. package/dist/harness-recipe.js +49 -36
  69. package/dist/harness-sign-in.js +12 -23
  70. package/dist/harness-table.d.ts +10 -3
  71. package/dist/harness-table.js +26 -21
  72. package/dist/harness.d.ts +1 -0
  73. package/dist/harness.js +17 -5
  74. package/dist/hosted-search.d.ts +1 -1
  75. package/dist/hosted-search.js +1 -2
  76. package/dist/import-worker.d.ts +4 -2
  77. package/dist/import-worker.js +9 -2
  78. package/dist/in-flight.d.ts +26 -0
  79. package/dist/in-flight.js +52 -0
  80. package/dist/key-refusal.d.ts +9 -4
  81. package/dist/key-refusal.js +107 -25
  82. package/dist/learn/ledger.d.ts +170 -0
  83. package/dist/learn/ledger.js +218 -0
  84. package/dist/learn/promote.d.ts +3 -3
  85. package/dist/learn/promote.js +1 -1
  86. package/dist/learn/secrets.d.ts +13 -3
  87. package/dist/learn/secrets.js +118 -17
  88. package/dist/learning-cost.d.ts +28 -23
  89. package/dist/learning-cost.js +19 -23
  90. package/dist/link-check.js +1 -1
  91. package/dist/live-reach.d.ts +2 -0
  92. package/dist/live-reach.js +2 -0
  93. package/dist/llms.txt +1 -1
  94. package/dist/marketplace.d.ts +77 -0
  95. package/dist/marketplace.js +224 -0
  96. package/dist/mcp-api-only-origins.d.ts +35 -0
  97. package/dist/mcp-api-only-origins.js +57 -0
  98. package/dist/mcp-gateway.d.ts +7 -5
  99. package/dist/mcp-gateway.js +9 -12
  100. package/dist/mcp-secret-writes.js +5 -3
  101. package/dist/mcp-servers-store.d.ts +28 -6
  102. package/dist/mcp-servers-store.js +53 -4
  103. package/dist/media-duration.d.ts +3 -0
  104. package/dist/media-duration.js +90 -9
  105. package/dist/micro.d.ts +2 -0
  106. package/dist/micro.js +2 -0
  107. package/dist/model-form.d.ts +5 -4
  108. package/dist/model-form.js +11 -7
  109. package/dist/model.d.ts +10 -6
  110. package/dist/model.js +16 -11
  111. package/dist/monid.d.ts +14 -1
  112. package/dist/monid.js +103 -26
  113. package/dist/ollama-provider.d.ts +7 -1
  114. package/dist/ollama-provider.js +14 -2
  115. package/dist/openapi.js +210 -37
  116. package/dist/otel/genai.d.ts +65 -0
  117. package/dist/otel/genai.js +116 -0
  118. package/dist/otel/tracer.d.ts +55 -0
  119. package/dist/otel/tracer.js +308 -0
  120. package/dist/page.d.ts +2 -0
  121. package/dist/page.js +3 -1
  122. package/dist/paid-calls.d.ts +1 -32
  123. package/dist/paid-calls.js +4 -39
  124. package/dist/place-offers.d.ts +4 -0
  125. package/dist/place-offers.js +7 -4
  126. package/dist/provider.d.ts +11 -2
  127. package/dist/provider.js +59 -8
  128. package/dist/redact/match.d.ts +30 -3
  129. package/dist/redact/match.js +422 -41
  130. package/dist/refusal-words.d.ts +11 -0
  131. package/dist/refusal-words.js +11 -0
  132. package/dist/run-census.d.ts +67 -0
  133. package/dist/run-census.js +240 -0
  134. package/dist/run-computer.d.ts +6 -3
  135. package/dist/run-computer.js +4 -1
  136. package/dist/run-cut.d.ts +15 -6
  137. package/dist/run-cut.js +30 -9
  138. package/dist/run-files.d.ts +3 -0
  139. package/dist/run-files.js +3 -0
  140. package/dist/run-launch.d.ts +12 -1
  141. package/dist/run-launch.js +9 -10
  142. package/dist/run-learning-served.d.ts +4 -2
  143. package/dist/run-model-key.d.ts +8 -0
  144. package/dist/run-model-key.js +31 -1
  145. package/dist/run-reads-over-store.d.ts +24 -6
  146. package/dist/run-reads-over-store.js +67 -23
  147. package/dist/run-recordings.d.ts +5 -1
  148. package/dist/run-recordings.js +39 -14
  149. package/dist/run-timeline-served.d.ts +2 -0
  150. package/dist/run-timeline-served.js +2 -2
  151. package/dist/run-usage.d.ts +1 -0
  152. package/dist/run-view.d.ts +1 -2
  153. package/dist/run-view.js +2 -1
  154. package/dist/runnable.d.ts +10 -1
  155. package/dist/runnable.js +20 -8
  156. package/dist/runner/adapter-loop.d.ts +11 -0
  157. package/dist/runner/adapter-loop.js +58 -26
  158. package/dist/runner/adapter-run-spec.d.ts +55 -11
  159. package/dist/runner/adapter-run-spec.js +183 -52
  160. package/dist/runner/adapters/pi.js +25 -3
  161. package/dist/runner/beside.d.ts +9 -2
  162. package/dist/runner/beside.js +27 -9
  163. package/dist/runner/big-writes.js +1 -10
  164. package/dist/runner/claim-secrets.d.ts +27 -10
  165. package/dist/runner/claim-secrets.js +49 -22
  166. package/dist/runner/cli-run-spec.d.ts +6 -0
  167. package/dist/runner/cli-run-spec.js +97 -38
  168. package/dist/runner/computer-journal.d.ts +9 -1
  169. package/dist/runner/computer-journal.js +26 -0
  170. package/dist/runner/conformance/harness.js +1 -1
  171. package/dist/runner/feedback-round.js +3 -0
  172. package/dist/runner/harness-loops.d.ts +6 -5
  173. package/dist/runner/harness-loops.js +7 -7
  174. package/dist/runner/held.d.ts +24 -6
  175. package/dist/runner/journal-kinds.d.ts +5 -0
  176. package/dist/runner/journal-kinds.js +5 -0
  177. package/dist/runner/main.d.ts +11 -6
  178. package/dist/runner/main.js +19 -9
  179. package/dist/runner/mcp-claim.js +31 -3
  180. package/dist/runner/mcp-run.d.ts +9 -0
  181. package/dist/runner/mcp-run.js +11 -5
  182. package/dist/runner/model-route.d.ts +17 -0
  183. package/dist/runner/model-route.js +120 -2
  184. package/dist/runner/presence.d.ts +11 -1
  185. package/dist/runner/presence.js +7 -0
  186. package/dist/runner/reflect-hook.js +1 -1
  187. package/dist/runner/run-child-host.d.ts +22 -8
  188. package/dist/runner/run-child-host.js +128 -41
  189. package/dist/runner/run-child.js +5 -2
  190. package/dist/runner/runner.d.ts +17 -3
  191. package/dist/runner/runner.js +130 -34
  192. package/dist/runner/save-slots.js +2 -1
  193. package/dist/runner/store-port.d.ts +1 -1
  194. package/dist/runner/store-secrets.d.ts +6 -0
  195. package/dist/runner/store-secrets.js +49 -7
  196. package/dist/runner/subagent.d.ts +11 -0
  197. package/dist/runner/subagent.js +16 -38
  198. package/dist/runner/workflow-first.d.ts +35 -15
  199. package/dist/runner/workflow-first.js +38 -25
  200. package/dist/runner/workflow-spec.js +4 -3
  201. package/dist/runs-over-store.d.ts +15 -6
  202. package/dist/runs-over-store.js +33 -21
  203. package/dist/scrub-command.d.ts +73 -0
  204. package/dist/scrub-command.js +307 -0
  205. package/dist/secret-cut.d.ts +73 -0
  206. package/dist/secret-cut.js +291 -4
  207. package/dist/secret-rules.d.ts +143 -0
  208. package/dist/secret-rules.js +2564 -0
  209. package/dist/secrets.d.ts +7 -0
  210. package/dist/secrets.js +20 -0
  211. package/dist/server-keys.d.ts +20 -0
  212. package/dist/server-keys.js +25 -6
  213. package/dist/server.d.ts +65 -13
  214. package/dist/server.js +470 -157
  215. package/dist/skills/agentrun-serve/SKILL.md +4 -0
  216. package/dist/slots.d.ts +9 -0
  217. package/dist/slots.js +45 -0
  218. package/dist/store/index.d.ts +1 -1
  219. package/dist/store/index.js +1 -1
  220. package/dist/store/journal/storage.js +1 -1
  221. package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
  222. package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
  223. package/dist/store/schema.d.ts +23 -0
  224. package/dist/store/schema.js +58 -2
  225. package/dist/store/seal.d.ts +6 -1
  226. package/dist/store/seal.js +5 -3
  227. package/dist/store/sqlite/run-launch.d.ts +9 -1
  228. package/dist/store/sqlite/run-launch.js +24 -13
  229. package/dist/store/sqlite/run-patch.d.ts +12 -2
  230. package/dist/store/sqlite/run-patch.js +42 -5
  231. package/dist/store/sqlite/store.js +105 -12
  232. package/dist/store/store.d.ts +57 -2
  233. package/dist/store/store.js +20 -0
  234. package/dist/store-reads/learning.d.ts +84 -124
  235. package/dist/store-reads/learning.js +210 -274
  236. package/dist/store-view.d.ts +3 -0
  237. package/dist/store-view.js +3 -3
  238. package/dist/suggestions.js +3 -2
  239. package/dist/template-eval.d.ts +39 -9
  240. package/dist/template-eval.js +191 -60
  241. package/dist/template-import.js +6 -2
  242. package/dist/templates.d.ts +10 -2
  243. package/dist/templates.js +28 -8
  244. package/dist/timeline/labels.d.ts +6 -4
  245. package/dist/timeline/labels.js +18 -6
  246. package/dist/timeline/timeline.d.ts +5 -0
  247. package/dist/timeline/timeline.js +14 -8
  248. package/dist/timeline/util.js +1 -1
  249. package/dist/timeline/web-calls.d.ts +22 -7
  250. package/dist/timeline/web-calls.js +106 -35
  251. package/dist/tool-gate.d.ts +42 -3
  252. package/dist/tool-gate.js +66 -5
  253. package/dist/tool-keys-store.d.ts +2 -4
  254. package/dist/tool-keys-store.js +5 -21
  255. package/dist/tool-keys.d.ts +2 -2
  256. package/dist/tool-keys.js +2 -2
  257. package/dist/tool-list.js +1 -1
  258. package/dist/tool-plane.d.ts +2 -2
  259. package/dist/tool-plane.js +35 -33
  260. package/dist/tools.js +13 -7
  261. package/dist/trigger-targets.d.ts +4 -0
  262. package/dist/trigger-targets.js +9 -2
  263. package/dist/triggers.d.ts +67 -4
  264. package/dist/triggers.js +171 -22
  265. package/dist/until.d.ts +3 -0
  266. package/dist/until.js +11 -0
  267. package/dist/web-fake.d.ts +1 -3
  268. package/dist/web-fake.js +7 -18
  269. package/dist/web-fetch.d.ts +6 -72
  270. package/dist/web-fetch.js +11 -265
  271. package/dist/web-run.d.ts +31 -0
  272. package/dist/web-run.js +90 -0
  273. package/dist/web-save.d.ts +10 -13
  274. package/dist/web-save.js +13 -55
  275. package/dist/web-search.d.ts +9 -127
  276. package/dist/web-search.js +23 -259
  277. package/dist/wires.d.ts +13 -0
  278. package/dist/wires.js +11 -0
  279. package/dist/workflow-run.d.ts +5 -4
  280. package/dist/workflow-run.js +5 -4
  281. package/dist/workspace/attached-computers.d.ts +32 -9
  282. package/dist/workspace/attached-computers.js +77 -13
  283. package/dist/workspace/computer-deps.d.ts +8 -2
  284. package/dist/workspace/computer-deps.js +10 -3
  285. package/dist/workspace/computer-for-claim.d.ts +12 -1
  286. package/dist/workspace/computer-for-claim.js +83 -11
  287. package/dist/workspace/computer-kept.d.ts +3 -0
  288. package/dist/workspace/computer-kept.js +11 -2
  289. package/dist/workspace/index.d.ts +1 -1
  290. package/dist/workspace/index.js +1 -1
  291. package/dist/workspace/kind-skills.d.ts +4 -0
  292. package/dist/workspace/kind-skills.js +9 -0
  293. package/dist/workspace/paired-route.d.ts +91 -0
  294. package/dist/workspace/paired-route.js +153 -0
  295. package/dist/workspace/synced-folder.js +3 -4
  296. package/dist/wrapped.d.ts +20 -6
  297. package/dist/wrapped.js +66 -25
  298. package/package.json +17 -11
  299. package/skills/agentrun-serve/SKILL.md +4 -0
  300. package/templates/README.md +32 -10
  301. package/dist/console/assets/index-CQ3cJRzI.js +0 -746
  302. package/dist/console/assets/index-DKkaS3a0.css +0 -1
  303. package/dist/exa-keyless.d.ts +0 -34
  304. package/dist/exa-keyless.js +0 -118
  305. package/dist/firecrawl-keyless.d.ts +0 -41
  306. package/dist/firecrawl-keyless.js +0 -152
  307. package/dist/keyless-mcp.d.ts +0 -36
  308. package/dist/keyless-mcp.js +0 -127
  309. package/dist/text-urls.d.ts +0 -38
  310. package/dist/text-urls.js +0 -170
  311. package/dist/web-fetch-direct.d.ts +0 -119
  312. package/dist/web-fetch-direct.js +0 -190
@@ -0,0 +1,170 @@
1
+ import { type Bill, type CostRun, type CostSummary, type NotServed, type RevisionSpend, type RunPath } from "../learning-cost.js";
2
+ /** A run's own cost as its row stores it: `known`, an exact figure; `unknown`, none; `at_most`, only a bound (a request
3
+ * cut at its cap hold), never shown as a cost. */
4
+ export declare const COST_STATES: readonly ["known", "unknown", "at_most"];
5
+ export type CostState = (typeof COST_STATES)[number];
6
+ /** One ended run: who answered it (`path`, null when its end named none), the learned workflow revision that ran it
7
+ * (`workflow` at `digest`; for an audit's shadow, the revision it audits), why that workflow did not serve it alone,
8
+ * the job's own $ (`jobUsd`: what it had cost when its answer was final, its look-back left out) and everything its
9
+ * rounds looked back for (`lookBackUsd`: its compile turns and its follow-up rounds' turns); each null when unknown. */
10
+ export type LedgerRow = {
11
+ readonly runId: string;
12
+ readonly agentId: string;
13
+ readonly startedAt: number;
14
+ readonly path: RunPath | null;
15
+ readonly workflow: string | null;
16
+ readonly digest: string | null;
17
+ readonly notServed: NotServed | null;
18
+ readonly jobUsd: number | null;
19
+ readonly lookBackUsd: number | null;
20
+ readonly cost: CostState;
21
+ };
22
+ /** What a spend row paid for: a compile turn that drafted a revision (`compile`), a replay run checking one (`check`), or
23
+ * an audit's shadow run of a served run (`audit`). */
24
+ export declare const SPEND_KINDS: readonly ["compile", "check", "audit"];
25
+ export type SpendKind = (typeof SPEND_KINDS)[number];
26
+ /** One learning cost: the run whose end booked it (`runId`, with its `round` for a compile turn, 0 otherwise), the run
27
+ * an audit's shadow audited (`ofRun`), the revision it is for (`workflow` at `digest`; a compile that kept no draft drafted
28
+ * none: both null; one whose drafts failed their checks, the workflow alone) and its $ (null: unknown). */
29
+ export type SpendRow = {
30
+ readonly runId: string;
31
+ readonly round: number;
32
+ readonly agentId: string;
33
+ readonly kind: SpendKind;
34
+ readonly ofRun: string | null;
35
+ readonly workflow: string | null;
36
+ readonly digest: string | null;
37
+ readonly usd: number | null;
38
+ };
39
+ /** What record() reads of an ended run: its row (its cost, the bound beside it, its metrics: the run-end classifier's
40
+ * path, workflow and digest, runner/workflow-first.ts pathMetrics) and every round its learning kept (learning_proposals). */
41
+ export type RunEnd = {
42
+ readonly id: string;
43
+ readonly agentId: string;
44
+ readonly startedAt: number;
45
+ readonly costUsd: number | null;
46
+ readonly costAtMostUsd: number | null;
47
+ readonly metrics: unknown;
48
+ readonly rounds: readonly {
49
+ readonly round: number;
50
+ readonly proposal: unknown;
51
+ }[];
52
+ };
53
+ /** What a kept round says of its job as it answered (runner/reflect-hook.ts): when, what the job had cost by then, and
54
+ * what looking back cost after it. */
55
+ export type Answered = {
56
+ readonly answered_at: string;
57
+ readonly job_cost_usd: number | null;
58
+ readonly look_back_usd: number | null;
59
+ };
60
+ /** A kept round's Answered; undefined for one that never answered. */
61
+ export declare const answeredOf: (proposal: unknown) => Answered | undefined;
62
+ /** A run a follow-up opened again: its job is what it had cost when its first round answered, and everything its row
63
+ * (`rowUsd`) spent after that (each later round's follow-up turn and every round's look-back: feedback the run was given
64
+ * is learning, never the job) is its look-back; unknown when the row's cost is and the job's is known (a later round
65
+ * stopped mid-request keeps no figures, so the rounds' sum would read short as if settled); the rounds' look-backs added
66
+ * up when the job's cost is unknown. The impact read (store-reads/learning.ts impactLearningOf) takes the same. */
67
+ export declare function roundsLooked(rounds: Answered, rowUsd: number | null): Answered;
68
+ /** Over a run's kept rounds, oldest first: with two or more and one that answered, what they kept together (its first
69
+ * answer's job, every round's look-back added up, null once one is unknown); else undefined. */
70
+ export declare function roundsSpentIn(proposals: readonly unknown[]): Answered | undefined;
71
+ /** What a run's rounds kept as it answered, as its cost reads it: over every round (roundsLooked) for one a follow-up
72
+ * opened again, else its one round's; undefined for one that never answered. */
73
+ export declare function lookedOf(proposals: readonly unknown[], rowUsd: number | null): Answered | undefined;
74
+ /** The ledger row and spend rows a run's end writes, from its row and its kept rounds (RunEnd). The job's own $ is its
75
+ * row's cost less every look-back, never under what it had cost when it answered (a later turn's spend is the job's
76
+ * too); its row's cost for a run that did not look back. Its compile turns are spend rows of the revision each drafted.
77
+ * A replay run's cost is its revision's check, and an audit's shadow run's the run it audits: a spend row each, beside
78
+ * its own ledger row. */
79
+ export declare function record(end: RunEnd): {
80
+ row: LedgerRow;
81
+ spend: SpendRow[];
82
+ };
83
+ /** The audit spend row of shadow run `shadow` of run `ofRun`, from its row alone: for a shadow whose end named no audit
84
+ * (it failed before its end wrote its metrics), found by its id (learn/audit.ts shadowRunId). Its cost is the row's,
85
+ * null when unknown or only a bound. */
86
+ export declare function shadowSpend(shadow: Pick<RunEnd, "id" | "agentId" | "costUsd" | "costAtMostUsd">, ofRun: string): SpendRow;
87
+ /** An audit's shadow run of a run, as the reader finds it: `open` while it is queued or running (its cost not known yet),
88
+ * `ended` once it ended, stopped or failed. A run with none has no entry. */
89
+ export type Shadow = "open" | "ended";
90
+ /** A run's figures, every one null when unknown, never $0 for unknown:
91
+ * - `usd`: the job's own $ (GET /runs/{id} `cost.usd`, the series' `cost_usd`);
92
+ * - `compile_usd`, `followup_usd`, `shadow_usd`: its own compile turns, the rest of its look-back (its follow-up rounds'
93
+ * turns) and its audit's shadow run;
94
+ * - `share_usd`: its share of its revision's compile and check (amortize), 0 for a run that carries none;
95
+ * - `series_learning_usd` and `series_total_usd`: the cost series' `learning_usd` (its whole look-back and its shadow)
96
+ * and `total_usd`, the all-in both sides of the money rule read;
97
+ * - `learning_usd` and `all_in_usd`: GET /runs/{id}'s (its follow-ups, its shadow and its share: its compile turns are
98
+ * its revision's), 0 for a replay or a shadow run, whose spend is on the runs it serves. */
99
+ export type RunFigures = {
100
+ readonly usd: number | null;
101
+ readonly compile_usd: number | null;
102
+ readonly followup_usd: number | null;
103
+ readonly shadow_usd: number | null;
104
+ readonly share_usd: number | null;
105
+ readonly series_learning_usd: number | null;
106
+ readonly series_total_usd: number | null;
107
+ readonly learning_usd: number | null;
108
+ readonly all_in_usd: number | null;
109
+ };
110
+ /** One run's figures (RunFigures) from its row and the parts the spend rows give it (its compile turns, its shadow's
111
+ * cost, its share): the one formula every reader of a run's cost takes. */
112
+ export declare function figuresOf(row: Pick<LedgerRow, "path" | "jobUsd" | "lookBackUsd">, parts: {
113
+ readonly compile: number | null;
114
+ readonly shadow: number | null;
115
+ readonly share: number | null;
116
+ }): RunFigures;
117
+ /** The spend rows read by run: each run's compile turns (null once one is unknown) and each audited run's shadow cost. */
118
+ export declare function spendByRun(spend: readonly SpendRow[]): {
119
+ compile: Map<string, number | null>;
120
+ audit: Map<string, number | null>;
121
+ };
122
+ /** A run's shadow cost: 0 with none; unknown while it is at work, or once it ended with no spend row; its spend row's
123
+ * once it has one. */
124
+ export declare function shadowCostOf(runId: string, audit: ReadonlyMap<string, number | null>, shadows: ReadonlyMap<string, Shadow>): number | null;
125
+ /** A revision of a learned workflow as its records say it now (store-reads/learning.ts revisionsOf): the served runs its
126
+ * spend is spread over (`k`, its check's compile_after) and where it stands. Order is the records'. */
127
+ export type RevisionAt = {
128
+ readonly workflow: string;
129
+ readonly digest: string;
130
+ readonly k: number;
131
+ readonly state: RevisionSpend["state"];
132
+ };
133
+ /** What summarize reads:
134
+ * - `rows`, the runs of the series (ended, neither imported nor archived nor purged, no workflow revision's run, no
135
+ * shadow), any order, each with its path (null: its end named none);
136
+ * - `spend`, the agent's spend rows: a compile or a check of a run `rows` leaves out is left out as its run is, an
137
+ * audit's by the run it audits;
138
+ * - `shadows`, each run's audit shadow by the run it audits;
139
+ * - `learning`, the runs of `rows` whose spend and service make up a revision's (on no named disk: one on a named disk
140
+ * learns nothing and serves nothing, learn/learning-of.ts); absent, every one;
141
+ * - `revisions`, as the records say them; `compileAfter`, the K of a revision no record names;
142
+ * - `named`, the workflow name a run's series row shows (its row's when absent).
143
+ * The summary's `replay` is the records' (store-reads/learning.ts servingReplayOf), null here. */
144
+ export type LedgerRead = {
145
+ readonly rows: readonly LedgerRow[];
146
+ readonly spend: readonly SpendRow[];
147
+ readonly shadows: ReadonlyMap<string, Shadow>;
148
+ readonly learning?: ReadonlySet<string>;
149
+ readonly revisions: readonly RevisionAt[];
150
+ readonly compileAfter: number;
151
+ readonly named?: (row: LedgerRow) => string | null;
152
+ };
153
+ export type Summarized = {
154
+ runs: CostRun[];
155
+ summary: CostSummary;
156
+ bill: Omit<Bill, "holds">;
157
+ figures: Map<string, RunFigures>;
158
+ unknown_path_runs: number;
159
+ };
160
+ /** What the ledger says over an agent's series: each run of it (`runs`, oldest first, every one), what they show
161
+ * (`summary`), the owner's bill (`bill`, its holds aside: they are the records'), each run's figures by id (`figures`)
162
+ * and the rows whose end named no path (`unknown_path_runs`, left out of all of it). Every sum is over every run.
163
+ *
164
+ * A revision is its workflow and its digest, never the digest alone: two workflows of the same text share a digest, and
165
+ * each pays its own way. Its spend is its compile turns and its check's replay runs (spend rows of its workflow at its
166
+ * digest), whether or not a record names it or the records were trimmed: one no record names follows the ones that do,
167
+ * at `compileAfter`, `checking` while it is its workflow's newest spend, else `stopped`. It is spread over its first K
168
+ * served runs (amortize). What no run carries is the booked total less every run's all-in, unknown while any run's
169
+ * figures are. */
170
+ export declare function summarize(read: LedgerRead): Summarized;
@@ -0,0 +1,218 @@
1
+ // The ledger: one row a run, written by its end, and one spend row a learning cost (a compile turn, a check's replay run,
2
+ // an audit's shadow run), keyed to the workflow revision it is for. record() is what a run's end writes, in the end's own
3
+ // transaction (store/sqlite/run-patch.ts); summarize() is the one reading of them, which GET /agents/{id}/learning/cost,
4
+ // GET /runs/{id}'s cost and the money rule (runner/workflow-first.ts costLineOf, over RunFigures) all take. Pure: no
5
+ // store, no clock.
6
+ import { amortize, billOf, costSummary, JOB_PATHS, NOT_SERVED, noiseOff, RUN_PATHS, SERVED_PATHS, tookOverOf } from "../learning-cost.js";
7
+ /** A run's own cost as its row stores it: `known`, an exact figure; `unknown`, none; `at_most`, only a bound (a request
8
+ * cut at its cap hold), never shown as a cost. */
9
+ export const COST_STATES = ["known", "unknown", "at_most"];
10
+ /** What a spend row paid for: a compile turn that drafted a revision (`compile`), a replay run checking one (`check`), or
11
+ * an audit's shadow run of a served run (`audit`). */
12
+ export const SPEND_KINDS = ["compile", "check", "audit"];
13
+ const usdOrNull = (value) => (typeof value === "number" && Number.isFinite(value) ? value : null);
14
+ const textOrNull = (value) => (typeof value === "string" ? value : null);
15
+ const objectOf = (value) => (value && typeof value === "object" && !Array.isArray(value) ? value : {});
16
+ /** A sum of parts, null once one is unknown; 0 for none. */
17
+ const sumOf = (parts) => (parts.some((one) => one === null) ? null : noiseOff(parts.reduce((total, one) => total + one, 0)));
18
+ /** A kept round's Answered; undefined for one that never answered. */
19
+ export const answeredOf = (proposal) => {
20
+ const kept = objectOf(proposal);
21
+ return typeof kept.answered_at === "string" ? { answered_at: kept.answered_at, job_cost_usd: usdOrNull(kept.job_cost_usd), look_back_usd: usdOrNull(kept.look_back_usd) } : undefined;
22
+ };
23
+ /** A run a follow-up opened again: its job is what it had cost when its first round answered, and everything its row
24
+ * (`rowUsd`) spent after that (each later round's follow-up turn and every round's look-back: feedback the run was given
25
+ * is learning, never the job) is its look-back; unknown when the row's cost is and the job's is known (a later round
26
+ * stopped mid-request keeps no figures, so the rounds' sum would read short as if settled); the rounds' look-backs added
27
+ * up when the job's cost is unknown. The impact read (store-reads/learning.ts impactLearningOf) takes the same. */
28
+ export function roundsLooked(rounds, rowUsd) {
29
+ const after = rounds.job_cost_usd === null ? rounds.look_back_usd : rowUsd === null ? null : Math.max(0, Math.round((rowUsd - rounds.job_cost_usd) * 1e9) / 1e9);
30
+ return { answered_at: rounds.answered_at, job_cost_usd: rounds.job_cost_usd, look_back_usd: after };
31
+ }
32
+ /** Over a run's kept rounds, oldest first: with two or more and one that answered, what they kept together (its first
33
+ * answer's job, every round's look-back added up, null once one is unknown); else undefined. */
34
+ export function roundsSpentIn(proposals) {
35
+ if (proposals.length < 2)
36
+ return undefined;
37
+ let first;
38
+ let look = 0;
39
+ for (const proposal of proposals) {
40
+ const answered = answeredOf(proposal);
41
+ if (!first && answered)
42
+ first = answered;
43
+ // A round that never looked back (no figures kept) added none.
44
+ if (answered)
45
+ look = look === null || answered.look_back_usd === null ? null : look + answered.look_back_usd;
46
+ }
47
+ return first ? { answered_at: first.answered_at, job_cost_usd: first.job_cost_usd, look_back_usd: look } : undefined;
48
+ }
49
+ /** What a run's rounds kept as it answered, as its cost reads it: over every round (roundsLooked) for one a follow-up
50
+ * opened again, else its one round's; undefined for one that never answered. */
51
+ export function lookedOf(proposals, rowUsd) {
52
+ const together = roundsSpentIn(proposals);
53
+ return together ? roundsLooked(together, rowUsd) : proposals.length ? answeredOf(proposals.at(-1)) : undefined;
54
+ }
55
+ function compilesIn(rounds) {
56
+ return rounds.flatMap(({ round, proposal }) => {
57
+ const kept = objectOf(proposal);
58
+ const usd = "look_back_usd" in kept ? usdOrNull(kept.look_back_usd) : 0;
59
+ const compiled = objectOf(kept.compiled);
60
+ if (typeof compiled.workflow !== "string")
61
+ return usd === 0 ? [] : [{ round, workflow: null, digest: null, usd }];
62
+ const failed = Array.isArray(kept.draft_errors) && kept.draft_errors.some((one) => typeof one === "string");
63
+ const digest = typeof compiled.digest === "string" && /^[0-9a-f]{16}$/.test(compiled.digest) && !failed ? compiled.digest : null;
64
+ return [{ round, workflow: compiled.workflow, digest, usd }];
65
+ });
66
+ }
67
+ /** The ledger row and spend rows a run's end writes, from its row and its kept rounds (RunEnd). The job's own $ is its
68
+ * row's cost less every look-back, never under what it had cost when it answered (a later turn's spend is the job's
69
+ * too); its row's cost for a run that did not look back. Its compile turns are spend rows of the revision each drafted.
70
+ * A replay run's cost is its revision's check, and an audit's shadow run's the run it audits: a spend row each, beside
71
+ * its own ledger row. */
72
+ export function record(end) {
73
+ const metrics = objectOf(end.metrics);
74
+ const cost = typeof end.costAtMostUsd === "number" ? "at_most" : end.costUsd === null ? "unknown" : "known";
75
+ const rowUsd = cost === "known" ? end.costUsd : null;
76
+ const rounds = [...end.rounds].sort((a, b) => a.round - b.round);
77
+ const looked = lookedOf(rounds.map((one) => one.proposal), rowUsd);
78
+ const asAnswered = looked ? looked.job_cost_usd : rowUsd;
79
+ const back = looked ? looked.look_back_usd : 0;
80
+ // What the row holds past the answer and its look-back is a later turn's spend, unknown once the row's cost is; with the
81
+ // look-back's cost unknown the two can't be told apart, and the job is what it had cost when it answered.
82
+ const job = !looked || asAnswered === null || back === null ? asAnswered : rowUsd === null ? null : Math.max(asAnswered, rowUsd - back);
83
+ const path = RUN_PATHS.includes(metrics.path) ? metrics.path : null;
84
+ const audit = objectOf(metrics.audit);
85
+ const audited = path === "audit";
86
+ const workflow = textOrNull(audited ? audit.workflow : metrics.workflow);
87
+ const digest = textOrNull(audited ? audit.digest : metrics.workflow_digest);
88
+ // A hand-back a restart cut (pathMetrics workflow_cut) is `cut`, never the workflow's own `back`.
89
+ const cut = path === "handed_back" && metrics.workflow_cut === true;
90
+ const notServed = cut ? "cut" : NOT_SERVED.includes(metrics.not_served) ? metrics.not_served : null;
91
+ const row = {
92
+ runId: end.id, agentId: end.agentId, startedAt: end.startedAt, path, workflow, digest, notServed,
93
+ jobUsd: job === null ? null : noiseOff(job), lookBackUsd: back === null ? null : noiseOff(back), cost,
94
+ };
95
+ const base = { runId: end.id, agentId: end.agentId };
96
+ const spend = compilesIn(rounds).map((one) => ({ ...base, round: one.round, kind: "compile", ofRun: null, workflow: one.workflow, digest: one.digest, usd: one.usd }));
97
+ if (path === "replay")
98
+ spend.push({ ...base, round: 0, kind: "check", ofRun: null, workflow, digest, usd: rowUsd });
99
+ if (audited)
100
+ spend.push({ ...base, round: 0, kind: "audit", ofRun: textOrNull(audit.of), workflow, digest, usd: rowUsd });
101
+ return { row, spend };
102
+ }
103
+ /** The audit spend row of shadow run `shadow` of run `ofRun`, from its row alone: for a shadow whose end named no audit
104
+ * (it failed before its end wrote its metrics), found by its id (learn/audit.ts shadowRunId). Its cost is the row's,
105
+ * null when unknown or only a bound. */
106
+ export function shadowSpend(shadow, ofRun) {
107
+ const usd = typeof shadow.costAtMostUsd === "number" ? null : shadow.costUsd;
108
+ return { runId: shadow.id, agentId: shadow.agentId, round: 0, kind: "audit", ofRun, workflow: null, digest: null, usd };
109
+ }
110
+ /** One run's figures (RunFigures) from its row and the parts the spend rows give it (its compile turns, its shadow's
111
+ * cost, its share): the one formula every reader of a run's cost takes. */
112
+ export function figuresOf(row, parts) {
113
+ const { compile, shadow, share } = parts;
114
+ const back = row.lookBackUsd;
115
+ const followup = back === null || compile === null ? null : noiseOff(Math.max(0, back - compile));
116
+ const seriesLearning = sumOf([back, shadow]);
117
+ const learns = row.path !== "replay" && row.path !== "audit";
118
+ const learning = learns ? sumOf([followup, shadow, share]) : 0;
119
+ return {
120
+ usd: row.jobUsd, compile_usd: compile, followup_usd: followup, shadow_usd: shadow, share_usd: learns ? share : 0,
121
+ series_learning_usd: seriesLearning, series_total_usd: sumOf([row.jobUsd, seriesLearning]),
122
+ learning_usd: learning, all_in_usd: learns ? sumOf([row.jobUsd, learning]) : 0,
123
+ };
124
+ }
125
+ /** The spend rows read by run: each run's compile turns (null once one is unknown) and each audited run's shadow cost. */
126
+ export function spendByRun(spend) {
127
+ const compile = new Map();
128
+ const audit = new Map();
129
+ const add = (map, key, usd) => map.set(key, map.has(key) ? sumOf([map.get(key), usd]) : usd);
130
+ for (const one of spend) {
131
+ if (one.kind === "compile")
132
+ add(compile, one.runId, one.usd);
133
+ else if (one.kind === "audit" && one.ofRun !== null)
134
+ add(audit, one.ofRun, one.usd);
135
+ }
136
+ return { compile, audit };
137
+ }
138
+ /** A run's shadow cost: 0 with none; unknown while it is at work, or once it ended with no spend row; its spend row's
139
+ * once it has one. */
140
+ export function shadowCostOf(runId, audit, shadows) {
141
+ const state = shadows.get(runId);
142
+ if (state === "open")
143
+ return null;
144
+ if (audit.has(runId))
145
+ return audit.get(runId);
146
+ return state === "ended" ? null : 0;
147
+ }
148
+ /** What the ledger says over an agent's series: each run of it (`runs`, oldest first, every one), what they show
149
+ * (`summary`), the owner's bill (`bill`, its holds aside: they are the records'), each run's figures by id (`figures`)
150
+ * and the rows whose end named no path (`unknown_path_runs`, left out of all of it). Every sum is over every run.
151
+ *
152
+ * A revision is its workflow and its digest, never the digest alone: two workflows of the same text share a digest, and
153
+ * each pays its own way. Its spend is its compile turns and its check's replay runs (spend rows of its workflow at its
154
+ * digest), whether or not a record names it or the records were trimmed: one no record names follows the ones that do,
155
+ * at `compileAfter`, `checking` while it is its workflow's newest spend, else `stopped`. It is spread over its first K
156
+ * served runs (amortize). What no run carries is the booked total less every run's all-in, unknown while any run's
157
+ * figures are. */
158
+ export function summarize(read) {
159
+ const ordered = read.rows.filter((row) => row.path !== null && row.path !== "audit").sort((a, b) => a.startedAt - b.startedAt || (a.runId < b.runId ? -1 : a.runId > b.runId ? 1 : 0));
160
+ const unknownPath = read.rows.filter((row) => row.path === null).length;
161
+ const place = new Map(ordered.map((row, at) => [row.runId, at]));
162
+ const learns = (runId) => place.has(runId) && (read.learning?.has(runId) ?? true);
163
+ const spend = read.spend.filter((one) => (one.kind === "audit" ? place.has(one.ofRun ?? "") : learns(one.runId)));
164
+ const { compile, audit } = spendByRun(spend);
165
+ const partsOf = (row, share) => ({ compile: compile.has(row.runId) ? compile.get(row.runId) : 0, shadow: shadowCostOf(row.runId, audit, read.shadows), share });
166
+ // One numbering, the bill's: the runs that do a job, 1 the first; a replay checks a revision and has none.
167
+ let jobs = 0;
168
+ const series = ordered.map((row) => {
169
+ const figures = figuresOf(row, partsOf(row, 0));
170
+ const path = row.path;
171
+ return {
172
+ n: JOB_PATHS.includes(path) ? (jobs += 1) : null, run_id: row.runId, started_at: new Date(row.startedAt).toISOString(), path,
173
+ workflow: path === "agent" ? null : read.named ? read.named(row) : row.workflow,
174
+ digest: path === "agent" || row.workflow === null ? null : row.digest,
175
+ audited: read.shadows.has(row.runId) || audit.has(row.runId),
176
+ cost_usd: figures.usd, cost_upper_bound: row.cost === "at_most", learning_usd: figures.series_learning_usd, total_usd: figures.series_total_usd,
177
+ compile_usd: figures.compile_usd, followup_usd: figures.followup_usd, shadow_usd: figures.shadow_usd, share_usd: 0, not_served: row.notServed,
178
+ };
179
+ });
180
+ const summary = costSummary(tookOverOf(series), null, new Set(series.flatMap((run) => (run.not_served === "cut" ? [run.run_id] : []))));
181
+ const booked = billOf(tookOverOf(series), summary);
182
+ // Each revision's compile and check, in spend order (the runs' order, then the rounds').
183
+ const key = (workflow, digest) => `${workflow}\0${digest}`;
184
+ const parts = new Map();
185
+ const newest = new Map();
186
+ // An audit's row is the run it audits' (its shadow is no run of the series): it is no revision's spend.
187
+ for (const one of spend.filter((each) => each.kind !== "audit").sort((a, b) => place.get(a.runId) - place.get(b.runId) || a.round - b.round)) {
188
+ if (one.workflow === null || one.digest === null)
189
+ continue;
190
+ const at = key(one.workflow, one.digest);
191
+ const entry = parts.get(at) ?? { workflow: one.workflow, digest: one.digest, compile: [], check: [] };
192
+ (one.kind === "compile" ? entry.compile : entry.check).push(one.usd);
193
+ parts.set(at, entry);
194
+ newest.set(one.workflow, at);
195
+ }
196
+ const spendOf = (workflow, digest, k, state) => {
197
+ const entry = parts.get(key(workflow, digest));
198
+ const compileUsd = sumOf(entry?.compile ?? []);
199
+ const checkUsd = sumOf(entry?.check ?? []);
200
+ return { workflow, digest, compile_usd: compileUsd, check_usd: checkUsd, spend_usd: sumOf([compileUsd, checkUsd]), k, state };
201
+ };
202
+ const named = new Set(read.revisions.map((one) => key(one.workflow, one.digest)));
203
+ const revisions = [
204
+ ...read.revisions.map((one) => spendOf(one.workflow, one.digest, one.k, one.state)),
205
+ ...[...parts].filter(([at]) => !named.has(at)).map(([at, entry]) => spendOf(entry.workflow, entry.digest, read.compileAfter, newest.get(entry.workflow) === at ? "checking" : "stopped")),
206
+ ];
207
+ const served = ordered.flatMap((row) => (learns(row.runId) && SERVED_PATHS.includes(row.path) && row.workflow !== null && row.digest !== null ? [{ run_id: row.runId, workflow: row.workflow, digest: row.digest }] : []));
208
+ const split = amortize(revisions, served);
209
+ const figures = new Map(ordered.map((row) => [row.runId, figuresOf(row, partsOf(row, split.shares.has(row.runId) ? split.shares.get(row.runId) : 0))]));
210
+ const runs = tookOverOf(series.map((run) => ({ ...run, share_usd: figures.get(run.run_id).share_usd })));
211
+ let carried = 0;
212
+ for (const row of ordered) {
213
+ const all = row.path === "replay" ? 0 : row.cost === "at_most" ? null : figures.get(row.runId).all_in_usd;
214
+ carried = carried === null || all === null ? null : noiseOff(carried + all);
215
+ }
216
+ const unattributed = booked.withheld > 0 || carried === null ? null : noiseOff(booked.booked_usd - carried);
217
+ return { runs, summary, bill: { ...booked, revisions: split.revisions, unattributed_usd: unattributed }, figures, unknown_path_runs: unknownPath };
218
+ }
@@ -220,7 +220,7 @@ export declare const gradesKey: (agentId: string) => string;
220
220
  export declare const promotionsKey: (agentId: string) => string;
221
221
  /** A learned workflow revision an agent's learning reset deleted (DELETE /agents/{id}/learning, learning-reset.ts): its
222
222
  * workflow, its digest and its K (its check's compile_after; null when its records named none), nothing else of its
223
- * records. What the runs it served carry of its compile and check (store-reads/learning.ts revisionLedgerOf) is read
223
+ * records. What the runs it served carry of its compile and check (learn/ledger.ts summarize, store-reads/learning.ts revisionsOf) is read
224
224
  * from it after the reset, so a kept run's cost reads as before. The runs keep the same names and digests. */
225
225
  export interface ResetRevision {
226
226
  readonly workflow: string;
@@ -232,7 +232,7 @@ export declare const resetLedgerKey: (agentId: string) => string;
232
232
  export declare const resetLedgerOf: (settings: Pick<Settings, "get">, agentId: string) => Promise<ResetRevision[]>;
233
233
  /** Each revision `records` name (one per workflow and digest, its newest record's K) added to the agent's reset ledger,
234
234
  * before a reset deletes the records. A revision it holds already keeps its place and takes the records' K: while they
235
- * stood, the ledger read their K (revisionLedgerOf), so the runs' shares read the same after this reset too. */
235
+ * stood, the ledger read their K (store-reads/learning.ts revisionsOf), so the runs' shares read the same after this reset too. */
236
236
  export declare function keepResetLedger(settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, records: readonly PromotionRecord[]): Promise<void>;
237
237
  /** The agent's reset watermark: when its newest reset began (epoch ms). Learning reads only the runs after it
238
238
  * (learn/compile.ts sinceReset): a run that started, or read its learning seed, at or before it learns nothing and is
@@ -427,7 +427,7 @@ export declare function comparedOf(value: unknown): Compared | undefined;
427
427
  export declare const gradeView: (grade: Grade) => {
428
428
  source: "feedback" | "eval";
429
429
  graded_at: string;
430
- path: "agent" | "workflow" | "replay" | "audit" | "handed_back";
430
+ path: "agent" | "handed_back" | "workflow" | "replay" | "audit";
431
431
  workflow: string | null;
432
432
  workflow_digest: string | null;
433
433
  feedback: "correction" | null;
@@ -74,7 +74,7 @@ export const resetLedgerKey = (agentId) => `learning.reset-ledger.${agentId}`;
74
74
  export const resetLedgerOf = async (settings, agentId) => itemsOf(await settings.get(resetLedgerKey(agentId)));
75
75
  /** Each revision `records` name (one per workflow and digest, its newest record's K) added to the agent's reset ledger,
76
76
  * before a reset deletes the records. A revision it holds already keeps its place and takes the records' K: while they
77
- * stood, the ledger read their K (revisionLedgerOf), so the runs' shares read the same after this reset too. */
77
+ * stood, the ledger read their K (store-reads/learning.ts revisionsOf), so the runs' shares read the same after this reset too. */
78
78
  export async function keepResetLedger(settings, agentId, records) {
79
79
  const newest = new Map();
80
80
  for (const record of records)
@@ -1,4 +1,4 @@
1
- import { type Span } from "../redact/match.js";
1
+ import { type Needles, type Span } from "../redact/match.js";
2
2
  /** Whether `text` ends in a `Bearer` scheme and the blanks after it: the one place a shape is read across whitespace
3
3
  * (the scheme, then its token), so a reader that cuts a text at whitespace must not cut there (key-refusal.ts
4
4
  * redactedAnswer). */
@@ -19,8 +19,15 @@ export declare const PRINT_MAX = 4096;
19
19
  * form not found as it stands (percent encoded, split by whitespace, an NFKC variant), read in `text` as given, is
20
20
  * redacted whole, never in part, unless every character of it is inside what the finds cut: a cut can hide part of a
21
21
  * value, so the rest is looked for before the cut (redact/match.ts planCut). So is a text over `max` bytes (PRINT_MAX
22
- * unless the caller names more), and one whose cut leaves a value or a shape. */
23
- export declare function redactSecrets(text: string, values: readonly string[], max?: number): string;
22
+ * unless the caller names more), and one whose cut leaves a value or a shape. `held`: spans of `text` cut in place
23
+ * beside the finds (heldSpans, of values no longer at hand). */
24
+ export declare function redactSecrets(text: string, values: readonly string[], max?: number, held?: readonly (readonly [number, number])[]): string;
25
+ /** Where redactSecrets cuts `values` in `text`, shapes left out: each span it cuts in place (UTF-16 offsets, overlapping
26
+ * ones merged, in order), or "whole" when its checks over them cut the text whole (a value split by a line break,
27
+ * percent encoded, an NFKC variant, read in the text as it came: redact/match.ts planCut). What a run's census keeps of
28
+ * a file, never the values (run-census.ts): redactSecrets given these spans as `held` cuts the text as it would have
29
+ * with the values among its own. */
30
+ export declare function heldSpans(text: string, values: readonly string[]): Span[] | "whole";
24
31
  /** `text` as redactSecrets cuts it, and of a bank's numbers beside their words too (MONEY_SHAPES): what learning prints
25
32
  * and serves of what it learned or refused (a problem's path and detail, a note read), never a run's own view, which
26
33
  * may show its user an account number. */
@@ -37,6 +44,9 @@ export declare function cutSecrets(text: string, values: readonly string[], max?
37
44
  * reader that cut it in pieces cut each), or else those redactSecrets makes of `text` whole (its values' forms, hexes
38
45
  * and folded identifiers, and the secret shapes, found as they stand). */
39
46
  export declare function valueLeft(text: string, values: readonly string[], cuts?: readonly Span[]): boolean;
47
+ /** What the matcher looks for of `values` (derivedOf, cached by array): the scrubber's held rule (secret-rules.ts) cuts
48
+ * each form, hex and folded identifier in place with redact/match.ts cutSpans. */
49
+ export declare const heldNeedles: (values: readonly string[]) => Needles;
40
50
  /** A value shorter than this matches too much text by chance to be refused. */
41
51
  export declare const MIN_SECRET = 8;
42
52
  /** An excerpt of a run's input or answer as learning keeps it: `text` cut of the secrets `shown` knows, whole, then