Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
8e310e5
fix(core): rebase a copied or moved data folder onto its own library
nodemode-ai Nov 28, 2026
dae1641
fix(routers): answer 404 for an unknown api path under every method
nodemode-ai Nov 28, 2026
5cb73d0
docs(cite): state how form.ext maps cite service answers to json-rpc …
nodemode-ai Nov 28, 2026
7c2a464
docs(cite): record the hello example run through form.ext fcite.call
nodemode-ai Nov 28, 2026
ac27830
docs(backend): log what the form.ext fcite.call run showed of the ser…
nodemode-ai Nov 28, 2026
f622c97
docs(data): explain copying, moving and restoring a data folder
nodemode-ai Nov 28, 2026
ff6755e
docs(hashout): log the data folder rebase, the api 404 and the trash run
nodemode-ai Nov 28, 2026
c7cad51
fix(desktop): open the window when the engine gives its address
nodemode-ai Nov 28, 2026
6d35171
feat(desktop): the splash opens in the saved theme on the next launch
nodemode-ai Nov 28, 2026
e75cb85
docs(desktop): log the first real desktop run and what it fixed
nodemode-ai Nov 28, 2026
6872f12
fix(store): keep a library inside the data folder by its relative path
nodemode-ai Nov 28, 2026
36bf87d
refactor(engine): mount the look routes once, in the registry
nodemode-ai Nov 28, 2026
aa75e75
feat(toast): let a notice open something when clicked
nodemode-ai Nov 28, 2026
b0746a6
fix(connections): drop the asks toast once the request is answered
nodemode-ai Nov 28, 2026
04dd883
docs(log): note the asks toast following its request
nodemode-ai Nov 28, 2026
5abf570
chore(release): 0.14.0
nodemode-ai Nov 28, 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
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Changelog

## 0.14.0

The desktop app starts, a copied library stands on its own, and an extension has searched a real FormCite.

### Fixed
- **The desktop app did not start.** It waited ten seconds for its engine to hand over a key that the engine never sends, then gave up. It now opens the window as soon as the engine is ready. Seen working in a release build on Linux: the library opened with 2,000 items.
- **A copied data folder wrote into the original.** The library's place was stored as a full path, so a copy or a moved folder still pointed at the old one. A library inside the data folder is now stored by its relative path, and folders written by older versions are read and corrected on first open. See `docs/DATA_FOLDER.md`.
- **The pairing notice stayed on screen** after the request was answered. It now goes when the request is approved, denied or expires, and clicking it opens Connections.
- An unknown address under `/api` answers "not found" for every kind of request, not "method not allowed" for some.

### Improved
- **The splash on the desktop** opens in the theme you chose, from the second launch after you choose it.

### Under the hood
- `docs/CITE_SERVICE.md` records the first run with form.ext's own `hello` example against a real engine: one found title after consent and approval, and the codes a host gives for each refusal.
- Checked for this version: the release build on Linux with the engine started from source; "Deleted for good." in Trash; the arrow keys on the theme list; Meta+Enter and Control+Enter on the title. Not run: a packaged build with the frozen engine, and anything on macOS or Windows.

## 0.13.9

Your theme and settings now stay with your library, the title saves on Enter, and a removed row says what happened.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</p>

<p align="center">
<img alt="version 0.13.9" src="https://img.shields.io/badge/version-0.13.9-eef0f4?style=flat-square">
<img alt="version 0.14.0" src="https://img.shields.io/badge/version-0.14.0-eef0f4?style=flat-square">
<img alt="Python 3.12 or later" src="https://img.shields.io/badge/Python-3.12%2B-3776ab?style=flat-square&logo=python&logoColor=white">
<img alt="License: GPL-3.0-only" src="https://img.shields.io/badge/license-GPL--3.0--only-3a3a3a?style=flat-square">
<img alt="Status: early" src="https://img.shields.io/badge/status-early-d69e2e?style=flat-square">
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.13.9
Current build version: v0.14.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 @@ -1689,3 +1689,11 @@ Run in v0.12.0 work (2026-11-27), no code changed. A stand-in Python client aske
## app/core/look_store.py, app/routers/look.py, app/main.py {#app-window-look}

