@halonicjs/testing 0.1.0 → 0.1.2

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 (228) hide show
  1. package/NOTICE +4 -0
  2. package/README.md +1 -1
  3. package/dist/adapters/http-kit/src/address-checking.d.ts +19 -0
  4. package/dist/adapters/http-kit/src/address-checking.js +1 -0
  5. package/dist/adapters/http-kit/src/connector-host-class.d.ts +14 -0
  6. package/dist/adapters/http-kit/src/connector-host-class.js +34 -0
  7. package/dist/adapters/http-kit/src/index.d.ts +3 -0
  8. package/dist/adapters/http-kit/src/index.js +2 -0
  9. package/dist/adapters/http-kit/src/ollama-tags.d.ts +20 -0
  10. package/dist/adapters/http-kit/src/ollama-tags.js +38 -0
  11. package/dist/adapters/integration-kit/src/auth-placement.d.ts +40 -0
  12. package/dist/adapters/integration-kit/src/auth-placement.js +102 -0
  13. package/dist/adapters/integration-kit/src/current-secret-forms.d.ts +28 -0
  14. package/dist/adapters/integration-kit/src/current-secret-forms.js +60 -0
  15. package/dist/adapters/integration-kit/src/declaration.d.ts +2 -1
  16. package/dist/adapters/integration-kit/src/declaration.js +4 -3
  17. package/dist/adapters/integration-kit/src/host.d.ts +7 -1
  18. package/dist/adapters/integration-kit/src/host.js +1 -0
  19. package/dist/adapters/integration-kit/src/index.d.ts +5 -2
  20. package/dist/adapters/integration-kit/src/index.js +2 -0
  21. package/dist/adapters/integration-kit/src/leak-attempt.d.ts +4 -2
  22. package/dist/adapters/integration-kit/src/leak-attempt.js +5 -2
  23. package/dist/adapters/integration-kit/src/limited-http.d.ts +7 -1
  24. package/dist/adapters/integration-kit/src/limited-http.js +53 -10
  25. package/dist/adapters/integration-kit/src/loader.d.ts +28 -11
  26. package/dist/adapters/integration-kit/src/loader.js +36 -21
  27. package/dist/adapters/integration-kit/src/own-request.d.ts +2 -2
  28. package/dist/adapters/integration-kit/src/own-request.js +1 -1
  29. package/dist/adapters/integration-kit/src/plugin-load.d.ts +3 -3
  30. package/dist/adapters/integration-kit/src/plugin-load.js +5 -5
  31. package/dist/adapters/integration-kit/src/policy.d.ts +28 -0
  32. package/dist/adapters/integration-kit/src/response-body.d.ts +6 -2
  33. package/dist/adapters/integration-kit/src/secret-filter.d.ts +3 -3
  34. package/dist/adapters/integration-kit/src/secret-filter.js +19 -4
  35. package/dist/adapters/integration-kit/src/secret-in-request.d.ts +3 -0
  36. package/dist/adapters/integration-kit/src/secret-in-request.js +8 -2
  37. package/dist/adapters/integration-kit/src/secret-placement.d.ts +35 -25
  38. package/dist/adapters/integration-kit/src/secret-placement.js +65 -95
  39. package/dist/adapters/integration-kit/src/sign-in-placement.d.ts +29 -0
  40. package/dist/adapters/integration-kit/src/sign-in-placement.js +92 -0
  41. package/dist/adapters/integration-kit/src/workspace-choices.d.ts +37 -0
  42. package/dist/adapters/integration-kit/src/workspace-choices.js +37 -0
  43. package/dist/core/events/src/blocked-sites.d.ts +57 -0
  44. package/dist/core/events/src/blocked-sites.js +89 -0
  45. package/dist/core/events/src/connector-listing-failed.d.ts +18 -0
  46. package/dist/core/events/src/connector-listing-failed.js +1 -0
  47. package/dist/core/events/src/home-path.d.ts +4 -1
  48. package/dist/core/events/src/home-path.js +14 -3
  49. package/dist/core/events/src/index.d.ts +8 -2
  50. package/dist/core/events/src/index.js +5 -0
  51. package/dist/core/events/src/provider-notes.d.ts +16 -0
  52. package/dist/core/events/src/provider-notes.js +24 -0
  53. package/dist/core/events/src/run-basics.d.ts +131 -10
  54. package/dist/core/events/src/run-event.d.ts +120 -11
  55. package/dist/core/events/src/run-reads.d.ts +25 -0
  56. package/dist/core/events/src/run-reads.js +44 -0
  57. package/dist/core/events/src/run-sends.d.ts +47 -0
  58. package/dist/core/events/src/run-sends.js +68 -0
  59. package/dist/core/events/src/run-summary.d.ts +11 -1
  60. package/dist/core/events/src/sandbox-opened-read.d.ts +2 -1
  61. package/dist/core/events/src/sandbox-opened-read.js +27 -2
  62. package/dist/core/events/src/sandbox-opened.d.ts +37 -4
  63. package/dist/core/events/src/sandbox-opened.js +13 -3
  64. package/dist/core/events/src/summarize.js +8 -1
  65. package/dist/core/events/src/timeline-entry.js +1 -0
  66. package/dist/core/events/src/tool-failure-cause.d.ts +25 -0
  67. package/dist/core/events/src/tool-failure-cause.js +66 -0
  68. package/dist/core/format/src/index.d.ts +9 -6
  69. package/dist/core/format/src/index.js +7 -3
  70. package/dist/core/format/src/integration/index.d.ts +3 -2
  71. package/dist/core/format/src/integration/index.js +2 -1
  72. package/dist/core/format/src/kinds/agent/harness-limits.d.ts +14 -0
  73. package/dist/core/format/src/kinds/agent/harness-limits.js +27 -0
  74. package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +15 -5
  75. package/dist/core/format/src/kinds/agent/sandbox-fields.js +29 -10
  76. package/dist/core/format/src/kinds/agent/schema.d.ts +5 -0
  77. package/dist/core/format/src/kinds/agent/schema.js +5 -2
  78. package/dist/core/format/src/kinds/connector/is-local.js +1 -1
  79. package/dist/core/format/src/kinds/connector/kind.js +122 -2
  80. package/dist/core/format/src/kinds/connector/schema.d.ts +38 -0
  81. package/dist/core/format/src/kinds/connector/schema.js +71 -2
  82. package/dist/core/format/src/kinds/deployments/kind.js +25 -1
  83. package/dist/core/format/src/kinds/deployments/schema.d.ts +40 -0
  84. package/dist/core/format/src/kinds/deployments/schema.js +52 -0
  85. package/dist/core/format/src/kinds/integration/approved-sign-ins.d.ts +62 -0
  86. package/dist/core/format/src/kinds/integration/approved-sign-ins.js +125 -0
  87. package/dist/core/format/src/kinds/integration/host-key.d.ts +7 -0
  88. package/dist/core/format/src/kinds/integration/host-key.js +8 -0
  89. package/dist/core/format/src/kinds/integration/kind.d.ts +4 -2
  90. package/dist/core/format/src/kinds/integration/kind.js +49 -12
  91. package/dist/core/format/src/kinds/integration/policy.d.ts +47 -2
  92. package/dist/core/format/src/kinds/integration/policy.js +61 -2
  93. package/dist/core/format/src/kinds/integration/schema.d.ts +180 -3
  94. package/dist/core/format/src/kinds/integration/schema.js +133 -7
  95. package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +14 -0
  96. package/dist/core/format/src/kinds/integration/sign-in-checks.js +150 -0
  97. package/dist/core/format/src/kinds/integration/sign-in-urls.d.ts +19 -0
  98. package/dist/core/format/src/kinds/integration/sign-in-urls.js +47 -0
  99. package/dist/core/format/src/kinds/plugin/checks.d.ts +3 -2
  100. package/dist/core/format/src/kinds/plugin/checks.js +24 -6
  101. package/dist/core/format/src/kinds/plugin/schema.d.ts +130 -0
  102. package/dist/core/format/src/kinds/plugin/schema.js +26 -6
  103. package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +1 -1
  104. package/dist/core/format/src/kinds/plugin/ui-checks.js +1 -10
  105. package/dist/core/format/src/kinds/provider/kind.js +40 -1
  106. package/dist/core/format/src/kinds/provider/types.d.ts +19 -0
  107. package/dist/core/format/src/kinds/provider/types.js +22 -0
  108. package/dist/core/format/src/kinds/routine/kind.js +38 -1
  109. package/dist/core/format/src/kinds/routine/schema.d.ts +20 -5
  110. package/dist/core/format/src/kinds/routine/schema.js +42 -14
  111. package/dist/core/format/src/kinds/routine/webhook-headers.d.ts +9 -0
  112. package/dist/core/format/src/kinds/routine/webhook-headers.js +26 -0
  113. package/dist/core/format/src/kinds/workflow/schema.js +1 -1
  114. package/dist/core/format/src/kinds/workspace/kind.js +1 -1
  115. package/dist/core/format/src/kinds/workspace/schema.d.ts +2 -2
  116. package/dist/core/format/src/kinds/workspace/schema.js +6 -5
  117. package/dist/core/format/src/parse-file.js +3 -1
  118. package/dist/core/format/src/shared/fields.d.ts +12 -8
  119. package/dist/core/format/src/shared/fields.js +48 -19
  120. package/dist/core/format/src/shared/guard.d.ts +8 -0
  121. package/dist/core/format/src/shared/guard.js +50 -1
  122. package/dist/core/format/src/shared/missing-keys.d.ts +17 -0
  123. package/dist/core/format/src/shared/missing-keys.js +110 -0
  124. package/dist/core/ports/src/agent-runs-not-available.d.ts +21 -0
  125. package/dist/core/ports/src/agent-runs-not-available.js +25 -0
  126. package/dist/core/ports/src/blob-store.d.ts +12 -0
  127. package/dist/core/ports/src/blob-store.js +22 -0
  128. package/dist/core/ports/src/chat.d.ts +8 -0
  129. package/dist/core/ports/src/connector-client.d.ts +48 -4
  130. package/dist/core/ports/src/connector-client.js +17 -0
  131. package/dist/core/ports/src/connector-start-failure.d.ts +31 -0
  132. package/dist/core/ports/src/connector-start-failure.js +32 -0
  133. package/dist/core/ports/src/connector-tool-error.d.ts +33 -0
  134. package/dist/core/ports/src/connector-tool-error.js +40 -0
  135. package/dist/core/ports/src/definition-store-left-out.d.ts +46 -0
  136. package/dist/core/ports/src/definition-store-left-out.js +47 -0
  137. package/dist/core/ports/src/definition-store.d.ts +36 -5
  138. package/dist/core/ports/src/definition-store.js +1 -1
  139. package/dist/core/ports/src/deploy-target.d.ts +358 -0
  140. package/dist/core/ports/src/deploy-target.js +2 -0
  141. package/dist/core/ports/src/harness-bridge-server.d.ts +67 -7
  142. package/dist/core/ports/src/harness-sign-in-command.d.ts +27 -0
  143. package/dist/core/ports/src/harness-sign-in-command.js +31 -0
  144. package/dist/core/ports/src/harness.d.ts +79 -15
  145. package/dist/core/ports/src/harness.js +1 -1
  146. package/dist/core/ports/src/host-settings-store.d.ts +116 -0
  147. package/dist/core/ports/src/host-settings-store.js +106 -0
  148. package/dist/core/ports/src/host-too-old.d.ts +23 -0
  149. package/dist/core/ports/src/host-too-old.js +27 -0
  150. package/dist/core/ports/src/index.d.ts +32 -13
  151. package/dist/core/ports/src/index.js +28 -8
  152. package/dist/core/ports/src/instruction-trust-store.d.ts +81 -0
  153. package/dist/core/ports/src/instruction-trust-store.js +43 -0
  154. package/dist/core/ports/src/integration.d.ts +71 -7
  155. package/dist/core/ports/src/integration.js +22 -4
  156. package/dist/core/ports/src/llm-provider.d.ts +39 -6
  157. package/dist/core/ports/src/llm-provider.js +46 -3
  158. package/dist/core/ports/src/pairing-codes.d.ts +111 -0
  159. package/dist/core/ports/src/pairing-codes.js +336 -0
  160. package/dist/core/ports/src/pairing-qr-bytes.d.ts +32 -0
  161. package/dist/core/ports/src/pairing-qr-bytes.js +116 -0
  162. package/dist/core/ports/src/password-hasher.d.ts +36 -20
  163. package/dist/core/ports/src/port-versions.d.ts +13 -6
  164. package/dist/core/ports/src/port-versions.js +14 -0
  165. package/dist/core/ports/src/program-probe.d.ts +25 -2
  166. package/dist/core/ports/src/program-probe.js +1 -1
  167. package/dist/core/ports/src/provider-default-base-url.d.ts +10 -0
  168. package/dist/core/ports/src/provider-default-base-url.js +18 -0
  169. package/dist/core/ports/src/record-store.d.ts +17 -0
  170. package/dist/core/ports/src/record-store.js +70 -0
  171. package/dist/core/ports/src/remote-control.d.ts +159 -0
  172. package/dist/core/ports/src/remote-control.js +26 -0
  173. package/dist/core/ports/src/remote-gateway-protocol.d.ts +220 -0
  174. package/dist/core/ports/src/remote-gateway-protocol.js +62 -0
  175. package/dist/core/ports/src/remote-gateway-session.d.ts +194 -0
  176. package/dist/core/ports/src/remote-gateway-session.js +241 -0
  177. package/dist/core/ports/src/run-executor.d.ts +44 -7
  178. package/dist/core/ports/src/run-executor.js +1 -1
  179. package/dist/core/ports/src/run-target-not-found.d.ts +34 -0
  180. package/dist/core/ports/src/run-target-not-found.js +41 -0
  181. package/dist/core/ports/src/sandbox-setting-store.d.ts +68 -0
  182. package/dist/core/ports/src/sandbox-setting-store.js +33 -0
  183. package/dist/core/ports/src/sandbox.d.ts +149 -13
  184. package/dist/core/ports/src/sandbox.js +52 -2
  185. package/dist/core/ports/src/secrets.d.ts +105 -1
  186. package/dist/core/ports/src/secrets.js +75 -2
  187. package/dist/core/ports/src/tool-approval-store.d.ts +50 -8
  188. package/dist/core/ports/src/tool-approval-store.js +59 -0
  189. package/dist/core/ports/src/tunnel-provider.d.ts +117 -0
  190. package/dist/core/ports/src/tunnel-provider.js +65 -0
  191. package/dist/core/ports/src/tunnel-resolver.d.ts +83 -0
  192. package/dist/core/ports/src/tunnel-resolver.js +36 -0
  193. package/dist/core/ports/src/vcs-status.d.ts +8 -0
  194. package/dist/core/ports/src/vcs-status.js +90 -0
  195. package/dist/core/ports/src/vcs.d.ts +30 -0
  196. package/dist/core/schema-kit/src/builders.d.ts +5 -0
  197. package/dist/core/schema-kit/src/builders.js +5 -0
  198. package/dist/core/std/src/amount.d.ts +13 -0
  199. package/dist/core/std/src/amount.js +22 -0
  200. package/dist/core/std/src/hidden-characters.d.ts +28 -0
  201. package/dist/core/std/src/hidden-characters.js +72 -0
  202. package/dist/core/std/src/index.d.ts +7 -0
  203. package/dist/core/std/src/index.js +7 -0
  204. package/dist/core/std/src/path-overlap.d.ts +22 -0
  205. package/dist/core/std/src/path-overlap.js +57 -0
  206. package/dist/core/std/src/public-suffixes.generated.d.ts +9 -0
  207. package/dist/core/std/src/public-suffixes.generated.js +10428 -0
  208. package/dist/core/std/src/registrable-domain.d.ts +10 -0
  209. package/dist/core/std/src/registrable-domain.js +62 -0
  210. package/dist/core/std/src/secret-variable-name.d.ts +12 -0
  211. package/dist/core/std/src/secret-variable-name.js +34 -0
  212. package/dist/core/std/src/site-name.d.ts +35 -0
  213. package/dist/core/std/src/site-name.js +111 -0
  214. package/dist/core/std/src/url-host.d.ts +35 -0
  215. package/dist/core/std/src/url-host.js +170 -0
  216. package/dist/core/std/src/word-diff.d.ts +28 -0
  217. package/dist/core/std/src/word-diff.js +77 -0
  218. package/dist/core/yaml/src/edit-data.d.ts +7 -0
  219. package/dist/core/yaml/src/edit-data.js +62 -3
  220. package/dist/core/yaml/src/edit.d.ts +7 -0
  221. package/dist/core/yaml/src/edit.js +34 -3
  222. package/dist/core/yaml/src/splice-node.d.ts +6 -0
  223. package/dist/core/yaml/src/splice-node.js +10 -0
  224. package/dist/core/yaml/src/splice.js +20 -10
  225. package/dist/testing/integration/src/checks.d.ts +5 -3
  226. package/dist/testing/integration/src/checks.js +31 -3
  227. package/dist/testing/integration/src/load.js +3 -1
  228. package/package.json +9 -2
@@ -17,9 +17,14 @@ export declare const toolApprovalStoreVersion = 1;
17
17
  * identity. The headers count too, but only as their {@link WrittenDigest},
18
18
  * because a person may have typed a token straight into one.
19
19
  * - `stdio`: the command and its arguments, the pin when the command is a
20
- * package runner, else `null`, and the environment as its
21
- * {@link WrittenDigest}, for the same reason. So a wrapper pointed at
22
- * another server through its environment asks again.
20
+ * package runner, else `null`, the folder it starts in, normalised as the
21
+ * trust content writes it (`.` when the workspace writes none), the
22
+ * environment as its {@link WrittenDigest}, for the same reason, and the
23
+ * secret environment (variable name to secret name) as its
24
+ * {@link WrittenDigest}, and the names it takes from the app's environment
25
+ * (`inheritEnv`), sorted, only when it names one. So a wrapper pointed at
26
+ * another server through its environment, its folder, another secret or
27
+ * another variable of the person's asks again.
23
28
  * - `integration`: the integration's id, its version and the settings the
24
29
  * workspace gives it, such as the `url` of an MCP server. A new version
25
30
  * asks again, because its reviewed code may talk to the server
@@ -37,7 +42,10 @@ export type ToolServer = {
37
42
  command: string;
38
43
  args: string[];
39
44
  pin: ConnectorPin | null;
45
+ cwd: string;
40
46
  env: WrittenDigest | null;
47
+ secretEnv: WrittenDigest | null;
48
+ inheritEnv?: string[];
41
49
  } | {
42
50
  kind: "integration";
43
51
  id: string;
@@ -105,6 +113,8 @@ export interface ToolApproval extends ToolApprovalKey {
105
113
  /** When the person approved it, as ISO text. */
106
114
  approvedAt: string;
107
115
  }
116
+ /** The `fingerprint` of a stored {@link ToolApproval}: `htl1:` and 64 lowercase hex digits. */
117
+ export declare const listedToolFingerprintPattern: RegExp;
108
118
  /** One version of a listed tool that waited for approval. */
109
119
  export interface WaitingVersion {
110
120
  fingerprint: ListedToolFingerprint;
@@ -153,11 +163,11 @@ export interface ToolApprovalStore {
153
163
  list(location: string, source: string): Promise<ToolApproval[]>;
154
164
  /**
155
165
  * Notes that a version of a listed tool is waiting, and returns the
156
- * versions noted for that tool, oldest first. Noting a fingerprint that
157
- * is already there keeps its first `firstSeenAt`. The store keeps at most
158
- * the newest {@link maxWaitingVersions}, so a server that changes a tool
159
- * on every call can't fill the profile. The host uses them to stop asking
160
- * about a tool its server keeps changing.
166
+ * versions noted for that tool, oldest first. The store follows
167
+ * {@link keptWaitingVersions}, so a server that changes a tool on every
168
+ * call, or lists new names on every call, can't fill the profile. The
169
+ * host uses the versions to stop asking about a tool its server keeps
170
+ * changing.
161
171
  */
162
172
  noteWaiting(key: ToolApprovalKey, version: WaitingVersion): Promise<WaitingVersion[]>;
163
173
  }
@@ -209,3 +219,35 @@ export declare class UnreadableToolApprovalError extends Error {
209
219
  export declare function isUnreadableToolApprovalError(value: unknown): value is UnreadableToolApprovalError;
210
220
  /** How many waiting versions of one listed tool a {@link ToolApprovalStore} keeps. */
211
221
  export declare const maxWaitingVersions = 8;
222
+ /**
223
+ * How many listed tools of one source a {@link ToolApprovalStore} keeps
224
+ * waiting versions for: twice the most tools one listing may return.
225
+ */
226
+ export declare const maxWaitingTools = 256;
227
+ /** How long a {@link ToolApprovalStore} keeps a waiting version after it was first seen: 24 hours. */
228
+ export declare const waitingVersionKeptMs: number;
229
+ /**
230
+ * The waiting versions of one source after noting `version` for the tool
231
+ * `name`, the one rule every {@link ToolApprovalStore} follows:
232
+ *
233
+ * - The time `version` was first seen counts as now. Every version first
234
+ * seen more than {@link waitingVersionKeptMs} before it is dropped, and so
235
+ * is a tool left with none.
236
+ * - A fingerprint that is still noted keeps its first `firstSeenAt`;
237
+ * otherwise `version` is added as the newest.
238
+ * - Each tool keeps its newest {@link maxWaitingVersions} versions.
239
+ * - The source keeps the {@link maxWaitingTools} tools whose newest version
240
+ * was first seen most recently, `name` always among them. Among tools
241
+ * whose newest versions were first seen at the same time, the one first
242
+ * in UTF-16 code-unit order is dropped first.
243
+ *
244
+ * Dropping only ever makes the host ask again, never offer a tool.
245
+ *
246
+ * @param waiting - the source's waiting versions by tool name, each oldest first; not changed
247
+ * @returns the source's waiting versions to store, and those of `name`, as `noteWaiting` returns them
248
+ * @throws RangeError when `version.firstSeenAt` isn't a date
249
+ */
250
+ export declare function keptWaitingVersions(waiting: ReadonlyMap<string, readonly WaitingVersion[]>, name: string, version: WaitingVersion): {
251
+ waiting: Map<string, WaitingVersion[]>;
252
+ versions: WaitingVersion[];
253
+ };
@@ -1,5 +1,7 @@
1
1
  /** Version of the {@link ToolApprovalStore} port. A breaking change bumps it and comes with an ADR. */
2
2
  export const toolApprovalStoreVersion = 1;
3
+ /** The `fingerprint` of a stored {@link ToolApproval}: `htl1:` and 64 lowercase hex digits. */
4
+ export const listedToolFingerprintPattern = /^htl1:[0-9a-f]{64}$/u;
3
5
  /**
4
6
  * What a {@link ToolApprovalStore} throws for an approval that exists but
5
7
  * can't be read: a damaged file, or one a newer Halonic wrote. It names the
@@ -55,3 +57,60 @@ export function isUnreadableToolApprovalError(value) {
55
57
  }
56
58
  /** How many waiting versions of one listed tool a {@link ToolApprovalStore} keeps. */
57
59
  export const maxWaitingVersions = 8;
60
+ /**
61
+ * How many listed tools of one source a {@link ToolApprovalStore} keeps
62
+ * waiting versions for: twice the most tools one listing may return.
63
+ */
64
+ export const maxWaitingTools = 256;
65
+ /** How long a {@link ToolApprovalStore} keeps a waiting version after it was first seen: 24 hours. */
66
+ export const waitingVersionKeptMs = 24 * 60 * 60 * 1000;
67
+ /**
68
+ * The waiting versions of one source after noting `version` for the tool
69
+ * `name`, the one rule every {@link ToolApprovalStore} follows:
70
+ *
71
+ * - The time `version` was first seen counts as now. Every version first
72
+ * seen more than {@link waitingVersionKeptMs} before it is dropped, and so
73
+ * is a tool left with none.
74
+ * - A fingerprint that is still noted keeps its first `firstSeenAt`;
75
+ * otherwise `version` is added as the newest.
76
+ * - Each tool keeps its newest {@link maxWaitingVersions} versions.
77
+ * - The source keeps the {@link maxWaitingTools} tools whose newest version
78
+ * was first seen most recently, `name` always among them. Among tools
79
+ * whose newest versions were first seen at the same time, the one first
80
+ * in UTF-16 code-unit order is dropped first.
81
+ *
82
+ * Dropping only ever makes the host ask again, never offer a tool.
83
+ *
84
+ * @param waiting - the source's waiting versions by tool name, each oldest first; not changed
85
+ * @returns the source's waiting versions to store, and those of `name`, as `noteWaiting` returns them
86
+ * @throws RangeError when `version.firstSeenAt` isn't a date
87
+ */
88
+ export function keptWaitingVersions(waiting, name, version) {
89
+ const now = Date.parse(version.firstSeenAt);
90
+ if (Number.isNaN(now)) {
91
+ throw new RangeError(`The waiting version's firstSeenAt isn't a date: ${version.firstSeenAt}`);
92
+ }
93
+ const recent = (noted) => now - Date.parse(noted.firstSeenAt) <= waitingVersionKeptMs;
94
+ const kept = new Map();
95
+ for (const [other, versions] of waiting) {
96
+ const left = versions.filter(recent).map((noted) => ({ ...noted }));
97
+ if (left.length > 0)
98
+ kept.set(other, left);
99
+ }
100
+ const versions = kept.get(name) ?? [];
101
+ if (!versions.some((noted) => noted.fingerprint === version.fingerprint)) {
102
+ versions.push({ fingerprint: version.fingerprint, firstSeenAt: version.firstSeenAt });
103
+ }
104
+ const toolVersions = versions.slice(-maxWaitingVersions);
105
+ kept.set(name, toolVersions);
106
+ if (kept.size > maxWaitingTools) {
107
+ const lastNoted = (versions) => Math.max(...versions.map((noted) => Date.parse(noted.firstSeenAt)));
108
+ const others = [...kept]
109
+ .filter(([other]) => other !== name)
110
+ .sort(([leftName, left], [rightName, right]) => lastNoted(left) - lastNoted(right) || (leftName < rightName ? -1 : 1));
111
+ for (const [other] of others.slice(0, kept.size - maxWaitingTools)) {
112
+ kept.delete(other);
113
+ }
114
+ }
115
+ return { waiting: kept, versions: toolVersions.map((noted) => ({ ...noted })) };
116
+ }
@@ -0,0 +1,117 @@
1
+ /** Version of the {@link TunnelProvider} port. A breaking change bumps it and comes with an ADR. */
2
+ export declare const tunnelProviderVersion = 1;
3
+ /** The four states a tunnel reports, in the order a healthy start passes through the first two. */
4
+ export declare const tunnelStates: readonly ["starting", "ready", "degraded", "down"];
5
+ /** One of {@link tunnelStates}. */
6
+ export type TunnelState = (typeof tunnelStates)[number];
7
+ /**
8
+ * Why a tunnel is `degraded` or `down`. Studio words each code; there is no
9
+ * free-text fallback, so a provider maps its own errors onto this list.
10
+ */
11
+ export declare const tunnelReasons: readonly ["not-installed", "signed-out", "offline", "provider-error", "public-refused", "stopped"];
12
+ /** One of {@link tunnelReasons}. */
13
+ export type TunnelReason = (typeof tunnelReasons)[number];
14
+ /** What a provider can do, read before `start` so Studio can explain the choice. */
15
+ export interface TunnelCapabilities {
16
+ /** The provider's id, such as "tailscale", "lan" or "fake". */
17
+ readonly id: string;
18
+ /**
19
+ * `true` when the endpoint can be reached from the public internet (a
20
+ * Cloudflare quick tunnel, Tailscale Funnel). Studio treats such a host as
21
+ * public; the remote gateway still accepts only paired devices.
22
+ */
23
+ readonly public: boolean;
24
+ /**
25
+ * `true` when the provider encrypts the path itself (WireGuard, TLS). The
26
+ * gateway protocol always runs inside Halonic's own end-to-end session as
27
+ * well, so this never replaces it.
28
+ */
29
+ readonly encryptsPath: boolean;
30
+ }
31
+ /**
32
+ * The one thing a tunnel may point at: the remote gateway, on loopback. The
33
+ * host is a literal loopback address, so a config can't name another
34
+ * interface. The bridge, the model gateway, MCP servers and secrets never get
35
+ * a `TunnelConfig` (ADR "Only the remote gateway is reachable by a tunnel").
36
+ */
37
+ export interface TunnelConfig {
38
+ readonly gateway: {
39
+ readonly host: "127.0.0.1" | "::1";
40
+ readonly port: number;
41
+ };
42
+ }
43
+ /**
44
+ * Checks at runtime what {@link TunnelConfig} says at compile time, for a
45
+ * config read from JSON or a setting: exactly a `gateway` with exactly a
46
+ * loopback `host` and a whole-number `port` from 1 to 65535. Throws a
47
+ * `RangeError` otherwise. Every provider's `start` rejects such a config.
48
+ */
49
+ export declare function assertTunnelConfig(config: unknown): asserts config is TunnelConfig;
50
+ /**
51
+ * The host's check before it calls `TunnelProvider.start`: the config passes
52
+ * {@link assertTunnelConfig} and its port is `gatewayPort`, the port the
53
+ * host's own remote gateway listener is bound to. Any other port (the
54
+ * bridge's, the model gateway's) throws a `RangeError`, so the provider is
55
+ * never called for it.
56
+ */
57
+ export declare function assertGatewayTunnelConfig(config: unknown, gatewayPort: number): asserts config is TunnelConfig;
58
+ /**
59
+ * Where a phone reaches the gateway. `url` uses `https:`, `wss:` or `tcp:`;
60
+ * plain `http:` and `ws:` are never given, so an iOS client needs no
61
+ * exception. A `tcp:` stream carries only the end-to-end session.
62
+ */
63
+ export interface TunnelEndpoint {
64
+ /** The provider that made the endpoint, the same as `TunnelCapabilities.id`. */
65
+ readonly providerId: string;
66
+ readonly url: string;
67
+ /** The same as `TunnelCapabilities.public` for this provider. */
68
+ readonly public: boolean;
69
+ }
70
+ /** One change of a tunnel's state. `reason` is set exactly when `state` is `degraded` or `down`. */
71
+ export type TunnelStatus = {
72
+ readonly state: "starting" | "ready";
73
+ readonly at: string;
74
+ } | {
75
+ readonly state: "degraded" | "down";
76
+ readonly reason: TunnelReason;
77
+ readonly at: string;
78
+ };
79
+ /**
80
+ * Makes the remote gateway reachable from a phone, and nothing more: it
81
+ * carries bytes. Pairing, encryption and what a phone may do are not its
82
+ * concern (tunnel phase A; requirement `ports.tunnel-provider`).
83
+ *
84
+ * `start` rejects with a `RangeError` a config that fails
85
+ * {@link assertTunnelConfig}. The host calls {@link assertGatewayTunnelConfig}
86
+ * before `start`, so no other port ever reaches a provider. The endpoint's
87
+ * `public` equals `capabilities().public`.
88
+ *
89
+ * A provider handles one tunnel at a time. `start` while a tunnel is up
90
+ * returns its endpoint unchanged when the config is the same, and rejects
91
+ * with a `RangeError` when it isn't. A provider that would expose the gateway
92
+ * publicly while `capabilities().public` is `false` refuses with status
93
+ * `down`, reason `public-refused`, instead of starting.
94
+ *
95
+ * @example
96
+ * const config = { gateway: { host: "127.0.0.1", port: gateway.port } };
97
+ * assertGatewayTunnelConfig(config, gateway.port);
98
+ * const endpoint = await provider.start(config);
99
+ * for await (const status of provider.status()) indicator.show(status.state);
100
+ */
101
+ export interface TunnelProvider {
102
+ capabilities(): Promise<TunnelCapabilities>;
103
+ /**
104
+ * Opens the tunnel and resolves with its endpoint once the state is
105
+ * `ready`. Rejects when the tunnel goes `down` first; the status stream
106
+ * says why.
107
+ */
108
+ start(config: TunnelConfig): Promise<TunnelEndpoint>;
109
+ /**
110
+ * The current state first, then every change, never the same state and
111
+ * reason twice in a row. Each call gives a new stream. A stream ends after
112
+ * `stop` has reported `down` with reason `stopped`.
113
+ */
114
+ status(): AsyncIterable<TunnelStatus>;
115
+ /** Closes the tunnel. Calling it when no tunnel is up does nothing. */
116
+ stop(): Promise<void>;
117
+ }
@@ -0,0 +1,65 @@
1
+ /** Version of the {@link TunnelProvider} port. A breaking change bumps it and comes with an ADR. */
2
+ export const tunnelProviderVersion = 1;
3
+ /** The four states a tunnel reports, in the order a healthy start passes through the first two. */
4
+ export const tunnelStates = ["starting", "ready", "degraded", "down"];
5
+ /**
6
+ * Why a tunnel is `degraded` or `down`. Studio words each code; there is no
7
+ * free-text fallback, so a provider maps its own errors onto this list.
8
+ */
9
+ export const tunnelReasons = [
10
+ "not-installed",
11
+ "signed-out",
12
+ "offline",
13
+ "provider-error",
14
+ "public-refused",
15
+ "stopped",
16
+ ];
17
+ const loopbackHosts = ["127.0.0.1", "::1"];
18
+ function isPort(value) {
19
+ return Number.isInteger(value) && value >= 1 && value <= 65_535;
20
+ }
21
+ /**
22
+ * Checks at runtime what {@link TunnelConfig} says at compile time, for a
23
+ * config read from JSON or a setting: exactly a `gateway` with exactly a
24
+ * loopback `host` and a whole-number `port` from 1 to 65535. Throws a
25
+ * `RangeError` otherwise. Every provider's `start` rejects such a config.
26
+ */
27
+ export function assertTunnelConfig(config) {
28
+ const why = tunnelConfigProblem(config);
29
+ if (why !== undefined)
30
+ throw new RangeError(`not a tunnel config: ${why}`);
31
+ }
32
+ function tunnelConfigProblem(config) {
33
+ if (typeof config !== "object" || config === null)
34
+ return "not an object";
35
+ if (Object.keys(config).join() !== "gateway")
36
+ return "it has fields other than gateway";
37
+ const { gateway } = config;
38
+ if (typeof gateway !== "object" || gateway === null)
39
+ return "gateway is not an object";
40
+ if (Object.keys(gateway).sort().join() !== "host,port") {
41
+ return "gateway is not exactly host and port";
42
+ }
43
+ const { host, port } = gateway;
44
+ if (!loopbackHosts.includes(host))
45
+ return `host is not 127.0.0.1 or ::1: ${String(host)}`;
46
+ if (!isPort(port))
47
+ return `port is not a whole number from 1 to 65535: ${String(port)}`;
48
+ return undefined;
49
+ }
50
+ /**
51
+ * The host's check before it calls `TunnelProvider.start`: the config passes
52
+ * {@link assertTunnelConfig} and its port is `gatewayPort`, the port the
53
+ * host's own remote gateway listener is bound to. Any other port (the
54
+ * bridge's, the model gateway's) throws a `RangeError`, so the provider is
55
+ * never called for it.
56
+ */
57
+ export function assertGatewayTunnelConfig(config, gatewayPort) {
58
+ if (!isPort(gatewayPort)) {
59
+ throw new RangeError(`gateway port is not a whole number from 1 to 65535: ${gatewayPort}`);
60
+ }
61
+ assertTunnelConfig(config);
62
+ if (config.gateway.port !== gatewayPort) {
63
+ throw new RangeError(`a tunnel may point only at the remote gateway on port ${gatewayPort}, not ${config.gateway.port}`);
64
+ }
65
+ }
@@ -0,0 +1,83 @@
1
+ import type { TunnelEndpoint } from "./tunnel-provider.js";
2
+ /** Version of the {@link TunnelResolver} port. A breaking change bumps it and comes with an ADR. */
3
+ export declare const tunnelResolverVersion = 1;
4
+ /**
5
+ * How a transport waits between tries to reconnect: `firstDelayMs` after the
6
+ * first drop, times `factor` after each failed try, a base of at most
7
+ * `maxDelayMs`, each delay moved by up to `jitter` of itself either way (so
8
+ * up to 36 s). A connection that stays
9
+ * open for `resetAfterMs` starts again from `firstDelayMs`.
10
+ */
11
+ export declare const tunnelBackoff: {
12
+ readonly firstDelayMs: 500;
13
+ readonly factor: 2;
14
+ readonly maxDelayMs: 30000;
15
+ readonly jitter: 0.2;
16
+ readonly resetAfterMs: 30000;
17
+ };
18
+ /**
19
+ * The delay before reconnect try `attempt` (1 for the first try after a
20
+ * drop), by {@link tunnelBackoff}. `random` is a number from 0 up to (not
21
+ * including) 1, such as `Math.random()`; 0.5 gives the delay without jitter.
22
+ * Any other `random` (NaN, negative, 1 or more) throws a `RangeError`, since
23
+ * a timer would read the NaN or negative delay as 0 and reconnect in a tight
24
+ * loop. Every transport uses this one rule, so phones and the fake provider
25
+ * back off alike.
26
+ */
27
+ export declare function tunnelReconnectDelayMs(attempt: number, random: number): number;
28
+ /**
29
+ * A transport's state. `paused` means the app went to the background: the
30
+ * transport closed its connection and doesn't try again until `resume`.
31
+ */
32
+ export type TunnelTransportState = "connecting" | "open" | "reconnecting" | "paused" | "closed";
33
+ /**
34
+ * A byte pipe from the phone to one host's remote gateway, reconnecting by
35
+ * itself. It carries the end-to-end session's frames and never reads them.
36
+ *
37
+ * **Reconnect.** When the connection drops, the state goes to `reconnecting`
38
+ * and the transport tries again after {@link tunnelReconnectDelayMs}, without
39
+ * a limit on tries, for as long as the app is in the foreground. A frame sent
40
+ * while not `open` rejects; frames are never queued or sent again after a
41
+ * reconnect. Each reconnect is a new connection: the session layer starts a
42
+ * new handshake and the gateway protocol resumes its sessions from the last
43
+ * event it saw.
44
+ *
45
+ * **Foreground only.** `pause` closes the connection and stops every timer,
46
+ * because a phone (iOS above all) may freeze a background app at any moment.
47
+ * `resume` connects at once, with no delay, and starts the backoff from the
48
+ * first try.
49
+ */
50
+ export interface TunnelTransport {
51
+ readonly state: TunnelTransportState;
52
+ /** Calls `listener` on each change of state; returns a function that stops it. */
53
+ onState(listener: (state: TunnelTransportState) => void): () => void;
54
+ /** Sends one frame. Rejects unless the state is `open`. */
55
+ send(frame: Uint8Array): Promise<void>;
56
+ /**
57
+ * Every frame received, in order, across reconnects. The stream ends when
58
+ * the transport is closed.
59
+ */
60
+ frames(): AsyncIterable<Uint8Array>;
61
+ /** Closes the connection and stops reconnecting until {@link resume}. */
62
+ pause(): void;
63
+ /** Connects again at once after {@link pause}; does nothing in any other state. */
64
+ resume(): void;
65
+ /** Closes the transport for good; the state becomes `closed`. */
66
+ close(): Promise<void>;
67
+ }
68
+ /**
69
+ * Turns an endpoint from a pairing into a transport, on the phone (tunnel
70
+ * phase A; requirement `ports.tunnel-resolver`). It refuses with a
71
+ * `RangeError` an endpoint whose URL scheme isn't `https:`, `wss:` or `tcp:`.
72
+ *
73
+ * @example
74
+ * const transport = await resolver.resolve(pairing.endpoint);
75
+ * app.onBackground(() => transport.pause());
76
+ */
77
+ export interface TunnelResolver {
78
+ /**
79
+ * Resolves once the first connection is `open`, or rejects when the first
80
+ * try fails; only a connection that was open once reconnects by itself.
81
+ */
82
+ resolve(endpoint: TunnelEndpoint): Promise<TunnelTransport>;
83
+ }
@@ -0,0 +1,36 @@
1
+ /** Version of the {@link TunnelResolver} port. A breaking change bumps it and comes with an ADR. */
2
+ export const tunnelResolverVersion = 1;
3
+ /**
4
+ * How a transport waits between tries to reconnect: `firstDelayMs` after the
5
+ * first drop, times `factor` after each failed try, a base of at most
6
+ * `maxDelayMs`, each delay moved by up to `jitter` of itself either way (so
7
+ * up to 36 s). A connection that stays
8
+ * open for `resetAfterMs` starts again from `firstDelayMs`.
9
+ */
10
+ export const tunnelBackoff = {
11
+ firstDelayMs: 500,
12
+ factor: 2,
13
+ maxDelayMs: 30_000,
14
+ jitter: 0.2,
15
+ resetAfterMs: 30_000,
16
+ };
17
+ /**
18
+ * The delay before reconnect try `attempt` (1 for the first try after a
19
+ * drop), by {@link tunnelBackoff}. `random` is a number from 0 up to (not
20
+ * including) 1, such as `Math.random()`; 0.5 gives the delay without jitter.
21
+ * Any other `random` (NaN, negative, 1 or more) throws a `RangeError`, since
22
+ * a timer would read the NaN or negative delay as 0 and reconnect in a tight
23
+ * loop. Every transport uses this one rule, so phones and the fake provider
24
+ * back off alike.
25
+ */
26
+ export function tunnelReconnectDelayMs(attempt, random) {
27
+ if (!Number.isInteger(attempt) || attempt < 1) {
28
+ throw new RangeError(`attempt must be a whole number from 1: ${attempt}`);
29
+ }
30
+ if (!(random >= 0 && random < 1)) {
31
+ throw new RangeError(`random must be from 0 up to (not including) 1: ${random}`);
32
+ }
33
+ const { firstDelayMs, factor, maxDelayMs, jitter } = tunnelBackoff;
34
+ const base = Math.min(maxDelayMs, firstDelayMs * factor ** (attempt - 1));
35
+ return Math.round(base * (1 + jitter * (2 * random - 1)));
36
+ }
@@ -0,0 +1,8 @@
1
+ import type { VcsStatus } from "./vcs.js";
2
+ /**
3
+ * Reads the output of `git status --porcelain=v2 -z`, with or without `--branch`: the branch
4
+ * header lines, if any, then one record per changed path. A path changed both in the index and
5
+ * in the working tree gives two changes, one staged and one not. The result is for a repository;
6
+ * a folder that isn't one is for the caller to tell.
7
+ */
8
+ export declare function parseStatus(output: string): VcsStatus;
@@ -0,0 +1,90 @@
1
+ /** What one letter of a porcelain `XY` field means; `.` is no change. */
2
+ const letterStatus = {
3
+ M: "modified",
4
+ T: "modified",
5
+ A: "added",
6
+ C: "added",
7
+ D: "deleted",
8
+ R: "renamed",
9
+ };
10
+ /** The spaces before the path in an ordinary (`1`), renamed (`2`) and conflicted (`u`) record. */
11
+ const pathAfterSpaces = { "1": 8, "2": 9, u: 10 };
12
+ /**
13
+ * Reads the output of `git status --porcelain=v2 -z`, with or without `--branch`: the branch
14
+ * header lines, if any, then one record per changed path. A path changed both in the index and
15
+ * in the working tree gives two changes, one staged and one not. The result is for a repository;
16
+ * a folder that isn't one is for the caller to tell.
17
+ */
18
+ export function parseStatus(output) {
19
+ const status = {
20
+ isRepo: true,
21
+ branch: null,
22
+ upstream: null,
23
+ ahead: 0,
24
+ behind: 0,
25
+ changes: [],
26
+ };
27
+ const fields = output.split("\0");
28
+ for (let at = 0; at < fields.length; at++) {
29
+ const field = fields[at] ?? "";
30
+ if (field.startsWith("# "))
31
+ readHeader(field.slice(2), status);
32
+ else if (field.startsWith("1 "))
33
+ status.changes.push(...ordinary(field, pathAfterSpaces["1"]));
34
+ else if (field.startsWith("2 ")) {
35
+ // A rename's old path is the next field.
36
+ at += 1;
37
+ status.changes.push(...ordinary(field, pathAfterSpaces["2"], fields[at]));
38
+ }
39
+ else if (field.startsWith("u ")) {
40
+ status.changes.push({
41
+ path: pathAfter(field, pathAfterSpaces.u),
42
+ status: "conflicted",
43
+ staged: false,
44
+ });
45
+ }
46
+ else if (field.startsWith("? ")) {
47
+ status.changes.push({ path: field.slice(2), status: "untracked", staged: false });
48
+ }
49
+ }
50
+ return status;
51
+ }
52
+ function readHeader(header, status) {
53
+ const space = header.indexOf(" ");
54
+ const name = header.slice(0, space);
55
+ const value = header.slice(space + 1);
56
+ if (name === "branch.head")
57
+ status.branch = value === "(detached)" ? null : value;
58
+ if (name === "branch.upstream")
59
+ status.upstream = value;
60
+ if (name === "branch.ab") {
61
+ const match = /^\+(\d+) -(\d+)$/u.exec(value);
62
+ status.ahead = Number(match?.[1] ?? 0);
63
+ status.behind = Number(match?.[2] ?? 0);
64
+ }
65
+ }
66
+ /** The changes of an ordinary or renamed record: one for the index letter, one for the tree's. */
67
+ function ordinary(field, spaces, from) {
68
+ const path = pathAfter(field, spaces);
69
+ const changes = [];
70
+ for (const [letter, staged] of [
71
+ [field.charAt(2), true],
72
+ [field.charAt(3), false],
73
+ ]) {
74
+ const status = letterStatus[letter];
75
+ if (status === undefined)
76
+ continue;
77
+ const change = { path, status, staged };
78
+ if (status === "renamed" && from !== undefined)
79
+ change.from = from;
80
+ changes.push(change);
81
+ }
82
+ return changes;
83
+ }
84
+ /** The text after the first `spaces` spaces of a record: the path, which may hold spaces itself. */
85
+ function pathAfter(field, spaces) {
86
+ let at = 0;
87
+ for (let found = 0; found < spaces; found++)
88
+ at = field.indexOf(" ", at) + 1;
89
+ return field.slice(at);
90
+ }
@@ -85,6 +85,25 @@ export interface VcsFileDiff {
85
85
  /** Unified diff of the file, in git's format. */
86
86
  diff: string;
87
87
  }
88
+ /**
89
+ * Where this branch and its upstream stand when both have commits the other
90
+ * lacks, and the items both changed.
91
+ */
92
+ export interface VcsDivergence {
93
+ /** This branch's last commit. */
94
+ ours: string;
95
+ /** The upstream's last commit, as fetched: a full commit id `readAt` takes. */
96
+ theirs: string;
97
+ /** The last commit both have: where they parted. */
98
+ base: string;
99
+ /**
100
+ * Paths, sorted, that both sides changed since `base` (added, edited or
101
+ * deleted) and now hold differently: the items a person must choose for.
102
+ * A file only one side changed, or both changed the same way, isn't listed.
103
+ * Private entries are left out.
104
+ */
105
+ items: string[];
106
+ }
88
107
  /** How `applyPatch` applies a patch. */
89
108
  export interface VcsApplyOptions {
90
109
  /** Undo the patch instead: what discarding one hunk does. */
@@ -384,6 +403,17 @@ export interface Vcs {
384
403
  * @throws when the branch and its upstream have both moved on; nothing is merged
385
404
  */
386
405
  pull(): Promise<void>;
406
+ /**
407
+ * Fetches the upstream, then says where the branch and it parted, when
408
+ * `pull` would refuse because both have new commits; `null` when it
409
+ * wouldn't (nothing new either way, or only one side has commits). Changes
410
+ * no branch, no file and no index; only the fetched commits are new. The
411
+ * remote and the branch come from the repository, as for `pull`.
412
+ *
413
+ * @throws when there is no upstream, the fetch fails, or the two share no
414
+ * commit
415
+ */
416
+ diverged(): Promise<VcsDivergence | null>;
387
417
  /**
388
418
  * Sends the branch's commits to its upstream, or to the first remote (which
389
419
  * becomes the upstream) when it has none.
@@ -45,6 +45,11 @@ export declare const s: {
45
45
  readonly lazy: typeof z.lazy;
46
46
  /** Any JSON value: null, a boolean, a finite number, text, or a list or map of JSON values. */
47
47
  readonly json: typeof z.json;
48
+ /**
49
+ * Changes the input before the schema checks it, such as a number into
50
+ * text, so the schema's own message applies. JSON Schema describes the schema.
51
+ */
52
+ readonly preprocess: typeof z.preprocess;
48
53
  /** An absolute `http` or `https` URL as `URL` writes it; see `URL_PATTERN`. */
49
54
  readonly url: () => z.ZodString;
50
55
  };
@@ -67,6 +67,11 @@ export const s = {
67
67
  lazy: z.lazy,
68
68
  /** Any JSON value: null, a boolean, a finite number, text, or a list or map of JSON values. */
69
69
  json: z.json,
70
+ /**
71
+ * Changes the input before the schema checks it, such as a number into
72
+ * text, so the schema's own message applies. JSON Schema describes the schema.
73
+ */
74
+ preprocess: z.preprocess,
70
75
  /** An absolute `http` or `https` URL as `URL` writes it; see `URL_PATTERN`. */
71
76
  url: () => z.string().regex(URL_PATTERN, "must be an http or https URL as URL writes it"),
72
77
  };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Reads an amount the way someone writes it on a receipt: digits, and at
3
+ * most one `.` or `,` before the decimals. No sign, no grouping, no
4
+ * exponent. A single separator is always the decimal one, so `1,000` is 1.
5
+ *
6
+ * @param text - what the user typed; surrounding spaces are ignored
7
+ * @returns the amount, or `undefined` for empty or anything else
8
+ *
9
+ * @example
10
+ * parseAmount("15,00"); // 15
11
+ * parseAmount("1.000,50"); // undefined
12
+ */
13
+ export declare function parseAmount(text: string): number | undefined;