27 KiB
X Article, Vision Summaries, and Summary Search Implementation Plan
For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: Make X Articles summarize their archived article text, let a user explicitly attach eligible archived images to a requested summary, and search the latest completed summary text (including its JSON tags).
Architecture: Keep archivr-core synchronous and make the summary input the single carrier of both reduced text and an opt-in, bounded list of image descriptors. The image-selection policy is serialized into the existing input_sha256 preimage, preserving the existing entry_summaries uniqueness key without a migration. Extend the existing server-side entry search query with a correlated latest-completed-summary predicate; the endpoint response and frontend search transport stay unchanged.
Tech Stack: Rust 2024, anyhow, rusqlite, reqwest blocking HTTP, serde_json, Axum, React JSX, and plain CSS.
File map and interfaces
| File | Responsibility |
|---|---|
crates/archivr-core/src/summarizer.rs |
X Article reducer, image candidate policy, SummaryBuildOptions, SummaryImage, cache digest preimage, provider request payloads, Codex invocation, and unit tests. |
crates/archivr-server/src/routes.rs |
Parse include_images, reject an unsupported Claude CLI vision request before a job is created, and pass build options to both cache lookup and the background worker. |
frontend/src/api.js |
Send the explicit include_images boolean in the existing summary POST. |
frontend/src/components/ContextRail.jsx |
Per-generation checkbox, provider-specific disabled Claude state, privacy/cap warning, and request wiring. |
frontend/src/styles.css |
Dedicated summary-image option layout and disabled-note treatment. |
crates/archivr-core/src/archive.rs |
Correlated SQL predicate for the latest completed summary and search tests. |
docs/README.md, AGENTS.md, ARCHIVR-MENTAL-MODEL.md |
User, contributor, and architectural documentation after the implementation is complete. |
Define the following core interfaces before server or UI tasks use them. archive_file is an absolute local path derived from ArchivePaths.store_path plus the stored artifact relpath; it is never returned from an API.
pub const MAX_SUMMARY_IMAGES: usize = 4;
pub const MAX_SUMMARY_IMAGE_BYTES: u64 = 5 * 1024 * 1024;
pub const MAX_SUMMARY_IMAGE_TOTAL_BYTES: u64 = 12 * 1024 * 1024;
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct SummaryBuildOptions {
pub include_images: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SummaryImage {
pub sha256: String,
pub mime_type: String,
pub byte_size: u64,
pub archive_file: PathBuf,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SummaryRequest {
pub entry_uid: String,
pub title: Option<String>,
pub source_kind: String,
pub entity_kind: String,
pub content: String,
pub images: Vec<SummaryImage>,
}
pub fn build_summary_input(
paths: &ArchivePaths,
entry_uid: &str,
options: SummaryBuildOptions,
) -> Result<SummaryInput>;
pub fn summarize_entry(
archive_paths: &ArchivePaths,
entry_uid: &str,
options: SummaryBuildOptions,
provider: &dyn SummaryProvider,
prompt_version: &str,
) -> Result<database::EntrySummaryRecord>;
Use one deterministic digest preimage: content bytes, then "\0images=", then include_images as "0" or "1", followed by each selected image in query order as "\0" + sha256 + "\0" + mime_type + "\0" + byte_size. Hash that complete byte sequence with the existing hash::hash_bytes. This means an unchecked request has no images and a different digest from a checked request even when no candidate qualifies.
Task 1: Add the X Article reducer with test-first precedence
Files:
-
Modify:
crates/archivr-core/src/summarizer.rs -
Test:
crates/archivr-core/src/summarizer.rs(#[cfg(test)] mod tests) -
Step 1: Write failing tests for each per-status X Article precedence rule.
Add assertions against
extract_tweet_textusing values that retain a link-only top-level tweet body:#[test] fn extract_tweet_text_prefers_x_article_plain_text_over_tco_body() { let tweet = serde_json::json!({ "full_text": "https://t.co/article", "article": { "title": "Skin guide", "plain_text": "Use sunscreen daily." } }); assert_eq!(extract_tweet_text(&tweet).as_deref(), Some("Skin guide\n\nUse sunscreen daily.")); } #[test] fn extract_tweet_text_uses_article_blocks_when_plain_text_is_empty() { let tweet = serde_json::json!({"article": { "title": "Blocks", "plain_text": " ", "blocks": [{"text": "First"}, {"children": [{"text": "Second"}]}] }}); assert_eq!(extract_tweet_text(&tweet).as_deref(), Some("Blocks\n\nFirst\n\nSecond")); } #[test] fn extract_tweet_text_falls_back_from_article_to_link_only_tweet_body() { let tweet = serde_json::json!({ "full_text": "https://t.co/fallback", "article": {"title": "Preview", "preview_text": "Preview copy", "summary_text": "Later"} }); assert_eq!(extract_tweet_text(&tweet).as_deref(), Some("Preview\n\nPreview copy")); } -
Step 2: Run the focused test target and observe it fail.
Run:
cargo test -p archivr-core extract_tweet_text_Expected: FAIL because the current reducer returns the top-level
full_textor does not descend intoarticle.blocks. -
Step 3: Implement
article_textand deterministic block flattening.Add private helpers before
extract_tweet_text:fn nonempty_string(v: &serde_json::Value, key: &str) -> Option<String>; fn flatten_article_blocks(v: &serde_json::Value, out: &mut Vec<String>); fn article_text(status: &serde_json::Value) -> Option<String>;article_textmust inspect the status'sarticleobject before ordinary fields. With a nonempty title, format each successful source astitle + "\n\n" + body; if title is empty, return onlybody. Select the body in this exact order: nonblankplain_text; recursive text leaves fromblocksin JSON array/object encounter order; nonblankpreview_text; nonblanksummary_text.flatten_article_blocksmust collect only textual scalar values from conventional textual keys (text,plain_text,content,body,title,heading) and recursively visit arrays and objects; it must not stringify IDs, URLs, booleans, media metadata, or arbitrary scalar fields. Join block leaves with"\n\n". -
Step 4: Integrate the helper into all tweet-status paths.
Make
one(v)callarticle_text(v).or_else(|| normal_tweet_text(v)), wherenormal_tweet_textpreserves the existingfull_text,text,content,bodysequence. Keep support for a top-level{ "tweet": ... }wrapper and for embeddedthread,tweets, andrepliesmembers. -
Step 5: Add the thread-artifact regression test and run the focused tests.
Add a fixture archive with two
raw_tweet_jsonartifacts, where each JSON status has article text, then assertbuild_summary_input(..., SummaryBuildOptions::default())?.request.contentcontains both article bodies separated by"\n\n---\n\n". Run:cargo test -p archivr-core extract_tweet_text_ build_summary_input_Expected: PASS, including the existing wrapped/thread tweet tests.
-
Step 6: Commit the atomic reducer change.
git add crates/archivr-core/src/summarizer.rs git commit -m "fix: summarize X Article text"
Task 2: Model and select explicit image inputs in core
Files:
-
Modify:
crates/archivr-core/src/summarizer.rs -
Test:
crates/archivr-core/src/summarizer.rs(#[cfg(test)] mod tests) -
Step 1: Write failing candidate-selection and digest tests.
Build a temporary archive entry containing
mediaartifacts for validjpg,png,webp,gif, andavif, plusavatar,video,audio, unsupportedsvg, one 5 MiB + 1 byte image, and enough valid images to exceed both the four-image and 12 MiB limits. Assert only rolemedia, allowed MIME/extension pairs, at most four descriptors, no descriptor over 5 MiB, and total selected bytes at most 12 MiB. Also assert:let text_only = build_summary_input(&paths, &uid, SummaryBuildOptions { include_images: false })?; let visual = build_summary_input(&paths, &uid, SummaryBuildOptions { include_images: true })?; assert!(text_only.request.images.is_empty()); assert!(!visual.request.images.is_empty()); assert_ne!(text_only.input_sha256, visual.input_sha256); -
Step 2: Run the new core tests and observe failure.
Run:
cargo test -p archivr-core summary_image_Expected: FAIL because
SummaryRequesthas no images and input construction has no image-selection mode. -
Step 3: Define the shared image model and query candidates from existing blobs.
Add the constants and
SummaryBuildOptions,SummaryImage, andSummaryRequest.imagesdefinitions from the file map. Add a privateload_summary_image_candidates(conn, entry_id) -> Result<Vec<SummaryImage>>queryingentry_artifacts ea JOIN blobs bforea.entry_id = ?1 AND ea.artifact_role = 'media', ordered byea.id ASC, selectingb.sha256,b.mime_type,b.extension,b.byte_size, andea.relpath.Accept a candidate only when both of the following are true: its extension is one of
jpg,jpeg,png,webp,gif,avif, and its MIME is the matchingimage/jpeg,image/png,image/webp,image/gif, orimage/aviffamily. Resolvearchive_fileunder the configured store path and reject a candidate whose canonicalized/normalized path escapes that store root. Stop at the first candidate that would exceed either image count, per-image, or aggregate byte limit; continue scanning later candidates so a too-large or unsupported early artifact cannot hide a valid later one. -
Step 4: Build options-aware input and a complete cache digest.
Change every current
build_summary_inputcall to passSummaryBuildOptions::default()until Task 4 changes the server. Populaterequest.imagesonly ifoptions.include_imagesis true; text extraction andMAX_INPUT_CHARShandling remain identical. Replacehash_bytes(content.as_bytes())with a privatesummary_input_digest(content, include_images, images)implementing the stated NUL-delimited preimage so the existing database uniqueness constraint continues to distinguish all modes. Do not alterdatabase.rs:input_sha256already participates in the cache key. -
Step 5: Run core regression tests.
Run:
cargo test -p archivr-core summary_image_ build_summary_input_Expected: PASS; the text-only request has zero image descriptors, and selection is deterministic by artifact insertion order.
-
Step 6: Commit the core input model.
git add crates/archivr-core/src/summarizer.rs git commit -m "feat: model opt-in summary images"
Task 3: Make provider transports honor image descriptors
Files:
-
Modify:
crates/archivr-core/src/summarizer.rs -
Test:
crates/archivr-core/src/summarizer.rs(#[cfg(test)] mod tests) -
Step 1: Write failing payload, command, and capability tests.
Construct a
SummaryRequestwith one tiny fixtureSummaryImageand assertanthropic_request_bodyputs a text block and{ "type": "image", "source": { "type": "base64", "media_type": "image/png", "data": "..." } }inmessages[0].content. Assertopenai_request_bodyemits a text content part plus{ "type": "image_url", "image_url": { "url": "data:image/png;base64,..." } }. Unit-test a pure Codex argument builder so its primary arguments containexec,--image, the fixture path,--output-last-message, output path, and final-; test its positional fallback also keeps--image. AssertClaudeCliProvider::summarizereturns an error containingClaude CLI cannot attach local imageswhenrequest.imagesis nonempty. -
Step 2: Run the provider tests and observe failure.
Run:
cargo test -p archivr-core "anthropic_request_body|openai_request_body|codex.*image|claude.*images"Expected: FAIL because HTTP bodies are string-only, Codex has no
--image, and Claude silently accepts the request. -
Step 3: Encode images for each HTTP protocol.
Add
read_image_base64(image: &SummaryImage) -> Result<String>which reads only the already bounded selected file and usesbase64::Enginewith the existing dependency or workspace dependency. Makeanthropic_request_bodyandopenai_request_bodyreturn their present text-only JSON shapes whenrequest.images.is_empty()and their documented content-part arrays otherwise. PreserveSYSTEM_PROMPT,build_user_prompt, provider URL, headers, and response parsing. -
Step 4: Extend Codex safely and reject Claude at the provider boundary.
Refactor
codex::runto accept&[SummaryImage]; add--image <archive_file>once per selected image before--output-last-messagein both primary stdin and positional-prompt forms. Keep the existing last-message temporary-file contract and cleanup behavior. HaveClaudeCliProvider::summarizebail!("Claude CLI cannot attach local images; choose an HTTP provider or Codex CLI")before spawning when images are supplied. -
Step 5: Thread image-aware options through synchronous orchestration.
Change
summarize_entryto acceptSummaryBuildOptionsand call the options-aware builder before provider invocation. This is a synchronous core function; do not introduce Tokio, async traits, or new database fields. -
Step 6: Run provider and existing summary tests.
Run:
cargo test -p archivr-core summarizer::testsExpected: PASS, with all four providers retaining their text-only behavior when
imagesis empty. -
Step 7: Commit the provider implementation.
git add crates/archivr-core/src/summarizer.rs git commit -m "feat: attach opted-in images to summaries"
Task 4: Expose the opt-in flag through the server API
Files:
-
Modify:
crates/archivr-server/src/routes.rs -
Test:
crates/archivr-server/src/routes.rs(#[cfg(test)] mod tests) -
Step 1: Write failing route tests.
Add authenticated POST tests that deserialize a request without
include_imagesand assert it takes the text-only build path, and with{ "provider": "claude_cli", "include_images": true }assert status400 BAD_REQUESTand an error containingClaude CLI cannot attach local images. Add a successful non-Claude request test withinclude_images: trueusing a configured test provider and assert the returned cache key differs from the equivalent text-only request. Keep GET assertions unchanged: it remains{ "entry_uid", "summary" }. -
Step 2: Run the focused route tests and observe failure.
Run:
cargo test -p archivr-server "summary.*include_images|claude.*images"Expected: FAIL because the request body does not accept the field and no capability check occurs.
-
Step 3: Add the backward-compatible request field and capability guard.
Extend
SummaryRequestBodyexactly as follows:#[derive(Debug, serde::Deserialize)] struct SummaryRequestBody { provider: String, #[serde(default)] force: bool, #[serde(default)] include_images: bool, }After resolving
provider_cfgand before cache lookup/upsert/spawn, returnApiError::bad_request("Claude CLI cannot attach local images; choose an HTTP provider or Codex CLI")whenbody.include_images && matches!(provider_cfg, ProviderConfig::ClaudeCli(_)). ConstructSummaryBuildOptions { include_images: body.include_images }once and pass it to the preflight builder and cloned intospawn_blockingforsummarize_entry. -
Step 4: Verify cache and lifecycle consistency.
Ensure preflight
build_summary_inputand backgroundsummarize_entryreceive the same options, sofind_entry_summaryandupsert_pending_entry_summaryuse the same digest. Do not changeentry_summaries,latest_entry_summary, or the GET route; the existing input-hash uniqueness constraint is sufficient. -
Step 5: Run the focused server tests.
Run:
cargo test -p archivr-server "summary.*include_images|claude.*images"Expected: PASS; omitting the new field is text-only and a Claude image request produces no pending summary row.
-
Step 6: Commit the API wiring.
git add crates/archivr-server/src/routes.rs git commit -m "feat: accept image summary requests"
Task 5: Add the explicit, provider-aware image consent control
Files:
-
Modify:
frontend/src/api.js -
Modify:
frontend/src/components/ContextRail.jsx -
Modify:
frontend/src/styles.css -
Test: manual browser smoke test (no frontend test harness exists)
-
Step 1: Inspect the existing provider selector and write the manual failure script.
In a locally authenticated entry detail, select an HTTP provider and verify the Summary section currently has no
Include attached imagescheckbox; select Claude CLI and verify there is no capability explanation. Record this as the observed pre-implementation failure. Do not add a frontend test framework. -
Step 2: Change the API client contract.
Change the function signature and POST body only:
export async function requestEntrySummary( archiveId, entryUid, { provider, force = false, includeImages = false } = {} ) { // existing fetch and error parsing body: JSON.stringify({ provider, force, include_images: includeImages }) }Keep all
fetchcalls insidefrontend/src/api.js; do not add an inline fetch in the component. -
Step 3: Implement the local per-generation control.
Add
const [includeSummaryImages, setIncludeSummaryImages] = useState(false)beside the summary provider state. InhandleGenerateSummary, passincludeImages: includeSummaryImages. Reset this state tofalsewheneverdetail?.summary?.entry_uidchanges, so a consent choice cannot carry to another entry. Do not persist the checkbox insessionStorage; the consent is per generation and defaults off. -
Step 4: Render clear consent, scope, and Claude capability states.
In
.rail-summary-controls, below the provider<select>, render a labeled checkbox with exact visible labelInclude attached images. Its help text must say that selected archived images are sent to the chosen provider and that only up to four supported images (5 MiB each, 12 MiB total) can be attached; unsupported or oversized artifacts are skipped. WhensummaryProvider === 'claude_cli', render the checkbox disabled, forceincludeSummaryImagesto false via an effect or provider-change handler, and showClaude CLI cannot attach local images. Choose an HTTP provider or Codex CLI.Do not submit a silently dropped image choice. -
Step 5: Add scoped plain-CSS rules.
Add
.rail-summary-image-option,.rail-summary-image-option__label,.rail-summary-image-option__note, and.rail-summary-image-option--disabledunder the existing summary rail CSS. Use the project variables (--muted,--line,--paper) and preserve keyboard focus and normal checkbox semantics; do not use a generic row class or inline layout styles. -
Step 6: Run the manual success script and build verification.
Run:
bun run buildExpected: successful production bundle in
crates/archivr-server/static. Then manually verify: unchecked generation sendsinclude_images:false; checked Anthropic/OpenAI/Codex generation sendstrue; changing to Claude unchecks/disables the control and shows the exact explanation; server errors still appear through existingsummaryErrorhandling. -
Step 7: Commit source files, not generated static output.
git add frontend/src/api.js frontend/src/components/ContextRail.jsx frontend/src/styles.css git commit -m "feat: add summary image consent control"
Task 6: Search latest completed summary JSON without changing API shape
Files:
-
Modify:
crates/archivr-core/src/archive.rs -
Test:
crates/archivr-core/src/archive.rs(#[cfg(test)] mod tests) -
Step 1: Write failing search tests with real cache rows.
Extend
make_test_db_with_entriesor add a focused fixture helper that inserts summary rows throughdatabase::upsert_pending_entry_summaryanddatabase::update_entry_summary_status. Add assertions for all of the following:// A completed JSON string with {"tags":["skincare","dermatology"]} matches skincare. // An unrelated query yields no result. // Two completed rows: the newer completed row is searched; the older one is not. // A completed older row remains matched while a newer row is pending or failed. // source:, entity:, url:, title:, after:, before:, tag: and collection/visibility scope keep their current behavior.Set distinct
updated_atvalues (or insert/transition rows in distinct timestamp order) so "latest completed" is unambiguous. The tag assertion must matchsummary_textitself, notentry_tag_assignments. -
Step 2: Run the focused tests and observe failure.
Run:
cargo test -p archivr-core search_.*summaryExpected: FAIL because free text only checks entry and source identity fields.
-
Step 3: Add a parameter-bound latest-completed summary predicate.
In the existing unqualified
query.qblock insearch_entries, preserve every presentLOWER(...) LIKE ?{n}condition and add this clause using the same single boundterm:OR LOWER(COALESCE(( SELECT s.summary_text FROM entry_summaries s WHERE s.entry_id = e.id AND s.status = 'completed' AND s.summary_text IS NOT NULL ORDER BY s.completed_at DESC, s.updated_at DESC, s.id DESC LIMIT 1 ), '')) LIKE ?NUse the existing numbered parameter construction (
?{n}) and pushtermonce, so user text is never concatenated into SQL.completed_atordering means only completed rows participate, and a later pending/failed row cannot displace an older completed row. Do not add an archive method, schema column, migration, route parameter, or frontend response field. -
Step 4: Run core search tests.
Run:
cargo test -p archivr-core search_Expected: PASS, including old prefix-filter behavior and JSON tag substring matches.
-
Step 5: Verify the existing API transport needs no change.
Inspect
crates/archivr-server/src/routes.rs::search_entries_handler,frontend/src/api.js::searchEntries, andfrontend/src/App.jsxsearch call sites. Confirm the server still callsarchive::search_entrieswith the sameSearchEntriesQueryand returnsVec<EntrySummary>; record no source edit for these files unless the inspection reveals a type break. Add no client-side filtering. -
Step 6: Commit the search change.
git add crates/archivr-core/src/archive.rs git commit -m "feat: search completed summary tags"
Task 7: Document, bundle, and verify the completed feature set
Files:
-
Modify:
docs/README.md -
Modify:
AGENTS.md -
Modify:
ARCHIVR-MENTAL-MODEL.md -
Generated (do not hand-edit):
crates/archivr-server/static/ -
Step 1: Update user documentation.
In
docs/README.md, document that summaries are manual, text-only by default, and the explicitInclude attached imagesoption sends at most four eligible local images to the selected provider. State the allowed formats and byte limits, identify Anthropic/OpenAI-compatible/Codex support, state Claude CLI cannot attach local images, and state free-text search includes the latest completed summary text and its generated tags. -
Step 2: Update contributor constraints.
In
AGENTS.md, record theSummaryBuildOptions/digest rule, the image candidate role and limits, the provider capability matrix, and the latest-completed-only search semantic. Preserve the rule that core remains synchronous and that generated static files are not hand-edited. -
Step 3: Update the architectural data-flow documentation.
In
ARCHIVR-MENTAL-MODEL.md, extend the LLM Summary section to show explicit UI consent flowing into image selection, cache hashing, provider transport, and the existing row lifecycle. Add that entry search reads only the latest completedsummary_text, retaining a prior completed result while newer work is pending or failed. -
Step 4: Build and test the final implementation.
Run:
cargo test bun --cwd frontend run build cargo buildExpected: all Rust tests pass, frontend build succeeds, and the generated static bundle contains the checkbox UI. Do not hand-edit generated files; include them in a commit only if this repository currently tracks frontend bundle changes after
bun run build. -
Step 5: Run the end-to-end manual smoke test.
Start the server with a test archive and verify: an X Article whose normal tweet text is only a t.co URL summarizes article body text; a text-only generation remains unchanged; a checked vision-capable request attaches only bounded eligible images; Claude has a disabled explanatory option and a direct API request is rejected; a
skincaresearch finds completed summary JSON tags; pending/failed rows do not hide a previous completed match. -
Step 6: Commit documentation and any tracked generated bundle.
git add docs/README.md AGENTS.md ARCHIVR-MENTAL-MODEL.md crates/archivr-server/static git commit -m "docs: explain image summaries and summary search"
Task 8: Final implementation review before integration
Files:
-
Review:
crates/archivr-core/src/summarizer.rs -
Review:
crates/archivr-core/src/archive.rs -
Review:
crates/archivr-server/src/routes.rs -
Review:
frontend/src/api.js -
Review:
frontend/src/components/ContextRail.jsx -
Review:
frontend/src/styles.css -
Review:
docs/README.md,AGENTS.md,ARCHIVR-MENTAL-MODEL.md -
Step 1: Perform the approved-design coverage review.
Verify A is covered by Tasks 1 and 2 (plain text, blocks, preview/summary, normal tweet fallback, and every thread JSON artifact); B by Tasks 2–5 (explicit default-off consent, selection policy/caps, input hash, all four provider outcomes, POST flag, and compatible GET); and C by Task 6 (latest completed summary JSON/tags, pending/failed semantics, prefix-filter preservation, server-side architecture).
-
Step 2: Scan the plan and implementation for unfinished markers and type drift.
Run:
rg -n -i '\\bt[o]do\\b|\\bt[b]d\\b|placehold[e]r|implement[[:space:]]later' docs/superpowers/plans/2026-08-23-x-article-vision-search.md crates/archivr-core/src/summarizer.rs crates/archivr-core/src/archive.rs crates/archivr-server/src/routes.rs frontend/srcExpected: no newly introduced unfinished markers in the changed feature code or plan. Confirm every use of
SummaryBuildOptions,SummaryImage, options-awarebuild_summary_input, and options-awaresummarize_entrymatches the Task 2 definitions. -
Step 3: Review commits and working tree.
Run:
git log --oneline --decorate -8andgit status --shortExpected: atomic commits cover the reducer, core image model/providers, server API, frontend control, search, and docs; no unintended artifacts or source edits remain.