@parcha/agentrun-serve 0.1.0-beta.59 → 0.1.0-beta.60

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 (194) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +188 -106
  3. package/dist/agent-delete.d.ts +6 -9
  4. package/dist/agent-delete.js +5 -3
  5. package/dist/agent-package.js +11 -1
  6. package/dist/api-only.d.ts +2 -2
  7. package/dist/api-only.js +3 -3
  8. package/dist/archil-routes.d.ts +4 -1
  9. package/dist/archil-routes.js +15 -12
  10. package/dist/archil-settings.d.ts +18 -8
  11. package/dist/archil-settings.js +35 -17
  12. package/dist/chatgpt-plan.d.ts +4 -2
  13. package/dist/chatgpt-plan.js +13 -3
  14. package/dist/claude-login-token.d.ts +5 -0
  15. package/dist/claude-login-token.js +8 -0
  16. package/dist/claude-login.d.ts +49 -3
  17. package/dist/claude-login.js +140 -10
  18. package/dist/cli-learning/connections.js +1 -1
  19. package/dist/console/assets/{backend-BztxEAvb.js → backend-QnwGVBeU.js} +1 -1
  20. package/dist/console/assets/index-DZi-muIj.js +629 -0
  21. package/dist/console/assets/{share-L84tlUDW.js → share-pz61zIn9.js} +2 -2
  22. package/dist/console/assets/{styles-CaRKlHke.js → styles-CcceGcu2.js} +31 -31
  23. package/dist/console/assets/styles-fjQBFfMv.css +1 -0
  24. package/dist/console/index.html +3 -3
  25. package/dist/console/share.html +3 -3
  26. package/dist/decisions.d.ts +1 -1
  27. package/dist/decisions.js +2 -2
  28. package/dist/factory-activity.d.ts +68 -0
  29. package/dist/factory-activity.js +153 -0
  30. package/dist/factory-runs.d.ts +11 -0
  31. package/dist/factory-runs.js +52 -0
  32. package/dist/filed-tool.d.ts +32 -0
  33. package/dist/filed-tool.js +122 -0
  34. package/dist/harness-keys.d.ts +1 -2
  35. package/dist/harness-keys.js +1 -2
  36. package/dist/harness-table.d.ts +4 -0
  37. package/dist/harness-table.js +4 -0
  38. package/dist/harness.js +6 -2
  39. package/dist/import-worker.js +2 -2
  40. package/dist/import.d.ts +9 -0
  41. package/dist/import.js +11 -1
  42. package/dist/key-refusal.d.ts +5 -0
  43. package/dist/key-refusal.js +25 -15
  44. package/dist/learn/audit.d.ts +20 -22
  45. package/dist/learn/audit.js +72 -55
  46. package/dist/learn/check.js +1 -1
  47. package/dist/learn/commit.d.ts +35 -43
  48. package/dist/learn/commit.js +62 -270
  49. package/dist/learn/compile.d.ts +4 -4
  50. package/dist/learn/compile.js +6 -7
  51. package/dist/learn/corrections.js +1 -1
  52. package/dist/learn/delete.d.ts +5 -12
  53. package/dist/learn/delete.js +17 -30
  54. package/dist/learn/forget-run.d.ts +16 -0
  55. package/dist/learn/forget-run.js +53 -0
  56. package/dist/learn/index.js +1 -1
  57. package/dist/learn/learning-of.d.ts +0 -4
  58. package/dist/learn/learning-of.js +0 -5
  59. package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
  60. package/dist/learn/{folder.js → legacy/folder.js} +4 -7
  61. package/dist/learn/legacy/place.d.ts +16 -0
  62. package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
  63. package/dist/learn/legacy/scrub.d.ts +28 -0
  64. package/dist/learn/legacy/scrub.js +258 -0
  65. package/dist/learn/promote.d.ts +40 -66
  66. package/dist/learn/promote.js +69 -207
  67. package/dist/learn/reset-ledger.d.ts +18 -0
  68. package/dist/learn/reset-ledger.js +14 -0
  69. package/dist/learn/rows.d.ts +186 -0
  70. package/dist/learn/rows.js +376 -0
  71. package/dist/learn/workflow-draft.d.ts +4 -1
  72. package/dist/learn/workflow-draft.js +12 -2
  73. package/dist/learning-reset.d.ts +1 -1
  74. package/dist/learning-reset.js +9 -11
  75. package/dist/learning-routes.d.ts +60 -81
  76. package/dist/learning-routes.js +187 -360
  77. package/dist/learning-words.d.ts +2 -0
  78. package/dist/learning-words.js +2 -0
  79. package/dist/learning.d.ts +18 -24
  80. package/dist/learning.js +35 -66
  81. package/dist/mcp-gateway.d.ts +6 -0
  82. package/dist/mcp-gateway.js +44 -8
  83. package/dist/mcp-resources.d.ts +1 -1
  84. package/dist/native/discovery.d.ts +6 -0
  85. package/dist/native/discovery.js +14 -1
  86. package/dist/native/remote.d.ts +5 -0
  87. package/dist/native/remote.js +16 -0
  88. package/dist/native/runtime.js +3 -2
  89. package/dist/observation/observer.d.ts +6 -6
  90. package/dist/openapi.js +89 -29
  91. package/dist/place-offers.d.ts +3 -0
  92. package/dist/place-offers.js +3 -0
  93. package/dist/place.d.ts +33 -11
  94. package/dist/place.js +61 -26
  95. package/dist/purged-workflow.d.ts +0 -33
  96. package/dist/purged-workflow.js +3 -71
  97. package/dist/redact/match.d.ts +19 -4
  98. package/dist/redact/match.js +123 -30
  99. package/dist/run-launch.d.ts +3 -3
  100. package/dist/run-learning-served.d.ts +3 -3
  101. package/dist/run-learning-served.js +1 -1
  102. package/dist/run-listing.d.ts +1 -1
  103. package/dist/run-timeline-served.d.ts +1 -1
  104. package/dist/run-timeline-served.js +6 -5
  105. package/dist/runnable.js +25 -8
  106. package/dist/runner/adapter-run-spec.js +11 -20
  107. package/dist/runner/audit.d.ts +2 -4
  108. package/dist/runner/audit.js +28 -51
  109. package/dist/runner/cli-run-spec.js +8 -14
  110. package/dist/runner/compare-end.d.ts +0 -2
  111. package/dist/runner/compare-end.js +6 -2
  112. package/dist/runner/disk-free.d.ts +15 -4
  113. package/dist/runner/disk-free.js +25 -7
  114. package/dist/runner/feedback-round.d.ts +1 -1
  115. package/dist/runner/feedback-round.js +2 -2
  116. package/dist/runner/harness-loops.js +2 -3
  117. package/dist/runner/held.d.ts +0 -10
  118. package/dist/runner/held.js +0 -25
  119. package/dist/runner/journal-kinds.d.ts +4 -1
  120. package/dist/runner/journal-kinds.js +1 -1
  121. package/dist/runner/learned-first.d.ts +0 -2
  122. package/dist/runner/learned-first.js +3 -3
  123. package/dist/runner/learning-end.d.ts +12 -16
  124. package/dist/runner/learning-end.js +41 -75
  125. package/dist/runner/learning-seed.d.ts +13 -16
  126. package/dist/runner/learning-seed.js +13 -23
  127. package/dist/runner/main.js +1 -1
  128. package/dist/runner/mcp-run.d.ts +4 -0
  129. package/dist/runner/mcp-run.js +2 -0
  130. package/dist/runner/native-loop.js +2 -3
  131. package/dist/runner/promotion.d.ts +19 -28
  132. package/dist/runner/promotion.js +50 -69
  133. package/dist/runner/reflect-hook.d.ts +2 -2
  134. package/dist/runner/reflect-hook.js +4 -1
  135. package/dist/runner/run-child-host.d.ts +1 -9
  136. package/dist/runner/run-child-host.js +11 -67
  137. package/dist/runner/runner.d.ts +1 -1
  138. package/dist/runner/sdk-loop.js +2 -4
  139. package/dist/sdk/check.d.ts +1 -4
  140. package/dist/sdk/check.js +2 -3
  141. package/dist/sdk/runs.d.ts +20 -7
  142. package/dist/sdk/runs.js +105 -68
  143. package/dist/secrets.d.ts +4 -0
  144. package/dist/secrets.js +44 -10
  145. package/dist/server-fs.d.ts +1 -1
  146. package/dist/server-fs.js +1 -1
  147. package/dist/server-keys.d.ts +6 -0
  148. package/dist/server-keys.js +12 -0
  149. package/dist/server.d.ts +15 -15
  150. package/dist/server.js +214 -164
  151. package/dist/source-sync/auxiliary.js +2 -2
  152. package/dist/store/index.d.ts +1 -1
  153. package/dist/store/index.js +1 -1
  154. package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
  155. package/dist/store/schema.d.ts +28 -2
  156. package/dist/store/schema.js +81 -5
  157. package/dist/store/sqlite/learning-rows.d.ts +23 -0
  158. package/dist/store/sqlite/learning-rows.js +559 -0
  159. package/dist/store/sqlite/store.d.ts +7 -1
  160. package/dist/store/sqlite/store.js +84 -18
  161. package/dist/store/store.d.ts +219 -6
  162. package/dist/store/store.js +13 -0
  163. package/dist/store-reads/journal.d.ts +33 -3
  164. package/dist/store-reads/journal.js +99 -4
  165. package/dist/store-reads/learning.d.ts +18 -22
  166. package/dist/store-reads/learning.js +35 -26
  167. package/dist/store-reads/loop.js +1 -1
  168. package/dist/store-view.d.ts +24 -2
  169. package/dist/store-view.js +40 -11
  170. package/dist/templates.d.ts +10 -2
  171. package/dist/templates.js +31 -4
  172. package/dist/tool-plane.d.ts +4 -2
  173. package/dist/tool-plane.js +9 -2
  174. package/dist/web-holds.d.ts +2 -0
  175. package/dist/web-holds.js +5 -2
  176. package/dist/web-run.js +2 -1
  177. package/dist/workspace/archil-exec.js +1 -1
  178. package/dist/workspace/archil.d.ts +1 -1
  179. package/dist/workspace/archil.js +1 -1
  180. package/dist/workspace/computer-deps.js +5 -3
  181. package/dist/workspace/computer-providers.d.ts +11 -1
  182. package/dist/workspace/computer-providers.js +29 -2
  183. package/dist/workspace/index.d.ts +1 -2
  184. package/dist/workspace/index.js +1 -2
  185. package/dist/workspace/paths.d.ts +0 -4
  186. package/dist/workspace/paths.js +0 -6
  187. package/dist/workspace/workspace.d.ts +1 -1
  188. package/dist/workspace/workspace.js +1 -1
  189. package/package.json +13 -13
  190. package/templates/TOOLS.md +46 -0
  191. package/dist/console/assets/index-LwNL4L9q.js +0 -619
  192. package/dist/console/assets/styles-DQo8rzY-.css +0 -1
  193. package/dist/workspace/learning-workspace.d.ts +0 -24
  194. /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
