- Odin 98%
- HTML 2%
Memoria #
Run the application from the repository root with an OpenRouter key in the environment:
OPENROUTER_API_KEY=... odin run src
Alternatively, store the key once at $XDG_CONFIG_HOME/memoria/auth.json, or ~/.config/memoria/auth.json when XDG is unset:
{
"openrouter": {
"api_key": "your-openrouter-key"
}
}
The credential file must be owned by the current user, be a regular file rather than a symlink, and have private permissions:
install -d -m 700 ~/.config/memoria
chmod 600 ~/.config/memoria/auth.json
OPENROUTER_API_KEY overrides the stored key when set. Runtime diagnostics are
appended to $XDG_CONFIG_HOME/memoria/memoria.log, or
~/.config/memoria/memoria.log when XDG is unset. The log directory and file
are secured with private permissions; provider HTTP failures include the request
URL and HTTP status when available.
To use an OpenAI model through a ChatGPT Plus, Pro, Business, Edu, or Enterprise subscription, authorize the codex provider once with OpenAI's device flow:
odin run src -- login
Open the displayed OpenAI URL, enter the code, and approve access. The refreshable OAuth credentials are written to the same private auth.json store under the codex entry. Then select the provider:
{
"provider": "codex",
"model": "gpt-5.4"
}
This is the ChatGPT Codex subscription backend, not the metered OpenAI API-key service. The provider refreshes expiring access tokens on startup. Run the login command again if OpenAI revokes the refresh token.
Provider and model settings are loaded in this order:
- Built-in defaults:
openrouterandopenrouter/auto. $XDG_CONFIG_HOME/memoria/config.json, or~/.config/memoria/config.jsonwhen XDG is unset.memoria.jsonin the startup working directory.MEMORIA_PROVIDERandMEMORIA_MODELenvironment variables.
Configuration files contain strict JSON:
{
"provider": "openrouter",
"model": "openai/gpt-oss-120b"
}
Agent access policy #
Both user config.json and project memoria.json may set agent_access.
For example, user configuration:
{
"agent_access": {
"network": false,
"paths": [
{"path": "~/work/opencode", "access": ["read", "write"]},
{"path": "/absolute/reference", "access": ["read"]}
]
}
}
Project configuration can override that grant:
{
"agent_access": {
"paths": [
{"path": "~/work/opencode", "access": ["read"]},
{"path": "/absolute/project-data", "access": ["read", "write"]}
]
}
}
Permissions are applied as defaults → user → project. For the same normalized
path, project modes replace, rather than union with, user modes: the example
narrows opencode to read-only. Reversing the two mode lists widens it to
read/write. Unmatched user grants remain and project-only grants are added.
~ expansion and canonicalization (including symlink aliases) happen before
matching. Omitted project fields inherit user values; an explicit network
overrides the user value, including false.
Project trust: the first time project agent_access is supplied (even {}),
Memoria displays the effective canonical roots/modes and shell network setting
and requires typing yes on a terminal before starting agent tools. Only approve
repositories you trust: a repository can request external writes or networking.
Approval is remembered per canonical workspace in private
project-access-approval-*.json files in the user config directory, never in the
repository. Unchanged normalized permissions skip the prompt; changes to project
grants or the effective policy require approval again. Formatting, path aliases,
and grant ordering do not trigger reapproval. Only the latest approval is kept.
Delete the workspace's approval file to forget it (or all matching files to reset
all approvals). Missing, invalid, or insecure cache files require fresh approval.
When approval is required, declining, EOF, or non-terminal input aborts startup.
If remembering approval fails, it applies only to the current run and Memoria
warns that it could not save it. Review project instructions and skills as well;
this approval covers permissions, not all host startup reads.
The startup workspace always has read/write access. Additional grants must name
existing directories using absolute paths or ~/~/; relative grants, unknown
fields/modes, and empty access lists are rejected. Omitted settings mean no
additional grants and no shell network access when neither layer supplies them.
Grants for distinct overlapping directories are recursive and additive,
and canonicalized once per run. Relative tool paths are anchored to the startup
workspace; absolute paths must be covered by a grant. edit_file needs both
read and write. Native file tools traverse with descriptor-relative, no-symlink
opens, reject special files, and reject multiply-linked write/edit targets.
On macOS, every bash invocation uses /usr/bin/sandbox-exec with this
profile; descendants inherit it:
(version 1)
(deny default)
(allow process-exec)
(allow sysctl-read)
(allow mach-lookup)
(allow system-info)
(allow process-fork)
(allow file-read*)
(allow file-map-executable)
(allow file-write* (subpath (param "CWD")))
CWD is set to the invocation's working directory. Each invocation also gets a
unique temporary directory exposed as TMPDIR; its path is added as a separate
scoped write grant and cleanup is attempted after the command. Reads and execution
are allowed broadly, while writes are limited to CWD and that temporary directory. Tools installed elsewhere (for example Homebrew) can therefore be
read and executed. Shell network remains denied. Provider HTTP traffic is
unaffected: Memoria itself is not sandboxed. Setup failures never retry
unsandboxed; unsupported platforms deny shell execution.
The same policy is inherited by delegated tasks and skill resource reads. Home skills can appear in the metadata catalogue, but reading their bodies/resources requires a read grant. Model/variant selection saves only user grants, never project permission overrides. The effective policy is fixed for the entire run, including subagents and conversation switches. Restart and approve again to apply access changes; editing either configuration cannot change active tool permissions.
This is an agent-tool boundary, not a sandbox for the whole application. Startup
configuration, credentials, project instructions, and skill discovery remain
host reads. Shells inherit the process environment, including any exported
secrets, except TMPDIR, which is set to the per-invocation sandbox temporary
directory. Do not export secrets you want hidden from commands. Native tools are
stricter about symlinks than the shell, whose resolved targets must be allowed
by the OS sandbox. Existing hard-link aliases and concurrent directory moves
are not a complete filesystem-isolation boundary. Cancellation/timeout cleanup
of descendants is best-effort; surviving descendants remain sandboxed.
The supported providers are openrouter, codex, opencode (Zen), and opencode-go (Go). Selecting another provider or loading invalid configuration exits before the terminal UI starts. OPENROUTER_MODEL remains available as a deprecated model override below the MEMORIA_* variables. Credentials cannot be stored in configuration files.
OpenCode Zen and Go #
OPENCODE_API_KEY=... MEMORIA_PROVIDER=opencode MEMORIA_MODEL=glm-5.2 odin run src
# For Go, use MEMORIA_PROVIDER=opencode-go (the same environment variable).
Alternatively add "opencode": {"api_key": "..."} and/or
"opencode-go": {"api_key": "..."} to the private auth.json store.
OPENCODE_API_KEY overrides the selected provider's stored key. Both providers
default to glm-5.2 and support streaming text, reasoning, tools, and usage via
Chat Completions. /models uses each gateway's separate models.dev catalog and
only exposes models whose effective SDK is @ai-sdk/openai-compatible.
Responses, Anthropic Messages, and Google models are not supported by these
adapters; known incompatible model families are rejected before sending.
Prefer /models over manually configured IDs, whose protocol metadata cannot
be checked locally. Go's subscription /usage operation is not implemented.
Ctrl-X starts a key prefix. Press e next to edit the current prompt with $EDITOR (or vi when unset), m to open the model selector, t to open the variant picker, or q to quit. Unknown prefix combinations are consumed. Prompt editing is unavailable while a response is streaming.
Left and Right move through the prompt, Home and End move within the current line, and Delete removes the character after the cursor. Up and Down move between multiline prompt rows when no picker is open.
Enter /models while idle to fetch all models available from the active provider. Type in the prompt to filter model IDs, use the arrow keys or Ctrl-N and Ctrl-P to move, Enter or Tab to select, and Esc to cancel. Selecting a model clears the filter, applies the model immediately, and saves the provider and model to the user config.json. A project memoria.json or MEMORIA_* environment variable can still override that saved user setting on the next launch.
Each launch starts a new session. Enter /new while idle to start another new session with the current model. Sessions with conversation history are saved as private JSON files under $XDG_CONFIG_HOME/memoria/sessions, or ~/.config/memoria/sessions when XDG is unset; unused new sessions are not saved. Enter /session while idle to list saved sessions created in the current working directory only (not its subdirectories), type to filter them, and select one with Enter or Tab. Starting or switching sessions prints a session boundary; switching also restores its model, token metadata, and complete provider history and replays its visible messages in the terminal.
Enter /compact while idle to summarize the conversation with the current model and variant, without tools. The UI streams the summary beneath a compaction started boundary, then prints done once both sessions are saved. The new session retains the summary as model context in its session file, without replaying it as a user message or duplicating it in the terminal. Resuming the new session shows a compact context marker. Reasoning and terminal styling are excluded from the summary. Cancellation (Ctrl+C or Esc twice), an empty summary, or a request/save failure keeps the current session. You can draft a prompt while compacting; send it after compaction finishes. The original session remains available through /session.
The models.dev catalog is cached as compact, processed binary model records in
$XDG_CONFIG_HOME/memoria/models.dev.bin, or
~/.config/memoria/models.dev.bin when XDG is unset (or not absolute).
Both model and variant pickers read this disk cache on each request; there is no
persistent in-memory catalog. A cache younger than one hour avoids network and
JSON parsing; exactly one hour is expired, using the embedded fetch timestamp
(not the file modification time). Missing, unreadable, corrupt, incompatible,
unusable, or future-dated cache data falls back to models.dev. Only a successful,
usable remote response replaces the cache, atomically and best effort. Remote
errors preserve existing bytes but expired data is not an offline fallback.
Delete the binary file to force a refresh. Old models.dev.json files are ignored.
Binary format v1 uses MEMMODEL, a u32 version, u64 Unix-nanosecond timestamp,
a length-prefixed registry identity, and a u32 record count. Records contain five
length-prefixed strings (provider, ID, name, family, release date), three u64
limits, four IEEE-754 f64 costs, u32 capability flags, u32 status, and a u32
variant count followed by length-prefixed variant strings. All numbers are
little-endian; string lengths are u32 byte counts. A trailing FNV-1a u64 checksum
covers all preceding bytes (corruption detection, not authentication). Decoding
validates lengths, counts, values, sorting, checksum, version, and freshness.
Limits are 32 MiB per file, 100,000 records, 1 MiB per string, and 1,024 variants
per model. Decoded model data owns its strings independently of the file buffer.
The exact registry identity includes provider/catalog mappings, callback presence,
and versioned catalog_cache_policy strings. Filter/override changes must bump
that policy (and shared parsing/format changes must bump the format version).
Custom registrations with callbacks but no policy disable disk caching, rather
than reusing potentially incompatible results. Procedure pointers are never
serialized. Credential availability and active-provider selection do not change
catalog processing and are not part of the identity.
Enter /variants while idle to select a reasoning variant supported by the current model. Available levels come from the models.dev catalog and commonly include low, medium, high, xhigh, or max. Selecting Default leaves reasoning effort to the provider. The selected variant is displayed in the status row and saved with the session.
Type @ to select a file from the startup working directory. The picker searches recursively, respects scoped .gitignore and .ignore files, and skips .git. It displays at most eight matching paths at once; use the arrow keys or Ctrl-N and Ctrl-P to navigate all matches, then Enter or Tab to insert the selected path.
The model can call six built-in tools (plus two skill tools when skills are discovered):
list_directorylists up to 256 directory entries.read_filereads regular text files up to 64 KiB.write_filecreates or overwrites UTF-8 text files up to 64 KiB. Parent directories must already exist.edit_filereplaces one unique exactold_textmatch withnew_textin an existing UTF-8 file up to 4 MiB (empty replacement deletes text). It rejects missing or ambiguous matches.bashruns a foregroundbash -ccommand from the directory where the application starts. It captures combined output up to 64 KiB and accepts an optional timeout of up to 120 seconds.taskruns a complex, multi-step operation in an isolated in-memory subagent using the active model. The subagent can use the five workspace tools above and discovered skill tools, cannot delegate recursively, and returns only its final response to the parent conversation.
Every provider receives the same built-in coding-agent system prompt, including the available tools and startup working directory. If AGENTS.md exists in that directory, its contents are appended as project-specific instructions. The file is limited to 64 KiB; skill discovery is described below. Nested instruction-file discovery is not supported.
For list_directory, read_file, write_file, and edit_file, absolute paths, parent traversal, and symlink traversal are rejected. On macOS, bash runs under the deny-by-default sandbox described above; unsupported platforms deny shell execution. Tools run sequentially on a worker thread so input, rendering, and cancellation remain responsive while a command or subagent is active.
Submitted messages are printed from column one in light green with a > prefix. The active input starts with a blue ┃ marker, and session status is right-aligned below it in gray. Assistant prose uses the terminal's default color. Inline and fenced code uses light blue with Markdown backticks hidden; bold and italic Markdown both use terminal italics. Horizontal rules span the usable terminal width. H1 headings are bold, underlined, and magenta; H2 headings are bold and cyan; H3 headings are bold in the default color.
Each request includes the full conversation from the current session, including prior assistant responses, tool calls, and tool results. Terminal-only tool indicators and errors are not sent to the model.
Tool rounds have no fixed default limit. To stop an actual loop, the third consecutive call with the same tool name and exact argument JSON is rejected before that batch executes.
The prompt status row shows the configured model and its OpenRouter context-window size. After each response, it uses the served model ID and reports the API-provided token usage against that context window as compact k units and a percentage. If model metadata is unavailable, the model ID is still shown.
The runnable Odin package is in src/.
main.odininitializes dependencies and runs the application loop.application.odincontains the application model, input transitions, and redraw coordination.agent.odinowns conversation history and tool-call execution.session/owns conversation history, selected model, and token usage.system_prompt.odinbuilds shared provider instructions and loads optional project context.settings/loads configuration, securely manages provider credentials, and implements Codex device authorization and refresh.input.odinowns editable prompt state, autocomplete, and prompt rendering.stream.odinowns normalized stream events, response state, and incremental terminal output.markdown.odinincrementally formats emphasis, inline code, and fenced code across stream chunks.network.odinadapts application requests and events to the active provider.provider/owns the provider registry, catalog, retry policy, and provider adapters.http/owns HTTP requests, streaming transfers, and Server-Sent Event framing.tools/validates and executes filesystem and shell tools.terminal.odinowns raw terminal mode, terminal sizing, and keyboard parsing.
See STREAMING.md for the streaming architecture and follow-up plan.
Agent Skills #
Memoria discovers immediate skill directories in <cwd>/.agents/skills and
~/.agents/skills at startup (project names take precedence). Each directory
must contain a regular SKILL.md with YAML frontmatter starting and ending
with ---, a name matching the directory (lowercase letters, digits and
hyphens, up to 64 characters), and a non-empty description. Only metadata is
included in the initial prompt; activate_skill displays [activate_skill] name
and loads the Markdown instructions without frontmatter, plus the skill name,
SKILL.md path and skill directory, when needed. read_skill_resource reads
text paths under the named skill directory
(up to 64 KiB); neither tool runs scripts or grants permissions from
allowed-tools. Symlinked directories and resource paths are rejected. Project
skills are discovered without a trust prompt, like AGENTS.md; review skills
from unfamiliar repositories before working there. Skill files are not
sandboxed against explicit bash commands. /compact summarizes prior skill
instructions rather than retaining their original tool results, so reactivate
a skill after compaction when its exact instructions matter.
Frontmatter supports plain, JSON-style double-quoted, single-quoted, and
literal/folded block scalar values for name and description. Complex YAML
structures/escapes are not fully supported; unsupported required fields cause
that skill to be skipped with a diagnostic. Invalid skills do not prevent startup.