Skip to content

Share posts: a post from a highlight, a region, the paper or several highlights - #25

Merged
andrepaim merged 110 commits into
masterfrom
feat/share-posts
Nov 16, 2026
Merged

andrepaim merged 110 commits into
masterfrom
feat/share-posts

Conversation

@andrepaim

Copy link
Copy Markdown
Owner

What this adds

A reader can turn something from a PDF into a post for LinkedIn, X or Instagram: an image made from the paper's own page, and a draft text. One assistant request writes the words; everything is drawn locally. Posts stay on the device and are never synced.

  • From a highlight: the page cropped around the highlight, with every highlight in the crop drawn in its colour. The crop is automatic (whole lines, the highlight's column) and can be dragged.
  • From a region: a figure, table or passage chosen on the page.
  • Share the paper: a post about the paper as a whole (its question, method and results), written from the first pages, the method and results sections, the limitations and the conclusion.
  • From several highlights: a carousel with a cover, the study, one slide per highlight, the takeaway and limits.
  • Destination first: LinkedIn, X or Instagram sets the frame, the text length and the defaults. On Instagram a post opens as a carousel: three cards for a highlight or region, five or six for a paper.
  • The text: up to three drafts (the finding, belief versus paper, the caveat), built around a "Your take" line that is quoted word for word. Hashtags and link placement are options; the app adds the source line.
  • Slides show numbers as numbers: a key number, stat tiles for a study's design, a small comparison table. Every word, value and row can be edited.
  • Export: copy or save an image; a carousel also saves as a ZIP of PNG files or one PDF.

Plan, decisions and results: docs/share-posts-plan.md (the first build's brief is docs/share-cards-plan.md).

Safety of what the assistant writes

  • The assistant runs with tools disabled, as everywhere else; PDF text, the take and stored fields are untrusted data inside the request's JSON.
  • An answer is checked before it is stored, repaired once, then refused: exact quotations, every number present in the source, a value near a word of its label, no first person without a take, no links or hashtags of its own, limits per destination.
  • No telemetry events. zod stays out of the browser bundle.

Data

  • Schema version 16: a local share_cards table. A library at 15 migrates to it; nothing else changes. Posts are not in the sync schema or the Firestore rules.
  • Trash and backups include posts.

Desktop

  • One new IPC handler, copy-image, writes a PNG to the clipboard (the renderer may not), with a size limit and a PNG check. It is the only change to the main process and preload.
  • Bundled fonts (Inter, Newsreader) with their licences in the third-party notices.

Validation

On af1b34522f53fbd13098572530cb4c0d2f2336fd (the commits after it change documentation only):

Check Result
npm run typecheck passes
npm test 443 tests: 442 pass, 1 skipped (Firebase rules without an emulator)
npm run build passes
Frontend Playwright 197 passed
npm --prefix desktop test 75 passed
node scripts/check-secrets.mjs passes

An independent review of the first two stages found 19 defects; all were fixed with a failing test first (listed in the plan).

Limits

  • Live requests were made in one round of 14 (Codex, two arXiv papers) before the Instagram carousel, the paper post and the number layouts existed. Those later parts were tried by the owner in a Windows preview build, not in a recorded round.
  • Real pages beyond those two papers: two-column, scanned and rotated pages have unit tests and made-up pages only.
  • Copy image was not exercised on Linux; the browser tests run in Chromium only; no screen reader was used.

🤖 Generated with Claude Code

andrepaim and others added 30 commits November 15, 2026 09:24
The limits, shapes and pure functions that the pipeline, the routes and
the reader's renderer share, with the zod schemas kept in a server-only
module so the reader's bundle stays free of zod. Adds the plan, its
stage 0 results, and a multi-line PDF fixture with a line-end hyphen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ShareCardService writes a post's words in one assistant request with a
single repair, keeps one post per highlight, guards every write with an
attempt token, and supports change, undo, restyle, cancel, retry and the
reader's edits. Posts are local only: schema 16 adds share_cards, the
trash reconnects a post when its highlight, source or project returns,
and backups count them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The desktop shell refuses every permission request, so the reader may not
be able to write an image with the clipboard API there. A copy-image
bridge checks the bytes (a PNG of at most 8 MB) before handing them to
nativeImage. The bundled Inter and Newsreader fonts for share cards are
added with their SIL Open Font License texts, which the third-party
notices now include.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A pure layout (DistillPod's measurements and fitting), three looks with
a contrast test, the bundled fonts, and a canvas painter. The same code
draws the preview and every export. A hidden /dev/share-cards page draws
the sample matrix, which a browser test checks and saves as PNGs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Loads the PDF with the viewer's options, without needing the viewer, and
renders the highlighted lines with up to three lines of context, falling
back to fewer lines and then to none when the sheet would be too tall.
The PDF worker and options move to a shared module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clicking a highlight opens a menu: Ask, Create post or Open post,
colours and Delete. The Post tab waits for the words, then shows the
card with its styles and looks (drawn locally, saved in the background),
the caption, Copy image, Copy caption, Change, and a menu with Save
image, Save as Story, edits, Undo and Delete. Highlights with a post are
marked in the reader and the Highlights tab, which also lists every
post, including those whose highlight or PDF is gone. ?post=<id> opens
a post beside its page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… result

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	CLAUDE.md
#	desktop/package.json
#	desktop/scripts/stage.mjs
#	desktop/src/main.mjs
#	frontend/src/main.tsx
Master now probes every agent binary for its version and flags before running it, so the fixture has to answer those calls.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…les and crops

Adds docs/share-posts-plan.md and the constants and types the parallel tasks build on: the Page and Headline styles first, the Fit size, destinations, angles, draft limits, page marks and the reader's crop. Headline and Fit are drawn as Big idea and Feed until the renderer task lands.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…p, keyboard steps

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CARD.headlineMax rises from 60 to 80, as docs/share-posts-plan.md says.
The tests that named the old limit now name the new one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eadline style

- crop-box.ts: autoCrop with a context setting, readerCrop, fitSheet,
  cropMarks (clipped, dropped outside the crop) and planCrop.
- pageCrop takes { sheet, crop, marks, extraLines } and returns the
  crop's box and its marks; a reader's crop never fails for height.
- The layout draws every mark in its own colour, narrows and centres a
  sheet that is too tall, sizes Page at Fit from its sheet within FIT,
  and lays out Headline (topic, headline, sheet) on Feed and Story,
  falling back to Big idea without a crop.
- SharePostPanel passes the new options (automatic crop, 3 lines).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… failure detail too

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, keyboard steps

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r the crop editor

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…t build's table

Schema version stays 16, which never shipped. The share_cards table gains
destination (default linkedin) and take (default ''). A table without the
destination column exists only in two test libraries, so it is dropped and
created again rather than migrated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
numbersIn and unsupportedNumbers compare numerals canonically: thousands
separators in either style, decimal commas, trailing zeros, percent signs and
units do not matter; decimals may be rounded to fewer places; range ends,
abbreviated years, ordinals and English number words in the source count.
When a numeral has two readings both count, so an ambiguous number passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he highlight's lines

An automatic crop used 1.35 times the box height for every line of
context, which drifts from the real line pitch and cut the last line in
half. A highlight over several lines now gives the pitch itself; a
single line keeps the old estimate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A made-up paper page is drawn on a canvas, each mark's phrase is found
on it, and planCrop crops it as pageCrop crops a PDF. Twelve frames in
three looks: Page at Fit for short, medium, reader and whole-page crops,
Page at Feed and Story, Headline at Feed and Story with several marks.
The frames carry data-frame, so the browser test's count of data-sample
still holds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The contract: Caption carries the destination, the take, three drafts
(finding, contrast, caveat), the chosen angle, hashtags, whether they show,
and where the link goes; the record adds the request's destination and take
and the page's marks. captionText composes the chosen draft with the source
line, link and hashtags by destination; firstCommentText gives the LinkedIn
first-comment line; draftLimits gives one draft's limits. headlineMax is 80.

The prompt is written for one destination with its limits. The check names
the field and the limit for every rule it can check: lengths, paragraphs, the
hook, the take word for word as its own paragraph, no first person of the
assistant's own, no stock ending or closing question, exact quotations,
leaks, links, hashtags, Markdown, and the numbers check on every draft, the
headline and the takeaways. Still one request and one repair.

The service takes destination and take on start and change. The first
version opens on the destination's default style and hashtag setting; a new
destination brings its own and keeps the look, crop and link. Marks are read
live from the page's highlights. New edits: crop (kept through Undo), angle,
show_tags, link and headline (behind Undo). Undo restores the destination
and take of the version it returns to.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ine (T2)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…mbers check (T1)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

# Conflicts:
#	test/integration/share-cards.test.ts
…o step

Choosing an angle drops the reader's edited text so the chosen draft shows. That lost the
text with no way back. Now the version holding it goes behind Undo; without edited text
the angle is still written in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A post can start from a box the reader drew on a page, or from the first page,
without a highlight. The source records its kind and region; its passage is
the text read inside the region, which may be short or empty. The card has
only a headline and a topic, starts on the region as its crop and returns to
it when the crop is reset; text-card styles and quote edits are refused with
the reason. Region posts are not unique per region: only the request ID makes
a retry idempotent.

The prompt is one function with a variant per kind that shares every rule:
for a region it asks for the caption in the page text and forbids describing
visual detail the text does not state; for the first page the finding says
what the paper studied and its main result. The checks are a highlight's,
with the region text in the numbers pool and as the source of quotations.

samples.ts gains kind and region on its two sources so the frontend compiles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…column

page-crop.ts reads the page's text runs with pdf.js for an automatic
crop. crop-box.ts joins them into line pieces, finds the column the
highlight sits in from the text beside it (two columns stay apart; a
highlight across both takes both), and cuts between lines with a small
margin, so no line or word is cut through. Text across the column's edge
or a gap of several lines ends the context, which is then taken from the
other side, and the crop never ends on a heading without its next line.
extraLines is now the minimum context: the crop grows by whole lines,
balanced, while its sheet stays within sheet.fill. Without a usable text
layer the old rule applies. A reader's crop is drawn as set, also for a
post with no boxes of its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
andrepaim and others added 27 commits November 16, 2026 08:34
A lead slide is the Headline style above the post's own crop; without a
crop it is a cover, taking its fallback as the pull quote when it
differs from the headline and fits. Question, method and result slides
are text slides like the study and takeaway slides; a result that starts
with its number draws that number in the look's emphasis box, through a
new optional layout input that leaves every other card unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The six-slide paper carousel in every look, its lead also without a
crop, and the five-slide one in Ink, marked data-slide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…nd results

A paper post is now written from a wider text: paperText takes the first
pages, the start of the method and results sections and the conclusion,
found by their headings in running text (not in a table of contents, running
prose or a structured abstract), never the references, within 24,000
characters shared fairly between the parts. It is stored in source.context.

The answer for a paper post adds question, method and one or two results;
each passes the checks on the assistant's own words, results may not repeat
each other or the headline, and the headline may not be the paper's title.
The prompt is a paper variant of the shared rules naming regionText and
paperText; the highlight, region and set prompts are unchanged byte for
byte. The card keeps them in paper; PATCH paper_text edits one behind Undo.
postSlides gives a paper post five or six slides (lead, question, method,
results, takeaway); one stored before keeps its three cards. Summaries and
refusals call the kind "Paper".

Compile fixes outside the server: samples.ts gains paper on its base card;
SlideViewer.tsx keeps the stage 4 slide kinds until the panel adds the new.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… the method

On a real paper (QLoRA) the wider text lost section 8, "Limitations and
Discussion", took a mid-paper paragraph called "Summary" for the conclusion,
found no method, and matched a page number with the next page's figure
caption as a section heading.

paperParts (paperText joins it) now keeps a limitations part (Limitations and
Discussion, Discussion and Limitations, Limitations, Future Work, ...), takes
a conclusion only after the method and results, falls back to the first
numbered section that is not background or related work as the method, stops
parts at broader impact, acknowledgements, funding and appendices, and cuts
appendices when no references heading exists. A heading may open a page, but
never joins a number or its first word across a page break. The last page
stands in for a conclusion only when it starts after every part found.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… real papers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"Share the paper" replaces "Share the first page": one click works out the first page's
title, authors and abstract box and its text (readFirstPage) and starts a paper post, with no
modal; a double click starts one post, and the hint names what each action gives. The slide
viewer handles every kind: a paper post's lead (headline above the first page, with Adjust
crop and its reset to the first-page box), question, method and one or two results, edited
with { paper_text } (a result cannot be emptied). An older paper post keeps its three cards
with a notice and a Rewrite button. The kind is called Paper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s lose the first-page modal

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ions and the method

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… view

At some window sizes the reader has page 2 in view when the Post tab opens, so the hint named page 2 and the screenshot test failed in about half its runs.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…y the paper's

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A carousel's text slides take their layout from their content: stat
tiles for a method or study with stats, a comparison table for a result
with rows (the key row in the emphasis box, bars from a common zero
only when every value is one non-negative number in one unit), the
number very large over its label for a result or cover with a key
number, an oversized mark for a question that ends with one, and the
accent bar at the foot for every takeaway. Without numbers, a hook is
set as before and a study, method, result or limit as a lighter
statement. The kicker sits at the top of every such slide. Picture
slides and every card are unchanged; missing fields draw the slide
without numbers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A highlight post's three cards, a set carousel and a paper deck, each
with the numbers its text gives and without any, in every look, and the
layouts at their limits in Ink, marked data-slide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ats and comparisons in the paper deck

Every answer carries stat, the one number that carries the finding, from the
highlight itself, a region's text or page, one of a set's highlights, or the
paper (for a paper post it is the first result's stat when there is one). A
set's answer carries studyStats; a paper's carries methodStats and results
as { text, stat, rows }, a comparison of one measure and one unit.

Every value passes the numbers check and must sit near a word of its label in
the source (valueNearLabel: 150 characters each side of the number, content
words without case, plural or hyphen differences, skipped when the label's
words are nowhere in the source). Labels pass the checks on the assistant's
own words. Stored cards read: results as strings become objects, and
methodStats, studyStats and stat default to empty.

PATCH gains { stat }; paper_text takes stats, stat and rows beside an
optional text, and set_text takes the study's stats; one Undo step each.
postSlides and setSlides put stat on the cover and stats on the method and
study slides. The highlight, region and set prompts gain only their stat and
studyStats lines.

Compile fix outside the server: samples.ts gains stat on its base card.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…risons in the paper deck (T16)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Edit slide learns numbers: a cover's key number, a study's or method's stat tiles (up to four,
add and remove), a result's key number and comparison rows (none or two to four, add, remove,
move up and down). Values and labels are checked as the server checks them, next to their
fields; a server refusal shows in the dialog, which stays open. One Save is one request and
one Undo step, except a cover whose headline and number both changed (two edits on the
server). Each slide's alt text reads its numbers in order. The client reads a stored post
leniently: no key number, stats or rows is none, and a paper result stored as a sentence is
that sentence. The dialog moved to SlideEditDialog.tsx; the zod guard covers it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…key numbers, stats and rows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…w shots of numbers on slides; README and T18

The dialog filled its fields after the first paint, so it could flash the last slide's words
and numbers; it now fills them before. A label input keeps room for its words on a phone, so
Remove wraps under it. README: slides show numbers as numbers, and each can be edited.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… directory

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@andrepaim
andrepaim merged commit f41d54d into master Nov 16, 2026
9 checks passed
@andrepaim
andrepaim deleted the feat/share-posts branch November 16, 2026 16:13
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