@tt-a1i/openpi 0.4.0 → 0.5.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.
Files changed (109) hide show
  1. package/README.md +102 -40
  2. package/SETUP.md +22 -6
  3. package/assets/openpi-launch-card-v1.webp +0 -0
  4. package/bin/openpi.js +145 -0
  5. package/extensions/background-terminals/index.ts +30 -2
  6. package/extensions/background-terminals/src/domain.ts +2 -0
  7. package/extensions/background-terminals/src/manager.ts +486 -106
  8. package/extensions/background-terminals/src/output.ts +33 -0
  9. package/extensions/background-terminals/src/prompt.ts +13 -5
  10. package/extensions/background-terminals/src/result-delivery.ts +4 -1
  11. package/extensions/clear-context/index.ts +83 -0
  12. package/extensions/context-pivot/index.ts +16 -6
  13. package/extensions/cron/schedule.ts +7 -1
  14. package/extensions/file-mutation-display/render.ts +17 -257
  15. package/extensions/file-search/src/binaries.ts +57 -41
  16. package/extensions/git-read/index.ts +1 -3
  17. package/extensions/model-info/index.ts +21 -33
  18. package/extensions/model-info/session-metrics.ts +96 -0
  19. package/extensions/plan-mode/bash-policy.ts +54 -9
  20. package/extensions/plan-mode/index.ts +7 -2
  21. package/extensions/post-edit/index.ts +16 -6
  22. package/extensions/sessions/git-stats.ts +258 -72
  23. package/extensions/sessions/index.ts +153 -86
  24. package/extensions/sessions/preview-cache.ts +104 -0
  25. package/extensions/sessions/preview-loader.ts +856 -0
  26. package/extensions/sessions/sessions.ts +43 -4
  27. package/extensions/setup/index.ts +123 -127
  28. package/extensions/shared/activity-status.ts +30 -0
  29. package/extensions/shared/agent-session-page.ts +319 -0
  30. package/extensions/shared/agent-tool-renderer.ts +218 -0
  31. package/extensions/shared/agent-transcript.ts +524 -0
  32. package/extensions/shared/capability-intent.ts +1 -1
  33. package/extensions/shared/child-session.ts +437 -21
  34. package/extensions/shared/result-delivery.ts +34 -0
  35. package/extensions/shared/setup-config.ts +73 -33
  36. package/extensions/shared/setup-episode-state.ts +1 -1
  37. package/extensions/shared/terminal-text.ts +110 -23
  38. package/extensions/shared/text-projection.ts +72 -15
  39. package/extensions/shared/tool-activity.ts +382 -0
  40. package/extensions/shared/tool-surface.ts +29 -2
  41. package/extensions/shared/transcript-viewport.ts +46 -0
  42. package/extensions/shared/web-observer-registry.ts +390 -0
  43. package/extensions/shared/worktree.ts +11 -0
  44. package/extensions/subagents/index.ts +270 -59
  45. package/extensions/subagents/navigation.ts +34 -5
  46. package/extensions/subagents/src/backend.ts +12 -1
  47. package/extensions/subagents/src/backends/pi.ts +375 -66
  48. package/extensions/subagents/src/domain.ts +5 -0
  49. package/extensions/subagents/src/manager.ts +34 -2
  50. package/extensions/subagents/src/prompt.ts +32 -4
  51. package/extensions/subagents/src/result-artifact.ts +4 -0
  52. package/extensions/subagents/src/result-delivery.ts +7 -1
  53. package/extensions/subagents/src/runtime.ts +15 -1
  54. package/extensions/subagents/src/ui/takeover.ts +73 -257
  55. package/extensions/subagents/src/ui/transcript.ts +38 -535
  56. package/extensions/subagents/src/ui/wait-result.ts +103 -15
  57. package/extensions/suggestions/src/ui.ts +10 -4
  58. package/extensions/tasks/index.ts +0 -3
  59. package/extensions/ui-customization/footer.ts +0 -40
  60. package/extensions/ui-customization/index.ts +0 -4
  61. package/extensions/user-input-fold/index.ts +1 -1
  62. package/extensions/web/index.ts +234 -0
  63. package/extensions/workflows/artifacts.ts +137 -47
  64. package/extensions/workflows/completion-projection.ts +457 -0
  65. package/extensions/workflows/coordinator.ts +8 -10
  66. package/extensions/workflows/dashboard.ts +167 -228
  67. package/extensions/workflows/handoff.ts +70 -16
  68. package/extensions/workflows/index.ts +488 -198
  69. package/extensions/workflows/journal.ts +148 -13
  70. package/extensions/workflows/model.ts +74 -4
  71. package/extensions/workflows/navigation.ts +32 -8
  72. package/extensions/workflows/progress-projection.ts +306 -0
  73. package/extensions/workflows/prompt.ts +66 -6
  74. package/extensions/workflows/replay-safety.ts +42 -21
  75. package/extensions/workflows/result-delivery.ts +128 -64
  76. package/extensions/workflows/retention.ts +593 -0
  77. package/extensions/workflows/runner.ts +388 -279
  78. package/extensions/workflows/sandbox-child.cjs +25 -3
  79. package/extensions/workflows/sandbox.ts +62 -8
  80. package/extensions/workflows/serialization.ts +325 -17
  81. package/extensions/workflows/tool-renderer.ts +22 -0
  82. package/extensions/workflows/transcript.ts +149 -0
  83. package/extensions/workspace-cleanup-guard/index.ts +54 -0
  84. package/extensions/workspace-cleanup-guard/workspace-provenance.ts +563 -0
  85. package/package.json +28 -8
  86. package/skills/subagents/REFERENCE.md +189 -0
  87. package/skills/subagents/SKILL.md +1 -1
  88. package/skills/workflows/REFERENCE.md +4 -2
  89. package/web/adapter/pi-adapter.ts +661 -0
  90. package/web/host/browser-launcher.ts +20 -0
  91. package/web/host/static-assets.ts +4 -0
  92. package/web/host/terminal-status.ts +38 -0
  93. package/web/host/web-host.ts +789 -0
  94. package/web/http-dispatcher.ts +125 -0
  95. package/web/protocol/types.ts +462 -0
  96. package/web/runtime/pi-runtime.ts +991 -0
  97. package/web/runtime/types.ts +71 -0
  98. package/web/runtime/web-host-lease.ts +497 -0
  99. package/web/trace.ts +18 -0
  100. package/web/ui/app.js +1398 -0
  101. package/web/ui/index.html +139 -0
  102. package/web/ui/styles.css +598 -0
  103. package/web/vite.config.mjs +34 -0
  104. package/extensions/execution-convergence/active-evidence.ts +0 -129
  105. package/extensions/execution-convergence/index.ts +0 -442
  106. package/extensions/execution-convergence/workspace-provenance.ts +0 -338
  107. package/extensions/setup/intercom-fs-helper.cjs +0 -130
  108. package/extensions/setup/intercom.ts +0 -603
  109. package/extensions/subagents/src/backends/stub.ts +0 -303
@@ -0,0 +1,189 @@
1
+ # Agent types reference
2
+
3
+ An agent type is a reusable child-agent definition shared by
4
+ `subagent_spawn` and Workflow `agent()`: a named preset that can set a child's
5
+ system prompt, model, and thinking level, and — the point of the feature —
6
+ **which tools it may use at all**. Four provider-free built-in roles are always
7
+ available: `explorer`, `implementer`, `reviewer`, and `advisor`.
8
+
9
+ Without one, every subagent is the same thing: it inherits the parent model and
10
+ the full child tool set, so a "read-only research" subagent still holds `write`,
11
+ `edit`, and `bash`, restrained only by how the prompt was worded. A type turns
12
+ that into an enforced boundary.
13
+
14
+ ## File format
15
+
16
+ Types are markdown files with YAML frontmatter, one per file:
17
+
18
+ ```markdown
19
+ ---
20
+ name: explore
21
+ description: Read-only codebase exploration. Returns file:line references.
22
+ tools: [read, grep, find, ls, fd, rg]
23
+ model: anthropic/claude-sonnet-5 # optional
24
+ reasoning_effort: medium # optional
25
+ ---
26
+
27
+ You are a read-only exploration agent. Locate code and report concrete
28
+ file:line references. You cannot modify files — do not attempt to.
29
+ ```
30
+
31
+ | Field | Required | Meaning |
32
+ | ------------------ | -------- | ------------------------------------------------------------------------------------ |
33
+ | `name` | yes | `[a-z0-9-]`, ≤64 chars, and must equal the filename stem. |
34
+ | `description` | yes | Shown to the parent model when it picks a type. ≤1024 chars. |
35
+ | `tools` | no | Tool allowlist. **Omit to inherit the normal tool set.** |
36
+ | `model` | no | `provider/model-id`, or a bare id resolved against the current provider; ≤256 chars. |
37
+ | `reasoning_effort` | no | `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max`. |
38
+ | body | no | Appended to the child's system prompt. ≤16384 chars. |
39
+
40
+ Each file is capped at 64 KiB and each tool name at 128 characters before it can
41
+ enter a prompt or startup diagnostic. `name` must match the filename so a renamed
42
+ file cannot keep answering to its old name. An explicit `model` or `reasoning_effort` argument on `subagent_spawn`,
43
+ or `model`/`provider` or `effort` on Workflow `agent()`, overrides the type's own.
44
+
45
+ ## Built-in roles
46
+
47
+ All built-ins omit a model, so they inherit the parent model unless configured
48
+ through `/openpi-setup`. Their complete definitions can be replaced by a custom
49
+ file with the same name.
50
+
51
+ | Role | Tools | Relative effort guidance | Purpose |
52
+ | ------------- | ------------------------------------------------------------------- | ------------------------ | ------------------------------------------------------ |
53
+ | `explorer` | `read grep find ls fd rg git_show git_diff git_log` | Moderate | Read-only codebase tracing; increase for harder tasks. |
54
+ | `implementer` | `read bash edit write grep find ls fd rg git_show git_diff git_log` | Medium-high | Focused implementation; adjust for scope and risk. |
55
+ | `reviewer` | `read grep find ls fd rg git_show git_diff git_log` | High | Read-only correctness, safety, and regression review. |
56
+ | `advisor` | `read grep find ls fd rg git_show git_diff git_log` | High | Deep read-only analysis and technical advice. |
57
+
58
+ These are relative selection hints, not fixed Pi thinking levels. Built-ins set
59
+ no model or reasoning-effort default. An explicit user requirement takes
60
+ priority; otherwise the parent model chooses from levels supported by the
61
+ resolved child model according to the role and task difficulty. Their tool
62
+ allowlists still intersect with plan mode and the child denylist.
63
+
64
+ ## Discovery
65
+
66
+ Definitions are layered at each `session_start`:
67
+
68
+ | Priority | Source | Loaded |
69
+ | -------- | ------------------------- | ------------------------------ |
70
+ | lowest | package built-ins | Always. |
71
+ | middle | `~/.pi/agent/agents/*.md` | Always. |
72
+ | highest | `<cwd>/.pi/agents/*.md` | **Only in a trusted project.** |
73
+
74
+ A project file supplies an attacker-controllable system prompt and tool list, so
75
+ an untrusted repository contributes none. Each higher layer replaces the
76
+ **complete** same-name definition from the layer below, and every override is
77
+ reported as a diagnostic rather than applied silently.
78
+
79
+ The Subagent extension initially registers only built-in and global types, then
80
+ re-registers `subagent_spawn` at `session_start` from `ctx.cwd` and
81
+ `ctx.isProjectTrusted()`. The Workflow extension resolves the same layers at
82
+ `session_start` and snapshots that roster for each run. This honors temporary
83
+ session-only trust decisions and cross-cwd session replacements without ever
84
+ loading an untrusted project's prompt before trust resolves. Edits take effect
85
+ on `/reload` or a new session — the same as skills.
86
+
87
+ A malformed file is reported at session start and never prevents unrelated types
88
+ from loading. Its own filename is blocked at that precedence layer: a broken
89
+ project `implementer.md` cannot silently fall back to the broader global or
90
+ built-in `implementer`. Unknown frontmatter keys make that file malformed rather
91
+ than being ignored, so a misspelled `tools` or restriction field cannot expose
92
+ the inherited full tool set. If an entire configured layer exists but cannot be
93
+ read, all lower-precedence definitions are blocked because its intended overrides
94
+ cannot be determined safely; a genuinely missing directory remains the normal
95
+ no-override case.
96
+
97
+ ## Model and effort precedence
98
+
99
+ For an `agent_type` child, model selection is: explicit call model → selected
100
+ type file `model` → `/openpi-setup` assignment for that built-in role name →
101
+ inherited parent model. Effort is: explicit call effort → selected type default
102
+ (including a built-in) → parent effort. The generated `subagent_spawn.agent_type`
103
+ roster shows each type's default effort or explicit parent inheritance; Workflow
104
+ uses the same names and definitions. A custom `explorer.md` therefore replaces
105
+ the built-in definition, while an explicit call argument still wins.
106
+
107
+ `/openpi-setup` can assign any model currently present in Pi's registry to one or
108
+ more built-in roles. Assignments are partial; omitted roles stay unchanged, and
109
+ setting a role to `null` clears it back to parent-model inheritance. The
110
+ assignment is read when each child is created, so it applies to the next spawn
111
+ or Workflow `agent()` call without `/reload`.
112
+
113
+ ## Usage
114
+
115
+ ```
116
+ subagent_spawn({ prompt: "...", name: "auth audit", agent_type: "explorer" })
117
+ ```
118
+
119
+ Workflow scripts use the same role without hardcoding its configured model:
120
+
121
+ ```js
122
+ await agent("Map the auth flow", { agent_type: "explorer" });
123
+ ```
124
+
125
+ The `agent_type` parameter is always available because the built-in roles are
126
+ always present. Agent Type file changes take effect on `/reload` or a new
127
+ session for both direct Subagents and Workflows; each Workflow snapshots that
128
+ session roster when its run starts.
129
+
130
+ ## What `tools:` actually guarantees
131
+
132
+ The list is passed to pi as a session-level allowlist, which it composes with
133
+ this package's existing child denylist:
134
+
135
+ ```js
136
+ // pi: dist/core/agent-session.js
137
+ const isAllowedTool = (name) =>
138
+ (!allowedToolNames || allowedToolNames.has(name)) &&
139
+ !excludedToolNames?.has(name);
140
+ ```
141
+
142
+ Two consequences worth being precise about:
143
+
144
+ - **It can only narrow.** Listing a denied tool (`subagent_spawn`, `bg_start`,
145
+ `ask_user`, …) does not grant it. The child boundary in
146
+ `extensions/shared/child-session.ts` stays authoritative, and the drift guard
147
+ that protects it is unaffected.
148
+ - **It also unlocks.** Pi's default active set is only
149
+ `read, bash, edit, write`, so `grep`, `find`, and `ls` are otherwise
150
+ unreachable in a child. Naming them in `tools:` activates them.
151
+
152
+ So `tools: [read, grep, find, ls]` yields a child that genuinely has no
153
+ `write`, `edit`, or `bash` tool to call — not one that has been asked not to.
154
+ Parent-only names are removed before the generated roster and spawn result are
155
+ shown, so a type that lists `subagent_spawn` never advertises it as usable.
156
+ A structured Workflow child additionally receives only its terminating
157
+ `structured_output` tool; this does not restore any denied repository tool.
158
+
159
+ While `/plan` is armed, `isolation: "worktree"` is rejected before Git is
160
+ changed. A selected type whose declared tools plan mode would narrow (such as
161
+ `implementer`) is also rejected rather than spawning it with a contradictory
162
+ implementation prompt; use `explorer`, `reviewer`, `advisor`, or omit the type
163
+ for read-only investigation.
164
+
165
+ Unrecognized tool names are kept at parse time because a third-party extension
166
+ may register them. After child extensions initialize, every explicitly listed
167
+ child-safe tool is checked against the final active child registry before the
168
+ first model prompt. An extension-registered tool therefore works normally; a
169
+ typo or unavailable tool fails that direct Subagent or Workflow agent launch
170
+ with a bounded error and sends no model tokens. Parent-only names remain denied
171
+ and are not treated as missing, so the child denylist stays authoritative.
172
+
173
+ ## Implementation
174
+
175
+ - `extensions/subagents/src/agent-types.ts` — built-ins, parsing, discovery, diagnostics, and model
176
+ precedence helpers.
177
+ - `extensions/shared/subagent-roles.ts` — one typed source for built-in role names.
178
+ - `extensions/subagents/index.ts` — safe initial discovery, session-scoped roster refresh and
179
+ re-registration, the `agent_type` parameter, and merging a type/config
180
+ assignment into the spawn task.
181
+ - `extensions/subagents/src/backends/pi.ts` — applies `appendSystemPrompt` and the tool allowlist to
182
+ a direct subagent session.
183
+ - `extensions/workflows/index.ts` and `extensions/workflows/runner.ts` — resolve the same
184
+ type for each Workflow call and enforce its prompt, model, effort, and tools.
185
+ - `extensions/shared/child-session.ts` — `childToolPolicy(tools?)`, where the allowlist
186
+ and denylist compose.
187
+
188
+ Covered by `tests/extensions/subagents/agent-types.test.ts`, including the trust gate and the
189
+ narrowing-only property.
@@ -10,7 +10,7 @@ The tool definitions are canonical for parameters, limits, model syntax, isolati
10
10
  - Delegate substantial independent work, not a lookup or edit the parent can do directly.
11
11
  - Give the child a standalone prompt with paths, constraints, relevant context, and the expected report; it cannot see the parent conversation or ask the user.
12
12
  - Inherit the parent model by default. When choosing the child's reasoning effort, honor an explicit user requirement first; otherwise use the selected role's relative guidance and the task's difficulty, choosing from levels supported by the resolved child model.
13
- - Prefer a matching agent type when one exists; its tool restriction is enforced. Model precedence is explicit spawn override, selected type-file model, configured built-in role model, then parent model. Reasoning precedence is explicit spawn override, selected type default, then parent effort. Types live in `~/.pi/agent/agents/*.md` and, for trusted projects, `.pi/agents/*.md`; see `extensions/subagents/docs/agent-types.md`.
13
+ - Prefer a matching agent type when one exists; its tool restriction is enforced. Model precedence is explicit spawn override, selected type-file model, configured built-in role model, then parent model. Reasoning precedence is explicit spawn override, selected type default, then parent effort. Types live in `~/.pi/agent/agents/*.md` and, for trusted projects, `.pi/agents/*.md`; see [Agent types](REFERENCE.md).
14
14
  - Isolate concurrent writers in worktrees according to the `subagent_spawn` schema so they cannot overwrite one checkout or git index. While Plan Mode is active, use only read-only exploration types (or no type); worktree isolation and types narrowed by Plan Mode are rejected.
15
15
  - After spawning, continue useful parent work. In an interactive session, if none remains, tell the user the child is still running and end the turn; automatic result delivery will re-invoke the parent when it settles. Do not block merely because the next step depends on the result or because there is nothing else to do. Use `subagent_wait` only when the user explicitly asks to keep the current response open for the result, or when non-interactive automation must return it in the same invocation.
16
16
 
@@ -18,7 +18,7 @@ Useful options include `agent_type`, `label`, `phase`, `schema`, `acceptance`, `
18
18
 
19
19
  - Prefer a matching `agent_type`. Model precedence is explicit model/provider, type file, configured built-in role, then parent. Effort precedence is explicit effort, type default, then parent.
20
20
  - `schema` validates structured output. Use it whenever later workflow logic branches on fields.
21
- - `acceptance: { criteria: [{ id, description, requiredEvidence? }] }` requires the same child to return an evidence ledger. Missing, malformed, or rejected criteria make `ok:false` while preserving output and evidence.
21
+ - `acceptance: { criteria: [{ id, description, requiredEvidence?: string[] }] }` requires the same child to return an evidence ledger. An invocation accepts 1–32 criteria; each criterion has a 1–500 character human-readable `description` and an optional `requiredEvidence` array of at most 16 concise string labels (up to 120 characters each). The child must return exact matching labels in `acceptance.criteria[].evidence`. A criterion without `requiredEvidence` is an attestation of its description, not an evidence-backed gate; criteria that need evidence-backed acceptance must declare the required labels. Missing, malformed, or rejected criteria make `ok:false` while preserving output and evidence.
22
22
  - `operator: "name"` reuses one in-memory child Session for serialized follow-ups inside the same run. Its model, role/tools, effort, structured mode, and cwd are frozen by the first activation. Operators cannot use per-call worktrees or replay, and do not survive restarts.
23
23
  - `inputs: [ref, ...]` accepts successful opaque refs from the same workflow run only. Each conclusion is bounded to 16 KiB and total injected input to 48 KiB. The total budget is fairly distributed, so a large fan-out cannot starve later results merely because of order; partial projections are labeled. Full successful child results remain in the run's `agent-results/` artifacts. Inputs are marked as untrusted data; the resulting graph is observability, not scheduling authority.
24
24
  - Fair projection preserves the head and tail of every partial result and names its run-relative `agent-results/agent-N.json` audit artifact. That path is provenance for the parent/operator, not a child-readable handle. Fair presence is not proof of full evidence coverage: for large fan-out, group source refs into local Report agents, then pass only their refs to a global Report. The workflow script—not Runtime—must state planned, selected, covered, failed, and deferred counts.
@@ -40,7 +40,9 @@ Each call persists intent, admission, and execution state. Interrupted nontermin
40
40
 
41
41
  ## Lifecycle and replay
42
42
 
43
- Interactive TUI runs return an accepted run id immediately by default, release the parent turn, and later deliver a terminal completion with a stable delivery id. Delivery is at least once: normal retries do not duplicate a run, but a process loss after Pi accepts the message and before the receipt is persisted can replay the same id. `wait: true` explicitly waits inline; interrupting that wait releases only the waiter and the run continues. Print/automation defaults to waiting because it has no later delivery channel. The deprecated `background` parameter remains an inverse compatibility alias and cannot be combined with `wait`.
43
+ Interactive TUI runs return an accepted run id immediately by default, release the parent turn, and later deliver a terminal completion with a stable delivery id. Delivery is at least once: normal retries do not duplicate a run, but a process loss after Pi accepts the message and before the receipt is persisted can replay the same id. `wait: true` explicitly waits inline; interrupting that wait releases only the waiter and the run continues. Print/automation defaults to waiting because it has no later delivery channel.
44
+
45
+ New calls must use `wait`. For compatibility with released OpenPI versions, the deprecated `background` alias remains accepted during the current migration window: replace `background: true` with `wait: false`, or `background: false` with `wait: true`, and do not provide both fields. The alias will be removed only in an announced breaking release. Persisted artifact/details fields named `background` remain actual detached-state facts and are not part of that removal.
44
46
 
45
47
  Loading the Workflow capability exposes `workflow`, `workflow_status`, and `workflow_stop` as one stable group; starting or settling a run does not mutate the model tool Schema. `workflow_status` returns a bounded state/coverage summary and artifact path without consuming or repeating the full completion. `workflow_stop` is idempotent and preserves partial artifacts. A failed completion send remains pending with the same per-run delivery identity and is retried when the parent settles or the Session is restored.
46
48