package/dist/place.js CHANGED
@@ -9,13 +9,14 @@
9
9
  // sandbox, never a third mode.
10
10
  //
11
11
  // The box is a new agent's default machine for a shell: an agentic definition that names no place and no tools is saved,
12
- // at its create, with the local box (Docker's) as its place wherever this server has it, and with bash (newAgentPlace).
13
- // One that names its tools gets the box only when one of them needs a shell; else it keeps no place and runs on the
14
- // runner, with no container to wait for. A revision that names no place resolves the same way at each run
15
- // (defaultPlaceOf): with a shell tool, this server's default_place, so where docker is there now it runs in the Docker
16
- // box, and the runner where it is not. A workflow, a revision whose tools need no shell, and one with a tool the box
17
- // refuses run on the runner.
18
- import { BOX_IDS, BOXES_ENV, LOCAL_BOXES } from "./place-offers.js";
12
+ // at its create, with Docker's box as its place wherever this server has it, and with bash (newAgentPlace). One that
13
+ // names its tools gets the box only when one of them needs a shell; else it keeps no place and runs on the runner, with
14
+ // no container to wait for. Where Docker's box is not here, a definition that would get it is refused (noBoxRefusal):
15
+ // it names a box or the runner, and no other box that answers is picked for it. A revision that names no place resolves
16
+ // the same way at each run (defaultPlaceOf): with a shell tool, this server's default_place, so where docker is there
17
+ // now it runs in the Docker box, and where it is not its run is refused in the same words. A workflow, a revision whose
18
+ // tools need no shell, and one with a tool the box refuses run on the runner.
19
+ import { BOX_IDS, BOXES_ENV, DEFAULT_BOX } from "./place-offers.js";
19
20
  import { sentence } from "./errors.js";
20
21
  export const PLACE_MODES = ["runner", "sandbox"];
21
22
  /** Every box, from what this server found at its start (place-offers.ts): one it did not find is not set up. */
@@ -25,21 +26,31 @@ export function boxAvailability(registry) {
25
26
  return offer ? { ...offer } : { id, available: false, reason: `${id} is not set up on this server` };
26
27
  });
27
28
  }
