loki / tui_gateway
AGENTS.md28 starsChanged 2 months agoMITView on GitHub
Applies on top of the root AGENTS.md. The TUI fully replaces the classic prompt_toolkit CLI; activate with loki --tui or LOKI_TUI=1. tui_gateway is ALSO the backend the Desktop app and the dashboard /chat talk to — changes here have three consumers. TypeScript owns the screen. Python owns sessions, tools, model calls, and slash-command logic. Never move agent behaviour into the renderer. Newline-delimited JSON-RPC over stdio: requests from Ink, events from Python. tui_gateway/server.py is the facade with the method/event catalog; methods…
- Installs packages
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 31,774 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository69 other files it gives its agents.
- agent/AGENTS.mdAGENTS.md
- AGENTS.mdAGENTS.md
- cron/AGENTS.mdAGENTS.md
- gateway/AGENTS.mdAGENTS.md
- loki_cli/AGENTS.mdAGENTS.md
- plugins/AGENTS.mdAGENTS.md
- skills/AGENTS.mdAGENTS.md
- tools/AGENTS.mdAGENTS.md
- web/AGENTS.mdAGENTS.md
- llms-full.txtllms.txt
- apple-notesSkill
- apple-remindersSkill
- findmySkill
- imessageSkill
- claude-codeSkill
- codexSkill
- computer-useSkill
- loki-agentSkill
- opencodeSkill
- architecture-diagramSkill
- ascii-videoSkill
- baoyu-infographicSkill
- claude-designSkill
- design-mdSkill
- humanizerSkill
- manim-videoSkill
- p5jsSkill
- popular-web-designsSkill
- songwriting-and-ai-musicSkill
- sdlc-reviewSkill
- email-inbox-triageSkill
- himalayaSkill
- gif-searchSkill
- songseeSkill
- youtube-contentSkill
- obsidianSkill
- airtableSkill
- boxSkill
- document-to-action-itemsSkill
- docxSkill
- google-workspaceSkill
- mapsSkill
- meeting-action-itemsSkill
- notionSkill
- pdfSkill
- powerpointSkill
- product-price-monitorSkill
- teams-meeting-pipelineSkill
- weekly-review-planningSkill
- xlsxSkill
- arxivSkill
- competitor-news-monitorSkill
- grounded-citationsSkill
- llm-wikiSkill
- xurlSkill
- codebase-inspectionSkill
- dogfoodSkill
- githubSkill
- inspecting-loki-desktop-domSkill
- loki-agent-skill-authoringSkill
- The first 60 shown.
The file
We split this AGENTS.md into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Never move agent behaviour into the renderer.
≈ “Common” is an estimate: at least 1 in 5 of the 40,246 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
tui_gateway/ + tui-ui/ — the TUI and its JSON-RPC backend
Applies on top of the root AGENTS.md. The TUI fully replaces the classic prompt_toolkit CLI;
activate with loki --tui or LOKI_TUI=1. tui_gateway is ALSO the backend the Desktop app
and the dashboard /chat talk to — changes here have three consumers.
Process model
loki --tui
└─ Node (Ink) ──stdio JSON-RPC── Python (tui_gateway)
│ └─ AIAgent + tools + sessions
└─ renders transcript, composer, prompts, activityTypeScript owns the screen. Python owns sessions, tools, model calls, and slash-command logic. Never move agent behaviour into the renderer.
Transport
Newline-delimited JSON-RPC over stdio: requests from Ink, events from Python. tui_gateway/server.py
is the facade with the method/event catalog; methods live in methods_*.py siblings (methods_config,
methods_complete, methods_browser, methods_bot_relay, ...), event publishing in
event_publisher.py / event_replay.py. Desktop reaches the same server over WebSocket via
apps/shared (JsonRpcGatewayClient). New RPC = a new methods_<topic>.py or an entry in an
existing topical sibling, registered in the table — no if method == ... chain (root shape rules).
Key surfaces
| Surface | Ink component | Gateway method / event |
| Chat streaming | app.tsx + messageLine.tsx | prompt.submit → message.delta / message.complete |
| Tool activity | thinking.tsx | tool.start / tool.progress / tool.complete |
| Approvals | prompts.tsx | approval.request → approval.respond |
| Clarify / sudo / secret | prompts.tsx, maskedPrompt.tsx | clarify.respond, sudo.respond, secret.respond |
| Session picker | sessionPicker.tsx | session.list / session.resume |
| Slash commands | local handler + fallthrough | slash.exec → _SlashWorker; command.dispatch |
| Completions | useCompletion hook | complete.slash, complete.path |
| Theming | theme.ts + branding.tsx | gateway.ready carries skin data |
| Plugin compat notice | — | plugins.compat_report (see plugins/AGENTS.md) |
Shared subagent snapshots
subagent.list({session_id}) returns {subagents, delegations} for the calling
transport's live session. Live child records are pinned to the exact session
record and transport. Child authority is resolved at RPC time against the owning session's
LIVE transport slot, so every authenticated reattach path (prompt.submit, queued drain,
resume, activate, viewer failover) carries it with no registry bookkeeping — never add a
per-record transport sync at an attach site; foreign or retired generations remain inaccessible. last_tool is the last started tool, not an in-flight
indicator. Async completion units are not agents and lack exact generation authority;
delegations remains an empty array for wire compatibility. No dispatch context,
results, callbacks, or routing keys are sent. Clients hydrate from this snapshot
on their existing poll and avoid updates when unchanged.
subagent.tail({session_id, subagent_id}) returns
{subagent_id, available, text, truncated}: the last 16 KiB of the live child's
existing transcript. Poll only the selected detail. Missing/finished/foreign
children return an unavailable empty snapshot; no client-supplied path is opened.
This is live-only, not persisted completion history. Invalid session/transport
returns error 4001. subagent.steer({session_id, subagent_id, text}) remains the
shared control: status: queued acknowledges acceptance, not delivery; final
boundary races are reported by the existing runtime as missed_steer.
subagent.interrupt({session_id, subagent_id}) requires the same exact live
session/transport/generation ownership, including for subtree members. Missing
RPC session authority is rejected; direct in-process interrupt_subagent(id)
retains its legacy unscoped contract.
Slash command flow
- Built-in client commands (
/help,/quit,/clear,/resume,/copy,/paste, ...) are handled locally inapp.tsx. - Everything else →
slash.exec, which runs in the persistent_SlashWorkersubprocess →command.dispatchfallback, which the gateway resolves into a skill / alias / exec directive (a skill command resolves to{type: "skill", message}and is submitted as a normal prompt).
commands.catalog (empty-query list) and complete.slash (typed-query completions) already include
built-ins, user quick_commands, AND skill-derived commands (scan_skill_commands() /
get_skill_commands()) — clients do not need a new RPC to see skills. The command definitions
themselves come from loki_cli/commands.py (loki_cli/AGENTS.md).
Dev commands
cd tui-ui
npm install # first time
npm run dev # watch mode (rebuilds loki-ink + tsx --watch)
npm start # production
npm run build # full build (loki-ink + tsc)
npm run typecheck # tsc --noEmit
npm run lint # eslint
npm run fmt # prettier
npm test # vitestPython tests: tests/tui_gateway/ via scripts/run_tests.sh. TS tests: vitest in tui-ui. A
Python test that asserts about package.json / .ts sources will not run on a JS-only PR — keep
JS-side assertions in vitest (root testing rules). Root TypeScript style rules apply.
Related: web/AGENTS.md (dashboard embeds this TUI over a PTY), apps/desktop/AGENTS.md (own
renderer on the same backend).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

