Development

Extension Patches

Local patches to Pi extensions for RPC mode compatibility
Properties2
Iconi-lucide-puzzle
Order30

Pi Island requires some extensions to be patched for proper RPC mode support. This page documents the patches and their rationale.

pi-synthetic Extension

Location: ~/.pi/agent/git/github.com/aliou/pi-synthetic/

Problem

In RPC mode, Pi sets ctx.hasUI = true but ctx.ui.custom() returns undefined immediately (no-op). The pi-synthetic extension checks if (!ctx.hasUI) before falling back to console.log, so the fallback never triggers.

Patch

File: src/commands/quotas.ts

// Original code calls ctx.ui.custom() without checking the result
await ctx.ui.custom<void>((tui, theme, _kb, done) => {
  // ... TUI rendering code
});

// Patched to fall back to notify when custom() returns undefined
const result = await ctx.ui.custom<void>((tui, theme, _kb, done) => {
  // ... TUI rendering code
});

// If custom() returned undefined (RPC mode), use notify as fallback
if (result === undefined) {
  const quotas = await fetchQuotas();
  if (!quotas) {
    ctx.ui.notify("Failed to fetch quotas", "error");
    return;
  }
  ctx.ui.notify(formatQuotasPlain(quotas), "info");
}

Why This Works

  • ctx.ui.custom() in RPC mode immediately returns undefined
  • ctx.ui.notify() in RPC mode emits an extension_ui_request event with method: "notify"
  • Pi Island handles this event and displays the message in a terminal-style box

Upstream Fix

This patch should be submitted as a PR to the pi-synthetic repository. The recommended pattern for RPC-compatible extensions:

  1. Check if ctx.ui.custom() returns undefined
  2. Fall back to ctx.ui.notify() for simple text output
  3. Or check !ctx.hasUI for console.log fallback (if hasUI is fixed in Pi)

Other Extensions

If other extensions have similar issues (using ctx.ui.custom() without RPC fallback), apply the same pattern:

const result = await ctx.ui.custom(...);
if (result === undefined) {
  // RPC mode fallback
  ctx.ui.notify("Your output text", "info");
}