repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

extensions/angel/README.md

Raw

angel

Structured advisor and command guardrail for configured Pi model pairs.

Angel is available only when the active executor model matches a configured executor/advisor pair and the advisor model is registered.

It builds a context packet, asks the paired advisor model for JSON advice, injects advice after tool errors, and blocks selected dangerous shell commands once.

Install / load

Angel is loaded through the root pi-ext package. See root README.

Commands / tools / settings

Tools

angel asks the configured advisor model for structured advice.

angel({
  question: "What should I validate before editing auth?",
  context: "Extra context not already visible",
});

Parameters:

The tool is active only when angel.enabled !== false, the active model matches an angel.pairs[].executor entry, and the paired advisor model is registered.

Commands

Hooks

Settings

angel settings are read from Pi settings: global ~/.pi/agent/settings.json and project .pi/settings.json.

Example:

{
  "angel": {
    "pairs": [
      {
        "executor": "eldoria/wyvern",
        "advisor": "openai-codex/gpt-5.5"
      },
      {
        "executor": "openai-codex/gpt-5.5",
        "advisor": "eldoria/wyvern"
      }
    ],
    "maxCallsPerTask": 4,
    "enabled": true,
    "autoOnErrors": 1,
    "policyGate": "block"
  }
}

Pair fields:

Setting Type Default Notes
pairs { executor, advisor }[] [] Required for availability
maxCallsPerTask number 4 Session call budget
enabled boolean true Disables tool and gates if false
autoOnErrors number 1 Auto-consult every Nth failed tool result; 0 disables auto-consult
policyGate off|block block Gate dangerous bash commands once

Behavior

Policy Gates

No popups.

When policyGate is block:

  1. Executor attempts selected dangerous bash: sudo, rm -rf, git push, npm publish, pnpm publish, bun publish, recursive chmod/chown, dd if=/dd of=, mkfs, curl|sh, curl|bash, wget|sh, wget|bash, or fork bomb syntax.
  2. Angel blocks that exact command once.
  3. Angel consults the advisor and returns formatted advice in the block reason.
  4. Executor may retry the same command if still correct. Angel will not block that exact command again in the session.

The gate is skipped when Angel is disabled, policyGate is off, the command does not match the dangerous-command pattern, no executor/advisor binding exists, advisor auth is missing, or the session call budget is exhausted.

Difference from devil

Markdown source
File outline
# angel

Structured advisor and command guardrail for configured Pi model pairs.

Angel is available only when the active executor model matches a configured
executor/advisor pair and the advisor model is registered.

It builds a context packet, asks the paired advisor model for JSON advice,
injects advice after tool errors, and blocks selected dangerous shell commands
once.

## Install / load

Angel is loaded through the root `pi-ext` package.
See [root README](../../README.md).

## Commands / tools / settings

### Tools

`angel` asks the configured advisor model for structured advice.

```javascript
angel({
  question: "What should I validate before editing auth?",
  context: "Extra context not already visible",
});
```

Parameters:

- `question` optional string:
  advisor focus.
- `context` optional string:
  extra context added to the context packet.

The tool is active only when `angel.enabled !== false`, the active model matches
an `angel.pairs[].executor` entry, and the paired advisor model is registered.

### Commands

- `/angel on|off`:
  toggle Angel for the current session.
  Argument hint `<on|off>` and tab completion for `on` / `off`.
  Defaults to `settings.enabled !== false` on session start.
  No persistence — resets each session.
  Re-runs `syncAvailability` to show/hide the `angel` tool and status.

### Hooks

- `session_start`:
  resets call/error/gate counters, restores latest `angel-advice`, syncs tool
  availability.
- `model_select`:
  syncs tool availability for the selected executor model.
- `tool_call`:
  blocks selected dangerous `bash` commands once when `policyGate` is `block`.
- `tool_result`:
  auto-consults after every `autoOnErrors`-th failed non-`angel` tool result.

### Settings

`angel` settings are read from Pi settings: global
`~/.pi/agent/settings.json` and project `.pi/settings.json`.

Example:

```json
{
  "angel": {
    "pairs": [
      {
        "executor": "eldoria/wyvern",
        "advisor": "openai-codex/gpt-5.5"
      },
      {
        "executor": "openai-codex/gpt-5.5",
        "advisor": "eldoria/wyvern"
      }
    ],
    "maxCallsPerTask": 4,
    "enabled": true,
    "autoOnErrors": 1,
    "policyGate": "block"
  }
}
```

Pair fields:

- `executor`:
  active model required for Angel availability.
  Matches `provider/model` or bare model id.
- `advisor`:
  model Angel calls for advice.
  Prefer `provider/model`; bare ids use the executor provider.

| Setting           | Type                      | Default | Notes                                                                |
| ----------------- | ------------------------- | ------: | -------------------------------------------------------------------- |
| `pairs`           | `{ executor, advisor }[]` |    `[]` | Required for availability                                            |
| `maxCallsPerTask` | number                    |     `4` | Session call budget                                                  |
| `enabled`         | boolean                   |  `true` | Disables tool and gates if false                                     |
| `autoOnErrors`    | number                    |     `1` | Auto-consult every Nth failed tool result; `0` disables auto-consult |
| `policyGate`      | `off\|block`              | `block` | Gate dangerous bash commands once                                    |

## Behavior

- Builds a fresh context packet from session state:
  cwd, user request, system prompt, context usage, recent conversation, touched
  files, recent tool errors, missing-source notes, truncation limits, optional
  extra context.
- Includes up to 200 recent messages, 50 touched files, 30k chars per touched
  file, 9 recent tool errors, and 60k chars of system prompt.
- Tracks touched files from prior `read`, `edit`, and `write` tool calls.
- Calls the configured advisor model for the active executor model.
- Requests JSON advice with summary, next action, risks, assumptions, validation
  checklist, enforceable policy, advisory-only guidance, confidence, and
  insufficient-context flag.
- Strips JSON markdown fences before parsing advisor output.
- Falls back to low-confidence advisory text when the advisor response is not
  valid JSON.
- Persists advice as `angel-advice` entries with packet summary metadata.
- Injects formatted advice into the agent loop after configured failed
  tool-result intervals.
- Keeps semantic guidance in `advisoryOnly`; only dangerous-command detection is
  mechanical.
- Tool render marks low-confidence advice as `low confidence`; formatted advice
  prepends a `> ⚠ ADVISOR UNCERTAIN` banner and marks `Doubt` as recommended when
  confidence is below 50%.

## Policy Gates

No popups.

When `policyGate` is `block`:

1. Executor attempts selected dangerous `bash`:
   `sudo`, `rm -rf`, `git push`, `npm publish`, `pnpm publish`, `bun publish`,
   recursive `chmod`/`chown`, `dd if=`/`dd of=`, `mkfs`, `curl|sh`,
   `curl|bash`, `wget|sh`, `wget|bash`, or fork bomb syntax.
2. Angel blocks that exact command once.
3. Angel consults the advisor and returns formatted advice in the block reason.
4. Executor may retry the same command if still correct.
   Angel will not block that exact command again in the session.

The gate is skipped when Angel is disabled, `policyGate` is `off`, the command
does not match the dangerous-command pattern, no executor/advisor binding
exists, advisor auth is missing, or the session call budget is exhausted.

## Difference from devil

- `devil`:
  adversarial stress-test of an idea.
  User-initiated.
- `angel`:
  paired execution advisor, max-context packet, error-triggered advice,
  dangerous-command gate.