Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## 0.9.0

A small release that closes what the library window had left open.

### New
- Creators are edited one per row in the item pane: family name, given name, role, a single-name switch for institutions, move up, move down and remove. The item list's creator column follows a save.

### Changed
- A title can no longer be saved empty through the command line or the API either. Imports are not affected: an entry with no title still imports as it did.
- Removing an item the list had not loaded, or several items at once, now moves only the rows that change. The list reads itself again only for an item deleted for good, and for a never-loaded item removed while a search filter is on.
- Renaming a tag moves its row to its sorted place at once.

### Known issues
- After a tag rename, keyboard focus is sometimes lost about a second later on a slow machine. The cause has not been found.
- A brand-new tag added from the item pane pushes the tag rows under it down by one row.
- Creators come back grouped by role after a reload, because the library keeps one ordered list per role.
- Imported keywords are kept as text on the item and do not become tags.
- "Open in FormPDF" still opens the system viewer.
- The desktop app has not been built yet; the window runs in a browser against the engine.

### Under the hood
- The row position route can rank an item that is in the trash, and tells an unknown item apart from an older engine.

## 0.8.0

The library window is finished: everything in it now stays still while it loads and while you work.
Expand Down
10 changes: 9 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.8.0
Current build version: v0.9.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 @@ -1661,3 +1661,11 @@ New in v0.7.0 (2026-11-27). `POST /api/library/identify/upload?name=` reads the
## 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.

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

New in v0.9.0 (2026-11-27). `include_trashed=true` on the position route replaces the first `_where` clause (`i.trashed_at IS NULL`) with `(i.trashed_at IS NULL OR i.id = ?)` for the ranking only, so a just-trashed item is ranked among the live rows under the same `SORTS` order and `i.id` tie-break, and `total` still counts live rows. The answer then carries `include_trashed: true` so a window can tell an engine that ignored the flag. A purged item has no row and answers 404 `no item {id}`; Starlette's missing-route 404 says `Not Found`, which is how the window tells them apart.

## app/store/items.py {#app-items-title-required}

New in v0.9.0 (2026-11-27). `create` refuses a title that is empty or only white space with `Invalid("A title is required.")` (HTTP 422 through the routers, a line on stderr in the CLI) when no `batch_id` is given, which is every interactive path (`POST /api/library/items`, `item add`, the MCP add tool); `update` refuses it only when the item holds a non-blank title, so an old title-less item can still be edited in other fields. The model has no type that exempts a title (`title` is TEXT for ALL types in `record/fields.py`), so the rule covers every type, as the window already did. Import, lookup and identify pass a `batch_id` and keep their old behaviour: a BibTeX, RIS and CSL JSON entry with no title still imports with an empty title (checked: 2 of 2, 2 of 2 and 1 of 1 added, 0 failed). The twelve style regression cases pass.
2 changes: 1 addition & 1 deletion backend/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.8.0"
__version__ = "0.9.0"
12 changes: 11 additions & 1 deletion backend/app/routers/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,18 @@ def row_position(
q: str | None = None,
sort: str = "title",
desc: bool = False,
include_trashed: bool = False,
) -> dict:
return _run(window_rows.row_position, item_id, scope=scope, scope_id=id, q=q, sort=sort, desc=desc)
return _run(
window_rows.row_position,
item_id,
scope=scope,
scope_id=id,
q=q,
sort=sort,
desc=desc,
include_trashed=include_trashed,
)


@router.get("/rows/{item_id}")
Expand Down
14 changes: 11 additions & 3 deletions backend/app/services/window_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def position(
q: str | None = None,
sort: str = "title",
desc: bool = False,
include_trashed: bool = False,
) -> dict:
if sort not in SORTS:
raise Invalid(f"sort must be one of {', '.join(SORTS)}")
Expand All @@ -125,12 +126,19 @@ def position(
where = " WHERE " + " AND ".join(clauses)
total = conn.execute("SELECT COUNT(*) FROM items i" + where, args).fetchone()[0]
direction = "DESC" if desc else "ASC"
ranked_where, ranked_args = where, args
if include_trashed:
ranked_where = " WHERE " + " AND ".join(["(i.trashed_at IS NULL OR i.id = ?)", *clauses[1:]])
ranked_args = [item_id, *args]
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 = ?"
f"i.id {direction}) - 1 AS n FROM items i{ranked_where}) WHERE id = ?"
)
found = conn.execute(ranked, [*args, item_id]).fetchone()
return {"index": found[0] if found else -1, "total": total}
found = conn.execute(ranked, [*ranked_args, item_id]).fetchone()
answer = {"index": found[0] if found else -1, "total": total}
if include_trashed:
answer["include_trashed"] = True
return answer


def row_position(item_id: str, **kwargs) -> dict:
Expand Down
6 changes: 6 additions & 0 deletions backend/app/store/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def require(conn: sqlite3.Connection, item_id: str) -> None:

def create(conn: sqlite3.Connection, csl: dict, *, batch_id: str | None = None) -> dict:
fields = from_csl(csl)
if batch_id is None and not fields["title"].strip():
raise Invalid("A title is required.")
item_id = new_id()
stamp = now()
with tx(conn):
Expand All @@ -197,6 +199,10 @@ def update(conn: sqlite3.Connection, item_id: str, csl: dict) -> dict:
fields = from_csl(csl)
with tx(conn):
require(conn, item_id)
if not fields["title"].strip():
held = conn.execute("SELECT title FROM items WHERE id = ?", (item_id,)).fetchone()
if held is not None and str(held[0] or "").strip():
raise Invalid("A title is required.")
conn.execute(
"UPDATE items SET type = ?, title = ?, container_title = ?, issued = ?, year = ?, doi = ?, isbn = ?, url = ?, "
"abstract = ?, first_creator = ?, csl = ?, updated_at = ? WHERE id = ?",
Expand Down
2 changes: 1 addition & 1 deletion docs/WINDOW.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The **Items** view has three panes side by side.
- Columns: title, creator, year, type and date added. Click a column head to sort by it, click again to reverse.
- The search box filters the list by words in titles, creators, container titles, abstracts, notes and tags.
- Click a row or use the arrow keys to select it. The list stays smooth with thousands of items: only the rows on screen exist, and scrolling rewrites them.
- When an item is added or restored, the window asks the engine where that one row falls in the current list (`GET /api/library/rows/{id}/position`) and inserts only that row. When an item is removed, the rows below move up and only rows that were not yet loaded are fetched. If the engine cannot say where a row falls, or a removed item was never loaded, the list is read again.
- When an item is added or restored, the window asks the engine where that one row falls in the current list (`GET /api/library/rows/{id}/position`) and inserts only that row. When an item is removed, the rows below move up and only rows that were not yet loaded are fetched. A removed item the window never loaded is asked for with `include_trashed=true`, which answers where the trashed item sat in the same sort and filter. Several ids in one change are placed in one pass. An unknown id (404 with the engine's `detail`) is skipped on add. The list is read again only when the engine is older (405, or a bare `Not Found`), when an item was deleted for good before the window placed it, or when the count the engine returns does not agree, which today includes a never-loaded remove under a search filter.
- The creator column shows the first author, "A and B" for two authors, or "A et al." for more. Items with no year sort after the rest.

### Detail pane (right)
Expand Down
14 changes: 13 additions & 1 deletion frontend/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.8.0
Current build version: v0.9.0
Last updated: 2026-11-26 (US Eastern) · window skeleton: shell, engine store, window key, health status

---
Expand Down Expand Up @@ -408,3 +408,15 @@ New in v0.8.0 (2026-11-27). The engine stores an empty title without complaint,
## src/io/detail.ts, src/engine/detail.ts, src/ui/detail.ts, src/styles/detail.css {#src-detail-notes}

New in v0.8.0 (2026-11-27). Notes are editable in the pane through `POST /api/library/items/{id}/notes`, `PATCH /api/library/notes/{id}` and `DELETE /api/library/notes/{id}`, each with `{body}`. Each note is a one-line textarea inside the fixed-height notes box; it saves on blur or Ctrl or Cmd plus Enter, Escape puts back the stored text (kept in `data-saved`), and an empty edit is refused with a sentence in the reserved `.fc-dt-note-error` line. A line under the box adds a note on Enter. Delete asks for a second click within 3 seconds and its label box is sized for "Confirm", so the icon does not move. Notes are shown and sent as plain text: an HTML body from an import is flattened the first time it is saved. Checked in a fresh copy from HEAD with the 2,000-item library under CPU 4x, 400 ms and about 400 kbit/s: add, edit, Escape, delete and a reload all held, the box height did not change, and layout shift was 0 with and without input.

## src/engine/itemlist.ts, src/io/itemlist.ts {#src-itemlist-one-pass}

New in v0.9.0 (2026-11-27). `remove` and `insert` run through one queue so two notices never shift the cache at once. A removed id the cache never loaded is asked for with `fetchPosition(id, where, true)` (`include_trashed=true`); all answers come back together, the indices are sorted and the cache shifts once, then `ensure` reads only the holes. Adds and restores ask every position at once, check that the returned total grew by the number placed, read the rows with `GET /api/library/rows/{id}` in parallel and shift once. `fetchPosition` answers `unknown` for a 404 whose `detail` is not Starlette's bare `Not Found`, and `null` (older engine) for a 405, a bare `Not Found`, or a trashed ask whose answer lacks `include_trashed: true`. Unknown ids are skipped on add; on remove they mean the item was purged and its place cannot be known, so the list re-reads. Under a search filter a trashed item no longer matches the search index, the position comes back -1, the total check sees the count fell anyway and the list re-reads. Checked in a private built copy (with a `window.__fc` hook added only in the copy) with 2,000 items, CPU 4x, 400 ms and 50 kB/s, added-descending sort: never-loaded remove in all and in a tag, three removes and three restores in all, a 500-item collection, a 300-item tag and a `ledger` filter, and three adds in all, each with no `limit=200` read, zero pool nodes added or removed, pool 55, cached and painted ids equal to the engine's rows at the scroll top, scroll top and selection kept, and layout shift 0 with and without input except 0.0002 without input once in the collection.

## src/ui/side.ts {#src-side-tags-measured}

New in v0.9.0 (2026-11-27). The tag list was measured with 28 to 31 real tags on a 2,000-item library (a few hundred items tagged), CPU 4x, 400 ms and 50 kB/s, fresh engine. First fill: 30 rows inserted at once, 35 to 39 mutations in the pane, layout shift 0. `data-scope`, `data-name`, `data-parent` and `aria-current` were being rewritten on every row at every refresh (95 mutations for one scope pick, 64 for one delete); they now go through `setData` and `setCurrent`, which write only a changed value, and new rows get `aria-current` when built (60 and 8). A rename moves the row to its sorted place at the click through `placeTag` (reverted on an error), so the later refresh finds the order already right. `keepFocus` puts focus back on the focused node when a list patch or the post-rename scope change moves it. Still seen: after a rename under throttle, focus was lost to the body once in three runs about a second after the answer, from something outside `ui/side.ts` that was not found; a brand-new tag added from the item pane inserts a row in sorted place and shifts the rows below by 0.0013 without input; adding an existing tag only raises its count in place (20 to 21, shift 0).

## src/io/detail.ts, src/engine/detail.ts, src/ui/detail.ts, src/styles/detail.css {#src-detail-creators}

New in v0.9.0 (2026-11-27). Creators are edited in a fixed 144 px box under Title, one two-line row per creator: family and given on the first line, role (the 26 CSL name roles `NAME_ROLES` in `backend/app/store/items.py` accepts) with institution toggle, move up, move down and remove on the second. The engine keeps creators per role (`csl.author`, `csl.editor`, ...), each role ordered, with no order across roles; a save sends one `PATCH /api/library/items/{id}` whose `fields` carries every role that had or has names, an emptied role as `""` (which drops it). So the session keeps the order the user set, but after a reload the rows come back grouped by role in `NAME_ROLES` order. An institution is `{literal}`. `DetailModel.reconcile` keeps row keys across the quiet reload after a save, so `patchList` writes no row; a move swaps the two rows' contents and keys in place so no node moves. A row saves on blur out of the row, on Enter, and on a role change; Escape puts the stored row back (a new unsaved row is dropped); a refused save shows in `.fc-dt-cr-error` and puts the stored list back. The row buttons are `tabindex="-1"` so Tab runs family, given, role, next row; Alt plus Up or Down moves a row from the keyboard. Checked in a private built copy with 2,000 items under CPU 4x, 400 ms and 50 kB/s, fresh engine: add, reorder, role to editor, institution, refused save (routed 422) and remove each sent one PATCH (200), a reload read `author: [Castillo]`, `editor: [Second Ann, {literal: Acme Institute}]` through the API, the list creator cell went from "Haddad et al." to "Novak et al." to "Novak and Tanaka", the box stayed 144 px, and layout shift was 0 without input and 0.00085 with input (the rows under a removed row move up).
4 changes: 2 additions & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "formcite",
"private": true,
"version": "0.8.0",
"version": "0.9.0",
"description": "FormCite: a local-first personal research library from the Form family",
"license": "GPL-3.0-only",
"type": "module",
Expand Down
Loading
Loading