{"id":45995599,"url":"https://github.com/tryinget/pi-server","last_synced_at":"2026-03-04T17:00:38.261Z","repository":{"id":340856170,"uuid":"1166988934","full_name":"tryingET/pi-server","owner":"tryingET","description":"Session multiplexer for pi-coding-agent — WebSocket + stdio, the protocol IS the architecture","archived":false,"fork":false,"pushed_at":"2026-03-03T14:15:59.000Z","size":898,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-03T18:59:36.623Z","etag":null,"topics":["coding-agent","multiplexer","pi","session-management","stdio","websocket"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tryingET.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-02-25T20:36:07.000Z","updated_at":"2026-03-03T14:12:47.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/tryingET/pi-server","commit_stats":null,"previous_names":["tryinget/pi-server"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/tryingET/pi-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tryingET%2Fpi-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tryingET%2Fpi-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tryingET%2Fpi-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tryingET%2Fpi-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tryingET","download_url":"https://codeload.github.com/tryingET/pi-server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tryingET%2Fpi-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30086511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T15:40:14.053Z","status":"ssl_error","status_checked_at":"2026-03-04T15:40:13.655Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coding-agent","multiplexer","pi","session-management","stdio","websocket"],"created_at":"2026-02-28T21:03:41.325Z","updated_at":"2026-03-04T17:00:38.247Z","avatar_url":"https://github.com/tryingET.png","language":"TypeScript","readme":"# pi-server\n\nSession multiplexer for [pi-coding-agent](https://www.npmjs.com/package/@mariozechner/pi-coding-agent). Exposes N independent `AgentSession` instances through WebSocket and stdio transports.\n\n[![CI](https://github.com/tryingET/pi-server/actions/workflows/ci.yml/badge.svg)](https://github.com/tryingET/pi-server/actions/workflows/ci.yml)\n[![npm](https://img.shields.io/npm/v/pi-app-server.svg)](https://www.npmjs.com/package/pi-app-server)\n\n\u003e Note: This is a standalone pi server package, not an extension/skills/themes bundle.\n\n## Features\n\n- **Dual transport**: WebSocket (port 3141) + stdio (JSON lines)\n- **Session lifecycle**: Create, delete, list, switch sessions\n- **Command execution**: Deterministic lane serialization per session\n- **Idempotent replay**: Atomic outcome storage with free replay lookups\n- **Optimistic concurrency**: Session versioning for conflict detection\n- **Extension UI**: Full round-trip support for `select`, `confirm`, `input`, `editor`, `interview`\n- **Resource governance**: Rate limiting, session limits, message size limits\n- **Pluggable authentication**: `AuthProvider` abstraction (allow-all, token, IP allowlist, composite)\n- **Graceful shutdown**: Drain in-flight commands, notify clients\n- **Protocol versioning**: `serverVersion` + `protocolVersion` for compatibility checks\n\n## Installation\n\n```bash\nnpm install pi-app-server\n```\n\n## Quick Start\n\n### WebSocket\n\n```bash\n# Start server\nnpx pi-server\n\n# Connect with wscat\nwscat -c ws://localhost:3141\n```\n\n```js\n// Create and use a session\nws\u003e {\"type\":\"create_session\",\"sessionId\":\"my-session\"}\nws\u003e {\"type\":\"switch_session\",\"sessionId\":\"my-session\"}\nws\u003e {\"id\":\"cmd-1\",\"type\":\"prompt\",\"sessionId\":\"my-session\",\"message\":\"Hello!\"}\n```\n\n### stdio\n\n```bash\necho '{\"type\":\"create_session\",\"sessionId\":\"test\"}\n{\"type\":\"switch_session\",\"sessionId\":\"test\"}\n{\"id\":\"cmd-1\",\"type\":\"prompt\",\"sessionId\":\"test\",\"message\":\"Hello!\"}' | npx pi-server\n```\n\n## Architecture\n\n```\nsrc/\n├── server.ts               # transports, connection lifecycle, routing glue\n├── session-manager.ts      # orchestration: coordinates stores, engines, sessions\n├── command-router.ts       # session command handlers, routing\n├── command-classification.ts  # pure command classification (timeout, mutation)\n├── command-replay-store.ts    # idempotency, duplicate detection, outcome history\n├── session-version-store.ts   # monotonic version counters per session\n├── command-execution-engine.ts # lane serialization, dependency waits, timeouts\n├── resource-governor.ts    # limits, rate controls, health/metrics\n├── extension-ui.ts         # pending UI request tracking\n├── server-ui-context.ts    # ExtensionUIContext for remote clients\n├── validation.ts           # command validation\n└── types.ts                # wire protocol types + SessionResolver interface\n```\n\n### Core invariants\n\n- For each admitted command, there is exactly one terminal response.\n- For each session ID, there is at most one live `AgentSession`.\n- Subscriber session sets are always a subset of active sessions.\n- Session version is monotonic and mutation-sensitive.\n- Fingerprint excludes retry identity (`id`, `idempotencyKey`) for semantic equivalence.\n\n### Key abstractions\n\n- **`SessionResolver`** — Interface for session access (enables test doubles, future clustering)\n- **`CommandReplayStore`** — Idempotency and duplicate detection\n- **`SessionVersionStore`** — Optimistic concurrency via version counters\n- **`CommandExecutionEngine`** — Deterministic lane serialization and timeout management\n\n## Protocol\n\nSee [PROTOCOL.md](./PROTOCOL.md) for the normative wire contract.\n\n### Command → Response\n\nEvery command receives exactly one response:\n\n```json\n{\"id\": \"cmd-1\", \"type\": \"prompt\", \"sessionId\": \"s1\", \"message\": \"hello\"}\n{\"id\": \"cmd-1\", \"type\": \"response\", \"command\": \"prompt\", \"success\": true}\n```\n\n### Event Broadcast\n\nEvents flow session → subscribers:\n\n```json\n{\"type\": \"event\", \"sessionId\": \"s1\", \"event\": {\"type\": \"agent_start\", ...}}\n```\n\n### Extension UI Round-Trip\n\n1. Extension calls `ui.select()` → server creates pending request\n2. Server broadcasts `extension_ui_request` event with `requestId`\n3. Client sends `extension_ui_response` command with same `requestId`\n4. Server resolves pending promise → extension continues\n\n### Idempotency \u0026 Replay\n\n```json\n// First request with idempotency key\n{\"id\": \"cmd-1\", \"type\": \"list_sessions\", \"idempotencyKey\": \"key-1\"}\n{\"id\": \"cmd-1\", \"type\": \"response\", \"command\": \"list_sessions\", \"success\": true, ...}\n\n// Retry with same key → replayed (free, no rate limit charge)\n{\"id\": \"cmd-2\", \"type\": \"list_sessions\", \"idempotencyKey\": \"key-1\"}\n{\"id\": \"cmd-2\", \"type\": \"response\", \"command\": \"list_sessions\", \"success\": true, \"replayed\": true, ...}\n```\n\n### Timeout semantics (ADR-0001)\n\n- Timeout is a **terminal stored outcome** (`timedOut: true`), not an indeterminate placeholder.\n- Replay of the same command identity returns the **same timeout response**.\n- Late underlying completion does **not** overwrite the stored timeout outcome.\n\n## Development\n\n```bash\n# Install dependencies\nnpm install\n\n# Build\nnpm run build\n\n# Run tests\nnpm test                    # Main test suite\nnpm run test:integration    # Integration tests\nnpm run test:fuzz           # Fuzz tests\n\n# Module tests\nnode --experimental-vm-modules dist/test-command-classification.js\nnode --experimental-vm-modules dist/test-session-version-store.js\nnode --experimental-vm-modules dist/test-command-replay-store.js\nnode --experimental-vm-modules dist/test-command-execution-engine.js\n\n# Type check + lint\nnpm run check\n\n# Full CI\nnpm run ci\n```\n\n## Release Process\n\nThis project uses [release-please](https://github.com/googleapis/release-please) for automated versioning.\n\n### Automated Flow\n\n1. Push to `main` → release-please creates/updates a release PR\n2. Merge the release PR → Creates GitHub release + git tag\n3. Release published → GitHub Action publishes to npm with provenance\n\n### Manual Release Check\n\n```bash\nnpm run release:check\n```\n\nThis validates:\n- `package.json` has required fields\n- `dist/` exists with compiled files\n- Entry point has correct shebang\n- `npm pack` produces expected files\n- Full CI passes\n\n## Documentation\n\n| Document | Purpose |\n|----------|---------|\n| [AGENTS.md](./AGENTS.md) | Crystallized learnings, patterns, anti-patterns |\n| [PROTOCOL.md](./PROTOCOL.md) | Normative wire contract |\n| [ADR-0001](./docs/adr/0001-atomic-outcome-storage.md) | Atomic outcome storage (timeout semantics) |\n| [ADR-0007](./docs/adr/0007-session-persistence.md) | Session persistence |\n| [ADR-0009](./docs/adr/0009-connection-authentication.md) | Historical authentication proposal (superseded) |\n| [ADR-0010](./docs/adr/0010-circuit-breaker.md) | Circuit breaker for LLM calls |\n| [ADR-0014](./docs/adr/0014-pluggable-authentication.md) | Pluggable connection authentication (implemented) |\n| [ADR-0019](./docs/adr/0019-durable-command-journal-foundation.md) | Durable command journal foundation (Level 4) |\n| [ROADMAP.md](./ROADMAP.md) | Phase tracking and milestones |\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftryinget%2Fpi-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftryinget%2Fpi-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftryinget%2Fpi-server/lists"}