@narumitw/pi-subagents 0.51.0 → 0.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@narumitw/pi-subagents)](https://www.npmjs.com/package/@narumitw/pi-subagents) [![Pi extension](https://img.shields.io/badge/Pi-extension-blue)](https://pi.dev) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](./LICENSE)
4
4
 
5
- `@narumitw/pi-subagents` is a native [Pi coding agent](https://pi.dev) extension for delegating work to specialized agents. By default, it exposes seven capability-specific tools: blocking batches, four detached lifecycle tools, side-effect-free inspection, and synchronous read-only consultation. Users can keep every delegation method, choose async-only delegation, retain only blocking delegation, or disable delegation while keeping inspection available.
5
+ `@narumitw/pi-subagents` is a native [Pi coding agent](https://pi.dev) extension for delegating work to specialized agents. By default, it exposes eight capability-specific tools: blocking batches, explicit autonomous workflow planning, four detached lifecycle tools, side-effect-free inspection, and synchronous read-only consultation. Users can keep every delegation method, choose async-only delegation, retain only blocking delegation, or disable delegation while keeping inspection available.
6
6
 
7
7
  Use it to split independent research, planning, implementation, and review work across focused workers. Under the default next-turn delivery policy, background delegation is for work the current response does not depend on. Opt-in auto-resume also supports final-answer-dependent background work by requesting a synthesis turn after completion.
8
8
 
@@ -11,6 +11,7 @@ Use it to split independent research, planning, implementation, and review work
11
11
  - Offers all delegation methods by default, with goal-oriented presets for async-only, blocking-only, or disabled delegation.
12
12
  - Adds `subagent_inspect` for bounded metadata without child launch, mailbox-content access, acknowledgement, or mutation.
13
13
  - Adds `subagent_consult` for one synchronous ephemeral child constrained to built-in `read`, `grep`, `find`, and `ls` tools (or a narrower agent allow-list).
14
+ - Adds explicit `subagent_auto` requests that use one bounded read-only planning turn and a deterministic compiler to select the smallest justified existing workflow without changing omitted-field behavior.
14
15
  - Keeps batch workers isolated in `pi --mode json -p --no-session` subprocesses.
15
16
  - Lets users set a blocking parallel call's maximum worker count from 1 through 64 while keeping four-at-a-time execution.
16
17
  - Registers detached stateful lifecycle tools by default; completion can stay queued for the next turn or opt into an idle root synthesis turn.
@@ -22,7 +23,7 @@ Use it to split independent research, planning, implementation, and review work
22
23
  - Optionally loads project agents from `.pi/agents/*.md` with confirmation.
23
24
  - Provides a current-session-first `/subagents` manager, direct `settings|status|help` routes, and compatibility aliases for agent tools and retained agents.
24
25
  - Supports trust-aware per-task `cwd` policies, task-selected work, workflow, idle, turn, and tool-call budgets, deterministic timeout checkpoints, bounded abort-then-summary recovery, progress telemetry, and explicit Fast, Balanced, or Deep thinking profiles.
25
- - Renders all seven tools with Pi-native compact/expanded transcript rows; long-running blocking and consultation calls show bounded live activity.
26
+ - Uses Pi-native tool rows throughout; blocking and consultation calls add bounded custom live activity.
26
27
  - Bounds JSON lines, captured messages, stderr, final output, chain substitution, and fan-in context.
27
28
  - Enforces a recursion-depth guard and deterministic process-group termination.
28
29
  - Provides addressable stateful agents with follow-up, consolidated mailbox/management actions, idempotent spawn retries, context selection and preview, versioned structured outcomes, and persistence.
@@ -54,13 +55,13 @@ pi -e ./packages/pi-subagents
54
55
 
55
56
  ## 🛠️ Pi tool
56
57
 
57
- `pi-subagents` registers seven tools by default. Run `/subagents`, choose **Change delegation**, review the concrete tool changes, then select **Save and reload** to apply one of these workflows:
58
+ `pi-subagents` registers eight tools by default. Run `/subagents`, choose **Change delegation**, review the concrete tool changes, then select **Save and reload** to apply one of these workflows:
58
59
 
59
60
  | Workflow | Registered tools |
60
61
  | --- | --- |
61
- | **All delegation methods** (default) | Existing five delegation/lifecycle tools, `subagent_inspect`, and `subagent_consult` |
62
+ | **All delegation methods** (default) | Existing five delegation/lifecycle tools, `subagent_auto`, `subagent_inspect`, and `subagent_consult` |
62
63
  | **Async only** | Four detached lifecycle tools plus `subagent_inspect`; blocking `subagent` and `subagent_consult` are omitted |
63
- | **Blocking only** | `subagent`, `subagent_consult`, and `subagent_inspect` |
64
+ | **Blocking only** | `subagent`, `subagent_auto`, `subagent_consult`, and `subagent_inspect` |
64
65
  | **Disabled** | `subagent_inspect` only; delegation is disabled |
65
66
 
66
67
  The preview compares the selection with the tools registered in the current session, even when a manual settings edit is pending, and remains read-only until confirmation. Escape or **Cancel** leaves settings unchanged. Tool removal requires an extension reload because Pi does not expose extension tool unregistration. To avoid aborting work or removing isolated worktrees during `session_shutdown`, workflow changes are blocked while detached agents are retained; finish or clear them through **Current agents** first. Pi owns reload-error reporting and does not return a success result to extensions, so the save notification also tells users to run `/reload` if the tool surface does not refresh.
@@ -68,6 +69,7 @@ The preview compares the selection with the tools registered in the current sess
68
69
  The available tools are:
69
70
 
70
71
  - `subagent` — delegate blocking single, parallel, fan-in, chained, panel-review, or explicit dependency-workflow tasks. The main agent cannot process queued steering until the call returns.
72
+ - `subagent_auto` — explicitly request one read-only planning turn followed by deterministic compilation and, only when admitted, execution through the existing blocking workflow engine.
71
73
  - `subagent_spawn` and related lifecycle tools — when enabled, start reusable detached work, return immediately, and receive bounded completion messages automatically.
72
74
  - `subagent_inspect` — inspect agent/model/run/runtime metadata without launching work or changing state.
73
75
  - `subagent_consult` — run one ephemeral read-only consultation and wait for its answer.
@@ -96,6 +98,7 @@ Choose the API by lifecycle:
96
98
 
97
99
  | Need | Use |
98
100
  | --- | --- |
101
+ | The caller explicitly wants a high-level objective decomposed under an authority ceiling and aggregate budget | `subagent_auto`, when blocking delegation is enabled |
99
102
  | A delegated result is required before the root's next action under default next-turn delivery | Use one blocking `subagent` call when registered. In **Async only**, complete the critical-path work directly or switch workflows before delegating it |
100
103
  | Broad research/review the current response does not depend on | Prefer one `subagent_spawn` covering related branches, when lifecycle tools are enabled |
101
104
  | Final-answer-dependent broad work with `completionDelivery: "auto-resume"` | Prefer one `subagent_spawn`; completion requests a synthesis turn |
@@ -224,6 +227,70 @@ A blocking fan-out is reserved for output that must be synthesized before the ro
224
227
  }
225
228
  ```
226
229
 
230
+ ## 🧠 Explicit autonomous workflow planning
231
+
232
+ `subagent_auto` is an opt-in surface separate from the large multi-mode `subagent` schema.
233
+ It never intercepts ordinary prompts and does not change existing calls when omitted.
234
+ The caller supplies one versioned objective, non-goals, required inputs, acceptance criteria, required evidence, an authority ceiling, an aggregate budget, and deterministic constraints.
235
+
236
+ ```json
237
+ {
238
+ "request": {
239
+ "version": "pi-subagents:automation-request:v1",
240
+ "objective": "Implement and verify the package change",
241
+ "nonGoals": ["Do not publish or release"],
242
+ "requiredInputs": ["current trusted repository"],
243
+ "acceptanceCriteria": ["Focused and root checks pass"],
244
+ "requiredEvidence": ["test output", "final diff review"],
245
+ "authorityCeiling": {
246
+ "capabilities": ["implementation", "code-review"],
247
+ "tools": ["read", "bash", "edit", "write"],
248
+ "readPaths": ["packages/pi-subagents"],
249
+ "writePaths": ["packages/pi-subagents"],
250
+ "network": "unspecified",
251
+ "secrets": "unspecified",
252
+ "sideEffectPolicy": "mutating"
253
+ },
254
+ "aggregateBudget": {
255
+ "timeoutMs": 180000,
256
+ "maxTurns": 30,
257
+ "maxToolCalls": 60,
258
+ "maxTasks": 4,
259
+ "maxRevisions": 1
260
+ },
261
+ "constraints": {
262
+ "contextPressure": "high",
263
+ "maxMutatingWidth": 2,
264
+ "requireVerification": true,
265
+ "workspaceMode": "shared"
266
+ }
267
+ }
268
+ }
269
+ ```
270
+
271
+ The planner always uses the built-in `planner` with only `read`, `grep`, `find`, and `ls`, disabled extensions and session persistence, trust-aware prompt resources, a maximum 60-second planning deadline, and bounded turn/tool-call counts.
272
+ The planner returns only `pi-subagents:workflow-plan:v1` JSON and cannot choose agents, grant authority, create descendants, or forge executor identities.
273
+ The executor reserves at most one quarter of the aggregate timeout, turns, and tool calls for planning before compiling execution work.
274
+ It rejects before planning when that reservation leaves no positive execution budget, and it narrows the request task ceiling to the configured blocking-task limit before compilation or persistence.
275
+
276
+ The compiler validates strict unknown-field and UTF-8 bounds, relative scopes, cycles, artifacts, ownership, capability routes, aggregate budgets, task generations, integration ownership, and the two-mutating-worker limit before execution.
277
+ Caller-level acceptance criteria and required evidence are merged into the authoritative terminal, integration-owner, and verifier contracts without exceeding contract item limits.
278
+ Path ceilings are compiler and conflict-scheduling constraints, not operating-system filesystem isolation; use a container or sandbox when host-level containment is required.
279
+ Network and secrets guarantees other than `"unspecified"` fail closed because the current executor cannot enforce them.
280
+ It can narrow or reject a proposal and can add one verifier only within the caller's remaining authority and budget.
281
+ Parent-owned, needs-input, planner-failed, and compiler-rejected outcomes launch no execution workers.
282
+ Every admitted mutating workflow has one authoritative integration owner and one distinct `structured-v2` verifier before any mutating worker starts.
283
+ Project-local agents are not selected by this first surface, workflow grandchildren are rejected, and `workspaceMode: "worktree"` fails closed until blocking workflow worktree execution is supported.
284
+
285
+ Pending, needs-input, verification-rework, stale, or invalidated work can be revised through the internal `pi-subagents:workflow-plan-patch:v1` contract.
286
+ Each accepted patch must match the current plan identity and workflow generation, rotates both identity and task generations, preserves accepted history/artifacts/receipts, and stops after the caller's revision limit.
287
+ The initial tool surface does not expose free-form public graph editing.
288
+
289
+ For compatibility or exact task control, use caller-authored `subagent.workflow`.
290
+ Before downgrading, use that explicit workflow fallback and let active automation calls finish.
291
+ Older releases do not register `subagent_auto` and ignore the separate versioned automation records under `~/.pi/agent/pi-subagents-workflows/`; no settings migration is required.
292
+ No benchmark result in this release changes the default delegation policy or makes a production-quality claim.
293
+
227
294
  ## 🔎 Read-only inspection
228
295
 
229
296
  `subagent_inspect` is registered in every workflow, including disabled delegation. It never starts a child, sends or acknowledges mailbox messages, interrupts or closes a run, changes settings, refreshes providers, resolves credentials, or modifies files.
@@ -413,11 +480,58 @@ Run an explicit dependency workflow:
413
480
  }
414
481
  ```
415
482
 
483
+ A verification-gated implementation declares one distinct verifier:
484
+
485
+ ```json
486
+ {
487
+ "workflow": {
488
+ "tasks": [
489
+ {
490
+ "id": "implementation",
491
+ "agent": "worker",
492
+ "task": "Implement the contracted change.",
493
+ "resultFormat": "structured-v2",
494
+ "contract": {
495
+ "version": "pi-subagents:delegation:v2",
496
+ "level": "full",
497
+ "taskId": "implementation",
498
+ "objective": "Implement the contracted change",
499
+ "admission": {
500
+ "contextPressure": "medium",
501
+ "independentWorkItems": 1,
502
+ "coupling": "dense",
503
+ "verificationRequired": true,
504
+ "verificationAvailable": true,
505
+ "budgetAllowsChildren": true,
506
+ "requirementsComplete": true
507
+ }
508
+ }
509
+ },
510
+ {
511
+ "id": "verification",
512
+ "agent": "reviewer",
513
+ "task": "Independently verify the staged result.",
514
+ "dependsOn": ["implementation"],
515
+ "verifierFor": "implementation",
516
+ "resultFormat": "structured-v2"
517
+ }
518
+ ]
519
+ }
520
+ }
521
+ ```
522
+
416
523
  Cycles, missing dependencies, conflicting integration owners, recursive workflow grandchildren, and unsafe retry or hedge policies fail before child launch.
417
524
  Workflow scheduling starts at most two mutating tasks concurrently, while declared read-only work may use the existing four-child ceiling.
418
525
  Set `workflow.honorAdmission: true` only when explicit contract admission metadata should be allowed to decline parent-owned or insufficient-evidence work before launch; admission never silently widens the requested architecture.
419
526
  Workflow result details include the final ledger, scheduling decisions, artifact versions, task generations, attempts, hedge use, accepted plan identity, and bounded capability-grant metadata.
420
- Explicit workflow transitions are also atomically persisted as mode-0600, private-text-redacted snapshots for current-session `list_workflows` and `get_workflow` inspection; in-flight tasks inspect as `interrupted`, and no prior side effect is automatically resumed.
527
+ A task that explicitly requires independent verification must have exactly one direct-dependent `verifierFor` task using a different agent, and both tasks must request `structured-v2`.
528
+ The producer stops in `awaiting-verification`, its own passing verification claims remain untrusted, and ordinary downstream tasks stay blocked until the executor records an accepted verifier receipt.
529
+ The verifier runs alone in a fresh subprocess context against one bounded Git-visible tree identity and must encode `verification-accepted`, `verification-rework`, or `verification-rejected` through the documented `structured-v2` status and reason fields.
530
+ Dirty-tree identity covers at most 1 MiB across separately framed staged and unstaged binary diffs plus bounded non-ignored untracked paths and bytes; submodules, unsupported states, and changing trees fail closed.
531
+ A rework or rejection preserves bounded evidence but does not replay the producer automatically.
532
+ This acceptance gate does not isolate operating-system effects and does not make shared-workspace mutation into manager-controlled patch integration.
533
+ Explicit workflow transitions are also atomically persisted as mode-0600, private-text-redacted snapshots for current-session `list_workflows` and `get_workflow` inspection; running and awaiting-verification tasks inspect as `interrupted`, and no prior side effect is automatically resumed.
534
+ When a v1 ledger is restored, legacy self-reported verification flags and artifact trust are cleared because they have no executor receipt.
421
535
 
422
536
  ## 🔁 Stateful agents
423
537
 
@@ -871,6 +985,12 @@ packages/pi-subagents/
871
985
  ├── src/
872
986
  │ ├── index.ts # Pi package entrypoint
873
987
  │ ├── subagents.ts # Extension registration and blocking tool schema
988
+ │ ├── automation.ts # Explicit autonomous planning tool and lifecycle owner
989
+ │ ├── automation-contract.ts # Strict request, proposal, and graph-patch contracts
990
+ │ ├── automation-planner.ts # Bounded read-only planner prompt and resource policy
991
+ │ ├── workflow-plan-compiler.ts # Deterministic admission, routing, and workflow compilation
992
+ │ ├── workflow-plan-patch.ts # Generation-safe revisions and atomic plan persistence
993
+ │ ├── workflow-planning-benchmark.ts # Frozen matched offline evaluation protocol
874
994
  │ ├── inspect.ts # Side-effect-free metadata inspection tool
875
995
  │ ├── consult.ts # Synchronous read-only consultation tool
876
996
  │ ├── consult-policy.ts # Enforced read-only tool intersection
@@ -890,6 +1010,8 @@ packages/pi-subagents/
890
1010
  │ ├── execution-plan.ts # Executor-owned authority and resource resolution
891
1011
  │ ├── work-item-ledger.ts # Persistent dependency and artifact state machine
892
1012
  │ ├── work-item-persistence.ts # Atomic redacted workflow state and inspection
1013
+ │ ├── workflow-verification.ts # Executor-owned independent-verifier receipts
1014
+ │ ├── workflow-tree-identity.ts # Bounded exact Git-visible tree identities
893
1015
  │ ├── integration-controller.ts # Fail-closed canonical integration admission
894
1016
  │ ├── adaptive-scheduler.ts # Dependency, capacity, budget, and conflict scheduling
895
1017
  │ ├── semantic-snapshot.ts # Privacy-safe continuation compatibility checks
@@ -923,7 +1045,7 @@ packages/pi-subagents/
923
1045
  ```
924
1046
 
925
1047
  `index.ts` is the Pi entrypoint and forwards to `subagents.ts`; the other source modules are internal.
926
- Workflow settings remain backward compatible: older files without `blocking.enabled` receive the seven-tool default, and an absent `blocking.maxParallelTasks` keeps the previous eight-worker limit.
1048
+ Workflow settings remain backward compatible: older files without `blocking.enabled` receive the eight-tool default, and an absent `blocking.maxParallelTasks` keeps the previous eight-worker limit.
927
1049
  Existing `stateful.enabled: false` files expose blocking delegation plus inspection/consultation.
928
1050
  Older package releases ignore and preserve the optional `blocking.maxParallelTasks`, `consult`, and `cwdPolicy` fields.
929
1051
  The package exposes its Pi extension through `package.json`:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-subagents",
3
- "version": "0.51.0",
3
+ "version": "0.53.0",
4
4
  "description": "Pi extension for delegating work to specialized isolated subagents.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -9,7 +9,8 @@ export type SchedulingReason =
9
9
  | "state-not-ready"
10
10
  | "budget-exhausted"
11
11
  | "capacity-exhausted"
12
- | "scope-conflict";
12
+ | "scope-conflict"
13
+ | "verification-barrier";
13
14
 
14
15
  export interface SchedulingDecisionItem {
15
16
  id: string;
@@ -57,6 +58,33 @@ export class AdaptiveScheduler {
57
58
  ),
58
59
  );
59
60
  const effectiveConcurrency = options.remainingBudgetMs > 0 ? availableSlots : 0;
61
+ const readyVerifier = ready.find((item) => item.verifierFor !== undefined);
62
+ if (readyVerifier) {
63
+ const verifierMayStart = effectiveConcurrency > 0 && options.activeCount === 0;
64
+ return {
65
+ policy: ADAPTIVE_SCHEDULER_POLICY,
66
+ workflowId: snapshot.workflowId,
67
+ workflowGeneration: snapshot.generation,
68
+ effectiveConcurrency: verifierMayStart ? 1 : 0,
69
+ selected: verifierMayStart ? [readyVerifier.id] : [],
70
+ decisions: snapshot.items
71
+ .map((item) => ({
72
+ id: item.id,
73
+ reason:
74
+ item.id === readyVerifier.id
75
+ ? verifierMayStart
76
+ ? ("selected" as const)
77
+ : ("capacity-exhausted" as const)
78
+ : item.state === "ready"
79
+ ? ("verification-barrier" as const)
80
+ : item.state === "pending"
81
+ ? ("dependency-not-ready" as const)
82
+ : ("state-not-ready" as const),
83
+ criticalPathDepth: depth.get(item.id) ?? 0,
84
+ }))
85
+ .sort((left, right) => left.id.localeCompare(right.id)),
86
+ };
87
+ }
60
88
  const selected: string[] = [];
61
89
  let mutatingCount = options.activeMutatingCount ?? 0;
62
90
  const maxMutatingConcurrency = options.maxMutatingConcurrency ?? 2;
package/src/agents.ts CHANGED
@@ -190,6 +190,11 @@ const BUILT_IN_AGENTS: AgentConfig[] = [
190
190
  },
191
191
  ];
192
192
 
193
+ export function getBuiltInAgent(name: string): AgentConfig | undefined {
194
+ const agent = BUILT_IN_AGENTS.find((candidate) => candidate.name === name);
195
+ return agent ? structuredClone(agent) : undefined;
196
+ }
197
+
193
198
  function builtInManifest(
194
199
  capabilities: string[],
195
200
  filesystem: "read" | "write",