Skip to content
Skill Authoring
Skill

/pi-durable-multi-provider

Agent playbook for building multi-provider applications with @earendil-works/pi-durable and @earendil-works/pi-ai where every job pins its provider connection (connectionId, provider, modelId, authMethod) before initialization and executes strictly on that pinned connection.

From plugin
skills
2277 skills2 MCP

Claude Code

$ npx -y skills add hoangnb24/skills --skill pi-durable-multi-provider --agent claude-code

SKILL.md

pi-durable-multi-provider.SKILL.md
name: pi-durable-multi-provider
description: "Agent playbook for building multi-provider applications with @earendil-works/pi-durable and @earendil-works/pi-ai where every job pins its provider connection (connectionId, provider, modelId, authMethod) before initialization and executes strictly on that pinned connection."

Agent Playbook: Selection-Pinned Multi-Provider Runtime (`pi-durable` + `pi-ai`)

Use this playbook when implementing or refactoring a system that runs `@earendil-works/pi-durable` agents over `@earendil-works/pi-ai` with multiple provider connections (multiple providers or multiple accounts per provider).

1. Non-Negotiable Architectural Invariants

Every change you write MUST preserve these five invariants. Never weaken them for convenience:

1. **Explicit Selection Pinning Before Job Initialization (`DispatchedCallUsesPinnedSelection`)**:

  • A job's provider selection `PinnedSelection = { connectionId, provider, modelId, authMethod }` is supplied explicitly by the caller at job creation (`submit` / `submitGroup`), validated against the Host catalog, and written immutably into `job.selection` *before* authorization or execution.
  • `settings.selected` in Host Settings is a **UI draft seed only**. Backend job creation, authorization, and `pi-durable` workers MUST NEVER read `settings.selected` or fall back to a global default provider.

2. **Immutable Selection Chain (`SelectionChainIntact`)**:

  • `job.selection` is hashed into `agentInputHash(job)`.
  • Authorization copies `structuredClone(job.selection)` into `job.grant.selection` after verifying `expectedJobIdentity === agentInputHash(job)`.
  • Attempt startup copies `structuredClone(job.grant.selection)` into `job.run.agent.selection`.
  • `pi-durable` persists `sessionBinding.identity` (which includes `job.run.agent.selection`) inside the attempt's `agent.sqlite` before opening the root conversation.

3. **Per-Connection Credential Isolation**:

  • Each login creates a distinct `connectionId` (UUID) with its own `0600` credential file at `providers/<connectionId>/credentials.json`.
  • `boundModels(pinned)` constructs an isolated `pi-ai` `createModels({ credentials, authContext })` instance with **only** `catalog.getProvider(pinned.provider)` registered and `getModel(p, m)` returning `undefined` for any `(p, m) !== (pinned.provider, pinned.modelId)`.

4. **Persisted Task Phase Binding (`CallRequiresActivePiDurableTask`)**:

  • `pi-durable` model calls (`streamSimple` for generation, `completeSimple` for context compaction) are permitted ONLY when an active `'pi.durable.phase'` telemetry span resolves to a running persisted task in `agent.sqlite` (`pi.generation` in phase `request`, or `pi.compaction` in phase `summarize`).

5. **Pre-Handoff Credential Fence & Secret Redaction (`HandoffCredentialFenceHolds`)**:

  • `boundModels.streamSimple` snapshots `{ credential, generation }` from `providers/<connectionId>/credentials.json` on entry.
  • Inside `transformHeaders` (immediately before `pi-ai` invokes the provider SDK), verify that the on-disk credential generation and value have not changed, reject any mutation to auth headers, commit durable input evidence (`beforeInput`), and invoke the synchronous `handoff()` marker.
  • Redact all credential secrets (`key`, `access`, `refresh`, `idToken`, raw and URL-encoded) from every yielded stream event and final `.result()`.

---

2. Core Data Contracts & Storage Layout

Define these shapes first (`pstack-principle-foundational-thinking`) and keep shared mutable state separated by file ownership (`pstack-principle-separate-before-serializing-shared-state`).

Filesystem Layout

<runtime-root>/
├── providers/
│   ├── settings.json                         # Connections list + UI default seed (`selected`)
│   └── <connectionId>/
│       ├── credentials.json                  # Mode 0600, owned exclusively by connectionId store
│       └── catalog.json                      # Optional per-connection model snapshot
├── jobs/
│   └── <jobId>.json                          # Job record with pinned job.selection, grant, run
└── attempts/
    └── <jobId>/<attemptId>/
        ├── agent.sqlite                      # Dedicated pi-durable SQLite database for this attempt
        └── requests/<requestKey>.json        # Durable request ledger (intent -> input -> saved/unknown)

Canonical Identity Digest (`request-identity.js`)

import { createHash } from 'node:crypto';

export const sha256 = (bytes) => createHash('sha256').update(bytes).digest('hex');

export const inputHash = (job) =>
  sha256(Buffer.from(JSON.stringify({
    payload: job.payload,
    references: job.references ?? [],
    base: job.base ?? null,
  })));

export const agentInputHash = (job) =>
  sha256(Buffer.from(JSON.stringify({
    input: inputHash(job),
    selection: job.selection, // { connectionId, provider, modelId, authMethod }
    feedback: job.revisionFeedback ?? null,
    ...(job.assignment ? { assignment: job.assignment } : {}),
    ...(job.continuationOf ? { continuationOf: job.continuationOf } : {}),
  })));

---

3. Sequence of Verifiable Implementation Units

Execute these units in order. Do not advance to the next unit until the current unit's verification check passes.

Unit 1: Isolated Host Provider Settings & `boundModels(pinned)`

**Files to create/modify**: `host/provider-settings.js`

**Implementation requirements**: 1. Initialize the installed catalog via `createModels({ authContext })` from `@earendil-works/pi-ai/models` and register the allowed provider factories (`openrouterProvider`, `googleProvider`, `openaiProvider`, `openaiCodexProvider`). 2. For each connection in `providers/settings.json`, create a per-connection credential store over `providers/<connectionId>/credentials.json` (directory mode `0700`, file mode `0600`). 3. Implement synchronous `dispatchCredential()` on the credential store:

  • `statSync` + `readFileSync`
Read more
@hoangnb24
Ships withskills

Khuym is a focused Codex plugin containing five independent meta-skills and one tool-automation skill. It improves how an agent understands, researches, sequences, lands, and visualizes work without imposing a repository workflow.

2277 skills2 MCP
Get the whole plugin

Stars on GitHub

Momentum

stars in total
227
Star history of hoangnb24/skills on GitHub, a chart by star-history.com

Other skills on skills.

goal-griller

goal-griller

Turn vague ideas into verifiable Codex goals. Use when the user mentions goal mode, /goal, create_goal, autonomous work, or asks…

@hoangnb24@hoangnb24Install Skill
prompt-leverage

prompt-leverage

Upgrade raw prompts into execution-ready instructions. Use when asked to improve a prompt, add context, tool, verification, or…

@hoangnb24@hoangnb24Install Skill
sequence-execution-plan

sequence-execution-pla…

Build dependency-aware plans from goals, incidents, backlogs, or priorities. Use when priority conflicts with execution order and…

@hoangnb24@hoangnb24Install Skill
smart-commits

smart-commits

Organize an existing Git tree into logical commits and push them. Use when asked to commit everything, smart commit, group…

@hoangnb24@hoangnb24Install Skill
tldraw-api

tldraw-api

Create, inspect, edit, persist, and verify tldraw canvases through the tldraw Desktop local Canvas API without mouse-driven…

@hoangnb24@hoangnb24Install Skill
xia

xia

Research unfamiliar implementation work before coding. Use when work is ambiguous, version-sensitive, or risky and requires repo…

@hoangnb24@hoangnb24Install Skill

More skills from other plugins.

gstack-openclaw-ceo-review

gstack-openclaw-ceo-re…

Use when asked to review a plan, challenge a proposal, run a CEO review, poke holes in an approach, think bigger about scope, or…

gstack3w138k
@garrytan@garrytanInstall Skill
book-to-skill

book-to-skill

Converts books and documents (PDF, EPUB, DOCX, HTML, Markdown, plain text, RTF, MOBI/AZW with Calibre) into structured agent…

@virgiliojr94@virgiliojr94Install Skill
distilly

distilly

Set up the owner profile so a personal agent knows who it works for (first-run setup, \"get to know me\"), or distill colleague,…

@titanwings@titanwingsInstall Skill

Questions about pi-durable-multi-provider.

Which coding agents can use pi-durable-multi-provider?
pi-durable-multi-provider installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.