Skip to content

Add Pi discovery and managed gateway configuration - #109

Open
sebbycorp wants to merge 13 commits into
mainfrom
feature-adding-pi-harness
Open

sebbycorp wants to merge 13 commits into
mainfrom
feature-adding-pi-harness

Conversation

@sebbycorp

@sebbycorp sebbycorp commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds first-class support for the pi.dev coding-agent harness (@earendil-works/pi-coding-agent) so it shows up in local inventory and can be pointed at the LLM gateway.

Discovery

  • Binary: pi on PATH, plus Homebrew / ~/.local/bin candidates. The name pi is too generic to trust alone, so a candidate is accepted only after verifying the @earendil-works/pi-coding-agent package manifest. Windows npm CMD, PowerShell, and shell shims are checked against their sibling package and launch target without executing them. PowerShell-only installs are discovered from the standard npm location or custom locations on PATH, even when .ps1 is absent from PATHEXT; PowerShell PATH entries retain their order.
  • Version: npm package.json (no pi --version exec).
  • MCP: files pi-mcp-adapter actually loads. Globals are ~/.pi/agent/mcp.json, ~/.config/mcp/mcp.json, ~/.agents/mcp.json, and ~/.agents/mcp/mcp.json. Project files are the working directory's .mcp.json and .pi/mcp.json. Ancestor project files are included only when a user-global config sets settings.ancestorConfigRoots to an existing directory under the home that contains the working directory. Both .agents locations are supported by pi-mcp-adapter 2.34.0. PI_MCP_CONFIG_MODE=exclusive inventories only the Pi agent file. Host-specific Cursor/Claude files are not imported until the adapter copies them into a Pi-owned file. Args, env, and headers are omitted.
  • Skills: ~/.pi/agent/skills, ~/.agents/skills, the working directory's .pi/skills, and .agents/skills from the working directory through the git repository root.

Managed configuration

llmGateway:
  url: http://127.0.0.1:4001
  authentication:
    type: oidc
    issuer: http://127.0.0.1:5557/dex
    clientId: agentdesktop-local
    scopes: [openid, email, offline_access]
    allowInsecure: true
programs:
  pi:
    useLlmGateway: true
    model: claude-sonnet-4-5
  • --user merges providers.agentdesktop into ~/.pi/agent/models.json (api: anthropic-messages, authHeader: true, apiKey: !<credential command> resolved at request time) and sets defaultProvider / defaultModel in settings.json. Other keys (theme, packages, extra providers) are preserved.
  • model is required when the gateway is used. An omitted models map creates that catalog entry. Model map keys determine catalog IDs, and generated gateway URLs take precedence over per-model endpoints using each model's API dialect.
  • Sandbox translation is not supported (same as Grok / OpenCode / Claude Desktop / Copilot CLI / VS Code).
  • daemon.pi.models / daemon.pi.settings in the local YAML configuration override the managed paths, matching the daemon startup configuration on main. ~ in PI_CODING_AGENT_DIR is expanded consistently for configuration, MCP, and skills.
  • Commented models.json files, including BOMs and trailing commas, are merged and rewritten as standard JSON while preserving user values. Other settings files retain strict JSON parsing.
  • On Unix, models.json is written owner-only (0600), and a looser mode is repaired on the next reconcile; cleanup keeps the file's current mode. Dry runs report the models.json action and path without its contents, since it may hold the user's own API keys.
  • Pi reports per-program configuration status like the other programs, and the inventory file watch from feat(agent): refresh the inventory when its source files change #99 picks up changes to its MCP and skill files.

Pi does not read /etc/pi, so programs.pi requires --user. It cannot be combined with Claude Desktop or Grok Build, which require system mode. Empty model IDs are rejected before models.json is written. Authenticated gateway configuration also rejects --once because credential helpers need a running daemon. In the system-mode Claude Desktop example, Pi is opt-in; remove Claude Desktop and use --user before enabling it.

