annals#

annals: an in-tray for AI agents. Publish documents and media to a private page; get a link.

Agents call annals.tools.publish() (or annals publish file.md from a shell) and hand the printed URL to their human, who opens it on a phone. The documents are plain files in a directory, local or on another machine over ssh; annals.api.mk_app() serves that directory as a private page with search, sort, groups and a recycle bin.

Functions

configure(*[, target, base_url, to, outbox, ...])

Write the publisher config (where to publish, what link to print) and show it.

group(title, doc_ids, *[, add_to, target, ...])

Make a group (one URL for a set of documents) from existing document ids.

groups(*[, target, base_url, to])

List groups, newest first.

load_settings(*[, target, base_url, to, ...])

Resolve settings: arguments, then to, env, the config file, then local defaults.

ls([q, trash, limit, target, base_url, to, ...])

List documents (newest first), optionally filtered by words or showing the bin.

parse_target(spec)

host:/path becomes an SshTarget; anything else a LocalTarget.

publish(paths, *[, title, tags, group, ...])

Publish one document and print its link; several paths become several documents.

restore(doc_ids, *[, target, to])

Bring documents back from the recycle bin.

show(doc_id, *[, target, base_url, to])

A document's metadata, link, the groups it is in, and the annals links in its text.

trash(doc_ids, *[, target, to])

Move documents to the recycle bin (restorable).

Classes

DocStore(target, *[, settle])

Publish, list, read, trash, restore and group documents on a Target.

LocalTarget(root)

A directory on this machine.

Settings(target, base_url[, configured, ...])

Where to publish and what link to print.

SshTarget(host, root)

host:path on another machine, via the system ssh and rsync in batch mode.

class annals.DocStore(target, *, settle=True)[source]#

Bases: object

Publish, list, read, trash, restore and group documents on a Target.

add_to_group(gid, doc_ids)[source]#

Append documents to an existing group, keeping order and skipping ones it has.

Each document must exist and not be in the bin; KeyError for a group that is not there.

Return type:

dict

doc_rel(doc_id)[source]#

The directory of a document (or of a version, <id>@<n>) under the data root.

Return type:

str

group(gid)[source]#

One group, by id.

Return type:

dict

group_docs(gid)[source]#

A group and the meta of each of its documents, in its order (missing or binned ones left out).

Return type:

tuple[dict, list[dict]]

groups_of(doc_id)[source]#

The groups a document is in, newest first, each as {"id", "title", "n"}.

Return type:

list[dict]

holds(ref_id)[source]#

Whether a document (or a version of one) or a group with this id is here, in the bin or not.

Return type:

bool

list(*, trash=False)[source]#

Every document’s meta, last changed first (updated, else created).

Pending replacements are applied first (when this store settles). One whose document is not here is listed under its own id, so it is never out of sight.

Return type:

list[dict]

list_groups()[source]#

Every group, newest first.

Return type:

list[dict]

make_group(title, doc_ids, *, gid=None, live_only=True)[source]#

Create (or overwrite) a group: a titled, ordered list of documents.

The title is cleaned (control characters dropped, whitespace collapsed, at most MAX_GROUP_TITLE long, not blank); repeats are dropped, keeping the first; each document must exist and not be in the bin unless live_only=False (a bundle that keeps a document later binned). ValueError says which rule failed. An explicit gid rewrites that group, under its lock.

Return type:

dict

meta(doc_id, *, settle=True)[source]#

One document’s meta; in_trash says which side of the bin it is on.

<id>@<n> is version n: its own meta, with version_of naming the document. A pending replacement, read by its own id, says pending. settle=False skips applying pending replacements (for a hot path such as a raw file).

Return type:

dict

pending(doc_id=None, *, names=None)[source]#

Pending replacements (directory names), oldest first; of one document if given.

names: the listing of docs/ when the caller already has it.

Return type:

list[str]

publish(*sources, title=None, tags=(), source=None, text=None, filename='document.md', exclude=('.*', '__pycache__', '*.pyc', '*.pyo'), replace=None, artifact=None, pdf=True, pdf_renderer='default')[source]#

Publish files (or a directory, or text) as ONE document; return its meta.

One markdown or html file is the common case. A directory is published whole, with index.html (or the first renderable file) as the page shown. text publishes a string as filename instead of reading sources. exclude lists glob patterns skipped inside a directory (hidden files and caches by default; () keeps all).

replace (a document id) publishes a new version of that document instead of a new document: same id, same link, the current files kept as a version. It is written as a pending replacement and applied at once when this store settles (otherwise where the store is read). The returned meta says pending until then.

artifact (a claude.ai artifact link, see check_artifact_url()) is the interactive version of the page: the document’s page links out to it. A replacement that names none keeps the document’s current one.

An html page gets its own Download PDF button, and <stem>.pdf printed beside it by pdf_renderer unless it has one (annals.pagepdf, which says how a page declares or opts out). pdf=False leaves the page as it is.

Return type:

dict

purge(doc_id)[source]#

Delete a document that is in the bin. Refuses one that is not.

Return type:

None

read_text(doc_id, rel=None)[source]#

A document’s main file (or one of its files) as text.

