Repository navigation
feat(deck): Markdown draft editor over workspace drafts folder (#66) - #68
Conversation
Drafts are plain files under <WORKSPACE_ROOT>/drafts. The Deck page edits and saves them, shows last-saved time and person/agent writer, and warns visibly when the file changes outside the editor. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GNgHnmc7XDCrYeFW1SMTDd Signed-off-by: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Review of 40f5943. Scope is right: the first slice from #66 is all here (open/create, edit, save, last-saved time, person/agent writer, visible conflict alert). There is no rich text, no integration and no new service, and #65 is untouched. Confinement, symlink refusal, the 409/force path and the temp-workspace tests are solid. One real bug and a few smaller points.
1. Every browser save writes CRLF line endings, and the editor then shows "unsaved changes" for good (must fix)
DraftEditor.tsx:49-53 sends the body as multipart FormData. The multipart encoding algorithm in the HTML spec rewrites every bare LF in a string value as CRLF. Browsers do this, and so does Node's undici. I checked it against this branch: POSTing content: "a\nb\n" through the real action in api.drafts.tsx leaves "a\r\nb\r\n" on disk and in the returned draft. Two things follow:
- Agents and git see CRLF files in
drafts/, which goes against the repo's LF policy. - After a save,
setLoaded(body.draft)holds CRLF content buttextis still LF, sodirty(DraftEditor.tsx:69) stays true. The status line keeps saying "unsaved changes" and Save stays enabled.
Suggested fix: normalise on the server in saveDraft (drafts
8000
.server.ts:224, before the size check and the hash) with content.replace(/\r\n?/g, "\n"), so a CR-only file is converted too. Add a route test that posts multi-line content and asserts LF on disk. The current route test only uses single-line content, and the jsdom test stubs fetch, so neither can see this.
2. Unhandled throw inside the lock (low)
drafts.server.ts:245 calls view() inside withInboxLock. If drafts/x.md is a directory, or the file vanishes between existsSync and statSync, the action throws and you get a framework 500 rather than the JSON error the client expects. Wrapping it in try/catch and returning { ok: false, status: 500 } would fix it.
3. Sidecar read-modify-write is locked per draft, not per sidecar (low)
drafts.server.ts:242/266: the lock is on <draft>.lock, but .deck-drafts.json is shared. Within one process this is safe, because readMeta..writeMeta runs with no await (I ran 80 concurrent cross-draft saves and lost no attributions). Two Deck processes on the same workspace could still drop each other's "person" record. Either note it next to the code or lock the sidecar path.
4. Small things
- A relative
WORKSPACE_ROOTsilently disables the feature, becausedraftsEnabledswallows the error atdrafts.server.ts:86. A startup warning would save some head-scratching. request.formData()(api.drafts.tsx:51) buffers the whole body before the 1 MB check. That is acceptable on loopback, but the cap only limits what gets written, not what the server accepts.- The SPEC Log says "Commits: see branch". DEVELOPMENT.md asks for the short sha.
On authorship: "agent" meaning anything else is acceptable for this slice, because the UI says "the agent (changed outside this editor)" and the limitation is stated up front in the PR.
Generated by Claude Code
…ck sidecar (#66) Multipart posts turned LF into CRLF, leaving the editor permanently dirty. Saves now store LF. Failures inside the save lock return JSON errors, the shared sidecar update takes its own lock, and a relative WORKSPACE_ROOT logs a warning. Adds route and editor tests for save, load-newer and keep-mine. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GNgHnmc7XDCrYeFW1SMTDd Signed-off-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GNgHnmc7XDCrYeFW1SMTDd Signed-off-by: Claude <noreply@anthropic.com>
|
Re-review at b2edbbb. The earlier findings are fixed. LF normalisation runs before the size check and the hash, and on Node 22 undici really does post What's left:
Generated by Claude Code |
…ve result after write (#66) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
Review findings for head
|
|
Automated review (CodeRabbit CLI, run against this branch) found one issue, which agrees with the data-loss concern above: Major, - => e.target.value && void open(e.target.value)}
+ => {
+ const next = e.target.value;
+ if (!next) return;
+ if (dirty && !window.confirm("Discard unsaved changes?")) return;
+ void open(next);
+ }} |
…oss-origin writes (#66) Confirm before switching or creating over unsaved edits; drop save and poll responses that no longer match the editor; return the version a save wrote; re-check confinement inside the lock; refuse cross-origin browser writes; never read files over the cap; keep a copy of a corrupt sidecar; move the dev workspace out of .runtime. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
…ate (#66) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
|
Addressed in ddd1b7b (pushed to this branch; no history rewrite). Replies per finding, with the review items and the CodeRabbit comment together. Major (Review A and CodeRabbit)
Minor
SPEC log updated. Checks on the clean tree at ddd1b7b: Generated by Claude Code |
Review at head
|
…ng, capped fd reads (#66) Check Origin against the shared VOICE_ALLOWED_ORIGINS allowlist instead of Host, so DNS rebinding is refused and allowlisted proxies work. Make the editor read-on 8BD0 ly while an open or create is pending, show the server's message when opening fails, disable force-save buttons during a save, read drafts and the sidecar through a capped file descriptor, and never follow a symlink at the sidecar backup path. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
Review at head
|
…nv isolation (#66) Open drafts and the sidecar with O_NONBLOCK so a FIFO cannot freeze the server, refuse non-regular files, stop zero-filling a 1 MB buffer per read, pass VOICE_ALLOWED_ORIGINS to the dev app so --port works, document the requirement, and pin PORT and VOICE_ALLOWED_ORIGINS in the draft tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
Review at head
|
A blocked synchronous open cannot be interrupted by the test timeout, so the FIFO cases now spawn the real module in a child with a 20 s limit and fail cleanly on regression. Skipped, not passed, where mkfifo is missing. The symlink case targets a FIFO inside drafts/. Stat the path before opening as a mitigation; fstat stays authoritative. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
Review at head
|
…t keeps drafts (#66) Read the sidecar only if it resolves to itself inside the drafts folder, is not a symlink (O_NOFOLLOW) and has one hard link, and write the .bad backup from the confined read instead of copying through the path. Extract the dev reseed into scripts/dev-paths.mjs so a test runs the real reset and shows drafts survive it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
…lose (#66) useBlocker asks before an in-app navigation while the draft is dirty, and a beforeunload listener is registered only while dirty and removed after. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
Review of c73eadf (Opus)Verdict: changes requested. The sidecar fix holds: every sidecar exploit variant I tried is refused. Two problems from the same class remain in other paths, and I reproduced both against this head. The unsaved-edits guard and the dev reseed are correct. Findings
Verified, no finding
CI on c73eadfAll 4 check runs completed with success: Unverified
Generated by Claude Code |
…sive random temp files (#66) Refuse a draft with more than one hard link on the open descriptor, require the file a draft name resolves to to be a draft name, and write drafts, the sidecar and backups through an O_EXCL temp file with an unpredictable suffix instead of the shared predictable-name helper. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
|
Re-review at a050c6d. Verdict: approve. Both Majors from round 9 are closed, and I found no new real bugs. Re-exploits, run against the real module in a throwaway workspace
Findings: none at Major or Minor. CI on a050c6d: guards passed, licence passed, test (22.x) passed, test (24.x) passed (4/4). Locally: Scope: the diff touches only #66 files; #65 is untouched. Commits after b2edbbb have no Claude-Session trailer. Unverified
Generated by Claude Code |
Closes #66 (first slice only; see Follow-ups).
Known limitations (read first)
request.formData()reads the whole request body before the 1 MB content cap is applied, so the cap bounds what is stored, not what is received.VOICE_ALLOWED_ORIGINS(defaulthttp://localhost:$PORTplus the dev port), checked against the Origin header, not Host, so DNS rebinding is refused. Reaching Deck by another name, or through a proxy that rewrites Host, needs that origin listed (setting it replaces the default). Requests with no Origin or Sec-Fetch-Site (an agent using curl) pass. Draft reads over GET are not origin-protected, like the rest of Deck..deck-drafts.jsonis a symlink, is hard-linked, or resolves outsidedrafts/, it is ignored: every draft reads as "agent" and attribution is not recorded until the file is fixed (drafts still save)..lockfile (a token only) can be created outside the workspace before the re-check refuses the write; no draft content is written there.Draft.mdvsdraft.md) were not examined. Reads are synchronous, bounded to 1 MB each.atomicWriteinsafe-fs.server.ts(used by the inbox and other stores) has a predictable temp name and follows a planted symlink; the drafts module no longer uses it.withInboxLockalso does a blocking synchronous read of its lock file on release.TL;DR
A draft is an ordinary
<WORKSPACE_ROOT>/drafts/<name>.mdfile, so an agent reads and writes it with its normal file tools. The Deck gets a Drafts page (plain textarea) to open, create and save drafts. It shows last-saved time (file mtime) and whether the current version was written by the person (via this editor) or the agent (anything else). If the file changes outside the editor while open, a visible alert offers "Load the newer copy" or "Keep mine and overwrite"; a draft removed outside gets its own alert with "Keep mine and recreate". No rich text, multi-cursor, external integrations or new service. Large-paste and attachment behaviour (#65) is untouched.Design
app/lib/drafts.server.ts: list/read/save. Flat*.mdnames only, confined to the realpath ofdrafts/and re-checked inside the lock right before the write; the file a name resolves to must itself be a draft name; symlinked drafts, hard-linked drafts and adrafts/symlink out of the workspace are refused. Writes go through anO_EXCLtemp file with a random suffix, then rename. 1 MB cap (files over it are never read: open answers 413 with a message, the list shows them unread, save refuses). Reads stat first, open non-blocking (a FIFO cannot freeze the server), refuse non-regular files after fstat, and go through one file descriptor capped at the limit plus one byte. CRLF/CR normalised to LF on save.force. The save result is the version that save wrote. Check and write run under the advisory lock; the shared sidecar update takes its own lock. Errors inside the lock return JSON.drafts/.deck-drafts.jsonholds the hash the Deck last saved; match = person, else agent. The sidecar is read only if it resolves to itself insidedrafts/, is not a symlink (O_NOFOLLOW) and has one hard link. A corrupt sidecar is backed up to.deck-drafts.json.bad(written from the confined read, never through a link) and logged before being replaced.beforeunloadguard (only while dirty) cover in-app navigation and tab close; read-only while an open or create is pending; stale save and poll responses are dropped; force-save buttons are disabled during a save.GET/POST /api/drafts(POST refuses non-allowlisted browser origins with 403),/draftspage,DraftEditor, optionalWORKSPACE_ROOT(unset hides the feature; a relative value logs a warning and disables it). The dev script defaults it topackages/deck/.workspace/(gitignored), outside the.runtime/directory that is wiped on every start (the reseed is inscripts/dev-paths.mjsand a test runs it), and passesVOICE_ALLOWED_ORIGINSto the app so--port Nworks.SPEC:
.specs/claude-dazzling-davinci-h66qwp-issue-66/SPEC.md. Every review finding and its outcome:.specs/claude-dazzling-davinci-h66qwp-issue-66/REVIEW.md.Test plan (clean tree, head a050c6d)
pnpm typecheck: exit 0pnpm test: base 48 passed; deck 112 files, 2309 passed, 11 skipped (new suites:test/drafts.test.ts,test/draft-editor.test.tsx; the FIFO cases run in a child process with a 20 s timeout and report as skipped where mkfifo is missing)pnpm check:boundaries: no dependency violationspnpm check:leaks: clean (444 files, 33 rules)pnpm check:licence: okpnpm check:lib-version: no collisionpnpm -C packages/deck check:dashes: exit 0Follow-ups
atomicWrite.🤖 Generated with Claude Code