npcrs

June 12, 2026 · View on GitHub

npcrs logo

Rust core for the NPC system. Mirrors npcpy for function parity.

Modules

Modulenpcpy equivalentDescription
npc_compilernpcpy.npc_compilerNPC, Team, Jinx, Agent/ToolAgent/CodingAgent
gennpcpy.genLLM response (genai), cost, sanitization, image gen
llm_funcsnpcpy.llm_funcsget_llm_response(), check_llm_command()
memorynpcpy.memoryConversation history, knowledge graph, embeddings, search
toolsnpcpy.toolsTool registry, flatten_tool_messages()
datanpcpy.dataWeb search, file loading, text processing
worknpcpy.workJob scheduling, triggers
ml_funcsnpcpy.ml_funcsML model fit/predict/score (via Python subprocess)
npc_arraynpcpy.npc_arrayVectorized inference, ensemble voting
mixnpcpy.mixMulti-agent debate
ftnpcpy.ftFine-tuning (SFT via Python subprocess)
kernelOS kernel: process table, scheduling, IPC (Rust-specific)
processNPC process lifecycle, resource limits
servenpcpy.serveHTTP REST API + MCP server
ffiC-ABI for Flutter/Dart/mobile

See COVERAGE.md for detailed function-by-function parity status.

Build

cargo build --release

Usage as library

use npcrs::{Kernel, NPC, Team};

// Boot kernel with a team directory
let kernel = Kernel::boot("./npc_team", "~/npcsh_history.db")?;

// Execute through the agent loop (tools, delegation, etc.)
let output = kernel.exec(0, "what files are in this directory?").await?;

// Delegate to a specific NPC
let output = kernel.delegate(0, "corca", "refactor this function").await?;

Usage as npcsh (shell)

Build and run from npcsh/rust/:

cd npcsh/rust
cargo build --release
./target/release/npcsh

Or symlink as npc for direct .npc/.jinx execution:

ln -sf $(pwd)/target/release/npcsh ~/.local/bin/npc

# Run NPC files directly
npc ./npc_team/sibiji.npc "hello"

# Run jinx files directly
npc ./npc_team/jinxes/lib/sh.jinx bash_command="echo hi"

# Scaffold a new team
npc init

By default npcsh spawns a Python daemon subprocess per session. For faster startup and concurrent request handling, run the daemon as a persistent service.

macOS (launchd)

# Install the launchd plist
cp scripts/com.npcworldwide.npcsh-daemon.plist ~/Library/LaunchAgents/
launchctl load ~/Library/LaunchAgents/com.npcworldwide.npcsh-daemon.plist
launchctl start com.npcworldwide.npcsh-daemon

# Stop / unload
launchctl stop com.npcworldwide.npcsh-daemon
launchctl unload ~/Library/LaunchAgents/com.npcworldwide.npcsh-daemon.plist

Logs: tail -f /tmp/npcsh-daemon.log

Linux (systemd user service)

# Install the user service
mkdir -p ~/.config/systemd/user
cp scripts/npcsh-daemon.service ~/.config/systemd/user/
systemctl --user daemon-reload
systemctl --user enable --now npcsh-daemon

# Stop
systemctl --user stop npcsh-daemon

Logs: journalctl --user -u npcsh-daemon -f

The Rust client connects to ~/.npcsh/daemon.sock automatically; if the socket is missing it falls back to subprocess mode. Override the socket path with the NPCSH_DAEMON_SOCKET environment variable.

Cross-compile for Android

# Add targets
rustup target add aarch64-linux-android x86_64-linux-android

# Set NDK env
export ANDROID_NDK_HOME=/path/to/ndk
export CC_aarch64_linux_android=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android34-clang
export AR_aarch64_linux_android=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar

# Build
cargo build --lib --target aarch64-linux-android --release

# Copy to Flutter project
cp target/aarch64-linux-android/release/libnpcrs.so /path/to/flutter/android/app/src/main/jniLibs/arm64-v8a/

FFI

Produces cdylib and staticlib for embedding in Flutter, Android, iOS, desktop apps. See src/ffi/mod.rs for the C-ABI exports and eazy-phone/lib/npc/npcrs_bindings.dart for the Dart bindings.

DB

Uses the same ~/npcsh_history.db and conversation_history table schema as the Python npcsh. Both versions can share the same database.

License

MIT