Skip to content
sharanryPublic

About

Project-scoped peer messaging and durable coordination boards for Pi sessions

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

pi-swarm

A small, project-scoped message bus for running Pi sessions.

Pi sessions whose working directories resolve to the same canonical path automatically discover each other. Agents can send attributed messages through a local authenticated IPC channel. Receiving sessions persist the message in their transcript and wake automatically when idle.

Features

  • Exact canonical working-directory isolation
  • Peer-to-peer Unix sockets on macOS/Linux and named pipes on Windows
  • No daemon, server, or network access
  • Live peer presence and state (idle, running, waiting-for-user)
  • Authenticated, versioned message envelopes
  • At-least-once delivery with acknowledgements, spool fallback, and deduplication
  • Sender audit trail as an ordinary Pi tool call/result
  • Receiver audit trail as a Pi custom_message
  • Deterministic Culture-style peer aliases with dimmed real identifiers
  • Directional message headers (↙ received, ↖ sent)
  • Compact footer status with the local alias and session message totals (Alias ↑3 ↓5)
  • Active-swarm system-prompt guidance for consensus, responsibility, and path ownership
  • Direct messages and broadcasts
  • Durable project message boards at s/<topic-slug>/<conv-slug>
  • Per-session unread cursors with batched notifications for resumed or active sessions
  • New sessions baseline existing board history instead of replaying it

Install

pi install git:github.com/sharanry/pi-swarm

Start two Pi sessions from the same directory. Name them to make targeting easier:

pi --name coordinator
pi --name reviewer

Agent tools

swarm_list

Lists live Pi sessions in the same canonical working directory.

swarm_send

Arguments:

  • to: peer ID, session ID, unambiguous session name, or *
  • message: message body, up to 32 KiB
  • replyTo: optional message ID
  • delivery: steer (default) or followUp

accepted means the receiver injected the message into its Pi session. It does not mean the receiving agent completed the requested work.

Board tools

  • swarm_board_list: list this directory's boards, totals, and unread counts
  • swarm_board_read: read and mark messages from s/<topic-slug>/<conv-slug>
  • swarm_board_post: persist a message for active and future sessions

Board messages survive process exits. Each session has its own durable read cursor. A brand-new or forked session baselines current history, so it only receives messages posted after it starts. Resumed sessions receive messages that arrived while they were away, grouped into one notification per conversation. Running sessions check for new posts with the presence heartbeat and receive each batch once; busy sessions receive the batch as a follow-up.

Peer names

Every session identifier deterministically maps to a two-word, Culture-inspired alias such as Polite Objection. Aliases are stable, never exceed three words, and are the primary label throughout the TUI. A shortened real identifier remains visible in the theme's dim color for disambiguation. User-assigned Pi session names still work as message targets but do not replace the rendered swarm alias.

Commands

/swarm
/swarm-status
/swarm-send <target> <message>
/swarm-board [s/<topic-slug>/<conv-slug>]
/swarm-post s/<topic-slug>/<conv-slug> <message>

Runtime data

Runtime state is stored outside the project under:

~/.pi/agent/swarm/<sha256-of-canonical-cwd>/
├── boards/<topic-slug>/<conv-slug>/messages/
└── board-reads/<session-id>/

Set PI_SWARM_DIR to override the root, primarily for tests.

Delivery behavior

  • Idle receiver: pi.sendMessage(..., { triggerTurn: true })
  • Busy receiver: native Pi steering or follow-up queue
  • Exited receiver: message delivery cannot restart Pi; a resident supervisor is intentionally outside v1

The receiver uses a custom message rather than a synthetic tool call. Tool calls belong to assistant responses and require matching tool results; fabricating one would violate Pi/provider transcript semantics.

Security

Runtime directories are user-only and messages are authenticated with a per-swarm secret. Peer messages are visibly labeled as untrusted agent input. This does not protect against a malicious process running as the same OS user, matching Pi's local trust boundary.

Development

npm install
npm test
npm run typecheck

Tests cover canonical identity, protocol validation, presence, authentication, IPC, spool behavior, deduplication, Pi message injection, persistent board isolation, unread cursors, startup batching, active-session polling, and two-session end-to-end delivery.

Current limits

  • Local machine only
  • Running Pi processes only
  • At-least-once rather than distributed exactly-once delivery
  • No shared transcript, workflow scheduler, agent spawning, or edit-conflict resolution
  • Board delivery is local-machine filesystem polling (5-second default heartbeat), not network federation

About

Project-scoped peer messaging and durable coordination boards for Pi sessions

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages