Skip to content

refactor(pi): unify config format and add pi-agent execution layer - #26

Merged
FradSer merged 16 commits into
mainfrom
feat/pi-refactor
Aug 9, 2026
Merged

FradSer merged 16 commits into
mainfrom
feat/pi-refactor

Conversation

@FradSer

@FradSer FradSer commented Aug 9, 2026

Copy link
Copy Markdown
Owner

What

Refactor the pi plugin to unify its configuration format and add a dedicated execution layer.

  • Named-endpoint config: delegate, review, and setup now share the same endpoint-first settings format (endpoints / defaultEndpoint / defaultModel), with legacy flat fields kept as a fallback.
  • pi:pi-agent execution layer: all pi CLI runs go through a dedicated agent that builds the command as an array (zsh-safe), runs it in the background, and verifies the real outcome — delegate checks git diff --stat, review returns pi's stdout.
  • Worktree isolation: AGENT_DIR / PI_CODING_AGENT_DIR keeps pi state inside the project, and models.json merges idempotently (baseUrl + model registration, skip when unchanged) to avoid out-of-worktree writes.
  • THINKING default → max: all config defaults now use the highest thinking level.
  • Shared-scope guard: --edit-config --shared warns that apiKey must be a $ENV_VAR reference (tracked file, no literal secrets).
  • Version: 0.1.3 → 0.2.0 (adds a new agent).

Why

  • Previously delegate and review read different config formats, so a single .claude/pi.local.json could configure one but not the other.
  • pi's real output is file edits (delegate) or stdout (review); a dedicated execution layer keeps the main context clean and verifies the actual outcome.
  • In git-worktree/sandboxed sessions, writing $HOME/.pi is rejected; the agent-dir redirection fixes that.

Validation

  • validate-plugin.py pi → PASSED (no issues)
  • E2E: config reading resolves identically across endpoint and flat formats; models.json merge is idempotent; array-built pi command runs with no "Model not found" warning; pi returns OK through the local proxy.

Notes

  • Target branch main (default branch). No open issues are linked.
    🤖 Generated with Claude Code

FradSer and others added 4 commits August 9, 2026 12:47
- Unify pi plugin configuration to the standard endpoint format
- Add dedicated pi-agent execution layer for task delegation
- Resolve worktree isolation and default THINKING behavior
- Bump pi plugin version to 0.2.0

This change updates the pi plugin to use the new endpoint configuration
format and introduces a dedicated agent file for task execution. It also
addresses critical isolation issues with worktrees and stabilizes the
default THINKING configuration, while synchronizing versioning across
the marketplace and plugin manifests.

Co-Authored-By: DeepSeek V4 Flash <noreply@deepseek.com>
Co-Authored-By: Git Agent <noreply@git-agent.dev>
- Introduce pi-agent as the dedicated execution layer for pi operations
- Standardize plugin configuration to use endpoint-based models.json
- Ensure worktree isolation for agent state via configurable directories
- Set default thinking mode to max and update version to 0.2.0

This change introduces the pi-agent execution layer to unify how the
plugin interacts with the pi CLI. It refactors configuration to use an
endpoint-based system, improves isolation for worktrees by moving agent
state into project-local directories, and sets a default configuration
for execution tasks while bumping the project version.

Co-Authored-By: DeepSeek V4 Flash <noreply@deepseek.com>
Co-Authored-By: Git Agent <noreply@git-agent.dev>
- Unify pi plugin configuration to a named-endpoint format
- Add dedicated pi-agent execution layer for all tasks
- Fix worktree isolation for non-global state paths
- Change default thinking level to 'max'
- Bump pi plugin version to 0.2.0

This change unifies the configuration structure for both delegate and
review skills by adopting a shared named-endpoint format. All execution
is now offloaded to a dedicated pi-agent layer, ensuring consistent
backgrounding, validation, and error reporting. Worktree isolation was
improved by allowing configurable agent directories to prevent
out-of-worktree writes, and default settings were updated to prioritize
'max' thinking. The plugin version is bumped to 0.2.0.

Co-Authored-By: DeepSeek V4 Flash <noreply@deepseek.com>
Co-Authored-By: Git Agent <noreply@git-agent.dev>
- Revert marketplace.json to 1-space indentation
- Bump pi plugin version to 0.2.0

This change restores consistent 1-space formatting in the marketplace
config and updates the pi plugin version to 0.2.0.

Co-Authored-By: DeepSeek V4 Flash <noreply@deepseek.com>
Co-Authored-By: Git Agent <noreply@git-agent.dev>
@FradSer FradSer added the enhancement New feature or request label Aug 9, 2026
code-terrier[bot]

This comment was marked as resolved.

FradSer and others added 3 commits August 9, 2026 13:31
- Use PROVIDER_KEY to isolate agent configuration
- Preserve empty PROVIDER values for default use
- Reconfigure defaultEndpoint instead of static keys
- Conditionalize provider flag injection

