Skip to content

A drafted Copy lands in the Work's draft, across lists too - #1635

Merged
haowjy merged 4 commits into
mainfrom
feat/copy-into-draft
Nov 16, 2026
Merged

haowjy merged 4 commits into
mainfrom
feat/copy-into-draft

Conversation

@haowjy

@haowjy haowjy commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Changelog

  • Added: Copy documents and folders into a Work's draft, including copies made by the AI across lists. Scratch copies remain live even when Draft is selected.

Why

Copy previously refused a draft destination, so it was the one tree action that ignored the Draft view. Copies should land in the view the writer or AI selected and be available to Apply or Undo with the rest of the Work's changes.

Examples

Copy into Draft

  1. Start the app with pnpm dev, open a project and a Work with pending changes, and select Draft in Sources.
  2. Copy a folder from Your files into the project. Open a copied document, then switch to Live.
  3. The copy and its text appear in Draft, but not Live. Apply the changes to publish them. The AI can also move across lists into the draft and undo or redo the copy.

Screenshots: Draft sidebar, copied content, AI card.

Benchmarks

On the shared development machine, two successful copies of 197 documents into a Work's draft took 11.37 s and 8.91 s end to end. Instrumentation in the second run measured 5.16 s after namespace lock acquisition: 3.94 s in tree insertion and admission, then 1.22 s writing draft content. A third run took 10.42 s end to end and held the list key for approximately 6.20 s through commit; draft admission accounted for 3.72 s. These are individual observations under load (load average 44 on 24 CPUs; a Work with hundreds of pending changes), not a comparison. Draft admission and content writes run once per document; batching them needs a batch boundary in the shared draft runtime (one savepoint for draft creation and append, keeping pre-seeded imports), which also serves Apply and import. That is its own PR, next.

Design decisions

  1. Copy reads each source document as shown in the selected tree view: a Work's draft when one exists, otherwise live. It records the content version actually read.
  2. Draft copies use the existing draft coordinator and branch tree transaction, rather than a second draft-writing path. Links are bound to copied identities before writing.
  3. The destination view is part of the command receipt, so a resend with a different destination conflicts instead of replaying the wrong result.

Changes

Part Why Key paths
Source and destination views Resolve folders and content in the selected tree domains/context/copy, domains/context/adapters/context-fs
Draft content Create the branch tree and write text through the draft runtime domains/collab/domain/effective-document-reader.ts
Writer and AI Send the destination view and report the draft destination features/project/context, lib/model-tools
Protocol and docs Signal the request shape to old tabs and describe the new behavior packages/contracts/src/release, .context

Compatibility and risk

  • Migrations and state: no migration; existing trees and documents remain in their current format.
  • Clients during a deploy: protocol minimum and current rise to 3; older clients reload at a pause. Requests without a destination view retain live behavior until then.
  • Rollback: existing draft copies remain stored; the reverted client cannot make new ones through this path.
  • Where to look: transaction and draft-content writes, source view selection, and Undo receipts.

Verification

  • Review fix: destination branch selection now checks the destination scheme in the copy port, and the AI passes its grant destination. A contained draft content write fails the copy rather than silently losing text. On the final stack, a request carrying Draft to Scratch returned 200 and the copied text was readable live; the same request to Manuscript returned 200 and was absent from Live. A mock-model cross-list move in a draft-mode chat succeeded and its copy was absent from Live. Browser verification of this fix remains outstanding.

  • Browser: the prior run copied a folder into Draft, checked it was absent from Live, and applied it with text. Screenshots above.

  • Model: a live deepseek-flash chat copied across lists into Draft; card Undo and Redo changed the pending count from 8 to 6 and back to 8.

  • API: live and draft destinations, draft-only source, draft-only destination folder, mixed live/draft source folder, command ID conflict, and a copied internal link were exercised in the prior run.

  • Tests: prior run passed pnpm test:db (93 files, 605 tests) and draft-pulls.test.ts (3 tests). No tests added.

  • Combined live model and browser run: the AI copied a document, a linked folder and a PNG into a fresh draft. Card Undo and Redo restored the changes; Apply published the text and the image, which rendered in Live. After Apply, following the copied link opened the copied target in Manuscript. Large-copy batching remains outstanding.

  • Gates: pnpm test:db passed after the review fix (93 files, 605 tests). pnpm check failed on three unrelated test timeouts under machine load; its typecheck passed, and all three timed-out files passed on a focused rerun (8 tests). pnpm check:pr-body passed. Before the fix, pnpm check passed on commit 8dca757d63.

Deferred

  • Batch draft admission and content append for large copies: a collab-owned batch boundary (one savepoint over draft creation and append, existing draft runtime semantics, pre-seeded imports preserved), its own PR right after this one. A 197-document drafted copy holds the list for about 6 s meanwhile; a copy that size is rare.

References

  • Work item: project tree design and copy-into-draft plan.
  • Related: Copy, not move, at a project's edge #1598 introduced Copy across lists.
  • Docs updated: context copy, runtime tools, and tree-version state machine.
  • After merge: none.
Spawn Agent Model Role
p17930 coder See spawn record Implementation and prior verification
p17988 coder See spawn record Resume and final checks
p18009 coder See spawn record Gate, combined probe and timing investigation
p18035 coder See spawn record Review fixes and stack checks

@haowjy
haowjy marked this pull request as ready for review November 16, 2026 02:16
@haowjy

haowjy commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

Tree lead sign-off: plan reviewed (p17753) and revised; code review p18021's blocker (Copy into Scratch on Draft = 500) fixed at its cause in b1d17a8 (the copy port picks a branch only for drafted schemes; grant and placement now one decision) and checked on a stack; browser run p18046 passed folder copy into the draft + Apply + link, draft-only source copied with its text, the AI's drafted cross-list copy and its Undo, Discard. main merged (0a6d62f), test:db 605, CI 10/10. Batching large drafted copies is the next PR (plan approved with changes).

@haowjy
haowjy merged commit b02ea07 into main Nov 16, 2026
10 checks passed
@haowjy
haowjy deleted the feat/copy-into-draft branch November 16, 2026 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant