Kage Sensei is a TypeScript monorepo for AI coding memory and project-aware mentoring. It contains two related tools:
kage: a CLI memory layer for AI coding tools, powered by MemWal on Walrus.sensei: a project-aware mentor with a CLI and web interface, also backed by MemWal and Walrus.
The tools share the same goal: keep useful project knowledge available across AI coding sessions.
- Compression-first memory storage for Kage (
@kage-sensei/compression):- gzip compression with reversible fallback
- local CCR metadata store
- relevance scoring and token budget fitting
- deterministic context alignment for cache-friendly prefixes
- Kage local learning loop:
kage learnmines local session failures- writes generated guidance blocks to
CLAUDE.mdandAGENTS.md - stores learned rules in
${KAGE_LESSONS_DIR:-/home/kage/lessons}/lessons.json
- Kage MCP server:
- stdio transport for local MCP clients
- Streamable HTTP transport for remote MCP clients
- tools:
kage_remember,kage_recall,kage_context,kage_stats,kage_learn,kage_learn_start,kage_learn_poll,kage_learn_results,kage_export,kage_suggest,kage_analyze,kage_fetch_sessions,kage_cleanup kage_recall/kage_contextreturn CCR-backed memories to stay consistent withkage_stats
- Sensei Web MCP endpoint:
POST /mcp(initialize + message)GET /mcp(resume SSE stream)DELETE /mcp(terminate session)
- Sensei Web auth and secure upload:
POST /api/auth/login(returns JWT)POST /api/auth/change-password(requires JWT)POST /api/sessions/upload(requires JWT +x-api-key)POST /api/sync-project(requires JWT, accepts local source ZIP for Learn V2)GET /api/statsandGET /api/learn-historyfor dashboard metricsGET /loginandGET /dashboard(Tailwind-based developer dashboard)
- The Bridge local sync path:
packages/cli/sync.jszips a local project'ssrc/directory- uploads it to the cloud Sensei API
- runs Kage Learn V2 server-side
- stores the resulting project lessons in Walrus via MemWal
- Landing app:
- standalone Astro + Tailwind marketing site at
apps/landing - includes branded OG/favicons and legal pages (
/privacy,/terms) - ready for static deploy to Vercel/Netlify
- standalone Astro + Tailwind marketing site at
Kage stores and retrieves long-term developer memory for tools such as Codex, Claude Code, and OpenCode.
Main commands:
kage remember: save a memory.kage recall: search saved memories.kage context: print context for an AI coding session.kage why: retrieve reasoning behind a previous decision.kage stats: show compression and storage savings.kage mcp serve --stdio|--http: expose Kage over MCP.kage learn: mine local failures into reusable project rules.kage cleanup: detect legacy remote memories missing from CCR and optionally migrate them.
See kage/README.md for the full Kage guide.
Sensei is a project-aware mentor that stores project memory, ingests repositories, and answers questions using remembered project context.
The Sensei CLI supports:
sensei note: store a project memory.sensei load: ingest a git repository into memory.sensei ask: ask the mentor about the project.sensei recall: search project memory directly.sensei context: print context for AI tools.sensei team: manage team access.
Sensei also includes a web app with a Hono API server and React/Vite client.
Sensitive routes are protected by JWT middleware for /api/* (except /api/health and /api/auth/login) and /dashboard.
.
├── kage/ # Kage CLI package
│ └── packages/
│ └── compression/ # Shared compression module
├── apps/
│ └── landing/ # Astro landing page (static deploy)
├── packages/
│ └── cli/ # Local Bridge sidecar for source sync
├── sensei/
│ ├── cli/ # Sensei CLI package
│ └── web/ # Sensei web client and API server
├── Dockerfile
├── docker-compose.yml
├── .env.ec2.example
├── LICENSE
└── README.md
- Node.js 22+ or Bun 1+
- pnpm
- MemWal credentials from
memory.walrus.xyz
Sensei also needs an InferStack-compatible API key for mentor responses.
cd kage
pnpm install
cp .env.example .env
pnpm build
node dist/index.js --helpcd sensei/cli
pnpm install
cp .env.example .env
pnpm build
node dist/index.js --helpcd sensei/web
pnpm install
pnpm dev:serverIn another terminal:
cd sensei/web
pnpm dev:clientYou can run Kage Sensei with one container (Sensei Web + Kage runtime) using Docker Compose.
cp .env.ec2.example .env.ec2
# fill credentials
ENV_FILE=.env.ec2 docker compose up --build -dHealth checks:
curl -s http://localhost:3000/health
curl -X POST http://localhost:3000/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}'Published image:
bernieweb3/kage-sensei:latest
Pull and run:
docker pull bernieweb3/kage-sensei:latest
docker run --rm -p 3000:3000 --env-file .env.ec2 bernieweb3/kage-sensei:latestFor a full EC2 walkthrough, see docs/deploy/aws-ec2-docker-compose.md.
The runtime image keeps TypeScript source code at:
/app/kage/src/app/sensei/web/server/src
This supports meta-learning demos where the deployed MCP server runs kage_learn against its own source. The image also includes unzip for Bridge sync uploads and sets KAGE_LEARN_ALLOWED_ROOTS=/app,/tmp.
Kage Sensei uses MCP Streamable HTTP transport (POST /mcp, GET /mcp, DELETE /mcp), so you can connect directly without mcp-remote.
Codex config example:
[mcp_servers.kage-sensei]
url = "https://kage-sensei.hackon.team/mcp"Remote initialize test:
curl -X POST https://kage-sensei.hackon.team/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}'After deploying the current Docker image, test that the MCP server can learn from its own source code:
Call kage_learn with projectDir="/app/kage/src", maxFiles=20, maxLessons=10, debug=true.
Then call kage_learn with projectDir="/app/sensei/web/server/src", maxFiles=20, maxLessons=10, debug=true.
Report files analyzed, lessons found, patterns detected, discovered .ts files, and metadata breakdown.
Expected behavior:
- The server discovers
.tssource files under both runtime paths. - Learn V2 checks heuristic patterns such as TODO density, console usage, long functions, duplicate code, hardcoded secrets, deep nesting, and magic numbers.
- Matching patterns return lessons and pattern metadata.
See docs/devlog/2026-06-19.md and the related Learn V2 foundation notes in docs/devlog/2026-06-18.md.
The Bridge lets a local project send source code to the cloud MCP server without making the cloud server access local files directly.
Server route:
POST /api/sync-project
Accepted input:
multipart/form-datafile: ZIP archive containing source codeprojectName: project identifiergitUrl: repository URL orlocal
Required header:
Authorization: Bearer <jwt-from-/api/auth/login>
The server extracts the ZIP to a per-request temp directory, validates archive paths before extraction, runs kageLearnV2, stores a project_sync memory in Walrus, returns scan/lesson counts and the MemWal job id, then removes the temp directory.
Default safety limits:
- ZIP size:
50MBviaKAGE_SYNC_MAX_ZIP_BYTES - Rate limit:
10requests per15minutes viaKAGE_SYNC_RATE_LIMIT_MAXandKAGE_SYNC_RATE_LIMIT_WINDOW_MS
Local CLI setup:
cd packages/cli
npm installSync a local project:
cd /path/to/local/project
KAGE_CLOUD_URL=https://kage-sensei.hackon.team \
KAGE_TOKEN=<jwt-token> \
node /path/to/kage-project/packages/cli/sync.jsThe CLI reads Git metadata from .git/config, zips src/, skips generated directories, posts to /api/sync-project, and prints the server response.
kage_stats reads local CCR metadata (${KAGE_DATA_DIR}/ccr.json). If old remote-only memories exist in MemWal from earlier runs, they can create mismatches with recall results.
Use kage_cleanup to detect these legacy entries and optionally migrate them into fresh CCR-backed records:
cd kage
pnpm build
node dist/index.js cleanup --query E2E --limit 50
# optional migration:
node dist/index.js cleanup --query E2E --limit 50 --migrate-to-walrusThe command writes a report to ${KAGE_DATA_DIR:-/home/kage/data}/cleanup-report.json.
Upload session logs from external systems to feed kage_learn.
Route:
POST /api/sessions/upload
Accepted inputs:
application/json: body must be an array of session objectsmultipart/form-data: include one JSON file (fieldfilerecommended)
Required headers:
Authorization: Bearer <jwt-from-/api/auth/login>x-api-key: <API_SECRET_KEY>
Stored path and filename format:
${KAGE_DATA_DIR:-/home/kage/data}/sessions/session-{timestamp}-{randomId}.json
Example flow:
# 1) Login
TOKEN=$(curl -sS -X POST http://localhost:3000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"password":"123456"}' | jq -r .token)
# 2) Upload sessions
curl -X POST http://localhost:3000/api/sessions/upload \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${TOKEN}" \
-H "x-api-key: ${API_SECRET_KEY}" \
-d '[{"id":"session-1","events":[{"type":"message","text":"hello"}]}]'Kage and Sensei use MemWal/Walrus credentials:
MEMWAL_PRIVATE_KEYMEMWAL_ACCOUNT_IDMEMWAL_SERVER_URLMEMWAL_NAMESPACEfor Kage, optional
Sensei uses additional project and model settings:
SENSEI_PROJECT_IDINFERSTACK_API_KEYINFERSTACK_BASE_URL, optionalINFERSTACK_MODEL, optional
Auth settings for Dashboard and protected API routes:
JWT_SECRET(recommended for login/session token signing)JWR_SECRET(legacy alias accepted ifJWT_SECRETis not set)ADMIN_PASSWORD_HASH(recommended in Render env)AUTH_ENCRYPTION_KEY(required only if you store rotated hash in encrypted file)API_SECRET_KEY(required for/api/sessions/upload)CLAUDE_API_KEY(forkage_fetch_sessions)OPENAI_API_KEY(forkage_fetch_sessions)COMPATIBLE_API_KEYandCOMPATIBLE_BASE_URL(for compatible providers inkage_fetch_sessions)KAGE_HOME(default/home/kage)KAGE_DATA_DIR(default${KAGE_HOME}/data)KAGE_LESSONS_DIR(default${KAGE_HOME}/lessons)KAGE_ANALYZE_PER_FILE_TIMEOUT_MS(default5000)KAGE_ANALYZE_TOTAL_TIMEOUT_MS(legacy fallback, default600000)KAGE_TOTAL_TIMEOUT_MS(global MCP tool timeout, default600000)KAGE_ANALYZE_MAX_FILES(default50)KAGE_SYNC_MAX_FILES(default50)KAGE_SYNC_MAX_LESSONS(default20)KAGE_SYNC_TIMEOUT_MS(default60000)KAGE_SYNC_UNZIP_TIMEOUT_MS(default30000)KAGE_SYNC_MAX_ZIP_BYTES(default52428800)KAGE_SYNC_RATE_LIMIT_MAX(default10)KAGE_SYNC_RATE_LIMIT_WINDOW_MS(default900000)
Generate admin password hash (default password is 123456):
cd sensei/web
pnpm auth:generate-hashDo not commit real .env files. Use .env.example files as templates.
This project is licensed under the terms in LICENSE.