Skip to content
tobertPublic

About

会術 Kaijutsu - a mad science project agent fusing music and AI

Resources

Stars

5 stars

Watchers

0 watching

Forks

Repository files navigation

会術 Kaijutsu

The kernel’s central responsibility is coordinating anticipation and commitment on the shared pulse. Each model can have its own pace, provided its output arrives while it’s still useful.

Kaijutsu is an instrument for people and models working together across contexts. Players prepare work ahead of the moment it matters; the kernel coordinates shared state and accepted decisions. Music makes this concrete: models can take seconds to produce a phrase or analyze a clip, and binary media can travel over SFTP while the performance continues. The shared pulse gives that work a place in time. Whether a result is ready and still valid determines how it can join the performance.

This is the direction we judge the implementation against. The timing and shared-clock design is in Time and the pulse, and the hardware and model-placement rules are in Audio I/O. The iteration plan tracks the gaps between that direction and the code.

Developer Notes from Amy 2026-06-26

Kaijutsu started as a "more serious" version of an SSH MUD that nerdsniped me as I built out an equipment system for models. That led to having rooms have tools in them too. The system felt cool but then I had to face the context problem: how do I bound context for each model? How should I compact for them? Could it be customized by role, room, and other dimensions?

I was also working on variations of hootenanny which was a big pile of ideas and experiments while I learned about music models, real-time sound, and a few other things. I've retired it. I learned a lot but it was time to start over.

Kaijutsu is a maximal project, where I spend my leisure coding time building something ambitious and occasionally whimsical. Which is to say, it's turned into an operating system that lives in a process. It has its own shell, coreutils, and default assumptions around concurrent change by multiple agents and users, making it more like a shared game world than a typical developer tool. Also unlike developer tools, contexts can have a beat, and features exist for sliding window contexts with KV cache optimizations.

As I write this developer note, it's been about 6 months since the project started with "what if my agent had a bevy frontend and its own shell" has turned into kaish maturing rapidly as part of kaibo. In a lot of ways kaibo is a more pragmatic take on a lot of what I've explored in kaijutsu so far.

The curious are welcome to give it a try, but I wouldn't call this ready for consumption yet. The idea blender is still whirring and only the fast and the foolish should put their hands in at this point. If that's your jam, welcome, find me on Bluesky as @renice.bsky.social or open an issue on Github.

Introduction

Kaijutsu is an AI agent system built around context forking and drifting, with some experimental features for agentic music production. The core is the kaijutsu kernel: one authoritative sequencer that many players — humans, models, connected apps — write to at once. Clients send rich commands expressing intent; the kernel validates, orders, and commits them, then projects the accepted facts back out as an event stream. To make authentication simple and secure, kaijutsu uses an embedded SSH server and ssh keys exclusively to identify users.

Kaijutsu is deliberately not a partition-tolerant peer-to-peer system. Contexts are multi-writer because many players share one kernel, not because replicas reconcile: there is one place that decides what happened, and recovery is asking it again rather than merging with a peer. Block text is a plain Rust String, and concurrent merge into a kernel document is structurally impossible.

The stance behind all of it: kaijutsu is an instrument, not a harness. You play it, a model plays it, and if you hand someone a connected app they play it too — many hands on one keyboard. The kernel is the instrument's body: it supplies what a turn needs and doesn't play the turn itself.

The kaijutsu kernel maintains a DAG (directed acyclic graph) of contexts. Contexts can be forked with different models, content redacted/repaired, and other changes that usually mean breaking KV caches. Content can be sent across contexts with 'drifting'. Drifts are blocks of content that a user or agent can send from one context to another, with the relationship tracked by kaijutsu. This can be inspected and visualized in the app or over MCP.

Status

Kaijutsu is not released yet. The kernel feels solid and reliable, and the UI is coming along.

You may need my branch of kaish for this to build. Kaish will go back to cargo versions soon.

-Amy

Quick Start

# First time only: create your root character and bind your SSH key
# (see docs/character.md, "Bootstrap: the person creates themself")
cargo run -p kaijutsu-server -- init --as <your-name> --key ~/.ssh/id_ed25519.pub

# Terminal 1: Server
cargo run -p kaijutsu-server

# Check what's registered
cargo run -p kaijutsu-server -- list-keys
cargo run -p kaijutsu-server -- list-characters

# Terminal 2: Client
cargo run -p kaijutsu-app

A new kernel has no model backends, so a model turn fails until you configure a backend and give a character a model on it. In a client's shell:

# DeepSeek, with the key in an environment variable or a file
kj backend set deepseek --kind deepseek --api-key-env DEEPSEEK_API_KEY --api-key-file ~/.deepseek-key
kj backend model set deepseek deepseek-flash --context-window 1000000 --max-tokens 65536 --effort high
kj character create <character> --rc coder --model deepseek/deepseek-flash
kj context create <character> --name <label>

# Anthropic
kj backend set anthropic --kind anthropic --api-key-env ANTHROPIC_API_KEY --api-key-file ~/.anthropic-key.txt

# An OpenAI-compatible local server that takes no key
kj backend set ollama --kind openai --base-url http://localhost:11434/v1 --key-optional

# The semantic index's embedding model on that server; applies at the next server start
kj backend model set ollama embeddinggemma-2:270m-q8_0-text --embedding-profile embeddinggemma
kj embedding set ollama/embeddinggemma-2:270m-q8_0-text --dimensions 768

# OpenAI models on a ChatGPT Plus or Pro plan, signed in rather than keyed
kj backend set gpt-plan --kind chatgpt
kj backend login gpt-plan                          # prints an address to open
kj backend login gpt-plan --callback '<address>'   # the address the browser ends on

# A Decisions API, which answers gate decisions and runs no chat turn
kj backend set jev --kind decisions --base-url https://openrouter.ai/api/alpha/decisions \
  --api-key-file ~/.openrouter-key
kj character slot set <character> gate jev/typesafe/jev-1.13

The kernel reads an API key from the variable or the file the row names; it never stores the key. A chatgpt backend has no key: its sign-in tokens live in credentials/ under the kernel's data directory, at mode 0700, and refresh as needed. kj backend --help lists every flag.

Code Style

Do not run cargo fmt. rustfmt.toml sets disable_all_formatting, so fmt and fmt --check are both no-ops. Match the code around you and move on.

Most of this codebase is written by models, which emit stock-rustfmt-shaped Rust already — measured, line lengths are p99=93 against rustfmt's default 100, and every config we tried drifted further from the existing code than plain defaults. So formatting buys ~3500 hunks of churn, some of it worse to read, to fix a coordination problem a single-maintainer repo doesn't have.

The one real argument is merge determinism: enforced formatting makes a file's text a function of its AST, so parallel sessions can't conflict unless they actually disagree. Revisit when we hit a formatting-only merge conflict — then format per-crate with a .git-blame-ignore-revs.

Crates

kaijutsu-types

The relational foundation: typed IDs, principals, credentials, blocks, kernels, and context metadata. Pure leaf crate with no internal kaijutsu dependencies — read this first when learning the codebase.

kaijutsu-kernel

The kernel holds your filesystem, models, MCPs, and contexts behind a remote SSH server — the shared body everyone plays. It offers its own VFS, an MCP broker for tool dispatch, an LLM registry, a drift router, and a pub/sub FlowBus. Contexts can be forked any time, at which point the context can be edited and even switch models and tools.

kaijutsu_kernel::blocks holds the block document model and BlockStore. Documents are DAGs of blocks — each block carries metadata (role, kind, status, parent) and a plain String of text.

kaijutsu-server

SSH + Cap'n Proto RPC host. It authenticates connections through SQLite-backed public keys, admits requests to the kernel, and translates results and event subscriptions for clients. The kernel owns sequencing and accepted shell/model execution; the server owns transport and connection state. The beat scheduler is still hosted here.

kaijutsu-client

RPC client library. ActorHandle provides a Send+Sync interface, broadcast subscriptions for server events and connection status, and automatic reconnection that re-registers subscriptions.

