Skip to content

feat(cli): patchy delete takes a page down with the key that published it - #111

Merged
allisonmahmood merged 2 commits into
mainfrom
t3code/implement-issue-41
Sep 2, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
t3code/implement-issue-41

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Sep 2, 2026 •

Copy link
Copy Markdown
Owner

Onboarding teaches users to say "take that page down", and the skill promises their publishing key lets them delete pages, but the CLI had no delete command. The server already allowed an owner to delete, so this was CLI-only.

patchy delete <file> | --patch <id> resolves the patch from the cache entry the file's upload left behind, or from the flag, and deletes it with the same credential chain as upload. It never mints: a fresh key would own nothing. The cache forgets the patch only after the instance says yes, so a refusal leaves local state as it was. A missing or unowned patch is a rejected failure (exit 2). --json prints the wire Ok shape.

One vitest covers the flow against the stub instance (upload, delete by file, cache emptied, second delete 404s, no key means no request), and the packed real-server e2e proves the viewer URL answers 404 right after the delete. README, ADR-0004, the CLI CONTEXT.md and the patchy skill carry the one-line mirrors, with the skill hash refreshed in skills-lock.json.

Closes #41.

Written by Claude Fable 5.1 in Claude Code.

…d it

Onboarding teaches "take that page down", but the CLI had no way to do
it. `patchy delete <file> | --draft <id>` resolves the draft from the
cache or the flag, deletes it with the same credential chain as upload
(never minting), and forgets the cache entry on success. --json prints
the wire Ok shape. Closes #41.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@github-actions github-actions Bot added area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area size:m 100-500 changed lines labels Sep 2, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Code review — PR 111 / issue 41

Two-axis review (origin/main...HEAD, 73f6252) plus the extra passes you asked for: issue 41's intent vs what landed, the method, and YAGNI. Six sub-agents; Standards and Spec were kept separate on purpose.


Standards

No hard documented-standard breaches. Delete follows upload / whoami: Output.contract (ADR-0004: no command exits on its own), --json is encodeOk(Ok) ({"ok":true}), 404 → rejected, missing key/cache → local. Surfaces that apply were hit: README, ADR-0004, ADR-0002, CONTEXT.md patch cache, skill + matching skills-lock.json hash (e73a69c1…e49397), tests, packed e2e. docs/API.md already had DELETE /api/patches/:patchId. Reverse of cachePatch is forgetPatch after success.

Effect (.agents/skills/effect-service-conventions/SKILL.md)

No Effect service findings.

forgetPatch is on the inline State interface, implemented in make, deps still yield*'d. Effect.catch is the whole ClientFailure channel (404 then refused), same as upload — allowed when the channel is handled in full. Named @patchy/api / CliError imports; State / Instance / Api namespaced.

Documented — judgement

Publishing key vs token — packages/cli/CONTEXT.md (Publishing key: avoid token in user-facing copy); commands.ts header says the same.

`No publishing token is stored for ${instance.apiUrl}, so nothing there can be deleted from this machine.\n` +

Same handler's 404 says "publishing key". Mirrors whoami; glossary still wants key on new copy.

Skill exit-code examples — CLAUDE.md "Hit every surface" / CLI → public skill. skills/patchy/SKILL.md still illustrates 2 as "a missing update target"; README and ADR-0004 added delete. The command itself is taught.

Baseline smells — all judgement (YAGNI / existing CLI voice win)

Inaccurate error copy (deleteTarget): neither-args and both-args share "not both." Prefer "file or --draft, not both / not neither."

Not flagged: del (reserved delete); 404 catch paralleling upload (different next action — extracting would be speculative generality); forgetPatch by patchId (needed for --draft and dual file keys); the 10-file scatter (required mirrors, not Shotgun Surgery).


Spec

(a) Missing or partial

None of the Do-list items are missing. patchy delete <file> | --draft <id> resolves from the cache or the flag, forgetPatch runs only after a successful delete, the command description includes "Irreversible. Confirm with the user first.", --json encodes the shared @patchy/api Ok wire type ({"ok":true}), SKILL.md maps "take that page down" to the command, and the vitest deletes with the publishing key then treats a follow-up delete as gone.

(b) Not asked for

Spec Do-list is the command, cache drop on 2xx, description text, one vitest, --json, and one skill line.

  • Never mints. Spec: "An agent following the skill can take a page down with the same key it published with." Delete uses configuredToken only and errors locally if none is stored. Aligned, but not in the Do list (upload still mints).
  • forgetPatch drops every cache row for that patchId, not only the named file. Spec: "dropping the cache entry on 2xx."
  • Packed e2e (viewer 404 + cache drop + second delete exit 2). Spec: "One vitest: delete, then the draft 404s."
  • Vitest also covers XOR, keyless, and post-forget file lookup. Same spec line.

