Skip to content

Prototype: patchy init --tier 1, code-first config, first table and file over PGlite, first publish #176

Closed

Description

@allisonmahmood

Question

What does an agent that knows Vite and Convex but has never seen Patchy experience from patchy init --tier 1 to a first publish, and where does it go wrong?

Build, on a throwaway branch: init lays down a minimal tree (a patchy.config.ts with the tier, one table definition with a schema, one file store definition; index.html and src/main.ts on Vite; a generated directory with a typed client for the declared table; a context file naming the company, the dev identity and the refresh command; a skills folder with the core workflow skill). patchy dev runs the dev runtime over PGlite and a filesystem file store as the machine token's user, serving the patch locally with the SDK transport stubbed to plain HTTP against the local runtime (the frame prototype owns the real transport). The starter exercises one real insert and one query against synthetic local rows. patchy publish compiles the config to a manifest, refuses if the tree claims a lower tier than it has, uploads tree plus manifest, and the server provisions the table and file store in the company database before serving the version.

Then: hand the repo to a fresh agent session with only the laid-down skills and ask it to add a second table and a file upload. Record every place it went wrong (direct database access, editing generated files, production URLs, frontend-only permission checks) and what in the layout or skill would have prevented it.

Then the second-model review (see the map's Notes): attach the tree and the config shape and ask astra whether the layout and the config surface expand cleanly to connections, shared tables and tier 2 server handlers.

Recommendation: optimise for the agent's first ten minutes. Everything the agent needs should be in the tree or one command away; nothing that could touch production should be reachable from dev.

Activity

  1. added
    wayfinder:prototype
    on Sep 6, 2026
  2. allisonmahmood commented on Sep 6, 2026

    @allisonmahmood
    OwnerAuthor

    Evidence to build on from Research: PGlite parity with Postgres for the dev runtime: Effect 4.0.0-rc.112 ships an official PgliteClient for the same SqlClient contract, so the dev runtime needs no bespoke adapter. Two gaps to design around in this prototype: its query path rejects multi-statement sql.unsafe (the existing migrators use that form), so the schema provisioner must emit one statement per call inside one transaction; and PGlite's row codecs differ from pg's for int8 and DATE, so the tables service normalises codecs above the driver. PGlite 0.5.8 is Postgres 18.3, ~25 MB unpacked, ~1 s cold start; fsync is off by default, so the local fixture directory must be recreatable.

  3. allisonmahmood commented on Sep 6, 2026

    @allisonmahmood
    OwnerAuthor

    Prototype run 2026-09-06. Branch prototype/init-tier1 (throwaway; the learning is here). Awaiting Allison's verdict; astra's is recorded below.

    What was built

    • @patchy/sdk: defineConfig({ tier, tables: { notes: table({ title: t.text(), body: t.text().optional(), createdAt: t.timestamp().default("now") }) }, files: { attachments: files() } }) and a dependency-free browser client patchy.tables.<name>.insert|list|get|delete, patchy.files.<name>.put|get|list|delete, patchy.me(). Row and insert types are inferred from typeof config; nothing is generated for what the patch owns.
    • @patchy/primitives: Tables (additive diff → provisioning into schema p_<patchId>, one DDL statement per call in one transaction; bounded reads; runtime row check; codec normalisation above the driver) and Files (bytes in the content store, an index row per file), plus the /_patchy/* routes over a Binding (namespace, manifest, viewer) the host provides. The server composes them over Postgres, patchy dev over PGlite; same code.
    • The wire: Manifest, POST /api/publish (manifest + single-file bundle) answering PublishCreated|Updated with a provisioned list, or 422 tier_mismatch | schema_not_additive | invalid_manifest. Versions gained tier and manifest; a tier ≥ 1 version is served raw under Content-Security-Policy: sandbox allow-scripts.
    • CLI: patchy init --tier 1 <dir> lays down the tree and installs; patchy dev provisions the config into .patchy/pglite, binds the viewer from /api/me, and starts Vite with /_patchy proxied to the runtime; patchy publish executes the config, builds one HTML file, checks the tree's evident tier against the declared one (CLI: server/ and script; server: script in a tier 0 bundle), publishes, and writes the id to patchy.json on the first run; patchy refresh rewrites what the instance owns.

    The tree: patchy.config.ts, patchy.json (id, committed), index.html + src/main.ts (Vite, single-file build), patchy/_generated/{client.ts,context.json}, AGENTS.md (company, dev identity, commands; CLAUDE.md imports it), .agents/skills/patchy-sdk/SKILL.md, vite.config.ts, pnpm-workspace.yaml (esbuild build approval), .gitignore, .patchy/ for local data.

    What happened

    Everything the ticket asked for ran end to end against this worktree's dev instance: init in 2 s; patchy dev provisioned notes and attachments into PGlite in one go and the starter inserted, listed, and stored a file in a real browser; the first publish created the patch, provisioned p_<id>.notes and the file index in Postgres, and served the bundle publicly under the sandbox CSP; a second publish with a new table and a new optional column reported exactly those as provisioned; a rename was refused as a drop; a tier 0 claim over a bundle with script was refused by the CLI and, bypassing the CLI, by the server.

    Two things found on the way, both kept: config wants camelCase column names, so identifiers are quoted everywhere and camelCase survives into Postgres as written; and an Effect Schema.Record with a filtered key schema silently dropped the non-matching column on the server rather than refusing, so names are now checked as a filter over the whole record. Side bug outside this map: a failed migration makes pnpm dev say only "supervisor exited before the server became healthy" with nothing in dev.log.

    The fresh agent (astra through omp, only the laid-down tree, patchy on PATH)

    Asked to add comments per note and an image attachment, make it work locally, and publish. It read the skill first, ran patchy --help, added a comments table to the config, wrote the UI, started patchy dev in the background, verified in a headless browser, published, and stopped the server. No direct database access, no edit to patchy/_generated/, no hardcoded URL or token, no permission logic in the page, patchy.json committed. Where it went wrong or lost time, and what would have prevented it:

    1. It fetched every comment and filtered in the browser (comments.list() then .filter(row => row.noteId === note.id)), because list takes only limit. With the default limit of 100 this is a correctness bug the SDK's shape invited. The tables surface needs at least an equality filter on a column, tied to an index the config declares.
    2. No update operation; it modelled "replace the image" around the gap. update by id belongs in v1.
    3. A defaulted column typed as nullable on read. t.timestamp().default("now") made createdAt: string | null in RowOf, so new Date(note.createdAt) in the starter fails tsc (Vite transpiles without checking, so patchy dev hid it). Nullability and insert-omission are two properties; the SDK must keep them apart.
    4. pnpm typecheck failed out of the box because vite.config.ts uses process.env and the tree ships no Node types; it added @types/node itself. The laid-down tree must typecheck clean, and publish should run the typecheck before building.
    5. Vite listened on ::1, so its readiness probe on 127.0.0.1 timed out; server.host should be pinned in the laid-down Vite config, or patchy dev should print one URL and own the probe.
    6. It re-ran pnpm install although init had installed; init's output should say so, and AGENTS.md should say what is already done.
    7. It wrote .patchy-dev.log in the repo root and had to gitignore it: there is no non-blocking patchy dev for an agent. The dev runner in this repo (pnpm dev start/status/stop, log under a state dir) is the shape patchy dev needs.

    astra's review (second model, files attached; its words condensed, attribution kept)

    • Config surface: keep the builders; add uses: { warehouse: connection("postgres/warehouse"), contacts: sharedTable({ patch, table }) } beside tables/files, indexes: { byTitle: { columns: ["title"], unique: true } } inside table(...) with columns constrained to the table's keys, and tier 2 handlers as descriptors of server/ in the manifest, never functions imported into browser config. Defaulted is not nullable (independently confirms finding 3; also notes checkInsert turns an explicit null on a defaulted column into the default). Adding uniqueness is not automatically backward compatible; do not hide it behind "additive".
    • Inference versus generation: the split is right, but _generated/client.ts importing the executable config as a value drags its transitive imports into the browser bundle and breaks once config imports server handlers; use a type-only import and generate a tiny resource-name descriptor for enumeration. Stamp generated declaration metadata with its schema revision and validate it at publish.
    • Manifest and diff: neither the served version's manifest nor information_schema is the right authority. Keep a server-owned cumulative provisioned inventory per patch, committed with the DDL in the company database; serialise publishes per patch; version manifests immutable; rollback picks an older bundle and never rolls the inventory back; introspection detects drift only. The earliest failure needs no concurrency: provision commits, then the upload fails, and the next attempt re-runs CREATE TABLE against existing objects, or mints a new id and leaves an orphan namespace. Also diff accepts required → optional and default changes without emitting an ALTER; reject what it does not implement.
    • Runtime wire: keep the operations, define them as a versioned operation contract (request correlation, structured error codes, binary payloads) with HTTP and postMessage as adapters. The host binds company, patch, version and acting principal per request; Binding captured at route install is a dev-only shape. me is viewer claims, distinct from tier 2's acting principal. get must not swallow every 404 (undeclared table versus absent row). Add update.
    • Tree: sensible; separate the regenerated company/machine context from an agent-owned instructions file (overwriting all of AGENTS.md makes local instructions disposable and cloned identity claims misleading); give declarations an obvious fixture location with one example; say plainly that deleting .patchy/ destroys local rows and files.
    • Verdict: sound with named changes. Keep code-first definitions, inferred owned types, real shared capability implementations and the local dev loop. Change provisioning authority, default/null semantics, browser config loading and the transport/identity contract before production. The next experiment should exercise failed and concurrent publication, rollback and old-client writes.

    My synthesis, and what each open ticket inherits

    I agree with astra on every point but one nuance: the type-only config import is right, but the enumeration descriptor can be the manifest itself (already produced at dev and publish), so _generated/ holds manifest.json plus declaration types and client.ts imports the config's type and the manifest's value. Recommendation: keep the design; the ten changes above are what the spec writes down.

    Fog to add to the map when this closes: provisioning inventory and publish recovery (what the company database records per patch, how a half-failed publish resumes, what rollback does to tables) and the dev runner shape for agents (start/status/stop, logs, one URL).

  4. allisonmahmood commented on Sep 6, 2026

    @allisonmahmood
    OwnerAuthor

    PR for trying it: prototype(sdk): patchy init --tier 1, dev over PGlite, publish with manifest. Not for merge; the Try it section in its description is the walkthrough.

  5. allisonmahmood commented on Sep 8, 2026

    @allisonmahmood
    OwnerAuthor

    Resolved 2026-09-08 with Allison: go with the recommendation. The design holds: code-first patchy.config.ts executed locally into a manifest, owned types inferred from the config, real capability code shared by the server (Postgres) and patchy dev (PGlite), additive provisioning on publish. Astra's review and the synthesis above stand as written; the named changes are what the spec writes down, and each open ticket inherits the items listed for it in the synthesis.

    The ten changes, for the record:

    1. list with an equality filter bound to a declared index; update by id.
    2. Defaulted is not nullable; explicit null on insert is refused, not defaulted.
    3. Indexes and uniqueness in table(...), uniqueness outside "additive"; diff rejects what it does not implement.
    4. Provisioning authority is a server-owned cumulative inventory per patch in the company database, publishes serialised per patch, bytes uploaded before provisioning, publication recoverable across the non-transactional steps.
    5. _generated/client.ts imports the config's type and the manifest's value, never the executable config.
    6. Generated declaration metadata stamped with its schema revision and validated at publish.
    7. The runtime operations as a versioned contract with HTTP and postMessage as adapters; company, patch, version and acting principal bound per request; me is viewer claims.
    8. A regenerated context file separate from an agent-owned AGENTS.md; an obvious fixture location; a plain warning that deleting .patchy/ destroys local data.
    9. init leaves a tree that typechecks and says what it already did; publish typechecks before it builds.
    10. A non-blocking patchy dev with start, status, stop and one URL.

    Added to the map under Not yet specified: provisioning inventory and publish recovery, and the dev runner shape for agents. Prototype PR #187 closes as not for merge; the branch stays until the build tickets have lifted what they need from it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

wayfinder:prototype

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions