The desktop app talks to the engine over HTTP on 127.0.0.1 only. Start it with
doculens serve [--port 47815]. The server also runs the folder watcher, so the app needs only this one
process.
All bodies are JSON. Errors are returned as {"error": "<message>"} with a 4xx or 5xx status.
Every start of doculens serve writes a new random token, readable only by the user (mode 0600), to
$DOCULENS_HOME/api-token (default ~/.doculens/api-token). Every /api/* request must send it:
Authorization: Bearer <token>
- Without it (or with a wrong one) the answer is 401.
GET /api/eventsmay pass it as?token=<token>instead, for clients that can't set headers.GET /api/healthneeds no token, so the app can poll it before reading the token file; without the token it returns only{"ok": true, "version": "…"}.- A request whose
Hostheader isn't127.0.0.1:<port>orlocalhost:<port>gets 403, token or not. - CORS allows no web origin. For a renderer dev server, set
DOCULENS_DEV_ORIGIN(e.g.http://localhost:5173) in the engine's environment. The desktop app calls from its main process.
| Method | Path | Body | Returns |
|---|---|---|---|
| GET | /api/health |
– | {"ok": true, "version": "0.1.0", "provider": "claude-code", "watching": ["/Users/me/Downloads"], "paused": false}; without a token only ok and version |
| POST | /api/watch/pause |
– | {"watching": false}; new files are held, not lost |
| POST | /api/watch/resume |
– | {"watching": true}; held files are processed |
| GET | /api/suggestions?status=pending&limit=50&before=931 |
– | {"items": [Suggestion], "total": 1284, "next": 931} — one page, newest first. See Paging. status is optional and repeatable; limit defaults to 50 and is capped at 5000; before is the cursor. Pending/error ones whose file is gone are rejected first. |
| GET | /api/counts |
– | {"pending": 12, "applied": 1284, "rejected": 40, "undone": 3, "error": 1, "total": 1340, "filed_today": 7, "folders": {"Grants": 210}} — every number the sidebar shows, counted over the whole store. See Counts |
| GET | /api/suggestions/{id} |
– | Suggestion |
| POST | /api/suggestions/{id}/apply |
{"category": "Grants"} (optional; a different category records a correction) |
Suggestion; works on pending, error and undone ones (an undone one is filed again from where Undo put it) |
| POST | /api/suggestions/{id}/reject |
– | Suggestion |
| POST | /api/suggestions/{id}/undo |
– | Suggestion |
| POST | /api/undo |
– | the undone Suggestion (the most recently applied one) |
| POST | /api/scan |
{"paths": ["/optional/file/or/dir"], "limit": 50} |
{"processed": [Suggestion]} (files already seen are skipped; paths must be inside a watched folder, else 400) |
| GET | /api/config |
– | {"provider", "model", "watch": [..], "library_root", "auto_move_threshold", "rename", "finder_tags", "learn_from_filing", "memory", "categories": [Category], "rules": [Rule]} |
| PUT | /api/categories |
{"categories": [Category + {"was": "Old name"}], "rules_of_removed": "refuse"} (folder may be relative to library_root; was is optional) |
{"categories": [Category], "rules": [Rule], "renamed": {"Old name": "New name"}, "rules_removed": ["When a file …"]} (written back to config.toml); a new or changed folder must be inside the home folder, not ~/Library or a hidden folder, without .. (else 400). Rules follow their folder: a rename rewrites the rules that name it in the same write, and removing a folder that rules still file into is 409 unless rules_of_removed is "remove". See Smart folders |
| GET | /api/smart-folder?name=Bank%20%26%20Tax |
– | {"folder": Category, "exists": true, "files": 12, "filed": 40, "rules": [Rule + {"position", "how", "subfolder"}], "subfolders": [{"name", "path", "files"}], "learned": [{"sentence", "kind", "value", "subfolder", "files", "strong", "current"}]} — one folder as a smart folder. 404 for a name that is not a folder. See Smart folders |
| GET | /api/smart-folder/recent?name=Bank%20%26%20Tax&limit=20&before= |
– | {"files": [{"name", "subfolder", "modified"}], "total": 312, "next": "…"} — the newest files anywhere in the folder on disk, newest first, one page: subfolder is where each sits (relative, "" for the folder itself), modified when it arrived (the later of its content and its inode changing, so a file moved in reads as when it moved). limit defaults to 20, at most 500; pass next back as before for the page after. 404 for a name that is not a folder. See Smart folders |
| GET | /api/rules |
– | {"rules": [Rule]} — see Filing rules |
| PUT | /api/rules |
{"rules": [Rule]} (summary is ignored) |
{"rules": [Rule]} (written back to config.toml). The whole list is replaced; [] removes them all. A rule that could never be honoured, or whose folder is outside the allowed places, is 400 and nothing is saved |
| POST | /api/chat |
{"message": "stuff from a-site.test with thumbnail in the name goes to YouTube/Thumbnails", "conversation": 3, "turn": "c-17"} (conversation is optional; context is what the app has on screen, see What the chat sees; look_at_downloads: true makes the downloads lookup before the model is asked, and nothing in the app sends it any more; history is still accepted, and read only when the stored conversation is empty) |
{"rules": [Rule], "folders": [FolderChange], "files": [FileProposal], "question": "", "say": "You already keep a YouTube folder, so I'll file into its Thumbnails.", "apply_to_existing": false, "looked_at": "", "lookups": [{"tool", "args", "summary"}], "conversation": 3, "asked_id": 41, "message_id": 42, "states": States, "turn": "c-17", "cancelled": false, "remembered": [{"op", "id", "kind", "text", "folder", "until"}]} — what DocuLens proposes, or a question when the message is ambiguous. say is one or two plain sentences in the model's own words, shown above the proposals ("" beside a question, and when every proposal it introduced was dropped); with no proposals it may be the whole answer, up to 800 characters, and it is always cut at the end of a sentence. When the engine dropped anything the model drafted (a rule already covered or unusable, a folder change refused or colliding, a file that cannot be filed), say is the engine's plain reasons instead, even beside surviving cards, and when nothing survived those reasons are the question. The message and the answer are stored in conversation — the current one when it is missing, 404 when it names none kept (see The conversation); the model is told that conversation's earlier turns from the store. The lookup fields are described in What the chat can look up. A turn stopped with POST /api/chat/turn/{turn}/cancel answers cancelled: true, empty proposals and null ids, and nothing of it is stored. quick: true means a plain command (rename, remove, file this, undo) was answered without the model (quick.py), judged exactly as a model's answer is; the app offers "Not what you meant? Ask again properly" under it, which sends the same message with skip_quick: true to go straight to the model. Changes nothing about rules or folders, moves nothing and deletes nothing |
| POST | /api/chat/turn/{turn}/cancel |
– | {"turn": "c-17", "cancelled": true, "running": true} — stop that turn before its next lookup or model call. A model call already under way is not interrupted; its answer is thrown away. Neither the message nor an answer is kept, and nothing is remembered. A stop may arrive before the turn it names has started, and still stops it (running is then false). Published as event: chat with {"turn", "cancelled": true} |
| GET | /api/chat?conversation=3 |
– | {"conversation": 3, "messages": [ChatMessage]} — the current conversation, oldest first; conversation is optional and names an older one still kept (404 when it is not). See The conversation |
| GET | /api/chat/conversations |
– | {"conversations": [{"id", "created_at", "messages", "first", "dont_remember"}]} — every kept conversation, newest first; first is its first line, cut to 120 characters |
| POST | /api/chat/new |
– | {"conversation": 4, "messages": []} — start a new conversation. The one before is kept (the newest 20 are) |
| POST | /api/chat/messages |
{"role": "doculens", "text": "Added the rule.", "payload": {}} |
ChatMessage — a line the app adds to the current conversation itself. The app no longer needs it for a plan: the plan is kept on the answer it carried out (plan_run). role is you or doculens (else 400); empty text is 400; text is cut to 2000 characters |
| POST | /api/chat/messages/{id}/state |
{"kind": "rule", "index": 0, "state": "added"} |
ChatMessage — what the user did with one proposal of a stored answer. kind is rule, folder or file (with index), apply or plan; state is proposed, added, declined, done or undone. 400 for anything else or an index the answer does not have, 404 for an unknown message |
| POST | /api/plan |
{"folders": [FolderChange], "rules": [Rule], "files": [{"suggestion": 12, "folder": "GATE", "index": 0}], "file_waiting": true, "message_id": 42, "turn": "p-3"} |
{"plan": 7, "ok": true, "cancelled": false, "steps": [Step], "error": "", "filed": 3, "turn": "p-3"} — carry out a whole chat answer with one approval: folders, then rules, then the files it named, then filing what the rules catch. Stops at the first failing step, or before the next step once cancelled. 400 for an empty plan. See One plan, one approval |
| POST | /api/plan/{id}/cancel |
– | {"plan": 7, "cancelled": true} — stop a running plan before its next step. What it already did stays done and undoable, as after a failed step; the plan's status becomes cancelled. Published as event: plan with {"turn", "plan", "cancelled": true}. 404 unknown id, 409 when it is not running |
| GET | /api/plan/{id} |
– | {"plan": 7, "status": "done", "message_id": 42, "folders": 1, "rules": 1, "filed": 3, "created_at"} — status is running, done, failed, cancelled or undone. 404 for an unknown id |
| POST | /api/plan/{id}/undo |
– | {"plan": 7, "undone": true, "files": 3, "kept": ["bundle.zip was moved or filed again since, so it stays where it is."]} — take the whole plan back. 404 unknown id, 409 already undone or still running |
| GET | /api/memories |
– | {"enabled": true, "memories": [Memory], "count": 3, "chars": 112, "limit": 40, "max_chars": 2000} — what DocuLens remembers the user told it. See What DocuLens remembers |
| POST | /api/memories |
{"kind": "preference", "text": "Wants receipts named by shop and date", "folder": "", "until": ""} |
Memory (source: "user"). 400 for a kind that is not about/preference, empty or over-150-character text, an ID/account/card number, a folder that is not theirs, or an until that is not YYYY-MM-DD; 409 when the same sentence is already kept, or memory is full of the user's own |
| PUT | /api/memories/{id} |
any of {"kind", "text", "folder", "until"} |
Memory — edited by the user, so source becomes "user". Same checks as adding; 404 unknown id |
| POST | /api/memories/{id}/forget |
– | the Memory as it was. 404 unknown id |
| POST | /api/memories/{id}/undo |
– | {"memory": Memory | null} — takes back the latest change to that memory, whoever made it: an add is removed (null), an edit gets its old words back, a forget is put back. 404 when there is nothing to undo |
| POST | /api/memories/forget-all |
– | {"forgotten": 7} — every memory and every earlier version of one |
| PUT | /api/chat/conversations/{id} |
{"dont_remember": true} |
the conversation as GET /api/chat/conversations lists it — nothing said in it is remembered. 404 unknown id |
| POST | /api/rules/test |
{"rules": [Rule], "limit": 20} |
{"checked": 20, "matched": [{"suggestion": 12, "filename", "source_path", "rule": 0, "summary", "reason", "folder", "destination_path", "auto"}]} — a dry run against the most recent files. suggestion is the id to apply, which is how "file those 3" is carried out. Moves nothing |
| GET | /api/nothing-to-read |
– | {"waiting": 287, "groups": [{"kind": "image", "phrase": "images", "count": 133, "extensions": [".png", ".jpg"], "examples": [".."], "ids": [12, 14, ..]}]} — waiting files the no-text rung answered, grouped by kind, biggest group first. ids are every row in the group, to apply. Reads nothing and saves nothing |
| GET | /api/catch-up/survey?root=&min_files=3 |
– | {"root", "files": 513, "folders": 92, "worth_showing": true, "why_not": "", "kinds", "sites", "groups": [{"key", "label", "site", "matches", "count", "examples", "sentence", "rulable", "rule": {"when"}, "paths"}], "tail", "homeless", "coverage", "checks", "shelves"} — the whole pile read before anything in it is classified. See Reading the folder first. root must be a watched folder. Opens no file, calls no model, writes nothing |
| POST | /api/catch-up/survey/propose |
{"root": "", "min_files": 3} |
{"proposals": [{"group", "folder", "existing", "says", "does", "why", "skip"}], "reason": ""} — one model call for the whole folder. says is the model's sentence, does is the rule's own from rules.describe and is "" for a group that may not have a rule. Saves nothing, moves nothing |
| POST | /api/catch-up/place |
{"folder": "Papers", "paths": ["/Users/me/Downloads/a.png"]} |
{"placed": [Suggestion], "skipped": 2} — a group the user accepted, put in the Inbox pointed at one folder without any of it being read. skipped counts files already known, gone or empty. 400 for a folder that is not one of theirs or a path outside a watched folder. Moves nothing |
| POST | /api/rules/describe |
{"rules": [Rule]} |
{"summaries": ["When a file comes from a-site.test → file it into Papers, and ask first."]} — what these rules would really do, in the engine's own words. Saves nothing |
| GET | /api/rules/suggested?limit=50 |
– | {"considered": 12, "items": [Rule + {"message", "signal", "count", "examples": [..]}]} — rules found in the user's own filing. Saves nothing |
| POST | /api/discover-folders |
{"roots": ["/abs/dir"], "propose": true} (both optional; roots for testing, default ~/Documents, ~/Desktop and the watched folders) |
{"categories": [Category], "scanned": 42, "reason": ""}, or with "propose": false {"folders": [...], "places": [...], "scanned": 42} — see Folder discovery |
| GET | /api/providers |
– | {"items": [{"id": "ollama", "name": "On this Mac (Ollama)", "available": true, "detail": "Running, models: llama3.2:3b"}, …]} in the order ollama, claude-code, codex, claude-api, openai |
| PUT | /api/openai-key |
{"key": "sk-…"} |
{"saved": true} — the key for an OpenAI-compatible endpoint. Write-only: no endpoint ever returns it, and an empty string removes it. See Where keys live |
| PUT | /api/claude-key |
{"key": "sk-ant-…"} |
{"saved": true} — the Claude API key, on the same terms. Write-only: no endpoint ever returns it, and an empty string removes it. See Where keys live |
| PUT | /api/settings |
any of {"watch": ["/abs/dir"], "library_root", "provider", "model", "auto_move_threshold" (0.5–1), "rename", "finder_tags", "learn_from_filing", "openai_base_url", "memory"} |
same shape as GET /api/config; watched folders must exist and be inside the home folder or on /Volumes, and a new library_root inside the home folder (not ~/Library or hidden); changing watch restarts the watcher (files already waiting are kept), changing provider/model takes effect for the next file |
| GET | /api/precedent |
– | {"learning": true, "rows": 214, "decisions": 96, "rungs": {"rule": 8, "same-file": 3, "precedent": 31, "model": 54}, "shares": {…}} — what DocuLens has learned and which rung answered each file. See What DocuLens learns |
| POST | /api/precedent/adopt |
– | {"folders": [{"folder", "category", "files"}], "files": 312, "rows": 214} — read the names of what is already in the user's category folders and seed the tally. Opens no file, moves no file, skips folders already adopted. 400 while "Learn from what I file" is off |
| POST | /api/precedent/forget |
– | {"forgotten": 214, "rows": 0} — "Forget what you've learned". Empties the tally; the decisions record is kept |
| GET | /api/backlog |
– | {"running", "paused", "total", "done", "suggested", "started_at", "finished_at"} |
| POST | /api/backlog |
{"paths": ["/optional/dir"], "limit": 5000} |
the same status. Works through the files already in the watched folders in the background. Moves nothing, whatever a category's auto or a matching rule says. 409 when one is already running, 400 for a path outside a watched folder |
| POST | /api/backlog/pause | /resume | /stop |
– | the same status |
| GET | /api/idle |
– | {"ran_at", "forgotten", "rule_offers": [Rule + {"message", "signal", "count"}], "stale_rules": [{"summary", "folder", "corrected", "of", "message"}], "dead_folders": [{"category", "last_filed", "message"}], "due"} — the last idle pass. ran_at is "" before the first one |
| POST | /api/idle |
– | the same shape; runs one pass now. It only ever proposes |
| GET | /api/events |
– | Server-Sent Events: event: suggestion with a Suggestion payload whenever one is created or changes; event: chat for each lookup a chat turn makes as it happens; event: chat-text with the reply as it is written; event: plan for each step of a plan as it runs (see Live progress); a : keep-alive comment every 15 s |
Status codes: 401 missing or wrong token, 403 wrong Host, 404 unknown id, 409 invalid state
transition (e.g. applying an applied suggestion, one that is moving, or starting a second backlog
pass), 400 validation errors (unknown category, missing file, a folder outside the allowed places).
Both keys are written to their own file under $DOCULENS_HOME with mode 0600, never to
config.toml (which people paste into issues and screenshots), and neither is returned by any
endpoint: the app learns only whether one is set, from GET /api/providers. The matching
environment variable wins over the stored key, so a terminal run can use another account without
touching what the app saved.
| Provider | File | Environment, checked first |
|---|---|---|
openai |
$DOCULENS_HOME/openai-key |
DOCULENS_OPENAI_API_KEY, then OPENAI_API_KEY |
claude-api |
$DOCULENS_HOME/claude-key |
ANTHROPIC_API_KEY |
One file per provider is a known limit, not a design to extend. It works at two and stops paying
at the third, or at the first provider that wants OAuth rather than a static key, because a
refresh token, an expiry and a token type do not fit in a file whose whole content is the
secret. The shape to move to then is a single auth.json keyed by provider — {providerID: {type: "api", key}}, with other types for OAuth — as opencode does. It is not worth the
migration while openai-key is the only file already shipped.
GET /api/suggestions answers with one page, and with the two things a page needs to be honest
about itself:
totalis how many suggestions match thestatusfilter — all of them, not the ones on this page. This is the number to put beside "Filed" in the sidebar. With nostatus, it is every suggestion in the store.nextis the id to send back asbeforeto get the page after this one, ornullwhen this was the last page.
GET /api/suggestions?status=applied&status=undone&limit=100
-> {"items": [...100...], "total": 1284, "next": 1185}
GET /api/suggestions?status=applied&status=undone&limit=100&before=1185
-> {"items": [...100...], "total": 1284, "next": 1084}
...
-> {"items": [...14...], "total": 1284, "next": null}
before is a cursor, not an offset: it means "rows older than this id". That is what makes a
deep page cost the same as the first one — at 200,000 rows, LIMIT 50 OFFSET 100000 measured
400 ms against 0.3 ms for id < cursor — and it is also what makes scrolling stable while the
watcher is inserting new rows above the page. With an offset, a file arriving mid-scroll pushes
everything down and the next page repeats a row the reader has already seen.
Rows always come back newest first (descending id), whether or not a status filter is given, so
one cursor walks the whole list. before must be an id a previous page ended on; before=0 or a
negative one is 400.
Nothing about an old call changes. A request without before gets the newest limit rows
under the same items key, in the same order, as it always did — total and next are simply
there as well. limit is capped at 5000; a larger one is clamped, not refused. Raising limit
was never the fix in any case: it only moves where the list stops.
GET /api/counts is how the sidebar says 1,284 rather than 500. It returns counts over the whole
store, not over whatever page the app happens to have loaded:
{
"pending": 12, "applied": 1284, "rejected": 40, "undone": 3, "error": 1, // per status
"total": 1340, // every suggestion, whatever its status
"filed_today": 7, // applied since local midnight
"folders": {"Grants": 210, "Receipts & Invoices": 88} // filed into each category, all time
}folders counts applied rows only, and a category nobody has filed into is simply absent
(read it as 0). Like the lists, this sweeps for files that have gone missing first, so pending
never counts a file somebody moved in Finder.
Counts only. No filename, no path, and nothing read out of a document.
A count is one pass over an index — around 20 ms at 200,000 suggestions, under 1 ms at the size a
real store reaches — so call it on a refresh and after a burst of changes, not once per
/api/events message. The events themselves carry enough to keep a number moving between
calls: a suggestion changing status is ±1 on two of them.
POST /api/discover-folders powers onboarding: instead of only offering generic templates, DocuLens
looks at the folders the user already keeps and proposes categories pointed at those real folders.
It walks ~/Documents (and ~/Desktop, but only when that has subfolders) two levels deep and collects
folder names, relative paths and counts only. No file is ever opened. Hidden folders, ~/Library,
macOS packages (.app, .photoslibrary, …), node_modules and directory trees with no files anywhere
beneath them are skipped; a folder with thousands of entries is noted but not looked into. At most 60
folders are described to the model, which proposes at most 8 categories, most useful first.
scanned is how many folders were looked at. reason is empty when there are proposals, and otherwise
says in plain language why there are none ("No folders with documents in them were found…", the
model's own reason, or the error it failed with). A model that fails or answers with nonsense gives
200 with an empty list and a reason, not an error.
The endpoint saves nothing. The app shows the proposals, the user accepts the ones they want, and
PUT /api/categories writes them; each returned category is already in that endpoint's shape (with
auto: false and color: ""). Roots passed in the body, and the folder of every proposal, must pass
the same rules as any other destination — inside the home folder, not ~/Library or a hidden folder,
no .. — so a bad root is 400 and a proposal pointing anywhere else is dropped.
Names only ("propose": false). Setup's last screen has to appear at once, so this mode is the
walk alone — no model is asked and it answers in about as long as the walk takes. Each row in
folders is one top-level folder under a root:
{"name": "GATE", "label": "Downloads/GATE", "path": "/Users/me/Downloads/GATE", "root": "Downloads",
"files": 15, "subfolders": [{"name": "Syllabus", "files": 6}, {"name": "Past papers", "files": 9}],
"extensions": ["pdf", "png"], "filing": true, "written_by": ""}files counts the folder and the subfolders listed (what the adopt pass will read). filing says
whether it looks like a folder somebody files into, so setup can tick it for them; it is false for a
pile by its name (Screenshots, old stuff, untitled folder 2 — generic words, never a site or app),
a folder too crowded to have been looked into, one with fewer than 2 files, and a software project
(every common extension is source code). It is a default the user flips with one click, not a verdict.
written_by is why an app rather than the person fills the folder (discover.written_by_app: a
numbered series, one batch, or named after an app installed on this Mac, each only when few of its
files carry a where-from), or ""; such a folder is never filing, and "propose": true never
proposes it. A folder with no file anywhere beneath it is not listed at all.
places is [{"path", "files"}] for ~/Downloads, ~/Desktop and each watched folder that exists:
how many files sit directly in each, for the "what should DocuLens watch?" screen. The app then asks
for the model's descriptions with an ordinary "propose": true call in the background.
A rule is the user's own decision, written down. It is checked before the classifier, and a
match settles the filing completely: nothing is read, no model is called, and the suggestion's
reasoning says which rule decided it (Rule: from a-site.test). Rules are tried in list order
and the first match wins. Every condition in when must hold, and a rule with no condition at all
is refused — it would catch every file.
auto defaults to true, and a rule's auto does not go through auto_move_threshold: that
threshold is about how far to trust the model, and a rule is already the user's answer. The
suggestion is recorded either way, so Undo works exactly as it does for anything else.
then.folder may be one of the user's categories, by its exact name, or a folder path. A path is
taken under library_root unless it is absolute, and it must pass the same check as every other
destination: inside the home folder, not ~/Library, not hidden, no ... then.rename is
optional; without it the file keeps the name it was downloaded with, even when the global
rename setting is on, because a rule should not rename anything it was not asked to. The
template may use {name} (the name with any version hint stripped), {date} (the file's own
date), {version} and {source} (the domain it came from), and nothing else.
versions groups files that are the same thing: "keep together" spells versions of one base
name the way the destination folder already spells it, so they sort together, and
"move older to Versions" also moves the superseded ones into a Versions subfolder beside the
current one. Nothing is ever deleted.
Matching uses facts DocuLens reads off the file before it reads anything in it: the filename and
extension, the size, the version hint in the name, image dimensions, PDF page count, and — the one
that makes from exact — the com.apple.metadata:kMDItemWhereFroms extended attribute macOS
writes on every download. A fact it can't read (a file with no where-from, or image dimensions
without the optional ocr extra, which brings Pillow) simply never matches a condition about it.
kind matches by extension: image, video, audio, archive, document, spreadsheet or
slides. It is one condition instead of eleven extension entries, and it is what "my photos go
into Photos" becomes. It is a fact about the file, not a guess about meaning — a .mov is a video
the way a .pdf is a document — and where any kind goes is still entirely the user's.
DocuLens knows nothing about any particular website. from is a domain string like any other
value the user types; there is no list of sites anywhere in the engine.
GET /api/nothing-to-read groups everything still waiting that the no-text rung answered —
files with no words inside for anything to work from. On a real 513-file Downloads folder that
was 287 files: photos, clips, voice notes and archives.
Left as rows they are 287 identical decisions. Grouped they are three, and each answer is one
kind rule, so nothing of that kind reaches that rung again. The app writes the rule and then
offers, separately, to file the ids already waiting; both go through the ordinary
PUT /api/rules and POST /api/suggestions/{id}/apply, so every move undoes like any other.
A kind is only offered once there are 3 or more of it: a rule is permanent and applies to
everything of that kind forever, and offering to write one off a single file is the kind of offer
that teaches people to ignore offers. waiting still counts every one of them, so the app can say
what the rest are rather than letting two numbers quietly disagree.
Kinds with nothing sensible to say about them (an extension DocuLens has no name for) are left out rather than grouped as "other".
GET /api/catch-up/survey looks at the whole folder before the catch-up pass reads a single
file in it. It walks the loose pile and the folders beside it (scandir, stat and one batched
xattr — no file is opened), then groups the pile by what costs nothing to know: the site the
browser recorded, what kind of thing each file is, and the shape of its name. On the 513-file
Downloads folder it was measured against, that is 0.18 s and turns 513 Inbox rows into 35
decisions. docs/catch-up.md is the design, and every number in it came out of this code.
Three things in the answer are not decoration and the app may not drop them:
matchesis notsite.siteis the page the browser was on — canva.com — andmatchesis what a rule would have to put infrom, which is the host the bytes came from.labelshows both when they differ: "higgsfield.ai (via d8j0ntlcm91z4.cloudfront.net)".rulable: falsemeans no standing rule, ever, andbatch_reasonsays why in the engine's own words. Two ways to fail it, both measured. The host a rule would name is not the site or below it, so the rule promises far more than the group shows — three car logos arriving throughs3-eu-west-1.amazonaws.comwould file an entire AWS region into Car Logos. Or the rule, run back over the pile, catches files from another group: a Google search and a Drive share both download throughdrive.usercontent.google.com, sofrom = google.comis a correct generalisation of one group and quietly swallows the other (overlap). Such a group may still be placed as a one-off batch; it may not ask for anything permanent.tailandhomelessare the half that does not group, and they are in the same answer for that reason: files from sites with fewer thanmin_fileseach, and files that record no site at all and share no name pattern. On the measured folder that is 235 of 513 files. A screen that shows onlygroupsis telling somebody their folder is handled when nearly half of it is untouched.
worth_showing is the gate, and the app draws nothing when it is false. This pays when a
pile collapses into decisions — 513 files into 34 of them — and costs when it does not: thirty
files with no site appearing three times give two offers, twenty-six leftovers and a summary
longer than the list it summarises, which is worse than thirty rows in the Inbox. It is worse
again for somebody who has just installed DocuLens, who has no folders of their own to judge
"canva.com → Canva (new)" against. Three numbers decide it (survey.MIN_GROUPS, MIN_COVERED,
MIN_PER_DECISION), all from the free half of the survey, so the model call is never spent
finding out that there was nothing to ask about. Below the bar there is no empty state and no
card: the catch-up pass fills the Inbox exactly as it did before.
checks runs each proposed rule back over every surveyed file and reports what it really catches
(over_count is files it would catch that are not in its own group). Written naively this
feature fails confidently: 16 of the first 35 rules proposed did not catch the files they were
proposed from.
POST /api/catch-up/survey/propose is the one model call: the groups above, the user's own
folder names, and "name these, and say which of their folders each belongs in — or say skip".
It is told counts, folder names, domains and filenames, and nothing out of any file. What comes
back is a proposal: the same prompt over the same folder placed 20 groups on one run and 21
on the next, so the app must not present it with the confidence of a computed result.
POST /api/catch-up/place is what accepting a group does to the files already sitting there.
Each one becomes an ordinary pending row with its folder filled in — nothing is read, no model is
called, and nothing moves until the user files it through the ordinary apply path. A standing
rule is the separate half, saved through PUT /api/rules: a rule is advance approval for what
arrives next and is not consent to move the files that are already there.
GET /api/rules/suggested looks at what the user has already filed and offers a rule where the
evidence is real: at least 3 files shared one signal — the same where-from site, the same word in
the name, or the same extension — and none went anywhere else. A single counter-example is
enough to offer nothing, because a rule the user then has to correct is worse than no rule. Each
item carries the evidence (count, examples, signal) and a sentence to show: "The last 4
files from a-site.test all went to Video → Exports. File them there automatically from now on?"
Two things it never offers. A size band is not one of the signals: it is a log₂ bucket DocuLens chose for its own bookkeeping, and "zip files between 4 and 8 MB" is not a rule anyone could agree or disagree with. And it only ever reads filings the user decided — never a file one of their own rules filed, which would be the app offering to write down a rule it wrote itself. Nothing an existing rule already covers is offered either, in either direction: a rule for a site covers one for a subdomain of it, so the pair never gets made.
POST /api/chat does the same job from the other end: the user says what they want in
their own words and the model writes the rule. It is given the user's categories and folders and
the domains their recent downloads actually came from, and nothing else — so it proposes matches
that exist rather than guessing what a site is for. If the message doesn't say where the files
should go, it returns a question and no rules.
Answering that question is another POST to the same endpoint. The engine keeps the
conversation (see The conversation), so the app sends only the new message;
the turns before it are read from the store. Only the last 12 turns are replayed, each trimmed to
500 characters, so a long conversation cannot grow the prompt without bound. history is still
accepted from an app that keeps the conversation itself, and read only when the stored
conversation has nothing before this message. A model that fails or answers with nonsense gives 200 with an
empty list and a question, not an error.
All three of these propose. Only PUT /api/rules saves.
The same endpoint also answers with folders, which are proposed changes to the user's folder
list rather than to their rules. Each one is:
{
"action": "add" | "edit" | "remove",
"name": "Health", // the folder as it is named today
"category": Category | null, // the folder as it would be after; null for a remove
"changed": ["description"], // which fields an edit would really change
"summary": "Health: change what it holds to “…”", // the engine's own sentence
"note": "Nothing moves. …", // what happens to files already filed there
"existing": {"label": "Downloads/GATE", "folder": "~/Downloads/GATE", "files": 12} | null,
"rules": [{"position": 2, "summary": "When a file …"}] // remove: the rules that go with it;
// rename: the rules that follow the new name; else []
}existing is set when an add adopts a folder already on disk rather than creating a new one:
the model answers with the label of a folder listed to it this turn (the schema offers no other),
and the engine resolves it to that folder's absolute path in category.folder. An add whose name
is exactly one unlisted folder's name, ignoring case, is pointed at that folder too. An adopted
folder passes the same destination check as every other folder, and one that is already another
category's folder is refused, naming that category. Nothing on disk is moved, renamed or created;
the app follows the save with POST /api/precedent/adopt, which reads the names already in it.
Accepting one is an ordinary PUT /api/categories with the list it implies: append category
for an add, replace the folder of that name for an edit (sending "was": name when it renames),
drop that name for a remove — with "rules_of_removed": "remove" when rules is not empty,
since the card has said they go too. Or POST /api/plan, which does exactly that. There is no
folder endpoint the chat can reach.
Removing a folder never touches a file — it comes out of DocuLens's list and everything
already filed into it stays where it is, which note says with the count before the button is
pressed. An edit never changes a folder's place on disk either: category.folder is always
the path the folder already has, so a rename from the chat renames what DocuLens calls it and
moves nothing. Pointing a folder somewhere else is the folder editor's job.
A proposal naming a folder that does not exist, clashing with a name already used, taking the
last folder away, or changing nothing at all is dropped, and the reason comes back as the
question. So is a proposed folder that could claim the same document as another one — see
docs/chat.md, where that rule and the
measurement behind it are written down.
The chat used to be told the user's category names and the domains of their recent downloads, and nothing else, so it could not answer the first question anyone asks after writing a rule — "can you do that for existing ones?" Ten read-only lookups give it the answer. They are local, they return names, counts and folders, and no lookup ever returns a file's text or anything extracted from inside one; a filename is already on screen in the Inbox, and the inside of a document is not.
| Lookup | Args | Returns |
|---|---|---|
waiting |
limit (≤50) |
the files waiting now: filename, extension, source domain, size, when it arrived, the folder currently suggested |
matches |
rule |
the same dry run as POST /api/rules/test: how many recent files a rule would catch, and which |
rules |
– | the rules that exist, with the engine's own summary and each one's position |
folders |
– | category names, home-relative folders, and how many files went into each in the last 90 days |
filed |
folder, limit (≤50) |
the names recently filed into one folder, newest first |
domains |
limit (≤20) |
the domains recent downloads came from, with counts |
unplaced |
limit (≤50) |
waiting files that fitted no folder, by kind and by site |
corrections |
limit (≤50) |
where the user overruled DocuLens: proposed folder, chosen folder, how often |
on_disk |
name (optional) |
folders on disk and which are already categories; with a name, that folder's subfolders (two levels, with file counts), its newest 15 filenames and its extension mix — names only |
downloads |
– | what sits in the first watched folder now, including files DocuLens has not processed: how many files, the sites the browser recorded, what kinds of file and the folders beside them (folders.downloads_summary). Counts only, never a filename |
This is not four native tool APIs. The response schema every provider is already given becomes a
union: a tool name in call means "not yet, look this up first", and an empty one means the
answer is the answer. The engine runs the loop, and a model too weak to use tools never emits a
call and behaves exactly as the chat did before — same rules, same questions, one round trip.
The lookups are offered to claude-api, claude-code, codex and openai; ollama gets the
plain prompt until a local model is measured (chat_tools.TOOL_PROVIDERS).
Four guards bound a turn, because a 3B model asked to use tools will loop: four lookups, after which the fifth request is refused and the schema stops offering the branch; an invented tool name comes back as an error listing the real ones instead of failing the turn; a repeated identical call returns the same payload with "You already asked that", costs a lookup, and the third one ends the loop; and a 60-second wall clock over the whole turn, after which the answer is "That took too long — try saying it more directly." Every result is cut to 50 items and 4000 characters before it goes into the prompt.
lookups is what was actually looked up and looked_at is the one-line version of it
("5 files waiting, your 1 rule"), for the collapsed line the app shows above the answer. Both
are empty when the model asked for nothing.
The chat is kept by the engine, in doculens.db, so leaving the screen or quitting loses nothing.
Every POST /api/chat stores the message and the answer in the current conversation (the
newest one; there is always one). POST /api/chat/new starts another, and the one before is
kept — the newest 20 conversations are, and the 21st goes.
// ChatMessage
{
"id": 42,
"conversation": 3,
"role": "doculens", // "you" | "doculens"
"text": "When a file ends in .zip → file it into Zips automatically.",
"payload": { // for a line the user typed: {} or {"context": ChatContext}, as sent
"rules": [Rule], "folders": [FolderChange], "question": "", "say": "", "apply_to_existing": true,
"looked_at": "5 files waiting", "lookups": [{"tool", "args", "summary"}],
"states": States,
"plan_run": {"plan": 7, "ok": true, "cancelled": false, "error": "", "filed": 3, "steps": [Step]}
},
"created_at": "2026-09-25T10:00:00+00:00"
}
// States: what the user did with each proposal in that answer
{"rules": ["added"], "folders": ["proposed", "declined"], "apply": "done", "plan": ""}An answer's text is its question, or the engine's own sentences for what it proposed joined
with "; ". A line the user typed keeps the context it was sent with, exactly as sent, so the
app can send the same message again about the same thing ("Ask again properly"); it is absent
when none was sent. An answer's payload is the whole POST /api/chat answer as it was shown, plus states: one
entry per rule and per folder change, starting at proposed; apply is proposed when the
answer offered to file what is waiting and "" otherwise; plan is "" until
POST /api/plan runs one (One plan, one approval). The app sets them
with POST /api/chat/messages/{id}/state when a button is pressed. A stored payload may also carry
dropped: the engine's reasons for what it refused, in the words written for the model, which
are replayed to it on the next turn and never sent in the POST /api/chat answer; the app can
ignore it. plan_run is absent until a
plan carries the answer out, and then says which plan it was and how it ended, so a conversation
reopened later can say what was done and still undo it.
A conversation carries on where it was left: POST /api/chat with an older conversation adds
to that one, and it stays where it is in the list rather than becoming the current one.
The model is told the stored turns, not the app's: each earlier line as it was said, and for an answer, the sentence of each proposal and what became of it — "Proposed: When a file ends in .zip → file it into Zips automatically. (added)" — so it never proposes again what was just declined without knowing.
What is stored is what was on screen: what the person typed, the engine's sentences, folder names, rule summaries and the "Looked at" line. Nothing read out of a file.
POST /api/chat may carry context, what the app has on screen as the message is sent:
{"view": "inbox", // inbox | today | filed | left | folder | catchup | rules | settings | quick
"folder": "GATE", // with view "folder"
"filter": "syllabus", // the text filter typed over a list, if any
"chip": "School", // the group chip chosen, if any
"selected": [12, 13], // suggestion ids selected there
"opened": 12} // the one row opened, if anyIt becomes one short block in the per-message half of the prompt — never the cached half, which
must stay byte-identical from one message to the next — so "this", "these" and "here" resolve:
"In the app: the Inbox. The file selected: file 12: gate_syllabus_CS.pdf -- waiting in the
Inbox, DocuLens suggests GATE." Only the ids are trusted: every name comes out of the store,
an unknown id is dropped, and a file is named by its filename and where it stands, never by its
title or DocuLens's reasoning, which are written from what is inside it. quick is the ⌥Space
window, over another app: the model is told DocuLens is not on screen.
When a file on screen can be filed (waiting, unread, or put back), the answer may propose filing it — and only it — into one of their folders: the schema offers those ids and their folder names and nothing else.
// FileProposal
{"suggestion": 12, "filename": "gate_syllabus_CS.pdf", "folder": "GATE",
"source_path": "/Users/me/Downloads/gate_syllabus_CS.pdf",
"summary": "File gate_syllabus_CS.pdf into GATE"}It is a proposal like the rest: nothing moves until the user's "Do it" sends it back as a move
step of POST /api/plan. states.files follows it the way states.rules follows a rule.
A chat answer can carry folder changes, rules and apply_to_existing at once. POST /api/plan
carries all of it out with one approval, and POST /api/plan/{id}/undo takes all of it back.
Nothing here is a new way to change anything: every step runs through the same check it would
pass alone.
Order. Always folders, then rules, then the files the answer named, then filing what the rules catch, whatever order the body lists them in — a rule may name a folder the same plan adds, and filing needs the rule.
| Step | What runs | The same path as |
|---|---|---|
folder |
the change is judged by folders.parse_change against the folders as they are now, then the whole list is saved. An add carrying an absolute category.folder (a folder adopted from disk) keeps it, may not be another folder's place, and passes the destination check; with "Learn from what I file" on, its names are then read into the tally as POST /api/precedent/adopt would |
PUT /api/categories |
rule |
parsed and folder-checked, then appended to the rule list. A rule already in the list is not added twice (what ends "(already there)") |
PUT /api/rules |
move |
each of files: that file, filed into the folder the answer named, as if chosen by hand (a folder other than the suggested one is a correction). index is its place in files |
POST /api/suggestions/{id}/apply with category |
file |
with file_waiting, the plan's rules are dry-run over the newest 200 files still waiting, and each match is filed with no category, so the rule decides |
POST /api/rules/test + POST /api/suggestions/{id}/apply |
folders takes the FolderChange objects POST /api/chat returned (action, name,
category); rules takes its Rules (summary and covered_by are ignored). Either may carry
index, its position in the answer's own list, when the user left some of the answer out; the
answer's states are marked by it. Without it the position in the body is taken to be the same.
// Step
{"step": "folder" | "rule" | "move" | "file",
"index": 0, // position in body.folders / body.rules; for "file", the suggestion id
"ok": true,
"what": "Add a folder called Zips, for “Archives and zip downloads.”", // the engine's sentence
"error": "", // why, when ok is false
"suggestion": 12, "source_path": "/Users/me/Downloads/bundle.zip",
"destination_path": "/Users/me/Documents/DocuLens/Zips/bundle.zip"} // "file" onlyA failing step stops the plan. ok is false, the last step says why in error, and every
step before it stays done — and undoable with the same plan id. Nothing after it runs.
So does Stop. POST /api/plan/{id}/cancel is checked before every step, never during one: a
step is one save or one move, and half of either is worse than finishing it. The answer has
ok: false, cancelled: true and an error saying it was stopped; no step failed, so none has
ok: false. Undo works exactly as after a failure.
Undo takes back exactly what the plan did, and nothing the user did since.
- Every file the plan filed goes back through
POST /api/suggestions/{id}/undo's path, newest first — but only if it is still filed where the plan put it. One the user undid, re-filed or moved since stays where it is, andkeptsays so. - If
config.tomlis exactly as the plan left it, it is restored byte for byte to what it was before the plan. - Otherwise each step is taken back only if what it left is still there unchanged: a folder the
plan added is removed, an edited one gets its old name and description back, a removed one is
put back at its old place, a rule the plan added is removed. Anything changed since stays and
is named in
kept. - A folder the plan removed or renamed gets back what DocuLens had learned about it (its tally rows are kept with the plan for this).
When message_id names a stored chat answer, its states follow: each rule and folder that ran
becomes added, plan becomes done (and apply too, when file_waiting ran), and after an
undo plan is undone. Its payload gains plan_run — the plan's id, ok, cancelled, error,
filed and every step — whether it finished, failed or was stopped.
A chat turn can make four lookups and a plan can file a hundred files, so both say what they are
doing while they do it, on the same /api/events stream as suggestions. The request carries a
turn the app chooses (any string up to 100 characters) and every event it causes carries it
back, so the app can match an event to the request still waiting for its answer. A chat turn
sent without one gets one made up, returned in the answer.
event: chat
data: {"turn": "c-17", "tool": "waiting", "args": {"limit": 20}, "summary": "5 files waiting"}
event: plan
data: {"turn": "p-3", "plan": 7, "step": Step}
event: chat-text
data: {"turn": "c-17", "field": "say", "text": "You already keep a Renders"}
event: chat
data: {"turn": "c-17", "cancelled": true}
event: plan
data: {"turn": "p-3", "plan": 7, "cancelled": true}
chatis sent once per lookup, the moment it has run and before the model is asked again. It is exactly one entry of the answer'slookups— a tool name and the "Looked at" sentence, never a lookup's result. Setup's "Look in Downloads first" sends one withtool: "downloads"first. A lookup that failed or was refused sends nothing, as it adds nothing tolooked_at.chat-textis the reply as it is written, from a provider that can stream (todayclaude-code; the others send none, and the app shows its working line until the answer).fieldissayorquestionandtextis the whole of it so far, not a piece, so a missed event loses nothing; an unchanged text is not sent twice. Only ever that sentence: rules, folders, files and plans arrive with the answer, once the engine has checked them. A pass that turns out to be a lookup is followed bytext: ""for both fields, and the app also clears on eachchatevent. The answer'ssay/questionalways win: the engine may replace what the model wrote (its reasons for leaving a proposal out), so the app replaces the streamed text with the stored answer, never merges them.planis sent once per step, as it finishes, including the step that failed. The answer toPOST /api/planstill carries every step; the events are only there to show them sooner.- A stop is sent the moment it is asked for, as either event with
cancelled: trueand notoolorstep, so every window showing that turn or plan can stop showing it as working.
apply_to_existing: true on a draft is the model proposing that the new rule also be applied
to the files waiting now. Filing is deliberately not one of the lookups: a model deciding on its
own to move fifteen files is exactly what this app promises never happens. There is no endpoint
for it, because it needs none — the app offers two buttons, and the first one is:
PUT /api/ruleswith the proposed rule, thenPOST /api/rules/testwith the same rule, thenPOST /api/suggestions/{suggestion}/applyfor each match, with no body.
That is the ordinary apply path, so a rule that matches decides the destination and every move is undoable exactly as one made by hand. The second button is step 1 alone.
A folder is more than a name and a place. It carries what it holds (its description), the rules
that file into it, the subfolders already in it, and what DocuLens has learned from what went
there. GET /api/smart-folder?name= returns all four; nothing in it is new state, it is the one
folder's share of what the engine already keeps.
rulesare the rules that file into this folder, in the one global order —positionis where each sits inGET /api/rules(1 is tried first).howis"name"for a rule whosethen.folderis this folder's name,"inside"for one that files by path into it or a subfolder of it (subfoldersays which,""for the folder itself). The engine still tries every rule in one flat list and the first match wins; a folder's view never reorders anything.subfoldersare the folders already inside it, two levels down, by name (namerelative to the folder,pathhome-relative) with how many files sit directly in each. Read withscandir; no file is opened, and no filename is returned.GET /api/smart-folder/recentis the folder page's "Latest": what is really in the folder, including everything an adopted folder already held, not only what DocuLens filed there. Names, subfolders and times fromscandir/stat, inside the folder only, links never followed.filesis how many files sit directly in the folder (at most 500 are counted);filedis how many DocuLens has filed into it, all time;existsis false when the folder is not on disk yet (a new folder is created by the first file filed into it).learnedis what the tally holds about it, strongest first, at most 8: only signals with something to say, each as the sentence rung 3 would use — "The last 9 files from a-site.test went to Papers."strongmeans it answers a matching file on its own,currentthat it is recent enough (180 days) to vote. Empty while "Learn from what I file" is off.
Rules belong to their folder. PUT /api/categories used to take no notice of rules, so a
renamed folder silently orphaned every rule that named it, and a removed one left rules filing
into a name that no longer existed — which then meant a folder of that name under the library
root. Now:
-
Rename. A folder whose
wasnames an existing folder, or — whenwasis absent — whosefolderis exactly the place of one folder being dropped, is a rename. Every rule whosethen.folderis the old name is rewritten to the new one in the same write as the folder list (oneconfig.tomlreplace, so both change or neither does), keeping its position. What DocuLens learned (the tally), the folder's adopt mark, past corrections and the suggestions filed into or waiting for it follow the new name too.renamedin the answer says which. -
Remove. While any rule's
then.folderis the name of a folder being removed, the save is 409 and nothing is written:{"error": "Bank & Tax still has 1 rule filing into it. Say whether they go too (rules_of_removed: \"remove\").", "rules": [{"position": 1, "folder": "Bank & Tax", "summary": "When a file …"}]}Sending the same list again with
"rules_of_removed": "remove"removes those rules with it;rules_removedlists their sentences. Any other value is 400. Files are never touched either way — see Folder changes the chat proposes. -
A rule that files by path into a folder (
~/Downloads/GATE/Syllabus) keeps working when the folder is renamed or removed, since the place on disk is unchanged; it is listed in the folder's view as"inside"and is not touched by either.
DocuLens remembers a file it has seen before, byte for byte. Precedent is what it remembers about files like that one: a tally, not a model. Files carrying this signal went to this folder, this many times, and you corrected it this often. It costs no model call, it lives in the same SQLite file as everything else, and every number in it can be shown to the user as a sentence.
It is one rung of the decision ladder POST /api/scan, the watcher and POST /api/backlog all
walk:
| # | Rung | Cost | Decides when |
|---|---|---|---|
| 1 | Rule | ~0 ms | one of the user's rules matches — they already decided this |
| 2 | Same file | ~0 ms | these exact bytes were classified before (reasoning is "Same as a file you filed before") |
| 3 | Precedent | ~0 ms | a signal on this file has a clean, strong history |
| 4 | Model | 5–10 s | everything else — and it is told what rung 3 found |
The rungs never reorder. A rule always beats precedent, because a rule is the user speaking and precedent is only DocuLens inferring from what they did.
A signal is something knowable before the file is opened, so rung 3 stays free: the site it was
downloaded from, its extension, the two together, a word of four letters or more in its name, and
its size as a log2 band (4-8MB). Nothing in the engine knows what any site or word means — a
domain counts for nothing until the user has filed things from it, exactly as with from in a
rule.
A file answered by rung 3 comes back with confidence: 0.95 and a reasoning the user can check:
"The last 9 files from a-site.test went to Papers." Never a number: the number is for the code.
When the user's own filing put files like it into one subfolder of that folder, the answer is that
subfolder: subfolder is set ("Syllabus"), destination_path is inside it, and the sentence
says "…went to GATE/Syllabus." The model's answer is always a folder's top level. See
docs/precedent.md, Subfolders.
A thinner or contradictory history is not acted on; it is added to the model's prompt as one plain
line instead ("the last 6 files from a-site.test went to Travel, 2 went to Courses"), which the
model is free to disagree with.
The tally moves in exactly two places: POST /api/suggestions/{id}/apply adds a filing (and,
when a different category is passed, a correction towards it and a move away from what was
proposed), and POST /api/suggestions/{id}/undo takes all of that back. reject writes
nothing — leaving a file in Downloads says nothing about where it belongs. Only the user's own
categories are ever tallied.
Forgetting. A row not seen for 365 days is deleted on the idle pass; a row carrying a move-away
is kept, because being told "not there" should not wear off. Deleting a category through PUT /api/categories deletes its precedent rows, and rung 3 also refuses to answer with a category
that is not in the config, so a folder the user removed can never keep voting.
The switch. learn_from_filing (Settings: "Learn from what I file", on by default) gates
every read and every write, of both the tally and the decisions record. Turned off, the engine
behaves exactly as it did before precedent existed. POST /api/precedent/forget is the "Forget
what you've learned" button beside it.
Day one. POST /api/precedent/adopt reads the names of the files already sitting in the
folders the user accepted as categories — and in their subfolders, two levels down, each counted
where it sits — and counts them as filings, so the tally is useful before
the first download arrives. It opens no file (not even for a page count), moves no file, reads at
most 500 names per folder newest first, and looks only at folders the user accepted — declining one
during onboarding means it is never read. Running it twice does not double a tally.
The backlog. POST /api/backlog is the pile that was already in Downloads. Rungs 1–3 keep most
of it off the model. It runs in the background, can be paused and is safe to quit — files it has
already suggested are not read again. It moves nothing, whatever a category's auto setting or
a matching rule says: filing two thousand files unattended on the strength of a tally seeded
minutes ago is not a risk worth taking, so the user works through the Inbox.
The idle pass. GET/POST /api/idle is one pass, run on a timer when the inbox is empty and
at most every six hours. It does the forgetting and asks three cheap questions: is there a rule
worth offering (a signal at weight 12 never corrected away), is a rule going wrong (three
corrections in its last ten matches), and has a folder gone quiet (nothing filed into it for 120
days). Everything it returns is a proposal — it never moves a file or changes a rule.
Files the user already filed are never moved. No pass of any kind reaches into their own
folders: scan and backlog refuse a path outside the watched folders, and adopt and the idle
pass have no move in them at all.
Precedent is what the user did, rules are what they decided; memories are what they said
about themselves in the chat — "I'm preparing for GATE", "name receipts by shop and date" — so
the next conversation does not start from nothing. memory.py is the design.
// Memory
{
"id": 3,
"kind": "about", // "about": a fact about them | "preference": how they like things done
"text": "Preparing for the GATE exam", // one sentence, at most 150 characters
"folder": "", // one of their folders when it is about that folder only
"until": "2027-02-15", // "about" only: when it stops being true; "" for no end
"source": "chat", // "chat": the chat wrote it | "user": they wrote or edited it
"conversation": 12, // where it was said (provenance); null for one they typed here
"created_at": "…", "updated_at": "…",
"expired": false // past its "until": kept and listed, no longer shown to the chat
}How one is made. The chat's answer may carry remember: a list of changes, each add, or
update/delete naming a memory by the short id the model is shown it by (m3). The engine
judges every change before anything is kept, and refuses:
- anything over 150 characters (dropped whole, never cut);
- anything that looks like an ID, passport, account or card number, an email address or a password;
- anything built out of what a lookup returned rather than out of the user's own words — a word that appeared in this turn's lookup results and nowhere in what they typed in this conversation, or anything shaped like a filename or a site they did not type;
- an
update/deletenaming a memory that does not exist; anaddsaying what one already says (compared ignoring case, spacing and punctuation).
It is silent: remembered in the chat answer lists what was done, and the app need not say
anything about it. A condition — "leave screenshots alone", "invoices go in Money" — is never a
memory; the model is told to propose it as a rule, which is enforced where a memory is only
context. A memory never overrides a rule: rules decide before a model is asked, exactly as
before.
Where it goes. Every current memory is in the chat's system prompt, after the folders, in id
order: one kept for a folder sits under that folder in the list, the rest under "What they have
told you before". No retrieval — at forty sentences every one is shown, the same way each time,
which keeps that half of the prompt cacheable. Memories are never sent with the filing
prompt: see docs/decisions.md, What the user tells the chat is remembered, and only the chat
hears it.
Limits. At most 40 memories and 2,000 characters. Near that (80%) the model is asked to merge
rather than add; at it, the oldest memory the chat wrote is dropped to make room. One the user
wrote or edited is never dropped: when every memory is theirs, a new one is refused (409 from
POST /api/memories).
Controls. memory in PUT /api/settings is a pause: while it is false the memories are kept
and can be listed and edited here, but the chat is neither shown them nor able to add to them.
A conversation with dont_remember still sees what is kept, and adds nothing. Every change is
kept in a history, so POST /api/memories/{id}/undo can take back the chat's change as well as the
user's. A folder's memories follow it when it is renamed and go when it is removed (an undo of a
plan that removed it brings them back). A conversation dropping out of the newest 20 does not
take its memories with it; forget-all takes everything.
Only one watcher (doculens serve or doculens watch) may run per user. A second one exits with code
3 and prints DocuLens is already running (pid N).