@earendil-works/pi-durable 1.4.0 → 1.5.0

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 (221) hide show
  1. package/CHANGELOG.md +186 -0
  2. package/README.md +181 -84
  3. package/dist/codemode/codemode.d.ts +4 -4
  4. package/dist/codemode/codemode.d.ts.map +1 -1
  5. package/dist/codemode/codemode.js +9 -12
  6. package/dist/codemode/codemode.js.map +1 -1
  7. package/dist/codemode/models.js +4 -4
  8. package/dist/codemode/models.js.map +1 -1
  9. package/dist/env/index.d.ts +12 -10
  10. package/dist/env/index.d.ts.map +1 -1
  11. package/dist/env/index.js.map +1 -1
  12. package/dist/env/node-watch.d.ts +3 -3
  13. package/dist/env/node-watch.d.ts.map +1 -1
  14. package/dist/env/node-watch.js +18 -16
  15. package/dist/env/node-watch.js.map +1 -1
  16. package/dist/env/node.d.ts +2 -2
  17. package/dist/env/node.d.ts.map +1 -1
  18. package/dist/env/node.js +1 -1
  19. package/dist/env/node.js.map +1 -1
  20. package/dist/errors.d.ts +18 -2
  21. package/dist/errors.d.ts.map +1 -1
  22. package/dist/errors.js +26 -3
  23. package/dist/errors.js.map +1 -1
  24. package/dist/harness/agent.d.ts.map +1 -1
  25. package/dist/harness/agent.js +10 -2
  26. package/dist/harness/agent.js.map +1 -1
  27. package/dist/harness/compaction.d.ts.map +1 -1
  28. package/dist/harness/compaction.js +19 -2
  29. package/dist/harness/compaction.js.map +1 -1
  30. package/dist/harness/context.d.ts +23 -7
  31. package/dist/harness/context.d.ts.map +1 -1
  32. package/dist/harness/context.js +71 -25
  33. package/dist/harness/context.js.map +1 -1
  34. package/dist/harness/define.d.ts +7 -3
  35. package/dist/harness/define.d.ts.map +1 -1
  36. package/dist/harness/define.js +4 -0
  37. package/dist/harness/define.js.map +1 -1
  38. package/dist/harness/generation.d.ts +38 -5
  39. package/dist/harness/generation.d.ts.map +1 -1
  40. package/dist/harness/generation.js +445 -96
  41. package/dist/harness/generation.js.map +1 -1
  42. package/dist/harness/harness.d.ts +2 -0
  43. package/dist/harness/harness.d.ts.map +1 -1
  44. package/dist/harness/harness.js +87 -62
  45. package/dist/harness/harness.js.map +1 -1
  46. package/dist/harness/inbox.d.ts +5 -1
  47. package/dist/harness/inbox.d.ts.map +1 -1
  48. package/dist/harness/inbox.js +4 -1
  49. package/dist/harness/inbox.js.map +1 -1
  50. package/dist/harness/json.d.ts +20 -4
  51. package/dist/harness/json.d.ts.map +1 -1
  52. package/dist/harness/json.js +23 -5
  53. package/dist/harness/json.js.map +1 -1
  54. package/dist/harness/live.d.ts +122 -16
  55. package/dist/harness/live.d.ts.map +1 -1
  56. package/dist/harness/live.js +93 -12
  57. package/dist/harness/live.js.map +1 -1
  58. package/dist/harness/partial-changes.d.ts +54 -0
  59. package/dist/harness/partial-changes.d.ts.map +1 -0
  60. package/dist/harness/partial-changes.js +162 -0
  61. package/dist/harness/partial-changes.js.map +1 -0
  62. package/dist/harness/registry-reader.d.ts +11 -0
  63. package/dist/harness/registry-reader.d.ts.map +1 -0
  64. package/dist/harness/registry-reader.js +25 -0
  65. package/dist/harness/registry-reader.js.map +1 -0
  66. package/dist/harness/scheduler.d.ts +46 -19
  67. package/dist/harness/scheduler.d.ts.map +1 -1
  68. package/dist/harness/scheduler.js +973 -376
  69. package/dist/harness/scheduler.js.map +1 -1
  70. package/dist/harness/submissions.d.ts +17 -10
  71. package/dist/harness/submissions.d.ts.map +1 -1
  72. package/dist/harness/submissions.js +62 -25
  73. package/dist/harness/submissions.js.map +1 -1
  74. package/dist/harness/task-graph.d.ts +12 -9
  75. package/dist/harness/task-graph.d.ts.map +1 -1
  76. package/dist/harness/task-graph.js +38 -28
  77. package/dist/harness/task-graph.js.map +1 -1
  78. package/dist/harness/telemetry.d.ts +11 -11
  79. package/dist/harness/telemetry.d.ts.map +1 -1
  80. package/dist/harness/telemetry.js +7 -7
  81. package/dist/harness/telemetry.js.map +1 -1
  82. package/dist/harness/tool.d.ts +2 -0
  83. package/dist/harness/tool.d.ts.map +1 -1
  84. package/dist/harness/tool.js +171 -55
  85. package/dist/harness/tool.js.map +1 -1
  86. package/dist/harness/transcript.d.ts +72 -0
  87. package/dist/harness/transcript.d.ts.map +1 -0
  88. package/dist/harness/transcript.js +264 -0
  89. package/dist/harness/transcript.js.map +1 -0
  90. package/dist/harness/types.d.ts +218 -59
  91. package/dist/harness/types.d.ts.map +1 -1
  92. package/dist/harness/types.js.map +1 -1
  93. package/dist/harness/util.d.ts +3 -1
  94. package/dist/harness/util.d.ts.map +1 -1
  95. package/dist/harness/util.js +9 -0
  96. package/dist/harness/util.js.map +1 -1
  97. package/dist/harness/view.d.ts +43 -22
  98. package/dist/harness/view.d.ts.map +1 -1
  99. package/dist/harness/view.js +130 -71
  100. package/dist/harness/view.js.map +1 -1
  101. package/dist/index.d.ts +9 -7
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.js +4 -3
  104. package/dist/index.js.map +1 -1
  105. package/dist/search.d.ts +19 -3
  106. package/dist/search.d.ts.map +1 -1
  107. package/dist/search.js +107 -44
  108. package/dist/search.js.map +1 -1
  109. package/dist/session/cached-storage.d.ts +71 -0
  110. package/dist/session/cached-storage.d.ts.map +1 -0
  111. package/dist/session/cached-storage.js +269 -0
  112. package/dist/session/cached-storage.js.map +1 -0
  113. package/dist/session/conversation-tails.d.ts +33 -0
  114. package/dist/session/conversation-tails.d.ts.map +1 -0
  115. package/dist/session/conversation-tails.js +101 -0
  116. package/dist/session/conversation-tails.js.map +1 -0
  117. package/dist/session/keys.d.ts +68 -0
  118. package/dist/session/keys.d.ts.map +1 -0
  119. package/dist/session/keys.js +161 -0
  120. package/dist/session/keys.js.map +1 -0
  121. package/dist/session/session.d.ts +167 -26
  122. package/dist/session/session.d.ts.map +1 -1
  123. package/dist/session/session.js +1029 -171
  124. package/dist/session/session.js.map +1 -1
  125. package/dist/session/transaction.d.ts +81 -3
  126. package/dist/session/transaction.d.ts.map +1 -1
  127. package/dist/session/transaction.js +224 -37
  128. package/dist/session/transaction.js.map +1 -1
  129. package/dist/session/writer.d.ts +74 -0
  130. package/dist/session/writer.d.ts.map +1 -0
  131. package/dist/session/writer.js +294 -0
  132. package/dist/session/writer.js.map +1 -0
  133. package/dist/storage/indexeddb.d.ts +10 -2
  134. package/dist/storage/indexeddb.d.ts.map +1 -1
  135. package/dist/storage/indexeddb.js +91 -41
  136. package/dist/storage/indexeddb.js.map +1 -1
  137. package/dist/storage/jsonl/storage.d.ts +14 -2
  138. package/dist/storage/jsonl/storage.d.ts.map +1 -1
  139. package/dist/storage/jsonl/storage.js +88 -24
  140. package/dist/storage/jsonl/storage.js.map +1 -1
  141. package/dist/storage/memory.d.ts +7 -2
  142. package/dist/storage/memory.d.ts.map +1 -1
  143. package/dist/storage/memory.js +28 -2
  144. package/dist/storage/memory.js.map +1 -1
  145. package/dist/storage/sqlite/storage.d.ts +14 -2
  146. package/dist/storage/sqlite/storage.d.ts.map +1 -1
  147. package/dist/storage/sqlite/storage.js +110 -36
  148. package/dist/storage/sqlite/storage.js.map +1 -1
  149. package/dist/storage/store/commit.d.ts +33 -0
  150. package/dist/storage/store/commit.d.ts.map +1 -0
  151. package/dist/storage/store/commit.js +286 -0
  152. package/dist/storage/store/commit.js.map +1 -0
  153. package/dist/storage/store/documents.d.ts +43 -0
  154. package/dist/storage/store/documents.d.ts.map +1 -0
  155. package/dist/storage/store/documents.js +102 -0
  156. package/dist/storage/store/documents.js.map +1 -0
  157. package/dist/storage/store/index.d.ts +2 -0
  158. package/dist/storage/store/index.d.ts.map +1 -0
  159. package/dist/storage/store/index.js +2 -0
  160. package/dist/storage/store/index.js.map +1 -0
  161. package/dist/storage/store/queries.d.ts +49 -0
  162. package/dist/storage/store/queries.d.ts.map +1 -0
  163. package/dist/storage/store/queries.js +93 -0
  164. package/dist/storage/store/queries.js.map +1 -0
  165. package/dist/storage/store/storage.d.ts +59 -0
  166. package/dist/storage/store/storage.d.ts.map +1 -0
  167. package/dist/storage/store/storage.js +438 -0
  168. package/dist/storage/store/storage.js.map +1 -0
  169. package/dist/storage/store/tables.d.ts +54 -0
  170. package/dist/storage/store/tables.d.ts.map +1 -0
  171. package/dist/storage/store/tables.js +108 -0
  172. package/dist/storage/store/tables.js.map +1 -0
  173. package/dist/testing/commit-writes.d.ts +5 -0
  174. package/dist/testing/commit-writes.d.ts.map +1 -0
  175. package/dist/testing/commit-writes.js +12 -0
  176. package/dist/testing/commit-writes.js.map +1 -0
  177. package/dist/testing/env-conformance.js +7 -7
  178. package/dist/testing/env-conformance.js.map +1 -1
  179. package/dist/testing/index.d.ts +1 -0
  180. package/dist/testing/index.d.ts.map +1 -1
  181. package/dist/testing/index.js +1 -0
  182. package/dist/testing/index.js.map +1 -1
  183. package/dist/testing/storage-benchmark.d.ts.map +1 -1
  184. package/dist/testing/storage-benchmark.js +18 -17
  185. package/dist/testing/storage-benchmark.js.map +1 -1
  186. package/dist/testing/storage-conformance.d.ts.map +1 -1
  187. package/dist/testing/storage-conformance.js +354 -69
  188. package/dist/testing/storage-conformance.js.map +1 -1
  189. package/dist/tool-search/tool-search.d.ts +6 -12
  190. package/dist/tool-search/tool-search.d.ts.map +1 -1
  191. package/dist/tool-search/tool-search.js +7 -7
  192. package/dist/tool-search/tool-search.js.map +1 -1
  193. package/dist/tools/bash.d.ts +12 -12
  194. package/dist/tools/bash.d.ts.map +1 -1
  195. package/dist/tools/bash.js +16 -15
  196. package/dist/tools/bash.js.map +1 -1
  197. package/dist/tools/edit.d.ts +7 -7
  198. package/dist/tools/edit.d.ts.map +1 -1
  199. package/dist/tools/edit.js +9 -9
  200. package/dist/tools/edit.js.map +1 -1
  201. package/dist/tools/index.d.ts +32 -32
  202. package/dist/tools/read.d.ts +6 -6
  203. package/dist/tools/read.d.ts.map +1 -1
  204. package/dist/tools/read.js +19 -8
  205. package/dist/tools/read.js.map +1 -1
  206. package/dist/tools/write.d.ts +4 -4
  207. package/dist/tools/write.d.ts.map +1 -1
  208. package/dist/tools/write.js +5 -5
  209. package/dist/tools/write.js.map +1 -1
  210. package/dist/types.d.ts +223 -77
  211. package/dist/types.d.ts.map +1 -1
  212. package/dist/types.js.map +1 -1
  213. package/package.json +19 -12
  214. package/dist/harness/events.d.ts +0 -186
  215. package/dist/harness/events.d.ts.map +0 -1
  216. package/dist/harness/events.js +0 -373
  217. package/dist/harness/events.js.map +0 -1
  218. package/dist/session/observation.d.ts +0 -42
  219. package/dist/session/observation.d.ts.map +0 -1
  220. package/dist/session/observation.js +0 -281
  221. package/dist/session/observation.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/codemode/models.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGlD,mGAAmG;AACnG,MAAM,CAAC,MAAM,wBAAwB,GAAG,cAAc,CAAC;AACvD,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,wBAAwB,iBAAiB,CAAC;AAC1E,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,wBAAwB,uBAAuB,CAAC;AAEvF,mDAAmD;AACnD,MAAM,CAAC,MAAM,WAAW,GAAqC;IAC5D,iBAAiB,EAAE,aAAa;IAChC,uBAAuB,EAAE,oBAAoB;CAC7C,CAAC;AAEF,qEAAqE;AACrE,MAAM,CAAC,MAAM,eAAe,GAAG;IAC9B,wBAAwB;IACxB,2BAA2B;IAC3B,uBAAuB;CACd,CAAC;AAEX,4GAA4G;AAC5G,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAE5C,MAAM,WAAW,GAAwB,IAAI,GAAG,CAAY,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC;AAE7F,MAAM,CAAC,MAAM,kBAAkB,GAAG;IACjC,2CAA2C;IAC3C,yNAAyN;IACzN,0aAA0a;IAC1a,kPAAkP;IAClP,WAAW,0BAA0B,wD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CAAC,CAAC;AACjG,CAAC","sourcesContent":["/**\n * `models.*` for code mode scripts, copied from the coding agent's code mode: the model catalog, and classifier and\n * image model calls.\n *\n * The catalog functions are host globals, journaled like any global. `models.classify()` and `models.generateImages()`\n * are paid effects, so each runs as an internal tool (`callers: [\"tools\"]`, a reserved name, hidden from scripts'\n * tool listings): a nested durable call with its own task, live row, abort, usage accounting, and replay policy. The\n * code mode tool turns a script's call of the global into a call of that tool.\n */\nimport type { Context, JsonValue } from \"@earendil-works/chord\";\nimport type {\n\tAnyModel,\n\tClassifierContext,\n\tImagesContext,\n\tModels,\n\tModelType,\n\tModelTypeMap,\n\tUsage,\n} from \"@earendil-works/pi-ai\";\nimport { Type } from \"typebox\";\nimport { defineTool } from \"../harness/define.ts\";\nimport type { ToolRegistration } from \"../harness/types.ts\";\n\n/** Reserved names of code mode's internal tools; they are never listed to scripts or the model. */\nexport const CODEMODE_INTERNAL_PREFIX = \"pi.codemode.\";\nexport const CLASSIFY_TOOL = `${CODEMODE_INTERNAL_PREFIX}models.classify`;\nexport const GENERATE_IMAGES_TOOL = `${CODEMODE_INTERNAL_PREFIX}models.generateImages`;\n\n/** The global a script calls, by internal tool. */\nexport const MODEL_CALLS: Readonly<Record<string, string>> = {\n\t\"models.classify\": CLASSIFY_TOOL,\n\t\"models.generateImages\": GENERATE_IMAGES_TOOL,\n};\n\n/** The catalog functions, host globals of the `models` namespace. */\nexport const CATALOG_GLOBALS = [\n\t\"models.getModelsOfType\",\n\t\"models.getAvailableOfType\",\n\t\"models.getModelOfType\",\n] as const;\n\n/** `models.classify()` and `models.generateImages()` calls one script may have in flight; the rest wait. */\nexport const MAX_CONCURRENT_MODEL_CALLS = 4;\n\nconst MODEL_TYPES: ReadonlySet<string> = new Set<ModelType>([\"chat\", \"image\", \"classifier\"]);\n\nexport const MODELS_DESCRIPTION = [\n\t\"`models` (all functions return promises):\",\n\t'- `models.getModelsOfType(type, provider?)`, `models.getAvailableOfType(type, provider?)` (configured auth only), `models.getModelOfType(type, provider, id)`: the catalog; `type` is \"chat\", \"image\", or \"classifier\".',\n\t'- `models.classify(model, { state: { ... }, images?: [{ type: \"image\", data, mimeType }], questions: { <id>: { type: \"choice\", instructions, criteria: { <label>: <meaning> } } | { type: \"score\", instructions, criteria: [<lowest level>, ..., <highest level>] } | { type: \"bool\", instructions, criteria: { true: <meaning>, false: <meaning> } } } })` resolves to `{ answers: { <id>: ... }, stopReason, errorMessage?, usage? }`.',\n\t'- `models.generateImages(model, { input: [{ type: \"text\", text: <prompt> }, ...optional { type: \"image\", data, mimeType }] })` resolves to `{ output: [image blocks], stopReason, errorMessage?, usage? }`; show each image with `image(block)`.',\n\t`At most ${MAX_CONCURRENT_MODEL_CALLS} classify/generateImages calls run at once; more wait.`,\n].join(\"\\n\");\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** A script value in an error message: `undefined`, `a string`, `an array`, or its keys (`{ prompt }`). */\nfunction describeValue(value: unknown): string {\n\tif (value === undefined || value === null) return String(value);\n\tif (Array.isArray(value)) return value.length === 0 ? \"an empty array\" : \"an array\";\n\tif (typeof value === \"object\") {\n\t\tconst keys = Object.keys(value);\n\t\tif (keys.length === 0) return \"{}\";\n\t\treturn `{ ${keys.slice(0, 6).join(\", \")}${keys.length > 6 ? \", ...\" : \"\"} }`;\n\t}\n\treturn typeof value === \"string\" ? \"a string\" : `a ${typeof value}`;\n}\n\n/** `an image`, `a classifier`. */\nfunction withArticle(word: string): string {\n\treturn `${/^[aeiou]/.test(word) ? \"an\" : \"a\"} ${word}`;\n}\n\nfunction toModelType(value: unknown): ModelType {\n\tif (typeof value === \"string\" && MODEL_TYPES.has(value)) return value as ModelType;\n\tthrow new Error(`Unknown model type ${JSON.stringify(value)}. Use \"chat\", \"image\", or \"classifier\".`);\n}\n\nfunction toProvider(value: unknown): string | undefined {\n\tif (value === undefined || value === null) return undefined;\n\tif (typeof value !== \"string\") throw new Error(\"provider must be a string\");\n\treturn value;\n}\n\n/** Catalog entry for scripts. `headers` is dropped because configured headers can carry credentials. */\nfunction toModelInfo(model: AnyModel): JsonValue {\n\tconst info: Record<string, unknown> = { ...model };\n\tdelete info.headers;\n\treturn JSON.parse(JSON.stringify(info)) as JsonValue;\n}\n\n/** The catalog functions: what a script's call of `name` with `args` (the argument list) resolves to. */\nexport async function catalogCall(\n\tname: string,\n\targs: unknown,\n\tmodels: Models,\n\tcontext: Context,\n): Promise<JsonValue | undefined> {\n\tconst list = Array.isArray(args) ? args : [];\n\tconst [type, provider, id] = list;\n\tif (name === \"models.getModelsOfType\")\n\t\treturn models.getModelsOfType(toModelType(type), toProvider(provider)).map(toModelInfo);\n\tif (name === \"models.getAvailableOfType\") {\n\t\tconst available = await models.getAvailableOfType(toModelType(type), toProvider(provider), {\n\t\t\t...(context.abortSignal === undefined ? {} : { signal: context.abortSignal }),\n\t\t});\n\t\treturn available.map(toModelInfo);\n\t}\n\tif (typeof provider !== \"string\" || typeof id !== \"string\") {\n\t\tthrow new Error(\n\t\t\t`models.getModelOfType(type, provider, id) expects three strings, got (${list.map(describeValue).join(\", \")}). The provider and the id are separate arguments, for example models.getModelOfType(\"classifier\", \"typesafe\", \"jev-latest\").`,\n\t\t);\n\t}\n\tconst model = models.getModelOfType(toModelType(type), provider, id);\n\treturn model === undefined ? undefined : toModelInfo(model);\n}\n\nconst CLASSIFIER_CONTEXT_SHAPE =\n\t'{ state: { ... }, images?: [{ type: \"image\", data: <base64>, mimeType }], questions: { <id>: { type: \"choice\", instructions, criteria: { <label>: <meaning> } } | { type: \"score\", instructions, criteria: [<lowest level>, ..., <highest level>] } | { type: \"bool\", instructions, criteria: { true: <meaning>, false: <meaning> } } } }';\n\n/** Check a script's classifier context, so mistakes fail with the expected shape instead of a provider error. */\nfunction checkClassifierContext(context: unknown): ClassifierContext {\n\tconst fail = (problem: string) =>\n\t\tnew Error(`models.classify() ${problem}. Expected context: ${CLASSIFIER_CONTEXT_SHAPE}.`);\n\tif (!isRecord(context)) throw fail(`expects a context object as its second argument, got ${describeValue(context)}`);\n\tif (!isRecord(context.state)) throw fail(`context.state must be an object, got ${describeValue(context.state)}`);\n\tconst { images } = context;\n\tif (images !== undefined) {\n\t\tif (!Array.isArray(images)) throw fail(`context.images must be an array, got ${describeValue(images)}`);\n\t\timages.forEach((image: unknown, index) => {\n\t\t\tif (\n\t\t\t\t!isRecord(image) ||\n\t\t\t\timage.type !== \"image\" ||\n\t\t\t\ttypeof image.data !== \"string\" ||\n\t\t\t\ttypeof image.mimeType !== \"string\"\n\t\t\t) {\n\t\t\t\tthrow fail(`context.images[${index}] must be an image block, got ${describeValue(image)}`);\n\t\t\t}\n\t\t});\n\t}\n\tconst { questions } = context;\n\tif (!isRecord(questions) || Object.keys(questions).length === 0) {\n\t\tthrow fail(`context.questions must map question IDs to questions, got ${describeValue(questions)}`);\n\t}\n\tconst isStrings = (values: unknown[]) => values.length > 0 && values.every((value) => typeof value === \"string\");\n\tfor (const [id, question] of Object.entries(questions)) {\n\t\tconst at = `context.questions.${id}`;\n\t\tif (!isRecord(question)) throw fail(`${at} must be a question object, got ${describeValue(question)}`);\n\t\tif (typeof question.instructions !== \"string\") throw fail(`${at}.instructions must be a string`);\n\t\tconst { criteria } = question;\n\t\tif (question.type === \"choice\") {\n\t\t\tif (!isRecord(criteria) || !isStrings(Object.values(criteria))) {\n\t\t\t\tthrow fail(`${at} is a \"choice\" question, so criteria must map each label to its meaning`);\n\t\t\t}\n\t\t} else if (question.type === \"score\") {\n\t\t\tif (!Array.isArray(criteria) || !isStrings(criteria)) {\n\t\t\t\tthrow fail(`${at} is a \"score\" question, so criteria must list the levels as strings, lowest first`);\n\t\t\t}\n\t\t} else if (question.type === \"bool\") {\n\t\t\tif (!isRecord(criteria) || typeof criteria.true !== \"string\" || typeof criteria.false !== \"string\") {\n\t\t\t\tthrow fail(`${at} is a \"bool\" question, so criteria must be { true: string, false: string }`);\n\t\t\t}\n\t\t} else {\n\t\t\tthrow fail(`${at}.type must be \"choice\", \"score\", or \"bool\", got ${JSON.stringify(question.type)}`);\n\t\t}\n\t}\n\treturn context as unknown as ClassifierContext;\n}\n\n/** Check a script's image context, so mistakes such as `{ prompt }` fail with the expected shape. */\nfunction checkImagesContext(context: unknown): ImagesContext {\n\tconst fail = (problem: string) =>\n\t\tnew Error(\n\t\t\t`models.generateImages() ${problem}. Expected context: { input: [{ type: \"text\", text: <prompt> }, ...optional { type: \"image\", data: <base64>, mimeType } references] }.`,\n\t\t);\n\tif (!isRecord(context)) throw fail(`expects a context object as its second argument, got ${describeValue(context)}`);\n\tconst { input } = context;\n\tif (!Array.isArray(input) || input.length === 0) {\n\t\tthrow fail(`context.input must be a non-empty array of blocks, got ${describeValue(input)}`);\n\t}\n\tinput.forEach((block: unknown, index) => {\n\t\tif (isRecord(block) && block.type === \"text\" && typeof block.text === \"string\") return;\n\t\tif (\n\t\t\tisRecord(block) &&\n\t\t\tblock.type === \"image\" &&\n\t\t\ttypeof block.data === \"string\" &&\n\t\t\ttypeof block.mimeType === \"string\"\n\t\t)\n\t\t\treturn;\n\t\tthrow fail(`context.input[${index}] must be a text or image block, got ${describeValue(block)}`);\n\t});\n\treturn context as unknown as ImagesContext;\n}\n\n/**\n * Resolve the script's model by provider and id only, so a script-supplied baseUrl or headers never receive the\n * credentials, with errors that say what to do.\n */\nfunction resolveModel<TType extends \"classifier\" | \"image\">(\n\tname: string,\n\ttype: TType,\n\tmodel: unknown,\n\tmodels: Models,\n): ModelTypeMap[TType] {\n\tconst listHint = `List the ${type} models you can use with models.getAvailableOfType(\"${type}\").`;\n\tif (!isRecord(model) || typeof model.provider !== \"string\" || typeof model.id !== \"string\") {\n\t\tconst undefinedHint =\n\t\t\tmodel === undefined || model === null\n\t\t\t\t? \" models.getModelOfType() returns undefined for an unknown provider or id.\"\n\t\t\t\t: \"\";\n\t\tthrow new Error(\n\t\t\t`${name}() expects ${withArticle(type)} model as its first argument, got ${describeValue(model)}.${undefinedHint} ${listHint}`,\n\t\t);\n\t}\n\tconst { provider, id } = model;\n\tconst resolved = models.getModelOfType(type, provider, id);\n\tif (resolved !== undefined) return resolved;\n\tconst actualType = [...MODEL_TYPES].find(\n\t\t(other) => other !== type && models.getModelOfType(other as ModelType, provider, id) !== undefined,\n\t);\n\tthrow new Error(\n\t\tactualType\n\t\t\t? `\"${provider}/${id}\" is ${withArticle(actualType)} model, not ${withArticle(type)} model. ${listHint}`\n\t\t\t: `Unknown ${type} model \"${provider}/${id}\". ${listHint}`,\n\t);\n}\n\nconst ModelCallParameters = Type.Object({ model: Type.Unknown(), context: Type.Unknown() });\n\n/** The result of a model call as the tool returns it: the whole result for the script, usage counted by the Harness. */\nfunction modelResult(\n\tlabel: string,\n\tresult: { stopReason: string; errorMessage?: string; usage?: Usage },\n\tvalue: unknown,\n) {\n\tconst ok = result.stopReason === \"stop\";\n\treturn {\n\t\toutput: [\n\t\t\t{\n\t\t\t\ttype: \"text\" as const,\n\t\t\t\ttext: ok ? `${label} done` : `${label} ${result.stopReason}: ${result.errorMessage ?? \"\"}`,\n\t\t\t},\n\t\t],\n\t\tstructuredOutput: JSON.parse(JSON.stringify(value)) as JsonValue,\n\t\t...(ok ? {} : { isError: true }),\n\t\t...(result.usage === undefined ? {} : { usage: result.usage }),\n\t};\n}\n\n/** The internal tools behind `models.classify()` and `models.generateImages()`. */\nexport function createModelTools(): ToolRegistration[] {\n\tconst classify = defineTool({\n\t\tname: CLASSIFY_TOOL,\n\t\tdescription: \"models.classify() of code mode scripts.\",\n\t\tparameters: ModelCallParameters,\n\t\tstructuredOutputSchema: Type.Unknown(),\n\t\tcallers: [\"tools\"],\n\t\texecute: async (args, api, context) => {\n\t\t\tconst model = resolveModel(\"models.classify\", \"classifier\", args.model, api.models);\n\t\t\tconst checked = checkClassifierContext(args.context);\n\t\t\tconst result = await api.models.classify(model, checked, {\n\t\t\t\ttelemetry: context.telemetry,\n\t\t\t\t...(context.abortSignal === undefined ? {} : { signal: context.abortSignal }),\n\t\t\t});\n\t\t\treturn modelResult(`classify ${model.provider}/${model.id}`, result, result);\n\t\t},\n\t});\n\tconst generateImages = defineTool({\n\t\tname: GENERATE_IMAGES_TOOL,\n\t\tdescription: \"models.generateImages() of code mode scripts.\",\n\t\tparameters: ModelCallParameters,\n\t\tstructuredOutputSchema: Type.Unknown(),\n\t\tcallers: [\"tools\"],\n\t\texecute: async (args, api, context) => {\n\t\t\tconst model = resolveModel(\"models.generateImages\", \"image\", args.model, api.models);\n\t\t\tconst checked = checkImagesContext(args.context);\n\t\t\tconst result = await api.models.generateImages(model, checked, {\n\t\t\t\ttelemetry: context.telemetry,\n\t\t\t\t...(context.abortSignal === undefined ? {} : { signal: context.abortSignal }),\n\t\t\t});\n\t\t\treturn modelResult(`generateImages ${model.provider}/${model.id}`, result, result);\n\t\t},\n\t});\n\treturn [classify as unknown as ToolRegistration, generateImages as unknown as ToolRegistration];\n}\n"]}
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/codemode/models.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGlD,mGAAmG;AACnG,MAAM,CAAC,MAAM,wBAAwB,GAAG,cAAc,CAAC;AACvD,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,wBAAwB,iBAAiB,CAAC;AAC1E,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,wBAAwB,uBAAuB,CAAC;AAEvF,mDAAmD;AACnD,MAAM,CAAC,MAAM,WAAW,GAAqC;IAC5D,iBAAiB,EAAE,aAAa;IAChC,uBAAuB,EAAE,oBAAoB;CAC7C,CAAC;AAEF,qEAAqE;AACrE,MAAM,CAAC,MAAM,eAAe,GAAG;IAC9B,wBAAwB;IACxB,2BAA2B;IAC3B,uBAAuB;CACd,CAAC;AAEX,4GAA4G;AAC5G,MAAM,CAAC,MAAM,0BAA0B,GAAG,C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CAAC;aAC7E,CAAC,CAAC;YACH,OAAO,WAAW,CAAC,kBAAkB,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QACpF,CAAC;KACD,CAAC,CAAC;IACH,OAAO,CAAC,QAAuC,EAAE,cAA6C,CAAC,CAAC;AACjG,CAAC","sourcesContent":["/**\n * `models.*` for code mode scripts, copied from the coding agent's code mode: the model catalog, and classifier and\n * image model calls.\n *\n * The catalog functions are host globals, journaled like any global. `models.classify()` and `models.generateImages()`\n * are paid effects, so each runs as an internal tool (`callers: [\"tools\"]`, a reserved name, hidden from scripts'\n * tool listings): a nested durable call with its own task, live row, abort, usage accounting, and replay policy. The\n * code mode tool turns a script's call of the global into a call of that tool.\n */\nimport type { Context, JsonValue } from \"@earendil-works/chord\";\nimport type {\n\tAnyModel,\n\tClassifierContext,\n\tImagesContext,\n\tModels,\n\tModelType,\n\tModelTypeMap,\n\tUsage,\n} from \"@earendil-works/pi-ai\";\nimport { obj, unknown } from \"@earendil-works/pi-schema\";\nimport { defineTool } from \"../harness/define.ts\";\nimport type { ToolRegistration } from \"../harness/types.ts\";\n\n/** Reserved names of code mode's internal tools; they are never listed to scripts or the model. */\nexport const CODEMODE_INTERNAL_PREFIX = \"pi.codemode.\";\nexport const CLASSIFY_TOOL = `${CODEMODE_INTERNAL_PREFIX}models.classify`;\nexport const GENERATE_IMAGES_TOOL = `${CODEMODE_INTERNAL_PREFIX}models.generateImages`;\n\n/** The global a script calls, by internal tool. */\nexport const MODEL_CALLS: Readonly<Record<string, string>> = {\n\t\"models.classify\": CLASSIFY_TOOL,\n\t\"models.generateImages\": GENERATE_IMAGES_TOOL,\n};\n\n/** The catalog functions, host globals of the `models` namespace. */\nexport const CATALOG_GLOBALS = [\n\t\"models.getModelsOfType\",\n\t\"models.getAvailableOfType\",\n\t\"models.getModelOfType\",\n] as const;\n\n/** `models.classify()` and `models.generateImages()` calls one script may have in flight; the rest wait. */\nexport const MAX_CONCURRENT_MODEL_CALLS = 4;\n\nconst MODEL_TYPES: ReadonlySet<string> = new Set<ModelType>([\"chat\", \"image\", \"classifier\"]);\n\nexport const MODELS_DESCRIPTION = [\n\t\"`models` (all functions return promises):\",\n\t'- `models.getModelsOfType(type, provider?)`, `models.getAvailableOfType(type, provider?)` (configured auth only), `models.getModelOfType(type, provider, id)`: the catalog; `type` is \"chat\", \"image\", or \"classifier\".',\n\t'- `models.classify(model, { state: { ... }, images?: [{ type: \"image\", data, mimeType }], questions: { <id>: { type: \"choice\", instructions, criteria: { <label>: <meaning> } } | { type: \"score\", instructions, criteria: [<lowest level>, ..., <highest level>] } | { type: \"bool\", instructions, criteria: { true: <meaning>, false: <meaning> } } } })` resolves to `{ answers: { <id>: ... }, stopReason, errorMessage?, usage? }`.',\n\t'- `models.generateImages(model, { input: [{ type: \"text\", text: <prompt> }, ...optional { type: \"image\", data, mimeType }] })` resolves to `{ output: [image blocks], stopReason, errorMessage?, usage? }`; show each image with `image(block)`.',\n\t`At most ${MAX_CONCURRENT_MODEL_CALLS} classify/generateImages calls run at once; more wait.`,\n].join(\"\\n\");\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** A script value in an error message: `undefined`, `a string`, `an array`, or its keys (`{ prompt }`). */\nfunction describeValue(value: unknown): string {\n\tif (value === undefined || value === null) return String(value);\n\tif (Array.isArray(value)) return value.length === 0 ? \"an empty array\" : \"an array\";\n\tif (typeof value === \"object\") {\n\t\tconst keys = Object.keys(value);\n\t\tif (keys.length === 0) return \"{}\";\n\t\treturn `{ ${keys.slice(0, 6).join(\", \")}${keys.length > 6 ? \", ...\" : \"\"} }`;\n\t}\n\treturn typeof value === \"string\" ? \"a string\" : `a ${typeof value}`;\n}\n\n/** `an image`, `a classifier`. */\nfunction withArticle(word: string): string {\n\treturn `${/^[aeiou]/.test(word) ? \"an\" : \"a\"} ${word}`;\n}\n\nfunction toModelType(value: unknown): ModelType {\n\tif (typeof value === \"string\" && MODEL_TYPES.has(value)) return value as ModelType;\n\tthrow new Error(`Unknown model type ${JSON.stringify(value)}. Use \"chat\", \"image\", or \"classifier\".`);\n}\n\nfunction toProvider(value: unknown): string | undefined {\n\tif (value === undefined || value === null) return undefined;\n\tif (typeof value !== \"string\") throw new Error(\"provider must be a string\");\n\treturn value;\n}\n\n/** Catalog entry for scripts. `headers` is dropped because configured headers can carry credentials. */\nfunction toModelInfo(model: AnyModel): JsonValue {\n\tconst info: Record<string, unknown> = { ...model };\n\tdelete info.headers;\n\treturn JSON.parse(JSON.stringify(info)) as JsonValue;\n}\n\n/** The catalog functions: what a script's call of `name` with `args` (the argument list) resolves to. */\nexport async function catalogCall(\n\tname: string,\n\targs: unknown,\n\tmodels: Models,\n\tcontext: Context,\n): Promise<JsonValue | undefined> {\n\tconst list = Array.isArray(args) ? args : [];\n\tconst [type, provider, id] = list;\n\tif (name === \"models.getModelsOfType\")\n\t\treturn models.getModelsOfType(toModelType(type), toProvider(provider)).map(toModelInfo);\n\tif (name === \"models.getAvailableOfType\") {\n\t\tconst available = await models.getAvailableOfType(toModelType(type), toProvider(provider), {\n\t\t\t...(context.abortSignal === undefined ? {} : { signal: context.abortSignal }),\n\t\t});\n\t\treturn available.map(toModelInfo);\n\t}\n\tif (typeof provider !== \"string\" || typeof id !== \"string\") {\n\t\tthrow new Error(\n\t\t\t`models.getModelOfType(type, provider, id) expects three strings, got (${list.map(describeValue).join(\", \")}). The provider and the id are separate arguments, for example models.getModelOfType(\"classifier\", \"typesafe\", \"jev-latest\").`,\n\t\t);\n\t}\n\tconst model = models.getModelOfType(toModelType(type), provider, id);\n\treturn model === undefined ? undefined : toModelInfo(model);\n}\n\nconst CLASSIFIER_CONTEXT_SHAPE =\n\t'{ state: { ... }, images?: [{ type: \"image\", data: <base64>, mimeType }], questions: { <id>: { type: \"choice\", instructions, criteria: { <label>: <meaning> } } | { type: \"score\", instructions, criteria: [<lowest level>, ..., <highest level>] } | { type: \"bool\", instructions, criteria: { true: <meaning>, false: <meaning> } } } }';\n\n/** Check a script's classifier context, so mistakes fail with the expected shape instead of a provider error. */\nfunction checkClassifierContext(context: unknown): ClassifierContext {\n\tconst fail = (problem: string) =>\n\t\tnew Error(`models.classify() ${problem}. Expected context: ${CLASSIFIER_CONTEXT_SHAPE}.`);\n\tif (!isRecord(context)) throw fail(`expects a context object as its second argument, got ${describeValue(context)}`);\n\tif (!isRecord(context.state)) throw fail(`context.state must be an object, got ${describeValue(context.state)}`);\n\tconst { images } = context;\n\tif (images !== undefined) {\n\t\tif (!Array.isArray(images)) throw fail(`context.images must be an array, got ${describeValue(images)}`);\n\t\timages.forEach((image: unknown, index) => {\n\t\t\tif (\n\t\t\t\t!isRecord(image) ||\n\t\t\t\timage.type !== \"image\" ||\n\t\t\t\ttypeof image.data !== \"string\" ||\n\t\t\t\ttypeof image.mimeType !== \"string\"\n\t\t\t) {\n\t\t\t\tthrow fail(`context.images[${index}] must be an image block, got ${describeValue(image)}`);\n\t\t\t}\n\t\t});\n\t}\n\tconst { questions } = context;\n\tif (!isRecord(questions) || Object.keys(questions).length === 0) {\n\t\tthrow fail(`context.questions must map question IDs to questions, got ${describeValue(questions)}`);\n\t}\n\tconst isStrings = (values: unknown[]) => values.length > 0 && values.every((value) => typeof value === \"string\");\n\tfor (const [id, question] of Object.entries(questions)) {\n\t\tconst at = `context.questions.${id}`;\n\t\tif (!isRecord(question)) throw fail(`${at} must be a question object, got ${describeValue(question)}`);\n\t\tif (typeof question.instructions !== \"string\") throw fail(`${at}.instructions must be a string`);\n\t\tconst { criteria } = question;\n\t\tif (question.type === \"choice\") {\n\t\t\tif (!isRecord(criteria) || !isStrings(Object.values(criteria))) {\n\t\t\t\tthrow fail(`${at} is a \"choice\" question, so criteria must map each label to its meaning`);\n\t\t\t}\n\t\t} else if (question.type === \"score\") {\n\t\t\tif (!Array.isArray(criteria) || !isStrings(criteria)) {\n\t\t\t\tthrow fail(`${at} is a \"score\" question, so criteria must list the levels as strings, lowest first`);\n\t\t\t}\n\t\t} else if (question.type === \"bool\") {\n\t\t\tif (!isRecord(criteria) || typeof criteria.true !== \"string\" || typeof criteria.false !== \"string\") {\n\t\t\t\tthrow fail(`${at} is a \"bool\" question, so criteria must be { true: string, false: string }`);\n\t\t\t}\n\t\t} else {\n\t\t\tthrow fail(`${at}.type must be \"choice\", \"score\", or \"bool\", got ${JSON.stringify(question.type)}`);\n\t\t}\n\t}\n\treturn context as unknown as ClassifierContext;\n}\n\n/** Check a script's image context, so mistakes such as `{ prompt }` fail with the expected shape. */\nfunction checkImagesContext(context: unknown): ImagesContext {\n\tconst fail = (problem: string) =>\n\t\tnew Error(\n\t\t\t`models.generateImages() ${problem}. Expected context: { input: [{ type: \"text\", text: <prompt> }, ...optional { type: \"image\", data: <base64>, mimeType } references] }.`,\n\t\t);\n\tif (!isRecord(context)) throw fail(`expects a context object as its second argument, got ${describeValue(context)}`);\n\tconst { input } = context;\n\tif (!Array.isArray(input) || input.length === 0) {\n\t\tthrow fail(`context.input must be a non-empty array of blocks, got ${describeValue(input)}`);\n\t}\n\tinput.forEach((block: unknown, index) => {\n\t\tif (isRecord(block) && block.type === \"text\" && typeof block.text === \"string\") return;\n\t\tif (\n\t\t\tisRecord(block) &&\n\t\t\tblock.type === \"image\" &&\n\t\t\ttypeof block.data === \"string\" &&\n\t\t\ttypeof block.mimeType === \"string\"\n\t\t)\n\t\t\treturn;\n\t\tthrow fail(`context.input[${index}] must be a text or image block, got ${describeValue(block)}`);\n\t});\n\treturn context as unknown as ImagesContext;\n}\n\n/**\n * Resolve the script's model by provider and id only, so a script-supplied baseUrl or headers never receive the\n * credentials, with errors that say what to do.\n */\nfunction resolveModel<TType extends \"classifier\" | \"image\">(\n\tname: string,\n\ttype: TType,\n\tmodel: unknown,\n\tmodels: Models,\n): ModelTypeMap[TType] {\n\tconst listHint = `List the ${type} models you can use with models.getAvailableOfType(\"${type}\").`;\n\tif (!isRecord(model) || typeof model.provider !== \"string\" || typeof model.id !== \"string\") {\n\t\tconst undefinedHint =\n\t\t\tmodel === undefined || model === null\n\t\t\t\t? \" models.getModelOfType() returns undefined for an unknown provider or id.\"\n\t\t\t\t: \"\";\n\t\tthrow new Error(\n\t\t\t`${name}() expects ${withArticle(type)} model as its first argument, got ${describeValue(model)}.${undefinedHint} ${listHint}`,\n\t\t);\n\t}\n\tconst { provider, id } = model;\n\tconst resolved = models.getModelOfType(type, provider, id);\n\tif (resolved !== undefined) return resolved;\n\tconst actualType = [...MODEL_TYPES].find(\n\t\t(other) => other !== type && models.getModelOfType(other as ModelType, provider, id) !== undefined,\n\t);\n\tthrow new Error(\n\t\tactualType\n\t\t\t? `\"${provider}/${id}\" is ${withArticle(actualType)} model, not ${withArticle(type)} model. ${listHint}`\n\t\t\t: `Unknown ${type} model \"${provider}/${id}\". ${listHint}`,\n\t);\n}\n\nconst ModelCallParameters = obj({ model: unknown(), context: unknown() }, { open: true });\n\n/** The result of a model call as the tool returns it: the whole result for the script, usage counted by the Harness. */\nfunction modelResult(\n\tlabel: string,\n\tresult: { stopReason: string; errorMessage?: string; usage?: Usage },\n\tvalue: unknown,\n) {\n\tconst ok = result.stopReason === \"stop\";\n\treturn {\n\t\toutput: [\n\t\t\t{\n\t\t\t\ttype: \"text\" as const,\n\t\t\t\ttext: ok ? `${label} done` : `${label} ${result.stopReason}: ${result.errorMessage ?? \"\"}`,\n\t\t\t},\n\t\t],\n\t\tstructuredOutput: JSON.parse(JSON.stringify(value)) as JsonValue,\n\t\t...(ok ? {} : { isError: true }),\n\t\t...(result.usage === undefined ? {} : { usage: result.usage }),\n\t};\n}\n\n/** The internal tools behind `models.classify()` and `models.generateImages()`. */\nexport function createModelTools(): ToolRegistration[] {\n\tconst classify = defineTool({\n\t\tname: CLASSIFY_TOOL,\n\t\tdescription: \"models.classify() of code mode scripts.\",\n\t\tparameters: ModelCallParameters,\n\t\tstructuredOutputSchema: unknown(),\n\t\tcallers: [\"tools\"],\n\t\texecute: async (args, api, context) => {\n\t\t\tconst model = resolveModel(\"models.classify\", \"classifier\", args.model, api.models);\n\t\t\tconst checked = checkClassifierContext(args.context);\n\t\t\tconst result = await api.models.classify(model, checked, {\n\t\t\t\ttelemetry: context.telemetry,\n\t\t\t\t...(context.abortSignal === undefined ? {} : { signal: context.abortSignal }),\n\t\t\t});\n\t\t\treturn modelResult(`classify ${model.provider}/${model.id}`, result, result);\n\t\t},\n\t});\n\tconst generateImages = defineTool({\n\t\tname: GENERATE_IMAGES_TOOL,\n\t\tdescription: \"models.generateImages() of code mode scripts.\",\n\t\tparameters: ModelCallParameters,\n\t\tstructuredOutputSchema: unknown(),\n\t\tcallers: [\"tools\"],\n\t\texecute: async (args, api, context) => {\n\t\t\tconst model = resolveModel(\"models.generateImages\", \"image\", args.model, api.models);\n\t\t\tconst checked = checkImagesContext(args.context);\n\t\t\tconst result = await api.models.generateImages(model, checked, {\n\t\t\t\ttelemetry: context.telemetry,\n\t\t\t\t...(context.abortSignal === undefined ? {} : { signal: context.abortSignal }),\n\t\t\t});\n\t\t\treturn modelResult(`generateImages ${model.provider}/${model.id}`, result, result);\n\t\t},\n\t});\n\treturn [classify as unknown as ToolRegistration, generateImages as unknown as ToolRegistration];\n}\n"]}
@@ -70,19 +70,21 @@ export interface WatchTarget {
70
70
  };
71
71
  }
72
72
  /**
73
- * What changed:
73
+ * What changed, tagged by `kind`:
74
74
  * - `paths`: something at or below each path may have changed (a directory path covers its whole subtree). Calls may be
75
75
  * spurious; a change is never missed while the watcher is healthy.
76
76
  * - `overflow`: coverage was uncertain for a while (lost events, reconnect); rescan everything that is watched.
77
- * - `error`: the watcher stopped, for example because the watched tree grew past the environment's limit; no calls
78
- * follow.
77
+ * - `failed`: the watcher stopped with `error`, for example because the watched tree grew past the environment's limit;
78
+ * no calls follow.
79
79
  */
80
- export type WatchChange = {
81
- paths: string[];
80
+ export type FileChange = {
81
+ readonly kind: "paths";
82
+ readonly paths: string[];
82
83
  } | {
83
- overflow: true;
84
+ readonly kind: "overflow";
84
85
  } | {
85
- error: FileError;
86
+ readonly kind: "failed";
87
+ readonly error: FileError;
86
88
  };
87
89
  export interface FileWatcher {
88
90
  /**
@@ -92,7 +94,7 @@ export interface FileWatcher {
92
94
  */
93
95
  readonly mode: "native" | "polling";
94
96
  /** Stop watching; no `onChange` call starts after this resolves. Idempotent. */
95
- close(context: Context): Promise<void>;
97
+ stop(context: Context): Promise<void>;
96
98
  }
97
99
  /** Where lines of a file are, as `BinaryReader.scanLines` found them. */
98
100
  export interface LineScan {
@@ -204,9 +206,9 @@ export interface FileSystem {
204
206
  /**
205
207
  * Report changes to files and directories, for hosts that load resources from the environment. When the returned
206
208
  * watcher exists, coverage is established: a host that watches before it loads cannot miss a change made during the
207
- * load. See `WatchChange` for what is reported and `FileWatcher.mode` for how reliably.
209
+ * load. See `FileChange` for what is reported and `FileWatcher.mode` for how reliably.
208
210
  */
209
- watch(targets: readonly WatchTarget[], onChange: (change: WatchChange) => void, context: Context): Promise<Result<FileWatcher, FileError>>;
211
+ watch(targets: readonly WatchTarget[], onChange: (change: FileChange) => void, context: Context): Promise<Result<FileWatcher, FileError>>;
210
212
  canonicalPath(path: string, context: Context): Promise<Result<string, FileError>>;
211
213
  exists(path: string, context: Context): Promise<Result<boolean, FileError>>;
212
214
  createDir(path: string, options: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,wFAAwF;AACxF,MAAM,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhG,wBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,E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IACvD,IAAI,CAAC;QACJ,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACjC,CAAC;AACF,CAAC;AAcD,MAAM,OAAO,SAAU,SAAQ,KAAK;IAC5B,IAAI,CAAgB;IACpB,IAAI,CAAU;IAErB,YAAY,IAAmB,EAAE,OAAe,EAAE,IAAa,EAAE,KAAa;QAC7E,KAAK,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD;AAUD,MAAM,OAAO,cAAe,SAAQ,KAAK;IACjC,IAAI,CAAqB;IAChC,2GAA2G;IACpG,SAAS,CAAU;IAE1B,YAAY,IAAwB,EAAE,OAAe,EAAE,KAAa;QACnE,KAAK,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD;AA6SD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["import type { Context } from \"@earendil-works/chord\";\n\n/** Result of a fallible operation. Expected failures are returned instead of thrown. */\nexport type Result<TValue, TError> = { ok: true; value: TValue } | { ok: false; error: TError };\n\nexport function ok<TValue, TError>(value: TValue): Result<TValue, TError> {\n\treturn { ok: true, value };\n}\n\nexport function err<TValue, TError>(error: TError): Result<TValue, TError> {\n\treturn { ok: false, error };\n}\n\nexport function getOrThrow<TValue, TError>(result: Result<TValue, TError>): TValue {\n\tif (!result.ok) throw result.error;\n\treturn result.value;\n}\n\nexport function getOrUndefined<TValue extends object, TError>(result: Result<TValue, TError>): TValue | undefined {\n\treturn result.ok ? result.value : undefined;\n}\n\nexport function toError(error: unknown): Error {\n\tif (error instanceof Error) return error;\n\tif (typeof error === \"string\") return new Error(error);\n\ttry {\n\t\treturn new Error(JSON.stringify(error));\n\t} catch {\n\t\treturn new Error(String(error));\n\t}\n}\n\nexport type FileKind = \"file\" | \"directory\" | \"symlink\";\n\nexport type FileErrorCode =\n\t| \"aborted\"\n\t| \"not_found\"\n\t| \"permission_denied\"\n\t| \"not_directory\"\n\t| \"is_directory\"\n\t| \"invalid\"\n\t| \"not_supported\"\n\t| \"unknown\";\n\nexport class FileError extends Error {\n\tpublic code: FileErrorCode;\n\tpublic path?: string;\n\n\tconstructor(code: FileErrorCode, message: string, path?: string, cause?: Error) {\n\t\tsuper(message, cause === undefined ? undefined : { cause });\n\t\tthis.name = \"FileError\";\n\t\tthis.code = code;\n\t\tthis.path = path;\n\t}\n}\n\nexport type ExecutionErrorCode =\n\t| \"aborted\"\n\t| \"timeout\"\n\t| \"shell_unavailable\"\n\t| \"spawn_error\"\n\t| \"callback_error\"\n\t| \"unknown\";\n\nexport class ExecutionError extends Error {\n\tpublic code: ExecutionErrorCode;\n\t/** Spill file of a command that timed out or was aborted after its output crossed the spill thresholds. */\n\tpublic spillPath?: string;\n\n\tconstructor(code: ExecutionErrorCode, message: string, cause?: Error) {\n\t\tsuper(message, cause === undefined ? undefined : { cause });\n\t\tthis.name = \"ExecutionError\";\n\t\tthis.code = code;\n\t}\n}\n\nexport interface FileInfo {\n\tname: string;\n\tpath: string;\n\tkind: FileKind;\n\tsize: number;\n\tmtimeMs: number;\n}\n\nexport interface TextLine {\n\ttext: string;\n\tterminated: boolean;\n}\n\nexport interface TextLineReader {\n\treadLine(context: Context): Promise<Result<TextLine | undefined, FileError>>;\n\tclose(context: Context): Promise<void>;\n}\n\n/** Positional reads from one opened regular file; all calls see the same file even if its path is renamed. */\nexport interface BinaryReader {\n\t/** Metadata of the opened file, not of whatever its path names now. */\n\tinfo(context: Context): Promise<Result<FileInfo, FileError>>;\n\t/** Up to `length` bytes at `offset`; fewer only at end of file. */\n\tread(offset: number, length: number, context: Context): Promise<Result<Uint8Array, FileError>>;\n\t/**\n\t * One pass over the file that locates lines `[startLine, endLine)` (`endLine` absent: to the end), 0-based, where line\n\t * `k` starts after the `k`-th newline byte. Decoded sizes are those of the text `new TextDecoder().decode(file)` would\n\t * produce for that range, so a byte-order mark at the start of the file is not counted.\n\t */\n\tscanLines(options: { startLine: number; endLine?: number }, context: Context): Promise<Result<LineScan, FileError>>;\n\tclose(context: Context): Promise<void>;\n}\n\n/** A file or directory to watch. It may be missing; creating it is a change. */\nexport interface WatchTarget {\n\tpath: string;\n\t/** Watch everything below a directory, not only its entries. Symbolic links below it are not followed. */\n\trecursive?: boolean;\n\t/** Entries below `path` that are neither watched nor reported: names starting with `.`, or these names. */\n\texclude?: { hidden?: boolean; names?: readonly string[] };\n}\n\n/**\n * What changed:\n * - `paths`: something at or below each path may have changed (a directory path covers its whole subtree). Calls may be\n * spurious; a change is never missed while the watcher is healthy.\n * - `overflow`: coverage was uncertain for a while (lost events, reconnect); rescan everything that is watched.\n * - `error`: the watcher stopped, for example because the watched tree grew past the environment's limit; no calls\n * follow.\n */\nexport type WatchChange = { paths: string[] } | { overflow: true } | { error: FileError };\n\nexport interface FileWatcher {\n\t/**\n\t * `native`: changes are reported within about two seconds. `polling`: the environment compares snapshots, because\n\t * the file system does not report changes reliably (network and FUSE file systems); a change undone between two\n\t * snapshots can be missed.\n\t */\n\treadonly mode: \"native\" | \"polling\";\n\t/** Stop watching; no `onChange` call starts after this resolves. Idempotent. */\n\tclose(context: Context): Promise<void>;\n}\n\n/** Where lines of a file are, as `BinaryReader.scanLines` found them. */\nexport interface LineScan {\n\t/** Newline bytes in the whole file; it has `newlines + 1` lines. */\n\tnewlines: number;\n\t/**\n\t * Byte range of the selected lines: from the start of the first to the end of the last, without the newline that\n\t * ends it. A selection past the last line is empty at the end of the file.\n\t */\n\tstart: number;\n\tend: number;\n\t/** Where the first selected line ends: its newline, or the end of the file. */\n\tfirstLineEnd: number;\n\t/** Where the last selected line starts. */\n\tlastLineStart: number;\n\t/** UTF-8 byte length of the decoded selection and of its first line. */\n\tselectedBytes: number;\n\tfirstLineBytes: number;\n}\n\n/** Pages of one directory's entries. */\nexport interface DirReader {\n\t/**\n\t * Up to `maxEntries` entries in the order the file system returns them, continuing where the previous call stopped.\n\t * `done` marks the end; it may come with the last entries or with an empty page. An entry that disappears before its\n\t * metadata is read is skipped, as are entries of unsupported kinds. After a failed or aborted call, close the reader.\n\t */\n\tnext(maxEntries: number, context: Context): Promise<Result<{ entries: FileInfo[]; done: boolean }, FileError>>;\n\tclose(context: Context): Promise<void>;\n}\n\n/** What `FileSystem.listFiles` lists. */\nexport interface ListFilesOptions {\n\t/**\n\t * Include names starting with `.` (on Windows also files with the hidden attribute); default true. Entries named\n\t * `.git` are never listed.\n\t */\n\thidden?: boolean;\n\t/**\n\t * Inside a git work tree, skip what git ignores: the `.gitignore` files of the directory, its subdirectories and its\n\t * parents, `.git/info/exclude`, and the global excludes file; default true. Unlike `git ls-files`, a tracked file that\n\t * matches an ignore rule is skipped too. Outside work trees, `.gitignore` files have no effect.\n\t */\n\tgitignore?: boolean;\n\t/** Names of entries to skip with everything below them, such as `node_modules`. */\n\texclude?: readonly string[];\n\t/** Most entries to list; default 50 000. */\n\tmaxEntries?: number;\n\t/** Most bytes of the listing: each entry's UTF-8 path plus two; default 4 MiB, at most 15.9 MiB. */\n\tmaxBytes?: number;\n\t/** Time after which the listing stops; default 10 000 ms. */\n\ttimeoutMs?: number;\n}\n\n/** One entry of a `FileListing`. */\nexport interface FileListEntry {\n\t/** Relative to the listed directory, with `/` separators on every system. */\n\tpath: string;\n\t/** A symbolic link is listed as such and not followed. */\n\tkind: FileKind;\n}\n\nexport interface FileListing {\n\t/** Depth first, parents before their entries, siblings in byte order of their names. */\n\tentries: FileListEntry[];\n\t/** A bound in `ListFilesOptions` ended the listing early. */\n\ttruncated: boolean;\n}\n\n/** Portable filesystem capability. Operations return failures rather than throwing. */\nexport interface FileSystem {\n\t/**\n\t * The file namespace: equal ids see the same files at the same paths, whatever their `cwd`. Every local Node\n\t * environment shares one id; each container or remote host has its own.\n\t */\n\treadonly id: string;\n\tcwd: string;\n\tabsolutePath(path: string, context: Context): Promise<Result<string, FileError>>;\n\tjoinPath(parts: string[], context: Context): Promise<Result<string, FileError>>;\n\treadTextFile(path: string, context: Context): Promise<Result<string, FileError>>;\n\topenTextLineReader(path: string, context: Context): Promise<Result<TextLineReader, FileError>>;\n\treadTextLines(\n\t\tpath: string,\n\t\toptions: { maxLines?: number } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<string[], FileError>>;\n\treadBinaryFile(path: string, context: Context): Promise<Result<Uint8Array, FileError>>;\n\t/**\n\t * Open a regular file for bounded positional reads. A directory fails with `is_directory`, other non-regular files\n\t * with `invalid`. With `noFollow`, a symbolic link as the final path component fails with `invalid` instead of being\n\t * followed; earlier components are still resolved.\n\t */\n\topenBinaryReader(\n\t\tpath: string,\n\t\toptions: { noFollow?: boolean } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<BinaryReader, FileError>>;\n\twriteFile(path: string, content: string | Uint8Array, context: Context): Promise<Result<void, FileError>>;\n\tappendFile(path: string, content: string | Uint8Array, context: Context): Promise<Result<void, FileError>>;\n\t/** Truncate or extend a file to exactly `size` bytes. */\n\ttruncateFile(path: string, size: number, context: Context): Promise<Result<void, FileError>>;\n\t/** Flush file contents and metadata needed to retrieve them from an open file handle. */\n\tflushFile(path: string, context: Context): Promise<Result<void, FileError>>;\n\trenameFile(sourcePath: string, destinationPath: string, context: Context): Promise<Result<void, FileError>>;\n\tfileInfo(path: string, context: Context): Promise<Result<FileInfo, FileError>>;\n\tlistDir(path: string, context: Context): Promise<Result<FileInfo[], FileError>>;\n\t/**\n\t * Optional: the files, directories and symbolic links below a directory, at any depth, for indexes such as file\n\t * completion. Symbolic links are not followed; other kinds of files are not listed; entries that cannot be read are\n\t * skipped. See `ListFilesOptions` for hidden and ignored files and for the bounds. Fails with `not_supported` when\n\t * the environment cannot list right now (an older remote daemon), so callers fall back to their own walk.\n\t */\n\tlistFiles?(\n\t\tpath: string,\n\t\toptions: ListFilesOptions | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<FileListing, FileError>>;\n\topenDirReader(path: string, context: Context): Promise<Result<DirReader, FileError>>;\n\t/**\n\t * Report changes to files and directories, for hosts that load resources from the environment. When the returned\n\t * watcher exists, coverage is established: a host that watches before it loads cannot miss a change made during the\n\t * load. See `WatchChange` for what is reported and `FileWatcher.mode` for how reliably.\n\t */\n\twatch(\n\t\ttargets: readonly WatchTarget[],\n\t\tonChange: (change: WatchChange) => void,\n\t\tcontext: Context,\n\t): Promise<Result<FileWatcher, FileError>>;\n\tcanonicalPath(path: string, context: Context): Promise<Result<string, FileError>>;\n\texists(path: string, context: Context): Promise<Result<boolean, FileError>>;\n\tcreateDir(\n\t\tpath: string,\n\t\toptions: { recursive?: boolean } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<void, FileError>>;\n\tremove(\n\t\tpath: string,\n\t\toptions: { recursive?: boolean; force?: boolean } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<void, FileError>>;\n\tcreateTempDir(prefix: string | undefined, context: Context): Promise<Result<string, FileError>>;\n\tcreateTempFile(\n\t\toptions: { prefix?: string; suffix?: string } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<string, FileError>>;\n\tcleanup(context: Context): Promise<void>;\n}\n\n/** Spill the complete output to a temporary file once it exceeds either threshold. */\nexport interface ShellSpillOptions {\n\tafterBytes: number;\n\t/** Complete or partial lines. */\n\tafterLines: number;\n}\n\nexport interface ShellExecResult {\n\texitCode: number;\n\t/** Temporary file holding the complete raw output, when the spill thresholds were exceeded. */\n\tspillPath?: string;\n}\n\nexport interface ShellExecOptions {\n\tcwd?: string;\n\tenv?: Record<string, string>;\n\tinheritEnv?: boolean;\n\ttimeout?: number;\n\t/**\n\t * Every decoded chunk of stdout and stderr as it arrives, in arrival order, with the stream it came from: raw,\n\t * unbounded, and unthrottled. Each stream is decoded separately, so a character split across chunks survives.\n\t */\n\tonOutput?: (text: string, context: Context, info: ShellOutputInfo) => void;\n\tspill?: ShellSpillOptions;\n\t/**\n\t * The caller keeps only this tail of the output, so the environment may omit output outside it and report the omission\n\t * as `info.skipped`. Without it, every chunk is delivered.\n\t */\n\twindow?: ShellOutputWindow;\n}\n\n/**\n * The tail of the combined output a caller keeps, and how often it samples it. An environment that transfers output\n * over a slow link uses it to omit what the caller would drop anyway and to send no faster than the caller commits.\n */\nexport interface ShellOutputWindow {\n\t/** UTF-8 bytes of decoded text kept at the end of the output. */\n\tmaxBytes: number;\n\t/** Lines kept at the end of the output. */\n\tmaxLines: number;\n\t/** Minimum pause between the caller's samples of the output. */\n\tminIntervalMs: number;\n\t/** Each sample also pauses the caller in proportion to its size at this rate. */\n\tbytesPerSecond: number;\n}\n\n/**\n * Output an environment omitted, measured on the decoded text `onOutput` would have received: every U+FFFD counts as\n * three bytes, and no sanitizing is applied.\n */\n/** The shape of `OutputSkip` from `@earendil-works/chord/output`, which `OutputBuffer.push()` accepts. */\nexport interface ShellOutputSkip {\n\t/** UTF-8 byte length of the omitted text. */\n\tbytes: number;\n\t/** Newlines (U+000A) in the omitted text. */\n\tnewlines: number;\n\t/** Whether the omitted text ends with a newline. */\n\tendsWithNewline: boolean;\n}\n\nexport interface ShellOutputInfo {\n\tstream: \"stdout\" | \"stderr\";\n\t/**\n\t * Output omitted immediately before this chunk, only with `window`. The chunk then holds all output after the\n\t * omission up to its end, and that is more than the window by at least one byte or one line: more than\n\t * `window.maxBytes` bytes or more than `window.maxLines` newlines. So the omitted text can never be in the kept tail.\n\t * The omission and such a chunk may span both streams in arrival order; `stream` then names the chunk's last stream.\n\t * Callers that need the streams apart do not pass `window`.\n\t */\n\tskipped?: ShellOutputSkip;\n}\n\nexport interface Shell {\n\t/**\n\t * Run a command. A string runs through the environment's shell. An array runs `command[0]` directly with the rest\n\t * as its arguments, without a shell, so they reach the program unparsed. Aborting the context or a timeout kills\n\t * only this command's processes.\n\t */\n\texec(\n\t\tcommand: string | readonly string[],\n\t\toptions: ShellExecOptions | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<ShellExecResult, ExecutionError>>;\n\t/** Kill every command this environment still runs; for its owner's shutdown, never for one request. */\n\tcleanup(context: Context): Promise<void>;\n}\n\nexport interface ExecutionEnv extends FileSystem, Shell {}\n\nexport { rangeDecoder, StreamDecoder, startsWithBom } from \"./decode.ts\";\nexport { LineScanner } from \"./line-scan.ts\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/env/index.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,EAAE,CAAiB,KAAa;IAC/C,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,GAAG,CAAiB,KAAa;IAChD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,UAAU,CAAiB,MAA8B;IACxE,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,MAAM,MAAM,CAAC,KAAK,CAAC;IACnC,OAAO,MAAM,CAAC,KAAK,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,cAAc,CAAgC,MAA8B;IAC3F,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,OAAO,C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BAAgB,CAAC","sourcesContent":["import type { Context } from \"@earendil-works/chord\";\n\n/** Result of a fallible operation. Expected failures are returned instead of thrown. */\nexport type Result<TValue, TError> = { ok: true; value: TValue } | { ok: false; error: TError };\n\nexport function ok<TValue, TError>(value: TValue): Result<TValue, TError> {\n\treturn { ok: true, value };\n}\n\nexport function err<TValue, TError>(error: TError): Result<TValue, TError> {\n\treturn { ok: false, error };\n}\n\nexport function getOrThrow<TValue, TError>(result: Result<TValue, TError>): TValue {\n\tif (!result.ok) throw result.error;\n\treturn result.value;\n}\n\nexport function getOrUndefined<TValue extends object, TError>(result: Result<TValue, TError>): TValue | undefined {\n\treturn result.ok ? result.value : undefined;\n}\n\nexport function toError(error: unknown): Error {\n\tif (error instanceof Error) return error;\n\tif (typeof error === \"string\") return new Error(error);\n\ttry {\n\t\treturn new Error(JSON.stringify(error));\n\t} catch {\n\t\treturn new Error(String(error));\n\t}\n}\n\nexport type FileKind = \"file\" | \"directory\" | \"symlink\";\n\nexport type FileErrorCode =\n\t| \"aborted\"\n\t| \"not_found\"\n\t| \"permission_denied\"\n\t| \"not_directory\"\n\t| \"is_directory\"\n\t| \"invalid\"\n\t| \"not_supported\"\n\t| \"unknown\";\n\nexport class FileError extends Error {\n\tpublic code: FileErrorCode;\n\tpublic path?: string;\n\n\tconstructor(code: FileErrorCode, message: string, path?: string, cause?: Error) {\n\t\tsuper(message, cause === undefined ? undefined : { cause });\n\t\tthis.name = \"FileError\";\n\t\tthis.code = code;\n\t\tthis.path = path;\n\t}\n}\n\nexport type ExecutionErrorCode =\n\t| \"aborted\"\n\t| \"timeout\"\n\t| \"shell_unavailable\"\n\t| \"spawn_error\"\n\t| \"callback_error\"\n\t| \"unknown\";\n\nexport class ExecutionError extends Error {\n\tpublic code: ExecutionErrorCode;\n\t/** Spill file of a command that timed out or was aborted after its output crossed the spill thresholds. */\n\tpublic spillPath?: string;\n\n\tconstructor(code: ExecutionErrorCode, message: string, cause?: Error) {\n\t\tsuper(message, cause === undefined ? undefined : { cause });\n\t\tthis.name = \"ExecutionError\";\n\t\tthis.code = code;\n\t}\n}\n\nexport interface FileInfo {\n\tname: string;\n\tpath: string;\n\tkind: FileKind;\n\tsize: number;\n\tmtimeMs: number;\n}\n\nexport interface TextLine {\n\ttext: string;\n\tterminated: boolean;\n}\n\nexport interface TextLineReader {\n\treadLine(context: Context): Promise<Result<TextLine | undefined, FileError>>;\n\tclose(context: Context): Promise<void>;\n}\n\n/** Positional reads from one opened regular file; all calls see the same file even if its path is renamed. */\nexport interface BinaryReader {\n\t/** Metadata of the opened file, not of whatever its path names now. */\n\tinfo(context: Context): Promise<Result<FileInfo, FileError>>;\n\t/** Up to `length` bytes at `offset`; fewer only at end of file. */\n\tread(offset: number, length: number, context: Context): Promise<Result<Uint8Array, FileError>>;\n\t/**\n\t * One pass over the file that locates lines `[startLine, endLine)` (`endLine` absent: to the end), 0-based, where line\n\t * `k` starts after the `k`-th newline byte. Decoded sizes are those of the text `new TextDecoder().decode(file)` would\n\t * produce for that range, so a byte-order mark at the start of the file is not counted.\n\t */\n\tscanLines(options: { startLine: number; endLine?: number }, context: Context): Promise<Result<LineScan, FileError>>;\n\tclose(context: Context): Promise<void>;\n}\n\n/** A file or directory to watch. It may be missing; creating it is a change. */\nexport interface WatchTarget {\n\tpath: string;\n\t/** Watch everything below a directory, not only its entries. Symbolic links below it are not followed. */\n\trecursive?: boolean;\n\t/** Entries below `path` that are neither watched nor reported: names starting with `.`, or these names. */\n\texclude?: { hidden?: boolean; names?: readonly string[] };\n}\n\n/**\n * What changed, tagged by `kind`:\n * - `paths`: something at or below each path may have changed (a directory path covers its whole subtree). Calls may be\n * spurious; a change is never missed while the watcher is healthy.\n * - `overflow`: coverage was uncertain for a while (lost events, reconnect); rescan everything that is watched.\n * - `failed`: the watcher stopped with `error`, for example because the watched tree grew past the environment's limit;\n * no calls follow.\n */\nexport type FileChange =\n\t| { readonly kind: \"paths\"; readonly paths: string[] }\n\t| { readonly kind: \"overflow\" }\n\t| { readonly kind: \"failed\"; readonly error: FileError };\n\nexport interface FileWatcher {\n\t/**\n\t * `native`: changes are reported within about two seconds. `polling`: the environment compares snapshots, because\n\t * the file system does not report changes reliably (network and FUSE file systems); a change undone between two\n\t * snapshots can be missed.\n\t */\n\treadonly mode: \"native\" | \"polling\";\n\t/** Stop watching; no `onChange` call starts after this resolves. Idempotent. */\n\tstop(context: Context): Promise<void>;\n}\n\n/** Where lines of a file are, as `BinaryReader.scanLines` found them. */\nexport interface LineScan {\n\t/** Newline bytes in the whole file; it has `newlines + 1` lines. */\n\tnewlines: number;\n\t/**\n\t * Byte range of the selected lines: from the start of the first to the end of the last, without the newline that\n\t * ends it. A selection past the last line is empty at the end of the file.\n\t */\n\tstart: number;\n\tend: number;\n\t/** Where the first selected line ends: its newline, or the end of the file. */\n\tfirstLineEnd: number;\n\t/** Where the last selected line starts. */\n\tlastLineStart: number;\n\t/** UTF-8 byte length of the decoded selection and of its first line. */\n\tselectedBytes: number;\n\tfirstLineBytes: number;\n}\n\n/** Pages of one directory's entries. */\nexport interface DirReader {\n\t/**\n\t * Up to `maxEntries` entries in the order the file system returns them, continuing where the previous call stopped.\n\t * `done` marks the end; it may come with the last entries or with an empty page. An entry that disappears before its\n\t * metadata is read is skipped, as are entries of unsupported kinds. After a failed or aborted call, close the reader.\n\t */\n\tnext(maxEntries: number, context: Context): Promise<Result<{ entries: FileInfo[]; done: boolean }, FileError>>;\n\tclose(context: Context): Promise<void>;\n}\n\n/** What `FileSystem.listFiles` lists. */\nexport interface ListFilesOptions {\n\t/**\n\t * Include names starting with `.` (on Windows also files with the hidden attribute); default true. Entries named\n\t * `.git` are never listed.\n\t */\n\thidden?: boolean;\n\t/**\n\t * Inside a git work tree, skip what git ignores: the `.gitignore` files of the directory, its subdirectories and its\n\t * parents, `.git/info/exclude`, and the global excludes file; default true. Unlike `git ls-files`, a tracked file that\n\t * matches an ignore rule is skipped too. Outside work trees, `.gitignore` files have no effect.\n\t */\n\tgitignore?: boolean;\n\t/** Names of entries to skip with everything below them, such as `node_modules`. */\n\texclude?: readonly string[];\n\t/** Most entries to list; default 50 000. */\n\tmaxEntries?: number;\n\t/** Most bytes of the listing: each entry's UTF-8 path plus two; default 4 MiB, at most 15.9 MiB. */\n\tmaxBytes?: number;\n\t/** Time after which the listing stops; default 10 000 ms. */\n\ttimeoutMs?: number;\n}\n\n/** One entry of a `FileListing`. */\nexport interface FileListEntry {\n\t/** Relative to the listed directory, with `/` separators on every system. */\n\tpath: string;\n\t/** A symbolic link is listed as such and not followed. */\n\tkind: FileKind;\n}\n\nexport interface FileListing {\n\t/** Depth first, parents before their entries, siblings in byte order of their names. */\n\tentries: FileListEntry[];\n\t/** A bound in `ListFilesOptions` ended the listing early. */\n\ttruncated: boolean;\n}\n\n/** Portable filesystem capability. Operations return failures rather than throwing. */\nexport interface FileSystem {\n\t/**\n\t * The file namespace: equal ids see the same files at the same paths, whatever their `cwd`. Every local Node\n\t * environment shares one id; each container or remote host has its own.\n\t */\n\treadonly id: string;\n\tcwd: string;\n\tabsolutePath(path: string, context: Context): Promise<Result<string, FileError>>;\n\tjoinPath(parts: string[], context: Context): Promise<Result<string, FileError>>;\n\treadTextFile(path: string, context: Context): Promise<Result<string, FileError>>;\n\topenTextLineReader(path: string, context: Context): Promise<Result<TextLineReader, FileError>>;\n\treadTextLines(\n\t\tpath: string,\n\t\toptions: { maxLines?: number } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<string[], FileError>>;\n\treadBinaryFile(path: string, context: Context): Promise<Result<Uint8Array, FileError>>;\n\t/**\n\t * Open a regular file for bounded positional reads. A directory fails with `is_directory`, other non-regular files\n\t * with `invalid`. With `noFollow`, a symbolic link as the final path component fails with `invalid` instead of being\n\t * followed; earlier components are still resolved.\n\t */\n\topenBinaryReader(\n\t\tpath: string,\n\t\toptions: { noFollow?: boolean } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<BinaryReader, FileError>>;\n\twriteFile(path: string, content: string | Uint8Array, context: Context): Promise<Result<void, FileError>>;\n\tappendFile(path: string, content: string | Uint8Array, context: Context): Promise<Result<void, FileError>>;\n\t/** Truncate or extend a file to exactly `size` bytes. */\n\ttruncateFile(path: string, size: number, context: Context): Promise<Result<void, FileError>>;\n\t/** Flush file contents and metadata needed to retrieve them from an open file handle. */\n\tflushFile(path: string, context: Context): Promise<Result<void, FileError>>;\n\trenameFile(sourcePath: string, destinationPath: string, context: Context): Promise<Result<void, FileError>>;\n\tfileInfo(path: string, context: Context): Promise<Result<FileInfo, FileError>>;\n\tlistDir(path: string, context: Context): Promise<Result<FileInfo[], FileError>>;\n\t/**\n\t * Optional: the files, directories and symbolic links below a directory, at any depth, for indexes such as file\n\t * completion. Symbolic links are not followed; other kinds of files are not listed; entries that cannot be read are\n\t * skipped. See `ListFilesOptions` for hidden and ignored files and for the bounds. Fails with `not_supported` when\n\t * the environment cannot list right now (an older remote daemon), so callers fall back to their own walk.\n\t */\n\tlistFiles?(\n\t\tpath: string,\n\t\toptions: ListFilesOptions | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<FileListing, FileError>>;\n\topenDirReader(path: string, context: Context): Promise<Result<DirReader, FileError>>;\n\t/**\n\t * Report changes to files and directories, for hosts that load resources from the environment. When the returned\n\t * watcher exists, coverage is established: a host that watches before it loads cannot miss a change made during the\n\t * load. See `FileChange` for what is reported and `FileWatcher.mode` for how reliably.\n\t */\n\twatch(\n\t\ttargets: readonly WatchTarget[],\n\t\tonChange: (change: FileChange) => void,\n\t\tcontext: Context,\n\t): Promise<Result<FileWatcher, FileError>>;\n\tcanonicalPath(path: string, context: Context): Promise<Result<string, FileError>>;\n\texists(path: string, context: Context): Promise<Result<boolean, FileError>>;\n\tcreateDir(\n\t\tpath: string,\n\t\toptions: { recursive?: boolean } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<void, FileError>>;\n\tremove(\n\t\tpath: string,\n\t\toptions: { recursive?: boolean; force?: boolean } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<void, FileError>>;\n\tcreateTempDir(prefix: string | undefined, context: Context): Promise<Result<string, FileError>>;\n\tcreateTempFile(\n\t\toptions: { prefix?: string; suffix?: string } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<string, FileError>>;\n\tcleanup(context: Context): Promise<void>;\n}\n\n/** Spill the complete output to a temporary file once it exceeds either threshold. */\nexport interface ShellSpillOptions {\n\tafterBytes: number;\n\t/** Complete or partial lines. */\n\tafterLines: number;\n}\n\nexport interface ShellExecResult {\n\texitCode: number;\n\t/** Temporary file holding the complete raw output, when the spill thresholds were exceeded. */\n\tspillPath?: string;\n}\n\nexport interface ShellExecOptions {\n\tcwd?: string;\n\tenv?: Record<string, string>;\n\tinheritEnv?: boolean;\n\ttimeout?: number;\n\t/**\n\t * Every decoded chunk of stdout and stderr as it arrives, in arrival order, with the stream it came from: raw,\n\t * unbounded, and unthrottled. Each stream is decoded separately, so a character split across chunks survives.\n\t */\n\tonOutput?: (text: string, context: Context, info: ShellOutputInfo) => void;\n\tspill?: ShellSpillOptions;\n\t/**\n\t * The caller keeps only this tail of the output, so the environment may omit output outside it and report the omission\n\t * as `info.skipped`. Without it, every chunk is delivered.\n\t */\n\twindow?: ShellOutputWindow;\n}\n\n/**\n * The tail of the combined output a caller keeps, and how often it samples it. An environment that transfers output\n * over a slow link uses it to omit what the caller would drop anyway and to send no faster than the caller commits.\n */\nexport interface ShellOutputWindow {\n\t/** UTF-8 bytes of decoded text kept at the end of the output. */\n\tmaxBytes: number;\n\t/** Lines kept at the end of the output. */\n\tmaxLines: number;\n\t/** Minimum pause between the caller's samples of the output. */\n\tminIntervalMs: number;\n\t/** Each sample also pauses the caller in proportion to its size at this rate. */\n\tbytesPerSecond: number;\n}\n\n/**\n * Output an environment omitted, measured on the decoded text `onOutput` would have received: every U+FFFD counts as\n * three bytes, and no sanitizing is applied.\n */\n/** The shape of `OutputSkip` from `@earendil-works/chord/output`, which `OutputBuffer.push()` accepts. */\nexport interface ShellOutputSkip {\n\t/** UTF-8 byte length of the omitted text. */\n\tbytes: number;\n\t/** Newlines (U+000A) in the omitted text. */\n\tnewlines: number;\n\t/** Whether the omitted text ends with a newline. */\n\tendsWithNewline: boolean;\n}\n\nexport interface ShellOutputInfo {\n\tstream: \"stdout\" | \"stderr\";\n\t/**\n\t * Output omitted immediately before this chunk, only with `window`. The chunk then holds all output after the\n\t * omission up to its end, and that is more than the window by at least one byte or one line: more than\n\t * `window.maxBytes` bytes or more than `window.maxLines` newlines. So the omitted text can never be in the kept tail.\n\t * The omission and such a chunk may span both streams in arrival order; `stream` then names the chunk's last stream.\n\t * Callers that need the streams apart do not pass `window`.\n\t */\n\tskipped?: ShellOutputSkip;\n}\n\nexport interface Shell {\n\t/**\n\t * Run a command. A string runs through the environment's shell. An array runs `command[0]` directly with the rest\n\t * as its arguments, without a shell, so they reach the program unparsed. Aborting the context or a timeout kills\n\t * only this command's processes.\n\t */\n\texec(\n\t\tcommand: string | readonly string[],\n\t\toptions: ShellExecOptions | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<ShellExecResult, ExecutionError>>;\n\t/** Kill every command this environment still runs; for its owner's shutdown, never for one request. */\n\tcleanup(context: Context): Promise<void>;\n}\n\nexport interface ExecutionEnv extends FileSystem, Shell {}\n\nexport { rangeDecoder, StreamDecoder, startsWithBom } from \"./decode.ts\";\nexport { LineScanner } from \"./line-scan.ts\";\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { Context } from "@earendil-works/chord";
2
- import { type FileWatcher, type WatchChange, type WatchTarget } from "./index.ts";
2
+ import { type FileChange, type FileWatcher, type WatchTarget } from "./index.ts";
3
3
  /** How `NodeExecutionEnv` watches. */
4
4
  export interface NodeWatchOptions {
5
5
  /**
@@ -22,8 +22,8 @@ export declare class NodeFileWatcher implements FileWatcher {
22
22
  #private;
23
23
  private constructor();
24
24
  /** Establish coverage: watchers first, then the snapshot later changes are compared with. */
25
- static open(targets: readonly WatchTarget[], resolvePath: (path: string) => string, onChange: (change: WatchChange) => void, options: NodeWatchOptions): Promise<NodeFileWatcher>;
25
+ static open(targets: readonly WatchTarget[], resolvePath: (path: string) => string, onChange: (change: FileChange) => void, options: NodeWatchOptions): Promise<NodeFileWatcher>;
26
26
  get mode(): "native" | "polling";
27
- close(_context: Context): Promise<void>;
27
+ stop(_context: Context): Promise<void>;
28
28
  }
29
29
  //# sourceMappingURL=node-watch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node-watch.d.ts","sourceRoot":"","sources":["../../src/env/node-watch.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAa,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAE7F,sCAAsC;AACtC,MAAM,WAAW,gBAAgB;IAChC;;;OAGG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC5B,qEAAqE;IACrE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,2DAA2D;IAC3D,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAkHD;;;;;GAKG;AACH,qBAAa,eAAgB,YAAW,WAAW;;IAelD,OAAO,eAWN;IAED,6FAA6F;IAC7F,OAAa,IAAI,CAChB,OAAO,EAAE,SAAS,WAAW,EAAE,EAC/B,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,EACrC,QAAQ,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,EACvC,OAAO,EAAE,gBAAgB,GACvB,OAAO,CAAC,eAAe,CAAC,CAwB1B;IAED,IAAI,IAAI,IAAI,QAAQ,GAAG,SAAS,CAE/B;IAEK,KAAK,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAI5C;CA6SD"}
1
+ {"version":3,"file":"node-watch.d.ts","sourceRoot":"","sources":["../../src/env/node-watch.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,KAAK,UAAU,EAAa,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAE5F,sCAAsC;AACtC,MAAM,WAAW,gBAAgB;IAChC;;;OAGG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC5B,qEAAqE;IACrE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,2DAA2D;IAC3D,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAoHD;;;;;GAKG;AACH,qBAAa,eAAgB,YAAW,WAAW;;IAelD,OAAO,eAWN;IAED,6FAA6F;IAC7F,OAAa,IAAI,CAChB,OAAO,EAAE,SAAS,WAAW,EAAE,EAC/B,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,EACrC,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,EACtC,OAAO,EAAE,gBAAgB,GACvB,OAAO,CAAC,eAAe,CAAC,CAwB1B;IAED,IAAI,IAAI,IAAI,QAAQ,GAAG,SAAS,CAE/B;IAEK,IAAI,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAI3C;CA6SD"}
@@ -12,6 +12,8 @@ const DEBOUNCE_MS = 50;
12
12
  const FSEVENTS_SETTLE_MS = 500;
13
13
  const DEFAULT_POLL_MS = 2000;
14
14
  const DEFAULT_MAX_DIRECTORIES = 10_000;
15
+ /** The one `overflow` change; it carries nothing else. */
16
+ const OVERFLOW = { kind: "overflow" };
15
17
  /** In polling mode, recently modified small files are also compared by content: a second write within the file system's
16
18
  * timestamp granularity can keep size and modification time. */
17
19
  const HASH_MAX_BYTES = 256 * 1024;
@@ -99,7 +101,7 @@ export class NodeFileWatcher {
99
101
  #settleTimer;
100
102
  #running;
101
103
  #dirty = false;
102
- #closed = false;
104
+ #stopped = false;
103
105
  constructor(targets, onChange, mode, options) {
104
106
  this.#targets = targets;
105
107
  this.#onChange = onChange;
@@ -137,14 +139,14 @@ export class NodeFileWatcher {
137
139
  get mode() {
138
140
  return this.#mode;
139
141
  }
140
- async close(_context) {
141
- if (this.#closed)
142
+ async stop(_context) {
143
+ if (this.#stopped)
142
144
  return;
143
145
  this.#stop();
144
146
  await this.#running;
145
147
  }
146
148
  #stop() {
147
- this.#closed = true;
149
+ this.#stopped = true;
148
150
  clearTimeout(this.#timer);
149
151
  this.#timer = undefined;
150
152
  clearTimeout(this.#settleTimer);
@@ -154,7 +156,7 @@ export class NodeFileWatcher {
154
156
  this.#watchers.clear();
155
157
  }
156
158
  #deliver(change) {
157
- if (this.#closed)
159
+ if (this.#stopped)
158
160
  return;
159
161
  try {
160
162
  this.#onChange(change);
@@ -164,7 +166,7 @@ export class NodeFileWatcher {
164
166
  }
165
167
  }
166
168
  #schedulePoll() {
167
- if (this.#closed || this.#mode !== "polling")
169
+ if (this.#stopped || this.#mode !== "polling")
168
170
  return;
169
171
  this.#timer = setTimeout(() => {
170
172
  this.#timer = undefined;
@@ -172,7 +174,7 @@ export class NodeFileWatcher {
172
174
  }, this.#pollIntervalMs);
173
175
  }
174
176
  #scheduleFlush() {
175
- if (this.#closed || this.#timer !== undefined)
177
+ if (this.#stopped || this.#timer !== undefined)
176
178
  return;
177
179
  this.#timer = setTimeout(() => {
178
180
  this.#timer = undefined;
@@ -180,7 +182,7 @@ export class NodeFileWatcher {
180
182
  }, DEBOUNCE_MS);
181
183
  }
182
184
  #scheduleSettle() {
183
- if (this.#closed)
185
+ if (this.#stopped)
184
186
  return;
185
187
  clearTimeout(this.#settleTimer);
186
188
  this.#settleTimer = setTimeout(() => {
@@ -203,15 +205,15 @@ export class NodeFileWatcher {
203
205
  for (const path of events)
204
206
  changed.add(path);
205
207
  if (changed.size > 0)
206
- this.#deliver({ paths: [...changed].sort() });
207
- } while (this.#dirty && !this.#closed);
208
+ this.#deliver({ kind: "paths", paths: [...changed].sort() });
209
+ } while (this.#dirty && !this.#stopped);
208
210
  }
209
211
  catch (error) {
210
212
  const message = error instanceof Error ? error.message : String(error);
211
213
  const fileError = error instanceof FileError
212
214
  ? error
213
215
  : new FileError(isDenied(error) ? "permission_denied" : "invalid", message);
214
- this.#deliver({ error: fileError });
216
+ this.#deliver({ kind: "failed", error: fileError });
215
217
  this.#stop();
216
218
  }
217
219
  finally {
@@ -223,10 +225,10 @@ export class NodeFileWatcher {
223
225
  /** Rescan, report differences, and install watchers for new directories, rescanning until none are new. */
224
226
  async #sync(report) {
225
227
  const changed = new Set();
226
- for (let round = 0; round < 10 && !this.#closed; round++) {
228
+ for (let round = 0; round < 10 && !this.#stopped; round++) {
227
229
  const scan = await this.#scan();
228
230
  // Closed during the scan: installing watchers now would leak them.
229
- if (this.#closed)
231
+ if (this.#stopped)
230
232
  break;
231
233
  const next = scan.snapshot;
232
234
  if (report)
@@ -427,13 +429,13 @@ export class NodeFileWatcher {
427
429
  for (const { watcher } of this.#watchers.values())
428
430
  watcher.close();
429
431
  this.#watchers.clear();
430
- this.#deliver({ overflow: true });
432
+ this.#deliver(OVERFLOW);
431
433
  clearTimeout(this.#timer);
432
434
  this.#timer = undefined;
433
435
  this.#schedulePoll();
434
436
  }
435
437
  #onEvent(directory, filename) {
436
- if (this.#closed)
438
+ if (this.#stopped)
437
439
  return;
438
440
  const path = filename === undefined ? directory : `${directory.endsWith(sep) ? directory : directory + sep}${filename}`;
439
441
  // Events about unrelated siblings of an ancestor, or about excluded entries, are ignored.
@@ -445,7 +447,7 @@ export class NodeFileWatcher {
445
447
  }
446
448
  /** The file a target links to changed: report the target. */
447
449
  #onLinkedFileEvent(target) {
448
- if (this.#closed)
450
+ if (this.#stopped)
449
451
  return;
450
452
  this.#events.add(target);
451
453
  this.#scheduleFlush();