Repository navigation
Save plan review's linked-document comments per document (#1545) - #2263
Merged
Merged
Conversation
… the draft GET (#1545 review) - Shared store: settle() and countUnsent() act only on index entries this session can serve (offered()'s check). A decision drops the session's own entries and keeps the rest; the index file is deleted only when empty. The same plan, message or page in two working folders no longer lets one decision delete the other folder's unsent comments. - GET /api/draft/document marks the copy as the session's, so it gets the writes' cross-site guard on the Bun and Pi plan and annotate servers. - Banner: 'Found 1 annotation on 1 linked document' when the root has none. - Scenarios (both runtimes): approve clears; two working folders for plan, last-message and URL sessions; cross-site GET refused. Bun only: the plan file allowance (linked file accepted; unlinked sibling, symlink out, traversal, relative refused). - inbox-e2e.yml runs on editor, plan/annotate server and draft store changes.
… e2e (merged from main)
…-drafts # Conflicts: # tests/e2e/playwright.config.ts
…y per line) # Conflicts: # tests/e2e/playwright.config.ts
…and inbox-e2e.yml comment: keep both)
… take main's glob)
backnotprop
pushed a commit
that referenced
this pull request
Oct 31, 2026
… send clears only what that page saw - Every annotate session with per-document copies (a file, a folder, a bundle) now keeps the index #2263 gave plan review and URL / last-message sessions, so GET /api/draft offers every document's comments after a reload instead of only when each document is opened again. - The store remembers which copies each page (`?client=` page id) read, wrote or restored. A decision that names a page clears only those, so a reloaded or crashed tab's copies the new page never saw survive its send. A caller without a page id clears what this server wrote, read or offered, and no longer every copy the index lists. - Both runtimes (Bun and Pi) pass the page id on /api/draft/document and on every decision route, plan review's included. - Scenarios, both runtimes: the reported loss (three files, reload, open one, send), a page that restores everything and sends, a second tab's decision, Close from a reloaded page, and a single-file session's linked document.
1 task
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.
Fixes #1545 (plan review with linked docs)
Problem
In plan review, and in annotate sessions with no file of their own (a URL or the last message), the draft held only the document that was open:
#1710 fixed this for annotate on files and folders by saving each document under its own path (
/api/draft/document). This PR gives plan review, and the URL and last-message annotate sessions, the same per-document saving, through the same shared code. It changes both runtimes.What changes
Shared (
packages/shared/annotate-draft.ts, vendored to Pi)createAnnotateDraftSessionintocreateDocumentDraftStore. Annotate file and folder sessions behave as before. The existing Annotate drafts follow the file's path (0.29 PR 2) #1710 scenarios pass on both runtimes. One was rewritten on purpose: "a URL session has neither a path copy nor document copies" became "a URL session has no path copy, but its linked documents get copies", because URL sessions now get document copies (this PR's change). Every other Annotate drafts follow the file's path (0.29 PR 2) #1710 scenario is unchanged.indexKey: a session whose root has no file keeps a durable list of the copies it wrote or read (documentDraftIndexKey(<session draft key>)).loadSessionDraftWithDocuments: GET/api/draftaddsdocuments: [{ path, annotations, globalAttachments }]for every listed copy. If only linked documents have comments, it returns a draft with no root comments. That draft carries the session key's generation, so the client resumes above a tombstone.409.isAllowed, not the session's own file). On a decision it drops its own entries and keeps the others; the index file is deleted only when it ends up empty.doc-resolve.ts:isPlanLinkedDocPath, so the Bun plan server accepts exactly the documents/api/docserves beside the plan file.Bun (
packages/server/index.ts,packages/server/annotate.ts)/api/draft/document./api/planadvertisesdocumentDrafts: true./api/draftoffersdocuments. POST and DELETE of/api/draftare unchanged, so a single-document plan's draft is served exactly as before.unsentAnnotationscounts them.annotate-lastsessions get per-document copies with the index (annotateSessionHasRootlessDocuments)./api/draft/documentmarks the copy it reads as the session's (and lists it in the index), so a decision clears it. It now has the same cross-site guard as the writes (isSameOriginOrNoOrigin,403), on the plan and annotate servers.Pi (
apps/pi-extension/server/serverPlan.ts,serverAnnotate.ts)/api/draft/document(with the cross-site guard on GET), the advert, GET/api/draftwithdocuments, and clearing on approve and deny.unsentAnnotationscounts them on status and close./api/docserves nothing beside the plan file.Client
useAnnotationDraft(@plannotator/ui, additive):documents, and the bannercountincludes them.draftBanner.documentsanddraftBanner.documentComments(how many ofcountare on other documents) are set only when there are other documents, so a root-only banner is byte-identical to before.restoreDraft()returnsdocuments.dismissDraft()returns the documents it discarded.useLinkedDoc.restoreStoredDocumentsputs restored comments on their own documents before those documents are opened, so they count, list and reach the feedback at once.adoptRestoredCopies), so it is not merged a second time.discardCopies).composeSessionDraft, now on for plan review). Opening an empty linked document therefore never empties or deletes it.Docs: a new "Linked documents in plan review" section in
plan-review.md, the session scope inannotate.md, and the API table rows inserver-and-storage.md.Tests (fail on main, pass here)
packages/server/linked-document-drafts.scenarios.ts, run bypackages/server/linked-document-drafts.test.ts(Bun) andapps/pi-extension/server/linked-document-drafts.test.ts(Pi).unsentAnnotations1), decides, and clears its own copy; back in A, A's comment is still offered.403and does not list the copy.planFileDocuments): a plan file in aplans/folder outside the project. The linkedbeside.mdis accepted; an unlinked sibling plan, a linked symlink that points outside, aplans/../outside.mdtraversal, a linked../outside.mdand a relative path are refused (rejectedon POST;403, or400for the relative path, on GET).packages/ui/hooks/useAnnotationDraft.documents.test.tsx.packages/editor/App.planLinkedDrafts.test.tsx.tests/e2e/plan-linked-doc-drafts.spec.ts(headless Chromium, compiled binary, temp data dir and HOME,NO_BROWSER).design.md.inbox-e2e.ymlnow also runs whenpackages/editor/**,packages/server/index.ts,packages/server/annotate.ts,packages/shared/annotate*,draft.ts,review-draft.tsordoc-resolve.tschange, so a regression in App, the plan or annotate server, or the shared draft store runsplan-linked-doc-drafts.spec.tsand theannotate-*specs. The Pi server files are not listed: those specs drive only the compiled Bun binary, andtest.yml(bun test) runs the Pi mirrors of the scenarios.plannotator-announce-inbox-seen, as main's other specs do; everything below was rerun on the merged tree except the broadbun testrun.bun run typecheck; built in order (review, then hook, then opencode) and compiled.local/plannotatorwith the CI flags.plan-linked-doc-draftsand theannotate-*specs,--repeat-each 2: 28/28 pass.DOM_TESTS=1):App.planLinkedDrafts,useAnnotationDraft.documents,App.documentDrafts,useAnnotationDraft.seam,annotationDraftStaleRetry: 18/18 pass.bun test packages/server packages/shared apps/pi-extension packages/editor packages/ui tests/agents-md-size.test.ts scripts/dom-test-allowlist.test.ts tests/no-browser-sentinel.test.ts: 6808 pass, 4 fail. The 4 are inapps/pi-extension/inbox.test.ts(the real Pi in RPC mode against an Inbox), timing under the full run's load; that file passes alone (13/13). None is in draft code.HOMEandPLANNOTATOR_DATA_DIR,PLANNOTATOR_INBOX_CONNECT=0, the no-browser value, and stub agent CLIs first onPATH.servablefilter fromcountUnsentor fromsettle, or deleting the index file on every decision, fails the 12 two-folder scenarios (6 per runtime). Removingsettle()from/api/approvefails the approve scenarios on that runtime. Removing the Bun plan-file allowance, accepting the whole plan folder, or a lexical (non-realpath) containment check inresolvePlanLinkedDocfails the plan-file scenario. Removing the GET guard fails the cross-site scenario for that server (plan, or last-message and URL), on each runtime. Always saying "including" fails the new App DOM test.Notes for review
docs/design.mdalso come back, with the existing toast, when that file is opened in another session.