README / ADR-0004 / CONTEXT / skills-lock are repo surface, not extra product behavior. ADR-0002's --json mention is extra to #41.

(c) Implemented but wrong

Spec: "patchy delete <file> | --draft <id>" — exactly one of file or flag.

deleteTarget handles --draft alone, then:

if (Option.isNone(file) || Option.isSome(draft)) {
  return yield* new LocalError({
    message: "Pass the file the draft was uploaded from, or --draft <draft-id>, not both."
  });

Bare patchy delete (neither) is that same "not both" local error. The | form is rejected, but the message is wrong.

The required vitest's "then the draft 404s" is a second delete --draft mapped from stub PATCH_NOT_FOUND (exit 2). After a successful file delete, delete <file> is local exit 1 and never hits the instance. Viewer 404 is only in packed e2e, which the spec did not require.


Intent vs issue 41

Done-when holds for the path the issue named. After patchy validate './plan.html' && patchy upload './plan.html', mint writes the key and drafts.json maps the resolved file to the id. patchy delete './plan.html' uses configuredToken (same chain as upload) and readCachedPatch. That is enough.

Missing a skill-side delete --json example, env-token prose, or a CLI confirm prompt would not block it: every command already takes --json; the minted key is already stored; the issue wanted the agent to confirm, not a TTY prompt. Command description and skill both say confirm-with-the-user; the CLI never prompts — correct for an agent CLI.

They hit the Do-list and the spirit (never-mint, cache-on-success, README/ADR/CONTEXT, real-server 404). Not letter-without-spirit.

What is still open is the next-time loop onboarding taught, not the same-session reverse door:

  1. Skill frontmatter still triggers on publish/onboarding, not on the words onboarding tells users to say ("take that page down"). An agent already following the skill can delete; a new session that only hears that phrase may never load it.
  2. Onboarding sign-off lists the phrase; the sample transcript still closes with only "publish this with patchy". onboarding.md was not in the diff — letter of "one line in the skill."
  3. CLAUDE.md's "way to see it" is still thin. status --json does not list drafts. A later "take that page down" with no file in context has only ./plan.html as the skill example (onboarding published welcome.html) or --draft <id> with no teaching that /d/:id is that id.

Same-session take-down with the publish key works. The one-way user sentence is only half-closed. I would not block #41 on (1)–(3); they are the next DX cut, not a miss of the ticket.


Method

Reuse, correctly. Delete hangs off the same Instance / State / Api.client / Output.report / configuredToken / PATCH_NOT_FOUND / refused path as upload. Api.ts is untouched; client.delete already exists. The one intentional fork is right: upload mints when configuredToken is None; delete refuses ("a fresh key owns nothing"). Cache is forgotten only after the instance says yes. That is the smallest reverse of upload.

forgetPatch by patchId is justified, not gold-plating. cachePatch is keyed by file. upload B --draft <id-of-A> writes the same id under B. Dropping only the file you passed would leave B pointing at a corpse; --draft has no file at all. Scanning this host's map is the actual reverse of "later upload must not update a dead patch." Tests never prove the multi-file case (only that one file's slot is empty).

XOR control flow is the one real agent-DX bug in the method: both and neither take the same branch, so patchy delete with no args is status 1 and "not both." Upload's --draft/--new check names the actual conflict. Two errors (neither vs both) would be the obvious control flow.

Packed e2e: the comment is true today, and it is a time bomb. Last cliEnv write of fixtureCachePath is the --anonymous --new upload (deprecatedFlag). Later uploads of that fixture use other state dirs. Insert another cliEnv upload of the same artifact and delete silently retargets. A dedicated upload-then-delete on cliStateDir would not depend on script order.

File-only + drop-one-key would be smaller and wrong. forgetPatch (~16 lines) is the smallest correct State method. Layering is clean: command resolves target and talks HTTP; State owns the host map.


YAGNI / beautiful code

No speculative generality that matters. deleteTarget is a one-consumer helper, same shape as readHtml / validated, not a new layer. Scanning the file map instead of a reverse index is the small model.

The one it with a live Set stub is the focused test: delete, then a real 404 from the same handler. both and keyless are extra beats packed into one it to keep the "one vitest" budget — packing, not slop. Packed e2e is a different surface (real viewer 404), not a second smoke.

Comments on deleteTarget, del, and forgetPatch encode invariants. Stale: cli.test.ts says the next upload from the file is a create; the body then asserts a file-delete local error.

