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
|
Write the publisher config (where to publish, what link to print) and show it. |
|
Make a group (one URL for a set of documents) from existing document ids. |
|
List groups, newest first. |
|
Resolve settings: arguments, then |
|
List documents (newest first), optionally filtered by words or showing the bin. |
|
|
|
Publish one document and print its link; several paths become several documents. |
|
Bring documents back from the recycle bin. |
|
A document's metadata, link, the groups it is in, and the annals links in its text. |
|
Move documents to the recycle bin (restorable). |
Classes
|
Publish, list, read, trash, restore and group documents on a |
|
A directory on this machine. |
|
Where to publish and what link to print. |
|
|
- class annals.DocStore(target, *, settle=True)[source]#
Bases:
objectPublish, 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;
KeyErrorfor a group that is not there.- Return type:
- doc_rel(doc_id)[source]#
The directory of a document (or of a version,
<id>@<n>) under the data root.- Return type:
- group_docs(gid)[source]#
A group and the meta of each of its documents, in its order (missing or binned ones left out).
- 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:
- list(*, trash=False)[source]#
Every document’s meta, last changed first (
updated, elsecreated).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.
- 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_TITLElong, not blank); repeats are dropped, keeping the first; each document must exist and not be in the bin unlesslive_only=False(a bundle that keeps a document later binned).ValueErrorsays which rule failed. An explicitgidrewrites that group, under its lock.- Return type:
- meta(doc_id, *, settle=True)[source]#
One document’s meta;
in_trashsays which side of the bin it is on.<id>@<n>is versionn: its own meta, withversion_ofnaming the document. A pending replacement, read by its own id, sayspending.settle=Falseskips applying pending replacements (for a hot path such as a raw file).- Return type:
- pending(doc_id=None, *, names=None)[source]#
Pending replacements (directory names), oldest first; of one document if given.
names: the listing ofdocs/when the caller already has it.
- 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.textpublishes a string asfilenameinstead of reading sources.excludelists 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 sayspendinguntil then.artifact(a claude.ai artifact link, seecheck_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>.pdfprinted beside it bypdf_rendererunless it has one (annals.pagepdf, which says how a page declares or opts out).pdf=Falseleaves the page as it is.- Return type:
- read_text(doc_id, rel=None)[source]#
A document’s main file (or one of its files) as text.
- Return type:
- 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. Onlytitleandrenamedchange in the stored meta, which is read again under the document’s lock: a document that moved meanwhile (trashed, restored, purged) is aRuntimeError, never a meta written where its files are not. Returns its meta.- Return type:
- rename_group(gid, title)[source]#
Give a group a new title (cleaned as at creation); its documents stay as they are.
- Return type:
- search(query, *, trash=False)[source]#
Case-insensitive match of every query word against title, tags, excerpt, source.
- class annals.Settings(target, base_url, configured=True, outbox=False, share_base_url='', room=False)[source]#
Bases:
objectWhere to publish and what link to print. See the module docstring for precedence.
- 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
- room: bool = False#
what is written to it carries no provenance
- Type:
an outside audience reads this target
where share links point (
<this>/<token>/);<base_url>/sharedby default
- class annals.SshTarget(host, root)[source]#
Bases:
objecthost:pathon 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 NAMEsaves the target and base url as a named target (annals publish --to NAME) and leaves the default alone.--outboxmarks 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=0or an edit of the file turns it off).--share-base-urlis where share links point when the share server is not at<base-url>/shared(a platform running it as its own public app).--roommarks 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:
- 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, andtitleis ignored. The documents must exist and not be in the bin; the title is cleaned (seeannals.store.clean_title()).- Return type:
- annals.groups(*, target=None, base_url=None, to=None)[source]#
List groups, newest first.
- Return type:
- 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.tonames 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:
- 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.
tolists 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 like6hor2d: 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 byannals tag, win over the publisher’s) andmeta(key=value, several allowed, against the document’ssource:corpus=annals). A row is{id, title, kind, tags, created, updated, source, url}; with--jsonthat is the contract (misc/docs/design.md), andtotalcounts the matches beforelimit.- Return type:
- annals.parse_target(spec)[source]#
host:/pathbecomes anSshTarget; anything else aLocalTarget.- Return type:
- 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(ortalk.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: anindex.htmlor single page with its assets, else a gallery of everything in it), or-for stdin (markdown).tagsis comma separated.groupnames a group to create from the published documents; the reply then carriesgroup_urltoo.add_toappends 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.sessionrecords who published (the source shown on the page), andsession_urlthe claude.ai link that opens that session; by default the link of the Claude Code session this runs in (CLAUDE_CODE_BRIDGE_SESSION_ID),nonefor 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) unlessall_files.topublishes to a named target of the config file ([targets.NAME], seeannals 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_checkturns 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>.pdfprinted beside it (headless Chromium, thepdfextra; 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 itdata-annals-pdf;no_pdf(ordata-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 tohost,cwdandsessionin itssource: by conventioncorpus(the repository or body of work),repo,issue(the issue it answers),item(a desk item) andkind(report, brief, overview, render); other keys are kept as given.ls --session/--metafinds them again. The CLI’s--jsonprints the result below (id,title,url, and with a groupgroup_idandgroup_url; several paths givedocs) as JSON and nothing else on stdout; that shape is a contract (misc/docs/design.md).- Return type:
- annals.restore(doc_ids, *, target=None, to=None)[source]#
Bring documents back from the recycle bin.
- Return type:
- 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_idmay be the document’s link, on any annals this machine is configured for: the link finds its own place (tonames one explicitly). A group’s link gives the group and its documents’ links.linksare the links to other annals documents and groups found in the document’s text files, on any annals this machine can read: follow them withannals showorannals aggregate. To read the text, useannals aggregate <link>.- Return type:
- annals.trash(doc_ids, *, target=None, to=None)[source]#
Move documents to the recycle bin (restorable).
- Return type:
Modules
Many markdown files as ONE markdown document: a title, a table of contents, a section per file. |
|
The auth seam: who may read the annals. |
|
The catalog: every source's items as one list, with search and the owner's tags. |
|
Many files of many kinds as ONE document: a Markdown, html or PDF file. |
|
Settings: where documents are published and what link to print. |
|
Exact filters over a document's meta, for a caller that polls: since, session, tag, source. |
|
A |
|
Find what a document mentions without linking to it: the owner reads on a phone and clicks through. |
|
What each reader has heard of each audio document: percent heard, listens, where they stopped. |
|
MCP surface: the same operations as the CLI, from |
|
The media relay for published html pages: what a framed page plays, told to the page around it. |
|
A share's documents as separate notebook sources: one plain web page per text file. |
|
Spoken overviews of a document: the request a page makes, and the worker that fulfils it. |
|
Every published html page carries its own Download PDF button, and the PDF beside it. |
|
The published documents as records for a retrieval index, so an agent can find one by meaning. |
|
The references of documents, extracted and combined, in three forms. |
|
Render markdown (and other page-like files) to html and PDF, with their images inside. |
|
Optional dependencies, checked where they are needed and explained when they are missing. |
|
The sessions that made a document: each one's name and the link that opens it. |
|
Share links: one document (or a group) behind a public, unguessable, revocable link. |
|
A share link's page with its text in it, and no script, so every reader can read it. |
|
Item sources: everything the page lists, wherever it lives, as rows of one shape. |
|
The document store: a flat set of documents, tags, groups and a recycle bin, as plain files. |
|
Scrolling, zooming tables for published html pages. |
|
The owner's tags: a |
|
The transport seam: a document tree lands in a directory, here or on another machine. |
|
A title for a file whose name says nothing: |
|
The operations, as plain functions: JSON-able arguments in, JSON-able dicts out. |