28
- /** The box a new agent is given: the first local box (Docker's) this server has, else the first local box, unavailable,
29
- * whose reason says why. Undefined where no provider is local. */
30
- const defaultBox = (registry) => {
31
- const local = boxAvailability(registry).filter((box) => LOCAL_BOXES.includes(box.id));
32
- return local.find((box) => box.available) ?? local[0];
29
+ /** The box a new agent is given: the one whose provider's descriptor says so (`defaultBox`: Docker's), never another box
30
+ * that answers in its place. */
31
+ const defaultBox = (registry) => boxAvailability(registry).find((box) => box.id === DEFAULT_BOX);
32
+ /** Why Docker's box is not here when its probe gave no reason (the words this server always used). */
33
+ const NO_REASON = "no provider runs computers on this machine";
34
+ /** What a new agent that would get Docker's box sets where this server does not have it: a box, listing the boxes this
35
+ * server has (never picking one), or the runner. */
36
+ export function placeToName(registry) {
37
+ const ready = boxAvailability(registry).filter((box) => box.available).map((box) => box.id);
38
+ return `Set place to {mode: sandbox, box: <${ready.length ? `one of: ${ready.join(", ")}` : "none is set up"}>}, or to {mode: runner} to run without a shell.`;
39
+ }
40
+ /** Why such an agent is refused: it names a box (placeToName); and why Docker's box is not here, in the words its offer
41
+ * gave (its probe's, with their fix: start Docker, join its group), where it gave some. */
42
+ export const nameABox = (registry) => {
43
+ const why = registry.find((offer) => offer.id === DEFAULT_BOX && !offer.available)?.reason;
44
+ return `name a box: this server has no Docker box for a new agent. ${placeToName(registry)}${why ? ` ${sentence(`${DEFAULT_BOX}: ${why}`)}` : ""}`;
33
45
  };
34
- /** The place a new agentic definition that names none is saved with: the local box (Docker's) where this server has it;
35
- * else none, so the agent runs on the runner as it did before, with `reason` saying why, in its probe's own words. A
36
- * workflow is never given one. */
46
+ /** The place a new agentic definition that names none is saved with: Docker's box where this server has it; else none,
47
+ * with `reason`, the words such a definition is refused in (nameABox), and `why` Docker's box is not here, in its probe's
48
+ * own words. A workflow is never given one. */
37
49
  export function newAgentPlace(registry) {
38
50
  const box = defaultBox(registry);
39
51
  if (box?.available)
40
52
  return { place: { mode: "sandbox", box: box.id } };
41
- const why = box?.reason ?? "no provider runs computers on this machine";
42
- return { reason: `new agents run on the runner, because the ${box?.id ?? "local"} box is unavailable here: ${why}`, why };
53
+ return { reason: nameABox(registry), why: box?.reason ?? NO_REASON };
43
54
  }
44
55
  /** The place a revision that names none resolves to, at its create and at each run alike: this server's default place
45
56
  * (newAgentPlace) for an agentic revision with a tool that runs only in a box (`flags`, tools.ts: bash and the
@@ -47,12 +58,31 @@ export function newAgentPlace(registry) {
47
58
  * only read and write: a container would only hold up its start), and for one that names a tool the box refuses (the
48
59
  * browser, runner-only for now). */
49
60
  export function defaultPlaceOf(kind, tools, registry, flags) {
50
- const named = tools.flatMap((tool) => (typeof tool === "string" ? [flags(tool)] : []));
51
- if (kind === "workflow" || named.some((tool) => tool?.runnerOnly) || !named.some((tool) => tool?.sandboxOnly))
61
+ if (kind === "workflow" || !wantsBox(tools, flags))
52
62
  return { mode: "runner" };
53
63
  const fresh = newAgentPlace(registry);
54
64
  return "place" in fresh ? fresh.place : { mode: "runner" };
55
65
  }
66
+ /** Whether an agentic revision naming `tools` and no place would be given the default box: one of them runs only in a
67
+ * box, and none is a tool the box refuses. */
68
+ const wantsBox = (tools, flags) => {
69
+ const named = tools.flatMap((tool) => (typeof tool === "string" ? [flags(tool)] : []));
70
+ return !named.some((tool) => tool?.runnerOnly) && named.some((tool) => tool?.sandboxOnly);
71
+ };
72
+ /** The refusal of an agentic definition that names no place (noPlaceIssue), at its create or at an edit that would
73
+ * save it, where it would be given the default box (it names no tools, `tools` undefined, so it would get a shell, or a
74
+ * tool that runs only in a box) and this server does not have Docker's box, and where the runner has no shell
75
+ * (`runnerShell` false: Mode 1). On Mode 2 the runner's exec is a shell, and such a definition saves for the runner as
76
+ * it always did, its tools checked there (runnable.ts). Undefined for one that saves. */
77
+ export function noBoxRefusal(tools, registry, flags, runnerShell) {
78
+ if (runnerShell || !wantsBox(tools ?? NEW_AGENT_TOOLS, flags))
79
+ return undefined;
80
+ const fresh = newAgentPlace(registry);
81
+ return "reason" in fresh ? noPlaceIssue(registry) : undefined;
82
+ }
83
+ /** The refusal of a revision that names no place where Docker's box is not here, at definition.place: its words, and
84
+ * what to set as its fix, so no example of a place is picked for it. */
85
+ export const noPlaceIssue = (registry) => ({ field: "definition.place", reason: "missing", message: nameABox(registry), fix: placeToName(registry) });
56
86
  /** The tools a new agent in the default box is given when its definition names none: a shell, and the background tools
57
87
  * that start, read, feed, signal and list commands that outlive one call (background.ts SHELL_TOOLS, which a test holds
58
88
  * this list to; written out here, since background.ts reads this module). A definition that names its tools, an empty
@@ -80,8 +110,9 @@ export function noBoxReason(registry, listed) {
80
110
  /** The start banner's words on the boxes: which are ready for a sandbox agent's tools, then why each box is not that
81
111
  * AGENTRUN_BOXES lists (`listed`), and, when none is ready, the boxes it does not list, with what to do.
82
112
  * `byDefault`, with AGENTRUN_BOXES not set at all: short, the local box alone, said to be on by default, or why it is
83
- * not. */
84
- export function boxesLine(registry, listed, allow = "none", byDefault = false) {
113
+ * not, and where a new agent with no place goes then: it names its place, or, where the runner has a shell
114
+ * (`runnerShell`: Mode 2), it runs on the runner (placesOf). */
115
+ export function boxesLine(registry, listed, allow = "none", byDefault = false, runnerShell = false) {
85
116
  const boxes = boxAvailability(registry);
86
117
  const ready = boxes.filter((box) => box.available).map((box) => box.id);
87
118
  const said = ready.length ? [`${and(ready)} ${ready.length === 1 ? "is" : "are"} ready, so sandbox agents run their tools there.`] : [];
@@ -94,17 +125,21 @@ export function boxesLine(registry, listed, allow = "none", byDefault = false) {
94
125
  if (byDefault) {
95
126
  const box = defaultBox(registry);
96
127
  if (!box?.available)
97
- return `Boxes: none, so new agents run on the runner. ${sentence(box?.reason ?? "no provider runs computers on this machine")}`;
128
+ return `Boxes: none, so ${runnerShell ? "new agents run on the runner" : "a new agent must name its place: a box, or the runner"}. ${sentence(box?.reason ?? NO_REASON)}`;
98
129
  return [`Boxes: ${box.id} (on by default; set ${BOXES_ENV} to change).`, ...reach].join(" ");
99
130
  }
100
131
  return ["Boxes:", ...(none ? ["none is ready, so sandbox agents do not run here."] : said), ...reach, ...why.map((box) => sentence(`${box.id}: ${box.reason ?? "not available"}`)), ...(rest ? [sentence(rest)] : [])].join(" ");
101
132
  }
102
133
  /** `places` in capabilities: the modes a revision may name, the place a new agent is saved with and a revision that
103
- * names none runs in (`default_place`, with `default_reason` when it is the runner), each box, and the hosts a box whose
104
- * `network` is `allowlist` reaches (`allow`, box-settings.ts boxAllowOf; empty for `none`). */
105
- export const placesOf = (registry, allow = "none") => {
134
+ * names none runs in (`default_place`), each box, and the hosts a box whose `network` is `allowlist` reaches (`allow`,
135
+ * box-settings.ts boxAllowOf; empty for `none`). `default_place` is Docker's box where this server has it; else, where
136
+ * the runner has a shell (`runnerShell`: Mode 2's Archil exec), the runner; else null, no default: a new agent names its
137
+ * place, and `default_reason` is the words a no-place create is refused in (noBoxRefusal). `default_reason` is there
138
+ * exactly when `default_place` is null. */
139
+ export const placesOf = (registry, allow = "none", runnerShell = false) => {
106
140
  const fresh = newAgentPlace(registry);
107
- return { modes: [...PLACE_MODES], ...("place" in fresh ? { default_place: fresh.place } : { default_place: { mode: "runner" }, default_reason: fresh.reason }), boxes: boxAvailability(registry).map(stated), allow: allow === "none" ? [] : [...allow] };
141
+ const byDefault = "place" in fresh ? { default_place: fresh.place } : runnerShell ? { default_place: { mode: "runner" } } : { default_place: null, default_reason: fresh.reason };
142
+ return { modes: [...PLACE_MODES], ...byDefault, boxes: boxAvailability(registry).map(stated), allow: allow === "none" ? [] : [...allow] };
108
143
  };
109
144
  /** A box with its state, `ready` when it is available and `unavailable` when not; and, on an available box, its network as the server set it, with
110
145
  * `network_reason` when it is none for a cause of its own. */
@@ -1,40 +1,7 @@
1
1
  import { ApiError } from "./errors.js";
2
- import { type LearningFolder, type SnapChange, type Snapshot } from "./learn/folder.js";
3
- import type { PromotionRecord, Refused } from "./learn/promote.js";
4
2
  import type { RunRow, Store } from "./store/index.js";
5
- import type { Workspace } from "./workspace/index.js";
6
3
  /** 410 purged for a route of a purged run (Runs.purge): its tombstone, what is kept of it. `tools_usd`: its paid tools'
7
4
  * meter as /usage read it at its purge (null: unknown, or none read). */
8
5
  export declare function purgedRun(row: RunRow): ApiError;
9
6
  /** Which of `runIds` are purged, each with its row: by its row's purge time. One store read per run. */
10
7
  export declare function purgedRows(store: Pick<Store, "runs">, runIds: Iterable<string>): Promise<ReadonlyMap<string, RunRow>>;
11
- /** The one gate every read of the learning folder at a commit goes through, main's or a past commit's (learn/folder.ts
12
- * snapshotAt, folderAt): the view, the log and a workflow's revisions, a merge's diff, a run's seed (learning.ts seedAt)
13
- * and the champion read by digest, an SDK start's receipt, and a compile ask (runner/learning-end.ts compileAskOf).
14
- * `workflows`: each learned workflow of `snapshot` whose workflow.json a purged run wrote (SnapLearned.run: the run of
15
- * the newest commit that changed the file, over main's whole history, which a purge's put-back hands to the run that
16
- * wrote those bytes), by name, with that run's row; no read lays, checks, replays, serves or shows it. `served`, read
17
- * only when `log` is asked: whether a change of the snapshot's log is served (no purged run's merge is), so a log the
18
- * folder rebuilds names one and still serves none. */
19
- export declare function purgeGate(snapshot: Snapshot | undefined, store: Pick<Store, "runs">, log?: boolean): Promise<{
20
- workflows: ReadonlyMap<string, RunRow>;
21
- served: (change: SnapChange) => boolean;
22
- }>;
23
- /** The promotion records of `workflows` that championOf skips (learn/promote.ts Refused), read through purgeGate at
24
- * each record's commit of the learning folder at `ws`: newest promotion first, whatever its digest's newest decision
25
- * (a champion held since included: skipping it may leave an earlier one serving), one the gate refuses at its commit (a
26
- * purged run wrote its workflow there) is skipped with every record of its workflow at that commit (by workflow and
27
- * commit, so a copy of the records read later is skipped alike, a hold of it included), until the newest promotion left
28
- * is one the gate lets through, or none is left. The holds are walked the same way, newest first: a hold at a commit the
29
- * gate refuses (a check that ended after its revision's run was purged holds it there) is skipped with its commit's
30
- * records, until the newest hold left is one the gate lets through, so the compile's held names (learn/compile.ts
31
- * heldNamesOf) never ask a revision of a purged run's text. A record with no commit is let through, and so is a commit
32
- * the folder no longer has (reading its text fails on its own). A commit whose read throws refuses none here and is said
33
- * (Refused.unread), so the promotions trim trims nothing on it (recordPromotion); a store read of the gate's that throws
34
- * throws, so every write that asks fails closed. One read-only exec per commit asked. */
35
- export declare function refusedOf(records: readonly PromotionRecord[], workflows: Iterable<string>, ws: Workspace, store: Pick<Store, "runs">): Promise<Refused>;
36
- /** refusedOf in the learning folder `folder` opens for each ask (ended after it), over `workflows` (every workflow of
37
- * the records when absent): the port a champion's readers and the promotions trim ask (runner/promotion.ts
38
- * PromotionDeps refused, learn/promote.ts recordPromotion). An end() that throws is said to `log` (when given) and never
39
- * fails the ask: the answer was read. */
40
- export declare const refusedIn: (folder: () => Pick<LearningFolder, "workspace" | "end">, store: Pick<Store, "runs">, log?: (line: string) => void) => (records: readonly PromotionRecord[], workflows?: Iterable<string>) => Promise<Refused>;
@@ -1,9 +1,7 @@
1
- // What a purged run (DELETE /v2/runs/{id}, agent-delete.ts purgeRun) answers, and the one rule for a learned workflow
2
- // whose text it wrote: its purge puts back the version before it, or takes it off main when it wrote it new
3
- // (learn/commit.ts forgetRunText), and every read of the folder at a commit asks purgeGate, so a purged run's text is
4
- // never served or executed and none of its merges is shown.
1
+ // What a purged run (DELETE /v2/runs/{id}, agent-delete.ts purgeRun) answers. Its learned text needs no rule here: its
2
+ // purge deletes its learning rows (Store.learning purgeRun), so the version before its own serves again and none of its
3
+ // saves is shown.
5
4
  import { ApiError } from "./errors.js";
6
- import { snapshotAt } from "./learn/folder.js";
7
5
  const isoOrNull = (ms) => (ms === null ? null : new Date(ms).toISOString());
8
6
  /** 410 purged for a route of a purged run (Runs.purge): its tombstone, what is kept of it. `tools_usd`: its paid tools'
9
7
  * meter as /usage read it at its purge (null: unknown, or none read). */
@@ -22,69 +20,3 @@ export async function purgedRows(store, runIds) {
22
20
  const rows = await Promise.all([...new Set(runIds)].map((run) => store.runs.get(run)));
23
21
  return new Map(rows.flatMap((row) => (row && row.purgedAt !== null ? [[row.id, row]] : [])));
24
22
  }
25
- /** The one gate every read of the learning folder at a commit goes through, main's or a past commit's (learn/folder.ts
26
- * snapshotAt, folderAt): the view, the log and a workflow's revisions, a merge's diff, a run's seed (learning.ts seedAt)
27
- * and the champion read by digest, an SDK start's receipt, and a compile ask (runner/learning-end.ts compileAskOf).
28
- * `workflows`: each learned workflow of `snapshot` whose workflow.json a purged run wrote (SnapLearned.run: the run of
29
- * the newest commit that changed the file, over main's whole history, which a purge's put-back hands to the run that
30
- * wrote those bytes), by name, with that run's row; no read lays, checks, replays, serves or shows it. `served`, read
31
- * only when `log` is asked: whether a change of the snapshot's log is served (no purged run's merge is), so a log the
32
- * folder rebuilds names one and still serves none. */
33
- export async function purgeGate(snapshot, store, log = false) {
34
- const writers = new Map((snapshot?.workflows ?? []).flatMap((item) => (item.run ? [[item.name, item.run]] : [])));
35
- const logged = log ? (snapshot?.log ?? []).flatMap(({ by }) => ("run" in by ? [by.run] : [])) : [];
36
- const purged = await purgedRows(store, [...writers.values(), ...logged]);
37
- const workflows = new Map([...writers].flatMap(([name, run]) => (purged.has(run) ? [[name, purged.get(run)]] : [])));
38
- return {
39
- workflows,
40
- served: ({ by }) => {
41
- if (!log)
42
- throw new Error("the purge gate was not asked for the log");
43
- return !("run" in by && purged.has(by.run));
44
- },
45
- };
46
- }
47
- /** The promotion records of `workflows` that championOf skips (learn/promote.ts Refused), read through purgeGate at
48
- * each record's commit of the learning folder at `ws`: newest promotion first, whatever its digest's newest decision
49
- * (a champion held since included: skipping it may leave an earlier one serving), one the gate refuses at its commit (a
50
- * purged run wrote its workflow there) is skipped with every record of its workflow at that commit (by workflow and
51
- * commit, so a copy of the records read later is skipped alike, a hold of it included), until the newest promotion left
52
- * is one the gate lets through, or none is left. The holds are walked the same way, newest first: a hold at a commit the
53
- * gate refuses (a check that ended after its revision's run was purged holds it there) is skipped with its commit's
54
- * records, until the newest hold left is one the gate lets through, so the compile's held names (learn/compile.ts
55
- * heldNamesOf) never ask a revision of a purged run's text. A record with no commit is let through, and so is a commit
56
- * the folder no longer has (reading its text fails on its own). A commit whose read throws refuses none here and is said
57
- * (Refused.unread), so the promotions trim trims nothing on it (recordPromotion); a store read of the gate's that throws
58
- * throws, so every write that asks fails closed. One read-only exec per commit asked. */
59
- export async function refusedOf(records, workflows, ws, store) {
60
- const refused = new Set();
61
- const skip = (one) => one.commit !== undefined && refused.has(`${one.workflow}\0${one.commit}`);
62
- let unread = false;
63
- const reads = new Map();
64
- const gated = (commit) => reads.get(commit) ?? reads.set(commit, snapshotAt(ws, commit).then(async (at) => (await purgeGate(at, store)).workflows, () => {
65
- unread = true;
66
- return new Map();
67
- })).get(commit);
68
- const newestOf = (workflow, decided) => records.findLast((one) => one.workflow === workflow && one.decided === decided && !skip(one));
69
- for (const workflow of new Set(workflows)) {
70
- for (const decided of ["promote", "hold"]) {
71
- for (let last = newestOf(workflow, decided); last?.commit && (await gated(last.commit)).has(workflow); last = newestOf(workflow, decided)) {
72
- refused.add(`${workflow}\0${last.commit}`);
73
- }
74
- }
75
- }
76
- return Object.assign(skip, { unread });
77
- }
78
- /** refusedOf in the learning folder `folder` opens for each ask (ended after it), over `workflows` (every workflow of
79
- * the records when absent): the port a champion's readers and the promotions trim ask (runner/promotion.ts
80
- * PromotionDeps refused, learn/promote.ts recordPromotion). An end() that throws is said to `log` (when given) and never
81
- * fails the ask: the answer was read. */
82
- export const refusedIn = (folder, store, log) => async (records, workflows) => {
83
- const { workspace, end } = folder();
84
- try {
85
- return await refusedOf(records, workflows ?? records.map((one) => one.workflow), workspace, store);
86
- }
87
- finally {
88
- await end().catch((error) => log?.(`learning: the learning folder did not end after the purge gate's ask: ${error instanceof Error ? error.message : String(error)}`));
89
- }
90
- };
@@ -77,6 +77,16 @@ export declare function cutAt(text: string, spans: readonly Span[]): string;
77
77
  * ("Z" and U+0301 into "Ź"), and one written with a precomposed letter in place of its own ("Ź" for "Z"). A held
78
78
  * value's accents are dropped the same way, so it reads as itself with them or without: more cutting, never less. */
79
79
  export declare const squeeze: (text: string) => string;
80
+ /** One of Python's own escapes at `at`, as its repr writes a str: an escaped apostrophe ("\'", in a string that holds
81
+ * both quotes) is an apostrophe, "\x" and two hex digits the character they number; with `levels` 2, either written
82
+ * once more as a JSON string's text too ("\\'", "\\x41": a dict a model wrote in a call's arguments, read one level
83
+ * down). The character and where it ends; undefined where none starts. It reads at most five characters. key-refusal.ts's
84
+ * peek counts an escape by it (both levels), so the read past a call's stop counts "\x20" as the views that read
85
+ * Python's escapes do: a space. */
86
+ export declare function pythonEscapeAt(text: string, at: number, levels?: 1 | 2): {
87
+ char: string;
88
+ end: number;
89
+ } | undefined;
80
90
  /** What JSON_ESCAPE reads at `at`: the character the escape there decodes to, through both levels ("" for an escaped
81
91
  * quote, which decodes to nothing), and where it ends; undefined where no escape starts (the "\" is then itself).
82
92
  * key-refusal.ts's peek counts an escape by it, so the read past a call's stop and the JSON view see the same
@@ -85,10 +95,15 @@ export declare function jsonEscapeAt(text: string, at: number): {
85
95
  char: string;
86
96
  end: number;
87
97
  } | undefined;
88
- /** The character an HTML numeric character reference at `at` stands for ("&#" and 1 to 7 decimal digits, or "&#x" or
89
- * "&#X" and 1 to 6 hex digits, then ";"), and where it ends; undefined where none starts, or it stands for no
90
- * character (zero, a surrogate, past U+10FFFF). It reads at most 11 characters. key-refusal.ts's peek counts a
91
- * reference by it, so the read past a call's stop and the views see the same characters. */
98
+ /** The character an HTML character reference at `at` stands for, as a browser reads one in text, and where it ends:
99
+ * - a named one of NAMED, with its ";" ("&amp;" is "&"); it reads at most 6 characters;
100
+ * - a numeric one: "&#" and decimal digits, or "&#x" or "&#X" and hex digits, any zeros first (read as nothing:
101
+ * "&#00065;" is "A"), then at most 7 decimal or 6 hex digits, then ";" or not (a browser reads "&#65" before a letter
102
+ * as "A" too). It reads its zeros and one digit past the most, each once and counted: a run of zeros is read again
103
+ * only by the view that copies it where no reference stands.
104
+ * Undefined where none starts, or it stands for no character (zero, a surrogate, past U+10FFFF, or more digits than
105
+ * that). key-refusal.ts's peek counts a reference by it, so the read past a call's stop and the views see the same
106
+ * characters. */
92
107
  export declare function entityAt(text: string, at: number): {
93
108
  char: string;
94
109
  end: number;
@@ -827,6 +827,38 @@ const JSON_ESCAPE_QUOTED = jsonEscape(false);
827
827
  * two levels JSON_ESCAPE reads make the escaped backslash and what follows it one escape; so does one with a quote of
828
828
  * its own, written once. */
829
829
  const JSON_ESCAPE_ONCE = jsonEscape(false, 1);
830
+ /** One of Python's own escapes at `at`, as its repr writes a str: an escaped apostrophe ("\'", in a string that holds
831
+ * both quotes) is an apostrophe, "\x" and two hex digits the character they number; with `levels` 2, either written
832
+ * once more as a JSON string's text too ("\\'", "\\x41": a dict a model wrote in a call's arguments, read one level
833
+ * down). The character and where it ends; undefined where none starts. It reads at most five characters. key-refusal.ts's
834
+ * peek counts an escape by it (both levels), so the read past a call's stop counts "\x20" as the views that read
835
+ * Python's escapes do: a space. */
836
+ export function pythonEscapeAt(text, at, levels = 2) {
837
+ if (text[at] !== "\\")
838
+ return undefined;
839
+ scanned.chars += Math.min(5, text.length - at);
840
+ const from = levels === 2 && text[at + 1] === "\\" ? at + 2 : at + 1;
841
+ if (text[from] === "'")
842
+ return { char: "'", end: from + 1 };
843
+ if (text[from] !== "x" || !HEX(text.charCodeAt(from + 1)) || !HEX(text.charCodeAt(from + 2)))
844
+ return undefined;
845
+ return { char: String.fromCharCode(Number.parseInt(text.slice(from + 1, from + 3), 16)), end: from + 3 };
846
+ }
847
+ /** Python's escapes (pythonEscapeAt) at `levels`, and the rest as `json` reads them: a single-quoted dict's strings as
848
+ * its repr wrote them, with one level of JSON's escapes ("\\", "\n", "\u" and four hex digits); and, written in a
849
+ * JSON string, both levels of each ("\\'" and "\\x41", "\\\\" and "\\n"). */
850
+ const pythonEscape = (levels, json) => ({
851
+ trigger: "\\",
852
+ decode(text, at, unit) {
853
+ const found = pythonEscapeAt(text, at, levels);
854
+ if (!found)
855
+ return json.decode(text, at, unit);
856
+ unit(found.char, at, found.end);
857
+ return found.end;
858
+ },
859
+ });
860
+ const PYTHON_ESCAPE = pythonEscape(1, JSON_ESCAPE_ONCE);
861
+ const PYTHON_ESCAPE_TWICE = pythonEscape(2, JSON_ESCAPE_QUOTED);
830
862
  /** What JSON_ESCAPE reads at `at`: the character the escape there decodes to, through both levels ("" for an escaped
831
863
  * quote, which decodes to nothing), and where it ends; undefined where no escape starts (the "\" is then itself).
832
864
  * key-refusal.ts's peek counts an escape by it, so the read past a call's stop and the JSON view see the same
@@ -839,29 +871,51 @@ export function jsonEscapeAt(text, at) {
839
871
  return end < 0 ? undefined : { char, end };
840
872
  }
841
873
  const DECIMAL = only(DIGIT);
842
- /** The character an HTML numeric character reference at `at` stands for ("&#" and 1 to 7 decimal digits, or "&#x" or
843
- * "&#X" and 1 to 6 hex digits, then ";"), and where it ends; undefined where none starts, or it stands for no
844
- * character (zero, a surrogate, past U+10FFFF). It reads at most 11 characters. key-refusal.ts's peek counts a
845
- * reference by it, so the read past a call's stop and the views see the same characters. */
874
+ /** The named references a writer's HTML escape emits (and a no-break space), each with its ";". */
875
+ const NAMED = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: "\u00a0", AMP: "&", LT: "<", GT: ">", QUOT: '"' };
876
+ /** The character an HTML character reference at `at` stands for, as a browser reads one in text, and where it ends:
877
+ * - a named one of NAMED, with its ";" ("&amp;" is "&"); it reads at most 6 characters;
878
+ * - a numeric one: "&#" and decimal digits, or "&#x" or "&#X" and hex digits, any zeros first (read as nothing:
879
+ * "&#00065;" is "A"), then at most 7 decimal or 6 hex digits, then ";" or not (a browser reads "&#65" before a letter
880
+ * as "A" too). It reads its zeros and one digit past the most, each once and counted: a run of zeros is read again
881
+ * only by the view that copies it where no reference stands.
882
+ * Undefined where none starts, or it stands for no character (zero, a surrogate, past U+10FFFF, or more digits than
883
+ * that). key-refusal.ts's peek counts a reference by it, so the read past a call's stop and the views see the same
884
+ * characters. */
846
885
  export function entityAt(text, at) {
847
- scanned.chars += Math.min(11, text.length - at);
848
- if (text[at] !== "&" || text[at + 1] !== "#")
886
+ if (text[at] !== "&") {
887
+ scanned.chars++;
849
888
  return undefined;
889
+ }
890
+ if (text[at + 1] !== "#") {
891
+ scanned.chars += Math.min(6, text.length - at);
892
+ for (let length = 2; length <= 4; length++) {
893
+ const name = text.slice(at + 1, at + 1 + length);
894
+ if (text[at + 1 + length] === ";" && Object.hasOwn(NAMED, name))
895
+ return { char: NAMED[name], end: at + 2 + length };
896
+ }
897
+ return undefined;
898
+ }
850
899
  const hex = text[at + 2] === "x" || text[at + 2] === "X";
851
900
  const from = at + (hex ? 3 : 2);
852
901
  const digit = hex ? HEX : DECIMAL;
853
- let end = from;
854
- while (end < text.length && end - from < (hex ? 6 : 7) && digit(text.charCodeAt(end)))
902
+ const most = hex ? 6 : 7;
903
+ let start = from;
904
+ while (start < text.length && text.charCodeAt(start) === 48)
905
+ start++;
906
+ let end = start;
907
+ while (end < text.length && end - start <= most && digit(text.charCodeAt(end)))
855
908
  end++;
856
- if (end === from || text[end] !== ";")
909
+ scanned.chars += end - at + 1;
910
+ if (end === from || end - start > most)
857
911
  return undefined;
858
- const code = Number.parseInt(text.slice(from, end), hex ? 16 : 10);
912
+ const code = end === start ? 0 : Number.parseInt(text.slice(start, end), hex ? 16 : 10);
859
913
  if (code === 0 || (code >= 0xd800 && code <= 0xdfff) || code > 0x10ffff)
860
914
  return undefined;
861
- return { char: String.fromCodePoint(code), end: end + 1 };
915
+ return { char: String.fromCodePoint(code), end: text[end] === ";" ? end + 1 : end };
862
916
  }
863
- /** An HTML numeric character reference (entityAt), as the character it stands for (a character past U+FFFF as its two
864
- * UTF-16 units, each from the whole reference). */
917
+ /** An HTML character reference (entityAt), as the character it stands for (a character past U+FFFF as its two UTF-16
918
+ * units, each from the whole reference). */
865
919
  const ENTITY = {
866
920
  trigger: "&",
867
921
  decode(text, at, unit) {
@@ -877,10 +931,12 @@ const PERCENT_BYTE = /%[0-9a-fA-F]{2}/;
877
931
  const JSON_ESCAPED = /\\(?:u[0-9a-fA-F]{4}|["\\/bfnrt])/;
878
932
  const QUOTE_ESCAPED = /\\"|\\u00[2]2/;
879
933
  const BACKSLASH_ESCAPED = /\\\\|\\u005[cC]/;
934
+ const PYTHON_ESCAPED = /\\(?:'|x[0-9a-fA-F]{2})/;
935
+ const ENTITY_START = /&(?:#|(?:amp|lt|gt|quot|apos|nbsp|AMP|LT|GT|QUOT);)/;
880
936
  function familiesOf(text) {
881
- // Seven reads of the text, each to its first find at most.
882
- scanned.chars += 7 * text.length;
883
- return { percent: PERCENT_BYTE.test(text), escape: JSON_ESCAPED.test(text), quoteEscape: QUOTE_ESCAPED.test(text), entity: text.includes("&#"), plus: text.includes("+"), quote: text.includes('"'), deep: BACKSLASH_ESCAPED.test(text) };
937
+ // Nine reads of the text, each to its first find at most.
938
+ scanned.chars += 9 * text.length;
939
+ return { percent: PERCENT_BYTE.test(text), escape: JSON_ESCAPED.test(text), quoteEscape: QUOTE_ESCAPED.test(text), entity: ENTITY_START.test(text), plus: text.includes("+"), quote: text.includes('"'), apostrophe: text.includes("'"), deep: BACKSLASH_ESCAPED.test(text), python: PYTHON_ESCAPED.test(text) };
884
940
  }
885
941
  const viewSpec = (when, decoders, join) => ({
886
942
  when,
@@ -895,19 +951,30 @@ const viewSpec = (when, decoders, join) => ({
895
951
  * decodes to a backslash (elsewhere the two levels read as one does). Each reads a held value that holds another
896
952
  * family's text of its own (a literal "\n", a literal "%41", "&#65;") as itself, which a stacked view decodes, so
897
953
  * keeping them keeps every find they made;
898
- * - stacked: its percent-encoded bytes, JSON's escapes (twice, an escaped quote as nothing) and HTML's numeric character
899
- * references each decoded where it stands, so a value split by an encoded space of one family and an escaped one of
954
+ * - stacked: its percent-encoded bytes, JSON's escapes (twice, an escaped quote as nothing) and HTML's character
955
+ * references (entityAt) each decoded where it stands, so a value split by an encoded space of one family and an escaped one of
900
956
  * another, or written half in each, or split by an escaped quote, reads whole; and the same with "+" as a space. Each
901
957
  * is read only where it can read otherwise than the one-family views: the text has a character reference, an escaped
902
958
  * quote, or both percent-encoding and JSON's escapes (and, with "+", any of JSON's escapes);
903
959
  * - for a text with a quote in it, its JSON strings joined (joinOf), each string's contents read again for the strings
904
- * written in it, decoded as the stacked view;
960
+ * written in it, decoded as the stacked view; and the same with "+" as a space, where the text has a "+" (a "+" after
961
+ * a held value's head with a character reference in it, or in JSON written in a string);
905
962
  * - for a text with a quote in it, its JSON strings joined whole, read as the base's check of a web call's strings read
906
963
  * them (decoded as JSON.parse decodes them, then through the one-family views): one level of JSON's escapes, an
907
964
  * escaped quote a quote, so a held value with a quote of its own reads whole across two strings; the same
908
965
  * percent-decoded, and with "+" as a space (a "+" after a held value's head in one string and its rest in the next);
909
966
  * and JSON's escapes decoded twice, an escaped quote a quote (only where the text has an escaped backslash: otherwise
910
- * it reads as the first). Each is read only where the text holds what it decodes.
967
+ * it reads as the first). Each is read only where the text holds what it decodes;
968
+ * - for a text with an apostrophe in it, its strings joined whole with an apostrophe opening one too (a Python repr's
969
+ * single-quoted dict), one level of JSON's escapes decoded, followed by the again join (the text of each value
970
+ * written in quotes, read as the quoted join one level down: a dict written in a JSON string, a call's arguments)
971
+ * read the same way (a backslash of the dict's own, written once). A view of its own, so the views before it read an
972
+ * apostrophe outside a "..." string as they did; and the quoted join alone decoded through Python's escapes, where
973
+ * the text holds one ("\'" in a string with both quotes, "\x41"), beside it, so a backslash read as itself there
974
+ * still is; and, where the text holds a quote too, the again join alone through both levels of Python's escapes and
975
+ * of JSON's ("\\'", "\\x41", "\\t", "\"", or none). Neither level's parts are read beside the other's, so no held
976
+ * value reads across the two. The quoted join is never read through two levels: in a dict escaped once with no JSON
977
+ * string around it, "\\t" is a backslash and a "t", and a tab there would be a second decode, not a find.
911
978
  * The decoders of a view decode in one pass: each reads at its own trigger character, so a view costs one read of the
912
979
  * text whatever it decodes. Each view is lowered for hexes and flattened for folded identifiers in holds. */
913
980
  const VIEWS = [
@@ -919,10 +986,14 @@ const VIEWS = [
919
986
  viewSpec((has) => has.entity || has.quoteEscape || (has.percent && has.escape), [PERCENT, JSON_ESCAPE, ENTITY]),
920
987
  viewSpec((has) => has.plus && (has.entity || has.escape), [PERCENT, PLUS, JSON_ESCAPE, ENTITY]),
921
988
  viewSpec((has) => has.quote, [PERCENT, JSON_ESCAPE, ENTITY], "nested"),
989
+ viewSpec((has) => has.quote && has.plus, [PERCENT, PLUS, JSON_ESCAPE, ENTITY], "nested"),
922
990
  viewSpec((has) => has.quote, [JSON_ESCAPE_ONCE], "strings"),
923
991
  viewSpec((has) => has.quote && has.percent, [PERCENT, JSON_ESCAPE_ONCE], "strings"),
924
992
  viewSpec((has) => has.quote && has.plus, [PERCENT, PLUS, JSON_ESCAPE_ONCE], "strings"),
925
993
  viewSpec((has) => has.quote && has.deep, [JSON_ESCAPE_QUOTED], "strings"),
994
+ viewSpec((has) => has.apostrophe, [JSON_ESCAPE_ONCE], "both"),
995
+ viewSpec((has) => has.apostrophe && has.python, [PYTHON_ESCAPE], "quoted"),
996
+ viewSpec((has) => has.apostrophe && has.quote, [PYTHON_ESCAPE_TWICE], "again"),
926
997
  ];
927
998
  /** JSON's punctuation between its values. */
928
999
  const STRUCTURE = only("{}[],:");
@@ -950,10 +1021,12 @@ function unitAt(text, at, to, level) {
950
1021
  * (a string the next character after whitespace of which is ":") whole; a value's, at level 0 with `nested`, read again
951
1022
  * at level 1 for the strings written in it (JSON in a string), each of its parts added in its place, and else whole; and
952
1023
  * each run of characters outside a string that are neither whitespace nor JSON's punctuation. A string with no closing
953
- * quote runs to `to`. Any text is read so, JSON or not: a quote in prose opens a string as one in JSON does. Each
954
- * character is read at most three times (at level 0, at level 1, and in the whitespace after a string looking for a
955
- * ":"). */
956
- function partsOf(text, from, to, level, out, nested = true) {
1024
+ * quote runs to `to`. Any text is read so, JSON or not: a quote in prose opens a string as one in JSON does. With
1025
+ * `quoted`, an apostrophe opens a string too, closed by the next apostrophe (a quote inside it is text, as an
1026
+ * apostrophe inside a "..." string is), and at level 0, with `written`, the span of each value written in quotes is added
1027
+ * to it (the again join reads it one level down). Each character is read at most three times (at level 0, at level 1,
1028
+ * and in the whitespace after a string looking for a ":"). */
1029
+ function partsOf(text, from, to, level, out, kind = "nested", written) {
957
1030
  let bare = -1;
958
1031
  const endBare = (end) => {
959
1032
  if (bare >= 0)
@@ -963,7 +1036,7 @@ function partsOf(text, from, to, level, out, nested = true) {
963
1036
  for (let at = from; at < to;) {
964
1037
  const { char, end } = unitAt(text, at, to, level);
965
1038
  const code = char.charCodeAt(0);
966
- if (char !== '"') {
1039
+ if (char !== '"' && !(kind === "quoted" && char === "'")) {
967
1040
  if (isSpace(code) || STRUCTURE(code))
968
1041
  endBare(at);
969
1042
  else if (bare < 0)
@@ -976,7 +1049,7 @@ function partsOf(text, from, to, level, out, nested = true) {
976
1049
  let close = end;
977
1050
  while (close < to) {
978
1051
  const inner = unitAt(text, close, to, level);
979
- if (inner.char === '"')
1052
+ if (inner.char === char)
980
1053
  break;
981
1054
  close = inner.char === "\\" && inner.end < to ? unitAt(text, inner.end, to, level).end : inner.end;
982
1055
  }
@@ -994,10 +1067,13 @@ function partsOf(text, from, to, level, out, nested = true) {
994
1067
  }
995
1068
  if (next === ":")
996
1069
  out.push({ from: end, to: close, name: true });
997
- else if (level === 0 && nested)
1070
+ else if (level === 0 && kind === "nested")
998
1071
  partsOf(text, end, close, 1, out);
999
- else
1072
+ else {
1000
1073
  out.push({ from: end, to: close, name: false });
1074
+ if (level === 0 && char === '"')
1075
+ written?.push([end, close]);
1076
+ }
1001
1077
  at = after;
1002
1078
  }
1003
1079
  endBare(to);
@@ -1014,7 +1090,15 @@ function partsOf(text, from, to, level, out, nested = true) {
1014
1090
  * join is the same for every view that reads it: holds builds each kind once per text. */
1015
1091
  function joinOf(text, kind, cuts) {
1016
1092
  const parts = [];
1017
- partsOf(text, 0, text.length, 0, parts, kind === "nested");
1093
+ if (kind === "again") {
1094
+ // The quoted join's values written in quotes, each read one level down, in the text's order.
1095
+ const written = [];
1096
+ partsOf(text, 0, text.length, 0, [], "quoted", written);
1097
+ for (const [start, end] of written)
1098
+ partsOf(text, start, end, 1, parts, "quoted");
1099
+ }
1100
+ else
1101
+ partsOf(text, 0, text.length, 0, parts, kind);
1018
1102
  const pieces = [];
1019
1103
  const moved = [];
1020
1104
  let length = 0;
@@ -1048,6 +1132,15 @@ function joinOf(text, kind, cuts) {
1048
1132
  scanned.chars += length;
1049
1133
  return { text: pieces.join(""), ...(cuts ? { cuts: moved } : {}) };
1050
1134
  }
1135
+ /** Two joins one after the other (JoinKind `both`), the second's cuts moved past the first; written once. */
1136
+ function bothOf(first, second) {
1137
+ const text = first.text + second.text;
1138
+ scanned.chars += text.length;
1139
+ if (!first.cuts || !second.cuts)
1140
+ return { text };
1141
+ const at = first.text.length;
1142
+ return { text, cuts: [...first.cuts, ...second.cuts.map(([start, end]) => [at + start, at + end])] };
1143
+ }
1051
1144
  /** `text` as the whole-text check reads it: decoded by `spec`'s decoders, then squeezed (squeeze: NFKC, its whitespace
1052
1145
  * and its characters that render as nothing gone), as a held value's needles are. The squeeze is applied to each
1053
1146
  * stretch of non-ASCII characters with the ASCII character before it, which gives what it gives over the whole text (an
@@ -1299,7 +1392,7 @@ export function holds(text, needles, { fold = true, cuts } = {}) {
1299
1392
  const joinFor = (kind) => {
1300
1393
  let join = joins.get(kind);
1301
1394
  if (!join)
1302
- joins.set(kind, (join = joinOf(text, kind, cuts)));
1395
+ joins.set(kind, (join = kind === "both" ? bothOf(joinFor("quoted"), joinFor("again")) : joinOf(text, kind, cuts)));
1303
1396
  return join;
1304
1397
  };
1305
1398
  for (const spec of VIEWS) {
@@ -69,7 +69,7 @@ export interface RunLaunch {
69
69
  * The control marker is outside the run's tool workspace. No source path or credential is kept in this record. */
70
70
  readonly sourceProject?: SourceProjectLaunch;
71
71
  /** The run's learning start, when its agent learns and the server's learning is on, decided once here so the runner reads
72
- * no learning folder or git: `seed`, the learning commit's sha (or null when the seed could not be read); `section`,
72
+ * no learning rows: `seed`, the learning save's id (or null when the seed could not be read); `section`,
73
73
  * the exact # Learned text to lay into the prompt (its owner's corrections, learning.ts learnedSection); `workflows`,
74
74
  * the names of the learned workflows the seed offers the run (chooseWorkflows), absent when none; `noWorkflows`, a run
75
75
  * never answered by a learned workflow and asked for no workflow draft at its end (a native run, an SDK run with no
@@ -172,9 +172,9 @@ export declare function readLaunchBody(stored: unknown): RunLaunch | undefined;
172
172
  export declare const learningStartOf: (launch: RunLaunch) => RunLaunch["learning"];
173
173
  /** The same start read from a launch body's `learning` member alone (Store.runs.learningStarts), as readLaunchBody reads it. */
174
174
  export declare const learningStartOfStored: (stored: unknown) => RunLaunch["learning"];
175
- /** Why a learning run starts with nothing learned, as main says it: its agent's learning folder could not be read
175
+ /** Why a learning run starts with nothing learned, as main says it: its agent's learning could not be read
176
176
  * (`unreadable`, STOPPED.unreadable), what was read could not be made into its start (`not_copied`,
177
- * STOPPED.notCopied), or its launch names a disk of its own, whose learning folder the server does not read
177
+ * STOPPED.notCopied), or its launch names a disk of its own, whose learning the server does not read
178
178
  * (`other_disk`, STOPPED.otherDisk): a run on a named disk learns nothing (learn/learning-of.ts). */
179
179
  export type SeedFailed = "unreadable" | "not_copied" | "other_disk";
180
180
  /** A learning start with no seed (no commit of main, runs-over-store.ts learningStartFor): the run learns nothing, is