@bowmark/web 1.25.2 → 1.25.4

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.
package/README.md CHANGED
@@ -52,8 +52,8 @@ This is everything you need to write code that calls Bowmark:
52
52
  - **[Configuration](#configuration)** — How to pass your API key and other options
53
53
 
54
54
  Stop here if you just need to call the library. What exists to call is listed in
55
- [`CAPABILITIES.md`](https://github.com/bowmark-ai/web/blob/main/CAPABILITIES.md) and
56
- [`PROVIDERS.md`](https://github.com/bowmark-ai/web/blob/main/PROVIDERS.md) — absolute
55
+ [`CAPABILITIES.md`](https://raw.githubusercontent.com/bowmark-ai/web/main/CAPABILITIES.md) and
56
+ [`PROVIDERS.md`](https://raw.githubusercontent.com/bowmark-ai/web/main/PROVIDERS.md) — absolute
57
57
  URLs, because this README is read on npm where a relative link resolves to nothing.
58
58
 
59
59
  ---
@@ -186,237 +186,6 @@ A caller header cannot displace the key.
186
186
 
187
187
  ## For maintainers of this package
188
188
 
189
- Everything below describes how `@bowmark/web` is built, generated and published. Skip
190
- this section unless you are changing how the SDK itself works.
191
-
192
- ## Internals — how this package is built, generated and published
193
-
194
- Everything above is what you need to call the library. Everything below is for someone
195
- working on this package itself — the generator, the guards, the publish pipeline. Skip
196
- it unless you're changing how the SDK is built.
197
-
198
- ### The two halves, and why they are split
199
-
200
- - **`src/{index,session,transport,guard,validate}.ts`** — hand-written, ~700 lines,
201
- changes almost never.
202
- - **`src/generated/library.d.ts`** — every capability and provider, generated,
203
- committed, regenerated whenever a unit lands.
204
- - **`src/generated/validators.ts`** — the same functions' argument shapes as DATA, for
205
- the runtime half of the same job.
206
-
207
- The generated half is **ambient**: it declares globals and exports nothing, and
208
- `index.ts` reaches it with a `/// <reference>`. An `import` would make it a module, every
209
- declaration in it would stop being global, and the churn split would buy nothing — the
210
- types would become a real dependency of the client. `@cloudflare/workers-types` and
211
- `@types/node` are the precedent.
212
-
213
- `index.ts` therefore **aliases** rather than re-exports (`export type Library =
214
- BowmarkLibrary`). A global from an ambient file is not a local declaration, so
215
- `export type { BowmarkLibrary }` is `TS2661`.
216
-
217
- **The same declarations describe TWO implementations, deliberately.** `bowmark` exported
218
- here is a real Proxy over HTTP in the caller's process; `bowmark` inside a `run()` script
219
- is the sandbox's own global (`packages/runtime/src/namespace.ts`) in an isolate on ours.
220
- The types are generated once and describe both, so the two must stay in sync.
221
-
222
- **The Proxy accepts every name at runtime** — `bowmark.anything.at.all()` builds a path
223
- and sends it. That is not a bug; it is why the generated types are load-bearing rather
224
- than decorative. The Proxy makes a correct call work without enumerating half a million
225
- names, and TypeScript makes a wrong one a compile error. Neither half is sufficient
226
- alone. It does refuse two things locally: a path shorter than `<unit>.<fn>`, and an
227
- argument the wire cannot carry.
228
-
229
- **A proxy node answers `undefined` for `then`, `catch`, `finally` and `toJSON`.** Without
230
- that, `await bowmark.music` would find a callable `then`, invoke it as a thenable, and
231
- hang forever waiting for a resolve a path segment can never call.
232
-
233
- ### The wire guard is a checked COPY
234
-
235
- `src/guard.ts` duplicates `wireProblem` from `packages/schema/src/wire.ts`, because
236
- importing the workspace package would break the tarball for everyone outside this repo.
237
- A copy drifts, so `tests/unit/bowmark-web-guard.test.ts` runs both over one fixture
238
- table and asserts identical `{ path, reason }` for every entry. Add a refusal to
239
- `wire.ts` and this fails by name.
240
-
241
- It is a walk, not a `try { JSON.stringify(args) }`: stringify throws on exactly two
242
- things (a circular structure and a `BigInt`) and silently mangles everything else —
243
- `Date` → string, `Map`/`Set` → `{}`, class instance → plain object, function-valued key
244
- → dropped. Temporal shipped that exact bug, diagnosed it as a typing problem, and closed
245
- it won't-fix.
246
-
247
- ### The argument guard is TWO guards, in this order
248
-
249
- `assertWireSafeArgs` asks whether the value can cross at all — a `Date`, a `Map`, a
250
- function, a circular structure. `assertArgShape` asks whether it matches what the
251
- function declares. Wire first, always: shape-first would report a `Date` as "expected a
252
- string" and send the caller after the wrong bug.
253
-
254
- The shape half is `src/generated/validators.ts` (data, generated from the same manifest
255
- as the declarations) read by `src/validate.ts` (one interpreter, ~250 lines). Not 192
256
- emitted functions: 192 emitted functions are 192 pieces of code no test ever runs, and
257
- one interpreter over a fixture table is testable. No validator library on either side —
258
- zero runtime dependencies is the product.
259
-
260
- **Every rule leans toward ACCEPTING, and that is the design.** A false refusal is a
261
- caller whose correct argument their own client rejects, with no server to appeal to. A
262
- false accept costs one round trip and lands them exactly where they were before this
263
- existed. So:
264
-
265
- - **An object is OPEN.** An unlisted property is accepted — TypeScript's
266
- excess-property check fires on literals only, and a caller who spread a wider object
267
- is doing something legal.
268
- - **Anything the compiler could not model becomes `any`** and accepts everything. It
269
- never guesses a shape from a name, and `Required<T>` compiles to `T` rather than to
270
- T-with-everything-mandatory, because widening is free and narrowing is not.
271
- - **Arity is checked DOWNWARD only.** A missing required argument is refused; a surplus
272
- one is not, because that is what a caller on a version older than a new parameter has.
273
- - **A union reports the arm the value got FURTHEST into.** `string | { query: string }`
274
- given `{ query: 5 }` names `args[0].query`, not six arms and no location.
275
-
276
- The one deliberate strictness is a string literal union (`sort?: "hot" | "new"`), because
277
- a typo'd enum value is the commonest wrong argument and the accepted set is a legible
278
- message.
279
-
280
- **What it fails CLOSED on, and the two things it must not.** A known unit with an
281
- unknown FUNCTION is refused — the table is authoritative about a unit it carries. An
282
- unknown UNIT passes straight through, because a family MEMBER (`providers.gymshark`) is
283
- absent from the RUNTIME validator table **by design** — `listProviders()` excludes
284
- members and always will — so refusing an unknown unit would refuse the largest part of
285
- the library. A function with no readable argument shape is an EXPLICIT `null` in the
286
- table rather than an absence, and passes through; that distinction is what makes the
287
- first rule safe at all.
288
-
289
- Note the deliberate asymmetry with the TYPES: since 2026-08-06 a member IS declared in
290
- `library.d.ts`, so `providers.gymshark.search(…)` completes and type-checks. The two
291
- answer different questions. Types are a build-time artifact and can afford one line per
292
- member; the validator table is loaded into every client process at runtime, where 51,711
293
- entries would be a cost paid on every call to buy nothing — the family's arguments are
294
- already checked by the shared interface the compiler saw.
295
-
296
- **A parameter may not offer a type the wire cannot carry.** Every argument crosses as
297
- JSON on every surface, so `requestedTime?: string | Date` has an arm refused 100% of the
298
- time while the library says otherwise. `gate:public-types`' `wire-impossible-param`
299
- refuses one, with no exception set — an exception would be a declaration that a
300
- parameter is uncallable. Found once, on `pizzahut.priceOrder`, by generating validators
301
- for all 253 typed parameters.
302
-
303
- ### What ships is compiled, not `src/` verbatim
304
-
305
- `main`/`types` point at `dist/index.{js,d.ts}`. `dist/` is never committed — it does not
306
- exist in this workspace and does not exist in the public mirror's git history either — it
307
- is produced once, in the mirror's own `publish.yml`, by `npm run build`
308
- (`scripts/build.mjs`, `tsconfig.build.json`), immediately before `npm publish`. Nobody
309
- runs it but that one CI job:
310
-
311
- - **This workspace never does.** `pnpm typecheck` is `tsc -p tsconfig.json --noEmit` —
312
- reads `src/` directly, emits nothing, unaffected.
313
- - **A consumer never does.** `npm i @bowmark/web` installs the already-compiled `dist/`;
314
- there is still no build step on their side, which is the property this package has
315
- always promised.
316
-
317
- Why compiled at all: Node refuses to strip types out of a `.ts` file found inside
318
- `node_modules`, so shipping `main: src/index.ts` made plain `node app.mjs` fail with
319
- `ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING` for every consumer who was not already on
320
- `tsx`, Bun, or a bundler.
321
- `docs/decisions/2026-09-01-the-published-npm-client-ships-compiled-js.md` in Bowmark's
322
- internal engineering repo (not public).
323
-
324
- **One thing `tsc`'s declaration emit does not do on its own, and `build.mjs` does by
325
- hand:** `src/generated/library.d.ts` is ambient (no imports, no exports — see below) and
326
- `index.ts` reaches it only with `/// <reference path="./generated/library.d.ts" />`. tsc
327
- consumes that directive for this package's own compile but does not carry it into the
328
- emitted `dist/index.d.ts`. Left alone, a downstream `tsc` never loads `library.d.ts` at
329
- all and `BowmarkLibrary` — the type this package exists to ship — reads as `Cannot find
330
- name`. `build.mjs` re-inserts the reference line and copies `library.d.ts` into
331
- `dist/generated/` verbatim (it has nothing to compile).
332
-
333
- ### Regenerating
334
-
335
- ```bash
336
- pnpm run gen:public-types # writes src/generated/{library.d.ts,validators.ts}
337
- pnpm run gate:public-types # fails on a leak, a new refusal, a wire-impossible type
338
- pnpm run gate:public-types:drift # …and on the committed copy being stale
339
- ```
340
-
341
- **Only the middle one runs on your PR, and staleness is deliberately not fatal there.**
342
- The committed copy goes stale every time any unit anywhere lands a function, which is not
343
- something your branch can keep true — `regen-public-types.yml` repairs it on `main`. See
344
- `.claude/rules/public-types.md` § The gate is SPLIT.
345
-
346
- **`skipLibCheck: false` in this package's `tsconfig.json` is load-bearing**, and the base
347
- config sets the opposite. That flag skips type checking of every `.d.ts`, and this
348
- package's whole deliverable IS a `.d.ts` — with the inherited default, `pnpm typecheck`
349
- reported green over a generated file carrying 40 unresolved type names. Do not "tidy" it
350
- back to the inherited value.
351
-
352
- **`incremental: false` in the same file is load-bearing too, for the identical class of
353
- bug reaching a different config.** `tsconfig.build.json` already disables it, with its own
354
- comment explaining a stale `.tsbuildinfo` silently skipping a publish-time compile;
355
- `tsconfig.json` — the one CI's `Typecheck` step and `pnpm typecheck` actually use — needs
356
- the same override because `library.d.ts` regenerates every 20-60 minutes on `main` while
357
- `index.ts`/`session.ts` rarely change, and CI persists a `.tsbuildinfo` PER RUNNER AGENT
358
- across unrelated commits (`ci.yml`'s incremental-cache restore/save steps). tsc's weaker
359
- tracking of a triple-slash ambient reference (vs. a real import) let a stale buildinfo
360
- report `Cannot find name 'BowmarkLibrary'` on unchanged code, sticky to whichever runner
361
- happened to cache it — measured 4 times in 4 days on one agent, once costing a full day of
362
- client releases. `agents/richard/problems/runner-5-bowmarklibrary-typecheck-flake.md`. Do
363
- not re-enable it to chase the incremental typecheck speedup other packages get; this
364
- package is two files and the savings do not apply.
365
-
366
- The file is **committed**, for the reason the tier barrels are: this repo consumes
367
- TypeScript with no build step, so a generate-at-build artifact leaves `tsc` and vitest
368
- with nothing to read on a fresh clone. Committed plus a staleness gate is the only shape
369
- that works. Never hand-edit it.
370
-
371
- ### Four things the generator does that look like bugs and are not
372
-
373
- **One namespace per unit.** `music` and `flights` both declare `CallOptions`; `Track` and
374
- `Store` are names any provider may take. Each unit's `types` block is emitted VERBATIM
375
- inside `declare namespace BowmarkCapability_<id>` / `BowmarkProvider_<id>`, so a signature
376
- reading `Promise<MusicSearchResult>` resolves against its own block with no rewriting.
377
- Verbatim is the property that matters: what a caller compiles against is byte-for-byte
378
- what an agent reads from `get_library`.
379
-
380
- **The tier is in the namespace name.** `cars` is a capability AND a provider. A single
381
- `Bowmark_cars` would have emitted one and silently dropped the other.
382
-
383
- **20 provider functions are deliberately absent**, and none gets a
384
- `(...args: unknown[])` stand-in — a stand-in compiles, ships, and tells a caller nothing,
385
- which is the untyped surface this package exists to replace. They stay callable at
386
- runtime; only the compile-time claim is withheld, because there is no claim to make.
387
- Each one has a comment in its place saying which class it is and why.
388
-
389
- - **20 · untyped argument.** The declared argument is a bare destructuring pattern with
390
- no field types — `findStores({ near, radiusMiles?, limit? })` tells a model everything
391
- and a compiler nothing.
392
- - **0 · undeclared type.** The signature names a type the unit's own `types` block never
393
- declares. This was **11 functions across 7 providers** when the generator first
394
- compiled a provider's rendered types; all were fixed on 2026-08-05 by copying the real
395
- interface, and everything it transitively references, into the block. The class is now
396
- gated at source: `gate:capabilities`' `rendered-types-match-source` runs over the
397
- provider and family tiers, so it cannot come back silently.
398
-
399
- `gate:public-types` holds the two lists as separate SETS — merged, a provider could "fix"
400
- an undeclared type by making the argument untyped and stay green. Both can only shrink.
401
-
402
- **Seven providers have NO typed surface at all** — `aa`, `dickssportinggoods`,
403
- `flightradar24`, `ford`, `mailchimp`, `mcdonalds`, `namecheap`. Every function they
404
- declare is refused, so their interface is empty. The generated file says so in words,
405
- because an empty interface reads as "this unit does nothing", which is a different and
406
- wronger claim than "we can make no typed claim about anything it does".
407
-
408
- ### Scale
409
-
410
- Measured 2026-08-05 on synthetic units, one namespace each:
411
-
412
- | Units | raw | gzipped | `tsc` | editor cold load | member completion |
413
- |---|---|---|---|---|---|
414
- | 10,000 | 6.3 MB | 0.13 MB | 0.7s | 0.4s | 0.2 ms |
415
- | 500,000 | 321 MB | 6.5 MB | exit 0, 28.3s | 14.5s | **0.4 ms** |
416
-
417
- Reproduce with `pnpm tsx scripts/bench-public-types.ts <units>`. Completion — the only
418
- number a person feels — is flat. **The hard ceiling is ~849,000 units**, where the emitted
419
- string passes V8's `String::kMaxLength`; the generator throws there by name rather than
420
- letting `Array.prototype.join` produce a bare `RangeError`. Going past it needs the FAMILY
421
- shape (one shared interface, one line per member), which needs the manifest to describe a
422
- family and does not today.
189
+ How `@bowmark/web` is built, generated and published — the generator, the guards, the
190
+ publish pipeline — now lives in [`CONTRIBUTING.md`](./CONTRIBUTING.md), not here.
191
+ Nothing past this point is needed to call the library.