pi-server AGENTS.md

Repository instructions for pi-server, a server whose communication protocol and session handling define its architecture.

In plain words
What is it for?
Changing command dispatch, session behaviour, stores, protocol types, release documentation, and other cross-cutting parts of pi-server.
Why use it?
They point agents to the authoritative protocol and explain design rules that prevent client-visible behaviour and state handling from drifting.

Instructions file for CodexOpenCode

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add instructions/tryinget/pi-server/agents-md
Clone the repo
git clone --depth 1 https://github.com/tryingET/pi-server

Made for: Codex, OpenCode.

Per session 11,901 This file is loaded in full into every session.
When invoked 11,901 The same file — it is already loaded in full.
Security scan B 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.11901 $0.11901
Opus 5 $0.05951 $0.05951
Sonnet 5 $0.02380 $0.02380
Haiku 4.5 $0.01190 $0.01190

Measured 2d ago against content hash cc49f65281ad, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade B, and why

pi-server AGENTS.md scanned grade B with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Asks for rootmediumPrivilege escalation

A mod that escalates privileges can change anything on the machine, not only the project.

chmod 700 "$RUN_ROOT" "$RUN_ROOT"/{home,agent,tmp}
AGENTS.md · 1,519 lines

How it starts

The opening of the file, as written. The whole thing — 1,519 lines — stays where its author put it; the contents beside it link to each section on GitHub.

AGENTS.md — Crystallized Learnings for pi-server

This document captures patterns, anti-patterns, and gotchas discovered during development. Read this before working on pi-server.

Because parent/global AGENTS files are concatenated into every session, keep this file repo-specific and prefer pointing to canonical docs instead of duplicating large policy blocks.


Canonical References

Start here before changing behavior that crosses repo boundaries:

  • README.md — package shape, architecture overview, release flow
  • PROTOCOL.md — wire contract and client-visible semantics
  • docs/release-policy.md — commit, changelog, and breaking-change policy
  • next_session_prompt.md — current handoff / immediate priorities

Architecture Principles

  1. The protocol IS the architecturetypes.ts is the single source of truth
  2. Server should be thin — AgentSession does the work, we just multiplex
  3. Pass-through pattern — Session commands are thin wrappers around AgentSession methods
  4. Handler map > switchRecord<string, CommandHandler> for O(1) dispatch, easy extension
  5. Extract to stores — State with independent lifecycle gets its own module
  6. SessionResolver is the NEXUS seam — Interface for session access enables test doubles

ADR-0001: Atomic Outcome Storage

Status: Accepted (2026-02-22)

Full ADR: docs/adr/0001-atomic-outcome-storage.md

The Invariant

Same command ID must ALWAYS return the same response. Not "usually." Not "after the callback completes." ALWAYS.

Three Critical Rules

  1. Store BEFORE return — Outcomes are stored before the response is returned, not in async callbacks
  2. Timeout IS a response — Timeout responses are stored as valid outcomes (with timedOut: true)
  3. Replay is FREE — Replay operations are O(1) lookups, exempt from rate limiting

Code Pattern

// WRONG: Async callback creates race condition
commandExecution.then((response) => {
  this.storeOutcome(commandId, response);  // After return
});
return withTimeout(commandExecution, ...);

// CORRECT: Atomic storage before return
let response: RpcResponse;
try {
  response = await executeWithTimeout(commandExecution, ...);
} catch (error) {
  response = { success: false, error: error.message, timedOut: true };
}
this.storeOutcome(commandId, response);  // BEFORE return
return response;

Read the full file on GitHub · 1,519 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 1,519 lines · 11,901 tokens per session scan B cc49f65281ad

Subscribe to this mod's changes

pi-server AGENTS.md is an instructions file published in the GitHub repository tryingET/pi-server (11 stars, last pushed 11d ago), licensed MIT. It adds 11,901 tokens to every session, about $0.0595 per session on Opus 5. A static security scan graded it B with 1 finding (asks for root). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.