New in v0.13.9 (2026-11-27). The window look (mode, dark theme, light theme, accent, title field) lives in `window-look.json` in the data folder, written the same way as `network.json` in `app/net/switches.py`: a temp file in the same folder, `fsync`, `os.replace`, under a lock. Every value is checked against a fixed list (themes match `frontend/index.html` and `ui/themes.ts`; accent is `#rrggbb` lowercased or empty for the default), and anything else is dropped, so the file can never feed a bad value into the page. `state()` adds `saved`, true once the file exists. `GET` and `PUT /api/window/look` both depend on `window_only`. The router is included from `main.py` because `routers/registry.py` belongs to the orchestrator; moving it into the registry is a one-line change there. `main.py` now answers `GET /` and `GET /index.html` itself, before the static mount, with `Cache-Control: no-store`: when the look is saved it adds `data-fc-...` attributes to the first `<html>` tag, each value passed through `html.escape(quote=True)`. No page script is added and the engine sends no Content-Security-Policy header, so nothing about that changes. Checked across ports 8812 and 8822 on one data folder; the numbers are in the frontend entry `src-look-in-engine`.

## app/routers/pair.py, app/routers/service.py, app/routers/cite_read.py, app/service/writelog.py {#app-cite-service-formext-run}

Run in v0.14.0 work (2026-11-27), no code changed. form.ext 0.12.0 (`affacd2`) host bridge and Python `FamilyService` with its hello example, against the engine on 8911 with 2,001 items: pair as `formext` scope `write`, Approve in Connections, `GET /search?q=learning&limit=3` 200, one hit. The service log is writes only (`writelog`), so a read through a token leaves no line in `service-log`; proof of a read is the engine's access log and the token's `last_used_at`. form.ext maps a revoked token's 403 to -32004 and a denied pairing to -32003; -32001 is only the host's own permission. `FamilyService` takes the port as an argument and does not read `engine.json` itself; the host passes it in. A window toast "form.ext asks to use your library. Open Connections to answer." was still on screen after the request was approved (`/tmp/R1/shots/fc-connections-approved.png`).

## app/core/config.py, app/core/data_folder.py, app/routers/registry.py {#app-data-folder-copy-and-api-404}

New in v0.14.0 (2026-11-27). Cause of the shared copies: `store/libraries.py` writes each library's `root` as a full path, so `cp -a A B` left B's `libraries.json` naming `A/Library`. `data_dir()` now runs `data_folder.settle` once per process per resolved folder, before anything reads `libraries.json`, in the engine and in the CLI alike. `settle` keeps an entry inside the folder, keeps a relative entry untouched, and rewrites an absolute entry outside it to `folder / basename` when that holds `library.sqlite` and the old place is missing or sits in a folder that holds its own `libraries.json`; anything else is a library placed elsewhere and keeps its path. The write is temp file, `fsync`, `os.replace`, as `store/libraries.py` does. The stored value is still absolute because `Library.__post_init__` resolves a relative root against the working folder; storing `Library` relative needs that file changed, which belongs to another slice. Checked on 2,000 items: copy then edit through the copy left the original's title as it was, and the reverse; `mv` to a new name listed 2000 of 2000; an old-format copy written before the fix opened its own library and was rewritten once; a library at `/tmp/R2/ext/Thesis` kept its path through a copy. `registry.mount` now ends with `/api/{rest:path}` for every method raising 404 `Not Found`, after every group, the MCP route and the look routes, so StaticFiles at `/` no longer answers 405 to a POST on an unknown api path. The look router is included here as well as in `main.py`; the first match wins, and the openapi path table hashes the same before and after (90 paths, 112 operations).
2 changes: 1 addition & 1 deletion backend/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.13.9"
__version__ = "0.14.0"
11 changes: 10 additions & 1 deletion backend/app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ def _ensure(path: Path) -> Path:

def data_dir() -> Path:
raw = env("DATA_DIR")
return _ensure(Path(raw).expanduser() if raw else Path.home() / "FormCite")
folder = _ensure(Path(raw).expanduser() if raw else Path.home() / "FormCite")
key = str(folder.resolve())
if key not in _SETTLED:
_SETTLED.add(key)
from app.core.data_folder import settle
settle(folder.resolve())
return folder


_SETTLED: set[str] = set()


def discovery_path() -> Path:
Expand Down
66 changes: 66 additions & 0 deletions backend/app/core/data_folder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import json
import os
import tempfile
from pathlib import Path

REGISTRY = "libraries.json"
DATABASE = "library.sqlite"


def _inside(path: Path, folder: Path) -> bool:
try:
path.relative_to(folder)
except ValueError:
return False
return True


def _foreign_folder(root: Path, folder: Path) -> bool:
parent = root.parent
if not root.exists():
return True
return parent != folder and (parent / REGISTRY).is_file()


def place(raw: str, folder: Path) -> str:
root = Path(raw).expanduser()
if not root.is_absolute():
return raw
root = Path(os.path.normpath(root))
if _inside(root, folder):
return str(root)
here = folder / root.name
if (here / DATABASE).is_file() and _foreign_folder(root, folder):
return str(here)
return str(root)


def settle(folder: Path) -> bool:
target = folder / REGISTRY
try:
data = json.loads(target.read_text(encoding="utf-8"))
except (OSError, ValueError):
return False
if not isinstance(data, dict) or not isinstance(data.get("libraries"), list):
return False
changed = False
for item in data["libraries"]:
if not isinstance(item, dict) or not isinstance(item.get("root"), str) or not item["root"]:
continue
fixed = place(item["root"], folder)
if fixed != item["root"]:
item["root"] = fixed
changed = True
if not changed:
return False
fd, tmp = tempfile.mkstemp(prefix=".libraries.", suffix=".tmp", dir=folder)
try:
with os.fdopen(fd, "w", encoding="utf-8") as handle:
json.dump(data, handle, indent=2)
handle.flush()
os.fsync(handle.fileno())
os.replace(tmp, target)
except BaseException:
Path(tmp).unlink(missing_ok=True)
raise
return True
2 changes: 0 additions & 2 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from fastapi.staticfiles import StaticFiles

from app.core import config, look_store
from app.routers import look as look_routes
from app.core.local_guard import LocalGuard
from app.core.window_key import WindowKeyGuard
from app.routers import registry
Expand Down Expand Up @@ -52,7 +51,6 @@ async def lifespan(_: FastAPI):
app.add_middleware(WindowKeyGuard)
app.add_middleware(LocalGuard, origins=config.cors_origins())
registry.mount(app)
app.include_router(look_routes.router)

_HTML_TAG = re.compile(r"<html\b[^>]*>", re.IGNORECASE)
_NO_STORE = {"Cache-Control": "no-store", "Pragma": "no-cache"}
Expand Down
11 changes: 10 additions & 1 deletion backend/app/routers/registry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import APIRouter, FastAPI
from fastapi import APIRouter, FastAPI, HTTPException

from app.routers import library, system
from app.routers import transfer
Expand All @@ -19,10 +19,19 @@ def register(name: str, router: APIRouter) -> None:
GROUPS[name] = router


def _unknown(rest: str) -> None:
raise HTTPException(404, "Not Found")


def mount(app: FastAPI) -> None:
for router in GROUPS.values():
app.include_router(router, prefix=PREFIX)
app.include_router(__import__("app.routers.mcp_http", fromlist=["router"]).router)
app.include_router(__import__("app.routers.look", fromlist=["router"]).router)
app.add_api_route(
PREFIX + "/{rest:path}", _unknown, include_in_schema=False,
methods=["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
)


register(system.GROUP, system.router)
Expand Down
10 changes: 8 additions & 2 deletions backend/app/store/libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class Library:
files_dir: Path = field(init=False)

def __post_init__(self) -> None:
root = Path(self.root).expanduser().resolve()
root = Path(self.root).expanduser()
root = (root if root.is_absolute() else data_dir() / root).resolve()
object.__setattr__(self, "root", root)
object.__setattr__(self, "db_path", root / "library.sqlite")
object.__setattr__(self, "files_dir", root / "files")
Expand Down Expand Up @@ -110,10 +111,15 @@ def _entries(data: dict[str, Any]) -> list[Library]:
return out


def _stored_root(root: Path) -> str:
home = data_dir().resolve()
return root.relative_to(home).as_posix() if root.is_relative_to(home) else str(root)


def _save(libs: list[Library], current_name: str | None) -> None:
_write({
"current": current_name,
"libraries": [{"name": lib.name, "root": str(lib.root)} for lib in libs],
"libraries": [{"name": lib.name, "root": _stored_root(lib.root)} for lib in libs],
})


Expand Down
18 changes: 16 additions & 2 deletions docs/CITE_SERVICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,17 +294,31 @@ The JSON on stdout is `{"file", "entries": [{"time", "host", "name", "token_id",

## What a host maps, and what FormCite itself answers

The cite service speaks plain HTTP with JSON bodies, not JSON-RPC. A host that offers its add-ons a JSON-RPC call into FormCite (form.ext's `fcite.call`) turns these answers into its own error codes: a refusal (403) into its "denied" code, and a method the host does not know into -32601. FormCite never answers a JSON-RPC code. For a route it does not have it answers Starlette's own 404 `{"detail":"Not Found"}` to a `GET` and 405 `{"detail":"Method Not Allowed"}` to a `POST`, with or without a token.
The cite service speaks plain HTTP with JSON bodies, not JSON-RPC. A host that offers its add-ons a JSON-RPC call into FormCite (form.ext's `fcite.call`) turns these answers into its own error codes. form.ext 0.12.0 does it this way: a permission or service the person did not allow in the host is -32001 and never reaches FormCite; a host without `fcite.call` answers -32601; FormCite not running, or a pairing not approved (pending or denied), is -32003; any other answer that is not a success, a 403 for a removed token included, is -32004 with FormCite's own `detail` as the message. FormCite never answers a JSON-RPC code. For a route it does not have it answers Starlette's own 404 `{"detail":"Not Found"}` to a `GET` and 405 `{"detail":"Method Not Allowed"}` to a `POST`, with or without a token.

The consent sentence the owner approved for form.ext's `fcite.addon` permission is "Let {Name} search, cite and add to your FormCite library?". That sentence is the host's own prompt. FormCite's approval is a second, separate consent in its Connections view, which shows the request as "Asks to search, cite and add to your FormCite library" (or "Asks to search and cite from your FormCite library" for a read-only request) with Approve, Approve reading only and Deny.

## Run against a real engine (2026-11-27)

Run once end to end on FormCite 0.11.0 (branch `feat/themes-polish-pairing-0.12.0`): a built window served by the engine on port 8515 with its own data folder, 2,000 BibTeX items imported, style engine hayagriva 0.10.1. The caller was a stand-in client, a Python script making the same loopback HTTP calls a host makes; it was not form.ext's hello example, because form.ext's `fcite.call` is not on form.ext's main. The approval and the revoke were clicks in the window in headless Chrome.
Run once end to end on FormCite 0.11.0 (branch `feat/themes-polish-pairing-0.12.0`): a built window served by the engine on port 8515 with its own data folder, 2,000 BibTeX items imported, style engine hayagriva 0.10.1. This first run checked the routes with a Python script as the caller; the run with form.ext's own host and its hello example is in the next section. The approval and the revoke were clicks in the window in headless Chrome.

- Before pairing, no token: search, get, cite, bibliography, add and import each answered 403 `This needs a FormCite service token, and none was sent.`
- `POST /pair` `{"host":"standin","name":"Stand-in Host","scope":"write"}` answered 200 with a request id and secret; a poll answered `"status":"pending"`. While pending, a made-up token got 403 `This service token is not known to FormCite.` on all six.
- After the click on Approve, the next poll answered `"status":"approved"` with the token, scope `write`.
- With the token: `GET /search?q=consequences&limit=2` 200, total 2000, two items; `GET /items/{id}` 200; `POST /cite` apa 200, `(Author0 & Writer0, 1980; Author1 & Writer1, 1981)`; `POST /bibliography` ieee 200, two entries; `POST /items` 201, a new book; `POST /import` 201, one added (a second run of the same text skipped it as a duplicate). The four writes are in the write log under the token's holder.
- After the click on Remove access, then Remove: all six answered 403 `This service token was revoked by the person who uses FormCite.`
- Layout shift at CPU 4x and 400 ms, 50,000 bytes per second: 0 for opening Connections with the request waiting and 0 for the approval, with and without input.

## Run with form.ext's hello example (2026-11-27)

Run on FormCite 0.13.9 (branch `feat/close-0.14.0`), a built window served by the engine on port 8911 with its own data folder: 2,000 BibTeX items imported, plus one item titled "Learning to cite through the R1 closing probe", which only this library holds (the hello example always searches `learning`, and the seed has no other match). The two form.ext commits used:

- new host: form.ext 0.12.0, `affacd2a9f92845bb054b3a5aef54c5092d344be` (branch `feat/fcite-call-0.12.0`, not merged);
- older host: form.ext 0.11.0, `a449e91b0412446435d3adbef6d57f0fcffa1f7d` (`main`).

form.ext's window has no switch that sends Preview's `fcite.call` to a real FormCite: Preview always answers from its simulated library. The run therefore used form.ext's own host pieces unchanged, joined by a small page: the contract's host bridge (`contract/host/host-bridge.ts`) mounted the hello example (`contract/examples/hello`) in its sandboxed frame, and the bridge's service handler passed each call to form.ext's Python host client (`FamilyService` in `contract/host/python/formext_host.py`), which paired with FormCite as `formext` ("form.ext") with scope `write` and made the HTTP call. The port came from FormCite's `engine.json`. Everything a person does was a click in Chrome (headless).

- Allowed: the host's consent listed "Let Hello search, cite and add to your FormCite library?"; after Allow, the request showed in Connections as "form.ext, formext, Asks to search, cite and add to your FormCite library"; after Approve the host collected the token and the hello panel showed `1 found: Learning to cite through the R1 closing probe`. The answer was `{"query":"learning","total":1,"limit":3,"offset":0,"items":[{"id":"5mpqpsrtp7","type":"article-journal","title":"Learning to cite through the R1 closing probe","creators":"Quillfeather","year":2026,"container_title":"Journal of Probe Results","doi":null,"snippet":"[Learning] to cite through the R1 closing probe"}]}`. The engine's access log has `GET /api/cite/v1/search?q=learning&limit=3` 200, and `service tokens` shows the `formext` token last used at the same second. `service-log` shows nothing for it, because the service log holds writes only and a search is a read.
- Denied in the host: with `fcite.addon` turned off, `{"code":-32001,"message":"Hello does not have the fcite.addon permission"}`; with the permission but FormCite not among the allowed services, `{"code":-32001,"message":"Hello was not allowed to use FormCite"}`. Neither reached FormCite.
- Denied in FormCite: after Remove access, `{"code":-32004,"message":"This service token was revoked by the person who uses FormCite."}`; with a new pairing request denied, `{"code":-32003,"message":"FormCite has not approved this app yet"}`. form.ext gives -32001 only for its own permission, never for a FormCite refusal.
- Older host: the 0.11.0 host bridge with the same hello files answered `{"code":-32601,"message":"fcite.call is not in API 1"}`, and the panel showed `-32601: this app cannot reach FormCite yet`. The 0.11.0 Python host's acceptance check (`formext_host.check`) refuses the hello package outright, "it asks for a permission that does not exist", so an older host that runs that check never loads the package and the -32601 is never reached.
Loading
Loading