Skip to content
K4nesPublic

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PiKo

PiKo is a self-hosted workspace for a small team of persistent AI agents.

Pi is the lead. You chat with Pi. Pi can create specialist agents on request. Each agent keeps its own conversation, model, instructions, and memory. Agents can hand a task to another agent and return the result to the caller's thread.

The app runs as one Node.js process with two SQLite databases. It is designed for one owner and a 2 vCPU / 2 GB host. There is no queue service, no external database, and no platform lock-in.

Features

  • Durable agent runs. Pi Durable owns model turns, tool calls, retries, checkpoints, and crash recovery. A restarted process resumes queued or interrupted work instead of losing it.
  • Persistent agents. Every agent has one Pi conversation and a separate workspace.
  • Agent team. The lead can create specialists. A task can move across agents with a cycle guard and a Stop control.
  • Memory. Each agent can store and recall durable facts. Memory is separate for every agent.
  • Reasoning effort. The composer starts at Auto and offers the levels the selected model supports. The choice is stored on the active agent.
  • Distinct agents. New agents get a random face and colors that differ from the lead.
  • Tools. Agents can use read, write, edit, bash, fetch_url, web_search, remember, recall, list_agents, and handoff. Only the lead has create_agent.
  • Models. Use the built-in OpenRouter provider, or add any number of named custom OpenAI-compatible providers. The provider catalog supplies model ids, names, and context windows.
  • Local first. The API and the React client are served by the same process. Data stays on your disk.
  • Optional password login. Use a password before exposing the server.

Requirements

  • Node.js 22.19 or newer.
  • npm.
  • Linux with bubblewrap for sandboxed agent bash.
  • Docker only when you run the Docker test stack.

On Debian or Ubuntu:

sudo apt install bubblewrap

The server fails closed for agent bash when bubblewrap is missing. PIKO_ALLOW_UNSANDBOXED_BASH=1 is for isolated test hosts only.

Quick start

npm install
cp .env.example .env
npm run dev

Open http://127.0.0.1:5173.

With APP_PASSWORD unset, every request is the local owner. Set APP_PASSWORD to enable the login page.

Add at least one model before you chat. You can use the Settings → Models screen, or seed a provider from .env:

MODEL_PROVIDER_ID=openrouter
MODEL_PROVIDER_NAME=OpenRouter
MODEL_BASE_URL=https://openrouter.ai/api/v1
MODEL_API_KEY=your-key
MODEL_ID=deepseek-ai/DeepSeek-V4.1-Flash-1017

MODEL_BASE_URL and MODEL_API_KEY are required. On first start PiKo fetches <MODEL_BASE_URL>/models and seeds every model it finds. MODEL_ID is optional: the first catalog model becomes the default unless you name one. MODEL_PROVIDER_ID is openrouter or a custom id such as custom; MODEL_PROVIDER_NAME is the display name. Seeding happens only while the app has no provider. After that, the Models screen is authoritative.

npm run dev runs the server with Vite in middleware mode. Client edits hot-reload. Server edits restart the process.

VPS quick setup (Tailscale)

Install PiKo on a Debian or Ubuntu VPS from a prebuilt release. Nothing is cloned or built on the server. PiKo binds directly to the VPS Tailscale IPv4 address (for example http://<tailscale-ip>:8787), so it works even with Cloudflare/custom browser DoH enabled, and no public port is opened. The full operational guide is docs/vps-setup.md.

Private repository (current)

Create a fine-grained GitHub token with Contents: Read for this repository, then run:

Raw file URLs do not work for a private repository, so fetch install.sh through the GitHub contents API:

export GITHUB_TOKEN=<fine-grained-token>
curl -fsSL \
  -H "Authorization: Bearer $GITHUB_TOKEN" \
  -H "Accept: application/vnd.github.raw" \
  https://api.github.com/repos/K4nes/PiKo/contents/scripts/install.sh \
  -o /tmp/piko-install.sh \
  && sudo env GITHUB_TOKEN="$GITHUB_TOKEN" bash /tmp/piko-install.sh \
  && rm -f /tmp/piko-install.sh

Saving the script first (instead of piping curl | sudo bash) keeps your terminal attached to sudo so piko setup can prompt interactively on Ubuntu (sudo-rs / use_pty). sudo env GITHUB_TOKEN="$GITHUB_TOKEN" passes the token cleanly on both classic sudo and sudo-rs. The installer resolves releases/latest from K4nes/PiKo (override with PIKO_REPO) through the GitHub API, downloads the release asset with the token, verifies .sha256 when the release has one, and starts piko setup.

If you already have a checkout, copy scripts/install.sh to the VPS and run sudo env GITHUB_TOKEN="$GITHUB_TOKEN" bash install.sh instead.

From a local tarball

Build once on a development machine:

npm run pack:release

Copy dist/release/piko.tar.gz to the VPS, then run the installer from a checkout, or set the tarball with any installer copy:

sudo PIKO_TARBALL=/root/piko.tar.gz bash scripts/install.sh

PIKO_TARBALL also accepts a direct URL. Use it to test before cutting a GitHub release.

Public repository

Once the repository is public, no token is needed:

curl -fsSL https://raw.githubusercontent.com/K4nes/PiKo/main/scripts/install.sh -o /tmp/piko-install.sh \
  && sudo bash /tmp/piko-install.sh \
  && rm -f /tmp/piko-install.sh

What the installer and piko setup configure

  1. Debian packages, Node.js 24 LTS when needed, bubblewrap, and Tailscale.
  2. A piko system user and /var/lib/piko owned by it.
  3. Direct Tailscale IP access. Setup connects Tailscale, reads the VPS Tailscale IPv4 dynamically, clears any legacy tailscale serve route on :443, and prints http://<tailscale-ip>:8787.
  4. /var/lib/piko/.env (mode 0600): HOST=<tailscale-ip>, PORT=8787, a required APP_PASSWORD, a stable encryption secret, and an optional first model provider. Setup offers OpenRouter or a custom OpenAI-compatible endpoint, fetches <base URL>/models, and records the chosen default model. Re-running setup asks whether to keep that provider, so it stays reconfigurable.
  5. /etc/systemd/system/piko.service, running as piko with Restart=always. It never runs as root and does not restrict bubblewrap user namespaces.

Daily commands

piko status     # version, service, health, and Tailscale URL
piko logs       # follow the journal (--no-follow, -n <lines>)
piko doctor     # check Node, bubblewrap, data, service, health, Tailscale
piko update     # install the latest release, or --tarball / --version / --repo
piko setup      # change configuration without losing existing values
piko restart    # also start and stop
piko uninstall  # keeps DATA_DIR unless you pass --purge

Security note

Agent bash keeps network access. Restrict the PiKo VPS node with a Tailscale ACL so it can reach only what it needs, for example no access to laptops or other sensitive devices on the tailnet. Restricting outbound access from tag:piko limits what a prompt-injected agent can reach.

Using the app

  1. Chat with Pi. Send a request in the lead thread.
  2. Create an agent. Ask Pi directly, for example: Create a Research agent that checks primary sources.
  3. Let agents hand off work. The recipient receives a task entry. The caller receives a result card.
  4. Stop a chain. Use the Stop control to abort running Pi tasks and block new handoffs in that chain.
  5. Edit an agent. Use Profile for name and avatar, Mind for instructions, and Memory for facts. A specialist can be deleted from Profile; the lead cannot be deleted.
  6. Change models and appearance. Use the Settings screens.

A task can visit each agent once. There is no numeric handoff limit.

Models and providers

Open Settings → Models to configure providers. OpenRouter is built in. You can add any number of named custom OpenAI-compatible providers; each one gets its own card, catalog, refresh, and delete controls.

  1. Choose the built-in OpenRouter provider, or add a Custom provider.
  2. For a custom provider, set:
    • Provider name: shown beside this provider's models. Defaults to Custom.
    • Base URL: an OpenAI-compatible endpoint such as https://api.example.com/v1.
    • API key.
  3. Choose Test connection to check the endpoint without saving.
  4. Save the provider to encrypt and store the key, then fetch the catalog from <base URL>/models.
  5. Select the default chat model. An agent can override it in its Profile settings.
  6. Refresh a provider to re-read its catalog, or delete a custom provider. Deleting one clears agent overrides and the default model when they point at it.

OpenRouter uses https://openrouter.ai/api/v1. A custom provider must expose GET /models and the OpenAI-compatible chat API.

The Models screen shows each provider's catalog separately. Context windows come from provider metadata (context_length, context_window, top_provider, or equivalent fields). PiKo does not accept a manual context-window override. A model whose provider omits the value is left unknown.

Configuration

Copy .env.example to .env for local work.

Variable Default Purpose
APP_PASSWORD unset Password for /login. Unset means local-owner mode. Set it before exposing the server.
KEY_ENCRYPTION_SECRET generated Encrypts provider keys at rest. When unset, the server writes DATA_DIR/secret.key once. Keep it stable.
PIKO_ENV_FILE unset Env file loaded before DATA_DIR/.env and ./.env.
PIKO_REPO unset GitHub repository used by piko update.
DATA_DIR ./data Directory for databases, workspaces, and secret.key.
HOST 127.0.0.1 Bind address. A non-loopback address requires APP_PASSWORD.
PORT 8787 HTTP port.
MODEL_PROVIDER_ID inferred Provider id for the first-run seed: openrouter or a custom id such as custom.
MODEL_PROVIDER_NAME inferred Display name for the first-run provider.
MODEL_BASE_URL unset OpenAI-compatible base URL for the first provider. <MODEL_BASE_URL>/models is fetched on first start.
MODEL_API_KEY unset Key for that provider. Falls back to OPENROUTER_API_KEY.
OPENROUTER_API_KEY unset Alternative key source for the first-run provider.
MODEL_ID first catalog model Optional default model id.
MODEL_NAME MODEL_ID Display name when the seed falls back to a single model.
ALLOW_INSECURE_DEV unset Test hosts only: allow a non-loopback HOST without a password.
PIKO_ALLOW_UNSANDBOXED_BASH unset Test hosts only: skip bubblewrap for agent bash.

Tests

Native browser tests:

npm run test:e2e

The suite starts the app on http://127.0.0.1:5173, resets test data before each test, and runs 36 tests, including the smoke test in tests/example.e2e.ts. Model-backed tests need MODEL_API_KEY. The suite defaults to River's OpenAI-compatible endpoint and deepseek-ai/DeepSeek-V4.1-Flash-1017.

Run one file or watch it:

npx e2e run tests/02-lead.e2e.ts
npx e2e run tests/08-handoff.e2e.ts --headed

Docker tests:

npm run test:docker

This builds the app image and runs the same suite in a Playwright container. It needs Docker and a model key in .env or MODEL_API_KEY.

Useful test commands:

npx e2e list
npx e2e report
npx e2e doctor
npx e2e run --last-failed

Production

Build and run:

npm ci
npm run build
APP_PASSWORD=... KEY_ENCRYPTION_SECRET=... DATA_DIR=/var/lib/piko npm start

The server listens on 127.0.0.1:8787 by default. Put a TLS reverse proxy in front. The session cookie is marked Secure when the request uses HTTPS or X-Forwarded-Proto: https.

Docker:

docker build -t piko .
docker run -d --name piko \
  -p 8787:8787 \
  -e APP_PASSWORD='replace-with-a-strong-password' \
  -e KEY_ENCRYPTION_SECRET='replace-with-a-stable-random-secret' \
  -v piko-data:/data \
  piko

The image binds 0.0.0.0, so it requires APP_PASSWORD. Health check:

curl http://127.0.0.1:8787/api/health

Data and backup

Everything lives under DATA_DIR:

  • app.sqlite — agents, memory, tasks, settings, providers, models, and the agent-to-conversation map.
  • pi.sqlite — Pi transcripts, live run state, submissions, and Pi tasks.
  • workspaces/<agent-id>/ — files used by the read, write, edit, and bash tools.
  • secret.key — generated when KEY_ENCRYPTION_SECRET is unset.

One process must own DATA_DIR. Do not start two replicas on the same directory.

To back up, stop the server and copy the whole DATA_DIR, including SQLite WAL/SHM files and agent workspaces.

How recovery works

  • Pi stores a submission before it starts work. A repeated request id returns the original submission instead of running the work twice.
  • Model turns and replay-safe tool calls checkpoint to SQLite. On startup, the harness resumes live work and reattaches app tasks.
  • A side-effecting tool that was interrupted returns an error result to the model instead of repeating an unsafe action.
  • The app's tasks table remains the chain ledger: root, parent, visited agents, status, result, and stop flag.

Security model

  • One owner, not a multi-tenant service. A reachable server is an owner session unless APP_PASSWORD is set.
  • Agent file tools are confined to DATA_DIR/workspaces/<agent-id>. Paths and symlinks that resolve outside are rejected.
  • Agent bash runs in a bubblewrap mount namespace with the workspace mounted, system paths read-only, a private /tmp, and a cleared environment.
  • Bash keeps network access. An agent can read public web content and write inside its workspace, but cannot read the databases or server environment through bash.
  • Provider keys are encrypted with a key derived separately from the session key. A stored key is never sent to a new base URL.
  • fetch_url blocks loopback, private, link-local, and metadata addresses. It follows redirects manually and caps response size.
  • Web pages, tool output, handoff text, and memory are marked as untrusted data in prompts. Prompt injection remains a risk. Treat the agent team as trusted with its workspace and network.

Architecture

Browser (React SPA)
  |  HTTP + SSE
  v
Node.js process
  +-- Hono API and session auth
  +-- PiKoRuntime
  |     +-- Pi Harness  ->  pi.sqlite
  |     +-- AppDatabase ->  app.sqlite
  +-- per-agent workspaces under DATA_DIR

Pi Durable owns the execution path. PiKo owns the roster, memory, tasks, settings, providers and models, and the mapping from agent id to Pi conversation id.

Troubleshooting

  • Port already in use: PORT=5174 npm run dev, or stop the process with lsof -i :5173.
  • Model error: open Settings → Models, use Test connection, then Save & sync (or Save provider for a new custom provider), and set a default model.
  • Agent bash fails immediately: install bubblewrap. Use PIKO_ALLOW_UNSANDBOXED_BASH=1 only in an isolated test environment.
  • Tests cannot call the model: check MODEL_API_KEY or OPENROUTER_API_KEY, plus MODEL_BASE_URL and the optional MODEL_ID, in .env.
  • Password reset: changing APP_PASSWORD invalidates old sessions. Provider keys stay readable while KEY_ENCRYPTION_SECRET or secret.key is unchanged.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages