You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Prototype: patchy init --tier 1, code-first config, first table and file over PGlite, first publish #176
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.
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.
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:
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.
No update operation; it modelled "replace the image" around the gap. update by id belongs in v1.
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.
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.
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.
It re-ran pnpm install although init had installed; init's output should say so, and AGENTS.md should say what is already done.
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.
The tables surface: definitions, queries, joins, ids, and what additive-only refuses: list with an equality filter bound to a declared index, update by id, defaulted ≠ nullable, indexes and uniqueness in table(...) with uniqueness outside "additive", explicit null semantics on insert, and the diff rejecting what it does not implement.
What init pulls from the server: skills, generated types, context and the refresh command: the split proven here (inferred own types; _generated/ = context + manifest + declaration types, stamped with a schema revision); a regenerated context file separate from an agent-owned AGENTS.md; the skill content that worked (the fresh agent followed it); init must leave a tree that typechecks and print what it already did; a non-blocking patchy dev with start/status/stop.
Publish for a patch repo: build, manifest, tier check, provisioning order and wire versions: the tier check split (CLI sees the tree, server sees the bundle) held; provisioning authority must be a cumulative inventory in the company database with per-patch serialisation, bytes uploaded before provisioning and publication recoverable across the non-transactional steps; typecheck before build; patchy.json as the id's home.
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).
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:
list with an equality filter bound to a declared index; update by id.
Defaulted is not nullable; explicit null on insert is refused, not defaulted.
Indexes and uniqueness in table(...), uniqueness outside "additive"; diff rejects what it does not implement.
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.
_generated/client.ts imports the config's type and the manifest's value, never the executable config.
Generated declaration metadata stamped with its schema revision and validated at publish.
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.
A regenerated context file separate from an agent-owned AGENTS.md; an obvious fixture location; a plain warning that deleting .patchy/ destroys local data.
init leaves a tree that typechecks and says what it already did; publish typechecks before it builds.
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.
Activity
allisonmahmood commentedon Sep 6, 2026
Evidence to build on from Research: PGlite parity with Postgres for the dev runtime: Effect 4.0.0-rc.112 ships an official
PgliteClientfor the sameSqlClientcontract, so the dev runtime needs no bespoke adapter. Two gaps to design around in this prototype: its query path rejects multi-statementsql.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 forint8andDATE, 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.allisonmahmood commentedon Sep 6, 2026
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 clientpatchy.tables.<name>.insert|list|get|delete,patchy.files.<name>.put|get|list|delete,patchy.me(). Row and insert types are inferred fromtypeof config; nothing is generated for what the patch owns.@patchy/primitives:Tables(additive diff → provisioning into schemap_<patchId>, one DDL statement per call in one transaction; bounded reads; runtime row check; codec normalisation above the driver) andFiles(bytes in the content store, an index row per file), plus the/_patchy/*routes over aBinding(namespace, manifest, viewer) the host provides. The server composes them over Postgres,patchy devover PGlite; same code.Manifest,POST /api/publish(manifest + single-file bundle) answeringPublishCreated|Updatedwith aprovisionedlist, or 422tier_mismatch | schema_not_additive | invalid_manifest. Versions gainedtierandmanifest; a tier ≥ 1 version is served raw underContent-Security-Policy: sandbox allow-scripts.patchy init --tier 1 <dir>lays down the tree and installs;patchy devprovisions the config into.patchy/pglite, binds the viewer from/api/me, and starts Vite with/_patchyproxied to the runtime;patchy publishexecutes 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 topatchy.jsonon the first run;patchy refreshrewrites 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.mdimports 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 devprovisionednotesandattachmentsinto PGlite in one go and the starter inserted, listed, and stored a file in a real browser; the first publish created the patch, provisionedp_<id>.notesand 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.Recordwith 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 makespnpm devsay only "supervisor exited before the server became healthy" with nothing indev.log.The fresh agent (astra through
omp, only the laid-down tree,patchyon 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 acommentstable to the config, wrote the UI, startedpatchy devin the background, verified in a headless browser, published, and stopped the server. No direct database access, no edit topatchy/_generated/, no hardcoded URL or token, no permission logic in the page,patchy.jsoncommitted. Where it went wrong or lost time, and what would have prevented it:comments.list()then.filter(row => row.noteId === note.id)), becauselisttakes onlylimit. 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.updateoperation; it modelled "replace the image" around the gap.updateby id belongs in v1.t.timestamp().default("now")madecreatedAt: string | nullinRowOf, sonew Date(note.createdAt)in the starter failstsc(Vite transpiles without checking, sopatchy devhid it). Nullability and insert-omission are two properties; the SDK must keep them apart.pnpm typecheckfailed out of the box becausevite.config.tsusesprocess.envand the tree ships no Node types; it added@types/nodeitself. The laid-down tree must typecheck clean, andpublishshould run the typecheck before building.::1, so its readiness probe on 127.0.0.1 timed out;server.hostshould be pinned in the laid-down Vite config, orpatchy devshould print one URL and own the probe.pnpm installalthoughinithad installed;init's output should say so, andAGENTS.mdshould say what is already done..patchy-dev.login the repo root and had to gitignore it: there is no non-blockingpatchy devfor an agent. The dev runner in this repo (pnpm devstart/status/stop, log under a state dir) is the shapepatchy devneeds.astra's review (second model, files attached; its words condensed, attribution kept)
uses: { warehouse: connection("postgres/warehouse"), contacts: sharedTable({ patch, table }) }besidetables/files,indexes: { byTitle: { columns: ["title"], unique: true } }insidetable(...)with columns constrained to the table's keys, and tier 2 handlers as descriptors ofserver/in the manifest, never functions imported into browser config. Defaulted is not nullable (independently confirms finding 3; also notescheckInsertturns an explicitnullon a defaulted column into the default). Adding uniqueness is not automatically backward compatible; do not hide it behind "additive"._generated/client.tsimporting 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.information_schemais 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-runsCREATE TABLEagainst existing objects, or mints a new id and leaves an orphan namespace. Alsodiffaccepts required → optional and default changes without emitting an ALTER; reject what it does not implement.Bindingcaptured at route install is a dev-only shape.meis viewer claims, distinct from tier 2's acting principal.getmust not swallow every 404 (undeclared table versus absent row). Addupdate.AGENTS.mdmakes 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.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
devandpublish), so_generated/holdsmanifest.jsonplus declaration types andclient.tsimports the config's type and the manifest's value. Recommendation: keep the design; the ten changes above are what the spec writes down.listwith an equality filter bound to a declared index,updateby id, defaulted ≠ nullable, indexes and uniqueness intable(...)with uniqueness outside "additive", explicitnullsemantics on insert, and thediffrejecting what it does not implement._generated/= context + manifest + declaration types, stamped with a schema revision); a regenerated context file separate from an agent-ownedAGENTS.md; the skill content that worked (the fresh agent followed it);initmust leave a tree that typechecks and print what it already did; a non-blockingpatchy devwith start/status/stop.patchy.jsonas the id's home.me, tables insert/list/get/delete/update, files put/get/list/delete) as a versioned contract with HTTP and postMessage adapters; per-request binding of company, patch, version and acting principal;me= viewer claims.usesblock is the declaration surface.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).
allisonmahmood commentedon Sep 6, 2026
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.
allisonmahmood commentedon Sep 8, 2026
Resolved 2026-09-08 with Allison: go with the recommendation. The design holds: code-first
patchy.config.tsexecuted locally into a manifest, owned types inferred from the config, real capability code shared by the server (Postgres) andpatchy 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:
listwith an equality filter bound to a declared index;updateby id.nullon insert is refused, not defaulted.table(...), uniqueness outside "additive";diffrejects what it does not implement._generated/client.tsimports the config's type and the manifest's value, never the executable config.meis viewer claims.AGENTS.md; an obvious fixture location; a plain warning that deleting.patchy/destroys local data.initleaves a tree that typechecks and says what it already did;publishtypechecks before it builds.patchy devwith 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.