Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d08c58f
feat(engine): add an empty upload group for dropped files
nodemode-ai Nov 27, 2026
42077cb
feat(upload): identify a pdf sent as the raw request body
nodemode-ai Nov 27, 2026
ea5e419
fix(side): hold the side body until the first read and collapse empty…
nodemode-ai Nov 27, 2026
8f1ed5b
fix(detail): refuse an empty title before saving
nodemode-ai Nov 27, 2026
c6489c7
fix(detail): keep the trash button content still when armed
nodemode-ai Nov 27, 2026
76c7093
feat(pair): list approved requests the app has not collected
nodemode-ai Nov 27, 2026
5e56d04
feat(add): send a dropped pdf's bytes to the upload route
nodemode-ai Nov 27, 2026
34b0bc3
feat(add): identify dropped pdfs without a path and show progress in …
nodemode-ai Nov 27, 2026
d0ff5bb
feat(side): create a subcollection from a collection row
nodemode-ai Nov 27, 2026
582db14
feat(itemlist): drop removed rows in place and fetch only the holes
nodemode-ai Nov 27, 2026
8d42dda
feat(connections): track approved requests the app has not collected
nodemode-ai Nov 27, 2026
e54dea0
feat(connections): show approved requests waiting for the app
nodemode-ai Nov 27, 2026
7d44a8a
feat(side): keyboard movement and tree roles for the collection tree
nodemode-ai Nov 27, 2026
053faa5
feat(itemlist): insert added and restored rows in place
nodemode-ai Nov 27, 2026
2927435
docs(service-tokens): describe the approved and waiting list
nodemode-ai Nov 27, 2026
35b0f82
docs(connections): log the waiting list in both hashout logs
nodemode-ai Nov 27, 2026
1967446
docs(identify): describe the upload route and the window drop
nodemode-ai Nov 27, 2026
60b4bd8
docs(hashout): log the upload route's guards and limits
nodemode-ai Nov 27, 2026
1b9e49e
docs(side): log the side hold, subcollections and tree keys
nodemode-ai Nov 27, 2026
7142bf5
fix(preferences): fill new service and library rows when they are made
nodemode-ai Nov 27, 2026
76d3542
fix(review): remove rows on the click and keep the trash fresh
nodemode-ai Nov 27, 2026
5c7b263
feat(pairing): withdraw an approval before the app collects it
nodemode-ai Nov 27, 2026
32ab583
fix(identify): do not attach the same file to an item twice
nodemode-ai Nov 27, 2026
c3b26b0
docs(network): name the upload route and the window list
nodemode-ai Nov 27, 2026
230f426
docs(window): describe subcollections, tree keys, drop upload and row…
nodemode-ai Nov 27, 2026
7b7c645
feat(connections): withdraw an approval from the waiting row
nodemode-ai Nov 27, 2026
cad00b4
docs(frontend): log the single row item list updates
nodemode-ai Nov 27, 2026
57b1e8e
docs(hashout): log the trash and merge click checks
nodemode-ai Nov 27, 2026
73d7b40
docs(identify): say a file already attached is not added again
nodemode-ai Nov 27, 2026
4ab8f51
docs(hashout): record the sha256 check before attaching
nodemode-ai Nov 27, 2026
c9e036b
docs(service-tokens): document withdrawing an approval
nodemode-ai Nov 27, 2026
7f6706b
docs(preferences): log the row fill fix and the service check
nodemode-ai Nov 27, 2026
9a2d65d
docs(detail): log the item pane click check
nodemode-ai Nov 27, 2026
938262c
fix(side): keep focus on a nearby row after a delete
nodemode-ai Nov 27, 2026
61b1189
feat(window): add a row position route for the item list
nodemode-ai Nov 27, 2026
fe2205e
docs(readme): say the window and agent tools look up too, and where t…
nodemode-ai Nov 27, 2026
7f26543
feat(detail): add note routes to the detail engine
nodemode-ai Nov 27, 2026
e35e8d7
feat(detail): edit, add and delete notes in the item pane
nodemode-ai Nov 27, 2026
d92dbc0
feat(itemlist): place added and restored rows with the position route
nodemode-ai Nov 27, 2026
3db674d
fix(side): hide a deleted row at the click and refocus after rename
nodemode-ai Nov 27, 2026
4b16dc6
docs(window): log the row position route
nodemode-ai Nov 27, 2026
095b400
docs(frontend): note the item list now uses the position route
nodemode-ai Nov 27, 2026
2b21dd7
docs(detail): log editable notes
nodemode-ai Nov 27, 2026
15b6040
docs(window): add notes, withdraw, position route and delete focus
nodemode-ai Nov 27, 2026
9352716
chore(release): 0.8.0
nodemode-ai Nov 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
# Changelog

## 0.8.0

The library window is finished: everything in it now stays still while it loads and while you work.

### New
- Collections inside collections. Each collection has a "New subcollection" action, and the tree can be folded.
- Move through the collection tree with the keyboard: up and down between rows, left and right to fold, unfold or step in and out, Enter to choose.
- Drop a PDF on the window in a browser and it is identified and added with the file attached. Dropping the same file again does not attach it twice.
- Notes can be added, edited in place and deleted in the item pane.
- Connections shows an app you approved that has not collected its access yet, and you can withdraw that approval.

### Changed
- Adding, restoring or removing an item now changes only the rows that move in the list, where it used to read the page again.
- A title can no longer be saved empty from the item pane.
- Deleting a collection, restoring or deleting from the trash, and merging duplicates take effect at the click, and are put back if the engine refuses.
- The readme says that the window and agent tools look things up too, and that Preferences holds the switches.

### Fixed
- The side pane no longer jumps one row when collections and tags first appear, or when a collection is created or deleted.
- Preferences no longer shifts when the services and libraries fill in, or when a library is created or switched; a new library row used to appear empty.
- The Trash button in the item pane no longer moves when it asks you to confirm.
- After renaming or deleting a collection, keyboard focus stays in the tree.

### Known issues
- "Open in FormPDF" still opens the system viewer: FormPDF cannot yet take a file from another Form app.
- Removing an item the list has not loaded yet still reads the list again.
- Creators are still edited as one line of text.
- The tag list was not measured with real tags in this release.
- The desktop app has not been built yet; the window runs in a browser against the engine.

### Under the hood
- A new engine route says where a row falls in the current sort and filter, and a raw upload route takes a dropped PDF.

## 0.7.0

The window shows your library for the first time. This is a first pass: it works end to end, and parts of it have not yet been checked as closely as the rest.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Another app on this computer, or an agent you run, can use your library only wit

## What FormCite sends over the network

Nothing, unless you ask for a lookup. `./formcite cli add doi=...` (or `arxiv=`, `isbn=`, `pmid=`) and `./formcite cli identify FILE.pdf` send the identifier, and only the identifier, to the service that knows it. A PDF and its text never leave your computer. There is no timer, no update check and no call at start-up.
Nothing, unless you ask for a lookup. `./formcite cli add doi=...` (or `arxiv=`, `isbn=`, `pmid=`) and `./formcite cli identify FILE.pdf` send the identifier, and only the identifier, to the service that knows it. The window does the same when you add by identifier or drop a PDF on it, and so do the lookup tools an agent calls. A PDF and its text never leave your computer. There is no timer, no update check and no call at start-up.

