Repository navigation
feat(staged): move and copy notes between projects from stagedctl - #1090
Merged
Merged
Conversation
An agent driving Staged through stagedctl could read a note but not
send it to another project. Only the note dialogs' "Move to project…"
and "Copy to project…" could. Add a `note` noun with `move` and `copy`
verbs that run the same transfer:
stagedctl note move '#note:<id>' --to <project>
stagedctl note copy '#project-note:<id>' --to <project>
<NOTE> is the hashtag reference the CLI prints: `#note:<id>` for a
branch note, `#project-note:<id>` for a project note. The leading # may
be left off, because an unquoted # starts a shell comment. --to
resolves like every other <project>, by name or id. The noun has the
hidden plural alias `notes` and takes the global --json, like its
neighbours.
The output says where the note landed: the destination project, the
repo and branch a branch note is on now, and for a copy the new note's
reference. Each repo the transfer added to the destination is named.
--json carries the same as `{ ok, mode, projectId, reference, note,
addedRepos }`, plus `branch` and `repo` for a branch note, built from
the app's rows.
One code path. The four commands the dialogs already call
(`move_note_to_project`, `copy_note_to_project` and their project-note
twins) join the control server's allowlist, and their dispatch arms
call `transfer_branch_note` and `transfer_project_note` as before. The
transfer's rules are untouched, and its refusals reach the CLI verbatim
as `app_error` (exit 1). A Staged from before this change answers with
the "update Staged" hint the other late commands get.
Authorization. All four are writes with a new scope rule: the project
the note is in, found through the note, and the destination must both
be within the credential's reach, by the reach test every other write
uses. A read-only grant is refused, as is a note or a destination
outside that reach (exit 4, `scope_denied`). What a session's
credential reaches is unchanged: its own project and the projects it
created.
The one refactor is in what a control caller is answered, not in the
transfer. A window has the note open and is answered with the note
alone, as before. A control caller named a note by id, so its answer is
`{ note, branch, repo, addedRepos }` for a branch note and `{ note,
addedRepos }` for a project note. Which repos were added is known only
while the transfer runs, so the arms wrap the existing repo-adding step
in `note_transfer::control::AddedRepos`, which notes each repo once its
add has succeeded. The transfer functions, the Tauri commands and the
web answer are as they were.
`note move --help` and `note copy --help` say what a move carries (the
note's id, its session, a project note's child notes) and what a copy
produces (a new standalone note), with the refusals and the repo a
destination can gain. The help pins and the session guide are updated.
Tests: reference parsing, the request for each kind and verb, the
output, pass-through of refusals and scope denials in the CLI; the
scope rule for a note out of reach, a destination out of reach, a
read-only grant and an unconfined one; the control answer over real
transfers; and a pin that every caller's arm runs the one transfer.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: mtoohey <mtoohey@squareup.com>
…moved Review 1164ab6a of a928bca found that `stagedctl note move` and `stagedctl note copy` let embedded media escape the scope rule, and that their answers and help left gaps. This addresses its findings. The transfer itself, the Tauri commands and what a window is answered are unchanged. Embedded media. A note's body embeds stored images and videos by id, and the transfer puts each one in the destination whichever project its row is in. A confined caller that knew an id could have a note of its own embed it and copy the file into a project it reaches. The scope check now refuses a transfer (exit 4, `scope_denied`) whose note body embeds media from a project outside the credential's reach, the way `require_images_in_scope` refuses an attached `imageIds` entry. A project-note move is held to the same for each child note, since the children travel with it. A copy leaves them behind and is not. A reference with no row carries nothing and passes. Unconfined grants and the app's windows are not checked. The bodies are read when the request arrives. A transfer that adds a repo reads them again afterwards, so a body saved during the add is not re-checked; closing that needs a check inside the transfer, which this commit does not touch. The module docs say so. Session status of a moved project note. The row the move's transaction returns resolves no session, so the control answer said `sessionStatus: null` for a note whose session had completed. `project_note_answer` now reads the note again with `get_project_note_with_status`, and falls back to the transfer's value if that read fails. Children of a moved project note. The control answer gains `children`, one `{ reference, title, branch, repo }` per child note that came along: its `#note:<id>` reference and the branch and repo it is on now, read back as a branch note's are. A copy answers an empty list. The CLI prints a `child note …` line for each and passes the list through under `--json`. This extends a backend answer type, which AGENTS.md asks a human to review before it lands. Failure after a repo was added. A branch-note transfer that failed once its repo was in the destination returned an error that did not mention the repo. For a control caller the error now ends with the sentence a project-note failure already has: "<repo> was added to <project> along the way and remains tracked there." A window's error is as it was. The help no longer sends the caller to `stagedctl project get`. Exit 4 for a note that is not there. Under a confined credential, an id that names no note of its kind (unknown, or the other kind's) exits 4 with "not found", where an unconfined one gets the transfer's exit 1. The behaviour stays. Both verbs' help and the guide now say it, list the media refusal beside it, and the help pins are refreshed. One reach helper. `require_in_scope` now takes the refusal's wording and holds the reach test itself. `require_destination_in_scope` and `within_reach` are gone, and the image check goes through it too. Tests. `dispatch` takes the app's own handle, which no test can build, so the bodies of the four arms move to `web_server::note_transfer_arms` and take the repo-adding step as a parameter. `dispatch` passes `add_repo_to_project`. The new tests run the scope check and then those bodies as a control caller, over real transfers, and assert the JSON answered: the exact keys of each answer and of the note item, the session status of a moved branch note and project note, the children and their landing rows, a copy's standalone note, and a window's note-alone answer. They cover a failure after a repo was added for both kinds and both callers, a failed add, a missing and a wrong-kind id for confined and unconfined grants, and media from a third project in a note, in a child note and on a copy into the note's own project. The scope tests add the same media cases at the check, with media in reach and a reference with no row passing. The source pin on the arms is narrowed to what cannot be run, and its slice no longer stops one byte early. The CLI tests cover the children lines, unreadable landing rows, and pin the answer's key names to the app's source. Signed-off-by: Matt Toohey <contact@matttoohey.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…rs to a fixture Review beb7cbf7 of 9e63668 left small items on `stagedctl note move` and `stagedctl note copy`. This applies them. The transfer, the Tauri commands, what a window is answered and the UI are unchanged. Children that cannot be read back. A project note's control answer listed its child notes by reading them after the transfer committed, and a failed read was answered as an empty list. A caller could not tell that from a note with no children, though the children had moved. `project_note_answer` now answers `children: null` for a failed read, as `branch` and `repo` already answer `null` for a row that cannot be read back. The docs describe the list as what it is: the note's children as they read after the transfer, not the move's own plan. This makes a field of a backend answer nullable, which AGENTS.md asks a human to review before it lands. The CLI reads the key as absent, `null` or a list (`Children`). A move whose answer has `children: null` prints "child notes: the app could not read them back; any the note has moved with it". A copy prints nothing, since its note is new and has none. `--json` passes `null` through as the app said it. `note move --help` and the session guide say so, and the help pin is refreshed. Dangling media references in tests. The scope test for a reference with no row used `no-such-image`, which is not a UUID, so it was never a media reference and never reached the row lookup in `require_note_media_in_scope`. It now uses a fresh UUID and asserts the body parses to that id. The end-to-end test the review names, `media_from_a_project_out_of_reach_stops_the_transfer_before_it_runs`, embeds a well-formed id with no row that sorts ahead of the foreign one, so the check passes over it before it refuses. A new arm test moves and copies a branch note, and moves a project note with a child, whose bodies embed such an id, as a confined caller: each transfer goes through and the reference is left as written. With the skip turned into a refusal, the scope test and the new arm test both fail. A media row whose file is gone. The scope module docs now say the check goes by the row: a row with no file carries nothing either, so a note the user moved after a file was lost can be refused for media that would not have travelled. One fixture for the answer's names. stagedctl pinned the answer's keys by matching formatted source lines of `control.rs`. That test is gone. `src/note_transfer/control/fixtures/answers.json` holds one branch-note and one project-note answer. An arm test runs both moves for real, names the ids, zeroes the timestamps and asserts the result equal to the file (`STAGED_UPDATE_NOTE_TRANSFER_ANSWERS=1` rewrites it). The CLI tests answer with the same file and assert the full output, where every line is a field `Landed` reads, and that each key of the answer comes out under `--json`. Tests removed. The body half of the source pin in `web_server.rs` matched literal lines of the arm bodies, which the arm tests prove with real transfers for both callers. The arm-delegation and desktop-command halves stay, since `dispatch` cannot be run. The hand-built `{ id, title }` helper in `note_transfer/control/tests.rs` and its three tests are gone too. The one case only they covered, a branch note sent to a project that already tracks its repo, is now an arm test. Left for the human reviewer, as asked: the residual media race while a transfer adds a repo (`stage_media` is untouched), and whether a confined caller may move a child note away from its parent. Checked from this worktree, built into a private cargo target so the running app's binaries were not replaced: `cargo fmt --check`, `cargo clippy --workspace -- -D warnings`, all 246 stagedctl unit tests and the help pin, and the app's `note_transfer`, `web_server`, `control_server` and `note_media` tests (330). The rest of the app's suite was not run locally. Signed-off-by: Matt Toohey <contact@matttoohey.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review c20aea8b of b09b00a left three optional items on `stagedctl note move` and `stagedctl note copy`. This applies them. It touches tests and one line of output. The transfer, the answers the app gives and the help are unchanged. The fixture pinned too much. `answers.json` held every field of the branch row, the repo row, the note item and the project note, and the app's test asserted its answers equal to it. stagedctl reads about nine of those names. A PR that added a field to one of those models failed the test until the fixture was rewritten, and two such PRs that were each green could turn main red together. The app's test now asserts containment. `pinned_part` takes from the real answer the fields the fixture names, and that part has to equal the fixture. A field the answer gains passes. A pinned field that is renamed or removed fails with its path, such as "the answer has no `projectNote.children[0].reference`", and one answered with another value fails the comparison. A field pinned as `null` has to be there. A list is held item for item, so one of another length fails too. The fixture is cut to what `Landed` reads in stagedctl: the note's `id` and `title`, the branch's `id` and `branchName`, the repo's `githubRepo` and `subpath`, each child's `reference`, `title`, `branch` and `repo`, and `addedRepos`. It has no timestamps or session, project and repo ids left, so the test names fewer ids. stagedctl's tests parse the same file as before and assert the same output from it. The update variable. `STAGED_UPDATE_NOTE_TRANSFER_ANSWERS` rewrote the fixture when it was set to anything, an empty value or `0` included. It now has to equal `1`. A rewrite refreshes the values of the fields the fixture already pins and keeps it trimmed. A pinned field the answer no longer has stops the rewrite, so update mode no longer passes whatever the app answers. The output line. A move whose answer has `children: null` printed "child notes: the app could not read them back; any the note has moved with it". It now ends "any child notes it has moved with it", as the review suggests. The CLI test that asserts the line is updated. The help, the guide and the help pin do not quote it. Tests. A new test runs `pinned_part` on made-up answers: added fields pass, and a renamed field, a removed one, a changed value, a row answered as `null` and a grown list do not. The check was also proved against the app, with each change reverted afterwards. Renaming `reference` in `control.rs`, removing a branch note's `addedRepos` and changing a child's reference each failed the test. Adding unpinned fields to the answer and to a child passed. With `addedRepos` removed, the variable set to `0`, to empty and to `1` all failed and left the fixture alone. On the unchanged source, `=1` rewrote the fixture byte for byte. Checked from this worktree, built into a private cargo target so the running app's binaries were not replaced: `cargo fmt --check`, `cargo clippy --workspace -- -D warnings`, all 246 stagedctl unit tests and the help pin, and the app's `note_transfer`, `web_server`, `control_server`, `control_scope` and `note_media` tests (336). The rest of the app's suite was not run locally. Signed-off-by: Matt Toohey <contact@matttoohey.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Summary
An agent driving Staged through
stagedctlcould read a note but not send it to another project; only the note dialogs' "Move to project…" / "Copy to project…" could. This adds anotenoun withmoveandcopyverbs that run the same transfer the dialogs use:<NOTE>is the hashtag reference the CLI already prints (#note:<id>for a branch note,#project-note:<id>for a project note); the leading#may be omitted.--toresolves by project name or id. Hiddennotesplural alias and the global--jsonare supported.child note …line per child that travelled with a moved project note.--jsoncarries{ ok, mode, projectId, reference, note, addedRepos, branch?, repo?, children? }.Backend changes (please review per AGENTS.md)
move_note_to_project,copy_note_to_projectand their project-note twins) join the control server's allowlist. The transfer functions and what a window is answered are unchanged.{ note, branch, repo, addedRepos }for a branch note and{ note, addedRepos, children }for a project note.childrenlists the child notes as read back after the transfer ({ reference, title, branch, repo }) and isnullwhen they could not be read back. A moved project note'ssessionStatusis re-read so a completed session is reported correctly.scope_denied. Note bodies (and a moved project note's children) that embed media from a project outside the credential's reach are refused the same way, closing a path for a confined caller to copy media out of an unreachable project. A reference with no media row passes. Unconfined grants and app windows are not checked.Tests
dispatcharm bodies move toweb_server::note_transfer_armsso they can be exercised with real transfers for both control and window callers; tests cover answers, session status, children, copies, failures after a repo was added, missing/wrong-kind ids, and media out of reach.note_transfer/control/fixtures/answers.jsonpins the answer fields stagedctl reads; the app test asserts containment (added fields pass, renamed/removed/changed pinned fields fail with a path) andSTAGED_UPDATE_NOTE_TRANSFER_ANSWERS=1rewrites it. stagedctl's CLI tests parse the same fixture.Left for human review: the residual media race while a transfer adds a repo (
stage_mediauntouched), and whether a confined caller may move a child note away from its parent.🤖 Generated with Claude Code