Test plan

  • cargo test --locked -p agentdesktop-core -p agentdesktop-agent --lib — 412 passed (380 agent, 32 core), after merging main at a186749
  • cargo test --workspace — all unit tests pass; the container integration tests require Linux and pass in CI
  • cargo fmt --all --check
  • cargo clippy --locked --workspace --all-targets -- -D warnings
  • Schema regenerated with cargo xtask schema and verified unchanged
  • Frontend pnpm check:lint, both frontend production builds, and Storybook interaction tests (99 passed)
  • CI on a186749: Test and lint, Windows agent tests, and Container all pass
  • Local Pi startup-path regression tests and CLI smoke: custom paths are honored, dry-run writes nothing, and generated model files retain private permissions
  • Built CLI smoke: system-mode Pi and authenticated Pi --once reject before writes; authenticated user dry-run previews without writing
  • Pi 0.85.1 runtime smoke: generated catalog loads, default model matches, per-model endpoints use the gateway, personal providers survive merge/repeat/removal
  • Regression fixtures cover Windows npm shims, unrelated-launcher rejection, custom directories, commented models, and configuration cleanup

Follow-ups

  • Official Pi mark if there is a canonical SVG
  • Wire crates/agent/tests/integration.rs once the container fixture exists

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved critical and moderate issues affect system-mode configuration, gateway enforcement, and Pi discovery correctness.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 High severity · 2 Medium severity

Open (4)
What changed in this PR

This PR adds first-class Pi coding-agent discovery and managed LLM gateway configuration across the daemon, UI, schemas, documentation, and examples.

Changes:

  • Adds Pi binary, version, MCP, and skills discovery.
  • Reconciles Pi models.json and settings.json for gateway usage.
  • Updates schemas, controller configuration, branding, documentation, and examples.
File Description Final review notes
schema/​daemon-config.md Documents Pi configuration. —
schema/​daemon-config.json Adds Pi schema definitions. —
README.md Lists Pi integration support. —
frontend/​ui/​src/​tools.tsx Registers Pi branding. —
frontend/​ui/​src/​assets/​pi.svg Adds the Pi icon. —
frontend/​desktop/​src/​views/​ToolsView.tsx Updates inventory messaging. —
frontend/​controller/​src/​views/​ConfigurationView.tsx Adds Pi configuration controls. —
frontend/​controller/​src/​types.ts Adds the Pi agent type. —
examples/​standalone/​config.yaml Enables Pi gateway configuration. Nit (1): Update the walkthrough, prerequisites, and expected summary for Pi reconciliation.
examples/​claude/​claude-code.yaml Adds Pi gateway configuration. Moderate (1): Remove Pi from the system-mode example or provide a user-mode configuration/invocation.
crates/​core/​src/​config.rs Adds Pi config parsing and validation. —
crates/​agent/​src/​reconcile/​mod.rs Registers Pi reconciliation. —
crates/​agent/​src/​provider/​README.md Documents Pi provider support. —
crates/​agent/​src/​provider/​pi/​reconcile.rs Merges Pi models and settings. Moderate (2): Handle model IDs that differ from their map keys.
Moderate (1): Support Pi-compatible comments in models.json.
Critical (1): Prevent per-model baseUrl values from bypassing the managed gateway.
crates/​agent/​src/​provider/​pi/​mod.rs Defines Pi provider paths and behavior. Critical (2): Reject unsupported system-mode management or implement a supported system path.
Moderate (1): Expand ~ in PI_CODING_AGENT_DIR against the user home.
crates/​agent/​src/​provider/​pi/​discovery.rs Discovers Pi, MCP servers, and skills. Moderate (1): Preserve each user’s default MCP root when an override is set.
Moderate (1): Remove the unsupported ~/.agents/mcp/mcp.json path.
Moderate (3): Resolve Windows pi.cmd npm shims or inspect the global package location.
Moderate (1): Preserve each user’s default skills root alongside the override.
Moderate (1): Normalize PI_CODING_AGENT_DIR, including ~ expansion.
Moderate (1): Support Pi’s mcp-servers alias.
crates/​agent/​src/​provider/​mod.rs Registers the Pi provider module. —
crates/​agent/​src/​daemon.rs Adds Pi CLI path overrides. —

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/agent/src/provider/pi/mod.rs
Comment thread crates/agent/src/provider/pi/reconcile.rs
Comment thread crates/agent/src/provider/pi/discovery.rs
Comment thread crates/agent/src/provider/pi/reconcile.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Three moderate findings remain in Pi discovery and managed model reconciliation.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
Resolved since last review (4)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Inventory scans unsupported MCP configuration path

crates/​agent/​src/​provider/​pi/​discovery.rs:153

This function is documented as enumerating files that pi-mcp-adapter loads, but ~/.agents/mcp/mcp.json is not one of the adapter-owned paths listed in the PR contract. Scanning this extra file can show MCP servers in inventory that Pi will not actually load; remove it unless the adapter supports this path.

Comment thread crates/agent/src/provider/pi/discovery.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Two moderate MCP discovery issues remain in crates/agent/src/provider/pi/discovery.rs.

Review effort: Lite
Findings: None

Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Avoid scanning unsupported Pi MCP config path

crates/​agent/​src/​provider/​pi/​discovery.rs:169

The documented Pi adapter paths include ~/.agents/mcp.json, but not ~/.agents/mcp/mcp.json. Scanning this extra file can surface MCP servers that Pi never loads, so the inventory is inaccurate; keep discovery limited to files the adapter actually reads.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved critical credential-protection and model-catalog issues, plus moderate Pi discovery and inventory issues, block approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 High severity · 1 Medium severity

Open (3)

Comment thread crates/agent/src/provider/pi/reconcile.rs Outdated
Comment thread crates/agent/src/provider/pi/reconcile.rs
Comment thread crates/agent/src/provider/pi/discovery.rs
Detect the pi.dev coding-agent harness (@earendil-works/pi-coding-agent),
inventory MCP servers and skills, and reconcile user-level models.json
and settings.json so Pi can use the LLM gateway with a request-time
credential helper.
Local Agent Desktop Tools view of Pi 0.85.1 with MCP and skills.
The controller watches examples/claude/claude-code.yaml. Add programs.pi
so the Configuration UI shows Pi next to Claude Code/Desktop.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@peterj
peterj requested a balanced review from Copilot September 29, 2026 19:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Discovery over-reports project resources, and validation permits unusable Pi configurations.

Review effort: Balanced
Findings: 4 Medium severity

Open (4)

Comment thread crates/agent/src/provider/pi/discovery.rs Outdated
Comment thread crates/agent/src/provider/pi/discovery.rs Outdated
Comment thread crates/core/src/config.rs
Comment thread crates/core/src/config.rs
sebbycorp and others added 3 commits October 1, 2026 19:54
Project MCP files stay in the working directory unless a user-global
adapter config opts into ancestorConfigRoots. Skill discovery keeps
.pi/skills in the working directory and stops .agents/skills at the
git root. Validation rejects Pi combined with Claude Desktop or Grok
Build, and rejects empty Pi model IDs before models.json is written.
…ness

Bring in the local LLM proxy, Copilot CLI and VS Code Copilot Chat
providers, per-program status, the opt-in reconcile tick, and inventory
refresh, and fit Pi into them.

- json_merge keeps main's MergeOptions (mode, keyed arrays, diff
  redaction, looser-mode repair, removal keeping the file's mode) and
  adds the JSONC format and replace_paths that Pi's models.json needs.
- Pi implements Provider::id and is listed by configured_programs, so it
  gets a per-program status row like the other programs.
- Pi's models.json redacts dry-run diffs, like the other files that can
  hold the user's API keys. Cleanup now keeps the file's current mode,
  following main's json_merge removal rule.
- Reconciler::new, daemon startup paths, config validation, schemas,
  READMEs, and the controller configuration list Pi next to the Copilot
  CLI and VS Code.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E4vKY8hztcuF47Wc2hLnqA
@sebbycorp

Copy link
Copy Markdown
Collaborator Author

@peterj @howardjohn @christian-posta this is ready for review. a186749 merges current main (through #99), CI is green, and every review thread is answered and resolved.

Things worth a look in the merge:

  • json_merge keeps main's MergeOptions (mode, keyed arrays, diff redaction, looser-mode repair, removal keeping the file's mode) and adds only what Pi's models.json needs: the JSONC format and replace_paths. The Copilot CLI and VS Code options take the new fields from Default, so their behavior is unchanged.
  • Pi implements Provider::id and is listed in configured_programs, so it reports per-program status (pi_reports_applied_unchanged_removed_then_no_row). It needs no loopback proxy: its apiKey is a credential-helper command.
  • Pi's models.json now redacts dry-run diffs, like the other files that can hold the user's own API keys. Cleanup keeps the file's current mode, following main's removal rule; merges still write 0600 and repair a looser mode.

This branch has not been deployed

No deployments
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.

2 participants