@narumitw/pi-subagents 0.52.0 → 0.54.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 (67) hide show
  1. package/README.md +154 -12
  2. package/package.json +1 -1
  3. package/src/agents/built-ins.ts +124 -0
  4. package/src/agents/catalog.ts +224 -0
  5. package/src/agents/discovery.ts +249 -0
  6. package/src/agents/types.ts +98 -0
  7. package/src/agents.ts +47 -665
  8. package/src/auto-transport.ts +2 -1
  9. package/src/automation-contract.ts +709 -0
  10. package/src/automation-planner.ts +65 -0
  11. package/src/automation.ts +585 -0
  12. package/src/capability-router.ts +1 -1
  13. package/src/completion-delivery.ts +2 -3
  14. package/src/config-status.ts +2 -2
  15. package/src/config-ui.ts +8 -8
  16. package/src/consult-resources.ts +1 -1
  17. package/src/consult.ts +9 -7
  18. package/src/create-stateful-transport.ts +2 -1
  19. package/src/cwd-policy.ts +1 -1
  20. package/src/execution/budget.ts +56 -0
  21. package/src/execution/runtime-policy.ts +19 -0
  22. package/src/execution-plan.ts +2 -2
  23. package/src/execution-profiles.ts +1 -1
  24. package/src/execution-ui.ts +1 -1
  25. package/src/execution.ts +269 -100
  26. package/src/in-process-transport.ts +3 -2
  27. package/src/inspect.ts +35 -8
  28. package/src/limits.ts +1 -0
  29. package/src/orchestration-metrics.ts +12 -5
  30. package/src/panel-execution.ts +1 -1
  31. package/src/panel-planning.ts +1 -1
  32. package/src/params.ts +3 -1
  33. package/src/persistence.ts +1 -1
  34. package/src/registry-types.ts +1 -1
  35. package/src/registry.ts +1 -1
  36. package/src/render.ts +1 -1
  37. package/src/retained-semantic-state.ts +1 -1
  38. package/src/rpc-transport-metadata.ts +1 -1
  39. package/src/rpc-transport.ts +2 -1
  40. package/src/runner.ts +6 -1
  41. package/src/settings/inspection.ts +275 -0
  42. package/src/settings/schema.ts +186 -0
  43. package/src/settings.ts +72 -420
  44. package/src/spawn-idempotency.ts +1 -1
  45. package/src/stateful-agent-view.ts +87 -0
  46. package/src/stateful-config.ts +1 -1
  47. package/src/stateful-guidance.ts +1 -1
  48. package/src/stateful-limits.ts +1 -1
  49. package/src/stateful-prompt.ts +2 -2
  50. package/src/stateful-safety.ts +2 -1
  51. package/src/stateful.ts +23 -103
  52. package/src/subagents.ts +10 -9
  53. package/src/subprocess-transport.ts +2 -6
  54. package/src/transport-types.ts +1 -1
  55. package/src/transport-ui.ts +1 -1
  56. package/src/verification-harness.ts +516 -0
  57. package/src/verification-receipt.ts +275 -0
  58. package/src/verified-execution-benchmark.ts +86 -0
  59. package/src/verified-execution-contract.ts +219 -0
  60. package/src/work-item-ledger.ts +510 -37
  61. package/src/work-item-persistence.ts +31 -0
  62. package/src/workflow-completion-controller.ts +397 -0
  63. package/src/workflow-plan-compiler.ts +618 -0
  64. package/src/workflow-plan-patch.ts +636 -0
  65. package/src/workflow-planning-benchmark.ts +95 -0
  66. package/src/workflow-planning.ts +11 -1
  67. package/src/workflow-ui.ts +3 -3
