@narumitw/pi-subagents 0.49.2 → 0.51.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 (81) hide show
  1. package/README.md +313 -53
  2. package/package.json +11 -8
  3. package/src/adaptive-scheduler.ts +196 -0
  4. package/src/admission-benchmark.ts +95 -0
  5. package/src/admission-policy.ts +78 -0
  6. package/src/agent-projection.ts +53 -0
  7. package/src/agents.ts +58 -1
  8. package/src/auto-transport.ts +114 -0
  9. package/src/blocking-status.ts +63 -0
  10. package/src/capabilities.ts +145 -0
  11. package/src/capability-grant.ts +115 -0
  12. package/src/capability-router.ts +107 -0
  13. package/src/completion-delivery.ts +257 -0
  14. package/src/config-status.ts +221 -0
  15. package/src/config-ui.ts +215 -236
  16. package/src/consult-resources.ts +4 -27
  17. package/src/consult.ts +9 -1
  18. package/src/create-stateful-transport.ts +55 -0
  19. package/src/delegation-contract.ts +417 -0
  20. package/src/execution-plan.ts +322 -0
  21. package/src/execution-profiles.ts +95 -0
  22. package/src/execution-ui.ts +320 -0
  23. package/src/execution.ts +848 -158
  24. package/src/in-process-transport.ts +269 -25
  25. package/src/inspect-render.ts +101 -1
  26. package/src/inspect.ts +296 -3
  27. package/src/integration-controller.ts +98 -0
  28. package/src/limits.ts +3 -0
  29. package/src/orchestration-metrics.ts +78 -0
  30. package/src/outcome.ts +61 -0
  31. package/src/panel-child-group.ts +35 -0
  32. package/src/panel-contract.ts +343 -0
  33. package/src/panel-evidence.ts +59 -0
  34. package/src/panel-execution.ts +772 -0
  35. package/src/panel-failure.ts +56 -0
  36. package/src/panel-planning.ts +175 -0
  37. package/src/panel-prompts.ts +132 -0
  38. package/src/panel-reconciliation.ts +57 -0
  39. package/src/panel-render.ts +103 -0
  40. package/src/parallel-limit-ui.ts +112 -0
  41. package/src/params.ts +172 -3
  42. package/src/persistence.ts +182 -32
  43. package/src/prompt-resources.ts +38 -0
  44. package/src/registry-types.ts +175 -0
  45. package/src/registry.ts +466 -143
  46. package/src/render.ts +72 -6
  47. package/src/result-contract.ts +416 -0
  48. package/src/retained-semantic-state.ts +100 -0
  49. package/src/rpc-timeout-finalization.ts +207 -0
  50. package/src/rpc-transport-metadata.ts +65 -0
  51. package/src/rpc-transport.ts +990 -0
  52. package/src/rpc-turn-capture.ts +142 -0
  53. package/src/runner-result.ts +55 -0
  54. package/src/runner-usage.ts +48 -0
  55. package/src/runner.ts +325 -73
  56. package/src/semantic-snapshot.ts +214 -0
  57. package/src/settings.ts +254 -35
  58. package/src/spawn-idempotency.ts +61 -0
  59. package/src/stateful-config.ts +13 -0
  60. package/src/stateful-guidance.ts +1 -0
  61. package/src/stateful-lifecycle.ts +45 -2
  62. package/src/stateful-limit-ui.ts +246 -0
  63. package/src/stateful-limits.ts +96 -0
  64. package/src/stateful-prompt.ts +11 -2
  65. package/src/stateful-render.ts +48 -3
  66. package/src/stateful.ts +467 -357
  67. package/src/subagents.ts +114 -46
  68. package/src/subprocess-transport.ts +64 -5
  69. package/src/supervision.ts +103 -0
  70. package/src/timeout-checkpoint.ts +305 -0
  71. package/src/timeout-finalization.ts +75 -0
  72. package/src/transport-types.ts +68 -0
  73. package/src/transport-ui.ts +169 -0
  74. package/src/transport.ts +16 -4
  75. package/src/turn-budget.ts +109 -0
  76. package/src/verification-policy.ts +17 -0
  77. package/src/work-item-ledger.ts +682 -0
  78. package/src/work-item-persistence.ts +218 -0
  79. package/src/workflow-planning.ts +150 -0
  80. package/src/workflow-ui.ts +61 -0
  81. package/src/workspace.ts +69 -12
@@ -0,0 +1,109 @@
1
+ import { MAX_SUBAGENT_TIMEOUT_MS } from "./limits.js";
2
+ import type { TurnTerminationReason } from "./timeout-checkpoint.js";
3
+
4
+ export const MAX_SUBAGENT_TURNS = 1_000_000;
5
+ export const MAX_SUBAGENT_TOOL_CALLS = 1_000_000;
6
+
7
+ export interface TurnLimits {
8
+ idleTimeoutMs?: number;
9
+ maxTurns?: number;
10
+ maxToolCalls?: number;
11
+ }
12
+
13
+ export interface TurnBudgetStop {
14
+ reason: Extract<TurnTerminationReason, "idle_timeout" | "turn_limit" | "tool_call_limit">;
15
+ limit: number;
16
+ }
17
+
18
+ export interface TurnBudgetMonitorOptions extends TurnLimits {
19
+ onExceeded(stop: TurnBudgetStop): void;
20
+ }
21
+
22
+ const TERMINAL_STOP_REASONS = new Set(["stop", "length", "error", "aborted"]);
23
+
24
+ export function validateTurnLimits(limits: TurnLimits): TurnLimits {
25
+ validateOptionalInteger("idleTimeoutMs", limits.idleTimeoutMs, MAX_SUBAGENT_TIMEOUT_MS);
26
+ validateOptionalInteger("maxTurns", limits.maxTurns, MAX_SUBAGENT_TURNS);
27
+ validateOptionalInteger("maxToolCalls", limits.maxToolCalls, MAX_SUBAGENT_TOOL_CALLS);
28
+ return { ...limits };
29
+ }
30
+
31
+ export class TurnBudgetMonitor {
32
+ private readonly limits: TurnLimits;
33
+ private readonly onExceeded: (stop: TurnBudgetStop) => void;
34
+ private idleTimer?: NodeJS.Timeout;
35
+ private assistantTurns = 0;
36
+ private toolCalls = 0;
37
+ private stopped = false;
38
+
39
+ constructor(options: TurnBudgetMonitorOptions) {
40
+ this.limits = validateTurnLimits({
41
+ idleTimeoutMs: options.idleTimeoutMs,
42
+ maxTurns: options.maxTurns,
43
+ maxToolCalls: options.maxToolCalls,
44
+ });
45
+ this.onExceeded = options.onExceeded;
46
+ this.resetIdleTimer();
47
+ }
48
+
49
+ recordActivity(): void {
50
+ if (this.stopped) return;
51
+ this.resetIdleTimer();
52
+ }
53
+
54
+ recordAssistantTurn(stopReason?: string): void {
55
+ if (this.stopped) return;
56
+ this.assistantTurns++;
57
+ this.recordActivity();
58
+ if (
59
+ this.limits.maxTurns !== undefined &&
60
+ this.assistantTurns >= this.limits.maxTurns &&
61
+ !TERMINAL_STOP_REASONS.has(stopReason ?? "")
62
+ ) {
63
+ this.exceed({ reason: "turn_limit", limit: this.limits.maxTurns });
64
+ }
65
+ }
66
+
67
+ recordToolCalls(count = 1): void {
68
+ if (this.stopped || count < 1) return;
69
+ this.toolCalls += count;
70
+ if (this.limits.maxToolCalls !== undefined && this.toolCalls > this.limits.maxToolCalls) {
71
+ this.exceed({ reason: "tool_call_limit", limit: this.limits.maxToolCalls });
72
+ }
73
+ }
74
+
75
+ dispose(): void {
76
+ this.stopped = true;
77
+ if (this.idleTimer) clearTimeout(this.idleTimer);
78
+ this.idleTimer = undefined;
79
+ }
80
+
81
+ private resetIdleTimer(): void {
82
+ if (this.idleTimer) clearTimeout(this.idleTimer);
83
+ const idleTimeoutMs = this.limits.idleTimeoutMs;
84
+ if (idleTimeoutMs === undefined || this.stopped) {
85
+ this.idleTimer = undefined;
86
+ return;
87
+ }
88
+ this.idleTimer = setTimeout(
89
+ () => this.exceed({ reason: "idle_timeout", limit: idleTimeoutMs }),
90
+ idleTimeoutMs,
91
+ );
92
+ this.idleTimer.unref?.();
93
+ }
94
+
95
+ private exceed(stop: TurnBudgetStop): void {
96
+ if (this.stopped) return;
97
+ this.stopped = true;
98
+ if (this.idleTimer) clearTimeout(this.idleTimer);
99
+ this.idleTimer = undefined;
100
+ this.onExceeded(stop);
101
+ }
102
+ }
103
+
104
+ function validateOptionalInteger(name: string, value: number | undefined, maximum: number): void {
105
+ if (value === undefined) return;
106
+ if (!Number.isSafeInteger(value) || value < 1 || value > maximum) {
107
+ throw new Error(`${name} must be an integer between 1 and ${maximum}`);
108
+ }
109
+ }
@@ -0,0 +1,17 @@
1
+ import type { DelegationContract } from "./delegation-contract.js";
2
+
3
+ export interface VerificationRiskInput {
4
+ contract?: DelegationContract;
5
+ integrationOwner: boolean;
6
+ requiredCapabilities: string[];
7
+ }
8
+
9
+ export function requiresIndependentVerification(input: VerificationRiskInput): boolean {
10
+ return (
11
+ input.contract?.admission?.verificationRequired === true ||
12
+ input.requiredCapabilities.some((capability) =>
13
+ ["security-review", "security-implementation", "security-baseline"].includes(capability),
14
+ ) ||
15
+ (input.integrationOwner && input.contract?.sideEffectPolicy !== "read-only")
16
+ );
17
+ }