@llblab/pi-actors 0.35.0 → 0.36.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.
@@ -143,15 +143,23 @@ export function compactRecipeDoctor(summary) {
143
143
  const recommendations = Array.isArray(summary.recommendations)
144
144
  ? summary.recommendations
145
145
  : [];
146
+ const riskSummary = Array.isArray(summary.risk_summary)
147
+ ? summary.risk_summary
148
+ : [];
146
149
  const counts = { error: 0, info: 0, warning: 0 };
147
150
  for (const detail of details) {
148
151
  const severity = String(detail.severity ?? "info");
149
152
  if (severity === "error" || severity === "warning" || severity === "info")
150
153
  counts[severity] += 1;
151
154
  }
155
+ const riskCount = riskSummary.reduce((total, item) => total + Number(item.count ?? 0), 0);
156
+ const topRisks = riskSummary
157
+ .slice(0, 4)
158
+ .map((item) => `${String(item.label)}:${String(item.count ?? 0)}`)
159
+ .join(",");
152
160
  const topAction = asRecord(summary.top_action);
153
161
  const lines = [
154
- `recipes doctor errors=${counts.error} warnings=${counts.warning} info=${counts.info} actions=${remediations.length} recommendations=${recommendations.length}`,
162
+ `recipes doctor errors=${counts.error} warnings=${counts.warning} info=${counts.info} actions=${remediations.length} recommendations=${recommendations.length} risks=${riskCount}${topRisks ? ` top_risks=${topRisks}` : ""}`,
155
163
  ];
156
164
  if (Object.keys(topAction).length > 0) {
157
165
  const action = compactPreview(topAction.action, Limits.DOCTOR_ACTION_PREVIEW_CHARS);
@@ -162,7 +170,10 @@ export function compactRecipeDoctor(summary) {
162
170
  const blocked = item.blocked_fallback
163
171
  ? ` blocked=${compactPreview(item.blocked_fallback, Limits.DOCTOR_ACTION_PREVIEW_CHARS)}`
164
172
  : "";
165
- lines.push(`${String(item.severity ?? "info")} kind=${String(item.kind ?? "inspect")} id=${String(item.id ?? "root")}${blocked} action=${action ?? "inspect"}`);
173
+ const labels = Array.isArray(item.risk_labels)
174
+ ? ` labels=${item.risk_labels.map(String).slice(0, 4).join(",")}`
175
+ : "";
176
+ lines.push(`${String(item.severity ?? "info")} kind=${String(item.kind ?? "inspect")} id=${String(item.id ?? "root")}${blocked}${labels} action=${action ?? "inspect"}`);
166
177
  }
167
178
  const nextActions = Array.isArray(summary.next_actions)
168
179
  ? summary.next_actions
@@ -27,9 +27,9 @@ const { readResolvedRecipeConfig } = await importRuntimeModule("recipes-referenc
27
27
 
28
28
  export function validateRecipeUsage() {
29
29
  return `Usage:
30
- validate-recipe.mjs <recipe-file-or-dir> [--all]
30
+ validate-recipe.mjs <recipe-file-or-dir> [--all] [--qa] [--summary]
31
31
 
32
- Validates one template recipe file, or all *.json/*.md files in a directory when --all is set.`;
32
+ Validates one template recipe file, or all *.json/*.md files in a directory when --all is set. Add --qa for packaged-recipe quality checks. Add --summary for compact CLI output.`;
33
33
  }
34
34
 
35
35
  function expandPath(value) {
@@ -63,14 +63,133 @@ function recipeFiles(target, all) {
63
63
  .map((file) => resolve(target, file));
64
64
  }
65
65
 
66
- function validateFile(file) {
66
+ function mailboxType(value) {
67
+ if (typeof value === "string") return value;
68
+ if (value && typeof value === "object" && typeof value.type === "string")
69
+ return value.type;
70
+ return undefined;
71
+ }
72
+
73
+ function collectTemplateStrings(value, out = []) {
74
+ if (typeof value === "string") out.push(value);
75
+ else if (Array.isArray(value)) value.forEach((item) => collectTemplateStrings(item, out));
76
+ else if (value && typeof value === "object") {
77
+ collectTemplateStrings(value.template, out);
78
+ collectTemplateStrings(value.recover, out);
79
+ }
80
+ return out;
81
+ }
82
+
83
+ function hasPlatformNote(config) {
84
+ const text = [
85
+ config.description,
86
+ config.platforms,
87
+ config.platform_notes,
88
+ config.requirements,
89
+ ]
90
+ .filter(Boolean)
91
+ .join(" ");
92
+ return /linux|macos|darwin|windows|win32|unix|wsl|cross-platform|portable/i.test(text);
93
+ }
94
+
95
+ function validateArtifactDeclarations(config) {
96
+ const diagnostics = [];
97
+ const artifacts = config.artifacts;
98
+ if (artifacts === undefined) return diagnostics;
99
+ if (!artifacts || typeof artifacts !== "object" || Array.isArray(artifacts)) {
100
+ diagnostics.push("artifacts: must be an object of named artifact paths");
101
+ return diagnostics;
102
+ }
103
+ for (const [name, value] of Object.entries(artifacts)) {
104
+ const path = typeof value === "string" ? value : value?.path;
105
+ if (typeof path !== "string" || !path.trim())
106
+ diagnostics.push(`artifacts.${name}: must declare a non-empty path`);
107
+ if (typeof path === "string" && /^\/home\//.test(path))
108
+ diagnostics.push(`artifacts.${name}: must not use a machine-local absolute path`);
109
+ }
110
+ return diagnostics;
111
+ }
112
+
113
+ function validateHelperPaths(file, config) {
114
+ const diagnostics = [];
115
+ for (const template of collectTemplateStrings(config.template)) {
116
+ if (/(^|\s)(?:node\s+)?scripts\/[\w.-]+\.mjs/.test(template))
117
+ diagnostics.push("template: helper scripts must be referenced through {repo}/scripts for installed packages");
118
+ for (const match of template.matchAll(/\{repo\}\/scripts\/([^\s"']+\.mjs)/g)) {
119
+ const scriptPath = join(packageRoot(), "scripts", match[1]);
120
+ if (!existsSync(scriptPath))
121
+ diagnostics.push(`template: referenced helper script not found: scripts/${match[1]}`);
122
+ }
123
+ }
124
+ return diagnostics;
125
+ }
126
+
127
+ function validateMailboxContract(file, config) {
128
+ const diagnostics = [];
129
+ const mailbox = config.mailbox;
130
+ const accepts = Array.isArray(mailbox?.accepts) ? mailbox.accepts : [];
131
+ const emits = Array.isArray(mailbox?.emits) ? mailbox.emits : [];
132
+ if (config.async === true && !mailbox)
133
+ diagnostics.push("mailbox: async recipes must declare mailbox metadata");
134
+ if (config.async === true && !accepts.map(mailboxType).includes("control.kill"))
135
+ diagnostics.push("mailbox.accepts: async recipes must include control.kill");
136
+ const allowedLegacyTypes = new Set(["awaiting_assignment"]);
137
+ for (const [key, entries] of Object.entries({ accepts, emits })) {
138
+ entries.forEach((entry, index) => {
139
+ const type = mailboxType(entry);
140
+ if (!type) diagnostics.push(`mailbox.${key}[${index}]: must be a string or object with type`);
141
+ else if (
142
+ !allowedLegacyTypes.has(type) &&
143
+ !/^[a-z][a-z0-9_-]*\.(?:[a-z][a-z0-9_-]*|\*)$/.test(type)
144
+ )
145
+ diagnostics.push(`mailbox.${key}[${index}]: message type must use channel.action form`);
146
+ });
147
+ }
148
+ const allowedDomainTermination = new Set([
149
+ "coordinator-locker.json",
150
+ "locker.json",
151
+ "music-player.json",
152
+ ]);
153
+ const hasDomainTermination = accepts
154
+ .map(mailboxType)
155
+ .some((type) => type === "control.stop" || type === "control.cancel");
156
+ if (hasDomainTermination && !allowedDomainTermination.has(file.split(/[\\/]/).pop()))
157
+ diagnostics.push("mailbox.accepts: control.stop/control.cancel are reserved for actor-domain handlers");
158
+ return diagnostics;
159
+ }
160
+
161
+ function qaDiagnostics(file, config) {
162
+ const diagnostics = [];
163
+ const warnings = [];
164
+ if (typeof config.description !== "string" || !config.description.trim())
165
+ warnings.push("description: missing or empty");
166
+ diagnostics.push(...validateMailboxContract(file, config));
167
+ diagnostics.push(...validateArtifactDeclarations(config));
168
+ diagnostics.push(...validateHelperPaths(file, config));
169
+ const platformSpecificTemplate = collectTemplateStrings(config.template).some(
170
+ (template) =>
171
+ /(^|\s)(?:systemctl|launchctl|osascript|powershell|pwsh|cmd\.exe|apt|apt-get|dnf|yum|brew|pacman|apk)(\s|$)/i.test(
172
+ template,
173
+ ),
174
+ );
175
+ if (platformSpecificTemplate && !hasPlatformNote(config))
176
+ diagnostics.push("platform: platform-specific templates must document platform scope");
177
+ return { diagnostics, warnings };
178
+ }
179
+
180
+ function qaOk(qaReport) {
181
+ return qaReport.diagnostics.length === 0;
182
+ }
183
+
184
+ function validateFile(file, qa = false) {
67
185
  try {
68
186
  const config = readResolvedRecipeConfig(file);
69
187
  if (!config?.template)
70
188
  throw new Error("Recipe must define a non-empty template.");
189
+ const qaReport = qa ? qaDiagnostics(file, config) : { diagnostics: [], warnings: [] };
71
190
  return {
72
191
  file,
73
- ok: true,
192
+ ok: qaOk(qaReport),
74
193
  name: config.name ?? "",
75
194
  async: Boolean(config.async),
76
195
  args: Array.isArray(config.args) ? config.args : [],
@@ -93,6 +212,15 @@ function validateFile(file) {
93
212
  : [],
94
213
  }
95
214
  : undefined,
215
+ ...(qa
216
+ ? {
217
+ qa: {
218
+ ok: qaOk(qaReport),
219
+ diagnostics: qaReport.diagnostics,
220
+ warnings: qaReport.warnings,
221
+ },
222
+ }
223
+ : {}),
96
224
  template: templateKind(config.template),
97
225
  };
98
226
  } catch (error) {
@@ -107,12 +235,13 @@ function validateFile(file) {
107
235
  export function validateRecipes(argv) {
108
236
  const targetArg = argv.find((arg) => !arg.startsWith("-"));
109
237
  const all = argv.includes("--all");
238
+ const qa = argv.includes("--qa");
110
239
  if (!targetArg || argv.includes("--help") || argv.includes("-h")) {
111
240
  return { help: true, ok: Boolean(targetArg), usage: validateRecipeUsage() };
112
241
  }
113
242
 
114
243
  const files = recipeFiles(expandPath(targetArg), all);
115
- const results = files.map(validateFile);
244
+ const results = files.map((file) => validateFile(file, qa));
116
245
  const failed = results.filter((result) => !result.ok).length;
117
246
  return {
118
247
  ok: failed === 0,
@@ -123,10 +252,38 @@ export function validateRecipes(argv) {
123
252
  };
124
253
  }
125
254
 
255
+ function summarizeReport(report) {
256
+ const results = Array.isArray(report.results) ? report.results : [];
257
+ return {
258
+ ok: report.ok,
259
+ total: report.total,
260
+ passed: report.passed,
261
+ failed: report.failed,
262
+ diagnostics: results.reduce(
263
+ (total, result) => total + (result.qa?.diagnostics?.length ?? 0),
264
+ 0,
265
+ ),
266
+ warnings: results.reduce(
267
+ (total, result) => total + (result.qa?.warnings?.length ?? 0),
268
+ 0,
269
+ ),
270
+ failed_files: results
271
+ .filter((result) => !result.ok)
272
+ .map((result) => ({
273
+ file: result.file,
274
+ ...(result.error ? { error: result.error } : {}),
275
+ ...(result.qa?.diagnostics?.length
276
+ ? { diagnostics: result.qa.diagnostics }
277
+ : {}),
278
+ })),
279
+ };
280
+ }
281
+
126
282
  try {
127
- const report = validateRecipes(process.argv.slice(2));
283
+ const argv = process.argv.slice(2);
284
+ const report = validateRecipes(argv);
128
285
  if (report.help) console.error(report.usage);
129
- else console.log(JSON.stringify(report, null, 2));
286
+ else console.log(JSON.stringify(argv.includes("--summary") ? summarizeReport(report) : report, null, 2));
130
287
  process.exit(report.ok ? 0 : 1);
131
288
  } catch (error) {
132
289
  console.error(error instanceof Error ? error.message : String(error));
@@ -2,7 +2,7 @@
2
2
  name: actors
3
3
  description: Required practical guide for non-trivial pi-actors use. Read before using or changing spawn, message, inspect, actor runs, tools, recipes, command templates, async lifecycle, mailboxes, artifacts, and local orchestration mechanics.
4
4
  metadata:
5
- version: 0.35.0
5
+ version: 0.36.0
6
6
  ---
7
7
 
8
8
  # Actors (pi-actors)
@@ -194,12 +194,13 @@ Rules:
194
194
  2. `async: true` makes spawned work a detached actor run.
195
195
  3. Public knobs belong in `args`/`defaults`; hidden launch mechanics stay inside `template`.
196
196
  4. Use `imports` to compose recipes; imported recipes are definitions, not nested async runs.
197
- 5. Declare `mailbox` for actors that accept or emit meaningful messages.
198
- 6. Declare `artifacts` for durable outputs the coordinator should inspect.
199
- 7. File-backed recipe identity comes from the filename basename; legacy top-level `name` fields are ignored by loaders.
200
- 8. File-backed async recipes pass child `pi -p` actors a bounded JSONL recipe context bundle by default: raw entry/import recipe records, derived `name`, import path/alias, and `"you_are_here": true` on the launching recipe node. Set `"actor_context": false` or `"off"` to suppress it for minimal prompts.
201
- 9. Keep packaged recipes generic: no machine-local paths, no private companion identities, no project-specific defaults unless the recipe is explicitly project-specific.
202
- 10. Do not ship concrete model-version defaults in packaged recipes; expose `model`, `models`, and stage-specific model args so the caller must choose current policy at launch.
197
+ 5. When exposing an already-authored recipe as a user tool, make a small wrapper recipe in `~/.pi/agent/recipes` that imports the source recipe and uses a `{ "name": "alias" }` node. Do not copy the ready recipe's script command, defaults, mailbox, or artifacts into a second template.
198
+ 6. Declare `mailbox` for actors that accept or emit meaningful messages.
199
+ 7. Declare `artifacts` for durable outputs the coordinator should inspect.
200
+ 8. File-backed recipe identity comes from the filename basename; legacy top-level `name` fields are ignored by loaders.
201
+ 9. File-backed async recipes pass child `pi -p` actors a bounded JSONL recipe context bundle by default: raw entry/import recipe records, derived `name`, import path/alias, and `"you_are_here": true` on the launching recipe node. Set `"actor_context": false` or `"off"` to suppress it for minimal prompts.
202
+ 10. Keep packaged recipes generic: no machine-local paths, no private companion identities, no project-specific defaults unless the recipe is explicitly project-specific.
203
+ 11. Do not ship concrete model-version defaults in packaged recipes; expose `model`, `models`, and stage-specific model args so the caller must choose current policy at launch.
203
204
 
204
205
  Priority for same-id recipes:
205
206
 
@@ -227,16 +228,32 @@ Cleanup rule: periodically inspect `~/.pi/agent/recipes` as the live muscle-memo
227
228
 
228
229
  `register_tool` persists trusted local capabilities as recipe files in `~/.pi/agent/recipes/*.json`; hand-authored Markdown recipes in the same directory are also discovered as tools.
229
230
 
230
- Use it when a command/template/recipe should become durable agent muscle memory. Prefer typed args or placeholder-derived args; use `update=true` for replacement and `template=null` or `template=""` for deletion. `register_tool` should create/update/delete recipe files in the user recipe root; direct file editing is allowed but is the lower-level path.
231
+ Use it when a command/template/recipe should become durable agent muscle memory. Prefer typed args or placeholder-derived args; use `update=true` for replacement and `template=null` or `template=""` for deletion. `register_tool` should create/update/delete simple recipe files in the user recipe root; direct recipe-file editing is the right path when the wrapper needs `imports` or other top-level recipe metadata not exposed by the interactive mutation API.
232
+
233
+ Ready-recipe registration pattern:
234
+
235
+ ```json
236
+ {
237
+ "description": "Run the ABCd context validator through its skill recipe.",
238
+ "imports": {
239
+ "validate_context": "{agent}/skills/abcd-context/recipes/validate-context.json"
240
+ },
241
+ "args": ["path:path=."],
242
+ "template": { "name": "validate_context" }
243
+ }
244
+ ```
245
+
246
+ Use this pattern whenever a reusable recipe already exists: packaged pi-actors components, project-local recipes, ad hoc reviewed recipe files, and especially skill-owned recipes that wrap skill scripts. The wrapper owns only the public tool name, description, optional narrowed args/defaults, and local usage metadata. The imported recipe remains the source of truth for the script path, default values, mailbox contract, artifacts, and future fixes.
231
247
 
232
248
  Tool-registration lenses are open-ended prompts for deciding what deserves durable tool status:
233
249
 
234
250
  1. **Reliability lens**: register wrappers for operations where agents commonly omit checks, run steps out of order, pass ambiguous inputs, or recover poorly from partial failure.
235
251
  2. **Safety lens**: prefer read-only diagnostics, dry-runs, preflights, confirmations, or bounded adapters around high-impact operations before registering direct action tools.
236
252
  3. **Context-affordance lens**: register tools whose mere presence in the injected capability list should steer agents toward the right operational habit.
237
- 4. **Existing-recipe lens**: scan already-authored recipes before inventing a new tool. Packaged recipes, ad hoc project recipes, and recipes co-located under skill directories are often the first candidates to copy/register into the user recipe root when they match a recurring local workflow.
238
- 5. **Composition lens**: register small semantic entrypoints over reusable recipe components instead of baking one large scenario-specific shell command into a tool.
239
- 6. **Portability lens**: keep recipe files transportable; make tool exposure a consequence of placement in `~/.pi/agent/recipes`, not recipe-owned markers or machine-local assumptions.
253
+ 4. **Existing-recipe lens**: scan already-authored recipes before inventing a new tool. Packaged recipes, ad hoc project recipes, and recipes co-located under skill directories are the first candidates to import from a user-root wrapper when they match a recurring local workflow.
254
+ 5. **Skill-recipe lens**: when a skill ships a recipe for its script, local tools must import that recipe instead of calling the skill script directly. This preserves the skill's maintained interface and keeps future script/default changes centralized.
255
+ 6. **Composition lens**: register small semantic entrypoints over reusable recipe components instead of baking one large scenario-specific shell command into a tool.
256
+ 7. **Portability lens**: keep recipe files transportable; make tool exposure a consequence of placement in `~/.pi/agent/recipes`, not recipe-owned markers or machine-local assumptions.
240
257
 
241
258
  Default bias: register diagnostic/preflight tools before action tools, and promote existing recipes before writing new orchestration. A good persistent tool shrinks the chance of a subtle operational mistake, not just the number of keystrokes.
242
259
 
@@ -2,7 +2,7 @@
2
2
  name: swarm
3
3
  description: Subagent orchestration with scoped locks and quorum consensus. Use for multi-model review, parallel scoped work, delegated audit, and coordinated subagent execution.
4
4
  metadata:
5
- version: 0.35.0
5
+ version: 0.36.0
6
6
  ---
7
7
 
8
8
  # Swarm
@@ -115,6 +115,8 @@ Utility recipes cover local operator workflows that do not need subagents:
115
115
  - `recipes/utility-skill-summary.json`: Use `scripts/recipe-utils.mjs` to summarize packaged skill frontmatter, body shape, formatter-safe scalar lines, and package-version alignment.
116
116
  - `recipes/utility-validate-recipe.json`: Use `scripts/validate-recipe.mjs` to validate one template recipe file, or all packaged recipes in a directory with `all: true`.
117
117
 
118
+ Packaged QA is available through the `recipes:qa` npm script. It reports description warnings and fails exact diagnostics for async mailbox contracts, termination vocabulary, artifact paths, platform scope, helper script paths, and missing helper scripts.
119
+
118
120
  These recipes are intentionally small. Register them only for trusted local commands and prefer narrow scopes. Discovery diagnostics flag obvious trust-boundary shapes such as shell/eval/destructive commands; those warnings are operator review aids, not a sandbox. The helper-backed utilities share `scripts/recipe-utils.mjs` so repeated parsing/listing logic stays out of recipe strings.
119
121
 
120
122
  ## Actor OS Smoke Matrix
@@ -292,6 +292,8 @@ An import binding may be either a string recipe path/name or an object with:
292
292
 
293
293
  A template node of `{ "name": "alias" }` is replaced with the imported recipe's command-template graph. Imported recipe defaults are merged with import `defaults`, import `values`, node `defaults`, and node `values`; later layers win. This lets a parent recipe embed a reusable recipe in a sequence or `parallel: true` branch without inventing a workflow language.
294
294
 
295
+ Use imports as the default adapter for exposing ready recipes as local tools. A user-root recipe such as `~/.pi/agent/recipes/repo_context_check.json` should import the maintained source recipe and call `{ "name": "alias" }`, not duplicate the source recipe's script command. Skill scripts are the strongest version of this rule: when a skill provides `recipes/<name>.json` for its `scripts/*` entrypoint, local tools must import the skill recipe via `{agent}/skills/<skill>/recipes/<name>.json` instead of invoking the script path directly.
296
+
295
297
  Async composition stays explicit: importing a recipe reuses its command-template-shaped definition. It does not start a nested async run. Put `async: true` on the parent recipe when the combined imported graph should run detached as one run with one state dir. Ephemeral coordinator recipes may declare `retire_when: "children_terminal"` as an opt-in lifecycle hint for future graceful retirement handling; persistent services and implementer loops should omit it. For agent-callable fanout, prefer public inputs such as `prompts:array` plus `repeat: "{prompts.length}"`, then select each branch value with `{prompts[index]}` instead of baking concrete prompts or file names into the reusable recipe.
296
298
 
297
299
  ```json
@@ -24,14 +24,15 @@ Inspect the loaded pi-actors runtime and discovered registry with:
24
24
 
25
25
  ```text
26
26
  inspect target=tool:pi-actors view=status
27
+ inspect target=tool:pi-actors view=triage
27
28
  inspect target=recipes view=status
28
29
  inspect target=recipes view=doctor
29
30
  inspect target=recipes view=summary verbose=true
30
31
  ```
31
32
 
32
- `tool:pi-actors` is a reserved runtime-status actor: it reports the loaded package version, package root, source/dist mode, entrypoint path, recipe roots, and git commit when available. Use it after reloads to confirm which extension code is actually live.
33
+ `tool:pi-actors` is a reserved runtime-status actor. `view=status` reports the loaded package version, package root, source/dist mode, entrypoint path, recipe roots, and git commit when available. Use it after reloads to confirm which extension code is actually live. `view=triage` adds a compact attention surface for active runs, other-session runs, invalid or blocking recipes, exposed tool recipes with non-lifecycle risk labels, drafts, stale claims, failed runs, attention messages, and next inspect actions without repairing anything. Packaged components and recipes whose only label is `risk.long_running` stay in recipe doctor/summary evidence rather than triage attention.
33
34
 
34
- The recipe summary reports active, shadowed, invalid, disabled, and diagnostic entries so operators can answer why a tool is present, hidden, broken, or disabled. The doctor view keeps the same registry evidence but promotes an advisory action surface: compact output includes the highest-priority `top` remediation plus ordered actions for invalid/blocking, disabled, risky shell-boundary, and shadowed recipes. Verbose inspection keeps the structured `remediations`, `top_action`, diagnostic details, and blocked lower-priority fallback paths when a broken or disabled higher-priority recipe masks a fallback.
35
+ The recipe summary reports active, shadowed, invalid, disabled, and diagnostic entries so operators can answer why a tool is present, hidden, broken, or disabled. The doctor view keeps the same registry evidence but promotes an advisory action surface: compact output includes the highest-priority `top` remediation, risk-label counts, and ordered actions for invalid/blocking, disabled, risky shell-boundary, and shadowed recipes. Verbose inspection keeps per-recipe `risk_labels`, the structured `risk_summary`, `remediations`, `top_action`, diagnostic details, and blocked lower-priority fallback paths when a broken or disabled higher-priority recipe masks a fallback. Risk labels are deterministic review aids, not execution blockers or sandbox claims.
35
36
 
36
37
  Routine shadowing is quiet. If a bare `spawn` recipe launch already fails because an invalid or `disabled: true` user recipe blocks a lower-priority fallback, the launch error adds compact tokens such as `reason=shadowed_invalid` or `reason=shadowed_disabled`, `active_path`, `blocked_fallback`, and `hint=inspect_recipes_doctor`.
37
38
 
@@ -62,18 +63,22 @@ Use `update=true` to overwrite an existing tool. Omit `template` and co-located
62
63
  ]
63
64
  ```
64
65
 
65
- For reusable actor workflows, register a small tool whose `template` points to an existing actor recipe instead of embedding the launch graph in the tool itself:
66
+ For reusable actor workflows, expose an existing recipe by writing a small wrapper recipe in `~/.pi/agent/recipes` that imports the ready recipe and calls it by alias. This keeps the imported recipe as the source of truth for its script path, defaults, mailbox, artifacts, and future fixes:
66
67
 
67
- ```text
68
- register_tool name=docs_review \
69
- description="Start an async docs review actor" \
70
- template="docs_review" \
71
- args="scope:path,model:string"
68
+ ```json
69
+ {
70
+ "description": "Run the ABCd context validator through its skill recipe.",
71
+ "imports": {
72
+ "validate_context": "{agent}/skills/abcd-context/recipes/validate-context.json"
73
+ },
74
+ "args": ["path:path=."],
75
+ "template": { "name": "validate_context" }
76
+ }
72
77
  ```
73
78
 
74
- This writes or updates `~/.pi/agent/recipes/docs_review.json` with a recipe-reference template. Its location in the user recipe root makes it a tool. If the referenced recipe contains `async: true`, calling the tool starts a detached actor run and returns metadata immediately. If `async` is omitted or false, the same recipe runs foreground and returns normal tool output.
79
+ Use the same pattern for packaged pi-actors components, reviewed ad hoc recipes, project-local recipe files, and especially skill recipes that wrap skill scripts. Do not register a local tool that calls `~/.pi/agent/skills/<skill>/scripts/*` directly when the skill already ships a recipe. The wrapper's location in the user recipe root makes it a tool; the import preserves the ready recipe's maintained interface.
75
80
 
76
- When co-location is clearer than a separate file, `register_tool` writes the recipe fields directly into the user recipe file:
81
+ When no ready recipe exists and co-location is clearer than a separate file, `register_tool` writes the recipe fields directly into the user recipe file:
77
82
 
78
83
  ```json
79
84
  {
@@ -67,6 +67,29 @@ export interface CommandTemplateExecResult {
67
67
  killed: boolean;
68
68
  }
69
69
 
70
+ export type CommandTemplateRiskLabel =
71
+ | "risk.shell"
72
+ | "risk.eval"
73
+ | "risk.broad_fs_write"
74
+ | "risk.destructive_fs"
75
+ | "risk.network"
76
+ | "risk.external_side_effect"
77
+ | "risk.long_running"
78
+ | "risk.platform_specific"
79
+ | "risk.secret_touching";
80
+
81
+ const COMMAND_TEMPLATE_RISK_LABEL_ORDER: CommandTemplateRiskLabel[] = [
82
+ "risk.shell",
83
+ "risk.eval",
84
+ "risk.destructive_fs",
85
+ "risk.broad_fs_write",
86
+ "risk.external_side_effect",
87
+ "risk.secret_touching",
88
+ "risk.network",
89
+ "risk.long_running",
90
+ "risk.platform_specific",
91
+ ];
92
+
70
93
  export type CommandTemplateExecCommand = (
71
94
  command: string,
72
95
  args: string[],
@@ -181,6 +204,97 @@ function hasRiskyPathArg(args: string[]): boolean {
181
204
  );
182
205
  }
183
206
 
207
+ function sortRiskLabels(
208
+ labels: Iterable<CommandTemplateRiskLabel>,
209
+ ): CommandTemplateRiskLabel[] {
210
+ const unique = new Set(labels);
211
+ return COMMAND_TEMPLATE_RISK_LABEL_ORDER.filter((label) => unique.has(label));
212
+ }
213
+
214
+ function hasAnyArg(args: string[], values: string[]): boolean {
215
+ return args.some((arg) => values.includes(arg.toLowerCase()));
216
+ }
217
+
218
+ function hasSecretTouchingText(parts: string[]): boolean {
219
+ return parts.some((part) =>
220
+ /(^|[{}._\-\s/])(?:secret|token|password|passwd|credential|api[_-]?key|private[_-]?key|\.env|ssh[_-]?key)(?:[{}._\-\s/]|$)/i.test(
221
+ part,
222
+ ),
223
+ );
224
+ }
225
+
226
+ function getLeafCommandTemplateRiskLabels(
227
+ config: CommandTemplateLeafConfig,
228
+ ): CommandTemplateRiskLabel[] {
229
+ const parts = splitCommandTemplate(config.template);
230
+ const command = getExecutableName(parts[0]);
231
+ const args = parts.slice(1);
232
+ const labels = new Set<CommandTemplateRiskLabel>();
233
+ if (["bash", "sh", "zsh", "fish"].includes(command)) {
234
+ labels.add("risk.shell");
235
+ if (hasAnyFlag(args, ["-c"])) labels.add("risk.eval");
236
+ }
237
+ if (
238
+ ["node", "deno", "bun"].includes(command) &&
239
+ hasAnyFlag(args, ["-e", "--eval"])
240
+ ) {
241
+ labels.add("risk.eval");
242
+ }
243
+ if (
244
+ ["python", "python3", "perl", "ruby"].includes(command) &&
245
+ hasAnyFlag(args, ["-c", "-e"])
246
+ ) {
247
+ labels.add("risk.eval");
248
+ }
249
+ if (
250
+ command === "rm" &&
251
+ (args.some((arg) => /^-[^-]*r/.test(arg) || /^-[^-]*f/.test(arg)) ||
252
+ hasRiskyPathArg(args))
253
+ ) {
254
+ labels.add("risk.destructive_fs");
255
+ }
256
+ if (["mv", "cp", "rsync"].includes(command) && hasRiskyPathArg(args)) {
257
+ labels.add("risk.broad_fs_write");
258
+ }
259
+ if (
260
+ ["curl", "wget", "ssh", "scp", "sftp", "rsync", "nc", "ncat", "telnet", "ftp"].includes(
261
+ command,
262
+ ) ||
263
+ (command === "git" &&
264
+ hasAnyArg(args, ["clone", "fetch", "pull", "push", "ls-remote"])) ||
265
+ ["npm", "pnpm", "yarn", "pip", "cargo"].includes(command)
266
+ ) {
267
+ labels.add("risk.network");
268
+ }
269
+ if (
270
+ ["gh", "glab", "hub", "kubectl", "terraform"].includes(command) ||
271
+ (command === "git" && hasAnyArg(args, ["push"])) ||
272
+ (["npm", "pnpm", "yarn"].includes(command) &&
273
+ hasAnyArg(args, ["publish", "login", "logout", "deprecate"]))
274
+ ) {
275
+ labels.add("risk.external_side_effect");
276
+ }
277
+ if (
278
+ command === "sleep" ||
279
+ command === "watch" ||
280
+ (command === "tail" && hasAnyFlag(args, ["-f"])) ||
281
+ hasAnyArg(args, ["--watch", "--serve", "serve"])
282
+ ) {
283
+ labels.add("risk.long_running");
284
+ }
285
+ if (
286
+ ["systemctl", "launchctl", "osascript", "open", "xdg-open", "powershell", "pwsh", "cmd.exe", "apt", "apt-get", "dnf", "yum", "brew", "pacman", "apk", "xclip", "wl-copy"].includes(
287
+ command,
288
+ )
289
+ ) {
290
+ labels.add("risk.platform_specific");
291
+ }
292
+ if (["pass", "gpg", "ssh-add"].includes(command) || hasSecretTouchingText(parts)) {
293
+ labels.add("risk.secret_touching");
294
+ }
295
+ return sortRiskLabels(labels);
296
+ }
297
+
184
298
  function getLeafCommandTemplateWarnings(
185
299
  config: CommandTemplateLeafConfig,
186
300
  ): string[] {
@@ -347,6 +461,16 @@ export function getCommandTemplateWarnings(
347
461
  ];
348
462
  }
349
463
 
464
+ export function getCommandTemplateRiskLabels(
465
+ config: CommandTemplateConfig,
466
+ ): CommandTemplateRiskLabel[] {
467
+ return sortRiskLabels(
468
+ expandCommandTemplateConfigs(config).flatMap((leaf) =>
469
+ getLeafCommandTemplateRiskLabels(leaf),
470
+ ),
471
+ );
472
+ }
473
+
350
474
  function parseCommandTemplateArgToken(value: string): {
351
475
  name: string;
352
476
  defaultValue?: string;