Skip to content

feat(patchy): let agents discover patches with list - #265

Merged
allisonmahmood merged 2 commits into
mainfrom
portal/252-patchy-list
Sep 16, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
portal/252-patchy-list

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Agents could list company connections, but finding an existing tool or a usable shared table still required direct API calls.

patchy list now follows the discovery chain from company patches to a patch's tables, stores and reads, then to individual schemas. It replaces catalog, preserves wire JSON and lifecycle refusals, and teaches the same chain in all six skills and the CLI docs.

Stacked on portal/251-connections-group (#264), which provides the connections API. This PR targets that branch and contains only the CLI discovery work.

Closes #252.

Verification

  • pnpm typecheck and pnpm lint passed.
  • pnpm test --maxWorkers=4: 821 tests passed across 78 files.
  • pnpm test:packed-cli-e2e passed, including discovery against two seeded patches through the installed CLI.
  • Standards and spec reviews completed; all three standards findings addressed, no spec findings.

One default-concurrency rerun timed out in an unchanged server startup test. That file passed in isolation, and the full suite passed with four workers without changing any timeout.

Implemented with openai-codex/gpt-6-astra using Oh My Pi.

@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 15, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed 27e5992 against origin/portal/251-connections-group at 7e9fb39, using #252 and its referenced discovery contract. One pass, no subagents; merge blockers only.

Standards

No merge-blocking method or YAGNI findings.

Spec

No merge-blocking intent findings. The command forms, lifecycle filters and refusals, JSON documents, catalog removal, and required documentation, skill and packed-e2e updates match #252.

Verification: pnpm exec vitest run packages/patchy/src/cli.test.ts -t 'patchy list|ambiguous Postgres selection' --maxWorkers=1 passed with 24 tests passed and 127 skipped. The global skill's SHA-256 matches skills-lock.json. I inspected the packed-e2e additions but did not rerun that suite.

Summary: Standards 0 findings; Spec 0 findings. No merge blocker identified on either axis.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Code review of PR 265

Compared 27e5992 (portal/252-patchy-list) to origin/portal/251-connections-group. The spec is #252. Parallel reviewers covered standards, spec, intent, method, YAGNI, required surfaces, and the CLI contract.

Standards

Documented standards

packages/patchy/src/Output.ts:84-90, hard. Recovers a known tagged failure by _tag inside Effect.catch:

Effect.catch((error) =>
  fail(
    error.message,
    error.kind,
    error.code,
    error._tag === "WrongPatchState" ? error.state : undefined
  )
),

.agents/skills/effect-service-conventions/SKILL.md (Errors and predicates): catch statically known tagged failures with Effect.catchTags, including one tag. Do not recover known _tag variants with a predicate or tag test. Effect.catch is for the whole remaining channel. Expected: Effect.catchTags({ WrongPatchState: (e) => fail(e.message, e.kind, e.code, e.state) }), then Effect.catch for the rest of CliError.

WrongPatchState itself is fine: structured state/cause, message derived from state not cause, code: "wrong_state" matching ADR-0004. Discovery.ts is a module, not a Context.Service. Namespace imports, run vs runProject (list does not read patchy.json), and no runPromise in the module match the conventions. Wire WrongState is an untagged { ok: false, code } struct, so Schema.is in Discovery.ts:35-40 is not a catchTags miss.

Judgement (baseline / vocabulary)

Mysterious Name. Discovery.ts:132-133: top and boolean connections (a payload uses the same name in the if (top) block).

CONTEXT.md Discovery Avoid: inspect. New agent copy uses that verb for the drill-down: packages/patchy/README.md:176,225, skills/patchy/SKILL.md:51, packages/sdk/skills/patchy-files/SKILL.md:13, packages/sdk/skills/patchy-loop/SKILL.md:28, docs/product.md:175. Catalog/search as the command name, and "publishing key" in user-facing copy, are clean.

Shotgun edits across skills/ADR/README are required by the CLI contract surfaces. Not a smell here.

Spec

No material spec gaps. 27e5992 implements list's positional path, --state at top/patch/primitive, --mine/--all as local wrong-level errors, merged top-level { patches, connections }, catalog removal, ADR-0004 --json docs, lock hash 73e68e8d (matches skills/patchy/SKILL.md), Publishing Catalog removed and Discovery built, and product section Sharing and finding as built.

(a) Missing or partial. None of the Done-when items are missing.

  • CLI suite: every level's text and --json; wrong-level flags/paths; retired-by-name without --state (exit 2); deleted id refused without --state all and accepted with it at both depths.
  • Catalog-as-command is gone from CLI, README, skills, tests. Remaining catalog hits are pnpm catalog:, pg_catalog, and snapshot/portal nouns, never patchy catalog.
  • Packed e2e seeds two patches and runs list, list <patch> and list <patch> <table> (text + JSON) from the saved login, not a repo.
  • Skills teach the chain, "no match" = "none you can use", --state retired before absence, last-segment URLs, and add postgres listing from list connections.

(b) Scope creep. None that is not §7/§8 follow-through (URL last-segment, no slashes, --state refused on connections, state on JSON failures, glossary/README/CONTEXT-MAP catalog cleanup).

(c) Implemented but wrong vs required copy. None. Required phrases are present: deleted · gone in 18 days from purgeAt (not a second local deadline), · deactivated, (no description), Tables: unavailable, retired; pass --state retired / deleted; pass --state all (exit 2). Text is Patch is retired; pass --state retired. The quoted phrase is included, not replaced.

list uses run(), not runProject(), so it does not read repo patchy.json.

Intent vs #252

The problem was that agents could list company connections, but finding an existing tool or a usable shared table still meant calling GET /api/patches. catalog listed connections and stopped.

What shipped does that job. patchy list walks company patches, then a patch's tables/stores/reads, then a primitive's schema, plus connections, under the saved login, without reading patchy.json. Shared-tables no longer send agents at the bearer-protected patch API. Catalog the command is gone. --json is the wire. That is what #252 asked for.

Where the letter is met and the spirit is thinner: after the three-step chain, the global skill and patchy-loop paste the flag matrix (--mine top only, --all connections only, wrong_state JSON state, no ok wrapper). patchy-shared-tables restates the same instead of pointing at the loop. Tables and files stay closer to the actual job.

Text for list connections <handle> dumps the whole snapshot (relations, columns, PKs, FKs, enums, exclusions). Agents were told to use --json. The pretty-printer is extra weight on a path the issue specified much more thinly than patch/primitive text.

docs/product.md Sharing and finding now mentions that "the patch read query also carries live dependant edges for the future portal." Portal is ticket 8. This ticket asked that section to move agent discovery from decided to built.

Method

One Command.make("list") (commands.ts:793-827) with two optional positionals and three optional flags, then run(Discovery.list). Discovery is a module, not a service: dispatch, wrong-level flag checks, HTTP, schema encode, and text lines in one list. Top level merges GET /api/patches and GET /api/connections with Effect.all({ concurrency: 2 }) and fail-closes. Other depths pass the wire body through. Project.catalog was deleted, not wrapped.

This is the smallest method that matches the spec. Patch names are an open set, so list patches / list connections as separate Command trees cannot own the path without a leftover catch-all that is this same dispatch. One consumer, so a module is the repo rule. Flag.optional on booleans plus Option.isSome after parse is the honest way, on one Command, to refuse --mine/--all/--state at the wrong depth instead of ignoring them.

Costs of that seam, none of them a reason to change the method:

  • patches and connections are valid PatchNames. list patches never names a patch of that name. The id path still works. Dispatch does not say so.
  • --help advertises every flag at every depth. Unavoidable given one Command.
  • URL handling (Discovery.ts:181-186) is last path segment only. /company/name/~v/3 becomes "3" and 404s. That is what feat(patchy): patchy list replaces catalog; the skills teach the discovery chain #252 and product.md asked for. Name/id/wrong_state stay on the patches API.

I would not use subcommands. I would not fold Discovery into commands.ts.

YAGNI

Discovery.ts is not a framework. One Effect.fn, five ifs, no registry, no Level type. Days-left comes from purgeAt via Clock, not a second local deadline. Wrong-level coverage is one it.each table. Packed e2e seeds two real patches and walks the chain.

Nothing here is machinery the spec did not already buy.

What would be more beautiful if deleted:

  1. The cloned flag contract across ADR-0004, README, product.md, skills/patchy/SKILL.md, patchy-loop/SKILL.md, and patchy-shared-tables/SKILL.md. Keep the four-step chain where agents enter. Let ADR/README own flags.
  2. decodePatchReference (Discovery.ts:31-33,188-196) as Schema.String.check(/^[^/]+$/) for "no slashes", already refused for detail at line 146.
  3. Connection-detail text that pretty-prints the entire snapshot. Issue specified text for patch/primitive/top. Connection handle JSON is the wire body.

Do not introduce a Level union. The Option unwrap at the CLI boundary (getOrUndefined vs Option.isSome for presence) is honest.

Surfaces

All required surfaces are hit.

  • Wire contract. No new routes. list consumes the patches and connections GETs from feat(integrations): the connections group; the catalog route removed #251/feat(integrations): let agents discover company connections #264. --json is the wire body (top level merges { patches, connections }). docs/API.md correctly unchanged.
  • CLI. packages/patchy/README.md, ADR-0004, global skill, all five project skills, skills-lock.json. SHA-256 of skills/patchy/SKILL.md is 73e68e8dcf1ab1c21833b6c088c52013b2c3b783ff7f8762ed7fe1c9ddd34f77; the lock matches.
  • Dev loop. Packed e2e steps in docs/DEVELOPMENT.md and scripts/packed-cli-e2e.mjs. Runner/seed/vitest template N/A.
  • Vocabulary. Publishing Catalog removed, Discovery built. product.md § Sharing and finding moved from planned to built. CONTEXT-MAP and Integrations glossary updates are required, not drive-by.
  • Migrations, company resources, served pages, repo layout: N/A.

CLI tests

The implementation matches ADR-0004 Discovery. Holes that #252's Done when did not require, but the ADR lists:

  • --state retired on a live patch (live; pass --state live) at both depths, untested.
  • Default query state=live never asserted (stubs ignore search).
  • list connections without --all (no offered).
  • Wrong-level flags in text mode.
  • Packed e2e does not cover list patches, connections, or wrong_state.

Wrong-state JSON uses toMatchObject and does not require ok: false / error.

Summary

Standards: 3 findings (worst: Output.contract recovers WrongPatchState by _tag instead of catchTags). Spec: 0 findings.

@allisonmahmood

allisonmahmood commented Sep 15, 2026 •

Copy link
Copy Markdown
Owner Author

Addressed the review in commit 245511c. I read both conversation reviews and checked submitted reviews and inline comments; those contained no additional findings.

Fixed

  • Tagged error handling. Output.contract now uses Effect.catchTags for every known CLI failure. The handlers share ordinary failure rendering; WrongPatchState includes its state. One handler table avoids catching the already-rendered Failed sentinel a second time in a following generic catch.
  • Routing names. Renamed top and the boolean connections to isPatchList and isConnectionPath, removing the ambiguous name and payload shadowing.
  • Contract coverage. Extended the existing cases for a live patch requested with --state retired at both depths, the default top-level state=live query, and connection listings with and without --all. Wrong-state JSON now asserts the complete failure document, including ok: false, its error text, state, and no extra fields.

Kept as is

  • The verb "inspect" in prose. It describes reading metadata; it does not name a command or replace the Discovery domain term. Every executable example uses list. The glossary's naming guidance does not require banning the ordinary English verb.
  • Flag guidance across docs and skills. feat(patchy): patchy list replaces catalog; the skills teach the discovery chain #252 explicitly requires those distribution points. Installed global/project skills must give usable instructions without access to this repository's ADR or README. The shared-table skill already points to the loop contract and repeats the state rules that prevent declaring an unusable source.
  • Patch-reference decoding. It validates the first positional after URL normalization, including empty paths and decoded slashes. The other check validates the second positional. They are different inputs, not duplicate checks; the decoder stays compiled at module scope.
  • Connection snapshot text. The CLI supports text and JSON at every level. The printer exposes schema metadata and the unavailable-snapshot distinction, never business rows. Removing it would leave human-readable connection detail incomplete.
  • The shared-query sentence in product.md. It describes how discovery relates to the future portal, as feat(patchy): patchy list replaces catalog; the skills teach the discovery chain #252 requires; it does not implement or claim completion of portal behavior.
  • Command dispatch, help, and URL semantics. One command handles the open-ended patch reference. Help explains flag restrictions, and the handler rejects wrong-level flags. Although the lexical PatchName schema accepts patches and connections, Patches.reservedName rejects their creation, with API tests covering reserved_name. Pasted URLs deliberately resolve by their last segment per feat(patchy): patchy list replaces catalog; the skills teach the discovery chain #252; IDs remain available for legacy names.
  • Packed-e2e scope. It keeps the three required discovery levels against two real seeded patches. CLI/API suites cover state, connection and error contracts; multiplying every flag combination into packed e2e would duplicate those checks. Existing text-error tests and text wrong-state cases exercise the shared output contract.

Verification

The PR remains stacked on portal/251-connections-group; no merge or base change was performed.

@allisonmahmood
allisonmahmood force-pushed the portal/251-connections-group branch from 7e9fb39 to aebcfa1 Compare September 16, 2026 16:00
@allisonmahmood
allisonmahmood force-pushed the portal/251-connections-group branch from aebcfa1 to 986ea11 Compare September 16, 2026 16:34
Base automatically changed from portal/251-connections-group to main September 16, 2026 16:42
Implement issue #252 across the CLI, discovery skills, contracts, and packed e2e.
@allisonmahmood
allisonmahmood merged commit 4349fe7 into main Sep 16, 2026
8 checks passed
@allisonmahmood
allisonmahmood deleted the portal/252-patchy-list branch September 16, 2026 16:51
allisonmahmood added a commit that referenced this pull request Sep 16, 2026
Patch owners need to manage their patches from the CLI and keep repo
descriptions in sync with portal edits.

Adds lifecycle commands and description sync, with actionable refusals
and definition-change reminders. Notices remain visible when commands
fail or recover a saved publish attempt. CLI documentation and
distributed skills describe the new behavior.

Stacked on #265 (`portal/252-patchy-list`). This PR intentionally
targets that branch, not `main`.

Fixes #253.

## Verification

- `pnpm lint`
- `pnpm typecheck`
- `pnpm test`: 875 tests across 79 files passed
- `pnpm test:packed-cli-e2e`: complete real-server workflow passed

The full suite exposed a startup test's outer deadline being shorter
than its subprocess timeout. A separate commit aligns those deadlines
without changing the assertions.

Implemented with GPT-6 Astra in Oh My Pi.
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): patchy list replaces catalog; the skills teach the discovery chain

1 participant