pi-subagents 0.40.0 → 0.42.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 (121) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/README.md +54 -1879
  3. package/agents/oracle.md +1 -0
  4. package/inspector-runner.mjs +11 -0
  5. package/package.json +13 -5
  6. package/prompts/parallel-context-build.md +1 -1
  7. package/prompts/parallel-handoff-plan.md +1 -1
  8. package/prompts/review-loop.md +1 -1
  9. package/skills/pi-subagents/SKILL.md +9 -7
  10. package/skills/pi-subagents/references/constraints-and-recipes.md +24 -32
  11. package/skills/pi-subagents/references/execution-controls.md +99 -97
  12. package/skills/pi-subagents/references/management-authoring-rpc.md +2 -2
  13. package/skills/pi-subagents/references/prompting-and-roles.md +23 -30
  14. package/src/agents/agent-management.ts +155 -65
  15. package/src/agents/agent-serializer.ts +19 -0
  16. package/src/agents/agents.ts +154 -71
  17. package/src/agents/chain-serializer.ts +10 -7
  18. package/src/agents/frontmatter.ts +5 -3
  19. package/src/agents/identity.ts +1 -1
  20. package/src/agents/proactive-skills.ts +13 -10
  21. package/src/agents/skills.ts +23 -6
  22. package/src/api/control-channel.ts +4 -0
  23. package/src/api/delegation.ts +26 -194
  24. package/src/api/external-runs.ts +129 -0
  25. package/src/api/intercom-bridge.ts +3 -0
  26. package/src/api/pi-args.ts +5 -0
  27. package/src/api/preflight.ts +3 -3
  28. package/src/api/shared-types.ts +19 -0
  29. package/src/extension/config.ts +10 -0
  30. package/src/extension/control-notices.ts +5 -39
  31. package/src/extension/doctor.ts +10 -9
  32. package/src/extension/fanout-child.ts +7 -4
  33. package/src/extension/index.ts +232 -68
  34. package/src/extension/rpc.ts +18 -12
  35. package/src/extension/schemas.ts +48 -37
  36. package/src/extension/tool-description.ts +36 -86
  37. package/src/inspectors/herdr/actions.ts +229 -0
  38. package/src/inspectors/herdr/client.ts +130 -0
  39. package/src/inspectors/herdr/inspector-runner.ts +141 -0
  40. package/src/inspectors/herdr/project-panes.ts +154 -0
  41. package/src/integrations/herdr-status.ts +330 -0
  42. package/src/intercom/intercom-bridge.ts +3 -2
  43. package/src/intercom/result-intercom.ts +5 -1
  44. package/src/missions/actions.ts +374 -0
  45. package/src/missions/lifecycle.ts +314 -0
  46. package/src/missions/store.ts +442 -0
  47. package/src/missions/types.ts +135 -0
  48. package/src/policy/authority.ts +46 -0
  49. package/src/profiles/profiles.ts +29 -3
  50. package/src/runs/background/async-execution.ts +110 -50
  51. package/src/runs/background/async-job-tracker.ts +27 -4
  52. package/src/runs/background/async-resume.ts +6 -6
  53. package/src/runs/background/async-status.ts +29 -1
  54. package/src/runs/background/auto-drain.ts +3 -3
  55. package/src/runs/background/chain-append.ts +3 -2
  56. package/src/runs/background/control-channel.ts +9 -7
  57. package/src/runs/background/fleet-view.ts +3 -4
  58. package/src/runs/background/notify.ts +2 -1
  59. package/src/runs/background/process-terminal.ts +5 -5
  60. package/src/runs/background/result-watcher.ts +13 -5
  61. package/src/runs/background/run-id-resolver.ts +3 -3
  62. package/src/runs/background/run-status.ts +35 -8
  63. package/src/runs/background/scheduled-runs.ts +602 -375
  64. package/src/runs/background/stale-run-reconciler.ts +3 -3
  65. package/src/runs/background/subagent-runner.ts +608 -445
  66. package/src/runs/background/subagent-wait.ts +50 -9
  67. package/src/runs/background/wait-subscriptions.ts +253 -0
  68. package/src/runs/background/wait-tool.ts +12 -4
  69. package/src/runs/foreground/async-steering-action.ts +3 -3
  70. package/src/runs/foreground/chain-clarify.ts +8 -4
  71. package/src/runs/foreground/chain-execution.ts +56 -30
  72. package/src/runs/foreground/execution.ts +34 -9
  73. package/src/runs/foreground/subagent-executor.ts +1036 -274
  74. package/src/runs/shared/acceptance.ts +28 -6
  75. package/src/runs/shared/child-protocol.ts +302 -22
  76. package/src/runs/shared/dynamic-fanout.ts +1 -1
  77. package/src/runs/shared/external-cli-runner.ts +130 -0
  78. package/src/runs/shared/long-running-guard.ts +42 -1
  79. package/src/runs/shared/mcp-direct-tool-allowlist.ts +2 -0
  80. package/src/runs/shared/nested-events.ts +59 -5
  81. package/src/runs/shared/nested-render.ts +9 -4
  82. package/src/runs/shared/parallel-handoff.ts +86 -2
  83. package/src/runs/shared/parallel-utils.ts +11 -2
  84. package/src/runs/shared/permissions.ts +95 -0
  85. package/src/runs/shared/pi-args.ts +468 -109
  86. package/src/runs/shared/pi-spawn.ts +11 -1
  87. package/src/runs/shared/run-history.ts +1 -1
  88. package/src/runs/shared/subagent-prompt-runtime.ts +36 -5
  89. package/src/runs/shared/subagent-startup-retry.ts +5 -2
  90. package/src/runs/shared/turn-budget.ts +6 -6
  91. package/src/runs/shared/worktree.ts +122 -12
  92. package/src/shared/accessible-dir.ts +29 -7
  93. package/src/shared/artifacts.ts +143 -1
  94. package/src/shared/fork-context.ts +3 -2
  95. package/src/shared/launch-contract.ts +1 -0
  96. package/src/shared/settings.ts +10 -0
  97. package/src/shared/types.ts +156 -14
  98. package/src/shared/utils.ts +8 -6
  99. package/src/slash/delegation-adapters.ts +32 -194
  100. package/src/slash/delegation-request.ts +43 -126
  101. package/src/slash/prompt-template-bridge.ts +158 -205
  102. package/src/slash/prompt-workflows.ts +21 -57
  103. package/src/slash/slash-bridge.ts +14 -0
  104. package/src/slash/slash-commands.ts +31 -632
  105. package/src/slash/subagents-admin.ts +18 -14
  106. package/src/tui/fleet-status.ts +156 -21
  107. package/src/tui/fleet-transcript.ts +110 -5
  108. package/src/tui/fleet.ts +57 -25
  109. package/src/tui/render.ts +368 -152
  110. package/src/types/pi-runtime-compat.d.ts +8 -0
  111. package/src/watchdog/lsp-diagnostics.ts +12 -7
  112. package/src/watchdog/model-selection.ts +2 -2
  113. package/src/watchdog/permission-arbiter.ts +145 -0
  114. package/src/watchdog/register-child.ts +1 -1
  115. package/src/watchdog/register-main.ts +1 -1
  116. package/src/watchdog/review.ts +4 -1
  117. package/src/watchdog/runtime.ts +3 -2
  118. package/src/workflows/chat-progress.ts +140 -0
  119. package/src/workflows/scripted-workflow.ts +415 -0
  120. package/agents/advisor.md +0 -73
  121. package/src/extension/chain-validation.ts +0 -181
@@ -55,6 +55,7 @@ import { evaluateCompletionMutationGuard } from "../shared/completion-guard.ts";
55
55
  import { getPiSpawnCommand } from "../shared/pi-spawn.ts";
56
56
  import { createJsonlWriter } from "../../shared/jsonl-writer.ts";
57
57
  import { attachPostExitStdioGuard, trySignalChild } from "../../shared/post-exit-stdio-guard.ts";
58
+ import { resolvePermissionRules } from "../shared/permissions.ts";
58
59
  import { applyThinkingSuffix, buildPiArgs, cleanupTempDir, projectLaunchResolvedChildExtensions, resolvePiLaunchToolPlan } from "../shared/pi-args.ts";
59
60
  import { readRuntimeAcknowledgedExtensions } from "../shared/runtime-acknowledged-extensions.ts";
60
61
  import { assertAgentAllowedByCapabilityCeiling, decodeSubagentCapabilityCeiling, intersectSubagentCapabilityCeilings, resolveCurrentSubagentCapabilityCeiling, SUBAGENT_CAPABILITY_CEILING_ENV } from "../shared/capability-ceiling.ts";
@@ -86,13 +87,13 @@ import {
86
87
  shouldEscalateMutatingFailures,
87
88
  summarizeRecentMutatingFailures,
88
89
  } from "../shared/long-running-guard.ts";
89
- import { acceptanceFailureMessage, buildSkippedAcceptanceLedger, evaluateAcceptance, formatAcceptancePrompt, resolveEffectiveAcceptance, stripAcceptanceReport } from "../shared/acceptance.ts";
90
+ import { acceptanceFailureMessage, buildSkippedAcceptanceLedger, evaluateAcceptance, formatAcceptancePrompt, resolveEffectiveAcceptance, stripAcceptanceReport, validateAcceptanceInput } from "../shared/acceptance.ts";
90
91
  import { attachContractProjections, isAgentContractV1 } from "../shared/agent-contract.ts";
91
92
  import { appendTurnBudgetSystemPrompt, formatTurnBudgetOutput, initialTurnBudgetState, turnBudgetDecision, turnBudgetDeferredNote, turnBudgetDeferredState, turnBudgetExceededMessage, turnBudgetSoftNote, turnBudgetState } from "../shared/turn-budget.ts";
92
93
  import { initialToolBudgetState, toolBudgetState } from "../shared/tool-budget.ts";
93
94
  import { resolveWatchdogConfig } from "../../watchdog/settings.ts";
94
95
  import { agentDefinitionDigest, launchBindingDigest } from "../../shared/launch-contract.ts";
95
- import { createBoundedByteTail, createBoundedLineReader, formatProtocolOutputLimit, MAX_CHILD_STDERR_BYTES, projectChildLifecycle, type ChildLifecycleAction, type ProtocolOutputLimit } from "../shared/child-protocol.ts";
96
+ import { createBoundedByteTail, createBoundedLineReader, formatProtocolOutputLimit, MAX_CHILD_STDERR_BYTES, PI_AGGREGATE_EVENT_PROJECTOR, projectChildLifecycle, type ChildLifecycleAction, type ProtocolOutputLimit } from "../shared/child-protocol.ts";
96
97
  import {
97
98
  acceptChildWatchdogEvent,
98
99
  childWatchdogIsActive,
@@ -302,6 +303,10 @@ async function runSingleAttempt(
302
303
  childIndex: options.index ?? 0,
303
304
  })
304
305
  : undefined;
306
+ const permissionRules = resolvePermissionRules(options.permissions, agent.permissions);
307
+ const permissionAuditPath = permissionRules && options.artifactsDir
308
+ ? path.join(options.artifactsDir, "permission-audit", `${options.runId}-${options.index ?? 0}.jsonl`)
309
+ : undefined;
305
310
  const { args, env: sharedEnv, tempDir, toolDiagnosticPath, runtimeAcknowledgedExtensionsPath, capabilityAudit } = buildPiArgs({
306
311
  baseArgs: ["--mode", "json", "-p"],
307
312
  task,
@@ -334,6 +339,8 @@ async function runSingleAttempt(
334
339
  structuredOutput: options.structuredOutput,
335
340
  toolBudget: options.toolBudget,
336
341
  allowZeroToolBudget: options.allowZeroToolBudget,
342
+ permissionRules,
343
+ permissionAuditPath,
337
344
  childWatchdog,
338
345
  waitToolEnabled: options.waitToolEnabled,
339
346
  capabilityCeiling: options.capabilityCeiling,
@@ -977,14 +984,14 @@ async function runSingleAttempt(
977
984
  }
978
985
  };
979
986
 
980
- if (controlConfig.enabled) {
987
+ fireUpdate();
988
+ if (controlConfig.enabled || options.onUpdate) {
981
989
  activityTimer = setInterval(() => {
982
- if (processClosed || lifecycleFinished) return;
983
- const now = Date.now();
984
- if (updateActivityState(now)) {
985
- progress.durationMs = now - startTime;
986
- fireUpdate();
990
+ if (processClosed || lifecycleFinished) {
991
+ return;
987
992
  }
993
+ updateActivityState(Date.now());
994
+ fireUpdate();
988
995
  }, 1000);
989
996
  activityTimer.unref?.();
990
997
  }
@@ -1031,7 +1038,11 @@ async function runSingleAttempt(
1031
1038
  protocolHardKillTimer.unref?.();
1032
1039
  }
1033
1040
  };
1034
- const stdoutReader = createBoundedLineReader({ onLine: processLine, onLimit: failProtocol });
1041
+ const stdoutReader = createBoundedLineReader({
1042
+ oversizedLineProjector: PI_AGGREGATE_EVENT_PROJECTOR,
1043
+ onLine: processLine,
1044
+ onLimit: failProtocol,
1045
+ });
1035
1046
  const stderrReader = createBoundedLineReader({
1036
1047
  stream: "stderr",
1037
1048
  maxPendingLineBytes: MAX_CHILD_STDERR_BYTES,
@@ -1229,6 +1240,7 @@ async function runSingleAttempt(
1229
1240
 
1230
1241
  const acceptanceOutput = getFinalOutput(result.messages ?? []);
1231
1242
  let fullOutput = stripAcceptanceReport(acceptanceOutput);
1243
+ if (!fullOutput.trim() && result.structuredOutput !== undefined) fullOutput = JSON.stringify(result.structuredOutput, null, 2);
1232
1244
  result.outputState = fullOutput.trim() || result.structuredOutput !== undefined ? "present" : "absent";
1233
1245
  if (result.timedOut) {
1234
1246
  const timeoutMessage = formatTimeoutMessage(options.timeoutMs ?? 0);
@@ -1346,6 +1358,7 @@ async function runSyncCompletion(
1346
1358
  assertAgentAllowedByCapabilityCeiling(agent.name, options.capabilityCeiling);
1347
1359
  } catch (error) {
1348
1360
  return withRunContext({
1361
+ index: options.index ?? 0,
1349
1362
  agent: agent.name,
1350
1363
  task,
1351
1364
  exitCode: 1,
@@ -1355,6 +1368,18 @@ async function runSyncCompletion(
1355
1368
  ...(options.capabilityCeiling ? { capabilityCeiling: options.capabilityCeiling } : {}),
1356
1369
  }, options.context);
1357
1370
  }
1371
+ const acceptanceErrors = validateAcceptanceInput(options.acceptance);
1372
+ if (acceptanceErrors.length > 0) {
1373
+ return withRunContext({
1374
+ index: options.index ?? 0,
1375
+ agent: agentName,
1376
+ task,
1377
+ exitCode: 1,
1378
+ messages: [],
1379
+ usage: emptyUsage(),
1380
+ error: acceptanceErrors.join(" "),
1381
+ }, options.context);
1382
+ }
1358
1383
  const outputModeValidationError = validateFileOnlyOutputMode(options.outputMode, options.outputPath, `Single run (${agentName})`);
1359
1384
  if (outputModeValidationError) {
1360
1385
  return withRunContext({