@narumitw/pi-subagents 2.0.0 → 2.0.2

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 (148) hide show
  1. package/README.md +21 -8
  2. package/dist/chunks/auto-transport-SY2VHUFH.ts +109 -0
  3. package/dist/chunks/auto-transport-SY2VHUFH.ts.map +7 -0
  4. package/dist/chunks/capability-grant-CGEWOEKE.ts +19 -0
  5. package/dist/chunks/capability-grant-CGEWOEKE.ts.map +7 -0
  6. package/dist/chunks/chunk-434NII74.ts +282 -0
  7. package/dist/chunks/chunk-434NII74.ts.map +7 -0
  8. package/dist/chunks/chunk-47SK2QYC.ts +56 -0
  9. package/dist/chunks/chunk-47SK2QYC.ts.map +7 -0
  10. package/dist/chunks/chunk-6KJ34M6S.ts +159 -0
  11. package/dist/chunks/chunk-6KJ34M6S.ts.map +7 -0
  12. package/dist/chunks/chunk-7OBINKFM.ts +80 -0
  13. package/dist/chunks/chunk-7OBINKFM.ts.map +7 -0
  14. package/dist/chunks/chunk-7QPPBBXZ.ts +335 -0
  15. package/dist/chunks/chunk-7QPPBBXZ.ts.map +7 -0
  16. package/dist/chunks/chunk-AEUYS7JC.ts +73 -0
  17. package/dist/chunks/chunk-AEUYS7JC.ts.map +7 -0
  18. package/dist/chunks/chunk-BFK2Z4ZF.ts +189 -0
  19. package/dist/chunks/chunk-BFK2Z4ZF.ts.map +7 -0
  20. package/dist/chunks/chunk-BOAXY55Y.ts +153 -0
  21. package/dist/chunks/chunk-BOAXY55Y.ts.map +7 -0
  22. package/dist/chunks/chunk-C4L6P266.ts +22 -0
  23. package/dist/chunks/chunk-C4L6P266.ts.map +7 -0
  24. package/dist/chunks/chunk-DPPVEQAM.ts +29 -0
  25. package/dist/chunks/chunk-DPPVEQAM.ts.map +7 -0
  26. package/dist/chunks/chunk-DQMN4OYM.ts +913 -0
  27. package/dist/chunks/chunk-DQMN4OYM.ts.map +7 -0
  28. package/dist/chunks/chunk-DSOOH73Y.ts +238 -0
  29. package/dist/chunks/chunk-DSOOH73Y.ts.map +7 -0
  30. package/dist/chunks/chunk-EFBPISNT.ts +421 -0
  31. package/dist/chunks/chunk-EFBPISNT.ts.map +7 -0
  32. package/dist/chunks/chunk-EWWXFU7N.ts +150 -0
  33. package/dist/chunks/chunk-EWWXFU7N.ts.map +7 -0
  34. package/dist/chunks/chunk-F4L2UVSK.ts +380 -0
  35. package/dist/chunks/chunk-F4L2UVSK.ts.map +7 -0
  36. package/dist/chunks/chunk-F5YWVHQX.ts +1543 -0
  37. package/dist/chunks/chunk-F5YWVHQX.ts.map +7 -0
  38. package/dist/chunks/chunk-G3RSMSXJ.ts +63 -0
  39. package/dist/chunks/chunk-G3RSMSXJ.ts.map +7 -0
  40. package/dist/chunks/chunk-G6VZTCFH.ts +70 -0
  41. package/dist/chunks/chunk-G6VZTCFH.ts.map +7 -0
  42. package/dist/chunks/chunk-H3FP6DLR.ts +160 -0
  43. package/dist/chunks/chunk-H3FP6DLR.ts.map +7 -0
  44. package/dist/chunks/chunk-HA36LPCO.ts +130 -0
  45. package/dist/chunks/chunk-HA36LPCO.ts.map +7 -0
  46. package/dist/chunks/chunk-HKC4ES4B.ts +65 -0
  47. package/dist/chunks/chunk-HKC4ES4B.ts.map +7 -0
  48. package/dist/chunks/chunk-HOP5FXDT.ts +27 -0
  49. package/dist/chunks/chunk-HOP5FXDT.ts.map +7 -0
  50. package/dist/chunks/chunk-I2FAK44T.ts +324 -0
  51. package/dist/chunks/chunk-I2FAK44T.ts.map +7 -0
  52. package/dist/chunks/chunk-IGAMVWFN.ts +139 -0
  53. package/dist/chunks/chunk-IGAMVWFN.ts.map +7 -0
  54. package/dist/chunks/chunk-KMGKCEO4.ts +38 -0
  55. package/dist/chunks/chunk-KMGKCEO4.ts.map +7 -0
  56. package/dist/chunks/chunk-N7BLVXKK.ts +73 -0
  57. package/dist/chunks/chunk-N7BLVXKK.ts.map +7 -0
  58. package/dist/chunks/chunk-NIF42QMF.ts +297 -0
  59. package/dist/chunks/chunk-NIF42QMF.ts.map +7 -0
  60. package/dist/chunks/chunk-O4VO6JUJ.ts +52 -0
  61. package/dist/chunks/chunk-O4VO6JUJ.ts.map +7 -0
  62. package/dist/chunks/chunk-ONDTY4EL.ts +91 -0
  63. package/dist/chunks/chunk-ONDTY4EL.ts.map +7 -0
  64. package/dist/chunks/chunk-OVPHFGKO.ts +1769 -0
  65. package/dist/chunks/chunk-OVPHFGKO.ts.map +7 -0
  66. package/dist/chunks/chunk-P7OH4XMF.ts +60 -0
  67. package/dist/chunks/chunk-P7OH4XMF.ts.map +7 -0
  68. package/dist/chunks/chunk-PSK43Y6A.ts +339 -0
  69. package/dist/chunks/chunk-PSK43Y6A.ts.map +7 -0
  70. package/dist/chunks/chunk-QBORTI4W.ts +468 -0
  71. package/dist/chunks/chunk-QBORTI4W.ts.map +7 -0
  72. package/dist/chunks/chunk-QDVGH2X7.ts +171 -0
  73. package/dist/chunks/chunk-QDVGH2X7.ts.map +7 -0
  74. package/dist/chunks/chunk-RHRQMT7Q.ts +490 -0
  75. package/dist/chunks/chunk-RHRQMT7Q.ts.map +7 -0
  76. package/dist/chunks/chunk-RRR66UWR.ts +28 -0
  77. package/dist/chunks/chunk-RRR66UWR.ts.map +7 -0
  78. package/dist/chunks/chunk-RSUXZD6S.ts +275 -0
  79. package/dist/chunks/chunk-RSUXZD6S.ts.map +7 -0
  80. package/dist/chunks/chunk-RTCVYIZA.ts +221 -0
  81. package/dist/chunks/chunk-RTCVYIZA.ts.map +7 -0
  82. package/dist/chunks/chunk-S2IWVK3J.ts +44 -0
  83. package/dist/chunks/chunk-S2IWVK3J.ts.map +7 -0
  84. package/dist/chunks/chunk-SCZ33MYW.ts +52 -0
  85. package/dist/chunks/chunk-SCZ33MYW.ts.map +7 -0
  86. package/dist/chunks/chunk-SWGQLFSD.ts +60 -0
  87. package/dist/chunks/chunk-SWGQLFSD.ts.map +7 -0
  88. package/dist/chunks/chunk-UMBPMVJW.ts +22 -0
  89. package/dist/chunks/chunk-UMBPMVJW.ts.map +7 -0
  90. package/dist/chunks/chunk-UVFVHIOP.ts +735 -0
  91. package/dist/chunks/chunk-UVFVHIOP.ts.map +7 -0
  92. package/dist/chunks/completion-delivery-YPOWSSV3.ts +16 -0
  93. package/dist/chunks/completion-delivery-YPOWSSV3.ts.map +7 -0
  94. package/dist/chunks/config-status-J4GPWP46.ts +34 -0
  95. package/dist/chunks/config-status-J4GPWP46.ts.map +7 -0
  96. package/dist/chunks/config-ui-3IBMHTQB.ts +1146 -0
  97. package/dist/chunks/config-ui-3IBMHTQB.ts.map +7 -0
  98. package/dist/chunks/consult-NYXVDN5G.ts +518 -0
  99. package/dist/chunks/consult-NYXVDN5G.ts.map +7 -0
  100. package/dist/chunks/context-QDKLVQXE.ts +11 -0
  101. package/dist/chunks/context-QDKLVQXE.ts.map +7 -0
  102. package/dist/chunks/create-stateful-transport-4WKZHRSI.ts +130 -0
  103. package/dist/chunks/create-stateful-transport-4WKZHRSI.ts.map +7 -0
  104. package/dist/chunks/cwd-policy-NB6XZ5GF.ts +17 -0
  105. package/dist/chunks/cwd-policy-NB6XZ5GF.ts.map +7 -0
  106. package/dist/chunks/delegation-contract-WJPT4FVS.ts +24 -0
  107. package/dist/chunks/delegation-contract-WJPT4FVS.ts.map +7 -0
  108. package/dist/chunks/discovery-K25T3SH4.ts +12 -0
  109. package/dist/chunks/discovery-K25T3SH4.ts.map +7 -0
  110. package/dist/chunks/execution-DS2DEIQZ.ts +4034 -0
  111. package/dist/chunks/execution-DS2DEIQZ.ts.map +7 -0
  112. package/dist/chunks/in-process-transport-TEYAWSEC.ts +38 -0
  113. package/dist/chunks/in-process-transport-TEYAWSEC.ts.map +7 -0
  114. package/dist/chunks/inspect-UOQQ3KNL.ts +619 -0
  115. package/dist/chunks/inspect-UOQQ3KNL.ts.map +7 -0
  116. package/dist/chunks/peer-communication-KL36Z6CO.ts +294 -0
  117. package/dist/chunks/peer-communication-KL36Z6CO.ts.map +7 -0
  118. package/dist/chunks/persistence-VSGXAW4P.ts +344 -0
  119. package/dist/chunks/persistence-VSGXAW4P.ts.map +7 -0
  120. package/dist/chunks/registry-E6XPJB7L.ts +1324 -0
  121. package/dist/chunks/registry-E6XPJB7L.ts.map +7 -0
  122. package/dist/chunks/retained-semantic-state-7WXSGRJU.ts +81 -0
  123. package/dist/chunks/retained-semantic-state-7WXSGRJU.ts.map +7 -0
  124. package/dist/chunks/rpc-transport-Y6LA5BOP.ts +1154 -0
  125. package/dist/chunks/rpc-transport-Y6LA5BOP.ts.map +7 -0
  126. package/dist/chunks/runtime-policy-5YELCOVC.ts +15 -0
  127. package/dist/chunks/runtime-policy-5YELCOVC.ts.map +7 -0
  128. package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts +19 -0
  129. package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts.map +7 -0
  130. package/dist/chunks/spawn-idempotency-QGHO2WKC.ts +13 -0
  131. package/dist/chunks/spawn-idempotency-QGHO2WKC.ts.map +7 -0
  132. package/dist/chunks/stateful-lifecycle-JAR6K55H.ts +15 -0
  133. package/dist/chunks/stateful-lifecycle-JAR6K55H.ts.map +7 -0
  134. package/dist/chunks/subprocess-transport-C2XVR25R.ts +158 -0
  135. package/dist/chunks/subprocess-transport-C2XVR25R.ts.map +7 -0
  136. package/dist/chunks/workspace-WDKLN72J.ts +11 -0
  137. package/dist/chunks/workspace-WDKLN72J.ts.map +7 -0
  138. package/dist/index.ts +1057 -0
  139. package/dist/index.ts.map +7 -0
  140. package/package.json +8 -4
  141. package/src/index.ts +1 -1
  142. package/src/settings-reader.ts +208 -0
  143. package/src/settings.ts +22 -187
  144. package/src/stateful-registration.ts +1230 -0
  145. package/src/stateful-safety.ts +1 -1
  146. package/src/stateful.ts +2 -1234
  147. package/src/subagents-extension.ts +307 -0
  148. package/src/subagents.ts +1 -308
@@ -0,0 +1,344 @@
1
+ // @generated by scripts/build-runtime.mjs; do not edit.
2
+ // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
+ import {
4
+ isSemanticSnapshot
5
+ } from "./chunk-BOAXY55Y.js";
6
+ import {
7
+ isCapabilityGrant,
8
+ revokeCapabilityGrant
9
+ } from "./chunk-HKC4ES4B.js";
10
+ import {
11
+ copyExecutionPlan,
12
+ isExecutionPlan
13
+ } from "./chunk-DSOOH73Y.js";
14
+ import {
15
+ validateTaskName,
16
+ validateTaskPath
17
+ } from "./chunk-N7BLVXKK.js";
18
+ import {
19
+ copyTurnTerminationReport
20
+ } from "./chunk-RTCVYIZA.js";
21
+ import {
22
+ MAX_SUBAGENT_TOOL_CALLS,
23
+ MAX_SUBAGENT_TURNS
24
+ } from "./chunk-ONDTY4EL.js";
25
+ import {
26
+ SUBAGENT_RESULT_FORMATS,
27
+ parseAnyStructuredSubagentResult
28
+ } from "./chunk-RSUXZD6S.js";
29
+ import {
30
+ projectAgentRecords
31
+ } from "./chunk-KMGKCEO4.js";
32
+ import {
33
+ resolveStatefulLimits
34
+ } from "./chunk-7OBINKFM.js";
35
+ import {
36
+ isThinkingLevel
37
+ } from "./chunk-DPPVEQAM.js";
38
+ import {
39
+ normalizeDelegationContract
40
+ } from "./chunk-I2FAK44T.js";
41
+ import {
42
+ MAX_SUBAGENT_TIMEOUT_MS,
43
+ redactPrivateText
44
+ } from "./chunk-H3FP6DLR.js";
45
+
46
+ // src/persistence.ts
47
+ import { createHash } from "node:crypto";
48
+ import * as fs from "node:fs";
49
+ import * as path from "node:path";
50
+ import { getAgentDir, withFileMutationQueue } from "@earendil-works/pi-coding-agent";
51
+ var STATE_VERSION = 3;
52
+ var MAX_STORED_COMPLETIONS_PER_AGENT = 20;
53
+ var DEFAULT_STATEFUL_LIMITS = resolveStatefulLimits();
54
+ var MAX_STATE_BYTES = 5 * 1024 * 1024;
55
+ var AgentPersistence = class {
56
+ filePath;
57
+ retentionMs;
58
+ maxStoredAgents;
59
+ constructor(owner, options = {}) {
60
+ const retentionDays = options.retentionDays ?? 30;
61
+ if (!Number.isFinite(retentionDays) || retentionDays <= 0) {
62
+ throw new Error("Subagent retentionDays must be a positive finite number");
63
+ }
64
+ const retentionMs = retentionDays * 24 * 60 * 60 * 1e3;
65
+ if (!Number.isFinite(retentionMs)) {
66
+ throw new Error("Subagent retentionDays is too large");
67
+ }
68
+ const maxStoredAgents = options.maxStoredAgents ?? DEFAULT_STATEFUL_LIMITS.maxStoredAgents;
69
+ if (!Number.isSafeInteger(maxStoredAgents) || maxStoredAgents < 1) {
70
+ throw new Error("Subagent maxStoredAgents must be a positive safe integer");
71
+ }
72
+ const safeOwner = createHash("sha256").update(owner).digest("hex").slice(0, 24);
73
+ const stateDir = options.stateDir ?? path.join(getAgentDir(), "pi-subagents-state");
74
+ this.filePath = path.join(stateDir, `${safeOwner}.json`);
75
+ this.retentionMs = retentionMs;
76
+ this.maxStoredAgents = maxStoredAgents;
77
+ }
78
+ load() {
79
+ if (!fs.existsSync(this.filePath)) return [];
80
+ try {
81
+ const stat = fs.statSync(this.filePath);
82
+ if (stat.size > MAX_STATE_BYTES) throw new Error("state exceeds size limit");
83
+ const parsed = JSON.parse(fs.readFileSync(this.filePath, "utf8"));
84
+ if (!isStoredState(parsed)) throw new Error("unsupported or malformed state");
85
+ const cutoff = Date.now() - this.retentionMs;
86
+ return projectAgentRecords(
87
+ parsed.agents.filter((agent) => agent.updatedAt >= cutoff && agent.state !== "closed"),
88
+ { maxAgents: this.maxStoredAgents }
89
+ ).map(sanitizeAgent);
90
+ } catch {
91
+ this.quarantine();
92
+ return [];
93
+ }
94
+ }
95
+ async save(agents) {
96
+ const cutoff = Date.now() - this.retentionMs;
97
+ const eligible = agents.filter(
98
+ (agent) => agent.state !== "closed" && agent.updatedAt >= cutoff
99
+ );
100
+ const records = projectAgentRecords(eligible, {
101
+ maxAgents: this.maxStoredAgents
102
+ }).map(sanitizeAgent);
103
+ const state = { version: STATE_VERSION, updatedAt: Date.now(), agents: records };
104
+ let content = `${JSON.stringify(state, null, " ")}
105
+ `;
106
+ while (Buffer.byteLength(content, "utf8") > MAX_STATE_BYTES && state.agents.length > 0) {
107
+ const rootsWithPendingCompletions = new Set(
108
+ state.agents.filter((agent) => (agent.pendingCompletions?.length ?? 0) > 0).map((agent) => agent.rootId)
109
+ );
110
+ const droppableRoot = state.agents.find(
111
+ (agent) => !rootsWithPendingCompletions.has(agent.rootId)
112
+ )?.rootId;
113
+ if (droppableRoot) {
114
+ state.agents = state.agents.filter((agent) => agent.rootId !== droppableRoot);
115
+ } else if (!trimOldestHistory(state.agents) && !clearOldestContext(state.agents)) {
116
+ throw new Error("Subagent state exceeds its durable completion storage limit");
117
+ }
118
+ content = `${JSON.stringify(state, null, " ")}
119
+ `;
120
+ }
121
+ await fs.promises.mkdir(path.dirname(this.filePath), { recursive: true });
122
+ await withFileMutationQueue(this.filePath, async () => {
123
+ const tempPath = `${this.filePath}.${process.pid}.${Date.now()}.tmp`;
124
+ await fs.promises.writeFile(tempPath, content, { encoding: "utf8", mode: 384 });
125
+ await fs.promises.rename(tempPath, this.filePath);
126
+ });
127
+ }
128
+ async delete() {
129
+ await withFileMutationQueue(this.filePath, async () => {
130
+ await fs.promises.rm(this.filePath, { force: true });
131
+ });
132
+ }
133
+ quarantine() {
134
+ try {
135
+ fs.renameSync(this.filePath, `${this.filePath}.invalid-${Date.now()}`);
136
+ } catch {
137
+ }
138
+ }
139
+ };
140
+ function trimOldestHistory(agents) {
141
+ const candidate = agents.filter((agent) => agent.history.length > 0).sort(
142
+ (left, right) => (left.history[0]?.completedAt ?? Number.POSITIVE_INFINITY) - (right.history[0]?.completedAt ?? Number.POSITIVE_INFINITY)
143
+ )[0];
144
+ if (!candidate) return false;
145
+ candidate.history.shift();
146
+ return true;
147
+ }
148
+ function clearOldestContext(agents) {
149
+ const candidate = agents.find((agent) => agent.context !== void 0);
150
+ if (!candidate) return false;
151
+ candidate.context = void 0;
152
+ candidate.contextTruncated = true;
153
+ return true;
154
+ }
155
+ function sanitizeAgent(agent) {
156
+ return {
157
+ ...agent,
158
+ rootId: agent.rootId ?? agent.id,
159
+ depth: agent.depth ?? 0,
160
+ children: [...agent.children ?? []],
161
+ mailbox: (agent.mailbox ?? []).map((message) => ({
162
+ ...message,
163
+ recipientId: agent.id,
164
+ content: redactPrivateText(message.content)
165
+ })),
166
+ state: agent.state === "running" || agent.state === "starting" ? "interrupted" : agent.state,
167
+ currentTask: void 0,
168
+ currentRunId: void 0,
169
+ currentTurnGeneration: void 0,
170
+ turnGeneration: agent.turnGeneration ?? 0,
171
+ pendingCompletions: (agent.pendingCompletions ?? []).slice(-MAX_STORED_COMPLETIONS_PER_AGENT).map((completion) => ({
172
+ ...completion,
173
+ task: redactPrivateText(completion.task),
174
+ output: redactPrivateText(completion.output),
175
+ error: completion.error ? redactPrivateText(completion.error) : void 0
176
+ })),
177
+ currentTimeoutMs: void 0,
178
+ currentIdleTimeoutMs: void 0,
179
+ currentMaxTurns: void 0,
180
+ currentMaxToolCalls: void 0,
181
+ currentMailboxMessageIds: void 0,
182
+ telemetry: void 0,
183
+ contract: normalizeDelegationContract(agent.contract),
184
+ structuredResult: agent.structuredResult && agent.resultFormat ? parseAnyStructuredSubagentResult(
185
+ JSON.stringify(agent.structuredResult),
186
+ agent.resultFormat
187
+ ) : void 0,
188
+ executionPlan: agent.executionPlan ? copyExecutionPlan(agent.executionPlan) : void 0,
189
+ capabilityGrant: agent.capabilityGrant ? agent.capabilityGrant.state === "active" ? revokeCapabilityGrant(agent.capabilityGrant, "persistence-boundary", Date.now()) : structuredClone(agent.capabilityGrant) : void 0,
190
+ semanticSnapshot: agent.semanticSnapshot ? structuredClone(agent.semanticSnapshot) : void 0,
191
+ semanticCompatibility: agent.semanticCompatibility ? structuredClone(agent.semanticCompatibility) : void 0,
192
+ termination: agent.termination ? sanitizeTermination(agent.termination) : void 0,
193
+ context: agent.context ? redactPrivateText(agent.context) : void 0,
194
+ error: agent.error ? redactPrivateText(agent.error) : void 0,
195
+ history: agent.history.map((turn) => ({
196
+ ...turn,
197
+ task: redactPrivateText(turn.task),
198
+ output: redactPrivateText(turn.output),
199
+ termination: turn.termination ? sanitizeTermination(turn.termination) : void 0
200
+ }))
201
+ };
202
+ }
203
+ function sanitizeTermination(report) {
204
+ const copy = copyTurnTerminationReport(report);
205
+ copy.checkpoint.task = redactPrivateText(copy.checkpoint.task);
206
+ copy.checkpoint.partialOutput = copy.checkpoint.partialOutput ? redactPrivateText(copy.checkpoint.partialOutput) : void 0;
207
+ copy.checkpoint.assistantNotes = copy.checkpoint.assistantNotes.map(redactPrivateText);
208
+ copy.checkpoint.completedTools = copy.checkpoint.completedTools.map((item) => ({
209
+ ...item,
210
+ toolName: redactPrivateText(item.toolName),
211
+ output: redactPrivateText(item.output)
212
+ }));
213
+ copy.checkpoint.changedFiles = copy.checkpoint.changedFiles.map(redactPrivateText);
214
+ copy.finalization.error = copy.finalization.error ? redactPrivateText(copy.finalization.error) : void 0;
215
+ return copy;
216
+ }
217
+ function isStoredState(value) {
218
+ if (!value || typeof value !== "object") return false;
219
+ const state = value;
220
+ if (state.version !== 1 && state.version !== 2 && state.version !== STATE_VERSION || !Array.isArray(state.agents)) {
221
+ return false;
222
+ }
223
+ return state.agents.every((agent) => {
224
+ if (!agent || typeof agent !== "object") return false;
225
+ const record = agent;
226
+ return typeof record.id === "string" && (record.taskName === void 0 || isValidTaskName(record.taskName)) && (record.taskPath === void 0 || isValidTaskPath(record.taskPath)) && typeof record.agent === "string" && typeof record.cwd === "string" && typeof record.createdAt === "number" && Number.isFinite(record.createdAt) && typeof record.updatedAt === "number" && Number.isFinite(record.updatedAt) && (record.parentId === void 0 || typeof record.parentId === "string") && (record.thinkingLevel === void 0 || isThinkingLevel(record.thinkingLevel)) && (record.timeoutMs === void 0 || isTurnTimeout(record.timeoutMs)) && (record.idleTimeoutMs === void 0 || isTurnTimeout(record.idleTimeoutMs)) && (record.maxTurns === void 0 || isPositiveBounded(record.maxTurns, MAX_SUBAGENT_TURNS)) && (record.maxToolCalls === void 0 || isPositiveBounded(record.maxToolCalls, MAX_SUBAGENT_TOOL_CALLS)) && (record.termination === void 0 || isTerminationReport(record.termination)) && (record.contextTurns === void 0 || isNonNegativeInteger(record.contextTurns)) && (record.contextBytes === void 0 || isNonNegativeInteger(record.contextBytes)) && (record.turnGeneration === void 0 || isNonNegativeInteger(record.turnGeneration)) && (record.pendingCompletions === void 0 || isCompletionOutbox(record.pendingCompletions, record.turnGeneration ?? 0)) && (record.spawnIdempotencyKey === void 0 || typeof record.spawnIdempotencyKey === "string" && record.spawnIdempotencyKey.length > 0 && record.spawnIdempotencyKey.length <= 256) && (record.spawnRequestHash === void 0 || isSha256(record.spawnRequestHash)) && (record.contract === void 0 || normalizeDelegationContract(record.contract) !== void 0) && (record.resultFormat === void 0 || SUBAGENT_RESULT_FORMATS.includes(record.resultFormat)) && (record.structuredResult === void 0 || record.resultFormat !== void 0 && parseAnyStructuredSubagentResult(
227
+ JSON.stringify(record.structuredResult),
228
+ record.resultFormat
229
+ ) !== void 0) && (record.executionPlan === void 0 || isExecutionPlan(record.executionPlan)) && (record.capabilityGrant === void 0 || isCapabilityGrant(record.capabilityGrant)) && (record.semanticSnapshot === void 0 || isSemanticSnapshot(record.semanticSnapshot)) && (record.semanticCompatibility === void 0 || isSemanticCompatibility(record.semanticCompatibility)) && (record.workspaceMode === void 0 || record.workspaceMode === "worktree") && (record.target === void 0 || isTargetPolicyAudit(record.target)) && (record.children === void 0 || Array.isArray(record.children) && record.children.every((id) => typeof id === "string")) && Array.isArray(record.history) && record.history.every(isAgentTurn) && (record.mailbox === void 0 || Array.isArray(record.mailbox) && record.mailbox.every(isMailboxMessage));
230
+ });
231
+ }
232
+ function isValidTaskName(value) {
233
+ if (typeof value !== "string") return false;
234
+ try {
235
+ return validateTaskName(value) === value;
236
+ } catch {
237
+ return false;
238
+ }
239
+ }
240
+ function isValidTaskPath(value) {
241
+ if (typeof value !== "string") return false;
242
+ try {
243
+ return validateTaskPath(value) === value;
244
+ } catch {
245
+ return false;
246
+ }
247
+ }
248
+ function isSemanticCompatibility(value) {
249
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
250
+ const compatibility = value;
251
+ return ["compatible", "warning", "needs-revalidation", "rejected"].includes(
252
+ String(compatibility.status)
253
+ ) && Array.isArray(compatibility.changedComponents) && compatibility.changedComponents.every((item) => typeof item === "string");
254
+ }
255
+ function isNonNegativeInteger(value) {
256
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
257
+ }
258
+ function isTurnTimeout(value) {
259
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 1 && value <= MAX_SUBAGENT_TIMEOUT_MS;
260
+ }
261
+ function isPositiveBounded(value, maximum) {
262
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 1 && value <= maximum;
263
+ }
264
+ function isTerminationReport(value) {
265
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
266
+ const report = value;
267
+ if (report.version !== "pi-subagents:termination:v1" || ![
268
+ "work_timeout",
269
+ "idle_timeout",
270
+ "turn_limit",
271
+ "tool_call_limit",
272
+ "orchestration_timeout"
273
+ ].includes(String(report.reason)) || !isPositiveBounded(report.limit, MAX_SUBAGENT_TIMEOUT_MS)) {
274
+ return false;
275
+ }
276
+ const checkpoint = report.checkpoint;
277
+ const finalization = report.finalization;
278
+ if (!checkpoint || typeof checkpoint !== "object" || Array.isArray(checkpoint)) return false;
279
+ if (!finalization || typeof finalization !== "object" || Array.isArray(finalization))
280
+ return false;
281
+ const checkpointValue = checkpoint;
282
+ const finalizationValue = finalization;
283
+ return checkpointValue.version === "pi-subagents:checkpoint:v1" && typeof checkpointValue.task === "string" && (checkpointValue.partialOutput === void 0 || typeof checkpointValue.partialOutput === "string") && Array.isArray(checkpointValue.assistantNotes) && checkpointValue.assistantNotes.every((item) => typeof item === "string") && Array.isArray(checkpointValue.completedTools) && checkpointValue.completedTools.every(isCompletedToolEvidence) && Array.isArray(checkpointValue.changedFiles) && checkpointValue.changedFiles.every((item) => typeof item === "string") && typeof checkpointValue.sideEffectsMayHaveOccurred === "boolean" && typeof checkpointValue.truncated === "boolean" && typeof finalizationValue.attempted === "boolean" && ["completed", "failed", "timed_out", "skipped"].includes(String(finalizationValue.status)) && typeof finalizationValue.durationMs === "number" && Number.isFinite(finalizationValue.durationMs) && finalizationValue.durationMs >= 0 && (finalizationValue.error === void 0 || typeof finalizationValue.error === "string");
284
+ }
285
+ function isCompletedToolEvidence(value) {
286
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
287
+ const item = value;
288
+ return typeof item.toolName === "string" && typeof item.output === "string" && typeof item.isError === "boolean";
289
+ }
290
+ function isSha256(value) {
291
+ return typeof value === "string" && /^[a-f0-9]{64}$/u.test(value);
292
+ }
293
+ function isTargetPolicyAudit(value) {
294
+ if (!value || typeof value !== "object") return false;
295
+ const target = value;
296
+ if (typeof target.cwd !== "string" || target.boundary !== "current-workspace" && target.boundary !== "external" || !target.trust || typeof target.trust !== "object") {
297
+ return false;
298
+ }
299
+ const trust = target.trust;
300
+ return [
301
+ "session-trusted",
302
+ "session-untrusted",
303
+ "saved-trusted",
304
+ "saved-denied",
305
+ "unsaved",
306
+ "trust-error"
307
+ ].includes(String(trust.kind)) && typeof trust.projectTrusted === "boolean" && (trust.sourcePath === void 0 || typeof trust.sourcePath === "string") && (trust.warning === void 0 || typeof trust.warning === "string");
308
+ }
309
+ function isCompletionOutbox(value, turnGeneration) {
310
+ if (!Array.isArray(value) || value.length > MAX_STORED_COMPLETIONS_PER_AGENT) return false;
311
+ const ids = /* @__PURE__ */ new Set();
312
+ let previousGeneration = 0;
313
+ let previousCreatedAt = Number.NEGATIVE_INFINITY;
314
+ for (const completion of value) {
315
+ if (!isPersistedCompletion(completion, turnGeneration)) return false;
316
+ if (ids.has(completion.completionId)) return false;
317
+ if (completion.generation <= previousGeneration || completion.createdAt <= previousCreatedAt) {
318
+ return false;
319
+ }
320
+ ids.add(completion.completionId);
321
+ previousGeneration = completion.generation;
322
+ previousCreatedAt = completion.createdAt;
323
+ }
324
+ return true;
325
+ }
326
+ function isPersistedCompletion(value, turnGeneration) {
327
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
328
+ const completion = value;
329
+ return typeof completion.completionId === "string" && completion.completionId.length > 0 && completion.completionId.length <= 256 && (completion.recipientId === void 0 || typeof completion.recipientId === "string" && completion.recipientId.length > 0) && (completion.recipientPath === void 0 || isValidTaskPath(completion.recipientPath)) && typeof completion.runId === "string" && completion.runId.length > 0 && completion.runId.length <= 256 && typeof completion.generation === "number" && Number.isSafeInteger(completion.generation) && completion.generation >= 1 && completion.generation <= turnGeneration && typeof completion.task === "string" && typeof completion.output === "string" && (completion.error === void 0 || typeof completion.error === "string") && typeof completion.createdAt === "number" && Number.isFinite(completion.createdAt);
330
+ }
331
+ function isAgentTurn(value) {
332
+ if (!value || typeof value !== "object") return false;
333
+ const turn = value;
334
+ return (turn.runId === void 0 || typeof turn.runId === "string" && turn.runId.length > 0 && turn.runId.length <= 256) && (turn.generation === void 0 || typeof turn.generation === "number" && Number.isSafeInteger(turn.generation) && turn.generation >= 1) && typeof turn.task === "string" && typeof turn.output === "string" && typeof turn.startedAt === "number" && Number.isFinite(turn.startedAt) && typeof turn.completedAt === "number" && Number.isFinite(turn.completedAt) && typeof turn.exitCode === "number" && Number.isFinite(turn.exitCode) && (turn.termination === void 0 || isTerminationReport(turn.termination));
335
+ }
336
+ function isMailboxMessage(value) {
337
+ if (!value || typeof value !== "object") return false;
338
+ const message = value;
339
+ return typeof message.id === "string" && typeof message.senderId === "string" && typeof message.recipientId === "string" && typeof message.content === "string" && typeof message.createdAt === "number" && Number.isFinite(message.createdAt) && (message.readAt === void 0 || typeof message.readAt === "number" && Number.isFinite(message.readAt)) && (message.deduplicationKey === void 0 || typeof message.deduplicationKey === "string") && (message.completionId === void 0 || typeof message.completionId === "string");
340
+ }
341
+ export {
342
+ AgentPersistence
343
+ };
344
+ //# sourceMappingURL=persistence-VSGXAW4P.ts.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/persistence.ts"],
4
+ "sourcesContent": ["import { createHash } from \"node:crypto\";\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { getAgentDir, withFileMutationQueue } from \"@earendil-works/pi-coding-agent\";\nimport { projectAgentRecords } from \"./agent-projection.js\";\nimport { isThinkingLevel } from \"./agents/types.js\";\nimport { isCapabilityGrant, revokeCapabilityGrant } from \"./capability-grant.js\";\nimport { redactPrivateText } from \"./context.js\";\nimport { normalizeDelegationContract } from \"./delegation-contract.js\";\nimport { copyExecutionPlan, isExecutionPlan } from \"./execution-plan.js\";\nimport { MAX_SUBAGENT_TIMEOUT_MS } from \"./limits.js\";\nimport type { ManagedAgent } from \"./registry.js\";\nimport { parseAnyStructuredSubagentResult, SUBAGENT_RESULT_FORMATS } from \"./result-contract.js\";\nimport { isSemanticSnapshot } from \"./semantic-snapshot.js\";\nimport { resolveStatefulLimits } from \"./stateful-limits.js\";\nimport { validateTaskName, validateTaskPath } from \"./task-path.js\";\nimport { copyTurnTerminationReport, type TurnTerminationReport } from \"./timeout-checkpoint.js\";\nimport { MAX_SUBAGENT_TOOL_CALLS, MAX_SUBAGENT_TURNS } from \"./turn-budget.js\";\n\nconst STATE_VERSION = 3;\nconst MAX_STORED_COMPLETIONS_PER_AGENT = 20;\nconst DEFAULT_STATEFUL_LIMITS = resolveStatefulLimits();\nconst MAX_STATE_BYTES = 5 * 1024 * 1024;\n\ninterface StoredState {\n\tversion: 3;\n\tupdatedAt: number;\n\tagents: ManagedAgent[];\n}\n\nexport interface PersistenceOptions {\n\tretentionDays?: number;\n\tmaxStoredAgents?: number;\n\tstateDir?: string;\n}\n\nexport class AgentPersistence {\n\treadonly filePath: string;\n\tprivate readonly retentionMs: number;\n\tprivate readonly maxStoredAgents: number;\n\n\tconstructor(owner: string, options: PersistenceOptions = {}) {\n\t\tconst retentionDays = options.retentionDays ?? 30;\n\t\tif (!Number.isFinite(retentionDays) || retentionDays <= 0) {\n\t\t\tthrow new Error(\"Subagent retentionDays must be a positive finite number\");\n\t\t}\n\t\tconst retentionMs = retentionDays * 24 * 60 * 60 * 1000;\n\t\tif (!Number.isFinite(retentionMs)) {\n\t\t\tthrow new Error(\"Subagent retentionDays is too large\");\n\t\t}\n\t\tconst maxStoredAgents = options.maxStoredAgents ?? DEFAULT_STATEFUL_LIMITS.maxStoredAgents;\n\t\tif (!Number.isSafeInteger(maxStoredAgents) || maxStoredAgents < 1) {\n\t\t\tthrow new Error(\"Subagent maxStoredAgents must be a positive safe integer\");\n\t\t}\n\t\tconst safeOwner = createHash(\"sha256\").update(owner).digest(\"hex\").slice(0, 24);\n\t\tconst stateDir = options.stateDir ?? path.join(getAgentDir(), \"pi-subagents-state\");\n\t\tthis.filePath = path.join(stateDir, `${safeOwner}.json`);\n\t\tthis.retentionMs = retentionMs;\n\t\tthis.maxStoredAgents = maxStoredAgents;\n\t}\n\n\tload(): ManagedAgent[] {\n\t\tif (!fs.existsSync(this.filePath)) return [];\n\t\ttry {\n\t\t\tconst stat = fs.statSync(this.filePath);\n\t\t\tif (stat.size > MAX_STATE_BYTES) throw new Error(\"state exceeds size limit\");\n\t\t\tconst parsed = JSON.parse(fs.readFileSync(this.filePath, \"utf8\")) as unknown;\n\t\t\tif (!isStoredState(parsed)) throw new Error(\"unsupported or malformed state\");\n\t\t\tconst cutoff = Date.now() - this.retentionMs;\n\t\t\treturn projectAgentRecords(\n\t\t\t\tparsed.agents.filter((agent) => agent.updatedAt >= cutoff && agent.state !== \"closed\"),\n\t\t\t\t{ maxAgents: this.maxStoredAgents },\n\t\t\t).map(sanitizeAgent);\n\t\t} catch {\n\t\t\tthis.quarantine();\n\t\t\treturn [];\n\t\t}\n\t}\n\n\tasync save(agents: readonly ManagedAgent[]): Promise<void> {\n\t\tconst cutoff = Date.now() - this.retentionMs;\n\t\tconst eligible = agents.filter(\n\t\t\t(agent) => agent.state !== \"closed\" && agent.updatedAt >= cutoff,\n\t\t);\n\t\tconst records = projectAgentRecords(eligible, {\n\t\t\tmaxAgents: this.maxStoredAgents,\n\t\t}).map(sanitizeAgent);\n\t\tconst state: StoredState = { version: STATE_VERSION, updatedAt: Date.now(), agents: records };\n\t\tlet content = `${JSON.stringify(state, null, \"\\t\")}\\n`;\n\t\twhile (Buffer.byteLength(content, \"utf8\") > MAX_STATE_BYTES && state.agents.length > 0) {\n\t\t\tconst rootsWithPendingCompletions = new Set(\n\t\t\t\tstate.agents\n\t\t\t\t\t.filter((agent) => (agent.pendingCompletions?.length ?? 0) > 0)\n\t\t\t\t\t.map((agent) => agent.rootId),\n\t\t\t);\n\t\t\tconst droppableRoot = state.agents.find(\n\t\t\t\t(agent) => !rootsWithPendingCompletions.has(agent.rootId),\n\t\t\t)?.rootId;\n\t\t\tif (droppableRoot) {\n\t\t\t\tstate.agents = state.agents.filter((agent) => agent.rootId !== droppableRoot);\n\t\t\t} else if (!trimOldestHistory(state.agents) && !clearOldestContext(state.agents)) {\n\t\t\t\tthrow new Error(\"Subagent state exceeds its durable completion storage limit\");\n\t\t\t}\n\t\t\tcontent = `${JSON.stringify(state, null, \"\\t\")}\\n`;\n\t\t}\n\t\tawait fs.promises.mkdir(path.dirname(this.filePath), { recursive: true });\n\t\tawait withFileMutationQueue(this.filePath, async () => {\n\t\t\tconst tempPath = `${this.filePath}.${process.pid}.${Date.now()}.tmp`;\n\t\t\tawait fs.promises.writeFile(tempPath, content, { encoding: \"utf8\", mode: 0o600 });\n\t\t\tawait fs.promises.rename(tempPath, this.filePath);\n\t\t});\n\t}\n\n\tasync delete(): Promise<void> {\n\t\tawait withFileMutationQueue(this.filePath, async () => {\n\t\t\tawait fs.promises.rm(this.filePath, { force: true });\n\t\t});\n\t}\n\n\tprivate quarantine(): void {\n\t\ttry {\n\t\t\tfs.renameSync(this.filePath, `${this.filePath}.invalid-${Date.now()}`);\n\t\t} catch {\n\t\t\t// A concurrent process may already have moved or removed it.\n\t\t}\n\t}\n}\n\nfunction trimOldestHistory(agents: ManagedAgent[]): boolean {\n\tconst candidate = agents\n\t\t.filter((agent) => agent.history.length > 0)\n\t\t.sort(\n\t\t\t(left, right) =>\n\t\t\t\t(left.history[0]?.completedAt ?? Number.POSITIVE_INFINITY) -\n\t\t\t\t(right.history[0]?.completedAt ?? Number.POSITIVE_INFINITY),\n\t\t)[0];\n\tif (!candidate) return false;\n\tcandidate.history.shift();\n\treturn true;\n}\n\nfunction clearOldestContext(agents: ManagedAgent[]): boolean {\n\tconst candidate = agents.find((agent) => agent.context !== undefined);\n\tif (!candidate) return false;\n\tcandidate.context = undefined;\n\tcandidate.contextTruncated = true;\n\treturn true;\n}\n\nfunction sanitizeAgent(agent: ManagedAgent): ManagedAgent {\n\treturn {\n\t\t...agent,\n\t\trootId: agent.rootId ?? agent.id,\n\t\tdepth: agent.depth ?? 0,\n\t\tchildren: [...(agent.children ?? [])],\n\t\tmailbox: (agent.mailbox ?? []).map((message) => ({\n\t\t\t...message,\n\t\t\trecipientId: agent.id,\n\t\t\tcontent: redactPrivateText(message.content),\n\t\t})),\n\t\tstate: agent.state === \"running\" || agent.state === \"starting\" ? \"interrupted\" : agent.state,\n\t\tcurrentTask: undefined,\n\t\tcurrentRunId: undefined,\n\t\tcurrentTurnGeneration: undefined,\n\t\tturnGeneration: agent.turnGeneration ?? 0,\n\t\tpendingCompletions: (agent.pendingCompletions ?? [])\n\t\t\t.slice(-MAX_STORED_COMPLETIONS_PER_AGENT)\n\t\t\t.map((completion) => ({\n\t\t\t\t...completion,\n\t\t\t\ttask: redactPrivateText(completion.task),\n\t\t\t\toutput: redactPrivateText(completion.output),\n\t\t\t\terror: completion.error ? redactPrivateText(completion.error) : undefined,\n\t\t\t})),\n\t\tcurrentTimeoutMs: undefined,\n\t\tcurrentIdleTimeoutMs: undefined,\n\t\tcurrentMaxTurns: undefined,\n\t\tcurrentMaxToolCalls: undefined,\n\t\tcurrentMailboxMessageIds: undefined,\n\t\ttelemetry: undefined,\n\t\tcontract: normalizeDelegationContract(agent.contract),\n\t\tstructuredResult:\n\t\t\tagent.structuredResult && agent.resultFormat\n\t\t\t\t? parseAnyStructuredSubagentResult(\n\t\t\t\t\t\tJSON.stringify(agent.structuredResult),\n\t\t\t\t\t\tagent.resultFormat,\n\t\t\t\t\t)\n\t\t\t\t: undefined,\n\t\texecutionPlan: agent.executionPlan ? copyExecutionPlan(agent.executionPlan) : undefined,\n\t\tcapabilityGrant: agent.capabilityGrant\n\t\t\t? agent.capabilityGrant.state === \"active\"\n\t\t\t\t? revokeCapabilityGrant(agent.capabilityGrant, \"persistence-boundary\", Date.now())\n\t\t\t\t: structuredClone(agent.capabilityGrant)\n\t\t\t: undefined,\n\t\tsemanticSnapshot: agent.semanticSnapshot ? structuredClone(agent.semanticSnapshot) : undefined,\n\t\tsemanticCompatibility: agent.semanticCompatibility\n\t\t\t? structuredClone(agent.semanticCompatibility)\n\t\t\t: undefined,\n\t\ttermination: agent.termination ? sanitizeTermination(agent.termination) : undefined,\n\t\tcontext: agent.context ? redactPrivateText(agent.context) : undefined,\n\t\terror: agent.error ? redactPrivateText(agent.error) : undefined,\n\t\thistory: agent.history.map((turn) => ({\n\t\t\t...turn,\n\t\t\ttask: redactPrivateText(turn.task),\n\t\t\toutput: redactPrivateText(turn.output),\n\t\t\ttermination: turn.termination ? sanitizeTermination(turn.termination) : undefined,\n\t\t})),\n\t};\n}\n\nfunction sanitizeTermination(report: TurnTerminationReport): TurnTerminationReport {\n\tconst copy = copyTurnTerminationReport(report);\n\tcopy.checkpoint.task = redactPrivateText(copy.checkpoint.task);\n\tcopy.checkpoint.partialOutput = copy.checkpoint.partialOutput\n\t\t? redactPrivateText(copy.checkpoint.partialOutput)\n\t\t: undefined;\n\tcopy.checkpoint.assistantNotes = copy.checkpoint.assistantNotes.map(redactPrivateText);\n\tcopy.checkpoint.completedTools = copy.checkpoint.completedTools.map((item) => ({\n\t\t...item,\n\t\ttoolName: redactPrivateText(item.toolName),\n\t\toutput: redactPrivateText(item.output),\n\t}));\n\tcopy.checkpoint.changedFiles = copy.checkpoint.changedFiles.map(redactPrivateText);\n\tcopy.finalization.error = copy.finalization.error\n\t\t? redactPrivateText(copy.finalization.error)\n\t\t: undefined;\n\treturn copy;\n}\n\nfunction isStoredState(value: unknown): value is StoredState {\n\tif (!value || typeof value !== \"object\") return false;\n\tconst state = value as { version?: unknown; agents?: unknown };\n\tif (\n\t\t(state.version !== 1 && state.version !== 2 && state.version !== STATE_VERSION) ||\n\t\t!Array.isArray(state.agents)\n\t) {\n\t\treturn false;\n\t}\n\treturn state.agents.every((agent) => {\n\t\tif (!agent || typeof agent !== \"object\") return false;\n\t\tconst record = agent as Partial<ManagedAgent>;\n\t\treturn (\n\t\t\ttypeof record.id === \"string\" &&\n\t\t\t(record.taskName === undefined || isValidTaskName(record.taskName)) &&\n\t\t\t(record.taskPath === undefined || isValidTaskPath(record.taskPath)) &&\n\t\t\ttypeof record.agent === \"string\" &&\n\t\t\ttypeof record.cwd === \"string\" &&\n\t\t\ttypeof record.createdAt === \"number\" &&\n\t\t\tNumber.isFinite(record.createdAt) &&\n\t\t\ttypeof record.updatedAt === \"number\" &&\n\t\t\tNumber.isFinite(record.updatedAt) &&\n\t\t\t(record.parentId === undefined || typeof record.parentId === \"string\") &&\n\t\t\t(record.thinkingLevel === undefined || isThinkingLevel(record.thinkingLevel)) &&\n\t\t\t(record.timeoutMs === undefined || isTurnTimeout(record.timeoutMs)) &&\n\t\t\t(record.idleTimeoutMs === undefined || isTurnTimeout(record.idleTimeoutMs)) &&\n\t\t\t(record.maxTurns === undefined || isPositiveBounded(record.maxTurns, MAX_SUBAGENT_TURNS)) &&\n\t\t\t(record.maxToolCalls === undefined ||\n\t\t\t\tisPositiveBounded(record.maxToolCalls, MAX_SUBAGENT_TOOL_CALLS)) &&\n\t\t\t(record.termination === undefined || isTerminationReport(record.termination)) &&\n\t\t\t(record.contextTurns === undefined || isNonNegativeInteger(record.contextTurns)) &&\n\t\t\t(record.contextBytes === undefined || isNonNegativeInteger(record.contextBytes)) &&\n\t\t\t(record.turnGeneration === undefined || isNonNegativeInteger(record.turnGeneration)) &&\n\t\t\t(record.pendingCompletions === undefined ||\n\t\t\t\tisCompletionOutbox(record.pendingCompletions, record.turnGeneration ?? 0)) &&\n\t\t\t(record.spawnIdempotencyKey === undefined ||\n\t\t\t\t(typeof record.spawnIdempotencyKey === \"string\" &&\n\t\t\t\t\trecord.spawnIdempotencyKey.length > 0 &&\n\t\t\t\t\trecord.spawnIdempotencyKey.length <= 256)) &&\n\t\t\t(record.spawnRequestHash === undefined || isSha256(record.spawnRequestHash)) &&\n\t\t\t(record.contract === undefined ||\n\t\t\t\tnormalizeDelegationContract(record.contract) !== undefined) &&\n\t\t\t(record.resultFormat === undefined ||\n\t\t\t\tSUBAGENT_RESULT_FORMATS.includes(record.resultFormat)) &&\n\t\t\t(record.structuredResult === undefined ||\n\t\t\t\t(record.resultFormat !== undefined &&\n\t\t\t\t\tparseAnyStructuredSubagentResult(\n\t\t\t\t\t\tJSON.stringify(record.structuredResult),\n\t\t\t\t\t\trecord.resultFormat,\n\t\t\t\t\t) !== undefined)) &&\n\t\t\t(record.executionPlan === undefined || isExecutionPlan(record.executionPlan)) &&\n\t\t\t(record.capabilityGrant === undefined || isCapabilityGrant(record.capabilityGrant)) &&\n\t\t\t(record.semanticSnapshot === undefined || isSemanticSnapshot(record.semanticSnapshot)) &&\n\t\t\t(record.semanticCompatibility === undefined ||\n\t\t\t\tisSemanticCompatibility(record.semanticCompatibility)) &&\n\t\t\t(record.workspaceMode === undefined || record.workspaceMode === \"worktree\") &&\n\t\t\t(record.target === undefined || isTargetPolicyAudit(record.target)) &&\n\t\t\t(record.children === undefined ||\n\t\t\t\t(Array.isArray(record.children) &&\n\t\t\t\t\trecord.children.every((id) => typeof id === \"string\"))) &&\n\t\t\tArray.isArray(record.history) &&\n\t\t\trecord.history.every(isAgentTurn) &&\n\t\t\t(record.mailbox === undefined ||\n\t\t\t\t(Array.isArray(record.mailbox) && record.mailbox.every(isMailboxMessage)))\n\t\t);\n\t});\n}\n\nfunction isValidTaskName(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\ttry {\n\t\treturn validateTaskName(value) === value;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction isValidTaskPath(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\ttry {\n\t\treturn validateTaskPath(value) === value;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction isSemanticCompatibility(value: unknown): boolean {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst compatibility = value as Record<string, unknown>;\n\treturn (\n\t\t[\"compatible\", \"warning\", \"needs-revalidation\", \"rejected\"].includes(\n\t\t\tString(compatibility.status),\n\t\t) &&\n\t\tArray.isArray(compatibility.changedComponents) &&\n\t\tcompatibility.changedComponents.every((item) => typeof item === \"string\")\n\t);\n}\n\nfunction isNonNegativeInteger(value: unknown): value is number {\n\treturn typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0;\n}\n\nfunction isTurnTimeout(value: unknown): value is number {\n\treturn (\n\t\ttypeof value === \"number\" &&\n\t\tNumber.isSafeInteger(value) &&\n\t\tvalue >= 1 &&\n\t\tvalue <= MAX_SUBAGENT_TIMEOUT_MS\n\t);\n}\n\nfunction isPositiveBounded(value: unknown, maximum: number): value is number {\n\treturn typeof value === \"number\" && Number.isSafeInteger(value) && value >= 1 && value <= maximum;\n}\n\nfunction isTerminationReport(value: unknown): value is TurnTerminationReport {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst report = value as Record<string, unknown>;\n\tif (\n\t\treport.version !== \"pi-subagents:termination:v1\" ||\n\t\t![\n\t\t\t\"work_timeout\",\n\t\t\t\"idle_timeout\",\n\t\t\t\"turn_limit\",\n\t\t\t\"tool_call_limit\",\n\t\t\t\"orchestration_timeout\",\n\t\t].includes(String(report.reason)) ||\n\t\t!isPositiveBounded(report.limit, MAX_SUBAGENT_TIMEOUT_MS)\n\t) {\n\t\treturn false;\n\t}\n\tconst checkpoint = report.checkpoint;\n\tconst finalization = report.finalization;\n\tif (!checkpoint || typeof checkpoint !== \"object\" || Array.isArray(checkpoint)) return false;\n\tif (!finalization || typeof finalization !== \"object\" || Array.isArray(finalization))\n\t\treturn false;\n\tconst checkpointValue = checkpoint as Record<string, unknown>;\n\tconst finalizationValue = finalization as Record<string, unknown>;\n\treturn (\n\t\tcheckpointValue.version === \"pi-subagents:checkpoint:v1\" &&\n\t\ttypeof checkpointValue.task === \"string\" &&\n\t\t(checkpointValue.partialOutput === undefined ||\n\t\t\ttypeof checkpointValue.partialOutput === \"string\") &&\n\t\tArray.isArray(checkpointValue.assistantNotes) &&\n\t\tcheckpointValue.assistantNotes.every((item) => typeof item === \"string\") &&\n\t\tArray.isArray(checkpointValue.completedTools) &&\n\t\tcheckpointValue.completedTools.every(isCompletedToolEvidence) &&\n\t\tArray.isArray(checkpointValue.changedFiles) &&\n\t\tcheckpointValue.changedFiles.every((item) => typeof item === \"string\") &&\n\t\ttypeof checkpointValue.sideEffectsMayHaveOccurred === \"boolean\" &&\n\t\ttypeof checkpointValue.truncated === \"boolean\" &&\n\t\ttypeof finalizationValue.attempted === \"boolean\" &&\n\t\t[\"completed\", \"failed\", \"timed_out\", \"skipped\"].includes(String(finalizationValue.status)) &&\n\t\ttypeof finalizationValue.durationMs === \"number\" &&\n\t\tNumber.isFinite(finalizationValue.durationMs) &&\n\t\tfinalizationValue.durationMs >= 0 &&\n\t\t(finalizationValue.error === undefined || typeof finalizationValue.error === \"string\")\n\t);\n}\n\nfunction isCompletedToolEvidence(value: unknown): boolean {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst item = value as Record<string, unknown>;\n\treturn (\n\t\ttypeof item.toolName === \"string\" &&\n\t\ttypeof item.output === \"string\" &&\n\t\ttypeof item.isError === \"boolean\"\n\t);\n}\n\nfunction isSha256(value: unknown): value is string {\n\treturn typeof value === \"string\" && /^[a-f0-9]{64}$/u.test(value);\n}\n\nfunction isTargetPolicyAudit(value: unknown): boolean {\n\tif (!value || typeof value !== \"object\") return false;\n\tconst target = value as Record<string, unknown>;\n\tif (\n\t\ttypeof target.cwd !== \"string\" ||\n\t\t(target.boundary !== \"current-workspace\" && target.boundary !== \"external\") ||\n\t\t!target.trust ||\n\t\ttypeof target.trust !== \"object\"\n\t) {\n\t\treturn false;\n\t}\n\tconst trust = target.trust as Record<string, unknown>;\n\treturn (\n\t\t[\n\t\t\t\"session-trusted\",\n\t\t\t\"session-untrusted\",\n\t\t\t\"saved-trusted\",\n\t\t\t\"saved-denied\",\n\t\t\t\"unsaved\",\n\t\t\t\"trust-error\",\n\t\t].includes(String(trust.kind)) &&\n\t\ttypeof trust.projectTrusted === \"boolean\" &&\n\t\t(trust.sourcePath === undefined || typeof trust.sourcePath === \"string\") &&\n\t\t(trust.warning === undefined || typeof trust.warning === \"string\")\n\t);\n}\n\nfunction isCompletionOutbox(value: unknown, turnGeneration: number): boolean {\n\tif (!Array.isArray(value) || value.length > MAX_STORED_COMPLETIONS_PER_AGENT) return false;\n\tconst ids = new Set<string>();\n\tlet previousGeneration = 0;\n\tlet previousCreatedAt = Number.NEGATIVE_INFINITY;\n\tfor (const completion of value) {\n\t\tif (!isPersistedCompletion(completion, turnGeneration)) return false;\n\t\tif (ids.has(completion.completionId)) return false;\n\t\tif (completion.generation <= previousGeneration || completion.createdAt <= previousCreatedAt) {\n\t\t\treturn false;\n\t\t}\n\t\tids.add(completion.completionId);\n\t\tpreviousGeneration = completion.generation;\n\t\tpreviousCreatedAt = completion.createdAt;\n\t}\n\treturn true;\n}\n\nfunction isPersistedCompletion(\n\tvalue: unknown,\n\tturnGeneration: number,\n): value is import(\"./registry.js\").PersistedAgentCompletion {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst completion = value as Record<string, unknown>;\n\treturn (\n\t\ttypeof completion.completionId === \"string\" &&\n\t\tcompletion.completionId.length > 0 &&\n\t\tcompletion.completionId.length <= 256 &&\n\t\t(completion.recipientId === undefined ||\n\t\t\t(typeof completion.recipientId === \"string\" && completion.recipientId.length > 0)) &&\n\t\t(completion.recipientPath === undefined || isValidTaskPath(completion.recipientPath)) &&\n\t\ttypeof completion.runId === \"string\" &&\n\t\tcompletion.runId.length > 0 &&\n\t\tcompletion.runId.length <= 256 &&\n\t\ttypeof completion.generation === \"number\" &&\n\t\tNumber.isSafeInteger(completion.generation) &&\n\t\tcompletion.generation >= 1 &&\n\t\tcompletion.generation <= turnGeneration &&\n\t\ttypeof completion.task === \"string\" &&\n\t\ttypeof completion.output === \"string\" &&\n\t\t(completion.error === undefined || typeof completion.error === \"string\") &&\n\t\ttypeof completion.createdAt === \"number\" &&\n\t\tNumber.isFinite(completion.createdAt)\n\t);\n}\n\nfunction isAgentTurn(value: unknown): boolean {\n\tif (!value || typeof value !== \"object\") return false;\n\tconst turn = value as Record<string, unknown>;\n\treturn (\n\t\t(turn.runId === undefined ||\n\t\t\t(typeof turn.runId === \"string\" && turn.runId.length > 0 && turn.runId.length <= 256)) &&\n\t\t(turn.generation === undefined ||\n\t\t\t(typeof turn.generation === \"number\" &&\n\t\t\t\tNumber.isSafeInteger(turn.generation) &&\n\t\t\t\tturn.generation >= 1)) &&\n\t\ttypeof turn.task === \"string\" &&\n\t\ttypeof turn.output === \"string\" &&\n\t\ttypeof turn.startedAt === \"number\" &&\n\t\tNumber.isFinite(turn.startedAt) &&\n\t\ttypeof turn.completedAt === \"number\" &&\n\t\tNumber.isFinite(turn.completedAt) &&\n\t\ttypeof turn.exitCode === \"number\" &&\n\t\tNumber.isFinite(turn.exitCode) &&\n\t\t(turn.termination === undefined || isTerminationReport(turn.termination))\n\t);\n}\n\nfunction isMailboxMessage(value: unknown): boolean {\n\tif (!value || typeof value !== \"object\") return false;\n\tconst message = value as Record<string, unknown>;\n\treturn (\n\t\ttypeof message.id === \"string\" &&\n\t\ttypeof message.senderId === \"string\" &&\n\t\ttypeof message.recipientId === \"string\" &&\n\t\ttypeof message.content === \"string\" &&\n\t\ttypeof message.createdAt === \"number\" &&\n\t\tNumber.isFinite(message.createdAt) &&\n\t\t(message.readAt === undefined ||\n\t\t\t(typeof message.readAt === \"number\" && Number.isFinite(message.readAt))) &&\n\t\t(message.deduplicationKey === undefined || typeof message.deduplicationKey === \"string\") &&\n\t\t(message.completionId === undefined || typeof message.completionId === \"string\")\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,SAAS,aAAa,6BAA6B;AAgBnD,IAAM,gBAAgB;AACtB,IAAM,mCAAmC;AACzC,IAAM,0BAA0B,sBAAsB;AACtD,IAAM,kBAAkB,IAAI,OAAO;AAc5B,IAAM,mBAAN,MAAuB;AAAA,EACpB;AAAA,EACQ;AAAA,EACA;AAAA,EAEjB,YAAY,OAAe,UAA8B,CAAC,GAAG;AAC5D,UAAM,gBAAgB,QAAQ,iBAAiB;AAC/C,QAAI,CAAC,OAAO,SAAS,aAAa,KAAK,iBAAiB,GAAG;AAC1D,YAAM,IAAI,MAAM,yDAAyD;AAAA,IAC1E;AACA,UAAM,cAAc,gBAAgB,KAAK,KAAK,KAAK;AACnD,QAAI,CAAC,OAAO,SAAS,WAAW,GAAG;AAClC,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACtD;AACA,UAAM,kBAAkB,QAAQ,mBAAmB,wBAAwB;AAC3E,QAAI,CAAC,OAAO,cAAc,eAAe,KAAK,kBAAkB,GAAG;AAClE,YAAM,IAAI,MAAM,0DAA0D;AAAA,IAC3E;AACA,UAAM,YAAY,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK,EAAE,MAAM,GAAG,EAAE;AAC9E,UAAM,WAAW,QAAQ,YAAiB,UAAK,YAAY,GAAG,oBAAoB;AAClF,SAAK,WAAgB,UAAK,UAAU,GAAG,SAAS,OAAO;AACvD,SAAK,cAAc;AACnB,SAAK,kBAAkB;AAAA,EACxB;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