Skip to content

feat(patchy): ship CLI and SDK as one release - #219

Merged
allisonmahmood merged 2 commits into
mainfrom
sdk/203-patchy-package
Sep 12, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
sdk/203-patchy-package

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Patch repos need matching tooling and browser types, but the CLI was a separate package and release discovery did not provide an installable artifact.

Ship the CLI, config builders and browser client together as the private patchy package. The instance serves its immutable tarball with verified SHA-512 integrity, and shared release checks reject outdated tooling without disrupting pending publish recovery. Rename mirrors, ADRs and the skill lock follow the package.

Stacked on #218 (sdk/202-postgres). This PR targets that branch and contains only the #203 implementation; merge after its dependency.

Closes #203.

Verification

  • Full offline suite: 604 tests passed across 68 files.
  • Packed CLI real-server end-to-end flow passed.
  • After review corrections: typecheck, lint, formatting and 69 focused CLI/release tests passed.
  • Standards and spec reviews completed; findings addressed.

Implemented with OpenAI GPT-6 Astra (openai-codex/gpt-6-astra) in the Oh My Pi harness.

@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area size:l 501-1,000 changed lines labels Sep 10, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed db4ee5580f6d233f998e17ebd255d50c0addd54d against origin/sdk/202-postgres (27de001d8f6e87ad6400a599bab98c9e4641ca68), using #203. One pass, no subagents; merge blockers only.

Standards

No separate merge-blocking method or YAGNI findings.

Spec

1. [P1 · intent/extra] Keep SDK routing from hiding an existing company's patches

packages/sdk/src/SdkApi.ts:41–45

#203 asks for “the server serves it at GET /sdk/patchy-<release>.tgz.” The blanket /sdk/* fallback goes further: sdk was a valid company handle before this change, and company handles are fixed once created. Reserving it for new companies does not handle existing rows.

Using the actual tarballLayer alongside Serving's /:company/:name/* route, an isolated router probe changed both /sdk/team-notes and /sdk/team-notes/~v/1 from 200 to 404; /other/team-notes remained 200. An existing sdk company's published addresses therefore disappear on upgrade. Keep SDK handling narrow enough to preserve those addresses—the tarball's .tgz suffix cannot be a valid patch name—or provide an explicit existing-handle migration before taking over the prefix.

2. [P2 · intent] Preserve JSON nullability in insert/update types

packages/patchy/src/config.ts:149–152

#203 requires “defaulted is not nullable” and “update is partial with null only on optional.” JSON maps to unknown, which absorbs the conditional null union, and Writable reuses that read type. With required: t.json() and defaulted: t.json().default({}), a strict TypeScript probe accepts { required: null, defaulted: null } as both Insert and Update, including calls through the client. The runtime rejects these values as invalid_row (validator).

Keep JSON reads unknown, but give JSON write inputs a JSON-value type that admits top-level null only for optional columns. Cover required/defaulted JSON inserts and updates in the type checks.

Verification: 98 tests passed across the seven focused CLI/config/client/transport/release/Postgres-generation suites. Additional isolated router and strict TypeScript probes reproduced the gaps above. No live instance or Clerk calls.

Summary: Standards: 0 blockers. Spec: 2 blockers; worst is existing sdk company addresses becoming 404s.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Code review (issue #203)

Two-axis review of sdk/203-patchy-package vs sdk/202-postgres (db4ee55), plus the extra questions: did this match #203’s intent, is the method the smallest one that makes the behavior unsurprising, and does it channel YAGNI.

The package cut itself is the right ticket. Config builders, child-process execution, exact-current CLI check with recovery first, ADR-0011, and the immutable tarball path are the thing #203 was buying. The extra public surface is where it stops being beautiful.


Intent vs #203

#203 is the cut where Patchy becomes one installable unit: rename packages/cli → packages/patchy, ship CLI + patchy/config + patchy/client + patchy/dev stub at one version, serve that tarball from the instance with SHA-512 integrity, refuse non-current tooling, write ADR-0011. Init, refresh, catalog, and the real dev runtime are later tickets.

The PR delivered that unit. [email protected] is private, with the three named subpaths plus the binary. Config infers Row / Insert / Update. executeConfig forks a child and round-trips @patchy/api Manifest. The client has tables/files/shared/connections/me(), one PatchyError, postMessage + an HTTP test adapter. generateClient imports the config type and manifest.json value. Build packs patchy-<release>.tgz; the instance serves it immutable and reports the matching integrity. Publish recovers a pending attempt before the CLI release check. Surfaces moved.

Where it drifts: public patchy/executeConfig and patchy/generateClient were not in the specified subpaths. The skill still leads with “build from the patchy-cloud repo … symlink dist/index.js” (skills/patchy/SKILL.md), then mentions the tarball. Errors say Run: patchy refresh for a command that does not exist yet — acceptable as a pointer to #204, still a dead instruction today.

An agent that hits /api/release, installs the tarball, and publishes a file gets the unit the issue promised. An agent following the skill still builds the monorepo. That undercuts the “one package” story this ticket was supposed to land.


Spec

Checked against #203’s “What to build” / “Done when”, plus §7 of #193 only where this ticket owns it. Init/refresh/catalog/dev runtime were not treated as missing.

(a) Missing or partial

  • Generated unions per method are not generated and are unused. Spec: “one thrown PatchyError { code, message, details }, isPatchyError(e, code), generated unions per method.” clientError.ts has handwritten TableInsertError, FileGetError, etc. OwnedTable / FileStore / generateClient() never mention them. isPatchyError exists. Postgres Generate.ts still emits per-method unions; the owned-table client does not.

  • executeConfig is not on patchy/config. Spec listed it under “patchy/config: … executeConfig(path) runs the config in a child process.” Behavior matches (throwing config fails in-child; manifest round-trips the API schema). It lives at an extra Node subpath patchy/executeConfig.

(b) Scope creep

(c) Implemented but wrong

  • Required json accepts null. Spec: “update is partial with null only on optional” and json as unknown. ColumnValue maps json to unknown (config.ts), so { data: null } typechecks on a required column. config.types.ts asserts both data and dataOptional as unknown and never @ts-expect-errors { data: null }.

  • HTTP adapter is on the production client. Spec: “with an HTTP adapter for tests.” ADR-0011: HTTP is not permission for a frame to fetch the runtime. client.ts re-exports createHttpTransport from patchy/client.

  • files.*.url(name) can return a revoked blob URL. After createObjectURL, a closed/invalidated slot revokes then still return url (client.ts). Concurrent put / delete / close while files.get is in flight hands the caller a dead URL.

Port tests do what the done-when asked: correlation, error decoding, unknown_outcome on close/timeout, insert posted once. Publish uses checkRelease. Recovery still precedes it.


Method

The real constraint is: one pinned package, bytes the instance actually serves, config never executed on the server, latest-only tooling that does not eat a pending publish.

Piece Verdict Why
Child-process executeConfig Right User config can import, log, and throw. JSON-serialize in a child, stamp + Manifest decode in the parent, is the smallest “server never runs this” boundary.
Recovery before checkRelease Right CLI recovers pending, then checks; server replays, then release_mismatch. Same order, different errors. The unused pin/runtime slots on the helper are cheap and named by the spec.
Config builders + compile-only type tests Right No extra runtime. config.types.ts is the right kind of test.
packages/sdk for two routes Heavier than needed today Spec §2 / CONTEXT-MAP assign release+catalog+generation here, so the seam is not invented. Catalog is not in this PR. CLAUDE.md: a capability with one consumer stays a module. Artifact + SdkApi could have lived on the server until ticket 11. Copy script + turbo sdk#build exist to shuttle a tarball into the extra package.
Public executeConfig / generateClient subpaths Wrong method Spec/ADR surface is config, client, dev. File publish still synthesises an empty tier-0 manifest instead of calling executeConfig. Extra subpaths freeze a generator API before the generator exists.
HTTP + Port as public patchy/client API Heavier than needed createClient plus an injectable Call is this ticket. Spec asked for a fake-port test and an HTTP adapter for tests. Re-exporting them from the product entry is ticket 12’s broker, shipped before a shell exists.
generateClient.ts Right size as a function; too soon as an export Spec asked for the template. Ticket 11 should be the first caller.
Build script Heavier than needed Pack + SHA-512 + version-constant check is the right pack. Five public entries, rollup dts, and --stage-for-server are ceremony from the extra subpaths.

YAGNI

Delete or hide:

  • packages/patchy/package.json ./executeConfig and ./generateClient. Spec listed three subpaths. Keep the files; drop the public exports.
  • export { createHttpTransport, createPortTransport, … } from patchy/client. Patch frames need createClient, PatchyError, isPatchyError. Tests can import the transport module.
  • clientError.ts method-error aliases. Sixteen types, never referenced by OwnedTable / FileStore. Spec wanted unions on methods. FileUrlError is invented: url() is a local blob, not a wire op.
  • ExecutedManifest. Hand-copied Manifest while already decoding with @patchy/api Manifest. Return typeof Manifest.Type.
  • wire?: number on both transports. Unused outside the default. Hard-code WIRE_VERSION.
  • HTTP adapter reimplementing files REST, principal bootstrap, abort, me cache. Spec needed a test seam. JSON POST + injected fetch is enough.

Keep:

  • config.ts + config.types.ts — builders and compile-only inference.
  • executeConfigChild.ts + ReleaseCheck.ts — child isolation and a 15-line exact-current check.
  • Blob-URL cache/revoke for url(name) — once the revoke-then-return bug is fixed.

Standards

Effect services — no findings. Artifact.ts follows canonical order (errors, inline Context.Service, make, layer), namespace imports, yield* of FileSystem / Config, Schema.TaggedError with message from fields and cause on wrap. SdkApi.ts namespaces Artifact, hoists Schema.encodeSync. ReleaseCheck.ts is an Effect.fn module, not a service. executeConfig.ts is a Node child-process entry (ADR-0011), not an Effect service; Schema compilers sit at module scope.

packages/patchy/src/client.ts + clientTransport.ts — ADR-0011. The ADR: HTTP is a test adapter, not permission for a patch frame to fetch the runtime. createHttpTransport / HttpTransportOptions are re-exported from the public patchy/client entry. A patch can import { createHttpTransport } from "patchy/client" and hit /api/runtime/* directly. Keep the HTTP adapter off that export (tests can import ./clientTransport.js).

ui-consistency: N/A.

Smells (judgement)

  • Duplicated Code — packages/integrations/src/postgres/Generate.ts. Generated prelude still inlines the ErrorCode string union after moving PatchyError / decodeError to patchy/client. The template list can drift from clientError.ts errorCodes. Re-export ErrorCode from patchy/client in the prelude.
  • Divergent Change in packages/patchy: suppressed — ADR-0011 requires CLI, config, client, and dev in one package.
  • Speculative Generality on checkRelease pin/runtime: suppressed — ADR-0004 / docs/product.md specify that shared check.

Surfaces

Wire, CLI contract, skill lock hash, vocabulary, ADR-0011, and the rename are hit. sha256sum skills/patchy/SKILL.md matches skills-lock.json. No live packages/cli leftovers.

Partial:

  • README.md still lists “release metadata” under packages/patches after moving discovery to packages/sdk.
  • packages/sdk is missing from .github/labeler.yml area:server and from the area:server table in docs/agents/triage-labels.md. Those two files are supposed to say the same thing.

Summary

  • Standards: 2 findings (1 documented-standard, 1 judgement). Worst: public createHttpTransport on patchy/client against ADR-0011.
  • Spec: 7 findings (2 partial, 2 creep, 3 wrong). Worst: required json columns accept null, so the inference contract the ticket asked for is not actually true.

The package-and-release story is real. Trim the public surface to config / client / dev, keep HTTP off the product entry, and make json nullability honest — then this is the small model #203 wanted.

Reviewed with /code-review against #203 (Standards, Spec, intent, method, YAGNI, Effect conventions, surfaces, client/config correctness). Model: Grok 4.6.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Addressed both review comments in a4b5ad5.

Fixed

  • SDK routing: only the exact GET /sdk/patchy-<release>.tgz is registered. Removed /sdk/* and the new sdk company-handle reservation. Regression coverage preserves /sdk/team-notes, its versioned address, and non-GET routing; existing company addresses must not disappear on upgrade.
  • JSON writes: reads remain unknown, but inserts/updates take JSON values with top-level null only for optional columns. Required/defaulted null writes have @ts-expect-error coverage in both config types and the published client declarations; nested null remains valid.
  • Public surface: only patchy/config, patchy/client, and patchy/dev are exported. executeConfig is lazily exported from config; executor and generator source files remain internal. Removed public HTTP/Port/postMessage constructors and transport-specific options/types. The default client still uses the broker. Packed-consumer runtime and type checks cover this boundary.
  • Blob URLs: an in-flight URL invalidated by put/delete/close rejects before allocating a blob URL instead of returning a revoked one. Tests cover all three races and replacement bytes; normal caching/revocation remains.
  • Error/version cleanup: removed the 16 unused owned-method aliases rather than imply checked Promise errors. Retained the shared boundary union used by generated Postgres method unions; those now reuse the shared ErrorCode instead of copying its list. Removed unused wire overrides; adapters use WIRE_VERSION.
  • Surfaces: corrected README release ownership, SDK server labeling and its triage-doc mirror, public export guidance, and generated API docs. The skill now leads with downloading and integrity-verifying the instance tarball; source builds are contributor-only guidance. Refreshed and verified its lock hash.

Kept, with reasons

  • ExecutedManifest: retained a small dependency-free data boundary, strengthened its column/default discrimination, and added bidirectional schema-conformance plus key/signature checks. Returning the Effect schema type directly produced unresolved fast-check imports and invalid ambient declarations in the actual offline packed-consumer test. Keeping this checked boundary is smaller than introducing another declaration-generation system; runtime decoding still uses the API Manifest schema.
  • packages/sdk and artifact staging/declaration bundling: SDK: primitives, integrations, init and the dev loop on tier 1 #193 §2 explicitly assigns release/catalog/generation to this package. Standalone declarations and package-owned artifacts support the verified offline install; the public entry set is now just the specified three.
  • HTTP test adapter's principal bootstrap, bytes routes, identity cache and cancellation: these reflect the real runtime protocol. A JSON-only fake would stop exercising file transfers and browser admission correctly. The adapter is no longer public.
  • Postgres query builders: SDK: primitives, integrations, init and the dev loop on tier 1 #193 §6 requires the tables' column language for query shapes. Keeping this integration avoids two shape languages now that the builders exist.
  • Release-check pin/runtime slots and patchy refresh guidance: explicitly required by feat(patchy): one package: the CLI, patchy/config, patchy/client and the release #203/ADR-0011. Docs now distinguish the later refresh command from today's reinstall-current-artifact procedure. Pending publish recovery remains first.
  • Child isolation, internal generation template, and single-file tier-0 synthesis: required/current behavior. Repo orchestration remains in later tickets; file publishing must not execute an unrelated config.

Verification and readiness

  • Local pnpm test: 607 passed across 68 files.
  • Local typecheck, lint, format check, skill hash, and packed CLI real-server e2e: passed.
  • CI on this exact commit: test (22), test (24), clerk-live, lint, cli-smoke, dependency-review all passed; label check also passed.
  • GitHub reports MERGEABLE / CLEAN against sdk/202-postgres. No separately required checks are reported for this stacked PR; all seven reported checks are green.

No unresolved blockers for #219. It remains stacked on #218; no merge performed.

@allisonmahmood
allisonmahmood merged commit c4c718d into main Sep 12, 2026
7 checks passed
@allisonmahmood
allisonmahmood deleted the sdk/203-patchy-package branch September 12, 2026 12:11
allisonmahmood added a commit that referenced this pull request Sep 12, 2026
Starting a patch repo still required manual setup, and refreshing its
release could leave the installed CLI, generated clients and project
skills out of sync.

Add authenticated `init`, `refresh`, `catalog`, `add` and `remove`
commands, backed by instance-served generation and five canonical
project skills. Refresh installs and re-executes the pinned release,
then activates the managed files together or rolls back. Declaration
edits preserve user code and fixtures; initialization preserves the
caller's working directory.

Stacked on `sdk/203-patchy-package` (#219), which is this PR's base
rather than `main`. Local `patchy dev` runtime execution remains in the
next dev-runtime ticket.

Closes #204.

Validation:
- `pnpm lint` and `pnpm typecheck` pass.
- `pnpm test`: 70 files, 613 tests pass.
- Real CLI smoke covers default init, generated-project typechecking,
unusual connection handles, pin-only refresh and fixture preservation.
Regression tests cover the caller directory and concurrent package
edits.

Implemented with GPT-6 Astra in the Oh My Pi harness.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area area:server Touches the server area size:l 501-1,000 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(patchy): one package: the CLI, patchy/config, patchy/client and the release

1 participant