Skip to content

feat: Guardian Command — Phase 2 multi-agent platform rewrite#70

Merged
rz1989s merged 92 commits intomainfrom
feat/phase2-guardian-command
Apr 9, 2026
Merged

feat: Guardian Command — Phase 2 multi-agent platform rewrite#70
rz1989s merged 92 commits intomainfrom
feat/phase2-guardian-command

Conversation

@rz1989s
Copy link
Copy Markdown
Member

@rz1989s rz1989s commented Apr 9, 2026

Summary

Full rewrite of Sipher from a hand-rolled REST API + chat agent to a Pi SDK-native multi-agent platform with a world-class frontend.

Plan A: Infrastructure + Pi Migration (16 tasks)

  • Pi SDK (pi-agent-core + pi-ai) replaces Anthropic SDK
  • AgentPool (multi-tenant, 30min idle eviction)
  • Dynamic tool loading (21 tools in 4 groups + routeIntent)
  • EventBus + ActivityLogger (typed events, level filtering)
  • Wallet auth (nonce → JWT), SSE activity stream
  • 6 new DB tables, 10 new API routes
  • COURIER formalized with EventBus events

Plan B: HERALD — X Agent (11 tasks)

  • 9 X API tools (readMentions, readDMs, postTweet, replyTweet, likeTweet, searchPosts, readUserProfile, sendDM, schedulePost)
  • Budget tracker with circuit breaker ($150/mo cap, 4 gates)
  • Intent classifier (command/question/engagement/spam)
  • Post approval queue (auto-approve after 30min)
  • Adaptive poller (10min default, backoff after 3 empty polls)

Plan C: SENTINEL — Blockchain Monitor (6 tasks)

  • Scanner: vault state, stealth payments, balance changes
  • Detector: 6 event types (unclaimed, expired, threat, large transfer, balance, RPC error)
  • Refund guard: threshold check, double-processing prevention, idempotency
  • Adaptive worker: 60s idle, 15s active, exponential backoff on RPC errors

Plan D: Guardian Command UI (10 tasks)

  • AI Designer-generated designs (4 approved mockups)
  • Activity stream (SSE real-time feed)
  • Command bar (bottom sheet chat, Cmd+K, confirmation cards)
  • Vault view (balance, deposit/withdraw, pending ops, history)
  • HERALD view (budget bar, activity timeline, approval queue, DMs)
  • Squad view (agent status grid, stats, coordination log, kill switch)
  • Tailwind CSS 4, dark design system, mobile-first

Stats

  • 45 commits, 588 backend tests, ~160 new tests
  • Frontend: 27KB CSS + 625KB JS (191KB gzip)
  • Spec: docs/superpowers/specs/2026-04-09-sipher-phase2-guardian-command-design.md

Test plan

  • Backend: pnpm test -- --run (588 passing)
  • Frontend: cd app && pnpm build (builds clean)
  • Visual QA: open app/designs/*.html for design reference
  • API routes: verify /api/stream, /api/command, /api/vault, /api/squad, /api/herald
  • Full integration: start backend + frontend, connect wallet, test activity stream

rz1989s added 30 commits April 9, 2026 00:24
…in stats

Add getPaymentLinksBySession, expireStaleLinks, getPaymentLinkStats,
getAuditStats, and getSessionStats to db.ts with full test coverage
(15 new tests, 240 passing). Sort by rowid DESC as tie-breaker for
stable ordering when created_at timestamps collide within same tick.
…data

Implements the invoice tool with required amount, 7-day default expiry,
and invoice_meta JSON (description, dueDate, reference). Reuses payment_links
table with type='invoice'. 8 tests covering full metadata, DB storage,
validation, and expiry defaults.
Express router for payment link pages with dark-theme Tailwind HTML templates,
XSS-safe escaping, open-amount support, expiry/paid/404 states, and confirm endpoint.
…ls + /pay and /admin routes

Registers 4 new tools in TOOLS array, TOOL_EXECUTORS, and SYSTEM_PROMPT. Mounts
/pay and /admin route groups in index.ts with stale link expiry on the 5-minute
purge interval. Updates tools.test.ts to assert 14 tools and stream.test.ts mock
to include all new exports.
Pure-math synchronous tool that floors amounts to common denominations
(10, 50, 100, 500, 1000, 5000, 10000) to reduce amount correlation in
privacy-preserving transactions. Remainder stays in vault.
Implements crankTick with expiry, miss-window, max_exec completion,
recurring re-schedule via intervalMs, and per-op error isolation.
8 tests covering all branches (executed, expired, missed, failed, skipped).
Creates a single scheduled_op with action='send' and max_exec=1.
Supports exact delay, random range, or default 30-60 min. Expiry
set to scheduled time + 1 hour. 8 tests, all passing.
Add activity_stream, herald_queue, herald_dms, execution_links, cost_log,
and agent_events tables with indexes for Phase 2 Guardian/Command layer.

Exports: insertActivity, getActivity, dismissActivity, logCost,
getCostTotals, logAgentEvent, getAgentEvents, createExecutionLink,
getExecutionLink, updateExecutionLink — all ULID-keyed, ISO 8601 timestamps.

TDD: 34 tests in db-schema.test.ts, all passing, no regressions.
rz1989s added 26 commits April 9, 2026 16:06
Root tests/coordination/event-bus.test.ts was a duplicate of
packages/agent/tests/coordination/event-bus.test.ts (identical logic,
different import path). Deleted the root copy.

Root tests/pi/tool-adapter.test.ts had no counterpart in packages/agent —
moved it to packages/agent/tests/pi/tool-adapter.test.ts with corrected
import paths so it runs with the agent package test suite where it belongs.
…devnet (closes #85)

Scanner was hardcoded to createConnection('devnet') which would connect
to devnet in production. Now reads SOLANA_NETWORK env var, defaulting
to mainnet-beta for production safety. Devnet must be explicitly opted
into via SOLANA_NETWORK=devnet.
#86)

getReadyToPublish() had a TOCTOU race: it queried pending posts then
updated them individually, allowing concurrent callers to pick up the
same posts. Now wraps the select+update in db.transaction() and adds
a CAS guard (AND status = 'pending') on the UPDATE WHERE clause so
only the first caller wins the update.
…loses #87)

VaultView always rendered MOCK_BALANCE, MOCK_USD, MOCK_FEES, and
MOCK_PENDING regardless of API response. Now derives balance, usd,
fees, and pendingOps from data when available, falling back to mocks
only when data is null (loading or not connected).

Extended VaultData interface with optional balance/usd/fees/pending_ops
fields and added TODO noting the vault API should be extended to return
these fields.
…d handler, type mismatches, intent classifier (closes #88, closes #89, closes #90, closes #91, closes #92)
Store originating wallet in pending map and validate req.wallet
matches before resolving. Prevents unauthorized confirmation of
fund-moving operations by other authenticated wallets.
likeTweet, replyTweet, sendDM, and publishTweet now check the budget
gate before executing. Prevents overspending when gate is dm-only or paused.
…prompt, confirm cap, admin tokens (closes #106, closes #107, closes #108, closes #109, closes #110)
 #113, closes #114, closes #116)

- Replace `as any` with `as Tool['parameters']` across all 9 HERALD tool files
- Add message length validation (max 4000 chars) on /api/command
- Add per-IP rate limiter on /api/auth/verify (10 req/min) to prevent ed25519 CPU amplification
…loses #111, closes #112, closes #115)

- Add error state and banner to StreamView and VaultView when API fetch fails
- Replace hardcoded mock balance/pending data with placeholders when API has no real data
- Convert useSSE connected tracking from ref to useState for proper re-renders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant