Graduate the find_agents pi extension from the polaris agent-discovery worktree (commits b361398/d7449f7) into its own fetchable repo in the ash-bot/agent-enforcement layout (manifest at repo root pointing at ./extension/index.ts; jiti compiles TS at runtime, no build step). Exposes one LLM-callable tool: find_agents — read-only, same-daemon discovery of Paseo agents/sessions by title, leading-emoji state, status, labels, workspace, and requiresAttention. Domain-bounded: finds agents, does not wake/message/mutate them.
agent-discovery — a pi extension exposing find_agents
A pi extension (Layer 2 of the agent-discovery design) that exposes one
LLM-callable tool — find_agents — which finds Paseo agents on the
local daemon (same-daemon, read-only). It reads the daemon via the
paseo ls --json CLI (the stable surface), then adds the filtering and
enrichment the raw MCP paseo_list_agents tool lacks: title regex,
leading-emoji state, label match, status, workspace title, and a daemon
field.
Domain boundary (one-way, same principle as the sentinel skill and the
enforcement system): discovery finds "agents," "sessions," "workspaces,"
"labels." It does not know about Overseers, sentinels, or any higher
pattern. The state filter parses the leading emoji of the title and
understands the legend set (🟢 🔵 🔴 🟣 ✅ ⛔ ⏳), but it is stated as
"leading emoji of the title," not "Overseer state" — an unrecognized leading
emoji is state: null and the title is returned whole. The legend is a
caller convention, not a tool dependency.
Posture: read-only. No wake, no messaging, no paseo send, no
paseo agent update, no archive, no daemon mutation. The tool finds; it
does not act. CLI errors are caught and returned as tool errors, never
thrown into the agent loop (fail-safe).
See DESIGN.md for the full design, the search/filter API
spec, Findings D1–D7, and the layer split.
Layout
extension/
package.json pi.extensions: ["./index.ts"], deps: typebox + @earendil-works/pi-ai
tsconfig.json typecheck config (paths mapped to global pi dist)
index.ts default export agentDiscovery(pi); registers the find_agents tool
parse.ts PURE: RawAgent → EnrichedAgent, parseState, applyFilters, buildSummary
(no I/O — the shareable composition point with enforcement, DESIGN D7)
cli.ts I/O: paseo ls --json --global [-a] [--label k=v] + workspace-title correlation
test/
parse.test.mjs unit tests (node:test, run via jiti) — 16 tests
e2e.mjs live-daemon integration proof — drives the real tool
Build / typecheck
cd extension
npm install
npx tsc --noEmit
TypeScript must typecheck (tsc --noEmit) like the enforcement extension.
Test
Unit tests (pure, no I/O, no daemon):
JITI=/usr/local/lib/node_modules/@earendil-works/pi-coding-agent/node_modules/jiti/lib
node --import $JITI/jiti-register.mjs extension/test/parse.test.mjs
# 16 tests, 0 fail
End-to-end (live daemon, read-only) — the headline proof. Drives the real
extension's registered find_agents tool against the live daemon and
asserts the enforcement Overseer (727db2c5) is discoverable from a
different worktree:
node --import $JITI/jiti-register.mjs extension/test/e2e.mjs
# 14 tests, 0 fail
E2E proof (recorded)
[headline: cross-worktree discovery by title]
PASS enforcement Overseer (727db2c5) is in results
PASS enforcement Overseer is in a DIFFERENT worktree than this agent
PASS all returned titles contain 'enforcement' (case-insensitive)
PASS enforcement Overseer state parsed from leading emoji
-> 3 agent(s); overseer title: "🟢 Overseer — enforcement: graduate to repo + nixos-configs dist + shared rules corpus (delegating)"
[state filter: 🔴 agents only]
PASS every returned agent's title starts with 🔴
PASS count matches raw fleet 🔴 count
-> 1 🔴 agent(s) (raw fleet: 1)
[caller: exclude default hides the calling agent]
PASS calling agent (PASEO_AGENT_ID) is excluded by default
PASS calling agent included when caller: self
[limit truncation]
PASS limit:1 returns ≤1 agent
PASS truncated flag set when fleet exceeds limit
[daemon scope: peer/all deferred, non-throwing]
PASS daemon:all returns empty agents
PASS daemon:all returns a note (cross-daemon deferred)
[status + workspace filters compose]
PASS status-filtered results are all in the requested set
PASS title-filtered results all match 'Overseer'
14 passed, 0 failed
E2E PROOF: find_agents discovered the enforcement Overseer (727db2c5) in a
different worktree from a same-daemon call — exactly what the cwd-scoped
MCP paseo_list_agents (no cwd) cannot do. ✅
Install (global — pending Overseer + John sign-off)
Global install loads the extension into every pi agent (incl. all Paseo agents). Not done yet — pending review.
cp -r extension ~/.pi/agent/extensions/agent-discovery
# deps (typebox, @earendil-works/pi-ai) are in extension/node_modules after npm install
Or as a pi package (once published): pi install git:git.johnogle.info/…/agent-discovery.
No daemon restart; the extension loads on the next agent session (or
/reload). No daemon mutation.
API
find_agents({
title?: string | { regex: string }, // substring or regex on session name
state?: "🟢"|"🔵"|"🔴"|"🟣"|"✅"|"⛔"|"⏳", // leading-emoji of title
status?: ("initializing"|"idle"|"running"|"error"|"closed")[],
labels?: { [key]: string }, // exact key=value (CLI --label, server-side)
workspace?: string, // substring on cwd or workspace title
requiresAttention?: boolean,
includeArchived?: boolean = false,
sinceHours?: number, // accepted; CLI exposes no timestamp → no-op
limit?: number = 50, // cap 200
daemon?: "local" | "peer:<id>" | "all" = "local", // peer/all deferred (Layer 3)
caller?: "self" | "exclude" = "exclude", // hide the calling agent by default
}) -> {
agents: { id, shortId, title, state, status, cwd, workspaceTitle,
labels, requiresAttention, attentionReason, daemon }[],
truncated?: boolean,
note?: string,
}
Known limitations / deviations from DESIGN.md
- D3 deviation (CLI does not expose the rich snapshot). On this daemon
paseo ls --jsonandpaseo inspect <id> --jsondo not exposetitle(distinct fromname),labels,requiresAttention,attentionReason, orworkspaceId. Only the MCPpaseo_get_agent_statussnapshot exposes those (one agent at a time), and that is not reachable from extension code without re-implementing the daemon RPC. So:nameis treated astitle(they are equal on this daemon — verified).stateis parsed from the leading emoji ofname.labels: {},requiresAttention: null,attentionReason: nullare returned unless/until an upstream CLI widening or a daemon-RPC read path lands.- The
labelsfilter still works: passed through to the CLI as--label k=v(server-side). requiresAttentionfiltering operates on the (null) values and is a no-op in the live path; the pure logic is unit-tested on synthetic records.workspaceTitleIS populated: correlated frompaseo workspace ls --json(one cheap extra call), matching the agent'scwd.
sinceHoursis accepted for API parity but is a no-op on the CLI path (the CLIlshas no--sinceflag andcreatedis a relative string, not a parseable timestamp).- Cross-daemon (
daemon: "peer:<id>" | "all") is accepted but returns a clear "cross-daemon discovery not yet available" note (Layer 3 deferred per DESIGN.md — the bridgeremoteListAgentsprimitive is the bridge Overseer's job). Non-throwing. - Composition with enforcement (D7):
parse.tsis pure and is the shareable composition point; a sharedparseAgentSnapshothelper and a snapshot cache are later optimizations, not required for either to ship.