package/src/config-ui.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
2
- import {
3
- type CompletionDelivery,
4
- type ConsultationCwdPolicy,
5
- type ConsultResourcePolicy,
6
- type DelegationCwdPolicy,
7
- discoverAgents,
8
- } from "./agents.js";
2
+ import { discoverAgents } from "./agents/discovery.js";
3
+ import type {
4
+ CompletionDelivery,
5
+ ConsultationCwdPolicy,
6
+ ConsultResourcePolicy,
7
+ DelegationCwdPolicy,
8
+ } from "./agents/types.js";
9
9
  import {
10
10
  completionLabel,
11
11
  consultationCwdLabel,
@@ -38,8 +38,8 @@ import {
38
38
  } from "./parallel-limit-ui.js";
39
39
  import type { ManagedAgent } from "./registry.js";
40
40
  import { safeTerminalLine as safeTerminalText } from "./safe-text.js";
41
+ import type { DelegationWorkflow } from "./settings/inspection.js";
41
42
  import {
42
- type DelegationWorkflow,
43
43
  hasOwn,
44
44
  inspectBlockingParallelLimitSettings,
45
45
  inspectCompletionDeliverySettings,
@@ -1,4 +1,4 @@
1
- import type { ConsultResourcePolicy } from "./agents.js";
1
+ import type { ConsultResourcePolicy } from "./agents/types.js";
2
2
  import { DEFAULT_MAX_CONTEXT_BYTES, truncateUtf8 } from "./limits.js";
3
3
  import { resolvePiPromptResources } from "./prompt-resources.js";
4
4
  import type { ChildLaunchPolicy } from "./runner.js";
package/src/consult.ts CHANGED
@@ -8,17 +8,16 @@ import {
8
8
  type ToolDefinition,
9
9
  } from "@earendil-works/pi-coding-agent";
10
10
  import { type Static, Type } from "typebox";
11
+ import { DEFAULT_AGENT_CATALOG_MAX_ITEMS } from "./agents/catalog.js";
12
+ import { type AgentDiscoveryResult, discoverAgents } from "./agents/discovery.js";
11
13
  import {
12
14
  type AgentConfig,
13
- type AgentDiscoveryResult,
14
15
  type AgentScope,
15
16
  type ConsultResourcePolicy,
16
- DEFAULT_AGENT_CATALOG_MAX_ITEMS,
17
- discoverAgents,
18
17
  isThinkingLevel,
19
18
  type SubagentSettings,
20
19
  THINKING_LEVELS,
21
- } from "./agents.js";
20
+ } from "./agents/types.js";
22
21
  import { resolveConsultTools } from "./consult-policy.js";
23
22
  import { renderConsultCall, renderConsultResult } from "./consult-render.js";
24
23
  import { resolveConsultResourceLaunchPolicy } from "./consult-resources.js";
@@ -27,7 +26,10 @@ import {
27
26
  type ResolvedSubagentTarget,
28
27
  resolveSubagentTarget,
29
28
  } from "./cwd-policy.js";
30
- import { assertSubagentDepthAllowed, resolveDefaultSubagentTimeoutMs } from "./execution.js";
29
+ import {
30
+ assertSubagentDepthAllowed,
31
+ resolveDefaultSubagentTimeoutMs,
32
+ } from "./execution/runtime-policy.js";
31
33
  import {
32
34
  DEFAULT_MAX_CONTEXT_BYTES,
33
35
  DEFAULT_MAX_STDERR_BYTES,
@@ -45,8 +47,8 @@ import { boundedPrivateText, boundText, safeDisplayPath, safeTerminalLine } from
45
47
  import {
46
48
  DEFAULT_CONSULT_RESOURCE_POLICY,
47
49
  DEFAULT_CONSULTATION_CWD_POLICY,
48
- resolveSubagentThinkingLevel,
49
- } from "./settings.js";
50
+ } from "./settings/inspection.js";
51
+ import { resolveSubagentThinkingLevel } from "./settings.js";
50
52
 
51
53
  const ConsultScopeSchema = StringEnum(["user", "project", "both"] as const, {
52
54
  default: "user",
@@ -1,5 +1,6 @@
1
1
  import type { ModelRegistry } from "@earendil-works/pi-coding-agent";
2
- import { discoverAgents, type SubagentSettings, type SubagentTransportKind } from "./agents.js";
2
+ import { discoverAgents } from "./agents/discovery.js";
3
+ import type { SubagentSettings, SubagentTransportKind } from "./agents/types.js";
3
4
  import { AutoTransport } from "./auto-transport.js";
4
5
  import {
5
6
  type ChildSessionFactory,
package/src/cwd-policy.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
3
  import { getAgentDir, ProjectTrustStore } from "@earendil-works/pi-coding-agent";
4
- import type { ConsultationCwdPolicy, DelegationCwdPolicy } from "./agents.js";
4
+ import type { ConsultationCwdPolicy, DelegationCwdPolicy } from "./agents/types.js";
5
5
  import { safeTerminalLine } from "./safe-text.js";
6
6
 
7
7
  export type TargetBoundary = "current-workspace" | "external";
@@ -0,0 +1,56 @@
1
+ import type { AgentConfig } from "../agents/types.js";
2
+ import type { TurnLimits } from "../turn-budget.js";
3
+
4
+ export interface ExecutionBudget {
5
+ timeoutMs: number;
6
+ workTimeoutReason: "work_timeout" | "orchestration_timeout";
7
+ workTimeoutReportLimit: number;
8
+ }
9
+
10
+ export function resolveConfiguredTimeout(
11
+ agents: readonly AgentConfig[],
12
+ agentName: string,
13
+ localTimeoutMs: number | undefined,
14
+ topLevelTimeoutMs: number | undefined,
15
+ defaultTimeoutMs: number,
16
+ ): number {
17
+ return (
18
+ localTimeoutMs ??
19
+ topLevelTimeoutMs ??
20
+ agents.find((agent) => agent.name === agentName)?.timeoutMs ??
21
+ defaultTimeoutMs
22
+ );
23
+ }
24
+
25
+ export function mergeTurnLimits(local: TurnLimits | undefined, fallback: TurnLimits): TurnLimits {
26
+ return {
27
+ idleTimeoutMs: local?.idleTimeoutMs ?? fallback.idleTimeoutMs,
28
+ maxTurns: local?.maxTurns ?? fallback.maxTurns,
29
+ maxToolCalls: local?.maxToolCalls ?? fallback.maxToolCalls,
30
+ };
31
+ }
32
+
33
+ export function calculateExecutionBudget(input: {
34
+ requestedTimeoutMs: number;
35
+ orchestrationDeadline?: number;
36
+ totalTimeoutMs?: number;
37
+ now: number;
38
+ }): ExecutionBudget | undefined {
39
+ if (input.orchestrationDeadline === undefined) {
40
+ return {
41
+ timeoutMs: input.requestedTimeoutMs,
42
+ workTimeoutReason: "work_timeout",
43
+ workTimeoutReportLimit: input.requestedTimeoutMs,
44
+ };
45
+ }
46
+ const remaining = Math.floor(input.orchestrationDeadline - input.now);
47
+ if (remaining < 1) return undefined;
48
+ const orchestrationLimited = remaining < input.requestedTimeoutMs;
49
+ return {
50
+ timeoutMs: Math.min(input.requestedTimeoutMs, remaining),
51
+ workTimeoutReason: orchestrationLimited ? "orchestration_timeout" : "work_timeout",
52
+ workTimeoutReportLimit: orchestrationLimited
53
+ ? Math.floor(input.totalTimeoutMs as number)
54
+ : input.requestedTimeoutMs,
55
+ };
56
+ }
@@ -0,0 +1,19 @@
1
+ export const FALLBACK_TIMEOUT_MS = 10 * 60 * 1000;
2
+
3
+ export function parsePositiveInteger(value: string | undefined): number | undefined {
4
+ if (!value) return undefined;
5
+ const parsed = Number.parseInt(value, 10);
6
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
7
+ }
8
+
9
+ export function resolveDefaultSubagentTimeoutMs(): number {
10
+ return parsePositiveInteger(process.env.PI_SUBAGENT_TIMEOUT_MS) ?? FALLBACK_TIMEOUT_MS;
11
+ }
12
+
13
+ export function assertSubagentDepthAllowed(): void {
14
+ const depth = Number.parseInt(process.env.PI_SUBAGENT_DEPTH ?? "0", 10) || 0;
15
+ const maxDepth = parsePositiveInteger(process.env.PI_SUBAGENT_MAX_DEPTH) ?? 1;
16
+ if (depth >= maxDepth) {
17
+ throw new Error(`Subagent recursion depth limit reached (${maxDepth})`);
18
+ }
19
+ }
@@ -8,7 +8,7 @@ import {
8
8
  type AgentSource,
9
9
  resolveAgentToolNames,
10
10
  type SubagentThinkingLevel,
11
- } from "./agents.js";
11
+ } from "./agents/types.js";
12
12
  import type { TargetPolicyAudit } from "./cwd-policy.js";
13
13
  import type { DelegationContract } from "./delegation-contract.js";
14
14
  import type { SubagentResultFormat } from "./result-contract.js";
@@ -161,7 +161,7 @@ export function resolveContractTools(
161
161
  contract: DelegationContract | undefined,
162
162
  ): string[] | undefined {
163
163
  const requested = contract?.requestedAuthority?.tools;
164
- if (contract?.enforcement !== "enforce" || !requested || requested.length === 0) {
164
+ if (contract?.enforcement !== "enforce" || requested === undefined) {
165
165
  return configuredTools ? unique(configuredTools) : undefined;
166
166
  }
167
167
  const availableTools = resolveAgentToolNames(configuredTools);
@@ -1,4 +1,4 @@
1
- import type { SubagentThinkingLevel } from "./agents.js";
1
+ import type { SubagentThinkingLevel } from "./agents/types.js";
2
2
  import { readSubagentSettings, updateAgentSettingsPatch } from "./settings.js";
3
3
 
4
4
  export const EXECUTION_PROFILES = ["fast", "balanced", "deep"] as const;
@@ -1,5 +1,5 @@
1
1
  import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
2
- import type { AgentConfig, SubagentThinkingLevel } from "./agents.js";
2
+ import type { AgentConfig, SubagentThinkingLevel } from "./agents/types.js";
3
3
  import {
4
4
  applyExecutionProfile,
5
5
  EXECUTION_PROFILES,