@amaster.ai/pi-goal

中文文档
0.1.37发布于 2026/11/09Apache-2.0TypeScriptES Module近 30 天下载 3715

Pi extension that derives a goal from the conversation and keeps the agent working until the condition is met

原始使用文档
文档目录6 节
  1. How it works
  2. Pi lifecycle (how the engine hooks in)
  3. Usage
  4. Configuration
  5. Relationship to Claude Code / Codex
  6. Failure diagnostics

@amaster.ai/pi-goal

pi-goal preview

A Pi extension that lets Pi keep working until a goal is met. You don't have to write the completion condition yourself — run /goal with no argument and the extension derives a measurable condition from the conversation, shows it to you for a quick confirmation, then keeps the agent working (re-checking after each run) until the condition holds.

Modeled on Claude Code's stop-condition mechanism, with a token/iteration budget backstop borrowed from Codex's goal mode.

How it works

  1. Set a goal. Either give an explicit condition (/goal all tests pass and lint is clean) or let the extension derive one from the conversation (/goal with no argument).
  2. Derived goals are confirmed in interactive (TUI) mode before they start, so a mis-derived goal can't run off on its own. Non-interactive modes skip the confirmation.
  3. After each agent run (agent_end), a small evaluator model judges whether the condition is met:
    • Met → the goal is marked achieved and cleared. Pi stops.
    • Not yet → Pi is nudged to continue, told what still remains.
    • Impossible → Pi stops and tells you why.
  4. Backstops. Continuation stops after maxIterations rounds or once an optional tokenBudget is exceeded, so a bad goal can't loop forever.

Goal state is session-scoped and held in memory (no cross-session persistence), matching Claude Code's behavior.

Pi lifecycle (how the engine hooks in)

The goal engine is driven by Pi's lifecycle events. For one pi -p '<prompt>' run (non-interactive), events fire in this order:

session_start                                 ← session-level, once
  │   pi-goal: load config, read the --goal flag
  ▼
[ per user prompt — the "agent-level" block below repeats ]
  │
  before_agent_start  { prompt, systemPrompt } ← carries the user's input for this turn, once per prompt
  │
  agent_start         { }
  │
  ├─ [ per turn, may repeat ]
  │    turn_start       { turnIndex }
  │    message_start    { message (user) }
  │    message_end      { message (user) }
  │    message_start    { message (assistant) }
  │    message_end      { message (assistant) }
  │    turn_end         { turnIndex, message, toolResults }
  │
  agent_end           { messages: [...] }       ← engine evaluates + stops/continues, once per prompt
  │   If a goal is active: build a transcript from `messages`, ask the
  │   evaluator ok / impossible / not-yet. Not-yet → sendUserMessage(continue)
  │   → triggers a new agent run (back to before_agent_start).
  │
  agent_settled       { }                        ← this prompt is fully done
  ▼
[ interactive: wait for next input · print mode: process exits here ]

session_shutdown                               ← on exit/switch; pi-goal clears state

Events pi-goal uses:

EventWhat pi-goal doesNotes
session_startLoad config; read the --goal flagSession-level, fires once
before_agent_startIf a --goal derivation is pending, derive the condition from event.prompt (this turn's user input), then set the goalFires once per prompt; the right anchor for auto-derivation since no transcript exists yet at session_start
agent_endIf a goal is active, run the engine on event.messages: evaluate → mark achieved/impossible or queue a sendUserMessage follow-up to continueEngine core. event.messages is the full conversation, so no separate buffering is needed
session_shutdownClear the goalCleanup

The interactive /goal command (no argument) derives from the session's own history, read via ctx.sessionManager — not a buffer this extension maintains.

Note on derivation timing: a condition can only be derived once there is conversation to derive from. session_start is too early (no transcript yet); before_agent_start is the first point that carries the user's prompt for the turn, so auto-derivation keys off it rather than firing at startup.

Usage

/goal <condition>   Set an explicit completion condition.
/goal               No active goal → derive one from the conversation (with confirmation).
                    Active goal → show its status.
/goal clear         Clear the active goal (also: stop, off, reset, none, cancel).

The slash command is for interactive (TUI) use; print mode can't dispatch it. For the CLI / non-interactive runs, use the --goal flag instead:

pi --goal '<condition>' -p '<prompt>'   Set an explicit goal, then run the prompt.
pi --goal '' -p '<prompt>'              Derive the goal from the prompt (at before_agent_start).

Configuration

Settings key: pi-goal (in ~/.pi/agent/settings.json, agent dir, or project .pi/settings.json). Project settings are loaded only after project trust is accepted. Environment-variable interpolation is available in user and agent settings, but not in project settings.

{
  "pi-goal": {
    "model": { "provider": "anthropic", "model": "claude-haiku-4-5-20251001" },
    "maxIterations": 10,
    "tokenBudget": 200000,
    "transcriptMaxChars": 8000,
    "requireConfirmForDerived": true
  }
}
KeyDefaultPurpose
model—Provider/model for deriving and evaluating conditions. Omit to disable the automatic engine — /goal <condition> still sets a goal, but nothing auto-derives or auto-continues.
maxIterations10Max continuation rounds before Pi stops pushing.
tokenBudget—Optional hard token ceiling; the goal is paused (budget_limited) once exceeded.
transcriptMaxChars8000Max transcript chars fed to derive/evaluate.
requireConfirmForDerivedtrueAsk before starting a derived goal (TUI only).

Prefer a small, cheap model for model — the evaluator runs after every agent run.

Relationship to Claude Code / Codex

  • Engine (from Claude Code): goal = a stop condition; Pi keeps going until an evaluator judges it met. Passive — it drives continuation off agent_end, not a background scheduler.
  • Prompts (from Claude Code): the evaluator and activation prompts are adapted almost verbatim from Claude Code's own stop-hook prompts — including the quote-the-evidence requirement, the "insufficient evidence in transcript" fallback, the impossible-judgment discipline (the assistant's claim is evidence, not proof), and the truncated-transcript note.
  • Auto-derivation: you don't have to phrase the condition; it's inferred and confirmed. (No CC analogue — CC always takes an explicit condition.)
  • Budget backstop (from Codex): token + iteration limits prevent runaway loops.
  • Not included: Codex's idle auto-resume, pause/resume dialogs, file-backed objectives, and cross-session persistence.

Transcript limits include role labels and separators. An oversized newest message retains its beginning and conclusion within the configured limit and is reported as partially omitted evidence. If evaluation reports insufficient evidence, continuation asks the agent to recover original files or recorded results before rerunning unavailable checks.

Failure diagnostics

Evaluator failures keep the goal active and make the unavailable evaluation visible; they do not trigger continuation or mark the goal complete. The nullable completion API is preserved, with an optional onError callback carrying safe diagnostics on completeOnce, EvaluateOptions, and DeriveOptions.

版本与发布记录

@amaster.ai/pi-goal 共发布 82 个版本,首次发布于 2026/07/17;过去 12 个月发布了 82 个版本。

版本发布日期距今
0.1.37latest2026/11/09今天
0.1.2-beta.91beta2026/11/072 天前
0.1.2-beta.902026/11/062 天前
0.1.2-beta.892026/11/054 天前
0.1.2-beta.882026/11/054 天前
0.1.362026/11/054 天前

关于 @amaster.ai/pi-goal 的常见问题

@amaster.ai/pi-goal 是什么?

Pi extension that derives a goal from the conversation and keeps the agent working until the condition is met

如何安装 @amaster.ai/pi-goal?

在项目目录运行 npm install @amaster.ai/pi-goal,或使用 pnpm add / yarn add / bun add。

@amaster.ai/pi-goal 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@amaster.ai/pi-goal 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@amaster.ai/pi-goal 可以商用吗?

@amaster.ai/pi-goal 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@amaster.ai/pi-goal 的下载量有多少?

根据 npm 官方下载统计,@amaster.ai/pi-goal 在 2026/10/06 – 2026/11/04 这 30 天内被下载 3,715 次,日均约 124 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@amaster.ai/pi-goal 还在维护吗?

最新版本 0.1.37 发布于 2026/11/09(今天);至今共发布 82 个版本,其中过去 12 个月发布了 82 个;首次发布于 2026/07/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。