The XOR in deleteTarget is a bit golfy. if (isSome(file) === isSome(draft)) would be the obvious exclusive. Not worth a new abstraction — just a flatter if.

Beautiful: del is upload's control flow with the mint/HTML branches deleted. Order of forgetPatch after success is the whole cache invariant. Shared PATCH_NOT_FOUND / refused / configuredToken. Skill is one mapping line. del vs delete is fine (const delete = is a SyntaxError; the user-facing name is still Command.make("delete", …)).


Hit every surface

Surface Applied? Hit?
Wire contract yes (existing DELETE) yes — derived client, encodeOk(Ok), docs/API.md already documents it
CLI (README, ADR-0004, skill, skills-lock) yes mostly — leftover examples below
Dev loop no —
Vocabulary yes yes; remaining "draft" copy is the filed #92 rename
Migrations no —
Served pages no packed e2e viewer 404 is serving proof, not HTML/CSS
Reverse states yes — this PR is the way out way in / way out / way to see (CLI success, forgotten cache, re-delete rejected, e2e viewer 404). No list-of-live-pages; pre-existing
Repo layout no —

Leftover examples, not contract holes:

  • README PATCHY_API_TOKEN: still "ordinary authenticated commands such as whoami and upload"
  • Skill --json: still only upload --json; no delete → { "ok": true }
  • Skill exit-code examples: still "a missing update target"

Summary

  • Standards: 3 findings, all judgement. Worst: deleteTarget error copy ("not both") covering neither-args.
  • Spec: 2 findings. Worst: same XOR message is wrong for bare patchy delete. (The vitest 404 is the API 404 via --draft, not a viewer 404 — a reading of "then the draft 404s", not a missing Do-list item.)

I would not block on the leftover skill/README examples, the e2e seam, or the onboarding-trigger gap. The one change I would make on this PR is splitting the neither vs both errors so an agent that types patchy delete is told what to pass, not that it passed both.

- delete speaks patch: `--patch <patch-id>`, "Deleted patch", patches.json
- neither-target and both-target are separate local errors
- keyless message says publishing key, per the CLI glossary
- vitest proves forgetPatch drops every file pointing at the patch
- packed e2e delete step does its own upload instead of relying on script order
- skill and README examples name delete where they listed whoami/upload

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Thanks for the review. Merged main (#110 landed the draft→patch rename) and pushed d6df07b. Lint, typecheck, the CLI suite (23) and the packed real-server e2e are green on the merged tree.

Fixed

  • Neither vs both. deleteTarget is now a flat if with two errors: bare patchy delete gets "Pass the file the patch was uploaded from, or --patch <patch-id>." and file + flag gets the same with "not both". The vitest asserts each.
  • Publishing key, not token. The keyless message now reads "No publishing key is stored for …", matching the glossary and the 404 copy in the same handler.
  • Stale test comment. The comment said the next upload from the file would be a create; the test now proves what forgetPatch is for instead: a second file pointed at the same patch via upload --patch, one delete, both cache entries gone.
  • Packed e2e seam. The delete step does its own upload --new on the authenticated state dir and deletes that, so inserting another cliEnv upload earlier can no longer retarget it.
  • Leftover examples. README PATCHY_API_TOKEN lists delete beside whoami and upload; the skill's exit-code example says "a missing update or delete target" and its --json bullet says delete --json prints { "ok": true }. Skill hash refreshed.
  • Vocabulary. With fix(cli): say patch, not draft, in user-facing copy #110 in, the command speaks patch throughout: --patch <patch-id>, "Deleted patch / Patch ID", patches.json.

Kept as is

  • Never mints. Not in the Do-list, but it is the done-when: "with the same key it published with". A minted key would own nothing, so minting on delete could only ever produce a 404.
  • forgetPatch drops every entry for the id, not one file. upload B --patch <id-of-A> writes the same id under B, and --patch has no file at all. Dropping one key would leave a cache entry pointing at a deleted patch. Now covered by the test.
  • Packed e2e viewer 404. Beyond "one vitest", but it is the only place the literal "then the page 404s" is proven against a real server. Thirty lines at the tail of an existing flow, no new harness.
  • Onboarding trigger gaps (skill frontmatter, sample transcript sign-off, no list-of-live-pages). Agreed these are the next DX cut, not this ticket. Happy to file them.
  • del as the binding name. delete is reserved; the user-facing name is still patchy delete.

Written by Claude Fable 5.1 in Claude Code.

@allisonmahmood
allisonmahmood merged commit 20b388d into main Sep 2, 2026
6 checks passed
@allisonmahmood
allisonmahmood deleted the t3code/implement-issue-41 branch September 2, 2026 14:17
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 size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(cli): patchy delete

1 participant