repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

extensions/ultra/prompts/authoring-workflows.md

Raw

Authoring ultra workflows

These instructions help you choose between running an ephemeral one-off ultra workflow and co-designing a persisted workflow the user can re-run as /ultra run <name>. The canonical spec format is injected below; use it before writing any spec and do not restate it from memory.

First: persist vs. one-off

Infer the user's intent from the request and its context. Choose a persisted workflow when durable reuse is explicit or strongly implied, such as repeated use, a named utility, sharing, or future /ultra run invocations. Choose an ephemeral one-off when the request seeks one bounded result now and gives no meaningful reuse signal. Do not treat /ultra exec itself or generic creation verbs as evidence for persistence.

When confidence is high, act on that choice without asking or announcing the routing. When confidence is not high, ask one focused question before invoking run_workflow or writing a workflow file. Never resolve uncertainty by defaulting to persistence or ephemerality.

Single-agent gate

Use ultra only when independent parallel work, staged agent handoffs, or isolated specialist contexts materially improve the result. Otherwise perform the task directly and skip ultra's orchestration overhead.

Dynamic-extension delegation

Delegate one builder when a reusable extension can encode specialized capability, deterministic operations, or repeated reasoning that materially improves the user's task. A builder step selects all four tools: search_dynamic_extensions, create_dynamic_extension, checkout_dynamic_extension, and validate_dynamic_extension. Its brief states topic, outcome, intended consumers, and done conditions; it may add assumptions, current platform, relevant paths or evidence, and hard constraints. One builder owns one extension. Independent builder topics may fan out only with a non-empty writeIsolation rationale assigning disjoint ownership. Use big plus high for new architecture and medium plus high for bounded improvements unless task economics justify another deliberate choice. Known canonical names may be placed directly in a consumer's dynamicExtensions; discovery, creation, improvement, stale validation, and repair require a builder. Builder failure blocks later phases; never design a normal-tool fallback.

Authoring flow (persisted)

  1. Understand the goal. What does each stage do, and what flows between stages? Most workflows are fan-out then synthesize: parallel agents each handle one item (a dimension, a file, a finding), then a single pass judges or merges. Sketch the phases before writing JSON.

  2. Co-design the phases. For each phase decide:

    • Give every phase a unique interpolation identifier; the reserved phase ID args is forbidden.
    • single (one synthesis/judge pass) vs. fanout (one agent per item).
    • fanout needs an over — a literal array, or an interpolation token over a prior phase's results (e.g. {review.results[].findings[]}).
    • Optional when uses one existing selector; empty/false skips the phase and produces empty results.
    • A recovery fan-out may use {PHASE.failures} for both when and over; recovery remains one explicit later phase, never a loop.
    • The step's short summary, exact prompt, tools, and how tightly its structured JSON output must be constrained by a schema.
    • summary is one concise progress-UI sentence, uses the same interpolation grammar as prompt, and must describe the concrete sub-agent task without paraphrasing its result.
  3. Declare fan-out ownership. A fanout step without writeIsolation stays within Pi's core read, grep, find, ls, and bash tools, and its prompt must forbid mutation because parallel writers race. A mutating fan-out requires a non-empty writeIsolation rationale and a prompt assigning disjoint ownership to each item. Loaded extensions remain trusted to activate additional tools. Every listed tool must be installed and available or Ultra refuses to start the workflow.

  4. Design schemas and join-keys. Give a step a schema (named in schemas, or inline) when a later phase consumes its output. When phase B fans out over phase A's findings, add a shared field (a join-key) to both schemas and tell B to echo it, so each result ties back to its source. See the review worked example in the reference.

  5. Wire interpolation. Use only the closed grammar in both summary and prompt ({args.NAME}, {item}, {PHASE.results}, {PHASE.failures}, {PHASE.results[].FIELD[]}, {EXPR | where FIELD}). Keep literal {/} out of prompts except these tokens. Set return to the selector for the workflow's final value.

  6. Assign compute deliberately. For every step:

    • big — planning, specification, architecture, critique, synthesis.
    • medium — coding, testing, editing, routine implementation.
    • small — scouting, extraction, classification, easy text work.
    • Set thinkingLevel from off, minimal, low, medium, high, xhigh, or max based on that step's relative ambiguity, constraints, and cost of mistakes. max is the highest opt-in budget and requires model support.
    • Explicitly set both fields. If every phase uses the same pair, challenge the assignment before saving.
  7. Self-check the spec (there is no validator tool). You can't call parseWorkflow directly — verify by inspection against the reference: every required field is present, every step has a short summary, every fanout has an over, every when is one selector, every string schema names a key in schemas, and interpolation uses only the closed grammar. The real validator is the load itself: saving and test-running (steps 8–9) parses the file through the runtime's parseWorkflow, which surfaces a TypeBox error naming the offending path if anything is malformed — fix and re-run until it loads clean. One caveat: a JSON syntax error (a trailing comma, a missing quote) makes the file invisible to discovery entirely, so /ultra run <name> reports unknown workflow rather than a schema error — if a saved workflow seems to vanish, confirm it is valid JSON first.

  8. Save it. Write the spec as <name>.json (filename matching the spec's name):

    • project-scoped (lives in the repo): <cwd>/.pi/workflows/<name>.json
    • personal / global: ~/.pi/agent/workflows/<name>.json

    Ask which scope only if it isn't clear from context (a repo-specific review workflow → project; a personal utility → global).

  9. Offer a test run. After saving, offer to run it: /ultra run <name> (with any args the spec's hint declares). Tighten prompts/schemas from what the first run surfaces.

Ephemeral one-off

For a one-off, skip the persisted flow: construct the spec inline and call run_workflow with it as spec. Use the same format and rules (spec-format.md, fan-out ownership), but write nothing to disk. If the user later wants reuse, save it via the persisted flow.

Markdown source
File outline
# Authoring ultra workflows

These instructions help you choose between running an **ephemeral one-off**
ultra workflow and co-designing a **persisted** workflow the user can re-run as
`/ultra run <name>`.
The canonical spec format is injected below; use it before writing any spec and
do not restate it from memory.

## First: persist vs. one-off

Infer the user's intent from the request and its context.
Choose a **persisted** workflow when durable reuse is explicit or strongly implied, such as repeated use, a named utility, sharing, or future `/ultra run` invocations.
Choose an **ephemeral one-off** when the request seeks one bounded result now and gives no meaningful reuse signal.
Do not treat `/ultra exec` itself or generic creation verbs as evidence for persistence.

When confidence is high, act on that choice without asking or announcing the routing.
When confidence is not high, ask one focused question before invoking `run_workflow` or writing a workflow file.
Never resolve uncertainty by defaulting to persistence or ephemerality.

## Single-agent gate

Use ultra only when independent parallel work, staged agent handoffs, or isolated specialist contexts materially improve the result.
Otherwise perform the task directly and skip ultra's orchestration overhead.

## Dynamic-extension delegation

Delegate one builder when a reusable extension can encode specialized capability, deterministic operations, or repeated reasoning that materially improves the user's task.
A builder step selects all four tools: `search_dynamic_extensions`, `create_dynamic_extension`, `checkout_dynamic_extension`, and `validate_dynamic_extension`.
Its brief states topic, outcome, intended consumers, and done conditions; it may add assumptions, current platform, relevant paths or evidence, and hard constraints.
One builder owns one extension.
Independent builder topics may fan out only with a non-empty `writeIsolation` rationale assigning disjoint ownership.
Use `big` plus `high` for new architecture and `medium` plus `high` for bounded improvements unless task economics justify another deliberate choice.
Known canonical names may be placed directly in a consumer's `dynamicExtensions`; discovery, creation, improvement, stale validation, and repair require a builder.
Builder failure blocks later phases; never design a normal-tool fallback.

## Authoring flow (persisted)

1. **Understand the goal.** What does each stage do, and what flows between
   stages? Most workflows are _fan-out then synthesize_: parallel agents each
   handle one item (a dimension, a file, a finding), then a `single` pass
   judges or merges. Sketch the phases before writing JSON.

2. **Co-design the phases.** For each phase decide:
   - Give every phase a unique interpolation identifier; the reserved phase ID `args` is forbidden.
   - `single` (one synthesis/judge pass) vs. `fanout` (one agent per item).
   - `fanout` needs an `over` — a literal array, or an interpolation token over
     a prior phase's results (e.g. `{review.results[].findings[]}`).
   - Optional `when` uses one existing selector; empty/false skips the phase and produces empty results.
   - A recovery fan-out may use `{PHASE.failures}` for both `when` and `over`; recovery remains one explicit later phase, never a loop.
   - The step's short `summary`, exact `prompt`, `tools`, and how tightly its structured JSON output must be constrained by a schema.
   - `summary` is one concise progress-UI sentence, uses the same interpolation grammar as `prompt`, and must describe the concrete sub-agent task without paraphrasing its result.

3. **Declare fan-out ownership.** A `fanout` step without `writeIsolation` stays
   within Pi's core `read`, `grep`, `find`, `ls`, and `bash` tools, and its prompt
   must forbid mutation because parallel writers race.
   A mutating fan-out requires a non-empty `writeIsolation` rationale and a prompt assigning disjoint ownership to each item.
   Loaded extensions remain trusted to activate additional tools.
   Every listed tool must be installed and available or Ultra refuses to start the workflow.

4. **Design schemas and join-keys.** Give a step a `schema` (named in `schemas`,
   or inline) when a later phase consumes its output. When phase B fans out over
   phase A's findings, add a shared field (a join-key) to both schemas and tell
   B to echo it, so each result ties back to its source. See the `review`
   worked example in the reference.

5. **Wire interpolation.** Use only the closed grammar in both `summary` and `prompt` (`{args.NAME}`, `{item}`,
   `{PHASE.results}`, `{PHASE.failures}`, `{PHASE.results[].FIELD[]}`, `{EXPR | where FIELD}`). Keep
   literal `{`/`}` out of prompts except these tokens. Set `return` to the
   selector for the workflow's final value.

6. **Assign compute deliberately.** For every step:
   - `big` — planning, specification, architecture, critique, synthesis.
   - `medium` — coding, testing, editing, routine implementation.
   - `small` — scouting, extraction, classification, easy text work.
   - Set `thinkingLevel` from `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, or `max` based on that step's relative ambiguity, constraints, and cost of mistakes. `max` is the highest opt-in budget and requires model support.
   - Explicitly set both fields. If every phase uses the same pair, challenge the assignment before saving.

7. **Self-check the spec (there is no validator tool).** You can't call
   `parseWorkflow` directly — verify by inspection against the reference: every
   required field is present, every step has a short `summary`, every `fanout` has an `over`, every `when` is one selector, every string
   `schema` names a key in `schemas`, and interpolation uses only the closed
   grammar. The real validator is the load itself: saving and test-running
   (steps 8–9) parses the file through the runtime's `parseWorkflow`, which
   surfaces a TypeBox error naming the offending path if anything is malformed —
   fix and re-run until it loads clean. One caveat: a JSON _syntax_ error (a
   trailing comma, a missing quote) makes the file invisible to discovery
   entirely, so `/ultra run <name>` reports `unknown workflow` rather than a schema
   error — if a saved workflow seems to vanish, confirm it is valid JSON first.

8. **Save it.** Write the spec as `<name>.json` (filename matching the spec's
   `name`):
   - project-scoped (lives in the repo): `<cwd>/.pi/workflows/<name>.json`
   - personal / global: `~/.pi/agent/workflows/<name>.json`

   Ask which scope only if it isn't clear from context (a repo-specific review
   workflow → project; a personal utility → global).

9. **Offer a test run.** After saving, offer to run it: `/ultra run <name>` (with
   any `args` the spec's `hint` declares). Tighten prompts/schemas from what the
   first run surfaces.

## Ephemeral one-off

For a one-off, skip the persisted flow: construct the spec inline and call
`run_workflow` with it as `spec`.
Use the same format and rules (`spec-format.md`, fan-out ownership), but write
nothing to disk.
If the user later wants reuse, save it via the persisted flow.