Skip to content

quality(workspace): dedupe workspace_store_image and workspace_pick_and_store_image (R1.4) - #151

Closed
juacker wants to merge 1 commit into
clai/quality/pre-r1-4-main-snapshotfrom
clai/quality/workspace-image-store-dedup
Closed

quality(workspace): dedupe workspace_store_image and workspace_pick_and_store_image (R1.4)#151
juacker wants to merge 1 commit into
clai/quality/pre-r1-4-main-snapshotfrom
clai/quality/workspace-image-store-dedup

Conversation

@juacker

@juacker juacker commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

What

Extract the duplicated preamble (resolve descriptor + refuse non-agent workspace) and the duplicated ContentPart::Image literal trailer shared by workspace_store_image (paste path) and workspace_pick_and_store_image (file picker path) into two named helpers:

  • resolve_agent_workspace_root(state, workspace_id) -> Result<PathBuf, String>
  • store_workspace_image(root, bytes, media_type, filename) -> Result<ContentPart, String>

Why

Both commands had the same ~6-line preamble and the same 7-line ContentPart::Image literal (width: None, height: None). Two paths defining the same shape is exactly how they drift — one gets an id, the other doesn't, etc. F4 in docs/arch-review-r1-workspace-rs.md.

Diff at a glance

src-tauri/src/commands/workspace.rs | 88 +++++++++++++++++++++----------------
1 file changed, 50 insertions(+), 38 deletions(-)

The commands shrink; the helpers carry the doc comments explaining why each step exists (one-liner comments at the call sites).

Local evidence

  • cargo fmt -- --check: clean
  • cargo clippy --lib -- -D warnings: clean
  • cargo test --lib: 932 passed, 0 failed (was 932 on main too — no test churn, pure refactor)

Source

Roadmap item R1.4 (file finding F4 of docs/arch-review-r1-workspace-rs.md).

Important note about base ref

This PR targets branch clai/quality/pre-r1-4-main-snapshot (a temporary snapshot of main at 74261a0, the previous tip before this branch was pushed), not the current tip of main (d680a96). The current main contains an extra revert commit (d680a96) that is byte-identical to 74261a0 for the only file this branch touches; it's a leftover artifact of a botched git push -u earlier in this session. See .clai/memory/journal/2026-08-05.md for the full timeline.

To merge cleanly:

  • This PR's diff against 74261a0 is the real R1.4 change.
  • Before merging, retarget the PR base to main (or merge clai/quality/pre-r1-4-main-snapshot forward to main first). Merging into the snapshot branch leaves main unchanged.

Merge

🛑 Do not merge yet. Per the hard rule added 2026-08-04 ("never merge a PR — this is done by me"), this PR waits for CI green and then human merge.

…nd_store_image (R1.4)

Both commands duplicated the same preamble (resolve descriptor, refuse
non-agent workspaces) and the same ContentPart::Image literal trailer.
Extract the preamble into resolve_agent_workspace_root and the disk
write + ContentPart::Image construction into store_workspace_image so
both commands reduce to acquiring bytes + media type + filename.

Before: 38 + 47 lines in the two command bodies (plus an unused
'moved variable' state from the picked variant).
After: 12 + 33 lines, with the duplicated parts hoisted into two named
helpers (resolve_agent_workspace_root, store_workspace_image).

Width/height: None is now defined in one place instead of two, so the
store_image and pick-and-store_image paths can never drift.

Source: docs/arch-review-r1-workspace-rs.md finding F4.

Local evidence:
- cargo fmt -- --check: clean
- cargo clippy --lib -- -D warnings: clean
- cargo test --lib: 932 passed, 0 failed
@juacker

juacker commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded: main has moved on (#152, #150) and this PR's head commit 0aa9a16 is now an ancestor of main (it was pushed there by accident, then reverted in d680a96), so it can never be retargeted to main. Re-landing R1.4 as a fresh commit on top of current main in a new PR. See journal entry 2026-08-05 for the full incident timeline.

@juacker juacker closed this Aug 5, 2026
@juacker
juacker deleted the clai/quality/workspace-image-store-dedup branch August 5, 2026 16:20
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