This prevents the PI agent from leaking the openai provider into the
environment, allowing it to fall back to defaults. It also updates the
setup skill to resolve the defaultEndpoint dynamically, preventing
orphan entries.

Co-Authored-By: DeepSeek V4 Flash <noreply@deepseek.com>
Co-Authored-By: Git Agent <noreply@git-agent.dev>
- Remove pi tool from delegate skill for flow enforcement
- Include project and user CLAUDE.md in pi-agent context
- Document bash requirement for resolve_env in scripts

This change updates the delegate skill by removing direct pi tool access
to ensure architectural consistency. It integrates CLAUDE.md file
collection into the pi-agent delegation logic for better context
awareness and adds critical documentation regarding bash shell
requirements for environment variable resolution.

Co-Authored-By: DeepSeek V4 Flash <noreply@deepseek.com>
Co-Authored-By: Git Agent <noreply@git-agent.dev>
@code-terrier

code-terrier Bot commented Aug 9, 2026

Copy link
Copy Markdown

Code Terrier Review: primary reviewer failed

The primary model gateway-compat|dynamic/deepseek-v4-flash did not complete, so no review was published for this commit.

The primary is the verifier and publish identity for a review — without it, any findings the
other models produced would go out unverified, and an empty result would read as "no issues"
when the truth is "the main reviewer never ran". Failing loudly is deliberate.

  • Primary: gateway-compat|dynamic/deepseek-v4-flash
  • Other reviewers that did finish: 1
Failure detail
ReviewerError: pi review error: pi exited 0 without calling its terminating tool: {"input":0,"output":0,"cacheRead":0,"cacheWrite":0,"total":0}},"stopReason":"error","timestamp":1786255198389,"responseId":"6091d242-f6fb-4ad7-81cd-337c6eaf658f","responseModel":"deepseek-v4-flash","errorMessage":"Stream ended without finish_reason"}],"willRetry":false}
{"type":"auto_retry_end","success":false,"attempt":3,"finalError":"Stream ended without finish_reason"}
{"type":"agent_settled"}

Push a new commit (or re-run the review) once the underlying cause is resolved.

code-terrier[bot]

This comment was marked as resolved.

- Route doctor command through pi-agent for permissions
- Enable MODE=doctor within pi-agent lifecycle
- Resolve AGENT_DIR consistently across configurations
- Gate git context collection on MODE=delegate
- Apply conditional provider flags in test execution

This refactor centralizes agent diagnostics by routing the doctor
workflow through pi-agent, ensuring consistent configuration resolution.
It fixes directory targeting for model definitions by prioritizing
custom AGENT_DIR paths. Additionally, the update optimizes context
overhead by gating git data collection and improves provider selection
logic.

Co-Authored-By: DeepSeek V4 Flash <noreply@deepseek.com>
Co-Authored-By: Git Agent <noreply@git-agent.dev>
code-terrier[bot]

This comment was marked as resolved.

FradSer and others added 2 commits August 9, 2026 15:02
- Replace logical chains with explicit conditional blocks
- Pin doctor probe to directory for environment isolation
- Use bash arrays to prevent shell word splitting

This update hardens the pi cli by resolving provider logic flaws,
enforcing local directory scoping for doctor probes, and implementing
shell-safe command execution.

Co-Authored-By: DeepSeek V4 Flash <noreply@deepseek.com>
Co-Authored-By: Git Agent <noreply@git-agent.dev>
- Add model ownership verification to ensure consistency between endpoints
- Implement CLI --endpoint and --model override resolution
- Re-resolve provider and base URL settings after CLI flag processing

This change updates the delegate and review skill readers to validate
that the selected model belongs to the active endpoint, falling back to
the first available model if a mismatch occurs. It also introduces
robust handling for CLI overrides, allowing users to explicitly select
endpoints or models, which triggers a re-resolution of provider and
configuration metadata to maintain consistency.

Co-Authored-By: DeepSeek V4 Flash <noreply@deepseek.com>
Co-Authored-By: Git Agent <noreply@git-agent.dev>
code-terrier[bot]

This comment was marked as resolved.

- Re-resolve model and endpoint with flag region scoping
- Move model ownership checks after CLI re-resolution
- Pin setup probes to PI_CODING_AGENT_DIR and default to openai
- Honor TASK_TEXT in empty-diff guard for review

This refactor isolates flag parsing from task descriptions, ensuring
correct scoping for models and endpoints. It also centralizes ownership
checks, fixes setup probe paths, and improves empty-diff logic.

Co-Authored-By: DeepSeek V4 Flash <noreply@deepseek.com>
Co-Authored-By: Git Agent <noreply@git-agent.dev>
@code-terrier

