annals.tools#
The operations, as plain functions: JSON-able arguments in, JSON-able dicts out.
This module is the single source of truth for what a annals can do. The CLI
(annals.__main__, via cw), the MCP server (py2mcp over string refs to these
names) and the shipped skill all describe the same functions, so there is nothing to keep
in parity. Nothing here prints or exits; the surfaces do that.
Module Attributes
the suffixes whose text the link check reads (prose an author writes by hand) |
|
the suffixes whose text |
|
|
|
a surface serves the levels its caller allows. |
|
what an agent or a tool is offered unless its host asks for more (MCP reads this) |
Functions
|
The files of a group (or one document) as ONE markdown, html or pdf file (nothing is stored). |
|
Write the publisher config (where to publish, what link to print) and show it. |
|
Copy documents or groups to a named target, keeping their ids; print the new link. |
|
One markdown file of a document as a |
|
Make a group (one URL for a set of documents) from existing document ids. |
|
List groups, newest first. |
|
Ask for a spoken overview of a document, as its page's Listen button does. |
|
Say why spoken overviews cannot be made, and where that is being fixed; or clear it. |
|
Fulfil the queued overview requests, one at a time (a timer runs this on the server). |
|
List documents (newest first), optionally filtered by words or showing the bin. |
|
Where a document's spoken overview stands (not asked for, queued, made, failed), without asking for one. |
|
The page's html shell, for a host that serves the API under its own prefix. |
|
Publish one document and print its link; several paths become several documents. |
|
Delete documents that are in the bin for good (not restorable). |
|
The references of a document or a group, as its page's References action gives them. |
|
Rename a document or a group (its link or id), as the page's Rename does. |
|
Bring documents back from the recycle bin. |
|
Serve the annals page and API (needs |
|
Make a public link to ONE document (or group) and print it; nothing else is reachable. |
|
What the Share dialog offers for a document: its files, and the other annals documents its text links to. |
|
List share links, newest first ( |
|
A document's metadata, link, the groups it is in, and the annals links in its text. |
|
Set a document's tags (comma separated; "" clears them), as the page's tag editor does. |
|
The operations whose effect is in |
|
Move documents to the recycle bin (restorable). |
|
Revoke share links (their token or full link): they stop working at once. |
- annals.tools.DFLT_EFFECTS = frozenset({'read', 'write'})#
what an agent or a tool is offered unless its host asks for more (MCP reads this)
- annals.tools.EFFECTS = {'aggregate': 'file', 'configure': 'write', 'copy': 'write', 'export': 'file', 'group': 'write', 'groups': 'read', 'listen': 'spend', 'listen_down': 'spend', 'listen_work': 'server', 'ls': 'read', 'overview_state': 'read', 'page_shell': 'server', 'publish': 'write', 'purge': 'destructive', 'references': 'read', 'rename': 'write', 'restore': 'write', 'serve': 'server', 'share': 'write', 'shareable': 'read', 'shares': 'read', 'show': 'read', 'tag': 'write', 'trash': 'write', 'unshare': 'write'}#
a surface serves the levels its caller allows.
readchanges nothing;writechanges the store or a setting and can be undone or repeated;filewrites a path on the machine that runs it;destructivecannot be undone;spendcosts money or queues work that does;serveris run by a server or a timer, never by a caller.- Type:
what a function does to the world, least to most
- annals.tools.LINKS_MAX_FILES = 20#
show()reads at most this many of a document’s text files for links …
- annals.tools.LINKS_MAX_FILE_BYTES = 1000000#
… and none larger than this (bytes, from the document’s meta)
- annals.tools.LINKS_READ_SUFFIXES = frozenset({'.htm', '.html', '.markdown', '.md', '.txt'})#
the suffixes whose text
show()reads for the annals links a document makes
- annals.tools.LINK_CHECKED_SUFFIXES = frozenset({'.markdown', '.md', '.txt'})#
the suffixes whose text the link check reads (prose an author writes by hand)
- annals.tools.aggregate(group_id, *, format='md', output=None, demote=1, order='numbered', no_toc=False, keep_wraps=False, target=None, to=None)[source]#
The files of a group (or one document) as ONE markdown, html or pdf file (nothing is stored).
group_idis a group’s or a document’s id or link.format:md(printed, or written tooutput),html(a web page, the same) orpdf(needsoutput). Markdown, html, text, PDF and image files go in; what cannot (audio, video, other files, a damaged PDF) is listed on stderr, with the reason, and left out. The markdown has the group’s title, a table of contents, then one##section per file named after its path (a folder document’s files under its title).order:numberedputs paths that start with a number first, numerically, the rest in the group’s order;givenkeeps the group’s order.demotepushes each file’s headings that many levels down (0: as written). Hard-wrapped lines are joined unlesskeep_wraps;no_tocleaves out the table of contents. Redirect to save text, or name the file:annals aggregate <id> --format pdf --output bundle.pdf. A PDF or html needspip install 'annals[pdf]'; a missing library says so.
- annals.tools.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.tools.copy(refs, *, to, source=None, target=None, base_url=None)[source]#
Copy documents or groups to a named target, keeping their ids; print the new link.
refsare links (https://.../annals/d/<id>,.../g/<group-id>) or bare ids; only the id is used, so the link may point at any instance. They are read from the default target (or the named targetsource) and written to the named targetto. A group is copied with its documents and keeps its id and title. Copying again refreshes the copy. The source must be readable from this machine (a directory, orhost:/path).target/base_urloverride the DESTINATION’s location, as inpublish.- Return type:
- annals.tools.export(doc_id, *, format='pdf', file=None, output=None, target=None, to=None)[source]#
One markdown file of a document as a
.mdor a titled.pdf, as the page’s Export gives it.filenames another markdown file of a folder document (default: the main one). A PDF (images inside; needs theannals[pdf]extra) is a binary file, so name it with--output FILE;mdprints the text or writes it tooutput. For several documents as one file, with a table of contents, useannals aggregate.
- annals.tools.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.tools.groups(*, target=None, base_url=None, to=None)[source]#
List groups, newest first.
- Return type:
- annals.tools.listen(doc_id, *, minutes=5, force=False, also=None, target=None, to=None)[source]#
Ask for a spoken overview of a document, as its page’s Listen button does. Spends money.
also(more document ids) asks for ONE overview of all of them together, as the page does for a pick: their text is put in one document (made when the worker starts the job), and the same documents at the same versions reuse it.forcethen does not apply.- Return type:
- annals.tools.listen_down(reason='', *, link='', clear=False, target=None, to=None)[source]#
Say why spoken overviews cannot be made, and where that is being fixed; or clear it.
With nothing given, shows the current state. The Audio tab then shows the reason and the link instead of a Try again that cannot work, e.g.
annals listen-down "the server's login expired" --link <issue url>. The worker finds out by itself too, and clears it on the next success;--clearclears it now and queues every request that waited.- Return type:
- annals.tools.listen_work(*, command='', target=None, to=None)[source]#
Fulfil the queued overview requests, one at a time (a timer runs this on the server).
commandmakes one overview, with {source}, {minutes}, {out} and {url} filled in; by default,$ANNALS_OVERVIEW_COMMAND.- Return type:
- annals.tools.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.tools.overview_state(doc_id, *, target=None, to=None)[source]#
Where a document’s spoken overview stands (not asked for, queued, made, failed), without asking for one.
Poll this after
annals listen. For a combined overview (listen --also) give the combined document’s id once the worker has made it; until thenlistenreturns the state.- Return type:
- annals.tools.page_shell(*, api='/api/annals', base='/annals', title='annals')[source]#
The page’s html shell, for a host that serves the API under its own prefix.
An enlace app writes it once as its frontend:
annals page-shell --api /api/annals --base /annals > frontend/index.html. The shell only names the two paths; the page’s code loads from the API, so it upgrades with the package.- Return type:
- annals.tools.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.tools.purge(doc_ids, *, target=None, to=None)[source]#
Delete documents that are in the bin for good (not restorable). One that is not in the bin is refused.
- Return type:
- annals.tools.references(ref, *, form='grouped', also=None, target=None, to=None)[source]#
The references of a document or a group, as its page’s References action gives them.
refis a group’s or a document’s id or link.form:grouped(each document’s references section as it is),deduped(every entry once, numbers removed) orurls(one address per line, nothing else: what a notebook takes as pasted sources). Documents with no references section are left out; none at all is an error.also(more document ids) takes the references of those documents together, as a pick on the page does.- Return type:
- annals.tools.rename(ref, title, *, target=None, to=None)[source]#
Rename a document or a group (its link or id), as the page’s Rename does.
The document keeps the owner’s title when a new version is published over it (
publish --replace). Returns{id, title}.- Return type:
- annals.tools.restore(doc_ids, *, target=None, to=None)[source]#
Bring documents back from the recycle bin.
- Return type:
- annals.tools.serve(*, host='127.0.0.1', port=8765, data_dir=None, base_path='/annals', allow_open=False, overviews=None)[source]#
Serve the annals page and API (needs
pip install 'annals[server]').Auth comes from the environment:
ANNALS_WHOAMI_URL+ANNALS_ALLOWED_USERSto sit behind an existing login,ANNALS_BASIC_USER+ANNALS_BASIC_PASSWORDfor HTTP Basic, nothing for an open server on localhost. A host reachable beyond this machine with no auth configured is refused unlessallow_open(--allow-open) says something else gates it.overviews(--overviews '*', or reader names separated by commas) offers the Listen button to those the login lets in (unset:ANNALS_OVERVIEWSdecides, and unset it is off;--overviews ''forces it off). It spends money, needsANNALS_OVERVIEW_COMMANDand a worker (annals listen-workon a timer), and a server with no login serves it only on this machine.- Return type:
Make a public link to ONE document (or group) and print it; nothing else is reachable.
Returns three forms of the one link (the CLI prints the first on stdout, the others on stderr):
url, the page, whose text is in the html (a person, NotebookLM or any fetcher reads it without running script);markdown, the whole share as one text, for an agent;pdf, the same with its images. All three end with the link’s expiry or revocation.refis a document or group id, or its link. The link opens without a login, shows only that page and the files chosen, and can be revoked (annals unshare).include: comma separated files of the document to share (the page itself always is), or ids of other annals pages it links to; by default every file of the document (for a group: every document;includethen picks documents).excludedrops files.expires(7 days unless told):12h,30d,2w, a date (2026-11-01, through that day, UTC), an ISO time, ornever.passwordgates the link (stored hashed;-reads it from stdin, so it stays out of the shell history).- Return type:
What the Share dialog offers for a document: its files, and the other annals documents its text links to.
{main, files: [{rel, kind, size, referenced}], pages: [{id, title, kind}]}: the choicesannals sharetakes for what a link may show.- Return type:
List share links, newest first (
all: revoked and expired ones too).- Return type:
- annals.tools.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.tools.tag(doc_id, tags, *, target=None, to=None)[source]#
Set a document’s tags (comma separated; “” clears them), as the page’s tag editor does.
The tags are the owner’s overlay, kept apart from the document and shown by
lsandshowin place of the publisher’s. They live where the documents do, so this refuses an outbox or a remote target.doc_idmay be the document’s link. Returns{id, tags}.- Return type:
- annals.tools.tools_with(effects=frozenset({'read', 'write'}))[source]#
The operations whose effect is in
effects, in the CLI’s order: the list a caller-facing surface serves.>>> [f.__name__ for f in tools_with({"read"})] ['ls', 'show', 'groups', 'references', 'shareable', 'shares', 'overview_state']
- Return type:
- annals.tools.trash(doc_ids, *, target=None, to=None)[source]#
Move documents to the recycle bin (restorable).
- Return type:
Revoke share links (their token or full link): they stop working at once.
- Return type: