Long-term memory for AI chat companions
clanka AGENTS.md
19 kB 91 lines
Markdown
at main

Project memory #

This repository keeps durable project knowledge in machine-memory, in a remote database shared by every checkout. Every database command takes --remote. machine-memory help workflow explains each step below in full.

  • Before changing code, scan once and read the records that bear on the task: machine-memory suggest --files "a.ts,b.ts" --remote --json-min for known files, or machine-memory query "<topic>" --hybrid --remote --json-min for a topic or a task that touches no files; then machine-memory get <id,id> --remote. Results are candidates: judge them by match_strength, and "nothing relevant" is a valid outcome.
  • When the user's instruction contradicts a stored record, follow the user and update the record.
  • Write one fact per record, start it with the command, path or identifier it is about, and name its sources in --refs (stale checks them). Store decisions, constraints, preferences, references and gotchas. Put delivery state in one status record with --expires-after-days. Leave out pixel values, UI state and deploy outcomes, and put facts about one machine in that machine's guidance file.
  • Check size before writing: machine-memory size "<text>", or --dry-run on add and update.
  • Change a record with machine-memory update <id> "<whole new content>" --remote. It replaces the content, so read the record first and keep the details that still hold. Leave the content out to change only tags, type or certainty. Create one with machine-memory add "<content>" --upsert-match "<topic>" --type <type> --remote, which updates a strong match instead of adding a duplicate.
  • When a write reports dropped or review_candidates (also on stderr, in a machine-memory: line), restore details dropped by mistake, and update or deprecate the listed records that rely on what you changed.
  • --certainty verified requires --evidence: user_requirement, observed_implementation, verified_mechanism or tested_behavior. Reading the code proves only observed_implementation.
  • When delegating, scan once and pass the record ids to child agents. Children return findings with their evidence; the parent writes them.
  • Before the final response, run machine-memory checkpoint --remote --json-min, then add, update or deprecate records for what the task established.

Project preference: replace obsolete systems when practical; preserve backwards compatibility only when it is explicitly required.

Build and test #

Rust workspace: crates/core (the memory engine), crates/cli (the clanka binary and the code host plugins share), crates/protocol (the messages of clanka rpc), crates/app (the macOS app, on Rune; see below), crates/py (Python bindings for the Hermes plugin in hermes/clanka).

  • Format: cargo fmt --all
  • Lint: cargo clippy --workspace --exclude clanka-app --all-targets -- -D warnings
  • Test: cargo test --workspace --exclude clanka-app (no model provider, keyring, Hermes or network needed)
  • The app, on macOS: cargo clippy -p clanka-app --all-targets -- -D warnings and cargo test -p clanka-app
  • Build the CLI: cargo build -p clanka (target/debug/clanka)
  • On Windows (x86_64-pc-windows-msvc): Visual Studio Build Tools with the C++ workload, a Perl that OpenSSL's Configure accepts (Strawberry Perl works) and NASM on PATH (Strawberry Perl ships one in c\bin; without it the vendored OpenSSL builds with no assembly and CI's jobs fail). Run cargo in PowerShell, never Git Bash: there perl is MSYS's, and a clean build of the vendored OpenSSL fails in Configure (Can't locate Locale/Maketext/Simple.pm). crates/py needs a Python 3.11 or newer; PYO3_PYTHON names it when python is not on PATH. The same three commands are the gate there, with nothing ignored. bun run check cannot pass on Windows (oxlint reads ts-standard's plugin path as /C:/..., and ts-standard compares tsconfig paths with a backslash), so its parts run separately there and CI's check job is the real gate. bun run --cwd docs build there skips the search index (spawn pagefind.cmd ENOENT) and still exits 0.

CI (.github/workflows/ci.yml) runs on pushes to main and stable and on pull requests into them, and on no other branch push: first the advisory check (.github/workflows/advisories.yml, cargo deny check advisories against Cargo.lock), then the format check, lint and tests on Linux (rust, every crate but the app), the same lint and tests on Windows (windows) and on macOS (macos), and the app's build, lint and headless tests on macOS (app), all skipped when the advisory check fails. Rune's crates are in Cargo.lock, so the advisory check covers them. An advisory with no fix yet needs an ignore entry in deny.toml before anything else is checked.

To run the CLI without touching real companions or the keyring, point it at a throwaway directory whose config.toml holds [keys] and store = "file". On every platform CLANKA_HOME=<dir> puts config in <dir>/config and data in <dir>/data, so the file is <dir>/config/config.toml; this is the way on Windows, where the files otherwise live in %LOCALAPPDATA%\clanka:

$env:CLANKA_HOME = '<dir>'; .\target\debug\clanka.exe ...

Without it:

On Linux the file is <dir>/config/clanka/config.toml:

env XDG_CONFIG_HOME=<dir>/config XDG_DATA_HOME=<dir>/data DBUS_SESSION_BUS_ADDRESS=unix:path=/nonexistent ./target/debug/clanka ...

On macOS config and data both live in $HOME/Library/Application Support/clanka, so the file is <dir>/Library/Application Support/clanka/config.toml:

env HOME=<dir> ./target/debug/clanka ...

Releases #

The version is [workspace.package] version in Cargo.toml, which every crate inherits, and version in hermes/clanka/plugin.yaml; a test fails when the two differ. To release, bump both (semver: a schema change or a breaking CLI change is at least a minor bump while below 1.0) and land the bump on main; open a pull request from main into stable and merge it with a merge commit; then tag and push v<version> on a commit that is on stable, such as the main commit that pull request merged. .github/workflows/release.yml refuses a tag whose commit is not on stable (re-run it after the merge if the tag went first), checks the tag against both files, builds x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu, aarch64-apple-darwin and x86_64-pc-windows-msvc (no Intel macOS: ort has no prebuilt ONNX Runtime for it), and publishes clanka-<target>.tar.gz (the CLI, hermes/clanka/ with _clanka.abi3.so, _clanka.pyd on Windows, skills/soul-writer/SKILL.md, and on macOS Clanka.app from crates/app/bundle.sh, ad hoc signed, holding the app and its own clanka) and SHA256SUMS. hermes/install.sh installs Clanka.app into ~/Applications; clanka upgrade replaces it only where it is installed. hermes/install.sh, hermes/install.ps1 (Windows) and clanka upgrade (crates/cli/src/upgrade.rs) install the latest release only after its archive matches SHA256SUMS, so keep the archive names and layout in step across the four. The Windows build runs in PowerShell and fails without NASM on PATH, since without it the vendored OpenSSL would build with no assembly. The docs site serves hermes/install.sh at clanka.jfa.dev/install.sh and hermes/install.ps1 at clanka.jfa.dev/install.ps1 (docs/src/pages/install.sh.ts, install.ps1.ts); a push to main that changes either redeploys the site, since the Workers Builds trigger does not exclude them. Tag only when asked.

A schema change is a new file in crates/core/src/migrations/, added to MIGRATIONS in crates/core/src/db.rs; never edit a migration that has shipped.

Docs site #

docs/ is the Nimbus (Astro) documentation site for clanka.jfa.dev and iac/alchemy.run.ts is the Alchemy stack that deploys it. The stack holds four Workers: the docs (clanka-docs, a Cloudflare.Website.StaticSite that runs bun run build in docs/), the diagnostics endpoint (clanka-ingest, ingest/, an Effect program over a D1 database), the telemetry console (clanka-admin, admin/, a Cloudflare.Website.Foldkit page with a Worker that reads the same D1 database through an Effect HttpApi and never writes to it) and the router (clanka-router, router/, Hono), which has the custom domain, sends /ingest to the endpoint with the prefix stripped, /admin to the console with its prefix kept and everything else to the docs. Only the router has a hostname; it reaches the other three over service bindings. A Cloudflare Access application guards clanka.jfa.dev/admin, and the console's Worker also verifies each request's Cf-Access-Jwt-Assertion against that application's team and audience (the deploy config's access, passed to the Worker as ACCESS_TEAM_DOMAIN and ACCESS_AUD), refusing everything without them. The console's components are foldcn copies (admin/components.json, bunx shadcn@4.23.0 add @foldcn/<name>) restyled with jfa.dev's branding tokens, which admin/src/styles.css copies from jfa.dev's common/src/styles.css. Which of them a deployment has, and its hostname and Access application, come from a deploy config (iac/src/deploy-config.ts, iac/README.md): clanka.jfa.dev's (everything) is not in the repository: the package scripts take it from CLANKA_DEPLOY_CONFIG, a build variable of the Workers Builds trigger holding the JSON, else from the gitignored iac/clanka.production.deploy.json, and anyone else deploys with their own gitignored iac/clanka.deploy.json, or none for the endpoint alone on workers.dev. Keep that working: a part that needs a value only clanka.jfa.dev has goes in the deploy config, not in the stack. Every deploy of the stack deploys all the parts it has. A schema change to the endpoint is a new file in ingest/migrations/; A sender makes its own token with clanka diagnostics token --new and gives you the hash it prints; let it in with INSERT INTO tokens (hash, label, created_at) VALUES ('<hash>', '<label>', unixepoch() * 1000) on the clanka-diagnostics D1 database, and revoke it with UPDATE tokens SET revoked_at = unixepoch() * 1000 WHERE label = '<label>'. They form a Bun workspace (root package.json) that the Rust build does not use. docs/AGENT.md covers authoring.

  • Install: bun install (repo root); its prepare patches tsrs and oxlint with the Effect builds.
  • Check: bun run check (repo root) is the one read-only gate: lint, format:check, typecheck and test in every workspace, then oxfmt --check on the root's files. bun run fix is the one command that rewrites files. Every package has the same verbs; reach one with --cwd, as in bun run --cwd router test. STANDARD.md lists the exceptions to them.
  • Typecheck is effect-tsgo tsrs --noEmit, with the Effect diagnostics turned on by the plugin entry in tsconfig.base.json; docs uses astro check. Tests are vitest; the endpoint's and the console's tests run on node:sqlite with the real migrations.
  • bun run --cwd docs build validates the sidebar and produces docs/dist/pagefind/; check does not build. It also rewrites the tracked files in docs/.nimbus/, and nimbus-docs lint (check) checks internal links against routes.json there: commit them with any change to a page or the sidebar, and drop a diff that only moves builtAt.
  • Work on the console: bun run --cwd admin dev serves the page alone; its API needs a Worker with a D1 binding and an Access token
  • Plan: bun run plan (read-only); deploy: bun run deploy. Deploy only when asked.
  • CI: .github/workflows/ci.yml runs on pushes to main and stable and on pull requests into them; a push to any other branch runs it only through its pull request. Those triggers differ from the standard's reference, which an exception for workflows/ci-reference in standard.config.ts allows; it excuses any other difference of ci.yml from the reference too, so check a change to ci.yml against node_modules/@jfalava/ts-standard/reference/ci.yml by eye. STANDARD.md lists every exception; change it with standard.config.ts. Its changes job (dorny/paths-filter, the same in every repo of the standard) sets code and rust; check (bun run check) runs unless code is false, and advisories, rust, windows, app and macos unless rust is false. windows (windows-2025) runs its cargo steps in the runner's PowerShell, not Git Bash, because under Git Bash perl is MSYS's, which fails the vendored OpenSSL's Configure, and it fails unless NASM is on PATH (its step prints where it found it); it has no -D warnings in RUSTFLAGS, which would fail on the linker's LNK4099 for the vendored OpenSSL. app, macos (the workspace's lint and tests but the app, whose tests keep keys in files under temporary directories and so reach no keychain), and release.yml's macOS build, run on the owner's Mac (self-hosted runner clanka-mac, as jfalava, in ~/actions-runner/clanka with its own CARGO_HOME) when the mac job finds it online with the RUNNERS_TOKEN secret, else on macos-15; that Mac has no rustup, so "Install Rust" checks its Nix Rust is rust-version instead, and the repo requires approval for every external contributor's pull request because a fork could aim a workflow at the Mac. The rust filter's comment in the workflow says what it holds; keep it in step with what cargo reads, and the README's Development section with the jobs. The main ruleset requires check and rust; the stable ruleset requires check, rust, windows and macos. Both refuse deletion and force pushes, and the admin role bypasses both. Cloudflare Workers Builds on the clanka-router Worker only deploys: a push to main runs bun run ci:build (bun run check again) and then bun run ci:deploy, which deploys the whole stack, unless every file the push changes matches one of the trigger's excluded build watch paths (it includes * and excludes what neither the site nor the stack reads, such as crates/* and .github/*); a push of 20 or more commits, or 3000 or more changed files, always builds. The excludes are kept only in the trigger's settings in Cloudflare, not in this repository. hermes/install.sh and hermes/install.ps1 are not excluded, because the docs serve them. plan, deploy, ci:deploy and destroy pass --stage live_jfalava, the stage the stack was first deployed from, so builds and local runs share one state whatever ALCHEMY_STAGE or USER say.

The CLI pages under docs/src/content/docs/cli/ mirror clanka help <command>, and configuration.mdx mirrors the defaults in crates/core. Update them with the command or setting they describe.

The App pages' screenshots (docs/public/app/) come in pairs, <name>.png dark and <name>-light.png light, and docs/src/lib/themed-screenshots.ts (a hast plugin in docs/astro.config.ts) shows the one that matches the site's theme. Take them all with cargo build -p clanka-app && bun run --cwd docs screenshots (docs/scripts/app-screenshots.ts lists each file's scene and size), after a UI change and after a version bump, since home.png shows the version.

The Licenses page (docs/src/content/docs/licenses.mdx) lists every direct dependency of the Rust and Bun workspaces from docs/src/lib/licenses.ts. After adding, removing or upgrading a dependency, regenerate it with bun run --cwd docs licenses (it needs cargo, installed packages and network); bun run --cwd docs licenses:check fails when it is stale. It is not part of check, so neither CI nor Workers Builds runs it: the Workers Build has no cargo, and a check must not need the network.

The app and clanka rpc #

crates/app (clanka-app) is the macOS app, on Rune with rune-kit's components, branded by jfalava-ui-rune (jfalava/ui's rune/, a git dependency at a commit): its kit(dark) in place of Kit::neutral, its fonts in spec(), and its UpdateBadge, Callout, Mark and code, which view/parts.rs builds on. The plan, with the owner's decisions and the order of the releases, is machine-memory records #3720 and #3721. It never opens a database or the keychain: it starts clanka rpc (crates/cli/src/rpc/), as a child for this Mac and as ssh <target> clanka rpc for another machine, and talks JSON-RPC 2.0 over its stdio. crates/protocol declares every method, its parameters and its answer, and PROTOCOL, which the app compares on connect: raise it with any change to a method. docs/src/content/docs/cli/rpc.mdx describes both; update it with them.

  • Each action is one function in crates/cli/src/actions.rs returning the protocol's types; the command prints it and the rpc method sends it. The core's types reach the protocol's through JSON, and the protocol's refuse unknown fields, so a field added to one and not the other fails the rpc tests (crates/cli/src/rpc/tests.rs).
  • every_command_is_in_the_app_or_says_why_not in crates/cli/src/main.rs fails when a CLI subcommand has no rpc method and is in neither CLI_ONLY (chat, mcp, debug, eval, diagnostics, rpc, and doctor delete-all) nor LATER, the commands a later release brings to the app. A release moves its commands from LATER to IN_THE_APP with their methods.
  • Repairs: the app's doctor switch, off at launch and per companion, replaces clanka web --doctor. Nothing freezes on its own; a delete or a rollback shows the core's own plan (doctor.delete_plan, doctor.rollback_plan) and asks first, a rollback needs the companion's name typed, and delete-all stays a command the app only prints.
  • Rune is pinned to a rev of its dev branch in crates/app/Cargo.toml, and its [patch.crates-io] list is repeated at the same rev in the root Cargo.toml; bump both together, copying the list from that rev's Cargo.toml, and check that cargo build -p clanka-app says no patch went unused. jfalava-ui-rune declares Rune itself, without re-exporting it, so its rev must be the same: bump Rune in jfalava/ui first, then move both revs here. At two revs Cargo builds two Rune copies and the app stops compiling (a Kit that is not a Kit); cargo_lock_has_one_rune in crates/app/src/tests.rs says so first. Linux never builds the app: --exclude clanka-app.
  • Check the UI headless: target/debug/clanka-app --snap <png> --scene <name> --size 1100x720 (--list-scenes, --tree <json>); the scenes are fixtures and start no process. For the companions on this Mac the app runs the clanka next to its own binary first, so build both.

License #

AGPL-3.0-only (LICENSE, Cargo.toml, every package.json); releases up to 0.1.6 were MIT. REUSE.toml lists the files that keep another license (the foldcn copies in admin/, the Nimbus registry components in docs/, a vendored font); add an annotation there when you copy in third-party code.

  • ARCHITECTURE.md maps this repo. Update it in the same change when you add, move, rename or remove a package, entry point or boundary; otherwise leave it alone. Decisions, conventions and gotchas go in machine-memory, not there.