code-terrier Bot commented Aug 9, 2026

Copy link
Copy Markdown

Code Terrier Review: primary reviewer failed

The primary model gateway-compat|dynamic/deepseek-v4-flash did not complete, so no review was published for this commit.

The primary is the verifier and publish identity for a review — without it, any findings the
other models produced would go out unverified, and an empty result would read as "no issues"
when the truth is "the main reviewer never ran". Failing loudly is deliberate.

  • Primary: gateway-compat|dynamic/deepseek-v4-flash
  • Other reviewers that did finish: 1
Failure detail
ReviewerError: pi review error: pi exited 0 without calling its terminating tool: {"input":0,"output":0,"cacheRead":0,"cacheWrite":0,"total":0}},"stopReason":"error","timestamp":1786262628256,"responseId":"b70961dd-1a10-40ba-b075-5f13addd0234","responseModel":"deepseek-v4-flash","errorMessage":"Stream ended without finish_reason"}],"willRetry":false}
{"type":"auto_retry_end","success":false,"attempt":3,"finalError":"Stream ended without finish_reason"}
{"type":"agent_settled"}

Push a new commit (or re-run the review) once the underlying cause is resolved.

@FradSer

FradSer commented Aug 9, 2026

Copy link
Copy Markdown
Owner Author

@code-terrier review

code-terrier[bot]

This comment was marked as resolved.

FradSer and others added 2 commits August 9, 2026 16:40
- Remove unmatched fi block in review settings snippet
- Prevent model overrides when --model CLI flag is provided
- Allow provider to remain empty during endpoint creation

This change fixes a bash syntax error in the review settings, ensures
that CLI-provided model arguments take precedence over configuration
defaults, and allows the provider field to remain empty upon endpoint
creation to support default selection logic.

Co-Authored-By: DeepSeek V4 Flash <noreply@deepseek.com>
Co-Authored-By: Git Agent <noreply@git-agent.dev>
- Redirect stdin from /dev/null for pi commands
- Resolve API_KEY and BASE_URL within pi-agent
- Remove sensitive credentials from caller context
- Enforce background execution for all pi tasks

This refactor enhances security and reliability. By resolving secrets
locally within the agent, we prevent sensitive data from leaking into
the model prompt. Redirecting stdin prevents hanging, while background
execution ensures consistent process handling.

Co-Authored-By: DeepSeek V4 Flash <noreply@deepseek.com>
Co-Authored-By: Git Agent <noreply@git-agent.dev>
@FradSer

FradSer commented Aug 9, 2026

Copy link
Copy Markdown
Owner Author

@code-terrier review

code-terrier[bot]

This comment was marked as resolved.

- Add ENDPOINT input for credential resolution
- Remove API_KEY and BASE_URL from doctor handoff
- Update documentation for agent-side loading

This change updates the pi-agent protocol to pass only the non-secret
ENDPOINT. By delegating credential resolution to the agent's local
settings, we prevent raw secrets from entering the model context during
handoffs.

Co-Authored-By: DeepSeek V4 Flash <noreply@deepseek.com>
Co-Authored-By: Git Agent <noreply@git-agent.dev>
@FradSer

FradSer commented Aug 9, 2026

Copy link
Copy Markdown
Owner Author

@code-terrier review

code-terrier[bot]

This comment was marked as resolved.

- Parse cli --api-key in delegate skill for overrides
- Pass cli-provided api key to pi-agent execution
- Export resolved credentials for doctor probe
- Prevent config secrets from leaking into context

This change updates the delegate skill to allow api key overrides via
cli flags. It secures the execution context by preventing config file
secrets from leaking into the model and ensures doctor mode correctly
tests connectivity by exporting resolved credentials.

Co-Authored-By: DeepSeek V4 Flash <noreply@deepseek.com>
Co-Authored-By: Git Agent <noreply@git-agent.dev>
@FradSer

FradSer commented Aug 9, 2026

Copy link
Copy Markdown
Owner Author

@code-terrier review

code-terrier[bot]

This comment was marked as resolved.

- Prevent CLI --api-key from being overwritten by config
- Update resolution logic to prioritize CLI input
- Move config reading script to references/settings.md
- Reduce token overhead in skill documentation

This change ensures the CLI provided API key takes precedence over
config file values. The resolution logic was updated to check
existing values before reading from files, and documentation was
refined to reduce token overhead.

Co-Authored-By: DeepSeek V4 Flash <noreply@deepseek.com>
Co-Authored-By: Git Agent <noreply@git-agent.dev>

@code-terrier code-terrier Bot 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.

Code Terrier reviewed the changes — no issues found. ✅

Open in Code Terrier

@FradSer
FradSer merged commit 9afb95b into main Aug 9, 2026
89 checks passed
@FradSer
FradSer deleted the feat/pi-refactor branch August 9, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant