fix(api): PATCH /api/posts/:id — update preserves surface kind#155
Merged
Conversation
sideshow update always treated content as HTML, clobbering the original
surface kind (markdown → html, code → html, etc.). Add a PATCH endpoint
that accepts raw content and slots it into the existing surface's kind,
preserving extra fields (language, cols, layout, etc.).
- PATCH /api/posts/:id: accepts { content, title, kits }, reads the
existing post's first surface kind, maps content into the correct
field, validates, and delegates to reviseSurface. Errors on
multi-surface posts (400) and non-text kinds like image/trace (400).
JSON surfaces parse the content string. HTML surfaces accept kits.
- CLI update command: switches from PUT with hardcoded {kind:'html'} to
PATCH with {content, title, kits}.
- 18 new API tests covering every surface kind, field preservation,
error cases, title-only updates, version history, and feedback.
Closes the update-kind-bug where `sideshow update <id> file.md` on a
markdown post would render raw markdown as HTML.
Member
I think I want the proper solution or we're just moving stuff around and forgetting why it's there. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
sideshow update <id> <file>always treated the file as HTML, regardless of the original surface's kind. Updating a markdown post turned it into an html post; updating a code post lost the language; updating a diff lost its layout — every non-html surface kind was clobbered.Wherein I argue this is good enough for now
This isn't a full solution to this problem. The API that
sideshow updatewas originally using allows you to do a fine grained update of all the parts/surfaces of a post. However, there's no concept of managing individual surfaces elsewhere in the cli api surface (except implicitly viasideshow publishif you give multiple--<format>args.This is a stand-in fix before proposing something more complicated (e.g. offering the ability to update
--part Nof a post, but to support this there should probably also besideshow show :postId, have this list part indices, etc.I think the current PR is a pragmatic solution because auditing sessions of agents using sideshow, I see that they often just do
sideshow update :postId /path/to/something.md. So this is the expectation from the cli help documentation and I think it's reasonable considering most posts are single surface anyway. After making the update, the agent will notice that it accidentally set the kind tohtml, then they try stuff likesideshow update :postId --md /path/to/something.md, probably imitating howsideshow publishkind flags work, and then eventually resort to making a raw PUT to the API.Again, I want to make a deeper fix for this but IMO this would solve most of the problem right away.
Solution
A new
PATCH /api/posts/:idendpoint that accepts raw content and slots it into the existing surface's kind, preserving all extra fields.NOTE: I didn't want to modify the existing update API and make it "clever" by detecting this special case because I think it's useful to be able to do more complicated fine grained updates. Again, I think there should be a better cli ui for doing those updates.
Server:
PATCH /api/posts/:idAccepts
{ content, title, kits }— all optional, at least one ofcontent/titlerequired. Whencontentis provided:markdown→.markdown,code→.code,diff→.patch,terminal→.text, etc.)language,cols,layout, etc.)jsonsurfaces, parses the content string into a valuehtmlsurfaces, optionally updateskitsreviseSurfaceflow (validation, history, SSE broadcast, feedback collection)Errors cleanly on:
--surface Ntargeting)image/trace→ 400The existing
PUT /api/posts/:idfull-replacement API is unchanged.CLI
sideshow updatenow usesPATCHwith{ content, title, kits }instead of constructing{ kind: "html", html: content }and PUTting. No flag changes — it just works.Tests
18 new API tests covering:
Validation
npm test(282/282) ·typecheck(3 programs) ·lint·format:check— all green.