Return type:

str

rename(doc_id, title)[source]#

Give a document a title of the owner’s choosing; a later version keeps it.

The title is cleaned as a group’s is (clean_title()). A version or a pending replacement is refused (rename the document). Works in the bin too. Only title and renamed change in the stored meta, which is read again under the document’s lock: a document that moved meanwhile (trashed, restored, purged) is a RuntimeError, never a meta written where its files are not. Returns its meta.

Return type:

dict

rename_group(gid, title)[source]#

Give a group a new title (cleaned as at creation); its documents stay as they are.

Return type:

dict

restore(doc_id)[source]#

Move a document out of the bin (idempotent).

Return type:

dict

search(query, *, trash=False)[source]#

Case-insensitive match of every query word against title, tags, excerpt, source.

Return type:

list[dict]

settle(doc_id=None)[source]#

Apply pending replacements (of one document, or all); return the ids replaced.

A replacement whose document is not here yet (it is still on its way, or the document was purged) stays pending and is listed under its own id.

Return type:

list[str]

trash(doc_id)[source]#

Move a document into the bin (idempotent).

Return type:

dict

versions(doc_id)[source]#

Every version of a document, oldest first, the current one last.

Return type:

list[dict]

class annals.LocalTarget(root)[source]#

Bases: object

A directory on this machine.

local_path(rel)[source]#

rel under the root, resolved; None if it escapes the root (a symlink).

Return type:

Path | None

class annals.Settings(target, base_url, configured=True, outbox=False, share_base_url='', room=False)[source]#

Bases: object

Where to publish and what link to print. See the module docstring for precedence.

as_dict()[source]#

Plain dict, for the CLI and MCP surfaces.

Return type:

dict

configured: bool = True#

publishing then lands in the local data dir and the link points at a local server, which is rarely meant

Type:

False when nothing (argument, env, config file) named a target

outbox: bool = False#

the target is pulled and emptied by another machine; replacements apply there

room: bool = False#

what is written to it carries no provenance

Type:

an outside audience reads this target

share_base_url: str = ''#

where share links point (<this>/<token>/); <base_url>/shared by default

class annals.SshTarget(host, root)[source]#

Bases: object

host:path on another machine, via the system ssh and rsync in batch mode.

annals.configure(*, target=None, base_url=None, to=None, outbox=False, share_base_url=None, room=False)[source]#

Write the publisher config (where to publish, what link to print) and show it.

Example

annals configure --target tw:/root/.local/share/annals --base-url https://apps.example.com/annals. --to NAME saves the target and base url as a named target (annals publish --to NAME) and leaves the default alone. --outbox marks the target as an outbox: a directory the server pulls and empties (it cannot be written to from here), so replacements are left for the server to apply; it is kept by later changes (ANNALS_OUTBOX=0 or an edit of the file turns it off). --share-base-url is where share links point when the share server is not at <base-url>/shared (a platform running it as its own public app). --room marks a target an outside audience reads (a client’s room): what is published or copied to it carries no provenance; kept by later changes, like --outbox. With no arguments, shows the resolved settings without writing.

Return type:

dict

annals.group(title, doc_ids, *, add_to=None, target=None, base_url=None, to=None)[source]#

Make a group (one URL for a set of documents) from existing document ids.

With add_to (a group id) the documents are added to that group instead, and title is ignored. The documents must exist and not be in the bin; the title is cleaned (see annals.store.clean_title()).

Return type:

dict

annals.groups(*, target=None, base_url=None, to=None)[source]#

List groups, newest first.

Return type:

dict

annals.load_settings(*, target=None, base_url=None, to=None, outbox=None, share_base_url=None, room=None, config_path=None)[source]#

Resolve settings: arguments, then to, env, the config file, then local defaults.

to names a [targets.NAME] table of the config file; it replaces the environment and the file’s default target for this call (explicit arguments still win).

Return type:

Settings

annals.ls(q='', *, trash=False, limit=50, target=None, base_url=None, to=None, since=None, session=None, tag=None, meta=None)[source]#

List documents (newest first), optionally filtered by words or showing the bin.

to lists a named target instead of the default one. The rest are exact filters, all of which must hold, for tools that poll: since (an ISO date or time, or an age like 6h or 2d: published or replaced at or after it), session (the publishing session’s name, whole, case-sensitive), tag (one tag, whole: the owner’s own tags, set by annals tag, win over the publisher’s) and meta (key=value, several allowed, against the document’s source: corpus=annals). A row is {id, title, kind, tags, created, updated, source, url}; with --json that is the contract (misc/docs/design.md), and total counts the matches before limit.

Return type:

dict

annals.parse_target(spec)[source]#

host:/path becomes an SshTarget; anything else a LocalTarget.

Return type:

Target

annals.publish(paths, *, title=None, tags='', group=None, add_to=None, session=None, session_url=None, all_files=False, target=None, base_url=None, to=None, replace=None, artifact=None, no_link_check=False, no_pdf=False, meta=None)[source]#

Publish one document and print its link; several paths become several documents.

An audio or video file takes its timed text along as one document: talk.mp3 talk.vtt talk.chapters.vtt (or talk.cues.json) is one audio document whose page shows the transcript and chapters (annals.store.SIDECAR_SUFFIXES).

paths: files of any kind (markdown, html, images, video, audio, pdf, text), a directory (one document: an index.html or single page with its assets, else a gallery of everything in it), or - for stdin (markdown). tags is comma separated. group names a group to create from the published documents; the reply then carries group_url too. add_to appends them to an existing group instead (its id, as printed in a group link), so a second batch lands under the link the owner already has. session records who published (the source shown on the page), and session_url the claude.ai link that opens that session; by default the link of the Claude Code session this runs in (CLAUDE_CODE_BRIDGE_SESSION_ID), none for no link. The document’s page shows each session that made it, linked, under its title; a share or a room never does (annals.sessions). A directory skips hidden files and caches (.*, __pycache__, *.pyc) unless all_files. to publishes to a named target of the config file ([targets.NAME], see annals configure --to) instead of the default one. replace (a document’s link or id) publishes ONE path as a new version of that document: the link stays the same, the page shows the new version and offers the earlier ones. That is how a living page (a guide, a status page) keeps one link. artifact (a claude.ai artifact link) is the interactive version of the page: the document’s page shows an “Open the interactive version” button. Publish the Artifact first, then the same page here with its link. A markdown or text document that mentions an issue or a Slack/email/chat message without linking to it gets a warning on stderr (annals.linkcheck); it is published either way. no_link_check turns that check off.

An html page gets its own Download PDF button, inside the page, so it survives “open full page”, raw links and shares, and <stem>.pdf printed beside it (headless Chromium, the pdf extra; without it the button opens the print dialog). A page that already has its PDF says so with <link rel="alternate" type="application/pdf" href="...">; one with its own button marks it data-annals-pdf; no_pdf (or data-annals-pdf="off" on <html>/<body>) leaves the page as it is (annals.pagepdf).

meta (--meta key=value [key=value ...]) records what the document belongs to, next to host, cwd and session in its source: by convention corpus (the repository or body of work), repo, issue (the issue it answers), item (a desk item) and kind (report, brief, overview, render); other keys are kept as given. ls --session/--meta finds them again. The CLI’s --json prints the result below (id, title, url, and with a group group_id and group_url; several paths give docs) as JSON and nothing else on stdout; that shape is a contract (misc/docs/design.md).

Return type:

dict

annals.restore(doc_ids, *, target=None, to=None)[source]#

Bring documents back from the recycle bin.

Return type:

dict

annals.show(doc_id, *, target=None, base_url=None, to=None)[source]#

A document’s metadata, link, the groups it is in, and the annals links in its text.

doc_id may be the document’s link, on any annals this machine is configured for: the link finds its own place (to names one explicitly). A group’s link gives the group and its documents’ links. links are the links to other annals documents and groups found in the document’s text files, on any annals this machine can read: follow them with annals show or annals aggregate. To read the text, use annals aggregate <link>.

Return type:

dict

annals.trash(doc_ids, *, target=None, to=None)[source]#

Move documents to the recycle bin (restorable).

Return type:

dict

Modules

aggregate

Many markdown files as ONE markdown document: a title, a table of contents, a section per file.

auth

The auth seam: who may read the annals.

catalog

The catalog: every source's items as one list, with search and the owner's tags.

combine

Many files of many kinds as ONE document: a Markdown, html or PDF file.

config

Settings: where documents are published and what link to print.

docfilter

Exact filters over a document's meta, for a caller that polls: since, session, tag, source.

jsonstore

A MutableMapping kept in one JSON file, safe with several server processes.

linkcheck

Find what a document mentions without linking to it: the owner reads on a phone and clicks through.

listening

What each reader has heard of each audio document: percent heard, listens, where they stopped.

mcp

MCP surface: the same operations as the CLI, from annals.tools, via py2mcp.

media

The media relay for published html pages: what a framed page plays, told to the page around it.

notebook

A share's documents as separate notebook sources: one plain web page per text file.

overview

Spoken overviews of a document: the request a page makes, and the worker that fulfils it.

pagepdf

Every published html page carries its own Download PDF button, and the PDF beside it.

records

The published documents as records for a retrieval index, so an agent can find one by meaning.

references

The references of documents, extracted and combined, in three forms.

render

Render markdown (and other page-like files) to html and PDF, with their images inside.

requirements

Optional dependencies, checked where they are needed and explained when they are missing.

sessions

The sessions that made a document: each one's name and the link that opens it.

share

Share links: one document (or a group) behind a public, unguessable, revocable link.

share_page

A share link's page with its text in it, and no script, so every reader can read it.

sources

Item sources: everything the page lists, wherever it lives, as rows of one shape.

store

The document store: a flat set of documents, tags, groups and a recycle bin, as plain files.

tables

Scrolling, zooming tables for published html pages.

tags

The owner's tags: a MutableMapping from item key to tag list, kept apart from the items.

target

The transport seam: a document tree lands in a directory, here or on another machine.

titles

A title for a file whose name says nothing: overview.mp3, output.html, index.md.

tools

The operations, as plain functions: JSON-able arguments in, JSON-able dicts out.