@parcha/agentrun-serve 0.1.0-beta.55 → 0.1.0-beta.57

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 (296) hide show
  1. package/CHANGELOG.md +261 -0
  2. package/README.md +228 -45
  3. package/dist/acp-package.d.ts +2 -0
  4. package/dist/adapters.d.ts +18 -5
  5. package/dist/adapters.js +23 -9
  6. package/dist/agent-package.d.ts +3 -3
  7. package/dist/agent-package.js +17 -8
  8. package/dist/answer-json.d.ts +6 -2
  9. package/dist/answer-json.js +22 -4
  10. package/dist/api-keys.d.ts +76 -0
  11. package/dist/api-keys.js +217 -0
  12. package/dist/api-only.d.ts +17 -5
  13. package/dist/api-only.js +36 -8
  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/calendar/tools.js +3 -2
  19. package/dist/chatgpt-plan.d.ts +28 -3
  20. package/dist/chatgpt-plan.js +182 -21
  21. package/dist/claude-login.d.ts +101 -14
  22. package/dist/claude-login.js +232 -49
  23. package/dist/claude-sign-in.d.ts +46 -0
  24. package/dist/claude-sign-in.js +93 -0
  25. package/dist/cli.js +63 -6
  26. package/dist/composio-made.d.ts +4 -0
  27. package/dist/composio-made.js +4 -0
  28. package/dist/composio-preset.d.ts +43 -2
  29. package/dist/composio-preset.js +92 -4
  30. package/dist/computer-held-routes.d.ts +5 -4
  31. package/dist/computer-held-routes.js +29 -8
  32. package/dist/computer-held.d.ts +6 -1
  33. package/dist/computer-held.js +14 -0
  34. package/dist/computer-record.js +4 -2
  35. package/dist/computer-viewer.js +4 -1
  36. package/dist/console/assets/{backend-D5EmB4N3.js → backend-DVhHzJX2.js} +19 -19
  37. package/dist/console/assets/index-Bwn1oTem.css +1 -0
  38. package/dist/console/assets/index-okP-y8PK.js +747 -0
  39. package/dist/console/index.html +2 -2
  40. package/dist/decisions.d.ts +1 -1
  41. package/dist/decisions.js +1 -1
  42. package/dist/docker-host-addresses.d.ts +22 -11
  43. package/dist/docker-host-addresses.js +38 -26
  44. package/dist/env-switch.d.ts +10 -0
  45. package/dist/env-switch.js +33 -2
  46. package/dist/errors.d.ts +1 -0
  47. package/dist/errors.js +2 -0
  48. package/dist/fal-price.d.ts +58 -20
  49. package/dist/fal-price.js +341 -82
  50. package/dist/handed-values.d.ts +43 -1
  51. package/dist/handed-values.js +119 -2
  52. package/dist/harness-archive.d.ts +13 -10
  53. package/dist/harness-archive.js +60 -34
  54. package/dist/harness-check.d.ts +3 -1
  55. package/dist/harness-check.js +25 -46
  56. package/dist/harness-keys.d.ts +73 -27
  57. package/dist/harness-keys.js +194 -61
  58. package/dist/harness-recipe-entry.d.ts +8 -7
  59. package/dist/harness-recipe-entry.js +21 -32
  60. package/dist/harness-recipe.d.ts +38 -25
  61. package/dist/harness-recipe.js +49 -36
  62. package/dist/harness-sign-in.js +12 -23
  63. package/dist/harness-table.d.ts +10 -3
  64. package/dist/harness-table.js +26 -21
  65. package/dist/harness.d.ts +1 -0
  66. package/dist/harness.js +17 -5
  67. package/dist/host-check.d.ts +4 -0
  68. package/dist/host-check.js +4 -0
  69. package/dist/hosted-search.d.ts +1 -1
  70. package/dist/hosted-search.js +1 -2
  71. package/dist/import-worker.d.ts +4 -2
  72. package/dist/import-worker.js +9 -2
  73. package/dist/in-flight.d.ts +26 -0
  74. package/dist/in-flight.js +52 -0
  75. package/dist/key-refusal.d.ts +26 -5
  76. package/dist/key-refusal.js +313 -37
  77. package/dist/learn/secrets.d.ts +31 -11
  78. package/dist/learn/secrets.js +152 -191
  79. package/dist/learning-cost.d.ts +6 -3
  80. package/dist/learning-cost.js +4 -2
  81. package/dist/link-check.js +1 -1
  82. package/dist/llms.txt +2 -2
  83. package/dist/marketplace.d.ts +77 -0
  84. package/dist/marketplace.js +224 -0
  85. package/dist/mcp-api-only-origins.d.ts +30 -0
  86. package/dist/mcp-api-only-origins.js +57 -0
  87. package/dist/mcp-gateway.d.ts +7 -5
  88. package/dist/mcp-gateway.js +9 -12
  89. package/dist/mcp-secret-writes.js +5 -3
  90. package/dist/mcp-servers-store.d.ts +28 -6
  91. package/dist/mcp-servers-store.js +53 -4
  92. package/dist/media-duration.d.ts +3 -0
  93. package/dist/media-duration.js +90 -9
  94. package/dist/model-form.d.ts +5 -4
  95. package/dist/model-form.js +11 -7
  96. package/dist/model.d.ts +5 -2
  97. package/dist/model.js +9 -5
  98. package/dist/ollama-provider.d.ts +7 -1
  99. package/dist/ollama-provider.js +14 -2
  100. package/dist/openapi.d.ts +3 -3
  101. package/dist/openapi.js +245 -42
  102. package/dist/otel/genai.d.ts +65 -0
  103. package/dist/otel/genai.js +116 -0
  104. package/dist/otel/tracer.d.ts +55 -0
  105. package/dist/otel/tracer.js +308 -0
  106. package/dist/page.d.ts +2 -0
  107. package/dist/page.js +3 -1
  108. package/dist/paid-calls.d.ts +1 -32
  109. package/dist/paid-calls.js +4 -39
  110. package/dist/place-offers.d.ts +14 -6
  111. package/dist/place-offers.js +26 -13
  112. package/dist/provider.d.ts +9 -0
  113. package/dist/provider.js +50 -3
  114. package/dist/redact/match.d.ts +101 -0
  115. package/dist/redact/match.js +1152 -0
  116. package/dist/refusal-words.d.ts +11 -0
  117. package/dist/refusal-words.js +11 -0
  118. package/dist/run-census.d.ts +67 -0
  119. package/dist/run-census.js +240 -0
  120. package/dist/run-computer.d.ts +6 -3
  121. package/dist/run-computer.js +4 -1
  122. package/dist/run-cut.d.ts +15 -6
  123. package/dist/run-cut.js +30 -9
  124. package/dist/run-files.d.ts +3 -0
  125. package/dist/run-files.js +3 -0
  126. package/dist/run-launch.d.ts +12 -1
  127. package/dist/run-launch.js +9 -10
  128. package/dist/run-learning-served.d.ts +2 -0
  129. package/dist/run-model-key.d.ts +8 -0
  130. package/dist/run-model-key.js +31 -1
  131. package/dist/run-reads-over-store.d.ts +24 -6
  132. package/dist/run-reads-over-store.js +67 -23
  133. package/dist/run-recordings.d.ts +5 -1
  134. package/dist/run-recordings.js +39 -14
  135. package/dist/run-timeline-served.d.ts +3 -1
  136. package/dist/run-timeline-served.js +4 -4
  137. package/dist/run-usage.d.ts +1 -0
  138. package/dist/runnable.d.ts +10 -1
  139. package/dist/runnable.js +20 -8
  140. package/dist/runner/adapter-loop.d.ts +14 -0
  141. package/dist/runner/adapter-loop.js +56 -11
  142. package/dist/runner/adapter-run-spec.d.ts +45 -8
  143. package/dist/runner/adapter-run-spec.js +154 -29
  144. package/dist/runner/adapters/pi.js +25 -3
  145. package/dist/runner/beside.js +11 -6
  146. package/dist/runner/big-writes.js +1 -10
  147. package/dist/runner/claim-secrets.d.ts +18 -3
  148. package/dist/runner/claim-secrets.js +35 -6
  149. package/dist/runner/cli-run-spec.d.ts +6 -0
  150. package/dist/runner/cli-run-spec.js +85 -36
  151. package/dist/runner/computer-journal.d.ts +9 -1
  152. package/dist/runner/computer-journal.js +26 -0
  153. package/dist/runner/conformance/harness.js +1 -1
  154. package/dist/runner/feedback-round.js +3 -0
  155. package/dist/runner/harness-loops.d.ts +6 -5
  156. package/dist/runner/harness-loops.js +7 -7
  157. package/dist/runner/held.d.ts +11 -5
  158. package/dist/runner/journal-kinds.d.ts +5 -0
  159. package/dist/runner/journal-kinds.js +5 -0
  160. package/dist/runner/loop-contract.d.ts +4 -0
  161. package/dist/runner/main.js +15 -6
  162. package/dist/runner/mcp-claim.js +30 -3
  163. package/dist/runner/mcp-run.d.ts +12 -0
  164. package/dist/runner/mcp-run.js +12 -5
  165. package/dist/runner/model-route.d.ts +17 -0
  166. package/dist/runner/model-route.js +120 -2
  167. package/dist/runner/presence.d.ts +4 -3
  168. package/dist/runner/presence.js +4 -2
  169. package/dist/runner/run-child-host.d.ts +5 -0
  170. package/dist/runner/run-child-host.js +71 -30
  171. package/dist/runner/run-child.js +5 -2
  172. package/dist/runner/runner.d.ts +18 -3
  173. package/dist/runner/runner.js +162 -36
  174. package/dist/runner/store-port.d.ts +1 -1
  175. package/dist/runner/store-secrets.d.ts +6 -0
  176. package/dist/runner/store-secrets.js +49 -7
  177. package/dist/runner/subagent.js +4 -40
  178. package/dist/runner/workflow-first.d.ts +11 -4
  179. package/dist/runner/workflow-first.js +14 -8
  180. package/dist/runner/workflow-spec.js +3 -2
  181. package/dist/runs-over-store.d.ts +15 -6
  182. package/dist/runs-over-store.js +33 -21
  183. package/dist/scrub-command.d.ts +73 -0
  184. package/dist/scrub-command.js +307 -0
  185. package/dist/secret-cut.d.ts +73 -0
  186. package/dist/secret-cut.js +291 -4
  187. package/dist/secret-rules.d.ts +143 -0
  188. package/dist/secret-rules.js +2564 -0
  189. package/dist/secrets.d.ts +7 -0
  190. package/dist/secrets.js +20 -0
  191. package/dist/server-keys.d.ts +20 -0
  192. package/dist/server-keys.js +25 -6
  193. package/dist/server.d.ts +57 -13
  194. package/dist/server.js +371 -113
  195. package/dist/skills/agentrun-serve/SKILL.md +4 -0
  196. package/dist/store/dialect.d.ts +3 -0
  197. package/dist/store/dialect.js +1 -0
  198. package/dist/store/index.d.ts +1 -1
  199. package/dist/store/index.js +1 -1
  200. package/dist/store/journal/storage.js +1 -1
  201. package/dist/store/postgres/dialect.js +3 -0
  202. package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
  203. package/dist/store/schema.d.ts +6 -0
  204. package/dist/store/schema.js +11 -1
  205. package/dist/store/seal.d.ts +6 -1
  206. package/dist/store/seal.js +5 -3
  207. package/dist/store/sqlite/run-launch.d.ts +9 -1
  208. package/dist/store/sqlite/run-launch.js +24 -13
  209. package/dist/store/sqlite/run-patch.d.ts +1 -1
  210. package/dist/store/sqlite/run-patch.js +13 -4
  211. package/dist/store/sqlite/store.js +76 -16
  212. package/dist/store/store.d.ts +53 -3
  213. package/dist/store/store.js +27 -0
  214. package/dist/store-reads/learning.d.ts +6 -3
  215. package/dist/store-reads/learning.js +22 -7
  216. package/dist/store-view.d.ts +3 -0
  217. package/dist/store-view.js +4 -4
  218. package/dist/suggestions.js +3 -2
  219. package/dist/template-eval.d.ts +22 -11
  220. package/dist/template-eval.js +124 -41
  221. package/dist/template-import.d.ts +10 -0
  222. package/dist/template-import.js +16 -7
  223. package/dist/templates.d.ts +10 -2
  224. package/dist/templates.js +28 -8
  225. package/dist/timeline/index.d.ts +1 -1
  226. package/dist/timeline/index.js +1 -1
  227. package/dist/timeline/labels.d.ts +6 -4
  228. package/dist/timeline/labels.js +18 -6
  229. package/dist/timeline/timeline.d.ts +17 -7
  230. package/dist/timeline/timeline.js +28 -14
  231. package/dist/timeline/util.js +1 -1
  232. package/dist/timeline/web-calls.d.ts +26 -9
  233. package/dist/timeline/web-calls.js +124 -37
  234. package/dist/tool-gate.d.ts +42 -3
  235. package/dist/tool-gate.js +69 -6
  236. package/dist/tool-keys-store.d.ts +2 -4
  237. package/dist/tool-keys-store.js +5 -21
  238. package/dist/tool-keys.d.ts +2 -2
  239. package/dist/tool-keys.js +2 -2
  240. package/dist/tool-list.js +1 -1
  241. package/dist/tool-plane.d.ts +2 -2
  242. package/dist/tool-plane.js +35 -33
  243. package/dist/tools.js +13 -7
  244. package/dist/trigger-targets.d.ts +4 -0
  245. package/dist/trigger-targets.js +9 -2
  246. package/dist/triggers.d.ts +67 -4
  247. package/dist/triggers.js +171 -22
  248. package/dist/until.d.ts +3 -0
  249. package/dist/until.js +11 -0
  250. package/dist/validate.js +1 -1
  251. package/dist/web-fake.d.ts +1 -3
  252. package/dist/web-fake.js +7 -18
  253. package/dist/web-fetch.d.ts +6 -72
  254. package/dist/web-fetch.js +11 -265
  255. package/dist/web-run.d.ts +31 -0
  256. package/dist/web-run.js +90 -0
  257. package/dist/web-save.d.ts +6 -4
  258. package/dist/web-save.js +9 -12
  259. package/dist/web-search.d.ts +9 -127
  260. package/dist/web-search.js +23 -259
  261. package/dist/wires.d.ts +13 -0
  262. package/dist/wires.js +11 -0
  263. package/dist/workflow-run.d.ts +5 -4
  264. package/dist/workflow-run.js +5 -4
  265. package/dist/workspace/computer-deps.d.ts +3 -1
  266. package/dist/workspace/computer-deps.js +12 -4
  267. package/dist/workspace/computer-for-claim.d.ts +19 -2
  268. package/dist/workspace/computer-for-claim.js +101 -13
  269. package/dist/workspace/computer-janitor.d.ts +15 -7
  270. package/dist/workspace/computer-janitor.js +33 -8
  271. package/dist/workspace/computer-kept.d.ts +55 -4
  272. package/dist/workspace/computer-kept.js +129 -8
  273. package/dist/workspace/index.d.ts +1 -1
  274. package/dist/workspace/index.js +1 -1
  275. package/dist/workspace/kind-skills.d.ts +4 -0
  276. package/dist/workspace/kind-skills.js +9 -0
  277. package/dist/workspace/run-end-computers.d.ts +5 -1
  278. package/dist/workspace/run-end-computers.js +27 -1
  279. package/dist/workspace/synced-folder.js +3 -4
  280. package/dist/wrapped.d.ts +65 -0
  281. package/dist/wrapped.js +77 -0
  282. package/package.json +17 -11
  283. package/skills/agentrun-serve/SKILL.md +4 -0
  284. package/templates/README.md +38 -15
  285. package/dist/console/assets/index-DUYLaqiR.js +0 -746
  286. package/dist/console/assets/index-DYhU4adm.css +0 -1
  287. package/dist/exa-keyless.d.ts +0 -34
  288. package/dist/exa-keyless.js +0 -118
  289. package/dist/firecrawl-keyless.d.ts +0 -41
  290. package/dist/firecrawl-keyless.js +0 -152
  291. package/dist/keyless-mcp.d.ts +0 -36
  292. package/dist/keyless-mcp.js +0 -127
  293. package/dist/text-urls.d.ts +0 -38
  294. package/dist/text-urls.js +0 -170
  295. package/dist/web-fetch-direct.d.ts +0 -119
  296. package/dist/web-fetch-direct.js +0 -190
@@ -4,9 +4,10 @@
4
4
  // count, a file name, a duration, another service's status) is no refused key, and the error is left as it is.
5
5
  import { DEFAULT_HARNESS } from "./harness.js";
6
6
  import { harnessOf } from "./harness-table.js";
7
- import { endsInScheme, redactSecrets, valueMatcher } from "./learn/secrets.js";
7
+ import { cutSecrets, endsInScheme, redactSecrets, secretShapes, valueLeft, valueMatcher } from "./learn/secrets.js";
8
8
  import { hostModel, MODEL_KEYS } from "./model.js";
9
9
  import { modelWire, openRouterOnly, WIRES } from "./provider.js";
10
+ import { jsonEscapeAt, privateKeyEnd, scanned, squeeze } from "./redact/match.js";
10
11
  import { savedGatewayIn } from "./model-gateway.js";
11
12
  const row = (id) => {
12
13
  const found = MODEL_KEYS.find((r) => r.id === id);
@@ -59,7 +60,7 @@ const SHOWN = 2000;
59
60
  * form (6 times it, for JSON's \uXXXX; percent is 3, hex 2, base64 4/3) and 16 more. A key whose start the cut can show
60
61
  * starts before SHOWN, so it ends inside that head and is found whole; one that starts later is never shown. So a long
61
62
  * error costs no more to redact than a short one, whatever it holds. `shown`: a head of another length, for a reader
62
- * that is shown more (a template eval's grader reads a call's result to CALL_RESULT_CHARS). */
63
+ * that is shown more. */
63
64
  export function redacted(text, secrets, shown = SHOWN) {
64
65
  const longest = secrets.reduce((most, value) => Math.max(most, value.length), 0);
65
66
  const window = shown + 6 * longest + 16;
@@ -83,50 +84,325 @@ export const answerPasses = { count: 0 };
83
84
  * in it, and NEVER cut: an answer is shown whole. The same rule as redacted() (redactSecrets over `secrets`), over the
84
85
  * whole text, read in pieces of about ANSWER_PIECE characters cut at whitespace. No form of a held value redactSecrets
85
86
  * finds as it stands (as written, JSON-escaped, base64, hex) holds whitespace, so a cut there splits none; the one shape
86
- * read across whitespace, a Bearer scheme and its token, is never cut between the two (endsInScheme). A run of more
87
- * than ANSWER_PIECE characters with no whitespace is no person's text and is shown as "[redacted]", unread. A value split
88
- * by whitespace across a cut, or a form only found across pieces, still shows to one valueMatcher pass over the joined
89
- * output, and then the whole answer is "[redacted]", as redactSecrets does with a text that still holds a value. */
87
+ * read across whitespace, a Bearer scheme and its token, is never cut between the two (endsInScheme); nor is a private
88
+ * key block, cut whole by its shape from its BEGIN line to its END line (keyWhole). A run with no
89
+ * whitespace past a piece is cut at the end of a JSON string in it (never in a URL's user and password), or, a run of
90
+ * a JSON array's numbers only, after a comma (runCut), so compact JSON reads in pieces too. A run of more than ANSWER_PIECE characters with neither is no
91
+ * person's text and is shown as "[redacted]", unread, from where its run starts. A value or a secret shape split across
92
+ * a cut, or a form only found across pieces, still shows to one pass over the joined pieces (heldIn: valueLeft over
93
+ * them as they came, and secretShapes over them redacted; with the head of each run left unread, where the rest of a
94
+ * value split before it would be, and its tail, where the head of a value split after it would be), and then the whole
95
+ * answer is "[redacted]", as redactSecrets does with a text that still holds a value. So is an answer whose pieces,
96
+ * as shown, read as a held value together (heldIn reads the text it returns too). A value split inside one piece withholds only that piece, by the piece's own redaction. */
90
97
  export function redactedAnswer(text, secrets) {
91
98
  if (!text)
92
99
  return text;
93
100
  answerPasses.count++;
94
- const parts = [];
95
- for (let from = 0; from < text.length;) {
96
- let to = Math.min(text.length, from + ANSWER_PIECE);
97
- if (to < text.length) {
98
- const space = text.slice(from, to).search(/\s[^\s]*$/);
99
- if (space <= 0) {
100
- // No whitespace in this piece: the run of text with none goes on to the next whitespace, read as one.
101
- const next = text.slice(to).search(/\s/);
102
- to = next < 0 ? text.length : to + next;
103
- parts.push(to - from > ANSWER_PIECE ? "[redacted]" : redactSecrets(text.slice(from, to), secrets, Buffer.byteLength(text.slice(from, to))));
104
- from = to;
105
- continue;
101
+ const { out, seen } = inPieces(text, secrets);
102
+ return heldIn(seen, secrets, out) ? "[redacted]" : out;
103
+ }
104
+ /** `text`, a call's result as a grader's read shows it (timeline calls, tool_result_text), with no held secret in it:
105
+ * read in pieces as redactedAnswer reads an answer, each piece redacted, then shown as `show` makes it (the timeline's
106
+ * scrubUrls), then one pass over the pieces (heldIn). Every check reads the text as it came, redacted, and not only as
107
+ * shown: shown, a URL's query, fragment and userinfo are cut apart, and a held value in one no longer reads as itself;
108
+ * what it returns is read too, for a held value its pieces show only together. A piece
109
+ * never splits a URL (it is cut at whitespace, after a quote, or in a run of numbers), so a piece shows as the whole
110
+ * text would. Only the head the reader is shown is read: pieces stop once they show more than `shown` characters, and
111
+ * the pass also reads the text where they stopped (peek), so a value or a shape the stop split is seen whole. Every
112
+ * character returned was read; the caller cuts it to `shown`. So no redaction pass reads more than a piece, however long
113
+ * the result or its head. */
114
+ export function redactedCall(text, secrets, shown, show = (piece) => piece) {
115
+ if (!text)
116
+ return text;
117
+ const { out, seen, short } = inPieces(text, secrets, shown, show);
118
+ // A read that stopped on what it read, before what it shows reached `shown`, ends as a cut does ("...", timeline/util.ts
119
+ // cut), so a reader (the link check) knows it is not whole.
120
+ const result = short ? `${out}...` : out;
121
+ return heldIn(seen, secrets, result) ? "[redacted]" : result;
122
+ }
123
+ /** Whether redactSecrets withholds `text` whole: it holds a held value or a secret shape no cut in place takes (split by
124
+ * whitespace, encoded, written as JSON's \uXXXX escapes). Read whole, never in pieces: the caller bounds what it reads
125
+ * (a web call's strings, joined: timeline calls.holds). */
126
+ export function withheldWhole(text, secrets) {
127
+ return redactSecrets(text, secrets, Number.POSITIVE_INFINITY) === "[redacted]";
128
+ }
129
+ /** Whether the text a reader is about to be shown (`shown`, what the caller returns) holds a held value, or the joined
130
+ * pieces still hold one or a secret shape: one a cut split. `shown` is read whole for a held value (valueMatcher, one
131
+ * linear pass): however the pieces were put together, as each was cut or shown, or an unread run's "[redacted]" between
132
+ * them, no text that reads as a held value is returned (a held value holding "[redacted]", its parts on either side of
133
+ * a cut in another piece). A value is also looked for in the pieces as they came, joined by line breaks, each piece's
134
+ * own cuts covering it (valueLeft): a piece's cut can take part of a value split across pieces (a credential
135
+ * parameter's value cut in place at the end of a piece, the rest of the held value in the next), and the rest then no
136
+ * longer reads as the value. A piece withheld whole covers all of itself, so a value split inside one piece is that
137
+ * piece's own redaction's, and only a value no cut covers across pieces (or in the text read past where they stopped)
138
+ * withholds the text. Each unread run's head and tail are covered (it shows as "[redacted]") and read: its head for the
139
+ * rest of a value split before it, its tail for the head of a value whose rest comes after it. A shape is looked for in
140
+ * the pieces each redacted (a shape whole in one is no shape a cut split). A peek too long to read (`unread`) withholds
141
+ * the text too. */
142
+ function heldIn(seen, secrets, shown) {
143
+ return seen.unread || valueMatcher(secrets)(shown) || valueLeft(seen.raw, secrets, seen.cuts) || secretShapes(seen.shapes).length > 0;
144
+ }
145
+ /** `text` read in pieces as redactedAnswer says (pieceEnd), each redacted by itself: what the pieces show, joined, and
146
+ * what the pass after them reads (heldIn): each piece as it came and the spans its redaction cut, and each piece
147
+ * redacted, with the head and the tail of each unread run put back (covered, as they came; the head redacted by itself
148
+ * before its "[redacted]" for the shapes). A run runCut cut that then goes on past a piece with
149
+ * no place to cut is unread from its start, the pieces of it already read taken back, so no piece shows the head of a
150
+ * value or a shape the cut split. With `enough`, no piece is read once the pieces show more than `enough` characters,
151
+ * and the text where they stopped, `hold` characters the matcher sees of it (peek), goes to the pass the same way.
152
+ * Each piece is redacted, then shown as `show` makes it: `out` is what the pieces show, the pass reads them unshown. */
153
+ function inPieces(text, secrets, enough = Number.POSITIVE_INFINITY, show = (piece) => piece) {
154
+ const hold = 6 * secrets.reduce((most, value) => Math.max(most, value.length), 0) + 16;
155
+ const out = [];
156
+ const shapes = [];
157
+ const reads = [];
158
+ let shown = 0;
159
+ let unread = false;
160
+ // The run runCut is cutting: where it starts in `text`, and its first piece's index in `out`.
161
+ let run;
162
+ let from = 0;
163
+ // Also stops past 4 × `enough` characters read: text that shows as almost nothing (URLs whose queries are elided) is
164
+ // not read to its end. Where it stops, the peek reads on as at any stop.
165
+ while (from < text.length && shown <= enough && from <= 4 * enough) {
166
+ const to = pieceEnd(text, from);
167
+ const raw = text.slice(from, to);
168
+ if (raw.length > ANSWER_PIECE) {
169
+ const start = run?.from ?? from;
170
+ if (run) {
171
+ for (const part of out.splice(run.at))
172
+ shown -= part.length;
173
+ shapes.splice(run.at);
174
+ reads.splice(run.at);
106
175
  }
107
- to = from + space + 1;
108
- // A cut after a Bearer scheme would leave its token at the head of the next piece, where no shape reads it (the
109
- // shape is the scheme, then the token). The cut moves back to the whitespace before the scheme; with none in this
110
- // piece, the scheme and its token are read as one run, to the next whitespace, as a run with no whitespace is.
111
- if (endsInScheme(text.slice(from, to))) {
112
- const before = text.slice(from, to).trimEnd().search(/\s[^\s]*$/);
113
- if (before > 0)
114
- to = from + before + 1;
115
- else {
116
- const next = text.slice(to).search(/\s/);
117
- to = next < 0 ? text.length : to + next;
118
- parts.push(to - from > ANSWER_PIECE ? "[redacted]" : redactSecrets(text.slice(from, to), secrets, Buffer.byteLength(text.slice(from, to))));
119
- from = to;
120
- continue;
121
- }
176
+ // The run is shown as "[redacted]": its head is read, covered, for the rest of a value split before it, and its
177
+ // tail (tailOf: `hold` characters the matcher sees, at most a piece), covered too, for the head of a value whose
178
+ // rest comes after it. One read, the two joined by a line break, as each piece is one.
179
+ const head = peek(text, start, hold);
180
+ const tail = head === undefined ? undefined : tailOf(text, start, to, hold);
181
+ if (head === undefined || tail === undefined)
182
+ unread = true;
183
+ else {
184
+ shapes.push(`${redactSecrets(head, secrets, Buffer.byteLength(head))}[redacted]`);
185
+ const both = `${head}\n${tail}`;
186
+ reads.push({ text: both, cuts: [[0, both.length]] });
122
187
  }
188
+ out.push("[redacted]");
189
+ shown += "[redacted]".length;
190
+ run = undefined;
191
+ }
192
+ else {
193
+ const cut = cutSecrets(raw, secrets, Buffer.byteLength(raw));
194
+ const part = cut === "whole" ? "[redacted]" : cut.out;
195
+ reads.push({ text: raw, cuts: cut === "whole" ? [[0, raw.length]] : cut.spans });
196
+ // A piece that ends inside a run (runCut's): its run goes on in the next piece.
197
+ if (to < text.length && /\S/.test(text[to - 1] ?? "") && /\S/.test(text[to] ?? ""))
198
+ run ??= { from, at: out.length };
199
+ else
200
+ run = undefined;
201
+ const showsAs = show(part);
202
+ out.push(showsAs);
203
+ shapes.push(part);
204
+ shown += showsAs.length;
123
205
  }
124
- const piece = text.slice(from, to);
125
- parts.push(redactSecrets(piece, secrets, Buffer.byteLength(piece)));
126
206
  from = to;
127
207
  }
128
- const out = parts.join("");
129
- return valueMatcher(secrets)(out) ? "[redacted]" : out;
208
+ if (from < text.length) {
209
+ // Stopped inside a run runCut cut: the rest of it, to its next whitespace (at most a piece), goes to the pass too.
210
+ const space = run ? text.slice(from, from + ANSWER_PIECE).search(/\s/) : 0;
211
+ scanned.chars += space < 0 ? Math.min(ANSWER_PIECE, text.length - from) : space + 1;
212
+ const runTo = from + (space < 0 ? ANSWER_PIECE : space);
213
+ const ahead = peek(text, from, hold);
214
+ if (ahead === undefined)
215
+ unread = true;
216
+ else {
217
+ const rest = runTo > from + ahead.length ? text.slice(from, runTo) : ahead;
218
+ shapes.push(redactSecrets(rest, secrets, Buffer.byteLength(rest)));
219
+ reads.push({ text: rest, cuts: [] });
220
+ }
221
+ }
222
+ // The reads joined by line breaks, each one's cuts moved to where it stands in the join. The matcher's views read a
223
+ // line break as nothing, so a value whole across two pieces is no form found as it stands there, and is left.
224
+ let raw = "";
225
+ const cuts = [];
226
+ reads.forEach((read, at) => {
227
+ if (at > 0)
228
+ raw += "\n";
229
+ for (const [start, end] of read.cuts)
230
+ cuts.push([raw.length + start, raw.length + end]);
231
+ raw += read.text;
232
+ });
233
+ const [shows, cutShapes] = [out.join(""), shapes.join("")];
234
+ // Each of the three joins read once.
235
+ scanned.chars += raw.length + shows.length + cutShapes.length;
236
+ return { out: shows, seen: { raw, cuts, shapes: cutShapes, unread }, short: from < text.length && shown <= enough };
237
+ }
238
+ /** text from `from` on, as far as `count` characters the matcher sees (all of it, if it holds fewer), each run of
239
+ * whitespace in it one space. The matcher reads "+" as a space and decodes percent-encoded bytes and JSON's escapes
240
+ * (one level and two, as the JSON view reads them), so a "+", an encoded byte and an escape that decodes to whitespace
241
+ * count no more than whitespace does, and any other escape counts as what the view keeps of the character it decodes
242
+ * to. A character that renders as nothing (a zero-width space, a soft hyphen) counts as nothing too: the views drop it.
243
+ * Padding of any of them never hides the rest of a value split before it. Undefined, so the caller withholds the text,
244
+ * when that takes more than a piece of text (a run of whitespace counted as one): no redaction pass reads more than a
245
+ * piece. */
246
+ function peek(text, from, count) {
247
+ const read = visible(text, from, count, text.length);
248
+ return read.span > ANSWER_PIECE ? undefined : read.parts.join("");
249
+ }
250
+ /** The end of the run text[start, to) the pass reads for the head of a value whose rest comes after the run: as few of
251
+ * its last characters as hold `count` characters the matcher sees (at most a piece's worth), counted as peek counts
252
+ * them, so padding the views read as nothing (whitespace, a zero-width space, a soft hyphen, an escape or encoded bytes
253
+ * that decode to either) between that head and the run's end never pushes the head out of it. Read forward from a
254
+ * start moved back from `to`, twice as far each time, so it reads at most two pieces in all. Undefined, so the caller
255
+ * withholds the text, when that takes more than a piece of text. */
256
+ function tailOf(text, start, to, count) {
257
+ const want = Math.min(count, ANSWER_PIECE);
258
+ for (let width = Math.min(want, to - start);; width = Math.min(2 * width, ANSWER_PIECE, to - start)) {
259
+ const from = to - width;
260
+ if (from === start || visible(text, from, want, to).found >= want)
261
+ return text.slice(from, to);
262
+ if (width >= ANSWER_PIECE)
263
+ return undefined;
264
+ }
265
+ }
266
+ /** text[from, to) read as peek says, until `count` characters the matcher sees are found or the read passes a piece
267
+ * of text (`span`, a run of whitespace counted as one): what it read, as peek returns it, and how many it found. */
268
+ function visible(text, from, count, to) {
269
+ const parts = [];
270
+ let span = 0;
271
+ let found = 0;
272
+ let escape;
273
+ for (let at = from; at < to && found < count && span <= ANSWER_PIECE;) {
274
+ SPACES.lastIndex = at;
275
+ let end = SPACES.test(text) ? SPACES.lastIndex : at;
276
+ if (end > at) {
277
+ parts.push(" ");
278
+ span++;
279
+ }
280
+ else {
281
+ while (end - at <= ANSWER_PIECE && end + 3 <= to && text[end] === "%" && HEX_PAIR.test(text.slice(end + 1, end + 3)))
282
+ end += 3;
283
+ if (end > at)
284
+ found += squeeze(Buffer.from(text.slice(at, end).replaceAll("%", ""), "hex").toString("utf8")).length;
285
+ else if (text[at] === "\\" && (escape = jsonEscapeAt(text, at)) !== undefined) {
286
+ end = escape.end;
287
+ found += squeeze(escape.char).length;
288
+ }
289
+ else {
290
+ end = at + 1;
291
+ if (text[at] !== "+")
292
+ found += squeeze(text[at]).length;
293
+ }
294
+ parts.push(text.slice(at, end));
295
+ span += end - at;
296
+ }
297
+ // Each character read, a percent-encoded run's twice more (its hex parsed, then decoded).
298
+ scanned.chars += text[at] === "%" && end > at + 1 ? 3 * (end - at) : end - at;
299
+ at = end;
300
+ }
301
+ return { parts, found, span };
302
+ }
303
+ const SPACES = /\s+/y;
304
+ const HEX_PAIR = /^[0-9A-Fa-f]{2}$/;
305
+ /** Where the piece of `text` read from `from` ends: at its last whitespace before ANSWER_PIECE characters; with none, at
306
+ * runCut's place, else at the next whitespace (a run read as one, or unread past ANSWER_PIECE). Never inside a private
307
+ * key block whose END line is in reach (keyWhole). */
308
+ function pieceEnd(text, from) {
309
+ return keyWhole(text, from, spaceEnd(text, from));
310
+ }
311
+ /** `end`, the end of the piece read from `from`, or, where a private key block crosses it, where the piece ends instead,
312
+ * so the block is read whole in one piece and cut whole by its shape: a piece cut inside it would show the rest of its
313
+ * body and its END line in the next piece, where no shape starts. Only the last "-----BEGIN" in the piece (at most a
314
+ * piece back from `end`) can start a block that crosses it: the END line an earlier one reads stops at that one's
315
+ * dashes. The piece ends at the last whitespace before the block's BEGIN line, so the next piece starts with the block;
316
+ * with none in the piece (the block starts it, a run glued to it), at the block's END line, so the block is one piece
317
+ * (or, longer than a piece, one run read as "[redacted]"). */
318
+ function keyWhole(text, from, end) {
319
+ if (end >= text.length)
320
+ return end;
321
+ const start = Math.max(from, end - ANSWER_PIECE);
322
+ const window = text.slice(start, end);
323
+ const begin = window.lastIndexOf("-----BEGIN");
324
+ scanned.chars += window.length;
325
+ if (begin < 0)
326
+ return end;
327
+ const block = privateKeyEnd(text, start + begin);
328
+ if (block <= end)
329
+ return end;
330
+ const space = window.slice(0, begin).search(/\s\S*$/);
331
+ return space >= 0 ? start + space + 1 : block;
332
+ }
333
+ /** pieceEnd's place, before keyWhole moves it. */
334
+ function spaceEnd(text, from) {
335
+ const to = Math.min(text.length, from + ANSWER_PIECE);
336
+ if (to === text.length)
337
+ return to;
338
+ const head = text.slice(from, to);
339
+ const space = head.search(/\s[^\s]*$/);
340
+ // The search for the piece's last whitespace reads each run of the piece twice at most (to the run's end, then back);
341
+ // the scheme's check after it, as much again.
342
+ scanned.chars += 4 * head.length;
343
+ if (space <= 0) {
344
+ const cut = runCut(text, from, to);
345
+ return cut > from ? cut : runEnd(text, to);
346
+ }
347
+ const end = from + space + 1;
348
+ // A cut after a Bearer scheme would leave its token at the head of the next piece, where no shape reads it (the shape
349
+ // is the scheme, then the token). The cut moves back to the whitespace before the scheme; with none in this piece, the
350
+ // scheme and its token are read as one run, to the next whitespace, as a run with no whitespace is.
351
+ if (!endsInScheme(text.slice(from, end)))
352
+ return end;
353
+ const before = text.slice(from, end).trimEnd().search(/\s[^\s]*$/);
354
+ return before > 0 ? from + before + 1 : runEnd(text, end);
355
+ }
356
+ /** The next whitespace in `text` at or after `at`, or its end. */
357
+ function runEnd(text, at) {
358
+ const next = text.slice(at).search(/\s/);
359
+ scanned.chars += next < 0 ? text.length - at : next + 1;
360
+ return next < 0 ? text.length : at + next;
361
+ }
362
+ /** Where a run with no whitespace in text[from, to) may be cut, or -1: after the last quote in it that ends a JSON
363
+ * string (no backslash before it; a comma, colon or closing bracket after it) and is in no URL's authority
364
+ * (authorities); or, a run of a JSON array's numbers only, after its last comma. The one secret shape that may hold a
365
+ * quote is a URL's user and password, so no cut splits a shape, whatever its length: a run with no other place to cut
366
+ * is read to its end, or unread from its start. A held value cut there still shows to the pass over the joined pieces
367
+ * (heldIn), and withholds the text whole. Each search keeps to text[from, to), but for where a URL's authority ends,
368
+ * which is read once per URL, to the end of its run at most. */
369
+ function runCut(text, from, to) {
370
+ const head = text.slice(from, to);
371
+ // The head read three times: back from its end for each quote, and for a JSON array's numbers twice.
372
+ scanned.chars += 3 * head.length;
373
+ const urls = authorities(text, from, head);
374
+ let url = urls.length - 1;
375
+ for (let at = head.lastIndexOf('"'); at >= 0; at = at > 0 ? head.lastIndexOf('"', at - 1) : -1) {
376
+ // The authority starting last before this quote, the one it could be in: they do not overlap.
377
+ while (url >= 0 && urls[url][0] >= at)
378
+ url--;
379
+ const inUrl = url >= 0 && at < urls[url][1];
380
+ if (!inUrl && (at > 0 ? head[at - 1] : text[from - 1]) !== "\\" && /[,:\]}]/.test(text[from + at + 1] ?? ""))
381
+ return from + at + 1;
382
+ }
383
+ const comma = head.lastIndexOf(",");
384
+ return comma > 0 && /^\s?[-+.\deE,[\]{}:]+$/.test(head) ? from + comma + 1 : -1;
385
+ }
386
+ /** Each URL authority in `head` (text from `from`) that holds a user and password, as [start, end) in `head`: from its
387
+ * "://" to the "@" that ends it, past the head's end if need be. One whose first whitespace, "/", "?" or "#" comes
388
+ * before any "@" (a URL with no password, then the rest of the JSON it is in) holds none, so none of it is kept whole. */
389
+ function authorities(text, from, head) {
390
+ const found = [];
391
+ const stop = /[\s/?#@]/g;
392
+ for (let at = head.indexOf("://"); at >= 0; at = head.indexOf("://", at)) {
393
+ stop.lastIndex = from + at + 3;
394
+ const hit = stop.exec(text);
395
+ const end = (hit?.index ?? text.length) - from;
396
+ // Its authority, from the "://" to the stop (the head's search for "://" counts with runCut's reads).
397
+ scanned.chars += end - at;
398
+ if (hit?.[0] === "@")
399
+ found.push([at, end]);
400
+ if (end >= head.length)
401
+ break;
402
+ // Past an "@", on; past any other stop, from the character before it: a "/" may be the first of the next "://".
403
+ at = hit?.[0] === "@" ? end : end - 1;
404
+ }
405
+ return found;
130
406
  }
131
407
  /** Whether a number shows a held value. A held value can be all digits (a gateway's key), and a record or a call's
132
408
  * arguments can quote it as a number: one whose digits hold a held value, by the same rule as a string's, is held. A
@@ -1,8 +1,9 @@
1
+ import { type Needles, type Span } from "../redact/match.js";
1
2
  /** Whether `text` ends in a `Bearer` scheme and the blanks after it: the one place a shape is read across whitespace
2
3
  * (the scheme, then its token), so a reader that cuts a text at whitespace must not cut there (key-refusal.ts
3
4
  * redactedAnswer). */
4
5
  export declare const endsInScheme: (text: string) => boolean;
5
- /** The kinds of secret-shaped text in `text`. */
6
+ /** The kinds of secret-shaped text in `text` (redact/match.ts SECRET_SHAPES). */
6
7
  export declare const secretShapes: (text: string) => string[];
7
8
  /** The kinds of text in `text` learning never keeps: every secret shape, and a bank's numbers beside their words. */
8
9
  export declare const learnedSecretShapes: (text: string) => string[];
@@ -14,18 +15,38 @@ export declare const PRINT_MAX = 4096;
14
15
  * any case, base64, a hex identifier in it folded) and each secret-shaped run replaced by "[redacted]": what the
15
16
  * checker prints never holds a secret, wherever it was found, a file's name included, each value as a path names it too
16
17
  * (pathSpellings) and as a URL's path writes it (percentForms). Every form is found in `text` as given, and overlapping
17
- * finds are redacted as one, so
18
- * one value never hides part of another from the search. A text
19
- * that still holds a value or a shape after that (a form not found as it stands: percent encoded, split by whitespace,
20
- * an NFKC variant), or that is over `max` bytes (PRINT_MAX unless the caller names more), is redacted whole, never in
21
- * part. The folded finds only ever add to that: the whole-text check is first made with them left in (a value split by
22
- * a line break is still seen whole, never hidden by its hex part cut alone), and the fold-aware one always after, on
23
- * what is left (a folded value split by whitespace or percent-encoded is found there, never handed back). */
24
- export declare function redactSecrets(text: string, values: readonly string[], max?: number): string;
18
+ * finds are redacted as one, so one value never hides part of another from the search. A text that holds a value in a
19
+ * form not found as it stands (percent encoded, split by whitespace, an NFKC variant), read in `text` as given, is
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
+ * 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. `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";
25
31
  /** `text` as redactSecrets cuts it, and of a bank's numbers beside their words too (MONEY_SHAPES): what learning prints
26
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
27
33
  * may show its user an account number. */
28
34
  export declare function redactLearned(text: string, values: readonly string[], max?: number): string;
35
+ /** redactSecrets, and where it cut: the spans of `text` cut in place and the text so cut, or "whole" where redactSecrets
36
+ * answers "[redacted]". A reader that redacts a text in pieces (key-refusal.ts) reads the pieces as they came for a
37
+ * value split across them (valueLeft), each piece's cuts covering it. */
38
+ export declare function cutSecrets(text: string, values: readonly string[], max?: number): {
39
+ spans: Span[];
40
+ out: string;
41
+ } | "whole";
42
+ /** Whether `text` holds one of `values` in a form valueMatcher finds, a character of which no cut covers: what
43
+ * a reader that cut `text` there would still show of it. The cuts are `cuts` (merged spans of `text`, in order: where a
44
+ * reader that cut it in pieces cut each), or else those redactSecrets makes of `text` whole (its values' forms, hexes
45
+ * and folded identifiers, and the secret shapes, found as they stand). */
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;
29
50
  /** A value shorter than this matches too much text by chance to be refused. */
30
51
  export declare const MIN_SECRET = 8;
31
52
  /** An excerpt of a run's input or answer as learning keeps it: `text` cut of the secrets `shown` knows, whole, then
@@ -38,8 +59,7 @@ export declare function excerptShown(text: string, shown: {
38
59
  }, max: number): string;
39
60
  /** A matcher for `values` in a text: plain, split by whitespace, as JSON writes it, percent or form encoded, base64 or
40
61
  * hex, and each hex identifier in a value folded: in any case, its separators dropped or moved (foldedOf). Values
41
- * shorter than MIN_SECRET are left out. `fold: false`, the matcher without the folded needles (redactSecrets' first
42
- * whole-text check). */
62
+ * shorter than MIN_SECRET are left out. `fold: false`, the matcher without the folded needles. */
43
63
  export declare function valueMatcher(values: readonly string[], { fold }?: {
44
64
  fold?: boolean;
45
65
  }): (text: string) => boolean;