| Service | Host | Asked for |
| --- | --- | --- |
Expand All @@ -60,7 +60,7 @@ Nothing, unless you ask for a lookup. `./formcite cli add doi=...` (or `arxiv=`,
| Open Library | `openlibrary.org` | a book by ISBN |
| PubMed | `eutils.ncbi.nlm.nih.gov` | an article by PubMed ID |

`./formcite cli network list` shows these with their switches, `network off` stops every call, `network disable NAME` stops one service, and `network log` shows every call that was made. Setting `FORMCITE_OFFLINE=1` forces the network off. No email address is sent unless you set one with `network contact`. The rules are in [`docs/NETWORK.md`](docs/NETWORK.md).
In the window, Preferences lists every service with a switch for each. `./formcite cli network list` shows these with their switches, `network off` stops every call, `network disable NAME` stops one service, and `network log` shows every call that was made. Setting `FORMCITE_OFFLINE=1` forces the network off. No email address is sent unless you set one with `network contact`. The rules are in [`docs/NETWORK.md`](docs/NETWORK.md).

The data folder is `~/FormCite` (`FORMCITE_DATA_DIR`). Working on the code: see [`CONTRIBUTING.md`](CONTRIBUTING.md) and [`AGENTS.md`](AGENTS.md).

Expand Down
14 changes: 13 additions & 1 deletion backend/HASHOUT_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Living log of all comment content, explainers, rationale, TODOs, & removed (hashed-out) code for this side of the repo. Source files stay comment-free per dev-rules `sub-skills/hashout-log/SUB-SKILL.md`; everything they would have said lives here, indexed. This file is also the compressed contextual map of this side: read it first, then edit code surgically.

Current build version: v0.7.0
Current build version: v0.8.0
Last updated: 2026-11-27 (US Eastern) · the lean rows route for the window's list and opening an attachment

---
Expand Down Expand Up @@ -1649,3 +1649,15 @@ The item list's lean rows: one SQL statement per page, never `items.get` per row
- logged: v0.7.0 · 2026-11-27

FormTxt hands a PDF to FormPDF by POSTing `{"path"}` to `http://127.0.0.1:8198/api/pdf/open-path` (`formtxt/backend/app/services/versions_docs.py :: sign_handoff`). FormPDF's `WindowKeyGuard` refuses every POST without its own window key, and `/api/pdf/open-path` is not in its `OPEN` list, so that handoff is refused today; FormCite also may not open connections outside `app/net`, which is https only. So FormCite only reports whether a FormPDF install is present (`FORMCITE_FORMPDF_APP`, or `FormPDF.app` under `/Applications` or `~/Applications`) and always opens with the system viewer. The viewer is started from an argument list (`xdg-open`, `open`) or `os.startfile`, never a shell string, detached with `start_new_session` and no standard streams. The route sits behind `window_only` as well as the global guard, so a reader token can never open files.

## app/routers/pair.py {#app-routers-pair-waiting}

New in v0.7.0 (2026-11-27). `GET /api/cite/v1/pair/approved/waiting` lists approved pairing requests that have not been collected, from `pairing.listing(True)` filtered to `approved`. It lives under the service prefix, which the global guard lets through without a window key, so the route checks `window_key.valid` itself and answers 403 without it. It is declared before `/{request_id}` so it is not read as a request id. The token is still made when the app collects it. There is no withdraw route: `pairing._decide` only answers pending requests and `store` has no function to remove a request, both outside this slice.

## app/routers/upload.py {#app-routers-upload-identify}

New in v0.7.0 (2026-11-27). `POST /api/library/identify/upload?name=` reads the raw body with `Request.stream()`, so python-multipart is not needed. Neither guard looks at the content type: `WindowKeyGuard` only wants the key header on a non-read method and `LocalGuard` only checks host and origin, so the route is guarded exactly like `/identify`. `content-length` over `MAX_BYTES` (100 MB) is refused before reading, and the streamed count is checked again since the header can be absent or false. The first five bytes must be `%PDF-` or the answer is 415. The name is cut to its last path part and cleaned by `SAFE`, inside a fresh `mkdtemp` folder, so `..%2F..%2Fetc%2Fpasswd` becomes `passwd.pdf` there. `identify_file` runs in the thread pool through the path route's `_run`, so error mapping is shared; the file and folder are removed in `finally`. Dropping the same PDF twice no longer adds a second row: `identify._already` checks the matched item's attachments by sha256 before `_attach`, returns the existing row (with `path`) as `attached`, and the message says nothing was changed. It runs before any store, so `move` leaves the source file in place. Path route, upload route and CLI all go through `identify_file`, so they agree; the CLI was checked twice against the same data.

## app/routers/window.py, app/services/window_rows.py {#app-window-row-position}

New in v0.8.0 (2026-11-27). `GET /api/library/rows/{id}/position` takes the same `scope`, `id`, `q`, `sort` and `desc` as `GET /api/library/rows` and returns `{index, total}`. The index is `ROW_NUMBER() OVER (ORDER BY ...) - 1` built from the same `SORTS` expression, direction and `i.id` tie-break, under the same `_where`, so it can never disagree with the rows route. It is `-1` when the item exists but is outside the scope or filter (a trashed item is always `-1`), and the route answers 404 when no item has that id. Checked against `list_rows` on 2,002 items: year descending at offsets 700 to 702 and title with `q=river` at offsets 100 and 101 all matched.
2 changes: 1 addition & 1 deletion backend/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.0"
__version__ = "0.8.0"
9 changes: 9 additions & 0 deletions backend/app/routers/pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from fastapi import APIRouter, Header, HTTPException
from pydantic import BaseModel

from app.core import window_key
from app.service import pairing, store
from app.store.errors import Invalid, NotFound

Expand Down Expand Up @@ -34,6 +35,14 @@ def ask(body: Ask) -> dict:
return _run(pairing.ask, body.host, body.name, body.scope)


@router.get("/approved/waiting")
def approved_waiting(x_formcite_window_key: str | None = Header(default=None)) -> dict:
if not window_key.valid(x_formcite_window_key):
raise HTTPException(403, window_key.REFUSED)
rows = [r for r in _run(pairing.listing, True) if r["status"] == "approved"]
return {"requests": rows}


@router.get("/{request_id}")
def collect(request_id: str, x_formcite_pair_secret: str | None = Header(default=None)) -> dict:
return _run(pairing.collect, request_id, x_formcite_pair_secret)
1 change: 1 addition & 0 deletions backend/app/routers/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ def mount(app: FastAPI) -> None:
register("service", __import__("app.routers.service", fromlist=["router"]).router)
register("cite_write", __import__("app.routers.cite_write", fromlist=["router"]).router)
register("window", __import__("app.routers.window", fromlist=["router"]).router)
register("upload", __import__("app.routers.upload", fromlist=["router"]).router)
5 changes: 5 additions & 0 deletions backend/app/routers/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def deny(request_id: str) -> dict:
return _run(pairing.deny, request_id)


@router.post("/requests/{request_id}/withdraw")
def withdraw(request_id: str) -> dict:
return _run(pairing.withdraw, request_id)


@router.get("/tokens")
def tokens() -> dict:
return {"tokens": _run(store.tokens)}
Expand Down
59 changes: 59 additions & 0 deletions backend/app/routers/upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import os
import re
import tempfile
from pathlib import Path

from fastapi import APIRouter, HTTPException, Request
from fastapi.concurrency import run_in_threadpool

from app.routers.identify import _run
from app.services import identify as svc

GROUP = "upload"
router = APIRouter(prefix="/library", tags=[GROUP])

MAX_BYTES = 100 * 1024 * 1024
MAGIC = b"%PDF-"
SAFE = re.compile(r"[^A-Za-z0-9._ -]+")


def _safe_name(name: str) -> str:
base = SAFE.sub("_", Path(name.replace("\\", "/")).name).strip(" .")[:120]
stem = base[:-4] if base.lower().endswith(".pdf") else base
return (stem or "dropped") + ".pdf"


@router.post("/identify/upload")
async def identify_upload(request: Request, name: str = "dropped.pdf") -> dict:
declared = request.headers.get("content-length", "")
if declared.isdigit() and int(declared) > MAX_BYTES:
raise HTTPException(413, f"The file is larger than {MAX_BYTES // (1024 * 1024)} MB")
folder = tempfile.mkdtemp(prefix="formcite-upload-")
target = os.path.join(folder, _safe_name(name))
try:
size = 0
head = b""
with open(target, "wb") as out:
async for chunk in request.stream():
if not chunk:
continue
size += len(chunk)
if size > MAX_BYTES:
raise HTTPException(413, f"The file is larger than {MAX_BYTES // (1024 * 1024)} MB")
if len(head) < len(MAGIC):
head += chunk[: len(MAGIC) - len(head)]
if len(head) >= len(MAGIC) and head != MAGIC:
raise HTTPException(415, "Only PDF files can be identified")
out.write(chunk)
if head != MAGIC:
raise HTTPException(415, "Only PDF files can be identified")
return await run_in_threadpool(_run, svc.identify_file, target, attach="copy", on_duplicate="skip", add=True)
finally:
try:
os.remove(target)
except OSError:
pass
try:
os.rmdir(folder)
except OSError:
pass
12 changes: 12 additions & 0 deletions backend/app/routers/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ def rows(
)


@router.get("/rows/{item_id}/position")
def row_position(
item_id: str,
scope: str = "all",
id: str | None = None,
q: str | None = None,
sort: str = "title",
desc: bool = False,
) -> dict:
return _run(window_rows.row_position, item_id, scope=scope, scope_id=id, q=q, sort=sort, desc=desc)


@router.get("/rows/{item_id}")
def row(item_id: str) -> dict:
return _run(window_rows.one_row, item_id)
Expand Down
17 changes: 17 additions & 0 deletions backend/app/service/pairing.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@ def deny(request_id: str) -> dict[str, Any]:
return _decide(request_id, "denied")


def withdraw(request_id: str) -> dict[str, Any]:
now = int(time.time())
with store._locked():
data = store._read()
_expire(data, now)
req = next((r for r in data["requests"] if r["id"] == request_id), None)
if req is None:
store._write(data)
raise NotFound(f"pairing request {request_id}")
if req["status"] != "approved" or req.get("token_id"):
store._write(data)
raise Invalid(f"The pairing request {request_id} is {req['status']}, so its approval cannot be withdrawn.")
req["status"] = "denied"
store._write(data)
return public(req)


SAY = {
"pending": "Waiting for a person to approve or deny this request in FormCite.",
"denied": "The person who uses FormCite denied this request.",
Expand Down
14 changes: 12 additions & 2 deletions backend/app/services/identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ def _finish(lib, path: str, mode: str, attached: dict) -> dict:
return {**attached, "path": str(files.abs_path(lib, attached))}


def _already(lib, conn, item_id: str, path: str) -> dict | None:
sha = files.sha256_of(path)
for found in attachments.for_item(conn, item_id):
if found["sha256"] == sha:
return {**found, "path": str(files.abs_path(lib, found))}
return None


def _attach(lib, conn, item_id: str, path: str, mode: str) -> dict:
stored = None
try:
Expand Down Expand Up @@ -117,10 +125,12 @@ def identify_file(path: str, *, attach: str = "copy", on_duplicate: str = "skip"
return {**base, "found": True, "source": source, "record": resolved["record"],
"duplicates": matches, "message": "Looked up; nothing was added."}
if matches and on_duplicate == "skip":
attached = _attach(lib, conn, matches[0], path, attach)
held = _already(lib, conn, matches[0], path)
attached = held or _attach(lib, conn, matches[0], path, attach)
said = "this file was already attached to it, so nothing was changed" if held else "the file was attached to it"
return {**base, "found": True, "source": source, "duplicate_of": matches[0], "attached": attached,
"item": detail(conn, matches[0]),
"message": f"The item is already in the library as {matches[0]}; the file was attached to it."}
"message": f"The item is already in the library as {matches[0]}; {said}."}
made, attached = _create(lib, conn, resolved["record"], source, path, attach)
return {**base, "found": True, "added": True, "source": source, "duplicate_of": None, "attached": attached,
"item": detail(conn, made["id"]),
Expand Down
31 changes: 31 additions & 0 deletions backend/app/services/window_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,37 @@ def rows(
return {"total": total, "offset": offset, "rows": [_row(r) for r in found]}


def position(
conn: sqlite3.Connection,
item_id: str,
*,
scope: str = "all",
scope_id: str | None = None,
q: str | None = None,
sort: str = "title",
desc: bool = False,
) -> dict:
if sort not in SORTS:
raise Invalid(f"sort must be one of {', '.join(SORTS)}")
if conn.execute("SELECT 1 FROM items WHERE id = ?", (item_id,)).fetchone() is None:
raise NotFound(f"no item {item_id}")
clauses, args = _where(scope, scope_id, q)
where = " WHERE " + " AND ".join(clauses)
total = conn.execute("SELECT COUNT(*) FROM items i" + where, args).fetchone()[0]
direction = "DESC" if desc else "ASC"
ranked = (
f"SELECT n FROM (SELECT i.id AS id, ROW_NUMBER() OVER (ORDER BY {SORTS[sort]} {direction}, "
f"i.id {direction}) - 1 AS n FROM items i{where}) WHERE id = ?"
)
found = conn.execute(ranked, [*args, item_id]).fetchone()
return {"index": found[0] if found else -1, "total": total}


def row_position(item_id: str, **kwargs) -> dict:
with session() as (_, conn):
return position(conn, item_id, **kwargs)


def row(conn: sqlite3.Connection, item_id: str) -> dict:
found = conn.execute(COLUMNS + " WHERE i.id = ?", (item_id,)).fetchone()
if found is None:
Expand Down
4 changes: 3 additions & 1 deletion docs/IDENTIFY_PDF.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ FormCite can read a PDF you give it, find an identifier printed in it, look that

- Command line: `./formcite cli identify FILE`. Options: `--no-add` looks up and adds nothing; `--move` moves the file into the library, `--link` leaves it where it is (the default copies it); `--add-duplicate` adds a new item even when the library already holds the work; `--scan` only lists the identifiers and never goes to the network.
- Routes: `POST /api/library/identify` with `{path, attach?, add?, on_duplicate?}` (`attach` is `copy`, `move` or `link`); `POST /api/library/identify/scan` with `{path}` only lists the identifiers. Both need the window key like every other route.
- Upload: `POST /api/library/identify/upload?name=FILE_NAME` with the raw PDF bytes as the body (not a form). It needs the window key too. The bytes must start with `%PDF-` (otherwise 415) and stay within 100 MB (otherwise 413). They are written to a temporary folder under a name cleaned from `name` (only its last part, letters, digits, dot, dash, underscore and space, ending in `.pdf`), identified with `attach` copy, `add` on and `on_duplicate` skip, and the temporary file is removed afterwards. The answer has the same shape as the path route; its `file` is the temporary path, which no longer exists.
- Window: a PDF dropped on the window is sent to the upload route, since a browser never gives a path. Only when the desktop shell hands over a real path is the path route used. Progress and the answer appear in the line under the Import tab, which keeps its height, and in a short notice.

## What is read

Expand Down Expand Up @@ -33,7 +35,7 @@ Where it was found comes first: the metadata, then the first page, then later pa

## What is added

The item, its import batch and the attachment are written together: a failed lookup or a failed write leaves neither an item nor a stored file. When the library already holds the work (the duplicate check by DOI, then by title, year and first author), the file is attached to that item and the answer says so. A moved file is removed from its old place only after everything is written.
The item, its import batch and the attachment are written together: a failed lookup or a failed write leaves neither an item nor a stored file. When the library already holds the work (the duplicate check by DOI, then by title, year and first author), the file is attached to that item and the answer says so. When that item already holds an attachment with the same contents (same sha256), nothing is stored or recorded, `attached` is the existing attachment, and the answer says the file was already attached and nothing was changed; with `--move` the file then stays where it was. A moved file is removed from its old place only after everything is written.

## Limits

Expand Down
Loading
Loading