kaijutsu-cas

Content-addressed blob store. Hash, stage, and seal binary content (images, audio, attachments) by content hash, with metadata and references that point into blocks.

kaijutsu-agent-tools

Detects which AI coding tool (Claude Code, Gemini CLI, etc.) is hosting the current process, by walking parent processes and reading session metadata. Used to correlate kaijutsu sessions with their host agent.

kaijutsu-abc

Parser and MIDI generator for ABC music notation. Produces a structured AST plus SMF format 0 MIDI bytes. Used by abc_block so models can compose music that renders as both standard staff notation and audio.

kaijutsu-audio

FFI-free audio/render types: the mime-keyed RenderCue wire cue, the clip record (docs/audio-io.md), and the beat phasor/timebase used by the metronome. Sinks in kaijutsu-audio-runtime own the actual hardware. The timing doctrine — emission-stamped wire artifacts, receiver back-dating, staleness ladder, the deadband-locked phasor ("the local clock is the truth between references") — lives in docs/time.md.

kaijutsu-audio-runtime

Bevy-free MIDI and PCM runtime, hosted by the kaijutsu-audiod SSH client — the sole hardware owner; the app has no hardware I/O. The kernel drives playback; the runtime owns local hardware. See Audio I/O for device selection, capture, and systemd setup.

kaijutsu-hyoushigi

拍子木 — the beat/timing substrate: tracks, timelines, cells, speculation and commit. The shared score that musicians (model contexts) play onto.

kaijutsu-editor

Kernel-owned vi editing sessions (EditorCore, pure modalkit vim). The app is one renderer among many possible drivers; see docs/input.md.

kaijutsu-viz

Pure layout/geometry helpers for the time well context browser.

kaijutsu-index

Semantic vector indexing through an HTTP embedding service, with local HNSW nearest-neighbor search, density-based clustering, and persistent keyword/gist synthesis. Kaijutsu owns content selection and caching; the service owns model loading and inference. Query/document purpose, model identity, and normalization are explicit in the embedding interface. Automatic synthesis is disabled; kj synth <context> runs it on demand and reuses unchanged results. Add --force to recompute synthesis.

kaijutsu-mcp

MCP server exposing the kernel to Claude Code, Gemini CLI, opencode, and other MCP clients. Can run standalone (in-memory) or connected to kaijutsu-server.

cargo run -p kaijutsu-mcp

See crates/kaijutsu-mcp/README.md for tool documentation and configuration.

kaijutsu-telemetry

OpenTelemetry integration behind a telemetry feature flag. W3C TraceContext propagation through Cap'n Proto RPC, differentiated sampling rates via KaijutsuSampler, standard OTel envvars (OTEL_EXPORTER_OTLP_ENDPOINT).

kaijutsu-app

Bevy 0.18 GUI client with custom MSDF text rendering, vim-style focus-based input, a tiling window manager, and the time well — a 3D ring-carousel context browser where contexts seat on rings by idle age. See crates/kaijutsu-app/README.md for details on text rendering, theming, and the UI architecture.

Documentation

Doc Purpose
AGENTS.md System architecture, crate map, and working rules
docs/instrument-design.md The instrument stance, shared trust, and capabilities/loadouts
docs/character.md Characters, performers, and senpai–kohai
docs/contexts.md Contexts, conversations, forks, drift, rotations, and shadows
docs/rc.md /config, rc lifecycles, system prompts, and kaish execution
docs/approval-identity.md Turn identity, review routing, gate.toml, and the council
docs/input.md Input routing, vi editor sessions, and file buffers
docs/time.md The one timebase, pulse, tracks, and hyoushigi
docs/audio-io.md audiod, PCM rendering, MIDI profiles, and audio inference
docs/operating.md Operating the service and containers
docs/writing.md STE prose style and the canonical Terms table
docs/devlog.md Decisions and lessons, oldest to newest
docs/issues.md Open work items

About

会術 Kaijutsu - a mad science project agent fusing music and AI

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages